Mercurial > dwindows
comparison dw.hpp @ 2861:ef7a414f9b71
Add initial C++ binding header and example program.
Still trying to figure out how it will work, but it is loosely
based on GTK-- and when complete dwtestoo will replicate dwtest.
Added support for building dwtestoo on Unix and Mac.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 15 Dec 2022 12:42:34 +0000 |
parents | |
children | fd32dce7fecd |
comparison
equal
deleted
inserted
replaced
2860:9daee9d58956 | 2861:ef7a414f9b71 |
---|---|
1 /* Dynamic Windows C++ Language Bindings | |
2 * Copyright 2022 Brian Smith | |
3 */ | |
4 | |
5 #ifndef _HPP_DW | |
6 #define _HPP_DW | |
7 #include <dw.h> | |
8 | |
9 namespace DW | |
10 { | |
11 | |
12 // Base handle class which allows opaque access to | |
13 // The base system handles | |
14 class Handle | |
15 { | |
16 private: | |
17 void *handle; | |
18 public: | |
19 void SetHandle(void *newhandle) { handle = newhandle; } | |
20 void *GetHandle() { return handle; } | |
21 }; | |
22 | |
23 // Widget class allows packing and style | |
24 class Widget : public Handle | |
25 { | |
26 public: | |
27 HWND hwnd; | |
28 HWND GetHWND() { return reinterpret_cast<HWND>(GetHandle()); } | |
29 void SetHWND(HWND newhwnd) { hwnd = newhwnd; SetHandle(reinterpret_cast<void *>(newhwnd)); } | |
30 }; | |
31 | |
32 // Box class is a packable object | |
33 class Box : public Widget | |
34 { | |
35 }; | |
36 | |
37 // Top-level window class is packable | |
38 class Window : public Box | |
39 { | |
40 public: | |
41 Window(HWND owner, const char *title, unsigned long style) { SetHWND(dw_window_new(owner, title, style)); } | |
42 Window(const char *title, unsigned long style) { SetHWND(dw_window_new(HWND_DESKTOP, title, style)); } | |
43 Window(unsigned long style) { SetHWND(dw_window_new(HWND_DESKTOP, "", style)); } | |
44 Window(const char *title) { SetHWND(dw_window_new(HWND_DESKTOP, title, DW_FCF_SYSMENU | DW_FCF_TITLEBAR | | |
45 DW_FCF_TASKLIST | DW_FCF_SIZEBORDER | DW_FCF_MINMAX)); } | |
46 Window() { SetHWND(dw_window_new(HWND_DESKTOP, "", DW_FCF_SYSMENU | DW_FCF_TITLEBAR | | |
47 DW_FCF_TASKLIST | DW_FCF_SIZEBORDER | DW_FCF_MINMAX)); } | |
48 | |
49 void SetText(const char *text) { dw_window_set_text(hwnd, text); } | |
50 void SetSize(unsigned long width, unsigned long height) { dw_window_set_size(hwnd, width, height); } | |
51 void Show() { dw_window_show(hwnd); } | |
52 }; | |
53 | |
54 class App | |
55 { | |
56 public: | |
57 App() { dw_init(TRUE, 0, NULL); } | |
58 App(const char *appid) { dw_app_id_set(appid, NULL); dw_init(TRUE, 0, NULL); } | |
59 App(const char *appid, const char *appname) { dw_app_id_set(appid, appname); dw_init(TRUE, 0, NULL); } | |
60 App(int argc, char *argv[]) { dw_init(TRUE, argc, argv); } | |
61 App(int argc, char *argv[], const char *appid) { dw_app_id_set(appid, NULL); dw_init(TRUE, argc, argv); } | |
62 App(int argc, char *argv[], const char *appid, const char *appname) { dw_app_id_set(appid, appname); dw_init(TRUE, argc, argv); } | |
63 | |
64 void Main() { dw_main(); } | |
65 void MainIteration() { dw_main_iteration(); } | |
66 void MainQuit() { dw_main_quit(); } | |
67 void Exit(int exitcode) { dw_exit(exitcode); } | |
68 }; | |
69 | |
70 #if 0 | |
71 // Class that allows drawing, either to screen or picture (pixmap) | |
72 class Drawable | |
73 { | |
74 void DrawPoint(int x, int y); | |
75 void DrawLine(int x1, int y1, int x2, int y2); | |
76 void DrawPolygon(int flags, int x[], int y[]); | |
77 void DrawRect(int fill, int x, int y, int width, int height); | |
78 void DrawArc(int flags, int xorigin, int yorigin, int x1, int y1, int x2, int y2); | |
79 void DrawText(int x, int y, std::string text); | |
80 int BitBltStretch(int xdest, int ydest, int width, int height, HWND src, int xsrc, int ysrc, int srcwidth, int srcheight); | |
81 int BitBltStretch(int xdest, int ydest, int width, int height, HPIXMAP srcp, int xsrc, int ysrc, int srcwidth, int srcheight); | |
82 void BitBlt(int xdest, int ydest, int width, int height, HWND src, int xsrc, int ysrc); | |
83 void BitBlt(int xdest, int ydest, int width, int height, HPIXMAP srcp, int xsrc, int ysrc); | |
84 }; | |
85 | |
86 class Render : public Drawable, public Widget | |
87 { | |
88 }; | |
89 | |
90 class Pixmap : public Drawable, public Handle | |
91 { | |
92 }; | |
93 #endif | |
94 | |
95 } /* namespace DW */ | |
96 #endif |