src/window.cpp
branchnoai
changeset 9620 31e38d28a0af
parent 9601 b499fdd106d5
child 9624 b71483f2330f
equal deleted inserted replaced
9619:6e81cec30a2b 9620:31e38d28a0af
   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;