00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "stdafx.h"
00013 #include "landscape.h"
00014 #include "window_gui.h"
00015 #include "viewport_func.h"
00016 #include "gfx_func.h"
00017 #include "strings_func.h"
00018 #include "zoom_func.h"
00019 #include "window_func.h"
00020 #include "tilehighlight_func.h"
00021
00022 #include "table/strings.h"
00023 #include "table/sprites.h"
00024
00026 enum ExtraViewportWindowWidgets {
00027 EVW_CAPTION,
00028 EVW_VIEWPORT,
00029 EVW_ZOOMIN,
00030 EVW_ZOOMOUT,
00031 EVW_MAIN_TO_VIEW,
00032 EVW_VIEW_TO_MAIN,
00033 };
00034
00035
00036 static const NWidgetPart _nested_extra_view_port_widgets[] = {
00037 NWidget(NWID_HORIZONTAL),
00038 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
00039 NWidget(WWT_CAPTION, COLOUR_GREY, EVW_CAPTION), SetDataTip(STR_EXTRA_VIEW_PORT_TITLE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
00040 NWidget(WWT_SHADEBOX, COLOUR_GREY),
00041 NWidget(WWT_STICKYBOX, COLOUR_GREY),
00042 EndContainer(),
00043 NWidget(WWT_PANEL, COLOUR_GREY),
00044 NWidget(NWID_VIEWPORT, INVALID_COLOUR, EVW_VIEWPORT), SetPadding(2, 2, 2, 2), SetResize(1, 1), SetFill(1, 1),
00045 EndContainer(),
00046 NWidget(NWID_HORIZONTAL),
00047 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, EVW_ZOOMIN), SetDataTip(SPR_IMG_ZOOMIN, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_IN),
00048 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, EVW_ZOOMOUT), SetDataTip(SPR_IMG_ZOOMOUT, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_OUT),
00049 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
00050 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, EVW_MAIN_TO_VIEW), SetFill(1, 1), SetResize(1, 0),
00051 SetDataTip(STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW, STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW_TT),
00052 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, EVW_VIEW_TO_MAIN), SetFill(1, 1), SetResize(1, 0),
00053 SetDataTip(STR_EXTRA_VIEW_MOVE_VIEW_TO_MAIN, STR_EXTRA_VIEW_MOVE_VIEW_TO_MAIN_TT),
00054 EndContainer(),
00055 EndContainer(),
00056 NWidget(NWID_HORIZONTAL),
00057 NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1), SetResize(1, 0), EndContainer(),
00058 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
00059 EndContainer(),
00060 };
00061
00062 class ExtraViewportWindow : public Window {
00063 public:
00064 ExtraViewportWindow(const WindowDesc *desc, int window_number, TileIndex tile) : Window()
00065 {
00066 this->InitNested(desc, window_number);
00067
00068 NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(EVW_VIEWPORT);
00069 nvp->InitializeViewport(this, 0, ZOOM_LVL_NORMAL);
00070 this->DisableWidget(EVW_ZOOMIN);
00071
00072 Point pt;
00073 if (tile == INVALID_TILE) {
00074
00075 const Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
00076
00077
00078 pt.x = w->viewport->scrollpos_x + w->viewport->virtual_width / 2;
00079 pt.y = w->viewport->scrollpos_y + w->viewport->virtual_height / 2;
00080 } else {
00081 pt = RemapCoords(TileX(tile) * TILE_SIZE + TILE_SIZE / 2, TileY(tile) * TILE_SIZE + TILE_SIZE / 2, TileHeight(tile));
00082 }
00083
00084 this->viewport->scrollpos_x = pt.x - this->viewport->virtual_width / 2;
00085 this->viewport->scrollpos_y = pt.y - this->viewport->virtual_height / 2;
00086 this->viewport->dest_scrollpos_x = this->viewport->scrollpos_x;
00087 this->viewport->dest_scrollpos_y = this->viewport->scrollpos_y;
00088 }
00089
00090 virtual void SetStringParameters(int widget) const
00091 {
00092 switch (widget) {
00093 case EVW_CAPTION:
00094
00095 SetDParam(0, this->window_number + 1);
00096 break;
00097 }
00098 }
00099
00100 virtual void OnClick(Point pt, int widget, int click_count)
00101 {
00102 switch (widget) {
00103 case EVW_ZOOMIN: DoZoomInOutWindow(ZOOM_IN, this); break;
00104 case EVW_ZOOMOUT: DoZoomInOutWindow(ZOOM_OUT, this); break;
00105
00106 case EVW_MAIN_TO_VIEW: {
00107 Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
00108 int x = this->viewport->scrollpos_x;
00109 int y = this->viewport->scrollpos_y;
00110
00111
00112 w->viewport->dest_scrollpos_x = x - (w->viewport->virtual_width - this->viewport->virtual_width) / 2;
00113 w->viewport->dest_scrollpos_y = y - (w->viewport->virtual_height - this->viewport->virtual_height) / 2;
00114 w->viewport->follow_vehicle = INVALID_VEHICLE;
00115 break;
00116 }
00117
00118 case EVW_VIEW_TO_MAIN: {
00119 const Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
00120 int x = w->viewport->scrollpos_x;
00121 int y = w->viewport->scrollpos_y;
00122
00123 this->viewport->dest_scrollpos_x = x + (w->viewport->virtual_width - this->viewport->virtual_width) / 2;
00124 this->viewport->dest_scrollpos_y = y + (w->viewport->virtual_height - this->viewport->virtual_height) / 2;
00125 break;
00126 }
00127 }
00128 }
00129
00130 virtual void OnResize()
00131 {
00132 if (this->viewport != NULL) {
00133 NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(EVW_VIEWPORT);
00134 nvp->UpdateViewportCoordinates(this);
00135 }
00136 }
00137
00138 virtual void OnScroll(Point delta)
00139 {
00140 this->viewport->scrollpos_x += ScaleByZoom(delta.x, this->viewport->zoom);
00141 this->viewport->scrollpos_y += ScaleByZoom(delta.y, this->viewport->zoom);
00142 this->viewport->dest_scrollpos_x = this->viewport->scrollpos_x;
00143 this->viewport->dest_scrollpos_y = this->viewport->scrollpos_y;
00144 }
00145
00146 virtual void OnMouseWheel(int wheel)
00147 {
00148 ZoomInOrOutToCursorWindow(wheel < 0, this);
00149 }
00150
00151 virtual void OnInvalidateData(int data = 0)
00152 {
00153
00154 HandleZoomMessage(this, this->viewport, EVW_ZOOMIN, EVW_ZOOMOUT);
00155 }
00156 };
00157
00158 static const WindowDesc _extra_view_port_desc(
00159 WDP_AUTO, 300, 268,
00160 WC_EXTRA_VIEW_PORT, WC_NONE,
00161 WDF_UNCLICK_BUTTONS,
00162 _nested_extra_view_port_widgets, lengthof(_nested_extra_view_port_widgets)
00163 );
00164
00169 void ShowExtraViewPortWindow(TileIndex tile)
00170 {
00171 int i = 0;
00172
00173
00174 while (FindWindowById(WC_EXTRA_VIEW_PORT, i) != NULL) i++;
00175
00176 new ExtraViewportWindow(&_extra_view_port_desc, i, tile);
00177 }
00178
00184 void ShowExtraViewPortWindowForTileUnderCursor()
00185 {
00186
00187
00188 Point pt = GetTileBelowCursor();
00189 ShowExtraViewPortWindow(pt.x != -1 ? TileVirtXY(pt.x, pt.y) : INVALID_TILE);
00190 }