Euphoria
root.cc
Go to the documentation of this file.
1 #include "gui/root.h"
2 
3 #include "base/cint.h"
4 
5 #include "render/spriterender.h"
6 
7 #include "gui/load.h"
8 #include "gui/skin.h"
9 
10 
11 namespace eu::gui
12 {
13  Root::Root(const size2f& s)
14  : size(s)
15  {
16  }
17 
18 
19  Root::~Root() = default;
20 
21 
22  bool
24  (
25  io::FileSystem* fs,
26  render::FontCache* font,
27  const io::FilePath& path,
29  )
30  {
31  const bool result = eu::gui::load_gui(this, fs, font, path, cache);
32 
33  if(result)
34  {
36  }
37 
38  return result;
39  }
40 
41 
42  void
43  Root::set_input_mouse(const vec2f& pos, bool down)
44  {
45  state.mouse = pos;
46  state.mouse_down = down;
47  }
48 
49 
50  void
51  Root::update(float dt)
52  {
53  state.begin();
54  container.update(dt);
55  state.end();
56  }
57 
58 
59  void
60  Root::set_size(const size2f& new_size)
61  {
62  size = new_size;
64  }
65 
66 
67  void
69  {
70  container.render(sp);
71 
72  auto image = state.hot != nullptr ? hover_image : cursor_image;
73 
74  if(image)
75  {
76  sp->draw_sprite
77  (
78  *image,
80  (
81  state.mouse,
82  Scale2f{0, 1},
83  c_int_to_float(image->width),
84  c_int_to_float(image->height)
85  )
86  );
87  }
88  }
89 }
bool load_gui(Root *root, io::FileSystem *fs, render::FontCache *font, const io::FilePath &path, render::TextureCache *cache)
Definition: load.cc:308
constexpr float c_int_to_float(int i)
Definition: cint.h:50
static Rectf from_position_anchor_width_and_height(const vec2f &pos, const Scale2f &anchor, float width, float height)
Definition: rect.cc:56
static Rectf from_width_height(float width, float height)
Definition: rect.cc:98
void update(float dt)
Definition: container.cc:29
void render(render::SpriteRenderer *renderer) const
Definition: container.cc:39
void lay_out(Rectf area)
std::shared_ptr< render::Texture2 > hover_image
Definition: root.h:71
void set_size(const size2f &new_size)
Definition: root.cc:60
State state
Definition: root.h:68
size2f size
Definition: root.h:67
void set_input_mouse(const vec2f &pos, bool down)
Definition: root.cc:43
void update(float dt)
Definition: root.cc:51
LayoutContainer container
Definition: root.h:69
void render(render::SpriteRenderer *sp) const
Definition: root.cc:68
std::shared_ptr< render::Texture2 > cursor_image
Definition: root.h:70
bool load(io::FileSystem *fs, render::FontCache *font, const ::eu::io::FilePath &path, render::TextureCache *cache)
Definition: root.cc:24
Root(const size2f &s)
Definition: root.cc:13
vec2f mouse
Definition: uistate.h:16
Widget * hot
Definition: uistate.h:19
bool mouse_down
Definition: uistate.h:17
void draw_sprite(const Texture2 &texture, const Rectf &position, const DrawData &data=DrawData{})
Definition: vec2.h:33