Advertisement
Kitomas

kit_win32 as of 2024-02-22 (2/2)

Feb 22nd, 2024
892
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 36.94 KB | None | 0 0
  1. /*+include\kit\_misc_time.hpp+*/
  2.  
  3. #ifndef _KIT_INC__MISC_TIME_HPP
  4. #define _KIT_INC__MISC_TIME_HPP
  5.  
  6. #include "commondef.hpp"
  7.  
  8.  
  9. namespace kit {
  10.  
  11.  
  12. namespace time {
  13.  
  14.  
  15.  
  16.  
  17. u64 getTicks();
  18. u64 getTicksPerSecond();
  19. f64 getUptime();
  20.  
  21. void sleep(u32 milliseconds);
  22.  
  23.  
  24.  
  25.  
  26. };
  27.  
  28.  
  29. };
  30.  
  31. #endif /* _KIT_INC__MISC_TIME_HPP */
  32.  
  33. /*-include\kit\_misc_time.hpp-*/
  34.  
  35.  
  36. /*+include\kit\_video_Bitmap.hpp+*/
  37.  
  38. #ifndef _KIT_INC__VIDEO_BITMAP_HPP
  39. #define _KIT_INC__VIDEO_BITMAP_HPP
  40.  
  41. #include "commondef.hpp"
  42. #include "_video_misc.hpp"
  43.  
  44.  
  45. namespace kit {
  46.  
  47.  
  48.  
  49.  
  50. struct _BitmapOpaque;
  51.  
  52.  
  53.  
  54.  
  55. class Bitmap {
  56.   u32 _type;
  57.   u32 _padding32;
  58.   _BitmapOpaque* _opq = nullptr;
  59.   bool _valid = false;
  60.  
  61.  
  62. public:
  63.   u32 _getType(){ return _type; }
  64.   _BitmapOpaque* _accessOpaque(){ return _opq; }
  65.  
  66.  
  67.   //loads from memory
  68.   Bitmap(const color::ARGB* pixelData,
  69.          u32 width, u32 height,
  70.          bool directAccess = false);
  71.  
  72.   //loads from file
  73.   Bitmap(const char* fileName,
  74.          u32 width, u32 height,
  75.          bool directAccess = false);
  76.  
  77.   ~Bitmap();
  78.  
  79.  
  80. };
  81.  
  82.  
  83.  
  84.  
  85. };
  86.  
  87. #endif /* _KIT_INC__VIDEO_BITMAP_HPP */
  88.  
  89. /*-include\kit\_video_Bitmap.hpp-*/
  90.  
  91.  
  92. /*+include\kit\_video_misc.hpp+*/
  93.  
  94. #ifndef _KIT_INC__VIDEO_MISC_HPP
  95. #define _KIT_INC__VIDEO_MISC_HPP
  96.  
  97. #include "commondef.hpp"
  98.  
  99.  
  100. namespace kit {
  101.  
  102.  
  103.  
  104.  
  105. namespace color {
  106.  
  107.   //what GDI uses (save for the alpha channel)
  108.   union ARGB { //4B; 0xAARRGGBB
  109.     u32 v; //entire color [v]alue
  110.     struct {
  111.       u8 b;
  112.       u8 g;
  113.       u8 r;
  114.       u8 a;
  115.     };
  116.  
  117.     ARGB() : v(0) {}
  118.     ARGB(u32 _v) : v(_v) {}
  119.     ARGB(u8 _r, u8 _g,
  120.          u8 _b, u8 _a) : r(_r), g(_g), b(_b), a(_a) {}
  121.     inline void operator=(const u32 cv){ v = cv; }
  122.     inline bool operator==(const ARGB& c){ return (v == c.v); };
  123.     inline bool operator!=(const ARGB& c){ return (v != c.v); };
  124.     inline bool operator==(const u32& cv){ return (v == cv); };
  125.     inline bool operator!=(const u32& cv){ return (v != cv); };
  126.   };
  127.  
  128.  
  129.   union ABGR { //4B; 0xAABBGGRR
  130.     u32 v; //entire color [v]alue
  131.     struct {
  132.       u8 r;
  133.       u8 g;
  134.       u8 b;
  135.       u8 a;
  136.     };
  137.  
  138.     ABGR() : v(0) {}
  139.     ABGR(u32 _v) : v(_v) {}
  140.     ABGR(u8 _r, u8 _g,
  141.          u8 _b, u8 _a) : r(_r), g(_g), b(_b), a(_a) {}
  142.     inline void operator=(const u32 cv){ v = cv; }
  143.     inline bool operator==(const ABGR& c){ return (v == c.v); };
  144.     inline bool operator!=(const ABGR& c){ return (v != c.v); };
  145.     inline bool operator==(const u32& cv){ return (v == cv); };
  146.     inline bool operator!=(const u32& cv){ return (v != cv); };
  147.   };
  148.  
  149. };
  150.  
  151.  
  152.  
  153.  
  154. namespace shape {
  155.  
  156.   struct point { //8B
  157.     s32 x, y;
  158.     point() : x(0), y(0) {}
  159.     point(s32 _x, s32 _y) : x(_x), y(_y) {}
  160.     inline bool operator==(const point& p){ return (x==p.x && y==p.y); };
  161.     inline bool operator!=(const point& p){ return (x!=p.x && y!=p.y); };
  162.   };
  163.  
  164.   struct rect { //16B
  165.     s32 x, y; //x & y position of the rectangle's top-left corner
  166.     s32 w, h; //the rectangle's width & height
  167.     rect() : x(0), y(0), w(0), h(0) {}
  168.     rect(s32 _x, s32 _y) : x(_x), y(_y) {}
  169.     rect(s32 _x, s32 _y,
  170.          s32 _w, s32 _h) : x(_x), y(_y), w(_w), h(_h) {}
  171.     inline bool operator==(const rect& r){ return (x==r.x && y==r.y && w==r.w && h==r.h); };
  172.     inline bool operator!=(const rect& r){ return (x!=r.x && y!=r.y && w!=r.w && h!=r.h); };
  173.   };
  174.  
  175.   struct line { //16B
  176.     s32 x0, y0;
  177.     s32 x1, y1;
  178.     line() : x0(0), y0(0), x1(0), y1(0) {}
  179.     line(s32 _x0, s32 _y0,
  180.          s32 _x1, s32 _y1) : x0(_x0), y0(_y0), x1(_x1), y1(_y1) {}
  181.     inline bool operator==(const line& l){ return (x0==l.x0 && y0==l.y0 && x1==l.x1 && y1==l.y1); };
  182.     inline bool operator!=(const line& l){ return (x0!=l.x0 && y0!=l.y0 && x1!=l.x1 && y1!=l.y1); };
  183.   };
  184.  
  185.  
  186.  
  187.   struct fpoint { //8B
  188.     f32 x, y;
  189.     fpoint() : x(0.0f), y(0.0f) {}
  190.     fpoint(f32 _x, f32 _y) : x(_x), y(_y) {}
  191.     inline bool operator==(const fpoint& p){ return (x==p.x && y==p.y); };
  192.     inline bool operator!=(const fpoint& p){ return (x!=p.x && y!=p.y); };
  193.   };
  194.  
  195.   struct frect { //16B
  196.     f32 x, y; //x & y position of rectangle's top-left corner
  197.     f32 w, h; //the rectangle's width & height
  198.     frect() : x(0.0f), y(0.0f), w(0.0f), h(0.0f) {}
  199.     frect(f32 _x, f32 _y) : x(_x), y(_y) {}
  200.     frect(f32 _x, f32 _y,
  201.           f32 _w, f32 _h) : x(_x), y(_y), w(_w), h(_h) {}
  202.     inline bool operator==(const frect& r){ return (x==r.x && y==r.y && w==r.w && h==r.h); };
  203.     inline bool operator!=(const frect& r){ return (x!=r.x && y!=r.y && w!=r.w && h!=r.h); };
  204.   };
  205.  
  206.   struct fline { //16B
  207.     f32 x0, y0;
  208.     f32 x1, y1;
  209.     fline() : x0(0.0f), y0(0.0f), x1(0.0f), y1(0.0f) {}
  210.     fline(f32 _x0, f32 _y0,
  211.           f32 _x1, f32 _y1) : x0(_x0), y0(_y0), x1(_x1), y1(_y1) {}
  212.     inline bool operator==(const fline& l){ return (x0==l.x0 && y0==l.y0 && x1==l.x1 && y1==l.y1); };
  213.     inline bool operator!=(const fline& l){ return (x0!=l.x0 && y0!=l.y0 && x1!=l.x1 && y1!=l.y1); };
  214.   };
  215.  
  216.  
  217.  
  218.   struct dpoint { //16B
  219.     f64 x, y;
  220.     dpoint() : x(0.0), y(0.0) {}
  221.     dpoint(f64 _x, f64 _y) : x(_x), y(_y) {}
  222.     inline bool operator==(const dpoint& p){ return (x==p.x && y==p.y); };
  223.     inline bool operator!=(const dpoint& p){ return (x!=p.x && y!=p.y); };
  224.   };
  225.  
  226.   struct drect { //32B
  227.     f64 x, y; //x & y position of rectangle's top-left corner
  228.     f64 w, h; //the rectangle's width & height
  229.     drect() : x(0.0), y(0.0), w(0.0), h(0.0) {}
  230.     drect(f64 _x, f64 _y) : x(_x), y(_y) {}
  231.     drect(f64 _x, f64 _y,
  232.           f64 _w, f64 _h) : x(_x), y(_y), w(_w), h(_h) {}
  233.     inline bool operator==(const drect& r){ return (x==r.x && y==r.y && w==r.w && h==r.h); };
  234.     inline bool operator!=(const drect& r){ return (x!=r.x && y!=r.y && w!=r.w && h!=r.h); };
  235.   };
  236.  
  237.   struct dline { //32B
  238.     f64 x0, y0;
  239.     f64 x1, y1;
  240.     dline() : x0(0.0), y0(0.0), x1(0.0), y1(0.0) {}
  241.     dline(f64 _x0, f64 _y0,
  242.           f64 _x1, f64 _y1) : x0(_x0), y0(_y0), x1(_x1), y1(_y1) {}
  243.     inline bool operator==(const dline& l){ return (x0==l.x0 && y0==l.y0 && x1==l.x1 && y1==l.y1); };
  244.     inline bool operator!=(const dline& l){ return (x0!=l.x0 && y0!=l.y0 && x1!=l.x1 && y1!=l.y1); };
  245.   };
  246.  
  247. };
  248.  
  249.  
  250.  
  251.  
  252. };
  253.  
  254. #endif /* _KIT_INC__VIDEO_MISC_HPP */
  255.  
  256. /*-include\kit\_video_misc.hpp-*/
  257.  
  258.  
  259. /*+include\kit\_video_Window.hpp+*/
  260.  
  261. #ifndef _KIT_INC__VIDEO_WINDOW_HPP
  262. #define _KIT_INC__VIDEO_WINDOW_HPP
  263.  
  264. #include "commondef.hpp"
  265. #include "_video_misc.hpp"
  266. #include "_video_WindowEvent.hpp"
  267.  
  268.  
  269. namespace kit {
  270.  
  271.  
  272.  
  273.  
  274. enum WindowPositionEnum {
  275.   WINPOS_UNDEFINED = 0xC0000000,
  276.   WINPOS_CENTERED  = 0xC0000001,
  277.   WINPOS_UNCHANGED = 0xC0000002,
  278. };
  279.  
  280.  
  281. //(some flags override others!)
  282. enum WindowFlagEnum {
  283.   WINFLAG_HIDDEN        = 0x01, // window is not visible
  284.   WINFLAG_BORDERLESS    = 0x02, // window lacks any decoration
  285.   WINFLAG_RESIZABLE     = 0x04, // window can be resized
  286.   WINFLAG_MINIMIZED     = 0x08, // window is minimized
  287.   WINFLAG_MAXIMIZED     = 0x10, // window is maximized
  288.   WINFLAG_FOCUS         = 0x20, // window has grabbed input focus
  289.   WINFLAG_FULLSCREEN    = 0x40, // window is in fullscreen mode (non-exclusive)
  290. };
  291.  
  292.  
  293.  
  294.  
  295. struct _WindowOpaque;
  296.  
  297.  
  298.  
  299.  
  300. class Window {
  301.   u32 _type;
  302.   u32 _padding32;
  303.   _WindowOpaque* _opq = nullptr;
  304.   char _title[256];
  305.   bool _constructing = true;
  306.   bool _valid = false;
  307.  
  308.  
  309. public:
  310.   u32 _getType(){ return _type; }
  311.   _WindowOpaque* _accessOpaque(){ return _opq; }; //don't touch this, seriously
  312.  
  313.  
  314.   Window(const char* windowTitle,
  315.          u32 windowWidth, u32 windowHeight,
  316.          u32 windowFlags = 0,
  317.          s32 windowX = WINPOS_UNDEFINED,
  318.          s32 windowY = WINPOS_UNDEFINED,
  319.          u32 canvasWidth = 0, u32 canvasHeight = 0,
  320.          bool directAccess = false);
  321.  
  322.   ~Window();
  323.  
  324.  
  325.   bool isConstructing(){ return _constructing; }
  326.   bool isValid(){ return _valid; }
  327.   bool isClosed();
  328.  
  329.   const char* getTitle(){ return _title; }
  330.   shape::rect  getWindowRect();
  331.   shape::point getCanvasSize();
  332.   color::ARGB* getPixels();
  333.  
  334.   void setWindowRect(shape::rect* newRect);
  335.   void setVisibility(bool showWindow = true);
  336.   void setFocus(bool enable = true);
  337.   void setFullscreen(bool enable);
  338.  
  339.   bool pollEvent(WindowEvent* event_p = nullptr);
  340.  
  341.   void lock(bool locked = true);
  342.   void unlock(){ lock(false); }
  343.  
  344.   void present();
  345.   void clear(color::ARGB color = 0x00000000);
  346. };
  347.  
  348.  
  349.  
  350.  
  351. };
  352.  
  353. #endif /* _KIT__VIDEO_WINDOW_HPP */
  354.  
  355. /*-include\kit\_video_Window.hpp-*/
  356.  
  357.  
  358. /*+include\kit\_video_WindowEvent.hpp+*/
  359.  
  360. #ifndef _KIT_INC__VIDEO_WINDOWEVENT_HPP
  361. #define _KIT_INC__VIDEO_WINDOWEVENT_HPP
  362.  
  363. #include "commondef.hpp"
  364.  
  365.  
  366. namespace kit {
  367.  
  368.  
  369.  
  370.  
  371. #define KIT_EVENT_ID(_id) ( (_id) & 0xffff0000 )
  372. #define KIT_SUBEVENT_ID(_id) ( (_id) & 0xffff )
  373.  
  374. enum WindowEventEnum {
  375.   WINEVENT_NULL           = 0x00000000,
  376.  
  377.   WINEVENT_COMMON         = 0x00010000, //WindowEvent_Common
  378.  
  379.   WINEVENT_WIN            = 0x00020000, //WindowEvent_Win
  380.   WINEVENT_WIN_CLOSE      = WINEVENT_WIN   | 0x0001,
  381.   WINEVENT_WIN_MOVED      = WINEVENT_WIN   | 0x0002,
  382.   WINEVENT_WIN_RESIZED    = WINEVENT_WIN   | 0x0003,
  383.   WINEVENT_WIN_UNFOCUSING = WINEVENT_WIN   | 0x0004,
  384.   WINEVENT_WIN_FOCUSED    = WINEVENT_WIN   | 0x0005,
  385.  
  386.   WINEVENT_KEY            = 0x00030000, //WindowEvent_Key
  387.   WINEVENT_KEY_CHAR       = WINEVENT_KEY   | 0x0001,
  388.   WINEVENT_KEY_UP         = WINEVENT_KEY   | 0x0002,
  389.   WINEVENT_KEY_DOWN       = WINEVENT_KEY   | 0x0003,
  390.  
  391.   WINEVENT_MOUSE          = 0x00040000, //WindowEvent_Mouse
  392.   WINEVENT_MOUSE_MOVE     = WINEVENT_MOUSE | 0x0001,
  393.   WINEVENT_MOUSE_LEAVE    = WINEVENT_MOUSE | 0x0002, //(not fully implemented)
  394.   WINEVENT_MOUSE_ENTER    = WINEVENT_MOUSE | 0x0003, //(not fully implemented)
  395.   WINEVENT_MOUSE_UP       = WINEVENT_MOUSE | 0x0004,
  396.   WINEVENT_MOUSE_DOWN     = WINEVENT_MOUSE | 0x0005,
  397.   WINEVENT_MOUSE_HWHEEL   = WINEVENT_MOUSE | 0x0006,
  398.   WINEVENT_MOUSE_VWHEEL   = WINEVENT_MOUSE | 0x0007,
  399. };
  400.  
  401.  
  402.  
  403. /*+WINEVENT_COMMON+*/
  404.  
  405. struct WindowEvent_Common { //16B
  406.   u32 type;
  407.   u32 winIndex;
  408.   u64 timestamp;
  409. };
  410.  
  411. /*-WINEVENT_COMMON-*/
  412.  
  413.  
  414.  
  415. /*+WINEVENT_WIN+*/
  416.  
  417. struct WindowEvent_Win { //24B
  418.   u32 type;
  419.   u32 winIndex;
  420.   u64 timestamp;
  421.   union { s32 data1, dataX; };
  422.   union { s32 data2, dataY; };
  423. };
  424.  
  425. /*-WINEVENT_WIN-*/
  426.  
  427.  
  428.  
  429. /*+WINEVENT_KEY+*/
  430.  
  431. enum WindowEvent_Key_ModifierEnum {
  432.   KMOD_NONE      = 0x0000,
  433.   KMOD_LSHIFT    = 0x0001,
  434.   KMOD_RSHIFT    = 0x0002,
  435.   KMOD_LCTRL     = 0x0004,
  436.   KMOD_RCTRL     = 0x0008,
  437.   KMOD_LALT      = 0x0010,
  438.   KMOD_RALT      = 0x0020,
  439.   KMOD_LGUI      = 0x0040, //windows key?
  440.   KMOD_RGUI      = 0x0080,  //
  441.     KMOD_LWIN    = KMOD_LGUI,
  442.     KMOD_RWIN    = KMOD_RGUI,
  443.   KMOD_NUMLOCK   = 0x1000,
  444.   KMOD_CAPSLOCK  = 0x2000,
  445.   KMOD_ALTGRAPH  = 0x4000,
  446.   KMOD_SCROLLOCK = 0x8000,
  447.   KMOD_CTRL      = ( KMOD_LCTRL  | KMOD_RCTRL  ),
  448.   KMOD_SHIFT     = ( KMOD_LSHIFT | KMOD_RSHIFT ),
  449.   KMOD_ALT       = ( KMOD_LALT   | KMOD_RALT   ),
  450.   KMOD_GUI       = ( KMOD_LGUI   | KMOD_RGUI   ),
  451.   KMOD_WIN       = ( KMOD_LWIN   | KMOD_RWIN   ),
  452. };
  453.  
  454. enum WindowEvent_Key_PhysicalEnum {
  455.   //tbd
  456. };
  457.  
  458. enum WindowEvent_Key_VirtualEnum {
  459.   //(misc. mouse)       = 0x01 -> 0x06
  460.   //(reserved)          = 0x07,
  461.   VKEY_BACK             = 0x08, //backspace key
  462.     VKEY_BACKSPACE      = VKEY_BACK,
  463.   VKEY_TAB              = 0x09,
  464.   //(reserved)          = 0x0A -> 0x0B,
  465.   VKEY_CLEAR            = 0x0C,
  466.   VKEY_RETURN           = 0x0D, //enter key
  467.     VKEY_ENTER          = VKEY_RETURN,
  468.   //(unassigned)        = 0x0E -> 0x0F,
  469.   VKEY_SHIFT            = 0x10,
  470.   VKEY_CONTROL          = 0x11, //ctrl key
  471.     VKEY_CTRL           = VKEY_CONTROL,
  472.   VKEY_MENU             = 0x12, //alt key
  473.     VKEY_ALT            = VKEY_MENU,
  474.   VKEY_PAUSE            = 0x13,
  475.   VKEY_CAPITAL          = 0x14, //caps lock key
  476.     VKEY_CAPSLOCK       = VKEY_CAPITAL,
  477.   //(IME stuff)         = 0x15 -> 0x1A,
  478.   VKEY_ESCAPE           = 0x1B, //esc key
  479.   //(IME stuff)         = 0x1C -> 0x1F,
  480.   VKEY_SPACE            = 0x20, //space bar key
  481.   VKEY_PRIOR            = 0x21, //page up key
  482.     VKEY_PGUP           = VKEY_PRIOR,
  483.   VKEY_NEXT             = 0x22, //page down key
  484.     VKEY_PGDN           = VKEY_NEXT,
  485.   VKEY_END              = 0x23,
  486.   VKEY_HOME             = 0x24,
  487.   VKEY_LEFT             = 0x25, //left arrow key
  488.   VKEY_UP               = 0x26, //up arrow key
  489.   VKEY_RIGHT            = 0x27, //right arrow key
  490.   VKEY_DOWN             = 0x28, //down arrow key
  491.   VKEY_SELECT           = 0x29,
  492.   VKEY_PRINT            = 0x2A,
  493.   VKEY_EXECUTE          = 0x2B,
  494.   VKEY_SNAPSHOT         = 0x2C, //print screen key
  495.     VKEY_PRTSC          = VKEY_SNAPSHOT,
  496.   VKEY_INSERT           = 0x2D, //ins key
  497.   VKEY_DELETE           = 0x2E, //del key
  498.   VKEY_HELP             = 0x2F, //help key
  499.   VKEY_0                = 0x30, //'0'
  500.   VKEY_1                = 0x31, //'1'
  501.   VKEY_2                = 0x32, //'2'
  502.   VKEY_3                = 0x33, //'3'
  503.   VKEY_4                = 0x34, //'4'
  504.   VKEY_5                = 0x35, //'5'
  505.   VKEY_6                = 0x36, //'6'
  506.   VKEY_7                = 0x37, //'7'
  507.   VKEY_8                = 0x38, //'8'
  508.   VKEY_9                = 0x39, //'9'
  509.   //(undefined)         = 0x3A -> 0x40,
  510.   VKEY_A                = 0x41, //'A'
  511.   VKEY_B                = 0x42, //'B'
  512.   VKEY_C                = 0x43, //'C'
  513.   VKEY_D                = 0x44, //'D'
  514.   VKEY_E                = 0x45, //'E'
  515.   VKEY_F                = 0x46, //'F'
  516.   VKEY_G                = 0x47, //'G'
  517.   VKEY_H                = 0x48, //'H'
  518.   VKEY_I                = 0x49, //'I'
  519.   VKEY_J                = 0x4A, //'J'
  520.   VKEY_K                = 0x4B, //'K'
  521.   VKEY_L                = 0x4C, //'L'
  522.   VKEY_M                = 0x4D, //'M'
  523.   VKEY_N                = 0x4E, //'N'
  524.   VKEY_O                = 0x4F, //'O'
  525.   VKEY_P                = 0x50, //'P'
  526.   VKEY_Q                = 0x51, //'Q'
  527.   VKEY_R                = 0x52, //'R'
  528.   VKEY_S                = 0x53, //'S'
  529.   VKEY_T                = 0x54, //'T'
  530.   VKEY_U                = 0x55, //'U'
  531.   VKEY_V                = 0x56, //'V'
  532.   VKEY_W                = 0x57, //'W'
  533.   VKEY_X                = 0x58, //'X'
  534.   VKEY_Y                = 0x59, //'Y'
  535.   VKEY_Z                = 0x5A, //'Z'
  536.   VKEY_LWIN             = 0x5B, //left windows key
  537.   VKEY_RWIN             = 0x5C, //right windows key
  538.   VKEY_APPS             = 0x5D, //applications key
  539.   //(reserved)          = 0x5E,
  540.   VKEY_SLEEP            = 0x5F, //computer sleep key
  541.   VKEY_NUMPAD0          = 0x60,
  542.   VKEY_NUMPAD1          = 0x61,
  543.   VKEY_NUMPAD2          = 0x62,
  544.   VKEY_NUMPAD3          = 0x63,
  545.   VKEY_NUMPAD4          = 0x64,
  546.   VKEY_NUMPAD5          = 0x65,
  547.   VKEY_NUMPAD6          = 0x66,
  548.   VKEY_NUMPAD7          = 0x67,
  549.   VKEY_NUMPAD8          = 0x68,
  550.   VKEY_NUMPAD9          = 0x69,
  551.   VKEY_MULTIPLY         = 0x6A, //numpad '*'
  552.   VKEY_ADD              = 0x6B, //numpad '+'
  553.   VKEY_SEPARATOR        = 0x6C, //numpad enter
  554.   VKEY_SUBTRACT         = 0x6D, //numpad '-'
  555.   VKEY_DECIMAL          = 0x6E, //numpad '.'
  556.   VKEY_DIVIDE           = 0x6F, //numpad '/'
  557.   VKEY_F1               = 0x70,
  558.   VKEY_F2               = 0x71,
  559.   VKEY_F3               = 0x72,
  560.   VKEY_F4               = 0x73,
  561.   VKEY_F5               = 0x74,
  562.   VKEY_F6               = 0x75,
  563.   VKEY_F7               = 0x76,
  564.   VKEY_F8               = 0x77,
  565.   VKEY_F9               = 0x78,
  566.   VKEY_F10              = 0x79,
  567.   VKEY_F11              = 0x7A,
  568.   VKEY_F12              = 0x7B,
  569.   VKEY_F13              = 0x7C,
  570.   VKEY_F14              = 0x7D,
  571.   VKEY_F15              = 0x7E,
  572.   VKEY_F16              = 0x7F,
  573.   VKEY_F17              = 0x80,
  574.   VKEY_F18              = 0x81,
  575.   VKEY_F19              = 0x82,
  576.   VKEY_F20              = 0x83,
  577.   VKEY_F21              = 0x84,
  578.   VKEY_F22              = 0x85,
  579.   VKEY_F23              = 0x86,
  580.   VKEY_F24              = 0x87,
  581.   //(reserved)          = 0x88 -> 0x8F,
  582.   VKEY_NUMLOCK          = 0x90,
  583.   VKEY_SCROLL           = 0x91, //scroll lock key
  584.     VKEY_SCROLLOCK      = VKEY_SCROLL,
  585.   //(OEM-specific)      = 0x92 -> 0x96,
  586.   //(unassigned)        = 0x97 -> 0x9F,
  587.   //(l/r key variants)  = 0xA0 -> 0xA5,
  588.   //(browser keys)      = 0xA6 -> 0xAC,
  589.   VKEY_VOLUME_MUTE      = 0xAD,
  590.   VKEY_VOLUME_DOWN      = 0xAE,
  591.   VKEY_VOLUME_UP        = 0xAF,
  592.   VKEY_MEDIA_NEXT_TRACK = 0xB0,
  593.   VKEY_MEDIA_PREV_TRACK = 0xB1,
  594.   VKEY_MEDIA_STOP       = 0xB2,
  595.   VKEY_MEDIA_PLAY_PAUSE = 0xB3, //Play/Pause Media key
  596.   //(launch keys)       = 0xB4 -> 0xB7,
  597.   //(reserved)          = 0xB8 -> 0xB9,
  598.   VKEY_OEM_1            = 0xBA, //misc. chars; varies by keyboard (';',':' on US standard)
  599.     VKEY_SEMICOLON      = VKEY_OEM_1,
  600.   VKEY_OEM_PLUS         = 0xBB, //'+' in any country/region
  601.     VKEY_PLUS           = VKEY_OEM_PLUS,
  602.   VKEY_OEM_COMMA        = 0xBC, //',' in any country/region
  603.     VKEY_COMMA          = VKEY_OEM_COMMA,
  604.   VKEY_OEM_MINUS        = 0xBD, //'-' in any country/region
  605.     VKEY_MINUS          = VKEY_OEM_MINUS,
  606.   VKEY_OEM_PERIOD       = 0xBE, //'.' in any country/region
  607.     VKEY_PERIOD         = VKEY_OEM_PERIOD,
  608.   VKEY_OEM_2            = 0xBF, //misc. chars; varies by keyboard ('/','?' on US standard)
  609.     VKEY_FSLASH         = VKEY_OEM_2,
  610.   VKEY_OEM_3            = 0xC0, //misc. chars; varies by keyboard ('`','~' on US standard)
  611.     VKEY_BACKTICK       = VKEY_OEM_3,
  612.   //(reserved)          = 0xC1 -> 0xDA,
  613.   VKEY_OEM_4            = 0xDB, //misc. chars; varies by keyboard ('[','{' on US standard)
  614.     VKEY_LBRACKET       = VKEY_OEM_4,
  615.   VKEY_OEM_5            = 0xDC, //misc. chars; varies by keyboard ('\\','|' on US standard)
  616.     VKEY_BSLASH         = VKEY_OEM_5,
  617.   VKEY_OEM_6            = 0xDD, //misc. chars; varies by keyboard (']','}' on US standard)
  618.     VKEY_RBRACKET       = VKEY_OEM_6,
  619.   VKEY_OEM_7            = 0xDE, //misc. chars; varies by keyboard ('\'','\"' on US standard)
  620.     VKEY_APOSTROPHE     = VKEY_OEM_7,
  621.   VKEY_OEM_8            = 0xDF, //misc. chars; varies by keyboard
  622.   //(reserved)          = 0xE0,
  623.   //(misc.)             = 0xE1 -> 0xE7,
  624.   //(unassigned)        = 0xE8,
  625.   //(misc.)             = 0xE9 -> 0xFE,
  626. };
  627.  
  628.  
  629. union WindowEvent_Key_Mod { //2B
  630.   struct {
  631.     u16 lshift    : 1;
  632.     u16 rshift    : 1;
  633.     u16 lctrl     : 1;
  634.     u16 rctrl     : 1;
  635.     u16 lalt      : 1;
  636.     u16 ralt      : 1;
  637.     u16 lgui      : 1;
  638.     u16 rgui      : 1;
  639.     u16 _unused   : 4;
  640.     u16 numlock   : 1;
  641.     u16 capslock  : 1;
  642.     u16 altgraph  : 1;
  643.     u16 scrollock : 1;
  644.   };
  645.   u16 all;
  646. };
  647.  
  648. struct WindowEvent_Key_Sym { //8B
  649.   union {
  650.     WindowEvent_Key_Mod kmod;
  651.     u16  kmods;
  652.   };
  653.   u8  _unused;
  654.   u8   pkey; //physical key code (named .scancode in SDL's Keysym struct)
  655.   u8   vkey; //virtual key code (named .sym in SDL's Keysym struct)
  656.   bool pressed;
  657.   bool ischar; //'is event KEY_CHAR?', otherwise it's KEY_UP or KEY_DOWN
  658.   bool repeat;
  659. };
  660.  
  661. struct WindowEvent_Key { //24B
  662.   u32 type;
  663.   u32 winIndex;
  664.   u64 timestamp;
  665.   union {
  666.     struct { //(basically a copy of WindowEvent_Key_Sym)
  667.       u16  kmods;
  668.       u8  _unused;
  669.       u8   pkey;
  670.       u8   vkey;
  671.       bool pressed;
  672.       bool ischar;
  673.       bool repeat;
  674.     };
  675.     WindowEvent_Key_Sym sym;
  676.   };
  677. };
  678.  
  679. /*-WINEVENT_KEY-*/
  680.  
  681.  
  682.  
  683. /*+WINEVENT_MOUSE+*/
  684.  
  685. //how many steps between mouse wheel notches
  686. #define KIT_MOUSE_WHEEL_DELTA (120)
  687.  
  688.  
  689. enum WindowEvent_Mouse_ButtonEnum {
  690.   MBUTTON_LEFT   = 0x01,
  691.   MBUTTON_MIDDLE = 0x02,
  692.   MBUTTON_RIGHT  = 0x04,
  693.   MBUTTON_X1     = 0x08,
  694.   MBUTTON_X2     = 0x10,
  695. };
  696.  
  697.  
  698. struct WindowEvent_Mouse { //40B
  699.   u32  type;
  700.   u32  winIndex;
  701.   u64  timestamp;
  702.   s32  x;  //coordinates relative to window
  703.   s32  y;   //^^
  704.   s32  dx; //delta x (coordinates relative to last recorded x position)
  705.   s32  dy; //delta y (coordinates relative to last recorded y position)
  706.   s32  data; //currently used to store the value of wheel events before delta is applied
  707.   u8  _unused;
  708.   u8   button;   //flags for currently pressed buttons (WindowEvent_Mouse_ButtonEnum)
  709.   bool pressed;  //will be true if button is nonzero
  710.   bool dblClick; //'is double click?'
  711. };
  712.  
  713. /*-WINEVENT_MOUSE-*/
  714.  
  715.  
  716.  
  717. union WindowEvent { //<whatever the largest event is>B
  718.   u32                type;
  719.   WindowEvent_Common common;
  720.   WindowEvent_Win    win;
  721.   WindowEvent_Key    key;
  722.   WindowEvent_Mouse  mouse;
  723.   WindowEvent() : type(WINEVENT_NULL) {}
  724. };
  725.  
  726.  
  727.  
  728.  
  729. };
  730.  
  731. #endif /* _KIT_INC__VIDEO_WINDOWEVENT_HPP */
  732.  
  733. /*-include\kit\_video_WindowEvent.hpp-*/
  734.  
  735.  
  736. /*+include\kit\all.hpp+*/
  737.  
  738. #ifndef _KIT_INC_ALL_HPP
  739. #define _KIT_INC_ALL_HPP
  740.  
  741. #include "commondef.hpp"
  742. #include "misc.hpp"
  743. #include "video.hpp"
  744.  
  745.  
  746. #endif /* _KIT_INC_ALL_HPP */
  747.  
  748. /*-include\kit\all.hpp-*/
  749.  
  750.  
  751. /*+include\kit\commondef.hpp+*/
  752.  
  753. #ifndef _KIT_INC_COMMONDEF_HPP
  754. #define _KIT_INC_COMMONDEF_HPP
  755.  
  756. namespace kit {
  757.  
  758.  
  759.  
  760.  
  761. #ifndef   MIN
  762. #define   MIN(a,b) ( ((a)<(b)) ? (a) : (b) )
  763. #endif /* MIN(a,b) */
  764.  
  765. #ifndef   MAX
  766. #define   MAX(a,b) ( ((a)>(b)) ? (a) : (b) )
  767. #endif /* MAX(a,b) */
  768.  
  769. #ifndef   CLAMP
  770. #define   CLAMP(n, mn, mx) MIN(MAX(n,mn),mx)
  771. #endif /* CLAMP(n, mn, mx) */
  772.  
  773.  
  774.  
  775. // integer bounds
  776. #define KIT_U8_MAX  (0xff)
  777. #define KIT_U16_MAX (0xffff)
  778. #define KIT_U32_MAX (0xffffffff)
  779. #define KIT_U64_MAX (0xffffffffffffffff)
  780.  //
  781. #define KIT_S8_MIN  (-0x80)
  782. #define KIT_S8_MAX  ( 0x7f)
  783. #define KIT_S16_MIN (-0x8000)
  784. #define KIT_S16_MAX ( 0x7fff)
  785. #define KIT_S32_MIN (-0x80000000)
  786. #define KIT_S32_MAX ( 0x7fffffff)
  787. #define KIT_S64_MIN (-0x8000000000000000)
  788. #define KIT_S64_MAX ( 0x7fffffffffffffff)
  789.  
  790.  
  791. // most significant bits/Bytes
  792. #define KIT_MSb_8  (0x80)
  793. #define KIT_MSb_16 (0x8000)
  794. #define KIT_MSb_32 (0x80000000)
  795. #define KIT_MSb_64 (0x8000000000000000)
  796.  //
  797. #define KIT_MSB_8  (0xff)
  798. #define KIT_MSB_16 (0xff00)
  799. #define KIT_MSB_32 (0xff000000)
  800. #define KIT_MSB_64 (0xff00000000000000)
  801.  
  802.  
  803.  
  804.  
  805. #if defined(_STDINT) || defined(_CSTDINT_)
  806. typedef uint8_t  u8 ;
  807. typedef uint16_t u16;
  808. typedef uint32_t u32;
  809. typedef uint64_t u64;
  810. typedef int8_t  s8 ;
  811. typedef int16_t s16;
  812. typedef int32_t s32;
  813. typedef int64_t s64;
  814.  
  815. #else
  816. typedef unsigned char      u8 ;
  817. typedef unsigned short     u16;
  818. typedef unsigned int       u32;
  819. typedef unsigned long long u64;
  820. typedef signed char      s8 ;
  821. typedef signed short     s16;
  822. typedef signed int       s32;
  823. typedef signed long long s64;
  824.  
  825. #endif
  826.  
  827. // for consistency
  828. typedef float  f32;
  829. typedef double f64;
  830.  
  831.  
  832.  
  833. typedef void* _GenericOpaquePtr;
  834.  
  835.  
  836.  
  837. };
  838.  
  839. #endif /* _KIT_INC_COMMONDEF_HPP */
  840.  
  841. /*-include\kit\commondef.hpp-*/
  842.  
  843.  
  844. /*+include\kit\misc.hpp+*/
  845.  
  846. #ifndef _KIT_INC_VIDEO_MISC_HPP
  847. #define _KIT_INC_VIDEO_MISC_HPP
  848.  
  849. #include "commondef.hpp"
  850. #include "_misc_Mutex.hpp"
  851. #include "_misc_time.hpp"
  852.  
  853.  
  854. #endif /* _KIT_INC_VIDEO_MISC_HPP */
  855.  
  856. /*-include\kit\misc.hpp-*/
  857.  
  858.  
  859. /*+include\kit\video.hpp+*/
  860.  
  861. #ifndef _KIT_INC_VIDEO_HPP
  862. #define _KIT_INC_VIDEO_HPP
  863.  
  864. #include "commondef.hpp"
  865. #include "_video_misc.hpp"
  866. #include "_video_Window.hpp"
  867. #include "_video_Bitmap.hpp"
  868.  
  869.  
  870. #endif /* _KIT_INC_VIDEO_HPP */
  871.  
  872. /*-include\kit\video.hpp-*/
  873.  
  874.  
  875. /*+src\kit_win32\_kit_globals.hpp+*/
  876.  
  877. #ifndef _KIT_SRC_KIT_GLOBALS_HPP
  878. #define _KIT_SRC_KIT_GLOBALS_HPP
  879.  
  880. /* tbd:
  881. bitmap stuff
  882. when blitting, allow for nullptr rect so that the entire thing can be copied
  883.   (also, add separate 'blitAll' function that uses only a destination position)
  884. */
  885.  
  886. #include <windowsx.h>
  887. #include <Windows.h>
  888. #include <string.h>
  889.  
  890. #ifdef _DEBUG
  891. #define _printf(_fmt,...) printf(_fmt,__VA_ARGS__)
  892. #else
  893. #define _printf(_fmt,...)
  894. #endif
  895.  
  896. #if defined(_DEBUG)
  897. #include <stdio.h>
  898. #define loghere printf("line %4i: (%s)\n",__LINE__,__FILE__);
  899. #else
  900. #define loghere  /* do {} while(0); */
  901. #endif /* _DEBUG */
  902.  
  903.  
  904. #define KIT_LOCK_SPINCOUNT (2048)
  905.  
  906.  
  907. //used for Window and Bitmap
  908. #define KIT_INITIAL_STRETCH_MODE COLORONCOLOR
  909.  
  910.  
  911. //class type ID numbers
  912. #define KIT_CONTAINS_OPAQUE (0x80000000)
  913. #define KIT_CLASSTYPE_NULL        (0)
  914. #define KIT_CLASSTYPE_MUTEXSIMPLE (1 | KIT_CONTAINS_OPAQUE)
  915. #define KIT_CLASSTYPE_WINDOW      (2 | KIT_CONTAINS_OPAQUE)
  916. #define KIT_CLASSTYPE_BITMAP      (3 | KIT_CONTAINS_OPAQUE)
  917.  
  918.  
  919. namespace kit {
  920.  
  921.  
  922.  
  923.  
  924. /*++++++++++*/
  925. /*+kit_main+*/
  926. /*++++++++++*/
  927.  
  928. namespace w32 {
  929.  
  930.  
  931.  
  932. extern HINSTANCE hThisInst;
  933. extern HINSTANCE hPrevInst;
  934. extern LPSTR     lpszArg;
  935. extern int       nCmdShow;
  936.  
  937. extern LARGE_INTEGER ticksPerSecond; //used in time::getTicksPerSecond()
  938.  
  939.  
  940.  
  941. };
  942.  
  943. /*++++++++++*/
  944. /*+kit_main+*/
  945. /*++++++++++*/
  946.  
  947.  
  948.  
  949.  
  950. };
  951.  
  952.  
  953. #endif /* _KIT_SRC_KIT_GLOBALS_HPP */
  954.  
  955. /*-src\kit_win32\_kit_globals.hpp-*/
  956.  
  957.  
  958. /*+src\kit_win32\kit_Bitmap_shared.hpp+*/
  959.  
  960. #ifndef _KIT_SRC_KIT_BITMAP_SHARED_HPP
  961. #define _KIT_SRC_KIT_BITMAP_SHARED_HPP
  962.  
  963. #include "_kit_globals.hpp"
  964.  
  965.  
  966. namespace kit {
  967.  
  968.  
  969.  
  970.  
  971. /*++++++++++++*/
  972. /*+kit_Bitmap+*/
  973. /*++++++++++++*/
  974.  
  975. struct _BitmapOpaque {
  976.   BITMAPINFO   info;
  977.   HBITMAP      handle;
  978.   color::ARGB* pixels;
  979.   shape::point size;
  980.   HDC          devCtx;
  981.   s32          stretchMode; //stretch mode when used as blit destination
  982.   u8          _unused[3];
  983.   //false for CreateDIBitmap() bitmap, true for CreateDIBSection() bitmap
  984.   bool         directAccess;
  985. };
  986.  
  987.  
  988.  
  989. //returns true on success
  990. static inline bool PopulateBitmapOpaque(_BitmapOpaque& bmp,
  991.                                         const color::ARGB* pixelData,
  992.                                         s32 width, s32 height,
  993.                                         bool directAccess)
  994. {
  995.   //fill in internal bitmap info
  996.   bmp.info.bmiHeader.biSize        = sizeof(BITMAPINFOHEADER);
  997.   bmp.info.bmiHeader.biWidth       = width;
  998.   bmp.info.bmiHeader.biHeight      = height;
  999.   bmp.info.bmiHeader.biPlanes      = 1;      //should always be 1
  1000.   bmp.info.bmiHeader.biBitCount    = 32;     //for 0x--RRGGBB
  1001.   bmp.info.bmiHeader.biCompression = BI_RGB; //uncompressed rgb
  1002.  
  1003.   bmp.pixels = nullptr;
  1004.  
  1005.   bmp.size.x = width;
  1006.   bmp.size.y = height;
  1007.  
  1008.   //create the bitmap's device context (for rendering directly to the bitmap)
  1009.   bmp.stretchMode  = KIT_INITIAL_STRETCH_MODE;
  1010.  
  1011.   //determines whether you can edit the bitmap color data directly
  1012.   bmp.directAccess = directAccess;
  1013.  
  1014.  
  1015.   bmp.devCtx = CreateCompatibleDC(nullptr);
  1016.   if(bmp.devCtx == nullptr) return false;
  1017.  
  1018.  
  1019.   if(directAccess){
  1020.     bmp.handle = CreateDIBSection(nullptr, &bmp.info, DIB_RGB_COLORS,
  1021.                                   (void**)&bmp.pixels, nullptr, 0);
  1022.     if(pixelData!=nullptr && bmp.pixels!=nullptr)
  1023.       memcpy(bmp.pixels, pixelData, sizeof(color::ARGB)*width*height);
  1024.   } else {
  1025.     bmp.handle = CreateDIBitmap(nullptr, (BITMAPINFOHEADER*)&bmp.info,
  1026.                                 (pixelData != nullptr) ? CBM_INIT : 0,
  1027.                                 pixelData, &bmp.info, DIB_RGB_COLORS);
  1028.   }
  1029.  
  1030.  
  1031.   if(bmp.handle != nullptr){
  1032.     SelectObject(bmp.devCtx, bmp.handle);
  1033.     SetStretchBltMode(bmp.devCtx, KIT_INITIAL_STRETCH_MODE);
  1034.     return true;
  1035.   } else {
  1036.     DeleteDC(bmp.devCtx);
  1037.     bmp.devCtx = nullptr;
  1038.     return false;
  1039.   }
  1040. }
  1041.  
  1042.  
  1043.  
  1044. static inline bool ResizeBitmapOpaque(_BitmapOpaque& bmp,
  1045.                                       s32 width, s32 height)
  1046. {
  1047.   //set dimensions of bitmap to new values
  1048.   bmp.size.x = width;
  1049.   bmp.size.y = height; //working with shape::point is a lot prettier than...
  1050.   bmp.info.bmiHeader.biWidth  = width; //...whatever this is
  1051.   bmp.info.bmiHeader.biHeight = height;
  1052.  
  1053.  
  1054.   //delete old bitmap
  1055.   if(bmp.handle != nullptr) DeleteObject(bmp.handle);
  1056.  
  1057.  
  1058.   //create new bitmap
  1059.   if(bmp.directAccess){
  1060.     bmp.handle = CreateDIBSection(nullptr, &bmp.info, DIB_RGB_COLORS,
  1061.                                   (void**)&bmp.pixels, nullptr, 0);
  1062.  
  1063.   } else {
  1064.     bmp.handle = CreateDIBitmap(nullptr, (BITMAPINFOHEADER*)&bmp.info,
  1065.                                 0, nullptr, &bmp.info, DIB_RGB_COLORS);
  1066.   }
  1067.  
  1068.  
  1069.   //bind device context to new bitmap
  1070.   SelectObject(bmp.devCtx, bmp.handle);
  1071.  
  1072.  
  1073.   return true;
  1074. }
  1075.  
  1076. /*------------*/
  1077. /*-kit_Bitmap-*/
  1078. /*------------*/
  1079.  
  1080.  
  1081.  
  1082.  
  1083. };
  1084.  
  1085. #endif /* _KIT_SRC_KIT_BITMAP_SHARED_HPP */
  1086.  
  1087. /*-src\kit_win32\kit_Bitmap_shared.hpp-*/
  1088.  
  1089.  
  1090. /*+src\kit_win32\kit_Window_shared.hpp+*/
  1091.  
  1092. #ifndef _KIT_SRC_KIT_WINDOW_SHARED_HPP
  1093. #define _KIT_SRC_KIT_WINDOW_SHARED_HPP
  1094.  
  1095. #include <kit/_video_Window.hpp>
  1096. #include "_kit_globals.hpp"
  1097. #include "kit_Bitmap_shared.hpp"
  1098.  
  1099.  
  1100. namespace kit {
  1101.  
  1102.  
  1103.  
  1104.  
  1105. union WindowEvent;
  1106.  
  1107.  
  1108.  
  1109.  
  1110. /*++++++++++++*/
  1111. /*+kit_Window+*/
  1112. /*++++++++++++*/
  1113.  
  1114. namespace w32 {
  1115.   extern u32         winCount; //number of existing kit::Window instances
  1116.   extern const char  winClassName[];
  1117.   extern WNDCLASSEXA winClass;
  1118.   extern ATOM        winClassAtom;
  1119. };
  1120.  
  1121.  
  1122.  
  1123. struct _WindowOpaque {
  1124.   CRITICAL_SECTION lock;
  1125.  
  1126.   //eventQueueEnd indicates what index should be queued to next,
  1127.    //while eventQueueNext indicates what index should be dequeued next
  1128.    //(if they are the same, that means the queue is empty!)
  1129.   WindowEvent* eventQueue;
  1130.   u16          eventQueueNext;
  1131.   u16          eventQueueEnd;
  1132.  
  1133.   u32         winIndex;
  1134.   HWND        winHandle;
  1135.   shape::rect winRect; //contains both window position, and window size
  1136.   DWORD       winFlags;
  1137.   DWORD       winFlagsEx;
  1138.   bool        winFullscreen;
  1139.   bool        winShown;
  1140.   bool        winFocus;
  1141.   bool        winClosed; //true if window has been destroyed, false otherwise
  1142.  
  1143.   WindowEvent_Key_Mod kmod; //key modifier flags for key events (shift, ctrl, ...)
  1144.  
  1145.   //set to true after first WINEVENT_MOUSE_MOVE since entering client area
  1146.   bool mouseWasMovedBefore;
  1147.  
  1148.   bool          canvasStretch; //if false, canvas is resized alongside window
  1149.   _BitmapOpaque canvas;
  1150.  
  1151.   shape::point mousePosition;
  1152.  
  1153.   bool keyStates[256]; //true if a virtual key code's key is currently pressed
  1154. };
  1155.  
  1156. /*------------*/
  1157. /*-kit_Window-*/
  1158. /*------------*/
  1159.  
  1160.  
  1161.  
  1162.  
  1163. /*+++++++++++++++++++++++*/
  1164. /*+kit_Window_WindowProc+*/
  1165. /*+++++++++++++++++++++++*/
  1166.  
  1167. namespace w32 {
  1168.  
  1169.  
  1170.  
  1171. extern LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM);
  1172.  
  1173.  
  1174.  
  1175. };
  1176.  
  1177. /*-----------------------*/
  1178. /*-kit_Window_WindowProc-*/
  1179. /*-----------------------*/
  1180.  
  1181.  
  1182.  
  1183.  
  1184. static inline shape::rect ConvertToKitRect(RECT& rectIn){
  1185.   shape::rect rectOut;
  1186.   rectOut.x = rectIn.left;
  1187.   rectOut.y = rectIn.top;
  1188.   rectOut.w = rectIn.right  - rectIn.left;
  1189.   rectOut.h = rectIn.bottom - rectIn.top;
  1190.   return rectOut;
  1191. }
  1192.  
  1193.  
  1194.  
  1195. static inline RECT ConvertFromKitRect(shape::rect& rectIn){
  1196.   RECT rectOut;
  1197.   rectOut.left   = rectIn.x;
  1198.   rectOut.top    = rectIn.y;
  1199.   rectOut.right  = rectIn.x + rectIn.w;
  1200.   rectOut.bottom = rectIn.y + rectIn.h;
  1201.   return rectOut;
  1202. }
  1203.  
  1204.  
  1205.  
  1206.  
  1207. //assumes window is without a menu
  1208. static inline shape::point CalculateWindowSize(u32 innerWidth, u32 innerHeight,
  1209.                                                u32 flags,      u32 flagsEx)
  1210. {
  1211.   RECT winSize;
  1212.   winSize.left   = 0;
  1213.   winSize.top    = 0;
  1214.   winSize.right  = innerWidth;
  1215.   winSize.bottom = innerHeight;
  1216.   AdjustWindowRectEx(&winSize, flags, false, flagsEx);
  1217.  
  1218.   shape::point winSizeAdjusted;
  1219.   winSizeAdjusted.x = winSize.right  - winSize.left;
  1220.   winSizeAdjusted.y = winSize.bottom - winSize.top;
  1221.   return winSizeAdjusted;
  1222. }
  1223.  
  1224.  
  1225.  
  1226.  
  1227. static inline void HandlePreCreationWindowFlags(_WindowOpaque* opq,
  1228.                                                 u32 kitWinFlags)
  1229. {
  1230.   //pre-creation window flag handling (save for WINFLAG_FULLSCREEN)
  1231.   opq->winFlags   = WS_OVERLAPPEDWINDOW; //will be hidden initially
  1232.   opq->winFlagsEx = 0;
  1233.  
  1234.  
  1235.   if(kitWinFlags & WINFLAG_FULLSCREEN) opq->winFullscreen = true;
  1236.  
  1237.  
  1238.   if(kitWinFlags & WINFLAG_BORDERLESS){
  1239.     kitWinFlags &= ~WINFLAG_RESIZABLE;
  1240.     opq->winFlags |=  WS_POPUP;
  1241.     opq->winFlags &= ~WS_CAPTION;
  1242.     opq->winFlags &= ~WS_SYSMENU;
  1243.   }
  1244.  
  1245.   if(!(kitWinFlags & WINFLAG_RESIZABLE)) opq->winFlags &= ~WS_THICKFRAME;
  1246.  
  1247.   if(kitWinFlags & WINFLAG_MINIMIZED) opq->winFlags |= WS_MINIMIZE;
  1248.   if(kitWinFlags & WINFLAG_MAXIMIZED) opq->winFlags |= WS_MAXIMIZE;
  1249. }
  1250.  
  1251.  
  1252.  
  1253.  
  1254. //returns false if queue is full
  1255. static inline bool AddToEventQueue(_WindowOpaque* opq, WindowEvent& event){
  1256.   if((opq->eventQueueEnd+1) != opq->eventQueueNext){
  1257.     opq->eventQueue[opq->eventQueueEnd++] = event;
  1258.     return true;
  1259.   } else { //don't add to queue if doing so would overwrite a previous event
  1260.     return false;
  1261.   }
  1262. }
  1263.  
  1264.  
  1265.  
  1266. //returns a WINEVENT_NULL event if queue is empty
  1267. static inline WindowEvent RemoveFromEventQueue(_WindowOpaque* opq){
  1268.   if(opq->eventQueueNext != opq->eventQueueEnd){
  1269.     return opq->eventQueue[opq->eventQueueNext++];
  1270.   } else {
  1271.     static WindowEvent nullEvent; //should auto-initialize to type WINEVENT_NULL
  1272.     return nullEvent;
  1273.   }
  1274. }
  1275.  
  1276.  
  1277.  
  1278.  
  1279. };
  1280.  
  1281. #endif /* _KIT_SRC_KIT_WINDOW_SHARED_HPP */
  1282.  
  1283. /*-src\kit_win32\kit_Window_shared.hpp-*/
  1284.  
  1285.  
  1286. /*+src\kit_win32\kit_Window_WindowProcEvent.hpp+*/
  1287.  
  1288. #ifndef _KIT_SRC_KIT_WINDOW_WINDOWPROCEVENT_HPP
  1289. #define _KIT_SRC_KIT_WINDOW_WINDOWPROCEVENT_HPP
  1290.  
  1291. #include <kit/_video_WindowEvent.hpp>
  1292. #include "_kit_globals.hpp"
  1293.  
  1294. //(the WindowEvent used inside WindowProc is named "event")
  1295. #define KIT_HANDLE_EVENT(_name,...) \
  1296.   kit::WindowProcEvent::_name(event,__VA_ARGS__)
  1297.  
  1298.  
  1299. namespace kit {
  1300.  
  1301.  
  1302. namespace WindowProcEvent {
  1303.  
  1304.  
  1305.  
  1306.  
  1307. /*+WINEVENT_WIN+*/
  1308.  
  1309. //triggered when a window requests to be closed
  1310. static inline void WIN_CLOSE(WindowEvent& event){
  1311.   event.type = WINEVENT_WIN_CLOSE;
  1312. }
  1313.  
  1314.  
  1315.  
  1316. static inline void WIN_MOVED(WindowEvent& event, shape::rect& newRect){
  1317.   event.type = WINEVENT_WIN_MOVED;
  1318.   //(dataX&Y are unioned with data1&2)
  1319.   event.win.dataX = newRect.x; //new horizontal position
  1320.   event.win.dataY = newRect.y; //new vertical position
  1321. }
  1322.  
  1323.  
  1324. static inline void WIN_RESIZED(WindowEvent& event, shape::rect& newRect){
  1325.   event.type = WINEVENT_WIN_RESIZED;
  1326.   //(dataX&Y are unioned with data1&2)
  1327.   event.win.dataX = newRect.w; //new width
  1328.   event.win.dataY = newRect.h; //new height
  1329. }
  1330.  
  1331.  
  1332.  
  1333. static inline void WIN_UNFOCUSING(WindowEvent& event){
  1334.   event.type = WINEVENT_WIN_UNFOCUSING;
  1335. }
  1336.  
  1337.  
  1338. static inline void WIN_FOCUSED(WindowEvent& event){
  1339.   event.type = WINEVENT_WIN_FOCUSED;
  1340. }
  1341.  
  1342. /*-WINEVENT_WIN-*/
  1343.  
  1344.  
  1345.  
  1346.  
  1347. /*+WINEVENT_KEY+*/
  1348.  
  1349. union KEY_Params {
  1350.   struct {
  1351.     u32 repeatCount   : 16; // 0 -> 15
  1352.     u32 scanCode      :  8; //16 -> 23
  1353.     u32 extendedKey   :  1; //24
  1354.     u32 _reserved     :  4; //25 -> 28
  1355.     u32 altKeyDown    :  1; //29
  1356.     u32 prevUnpressed :  1; //30
  1357.     u32 currUnpressed :  1; //31
  1358.   };
  1359.   u32 value;
  1360.   KEY_Params(u32 _value) : value(_value) {}
  1361. };
  1362.  
  1363.  
  1364.  
  1365. //this event handler is used for KEY_CHAR, KEY_UP, and KEY_DOWN events
  1366. static inline void KEY_CHARUPDOWN(WindowEvent& event,
  1367.                                   bool charEvent,     u8 virtualKeyCode,
  1368.                                   KEY_Params& params, u16 kmods)
  1369. {
  1370.   if(charEvent){
  1371.     event.type = WINEVENT_KEY_CHAR;
  1372.   } else {
  1373.     if(params.currUnpressed) event.type = WINEVENT_KEY_UP;
  1374.     else                     event.type = WINEVENT_KEY_DOWN;
  1375.   }
  1376.  
  1377.   event.key.kmods = kmods;
  1378.  
  1379.   event.key.pkey = params.scanCode;
  1380.   event.key.vkey = virtualKeyCode;
  1381.  
  1382.   event.key.pressed = !params.currUnpressed;
  1383.   event.key.repeat  = params.repeatCount>0; //modified to act as a boolean
  1384.   event.key.ischar  = charEvent;
  1385. }
  1386.  
  1387. /*-WINEVENT_KEY-*/
  1388.  
  1389.  
  1390.  
  1391.  
  1392. /*+WINEVENT_MOUSE+*/
  1393.  
  1394. union MOUSE_ButtonStates {
  1395.   struct {
  1396.     u8 left    : 1;
  1397.     u8 middle  : 1;
  1398.     u8 right   : 1;
  1399.     u8 x1      : 1;
  1400.     u8 x2      : 1;
  1401.     u8 _unused : 3;
  1402.   };
  1403.   u8 value;
  1404.   MOUSE_ButtonStates() : value(0) {}
  1405.   MOUSE_ButtonStates(u8 _value) : value(_value) {}
  1406. };
  1407.  
  1408.  
  1409.  
  1410. //MOUSE_MOVED was already taken by a win32 macro >:(
  1411. static inline void MOUSE_MOVE(WindowEvent& event, u8 buttonStates,
  1412.                               shape::point& previous, shape::point& current)
  1413. {
  1414.   event.type = WINEVENT_MOUSE_MOVE;
  1415.  
  1416.   event.mouse.x = current.x;
  1417.   event.mouse.y = current.y;
  1418.  
  1419.   event.mouse.dx = current.x - previous.x;
  1420.   event.mouse.dy = current.y - previous.y;
  1421.  
  1422.   event.mouse.button  = buttonStates;
  1423.   event.mouse.pressed = buttonStates!=0;
  1424. }
  1425.  
  1426.  
  1427. static inline void MOUSE_LEAVE(WindowEvent& event){
  1428.   event.type = WINEVENT_MOUSE_LEAVE;
  1429. }
  1430.  
  1431.  
  1432. static inline void MOUSE_ENTER(WindowEvent& event){
  1433.   event.type = WINEVENT_MOUSE_ENTER;
  1434. }
  1435.  
  1436.  
  1437. //same event handler is used for both MOUSE_UP and MOUSE_DOWN events
  1438. static inline void MOUSE_UPDOWN(WindowEvent& event, shape::point& clickPosition,
  1439.                                 u8 buttonStates, bool pressed, bool doubleClick)
  1440. {
  1441.   if(pressed) event.type = WINEVENT_MOUSE_DOWN;
  1442.   else        event.type = WINEVENT_MOUSE_UP;
  1443.  
  1444.   event.mouse.x = clickPosition.x;
  1445.   event.mouse.y = clickPosition.y;
  1446.  
  1447.   event.mouse.button   = buttonStates;
  1448.   event.mouse.pressed  = pressed;
  1449.   event.mouse.dblClick = doubleClick;
  1450. }
  1451.  
  1452.  
  1453. //same event handler is used for both MOUSE_HWHEEL and MOUSE_VWHEEL events
  1454. static inline void MOUSE_HVWHEEL(WindowEvent& event,
  1455.                                  bool verticalScroll, s16 scrollAmount,
  1456.                                  u8 buttonStates, shape::point& mousePos)
  1457. {
  1458.   if(verticalScroll){
  1459.     event.type = WINEVENT_MOUSE_VWHEEL;
  1460.     event.mouse.dy = scrollAmount/WHEEL_DELTA;
  1461.   } else {
  1462.     event.type = WINEVENT_MOUSE_HWHEEL;
  1463.     event.mouse.dx = scrollAmount/WHEEL_DELTA;
  1464.   }
  1465.  
  1466.   event.mouse.x = mousePos.x;
  1467.   event.mouse.y = mousePos.y;
  1468.  
  1469.   event.mouse.data = scrollAmount; //the scroll value before delta is applied
  1470.  
  1471.   event.mouse.button  = buttonStates;
  1472.   event.mouse.pressed = buttonStates!=0;
  1473. }
  1474.  
  1475. /*-WINEVENT_MOUSE-*/
  1476.  
  1477.  
  1478.  
  1479.  
  1480. }; /* WindowProcEvent */
  1481.  
  1482.  
  1483. }; /* namespace kit */
  1484.  
  1485. #endif /* _KIT_SRC_KIT_WINDOW_WINDOWPROCEVENT_HPP */
  1486.  
  1487. /*-src\kit_win32\kit_Window_WindowProcEvent.hpp-*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement