Advertisement
Ryukuo

Lychee Window Test: Sizer

May 25th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.07 KB | None | 0 0
  1. #include <windows.h>
  2. #include "window.h"
  3. #include "generic.h"
  4. #include "tabcontrol.h"
  5. #include "tabcontrolex.h"
  6. #include "button.h"
  7. #include "sizer.h"
  8. #include "checkbox.h"
  9.  
  10. #pragma comment (lib, "Lychee.lib")
  11.  
  12. #ifdef _UNICODE
  13. #if defined _M_IX86
  14. #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
  15. #elif defined _M_IA64
  16. #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")
  17. #elif defined _M_X64
  18. #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
  19. #else
  20. #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
  21. #endif
  22. #endif
  23.  
  24. class mainwindow {
  25. public:
  26.     hinstance hinst;
  27.     window *w;
  28.  
  29. public:
  30.     button *btn1;
  31.     checkbox *checkbox1;
  32.     checkbox *checkbox2;
  33.     checkbox *checkbox3;
  34.     checkbox *checkbox4;
  35.     checkbox *checkbox1_2;
  36.     checkbox *checkbox2_2;
  37.     checkbox *checkbox3_2;
  38.     checkbox *checkbox4_2;
  39.     sizer *sizer1;
  40.     sizer *sizer2;
  41.     sizer *sizer3;
  42.     sizer *sizer4;
  43.  
  44.     enum LYCHEE_TEST_ID : uint32_t {
  45.  
  46.         BUTTON1 = 1,
  47.  
  48.     };
  49.  
  50. public:
  51.  
  52.     static LYCHEE_FUNCTION(on_button1, {
  53.         MessageBox(0, L"Button1 Clicked", 0, 0);
  54.        
  55.     })
  56.  
  57.     static void on_size(hwnd wnd, wparam w, lparam l, lpvoid parameter) {
  58.         rectangle r = window::get_window(wnd)->get_client_rectangle();
  59.  
  60.         reinterpret_cast<mainwindow*>(parameter)->btn1->expand_horizontal();
  61.         reinterpret_cast<mainwindow*>(parameter)->sizer3->size(r.right / 2 - 13);
  62.         reinterpret_cast<mainwindow*>(parameter)->sizer3->pos(6, 25);
  63.     }
  64.  
  65.     static void on_create(hwnd wnd, wparam w, lparam l, lpvoid parameter) {
  66.         mainwindow *m = reinterpret_cast<mainwindow*>(parameter);
  67.        
  68.  
  69.         m->btn1 = new button(mainwindow::BUTTON1, 0, 0, 0, 0, L"button1", wnd);
  70.        
  71.         m->btn1->set_window_size(0, 20);
  72.         m->btn1->set_window_pos(0, 5);
  73.         m->btn1->expand_horizontal(5);
  74.  
  75.         rectangle r = window::get_window(wnd)->get_client_rectangle();
  76.  
  77.         m->checkbox1 = new checkbox(mainwindow::BUTTON1, 0, 0, 0, 0, L"checkbox1", wnd);
  78.         m->checkbox2 = new checkbox(mainwindow::BUTTON1, 0, 0, 0, 0, L"checkbox2", wnd);
  79.         m->checkbox3 = new checkbox(mainwindow::BUTTON1, 0, 0, 0, 0, L"checkbox3", wnd);
  80.         m->checkbox4 = new checkbox(mainwindow::BUTTON1, 0, 0, 0, 0, L"checkbox4", wnd);
  81.  
  82.         m->sizer1 = new sizer(sizer::orientation::vertical, 25);
  83.         m->sizer1->add(std::vector<widget*>({ m->checkbox1, m->checkbox2, m->checkbox3, m->checkbox4 }));
  84.  
  85.         m->checkbox1_2 = new checkbox(mainwindow::BUTTON1, 0, 0, 0, 0, L"checkbox5", wnd);
  86.         m->checkbox2_2 = new checkbox(mainwindow::BUTTON1, 0, 0, 0, 0, L"checkbox6", wnd);
  87.         m->checkbox3_2 = new checkbox(mainwindow::BUTTON1, 0, 0, 0, 0, L"checkbox7", wnd);
  88.         m->checkbox4_2 = new checkbox(mainwindow::BUTTON1, 0, 0, 0, 0, L"checkbox8", wnd);
  89.  
  90.         m->sizer2 = new sizer(sizer::orientation::vertical, 25);
  91.         m->sizer2->add(std::vector<widget*>({ m->checkbox1_2, m->checkbox2_2, m->checkbox3_2, m->checkbox4_2 }));
  92.            
  93.         m->sizer3 = new sizer(sizer::orientation::horizontal);
  94.         m->sizer3->add(m->sizer1);
  95.         m->sizer3->add(m->sizer2);
  96.         m->sizer3->size(r.right / 2 - 13);
  97.         m->sizer3->pos(6, 25);
  98.         m->sizer3->insert_hyphen();
  99.  
  100.     }
  101.  
  102.     mainwindow(hinstance hinst) {
  103.         this->hinst = hinst;
  104.         w = new window(hinst, L"Lychee Tester Window", L"CLychee", &on_create, this, 500, 500);
  105.  
  106.         w->add_wndproc_listener(WM_SIZE, &on_size, false, this);
  107.         w->add_message_handler(mainwindow::BUTTON1, &on_button1);
  108.     }
  109.  
  110.     int message_loop() {
  111.         return w->handle_message();
  112.     }
  113.    
  114. };
  115.  
  116. int CALLBACK WinMain(
  117.     _In_ HINSTANCE hInstance,
  118.     _In_ HINSTANCE hPrevInstance,
  119.     _In_ LPSTR     lpCmdLine,
  120.     _In_ int       nCmdShow
  121. )
  122. {
  123.     return mainwindow(hInstance).message_loop();
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement