diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2024-05-19 12:24:00 -0400 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2024-05-19 12:24:00 -0400 |
commit | 983f01cb8a2eaecd162e5734de88c461ef197b34 (patch) | |
tree | 86f8987f63a1ab5ffa613104dae3d8cd10f3239f /src | |
parent | eaa21c53b96b945d8809dc5f4a9353ecaaacc266 (diff) | |
download | lingo-ap-tracker-983f01cb8a2eaecd162e5734de88c461ef197b34.tar.gz lingo-ap-tracker-983f01cb8a2eaecd162e5734de88c461ef197b34.tar.bz2 lingo-ap-tracker-983f01cb8a2eaecd162e5734de88c461ef197b34.zip |
Zoom in/out menu items with keyboard shortcuts
Diffstat (limited to 'src')
-rw-r--r-- | src/subway_map.cpp | 30 | ||||
-rw-r--r-- | src/subway_map.h | 3 | ||||
-rw-r--r-- | src/tracker_frame.cpp | 45 | ||||
-rw-r--r-- | src/tracker_frame.h | 9 |
4 files changed, 78 insertions, 9 deletions
diff --git a/src/subway_map.cpp b/src/subway_map.cpp index 98d544c..69bf51b 100644 --- a/src/subway_map.cpp +++ b/src/subway_map.cpp | |||
@@ -119,6 +119,26 @@ void SubwayMap::UpdateSunwarp(SubwaySunwarp from_sunwarp, | |||
119 | GD_GetSubwayItemForSunwarp(to_sunwarp)); | 119 | GD_GetSubwayItemForSunwarp(to_sunwarp)); |
120 | } | 120 | } |
121 | 121 | ||
122 | void SubwayMap::Zoom(bool in) { | ||
123 | wxPoint focus_point; | ||
124 | |||
125 | if (mouse_position_) { | ||
126 | focus_point = *mouse_position_; | ||
127 | } else { | ||
128 | focus_point = {GetSize().GetWidth() / 2, GetSize().GetHeight() / 2}; | ||
129 | } | ||
130 | |||
131 | if (in) { | ||
132 | if (zoom_ < 3.0) { | ||
133 | SetZoom(zoom_ + 0.25, focus_point); | ||
134 | } | ||
135 | } else { | ||
136 | if (zoom_ > 1.0) { | ||
137 | SetZoom(zoom_ - 0.25, focus_point); | ||
138 | } | ||
139 | } | ||
140 | } | ||
141 | |||
122 | void SubwayMap::OnPaint(wxPaintEvent &event) { | 142 | void SubwayMap::OnPaint(wxPaintEvent &event) { |
123 | if (GetSize() != rendered_.GetSize()) { | 143 | if (GetSize() != rendered_.GetSize()) { |
124 | wxSize panel_size = GetSize(); | 144 | wxSize panel_size = GetSize(); |
@@ -372,6 +392,8 @@ void SubwayMap::OnMouseMove(wxMouseEvent &event) { | |||
372 | 392 | ||
373 | SetScrollSpeed(scroll_x, scroll_y); | 393 | SetScrollSpeed(scroll_x, scroll_y); |
374 | 394 | ||
395 | mouse_position_ = event.GetPosition(); | ||
396 | |||
375 | event.Skip(); | 397 | event.Skip(); |
376 | } | 398 | } |
377 | 399 | ||
@@ -390,7 +412,10 @@ void SubwayMap::OnMouseScroll(wxMouseEvent &event) { | |||
390 | event.Skip(); | 412 | event.Skip(); |
391 | } | 413 | } |
392 | 414 | ||
393 | void SubwayMap::OnMouseLeave(wxMouseEvent &event) { SetScrollSpeed(0, 0); } | 415 | void SubwayMap::OnMouseLeave(wxMouseEvent &event) { |
416 | SetScrollSpeed(0, 0); | ||
417 | mouse_position_ = std::nullopt; | ||
418 | } | ||
394 | 419 | ||
395 | void SubwayMap::OnTimer(wxTimerEvent &event) { | 420 | void SubwayMap::OnTimer(wxTimerEvent &event) { |
396 | SetZoomPos({zoom_x_ + scroll_x_, zoom_y_ + scroll_y_}); | 421 | SetZoomPos({zoom_x_ + scroll_x_, zoom_y_ + scroll_y_}); |
@@ -464,7 +489,8 @@ void SubwayMap::Redraw() { | |||
464 | 489 | ||
465 | wxPoint real_area_pos = {subway_item.x, subway_item.y}; | 490 | wxPoint real_area_pos = {subway_item.x, subway_item.y}; |
466 | 491 | ||
467 | int real_area_size = (draw_type == ItemDrawType::kOwl ? OWL_ACTUAL_SIZE : AREA_ACTUAL_SIZE); | 492 | int real_area_size = |
493 | (draw_type == ItemDrawType::kOwl ? OWL_ACTUAL_SIZE : AREA_ACTUAL_SIZE); | ||
468 | 494 | ||
469 | if (draw_type == ItemDrawType::kBox) { | 495 | if (draw_type == ItemDrawType::kBox) { |
470 | dc.SetPen(*wxThePenList->FindOrCreatePen(*wxBLACK, 1)); | 496 | dc.SetPen(*wxThePenList->FindOrCreatePen(*wxBLACK, 1)); |
diff --git a/src/subway_map.h b/src/subway_map.h index e891058..986998a 100644 --- a/src/subway_map.h +++ b/src/subway_map.h | |||
@@ -25,6 +25,7 @@ class SubwayMap : public wxPanel { | |||
25 | void OnConnect(); | 25 | void OnConnect(); |
26 | void UpdateIndicators(); | 26 | void UpdateIndicators(); |
27 | void UpdateSunwarp(SubwaySunwarp from_sunwarp, SubwaySunwarp to_sunwarp); | 27 | void UpdateSunwarp(SubwaySunwarp from_sunwarp, SubwaySunwarp to_sunwarp); |
28 | void Zoom(bool in); | ||
28 | 29 | ||
29 | private: | 30 | private: |
30 | void OnPaint(wxPaintEvent &event); | 31 | void OnPaint(wxPaintEvent &event); |
@@ -65,6 +66,8 @@ class SubwayMap : public wxPanel { | |||
65 | 66 | ||
66 | wxSlider *zoom_slider_; | 67 | wxSlider *zoom_slider_; |
67 | 68 | ||
69 | std::optional<wxPoint> mouse_position_; | ||
70 | |||
68 | struct GetItemBox { | 71 | struct GetItemBox { |
69 | quadtree::Box<float> operator()(const int &id) const; | 72 | quadtree::Box<float> operator()(const int &id) const; |
70 | }; | 73 | }; |
diff --git a/src/tracker_frame.cpp b/src/tracker_frame.cpp index e944704..a15a6b4 100644 --- a/src/tracker_frame.cpp +++ b/src/tracker_frame.cpp | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | #include <wx/aboutdlg.h> | 3 | #include <wx/aboutdlg.h> |
4 | #include <wx/choicebk.h> | 4 | #include <wx/choicebk.h> |
5 | #include <wx/notebook.h> | ||
5 | #include <wx/webrequest.h> | 6 | #include <wx/webrequest.h> |
6 | 7 | ||
7 | #include <nlohmann/json.hpp> | 8 | #include <nlohmann/json.hpp> |
@@ -19,7 +20,9 @@ | |||
19 | enum TrackerFrameIds { | 20 | enum TrackerFrameIds { |
20 | ID_CONNECT = 1, | 21 | ID_CONNECT = 1, |
21 | ID_CHECK_FOR_UPDATES = 2, | 22 | ID_CHECK_FOR_UPDATES = 2, |
22 | ID_SETTINGS = 3 | 23 | ID_SETTINGS = 3, |
24 | ID_ZOOM_IN = 4, | ||
25 | ID_ZOOM_OUT = 5, | ||
23 | }; | 26 | }; |
24 | 27 | ||
25 | wxDEFINE_EVENT(STATE_RESET, wxCommandEvent); | 28 | wxDEFINE_EVENT(STATE_RESET, wxCommandEvent); |
@@ -38,12 +41,20 @@ TrackerFrame::TrackerFrame() | |||
38 | menuFile->Append(ID_SETTINGS, "&Settings"); | 41 | menuFile->Append(ID_SETTINGS, "&Settings"); |
39 | menuFile->Append(wxID_EXIT); | 42 | menuFile->Append(wxID_EXIT); |
40 | 43 | ||
44 | wxMenu *menuView = new wxMenu(); | ||
45 | zoom_in_menu_item_ = menuView->Append(ID_ZOOM_IN, "Zoom In\tCtrl-+"); | ||
46 | zoom_out_menu_item_ = menuView->Append(ID_ZOOM_OUT, "Zoom Out\tCtrl--"); | ||
47 | |||
48 | zoom_in_menu_item_->Enable(false); | ||
49 | zoom_out_menu_item_->Enable(false); | ||
50 | |||
41 | wxMenu *menuHelp = new wxMenu(); | 51 | wxMenu *menuHelp = new wxMenu(); |
42 | menuHelp->Append(wxID_ABOUT); | 52 | menuHelp->Append(wxID_ABOUT); |
43 | menuHelp->Append(ID_CHECK_FOR_UPDATES, "Check for Updates"); | 53 | menuHelp->Append(ID_CHECK_FOR_UPDATES, "Check for Updates"); |
44 | 54 | ||
45 | wxMenuBar *menuBar = new wxMenuBar(); | 55 | wxMenuBar *menuBar = new wxMenuBar(); |
46 | menuBar->Append(menuFile, "&File"); | 56 | menuBar->Append(menuFile, "&File"); |
57 | menuBar->Append(menuView, "&View"); | ||
47 | menuBar->Append(menuHelp, "&Help"); | 58 | menuBar->Append(menuHelp, "&Help"); |
48 | 59 | ||
49 | SetMenuBar(menuBar); | 60 | SetMenuBar(menuBar); |
@@ -57,6 +68,9 @@ TrackerFrame::TrackerFrame() | |||
57 | Bind(wxEVT_MENU, &TrackerFrame::OnSettings, this, ID_SETTINGS); | 68 | Bind(wxEVT_MENU, &TrackerFrame::OnSettings, this, ID_SETTINGS); |
58 | Bind(wxEVT_MENU, &TrackerFrame::OnCheckForUpdates, this, | 69 | Bind(wxEVT_MENU, &TrackerFrame::OnCheckForUpdates, this, |
59 | ID_CHECK_FOR_UPDATES); | 70 | ID_CHECK_FOR_UPDATES); |
71 | Bind(wxEVT_MENU, &TrackerFrame::OnZoomIn, this, ID_ZOOM_IN); | ||
72 | Bind(wxEVT_MENU, &TrackerFrame::OnZoomOut, this, ID_ZOOM_OUT); | ||
73 | Bind(wxEVT_NOTEBOOK_PAGE_CHANGED, &TrackerFrame::OnChangePage, this); | ||
60 | Bind(STATE_RESET, &TrackerFrame::OnStateReset, this); | 74 | Bind(STATE_RESET, &TrackerFrame::OnStateReset, this); |
61 | Bind(STATE_CHANGED, &TrackerFrame::OnStateChanged, this); | 75 | Bind(STATE_CHANGED, &TrackerFrame::OnStateChanged, this); |
62 | Bind(STATUS_CHANGED, &TrackerFrame::OnStatusChanged, this); | 76 | Bind(STATUS_CHANGED, &TrackerFrame::OnStatusChanged, this); |
@@ -66,15 +80,15 @@ TrackerFrame::TrackerFrame() | |||
66 | wxChoicebook *choicebook = new wxChoicebook(this, wxID_ANY); | 80 | wxChoicebook *choicebook = new wxChoicebook(this, wxID_ANY); |
67 | choicebook->AddPage(achievements_pane_, "Achievements"); | 81 | choicebook->AddPage(achievements_pane_, "Achievements"); |
68 | 82 | ||
69 | wxNotebook *rightpane = new wxNotebook(this, wxID_ANY); | 83 | notebook_ = new wxNotebook(this, wxID_ANY); |
70 | tracker_panel_ = new TrackerPanel(rightpane); | 84 | tracker_panel_ = new TrackerPanel(notebook_); |
71 | subway_map_ = new SubwayMap(rightpane); | 85 | subway_map_ = new SubwayMap(notebook_); |
72 | rightpane->AddPage(tracker_panel_, "Map"); | 86 | notebook_->AddPage(tracker_panel_, "Map"); |
73 | rightpane->AddPage(subway_map_, "Subway"); | 87 | notebook_->AddPage(subway_map_, "Subway"); |
74 | 88 | ||
75 | wxBoxSizer *top_sizer = new wxBoxSizer(wxHORIZONTAL); | 89 | wxBoxSizer *top_sizer = new wxBoxSizer(wxHORIZONTAL); |
76 | top_sizer->Add(choicebook, wxSizerFlags().Expand().Proportion(1)); | 90 | top_sizer->Add(choicebook, wxSizerFlags().Expand().Proportion(1)); |
77 | top_sizer->Add(rightpane, wxSizerFlags().Expand().Proportion(3)); | 91 | top_sizer->Add(notebook_, wxSizerFlags().Expand().Proportion(3)); |
78 | 92 | ||
79 | SetSizerAndFit(top_sizer); | 93 | SetSizerAndFit(top_sizer); |
80 | SetSize(1280, 728); | 94 | SetSize(1280, 728); |
@@ -174,6 +188,23 @@ void TrackerFrame::OnCheckForUpdates(wxCommandEvent &event) { | |||
174 | CheckForUpdates(/*manual=*/true); | 188 | CheckForUpdates(/*manual=*/true); |
175 | } | 189 | } |
176 | 190 | ||
191 | void TrackerFrame::OnZoomIn(wxCommandEvent &event) { | ||
192 | if (notebook_->GetSelection() == 1) { | ||
193 | subway_map_->Zoom(true); | ||
194 | } | ||
195 | } | ||
196 | |||
197 | void TrackerFrame::OnZoomOut(wxCommandEvent& event) { | ||
198 | if (notebook_->GetSelection() == 1) { | ||
199 | subway_map_->Zoom(false); | ||
200 | } | ||
201 | } | ||
202 | |||
203 | void TrackerFrame::OnChangePage(wxBookCtrlEvent &event) { | ||
204 | zoom_in_menu_item_->Enable(event.GetSelection() == 1); | ||
205 | zoom_out_menu_item_->Enable(event.GetSelection() == 1); | ||
206 | } | ||
207 | |||
177 | void TrackerFrame::OnStateReset(wxCommandEvent& event) { | 208 | void TrackerFrame::OnStateReset(wxCommandEvent& event) { |
178 | tracker_panel_->UpdateIndicators(); | 209 | tracker_panel_->UpdateIndicators(); |
179 | achievements_pane_->UpdateIndicators(); | 210 | achievements_pane_->UpdateIndicators(); |
diff --git a/src/tracker_frame.h b/src/tracker_frame.h index f1d7171..f7cb3f2 100644 --- a/src/tracker_frame.h +++ b/src/tracker_frame.h | |||
@@ -10,6 +10,8 @@ | |||
10 | class AchievementsPane; | 10 | class AchievementsPane; |
11 | class SubwayMap; | 11 | class SubwayMap; |
12 | class TrackerPanel; | 12 | class TrackerPanel; |
13 | class wxBookCtrlEvent; | ||
14 | class wxNotebook; | ||
13 | 15 | ||
14 | wxDECLARE_EVENT(STATE_RESET, wxCommandEvent); | 16 | wxDECLARE_EVENT(STATE_RESET, wxCommandEvent); |
15 | wxDECLARE_EVENT(STATE_CHANGED, wxCommandEvent); | 17 | wxDECLARE_EVENT(STATE_CHANGED, wxCommandEvent); |
@@ -30,6 +32,9 @@ class TrackerFrame : public wxFrame { | |||
30 | void OnConnect(wxCommandEvent &event); | 32 | void OnConnect(wxCommandEvent &event); |
31 | void OnSettings(wxCommandEvent &event); | 33 | void OnSettings(wxCommandEvent &event); |
32 | void OnCheckForUpdates(wxCommandEvent &event); | 34 | void OnCheckForUpdates(wxCommandEvent &event); |
35 | void OnZoomIn(wxCommandEvent &event); | ||
36 | void OnZoomOut(wxCommandEvent &event); | ||
37 | void OnChangePage(wxBookCtrlEvent &event); | ||
33 | 38 | ||
34 | void OnStateReset(wxCommandEvent &event); | 39 | void OnStateReset(wxCommandEvent &event); |
35 | void OnStateChanged(wxCommandEvent &event); | 40 | void OnStateChanged(wxCommandEvent &event); |
@@ -37,9 +42,13 @@ class TrackerFrame : public wxFrame { | |||
37 | 42 | ||
38 | void CheckForUpdates(bool manual); | 43 | void CheckForUpdates(bool manual); |
39 | 44 | ||
45 | wxNotebook *notebook_; | ||
40 | TrackerPanel *tracker_panel_; | 46 | TrackerPanel *tracker_panel_; |
41 | AchievementsPane *achievements_pane_; | 47 | AchievementsPane *achievements_pane_; |
42 | SubwayMap *subway_map_; | 48 | SubwayMap *subway_map_; |
49 | |||
50 | wxMenuItem *zoom_in_menu_item_; | ||
51 | wxMenuItem *zoom_out_menu_item_; | ||
43 | }; | 52 | }; |
44 | 53 | ||
45 | #endif /* end of include guard: TRACKER_FRAME_H_86BD8DFB */ | 54 | #endif /* end of include guard: TRACKER_FRAME_H_86BD8DFB */ |