Skip to content

Commit

Permalink
Custom title bar hit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
dvsku committed Feb 11, 2024
1 parent 8bcc39b commit 40166af
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/devue_app/src/gui/dv_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void dv_gui::on_gui_before_update() {
}

void dv_gui::on_gui_update() {
m_skip_titlebar_hit = ImGui::IsAnyItemHovered();
m_title_bar_hit_test = ImGui::IsAnyItemHovered();
ImGuiViewport* viewport = ImGui::GetMainViewport();

ImGuiWindowFlags flags = 0;
Expand Down Expand Up @@ -272,7 +272,7 @@ void dv_gui::on_gui_update() {
ImGui::Button(ICON_FA_WINDOW_RESTORE"##RestoreButton", { 30.0f, titlebar_size.y });
}

m_hover_maximize = ImGui::IsItemHovered();
m_maximize_hovered = ImGui::IsItemHovered();

ImGui::SameLine(0.0f, 0.0f);
ImGui::SetCursorPosY(min.y - titlebar_padding.y);
Expand Down Expand Up @@ -345,6 +345,14 @@ void dv_gui::on_drop(int count, const char* paths[]) {
}
}

bool dv_gui::is_title_bar(int32_t x, int32_t y) {
return !m_title_bar_hit_test && y > 0 && y <= 25;
}

bool dv_gui::is_maximize_button(int32_t x, int32_t y) {
return m_maximize_hovered;
}

void dv_gui::set_theme() {
ImGuiStyle& style = ImGui::GetStyle();
ImVec4* colors = style.Colors;
Expand Down
6 changes: 6 additions & 0 deletions src/devue_app/src/gui/dv_gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ namespace devue {
void on_mouse_move(double dx, double dy) override final;
void on_drop(int count, const char* paths[]) override final;

bool is_title_bar(int32_t x, int32_t y) override final;
bool is_maximize_button(int32_t x, int32_t y) override final;

void set_theme();

private:
Expand All @@ -37,6 +40,9 @@ namespace devue {

std::shared_ptr<core::dv_render_target> m_scene_render_target = nullptr;

bool m_maximize_hovered = false;
bool m_title_bar_hit_test = false;

private:
devue::uuid create_checkerboard_texture();
};
Expand Down

0 comments on commit 40166af

Please sign in to comment.