Add app::ui_scene helper base class
This commit is contained in:
parent
5e6d52f341
commit
a362dafee3
5 changed files with 130 additions and 1 deletions
|
|
@ -3,4 +3,4 @@ file(GLOB_RECURSE PSEMEK_APP_SOURCES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "sou
|
||||||
|
|
||||||
psemek_add_library(psemek-app ${PSEMEK_APP_HEADERS} ${PSEMEK_APP_SOURCES})
|
psemek_add_library(psemek-app ${PSEMEK_APP_HEADERS} ${PSEMEK_APP_SOURCES})
|
||||||
target_include_directories(psemek-app PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
target_include_directories(psemek-app PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||||
target_link_libraries(psemek-app PUBLIC psemek-log psemek-util psemek-gfx psemek-sdl2)
|
target_link_libraries(psemek-app PUBLIC psemek-log psemek-util psemek-gfx psemek-ui psemek-sdl2)
|
||||||
|
|
|
||||||
37
libs/app/include/psemek/app/ui_scene.hpp
Normal file
37
libs/app/include/psemek/app/ui_scene.hpp
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <psemek/app/scene.hpp>
|
||||||
|
|
||||||
|
#include <psemek/ui/controller.hpp>
|
||||||
|
|
||||||
|
namespace psemek::app
|
||||||
|
{
|
||||||
|
|
||||||
|
struct ui_scene
|
||||||
|
: scene_base
|
||||||
|
{
|
||||||
|
ui_scene(ui::controller & controller);
|
||||||
|
|
||||||
|
void on_resize(int width, int height) override;
|
||||||
|
|
||||||
|
void on_mouse_move(int x, int y, int dx, int dy) override;
|
||||||
|
void on_mouse_wheel(int delta) override;
|
||||||
|
void on_left_button_down() override;
|
||||||
|
void on_left_button_up() override;
|
||||||
|
void on_middle_button_down() override;
|
||||||
|
void on_middle_button_up() override;
|
||||||
|
void on_right_button_down() override;
|
||||||
|
void on_right_button_up() override;
|
||||||
|
|
||||||
|
void on_key_down(SDL_Keycode key) override;
|
||||||
|
void on_key_up(SDL_Keycode key) override;
|
||||||
|
|
||||||
|
void present() override;
|
||||||
|
|
||||||
|
ui::controller & controller() const { return controller_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
ui::controller & controller_;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
85
libs/app/source/ui_scene.cpp
Normal file
85
libs/app/source/ui_scene.cpp
Normal file
|
|
@ -0,0 +1,85 @@
|
||||||
|
#include <psemek/app/ui_scene.hpp>
|
||||||
|
|
||||||
|
namespace psemek::app
|
||||||
|
{
|
||||||
|
|
||||||
|
ui_scene::ui_scene(ui::controller & controller)
|
||||||
|
: controller_(controller)
|
||||||
|
{}
|
||||||
|
|
||||||
|
void ui_scene::on_resize(int width, int height)
|
||||||
|
{
|
||||||
|
scene_base::on_resize(width, height);
|
||||||
|
controller_.reshape({{{0.f, width}, {0.f, height}}});
|
||||||
|
}
|
||||||
|
|
||||||
|
void ui_scene::on_mouse_move(int x, int y, int dx, int dy)
|
||||||
|
{
|
||||||
|
scene_base::on_mouse_move(x, y, dx, dy);
|
||||||
|
controller_.event(ui::mouse_move{{x, y}});
|
||||||
|
}
|
||||||
|
|
||||||
|
void ui_scene::on_mouse_wheel(int delta)
|
||||||
|
{
|
||||||
|
scene_base::on_mouse_wheel(delta);
|
||||||
|
controller_.event(ui::mouse_wheel{delta});
|
||||||
|
}
|
||||||
|
|
||||||
|
void ui_scene::on_left_button_down()
|
||||||
|
{
|
||||||
|
scene_base::on_left_button_down();
|
||||||
|
controller_.event(ui::mouse_click{ui::mouse_button::left, true});
|
||||||
|
}
|
||||||
|
|
||||||
|
void ui_scene::on_left_button_up()
|
||||||
|
{
|
||||||
|
scene_base::on_left_button_up();
|
||||||
|
controller_.event(ui::mouse_click{ui::mouse_button::left, false});
|
||||||
|
}
|
||||||
|
|
||||||
|
void ui_scene::on_middle_button_down()
|
||||||
|
{
|
||||||
|
scene_base::on_left_button_down();
|
||||||
|
controller_.event(ui::mouse_click{ui::mouse_button::middle, true});
|
||||||
|
}
|
||||||
|
|
||||||
|
void ui_scene::on_middle_button_up()
|
||||||
|
{
|
||||||
|
scene_base::on_left_button_down();
|
||||||
|
controller_.event(ui::mouse_click{ui::mouse_button::middle, false});
|
||||||
|
}
|
||||||
|
|
||||||
|
void ui_scene::on_right_button_down()
|
||||||
|
{
|
||||||
|
scene_base::on_right_button_down();
|
||||||
|
controller_.event(ui::mouse_click{ui::mouse_button::right, true});
|
||||||
|
}
|
||||||
|
|
||||||
|
void ui_scene::on_right_button_up()
|
||||||
|
{
|
||||||
|
scene_base::on_right_button_down();
|
||||||
|
controller_.event(ui::mouse_click{ui::mouse_button::right, false});
|
||||||
|
}
|
||||||
|
|
||||||
|
void ui_scene::on_key_down(SDL_Keycode key)
|
||||||
|
{
|
||||||
|
scene_base::on_key_down(key);
|
||||||
|
controller_.event(ui::key_press{key, true});
|
||||||
|
}
|
||||||
|
|
||||||
|
void ui_scene::on_key_up(SDL_Keycode key)
|
||||||
|
{
|
||||||
|
scene_base::on_key_down(key);
|
||||||
|
controller_.event(ui::key_press{key, false});
|
||||||
|
}
|
||||||
|
|
||||||
|
void ui_scene::present()
|
||||||
|
{
|
||||||
|
gfx::render_target rt;
|
||||||
|
rt.viewport = {{{0, width()}, {0, height()}}};
|
||||||
|
rt.framebuffer = &gfx::framebuffer::null();
|
||||||
|
rt.draw_buffer = gl::BACK_LEFT;
|
||||||
|
controller_.render(rt);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -40,6 +40,9 @@ namespace psemek::ui
|
||||||
ellipsis,
|
ellipsis,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
label() = default;
|
||||||
|
explicit label(std::string text);
|
||||||
|
|
||||||
virtual void set_text(std::string text);
|
virtual void set_text(std::string text);
|
||||||
virtual std::string_view text() const { return text_; }
|
virtual std::string_view text() const { return text_; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,10 @@
|
||||||
namespace psemek::ui
|
namespace psemek::ui
|
||||||
{
|
{
|
||||||
|
|
||||||
|
label::label(std::string text)
|
||||||
|
: text_(std::move(text))
|
||||||
|
{}
|
||||||
|
|
||||||
void label::set_text(std::string text)
|
void label::set_text(std::string text)
|
||||||
{
|
{
|
||||||
text_ = std::move(text);
|
text_ = std::move(text);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue