Btk
window.hpp
1 #if !defined(_BTKIMPL_WINDOW_HPP_)
2 #define _BTKIMPL_WINDOW_HPP_
3 #include <SDL2/SDL.h>
4 #include <string_view>
5 #include <functional>
6 #include <mutex>
7 #include <list>
8 #include "render.hpp"
9 #include "../signal/signal.hpp"
10 #include "../widget.hpp"
11 #include "../themes.hpp"
12 #include "../event.hpp"
13 #include "../font.hpp"
14 #include "atomic.hpp"
15 namespace Btk{
16  class Event;
17  //Impl for Window
18  struct Renderer;
19  struct Widget;
20  struct Theme;
24  struct DrawCallback{
25  Widget *widget;
26  void *userdata;
27  bool (*draw_fn)(Renderer &,Widget *widget,void*);
35  bool call(Renderer &render) const{
36  return draw_fn(render,widget,userdata);
37  }
38  };
39  struct BTKAPI WindowImpl{
40  //Init SDL Window
41  WindowImpl(const char *title,int x,int y,int w,int h,int flags);
42  ~WindowImpl();
43  void draw();
44  void pixels_size(int *x,int *y);//GetWindowSize
45  //tirgger close cb
46 
47  bool on_close();
48  void on_resize(int new_w,int new_h);
49  void on_dropfile(std::string_view file);
50  //handle event
51  void handle_windowev(const SDL_Event &event);
52  //Dispatch Event to Widgets
53  bool dispatch(Event &event);
54 
55  //update wingets postions
56  void update_postion();
57  SDL_Window *win = nullptr;
58  Renderer render;
59  //Signals
60  Signal<void()> sig_leave;//mouse leave
61  Signal<void()> sig_enter;//mouse enter
62  Signal<bool()> sig_close;//CloseWIndow
63  Signal<void(std::string_view)> sig_dropfile;//DropFile
64  Signal<void(int new_w,int new_h)> sig_resize;//WindowResize
65  Signal<bool(Event &)> sig_event;//Process Unhandled Event
66  //BackGroud Color
67  Color bg_color;
68  //Background cursor
69  SDL_Cursor *cursor = nullptr;
70  //mutex
71  std::recursive_mutex mtx;
72  Atomic visible = false;
73  //Last draw ticks
74  Uint32 last_draw_ticks = 0;
75  //Window theme
76  Theme theme;
77  Container container;
78  //The draw callback
79  //It will be called at last
80  std::list<DrawCallback> draw_cbs;
81 
82  //Methods for Widget impl
88  Font font() const{
89  return theme.font;
90  }
91  };
92 };
93 
94 #endif // _BTKIMPL_WINDOW_HPP_
Definition: atomic.hpp:6
Definition: widget.hpp:219
This header include many useful containers.
Definition: async.hpp:7
Definition: themes.hpp:9
The Internal Window Draw Callback.
Definition: window.hpp:24
bool call(Renderer &render) const
Start Render.
Definition: window.hpp:35
Font Class.
Definition: font.hpp:26
Color structure.
Definition: pixels.hpp:19
Font font() const
Get window&#39;s font.
Definition: window.hpp:88
A base event of all events.
Definition: event.hpp:17
Definition: window.hpp:39
A Container of Widget.
Definition: widget.hpp:108