Btk
utils.hpp
1 #if !defined(_BTKIMPL_UTILS_HPP_)
2 #define _BTKIMPL_UTILS_HPP_
3 //This headers provide some utils
4 #include <SDL2/SDL_events.h>
5 #include "../widget.hpp"
6 #include "../event.hpp"
7 #include "../rect.hpp"
8 #include "window.hpp"
9 namespace Btk{
18  inline int CalculateXByAlign(const Rect &rect,int w,Align v_align){
19  switch(v_align){
20  case Align::Left:
21  return rect.x;
22  case Align::Right:
23  return rect.x + rect.w - w;
24  case Align::Center:
25  return rect.x + ((rect.w - w) / 2);
26  default:
27  return -1;
28  }
29  };
38  inline int CalculateYByAlign(const Rect &rect,int h,Align h_align){
39  switch(h_align){
40  case Align::Top:
41  return rect.y;
42  case Align::Buttom:
43  return rect.y + rect.h - h;
44  case Align::Center:
45  return rect.y + ((rect.h - h) / 2);
46  default:
47  return -1;
48  }
49  };
61  (const Rect &rect,
62  int w,int h,
63  Align v_align,
64  Align h_align){
65 
66 
67  return Rect{
68  CalculateXByAlign(rect,w,v_align),
69  CalculateYByAlign(rect,h,h_align),
70  w,
71  h
72  };
73  };
74  //Translate SDL_Event to Btk's event
75  MotionEvent TranslateEvent(const SDL_MouseMotionEvent &event);
76  MouseEvent TranslateEvent(const SDL_MouseButtonEvent &event);
77  WheelEvent TranslateEvent(const SDL_MouseWheelEvent &event);
78  KeyEvent TranslateEvent(const SDL_KeyboardEvent &event);
79 
80  TextInputEvent TranslateEvent(const SDL_TextInputEvent &event);
81 };
82 
83 #endif // _BTKIMPL_UTILS_HPP_
a SDL_Rect with methods
Definition: rect.hpp:10
This header include many useful containers.
Definition: async.hpp:7
Rect CalculateRectByAlign(const Rect &rect, int w, int h, Align v_align, Align h_align)
Calcaute a area in a Rect by alignment.
Definition: utils.hpp:61
A Event of text input.
Definition: event.hpp:237
A event about mouse click.
Definition: event.hpp:106
A event about keyboard.
Definition: event.hpp:171
A event about mouse motion.
Definition: event.hpp:216
int CalculateYByAlign(const Rect &rect, int h, Align h_align)
Calcaute a area&#39;s Y in a Rect by alignment.
Definition: utils.hpp:38
Definition: event.hpp:287
int CalculateXByAlign(const Rect &rect, int w, Align v_align)
Calcaute a area&#39;s X in a Rect by alignment.
Definition: utils.hpp:18