src/smallmap_gui.cpp
branchcpp_gui
changeset 6235 5077e6ed3788
parent 6206 67358999d80d
child 6241 6a7a41b0cd32
equal deleted inserted replaced
6234:42bf2d268a86 6235:5077e6ed3788
   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 = FindWindowById(WC_MAIN_WINDOW,0)->viewport;
   765 		vp = Window::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;
   787 
   787 
   788 void SmallMapCenterOnCurrentPos(Window *w)
   788 void SmallMapCenterOnCurrentPos(Window *w)
   789 {
   789 {
   790 	int x, y;
   790 	int x, y;
   791 	ViewPort *vp;
   791 	ViewPort *vp;
   792 	vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport;
   792 	vp = Window::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 	SetWindowDirty(w);
   798 	w->SetDirty();
   799 }
   799 }
   800 
   800 
   801 static void SmallMapWindowProc(Window *w, WindowEvent *e)
   801 static void SmallMapWindowProc(Window *w, WindowEvent *e)
   802 {
   802 {
   803 	switch (e->event) {
   803 	switch (e->event) {
   838 		} break;
   838 		} break;
   839 
   839 
   840 		case WE_CLICK:
   840 		case WE_CLICK:
   841 			switch (e->we.click.widget) {
   841 			switch (e->we.click.widget) {
   842 				case 4: { // Map window
   842 				case 4: { // Map window
   843 					Window *w2 = FindWindowById(WC_MAIN_WINDOW, 0);
   843 					Window *w2 = Window::FindById(WC_MAIN_WINDOW, 0);
   844 					Point pt;
   844 					Point pt;
   845 
   845 
   846 					/*
   846 					/*
   847 					 * XXX: scrolling with the left mouse button is done by subsequently
   847 					 * XXX: scrolling with the left mouse button is done by subsequently
   848 					 * clicking with the left mouse button; clicking once centers the
   848 					 * clicking with the left mouse button; clicking once centers the
   855 
   855 
   856 					pt = RemapCoords(WP(w,smallmap_d).scroll_x, WP(w,smallmap_d).scroll_y, 0);
   856 					pt = RemapCoords(WP(w,smallmap_d).scroll_x, WP(w,smallmap_d).scroll_y, 0);
   857 					WP(w2, vp_d).scrollpos_x = pt.x + ((_cursor.pos.x - w->left + 2) << 4) - (w2->viewport->virtual_width >> 1);
   857 					WP(w2, vp_d).scrollpos_x = pt.x + ((_cursor.pos.x - w->left + 2) << 4) - (w2->viewport->virtual_width >> 1);
   858 					WP(w2, vp_d).scrollpos_y = pt.y + ((_cursor.pos.y - w->top - 16) << 4) - (w2->viewport->virtual_height >> 1);
   858 					WP(w2, vp_d).scrollpos_y = pt.y + ((_cursor.pos.y - w->top - 16) << 4) - (w2->viewport->virtual_height >> 1);
   859 
   859 
   860 					SetWindowDirty(w);
   860 					w->SetDirty();
   861 				} break;
   861 				} break;
   862 
   862 
   863 				case 5:  // Show land contours
   863 				case 5:  // Show land contours
   864 				case 6:  // Show vehicles
   864 				case 6:  // Show vehicles
   865 				case 7:  // Show industries
   865 				case 7:  // Show industries
   868 				case 10: // Show land owners
   868 				case 10: // Show land owners
   869 					RaiseWindowWidget(w, _smallmap_type + 5);
   869 					RaiseWindowWidget(w, _smallmap_type + 5);
   870 					_smallmap_type = e->we.click.widget - 5;
   870 					_smallmap_type = e->we.click.widget - 5;
   871 					LowerWindowWidget(w, _smallmap_type + 5);
   871 					LowerWindowWidget(w, _smallmap_type + 5);
   872 
   872 
   873 					SetWindowDirty(w);
   873 					w->SetDirty();
   874 					SndPlayFx(SND_15_BEEP);
   874 					SndPlayFx(SND_15_BEEP);
   875 					break;
   875 					break;
   876 
   876 
   877 				case 11: // Center the smallmap again
   877 				case 11: // Center the smallmap again
   878 					SmallMapCenterOnCurrentPos(w);
   878 					SmallMapCenterOnCurrentPos(w);
   879 
   879 
   880 					SetWindowDirty(w);
   880 					w->SetDirty();
   881 					SndPlayFx(SND_15_BEEP);
   881 					SndPlayFx(SND_15_BEEP);
   882 					break;
   882 					break;
   883 
   883 
   884 				case 12: // Toggle town names
   884 				case 12: // Toggle town names
   885 					ToggleWidgetLoweredState(w, 12);
   885 					ToggleWidgetLoweredState(w, 12);
   886 					_smallmap_show_towns = IsWindowWidgetLowered(w, 12);
   886 					_smallmap_show_towns = IsWindowWidgetLowered(w, 12);
   887 
   887 
   888 					SetWindowDirty(w);
   888 					w->SetDirty();
   889 					SndPlayFx(SND_15_BEEP);
   889 					SndPlayFx(SND_15_BEEP);
   890 					break;
   890 					break;
   891 				}
   891 				}
   892 			break;
   892 			break;
   893 
   893 
   900 			}
   900 			}
   901 			break;
   901 			break;
   902 
   902 
   903 		case WE_MOUSELOOP:
   903 		case WE_MOUSELOOP:
   904 			/* update the window every now and then */
   904 			/* update the window every now and then */
   905 			if ((++w->vscroll.pos & 0x1F) == 0) SetWindowDirty(w);
   905 			if ((++w->vscroll.pos & 0x1F) == 0) w->SetDirty();
   906 			break;
   906 			break;
   907 
   907 
   908 		case WE_SCROLL: {
   908 		case WE_SCROLL: {
   909 			int x;
   909 			int x;
   910 			int y;
   910 			int y;
   961 
   961 
   962 			WP(w, smallmap_d).scroll_x = x;
   962 			WP(w, smallmap_d).scroll_x = x;
   963 			WP(w, smallmap_d).scroll_y = y;
   963 			WP(w, smallmap_d).scroll_y = y;
   964 			WP(w, smallmap_d).subscroll = sub;
   964 			WP(w, smallmap_d).subscroll = sub;
   965 
   965 
   966 			SetWindowDirty(w);
   966 			w->SetDirty();
   967 		} break;
   967 		} break;
   968 	}
   968 	}
   969 }
   969 }
   970 
   970 
   971 static const WindowDesc _smallmap_desc = {
   971 static const WindowDesc _smallmap_desc = {
  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 = FindWindowById(WC_MAIN_WINDOW, 0);
  1032 			Window *w2 = Window::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 = FindWindowById(WC_MAIN_WINDOW, 0);
  1042 			const Window *w2 = Window::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;
  1093 {
  1093 {
  1094 	Window *w, *v;
  1094 	Window *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 (FindWindowById(WC_EXTRA_VIEW_PORT, i) != NULL) i++;
  1098 	while (Window::FindById(WC_EXTRA_VIEW_PORT, i) != NULL) i++;
  1099 
  1099 
  1100 	w = AllocateWindowDescFront(&_extra_view_port_desc, i);
  1100 	w = AllocateWindowDescFront(&_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 = FindWindowById(WC_MAIN_WINDOW, 0);
  1104 		v = Window::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;