window.c
changeset 4337 f77887bd2634
parent 4335 18bc63352a17
child 4520 d5f94a18a68c
equal deleted inserted replaced
4336:d5cd47d24092 4337:f77887bd2634
  1144 	return false;
  1144 	return false;
  1145 }
  1145 }
  1146 
  1146 
  1147 static bool HandleViewportScroll(void)
  1147 static bool HandleViewportScroll(void)
  1148 {
  1148 {
  1149 	WindowEvent we;
  1149 	WindowEvent e;
  1150 	Window *w;
  1150 	Window *w;
  1151 
  1151 
  1152 	if (!_scrolling_viewport) return true;
  1152 	if (!_scrolling_viewport) return true;
  1153 
  1153 
  1154 	w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y);
  1154 	w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y);
  1158 		_scrolling_viewport = false;
  1158 		_scrolling_viewport = false;
  1159 		return true;
  1159 		return true;
  1160 	}
  1160 	}
  1161 
  1161 
  1162 	if (_patches.reverse_scroll) {
  1162 	if (_patches.reverse_scroll) {
  1163 		we.scroll.delta.x = -_cursor.delta.x;
  1163 		e.scroll.delta.x = -_cursor.delta.x;
  1164 		we.scroll.delta.y = -_cursor.delta.y;
  1164 		e.scroll.delta.y = -_cursor.delta.y;
  1165 	} else {
  1165 	} else {
  1166 		we.scroll.delta.x = _cursor.delta.x;
  1166 		e.scroll.delta.x = _cursor.delta.x;
  1167 		we.scroll.delta.y = _cursor.delta.y;
  1167 		e.scroll.delta.y = _cursor.delta.y;
  1168 	}
  1168 	}
  1169 
  1169 
  1170 	/* Create a scroll-event and send it to the window */
  1170 	/* Create a scroll-event and send it to the window */
  1171 	we.event = WE_SCROLL;
  1171 	e.event = WE_SCROLL;
  1172 	w->wndproc(w, &we);
  1172 	w->wndproc(w, &e);
  1173 
  1173 
  1174 	_cursor.delta.x = 0;
  1174 	_cursor.delta.x = 0;
  1175 	_cursor.delta.y = 0;
  1175 	_cursor.delta.y = 0;
  1176 	return false;
  1176 	return false;
  1177 }
  1177 }
  1337 
  1337 
  1338 	w = FindWindowFromPt(x, y);
  1338 	w = FindWindowFromPt(x, y);
  1339 	if (w == NULL) return;
  1339 	if (w == NULL) return;
  1340 	w = MaybeBringWindowToFront(w);
  1340 	w = MaybeBringWindowToFront(w);
  1341 	vp = IsPtInWindowViewport(w, x, y);
  1341 	vp = IsPtInWindowViewport(w, x, y);
       
  1342 
       
  1343 	/* Don't allow any action in a viewport if either in menu of in generating world */
       
  1344 	if (vp != NULL && (_game_mode == GM_MENU || IsGeneratingWorld())) return;
       
  1345 
       
  1346 	if (mousewheel != 0) {
       
  1347 		WindowEvent e;
       
  1348 
       
  1349 		/* Send WE_MOUSEWHEEL event to window */
       
  1350 		e.event = WE_MOUSEWHEEL;
       
  1351 		e.wheel.wheel = mousewheel;
       
  1352 		w->wndproc(w, &e);
       
  1353 
       
  1354 		/* Dispatch a MouseWheelEvent for widgets if it is not a viewport */
       
  1355 		if (vp == NULL) DispatchMouseWheelEvent(w, GetWidgetFromPos(w, x - w->left, y - w->top), mousewheel);
       
  1356 	}
       
  1357 
  1342 	if (vp != NULL) {
  1358 	if (vp != NULL) {
  1343 		if (_game_mode == GM_MENU || IsGeneratingWorld()) return;
  1359 		switch (click) {
  1344 
  1360 			case 1:
  1345 		// only allow zooming in-out in main window, or in viewports
  1361 				DEBUG(misc, 2) ("cursor: 0x%X (%d)", _cursor.sprite, _cursor.sprite);
  1346 		if (mousewheel &&
  1362 				if (_thd.place_mode != 0 &&
  1347 				!(w->flags4 & WF_DISABLE_VP_SCROLL) && (
  1363 						// query button and place sign button work in pause mode
  1348 					w->window_class == WC_MAIN_WINDOW ||
  1364 						_cursor.sprite != SPR_CURSOR_QUERY &&
  1349 					w->window_class == WC_EXTRA_VIEW_PORT
  1365 						_cursor.sprite != SPR_CURSOR_SIGN &&
  1350 				)) {
  1366 						_pause != 0 &&
  1351 			ZoomInOrOutToCursorWindow(mousewheel < 0,w);
  1367 						!_cheats.build_in_pause.value) {
  1352 		}
  1368 					return;
  1353 
  1369 				}
  1354 		if (click == 1) {
  1370 
  1355 			DEBUG(misc, 2) ("cursor: 0x%X (%d)", _cursor.sprite, _cursor.sprite);
  1371 				if (_thd.place_mode == 0) {
  1356 			if (_thd.place_mode != 0 &&
  1372 					HandleViewportClicked(vp, x, y);
  1357 					// query button and place sign button work in pause mode
  1373 				} else {
  1358 					_cursor.sprite != SPR_CURSOR_QUERY &&
  1374 					PlaceObject();
  1359 					_cursor.sprite != SPR_CURSOR_SIGN &&
  1375 				}
  1360 					_pause != 0 &&
  1376 				break;
  1361 					!_cheats.build_in_pause.value) {
  1377 
  1362 				return;
  1378 			case 2:
  1363 			}
  1379 				if (!(w->flags4 & WF_DISABLE_VP_SCROLL)) {
  1364 
  1380 					_scrolling_viewport = true;
  1365 			if (_thd.place_mode == 0) {
  1381 					_cursor.fix_at = true;
  1366 				HandleViewportClicked(vp, x, y);
  1382 				}
  1367 			} else {
  1383 				break;
  1368 				PlaceObject();
       
  1369 			}
       
  1370 		} else if (click == 2) {
       
  1371 			if (!(w->flags4 & WF_DISABLE_VP_SCROLL)) {
       
  1372 				_scrolling_viewport = true;
       
  1373 				_cursor.fix_at = true;
       
  1374 			}
       
  1375 		}
  1384 		}
  1376 	} else {
  1385 	} else {
  1377 		if (mousewheel)
       
  1378 			DispatchMouseWheelEvent(w, GetWidgetFromPos(w, x - w->left, y - w->top), mousewheel);
       
  1379 
       
  1380 		switch (click) {
  1386 		switch (click) {
  1381 			case 1: DispatchLeftClickEvent(w, x - w->left, y - w->top);  break;
  1387 			case 1: DispatchLeftClickEvent(w, x - w->left, y - w->top);  break;
  1382 			case 2: DispatchRightClickEvent(w, x - w->left, y - w->top); break;
  1388 			case 2: DispatchRightClickEvent(w, x - w->left, y - w->top); break;
  1383 		}
  1389 		}
  1384 	}
  1390 	}