21 #include "vehicle.h" |
21 #include "vehicle.h" |
22 #include "town.h" |
22 #include "town.h" |
23 #include "sound.h" |
23 #include "sound.h" |
24 #include "variables.h" |
24 #include "variables.h" |
25 |
25 |
26 static const Widget _smallmap_widgets[] = { |
26 static const OldWidget _smallmap_widgets[] = { |
27 { WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
27 { WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
28 { WWT_CAPTION, RESIZE_RIGHT, 13, 11, 433, 0, 13, STR_00B0_MAP, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
28 { WWT_CAPTION, RESIZE_RIGHT, 13, 11, 433, 0, 13, STR_00B0_MAP, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
29 { WWT_STICKYBOX, RESIZE_LR, 13, 434, 445, 0, 13, 0x0, STR_STICKY_BUTTON}, |
29 { WWT_STICKYBOX, RESIZE_LR, 13, 434, 445, 0, 13, 0x0, STR_STICKY_BUTTON}, |
30 { WWT_PANEL, RESIZE_RB, 13, 0, 445, 14, 257, 0x0, STR_NULL}, |
30 { WWT_PANEL, RESIZE_RB, 13, 0, 445, 14, 257, 0x0, STR_NULL}, |
31 { WWT_INSET, RESIZE_RB, 13, 2, 443, 16, 255, 0x0, STR_NULL}, |
31 { WWT_INSET, RESIZE_RB, 13, 2, 443, 16, 255, 0x0, STR_NULL}, |
577 * The passes are: |
577 * The passes are: |
578 * <ol><li>The colors of tiles in the different modes.</li> |
578 * <ol><li>The colors of tiles in the different modes.</li> |
579 * <li>Town names (optional)</li> |
579 * <li>Town names (optional)</li> |
580 * |
580 * |
581 * @param dpi pointer to pixel to write onto |
581 * @param dpi pointer to pixel to write onto |
582 * @param w pointer to Window struct |
582 * @param w pointer to BaseWindow struct |
583 * @param type type of map requested (vegetation, owners, routes, etc) |
583 * @param type type of map requested (vegetation, owners, routes, etc) |
584 * @param show_towns true if the town names should be displayed, false if not. |
584 * @param show_towns true if the town names should be displayed, false if not. |
585 */ |
585 */ |
586 static void DrawSmallMap(DrawPixelInfo *dpi, Window *w, int type, bool show_towns) |
586 static void DrawSmallMap(DrawPixelInfo *dpi, BaseWindow *w, int type, bool show_towns) |
587 { |
587 { |
588 DrawPixelInfo *old_dpi; |
588 DrawPixelInfo *old_dpi; |
589 int dx,dy, x, y, x2, y2; |
589 int dx,dy, x, y, x2, y2; |
590 Pixel *ptr; |
590 Pixel *ptr; |
591 int tile_x; |
591 int tile_x; |
760 // Draw map indicators |
760 // Draw map indicators |
761 { |
761 { |
762 Point pt; |
762 Point pt; |
763 |
763 |
764 // Find main viewport. |
764 // Find main viewport. |
765 vp = Window::FindById(WC_MAIN_WINDOW,0)->viewport; |
765 vp = BaseWindow::FindById(WC_MAIN_WINDOW,0)->viewport; |
766 |
766 |
767 pt = RemapCoords(WP(w, smallmap_d).scroll_x, WP(w, smallmap_d).scroll_y, 0); |
767 pt = RemapCoords(WP(w, smallmap_d).scroll_x, WP(w, smallmap_d).scroll_y, 0); |
768 |
768 |
769 x = vp->virtual_left - pt.x; |
769 x = vp->virtual_left - pt.x; |
770 y = vp->virtual_top - pt.y; |
770 y = vp->virtual_top - pt.y; |
783 DrawHorizMapIndicator(x, y2, x2, y2); |
783 DrawHorizMapIndicator(x, y2, x2, y2); |
784 } |
784 } |
785 _cur_dpi = old_dpi; |
785 _cur_dpi = old_dpi; |
786 } |
786 } |
787 |
787 |
788 void SmallMapCenterOnCurrentPos(Window *w) |
788 void SmallMapCenterOnCurrentPos(BaseWindow *w) |
789 { |
789 { |
790 int x, y; |
790 int x, y; |
791 ViewPort *vp; |
791 ViewPort *vp; |
792 vp = Window::FindById(WC_MAIN_WINDOW, 0)->viewport; |
792 vp = BaseWindow::FindById(WC_MAIN_WINDOW, 0)->viewport; |
793 |
793 |
794 x = ((vp->virtual_width - (w->widget[4].right - w->widget[4].left) * TILE_SIZE) / 2 + vp->virtual_left) / 4; |
794 x = ((vp->virtual_width - (w->widget[4].right - w->widget[4].left) * TILE_SIZE) / 2 + vp->virtual_left) / 4; |
795 y = ((vp->virtual_height - (w->widget[4].bottom - w->widget[4].top ) * TILE_SIZE) / 2 + vp->virtual_top ) / 2 - TILE_SIZE * 2; |
795 y = ((vp->virtual_height - (w->widget[4].bottom - w->widget[4].top ) * TILE_SIZE) / 2 + vp->virtual_top ) / 2 - TILE_SIZE * 2; |
796 WP(w, smallmap_d).scroll_x = (y - x) & ~0xF; |
796 WP(w, smallmap_d).scroll_x = (y - x) & ~0xF; |
797 WP(w, smallmap_d).scroll_y = (x + y) & ~0xF; |
797 WP(w, smallmap_d).scroll_y = (x + y) & ~0xF; |
798 w->SetDirty(); |
798 w->SetDirty(); |
799 } |
799 } |
800 |
800 |
801 static void SmallMapWindowProc(Window *w, WindowEvent *e) |
801 static void SmallMapWindowProc(BaseWindow *w, WindowEvent *e) |
802 { |
802 { |
803 switch (e->event) { |
803 switch (e->event) { |
804 case WE_PAINT: { |
804 case WE_PAINT: { |
805 const uint16 *tbl; |
805 const uint16 *tbl; |
806 int x, y, y_org; |
806 int x, y, y_org; |
976 SmallMapWindowProc |
976 SmallMapWindowProc |
977 }; |
977 }; |
978 |
978 |
979 void ShowSmallMap(void) |
979 void ShowSmallMap(void) |
980 { |
980 { |
981 Window *w; |
981 BaseWindow *w; |
982 |
982 |
983 w = AllocateWindowDescFront(&_smallmap_desc, 0); |
983 w = BaseWindow::AllocateFront(&_smallmap_desc, 0); |
984 if (w == NULL) return; |
984 if (w == NULL) return; |
985 |
985 |
986 w->LowerWidget(_smallmap_type + 5); |
986 w->LowerWidget(_smallmap_type + 5); |
987 w->SetWidgetLoweredState(12, _smallmap_show_towns); |
987 w->SetWidgetLoweredState(12, _smallmap_show_towns); |
988 w->resize.width = 350; |
988 w->resize.width = 350; |
989 w->resize.height = 250; |
989 w->resize.height = 250; |
990 |
990 |
991 SmallMapCenterOnCurrentPos(w); |
991 SmallMapCenterOnCurrentPos(w); |
992 } |
992 } |
993 |
993 |
994 /* Extra ViewPort Window Stuff */ |
994 /* Extra ViewPort BaseWindow Stuff */ |
995 static const Widget _extra_view_port_widgets[] = { |
995 static const OldWidget _extra_view_port_widgets[] = { |
996 { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
996 { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
997 { WWT_CAPTION, RESIZE_RIGHT, 14, 11, 287, 0, 13, STR_EXTRA_VIEW_PORT_TITLE, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
997 { WWT_CAPTION, RESIZE_RIGHT, 14, 11, 287, 0, 13, STR_EXTRA_VIEW_PORT_TITLE, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
998 { WWT_STICKYBOX, RESIZE_LR, 14, 288, 299, 0, 13, 0x0, STR_STICKY_BUTTON}, |
998 { WWT_STICKYBOX, RESIZE_LR, 14, 288, 299, 0, 13, 0x0, STR_STICKY_BUTTON}, |
999 { WWT_PANEL, RESIZE_RB, 14, 0, 299, 14, 233, 0x0, STR_NULL}, |
999 { WWT_PANEL, RESIZE_RB, 14, 0, 299, 14, 233, 0x0, STR_NULL}, |
1000 { WWT_INSET, RESIZE_RB, 14, 2, 297, 16, 231, 0x0, STR_NULL}, |
1000 { WWT_INSET, RESIZE_RB, 14, 2, 297, 16, 231, 0x0, STR_NULL}, |
1006 { WWT_PANEL, RESIZE_RTB, 14, 0, 287, 256, 267, 0x0, STR_NULL}, |
1006 { WWT_PANEL, RESIZE_RTB, 14, 0, 287, 256, 267, 0x0, STR_NULL}, |
1007 { WWT_RESIZEBOX, RESIZE_LRTB, 14, 288, 299, 256, 267, 0x0, STR_RESIZE_BUTTON}, |
1007 { WWT_RESIZEBOX, RESIZE_LRTB, 14, 288, 299, 256, 267, 0x0, STR_RESIZE_BUTTON}, |
1008 { WIDGETS_END}, |
1008 { WIDGETS_END}, |
1009 }; |
1009 }; |
1010 |
1010 |
1011 static void ExtraViewPortWndProc(Window *w, WindowEvent *e) |
1011 static void ExtraViewPortWndProc(BaseWindow *w, WindowEvent *e) |
1012 { |
1012 { |
1013 switch (e->event) { |
1013 switch (e->event) { |
1014 case WE_CREATE: /* Disable zoom in button */ |
1014 case WE_CREATE: /* Disable zoom in button */ |
1015 w->DisableWidget(5); |
1015 w->DisableWidget(5); |
1016 break; |
1016 break; |
1027 switch (e->we.click.widget) { |
1027 switch (e->we.click.widget) { |
1028 case 5: DoZoomInOutWindow(ZOOM_IN, w); break; |
1028 case 5: DoZoomInOutWindow(ZOOM_IN, w); break; |
1029 case 6: DoZoomInOutWindow(ZOOM_OUT, w); break; |
1029 case 6: DoZoomInOutWindow(ZOOM_OUT, w); break; |
1030 |
1030 |
1031 case 7: { /* location button (move main view to same spot as this view) 'Paste Location' */ |
1031 case 7: { /* location button (move main view to same spot as this view) 'Paste Location' */ |
1032 Window *w2 = Window::FindById(WC_MAIN_WINDOW, 0); |
1032 BaseWindow *w2 = BaseWindow::FindById(WC_MAIN_WINDOW, 0); |
1033 int x = WP(w, vp_d).scrollpos_x; // Where is the main looking at |
1033 int x = WP(w, vp_d).scrollpos_x; // Where is the main looking at |
1034 int y = WP(w, vp_d).scrollpos_y; |
1034 int y = WP(w, vp_d).scrollpos_y; |
1035 |
1035 |
1036 // set this view to same location. Based on the center, adjusting for zoom |
1036 // set this view to same location. Based on the center, adjusting for zoom |
1037 WP(w2, vp_d).scrollpos_x = x - (w2->viewport->virtual_width - w->viewport->virtual_width) / 2; |
1037 WP(w2, vp_d).scrollpos_x = x - (w2->viewport->virtual_width - w->viewport->virtual_width) / 2; |
1038 WP(w2, vp_d).scrollpos_y = y - (w2->viewport->virtual_height - w->viewport->virtual_height) / 2; |
1038 WP(w2, vp_d).scrollpos_y = y - (w2->viewport->virtual_height - w->viewport->virtual_height) / 2; |
1039 } break; |
1039 } break; |
1040 |
1040 |
1041 case 8: { /* inverse location button (move this view to same spot as main view) 'Copy Location' */ |
1041 case 8: { /* inverse location button (move this view to same spot as main view) 'Copy Location' */ |
1042 const Window *w2 = Window::FindById(WC_MAIN_WINDOW, 0); |
1042 const BaseWindow *w2 = BaseWindow::FindById(WC_MAIN_WINDOW, 0); |
1043 int x = WP(w2, const vp_d).scrollpos_x; |
1043 int x = WP(w2, const vp_d).scrollpos_x; |
1044 int y = WP(w2, const vp_d).scrollpos_y; |
1044 int y = WP(w2, const vp_d).scrollpos_y; |
1045 |
1045 |
1046 WP(w, vp_d).scrollpos_x = x + (w2->viewport->virtual_width - w->viewport->virtual_width) / 2; |
1046 WP(w, vp_d).scrollpos_x = x + (w2->viewport->virtual_width - w->viewport->virtual_width) / 2; |
1047 WP(w, vp_d).scrollpos_y = y + (w2->viewport->virtual_height - w->viewport->virtual_height) / 2; |
1047 WP(w, vp_d).scrollpos_y = y + (w2->viewport->virtual_height - w->viewport->virtual_height) / 2; |
1089 ExtraViewPortWndProc |
1089 ExtraViewPortWndProc |
1090 }; |
1090 }; |
1091 |
1091 |
1092 void ShowExtraViewPortWindow(void) |
1092 void ShowExtraViewPortWindow(void) |
1093 { |
1093 { |
1094 Window *w, *v; |
1094 BaseWindow *w, *v; |
1095 int i = 0; |
1095 int i = 0; |
1096 |
1096 |
1097 // find next free window number for extra viewport |
1097 // find next free window number for extra viewport |
1098 while (Window::FindById(WC_EXTRA_VIEW_PORT, i) != NULL) i++; |
1098 while (BaseWindow::FindById(WC_EXTRA_VIEW_PORT, i) != NULL) i++; |
1099 |
1099 |
1100 w = AllocateWindowDescFront(&_extra_view_port_desc, i); |
1100 w = BaseWindow::AllocateFront(&_extra_view_port_desc, i); |
1101 if (w != NULL) { |
1101 if (w != NULL) { |
1102 int x, y; |
1102 int x, y; |
1103 // the main window with the main view |
1103 // the main window with the main view |
1104 v = Window::FindById(WC_MAIN_WINDOW, 0); |
1104 v = BaseWindow::FindById(WC_MAIN_WINDOW, 0); |
1105 // New viewport start ats (zero,zero) |
1105 // New viewport start ats (zero,zero) |
1106 AssignWindowViewport(w, 3, 17, 294, 214, 0 , 0); |
1106 AssignWindowViewport(w, 3, 17, 294, 214, 0 , 0); |
1107 |
1107 |
1108 // center on same place as main window (zoom is maximum, no adjustment needed) |
1108 // center on same place as main window (zoom is maximum, no adjustment needed) |
1109 x = WP(v, vp_d).scrollpos_x; |
1109 x = WP(v, vp_d).scrollpos_x; |