mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r13071) -Codechange: make also a class of the MainWindow.
This commit is contained in:
parent
8e702d1053
commit
ab7a5568d7
|
@ -214,11 +214,16 @@ void ZoomInOrOutToCursorWindow(bool in, Window *w)
|
|||
|
||||
extern void UpdateAllStationVirtCoord();
|
||||
|
||||
static void MainWindowWndProc(Window *w, WindowEvent *e)
|
||||
struct MainWindow : Window
|
||||
{
|
||||
switch (e->event) {
|
||||
case WE_PAINT:
|
||||
DrawWindowViewport(w);
|
||||
MainWindow(int width, int height) : Window(0, 0, width, height, NULL, WC_MAIN_WINDOW, NULL)
|
||||
{
|
||||
InitializeWindowViewport(this, 0, 0, width, height, TileXY(32, 32), ZOOM_LVL_VIEWPORT);
|
||||
}
|
||||
|
||||
virtual void OnPaint()
|
||||
{
|
||||
DrawWindowViewport(this);
|
||||
if (_game_mode == GM_MENU) {
|
||||
int off_x = _screen.width / 2;
|
||||
|
||||
|
@ -231,44 +236,43 @@ static void MainWindowWndProc(Window *w, WindowEvent *e)
|
|||
DrawSprite(SPR_OTTD_T, PAL_NONE, off_x + 65, 50);
|
||||
DrawSprite(SPR_OTTD_D, PAL_NONE, off_x + 96, 50);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case WE_KEYPRESS:
|
||||
switch (e->we.keypress.keycode) {
|
||||
virtual bool OnKeyPress(uint16 key, uint16 keycode)
|
||||
{
|
||||
switch (keycode) {
|
||||
case 'Q' | WKC_CTRL:
|
||||
case 'Q' | WKC_META:
|
||||
HandleExitGameRequest();
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Disable all key shortcuts, except quit shortcuts when
|
||||
* generating the world, otherwise they create threading
|
||||
* problem during the generating, resulting in random
|
||||
* assertions that are hard to trigger and debug */
|
||||
if (IsGeneratingWorld()) break;
|
||||
if (IsGeneratingWorld()) return true;
|
||||
|
||||
if (e->we.keypress.keycode == WKC_BACKQUOTE) {
|
||||
if (keycode == WKC_BACKQUOTE) {
|
||||
IConsoleSwitch();
|
||||
e->we.keypress.cont = false;
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (e->we.keypress.keycode == ('B' | WKC_CTRL)) {
|
||||
e->we.keypress.cont = false;
|
||||
if (keycode == ('B' | WKC_CTRL)) {
|
||||
extern bool _draw_bounding_boxes;
|
||||
_draw_bounding_boxes = !_draw_bounding_boxes;
|
||||
MarkWholeScreenDirty();
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_game_mode == GM_MENU) break;
|
||||
if (_game_mode == GM_MENU) return true;
|
||||
|
||||
switch (e->we.keypress.keycode) {
|
||||
switch (keycode) {
|
||||
case 'C':
|
||||
case 'Z': {
|
||||
Point pt = GetTileBelowCursor();
|
||||
if (pt.x != -1) {
|
||||
if (e->we.keypress.keycode == 'Z') MaxZoomInOut(ZOOM_IN, w);
|
||||
if (keycode == 'Z') MaxZoomInOut(ZOOM_IN, this);
|
||||
ScrollMainWindowTo(pt.x, pt.y);
|
||||
}
|
||||
break;
|
||||
|
@ -305,7 +309,7 @@ static void MainWindowWndProc(Window *w, WindowEvent *e)
|
|||
case '8' | WKC_CTRL:
|
||||
case '9' | WKC_CTRL:
|
||||
/* Transparency toggle hot keys */
|
||||
ToggleTransparency((TransparencyOption)(e->we.keypress.keycode - ('1' | WKC_CTRL)));
|
||||
ToggleTransparency((TransparencyOption)(keycode - ('1' | WKC_CTRL)));
|
||||
MarkWholeScreenDirty();
|
||||
break;
|
||||
|
||||
|
@ -318,7 +322,7 @@ static void MainWindowWndProc(Window *w, WindowEvent *e)
|
|||
case '7' | WKC_CTRL | WKC_SHIFT:
|
||||
case '8' | WKC_CTRL | WKC_SHIFT:
|
||||
/* Invisibility toggle hot keys */
|
||||
ToggleInvisibilityWithTransparency((TransparencyOption)(e->we.keypress.keycode - ('1' | WKC_CTRL | WKC_SHIFT)));
|
||||
ToggleInvisibilityWithTransparency((TransparencyOption)(keycode - ('1' | WKC_CTRL | WKC_SHIFT)));
|
||||
MarkWholeScreenDirty();
|
||||
break;
|
||||
|
||||
|
@ -367,35 +371,37 @@ static void MainWindowWndProc(Window *w, WindowEvent *e)
|
|||
break;
|
||||
#endif
|
||||
|
||||
default: return;
|
||||
default: return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
e->we.keypress.cont = false;
|
||||
break;
|
||||
|
||||
case WE_SCROLL: {
|
||||
ViewPort *vp = IsPtInWindowViewport(w, _cursor.pos.x, _cursor.pos.y);
|
||||
virtual void OnScroll(Point delta)
|
||||
{
|
||||
ViewPort *vp = IsPtInWindowViewport(this, _cursor.pos.x, _cursor.pos.y);
|
||||
|
||||
if (vp == NULL) {
|
||||
_cursor.fix_at = false;
|
||||
_scrolling_viewport = false;
|
||||
}
|
||||
|
||||
w->viewport->scrollpos_x += ScaleByZoom(e->we.scroll.delta.x, vp->zoom);
|
||||
w->viewport->scrollpos_y += ScaleByZoom(e->we.scroll.delta.y, vp->zoom);
|
||||
w->viewport->dest_scrollpos_x = w->viewport->scrollpos_x;
|
||||
w->viewport->dest_scrollpos_y = w->viewport->scrollpos_y;
|
||||
} break;
|
||||
this->viewport->scrollpos_x += ScaleByZoom(delta.x, vp->zoom);
|
||||
this->viewport->scrollpos_y += ScaleByZoom(delta.y, vp->zoom);
|
||||
this->viewport->dest_scrollpos_x = this->viewport->scrollpos_x;
|
||||
this->viewport->dest_scrollpos_y = this->viewport->scrollpos_y;
|
||||
};
|
||||
|
||||
case WE_MOUSEWHEEL:
|
||||
ZoomInOrOutToCursorWindow(e->we.wheel.wheel < 0, w);
|
||||
break;
|
||||
virtual void OnMouseWheel(int wheel)
|
||||
{
|
||||
ZoomInOrOutToCursorWindow(wheel < 0, this);
|
||||
}
|
||||
|
||||
case WE_INVALIDATE_DATA:
|
||||
virtual void OnInvalidateData(int data)
|
||||
{
|
||||
/* Forward the message to the appropiate toolbar (ingame or scenario editor) */
|
||||
InvalidateWindowData(WC_MAIN_TOOLBAR, 0, e->we.invalidate.data);
|
||||
break;
|
||||
}
|
||||
InvalidateWindowData(WC_MAIN_TOOLBAR, 0, data);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void ShowSelectGameWindow();
|
||||
|
@ -409,11 +415,7 @@ void SetupColorsAndInitialWindow()
|
|||
memcpy(_colour_gradient[i], b + 0xC6, sizeof(_colour_gradient[i]));
|
||||
}
|
||||
|
||||
int width = _screen.width;
|
||||
int height = _screen.height;
|
||||
|
||||
Window *w = new Window(0, 0, width, height, MainWindowWndProc, WC_MAIN_WINDOW, NULL);
|
||||
InitializeWindowViewport(w, 0, 0, width, height, TileXY(32, 32), ZOOM_LVL_VIEWPORT);
|
||||
new MainWindow(_screen.width, _screen.height);
|
||||
|
||||
/* XXX: these are not done */
|
||||
switch (_game_mode) {
|
||||
|
|
Loading…
Reference in New Issue