804 } |
804 } |
805 |
805 |
806 static void SmallMapWindowProc(Window *w, WindowEvent *e) |
806 static void SmallMapWindowProc(Window *w, WindowEvent *e) |
807 { |
807 { |
808 switch (e->event) { |
808 switch (e->event) { |
809 case WE_PAINT: { |
809 case WE_PAINT: { |
810 const uint16 *tbl; |
810 const uint16 *tbl; |
811 int x,y,y_org; |
811 int x, y, y_org; |
812 DrawPixelInfo new_dpi; |
812 DrawPixelInfo new_dpi; |
813 |
813 |
814 /* draw the window */ |
814 /* draw the window */ |
815 SetDParam(0, STR_00E5_CONTOURS + _smallmap_type); |
815 SetDParam(0, STR_00E5_CONTOURS + _smallmap_type); |
816 DrawWindowWidgets(w); |
816 DrawWindowWidgets(w); |
817 |
817 |
818 /* draw the legend */ |
818 /* draw the legend */ |
819 tbl = _legend_table[(_smallmap_type != 2) ? _smallmap_type : (_opt.landscape + IND_OFFS)]; |
819 tbl = _legend_table[(_smallmap_type != 2) ? _smallmap_type : (_opt.landscape + IND_OFFS)]; |
820 x = 4; |
820 x = 4; |
821 y_org = w->height - 44 - 11; |
821 y_org = w->height - 44 - 11; |
822 y = y_org; |
822 y = y_org; |
823 for (;;) { |
823 for (;;) { |
824 GfxFillRect(x, y + 1, x + 8, y + 5, 0); |
824 GfxFillRect(x, y + 1, x + 8, y + 5, 0); |
825 GfxFillRect(x + 1, y + 2, x + 7, y + 4, (byte)tbl[0]); |
825 GfxFillRect(x + 1, y + 2, x + 7, y + 4, (byte)tbl[0]); |
826 DrawString(x + 11, y, tbl[1], 0); |
826 DrawString(x + 11, y, tbl[1], 0); |
827 |
827 |
828 tbl += 2; |
828 tbl += 2; |
829 y += 6; |
829 y += 6; |
830 |
830 |
831 if (tbl[0] == 0xFFFF) { |
831 if (tbl[0] == 0xFFFF) { |
832 break; |
832 break; |
833 } else if (tbl[0] & 0x100) { |
833 } else if (tbl[0] & 0x100) { |
834 x += 123; |
834 x += 123; |
835 y = y_org; |
835 y = y_org; |
836 } |
836 } |
837 } |
837 } |
838 |
838 |
839 if (!FillDrawPixelInfo(&new_dpi, 3, 17, w->width - 28 + 22, w->height - 64 - 11)) |
839 if (!FillDrawPixelInfo(&new_dpi, 3, 17, w->width - 28 + 22, w->height - 64 - 11)) |
840 return; |
840 return; |
841 |
841 |
842 DrawSmallMap(&new_dpi, w, _smallmap_type, _smallmap_show_towns); |
842 DrawSmallMap(&new_dpi, w, _smallmap_type, _smallmap_show_towns); |
843 } break; |
|
844 |
|
845 case WE_CLICK: |
|
846 switch (e->click.widget) { |
|
847 case 4: { // Map window |
|
848 Window *w2 = FindWindowById(WC_MAIN_WINDOW, 0); |
|
849 Point pt; |
|
850 int x, y; |
|
851 |
|
852 pt = RemapCoords(WP(w,smallmap_d).scroll_x, WP(w,smallmap_d).scroll_y, 0); |
|
853 x = pt.x + ((_cursor.pos.x - w->left + 2) << 4) - (w2->viewport->virtual_width >> 1); |
|
854 y = pt.y + ((_cursor.pos.y - w->top - 16) << 4) - (w2->viewport->virtual_height >> 1); |
|
855 |
|
856 /* If you press twice on a place in the smallmap, center there */ |
|
857 if (WP(w2, vp_d).scrollpos_x == x && WP(w2, vp_d).scrollpos_y == y) { |
|
858 SmallMapCenterOnCurrentPos(w); |
|
859 } else { |
|
860 WP(w2, vp_d).scrollpos_x = x; |
|
861 WP(w2, vp_d).scrollpos_y = y; |
|
862 } |
|
863 |
|
864 SetWindowDirty(w); |
|
865 } break; |
843 } break; |
866 |
844 |
867 case 5: // Show land contours |
845 case WE_CLICK: |
868 case 6: // Show vehicles |
846 switch (e->click.widget) { |
869 case 7: // Show industries |
847 case 4: { // Map window |
870 case 8: // Show transport routes |
848 Window *w2 = FindWindowById(WC_MAIN_WINDOW, 0); |
871 case 9: // Show vegetation |
849 Point pt; |
872 case 10: // Show land owners |
850 int x, y; |
873 w->click_state &= ~(1<<5|1<<6|1<<7|1<<8|1<<9|1<<10); |
851 |
874 w->click_state |= 1 << e->click.widget; |
852 pt = RemapCoords(WP(w,smallmap_d).scroll_x, WP(w,smallmap_d).scroll_y, 0); |
875 _smallmap_type = e->click.widget - 5; |
853 x = pt.x + ((_cursor.pos.x - w->left + 2) << 4) - (w2->viewport->virtual_width >> 1); |
876 |
854 y = pt.y + ((_cursor.pos.y - w->top - 16) << 4) - (w2->viewport->virtual_height >> 1); |
877 SetWindowDirty(w); |
855 |
878 SndPlayFx(SND_15_BEEP); |
856 /* If you press twice on a place in the smallmap, center there */ |
|
857 if (WP(w2, vp_d).scrollpos_x == x && WP(w2, vp_d).scrollpos_y == y) { |
|
858 SmallMapCenterOnCurrentPos(w); |
|
859 } else { |
|
860 WP(w2, vp_d).scrollpos_x = x; |
|
861 WP(w2, vp_d).scrollpos_y = y; |
|
862 } |
|
863 |
|
864 SetWindowDirty(w); |
|
865 } break; |
|
866 |
|
867 case 5: // Show land contours |
|
868 case 6: // Show vehicles |
|
869 case 7: // Show industries |
|
870 case 8: // Show transport routes |
|
871 case 9: // Show vegetation |
|
872 case 10: // Show land owners |
|
873 w->click_state &= ~( 1 << 5 | 1 << 6 | 1 << 7 | 1 << 8 | 1 << 9 | 1 << 10); |
|
874 w->click_state |= 1 << e->click.widget; |
|
875 _smallmap_type = e->click.widget - 5; |
|
876 |
|
877 SetWindowDirty(w); |
|
878 SndPlayFx(SND_15_BEEP); |
|
879 break; |
|
880 |
|
881 case 11: // Center the smallmap again |
|
882 SmallMapCenterOnCurrentPos(w); |
|
883 |
|
884 SetWindowDirty(w); |
|
885 SndPlayFx(SND_15_BEEP); |
|
886 break; |
|
887 |
|
888 case 12: // Toggle town names |
|
889 w->click_state ^= (1 << 12); |
|
890 _smallmap_show_towns = (w->click_state >> 12) & 1; |
|
891 |
|
892 SetWindowDirty(w); |
|
893 SndPlayFx(SND_15_BEEP); |
|
894 break; |
|
895 } |
879 break; |
896 break; |
880 |
897 |
881 case 11: // Center the smallmap again |
898 case WE_RCLICK: |
882 SmallMapCenterOnCurrentPos(w); |
899 if (e->click.widget == 4) { |
883 |
900 if (_scrolling_viewport) return; |
884 SetWindowDirty(w); |
901 _scrolling_viewport = true; |
885 SndPlayFx(SND_15_BEEP); |
902 _cursor.delta.x = 0; |
|
903 _cursor.delta.y = 0; |
|
904 } |
886 break; |
905 break; |
887 |
906 |
888 case 12: // Toggle town names |
907 case WE_MOUSELOOP: |
889 w->click_state ^= (1 << 12); |
908 /* update the window every now and then */ |
890 _smallmap_show_towns = (w->click_state >> 12) & 1; |
909 if ((++w->vscroll.pos & 0x1F) == 0) SetWindowDirty(w); |
891 |
|
892 SetWindowDirty(w); |
|
893 SndPlayFx(SND_15_BEEP); |
|
894 break; |
910 break; |
895 } |
|
896 break; |
|
897 |
|
898 case WE_RCLICK: |
|
899 if (e->click.widget == 4) { |
|
900 if (_scrolling_viewport) return; |
|
901 _scrolling_viewport = true; |
|
902 _cursor.delta.x = 0; |
|
903 _cursor.delta.y = 0; |
|
904 } |
|
905 break; |
|
906 |
|
907 case WE_MOUSELOOP: |
|
908 /* update the window every now and then */ |
|
909 if ((++w->vscroll.pos & 0x1F) == 0) SetWindowDirty(w); |
|
910 break; |
|
911 |
911 |
912 case WE_SCROLL: { |
912 case WE_SCROLL: { |
913 int x; |
913 int x; |
914 int y; |
914 int y; |
915 int sub; |
915 int sub; |