From 22014b967d0d9651b72bffbe02aba75dc98180a4 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Tue, 2 May 2023 12:05:05 -0400 Subject: Show locations popup when hovering over area --- CMakeLists.txt | 1 + area_popup.cpp | 37 +++++++++++++++++++++++++++++++++++++ area_popup.h | 18 ++++++++++++++++++ area_window.cpp | 16 ++++++---------- area_window.h | 8 +++++++- tracker_frame.cpp | 2 ++ tracker_panel.cpp | 22 +++++++++++++++++++++- 7 files changed, 92 insertions(+), 12 deletions(-) create mode 100644 area_popup.cpp create mode 100644 area_popup.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 9000583..6f089d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,7 @@ add_executable(lingo_ap_tracker tracker_panel.cpp game_data.cpp area_window.cpp + area_popup.cpp ) set_property(TARGET lingo_ap_tracker PROPERTY CXX_STANDARD 17) set_property(TARGET lingo_ap_tracker PROPERTY CXX_STANDARD_REQUIRED ON) diff --git a/area_popup.cpp b/area_popup.cpp new file mode 100644 index 0000000..62cbe4d --- /dev/null +++ b/area_popup.cpp @@ -0,0 +1,37 @@ +#include "area_popup.h" + +#include "game_data.h" + +AreaPopup::AreaPopup(wxWindow* parent, int area_id) + : wxPanel(parent, wxID_ANY), area_id_(area_id) { + const MapArea& map_area = GetGameData().GetMapArea(area_id); + + wxBoxSizer* list_sizer = new wxBoxSizer(wxVERTICAL); + + wxStaticText* top_label = new wxStaticText(this, -1, map_area.name); + top_label->SetForegroundColour(*wxBLACK); + top_label->SetFont(top_label->GetFont().Bold()); + list_sizer->Add(top_label, wxSizerFlags().Center().DoubleBorder(wxDOWN)); + + bool is_first = true; + for (const Location& location : map_area.locations) { + wxSizerFlags sizer_flags = wxSizerFlags().Left(); + if (!is_first) { + sizer_flags = sizer_flags.Border(wxUP); + } + + wxStaticText* section_label = new wxStaticText(this, -1, location.name); + section_label->SetForegroundColour(*wxBLACK); + list_sizer->Add(section_label, sizer_flags); + + is_first = false; + } + + wxBoxSizer* top_sizer = new wxBoxSizer(wxVERTICAL); + top_sizer->Add(list_sizer, wxSizerFlags().DoubleBorder(wxALL)); + + SetSizerAndFit(top_sizer); + + SetBackgroundColour(*wxLIGHT_GREY); + Hide(); +} diff --git a/area_popup.h b/area_popup.h new file mode 100644 index 0000000..c3de4bb --- /dev/null +++ b/area_popup.h @@ -0,0 +1,18 @@ +#ifndef AREA_POPUP_H_03FAC988 +#define AREA_POPUP_H_03FAC988 + +#include + +#ifndef WX_PRECOMP +#include +#endif + +class AreaPopup : public wxPanel { + public: + AreaPopup(wxWindow* parent, int area_id); + + private: + int area_id_; +}; + +#endif /* end of include guard: AREA_POPUP_H_03FAC988 */ diff --git a/area_window.cpp b/area_window.cpp index 482dcb0..2f334e4 100644 --- a/area_window.cpp +++ b/area_window.cpp @@ -4,14 +4,15 @@ #include "game_data.h" -AreaWindow::AreaWindow(wxWindow* parent, int area_id) - : wxWindow(parent, wxID_ANY), area_id_(area_id) { +AreaWindow::AreaWindow(wxWindow* parent, int area_id, AreaPopup* popup) + : wxWindow(parent, wxID_ANY), area_id_(area_id), popup_(popup) { SetSize(EFFECTIVE_SIZE, EFFECTIVE_SIZE); Redraw(); Bind(wxEVT_PAINT, &AreaWindow::OnPaint, this); Bind(wxEVT_ENTER_WINDOW, &AreaWindow::OnEnterWindow, this); + Bind(wxEVT_LEAVE_WINDOW, &AreaWindow::OnLeaveWindow, this); } void AreaWindow::OnPaint(wxPaintEvent& event) { @@ -23,14 +24,9 @@ void AreaWindow::OnPaint(wxPaintEvent& event) { dc.DrawBitmap(rendered_, 0, 0); } -void AreaWindow::OnEnterWindow(wxMouseEvent& event) { - std::cout << GetGameData().GetMapArea(area_id_).name << std::endl; - std::cout << "---" << std::endl; - for (const Location& loc : GetGameData().GetMapArea(area_id_).locations) { - std::cout << loc.name << std::endl; - } - std::cout << "---" << std::endl; -} +void AreaWindow::OnEnterWindow(wxMouseEvent& event) { popup_->Show(); } + +void AreaWindow::OnLeaveWindow(wxMouseEvent& event) { popup_->Hide(); } void AreaWindow::Redraw() { int actual_border_size = GetSize().GetWidth() * BORDER_SIZE / EFFECTIVE_SIZE; diff --git a/area_window.h b/area_window.h index 0806da4..c9abc4c 100644 --- a/area_window.h +++ b/area_window.h @@ -7,24 +7,30 @@ #include #endif +#include "area_popup.h" + class AreaWindow : public wxWindow { public: static constexpr int ACTUAL_SIZE = 64; static constexpr int BORDER_SIZE = 5; static constexpr int EFFECTIVE_SIZE = ACTUAL_SIZE + BORDER_SIZE * 2; - AreaWindow(wxWindow* parent, int area_id); + AreaWindow(wxWindow* parent, int area_id, AreaPopup* popup); int GetAreaId() const { return area_id_; } + AreaPopup* GetPopup() { return popup_; } + private: void OnPaint(wxPaintEvent& event); void OnEnterWindow(wxMouseEvent& event); + void OnLeaveWindow(wxMouseEvent& event); void Redraw(); int area_id_; wxBitmap rendered_; + AreaPopup* popup_; }; #endif /* end of include guard: AREA_WINDOW_H_C2653ACF */ diff --git a/tracker_frame.cpp b/tracker_frame.cpp index 0c3827e..b33cce9 100644 --- a/tracker_frame.cpp +++ b/tracker_frame.cpp @@ -6,6 +6,8 @@ TrackerFrame::TrackerFrame() : wxFrame(nullptr, wxID_ANY, "Lingo Archipelago Tracker") { ::wxInitAllImageHandlers(); + SetSize(1280, 728); + wxMenu *menuFile = new wxMenu(); menuFile->Append(wxID_EXIT); diff --git a/tracker_panel.cpp b/tracker_panel.cpp index 0cd65cc..0e78cc5 100644 --- a/tracker_panel.cpp +++ b/tracker_panel.cpp @@ -1,5 +1,6 @@ #include "tracker_panel.h" +#include "area_popup.h" #include "game_data.h" TrackerPanel::TrackerPanel(wxWindow *parent) : wxPanel(parent, wxID_ANY) { @@ -9,7 +10,13 @@ TrackerPanel::TrackerPanel(wxWindow *parent) : wxPanel(parent, wxID_ANY) { } for (const MapArea &map_area : GetGameData().GetMapAreas()) { - area_windows_.push_back(new AreaWindow(this, map_area.id)); + AreaPopup *area_popup = new AreaPopup(this, map_area.id); + area_popup->SetPosition({0, 0}); + area_popup->Raise(); + + AreaWindow *area_window = new AreaWindow(this, map_area.id, area_popup); + area_window->Lower(); + area_windows_.push_back(area_window); } Redraw(); @@ -62,5 +69,18 @@ void TrackerPanel::Redraw() { final_y + (map_area.map_y - (AreaWindow::EFFECTIVE_SIZE / 2)) * final_width / image_size.GetWidth(), }); + + AreaPopup *area_popup = area_window->GetPopup(); + int popup_x = + final_x + map_area.map_x * final_width / image_size.GetWidth(); + int popup_y = + final_y + map_area.map_y * final_width / image_size.GetWidth(); + if (popup_x + area_popup->GetSize().GetWidth() > panel_size.GetWidth()) { + popup_x = panel_size.GetWidth() - area_popup->GetSize().GetWidth(); + } + if (popup_y + area_popup->GetSize().GetHeight() > panel_size.GetHeight()) { + popup_y = panel_size.GetHeight() - area_popup->GetSize().GetHeight(); + } + area_popup->SetPosition({popup_x, popup_y}); } } -- cgit 1.4.1