Btk
window.hpp
1 #if !defined(_BTK_WINDOW_HPP_)
2 #define _BTK_WINDOW_HPP_
3 #include <string_view>
4 #include <functional>
5 #include <string>
6 #include "signal/signal.hpp"
7 #include "rect.hpp"
8 #include "defs.hpp"
9 namespace Btk{
10  struct WindowImpl;
11  class Container;
12  class PixBuf;
13  class Widget;
14  class Event;
15  class Font;
20  class BTKAPI Window:public HasSlots{
21  public:
22  //Signals
27  public:
28  Window():pimpl(nullptr){};
29  Window(const Window &) = delete;
30  Window(Window &&win){
31  pimpl = win.pimpl;
32  win.pimpl = nullptr;
33  };
41  Window(std::string_view title,int w,int h);
47  inline WindowImpl *impl() const noexcept{
48  return pimpl;
49  }
57  bool add(Widget *ptr);
66  template<class T,class ...Args>
67  T &add(Args &&...args){
68  T *ptr = new T(container(),std::forward<Args>(args)...);
69  add(ptr);
70  return *ptr;
71  }
76  void update();
81  void lock();
86  void unlock();
91  void done();
98  void move(int x,int y);
103  void show();
109  void draw();
115  void close();
122  bool mainloop();
129  bool exists() const;
135  PixBuf pixbuf();
141  void set_title(std::string_view title);
147  void set_icon(std::string_view file);
153  void set_icon(const PixBuf &pixbuf);
159  void set_fullscreen(bool val = true);
165  void set_resizeable(bool val = true);
172  void set_transparent(float value);
173  //Set Callbacks
174  template<class ...T>
175  Connection on_close(T &&...args){
176  return sig_close().connect(std::forward<T>(args)...);
177  }
178  template<class ...T>
179  Connection on_resize(T &&...args){
180  return sig_resize().connect(std::forward<T>(args)...);
181  }
182  template<class ...T>
183  Connection on_dropfile(T &&...args){
184  return sig_dropfile().connect(std::forward<T>(args)...);
185  }
186  //Connect Signals
187  SignalClose& sig_close();
188  SignalEvent& sig_event();
189  SignalResize& sig_resize();
190  SignalDropFile& sig_dropfile();
195  void set_cursor();
203  void set_cursor(const PixBuf &pixbuf,int hot_x = 0,int hot_y = 0);
204  //Get information
205  int w() const noexcept;//get w
206  int h() const noexcept;//get h
207  Font font() const;//get font
213  Container &container() const;
214  private:
215  WindowImpl *pimpl;
216  Uint32 winid;
217  };
218 }
219 #endif // _BTK_WINDOW_HPP_
Definition: signal.hpp:89
Definition: widget.hpp:219
This header include many useful containers.
Definition: async.hpp:7
A Basic Window.
Definition: window.hpp:20
Font Class.
Definition: font.hpp:26
Definition: pixels.hpp:32
bool exists(std::string_view fname)
Check the file exists.
Definition: fs.hpp:54
Definition: signal.hpp:119
WindowImpl * impl() const noexcept
Get window impl.
Definition: window.hpp:47
Definition: window.hpp:39
A Container of Widget.
Definition: widget.hpp:108
T & add(Args &&...args)
A helper template to add widget.
Definition: window.hpp:67