src/window.cpp
branchgamebalance
changeset 9911 0b8b245a2391
parent 9910 0b2aebc8283e
child 9913 e79cd19772dd
equal deleted inserted replaced
9910:0b2aebc8283e 9911:0b8b245a2391
   269 		dp->height = bottom - top;
   269 		dp->height = bottom - top;
   270 		dp->left = left - (*wz)->left;
   270 		dp->left = left - (*wz)->left;
   271 		dp->top = top - (*wz)->top;
   271 		dp->top = top - (*wz)->top;
   272 		dp->pitch = _screen.pitch;
   272 		dp->pitch = _screen.pitch;
   273 		dp->dst_ptr = _screen.dst_ptr + top * _screen.pitch + left;
   273 		dp->dst_ptr = _screen.dst_ptr + top * _screen.pitch + left;
   274 		dp->zoom = 0;
   274 		dp->zoom = ZOOM_LVL_NORMAL;
   275 		CallWindowEventNP(*wz, WE_PAINT);
   275 		CallWindowEventNP(*wz, WE_PAINT);
   276 	}
   276 	}
   277 }
   277 }
   278 
   278 
   279 void CallWindowEventNP(Window *w, int event)
   279 void CallWindowEventNP(Window *w, int event)
   680 struct SizeRect {
   680 struct SizeRect {
   681 	int left,top,width,height;
   681 	int left,top,width,height;
   682 };
   682 };
   683 
   683 
   684 
   684 
   685 static SizeRect _awap_r;
   685 static bool IsGoodAutoPlace1(int left, int top, int width, int height, Point &pos)
   686 
   686 {
   687 static bool IsGoodAutoPlace1(int left, int top)
   687 	Window* const *wz;
   688 {
   688 
   689 	int right,bottom;
   689 	int right  = width + left;
   690 	Window* const *wz;
   690 	int bottom = height + top;
   691 
       
   692 	_awap_r.left= left;
       
   693 	_awap_r.top = top;
       
   694 	right = _awap_r.width + left;
       
   695 	bottom = _awap_r.height + top;
       
   696 
   691 
   697 	if (left < 0 || top < 22 || right > _screen.width || bottom > _screen.height)
   692 	if (left < 0 || top < 22 || right > _screen.width || bottom > _screen.height)
   698 		return false;
   693 		return false;
   699 
   694 
   700 	/* Make sure it is not obscured by any window. */
   695 	/* Make sure it is not obscured by any window. */
   708 				w->top + w->height > top) {
   703 				w->top + w->height > top) {
   709 			return false;
   704 			return false;
   710 		}
   705 		}
   711 	}
   706 	}
   712 
   707 
       
   708 	pos.x = left;
       
   709 	pos.y = top;
   713 	return true;
   710 	return true;
   714 }
   711 }
   715 
   712 
   716 static bool IsGoodAutoPlace2(int left, int top)
   713 static bool IsGoodAutoPlace2(int left, int top, int width, int height, Point &pos)
   717 {
   714 {
   718 	int width,height;
   715 	Window* const *wz;
   719 	Window* const *wz;
       
   720 
       
   721 	_awap_r.left= left;
       
   722 	_awap_r.top = top;
       
   723 	width = _awap_r.width;
       
   724 	height = _awap_r.height;
       
   725 
   716 
   726 	if (left < -(width>>2) || left > _screen.width - (width>>1)) return false;
   717 	if (left < -(width>>2) || left > _screen.width - (width>>1)) return false;
   727 	if (top < 22 || top > _screen.height - (height>>2)) return false;
   718 	if (top < 22 || top > _screen.height - (height>>2)) return false;
   728 
   719 
   729 	/* Make sure it is not obscured by any window. */
   720 	/* Make sure it is not obscured by any window. */
   737 				w->top + w->height > top) {
   728 				w->top + w->height > top) {
   738 			return false;
   729 			return false;
   739 		}
   730 		}
   740 	}
   731 	}
   741 
   732 
       
   733 	pos.x = left;
       
   734 	pos.y = top;
   742 	return true;
   735 	return true;
   743 }
   736 }
   744 
   737 
   745 static Point GetAutoPlacePosition(int width, int height)
   738 static Point GetAutoPlacePosition(int width, int height)
   746 {
   739 {
   747 	Window* const *wz;
   740 	Window* const *wz;
   748 	Point pt;
   741 	Point pt;
   749 
   742 
   750 	_awap_r.width = width;
   743 	if (IsGoodAutoPlace1(0, 24, width, height, pt)) return pt;
   751 	_awap_r.height = height;
       
   752 
       
   753 	if (IsGoodAutoPlace1(0, 24)) goto ok_pos;
       
   754 
   744 
   755 	FOR_ALL_WINDOWS(wz) {
   745 	FOR_ALL_WINDOWS(wz) {
   756 		const Window *w = *wz;
   746 		const Window *w = *wz;
   757 		if (w->window_class == WC_MAIN_WINDOW) continue;
   747 		if (w->window_class == WC_MAIN_WINDOW) continue;
   758 
   748 
   759 		if (IsGoodAutoPlace1(w->left+w->width+2,w->top)) goto ok_pos;
   749 		if (IsGoodAutoPlace1(w->left + w->width + 2, w->top, width, height, pt)) return pt;
   760 		if (IsGoodAutoPlace1(w->left-   width-2,w->top)) goto ok_pos;
   750 		if (IsGoodAutoPlace1(w->left - width - 2,    w->top, width, height, pt)) return pt;
   761 		if (IsGoodAutoPlace1(w->left,w->top+w->height+2)) goto ok_pos;
   751 		if (IsGoodAutoPlace1(w->left, w->top + w->height + 2, width, height, pt)) return pt;
   762 		if (IsGoodAutoPlace1(w->left,w->top-   height-2)) goto ok_pos;
   752 		if (IsGoodAutoPlace1(w->left, w->top - height - 2,    width, height, pt)) return pt;
   763 		if (IsGoodAutoPlace1(w->left+w->width+2,w->top+w->height-height)) goto ok_pos;
   753 		if (IsGoodAutoPlace1(w->left + w->width + 2, w->top + w->height - height, width, height, pt)) return pt;
   764 		if (IsGoodAutoPlace1(w->left-   width-2,w->top+w->height-height)) goto ok_pos;
   754 		if (IsGoodAutoPlace1(w->left - width - 2,    w->top + w->height - height, width, height, pt)) return pt;
   765 		if (IsGoodAutoPlace1(w->left+w->width-width,w->top+w->height+2)) goto ok_pos;
   755 		if (IsGoodAutoPlace1(w->left + w->width - width, w->top + w->height + 2, width, height, pt)) return pt;
   766 		if (IsGoodAutoPlace1(w->left+w->width-width,w->top-   height-2)) goto ok_pos;
   756 		if (IsGoodAutoPlace1(w->left + w->width - width, w->top - height - 2,    width, height, pt)) return pt;
   767 	}
   757 	}
   768 
   758 
   769 	FOR_ALL_WINDOWS(wz) {
   759 	FOR_ALL_WINDOWS(wz) {
   770 		const Window *w = *wz;
   760 		const Window *w = *wz;
   771 		if (w->window_class == WC_MAIN_WINDOW) continue;
   761 		if (w->window_class == WC_MAIN_WINDOW) continue;
   772 
   762 
   773 		if (IsGoodAutoPlace2(w->left+w->width+2,w->top)) goto ok_pos;
   763 		if (IsGoodAutoPlace2(w->left + w->width + 2, w->top, width, height, pt)) return pt;
   774 		if (IsGoodAutoPlace2(w->left-   width-2,w->top)) goto ok_pos;
   764 		if (IsGoodAutoPlace2(w->left - width - 2,    w->top, width, height, pt)) return pt;
   775 		if (IsGoodAutoPlace2(w->left,w->top+w->height+2)) goto ok_pos;
   765 		if (IsGoodAutoPlace2(w->left, w->top + w->height + 2, width, height, pt)) return pt;
   776 		if (IsGoodAutoPlace2(w->left,w->top-   height-2)) goto ok_pos;
   766 		if (IsGoodAutoPlace2(w->left, w->top - height - 2,    width, height, pt)) return pt;
   777 	}
   767 	}
   778 
   768 
   779 	{
   769 	{
   780 		int left=0,top=24;
   770 		int left = 0, top = 24;
   781 
   771 
   782 restart:;
   772 restart:
   783 		FOR_ALL_WINDOWS(wz) {
   773 		FOR_ALL_WINDOWS(wz) {
   784 			const Window *w = *wz;
   774 			const Window *w = *wz;
   785 
   775 
   786 			if (w->left == left && w->top == top) {
   776 			if (w->left == left && w->top == top) {
   787 				left += 5;
   777 				left += 5;
   792 
   782 
   793 		pt.x = left;
   783 		pt.x = left;
   794 		pt.y = top;
   784 		pt.y = top;
   795 		return pt;
   785 		return pt;
   796 	}
   786 	}
   797 
       
   798 ok_pos:;
       
   799 	pt.x = _awap_r.left;
       
   800 	pt.y = _awap_r.top;
       
   801 	return pt;
       
   802 }
   787 }
   803 
   788 
   804 static Window *LocalAllocateWindowDesc(const WindowDesc *desc, int window_number)
   789 static Window *LocalAllocateWindowDesc(const WindowDesc *desc, int window_number)
   805 {
   790 {
   806 	Point pt;
   791 	Point pt;
  1631 			x -= vp->left;
  1616 			x -= vp->left;
  1632 			y -= vp->top;
  1617 			y -= vp->top;
  1633 			/* here allows scrolling in both x and y axis */
  1618 			/* here allows scrolling in both x and y axis */
  1634 #define scrollspeed 3
  1619 #define scrollspeed 3
  1635 			if (x - 15 < 0) {
  1620 			if (x - 15 < 0) {
  1636 				WP(w, vp_d).scrollpos_x += (x - 15) * scrollspeed << vp->zoom;
  1621 				WP(w, vp_d).scrollpos_x += ScaleByZoom((x - 15) * scrollspeed, vp->zoom);
  1637 			} else if (15 - (vp->width - x) > 0) {
  1622 			} else if (15 - (vp->width - x) > 0) {
  1638 				WP(w, vp_d).scrollpos_x += (15 - (vp->width - x)) * scrollspeed << vp->zoom;
  1623 				WP(w, vp_d).scrollpos_x += ScaleByZoom((15 - (vp->width - x)) * scrollspeed, vp->zoom);
  1639 			}
  1624 			}
  1640 			if (y - 15 < 0) {
  1625 			if (y - 15 < 0) {
  1641 				WP(w, vp_d).scrollpos_y += (y - 15) * scrollspeed << vp->zoom;
  1626 				WP(w, vp_d).scrollpos_y += ScaleByZoom((y - 15) * scrollspeed, vp->zoom);
  1642 			} else if (15 - (vp->height - y) > 0) {
  1627 			} else if (15 - (vp->height - y) > 0) {
  1643 				WP(w,vp_d).scrollpos_y += (15 - (vp->height - y)) * scrollspeed << vp->zoom;
  1628 				WP(w,vp_d).scrollpos_y += ScaleByZoom((15 - (vp->height - y)) * scrollspeed, vp->zoom);
  1644 			}
  1629 			}
  1645 #undef scrollspeed
  1630 #undef scrollspeed
  1646 		}
  1631 		}
  1647 	}
  1632 	}
  1648 }
  1633 }
  1983 
  1968 
  1984 		if (w->window_class == WC_MAIN_WINDOW) {
  1969 		if (w->window_class == WC_MAIN_WINDOW) {
  1985 			ViewPort *vp = w->viewport;
  1970 			ViewPort *vp = w->viewport;
  1986 			vp->width = w->width = neww;
  1971 			vp->width = w->width = neww;
  1987 			vp->height = w->height = newh;
  1972 			vp->height = w->height = newh;
  1988 			vp->virtual_width = neww << vp->zoom;
  1973 			vp->virtual_width = ScaleByZoom(neww, vp->zoom);
  1989 			vp->virtual_height = newh << vp->zoom;
  1974 			vp->virtual_height = ScaleByZoom(newh, vp->zoom);
  1990 			continue; // don't modify top,left
  1975 			continue; // don't modify top,left
  1991 		}
  1976 		}
  1992 
  1977 
  1993 		/* XXX - this probably needs something more sane. For example specying
  1978 		/* XXX - this probably needs something more sane. For example specying
  1994 		 * in a 'backup'-desc that the window should always be centred. */
  1979 		 * in a 'backup'-desc that the window should always be centred. */