window.c
changeset 5268 cbff87066429
parent 5236 e959e132a78e
child 5272 e27514065ed8
equal deleted inserted replaced
5267:af4a6aa071a7 5268:cbff87066429
  1024 
  1024 
  1025 	// Mouseover never stops execution
  1025 	// Mouseover never stops execution
  1026 	return true;
  1026 	return true;
  1027 }
  1027 }
  1028 
  1028 
       
  1029 /** Update all the widgets of a window based on their resize flags
       
  1030  * Both the areas of the old window and the new sized window are set dirty
       
  1031  * ensuring proper redrawal.
       
  1032  * @param w Window to resize
       
  1033  * @param x delta x-size of changed window (positive if larger, etc.(
       
  1034  * @param y delta y-size of changed window */
       
  1035 void ResizeWindow(Window *w, int x, int y)
       
  1036 {
       
  1037 	Widget *wi;
       
  1038 	bool resize_height = false;
       
  1039 	bool resize_width = false;
       
  1040 
       
  1041 	if (x == 0 && y == 0) return;
       
  1042 
       
  1043 	SetWindowDirty(w);
       
  1044 	for (wi = w->widget; wi->type != WWT_LAST; wi++) {
       
  1045 		/* Isolate the resizing flags */
       
  1046 		byte rsizeflag = GB(wi->display_flags, 0, 4);
       
  1047 
       
  1048 		if (rsizeflag == RESIZE_NONE) continue;
       
  1049 
       
  1050 		/* Resize the widget based on its resize-flag */
       
  1051 		if (rsizeflag & RESIZE_LEFT) {
       
  1052 			wi->left += x;
       
  1053 			resize_width = true;
       
  1054 		}
       
  1055 
       
  1056 		if (rsizeflag & RESIZE_RIGHT) {
       
  1057 			wi->right += x;
       
  1058 			resize_width = true;
       
  1059 		}
       
  1060 
       
  1061 		if (rsizeflag & RESIZE_TOP) {
       
  1062 			wi->top += y;
       
  1063 			resize_height = true;
       
  1064 		}
       
  1065 
       
  1066 		if (rsizeflag & RESIZE_BOTTOM) {
       
  1067 			wi->bottom += y;
       
  1068 			resize_height = true;
       
  1069 		}
       
  1070 	}
       
  1071 
       
  1072 	/* We resized at least 1 widget, so let's resize the window totally */
       
  1073 	if (resize_width)  w->width  += x;
       
  1074 	if (resize_height) w->height += y;
       
  1075 
       
  1076 	SetWindowDirty(w);
       
  1077 }
  1029 
  1078 
  1030 static bool _dragging_window;
  1079 static bool _dragging_window;
  1031 
  1080 
  1032 static bool HandleWindowDragging(void)
  1081 static bool HandleWindowDragging(void)
  1033 {
  1082 {
  1209 			/* Now find the new cursor pos.. this is NOT _cursor, because
  1258 			/* Now find the new cursor pos.. this is NOT _cursor, because
  1210 			    we move in steps. */
  1259 			    we move in steps. */
  1211 			_drag_delta.x += x;
  1260 			_drag_delta.x += x;
  1212 			_drag_delta.y += y;
  1261 			_drag_delta.y += y;
  1213 
  1262 
  1214 			SetWindowDirty(w);
  1263 			/* ResizeWindow sets both pre- and after-size to dirty for redrawal */
  1215 
  1264 			ResizeWindow(w, x, y);
  1216 			/* Scroll through all the windows and update the widgets if needed */
       
  1217 			{
       
  1218 				Widget *wi = w->widget;
       
  1219 				bool resize_height = false;
       
  1220 				bool resize_width = false;
       
  1221 
       
  1222 				while (wi->type != WWT_LAST) {
       
  1223 					/* Isolate the resizing flags */
       
  1224 					byte rsizeflag = GB(wi->display_flags, 0, 4);
       
  1225 
       
  1226 					if (rsizeflag != RESIZE_NONE) {
       
  1227 						/* Resize this widget */
       
  1228 						if (rsizeflag & RESIZE_LEFT) {
       
  1229 							wi->left += x;
       
  1230 							resize_width = true;
       
  1231 						}
       
  1232 						if (rsizeflag & RESIZE_RIGHT) {
       
  1233 							wi->right += x;
       
  1234 							resize_width = true;
       
  1235 						}
       
  1236 
       
  1237 						if (rsizeflag & RESIZE_TOP) {
       
  1238 							wi->top += y;
       
  1239 							resize_height = true;
       
  1240 						}
       
  1241 						if (rsizeflag & RESIZE_BOTTOM) {
       
  1242 							wi->bottom += y;
       
  1243 							resize_height = true;
       
  1244 						}
       
  1245 					}
       
  1246 					wi++;
       
  1247 				}
       
  1248 
       
  1249 				/* We resized at least 1 widget, so let's rezise the window totally */
       
  1250 				if (resize_width)  w->width  = x + w->width;
       
  1251 				if (resize_height) w->height = y + w->height;
       
  1252 			}
       
  1253 
  1265 
  1254 			e.event = WE_RESIZE;
  1266 			e.event = WE_RESIZE;
  1255 			e.we.sizing.size.x = x + w->width;
  1267 			e.we.sizing.size.x = x + w->width;
  1256 			e.we.sizing.size.y = y + w->height;
  1268 			e.we.sizing.size.y = y + w->height;
  1257 			e.we.sizing.diff.x = x;
  1269 			e.we.sizing.diff.x = x;
  1258 			e.we.sizing.diff.y = y;
  1270 			e.we.sizing.diff.y = y;
  1259 			w->wndproc(w, &e);
  1271 			w->wndproc(w, &e);
  1260 
       
  1261 			SetWindowDirty(w);
       
  1262 			return false;
  1272 			return false;
  1263 		}
  1273 		}
  1264 	}
  1274 	}
  1265 
  1275 
  1266 	_dragging_window = false;
  1276 	_dragging_window = false;