Compare commits

...
Sign in to create a new pull request.

421 commits

Author SHA1 Message Date
d6b96d0f8c major surgery on dbus code 2026-04-17 10:12:00 +02:00
30c84a915a minor adjustments for compliance 2026-04-17 09:22:30 +02:00
138555f41d auto detect dark theme change via dbus signals 2026-04-17 01:12:44 -05:00
bc942153fe cmacos: working? 2026-04-16 22:58:16 -07:00
3e49278a15 added wip fuzzer, fixed alot of memory leaks with wayland 2026-04-16 18:36:42 -07:00
e41dbd43c1 fix warnings 2026-04-16 13:22:21 -07:00
9caa50b94d
fix enum 2026-04-17 01:52:04 +09:00
d6538d4410
fix 2026-04-17 01:46:47 +09:00
c0e36df063
oops 2026-04-17 01:44:17 +09:00
6259f57677
fix cmake 2026-04-17 01:39:59 +09:00
570f05540e
many things changed 2026-04-17 01:36:34 +09:00
5220f742be
some changes 2026-04-17 01:03:14 +09:00
7a2ca3aa2d
oops 2026-04-17 00:27:04 +09:00
13a2db7fa8
better for binding 2026-04-17 00:26:02 +09:00
5201c46a21
update vulkan/opengl 2026-04-17 00:20:29 +09:00
b82e13cb2e
define opengl/vulkan symbols anyways 2026-04-16 23:53:29 +09:00
79efc31c55
dbus should work on netbsd now 2026-04-16 23:40:29 +09:00
c88dc48817 cmacos: Right we can just use the lowercase newcwindow instead of worrying about pascal conversions 2026-04-16 00:55:18 -07:00
8b176d3a00 cmacos: remove parent check oops 2026-04-16 00:53:37 -07:00
9b138c458e cmacos: very untested code but it's all so basic that it should work 2026-04-16 00:45:59 -07:00
0e96b715b0 classic mac os: comment out MwTimeSleep because I realize that wouldn't work either way 2026-04-15 22:25:26 -07:00
5ca241ad0a update time.c to not do a cast 2026-04-15 22:20:13 -07:00
b2ce5597b0 fix warning 2026-04-16 14:07:20 +09:00
220b76135e Merge branch 'master' into clipboard 2026-04-15 23:49:19 -05:00
15c39a2405 windows shouldn't default to ft2 anyways 2026-04-15 21:48:52 -07:00
62fd2adcd1 Merge branch 'master' into clipboard 2026-04-15 23:47:00 -05:00
2228fa1a46 fix build 2026-04-15 21:46:37 -07:00
5136207bf1 Merge branch 'master' into clipboard 2026-04-15 23:42:47 -05:00
c85b471c43 Merge branch 'master' into classicmacos 2026-04-15 23:42:22 -05:00
f8a94b7380 cmake 2026-04-15 21:41:16 -07:00
47fe57b31c ok 2026-04-15 20:25:08 -07:00
5315f4ec4d classic mac os 2026-04-15 20:21:20 -07:00
712a640f9d probably it is better to do this way 2026-04-16 10:47:24 +09:00
4e4da8659e fix gdi opengl 2026-04-16 10:45:53 +09:00
6f9b3c12a7 fix 2026-04-16 09:55:18 +09:00
48b847093b oops 2026-04-16 09:50:08 +09:00
a2c1489ffb add MwLLSetDarkTheme 2026-04-16 09:35:53 +09:00
0fb9c45ea4 improve 2026-04-16 08:42:01 +09:00
677d8c8046 guard dbus function impls with ifdef 2026-04-15 18:26:32 -05:00
54fed150e8 dbus 2026-04-15 16:12:38 -07:00
ecdecbc93b Merge branch 'master' into clipboard 2026-04-15 17:27:14 -05:00
9087782960 wayland: fix DBUS_FUNC 2026-04-15 15:23:55 -07:00
dc97522bb0 wayland: abstract the dbus stuff a bit in case we need it later 2026-04-15 15:21:16 -07:00
43c66417c7 use pkg-config for dbus includes 2026-04-15 14:03:48 -07:00
12703d451e use pkg-config for dbus includes 2026-04-15 14:02:22 -07:00
6257376b1f Merge branch 'master' into clipboard 2026-04-15 14:00:17 -07:00
a0c864d85b fix wayland crash by having MwLLDestroy flush before actually destroying handle 2026-04-15 13:58:50 -07:00
64930db2fc color picker example: have button match the background 2026-04-15 13:03:24 -07:00
d05e31b154 wayland: don't poll for dark theme, that doesn't work 2026-04-15 13:00:59 -07:00
a3bbcf30b2 wayland: dark theme detection 2026-04-15 12:25:51 -07:00
f7eb9840de milsko.xml: MwClipboardType should be marked as an enum for MwGetClipboard 2026-04-15 11:19:10 -07:00
e77eb5e08a add clipboard stuff to milsko.xml 2026-04-15 11:14:13 -07:00
b641a03bae clipboard refactoring 2026-04-15 10:58:46 -07:00
5c386e7665 Update examples/basic/colorpicker.c 2026-04-15 03:08:55 -05:00
6ff6b22644 border around color picker wheel 2026-04-15 01:05:51 -07:00
5cb9b5cab9 have color picker check for dark theme 2026-04-15 00:54:47 -07:00
0c822d5bfa some wayland fixes curtosey of valgrind 2026-04-14 23:49:04 -07:00
4ab846ad51 fix fpe in text drawing code 2026-04-14 22:53:20 -07:00
fc8330f477 uninitialized 2026-04-15 00:29:16 -05:00
714842461c Update examples/vkdemos/CMakeLists.txt 2026-04-14 23:04:59 -05:00
aac2b410c0 gl cmake doesnt need win32 2026-04-14 23:04:39 -05:00
83f5f7a820 examples cmake doesnt need win32 2026-04-14 23:04:13 -05:00
391f5a6924 remove endian related error 2026-04-15 12:23:54 +09:00
28f6d6ac56 cocoa: untested vulkan code 2026-04-14 20:08:45 -07:00
065b0d824c cocoa: untested vulkan code 2026-04-14 20:03:59 -07:00
32f99b62b6 have MwStringIsKeyUTF8 not use ub 2026-04-14 19:51:52 -07:00
4d7b33741f fix mac os memleak, maybe fix stringisutf8 idk 2026-04-14 19:38:52 -07:00
a01e1a9514 milsko.xml: remove roundness 2026-04-14 20:54:05 -05:00
a7d790698f mac: getXYImpl should also flip whatever is given to it 2026-04-14 18:28:44 -07:00
6e5057f8c6 cocoa: no more flickering 2026-04-14 18:04:00 -07:00
d597dc9411 new drawing system now works properly-ish 2026-04-14 16:58:28 -07:00
bfc6d8e9af mac: ditch the image rep shit and try switching to a draw commands system 2026-04-14 15:52:11 -07:00
1d59488927 wayland: fix several places where we don't attach buffer if not configured 2026-04-14 13:45:47 -07:00
f22f45d5bf give up on rounded borders 2026-04-14 13:34:49 -07:00
0e2e3a1901 some gnustep fixes, probably close to giving up on this ngl 2026-04-14 13:13:17 -07:00
fe72bc92bf mac: actually dispatch close event. reorganize code slightly more now that less is in objective-c methods 2026-04-13 22:30:25 -07:00
c0d7cb3fbc mac: add a few comments 2026-04-13 21:50:10 -07:00
554e5cd5dd mac: merge all the MilskoCocoa* functions into the C Milsko functions that call them, cleaning up the codebase 2026-04-13 21:36:17 -07:00
522f32cfcd mac: revert back to what i had before with drawing, i still don't know how to fix this but it's better then nothing 2026-04-13 21:19:09 -07:00
9283455cb9 links to gnustep but doesn't run 2026-04-13 20:07:00 -07:00
7d85a784f5 i think we're now linking to gnustep properly 2026-04-13 18:39:21 -07:00
a4c61b0e38 gnustep support? 2026-04-13 17:44:27 -07:00
bb876b9620 mac: only recreate rep if width/height is different. also untested but i'm confident in this 2026-04-13 16:45:20 -07:00
b661face26 mac: more untested changes but its just removing dead comments so i know this won't break anything 2026-04-13 16:43:31 -07:00
f44a70d4ec mac: untested code but i'll fall asleep at night with this in the codebase compared to the other thing 2026-04-13 16:21:30 -07:00
14e908488c mac 2026-04-13 16:09:28 -07:00
728983b92c fix builds on osx 10.4 2026-04-13 13:46:25 -07:00
0ab497ca88 oops prioritize wayland 2026-04-13 11:28:54 -07:00
c4f6d1eb14 Update src/core.c 2026-04-11 18:30:00 -05:00
2a7cf2de83 x11: allow apple. 2026-04-11 18:26:15 -05:00
d1f351a7ef
fix cmake 2026-04-12 07:27:07 +09:00
3852646ce3
fix warning 2026-04-12 07:12:59 +09:00
00397f17ea
update milsko.xml 2026-04-12 06:44:35 +09:00
0325584319
fix document 2026-04-12 00:27:04 +09:00
67788da3fb wayland: call wl_surface_attach on every update_buffer to fix weston 2026-04-08 12:36:18 -07:00
37bba97508 fix warnings 2026-04-09 04:03:48 +09:00
c0bfb51601 wayland/x11's env checking shouldn't be else if just if 2026-04-08 12:00:48 -07:00
e9ea675ae6 change the env vars that wayland/x11 check for 2026-04-08 11:59:05 -07:00
84ad1b0d6b Merge branch 'master' of ssh://forgejo.nishi.boats:2222/pyrite-dev/milsko 2026-04-08 11:48:09 -07:00
42af900127 ft2, stbtt: draw letters over each other so that they don't clip each other 2026-04-08 11:47:58 -07:00
3c336b5e95
fix listbox 2026-04-09 03:44:29 +09:00
a652514ab0
always use monospace for listbox 2026-04-09 03:42:45 +09:00
d373f04eed ft2: slightly better spacing 2026-04-08 11:38:55 -07:00
291bb09047
disable XIM for now 2026-04-09 00:35:04 +09:00
8a5a2f0f02
nvm 2026-04-07 22:59:16 +09:00
6af4c73905
introduce MwAfterStep, breaking change 2026-04-07 22:56:18 +09:00
1531f89ef0
better rendering 2026-04-07 22:42:19 +09:00
5d8e39b268
better size 2026-04-06 23:28:32 +09:00
5f6789631d
fix font size 2026-04-06 23:27:27 +09:00
d76bb49e45
better font rendering 2026-04-06 23:19:33 +09:00
8d597328f9
fix 2026-04-06 17:37:19 +09:00
07cab25d3e
fix 2026-04-06 17:36:14 +09:00
29bab28b78
oops 2026-04-06 17:34:32 +09:00
0de09207a4
refactor font api 2026-04-06 17:29:09 +09:00
9fc659b652
some code does this 2026-04-04 00:38:18 +09:00
55cb65be26
be c89 2026-04-04 00:35:11 +09:00
cce41b32b8 document tiny flag; have it use flto on clang 2026-03-31 17:15:25 -07:00
a00d4ba144 configure updates, new 'tiny config' option 2026-03-31 16:54:01 -07:00
da3312cee9 x11: only load in needed functions. also make it so xrender just isn't used if it's not found 2026-03-31 14:26:47 -07:00
d4f6ca14e2 allow x11 backend to be disabled (on by default) (i doubt people will do this) 2026-03-31 13:54:12 -07:00
2e2a97e4a8 replace MwPrintIntoBuffer w MwStringPrintIntoBuffer in core.c 2026-03-31 13:30:34 -07:00
b6b8f742d7 fix vulkan's usage of removed error primative 2026-03-31 13:28:05 -07:00
af54b3e515 dynload x11 and xrender 2026-03-31 13:24:28 -07:00
9d7d4541e4 dynload freetype2 2026-03-31 12:44:32 -07:00
2e30d7f4d9 remove merge conflict artifacts, prefix MwIsKeyUTF8 2026-03-31 12:36:31 -07:00
597dbe4e5a merge conflict 2026-03-30 11:32:40 -07:00
9560c4fd92 merge conflict 2026-03-30 11:31:40 -07:00
3d99a9249f remove mw/error.h includes 2026-03-30 11:22:22 -07:00
32842ca160 document MwStringPrintIntoBuffer slightly better 2026-03-30 11:19:15 -07:00
35d2b4bb76 MwStringPrintIntoBuffer 2026-03-30 11:14:33 -07:00
a5beb9e6b9
define types properly 2026-03-29 21:15:27 +09:00
e8d32dafc7
oops 2026-03-29 09:42:58 +09:00
e312b325c8
fix things 2026-03-29 09:42:34 +09:00
112ddd1521
fix libpng/libjpeg, enable zlib 2026-03-29 09:36:43 +09:00
89dad2c4be Wayland massachusetts 2026-03-27 18:06:17 -07:00
252490e2cf Wayland pointer lock fixes 2026-03-27 17:15:59 -07:00
4d694bba49 several wayland fixes, new util function MwIsUTF8 so that both backends can consistently check if something is a valid utf8 2026-03-27 15:14:19 -07:00
87c870a6c0
fix periodic 2026-03-28 02:40:12 +09:00
dac94c78e1
huh 2026-03-28 02:39:30 +09:00
df50c9531c
almost complete 2026-03-27 17:26:14 +09:00
7be0a72fca
optimize box later 2026-03-27 16:41:32 +09:00
f6abf02486
wip 2026-03-27 16:31:28 +09:00
251fc41020
fix hang 2026-03-27 16:16:30 +09:00
0e5f4f5ef7
fix document 2026-03-27 15:35:03 +09:00
309cd98ea1 Merge branch 'master' of ssh://forgejo.nishi.boats:2222/pyrite-dev/milsko 2026-03-26 23:33:46 -07:00
78ee4033b5 wayland: MwLLShowImpl 2026-03-26 23:32:24 -07:00
a16c1bcb5b
more 2026-03-27 15:31:51 +09:00
1d76cabf4c
wip 2026-03-27 15:25:02 +09:00
a5186cc1e9 Merge branch 'master' of ssh://forgejo.nishi.boats:2222/pyrite-dev/milsko 2026-03-26 22:53:42 -07:00
414fde9b77 fix text positioning on entry 2026-03-26 22:53:20 -07:00
efe1ea076e
fix timing 2026-03-27 14:49:10 +09:00
bf9474f4f4 mergE 2026-03-26 22:48:14 -07:00
a9d8d62146 reduce contrast of complex frame in light mode 2026-03-26 22:47:07 -07:00
f1c4a12cf3
implement MwLLGetClipboard for X11 2026-03-27 14:40:07 +09:00
efbf90945a fix entry widget's use of clipboard 2026-03-26 21:58:47 -07:00
d61e432e97 wayland: fix combobox 2026-03-26 21:36:57 -07:00
37835cb53a Merge branch 'master' of ssh://forgejo.nishi.boats:2222/pyrite-dev/milsko 2026-03-26 21:03:03 -07:00
849c439830 better code and better look for borders 2026-03-26 21:02:45 -07:00
7998454ab9 fix ub 2026-03-27 12:54:33 +09:00
6cc3925282
add MwNdarkTheme 2026-03-27 11:25:53 +09:00
df11b86cea +2 -> +3 2026-03-26 21:07:59 -05:00
258d0d2cb2 update xml 2026-03-26 21:07:59 -05:00
a42482a4e4 epic 2026-03-26 21:07:59 -05:00
8f7df275fb better 2026-03-26 21:07:59 -05:00
fc18c86201 disable rounding on checkbox 2026-03-26 21:07:59 -05:00
e5acf07b38 disable rounding on combobox 2026-03-26 21:07:59 -05:00
8dfa34e555 only do backing box draw if backend doesn't do transparency 2026-03-26 21:07:59 -05:00
17e437075e let ioixd do the job 2026-03-26 21:07:59 -05:00
60e1f36a41 slightly stronger gradient on modern theme 2026-03-26 21:07:59 -05:00
00e44bec32 MwNisRounded 2026-03-26 21:07:59 -05:00
6538f8e836 fix wayland csd, more doublebuffering fixes 2026-03-26 21:07:59 -05:00
2a2fdf55bc wayland: double buffering 2026-03-26 21:07:59 -05:00
19cd6dc242 increase smoothness 2026-03-26 21:07:59 -05:00
548d6c46fd r 2026-03-26 21:07:59 -05:00
8d7016367e experimental rounded corners idea 2026-03-26 21:07:59 -05:00
70f7f8f084
fix box bug 2026-03-27 11:05:15 +09:00
6ba77904d6 fix hitTest 2026-03-25 21:06:32 -07:00
90706b184f apple: assorted fixes 2026-03-25 19:09:01 -07:00
0bbbc51bb9 apple: fix polygon/pixmap coordinates, add line function 2026-03-25 18:53:13 -07:00
bcb108ae5f apple: 'more correct' polygons weren't correct at all 2026-03-25 18:47:58 -07:00
74779c8f42 apple: better polygons, revealing a bigger issue maybe 2026-03-25 18:21:27 -07:00
82999d716a apple: move all event stuff into callback system, fix cmake support for apple, add gl/vk examples to cmake 2026-03-25 17:49:50 -07:00
6bb72c224b support wayland backend on cmake 2026-03-25 14:06:50 -07:00
c05843a04b
ugh 2026-03-25 17:09:36 +09:00
aa6d1f43d3
fix 2026-03-25 17:06:44 +09:00
fa9ad8b984 enable wayland by default on linux builds 2026-03-25 00:43:35 -07:00
4b2bf63889 wayland: support pointer locking 2026-03-25 00:31:23 -07:00
f4e2ec8fa9 h 2026-03-24 23:44:30 -07:00
9757623d3c make always_render a global variable, MwWaylandAlwaysRender 2026-03-24 23:24:20 -07:00
a826ce5e12 GOD IS GOOD 2026-03-24 23:08:43 -07:00
195cccd65a perfect MwLLDetach 2026-03-24 22:40:36 -07:00
2a7327f27a wayland: update backbuffer on enddraw 2026-03-24 19:42:37 -07:00
aad8d1b536 wayland: combo box consistently shows up now 2026-03-24 18:01:55 -07:00
7162350e24 use-experimental-wayland => use-wayland 2026-03-24 17:39:25 -07:00
47746ff30e dynamically load wayland and its dependencies, fix warnings 2026-03-24 17:38:21 -07:00
e86d6acdf3 we can just draw even if events are pending 2026-03-24 14:53:02 -07:00
9a23045c30 change draw_n_resize to just resize 2026-03-24 14:43:38 -07:00
1ad75eca90 only draw on the parent and resize on the child in draw_n_resize 2026-03-24 14:41:20 -07:00
57609f1823 fire a draw/resize event manually to children when resizing 2026-03-24 13:31:49 -07:00
5e823b5a25 wayland: gl improvements 2026-03-23 19:30:21 -07:00
b9933b70e2 wayland: on resize, fire draw before resize 2026-03-23 15:56:01 -07:00
d491357635 wayland: csd fixes 2026-03-23 15:45:48 -07:00
24ae1c4e11 wayland: have backbuffer be larger then framebuffer instead of other way around 2026-03-23 15:32:28 -07:00
8ccf819b57 wayland: positive width/height 2026-03-23 14:56:27 -07:00
682d84879b wayland: cap x/y for viewporter to 0,0 2026-03-23 14:54:36 -07:00
ea2d62f2e1 more wayland fixes 2026-03-23 14:28:49 -07:00
f4072bcb3f fix clipboard 2026-03-23 13:38:26 -07:00
56cb0d4841 wayland: fix cursor 2026-03-24 04:56:08 +09:00
6277c8837a Merge branch 'master' of ssh://forgejo.nishi.boats:2221/pyrite-dev/milsko 2026-03-23 12:36:12 -07:00
3d83e0ca64 wayland: fix cursor 2026-03-23 12:35:29 -07:00
efa6804f46 fix math 2026-03-24 04:34:10 +09:00
6c65e58e37
fix 2026-03-24 04:27:57 +09:00
6d7fe3271f
fix cursor thing for x11/gdi, also format 2026-03-24 04:26:36 +09:00
9d65e9c6bf Wayland improvements 2026-03-23 12:05:32 -07:00
c3d25e6b7d wayland: don't do draw dispatch on forceRender anymore, merely update the buffer 2026-03-22 16:32:36 -07:00
09441380b5 wayland: fallback if selected_cairo is null 2026-03-22 16:15:50 -07:00
2499f82933 wayland: fix double free in wp_viewporter_interface_destroy 2026-03-22 16:12:54 -07:00
0527d376b7 add function for forcing the client to be configured before doing any xdg stuff (in a way Both all compositors like) 2026-03-20 20:23:02 -07:00
69076f2893 fix menus on csd 2026-03-20 19:42:30 -07:00
dee940161e clip: only apply extra clipping when haves decorations 2026-03-20 19:33:12 -07:00
52d676e54f csd and clipping 2026-03-20 19:28:18 -07:00
4e70de98e9 merge conflict 2026-03-19 19:46:58 -07:00
3cf94f6651 wayland: malicious compliance with gnome's CSD rule 2026-03-19 19:43:57 -07:00
22fe52c4a3 ugh 2026-03-20 09:59:07 +09:00
3eeace0963 don't use wl_dispatch_pending_timeout appearently debian still doesn't ship with it 2026-03-19 17:32:36 -07:00
f78e5e620f wayland: image clipping attempt 2026-03-19 17:06:48 -07:00
f44f98b8aa wayland: don't update buffer if we haven't configured 2026-03-19 16:35:56 -07:00
04eb28b617 revert the removal of MwLLBeginDraw/EndDraw, turns out the newer system still doesn't please weston and likely other compositors 2026-03-19 16:05:44 -07:00
42db5889db wayland c89 2026-03-19 16:01:32 -07:00
5f53236c91 remove unused test parameter added to common lowLevel 2026-03-19 15:59:44 -07:00
91c05b670d wayland: working viewport, subsurface input region 2026-03-19 15:57:20 -07:00
5960823801 wayland: don't early return from pointer_button, it causes a deadlock 2026-03-18 23:07:16 -07:00
0a62467760 correct mouse clicks 2026-03-18 23:01:39 -07:00
9309b5fe83 remove old hacks from wayland code, including MwLLBeginDraw and MwLLEndDraw which was really only ever needed for wayland and not anymore 2026-03-18 19:24:51 -07:00
fc7896b5ce wayland: improve event loop 2026-03-17 22:17:05 -07:00
eb0919333a wayland: fix several examples 2026-03-17 20:39:37 -07:00
1cb8fb6c53 wayland: SEVERAL fixes 2026-03-17 20:28:58 -07:00
d14c17b86e wayland fixes 2026-03-17 17:43:22 -07:00
98eb529c6f Merge branch 'master' of ssh://gitea.nishi.boats:2222/pyrite-dev/milsko 2026-03-16 16:09:01 -07:00
c64d7778cd mac: convert child windows to subviews 2026-03-16 16:08:25 -07:00
3260643ada
i wonder if this works 2026-03-14 05:21:53 +09:00
8f04ccdb68
cleanup 2026-03-14 05:16:27 +09:00
43dd61ffbe
clean old things 2026-03-14 05:10:16 +09:00
db5f0ed40a mac: some fixes 2026-03-12 01:10:45 -07:00
96528ca433 mac: don't set the xywh of parent windows twice 2026-03-11 20:27:51 -07:00
13320dce78 proper event handling 2026-03-11 15:49:14 -07:00
02faed2f04 reduce cpu usage on event loop 2026-03-11 13:13:16 -07:00
6c53df0fc5 correct pixmap updating (sadly memcpy'ing is not enough) 2026-03-10 20:09:37 -07:00
d9ee157ee8 mac: support delayed creation of the view's context, for anything whose size starts at 0x0 2026-03-10 17:10:47 -07:00
d3c30bf6d3 mac: mouse fixing, somewwhat. also just always send events for a bit 2026-03-10 16:31:29 -07:00
8f379e9751 add comment clarifying pending 2026-03-10 15:46:46 -07:00
9f1b455341 mac: new event pumping architecture that sucks and i hate it but apple is happy with it so we're happy with it 2026-03-10 15:33:20 -07:00
a0e2ec7f57 undo sending mouse event to both the parent and widget itself, forgot that that's exactly something we don't want to do 2026-03-09 16:40:30 -07:00
4ca11145f1 some 10.4 fixes 2026-03-09 16:35:09 -07:00
3f84b0f868 mac: document MilskoFakePointer 2026-03-09 16:19:12 -07:00
dd67e42054 mac: remove debug prints 2026-03-09 16:14:48 -07:00
dccc402b3d mac: send mouse/key to both event itself and window, evidently 2026-03-09 16:13:49 -07:00
128a1ec524 mac: 'implement' tool windows 2026-03-09 15:07:46 -07:00
65afd85439 mac: most window functions now implemented (save for makeToolWindow) 2026-03-09 14:01:57 -07:00
9eda46d981 mac: remove accidental includes 2026-03-08 23:38:57 -05:00
21d5625ec7 fix forceRender, at the cost of breaking the rotate example 2026-03-08 20:03:47 -07:00
75c9af91d1 mac: try and fix positioning for child windows 2026-03-08 19:15:17 -07:00
c20da369e8 try and fail to have the app be activated without setting the activation policy 2026-03-08 18:30:37 -07:00
3b78872ce8 mac: took a detour and got it working in 10.4, before accidentally fixing the remaining memory leak I think 2026-03-08 18:04:37 -07:00
4549e4f75b mac: remove nscolor release call after realizing it's likely UB and crashes high sierra 2026-03-08 17:07:48 -07:00
4319ea25b5 mac: fix a bunch of memory leaks 2026-03-08 16:05:57 -07:00
0fde05fa03 fix some parts 2026-03-08 07:06:12 +09:00
306f791641 mac: apple doesn't give us a reliable way to check if events are pending but we have to do the nextEventMatching trick anyways because the alternating pending implementation breaks opengl. 2026-03-05 22:52:25 -07:00
ea046f3a52 mac: fix memory leaks somewhat. 2026-03-05 22:41:09 -07:00
9d7a75394c mac: implement clipboard (At the cost of making the pending function a crime against god) 2026-03-05 21:58:22 -07:00
9be36b0755 mac: have key events get sent to parent 2026-03-05 20:19:19 -07:00
e2bcd7b9e9 mac: keyboard events and other nice refactors. they get sent to the opengl window but the callback isn't fired for some reason 2026-03-05 19:29:43 -07:00
39db13fa48 mac: center window when MwDEFAULT is passed 2026-03-04 23:06:56 -07:00
db577bb01f mac opengl support. proper coordinate flipping 2026-03-04 22:56:04 -07:00
f700e90d23 did some code cleanup 2026-03-04 20:47:55 -07:00
b585ad69b7 code cleanup 2026-03-04 20:44:25 -07:00
943500a7ec mac: got a bunch of events handled. failed to get resizing working though 2026-03-04 19:34:19 -07:00
0832533c51 Oops the readme is generated 2026-03-04 16:52:19 -07:00
f9c35cded4 macos note in readme should just be the version, my bad 2026-03-04 13:32:39 -07:00
2e4e2a1c7f Remove xcodetools note 2026-03-04 13:31:25 -07:00
5eeba311ab i fixed the makefiles but forgot to run the script 2026-03-04 13:22:00 -07:00
890294cd55 update macos readme 2026-03-04 13:18:01 -07:00
de1e8da6f9 fix generated mkfiles 2026-03-04 13:05:38 -07:00
e09eccbf5f refactor font.c into an MwFL section (#9)
Reviewed-on: https://gitea.nishi.boats/pyrite-dev/milsko/pulls/9
Co-authored-by: IoIxD <alphaproject217@gmail.com>
Co-committed-by: IoIxD <alphaproject217@gmail.com>
2026-03-04 13:59:28 -06:00
b3735fa364
rename Makefile.pl to configure 2026-03-05 04:09:01 +09:00
cc2d3008d0 mac: implement polygon function 2026-03-04 00:02:14 -07:00
efa43456c1 significant macos progress, now compiles/runs on monetery 2026-03-03 23:24:28 -07:00
11fec984cf
fix 2026-02-06 22:05:13 +09:00
d7db903695
msvc 2026-02-04 00:30:22 +09:00
c04f751a4f
msvc 2026-02-04 00:25:49 +09:00
280ba93cf1
hmm 2026-02-04 00:21:31 +09:00
3329184993
unused 2026-02-04 00:06:31 +09:00
4a092e71d2
testing 2026-02-04 00:02:21 +09:00
c308bd9324
test 2026-02-03 23:46:24 +09:00
282283609c
i wonder if doc gets generated 2026-02-03 23:43:08 +09:00
12f7312d40
testing jenkins 2026-02-03 23:27:27 +09:00
5bc06dc851
testing jenkins 2026-02-03 23:24:34 +09:00
7ad4d82024
c89 2026-02-02 23:02:42 +09:00
ad5aa03d11
remove non required headers 2026-01-31 20:42:09 +09:00
bbb20f081e
add MwNdarkThemeHandler 2026-01-27 18:51:57 +09:00
626294c95f
format 2026-01-27 18:50:03 +09:00
9544404f7c
fix warning 2026-01-27 18:46:12 +09:00
65c872710a it should be working now, closes #6 2026-01-27 18:12:36 +09:00
64c3cdb4a5 MwSetDarkTheme instead of MwToggleDarkTheme 2026-01-27 18:03:16 +09:00
5e492ee5b4 oops 2026-01-27 18:00:44 +09:00
ae96b127e1 fix leak 2026-01-27 17:58:52 +09:00
0cecae2dd1 better registry function 2026-01-27 17:58:30 +09:00
18457ccbcb tiny fix 2026-01-27 17:36:21 +09:00
8b28b3e1b0 might be functional 2026-01-27 17:34:25 +09:00
836b13e62e add RPN calculator demo 2026-01-27 17:02:40 +09:00
5413332506
introduce MwWidget->berserk 2026-01-23 15:29:32 +09:00
8d86f185f2
use milsko's typedefs instead in cocoa 2026-01-23 13:57:05 +09:00
b458613f87 update 2026-01-20 14:05:03 +09:00
04f1a94cb5 cocoa: attempted drawing 2026-01-14 17:13:12 -07:00
a710967115 cocoa: move interfaces to header (guarded by ifdef __OBJC__) 2026-01-14 13:47:49 -07:00
e2f34df4e3
format objective c files 2026-01-15 05:31:04 +09:00
3dec3ff0da
format 2026-01-15 05:16:47 +09:00
85994d42f1
fix issue #5 2026-01-15 05:16:27 +09:00
32f09a9af2 wayland: don't do parent draws on every event when we do'nt need to 2026-01-12 19:21:32 -07:00
d340c64ca3 wayland: fix weird regressiong 2026-01-12 18:50:33 -07:00
14e55b7f53 wayland: fix weird regression 2026-01-12 18:48:22 -07:00
69c95d5752 wayland: more fix 2026-01-12 18:18:05 -07:00
efcc176c04 cocoa: more fixes 2026-01-12 15:31:22 -07:00
e45a1f6ad8 cocoa: more fixes 2026-01-12 15:30:05 -07:00
31cc8e5a0d cocoa: fix syntax errors. Also allow cmake to compile it (untested) 2026-01-12 15:13:59 -07:00
a70f3dbb59 remove old appkit.m file that somehow got here 2026-01-12 13:07:35 -07:00
ca4adf5f39 cocoa: fill a bunch of no-brainer functions, i haven't actually tested this yet and won't until I get home but I assume the worst case scenario is that I fucked up the syntax 2026-01-12 13:04:30 -07:00
eb50af2b81
manpage says usleep is obsolete but i dont care 2026-01-13 01:00:28 +09:00
a0d1bada8f
probably left debug code 2026-01-12 18:50:55 +09:00
7e32866c0a
fix cmake 2026-01-12 06:28:43 +09:00
e8f743ed84
better 2026-01-12 06:24:48 +09:00
c61e26f028
yeah 2026-01-12 06:05:24 +09:00
e73964882e renamed appkit backend to cocoa and got something that compiles 2026-01-09 21:35:23 -07:00
da33a1a3c6 darwin: remove invalid characters 2026-01-09 14:45:12 -07:00
2d3bd9213e appkit 2026-01-09 14:43:44 -07:00
079cfa18b9
fix english 2026-01-09 07:25:05 +09:00
debdaf998e
add MW_OPENGL_NO_INCLUDE 2026-01-09 03:06:38 +09:00
1f1318d0e1 cmake: allow shared or static building 2026-01-07 12:30:18 -07:00
85df90ceaf
what did i even change? 2026-01-06 00:54:00 +09:00
e2aecbf9d4
this should be more correct 2026-01-05 23:27:18 +09:00
d3751c0bf9 submenu: just don't adjust if there's no global coordinates, there's not much of another way 2026-01-04 18:25:33 -07:00
54cdd85015 coords 2026-01-04 13:06:36 -07:00
d784770ca9 wayland: popup positioning 2026-01-04 13:01:50 -07:00
12f279e83a wayland: ensure every event callback uses the mutex 2026-01-04 11:40:34 -07:00
8cdffa12ae wayland/opengl: fix o->egl_window_native warning 2026-01-04 11:13:59 -07:00
933b5198c7 wayland/vulkan: quickly get that going 2026-01-04 11:12:57 -07:00
30a100fd28 wayland/opengl: set EGL_DEPTH_SIZE to 24 2026-01-03 19:21:03 -07:00
a148b3bedf wayland: use mutexes to ensure that MwLLDestroyImpl never conflicts with wayland events. 2026-01-03 18:27:34 -07:00
bed668b84a wayland: fix misc. crashes on the destruction of widgets 2026-01-02 14:19:48 -07:00
6183a1ccda
update license 2026-01-02 00:24:59 +09:00
f32f6cefc0 wayland: accidentally removed event_loop call from MwLLNextEventImpl 2025-12-30 22:44:04 -07:00
f3683dece3 undo HAS_OPENGL stuff 2025-12-30 22:38:01 -07:00
808495cccf wayland: misc fixes 2025-12-30 22:28:36 -07:00
6946c1eaf3 wayland: opengl support 2025-12-30 22:26:19 -07:00
029e62d765 wayland: opengl 2025-12-30 20:30:29 -07:00
a03065ae52 wayland: forgot to commit .h 2025-12-30 19:16:01 -07:00
324257c43f wayland: no pthreads needed 2025-12-30 19:15:33 -07:00
afecb04848 clipboard: don't set clipboard after pasting 2025-12-30 17:14:57 -07:00
bed63dd245 clipboard: fix syntax 2025-12-30 17:14:39 -07:00
67bd6029af wayland: finish clipboard 2025-12-30 17:12:12 -07:00
72820e87f1
rename clipboard_received to clipboard 2025-12-31 04:35:10 +09:00
d3147ac087
format 2025-12-31 04:29:27 +09:00
4bdda59693 better api for clipboard 2025-12-31 04:29:13 +09:00
823c865791
handle WM_DELETE_WINDOW better 2025-12-31 00:48:44 +09:00
3f9125d1ae
fix 2025-12-30 23:54:30 +09:00
549d235893
better 2025-12-28 21:56:45 +09:00
0daa527b1d
fix 2025-12-28 18:03:37 +09:00
0ca7f6ed8a
dispatch children_update 2025-12-28 17:41:11 +09:00
e895e96941 introduce MwNleftPadding to label 2025-12-25 15:39:54 +09:00
0d79141a49
tiny fix 2025-12-25 04:21:33 +09:00
c80987ffe4
better 2025-12-25 04:18:12 +09:00
d3a7b0a01d
oops 2025-12-25 04:03:05 +09:00
e77c4f3c38
add MwNleftPadding to SubMenu 2025-12-25 03:56:04 +09:00
22b4737c33
better separator 2025-12-25 02:27:41 +09:00
509351a0a0
fix submenu 2025-12-25 00:19:27 +09:00
86effbdfd7
fix 2025-12-24 22:52:26 +09:00
7b47524286
improve submenu 2025-12-24 13:56:08 +09:00
c8e7f58230
wrong 2025-12-23 22:11:22 +09:00
9ea54b4f88
format 2025-12-23 22:08:55 +09:00
55f82e4fbc
update 2025-12-23 22:08:49 +09:00
a23016bc05 yes 2025-12-23 18:14:00 +09:00
df99e66d87 tiny fix 2025-12-23 18:10:50 +09:00
e9fd2705d4
fix 2025-12-21 23:05:42 +09:00
a824b4fc44
oops 2025-12-21 23:04:53 +09:00
c7c8f236b0
yes 2025-12-21 23:03:33 +09:00
bdc67d6369
text shadow 2025-12-21 23:02:02 +09:00
873c75b882
fix 2025-12-21 22:21:10 +09:00
e44eaa2c16
fix 2025-12-21 22:02:33 +09:00
0d281c09ce
i will work on vms port at some point 2025-12-21 20:25:57 +09:00
2b30a06ecf
wip VMS port 2025-12-21 19:29:05 +09:00
188da6803e
adjust some stuff 2025-12-21 15:33:48 +09:00
2304b493d1
add MwNlength 2025-12-21 15:17:00 +09:00
91d9677bf7
add seven segment 2025-12-21 14:38:07 +09:00
f09960195f
submenu 2025-12-21 12:08:08 +09:00
ab9d0ffc5f
improve submenu 2025-12-21 11:53:47 +09:00
a67a0c11f8
fix 2025-12-19 23:31:05 +09:00
dc8168df12
fix 2025-12-19 22:36:49 +09:00
604ff72d6e
add MwNbitmapFont 2025-12-19 22:35:35 +09:00
a384add9e9 wayland: properly do MwLLPending and MwLLNextEvent 2025-12-18 23:50:03 -07:00
6123fd1304 wayland: implement tool windows. add destructors for protocols 2025-12-18 23:32:51 -07:00
b7488b9440 wayland: seperate MwLLPending and MwLLNextEvent 2025-12-18 19:59:40 -07:00
18511dec2f wayland: remove a few unused fields 2025-12-18 18:27:44 -07:00
59ff6f1008 wayland: add icon support 2025-12-18 18:21:57 -07:00
a27a01ce41 wayland: MwLLGetClipboardImpl. 2025-12-18 17:46:23 -07:00
b0f4713ff1 wayland: remove unused cursor_shape 2025-12-18 13:46:22 -07:00
8d4e845e7c wayland: MwLLGetScreenSize 2025-12-18 13:43:45 -07:00
aeaf0a4547 wayland: MwLLGetCursorCoordImpl 2025-12-18 13:16:16 -07:00
b366fc12a7 Merge branch 'master' of ssh://gitea.nishi.boats:2222/pyrite-dev/milsko 2025-12-18 13:15:20 -07:00
d8c08f80d6 wayland: cursor support 2025-12-18 13:15:03 -07:00
bfa0a5811e
fix 2025-12-19 04:38:29 +09:00
19f52488b8
fancy things 2025-12-19 03:57:45 +09:00
c6e7421b31 wayland: key modifiers 2025-12-18 11:36:04 -07:00
e3b3363e42 Merge branch 'master' of ssh://gitea.nishi.boats:2222/pyrite-dev/milsko 2025-12-18 11:29:12 -07:00
a815998ace wayland: fix pointer 2025-12-18 11:26:51 -07:00
75749697ba
netbsd wants pthread. idk why 2025-12-19 03:01:12 +09:00
c9c3a00ed3
unrelated changes 2025-12-19 02:55:30 +09:00
012650f06f
tiny change 2025-12-19 01:37:02 +09:00
72fbba1a74 force aliasing 2025-12-18 12:24:06 +09:00
b8a92f4ae0 wayland: buffer destroy/recreate in SetWHImpl too 2025-12-17 19:44:15 -07:00
724b008220 impl resizing in wayland 2025-12-17 19:41:05 -07:00
320de34ce8 remove opengl from wayland in favor of cairo 2025-12-17 19:14:54 -07:00
120 changed files with 16297 additions and 2222 deletions

View file

@ -1,5 +1,4 @@
---
Language: Cpp
UseTab: Always
TabWidth: 8
AlignConsecutiveAssignments:

3
.clangd Normal file
View file

@ -0,0 +1,3 @@
Completion:
HeaderInsertion: Never
ClangFormat: Tab

14
.gitignore vendored
View file

@ -5,10 +5,24 @@ examples/*/*.exe
!examples/*/
!examples/*.*
!examples/*/*.*
*.exe
*.o
*.obj
*.core
*.so
*.dll
*.lib
*.dylib
*.a
/Makefile
/build
compile_flags.txt
.cache
.DS_Store
*.pef
*.dsk
*.bin
*.rsrc
*.finf
*.gdb

36
BorMakefile generated
View file

@ -1,11 +1,26 @@
CC = bcc32 -c
LD = bcc32
CFLAGS = -Iinclude -D_MILSKO -DUSE_GDI -DUSE_STB_TRUETYPE -DUSE_STB_IMAGE -DSTBI_NO_SIMD
CFLAGS = -Iinclude -Iexternal\libz\include -D_MILSKO -DUSE_GDI -DUSE_STB_TRUETYPE -DUSE_STB_IMAGE -DSTBI_NO_SIMD
LDFLAGS = -tWD
.SUFFIXES: .obj .c
all: src\Mw.dll
clean:
del /f /q external\libz\src\adler32.obj
del /f /q external\libz\src\compress.obj
del /f /q external\libz\src\crc32.obj
del /f /q external\libz\src\deflate.obj
del /f /q external\libz\src\gzclose.obj
del /f /q external\libz\src\gzlib.obj
del /f /q external\libz\src\gzread.obj
del /f /q external\libz\src\gzwrite.obj
del /f /q external\libz\src\infback.obj
del /f /q external\libz\src\inffast.obj
del /f /q external\libz\src\inflate.obj
del /f /q external\libz\src\inftrees.obj
del /f /q external\libz\src\trees.obj
del /f /q external\libz\src\uncompr.obj
del /f /q external\libz\src\zutil.obj
del /f /q external\stb_ds.obj
del /f /q external\stb_image.obj
del /f /q external\stb_truetype.obj
@ -26,11 +41,6 @@ clean:
del /f /q src\dialog\filechooser.obj
del /f /q src\dialog\messagebox.obj
del /f /q src\draw.obj
del /f /q src\error.obj
del /f /q src\font\boldfont.obj
del /f /q src\font\boldttf.obj
del /f /q src\font\font.obj
del /f /q src\font\ttf.obj
del /f /q src\icon\back.obj
del /f /q src\icon\clock.obj
del /f /q src\icon\computer.obj
@ -49,7 +59,15 @@ clean:
del /f /q src\icon\warning.obj
del /f /q src\lowlevel.obj
del /f /q src\string.obj
del /f /q src\text.obj
del /f /q src\text\font\boldfont.obj
del /f /q src\text\font\boldmonottf.obj
del /f /q src\text\font\boldttf.obj
del /f /q src\text\font\font.obj
del /f /q src\text\font\monottf.obj
del /f /q src\text\font\ttf.obj
del /f /q src\text\ft2.obj
del /f /q src\text\stbtt.obj
del /f /q src\text\text.obj
del /f /q src\unicode.obj
del /f /q src\widget\box.obj
del /f /q src\widget\button.obj
@ -74,8 +92,8 @@ clean:
del /f /q src\Mw.dll
del /f /q src\Mw.lib
src\Mw.dll: external\stb_ds.obj external\stb_image.obj external\stb_truetype.obj src\abstract\directory.obj src\abstract\dynamic.obj src\abstract\time.obj src\backend\gdi.obj src\color.obj src\core.obj src\cursor\arrow.obj src\cursor\cross.obj src\cursor\default.obj src\cursor\hidden.obj src\cursor\text.obj src\default.obj src\dialog\colorpicker.obj src\dialog\directorychooser.obj src\dialog\filechooser.obj src\dialog\messagebox.obj src\draw.obj src\error.obj src\font\boldfont.obj src\font\boldttf.obj src\font\font.obj src\font\ttf.obj src\icon\back.obj src\icon\clock.obj src\icon\computer.obj src\icon\directory.obj src\icon\down.obj src\icon\error.obj src\icon\file.obj src\icon\forward.obj src\icon\info.obj src\icon\left.obj src\icon\news.obj src\icon\note.obj src\icon\right.obj src\icon\search.obj src\icon\up.obj src\icon\warning.obj src\lowlevel.obj src\string.obj src\text.obj src\unicode.obj src\widget\box.obj src\widget\button.obj src\widget\checkbox.obj src\widget\combobox.obj src\widget\entry.obj src\widget\frame.obj src\widget\image.obj src\widget\label.obj src\widget\listbox.obj src\widget\menu.obj src\widget\numberentry.obj src\widget\opengl.obj src\widget\progressbar.obj src\widget\radiobox.obj src\widget\scrollbar.obj src\widget\separator.obj src\widget\submenu.obj src\widget\treeview.obj src\widget\viewport.obj src\widget\window.obj
$(LD) $(LDFLAGS) -e$@ external\stb_ds.obj external\stb_image.obj external\stb_truetype.obj src\abstract\directory.obj src\abstract\dynamic.obj src\abstract\time.obj src\backend\gdi.obj src\color.obj src\core.obj src\cursor\arrow.obj src\cursor\cross.obj src\cursor\default.obj src\cursor\hidden.obj src\cursor\text.obj src\default.obj src\dialog\colorpicker.obj src\dialog\directorychooser.obj src\dialog\filechooser.obj src\dialog\messagebox.obj src\draw.obj src\error.obj src\font\boldfont.obj src\font\boldttf.obj src\font\font.obj src\font\ttf.obj src\icon\back.obj src\icon\clock.obj src\icon\computer.obj src\icon\directory.obj src\icon\down.obj src\icon\error.obj src\icon\file.obj src\icon\forward.obj src\icon\info.obj src\icon\left.obj src\icon\news.obj src\icon\note.obj src\icon\right.obj src\icon\search.obj src\icon\up.obj src\icon\warning.obj src\lowlevel.obj src\string.obj src\text.obj src\unicode.obj src\widget\box.obj src\widget\button.obj src\widget\checkbox.obj src\widget\combobox.obj src\widget\entry.obj src\widget\frame.obj src\widget\image.obj src\widget\label.obj src\widget\listbox.obj src\widget\menu.obj src\widget\numberentry.obj src\widget\opengl.obj src\widget\progressbar.obj src\widget\radiobox.obj src\widget\scrollbar.obj src\widget\separator.obj src\widget\submenu.obj src\widget\treeview.obj src\widget\viewport.obj src\widget\window.obj -lopengl32.lib -lgdi32.lib -luser32.lib
src\Mw.dll: external\libz\src\adler32.obj external\libz\src\compress.obj external\libz\src\crc32.obj external\libz\src\deflate.obj external\libz\src\gzclose.obj external\libz\src\gzlib.obj external\libz\src\gzread.obj external\libz\src\gzwrite.obj external\libz\src\infback.obj external\libz\src\inffast.obj external\libz\src\inflate.obj external\libz\src\inftrees.obj external\libz\src\trees.obj external\libz\src\uncompr.obj external\libz\src\zutil.obj external\stb_ds.obj external\stb_image.obj external\stb_truetype.obj src\abstract\directory.obj src\abstract\dynamic.obj src\abstract\time.obj src\backend\gdi.obj src\color.obj src\core.obj src\cursor\arrow.obj src\cursor\cross.obj src\cursor\default.obj src\cursor\hidden.obj src\cursor\text.obj src\default.obj src\dialog\colorpicker.obj src\dialog\directorychooser.obj src\dialog\filechooser.obj src\dialog\messagebox.obj src\draw.obj src\icon\back.obj src\icon\clock.obj src\icon\computer.obj src\icon\directory.obj src\icon\down.obj src\icon\error.obj src\icon\file.obj src\icon\forward.obj src\icon\info.obj src\icon\left.obj src\icon\news.obj src\icon\note.obj src\icon\right.obj src\icon\search.obj src\icon\up.obj src\icon\warning.obj src\lowlevel.obj src\string.obj src\text\font\boldfont.obj src\text\font\boldmonottf.obj src\text\font\boldttf.obj src\text\font\font.obj src\text\font\monottf.obj src\text\font\ttf.obj src\text\ft2.obj src\text\stbtt.obj src\text\text.obj src\unicode.obj src\widget\box.obj src\widget\button.obj src\widget\checkbox.obj src\widget\combobox.obj src\widget\entry.obj src\widget\frame.obj src\widget\image.obj src\widget\label.obj src\widget\listbox.obj src\widget\menu.obj src\widget\numberentry.obj src\widget\opengl.obj src\widget\progressbar.obj src\widget\radiobox.obj src\widget\scrollbar.obj src\widget\separator.obj src\widget\submenu.obj src\widget\treeview.obj src\widget\viewport.obj src\widget\window.obj
$(LD) $(LDFLAGS) -e$@ external\libz\src\adler32.obj external\libz\src\compress.obj external\libz\src\crc32.obj external\libz\src\deflate.obj external\libz\src\gzclose.obj external\libz\src\gzlib.obj external\libz\src\gzread.obj external\libz\src\gzwrite.obj external\libz\src\infback.obj external\libz\src\inffast.obj external\libz\src\inflate.obj external\libz\src\inftrees.obj external\libz\src\trees.obj external\libz\src\uncompr.obj external\libz\src\zutil.obj external\stb_ds.obj external\stb_image.obj external\stb_truetype.obj src\abstract\directory.obj src\abstract\dynamic.obj src\abstract\time.obj src\backend\gdi.obj src\color.obj src\core.obj src\cursor\arrow.obj src\cursor\cross.obj src\cursor\default.obj src\cursor\hidden.obj src\cursor\text.obj src\default.obj src\dialog\colorpicker.obj src\dialog\directorychooser.obj src\dialog\filechooser.obj src\dialog\messagebox.obj src\draw.obj src\icon\back.obj src\icon\clock.obj src\icon\computer.obj src\icon\directory.obj src\icon\down.obj src\icon\error.obj src\icon\file.obj src\icon\forward.obj src\icon\info.obj src\icon\left.obj src\icon\news.obj src\icon\note.obj src\icon\right.obj src\icon\search.obj src\icon\up.obj src\icon\warning.obj src\lowlevel.obj src\string.obj src\text\font\boldfont.obj src\text\font\boldmonottf.obj src\text\font\boldttf.obj src\text\font\font.obj src\text\font\monottf.obj src\text\font\ttf.obj src\text\ft2.obj src\text\stbtt.obj src\text\text.obj src\unicode.obj src\widget\box.obj src\widget\button.obj src\widget\checkbox.obj src\widget\combobox.obj src\widget\entry.obj src\widget\frame.obj src\widget\image.obj src\widget\label.obj src\widget\listbox.obj src\widget\menu.obj src\widget\numberentry.obj src\widget\opengl.obj src\widget\progressbar.obj src\widget\radiobox.obj src\widget\scrollbar.obj src\widget\separator.obj src\widget\submenu.obj src\widget\treeview.obj src\widget\viewport.obj src\widget\window.obj -lopengl32.lib -lgdi32.lib -luser32.lib -ladvapi32.lib
implib src\Mw.lib src\Mw.dll
.c.obj:

View file

@ -9,28 +9,47 @@ include(GNUInstallDirs)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
option(TRY_OPENGL "Try to compile OpenGL widget or not" ON)
option(TRY_VULKAN "Try to compile Vulkan widget or not" ON)
option(CLASSIC_THEME "Use classic theme" OFF)
option(BUILD_EXAMPLES "Build examples" OFF)
option(USE_STB_IMAGE "Use stb_image" ON)
option(USE_STB_TRUETYPE "Use stb_truetype" OFF)
option(USE_FREETYPE2 "Use FreeType 2" ON)
option(MW_CLASSIC_THEME "Use classic theme" OFF)
option(MW_BUILD_EXAMPLES "Build examples" OFF)
option(MW_USE_STB_IMAGE "Use stb_image" ON)
option(MW_USE_STB_TRUETYPE "Use stb_truetype" OFF)
if(${CMAKE_SYSTEM_NAME} MATCHES Retro)
option(MW_BUILD_SHARED "Build a shared library" OFF)
option(MW_BUILD_STATIC "Build a static library" ON)
option(MW_TRY_OPENGL "Try to compile OpenGL widget or not" OFF)
option(MW_TRY_VULKAN "Try to compile Vulkan widget or not" OFF)
else()
option(MW_BUILD_SHARED "Build a shared library" ON)
option(MW_BUILD_STATIC "Build a static library" OFF)
option(MW_TRY_OPENGL "Try to compile OpenGL widget or not" ON)
option(MW_TRY_VULKAN "Try to compile Vulkan widget or not" ON)
endif()
option(MW_INSTALL_HEADERS "Install headers" ON)
if(${CMAKE_SYSTEM_NAME} STREQUAL Darwin OR ${CMAKE_SYSTEM_NAME} MATCHES Retro)
option(MW_USE_FREETYPE2 "Use FreeType 2" OFF)
else()
option(MW_USE_FREETYPE2 "Use FreeType 2" ON)
endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL Linux)
option(MW_USE_WAYLAND "Enable Wayland backend" ON)
endif()
file(
GLOB
SOURCES
src/*.c src/cursor/*.c src/icon/*.c src/text.c src/widget/*.c src/math/*.c src/font/*.c src/dialog/*.c src/abstract/*.c external/*.c
external/libz/src/*.c src/*.c src/cursor/*.c src/icon/*.c src/widget/*.c src/text/*.c src/text/font/*.c src/dialog/*.c src/abstract/*.c external/*.c
)
list(REMOVE_ITEM SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/widget/opengl.c")
list(REMOVE_ITEM SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/widget/vulkan.c")
if(NOT USE_STB_IMAGE)
if(NOT MW_USE_STB_IMAGE)
list(REMOVE_ITEM SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/external/stb_image.c")
endif()
if(NOT USE_STB_TRUETYPE)
if(NOT MW_USE_STB_TRUETYPE)
list(REMOVE_ITEM SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/external/stb_truetype.c")
endif()
@ -39,35 +58,47 @@ if(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
list(APPEND CMAKE_REQUIRED_INCLUDES "/usr/pkg/include")
endif()
if(TRY_OPENGL)
check_include_files(GL/gl.h HAVE_GL_GL_H)
if(HAVE_GL_GL_H)
set(BUILD_OPENGL ON)
list(APPEND SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/widget/opengl.c")
if(MW_TRY_OPENGL)
find_package(OpenGL)
if(OpenGL_FOUND)
set(MW_BUILD_OPENGL ON)
if(APPLE)
list(APPEND SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/widget/opengl_cocoa.m")
endif()
message(STATUS "OpenGL widget has been enabled")
else()
message(WARNING "OpenGL widget has been disabled")
endif()
endif()
if(TRY_OPENGL)
if(MW_TRY_VULKAN)
check_include_files(vulkan/vulkan.h HAVE_VULKAN_VULKAN_H)
if(HAVE_VULKAN_VULKAN_H)
set(BUILD_VULKAN ON)
list(APPEND SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/widget/vulkan.c")
set(MW_BUILD_VULKAN ON)
message(STATUS "Vulkan widget has been enabled")
else()
message(WARNING "Vulkan widget has been disabled")
endif()
endif()
if(MW_BUILD_STATIC)
message(STATUS "Building Milsko as a static library")
add_library(
Mw
${SOURCES}
)
elseif(MW_BUILD_SHARED)
message(STATUS "Building Milsko as a shared library")
add_library(
Mw
SHARED
${SOURCES}
)
else()
message(ERROR "Must either build a shared library or a static library")
endif()
if(USE_STB_IMAGE)
if(MW_USE_STB_IMAGE)
target_compile_definitions(
Mw
PRIVATE
@ -77,21 +108,21 @@ else()
file(
GLOB
IMAGE_SOURCES
external/libz/src/*.c external/libjpeg/src/*.c external/libpng/src/*.c
external/libjpeg/src/*.c external/libpng/src/*.c
)
target_sources(
Mw
PRIVATE
${IMAGE_SOURCES}
${MW_IMAGE_SOURCES}
)
target_include_directories(
Mw
PRIVATE
external/libz/include external/libjpeg/include external/libpng/include
external/libjpeg/include external/libpng/include
)
endif()
if(USE_STB_TRUETYPE)
if(MW_USE_STB_TRUETYPE)
target_compile_definitions(
Mw
PRIVATE
@ -99,7 +130,7 @@ if(USE_STB_TRUETYPE)
)
endif()
if(USE_FREETYPE2)
if(MW_USE_FREETYPE2)
target_compile_definitions(
Mw
PRIVATE
@ -113,13 +144,119 @@ if(USE_FREETYPE2)
list(APPEND LIBRARIES ${FT2_LIBRARIES})
endif()
if(MW_USE_WAYLAND)
function(scan_wayland_protocol_core)
execute_process(
COMMAND wayland-scanner private-code /usr/share/wayland/wayland.xml ${CMAKE_CURRENT_SOURCE_DIR}/src/backend/wayland-core-protocol.c
OUTPUT_VARIABLE WAYLAND_SCANNER_OUTPUT
ERROR_VARIABLE WAYLAND_SCANNER_ERROR
ECHO_OUTPUT_VARIABLE
ECHO_ERROR_VARIABLE
COMMAND_ECHO STDOUT
)
target_sources(
Mw
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src/backend/wayland-core-protocol.c
)
execute_process(
COMMAND wayland-scanner client-header /usr/share/wayland/wayland.xml ${CMAKE_CURRENT_SOURCE_DIR}/include/Mw/LowLevel/Wayland/wayland-core-protocol.h
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE WAYLAND_SCANNER_OUTPUT
ERROR_VARIABLE WAYLAND_SCANNER_ERROR
ECHO_OUTPUT_VARIABLE
ECHO_ERROR_VARIABLE
COMMAND_ECHO STDOUT
)
endfunction()
function(scan_wayland_protocol tier proto ver)
SET(proto_c ${CMAKE_CURRENT_SOURCE_DIR}/src/backend/wayland-${proto}-protocol.c)
execute_process(
COMMAND wayland-scanner private-code /usr/share/wayland-protocols/${tier}/${proto}/${proto}${ver}.xml ${proto_c}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE WAYLAND_SCANNER_OUTPUT
ERROR_VARIABLE WAYLAND_SCANNER_ERROR
ECHO_OUTPUT_VARIABLE
ECHO_ERROR_VARIABLE
COMMAND_ECHO STDOUT
)
target_sources(
Mw
PRIVATE
${proto_c}
)
execute_process(
COMMAND wayland-scanner client-header /usr/share/wayland-protocols/${tier}/${proto}/${proto}${ver}.xml ${CMAKE_CURRENT_SOURCE_DIR}/include/Mw/LowLevel/Wayland/${proto}-client-protocol.h
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE WAYLAND_SCANNER_OUTPUT
ERROR_VARIABLE WAYLAND_SCANNER_ERROR
ECHO_OUTPUT_VARIABLE
ECHO_ERROR_VARIABLE
COMMAND_ECHO STDOUT
)
endfunction()
check_include_files(wayland-client.h HAVE_WL_H)
check_include_files(xkbcommon/xkbcommon.h HAVE_XKBCOMMON_H)
check_include_files(cairo/cairo.h HAVE_CAIRO_H)
if(HAVE_WL_H)
if(HAVE_XKBCOMMON_H)
if(HAVE_CAIRO_H)
scan_wayland_protocol_core()
scan_wayland_protocol("stable" "xdg-shell" "")
scan_wayland_protocol("stable" "viewporter" "")
scan_wayland_protocol("stable" "tablet" "-v2")
scan_wayland_protocol("staging" "xdg-toplevel-icon" "-v1")
scan_wayland_protocol("staging" "cursor-shape" "-v1")
scan_wayland_protocol("unstable" "xdg-decoration" "-unstable-v1")
scan_wayland_protocol("unstable" "primary-selection" "-unstable-v1")
scan_wayland_protocol("unstable" "pointer-constraints" "-unstable-v1")
scan_wayland_protocol("unstable" "relative-pointer" "-unstable-v1")
target_sources(
Mw
PRIVATE
src/backend/wayland.c
)
target_compile_definitions(
Mw
PRIVATE
USE_WAYLAND
)
message(STATUS "Wayland backend has been enabled")
else()
message(WARNING "Wayland backend has been disabled")
endif()
else()
message(WARNING "Wayland backend has been disabled")
endif()
else()
message(WARNING "Wayland backend has been disabled")
endif()
endif()
if(APPLE AND MW_BUILD_OPENGL)
target_compile_definitions(
Mw
PRIVATE
GL_SILENCE_DEPRECATION
)
endif()
target_include_directories(
Mw
PRIVATE
external/libz/include
)
target_include_directories(
Mw
PUBLIC
include
)
if(CLASSIC_THEME)
if(MW_CLASSIC_THEME)
target_compile_definitions(
Mw
PRIVATE
@ -139,6 +276,46 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
USE_GDI
)
list(APPEND LIBRARIES gdi32)
target_link_options(
Mw
PRIVATE
-static-libgcc
)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
target_sources(
Mw
PRIVATE
src/backend/cocoa.m
)
target_compile_definitions(
Mw
PRIVATE
USE_COCOA
)
list(APPEND LIBRARIES objc)
target_link_options(
Mw
PRIVATE
-framework Cocoa
)
elseif(CMAKE_SYSTEM_NAME MATCHES "Retro")
target_sources(
Mw
PRIVATE
src/backend/classicmacos.c
)
if(PLATFORM MATCHES retroppc)
set_target_properties(Mw PROPERTIES COMPILE_FLAGS "-ffunction-sections -mcpu=601 -Os -Wall -Wextra -Wno-unused-parameter")
set_target_properties(Mw PROPERTIES LINK_FLAGS "-Wl,-gc-sections")
endif()
list(APPEND LIBRARIES InterfaceLib WindowsLib ThreadsLib)
target_compile_definitions(
Mw
PRIVATE
CLASSIC_MAC_OS
)
else()
find_package(PkgConfig)
pkg_check_modules(X11 REQUIRED x11)
@ -178,7 +355,15 @@ target_link_libraries(
${LIBRARIES}
)
if(BUILD_VULKAN)
if(MW_BUILD_OPENGL)
target_compile_definitions(
Mw
PRIVATE
MW_OPENGL
)
endif()
if(MW_BUILD_VULKAN)
check_include_files(vulkan/vk_enum_string_helper.h HAS_VK_ENUM_STRING_HELPER)
if(HAS_VK_ENUM_STRING_HELPER)
target_compile_definitions(
@ -187,6 +372,12 @@ if(BUILD_VULKAN)
HAS_VK_ENUM_STRING_HELPER
)
endif()
target_compile_definitions(
Mw
PRIVATE
MW_VULKAN
)
endif()
target_compile_definitions(
@ -195,19 +386,21 @@ target_compile_definitions(
_MILSKO
)
include(GNUInstallDirs)
install(
TARGETS Mw
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
if(MW_INSTALL_HEADERS)
install(
DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.h"
)
endif()
if(BUILD_EXAMPLES)
if(MW_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

74
Jenkinsfile vendored Normal file
View file

@ -0,0 +1,74 @@
pipeline {
agent {
label "built-in"
}
stages {
stage("Build document") {
when {
branch "master"
}
agent {
label "built-in"
}
steps {
sh("rm -rf include/Mw/LowLevel/Wayland")
sh("doxygen")
sh("rm -rf /var/www/milsko-doxygen")
sh("mv doxygen/html /var/www/milsko-doxygen")
}
post {
always {
notifyDiscord()
}
}
}
stage("Build") {
parallel {
stage("Build for Linux 64-bit") {
agent {
label "built-in"
}
steps {
sh("./configure --enable-opengl --enable-vulkan --without-vulkan-string-helper")
sh("make clean")
sh("make -j4")
}
}
stage("Build for Windows 32-bit") {
agent {
label "built-in"
}
steps {
sh("./configure --enable-opengl --enable-stb-truetype --disable-freetype2 --cross --target=Windows --host=i686-w64-mingw32")
sh("make clean")
sh("make -j4")
}
}
stage("Build for Windows 64-bit") {
agent {
label "built-in"
}
steps {
sh("./configure --enable-opengl --enable-stb-truetype --disable-freetype2 --cross --target=Windows --host=x86_64-w64-mingw32")
sh("make clean")
sh("make -j4")
}
}
stage("Build for Windows 32-bit (MSVC)") {
agent {
label "2012r2"
}
steps {
bat("nmake -f NTMakefile clean")
bat("nmake -f NTMakefile")
}
}
}
post {
always {
notifyDiscord()
}
}
}
}
}

View file

@ -1,24 +0,0 @@
# vim: syntax=tcl
proc run {project_name} {
if { "$project_name" == "MilskoDoxygen" } {
RunCommand "doxygen"
RunCommand "rm -rf /var/www/milsko-doxygen"
RunCommand "mv doxygen/html /var/www/milsko-doxygen"
} else {
foreach target {"Linux" "Win32" "Win64"} {
if { [file exists "Makefile"] == 1 } {
RunCommand "make distclean"
}
if { "$target" == "Linux" } {
RunCommand "./Makefile.pl --enable-opengl --enable-vulkan --without-vulkan-string-helper"
} elseif { "$target" == "Win32" } {
RunCommand "./Makefile.pl --enable-opengl --enable-stb-truetype --disable-freetype2 --cross --target=Windows --host=i686-w64-mingw32"
} elseif { "$target" == "Win64" } {
RunCommand "./Makefile.pl --enable-opengl --enable-stb-truetype --disable-freetype2 --cross --target=Windows --host=x86_64-w64-mingw32"
}
RunCommand "make clean"
RunCommand "make -j4"
}
}
}

View file

@ -1,4 +1,4 @@
Copyright (c) 2025, Pyrite development team
Copyright (c) 2025-2026, Pyrite development team
All rights reserved.
Redistribution and use in source and binary forms, with or without

36
NTMakefile generated
View file

@ -1,11 +1,26 @@
CC = cl /TC /c /nologo
LD = link /nologo
CFLAGS = /Iinclude /D_MILSKO /DUSE_GDI /DUSE_STB_TRUETYPE /DUSE_STB_IMAGE /DSTBI_NO_SIMD
CFLAGS = /Iinclude /Iexternal\libz\include /D_MILSKO /DUSE_GDI /DUSE_STB_TRUETYPE /DUSE_STB_IMAGE /DSTBI_NO_SIMD
LDFLAGS = /DLL
.SUFFIXES: .obj .c
all: src\Mw.dll
clean:
del /f /q external\libz\src\adler32.obj
del /f /q external\libz\src\compress.obj
del /f /q external\libz\src\crc32.obj
del /f /q external\libz\src\deflate.obj
del /f /q external\libz\src\gzclose.obj
del /f /q external\libz\src\gzlib.obj
del /f /q external\libz\src\gzread.obj
del /f /q external\libz\src\gzwrite.obj
del /f /q external\libz\src\infback.obj
del /f /q external\libz\src\inffast.obj
del /f /q external\libz\src\inflate.obj
del /f /q external\libz\src\inftrees.obj
del /f /q external\libz\src\trees.obj
del /f /q external\libz\src\uncompr.obj
del /f /q external\libz\src\zutil.obj
del /f /q external\stb_ds.obj
del /f /q external\stb_image.obj
del /f /q external\stb_truetype.obj
@ -26,11 +41,6 @@ clean:
del /f /q src\dialog\filechooser.obj
del /f /q src\dialog\messagebox.obj
del /f /q src\draw.obj
del /f /q src\error.obj
del /f /q src\font\boldfont.obj
del /f /q src\font\boldttf.obj
del /f /q src\font\font.obj
del /f /q src\font\ttf.obj
del /f /q src\icon\back.obj
del /f /q src\icon\clock.obj
del /f /q src\icon\computer.obj
@ -49,7 +59,15 @@ clean:
del /f /q src\icon\warning.obj
del /f /q src\lowlevel.obj
del /f /q src\string.obj
del /f /q src\text.obj
del /f /q src\text\font\boldfont.obj
del /f /q src\text\font\boldmonottf.obj
del /f /q src\text\font\boldttf.obj
del /f /q src\text\font\font.obj
del /f /q src\text\font\monottf.obj
del /f /q src\text\font\ttf.obj
del /f /q src\text\ft2.obj
del /f /q src\text\stbtt.obj
del /f /q src\text\text.obj
del /f /q src\unicode.obj
del /f /q src\widget\box.obj
del /f /q src\widget\button.obj
@ -74,8 +92,8 @@ clean:
del /f /q src\Mw.dll
del /f /q src\Mw.lib
src\Mw.dll: external\stb_ds.obj external\stb_image.obj external\stb_truetype.obj src\abstract\directory.obj src\abstract\dynamic.obj src\abstract\time.obj src\backend\gdi.obj src\color.obj src\core.obj src\cursor\arrow.obj src\cursor\cross.obj src\cursor\default.obj src\cursor\hidden.obj src\cursor\text.obj src\default.obj src\dialog\colorpicker.obj src\dialog\directorychooser.obj src\dialog\filechooser.obj src\dialog\messagebox.obj src\draw.obj src\error.obj src\font\boldfont.obj src\font\boldttf.obj src\font\font.obj src\font\ttf.obj src\icon\back.obj src\icon\clock.obj src\icon\computer.obj src\icon\directory.obj src\icon\down.obj src\icon\error.obj src\icon\file.obj src\icon\forward.obj src\icon\info.obj src\icon\left.obj src\icon\news.obj src\icon\note.obj src\icon\right.obj src\icon\search.obj src\icon\up.obj src\icon\warning.obj src\lowlevel.obj src\string.obj src\text.obj src\unicode.obj src\widget\box.obj src\widget\button.obj src\widget\checkbox.obj src\widget\combobox.obj src\widget\entry.obj src\widget\frame.obj src\widget\image.obj src\widget\label.obj src\widget\listbox.obj src\widget\menu.obj src\widget\numberentry.obj src\widget\opengl.obj src\widget\progressbar.obj src\widget\radiobox.obj src\widget\scrollbar.obj src\widget\separator.obj src\widget\submenu.obj src\widget\treeview.obj src\widget\viewport.obj src\widget\window.obj
$(LD) $(LDFLAGS) /OUT:$@ external\stb_ds.obj external\stb_image.obj external\stb_truetype.obj src\abstract\directory.obj src\abstract\dynamic.obj src\abstract\time.obj src\backend\gdi.obj src\color.obj src\core.obj src\cursor\arrow.obj src\cursor\cross.obj src\cursor\default.obj src\cursor\hidden.obj src\cursor\text.obj src\default.obj src\dialog\colorpicker.obj src\dialog\directorychooser.obj src\dialog\filechooser.obj src\dialog\messagebox.obj src\draw.obj src\error.obj src\font\boldfont.obj src\font\boldttf.obj src\font\font.obj src\font\ttf.obj src\icon\back.obj src\icon\clock.obj src\icon\computer.obj src\icon\directory.obj src\icon\down.obj src\icon\error.obj src\icon\file.obj src\icon\forward.obj src\icon\info.obj src\icon\left.obj src\icon\news.obj src\icon\note.obj src\icon\right.obj src\icon\search.obj src\icon\up.obj src\icon\warning.obj src\lowlevel.obj src\string.obj src\text.obj src\unicode.obj src\widget\box.obj src\widget\button.obj src\widget\checkbox.obj src\widget\combobox.obj src\widget\entry.obj src\widget\frame.obj src\widget\image.obj src\widget\label.obj src\widget\listbox.obj src\widget\menu.obj src\widget\numberentry.obj src\widget\opengl.obj src\widget\progressbar.obj src\widget\radiobox.obj src\widget\scrollbar.obj src\widget\separator.obj src\widget\submenu.obj src\widget\treeview.obj src\widget\viewport.obj src\widget\window.obj opengl32.lib gdi32.lib user32.lib
src\Mw.dll: external\libz\src\adler32.obj external\libz\src\compress.obj external\libz\src\crc32.obj external\libz\src\deflate.obj external\libz\src\gzclose.obj external\libz\src\gzlib.obj external\libz\src\gzread.obj external\libz\src\gzwrite.obj external\libz\src\infback.obj external\libz\src\inffast.obj external\libz\src\inflate.obj external\libz\src\inftrees.obj external\libz\src\trees.obj external\libz\src\uncompr.obj external\libz\src\zutil.obj external\stb_ds.obj external\stb_image.obj external\stb_truetype.obj src\abstract\directory.obj src\abstract\dynamic.obj src\abstract\time.obj src\backend\gdi.obj src\color.obj src\core.obj src\cursor\arrow.obj src\cursor\cross.obj src\cursor\default.obj src\cursor\hidden.obj src\cursor\text.obj src\default.obj src\dialog\colorpicker.obj src\dialog\directorychooser.obj src\dialog\filechooser.obj src\dialog\messagebox.obj src\draw.obj src\icon\back.obj src\icon\clock.obj src\icon\computer.obj src\icon\directory.obj src\icon\down.obj src\icon\error.obj src\icon\file.obj src\icon\forward.obj src\icon\info.obj src\icon\left.obj src\icon\news.obj src\icon\note.obj src\icon\right.obj src\icon\search.obj src\icon\up.obj src\icon\warning.obj src\lowlevel.obj src\string.obj src\text\font\boldfont.obj src\text\font\boldmonottf.obj src\text\font\boldttf.obj src\text\font\font.obj src\text\font\monottf.obj src\text\font\ttf.obj src\text\ft2.obj src\text\stbtt.obj src\text\text.obj src\unicode.obj src\widget\box.obj src\widget\button.obj src\widget\checkbox.obj src\widget\combobox.obj src\widget\entry.obj src\widget\frame.obj src\widget\image.obj src\widget\label.obj src\widget\listbox.obj src\widget\menu.obj src\widget\numberentry.obj src\widget\opengl.obj src\widget\progressbar.obj src\widget\radiobox.obj src\widget\scrollbar.obj src\widget\separator.obj src\widget\submenu.obj src\widget\treeview.obj src\widget\viewport.obj src\widget\window.obj
$(LD) $(LDFLAGS) /OUT:$@ external\libz\src\adler32.obj external\libz\src\compress.obj external\libz\src\crc32.obj external\libz\src\deflate.obj external\libz\src\gzclose.obj external\libz\src\gzlib.obj external\libz\src\gzread.obj external\libz\src\gzwrite.obj external\libz\src\infback.obj external\libz\src\inffast.obj external\libz\src\inflate.obj external\libz\src\inftrees.obj external\libz\src\trees.obj external\libz\src\uncompr.obj external\libz\src\zutil.obj external\stb_ds.obj external\stb_image.obj external\stb_truetype.obj src\abstract\directory.obj src\abstract\dynamic.obj src\abstract\time.obj src\backend\gdi.obj src\color.obj src\core.obj src\cursor\arrow.obj src\cursor\cross.obj src\cursor\default.obj src\cursor\hidden.obj src\cursor\text.obj src\default.obj src\dialog\colorpicker.obj src\dialog\directorychooser.obj src\dialog\filechooser.obj src\dialog\messagebox.obj src\draw.obj src\icon\back.obj src\icon\clock.obj src\icon\computer.obj src\icon\directory.obj src\icon\down.obj src\icon\error.obj src\icon\file.obj src\icon\forward.obj src\icon\info.obj src\icon\left.obj src\icon\news.obj src\icon\note.obj src\icon\right.obj src\icon\search.obj src\icon\up.obj src\icon\warning.obj src\lowlevel.obj src\string.obj src\text\font\boldfont.obj src\text\font\boldmonottf.obj src\text\font\boldttf.obj src\text\font\font.obj src\text\font\monottf.obj src\text\font\ttf.obj src\text\ft2.obj src\text\stbtt.obj src\text\text.obj src\unicode.obj src\widget\box.obj src\widget\button.obj src\widget\checkbox.obj src\widget\combobox.obj src\widget\entry.obj src\widget\frame.obj src\widget\image.obj src\widget\label.obj src\widget\listbox.obj src\widget\menu.obj src\widget\numberentry.obj src\widget\opengl.obj src\widget\progressbar.obj src\widget\radiobox.obj src\widget\scrollbar.obj src\widget\separator.obj src\widget\submenu.obj src\widget\treeview.obj src\widget\viewport.obj src\widget\window.obj opengl32.lib gdi32.lib user32.lib advapi32.lib
.c.obj:

View file

@ -6,8 +6,10 @@ distributions and building instructions for Milsko GUI Toolkit.
Requirements
Milsko requires the Windows environment with GDI (so anything NT or 9x) or
the Unix-like environment with X11 for runtime.
Milsko requires either
* A Windows environment with GDI (so anything NT or 9x)
* A MacOS environment with Cocoa (10.4 or above supported)
* A Unix-like environment with X11 for runtime.
To build Milsko for Windows, you must have one of following compilers:
* Visual C++ 6.0 or newer
@ -15,7 +17,7 @@ the Unix-like environment with X11 for runtime.
* Open Watcom 2.0 or newer
* MinGW-w64
and for Unix-like:
and for Unix-like and MacOS:
* GNU C Compiler
* Clang
@ -61,8 +63,8 @@ D. MinGW-w64/GCC/Clang
1) Determine if you need Vulkan and/or OpenGL.
2) Run `./Makefile.pl'.
For help, run `./Makefile.pl --help'.
2) Run `./configure'.
For help, run `./configure --help'.
3) Run `make'.

96
WatMakefile generated
View file

@ -1,10 +1,25 @@
CC = wcc386 -bt=nt -q -bd
CC = wcc386 -bt=nt -q -bd -d3
LD = wlink option quiet
CFLAGS = -i=include -d_MILSKO -dUSE_GDI -dUSE_STB_TRUETYPE -dUSE_STB_IMAGE -dSTBI_NO_SIMD
CFLAGS = -i=include -i=external/libz/include -d_MILSKO -dUSE_GDI -dUSE_STB_TRUETYPE -dUSE_STB_IMAGE -dSTBI_NO_SIMD
LDFLAGS = system nt_dll
all: src/Mw.dll
clean: .SYMBOLIC
%erase external/libz/src/adler32.obj
%erase external/libz/src/compress.obj
%erase external/libz/src/crc32.obj
%erase external/libz/src/deflate.obj
%erase external/libz/src/gzclose.obj
%erase external/libz/src/gzlib.obj
%erase external/libz/src/gzread.obj
%erase external/libz/src/gzwrite.obj
%erase external/libz/src/infback.obj
%erase external/libz/src/inffast.obj
%erase external/libz/src/inflate.obj
%erase external/libz/src/inftrees.obj
%erase external/libz/src/trees.obj
%erase external/libz/src/uncompr.obj
%erase external/libz/src/zutil.obj
%erase external/stb_ds.obj
%erase external/stb_image.obj
%erase external/stb_truetype.obj
@ -25,11 +40,6 @@ clean: .SYMBOLIC
%erase src/dialog/filechooser.obj
%erase src/dialog/messagebox.obj
%erase src/draw.obj
%erase src/error.obj
%erase src/font/boldfont.obj
%erase src/font/boldttf.obj
%erase src/font/font.obj
%erase src/font/ttf.obj
%erase src/icon/back.obj
%erase src/icon/clock.obj
%erase src/icon/computer.obj
@ -48,7 +58,15 @@ clean: .SYMBOLIC
%erase src/icon/warning.obj
%erase src/lowlevel.obj
%erase src/string.obj
%erase src/text.obj
%erase src/text/font/boldfont.obj
%erase src/text/font/boldmonottf.obj
%erase src/text/font/boldttf.obj
%erase src/text/font/font.obj
%erase src/text/font/monottf.obj
%erase src/text/font/ttf.obj
%erase src/text/ft2.obj
%erase src/text/stbtt.obj
%erase src/text/text.obj
%erase src/unicode.obj
%erase src/widget/box.obj
%erase src/widget/button.obj
@ -73,11 +91,41 @@ clean: .SYMBOLIC
%erase src/Mw.dll
%erase src/Mw.lib
src/Mw.dll: external/stb_ds.obj external/stb_image.obj external/stb_truetype.obj src/abstract/directory.obj src/abstract/dynamic.obj src/abstract/time.obj src/backend/gdi.obj src/color.obj src/core.obj src/cursor/arrow.obj src/cursor/cross.obj src/cursor/default.obj src/cursor/hidden.obj src/cursor/text.obj src/default.obj src/dialog/colorpicker.obj src/dialog/directorychooser.obj src/dialog/filechooser.obj src/dialog/messagebox.obj src/draw.obj src/error.obj src/font/boldfont.obj src/font/boldttf.obj src/font/font.obj src/font/ttf.obj src/icon/back.obj src/icon/clock.obj src/icon/computer.obj src/icon/directory.obj src/icon/down.obj src/icon/error.obj src/icon/file.obj src/icon/forward.obj src/icon/info.obj src/icon/left.obj src/icon/news.obj src/icon/note.obj src/icon/right.obj src/icon/search.obj src/icon/up.obj src/icon/warning.obj src/lowlevel.obj src/string.obj src/text.obj src/unicode.obj src/widget/box.obj src/widget/button.obj src/widget/checkbox.obj src/widget/combobox.obj src/widget/entry.obj src/widget/frame.obj src/widget/image.obj src/widget/label.obj src/widget/listbox.obj src/widget/menu.obj src/widget/numberentry.obj src/widget/opengl.obj src/widget/progressbar.obj src/widget/radiobox.obj src/widget/scrollbar.obj src/widget/separator.obj src/widget/submenu.obj src/widget/treeview.obj src/widget/viewport.obj src/widget/window.obj
$(LD) $(LDFLAGS) option implib=src/Mw.lib name $@ file external/stb_ds.obj file external/stb_image.obj file external/stb_truetype.obj file src/abstract/directory.obj file src/abstract/dynamic.obj file src/abstract/time.obj file src/backend/gdi.obj file src/color.obj file src/core.obj file src/cursor/arrow.obj file src/cursor/cross.obj file src/cursor/default.obj file src/cursor/hidden.obj file src/cursor/text.obj file src/default.obj file src/dialog/colorpicker.obj file src/dialog/directorychooser.obj file src/dialog/filechooser.obj file src/dialog/messagebox.obj file src/draw.obj file src/error.obj file src/font/boldfont.obj file src/font/boldttf.obj file src/font/font.obj file src/font/ttf.obj file src/icon/back.obj file src/icon/clock.obj file src/icon/computer.obj file src/icon/directory.obj file src/icon/down.obj file src/icon/error.obj file src/icon/file.obj file src/icon/forward.obj file src/icon/info.obj file src/icon/left.obj file src/icon/news.obj file src/icon/note.obj file src/icon/right.obj file src/icon/search.obj file src/icon/up.obj file src/icon/warning.obj file src/lowlevel.obj file src/string.obj file src/text.obj file src/unicode.obj file src/widget/box.obj file src/widget/button.obj file src/widget/checkbox.obj file src/widget/combobox.obj file src/widget/entry.obj file src/widget/frame.obj file src/widget/image.obj file src/widget/label.obj file src/widget/listbox.obj file src/widget/menu.obj file src/widget/numberentry.obj file src/widget/opengl.obj file src/widget/progressbar.obj file src/widget/radiobox.obj file src/widget/scrollbar.obj file src/widget/separator.obj file src/widget/submenu.obj file src/widget/treeview.obj file src/widget/viewport.obj file src/widget/window.obj library clib3r.lib library opengl32.lib library gdi32.lib library user32.lib
src/Mw.dll: external/libz/src/adler32.obj external/libz/src/compress.obj external/libz/src/crc32.obj external/libz/src/deflate.obj external/libz/src/gzclose.obj external/libz/src/gzlib.obj external/libz/src/gzread.obj external/libz/src/gzwrite.obj external/libz/src/infback.obj external/libz/src/inffast.obj external/libz/src/inflate.obj external/libz/src/inftrees.obj external/libz/src/trees.obj external/libz/src/uncompr.obj external/libz/src/zutil.obj external/stb_ds.obj external/stb_image.obj external/stb_truetype.obj src/abstract/directory.obj src/abstract/dynamic.obj src/abstract/time.obj src/backend/gdi.obj src/color.obj src/core.obj src/cursor/arrow.obj src/cursor/cross.obj src/cursor/default.obj src/cursor/hidden.obj src/cursor/text.obj src/default.obj src/dialog/colorpicker.obj src/dialog/directorychooser.obj src/dialog/filechooser.obj src/dialog/messagebox.obj src/draw.obj src/icon/back.obj src/icon/clock.obj src/icon/computer.obj src/icon/directory.obj src/icon/down.obj src/icon/error.obj src/icon/file.obj src/icon/forward.obj src/icon/info.obj src/icon/left.obj src/icon/news.obj src/icon/note.obj src/icon/right.obj src/icon/search.obj src/icon/up.obj src/icon/warning.obj src/lowlevel.obj src/string.obj src/text/font/boldfont.obj src/text/font/boldmonottf.obj src/text/font/boldttf.obj src/text/font/font.obj src/text/font/monottf.obj src/text/font/ttf.obj src/text/ft2.obj src/text/stbtt.obj src/text/text.obj src/unicode.obj src/widget/box.obj src/widget/button.obj src/widget/checkbox.obj src/widget/combobox.obj src/widget/entry.obj src/widget/frame.obj src/widget/image.obj src/widget/label.obj src/widget/listbox.obj src/widget/menu.obj src/widget/numberentry.obj src/widget/opengl.obj src/widget/progressbar.obj src/widget/radiobox.obj src/widget/scrollbar.obj src/widget/separator.obj src/widget/submenu.obj src/widget/treeview.obj src/widget/viewport.obj src/widget/window.obj
$(LD) $(LDFLAGS) option implib=src/Mw.lib name $@ file external/libz/src/adler32.obj file external/libz/src/compress.obj file external/libz/src/crc32.obj file external/libz/src/deflate.obj file external/libz/src/gzclose.obj file external/libz/src/gzlib.obj file external/libz/src/gzread.obj file external/libz/src/gzwrite.obj file external/libz/src/infback.obj file external/libz/src/inffast.obj file external/libz/src/inflate.obj file external/libz/src/inftrees.obj file external/libz/src/trees.obj file external/libz/src/uncompr.obj file external/libz/src/zutil.obj file external/stb_ds.obj file external/stb_image.obj file external/stb_truetype.obj file src/abstract/directory.obj file src/abstract/dynamic.obj file src/abstract/time.obj file src/backend/gdi.obj file src/color.obj file src/core.obj file src/cursor/arrow.obj file src/cursor/cross.obj file src/cursor/default.obj file src/cursor/hidden.obj file src/cursor/text.obj file src/default.obj file src/dialog/colorpicker.obj file src/dialog/directorychooser.obj file src/dialog/filechooser.obj file src/dialog/messagebox.obj file src/draw.obj file src/icon/back.obj file src/icon/clock.obj file src/icon/computer.obj file src/icon/directory.obj file src/icon/down.obj file src/icon/error.obj file src/icon/file.obj file src/icon/forward.obj file src/icon/info.obj file src/icon/left.obj file src/icon/news.obj file src/icon/note.obj file src/icon/right.obj file src/icon/search.obj file src/icon/up.obj file src/icon/warning.obj file src/lowlevel.obj file src/string.obj file src/text/font/boldfont.obj file src/text/font/boldmonottf.obj file src/text/font/boldttf.obj file src/text/font/font.obj file src/text/font/monottf.obj file src/text/font/ttf.obj file src/text/ft2.obj file src/text/stbtt.obj file src/text/text.obj file src/unicode.obj file src/widget/box.obj file src/widget/button.obj file src/widget/checkbox.obj file src/widget/combobox.obj file src/widget/entry.obj file src/widget/frame.obj file src/widget/image.obj file src/widget/label.obj file src/widget/listbox.obj file src/widget/menu.obj file src/widget/numberentry.obj file src/widget/opengl.obj file src/widget/progressbar.obj file src/widget/radiobox.obj file src/widget/scrollbar.obj file src/widget/separator.obj file src/widget/submenu.obj file src/widget/treeview.obj file src/widget/viewport.obj file src/widget/window.obj library clib3r.lib library opengl32.lib library gdi32.lib library user32.lib library advapi32.lib
external/libz/src/adler32.obj: external/libz/src/adler32.c
$(CC) $(CFLAGS) -fo=$@ $<
external/libz/src/compress.obj: external/libz/src/compress.c
$(CC) $(CFLAGS) -fo=$@ $<
external/libz/src/crc32.obj: external/libz/src/crc32.c
$(CC) $(CFLAGS) -fo=$@ $<
external/libz/src/deflate.obj: external/libz/src/deflate.c
$(CC) $(CFLAGS) -fo=$@ $<
external/libz/src/gzclose.obj: external/libz/src/gzclose.c
$(CC) $(CFLAGS) -fo=$@ $<
external/libz/src/gzlib.obj: external/libz/src/gzlib.c
$(CC) $(CFLAGS) -fo=$@ $<
external/libz/src/gzread.obj: external/libz/src/gzread.c
$(CC) $(CFLAGS) -fo=$@ $<
external/libz/src/gzwrite.obj: external/libz/src/gzwrite.c
$(CC) $(CFLAGS) -fo=$@ $<
external/libz/src/infback.obj: external/libz/src/infback.c
$(CC) $(CFLAGS) -fo=$@ $<
external/libz/src/inffast.obj: external/libz/src/inffast.c
$(CC) $(CFLAGS) -fo=$@ $<
external/libz/src/inflate.obj: external/libz/src/inflate.c
$(CC) $(CFLAGS) -fo=$@ $<
external/libz/src/inftrees.obj: external/libz/src/inftrees.c
$(CC) $(CFLAGS) -fo=$@ $<
external/libz/src/trees.obj: external/libz/src/trees.c
$(CC) $(CFLAGS) -fo=$@ $<
external/libz/src/uncompr.obj: external/libz/src/uncompr.c
$(CC) $(CFLAGS) -fo=$@ $<
external/libz/src/zutil.obj: external/libz/src/zutil.c
$(CC) $(CFLAGS) -fo=$@ $<
external/stb_ds.obj: external/stb_ds.c
$(CC) $(CFLAGS) -fo=$@ $<
external/stb_image.obj: external/stb_image.c
@ -118,16 +166,6 @@ src/dialog/messagebox.obj: src/dialog/messagebox.c
$(CC) $(CFLAGS) -fo=$@ $<
src/draw.obj: src/draw.c
$(CC) $(CFLAGS) -fo=$@ $<
src/error.obj: src/error.c
$(CC) $(CFLAGS) -fo=$@ $<
src/font/boldfont.obj: src/font/boldfont.c
$(CC) $(CFLAGS) -fo=$@ $<
src/font/boldttf.obj: src/font/boldttf.c
$(CC) $(CFLAGS) -fo=$@ $<
src/font/font.obj: src/font/font.c
$(CC) $(CFLAGS) -fo=$@ $<
src/font/ttf.obj: src/font/ttf.c
$(CC) $(CFLAGS) -fo=$@ $<
src/icon/back.obj: src/icon/back.c
$(CC) $(CFLAGS) -fo=$@ $<
src/icon/clock.obj: src/icon/clock.c
@ -164,7 +202,23 @@ src/lowlevel.obj: src/lowlevel.c
$(CC) $(CFLAGS) -fo=$@ $<
src/string.obj: src/string.c
$(CC) $(CFLAGS) -fo=$@ $<
src/text.obj: src/text.c
src/text/font/boldfont.obj: src/text/font/boldfont.c
$(CC) $(CFLAGS) -fo=$@ $<
src/text/font/boldmonottf.obj: src/text/font/boldmonottf.c
$(CC) $(CFLAGS) -fo=$@ $<
src/text/font/boldttf.obj: src/text/font/boldttf.c
$(CC) $(CFLAGS) -fo=$@ $<
src/text/font/font.obj: src/text/font/font.c
$(CC) $(CFLAGS) -fo=$@ $<
src/text/font/monottf.obj: src/text/font/monottf.c
$(CC) $(CFLAGS) -fo=$@ $<
src/text/font/ttf.obj: src/text/font/ttf.c
$(CC) $(CFLAGS) -fo=$@ $<
src/text/ft2.obj: src/text/ft2.c
$(CC) $(CFLAGS) -fo=$@ $<
src/text/stbtt.obj: src/text/stbtt.c
$(CC) $(CFLAGS) -fo=$@ $<
src/text/text.obj: src/text/text.c
$(CC) $(CFLAGS) -fo=$@ $<
src/unicode.obj: src/unicode.c
$(CC) $(CFLAGS) -fo=$@ $<

View file

@ -14,11 +14,12 @@ our $prefix = "/usr/local";
our $cc = defined($ENV{CC}) ? $ENV{CC} : "*host*gcc";
our $ar = defined($ENV{AR}) ? $ENV{AR} : "*host*ar";
our $incdir = "-I include";
our $cflags = "-fPIC -D_MILSKO";
our $incdir2 = "";
our $cflags = "-fPIC -D_MILSKO -fvisibility=hidden";
our $libdir = "";
our $ldflags = "";
our $math = "-lm";
our $shared = "-shared";
our @shared = "-shared";
our @backends = ();
our $library_prefix = "lib";
@ -37,18 +38,18 @@ require("./pl/utils.pl");
param_set("classic-theme", 0);
param_set("stb-image", 1);
param_set("stb-truetype", 0);
param_set("freetype2", 1);
param_set("xrender", 1);
param_set("opengl", 0);
param_set("vulkan", 0);
param_set("vulkan-string-helper", 1);
param_set("shared", 1);
param_set("static", 1);
param_set("examples", 1);
my %features = (
"classic-theme" => "use classic theme",
"stb-image" => "use stb_image instead of libjpeg/libpng",
"stb-image" => "use stb_image, instead use libjpeg/libpng",
"stb-truetype" => "use stb_truetype",
"freetype2" => "use FreeType2",
"xrender" => "use XRender",
@ -56,14 +57,17 @@ my %features = (
"vulkan" => "build Vulkan widget",
"vulkan-string-helper" => "use Vulkan string helper",
"shared" => "build shared library",
"static" => "build static library"
"static" => "build static library",
"wayland" => "enable wayland backend",
"gnustep" => "use gnustep",
);
my @features_keys = (
"1classic-theme", "1stb-image",
"1stb-truetype", "1freetype2",
"1opengl", "2xrender",
"1vulkan", "2vulkan-string-helper",
"1shared", "1static"
"1shared", "1static",
"1wayland", "1gnustep",
);
foreach my $l (@ARGV) {
@ -82,9 +86,15 @@ foreach my $l (@ARGV) {
elsif ($l =~ /^--host=(.+)$/) {
$host = $1 . "-";
}
elsif ($l =~ /^--cflags=(.+)$/) {
add_cflags($1);
}
elsif ($l eq "--cross") {
$cross = 1;
}
elsif ($l eq "--tiny") {
param_set("tiny",1);
}
elsif (($l eq "-h") or ($l eq "--help")) {
print("Milsko Toolkit Configuration Utility\n");
print("\n");
@ -95,6 +105,8 @@ foreach my $l (@ARGV) {
print(" --prefix=PREFIX Installation prefix\n");
print(" --host=TARGET Host for compiler/archiver\n");
print(" --target=TARGET Specify target\n");
print(" --cflags=CFLAGS Add cflags\n");
print(" --tiny Build smallest possible library\n");
print(" --cross Indicate cross compilation\n");
print("\n");
print("Features:\n");
@ -120,6 +132,21 @@ foreach my $l (@ARGV) {
}
}
if($target ne "Darwin" and $target ne "ClassicMacOS" and $target ne "Windows") {
param_set("freetype2", 1);
param_set("stb-truetype", 0);
} else {
param_set("freetype2", 0);
param_set("stb-truetype", 0);
}
if($target eq "Linux") {
param_set("x11", 1);
if(!param_get("tiny")){
param_set("wayland", 1);
}
}
if (-f "./pl/ostype/${target}.pl") {
require("./pl/ostype/${target}.pl");
}
@ -158,13 +185,13 @@ open(OUT, ">", "Makefile");
print(OUT "PREFIX = ${prefix}\n");
print(OUT "AR = ${ar}\n");
print(OUT "CC = ${cc}\n");
print(OUT "INCDIR = ${incdir}\n");
print(OUT "INCDIR = ${incdir} ${incdir2}\n");
print(OUT "CFLAGS = ${cflags}\n");
print(OUT "LIBDIR = ${libdir}\n");
print(OUT "LDFLAGS = ${ldflags}\n");
print(OUT "LIBS = ${math} ${libs}\n");
print(OUT "MATH = ${math}\n");
print(OUT "SHARED = ${shared}\n");
print(OUT "SHARED = @{shared}\n");
print(OUT "\n");
print(OUT ".PHONY: all format clean distclean lib examples install\n");
print(OUT "\n");
@ -181,10 +208,10 @@ print(OUT " cp -rf include \$(DESTDIR)\$(PREFIX)/\n");
print(OUT "\n");
print(OUT "format:\n");
print(OUT
" clang-format --verbose -i `find src include examples -name \"*.c\" -or -name \"*.h\"`\n"
" clang-format --verbose -i `find src include examples \"(\" -name \"*.c\" -or -name \"*.h\" -or -name \"*.m\" \")\" -and -not -name \"*ttf.c\"`\n"
);
print(OUT
" perltidy -b -bext=\"/\" --paren-tightness=2 `find tools pl Makefile.pl -name \"*.pl\"`\n"
" perltidy -b -bext=\"/\" --paren-tightness=2 `find tools pl configure -name \"*.pl\"`\n"
);
print(OUT "\n");
print(OUT "lib:");
@ -217,17 +244,24 @@ foreach my $l (@library_targets) {
my $s = $l;
my $o = $object_suffix;
$o =~ s/\./\\\./g;
if ($l =~ /cocoa/) {
$s =~ s/$o$/.m/;
}
else {
$s =~ s/$o$/.c/;
}
if ($l =~ /^external\//) {
$warn = "";
}
print(OUT "${l}: ${s}\n");
print(OUT " \$(CC) $warn \$(CFLAGS\) \$\(INCDIR) -c -o ${l} ${s}\n");
print(OUT " \$(CC) $warn \$\(INCDIR) \$(CFLAGS\) -c -o ${l} ${s}\n");
}
print(OUT "\n");
print(OUT "\n");
if (param_get("examples")) {
print(OUT "examples: " . join(" ", @examples_targets) . "\n");
print(OUT "\n");
foreach my $l (@examples_targets) {
@ -241,21 +275,44 @@ foreach my $l (@examples_targets) {
$libs = $examples_libs{$l};
}
if (param_get("shared")) {
print(OUT
"${l}: ${s}${object_suffix} src/${library_prefix}Mw${library_suffix}\n"
);
} else {
print(OUT
"${l}: ${s}${object_suffix} src/${library_prefix}Mw.a\n"
);
}
if (grep(/^cocoa$/, @backends)) {
print(OUT
" \$(CC) -L./src \$\(LIBDIR) -o ${l} ${s}${object_suffix} -lMw ${math} ${libs}\n"
);
}
else {
print(OUT
" \$(CC) -L src -Wl,-R./src \$\(LIBDIR) -o ${l} ${s}${object_suffix} -lMw ${math} ${libs}\n"
);
}
if($target eq "ClassicMacOS") {
print(OUT
" ".$ENV{RETRO68_TOOLCHAIN_PATH}."/bin/MakePEF ${l} -o ${s}.pef\n");
print(OUT
" Rez -I ".$ENV{RETRO68_TOOLCHAIN_PATH}."/RIncludes ".$ENV{RETRO68_TOOLCHAIN_PATH}."/RIncludes/Retro68APPL.r -DCFRAG_NAME=\"example\" --data ${l}.pef --cc ${l}.dsk -t APPL\n"
);
}
print(OUT "${s}${object_suffix}: ${s}.c\n");
print(OUT
" \$(CC) -c \$\(INCDIR) -o ${s}${object_suffix} ${s}.c -lMw ${math}\n"
);
}
}
print(OUT "\n");
print(OUT "clean:\n");
print(OUT
" rm -f */*.o */*/*.o */*/*/*.o */*.exe */*/*.exe */*/*/*.exe src/*.so src/*.dll src/*.a "
" rm -f */*.o */*/*.o */*/*/*.o */*.exe */*/*.exe */*/*/*.exe src/*.so src/*.dll src/*.dylib src/*.a "
. join(" ", @examples_targets)
. "\n");
print(OUT "\n");

8
doc/TINYCONFIG.md Normal file
View file

@ -0,0 +1,8 @@
# Tiny Config
Milsko's configure script supports the `--tiny` option for building the tiniest possible Milsko library (~400kb as of writing). Currently, what it does is:
- Add `-Oz` to the cflags
- (clang only) add `-flto=thin` to the cflags and linker flags
- Build stb-image with `STB_IMAGE_STATIC` (this is why you get warnings with stb_image when you use it)
- Disable the Wayland backend

View file

@ -1 +1,7 @@
add_subdirectory(basic)
if(${MW_TRY_OPENGL})
add_subdirectory(gldemos)
endif()
if(${MW_TRY_VULKAN})
add_subdirectory(vkdemos)
endif()

View file

@ -6,7 +6,11 @@ file(
foreach(PATH IN LISTS EXAMPLES_BASIC_SOURCES)
get_filename_component(TARGET ${PATH} NAME_WE)
add_executable(${TARGET} ${PATH})
if(CMAKE_SYSTEM_NAME MATCHES Retro)
add_application(${TARGET} ${PATH})
else()
add_executable(${TARGET} MACOSX_BUNDLE ${PATH})
endif()
target_link_libraries(
${TARGET}
PRIVATE

185
examples/basic/calculator.c Normal file
View file

@ -0,0 +1,185 @@
#include <Mw/Milsko.h>
MwWidget widgets[18];
MwWidget inp;
/* probably enough for most tasks */
double stack[512];
int sp = 0;
static void resize(MwWidget handle, void* client, void* user) {
int ww = MwGetInteger(handle, MwNwidth);
int wh = MwGetInteger(handle, MwNheight) - MwGetInteger(inp, MwNheight);
int i;
MwVaApply(inp,
MwNwidth, ww,
NULL);
for(i = 0; i < sizeof(widgets) / sizeof(widgets[0]); i++) {
int x = i % 4;
int y = i / 4;
if(widgets[i] != NULL) {
MwVaApply(widgets[i],
MwNwidth, ww / 4,
MwNheight, wh / 5,
MwNx, ww / 4 * x,
MwNy, wh / 5 * y + MwGetInteger(inp, MwNheight),
NULL);
}
}
}
static void activate(MwWidget handle, void* client, void* user) {
const char* n = MwGetText(handle, MwNtext);
if(('0' <= n[0] && n[0] <= '9') || n[0] == '.') {
const char* s = MwGetText(inp, MwNtext);
char* r;
if(n[0] == '.' && s != NULL) {
int i;
for(i = 0; s[i] != 0; i++) {
if(s[i] == '.') return;
}
}
if(s == NULL) s = "";
r = MwStringConcat(s, n);
MwVaApply(inp,
MwNtext, r,
NULL);
free(r);
} else if(n[0] == 'E') {
const char* s = MwGetText(inp, MwNtext);
if(s != NULL) {
stack[sp++] = atof(s);
MwVaApply(inp,
MwNtext, "",
NULL);
}
} else if(n[0] == 'C') {
MwVaApply(inp,
MwNtext, "",
NULL);
} else if(n[0] == '+' || n[0] == '-' || n[0] == '*' || n[0] == '/') {
if(sp >= 2) {
double sv = stack[--sp];
double fv = stack[--sp];
double v;
char buf[256];
if(n[0] == '+') {
v = fv + sv;
} else if(n[0] == '-') {
v = fv - sv;
} else if(n[0] == '*') {
v = fv * sv;
} else if(n[0] == '/') {
v = fv / sv;
}
MwStringPrintIntoBuffer(buf, 256, "%g", v);
MwVaApply(inp,
MwNtext, buf,
NULL);
}
}
}
int main() {
MwWidget w;
int i;
for(i = 0; i < sizeof(widgets) / sizeof(widgets[0]); i++) widgets[i] = NULL;
MwLibraryInit();
w = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 150, 150,
MwNtitle, "Calculator",
NULL);
inp = MwCreateWidget(MwEntryClass, "entry", w, 0, 0, 0, 24);
widgets[0] = MwVaCreateWidget(MwButtonClass, "7", w, 0, 0, 0, 0,
MwNtext, "7",
NULL);
widgets[1] = MwVaCreateWidget(MwButtonClass, "8", w, 0, 0, 0, 0,
MwNtext, "8",
NULL);
widgets[2] = MwVaCreateWidget(MwButtonClass, "9", w, 0, 0, 0, 0,
MwNtext, "9",
NULL);
widgets[3] = MwVaCreateWidget(MwButtonClass, "/", w, 0, 0, 0, 0,
MwNtext, "/",
NULL);
widgets[4] = MwVaCreateWidget(MwButtonClass, "4", w, 0, 0, 0, 0,
MwNtext, "4",
NULL);
widgets[5] = MwVaCreateWidget(MwButtonClass, "5", w, 0, 0, 0, 0,
MwNtext, "5",
NULL);
widgets[6] = MwVaCreateWidget(MwButtonClass, "6", w, 0, 0, 0, 0,
MwNtext, "6",
NULL);
widgets[7] = MwVaCreateWidget(MwButtonClass, "*", w, 0, 0, 0, 0,
MwNtext, "*",
NULL);
widgets[8] = MwVaCreateWidget(MwButtonClass, "1", w, 0, 0, 0, 0,
MwNtext, "1",
NULL);
widgets[9] = MwVaCreateWidget(MwButtonClass, "2", w, 0, 0, 0, 0,
MwNtext, "2",
NULL);
widgets[10] = MwVaCreateWidget(MwButtonClass, "3", w, 0, 0, 0, 0,
MwNtext, "3",
NULL);
widgets[11] = MwVaCreateWidget(MwButtonClass, "-", w, 0, 0, 0, 0,
MwNtext, "-",
NULL);
widgets[12] = MwVaCreateWidget(MwButtonClass, "0", w, 0, 0, 0, 0,
MwNtext, "0",
NULL);
widgets[13] = MwVaCreateWidget(MwButtonClass, ".", w, 0, 0, 0, 0,
MwNtext, ".",
NULL);
widgets[16] = MwVaCreateWidget(MwButtonClass, "E", w, 0, 0, 0, 0,
MwNtext, "E",
NULL);
widgets[15] = MwVaCreateWidget(MwButtonClass, "+", w, 0, 0, 0, 0,
MwNtext, "+",
NULL);
widgets[17] = MwVaCreateWidget(MwButtonClass, "C", w, 0, 0, 0, 0,
MwNtext, "C",
NULL);
for(i = 0; i < sizeof(widgets) / sizeof(widgets[0]); i++) {
if(widgets[i] != NULL) MwAddUserHandler(widgets[i], MwNactivateHandler, activate, NULL);
}
MwAddUserHandler(w, MwNresizeHandler, resize, NULL);
resize(w, NULL, NULL);
MwLoop(w);
}

View file

@ -0,0 +1,78 @@
#include <Mw/Milsko.h>
MwWidget window, instructions, text1, text2, cur_text;
static void resize(MwWidget handle, void* user_data, void* call_data) {
unsigned int w, h;
(void)user_data;
(void)call_data;
w = MwGetInteger(handle, MwNwidth);
h = MwGetInteger(handle, MwNheight);
MwVaApply(instructions,
MwNy, 50,
MwNwidth, w - 50 * 2,
MwNheight, h - 125 - 50 * 3,
NULL);
MwVaApply(text1,
MwNy, 150,
MwNwidth, w - 25 * 2,
MwNheight, h - 125 - 50 * 3,
NULL);
MwVaApply(text2,
MwNy, 250,
MwNwidth, w - 25 * 2,
MwNheight, h - 125 - 50 * 3,
NULL);
}
static void clipboard(MwWidget handle, void* user_data, void* call_data) {
char* clipboard = call_data;
(void)handle;
(void)user_data;
if(clipboard != NULL) {
MwVaApply(cur_text, MwNtext, clipboard, NULL);
MwForceRender(cur_text);
}
}
static void tick(MwWidget handle, void* user_data, void* call_data) {
cur_text = text1;
MwGetClipboard(handle, MwCLIPBOARD_MAIN);
cur_text = text2;
MwGetClipboard(handle, MwCLIPBOARD_PRIMARY);
MwForceRender(window);
}
int main() {
MwLibraryInit();
window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 400, 400,
MwNtitle, "clipboard",
NULL);
instructions = MwVaCreateWidget(MwLabelClass, "button", window, 50, 50, 300, 125,
MwNtext, "clipboard contents will show up below.",
NULL);
text1 = MwVaCreateWidget(MwLabelClass, "label", window, 25, 150, 300, 75,
MwNtext, "",
NULL);
text2 = MwVaCreateWidget(MwLabelClass, "label2", window, 25, 250, 300, 75,
MwNtext, "",
NULL);
cur_text = text1;
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
MwAddUserHandler(window, MwNclipboardHandler, clipboard, NULL);
MwAddUserHandler(instructions, MwNclipboardHandler, clipboard, NULL);
MwAddUserHandler(cur_text, MwNclipboardHandler, clipboard, NULL);
MwAddUserHandler(window, MwNtickHandler, tick, NULL);
resize(window, NULL, NULL);
MwLoop(window);
}

View file

@ -1,4 +1,3 @@
#include <Mw/Milsko.h>
MwWidget cpicker;
@ -15,7 +14,7 @@ void color_callback(MwWidget handle, void* user_data, void* call_data) {
rgb->red &= 0xff;
rgb->green &= 0xff;
rgb->blue &= 0xff;
sprintf(hexColor, "#%02X%02X%02X", rgb->red, rgb->green, rgb->blue);
MwStringPrintIntoBuffer(hexColor, 8, "#%02X%02X%02X", rgb->red, rgb->green, rgb->blue);
MwSetText(window, MwNbackground, hexColor);
}
@ -28,7 +27,7 @@ void color_picker(MwWidget handle, void* user_data, void* call_data) {
MwAddUserHandler(cpicker, MwNcolorChosenHandler, color_callback, NULL);
MwSetText(cpicker, MwNbackground, MwDefaultBackground);
MwSetText(cpicker, MwNbackground, MwGetInteger(cpicker, MwNdarkTheme) ? MwDefaultDarkBackground : MwDefaultBackground);
}
int main() {
@ -36,12 +35,12 @@ int main() {
window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT,
MwDEFAULT, 640, 480, MwNtitle, "color picker", NULL);
MwSetText(window, MwNbackground, "#000000");
MwSetText(window, MwNbackground, MwGetInteger(window, MwNdarkTheme) ? MwDefaultBackground : MwDefaultDarkBackground);
button = MwVaCreateWidget(MwButtonClass, "button", window, 160, 180, 320, 120,
MwNtext, "change window background",
NULL);
MwSetText(button, MwNbackground, MwDefaultBackground);
MwSetText(button, MwNbackground, MwGetInteger(window, MwNdarkTheme) ? MwDefaultBackground : MwDefaultDarkBackground);
MwAddUserHandler(button, MwNactivateHandler, color_picker, NULL);

View file

@ -1,6 +1,6 @@
#include <Mw/Milsko.h>
MwWidget window, menu, button, button2, button3, button4;
MwWidget window, menu, button, button2, button3, button4, button5, button6;
void handler(MwWidget handle, void* user_data, void* call_data) {
(void)handle;
@ -10,14 +10,34 @@ void handler(MwWidget handle, void* user_data, void* call_data) {
printf("hello world!\n");
}
int toggle = 0;
void handler_dark(MwWidget handle, void* user_data, void* call_data) {
void handler_theme(MwWidget handle, void* user_data, void* call_data) {
(void)handle;
(void)user_data;
(void)call_data;
toggle = toggle ? 0 : 1;
MwToggleDarkTheme(window, toggle);
MwVaApply(window,
MwNdarkTheme, MwGetInteger(window, MwNdarkTheme) == 0 ? 1 : 0,
NULL);
}
void handler_look(MwWidget handle, void* user_data, void* call_data) {
(void)handle;
(void)user_data;
(void)call_data;
MwVaApply(window,
MwNmodernLook, MwGetInteger(window, MwNmodernLook) == 0 ? 1 : 0,
NULL);
}
void handler_font(MwWidget handle, void* user_data, void* call_data) {
(void)handle;
(void)user_data;
(void)call_data;
MwVaApply(window,
MwNbitmapFont, MwGetInteger(window, MwNbitmapFont) == 0 ? 1 : 0,
NULL);
}
void resize(MwWidget handle, void* user_data, void* call_data) {
@ -31,23 +51,37 @@ void resize(MwWidget handle, void* user_data, void* call_data) {
MwVaApply(button,
MwNy, 50 + mh,
MwNwidth, w - 50 * 2,
MwNwidth, (w - 50 * 2) / 3,
MwNheight, h - 125 - 50 * 3,
NULL);
MwVaApply(button2,
MwNx, 50 + (w - 50 * 2) / 3,
MwNy, 50 + mh,
MwNwidth, (w - 50 * 2) / 3,
MwNheight, h - 125 - 50 * 3,
NULL);
MwVaApply(button3,
MwNx, 50 + (w - 50 * 2) / 3 * 2,
MwNy, 50 + mh,
MwNwidth, (w - 50 * 2) / 3,
MwNheight, h - 125 - 50 * 3,
NULL);
MwVaApply(button4,
MwNx, 50 + (w - 50 * 2) / 3 * 0,
MwNy, h - 50 - 125 + mh,
MwNwidth, (w - 50 * 2) / 3,
NULL);
MwVaApply(button3,
MwVaApply(button5,
MwNx, 50 + (w - 50 * 2) / 3 * 1,
MwNy, h - 50 - 125 + mh,
MwNwidth, (w - 50 * 2) / 3,
NULL);
MwVaApply(button4,
MwVaApply(button6,
MwNx, 50 + (w - 50 * 2) / 3 * 2,
MwNy, h - 50 - 125 + mh,
MwNwidth, (w - 50 * 2) / 3,
@ -63,30 +97,38 @@ int main() {
MwNtitle, "hello world",
NULL);
menu = MwCreateWidget(MwMenuClass, "menu", window, 0, 0, 0, 0);
button = MwVaCreateWidget(MwButtonClass, "button", window, 50, 50, 300, 125,
MwNtext, "toggle dark theme",
button = MwVaCreateWidget(MwButtonClass, "button", window, 50, 50, 100, 125,
MwNtext, "theme",
NULL);
button2 = MwVaCreateWidget(MwButtonClass, "button", window, 50, 225, 100, 125,
button2 = MwVaCreateWidget(MwButtonClass, "button", window, 150, 50, 100, 125,
MwNtext, "look",
NULL);
button3 = MwVaCreateWidget(MwButtonClass, "button", window, 250, 50, 100, 125,
MwNtext, "font",
NULL);
button4 = MwVaCreateWidget(MwButtonClass, "button", window, 50, 225, 100, 125,
MwNtext, "lorem ipsum",
MwNbackground, "#f66",
MwNforeground, "#000",
NULL);
button3 = MwVaCreateWidget(MwButtonClass, "button", window, 150, 225, 100, 125,
button5 = MwVaCreateWidget(MwButtonClass, "button", window, 150, 225, 100, 125,
MwNtext, "lorem ipsum",
MwNbackground, "#6f6",
MwNforeground, "#000",
NULL);
button4 = MwVaCreateWidget(MwButtonClass, "button", window, 250, 225, 100, 125,
button6 = MwVaCreateWidget(MwButtonClass, "button", window, 250, 225, 100, 125,
MwNtext, "lorem ipsum",
MwNbackground, "#66f",
MwNforeground, "#000",
NULL);
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
MwAddUserHandler(button, MwNactivateHandler, handler_dark, NULL);
MwAddUserHandler(button2, MwNactivateHandler, handler, NULL);
MwAddUserHandler(button3, MwNactivateHandler, handler, NULL);
MwAddUserHandler(button, MwNactivateHandler, handler_theme, NULL);
MwAddUserHandler(button2, MwNactivateHandler, handler_look, NULL);
MwAddUserHandler(button3, MwNactivateHandler, handler_font, NULL);
MwAddUserHandler(button4, MwNactivateHandler, handler, NULL);
MwAddUserHandler(button5, MwNactivateHandler, handler, NULL);
MwAddUserHandler(button6, MwNactivateHandler, handler, NULL);
resize(window, NULL, NULL);

View file

@ -16,7 +16,7 @@ void activate(MwWidget handle, void* user, void* call) {
(void)user;
sprintf(msg, "You pressed: %s", MwListBoxGet(handle, *(int*)call));
MwStringPrintIntoBuffer(msg, 256, "You pressed: %s", MwListBoxGet(handle, *(int*)call));
msgbox = MwMessageBox(wmain, msg, "wow", MwMB_ICONINFO | MwMB_BUTTONOK);
MwAddUserHandler(MwMessageBoxGetChild(msgbox, MwMB_BUTTONOK), MwNactivateHandler, destroy, msgbox);
@ -48,7 +48,7 @@ int main() {
for(i = 0; i < len; i++) {
char sz[16];
sprintf(sz, "%d", (int)strlen(harvard[i]));
MwStringPrintIntoBuffer(sz, 16, "%d", (int)strlen(harvard[i]));
index = MwListBoxPacketInsert(packet, -1);
MwListBoxPacketSetIcon(packet, index, px);
MwListBoxPacketSet(packet, index, 0, harvard[i]);

285
examples/basic/periodic.c Normal file
View file

@ -0,0 +1,285 @@
#include <Mw/Milsko.h>
#include <stdarg.h>
#define Columns 5
#define Padding 20
#define PaddingContent 2
MwWidget window, menu, box;
MwWidget boxes[32];
int n = 0, row = -1;
MwMenu e;
static void resize(MwWidget handle, void* user, void* call) {
int w = MwGetInteger(window, MwNwidth);
int h = MwGetInteger(window, MwNheight);
MwVaApply(box,
MwNx, Padding,
MwNy, MwGetInteger(menu, MwNheight) + Padding,
MwNwidth, w - Padding * 2,
MwNheight, h - MwGetInteger(menu, MwNheight) - Padding * 2,
NULL);
}
static void newrow(void) {
if(row >= 0) {
int i;
for(i = n; i < Columns; i++) MwCreateWidget(MwFrameClass, "frame", boxes[row], 0, 0, 0, 0);
}
boxes[++row] = MwCreateWidget(MwBoxClass, "box", box, 0, 0, 0, 0);
n = 0;
}
static void add(MwWidget w) {
int r = MwGetInteger(w, MwNratio);
if(r == MwDEFAULT) r = 1;
n += r;
if(n == Columns) {
newrow();
}
}
static void resize_content(MwWidget handle, void* user, void* call) {
MwWidget* ws = MwGetChildren(handle);
if(ws != NULL) {
int pw = MwGetInteger(ws[0], "IpWidth");
int ph = MwGetInteger(ws[0], "IpHeight");
if(pw < 0) {
pw += MwGetInteger(handle, MwNwidth);
} else if(pw == 0) {
pw = MwGetInteger(handle, MwNwidth);
}
if(ph < 0) {
ph += MwGetInteger(handle, MwNheight);
} else if(ph == 0) {
ph = MwGetInteger(handle, MwNheight);
}
MwVaApply(ws[0],
MwNx, (MwGetInteger(handle, MwNwidth) - pw) / 2,
MwNy, (MwGetInteger(handle, MwNheight) - ph) / 2,
MwNwidth, pw,
MwNheight, ph,
NULL);
free(ws);
}
}
static void resize_frame(MwWidget handle, void* user, void* call) {
MwWidget* ws = MwGetChildren(handle);
if(ws != NULL) {
int w = MwGetInteger(handle, MwNwidth);
int h = MwGetInteger(handle, MwNheight);
if(ws[0] != NULL) {
MwVaApply(ws[0],
MwNx, MwDefaultBorderWidth(handle) + PaddingContent,
MwNy, MwDefaultBorderWidth(handle) + PaddingContent,
MwNwidth, w - (MwDefaultBorderWidth(handle) + PaddingContent) * 2,
MwNheight, h - (MwDefaultBorderWidth(handle) + PaddingContent) * 2,
NULL);
}
free(ws);
}
}
static MwWidget frame(const char* name, int width, int height, MwClass cl, ...) {
MwWidget f = MwVaCreateWidget(MwFrameClass, "frame", boxes[row], 0, 0, 0, 0,
MwNhasBorder, 1,
MwNinverted, 1,
NULL);
MwWidget box = MwVaCreateWidget(MwBoxClass, "box", f, 0, 0, 0, 0,
MwNorientation, MwVERTICAL,
NULL);
MwWidget label = MwVaCreateWidget(MwLabelClass, "label", box, 0, 0, 0, 0,
MwNtext, name,
MwNalignment, MwALIGNMENT_BEGINNING,
MwNfixedSize, 20,
NULL);
va_list va;
if(cl != NULL) {
MwWidget frame = MwCreateWidget(MwFrameClass, "frame", box, 0, 0, 0, 0);
MwWidget w;
va_start(va, cl);
w = MwVaListCreateWidget(cl, "widget", frame, 0, 0, 0, 0, va);
va_end(va);
MwVaApply(w,
"IpWidth", width,
"IpHeight", height,
NULL);
MwAddUserHandler(frame, MwNresizeHandler, resize_content, NULL);
MwVaApply(f,
"VhandledWidget", w,
NULL);
}
MwAddUserHandler(f, MwNresizeHandler, resize_frame, NULL);
resize_frame(f, NULL, NULL);
return f;
}
static MwWidget child(MwWidget w) {
return MwGetVoid(w, "VhandledWidget");
}
static void menu_handler(MwWidget handle, void* user, void* call) {
if(call == e) MwDestroyWidget(window);
}
int main() {
int i;
MwWidget f, w;
MwListBoxPacket* pkt;
int index;
MwMenu m, m2;
void* v;
MwLibraryInit();
window = MwVaCreateWidget(MwWindowClass, "window", NULL, MwDEFAULT, MwDEFAULT, 800, 800,
MwNtitle, "Milsko Periodic Table",
NULL);
menu = MwCreateWidget(MwMenuClass, "menu", window, 0, 0, 0, 0);
m = MwMenuAdd(menu, NULL, "File");
MwMenuAdd(menu, m, "New");
MwMenuAdd(menu, m, "Open");
MwMenuAdd(menu, m, "Save");
MwMenuAdd(menu, m, "Save As");
MwMenuAdd(menu, m, "Print");
e = MwMenuAdd(menu, m, "Exit");
m = MwMenuAdd(menu, NULL, "Edit");
MwMenuAdd(menu, m, "Undo");
MwMenuAdd(menu, m, "----");
MwMenuAdd(menu, m, "Cut");
MwMenuAdd(menu, m, "Copy");
MwMenuAdd(menu, m, "Paste");
MwMenuAdd(menu, m, "----");
MwMenuAdd(menu, m, "Clear");
MwMenuAdd(menu, m, "Delete");
m = MwMenuAdd(menu, NULL, "View");
MwMenuAdd(menu, m, "Stack");
MwMenuAdd(menu, m, "Tile");
MwMenuAdd(menu, m, "----");
MwMenuAdd(menu, m, "Day");
MwMenuAdd(menu, m, "Week");
MwMenuAdd(menu, m, "Month");
MwMenuAdd(menu, m, "Year");
m = MwMenuAdd(menu, NULL, "Options");
m2 = MwMenuAdd(menu, m, "Font");
MwMenuAdd(menu, m2, "Small");
MwMenuAdd(menu, m2, "Medium");
MwMenuAdd(menu, m2, "Large");
m2 = MwMenuAdd(menu, m, "Direction");
MwMenuAdd(menu, m2, "Up");
MwMenuAdd(menu, m2, "Down");
MwMenuAdd(menu, m2, "Left");
MwMenuAdd(menu, m2, "Right");
MwMenuAdd(menu, m, "Case Sensitive");
MwMenuAdd(menu, m, "Word Wrap");
m = MwMenuAdd(menu, NULL, "?Help");
MwMenuAdd(menu, m, "On Context");
MwMenuAdd(menu, m, "On Window");
MwMenuAdd(menu, m, "Tutorial");
MwMenuAdd(menu, m, "On Version");
MwAddUserHandler(menu, MwNmenuHandler, menu_handler, NULL);
box = MwVaCreateWidget(MwBoxClass, "box", window, 0, 0, 0, 0,
MwNorientation, MwVERTICAL,
NULL);
newrow();
f = frame("Button", -PaddingContent, -PaddingContent, MwButtonClass,
MwNtext, "Press me",
NULL);
add(f);
add(MwVaCreateWidget(MwLabelClass, "label", boxes[row], 0, 0, 0, 0,
MwNbold, 1,
MwNtext, "The Periodic Table of Milsko Widgets",
MwNratio, Columns - 2,
NULL));
f = frame("ComboBox", -PaddingContent, 24, MwComboBoxClass, NULL);
w = child(f);
MwComboBoxAdd(w, -1, "Hello!");
add(f);
f = frame("Entry", -PaddingContent, 24, MwEntryClass, NULL);
add(f);
f = frame("Label", -PaddingContent, -PaddingContent, MwLabelClass,
MwNtext, "Epic text",
NULL);
add(f);
f = frame("ListBox", -PaddingContent, -PaddingContent, MwListBoxClass,
MwNhasHeading, 1,
NULL);
w = child(f);
pkt = MwListBoxCreatePacket();
index = MwListBoxPacketInsert(pkt, -1);
MwListBoxPacketSet(pkt, index, 0, "Epic title...");
index = MwListBoxPacketInsert(pkt, -1);
MwListBoxPacketSet(pkt, index, 0, "Hello");
MwListBoxInsert(w, -1, pkt);
MwListBoxDestroyPacket(pkt);
add(f);
f = frame("NumberEntry", -PaddingContent, 24, MwNumberEntryClass, NULL);
add(f);
f = frame("ProgressBar", -PaddingContent, 24, MwProgressBarClass,
MwNvalue, 25,
NULL);
add(f);
f = frame("ScrollBar", -PaddingContent, 16, MwScrollBarClass,
MwNorientation, MwHORIZONTAL,
NULL);
add(f);
f = frame("Separator", -PaddingContent, -PaddingContent, MwSeparatorClass, NULL);
add(f);
f = frame("TreeView", -PaddingContent, -PaddingContent, MwTreeViewClass, NULL);
w = child(f);
v = MwTreeViewAdd(w, NULL, NULL, "abc");
v = MwTreeViewAdd(w, v, NULL, "def");
v = MwTreeViewAdd(w, v, NULL, "ghi");
add(f);
if(n != 0) newrow();
if(n == 0) MwDestroyWidget(boxes[row]);
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
resize(window, NULL, NULL);
MwLoop(window);
}

View file

@ -0,0 +1,23 @@
#include <Mw/Milsko.h>
int main() {
MwWidget wnd, label;
int W = 480, H = 40;
MwLibraryInit();
wnd = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, W, H,
MwNtitle, "seven segment",
NULL);
label = MwVaCreateWidget(MwLabelClass, "label", wnd, 0, 0, W, H,
MwNtext, " 123456:78.90 abcdef",
MwNsevenSegment, 1,
MwNalignment, MwALIGNMENT_BEGINNING,
MwNlength, 8,
NULL);
MwLabelSetSevenSegment(label, 0, (1 << 0) | (1 << 3) | (1 << 6));
MwLoop(wnd);
}

View file

@ -14,7 +14,7 @@ void activate(MwWidget handle, void* user, void* call) {
(void)user;
sprintf(msg, "You pressed: %s", MwTreeViewGet(handle, call));
MwStringPrintIntoBuffer(msg, 256, "You pressed: %s", MwTreeViewGet(handle, call));
msgbox = MwMessageBox(wmain, msg, "wow", MwMB_ICONINFO | MwMB_BUTTONOK);
MwAddUserHandler(MwMessageBoxGetChild(msgbox, MwMB_BUTTONOK), MwNactivateHandler, destroy, msgbox);

View file

@ -0,0 +1,27 @@
file(
GLOB
EXAMPLES_GL_SOURCES
*.c
)
find_package(OpenGL)
foreach(PATH IN LISTS EXAMPLES_GL_SOURCES)
get_filename_component(TARGET ${PATH} NAME_WE)
if(${TARGET} STREQUAL "glutlayer")
continue()
endif()
add_executable(${TARGET} MACOSX_BUNDLE ${PATH})
target_link_libraries(
${TARGET}
PRIVATE
Mw
OpenGL::GL OpenGL::GLU
)
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_link_libraries(
${TARGET}
PRIVATE
m
)
endif()
endforeach()

View file

@ -32,10 +32,10 @@ void tick(MwWidget handle, void* user, void* call) {
char buf[512];
tm = localtime(&t);
sprintf(buf, "%s %02d %s", mon[tm->tm_mon], tm->tm_mday, wday[tm->tm_wday]);
MwStringPrintIntoBuffer(buf, 512, "%s %02d %s", mon[tm->tm_mon], tm->tm_mday, wday[tm->tm_wday]);
MwSetText(ldate, MwNtext, buf);
sprintf(buf, "%02d:%02d %s", tm->tm_hour % 12, tm->tm_min, tm->tm_hour >= 12 ? "PM" : "AM");
MwStringPrintIntoBuffer(buf, 512, "%02d:%02d %s", tm->tm_hour % 12, tm->tm_min, tm->tm_hour >= 12 ? "PM" : "AM");
MwSetText(ltime, MwNtext, buf);
render = 1;

View file

@ -1,7 +1,13 @@
#define TITLE "cube"
#include "glutlayer.c"
#if defined(__APPLE__)
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else
#include <GL/gl.h>
#include <GL/glu.h>
#endif
static double deg = 0;
@ -15,12 +21,18 @@ static void draw(void) {
glRotatef(deg, 0, 0, 1);
for(i = 0; i < 6; i++) {
if(i == 0) glColor3f(1, 0, 0);
if(i == 1) glColor3f(0, 1, 0);
if(i == 2) glColor3f(1, 1, 0);
if(i == 3) glColor3f(0, 0, 1);
if(i == 4) glColor3f(1, 0, 1);
if(i == 5) glColor3f(0, 1, 1);
if(i == 0)
glColor3f(1, 0, 0);
if(i == 1)
glColor3f(0, 1, 0);
if(i == 2)
glColor3f(1, 1, 0);
if(i == 3)
glColor3f(0, 0, 1);
if(i == 4)
glColor3f(1, 0, 1);
if(i == 5)
glColor3f(0, 1, 1);
glBegin(GL_QUADS);
glNormal3f(0, 1, 0);
@ -30,9 +42,12 @@ static void draw(void) {
glVertex3f(1, 1, -1);
glEnd();
if(i < 3) glRotatef(90, 0, 0, 1);
if(i == 3) glRotatef(90, 1, 0, 0);
if(i == 4) glRotatef(180, 0, 0, 1);
if(i < 3)
glRotatef(90, 0, 0, 1);
if(i == 3)
glRotatef(90, 1, 0, 0);
if(i == 4)
glRotatef(180, 0, 0, 1);
}
glPopMatrix();
}

View file

@ -51,12 +51,12 @@ static void tick(MwWidget handle, void* user, void* call) {
}
static void mouse(MwWidget handle, void* user, void* call) {
MwLLMouse* mouse = call;
MwMouse* mouse = call;
(void)handle;
(void)user;
if(mouse->button == MwLLMouseLeft) {
if(mouse->button == MwMOUSE_LEFT) {
t[ct].points[click * 2 + 0] = mouse->point.x;
t[ct].points[click * 2 + 1] = mouse->point.y;
click++;
@ -82,7 +82,7 @@ static void mouse(MwWidget handle, void* user, void* call) {
for(i = 0; i < ct; i++) t[i] = old[i];
free(old);
}
} else if(mouse->button == MwLLMouseRight) {
} else if(mouse->button == MwMOUSE_RIGHT) {
if(click > 0) {
click = 0;
} else if(ct > 0) {

View file

@ -0,0 +1,28 @@
file(
GLOB
EXAMPLES_VULKAN_SOURCES
*.c
)
find_package(Vulkan)
foreach(PATH IN LISTS EXAMPLES_VULKAN_SOURCES)
get_filename_component(TARGET ${PATH} NAME_WE)
add_executable(${TARGET} MACOSX_BUNDLE ${PATH})
target_include_directories(
${TARGET}
PRIVATE
${Vulkan_INCLUDE_DIR}
)
target_link_libraries(
${TARGET}
PRIVATE
Mw
)
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_link_libraries(
${TARGET}
PRIVATE
m
)
endif()
endforeach()

View file

@ -5,7 +5,6 @@
* ioixd maintains this file. nishi doesn't know vulkan at all
*/
#include "Mw/Error.h"
#include <Mw/Milsko.h>
#include <Mw/Widget/Vulkan.h>
@ -17,7 +16,7 @@
char buffer[512];
char* string_VkResult(VkResult res) {
sprintf(buffer, "%d", res);
MwStringPrintIntoBuffer(buffer, 512, "%d", res);
return &buffer[0];
}
@ -27,6 +26,8 @@ MwWidget window, vulkan;
int ow = 300;
int oh = 250;
double timer = 0;
PFN_vkGetInstanceProcAddr _vkGetInstanceProcAddr;
VkInstance instance;
VkDevice device;
@ -75,9 +76,10 @@ void tick(MwWidget handle, void* user_data, void* call_data) {
VkSubmitInfo submitInfo = {};
VkPresentInfoKHR presentInfo = {};
VkClearValue clearColor = {{{0.0f, 0.0f, 0.0f, 1.0f}}};
VkClearValue clearColor = {{{sin(timer) / 10., cos(timer) / 10., atan(timer) / 10., 1.0f}}};
uint32_t vertexCount = 3;
uint32_t instanceCount = 1;
timer += (float)(rand() % 1000) / 1000.;
VkPipelineStageFlags waitStages[] = {VK_PIPELINE_STAGE_2_VERTEX_SHADER_BIT};
@ -229,43 +231,16 @@ void vulkan_setup(MwWidget handle) {
VkSemaphoreCreateInfo semaphoreInfo = {};
VkFenceCreateInfo fenceInfo = {};
MwErrorEnum err = MwEsuccess;
_vkGetInstanceProcAddr = MwVulkanGetField(handle, MwVulkanField_GetInstanceProcAddr, &err);
if(err != MwEsuccess) {
printf("Error getting vkGetInstanceProcAddr!\n%s\n", MwGetLastError());
}
instance = MwVulkanGetField(handle, MwVulkanField_Instance, &err);
if(err != MwEsuccess) {
printf("Error getting vulkan instance!\n%s\n", MwGetLastError());
}
device = MwVulkanGetField(handle, MwVulkanField_LogicalDevice, &err);
if(err != MwEsuccess) {
printf("Error getting VkDevice!\n%s\n", MwGetLastError());
}
physicalDevice = MwVulkanGetField(handle, MwVulkanField_PhysicalDevice, &err);
if(err != MwEsuccess) {
printf("Error getting physical device!\n%s\n", MwGetLastError());
}
graphicsQueue = MwVulkanGetField(handle, MwVulkanField_GraphicsQueue, &err);
if(err != MwEsuccess) {
printf("Error getting graphics queue!\n%s\n", MwGetLastError());
}
presentQueue = MwVulkanGetField(handle, MwVulkanField_PresentQueue, &err);
if(err != MwEsuccess) {
printf("Error getting present queue!\n%s\n", MwGetLastError());
}
surface = MwVulkanGetField(handle, MwVulkanField_Surface, &err);
if(err != MwEsuccess) {
printf("Error getting surface!\n%s\n", MwGetLastError());
}
presentQueueIndex = MwVulkanGetField(handle, MwVulkanField_PresentQueueIndex, &err);
if(err != MwEsuccess) {
printf("Error getting present queue index!\n%s\n", MwGetLastError());
}
graphicsQueueIndex = MwVulkanGetField(handle, MwVulkanField_GraphicsQueueIndex, &err);
if(err != MwEsuccess) {
printf("Error getting graphics queue index!\n%s\n", MwGetLastError());
}
int err = 0;
_vkGetInstanceProcAddr = MwVulkanGetField(handle, MwVULKANFIELD_GETINSTANCEPROCADDR, &err);
instance = MwVulkanGetField(handle, MwVULKANFIELD_INSTANCE, &err);
device = MwVulkanGetField(handle, MwVULKANFIELD_LOGICALDEVICE, &err);
physicalDevice = MwVulkanGetField(handle, MwVULKANFIELD_PHYSICALDEVICE, &err);
graphicsQueue = MwVulkanGetField(handle, MwVULKANFIELD_GRAPHICSQUEUE, &err);
presentQueue = MwVulkanGetField(handle, MwVULKANFIELD_PRESENTQUEUE, &err);
surface = MwVulkanGetField(handle, MwVULKANFIELD_SURFACE, &err);
presentQueueIndex = MwVulkanGetField(handle, MwVULKANFIELD_PRESENTQUEUEINDEX, &err);
graphicsQueueIndex = MwVulkanGetField(handle, MwVULKANFIELD_GRAPHICSQUEUEINDEX, &err);
LOAD_VK_FUNCTION(vkCreateShaderModule);
LOAD_VK_FUNCTION(vkCreatePipelineLayout);

View file

@ -32,7 +32,7 @@ typedef int8_t MwI8;
typedef uint8_t MwU8;
#define MW_OTHER_TYPES_DEFINED
#elif __GNUC__ > 2
#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) || defined(__clang__))
typedef long long MwI64;
typedef unsigned long long MwU64;
#elif defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__)
@ -78,8 +78,8 @@ struct _MwPoint {
struct _MwRect {
int x;
int y;
unsigned int width;
unsigned int height;
int width;
int height;
};
struct _MwSizeHints {

View file

@ -99,4 +99,26 @@ enum MwMB_ICON {
*/
#define MwMB_BUTTONYESNOCANCEL (MwMB_BUTTONYES | MwMB_BUTTONNO | MwMB_BUTTONCANCEL)
/* Whether or not GetXY/SetXY works with global or local coordinates */
enum MwCOORDINATE {
MwCOORDINATE_GLOBAL = 0,
MwCOORDINATE_LOCAL,
};
/* The clipboard type that MwGetClipboard should return */
enum MwCLIPBOARD {
/* the clipboard that is present on every platform that supports it */
MwCLIPBOARD_MAIN = 0,
/* the "primary" clipboard that Wayland stores to emulate X11's behavior. */
MwCLIPBOARD_PRIMARY,
};
enum MwMOUSE {
MwMOUSE_LEFT = 1,
MwMOUSE_MIDDLE,
MwMOUSE_RIGHT,
MwMOUSE_WHEELUP,
MwMOUSE_WHEELDOWN
};
#endif

View file

@ -295,8 +295,9 @@ MWDECL void MwHideCursor(MwWidget handle);
* @brief Toggles the dark theme
* @param handle Widget
* @param toggle Toggle
* @deprecated Use MwNdarkTheme instead
*/
MWDECL void MwToggleDarkTheme(MwWidget handle, int toggle);
MWDECL void MwSetDarkTheme(MwWidget handle, int toggle);
/*!
* @brief Gets the parent widget
@ -354,6 +355,19 @@ MWDECL void MwGetCursorCoord(MwWidget handle, MwPoint* point);
*/
MWDECL void MwGetScreenSize(MwWidget handle, MwRect* rect);
/*!
* @brief Reports whether a widget reports global or local coordinates upon GetXY/SetXY. Anything with a parent reports local, and most backends report global coordinates being supported for top level windows, but some (Wayland) do not.
* @param handle Widget
*/
MWDECL int MwGetCoordinateType(MwWidget handle);
/*!
* @brief Queue to get clipboard content.
* @param handle Widget
* @param clipboard_type The Clipboard Type to get. See MwClipboardType. This is ignored on backends that aren't X11/Wayland, so if you're unsure, just use MwClipboardMain
*/
MWDECL void MwGetClipboard(MwWidget handle, int clipboard_type);
#ifdef __cplusplus
}
#endif

View file

@ -52,6 +52,11 @@ MWDECL const char* MwDefaultDarkSubBackground;
*/
MWDECL const char* MwDefaultDarkSubForeground;
/*!
* @brief Default shadow difference
*/
MWDECL const int MwDefaultShadow;
/*!
* @brief Gets default border width
* @param handle Widget

View file

@ -93,6 +93,7 @@ MWDECL void MwDrawTriangle(MwWidget handle, MwRect* rect, MwLLColor color, int i
* @param border Border width
* @param diff Difference (set this to 0 if you don't know what this does)
* @param same Same as dark color
* @param rounded Rounded or not
* @warning `rect` gets changed to the area of rectangle inside
*/
MWDECL void MwDrawFrameEx(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int border, int diff, int same);
@ -175,29 +176,31 @@ MWDECL void MwDrawDiamond(MwWidget handle, MwRect* rect, MwLLColor color, int in
/*!
* @brief Draws a text
* @param handle Widget
* @param ttf TTF, NULLable
* @param point Center point of the text
* @param text Text
* @param bold Bold
* @param align Align
* @param color Color
*/
MWDECL void MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color);
MWDECL void MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text, int align, MwLLColor color);
/*!
* @brief Calculates a text width
* @param handle Widget
* @param text Text
* @param font Font, NULLable
* @return Text width
*/
MWDECL int MwTextWidth(MwWidget handle, const char* text);
MWDECL int MwTextWidth(MwWidget handle, MwFLFont font, const char* text);
/*!
* @brief Calculates a text height
* @param handle Widget
* @param text Text
* @param font Font, NULLable
* @return Text height
*/
MWDECL int MwTextHeight(MwWidget handle, const char* text);
MWDECL int MwTextHeight(MwWidget handle, MwFLFont font, const char* text);
/* color.c */

View file

@ -1,29 +0,0 @@
/*!
* @file Mw/Error.h
* @brief Error codes
*/
#ifndef __MW_ERROR_H__
#define __MW_ERROR_H__
#include <Mw/MachDep.h>
/*!
* @brief Error code enumeration
*/
typedef enum MwErrorEnum_T {
/*!
* @brief No error
*/
MwEsuccess = 0,
/*!
* @brief There was an error
*/
MwEerror,
} MwErrorEnum;
/*!
* @brief Get the last error
*/
MWDECL const char* MwGetLastError(void);
#endif

View file

@ -6,10 +6,10 @@
#ifndef __MW_LOWLEVEL_H__
#define __MW_LOWLEVEL_H__
#include <Mw/BaseTypes.h>
#include <Mw/MachDep.h>
typedef struct _MwLLHandler* MwLLHandler;
typedef struct _MwLLMouse MwLLMouse;
typedef struct _MwLLCommon* MwLLCommon;
typedef struct _MwLLCommonColor* MwLLCommonColor;
typedef struct _MwLLCommonPixmap* MwLLCommonPixmap;
@ -17,30 +17,35 @@ typedef struct _MwLLCommonPixmap* MwLLCommonPixmap;
typedef union _MwLL* MwLL;
typedef union _MwLLColor* MwLLColor;
typedef union _MwLLPixmap* MwLLPixmap;
typedef struct _MwFLFont* MwFLFont;
#else
typedef void* MwLL;
typedef void* MwLLColor;
typedef void* MwLLPixmap;
typedef void* MwFLFont;
#endif
enum MwLLBackends {
MwLLBackendX11 = 0,
MwLLBackendGDI,
MwLLBackendWayland,
MwLLBackendCocoa,
};
struct _MwLLCommon {
void* user;
int copy_buffer;
int type;
int coordinate_type;
MwBool supports_transparency;
MwLLHandler handler;
};
struct _MwLLCommonColor {
int red;
int green;
int blue;
MwU8 red;
MwU8 green;
MwU8 blue;
};
struct _MwLLCommonPixmap {
@ -50,6 +55,52 @@ struct _MwLLCommonPixmap {
void* user;
};
#ifdef USE_DBUS
typedef struct _MwLLDBusFuncTable {
void* lib;
void (*dbus_error_init)(DBusError* error);
DBusConnection* (*dbus_bus_get)(DBusBusType type, DBusError* error);
dbus_bool_t (*dbus_error_is_set)(const DBusError* error);
void (*dbus_error_free)(DBusError* error);
DBusMessage* (*dbus_message_new_method_call)(const char* bus_name, const char* path, const char* iface, const char* method);
void (*dbus_message_iter_init_append)(DBusMessage* message, DBusMessageIter* iter);
dbus_bool_t (*dbus_message_iter_append_basic)(DBusMessageIter* iter, int type, const void* value);
void (*dbus_connection_flush)(DBusConnection* connection);
dbus_bool_t (*dbus_connection_read_write)(DBusConnection* connection, int timeout_milliseconds);
DBusMessage* (*dbus_connection_send_with_reply_and_block)(DBusConnection* connection, DBusMessage* message, int timeout_milliseconds, DBusError* error);
DBusMessage* (*dbus_connection_pop_message)(DBusConnection* connection);
void (*dbus_bus_add_match)(DBusConnection* connection, const char* rule, DBusError* error);
void (*dbus_message_unref)(DBusMessage* message);
dbus_bool_t (*dbus_message_iter_init)(DBusMessage* message, DBusMessageIter* iter);
dbus_bool_t (*dbus_message_is_signal)(DBusMessage* message, const char* iface, const char* signal_name);
int (*dbus_message_iter_get_arg_type)(DBusMessageIter* iter);
void (*dbus_message_iter_recurse)(DBusMessageIter* iter, DBusMessageIter* sub);
void (*dbus_message_iter_next)(DBusMessageIter* iter);
void (*dbus_connection_unref)(DBusConnection* connection);
void (*dbus_message_iter_get_basic)(DBusMessageIter* iter, void* value);
} MwLLDBusFuncTable;
typedef struct _MwLLDBusContext {
DBusConnection* dbus_conn;
DBusError dbus_err;
DBusMessage* dbus_msg;
DBusMessage* dbus_reply;
} MwLLDBusContext;
typedef void (*MwLLDBusPortalPollListener)(MwLL handle, MwU32 new_value);
/* setup the dbus func table. Returns false and prints a warning if dbus couldn't be found. */
MWDECL MwBool MwLLDBusFuncSetup(MwLLDBusFuncTable* tbl);
MWDECL MwBool MwLLDBusNewContext(MwLLDBusFuncTable* tbl, MwLLDBusContext* ctx);
MWDECL MwBool MwLLDBusPortalGet(MwLLDBusFuncTable* tbl, MwLLDBusContext* ctx, const char* portal, const char* namespace, const char* key, void* out);
MWDECL MwBool MwLLDBusPortalWatch(MwLLDBusFuncTable* tbl, MwLLDBusContext* ctx, const char* portal);
MWDECL MwBool MwLLDBusPortalPoll(MwLLDBusFuncTable* tbl, MwLLDBusContext* ctx, MwLL handle, const char* portal, const char* namespace, const char* key, MwLLDBusPortalPollListener);
MWDECL void MwLLDBusFreeContext(MwLLDBusFuncTable* tbl, MwLLDBusContext* ctx);
#endif
#ifdef _MILSKO
#ifdef USE_X11
#include <Mw/LowLevel/X11.h>
@ -60,6 +111,12 @@ struct _MwLLCommonPixmap {
#ifdef USE_WAYLAND
#include <Mw/LowLevel/Wayland.h>
#endif
#ifdef USE_COCOA
#include <Mw/LowLevel/Cocoa.h>
#endif
#ifdef CLASSIC_MAC_OS
#include <Mw/LowLevel/ClassicMacOS.h>
#endif
union _MwLL {
struct _MwLLCommon common;
@ -72,6 +129,12 @@ union _MwLL {
#ifdef USE_WAYLAND
struct _MwLLWayland wayland;
#endif
#ifdef USE_COCOA
struct _MwLLCocoa cocoa;
#endif
#ifdef CLASSIC_MAC_OS
struct _MwLLClassicMacOS cmacos;
#endif
};
union _MwLLColor {
@ -85,6 +148,9 @@ union _MwLLColor {
#ifdef USE_WAYLAND
struct _MwLLWaylandColor wayland;
#endif
#ifdef USE_COCOA
struct _MwLLCocoaColor cocoa;
#endif
};
union _MwLLPixmap {
@ -98,6 +164,12 @@ union _MwLLPixmap {
#ifdef USE_WAYLAND
struct _MwLLWaylandPixmap wayland;
#endif
#ifdef USE_COCOA
struct _MwLLCocoaPixmap cocoa;
#endif
#ifdef CLASSIC_MAC_OS
struct _MwLLClassicMacOSPixmap cmacos;
#endif
};
#endif
#include <Mw/TypeDefs.h>
@ -123,19 +195,6 @@ enum MwLLKeyEnum {
#define MwLLControlMask MwLLKeyMask | (1 << 30)
#define MwLLAltMask MwLLKeyMask | (1 << 29)
enum MwLLMouseEnum {
MwLLMouseLeft = 1,
MwLLMouseMiddle,
MwLLMouseRight,
MwLLMouseWheelUp,
MwLLMouseWheelDown
};
struct _MwLLMouse {
MwPoint point;
int button;
};
struct _MwLLHandler {
void (*draw)(MwLL handle, void* data);
void (*up)(MwLL handle, void* data);
@ -147,8 +206,22 @@ struct _MwLLHandler {
void (*key_released)(MwLL handle, void* data);
void (*focus_in)(MwLL handle, void* data);
void (*focus_out)(MwLL handle, void* data);
void (*clipboard)(MwLL handle, void* data);
void (*dark_theme)(MwLL handle, void* data);
};
struct _MwLLTextDispatchTable {
int (*drawText)(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color);
int (*textWidth)(MwWidget handle, const char* text);
int (*textHeight)(MwWidget handle, int count);
void* (*fontLoad)(unsigned char* data, unsigned int size);
void (*fontFree)(void* handle);
};
#define MwFLFlagMonospace (1 << 0)
#define MwFLFlagBold (1 << 1)
#define MwFLBuildFont(x) ((MwFLFont)(void*)(size_t)(x))
#ifdef __cplusplus
extern "C" {
#endif
@ -202,12 +275,30 @@ MWDECL void (*MwLLEndStateChange)(MwLL handle);
MWDECL void (*MwLLFocus)(MwLL handle);
MWDECL void (*MwLLGrabPointer)(MwLL handle, int toggle);
MWDECL void (*MwLLSetClipboard)(MwLL handle, const char* text);
MWDECL char* (*MwLLGetClipboard)(MwLL handle);
MWDECL void (*MwLLSetClipboard)(MwLL handle, const char* text, int clipboard_type);
MWDECL void (*MwLLGetClipboard)(MwLL handle, int clipboard_type);
MWDECL void (*MwLLGetCursorCoord)(MwLL handle, MwPoint* point);
MWDECL void (*MwLLGetScreenSize)(MwLL handle, MwRect* rect);
MWDECL void (*MwLLSetDarkTheme)(MwLL handle, int toggle);
/* font renderer */
MWDECL void MwFLSetup(void);
#ifdef USE_FREETYPE2
MWDECL int MWFL_FT2Setup(void);
#endif
#ifdef USE_STB_TRUETYPE
MWDECL int MwFL_STBTTSetup(void);
#endif
MWDECL int (*MwFLDrawText)(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text, MwLLColor color);
MWDECL int (*MwFLTextWidth)(MwFLFont ttf, const char* text);
MWDECL int (*MwFLTextHeight)(MwFLFont ttf, int count);
MWDECL void* (*MwFLFontLoad)(unsigned char* data, unsigned int size, int px);
MWDECL void (*MwFLFontFree)(void* handle);
#ifdef __cplusplus
}
#endif

View file

@ -0,0 +1,35 @@
/*!
* @file Mw/LowLevel/ClassicMacOS.h
* @brief ClassicMacOS Backend
* @warning This is used internally
*/
#ifndef __MW_LOWLEVEL_ClassicMacOS_H__
#define __MW_LOWLEVEL_ClassicMacOS_H__
#include <Mw/MachDep.h>
#include <Mw/TypeDefs.h>
#include <Mw/LowLevel.h>
struct _MwLLClassicMacOS {
struct _MwLLCommon common;
MwLL parent;
WindowRef window;
ControlHandle control;
EventRecord event;
Rect winRect;
};
struct _MwLLClassicMacOSColor {
struct _MwLLCommonColor common;
};
struct _MwLLClassicMacOSPixmap {
struct _MwLLCommonPixmap common;
BitMap bmp;
};
MWDECL int MwLLClassicMacOSCallInit(void);
#endif

180
include/Mw/LowLevel/Cocoa.h Normal file
View file

@ -0,0 +1,180 @@
/*!
* @file Mw/LowLevel/Cocoa.h
* @brief Work in progress Cocoa Backend
* @warning This is used internally.
*/
#ifndef __MW_LOWLEVEL_COCOA_H__
#define __MW_LOWLEVEL_COCOA_H__
#include <Mw/LowLevel.h>
#include <Mw/MachDep.h>
#include <Mw/TypeDefs.h>
typedef struct {
enum {
COCOA_DRAW_COMMAND_POLY = 0,
COCOA_DRAW_COMMAND_LINES,
COCOA_DRAW_COMMAND_PIXMAP,
} type;
union {
struct {
MwPoint* points;
int points_count;
struct _MwLLCommonColor color;
} poly;
struct {
MwPoint* points;
struct _MwLLCommonColor color;
} lines;
struct {
MwRect rect;
MwLLPixmap pixmap;
} pixmap;
};
} draw_command;
#ifdef __OBJC__
#import <AppKit/AppKit.h>
#import <Foundation/Foundation.h>
#import <Foundation/NSGeometry.h>
@interface MilskoCocoaApplication : NSApplication {
MwBool doPending;
}
- (MwBool)pending;
@end
// Note: implements NSApplicationDelegate
@interface MilskoCocoaApplicationDelegate : NSObject {
MilskoCocoaApplication* appl;
}
- (MilskoCocoaApplicationDelegate*)initWithAppl:(MilskoCocoaApplication*)appl;
@end
@interface MilskoCocoaWindow : NSWindow {
}
@end
// Note: implements NSWindowDelegate
@interface MilskoCocoaWindowDelegate : NSObject {
NSWindow* w;
}
- (MilskoCocoaWindowDelegate*)initWithWin:(NSWindow*)win;
@end
/*
So we want to associate each NSWindow with its corresponding MwLL handle. The
conventional way of doing this is through "associative pointers", however
this is a feature that Apple added in 10.6 (marketted back then as "Objective
C 2" iirc). For 10.4 compatibility, we have to do a bit of an ugly hack that
might seem like horrifically undefined behavior, but I've tested this on
both 10.4 and modern Mac OS and as long as we're careful there's no
problems: we override NSView, use NSView's "frame" property to store the
pointer, and then override functions appropriately so that this frame is never
actually used. This can then be attached to an NSWindow with addSubview and
retrieved appropriately.
*/
@interface MilskoFakePointer : NSView {
void* ptr;
}
- (void)setPointer:(void*)ptr;
- (void*)pointer;
@end
@interface MilskoCocoaPixmap : NSObject {
@public
MwBool valid;
int width;
int height;
unsigned char* buf;
NSImage* image;
NSBitmapImageRep* rep;
}
+ (MilskoCocoaPixmap*)newWithWidth:(int)width height:(int)height;
- (void)updateWithData:(unsigned char*)data;
- (void)destroy;
/* using @property to create instance variables fucks up 10.4 gcc for some
* reason? */
- (NSImage*)image;
@end
@interface MilskoCocoaView : NSView {
MwBool _child;
@public
draw_command* commands;
}
- (void)destroy;
- (void)setChild;
@end
@interface MilskoCocoaSubView : MilskoCocoaView {
}
@end
@interface MilskoCocoa : NSObject {
@public
MilskoCocoaApplication* application;
MwBool _forceRender;
MwBool _eventsPending;
NSWindow* window;
NSRect rect;
MilskoCocoaView* view;
MwLL parent;
MilskoFakePointer* handle;
unsigned int strHash;
NSEvent* lastEvent;
MilskoCocoaPixmap* cursorPixmap;
NSCursor* cursor;
NSModalSession modalSession;
MwBool pointerLocked;
MwBool mouseMoved;
MwBool rejectFirstTest;
}
- (void)destroy;
- (void)sendClipboardEvent;
- (MwLL)getParent;
- (NSView*)getView;
- (NSWindow*)getWindow;
- (void)nudge;
- (void)pushCursor;
- (void)popCursor;
- (MilskoFakePointer*)getHandle;
@end
#define OBJC(x) x
#else
#define OBJC(x) void*
#endif
MWDECL int MwLLCocoaCallInit(void);
struct _MwLLCocoa {
struct _MwLLCommon common;
OBJC(MilskoCocoa*)
real;
};
struct _MwLLCocoaColor {
struct _MwLLCommonColor common;
};
struct _MwLLCocoaPixmap {
struct _MwLLCommonPixmap common;
OBJC(MilskoCocoaPixmap*)
real;
};
#endif

View file

@ -21,6 +21,8 @@ struct _MwLLGDI {
int grabbed;
int force_render;
int get_clipboard;
int get_darktheme;
};
struct _MwLLGDIColor {

View file

@ -1,8 +1,7 @@
/*!
* @file Mw/LowLevel/Wayland.h
* @brief Work in progress Wayland Backend
* @brief Wayland Backend
* @warning This is used internally.
* @warning This is disabled by default.
*/
#ifndef __MW_LOWLEVEL_WAYLAND_H__
#define __MW_LOWLEVEL_WAYLAND_H__
@ -10,33 +9,317 @@
#include <Mw/MachDep.h>
#include <Mw/TypeDefs.h>
#include <Mw/LowLevel.h>
#include <Mw/Abstract/Dynamic.h>
#include <wayland-client-protocol.h>
#include <wayland-egl.h>
#include <EGL/egl.h>
#include <GL/gl.h>
#include <GL/glext.h>
#include <wayland-client.h>
#include <xkbcommon/xkbcommon.h>
#include <cairo/cairo.h>
#include <pthread.h>
#include <dbus/dbus.h>
MWDECL int MwLLWaylandCallInit(void);
#ifndef WL_PROTOCOLS_DEFINED
#define WL_PROTOCOLS_DEFINED
#include "Wayland/xdg-shell-client-protocol.h"
#include "Wayland/xdg-decoration-client-protocol.h"
#include "Wayland/cursor-shape-client-protocol.h"
#endif
#define CSD_BORDER_FRAME_LEFT 5
#define CSD_BORDER_FRAME_RIGHT 5
#define CSD_BORDER_FRAME_TOP 24
#define CSD_BORDER_FRAME_BOTTOM 5
struct _MwLLWayland;
#include <wayland-client-core.h>
#if WAYLAND_LOAD_OPENGL
#include <EGL/egl.h>
#include <wayland-egl-core.h>
#endif
typedef struct wayland_call_table {
void* lib;
void* xkb_lib;
void* cairo_lib;
#ifdef USE_DBUS
MwLLDBusFuncTable dbus;
MwBool has_dbus;
#endif
int (*wl_display_dispatch)(struct wl_display* display);
int (*wl_display_dispatch_pending)(struct wl_display* display);
void (*wl_display_disconnect)(struct wl_display* display);
void (*wl_display_cancel_read)(struct wl_display* display);
int (*wl_display_prepare_read)(struct wl_display* display);
int (*wl_display_read_events)(struct wl_display* display);
int (*wl_display_flush)(struct wl_display* display);
int (*wl_display_get_fd)(struct wl_display* display);
int (*wl_display_roundtrip)(struct wl_display* display);
int (*wl_proxy_add_listener)(struct wl_proxy* proxy, void (**implementation)(void), void* data);
void (*wl_proxy_destroy)(struct wl_proxy* proxy);
void (*wl_log_set_handler_client)(wl_log_func_t handler);
struct wl_proxy* (*wl_proxy_marshal_flags)(struct wl_proxy* proxy, uint32_t opcode,
const struct wl_interface* interface,
uint32_t version,
uint32_t flags, ...);
struct wl_display* (*wl_display_connect)(const char* name);
uint32_t (*wl_proxy_get_version)(struct wl_proxy* proxy);
struct wl_display* (*wl_display_connect_to_fd)(int fd);
struct xkb_context* (*xkb_context_new)(enum xkb_context_flags flags);
void (*xkb_context_unref)(struct xkb_context* context);
struct xkb_state* (*xkb_state_new)(struct xkb_keymap* keymap);
void (*xkb_state_unref)(struct xkb_state* state);
struct xkb_keymap* (*xkb_keymap_new_from_string)(struct xkb_context* context, const char* string, enum xkb_keymap_format format, enum xkb_keymap_compile_flags flags);
xkb_level_index_t (*xkb_keymap_num_levels_for_key)(struct xkb_keymap* keymap, xkb_keycode_t key, xkb_layout_index_t layout);
int (*xkb_keymap_key_get_syms_by_level)(struct xkb_keymap* keymap, xkb_keycode_t key, xkb_layout_index_t layout, xkb_level_index_t level, const xkb_keysym_t** syms_out);
xkb_layout_index_t (*xkb_state_key_get_layout)(struct xkb_state* state, xkb_keycode_t key);
void (*xkb_keymap_unref)(struct xkb_keymap* keymap);
void (*cairo_set_line_width)(cairo_t* cr,
double width);
void (*cairo_scale)(cairo_t* cr,
double sx,
double sy);
cairo_t* (*cairo_create)(cairo_surface_t* target);
void (*cairo_move_to)(cairo_t* cr,
double x,
double y);
void (*cairo_rectangle)(cairo_t* cr,
double x,
double y,
double width,
double height);
void (*cairo_new_path)(cairo_t* cr);
void (*cairo_set_line_cap)(cairo_t* cr,
cairo_line_cap_t line_cap);
void (*cairo_set_source_rgba)(cairo_t* cr,
double red,
double green,
double blue,
double alpha);
void (*cairo_set_source_rgb)(cairo_t* cr,
double red,
double green,
double blue);
void (*cairo_reset_clip)(cairo_t* cr);
unsigned char* (*cairo_image_surface_get_data)(cairo_surface_t* surface);
void (*cairo_line_to)(cairo_t* cr,
double x,
double y);
void (*cairo_surface_destroy)(cairo_surface_t* surface);
cairo_surface_t* (*cairo_image_surface_create_for_data)(unsigned char* data,
cairo_format_t format,
int width,
int height,
int stride);
cairo_surface_t* (*cairo_image_surface_create)(cairo_format_t format,
int width,
int height);
void (*cairo_destroy)(cairo_t* cr);
cairo_pattern_t* (*cairo_get_source)(cairo_t* cr);
void (*cairo_close_path)(cairo_t* cr);
void (*cairo_paint)(cairo_t* cr);
void (*cairo_surface_flush)(cairo_surface_t* surface);
void (*cairo_clip)(cairo_t* cr);
void (*cairo_surface_mark_dirty)(cairo_surface_t* surface);
void (*cairo_stroke)(cairo_t* cr);
void (*cairo_set_source_surface)(cairo_t* cr,
cairo_surface_t* surface,
double x,
double y);
void (*cairo_fill)(cairo_t* cr);
void (*cairo_pattern_set_filter)(cairo_pattern_t* pattern,
cairo_filter_t filter);
void (*cairo_set_antialias)(cairo_t*, cairo_antialias_t);
void (*cairo_set_operator)(cairo_t* cr, cairo_operator_t op);
} wayland_call_table_t;
extern wayland_call_table_t wl_call_tbl;
extern MwBool MwWaylandAlwaysRender;
/* defined inline right here so that it doesn't conflict with the other macros */
MwInline int wayland_load_funcs() {
wl_call_tbl.lib = MwDynamicOpen("libwayland-client.so");
if(!wl_call_tbl.lib) {
printf("(libwayland-client.so not found, falling back to X11)\n");
return 1;
}
wl_call_tbl.xkb_lib = MwDynamicOpen("libxkbcommon.so");
if(!wl_call_tbl.xkb_lib) {
printf("(libxkbcommon.so not found, cannot use Wayland backend.)\n");
return 1;
}
wl_call_tbl.cairo_lib = MwDynamicOpen("libcairo.so");
if(!wl_call_tbl.cairo_lib) {
printf("(libcairo.so not found, cannot use Wayland backend.)\n");
return 1;
}
#define WAYLAND_FUNC(x) \
wl_call_tbl.x = MwDynamicSymbol(wl_call_tbl.lib, #x); \
if(!wl_call_tbl.x) { \
printf("WARNING: Could use Wayland backend if " #x " was found.\n"); \
return 1; \
};
WAYLAND_FUNC(wl_display_dispatch)
WAYLAND_FUNC(wl_display_dispatch_pending)
WAYLAND_FUNC(wl_display_disconnect)
WAYLAND_FUNC(wl_display_cancel_read)
WAYLAND_FUNC(wl_display_prepare_read)
WAYLAND_FUNC(wl_display_read_events)
WAYLAND_FUNC(wl_display_flush)
WAYLAND_FUNC(wl_display_get_fd)
WAYLAND_FUNC(wl_display_roundtrip)
WAYLAND_FUNC(wl_proxy_add_listener)
WAYLAND_FUNC(wl_proxy_destroy)
WAYLAND_FUNC(wl_log_set_handler_client)
WAYLAND_FUNC(wl_proxy_marshal_flags)
WAYLAND_FUNC(wl_display_connect)
WAYLAND_FUNC(wl_proxy_get_version)
WAYLAND_FUNC(wl_display_connect_to_fd)
#undef WAYLAND_FUNC
#define XKB_FUNC(x) \
wl_call_tbl.x = MwDynamicSymbol(wl_call_tbl.xkb_lib, #x); \
if(!wl_call_tbl.x) { \
printf("WARNING: Could use Wayland backend if " #x " was found. Do you have libxkbcommon?\n"); \
return 1; \
};
XKB_FUNC(xkb_state_unref)
XKB_FUNC(xkb_context_new)
XKB_FUNC(xkb_context_unref)
XKB_FUNC(xkb_state_new)
XKB_FUNC(xkb_keymap_new_from_string)
XKB_FUNC(xkb_keymap_unref)
XKB_FUNC(xkb_keymap_num_levels_for_key)
XKB_FUNC(xkb_keymap_key_get_syms_by_level)
XKB_FUNC(xkb_state_key_get_layout)
#undef XKB_FUNC
#define CAIRO_FUNC(x) \
wl_call_tbl.x = MwDynamicSymbol(wl_call_tbl.cairo_lib, #x); \
if(!wl_call_tbl.x) { \
printf("WARNING: Could use Wayland backend if " #x " was found. Do you have libcairo?\n"); \
return 1; \
};
CAIRO_FUNC(cairo_set_line_width);
CAIRO_FUNC(cairo_scale);
CAIRO_FUNC(cairo_create);
CAIRO_FUNC(cairo_move_to);
CAIRO_FUNC(cairo_rectangle);
CAIRO_FUNC(cairo_new_path);
CAIRO_FUNC(cairo_set_line_cap);
CAIRO_FUNC(cairo_set_antialias);
CAIRO_FUNC(cairo_set_source_rgba);
CAIRO_FUNC(cairo_set_source_rgb);
CAIRO_FUNC(cairo_reset_clip);
CAIRO_FUNC(cairo_image_surface_get_data);
CAIRO_FUNC(cairo_line_to);
CAIRO_FUNC(cairo_surface_destroy);
CAIRO_FUNC(cairo_image_surface_create_for_data);
CAIRO_FUNC(cairo_image_surface_create);
CAIRO_FUNC(cairo_destroy);
CAIRO_FUNC(cairo_get_source);
CAIRO_FUNC(cairo_close_path);
CAIRO_FUNC(cairo_paint);
CAIRO_FUNC(cairo_surface_flush);
CAIRO_FUNC(cairo_clip);
CAIRO_FUNC(cairo_surface_mark_dirty);
CAIRO_FUNC(cairo_stroke);
CAIRO_FUNC(cairo_set_source_surface);
CAIRO_FUNC(cairo_fill);
CAIRO_FUNC(cairo_set_operator);
CAIRO_FUNC(cairo_pattern_set_filter);
#undef CAIRO_FUNC
#ifdef USE_DBUS
wl_call_tbl.has_dbus = MwLLDBusFuncSetup(&wl_call_tbl.dbus);
#endif
return 0;
}
#define wl_display_dispatch wl_call_tbl.wl_display_dispatch
#define wl_display_dispatch_pending wl_call_tbl.wl_display_dispatch_pending
#define wl_display_disconnect wl_call_tbl.wl_display_disconnect
#define wl_display_cancel_read wl_call_tbl.wl_display_cancel_read
#define wl_display_prepare_read wl_call_tbl.wl_display_prepare_read
#define wl_display_read_events wl_call_tbl.wl_display_read_events
#define wl_display_flush wl_call_tbl.wl_display_flush
#define wl_display_get_fd wl_call_tbl.wl_display_get_fd
#define wl_display_roundtrip wl_call_tbl.wl_display_roundtrip
#define wl_proxy_add_listener wl_call_tbl.wl_proxy_add_listener
#define wl_proxy_destroy wl_call_tbl.wl_proxy_destroy
#define wl_log_set_handler_client wl_call_tbl.wl_log_set_handler_client
#define wl_proxy_marshal_flags wl_call_tbl.wl_proxy_marshal_flags
#define wl_display_connect wl_call_tbl.wl_display_connect
#define wl_proxy_get_version wl_call_tbl.wl_proxy_get_version
#define wl_display_connect_to_fd wl_call_tbl.wl_display_connect_to_fd
#define xkb_state_unref wl_call_tbl.xkb_state_unref
#define xkb_context_new wl_call_tbl.xkb_context_new
#define xkb_context_unref wl_call_tbl.xkb_context_unref
#define xkb_state_new wl_call_tbl.xkb_state_new
#define xkb_keymap_new_from_string wl_call_tbl.xkb_keymap_new_from_string
#define xkb_keymap_unref wl_call_tbl.xkb_keymap_unref
#define xkb_keymap_num_levels_for_key wl_call_tbl.xkb_keymap_num_levels_for_key
#define xkb_keymap_key_get_syms_by_level wl_call_tbl.xkb_keymap_key_get_syms_by_level
#define xkb_state_key_get_layout wl_call_tbl.xkb_state_key_get_layout
#define cairo_set_line_width wl_call_tbl.cairo_set_line_width
#define cairo_scale wl_call_tbl.cairo_scale
#define cairo_create wl_call_tbl.cairo_create
#define cairo_move_to wl_call_tbl.cairo_move_to
#define cairo_rectangle wl_call_tbl.cairo_rectangle
#define cairo_new_path wl_call_tbl.cairo_new_path
#define cairo_set_line_cap wl_call_tbl.cairo_set_line_cap
#define cairo_set_antialias wl_call_tbl.cairo_set_antialias
#define cairo_set_source_rgba wl_call_tbl.cairo_set_source_rgba
#define cairo_set_source_rgb wl_call_tbl.cairo_set_source_rgb
#define cairo_reset_clip wl_call_tbl.cairo_reset_clip
#define cairo_image_surface_get_data wl_call_tbl.cairo_image_surface_get_data
#define cairo_line_to wl_call_tbl.cairo_line_to
#define cairo_surface_destroy wl_call_tbl.cairo_surface_destroy
#define cairo_image_surface_create_for_data wl_call_tbl.cairo_image_surface_create_for_data
#define cairo_image_surface_create wl_call_tbl.cairo_image_surface_create
#define cairo_destroy wl_call_tbl.cairo_destroy
#define cairo_get_source wl_call_tbl.cairo_get_source
#define cairo_close_path wl_call_tbl.cairo_close_path
#define cairo_paint wl_call_tbl.cairo_paint
#define cairo_surface_flush wl_call_tbl.cairo_surface_flush
#define cairo_clip wl_call_tbl.cairo_clip
#define cairo_surface_mark_dirty wl_call_tbl.cairo_surface_mark_dirty
#define cairo_stroke wl_call_tbl.cairo_stroke
#define cairo_set_source_surface wl_call_tbl.cairo_set_source_surface
#define cairo_fill wl_call_tbl.cairo_fill
#define cairo_set_operator wl_call_tbl.cairo_set_operator
#define cairo_pattern_set_filter wl_call_tbl.cairo_pattern_set_filter
#ifndef WL_PROTOCOLS_DEFINED
#define WL_PROTOCOLS_DEFINED
#include "Wayland/wayland-core-protocol.h"
#include "Wayland/xdg-shell-client-protocol.h"
#include "Wayland/viewporter-client-protocol.h"
#include "Wayland/xdg-decoration-client-protocol.h"
#include "Wayland/cursor-shape-client-protocol.h"
#include "Wayland/primary-selection-client-protocol.h"
#include "Wayland/pointer-constraints-client-protocol.h"
#include "Wayland/relative-pointer-client-protocol.h"
#include "Wayland/xdg-toplevel-icon-client-protocol.h"
#endif
typedef struct wayland_protocol {
void* listener;
void* context;
} wayland_protocol_t;
typedef wayland_protocol_t*(wl_setup_func)(MwU32, struct _MwLLWayland*);
typedef void(wl_destroy_func)(struct _MwLLWayland* wayland, wayland_protocol_t* data);
typedef struct wayland_protocol_callback_table {
wl_setup_func* setup;
wl_destroy_func* destroy;
} wayland_protocol_callback_table_t;
struct _MwLLWaylandTopLevel {
struct xdg_surface* xdg_surface;
@ -44,68 +327,203 @@ struct _MwLLWaylandTopLevel {
struct xdg_toplevel_listener xdg_toplevel_listener;
struct xdg_surface_listener xdg_surface_listener;
struct xkb_context* xkb_context;
struct xkb_keymap* xkb_keymap;
struct xkb_state* xkb_state;
MwBool compositor_created;
MwBool xdg_wm_base_created;
MwBool xdg_surface_created;
struct wl_subsurface* ssurface;
struct wl_subcompositor* scompositor;
};
struct _MwLLWaylandSublevel {
struct wl_subsurface* subsurface;
struct wl_subcompositor* subcompositor;
MwLL parent;
struct xdg_surface* xdg_surface;
};
struct _MwLLWaylandPopup {
struct xdg_surface* xdg_surface;
struct xdg_popup* xdg_popup;
struct xdg_positioner* xdg_positioner;
struct xdg_surface_listener xdg_surface_listener;
struct xdg_wm_base* xdg_wm_base;
MwLL topmost_parent;
};
/* Shared set of anything needed for a shm buffer. */
struct _MwLLWaylandShmBuffer {
struct wl_shm* shm;
struct wl_shm_pool* shm_pool;
struct wl_buffer* shm_buffer;
struct wl_shm_pool* shm_pool_back;
struct wl_buffer* shm_buffer_back;
struct wl_surface* surface;
struct wl_output* output;
MwU8* buf;
MwU8* buf_back;
MwU64 buf_size;
int fd;
int fd_back;
MwBool setup;
};
enum _MwLLWaylandType {
MWLL_WAYLAND_UNKNOWN = 0,
MWLL_WAYLAND_TOPLEVEL,
MWLL_WAYLAND_SUBLEVEL,
MWLL_WAYLAND_POPUP,
};
typedef struct wl_clipboard_device_context {
struct {
struct wl_data_device* wl;
struct zwp_primary_selection_device_v1* zwp;
} device;
struct {
struct wl_data_offer* wl;
struct zwp_primary_selection_offer_v1* zwp;
} offer;
MwLL ll;
struct wl_seat* seat;
MwU32 capabilities;
} wl_clipboard_device_context_t;
struct _MwLLWayland {
struct _MwLLCommon common;
union {
/* Pointer for data that's only loaded if the widget is a toplevel */
struct _MwLLWaylandTopLevel* toplevel;
/* Pointer for data that's only loaded if the widget is a sublevel */
struct _MwLLWaylandSublevel* sublevel;
/* Pointer for data that's only loaded if the widget is a popup */
struct _MwLLWaylandPopup* popup;
};
enum {
MWLL_WAYLAND_TOPLEVEL = 0,
MWLL_WAYLAND_SUBLEVEL = 1, /* Sublevels are surfaces that have the toplevel as a parent. They could be implemented as subsurfaces if we ever switch away from OpenGL. Some parts of the code also call them subwidgets. */
} type;
enum _MwLLWaylandType type;
enum _MwLLWaylandType type_to_be;
MwBool detatching;
MwPoint detach_point;
MwBool did_initial_resize;
/* Map of Wayland interfaces to their relevant setup functions. */
struct {
const char* key;
wl_setup_func* value;
char key[255];
wayland_protocol_callback_table_t* value;
}* wl_protocol_setup_map;
/* Map of Wayland interfaces to any information we keep about them once we've registered them. */
struct {
const char* key;
char key[255];
wayland_protocol_t* value;
}* wl_protocol_map;
MwBool has_decorations;
char title[255];
struct xkb_context* xkb_context;
struct xkb_keymap* xkb_keymap;
struct xkb_state* xkb_state;
struct wl_display* display;
struct wl_registry* registry;
struct wl_compositor* compositor;
struct wl_subcompositor* subcompositor;
struct wl_surface* surface;
struct wl_registry_listener registry_listener;
struct wl_event_queue* event_queue;
struct wl_region* o_region;
struct wl_region* region;
struct wl_output* output;
EGLNativeWindowType egl_window_native;
EGLDisplay egl_display;
EGLContext egl_context;
EGLSurface egl_surface;
EGLConfig egl_config;
struct wp_viewport* vp;
MwBool do_lock_pointer;
struct zwp_pointer_constraints_v1* pointer_constraints;
struct zwp_relative_pointer_manager_v1* relative_pointer_manager;
struct zwp_relative_pointer_v1* relative_pointer;
struct zwp_locked_pointer_v1* locked_pointer;
MwBool pointer_constrained;
#ifdef USE_DBUS
MwLLDBusContext dbus;
#endif
MwBool dark_theme_detection;
MwU32 dark_theme;
/* clipboard related stuff.
* Note that unlike most interfaces, we don't keep zwp_primary_selection stuff in a wayland_protocol_t because we use wl_data_device as a fallback and want to have it share memory space.*/
struct {
struct wl_data_device_manager* wl;
struct zwp_primary_selection_device_manager_v1* zwp;
} clipboard_manager;
union {
struct wl_data_source* wl;
struct zwp_primary_selection_source_v1* zwp;
} clipboard_source;
char* clipboard_buffer;
MwBool supports_zwp;
uint32_t clipboard_serial;
wl_clipboard_device_context_t** clipboard_devices_wl;
wl_clipboard_device_context_t** clipboard_devices_zwp;
struct wl_pointer* pointer;
MwU32 pointer_serial;
struct wl_seat* pointer_seat;
struct wl_keyboard* keyboard;
MwU32 keyboard_serial;
MwU64 events_pending;
MwU32 mod_state;
MwLL* sublevels; /* stb_ds managed array of any sublevels */
MwBool configured; /* Whether or not xdg_toplevel_configure has run once */
MwBool egl_setup; /* Whether or not EGL has been set up */
MwBool has_set_xy /* Whether or not MwSetXY has been called */;
int resize_counter; /* Counter that's for a hack in event_loop */
MwU32 x, y, ww, wh; /* Window position */
MwU32 lw, lh; /* Last known window position */
MwBool held_down;
MwI32 x, y;
MwI32 ox, oy;
MwU32 ww, wh; /* Window position */
MwPoint cur_mouse_pos; /* Currently known mouse position */
struct timeval timer;
MwU64 cooldown_timer;
MwU64 cooldown_timer_epoch;
MwU32 mw, mh; /* Monitor width and height as advertised by wl_output.mode */
MwLL parent;
MwLL topmost_parent; /* The parent at the top of all the other parents. Usually a toplevel. */
MwBool force_render;
MwBool did_event_loop_early;
MwBool dispatching_resize;
struct _MwLLWaylandShmBuffer framebuffer;
struct _MwLLWaylandShmBuffer backbuffer;
struct _MwLLWaylandShmBuffer cursor;
struct _MwLLWaylandShmBuffer* icon;
/*
Events mutex. Any time a keyboard/mouse event happens, we try to lock this for 100 milliseconds, then give up if we can't do it. This is used in conjunction with some code in the MwLLDestroyImpl to make sure that destroy is NEVER interferes with an ongoing event.
IOI_XD: This sounds like a hilariously rare edge case, so it's almost funnier that this happened with 100% certainty for me and I spent day(s) trying to figure out what was happening. */
pthread_mutex_t eventsMutex;
uint32_t last_time;
MwBool moving;
cairo_surface_t* front_cs;
cairo_surface_t* back_cs;
cairo_t* front_cairo;
cairo_t* back_cairo;
/* The cairo to actually use for draw operations. Typically is front_cairo, but MwLLBeginDraw can change this to the back_cairo so it can be used to draw window decorations. */
cairo_t* selected_cairo;
};
struct _MwLLWaylandColor {
@ -114,8 +532,8 @@ struct _MwLLWaylandColor {
struct _MwLLWaylandPixmap {
struct _MwLLCommonPixmap common;
GLuint texture;
MwBool texture_deleted;
cairo_surface_t* cs;
};
#endif

View file

@ -29,9 +29,18 @@ struct _MwLLX11 {
GC gc;
Colormap colormap;
Atom wm_delete;
Atom wm_protocols;
Atom utf8_string;
Atom compound_text;
Atom text;
Atom clipboard;
Atom selection;
XIM xim;
XIC xic;
long clipboard_time;
int clipboard_pending; /* 1 if UTF8_STRING, 2 if COMPOUNd_TEXT, 3 if TEXT, 4 if STRING, otherwise 0 */
int top;
int toplevel;
int grabbed;
@ -48,6 +57,12 @@ struct _MwLLX11 {
unsigned long blue_mask;
unsigned long blue_max;
unsigned long blue_shift;
#ifdef USE_DBUS
MwLLDBusContext dbus;
#endif
MwBool dark_theme_detection;
};
struct _MwLLX11Color {

View file

@ -37,27 +37,63 @@
#define GET_WHEEL_DELTA_WPARAM(x) ((short)HIWORD(x))
#endif
#endif
#elif defined(CLASSIC_MAC_OS)
#include <unistd.h>
#include <MacTypes.h>
#include <CFBundle.h>
#include <CodeFragments.h>
#include <Timer.h>
#include <MacWindows.h>
#include <TextEdit.h>
#include <Dialogs.h>
#else
#include <unistd.h>
#include <pwd.h>
#include <dlfcn.h>
#include <signal.h>
#include <dirent.h>
#include <fcntl.h>
#include <limits.h>
#endif
#ifdef __unix__
#include <dirent.h>
#include <dlfcn.h>
#endif
#ifdef __APPLE__
#include <mach/clock.h>
#include <mach/mach.h>
#endif
#ifdef USE_DBUS
#include <dbus/dbus.h>
#endif
#ifndef M_PI
#define M_PI 3.14159265
#endif
/* Windows */
#if defined(_MILSKO) && defined(_WIN32)
#define MWDECL extern __declspec(dllexport)
#elif defined(_WIN32)
#define MWDECL extern __declspec(dllimport)
/* GCC/Clang */
/* First check if we have __has_attribute and can check for the existence of visibility */
#elif defined(__has_attribute)
#if __has_attribute(visibility)
#define MWDECL extern __attribute__((visibility("default")))
#else
#define MWDECL extern
#endif
/* It might be that we're on an old version of GCC (like the one Apple ships with older versions of Mac OS).
* If we're on gcc 3 or above, assume it's there
*/
#elif __GNUC__ >= 3
#define MWDECL extern __attribute__((visibility("default")))
#else
/* all else fails */
#define MWDECL extern
#endif
#define MwInline static __inline

View file

@ -12,7 +12,6 @@
#include <Mw/Core.h>
#include <Mw/Default.h>
#include <Mw/Font.h>
#include <Mw/Error.h>
#include <Mw/Constants.h>
#include <Mw/Unicode.h>
#include <Mw/String.h>

View file

@ -42,6 +42,26 @@ MWDECL unsigned char MwBoldTTFData[];
*/
MWDECL unsigned int MwBoldTTFDataSize;
/*!
* @brief Default monospace TTF font data
*/
MWDECL unsigned char MwMonospaceTTFData[];
/*!
* @brief Default monospace TTF font size
*/
MWDECL unsigned int MwMonospaceTTFDataSize;
/*!
* @brief Default bold monospace TTF font data
*/
MWDECL unsigned char MwBoldMonospaceTTFData[];
/*!
* @brief Default bold monospace TTF font size
*/
MWDECL unsigned int MwBoldMonospaceTTFDataSize;
#ifdef __cplusplus
}
#endif

View file

@ -41,6 +41,21 @@ MWDECL void MwStringSize(char* out, MwOffset size);
*/
MWDECL void MwStringTime(char* out, time_t t);
/*!
* @brief Prints up to n characters into a bufferMwStringPrintIntoBuffer.
* @note On compilers that support C99, this uses vsnprintf to safely print into a buffer; on compilers that don't, vsprintf is used.
* @param out Buffer
* @param size Max size
*/
MWDECL void MwStringPrintIntoBuffer(char* out, MwU32 size, const char* fmt, ...);
/*!
* @brief Check if the given key is UTF8
* @param key Input
* @return whether its utf8
*/
MWDECL MwBool MwStringIsKeyUTF8(MwU32 key);
#ifdef __cplusplus
}
#endif

View file

@ -35,6 +35,14 @@
#define MwNratio "Iratio"
#define MwNfixedSize "IfixedSize"
#define MwNmargin "Imargin"
#define MwNbitmapFont "IbitmapFont"
#define MwNsevenSegment "IsevenSegment"
#define MwNlength "Ilength"
#define MwNforceInverted "IforceInverted"
#define MwNroundness "Iroundness"
#define MwNisRounded "IisRounded"
#define MwNdarkTheme "IdarkTheme"
#define MwNuseMonospace "IuseMonospace"
#define MwNtitle "Stitle"
#define MwNtext "Stext"
@ -49,15 +57,20 @@
#define MwNfont "Vfont"
#define MwNboldFont "VboldFont"
#define MwNbackgroundPixmap "VbackgroundPixmap"
#define MwNmonospaceFont "VmonospaceFont"
#define MwNboldMonospaceFont "VboldMonospaceFont"
#define MwNactivateHandler "Cactivate" /* NULL/int* (MwListBox)/void* (MwTreeView) */
#define MwNactivateHandler "Cactivate" /* NULL */
#define MwNlistBoxActivateHandler "ClistBoxActivate" /* int* */
#define MwNtreeViewActivateHandler "CtreeViewActivate" /* void* */
#define MwNresizeHandler "Cresize" /* NULL */
#define MwNtickHandler "Ctick" /* NULL */
#define MwNmenuHandler "Cmenu" /* MwMenu */
#define MwNmouseDownHandler "CmouseDown" /* MwLLMouse* */
#define MwNmouseDownHandler "CmouseDown" /* MwMouse* */
#define MwNmouseUpHandler "CmouseUp" /* same as MwNmouseDownHandler */
#define MwNmouseMoveHandler "CmouseMove" /* MwPoint* */
#define MwNchangedHandler "Cchanged" /* NULL/int* (MwComboBox) */
#define MwNchangedHandler "Cchanged" /* NULL */
#define MwNcomboBoxChangedHandler "CcomboBoxChanged" /* int* */
#define MwNkeyHandler "Ckey" /* int* (MwLLKeyEnum or character code) */
#define MwNkeyReleaseHandler "CkeyRelease" /* same as MwNkeyHandler */
#define MwNcloseHandler "Cclose" /* NULL */
@ -67,5 +80,7 @@
#define MwNdirectoryChosenHandler "CdirectoryChosen" /* char* */
#define MwNcolorChosenHandler "CcolorChosen" /* MwRGB* */
#define MwNdrawHandler "Cdraw" /* NULL */
#define MwNclipboardHandler "Cclipboard" /* char* */
#define MwNdarkThemeHandler "CdarkTheme" /* int* */
#endif

View file

@ -20,10 +20,15 @@ typedef struct _MwViewport* MwViewport;
typedef struct _MwListBox* MwListBox;
typedef struct _MwComboBox* MwComboBox;
typedef struct _MwTreeView* MwTreeView;
typedef struct _MwScrollBar* MwScrollBar;
typedef struct _MwLabel* MwLabel;
typedef struct _MwLabelSegment MwLabelSegment;
typedef struct _MwListBoxEntry MwListBoxEntry;
typedef struct _MwTreeViewEntry MwTreeViewEntry;
typedef struct _MwDirectoryEntry MwDirectoryEntry;
typedef struct _MwListBoxPacket MwListBoxPacket;
typedef struct _MwBox* MwBox;
typedef struct _MwMouse MwMouse;
#ifdef _MILSKO
typedef struct _MwWidget* MwWidget;
#else
@ -36,6 +41,7 @@ typedef void (*MwHandlerChildrenProp)(MwWidget handle, MwWidget child, const cha
typedef void (*MwHandlerKey)(MwWidget handle, int key);
typedef void (*MwHandlerMouse)(MwWidget handle, void* ptr);
typedef void (*MwHandlerExecute)(MwWidget handle, const char* name, void* out, va_list args);
typedef void (*MwHandlerClipboardReceived)(MwWidget handle, const char* data);
typedef void (*MwUserHandler)(MwWidget handle, void* user_data, void* call_data);
typedef void (*MwErrorHandler)(int code, const char* message, void* user_data);
@ -71,7 +77,6 @@ struct _MwVoidKeyValue {
struct _MwWidget {
char* name;
MwLLColor bgcolor;
int dark_theme;
MwLL lowlevel;
MwWidget parent;
@ -97,6 +102,16 @@ struct _MwWidget {
MwWidget* tick_list;
int destroyed;
void* root_font;
void* root_boldfont;
void* root_monofont;
void* root_boldmonofont;
int top_step;
MwWidget* draw_queue;
int berserk;
};
#endif
@ -105,6 +120,7 @@ struct _MwMenu {
int keep;
MwWidget wsub;
MwMenu* sub;
void* opaque;
};
struct _MwEntry {
@ -164,6 +180,21 @@ struct _MwTreeView {
MwPoint pressed;
};
struct _MwScrollBar {
MwPoint point;
int drag;
int pos;
};
struct _MwLabel {
MwLabelSegment* segment;
};
struct _MwLabelSegment {
int key;
unsigned char value;
};
struct _MwDirectoryEntry {
char* name;
int type;
@ -176,6 +207,15 @@ struct _MwListBoxPacket {
char*** names;
};
struct _MwBox {
int layout;
};
struct _MwMouse {
MwPoint point;
int button;
};
struct _MwClass {
MwHandlerWithStatus create;
MwHandler destroy;
@ -192,11 +232,11 @@ struct _MwClass {
MwHandler resize;
MwHandler children_update;
MwHandlerChildrenProp children_prop_change;
MwHandlerClipboardReceived clipboard;
void* reserved1;
void* reserved2;
void* reserved3;
void* reserved4;
void* reserved5;
};
#endif

View file

@ -17,6 +17,17 @@ extern "C" {
*/
MWDECL MwClass MwLabelClass;
/*!
* @brief Sets the custom data for seven segment
* @param handle Widget
* @param index Index
* @param data Data, `GFEDCBA` as 7-bit value
* @note See https://en.wikipedia.org/wiki/File:7_Segment_Display_with_Labeled_Segments.svg for what alphabets mean here
* */
MwInline void MwLabelSetSevenSegment(MwWidget handle, int index, int data) {
MwVaWidgetExecute(handle, "mwLabelSetSevenSegment", NULL, index, data);
}
#ifdef __cplusplus
}
#endif

View file

@ -5,20 +5,29 @@
#ifndef __MW_WIDGET_OPENGL_H__
#define __MW_WIDGET_OPENGL_H__
#include <Mw/Core.h>
#include <Mw/MachDep.h>
#include <Mw/TypeDefs.h>
#include <Mw/Core.h>
#if !defined(MW_OPENGL_NO_INCLUDE) && !defined(__gl_h_)
#ifdef _WIN32
#include <windows.h>
#elif defined(__APPLE__)
#else
#include <GL/glx.h>
#endif
#if defined(__APPLE__)
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else
#include <GL/gl.h>
#include <GL/glu.h>
#endif
#ifndef GLAPIENTRY
#define GLAPIENTRY APIENTRY
#endif
#endif
#ifdef __cplusplus
extern "C" {

View file

@ -18,8 +18,25 @@ extern "C" {
*/
MWDECL MwClass MwSubMenuClass;
MwInline void MwSubMenuAppear(MwWidget handle, MwMenu menu, MwPoint* point) {
MwVaWidgetExecute(handle, "mwSubMenuAppear", NULL, menu, point);
/*!
* @brief Makes submenu appear
* @param handle Handle
* @param menu Menu
* @param point Point
* @param diff_calc Toggles different way to calculate positiion
*/
MwInline void MwSubMenuAppear(MwWidget handle, MwMenu menu, MwPoint* point, int diff_calc) {
MwVaWidgetExecute(handle, "mwSubMenuAppear", NULL, menu, point, diff_calc);
}
/*!
* @brief Calculates the size of submenu
* @param handle Handle
* @param menu Menu
* @param rect Size
*/
MwInline void MwSubMenuGetSize(MwWidget handle, MwMenu menu, MwRect* rect) {
MwVaWidgetExecute(handle, "mwSubMenuGetSize", NULL, menu, rect);
}
#ifdef __cplusplus

View file

@ -11,17 +11,18 @@
#ifndef __MW_WIDGET_VULKAN_H__
#define __MW_WIDGET_VULKAN_H__
#if !defined(_WIN32) && !defined(__linux__) && !defined(__FreeBSD__) && !defined(__NetBSD__)
#if defined(MW_VULKAN) && !defined(_WIN32) && !defined(__linux__) && !defined(__FreeBSD__) && !defined(__NetBSD__)
#error Vulkan is unsupported on the requested platform.
#endif
#if !defined(MW_VULKAN_NO_INCLUDE)
#include <vulkan/vulkan.h>
#include <vulkan/vulkan_core.h>
#endif
#include <Mw/MachDep.h>
#include <Mw/TypeDefs.h>
#include <Mw/Core.h>
#include <Mw/Error.h>
#ifdef __cplusplus
extern "C" {
@ -47,19 +48,19 @@ MWDECL void MwVulkanEnableLayer(const char* ext_name);
/*!
* @brief Configuration options that can be passed to setup Vulkan before a widget is created.
*/
typedef struct MwVulkanConfig_T {
typedef struct _MwVulkanConfig {
/*!
* @brief Vulkan API version (default: VK_API_VERSION_1_0)
*/
uint32_t api_version;
MwU32 api_version;
/*!
* @brief Vulkan version (default: VK_VERSION_1_0)
*/
uint32_t vk_version;
MwU32 vk_version;
/*!
* @brief Whether or not to enable validation layers (default: false)
*/
VkBool32 validation_layers;
int validation_layers;
} MwVulkanConfig;
/*!
@ -67,61 +68,61 @@ typedef struct MwVulkanConfig_T {
* @warning This must be called before MwCreateWidget.
* @warning The configuration provided will be used for future initializations of the Vulkan widget (unless it's changed)
*/
MWDECL void MwVulkanConfigure(MwVulkanConfig cfg);
MWDECL void MwVulkanConfigure(MwVulkanConfig* cfg);
/*!
* @brief Field that can be gotten from Vulkan.
*/
typedef enum MwVulkanField_T {
enum MwVULKANFIELD {
/*!
* @brief The address of the vulkan widget's vkGetInstanceProcAddr function (PFN_vkGetInstanceProcAddr)
*/
MwVulkanField_GetInstanceProcAddr = 0,
MwVULKANFIELD_GETINSTANCEPROCADDR = 0,
/*!
* @brief The address of the vulkan widget's instance (VkInstance)
*/
MwVulkanField_Instance,
MwVULKANFIELD_INSTANCE,
/*!
* @brief The address of the vulkan widget's surface (VkSurfaceKHR)
*/
MwVulkanField_Surface,
MwVULKANFIELD_SURFACE,
/*!
* @brief The address of the vulkan widget's physical device (VkPhysicalDevice)
*/
MwVulkanField_PhysicalDevice,
MwVULKANFIELD_PHYSICALDEVICE,
/*!
* @brief The address of the vulkan widget's logical device (VkDevice)
*/
MwVulkanField_LogicalDevice,
MwVULKANFIELD_LOGICALDEVICE,
/*!
* @brief The address of the index that the vulkan widget uses for the graphics queue (uint32_t *)
*/
MwVulkanField_GraphicsQueueIndex,
MwVULKANFIELD_GRAPHICSQUEUEINDEX,
/*!
* @brief The address of the index that the vulkan widget uses for the present queue (uint32_t *)
*/
MwVulkanField_PresentQueueIndex,
MwVulkanField_GraphicsQueue,
MwVULKANFIELD_PRESENTQUEUEINDEX,
MwVULKANFIELD_GRAPHICSQUEUE,
/*!
* @brief The address of the vulkan widget's graphics queue (VkQueue)
*/
MwVulkanField_PresentQueue,
} MwVulkanField;
MwVULKANFIELD_PRESENTQUEUE,
};
/*!
* @brief Function for getting a field from within Vulkan.
* @warning Consult the documentation for MwVulkanField to know what type is expected for out.
* @note Consult the documentation for MwVULKANFIELD to know what type is expected for output.
*/
MwInline void* MwVulkanGetField(MwWidget handle, MwVulkanField field, MwErrorEnum* out) {
MwInline void* MwVulkanGetField(MwWidget handle, int field, int* err) {
void* field_out;
MwVaWidgetExecute(handle, "mwVulkanGetField", &field_out, field, out);
MwVaWidgetExecute(handle, "mwVulkanGetField", &field_out, field, err);
return field_out;
}
/*!
* @brief Return whether Vulkan is installed on the target platform.
*/
MWDECL VkBool32 MwVulkanSupported(void);
MWDECL int MwVulkanSupported(void);
#ifdef __cplusplus
}

View file

@ -38,19 +38,18 @@
<short name="green" unsigned="yes" />
<short name="blue" unsigned="yes" />
</struct>
<struct name="MwMouse">
<struct defname="MwPoint" name="point" />
<integer name="button" />
</struct>
<struct name="MwVulkanConfig">
<integer name="api_version" unsigned="yes" />
<integer name="vk_version" unsigned="yes" />
<integer name="validation_layers" />
</struct>
</structs>
<!--
All widgets have:
- MwNbackground
- MwNforeground
- MwNx
- MwNy
- MwNwidth
- MwNheight
- MwNborderWidth
- MwNbackgroundPixmap
- MwNratio
- MwNfixedSize
All widgets have properties that are common="yes".
Integer properties must be prefixed with I.
String properties must be prefixed with S.
@ -58,10 +57,10 @@
Other properties must be prefixed with V.
-->
<properties>
<integer name="x" />
<integer name="y" />
<integer name="width" />
<integer name="height" />
<integer name="x" common="yes" />
<integer name="y" common="yes" />
<integer name="width" common="yes" />
<integer name="height" common="yes" />
<integer name="orientation" />
<integer name="minValue" />
<integer name="maxValue" />
@ -76,46 +75,93 @@
<integer name="hasHeading" />
<integer name="hasBorder" />
<integer name="inverted" />
<integer name="modernLook" />
<integer name="waitMS" />
<integer name="modernLook" common="yes" />
<integer name="hideInput" />
<integer name="singleClickSelectable" />
<integer name="flat" />
<integer name="showArrows" />
<integer name="padding" />
<integer name="borderWidth" />
<integer name="ratio" />
<integer name="fixedSize" />
<integer name="borderWidth" common="yes" />
<integer name="ratio" common="yes" />
<integer name="fixedSize" common="yes" />
<integer name="margin" />
<integer name="bitmapFont" common="yes" />
<integer name="sevenSegment" />
<integer name="length" />
<integer name="forceInverted" common="yes" />
<integer name="isRounded" common="yes" />
<integer name="darkTheme" common="yes" />
<integer name="useMonospace" common="yes" />
<!-- waitMS is a special property, only applies to toplevel widget -->
<integer name="waitMS" common="yes" />
<string name="title" />
<string name="text" />
<string name="background" />
<string name="foreground" />
<string name="background" common="yes" />
<string name="subBackground" common="yes" />
<string name="foreground" common="yes" />
<string name="subForeground" common="yes" />
<pixmap name="pixmap" />
<pixmap name="iconPixmap" />
<struct defname="MwSizeHints" pointer="yes" name="sizeHints" />
<pointer name="font" />
<pointer name="boldFont" />
<pixmap name="backgroundPixmap" common="yes" />
<pointer name="monospaceFont" />
<pointer name="boldMonospaceFont" />
<handler name="activate" />
<handler name="listBoxActivate">
<integer pointer="yes" />
</handler>
<handler name="treeViewActivate">
<pointer />
</handler>
<handler name="resize" />
<handler name="tick" />
<handler name="menu" />
<handler name="mouseDown" />
<handler name="mouseUp" />
<handler name="mouseMove" />
<handler name="menu">
<pointer />
</handler>
<handler name="mouseDown">
<struct defname="MwMouse" pointer="yes" />
</handler>
<handler name="mouseUp">
<struct defname="MwMouse" pointer="yes" />
</handler>
<handler name="mouseMove">
<struct defname="MwPoint" pointer="yes" />
</handler>
<handler name="changed" />
<handler name="key" />
<handler name="keyRelease" />
<handler name="comboBoxChanged">
<integer pointer="yes" />
</handler>
<handler name="key">
<integer pointer="yes" />
</handler>
<handler name="keyRelease">
<integer pointer="yes" />
</handler>
<handler name="close" />
<handler name="focusIn" />
<handler name="focusOut" />
<handler name="fileChosen" />
<handler name="directoryChosen" />
<handler name="colorChosen" />
<handler name="fileChosen">
<string />
</handler>
<handler name="directoryChosen">
<string />
</handler>
<handler name="colorChosen">
<struct defname="MwRGB" pointer="yes" />
</handler>
<handler name="draw" />
<handler name="clipboard">
<string />
</handler>
<handler name="darkTheme">
<integer pointer="yes" />
</handler>
</properties>
<enumerations>
<enumeration name="MwDIRECTION">
@ -142,6 +188,32 @@
<integer name="MwMB_ICONERROR" />
<integer name="MwMB_ICONCLOCK" />
</enumeration>
<enumeration name="MwCOORDINATE">
<integer name="MwCOORDINATE_GLOBAL">0</integer>
<integer name="MwCOORDINATE_LOCAL" />
</enumeration>
<enumeration name="MwCLIPBOARD">
<integer name="MwCLIPBOARD_MAIN">0</integer>
<integer name="MwCLIPBOARD_PRIMARY" />
</enumeration>
<enumeration name="MwMOUSE">
<integer name="MwMOUSE_LEFT">1</integer>
<integer name="MwMOUSE_MIDDLE" />
<integer name="MwMOUSE_RIGHT" />
<integer name="MwMOUSE_WHEELUP" />
<integer name="MwMOUSE_WHEELDOWN" />
</enumeration>
<enumeration name="MwVULKANFIELD">
<integer name="MwVULKANFIELD_GETINSTANCEPROCADDR">0</integer>
<integer name="MwVULKANFIELD_INSTANCE" />
<integer name="MwVULKANFIELD_SURFACE" />
<integer name="MwVULKANFIELD_PHYSICALDEVICE" />
<integer name="MwVULKANFIELD_LOGICALDEVICE" />
<integer name="MwVULKANFIELD_GRAPHICSQUEUEINDEX" />
<integer name="MwVULKANFIELD_PRESENTQUEUEINDEX" />
<integer name="MwVULKANFIELD_GRAPHICSQUEUE" />
<integer name="MwVULKANFIELD_PRESENTQUEUE" />
</enumeration>
</enumerations>
<constants>
<integer name="MwDEFAULT">0x0fffffff</integer>
@ -346,7 +418,7 @@
<widget name="handle" />
</arguments>
</function>
<function name="MwToggleDarkTheme">
<function name="MwSetDarkTheme">
<arguments>
<widget name="handle" />
<integer name="toggle" />
@ -395,14 +467,18 @@
<struct defname="MwRect" pointer="yes" name="rect" />
</arguments>
</function>
</functions>
</header>
<header name="Error">
<functions>
<function name="MwGetLastError">
<return>
<string />
</return>
<function name="MwGetClipboard">
<arguments>
<widget name="handle" />
<integer enumname="MwClipboardType" name="clipboard_type" />
</arguments>
</function>
<function name="MwSetClipboard">
<arguments>
<widget name="handle" />
<string name="text" />
<integer enumname="MwClipboardType" name="clipboard_type" />
</arguments>
</function>
</functions>
</header>
@ -486,13 +562,31 @@
</function>
</functions>
</header>
<!-- They are not alphabetically sorted for reasons -->
<header name="Widget/Vulkan.h">
<functions>
<function name="MwVulkanConfigure">
<return>
<pointer />
</return>
<arguments>
<struct defname="MwVulkanConfig" name="cfg" pointer="yes" />
</arguments>
</function>
</functions>
</header>
</headers>
<!-- Widget functions are prefixed with mw<widget name> -->
<widgets>
<widget name="Box">
<properties>
<property name="orientation" />
<property name="margin" />
<property name="padding" />
<property name="hasBorder" />
<property name="inverted" />
</properties>
</widget>
<widget name="Button">
@ -526,6 +620,7 @@
<property name="pixmap" />
<property name="hasBorder" />
<property name="inverted" />
<property name="fillArea" />
</properties>
</widget>
<widget name="Label">
@ -533,7 +628,18 @@
<property name="text" />
<property name="alignment" />
<property name="bold" />
<property name="sevenSegment" />
<property name="length" />
<property name="leftPadding" />
</properties>
<functions>
<function name="SetSevenSegment">
<arguments>
<integer name="index" />
<integer name="data" />
</arguments>
</function>
</functions>
</widget>
<widget name="ListBox">
<properties>
@ -588,20 +694,6 @@
<property name="text" />
</properties>
</widget>
<widget name="OpenGL">
<functions>
<function name="MakeCurrent" />
<function name="GetProcAddress">
<return>
<pointer />
</return>
<arguments>
<string name="name" />
</arguments>
</function>
<function name="SwapBuffer" />
</functions>
</widget>
<widget name="ScrollBar">
<properties>
<property name="showArrows" />
@ -621,6 +713,9 @@
</functions>
</widget>
<widget name="SubMenu">
<properties>
<property name="leftPadding" />
</properties>
<functions>
<function name="Appear">
<arguments>
@ -689,15 +784,48 @@
</properties>
<functions>
<function name="Add">
<arguments>
<pointer name="parent" />
<pixmap name="pixmap" />
<string name="item" />
</arguments>
</function>
<function name="Delete">
<arguments>
<pointer name="item" />
</arguments>
</function>
<function name="Reset" />
</functions>
</widget>
<!-- They are not alphabetically sorted for reasons -->
<widget name="OpenGL">
<functions>
<function name="MakeCurrent" />
<function name="GetProcAddress">
<return>
<pointer />
</return>
<arguments>
<string name="name" />
</arguments>
</function>
<function name="SwapBuffer" />
</functions>
</widget>
<widget name="Vulkan">
<functions>
<function name="GetField">
<return>
<pointer />
</return>
<arguments>
<integer enumname="MwVulkanField" name="field" />
<integer pointer="yes" name="output" />
</arguments>
</function>
</functions>
</widget>
</widgets>
</milsko>

12
pl/ostype/ClassicMacOS.pl Normal file
View file

@ -0,0 +1,12 @@
use_backend("classicmacos");
print(
"Compiling for Classic Mac OS via ./configure currently outputs a broken executable and it only supports PowerPC. Help is wanted. In the mean time, use CMake."
);
$cc = $ENV{RETRO68_TOOLCHAIN_PATH} . "/bin/powerpc-apple-macos-gcc";
$ar = $ENV{RETRO68_TOOLCHAIN_PATH} . "/bin/powerpc-apple-macos-ar";
add_cflags("-DCLASSIC_MAC_OS");
add_cflags("-DSTBI_NO_THREAD_LOCALS");
1;

9
pl/ostype/Darwin.pl Normal file
View file

@ -0,0 +1,9 @@
$library_suffix = ".dylib";
set_shared_flag("-dynamiclib");
use_backend("cocoa");
add_cflags("-DSTBI_NO_THREAD_LOCALS");
add_ldflags("-framework Cocoa -lobjc");
1;

View file

@ -1,3 +1,14 @@
use_backend("x11");
my @enabled_backends = ();
if (param_get("wayland")) {
push(@enabled_backends, "wayland");
}
if (param_get("x11")) {
push(@enabled_backends, "x11");
}
add_cflags("-DUSE_DBUS");
use_backend(@enabled_backends);
1;

View file

@ -1,6 +1,9 @@
add_incdir("-I/usr/X11R7/include -I/usr/pkg/include");
add_incdir2("-I/usr/X11R7/include -I/usr/pkg/include");
add_libdir(
"-L/usr/X11R7/lib -Wl,-R/usr/X11R7/lib -L/usr/pkg/lib -Wl,-R/usr/pkg/lib");
use_backend("x11");
add_libs("-lpthread");
add_cflags("-DUSE_DBUS");
1;

View file

@ -1,20 +1,24 @@
new_object("src/*.c");
my $gl_libs = "";
if (param_get("tiny")) {
add_cflags("-Oz");
if (defined($ENV{CC}) && grep(/^clang$/, $ENV{CC})) {
add_libs("-flto=thin");
add_cflags("-flto=thin");
}
}
if (param_get("classic-theme")) {
add_cflags("-DUSE_CLASSIC_THEME");
}
if (grep(/^x11$/, @backends)) {
add_cflags("-DUSE_X11");
new_object("src/backend/x11.c");
add_libs("-lX11");
$gl_libs = "-lGL -lGLU";
if (param_get("xrender")) {
add_cflags("-DUSE_XRENDER");
add_libs("-lXrender");
}
}
@ -26,40 +30,83 @@ if (grep(/^gdi$/, @backends)) {
$gl_libs = "-lopengl32 -lglu32";
}
if (grep(/^classicmacos$/, @backends)) {
#add_cflags("-DCLASSIC_MAC_OS");
new_object("src/backend/classicmacos.c");
$gl_libs = "";
}
if (grep(/^wayland$/, @backends)) {
add_cflags("-DUSE_WAYLAND");
new_object("src/backend/wayland.c");
if ($cross) {
add_libs("-lGL -lEGL -lwayland-egl -lwayland-client -lxkbcommon");
}
else {
add_libs("-lGL -lEGL");
add_cflags(`pkg-config --cflags wayland-egl wayland-client xkbcommon`);
add_libs(`pkg-config --libs wayland-egl wayland-client xkbcommon`);
if (param_get("opengl")) {
add_cflags("-DWAYLAND_LOAD_OPENGL");
}
scan_wayland_protocol_core();
scan_wayland_protocol("stable", "xdg-shell", "");
scan_wayland_protocol("stable", "viewporter", "");
scan_wayland_protocol("stable", "tablet", "-v2");
scan_wayland_protocol("staging", "xdg-toplevel-icon", "-v1");
scan_wayland_protocol("staging", "cursor-shape", "-v1");
scan_wayland_protocol("unstable", "xdg-decoration", "-unstable-v1");
scan_wayland_protocol("unstable", "primary-selection", "-unstable-v1");
scan_wayland_protocol("unstable", "pointer-constraints", "-unstable-v1");
scan_wayland_protocol("unstable", "relative-pointer", "-unstable-v1");
$gl_libs = "-lGL -lGLU";
}
if (grep(/( |^)-DUSE_DBUS( |$)/, $cflags)) {
add_cflags(`pkg-config --cflags dbus-1`);
}
if (grep(/^cocoa$/, @backends) || param_get("gnustep")) {
add_cflags("-DUSE_COCOA");
new_object("src/backend/cocoa.m");
if (param_get("gnustep")) {
add_incdir("-I" . `gnustep-config --variable=GNUSTEP_SYSTEM_HEADERS`);
add_libdir("-L" . `gnustep-config --variable=GNUSTEP_SYSTEM_LIBRARIES`);
add_cflags("-fobjc-runtime=gnustep-2.0 -fblocks");
add_ldflags("-lobjc -lgnustep-base -lm -lgnustep-gui");
}
if (param_get("opengl")) {
new_object("src/widget/opengl_cocoa.m");
}
# tim cook my man literally everybody and their mother who knows what opengl is knows its deprecated on macos and i'm not having you spam the console with this
add_cflags("-DGL_SILENCE_DEPRECATION");
$gl_libs = "-framework OpenGL";
}
if (param_get("stb-image")) {
add_cflags("-DUSE_STB_IMAGE");
if (param_get("tiny")) {
add_cflags("-DSTB_IMAGE_STATIC");
add_cflags("-DSTB_IMAGE_IMPLEMENTATION");
}
}
else {
new_object("external/libjpeg/src/*.c");
new_object("external/libpng/src/*.c");
add_incdir("-Iexternal/libjpeg/include -Iexternal/libpng/include");
}
if (param_get("stb-truetype")) {
add_cflags("-DUSE_STB_TRUETYPE");
}
add_incdir("-Iexternal/libz/include");
if (param_get("freetype2")) {
add_cflags("-DUSE_FREETYPE2");
if ($cross) {
add_libs("-lfreetype");
}
else {
if (!$cross) {
add_cflags(`pkg-config --cflags freetype2`);
add_libs(`pkg-config --libs freetype2`);
}
}
@ -68,8 +115,9 @@ if (param_get("vulkan") && param_get("vulkan-string-helper")) {
}
new_object("src/icon/*.c");
new_object("src/font/*.c");
new_object("src/cursor/*.c");
new_object("src/text/*.c");
new_object("src/text/font/*.c");
new_object("src/widget/box.c");
new_object("src/widget/button.c");
@ -91,11 +139,14 @@ new_object("src/widget/treeview.c");
new_object("src/widget/viewport.c");
new_object("src/widget/window.c");
if (param_get("opengl")) {
new_object("src/widget/opengl.c");
new_object("src/widget/vulkan.c");
if (param_get("opengl")) {
add_cflags("-DMW_OPENGL");
}
if (param_get("vulkan")) {
new_object("src/widget/vulkan.c");
add_cflags("-DMW_VULKAN");
}
new_object("src/dialog/*.c");
@ -103,6 +154,7 @@ new_object("src/dialog/*.c");
new_object("src/abstract/*.c");
new_object("external/*.c");
new_object("external/libz/src/*.c");
new_example("examples/basic/example");
new_example("examples/basic/rotate");
@ -118,6 +170,10 @@ new_example("examples/basic/colorpicker");
new_example("examples/basic/combobox");
new_example("examples/basic/treeview");
new_example("examples/basic/box");
new_example("examples/basic/clipboard");
new_example("examples/basic/sevensegment");
new_example("examples/basic/calculator");
new_example("examples/basic/periodic");
if (param_get("opengl")) {
new_example("examples/gldemos/boing", $gl_libs);

View file

@ -5,6 +5,13 @@ sub add_incdir {
$incdir = "${incdir} ${input}";
}
sub add_incdir2 {
my $input = $_[0];
$input =~ s/\r?\n/ /g;
$incdir2 = "${incdir2} ${input}";
}
sub add_cflags {
my $input = $_[0];
$input =~ s/\r?\n/ /g;
@ -40,10 +47,14 @@ sub new_example {
push(@examples_targets, "${_[0]}${executable_suffix}");
}
sub set_shared_flag {
@shared = $_[0];
}
sub new_object {
my @l = glob($_[0]);
foreach my $e (@l) {
$e =~ s/\.c$/$object_suffix/;
$e =~ s/\.(c|m)$/$object_suffix/;
push(@library_targets, $e);
}
}
@ -54,6 +65,34 @@ sub use_backend {
}
}
sub scan_wayland_protocol_core {
my $proto_c = "src/backend/wayland-core-protocol.c";
if (
system(
"wayland-scanner private-code /usr/share/wayland/wayland.xml ${proto_c}"
) != 0
)
{
print(
"^ Error on getting private code for /usr/share/wayland/wayland.xml\n"
);
}
else {
new_object($proto_c);
}
if (
system(
"wayland-scanner client-header /usr/share/wayland/wayland.xml include/Mw/LowLevel/Wayland/wayland-core-protocol.h"
)
)
{
print(
"^ Error on getting client header for /usr/share/wayland/wayland.xml\n"
);
}
}
sub scan_wayland_protocol {
my $tier = $_[0];
my $proto = $_[1];

Binary file not shown.

Binary file not shown.

View file

@ -4,7 +4,11 @@
typedef struct dir {
HANDLE hFind;
WIN32_FIND_DATA ffd;
int first;
int next;
} dir_t;
#elif defined(CLASSIC_MAC_OS)
typedef struct dir {
int dummy;
} dir_t;
#else
typedef struct dir {
@ -18,14 +22,21 @@ void* MwDirectoryOpen(const char* path) {
#ifdef _WIN32
char* p = malloc(strlen(path) + 2 + 1);
strcpy(p, path);
strcat(p, "/*");
if(strchr(path, '/') != NULL) {
strcat(p, "/");
} else {
strcat(p, "\\");
}
strcat(p, "*");
if((dir->hFind = FindFirstFile(p, &dir->ffd)) == INVALID_HANDLE_VALUE) {
free(p);
free(dir);
return NULL;
}
free(p);
dir->first = 1;
dir->next = 1;
#elif defined(CLASSIC_MAC_OS)
/* todo */
#else
if((dir->dir = opendir(path)) == NULL) {
free(dir);
@ -42,6 +53,8 @@ void MwDirectoryClose(void* handle) {
dir_t* dir = handle;
#ifdef _WIN32
FindClose(dir->hFind);
#elif defined(CLASSIC_MAC_OS)
/* todo */
#else
closedir(dir->dir);
free(dir->base);
@ -54,14 +67,10 @@ MwDirectoryEntry* MwDirectoryRead(void* handle) {
MwDirectoryEntry* entry = malloc(sizeof(*entry));
#ifdef _WIN32
ULARGE_INTEGER* l;
if(dir->first) {
dir->first = 0;
} else if(FindNextFile(dir->hFind, &dir->ffd) == 0) {
free(entry);
return NULL;
}
entry->name = MwStringDuplicate(dir->ffd.cFileName);
if(!dir->next) return NULL;
entry->name = MwStringDuplicate(dir->ffd.cFileName);
if(dir->ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
entry->type = MwDIRECTORY_DIRECTORY;
} else {
@ -77,6 +86,10 @@ MwDirectoryEntry* MwDirectoryRead(void* handle) {
l = (ULARGE_INTEGER*)&dir->ffd.ftLastWriteTime;
entry->mtime = l->QuadPart / 10000000 - 11644473600;
dir->next = FindNextFile(dir->hFind, &dir->ffd);
#elif defined(CLASSIC_MAC_OS)
/* todo */
#else
struct dirent* d;
struct stat s;
@ -120,6 +133,8 @@ char* MwDirectoryCurrent(void) {
GetCurrentDirectory(len, out);
return out;
#elif CLASSIC_MAC_OS
return "";
#else
return getcwd(NULL, 0);
#endif

View file

@ -12,7 +12,43 @@ void* MwDynamicSymbol(void* handle, const char* symbol) {
void MwDynamicClose(void* handle) {
FreeLibrary(handle);
}
#elif defined(__unix__)
#elif defined(CLASSIC_MAC_OS)
void* MwDynamicOpen(const char* path) {
// CFragConnectionID connID;
// Ptr* addr;
// unsigned char err[255];
// if(GetSharedLibrary((ConstStr63Param)path, kPowerPCCFragArch, kPrivateCFragCopy,
// &connID, addr, err)) {
// printf("Error getting %s: %s\n", path, err);
// return NULL;
// };
// return connID;
printf("MwDynamicOpen not implemented yet.\n");
getchar();
return NULL;
}
void* MwDynamicSymbol(void* handle, const char* symbol) {
// CFragConnectionID connID = (CFragConnectionID)handle;
// Ptr* symAddr;
// CFragSymbolClass* symClass;
// OSErr err;
// if((err = FindSymbol(connID, (ConstStr63Param)symbol, symAddr, symClass))) {
// printf("Error getting %s: %d\n", symbol, err);
// return NULL;
// };
// return symAddr;
printf("MwDynamicSymbol not implemented yet.\n");
getchar();
return NULL;
}
void MwDynamicClose(void* handle) {
// CFragConnectionID connID = (CFragConnectionID)handle;
// CloseConnection(&connID);
}
#elif defined(__unix__) || defined(__APPLE__)
void* MwDynamicOpen(const char* path) {
return dlopen(path, RTLD_LOCAL | RTLD_LAZY);
}

View file

@ -8,6 +8,53 @@ long MwTimeGetTick(void) {
void MwTimeSleep(int ms) {
Sleep(ms);
}
#elif defined(__APPLE__)
long MwTimeGetTick(void) {
struct timespec ts;
long n = 0;
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
clock_get_time(cclock, &mts);
mach_port_deallocate(mach_task_self(), cclock);
n += ts.tv_nsec / 1000 / 1000;
n += ts.tv_sec * 1000;
return n;
}
void MwTimeSleep(int ms) {
struct timespec ts;
ts.tv_sec = ms / 1000;
ts.tv_nsec = (ms % 1000) * 1000 * 1000;
nanosleep(&ts, NULL);
}
#elif defined(CLASSIC_MAC_OS)
// static TMTask tm;
// static int timer;
// void timerUpdateFunc(void) {
// timer += 1;
// PrimeTime((QElemPtr)&tm, 1);
// };
long MwTimeGetTick(void) {
UnsignedWide h;
Microseconds(&h);
return h.lo;
}
void MwTimeSleep(int ms) {
// tm.tmAddr = NewTimerProc(timerUpdateFunc);
// tm.tmWakeUp = 0;
// tm.tmReserved = 0;
// InsTime((QElemPtr)&tm);
// PrimeTime((QElemPtr)&tm, 1);
// DisposeTimerUPP(tm.tmAddr);
}
#elif defined(__unix__)
long MwTimeGetTick(void) {
struct timespec ts;
@ -25,7 +72,7 @@ void MwTimeSleep(int ms) {
struct timespec ts;
ts.tv_sec = ms / 1000;
ts.tv_nsec = (ms % 1000) * 1000 * 1000;
ts.tv_nsec = (ms % 1000) * 1000000;
nanosleep(&ts, NULL);
}

View file

@ -54,6 +54,8 @@
\
MwLLGetCursorCoord = MwLLGetCursorCoordImpl; \
MwLLGetScreenSize = MwLLGetScreenSizeImpl; \
\
MwLLSetDarkTheme = MwLLSetDarkThemeImpl; \
\
return 0; \
}

357
src/backend/classicmacos.c Normal file
View file

@ -0,0 +1,357 @@
#include <Mw/Milsko.h>
#include <Threads.h>
#include <QuickDraw.h>
#include "../../external/stb_ds.h"
static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
MwLL r;
r = malloc(sizeof(*r));
memset(r, 0, sizeof(*r));
MwLLCreateCommon(r);
r->cmacos.parent = parent;
if(x == MwDEFAULT) {
x = (qd.screenBits.bounds.right / 2) - (width / 2);
}
if(y == MwDEFAULT) {
y = (qd.screenBits.bounds.bottom / 2) - (height / 2);
}
/* todo: how do we set parent windows? If we can't, what is our equivalant to MacOS's NSViews, Wayland's subsurfaces, etc.? */
SetRect(&r->cmacos.winRect, x, y, width, height);
r->cmacos.window = newcwindow(nil, &r->cmacos.winRect, "", true,
documentProc, (WindowPtr)(-1), true, 0);
SetPort(r->cmacos.window);
return r;
}
static void MwLLDestroyImpl(MwLL handle) {
MwLLDestroyCommon(handle);
free(handle);
}
static void MwLLBeginDrawImpl(MwLL handle) {
}
static void MwLLEndDrawImpl(MwLL handle) {
}
static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLLColor color) {
int i;
PolyHandle p;
RGBColor col;
SetPort(handle->cmacos.window);
BeginUpdate(handle->cmacos.window);
p = OpenPoly();
col.red = color->common.red * 0x101;
col.green = color->common.green * 0x101;
col.blue = color->common.blue * 0x101;
RGBForeColor(&col);
PenMode(patCopy);
for(i = 0; i < points_count; i++) {
if(i == 0) {
MoveTo(points[i].x, points[i].y);
} else {
LineTo(points[i].x, points[i].y);
}
}
ClosePoly();
FillCPoly(p, &qd.ltGray);
KillPoly(p);
EndUpdate(handle->cmacos.window);
}
static void MwLLLineImpl(MwLL handle, MwPoint* points, MwLLColor color) {
RGBColor col;
SetPort(handle->cmacos.window);
col.red = color->common.red;
col.green = color->common.green;
col.blue = color->common.blue;
RGBForeColor(&col);
PenMode(patCopy);
MoveTo(points[0].x, points[0].y);
LineTo(points[1].x, points[1].y);
}
static MwLLColor MwLLAllocColorImpl(MwLL handle, int r, int g, int b) {
MwLLColor c = malloc(sizeof(*c));
MwLLColorUpdate(handle, c, r, g, b);
return c;
}
static void MwLLColorUpdateImpl(MwLL handle, MwLLColor c, int r, int g, int b) {
c->common.red = r;
c->common.green = g;
c->common.blue = b;
}
static void MwLLGetXYWHImpl(MwLL handle, int* x, int* y, unsigned int* w, unsigned int* h) {
Rect bounds;
GetWindowBounds(handle->cmacos.window, kWindowContentRgn, &bounds);
*x = bounds.left;
*y = bounds.top;
*w = bounds.right;
*h = bounds.bottom;
}
static void MwLLSetXYImpl(MwLL handle, int x, int y) {
MoveWindow(handle->cmacos.window, x, y, MwTRUE);
}
static void MwLLSetWHImpl(MwLL handle, int w, int h) {
SizeWindow(handle->cmacos.window, w, h, MwTRUE);
}
static void MwLLFreeColorImpl(MwLLColor color) {
free(color);
}
static int MwLLPendingImpl(MwLL handle) {
YieldToAnyThread();
return EventAvail(everyEvent, &handle->cmacos.event);
}
static void MwLLNextEventImpl(MwLL handle) {
EventRecord event;
GetNextEvent(everyEvent, &event);
switch(event.what) {
case updateEvt: {
}
// MwLLDispatch(handle, draw, NULL);
break;
case osEvt:
break;
case mouseUp: {
// MwLLMouse m;
// m.button = MwLLMouseLeft;
// if(___curWindow->mouseButtonCallback != NULL) {
// int mods = MacModifiersToGLFWModifiers(event.modifiers);
// if(___curWindow->keyStateMap[MK_LCTRL] == 1) {
// ___curWindow->mouseButtonCallback(
// ___curWindow, GLFW_MOUSE_BUTTON_RIGHT, GLFW_RELEASE, mods);
// } else {
// ___curWindow->mouseButtonCallback(
// ___curWindow, GLFW_MOUSE_BUTTON_LEFT, GLFW_RELEASE, mods);
// }
// }
}
case mouseDown: {
// // start with callback stuff
// if(___curWindow->mouseButtonCallback != NULL) {
// int mods = MacModifiersToGLFWModifiers(event.modifiers);
// if(___curWindow->keyStateMap[MK_LCTRL] == 1) {
// ___curWindow->mouseButtonCallback(
// ___curWindow, GLFW_MOUSE_BUTTON_RIGHT, GLFW_PRESS, mods);
// } else {
// ___curWindow->mouseButtonCallback(
// ___curWindow, GLFW_MOUSE_BUTTON_LEFT, GLFW_PRESS, mods);
// }
// }
// then do system stuff
switch(FindWindow(event.where, &handle->cmacos.window)) {
case inDrag:
DragWindow(handle->cmacos.window, event.where, &qd.screenBits.bounds);
// if(___curWindow->windowPosCallback != NULL) {
// ___curWindow->windowPosCallback(___curWindow, event.where.h,
// event.where.v);
// }
break;
case inGrow: {
long growResult =
GrowWindow(handle->cmacos.window, event.where, &qd.screenBits.bounds);
int width = growResult & 0xFFFF;
int height = growResult >> 16;
SizeWindow(handle->cmacos.window, growResult & 0xFFFF, growResult >> 16, true);
Rect rect;
GetWindowBounds(handle->cmacos.window, kWindowStructureRgn, &rect);
rect.right = width;
rect.bottom = height;
SetWindowBounds(handle->cmacos.window, kWindowStructureRgn, &rect);
// ___curWindow->width = width;
// ___curWindow->height = height;
// if(___curWindow->windowSizeCallback != NULL) {
// ___curWindow->windowSizeCallback(___curWindow, width, height);
// }
// if(___curWindow->windowSetFramebufferSizeCallback != NULL) {
// ___curWindow->windowSetFramebufferSizeCallback(___curWindow,
// width, height);
// }
} break;
case inGoAway: {
if(TrackGoAway(handle->cmacos.window, event.where)) {
MwLLDispatch(handle, close, NULL);
// if(___curWindow->windowCloseCallback != NULL) {
// ___curWindow->windowCloseCallback(___curWindow);
// }
// ___curWindow->shouldClose = true;
}
} break;
}
}
case autoKey:
case keyDown:
case keyUp: {
// // key char stuff
// unsigned char ch = (event.message & charCodeMask);
// if(*___curWindow->charCallback != NULL) {
// ___curWindow->charCallback(___curWindow, ch);
// }
// // key state map
// unsigned char key = (event.message & keyCodeMask) >> 8;
// ___curWindow->keyStateMap[key] = 0;
// if(event.what == keyDown || event.what == autoKey) {
// ___curWindow->keyStateMap[key] &= 1;
// }
// if(*___curWindow->keyCallback != NULL) {
// int key = MacKeyToGLFWKey(event.message);
// int scancode = (event.message & adbAddrMask) >> 16;
// int mods = MacModifiersToGLFWModifiers(event.modifiers);
// int action;
// if(event.what == keyUp) {
// action = GLFW_RELEASE;
// } else {
// action = GLFW_PRESS;
// }
// ___curWindow->keyCallback(___curWindow, key, scancode, action,
// mods);
// }
}
}
FlushEvents(everyEvent, -1);
YieldToAnyThread();
}
static void MwLLSetTitleImpl(MwLL handle, const char* title) {
setwtitle(handle->cmacos.window, title);
}
static MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, int width, int height) {
MwLLPixmap r = malloc(sizeof(*r));
r->common.raw = malloc(4 * width * height);
memcpy(r->common.raw, data, 4 * width * height);
MwLLPixmapUpdate(r);
return r;
}
static void MwLLPixmapUpdateImpl(MwLLPixmap r) {
}
static void MwLLDestroyPixmapImpl(MwLLPixmap pixmap) {
}
static void MwLLDrawPixmapImpl(MwLL handle, MwRect* rect, MwLLPixmap pixmap) {
}
static void MwLLSetIconImpl(MwLL handle, MwLLPixmap pixmap) {
}
static void MwLLForceRenderImpl(MwLL handle) {
}
static void MwLLSetCursorImpl(MwLL handle, MwCursor* image, MwCursor* mask) {
}
static void MwLLDetachImpl(MwLL handle, MwPoint* point) {
}
static void MwLLShowImpl(MwLL handle, int show) {
if(show)
ShowWindow(handle->cmacos.window);
else
HideWindow(handle->cmacos.window);
}
static void MwLLMakePopupImpl(MwLL handle, MwLL parent) {
}
static void MwLLSetSizeHintsImpl(MwLL handle, int minx, int miny, int maxx, int maxy) {
}
static void MwLLMakeBorderlessImpl(MwLL handle, int toggle) {
}
static void MwLLFocusImpl(MwLL handle) {
HiliteWindow(handle->cmacos.window, MwTRUE);
}
static void MwLLGrabPointerImpl(MwLL handle, int toggle) {
}
static void MwLLSetClipboardImpl(MwLL handle, const char* text, int clipboard_type) {
/* TODO */
(void)handle;
(void)text;
}
static void MwLLGetClipboardImpl(MwLL handle, int clipboard_type) {
}
static void MwLLMakeToolWindowImpl(MwLL handle) {
}
static void MwLLGetCursorCoordImpl(MwLL handle, MwPoint* point) {
}
static void MwLLGetScreenSizeImpl(MwLL handle, MwRect* rect) {
}
static void MwLLBeginStateChangeImpl(MwLL handle) {
MwLLShow(handle, 0);
}
static void MwLLEndStateChangeImpl(MwLL handle) {
MwLLShow(handle, 1);
}
static void MwLLSetDarkThemeImpl(MwLL handle, int toggle) {
(void)handle;
(void)toggle;
}
static int MwLLClassicMacOSCallInitImpl(void) {
InitGraf(&qd.thePort);
InitFonts();
FlushEvents(everyEvent, 0);
InitWindows();
InitMenus();
TEInit();
InitDialogs(0L);
InitCursor();
return 0;
}
#include "call.c"
CALL(ClassicMacOS);

1115
src/backend/cocoa.m Normal file

File diff suppressed because it is too large Load diff

View file

@ -8,6 +8,40 @@ typedef struct userdata {
int max_set;
} userdata_t;
static struct symtbl {
void* lib_dwmapi;
HRESULT(WINAPI* DwmSetWindowAttribute)(HWND hwnd, DWORD dwAttribute, LPCVOID pvAttribute, DWORD cbAttribute);
} wsymtbl;
#define DwmSetWindowAttribute wsymtbl.DwmSetWindowAttribute
static void detect_darktheme(MwLL handle) {
DWORD dw;
DWORD sz = sizeof(dw);
int err, t;
HKEY hkey;
DWORD type;
err = RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", 0, KEY_QUERY_VALUE, &hkey);
if(err != ERROR_SUCCESS) return;
err = RegQueryValueEx(hkey, "AppsUseLightTheme", NULL, &type, (PBYTE)&dw, &sz);
RegCloseKey(hkey);
if(err != ERROR_SUCCESS || type != REG_DWORD) {
return;
}
t = dw ? 0 : 1;
if(t && DwmSetWindowAttribute != NULL) {
LPARAM style = GetWindowLongPtr(handle->gdi.hWnd, GWL_STYLE);
if(!(style & WS_CHILD)) MwLLSetDarkTheme(handle, 1);
}
MwLLDispatch(handle, dark_theme, &t);
}
static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
userdata_t* u = (userdata_t*)GetWindowLongPtr(hWnd, GWLP_USERDATA);
@ -45,44 +79,44 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
EndPaint(hWnd, &ps);
}
} else if(msg == WM_LBUTTONDOWN || msg == WM_MBUTTONDOWN || msg == WM_RBUTTONDOWN) {
MwLLMouse p;
MwMouse p;
p.point.x = LOWORD(lp);
p.point.y = HIWORD(lp);
if(msg == WM_LBUTTONDOWN) {
p.button = MwLLMouseLeft;
p.button = MwMOUSE_LEFT;
} else if(msg == WM_MBUTTONDOWN) {
p.button = MwLLMouseMiddle;
p.button = MwMOUSE_MIDDLE;
} else if(msg == WM_RBUTTONDOWN) {
p.button = MwLLMouseRight;
p.button = MwMOUSE_RIGHT;
}
SetCapture(hWnd);
SetFocus(hWnd);
MwLLDispatch(u->ll, down, &p);
} else if(msg == WM_LBUTTONUP || msg == WM_MBUTTONUP || msg == WM_RBUTTONUP) {
MwLLMouse p;
MwMouse p;
p.point.x = LOWORD(lp);
p.point.y = HIWORD(lp);
if(msg == WM_LBUTTONUP) {
p.button = MwLLMouseLeft;
p.button = MwMOUSE_LEFT;
} else if(msg == WM_MBUTTONUP) {
p.button = MwLLMouseMiddle;
p.button = MwMOUSE_MIDDLE;
} else if(msg == WM_RBUTTONUP) {
p.button = MwLLMouseRight;
p.button = MwMOUSE_RIGHT;
}
SetCapture(NULL);
MwLLDispatch(u->ll, up, &p);
} else if(msg == WM_MOUSEWHEEL) {
int d = GET_WHEEL_DELTA_WPARAM(wp);
MwLLMouse p;
MwMouse p;
p.point.x = LOWORD(lp);
p.point.y = HIWORD(lp);
if(d > 0) {
p.button = MwLLMouseWheelUp;
p.button = MwMOUSE_WHEELUP;
} else if(d < 0) {
p.button = MwLLMouseWheelDown;
p.button = MwMOUSE_WHEELDOWN;
}
MwLLDispatch(u->ll, down, &p);
@ -205,6 +239,13 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
} else if(msg == WM_USER) {
InvalidateRect(hWnd, NULL, FALSE);
UpdateWindow(hWnd);
} else if(msg == WM_WININICHANGE) {
char* s = (char*)lp;
LPARAM style = GetWindowLongPtr(hWnd, GWL_STYLE);
if(!(style & WS_CHILD)) {
if(s != NULL && strcmp(s, "ImmersiveColorSet") == 0) detect_darktheme(u->ll);
}
} else {
return DefWindowProc(hWnd, msg, wp, lp);
}
@ -237,6 +278,8 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
r->common.copy_buffer = 1;
r->common.type = MwLLBackendGDI;
r->gdi.get_clipboard = 0;
if(parent == NULL) r->gdi.get_darktheme = 1;
r->gdi.force_render = 0;
r->gdi.grabbed = 0;
r->gdi.hWnd = CreateWindow("milsko", "Milsko", parent == NULL ? (WS_OVERLAPPEDWINDOW) : (WS_CHILD | WS_VISIBLE), x == MwDEFAULT ? CW_USEDEFAULT : x, y == MwDEFAULT ? CW_USEDEFAULT : y, width, height, parent == NULL ? NULL : parent->gdi.hWnd, 0, wc.hInstance, NULL);
@ -383,6 +426,7 @@ static int MwLLPendingImpl(MwLL handle) {
(void)handle;
if(handle->gdi.get_clipboard || handle->gdi.get_darktheme) return 1;
return PeekMessage(&msg, handle->gdi.hWnd, 0, 0, PM_NOREMOVE) ? 1 : 0;
}
@ -391,6 +435,29 @@ static void MwLLNextEventImpl(MwLL handle) {
(void)handle;
if(handle->gdi.get_clipboard) {
HGLOBAL hg;
if(OpenClipboard(handle->gdi.hWnd) != 0 && (hg = GetClipboardData(CF_TEXT)) != NULL) {
char* txt = malloc(GlobalSize(hg));
char* clp = GlobalLock(hg);
strcpy(txt, clp);
GlobalUnlock(hg);
CloseClipboard();
MwLLDispatch(handle, clipboard, txt);
free(txt);
}
handle->gdi.get_clipboard = 0;
}
if(handle->gdi.get_darktheme) {
detect_darktheme(handle);
handle->gdi.get_darktheme = 0;
}
while(PeekMessage(&msg, handle->gdi.hWnd, 0, 0, PM_NOREMOVE)) {
GetMessage(&msg, handle->gdi.hWnd, 0, 0);
TranslateMessage(&msg);
@ -535,8 +602,8 @@ HCURSOR MwLLGDICreateCursor(MwCursor* image, MwCursor* mask) {
int y, x, ys, xs;
xs = -mask->x + image->x;
ys = MwCursorDataHeight + mask->y;
ys = MwCursorDataHeight + image->y - ys;
ys = mask->height + mask->y;
ys = image->height + image->y - ys;
memset(dmask, 0xff, (MwCursorDataHeight / 8) * MwCursorDataHeight);
memset(dimage, 0, (MwCursorDataHeight / 8) * MwCursorDataHeight);
@ -567,7 +634,7 @@ HCURSOR MwLLGDICreateCursor(MwCursor* image, MwCursor* mask) {
}
}
cursor = CreateCursor(GetModuleHandle(NULL), xs, ys, MwCursorDataHeight, MwCursorDataHeight, dmask, dimage);
cursor = CreateCursor(GetModuleHandle(NULL), xs - image->x, ys + (MwCursorDataHeight + image->y), MwCursorDataHeight, MwCursorDataHeight, dmask, dimage);
free(dimage);
free(dmask);
@ -609,6 +676,8 @@ static void MwLLDetachImpl(MwLL handle, MwPoint* point) {
rc2.bottom -= rc2.top;
SetWindowPos(handle->gdi.hWnd, HWND_TOPMOST, rc.left, rc.top, rc2.right == 0 ? 1 : rc2.right, rc2.bottom == 0 ? 1 : rc2.bottom, SWP_FRAMECHANGED | SWP_NOACTIVATE);
handle->gdi.get_darktheme = 1;
}
static void MwLLShowImpl(MwLL handle, int show) {
@ -679,8 +748,9 @@ static void MwLLGrabPointerImpl(MwLL handle, int toggle) {
}
}
static void MwLLSetClipboardImpl(MwLL handle, const char* text) {
static void MwLLSetClipboardImpl(MwLL handle, const char* text, int clipboard_type) {
HGLOBAL hg;
(void)clipboard_type;
if(OpenClipboard(handle->gdi.hWnd) != 0) {
char* lock;
@ -697,21 +767,9 @@ static void MwLLSetClipboardImpl(MwLL handle, const char* text) {
}
}
static char* MwLLGetClipboardImpl(MwLL handle) {
HGLOBAL hg;
char* r = NULL;
if(OpenClipboard(handle->gdi.hWnd) != 0 && (hg = GetClipboardData(CF_TEXT)) != NULL) {
char* lock;
r = malloc(GlobalSize(hg));
lock = GlobalLock(hg);
strcpy(r, lock);
GlobalUnlock(hg);
CloseClipboard();
}
return r;
static void MwLLGetClipboardImpl(MwLL handle, int clipboard_type) {
(void)clipboard_type;
handle->gdi.get_clipboard = 1; /* nishi: we do this to make clipboard api work similar to other backends */
}
static void MwLLMakeToolWindowImpl(MwLL handle) {
@ -761,7 +819,19 @@ static void MwLLEndStateChangeImpl(MwLL handle) {
(void)handle;
}
static void MwLLSetDarkThemeImpl(MwLL handle, int toggle) {
BOOL v = toggle ? TRUE : FALSE;
DwmSetWindowAttribute(handle->gdi.hWnd, 20, &v, sizeof(v));
}
static int MwLLGDICallInitImpl(void) {
memset(&wsymtbl, 0, sizeof(wsymtbl));
wsymtbl.lib_dwmapi = MwDynamicOpen("dwmapi.dll");
if(wsymtbl.lib_dwmapi != NULL) DwmSetWindowAttribute = MwDynamicSymbol(wsymtbl.lib_dwmapi, "DwmSetWindowAttribute");
/* TODO: check properly */
return 0;
}

File diff suppressed because it is too large Load diff

View file

@ -2,6 +2,190 @@
#include "../../external/stb_ds.h"
#define ClipboardTimeout 100
static struct symtbl {
void* lib_xlib;
void* lib_xrender;
MwBool has_xrender;
#ifdef USE_DBUS
MwLLDBusFuncTable dbus;
MwBool has_dbus;
#endif
int (*XClearWindow)(Display* display, Window w);
XImage* (*XCreateImage)(Display*, Visual*, unsigned int, int, int, char*, unsigned int, unsigned int, int, int);
Display* (*XOpenDisplay)(_Xconst char*);
char* (*XKeysymToString)(KeySym);
Atom (*XInternAtom)(Display*, _Xconst char*, Bool);
Cursor (*XCreatePixmapCursor)(Display*, Pixmap, Pixmap, XColor*, XColor*, unsigned int, unsigned int);
GC (*XCreateGC)(Display*, Drawable, unsigned long, XGCValues*);
Pixmap (*XCreatePixmap)(Display*, Drawable, unsigned int, unsigned int, unsigned int);
Window (*XCreateSimpleWindow)(Display*, Window, int, int, unsigned int, unsigned int, unsigned int, unsigned long, unsigned long);
VisualID (*XVisualIDFromVisual)(Visual*);
Window (*XRootWindow)(Display*, int);
Status (*XSetWMProtocols)(Display*, Window, Atom*, int);
int (*XSetTransientForHint)(Display*, Window, Window);
Status (*XAllocColor)(Display*, Colormap, XColor*);
int (*XChangeProperty)(Display*, Window, Atom, Atom, int, int, _Xconst unsigned char*, int);
int (*XChangeWindowAttributes)(Display*, Window, unsigned long, XSetWindowAttributes*);
Bool (*XCheckTypedWindowEvent)(Display*, Window, int, XEvent*);
Bool (*XCheckWindowEvent)(Display*, Window, long, XEvent*);
int (*XCloseDisplay)(Display*);
int (*XConfigureWindow)(Display*, Window, unsigned int, XWindowChanges*);
int (*XConvertSelection)(Display*, Atom, Atom, Atom, Window, Time);
int (*XCopyArea)(Display*, Drawable, Drawable, GC, int, int, unsigned int, unsigned int, int, int);
int (*XDefaultScreen)(Display*);
int (*XDefineCursor)(Display*, Window, Cursor);
int (*XDeleteProperty)(Display*, Window, Atom);
int (*XDestroyWindow)(Display*, Window);
int (*XDrawLine)(Display*, Drawable, GC, int, int, int, int);
int (*XFillPolygon)(Display*, Drawable, GC, XPoint*, int, int, int);
int (*XFree)(void*);
int (*XFreeCursor)(Display*, Cursor);
int (*XFreeGC)(Display*, GC);
int (*XFreePixmap)(Display*, Pixmap);
Status (*XGetGeometry)(Display*, Drawable, Window*, int*, int*, unsigned int*, unsigned int*, unsigned int*, unsigned int*);
int (*XGetWindowProperty)(Display*, Window, Atom, long, long, Bool, Atom, Atom*, int*, unsigned long*, unsigned long*, unsigned char**);
Status (*XGetWindowAttributes)(Display*, Window, XWindowAttributes*);
int (*XMapWindow)(Display*, Window);
int (*XNextEvent)(Display*, XEvent*);
int (*XPending)(Display*);
int (*XPutBackEvent)(Display*, XEvent*);
int (*XPutImage)(Display*, Drawable, GC, XImage*, int, int, int, int, unsigned int, unsigned int);
Bool (*XQueryPointer)(Display*, Window, Window*, Window*, int*, int*, int*, int*, unsigned int*);
Status (*XQueryTree)(Display*, Window, Window*, Window*, Window**, unsigned int*);
int (*XReparentWindow)(Display*, Window, Window, int, int);
int (*XSelectInput)(Display*, Window, long);
Status (*XSendEvent)(Display*, Window, Bool, long, XEvent*);
int (*XSetClipMask)(Display*, GC, Pixmap);
int (*XSetClipOrigin)(Display*, GC, int, int);
int (*XSetForeground)(Display*, GC, unsigned long);
int (*XSetGraphicsExposures)(Display*, GC, Bool);
int (*XSetInputFocus)(Display*, Window, int, Time);
int (*XSetWindowBackgroundPixmap)(Display*, Window, Pixmap);
int (*XSync)(Display*, Bool);
Bool (*XTranslateCoordinates)(Display*, Window, Window, int, int, int*, int*, Window*);
int (*XUnmapWindow)(Display*, Window);
int (*XWarpPointer)(Display*, Window, Window, int, int, unsigned int, unsigned int, int, int);
char* (*XSetLocaleModifiers)(const char*);
XIM (*XOpenIM)(Display*, struct _XrmHashBucketRec*, char*, char*);
Status (*XCloseIM)(XIM);
XIC (*XCreateIC)(XIM, ...);
void (*XDestroyIC)(XIC);
void (*XSetICFocus)(XIC);
XSizeHints* (*XAllocSizeHints)(void);
XVisualInfo* (*XGetVisualInfo)(Display*, long, XVisualInfo*, int*);
Status (*XGetWMNormalHints)(Display*, Window, XSizeHints*, long*);
Status (*XGetWMSizeHints)(Display*, Window, XSizeHints*, long*, Atom);
int (*XLookupString)(XKeyEvent*, char*, int, KeySym*, XComposeStatus*);
int (*XSetStandardProperties)(Display*, Window, _Xconst char*, _Xconst char*, Pixmap, char**, int, XSizeHints*);
void (*XSetWMNormalHints)(Display*, Window, XSizeHints*);
void (*XSetWMSizeHints)(Display*, Window, XSizeHints*, Atom);
#if USE_XRENDER
Bool (*XRenderQueryExtension)(Display* dpy, int* event_basep, int* error_basep);
XRenderPictFormat* (*XRenderFindStandardFormat)(Display* dpy, int format);
Picture (*XRenderCreatePicture)(Display* dpy, Drawable drawable,
_Xconst XRenderPictFormat* format,
unsigned long valuemask,
_Xconst XRenderPictureAttributes* attributes);
void (*XRenderFreePicture)(Display* dpy, Picture picture);
void (*XRenderSetPictureTransform)(Display* dpy, Picture picture,
XTransform* transform);
void (*XRenderComposite)(Display* dpy, int op, Picture src, Picture mask,
Picture dst, int src_x, int src_y, int mask_x, int mask_y,
int dst_x, int dst_y, unsigned int width,
unsigned int height);
#endif
} xsymtbl;
#define XClearWindow xsymtbl.XClearWindow
#define XCreateIC xsymtbl.XCreateIC
#define XFree xsymtbl.XFree
#define XFreeCursor xsymtbl.XFreeCursor
#define XConfigureWindow xsymtbl.XConfigureWindow
#define XCheckTypedWindowEvent xsymtbl.XCheckTypedWindowEvent
#define XGetWMNormalHints xsymtbl.XGetWMNormalHints
#define XLookupString xsymtbl.XLookupString
#define XCreateImage xsymtbl.XCreateImage
#define XSetClipMask xsymtbl.XSetClipMask
#define XConvertSelection xsymtbl.XConvertSelection
#define XGetWindowProperty xsymtbl.XGetWindowProperty
#define XSetWMNormalHints xsymtbl.XSetWMNormalHints
#define XTranslateCoordinates xsymtbl.XTranslateCoordinates
#define XCreateSimpleWindow xsymtbl.XCreateSimpleWindow
#define XGetWMSizeHints xsymtbl.XGetWMSizeHints
#define XRootWindow xsymtbl.XRootWindow
#define XOpenDisplay xsymtbl.XOpenDisplay
#define XCopyArea xsymtbl.XCopyArea
#define XDeleteProperty xsymtbl.XDeleteProperty
#define XDrawLine xsymtbl.XDrawLine
#define XSetGraphicsExposures xsymtbl.XSetGraphicsExposures
#define XDestroyWindow xsymtbl.XDestroyWindow
#define XCloseDisplay xsymtbl.XCloseDisplay
#define XSetForeground xsymtbl.XSetForeground
#define XGetGeometry xsymtbl.XGetGeometry
#define XUnmapWindow xsymtbl.XUnmapWindow
#define XSetTransientForHint xsymtbl.XSetTransientForHint
#define XSetWMSizeHints xsymtbl.XSetWMSizeHints
#define XCreatePixmapCursor xsymtbl.XCreatePixmapCursor
#define XFreeGC xsymtbl.XFreeGC
#define XNextEvent xsymtbl.XNextEvent
#define XSetWMProtocols xsymtbl.XSetWMProtocols
#define XDefaultScreen xsymtbl.XDefaultScreen
#define XKeysymToString xsymtbl.XKeysymToString
#define XMapWindow xsymtbl.XMapWindow
#define XPutBackEvent xsymtbl.XPutBackEvent
#define XCreateGC xsymtbl.XCreateGC
#define XSelectInput xsymtbl.XSelectInput
#define XSetInputFocus xsymtbl.XSetInputFocus
#define XDestroyIC xsymtbl.XDestroyIC
#define XSync xsymtbl.XSync
#define XSendEvent xsymtbl.XSendEvent
#define XSetICFocus xsymtbl.XSetICFocus
#define XWarpPointer xsymtbl.XWarpPointer
#define XPutImage xsymtbl.XPutImage
#define XFillPolygon xsymtbl.XFillPolygon
#define XOpenIM xsymtbl.XOpenIM
#define XDefineCursor xsymtbl.XDefineCursor
#define XSetWindowBackgroundPixmap xsymtbl.XSetWindowBackgroundPixmap
#define XAllocColor xsymtbl.XAllocColor
#define XInternAtom xsymtbl.XInternAtom
#define XQueryPointer xsymtbl.XQueryPointer
#define XGetVisualInfo xsymtbl.XGetVisualInfo
#define XVisualIDFromVisual xsymtbl.XVisualIDFromVisual
#define XSetLocaleModifiers xsymtbl.XSetLocaleModifiers
#define XGetWindowAttributes xsymtbl.XGetWindowAttributes
#define XSetStandardProperties xsymtbl.XSetStandardProperties
#define XChangeProperty xsymtbl.XChangeProperty
#define XAllocSizeHints xsymtbl.XAllocSizeHints
#define XCheckWindowEvent xsymtbl.XCheckWindowEvent
#define XFreePixmap xsymtbl.XFreePixmap
#define XReparentWindow xsymtbl.XReparentWindow
#define XCreatePixmap xsymtbl.XCreatePixmap
#define XSetClipOrigin xsymtbl.XSetClipOrigin
#define XCloseIM xsymtbl.XCloseIM
#define XQueryTree xsymtbl.XQueryTree
#define XPending xsymtbl.XPending
#define XChangeWindowAttributes xsymtbl.XChangeWindowAttributes
#if USE_XRENDER
#define XRenderFindStandardFormat xsymtbl.XRenderFindStandardFormat
#define XRenderCreatePicture xsymtbl.XRenderCreatePicture
#define XRenderFreePicture xsymtbl.XRenderFreePicture
#define XRenderComposite xsymtbl.XRenderComposite
#define XRenderQueryExtension xsymtbl.XRenderQueryExtension
#define XRenderSetPictureTransform xsymtbl.XRenderSetPictureTransform
#endif
typedef struct mwm_hints {
unsigned long flags;
unsigned long functions;
@ -9,10 +193,10 @@ typedef struct mwm_hints {
long input_mode;
unsigned long status;
} mwm_hints_t;
enum mwm_hints_enum {
MWM_HINTS_FUNCTIONS = (1L << 0),
MWM_HINTS_DECORATIONS = (1L << 1),
MWM_FUNC_ALL = (1L << 0),
MWM_FUNC_RESIZE = (1L << 1),
MWM_FUNC_MOVE = (1L << 2),
@ -129,6 +313,18 @@ static XVisualInfo* get_visual_info(Display* display) {
return XGetVisualInfo(display, VisualIDMask, &xvi, &n);
}
#ifdef USE_DBUS
static void detect_dark_theme(MwLL handle) {
MwU32 value = 0;
MwU32 dark_theme = 0;
MwLLDBusPortalGet(&xsymtbl.dbus, &handle->x11.dbus, "org.freedesktop.portal.Settings", "org.freedesktop.appearance", "color-scheme", &value);
dark_theme = (value == 1) ? 1 : 0;
MwLLDispatch(handle, dark_theme, &dark_theme);
}
#endif
static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
MwLL r;
Window p;
@ -159,6 +355,7 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
r->x11.toplevel = 0;
}
r->x11.window = XCreateSimpleWindow(r->x11.display, p, px, py, width, height, 0, 0, WhitePixel(r->x11.display, DefaultScreen(r->x11.display)));
sh.flags = PWinGravity;
sh.win_gravity = StaticGravity;
XSetWMNormalHints(r->x11.display, r->x11.window, &sh);
@ -187,6 +384,7 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
XFree(xvi);
#ifdef DO_XIM
XSetLocaleModifiers("");
if((r->x11.xim = XOpenIM(r->x11.display, 0, 0, 0)) == NULL) {
XSetLocaleModifiers("@im=none");
@ -199,6 +397,7 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
XNFocusWindow, r->x11.window,
NULL);
XSetICFocus(r->x11.xic);
#endif
r->common.copy_buffer = 1;
r->common.type = MwLLBackendX11;
@ -211,8 +410,17 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
r->x11.colormap = DefaultColormap(r->x11.display, XDefaultScreen(r->x11.display));
r->x11.wm_delete = XInternAtom(r->x11.display, "WM_DELETE_WINDOW", False);
r->x11.wm_protocols = XInternAtom(r->x11.display, "WM_PROTOCOLS", False);
XSetWMProtocols(r->x11.display, r->x11.window, &r->x11.wm_delete, 1);
r->x11.utf8_string = XInternAtom(r->x11.display, "UTF8_STRING", False);
r->x11.compound_text = XInternAtom(r->x11.display, "COMPOUND_TEXT", False);
r->x11.text = XInternAtom(r->x11.display, "TEXT", False);
r->x11.clipboard = XInternAtom(r->x11.display, "CLIPBOARD", False);
r->x11.selection = XInternAtom(r->x11.display, "_MILSKO_SELECTION_", False);
r->x11.clipboard_pending = 0;
r->x11.gc = XCreateGC(r->x11.display, r->x11.window, 0, NULL);
create_pixmap(r);
@ -238,14 +446,24 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
}
}
#ifdef USE_DBUS
memset(&r->x11.dbus, 0, sizeof(r->x11.dbus));
if(!parent && xsymtbl.has_dbus) {
xsymtbl.has_dbus = MwLLDBusNewContext(&xsymtbl.dbus, &r->x11.dbus);
r->x11.dark_theme_detection = MwTRUE;
}
#endif
return r;
}
static void MwLLDestroyImpl(MwLL handle) {
MwLLDestroyCommon(handle);
#ifdef DO_XIM
if(handle->x11.xic) XDestroyIC(handle->x11.xic);
if(handle->x11.xim) XCloseIM(handle->x11.xim);
#endif
destroy_pixmap(handle);
XFreeGC(handle->x11.display, handle->x11.gc);
@ -256,6 +474,12 @@ static void MwLLDestroyImpl(MwLL handle) {
if(handle->x11.toplevel) XCloseDisplay(handle->x11.display);
#ifdef USE_DBUS
if(!xsymtbl.has_dbus) {
MwLLDBusFreeContext(&xsymtbl.dbus, &handle->x11.dbus);
}
#endif
free(handle);
}
@ -265,6 +489,8 @@ static void MwLLBeginDrawImpl(MwLL handle) {
static void MwLLEndDrawImpl(MwLL handle) {
(void)handle;
XClearWindow(handle->x11.display, handle->x11.window);
}
static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLLColor color) {
@ -411,7 +637,22 @@ static void MwLLFreeColorImpl(MwLLColor color) {
static int MwLLPendingImpl(MwLL handle) {
XEvent ev;
if(XCheckTypedWindowEvent(handle->x11.display, handle->x11.window, ClientMessage, &ev) || XCheckWindowEvent(handle->x11.display, handle->x11.window, mask, &ev)) {
if(handle->x11.dark_theme_detection) {
handle->x11.dark_theme_detection = MwFALSE;
#ifdef USE_DBUS
if(xsymtbl.has_dbus) {
detect_dark_theme(handle);
MwLLDispatch(handle, draw, NULL);
}
#endif
}
if(handle->x11.clipboard_pending && (MwTimeGetTick() - handle->x11.clipboard_time) >= ClipboardTimeout) {
return 1;
}
if(XCheckTypedWindowEvent(handle->x11.display, handle->x11.window, ClientMessage, &ev) || XCheckTypedWindowEvent(handle->x11.display, handle->x11.window, SelectionNotify, &ev) || XCheckWindowEvent(handle->x11.display, handle->x11.window, mask, &ev)) {
XPutBackEvent(handle->x11.display, &ev);
return 1;
}
@ -420,44 +661,71 @@ static int MwLLPendingImpl(MwLL handle) {
static void MwLLNextEventImpl(MwLL handle) {
XEvent ev;
while(XCheckTypedWindowEvent(handle->x11.display, handle->x11.window, ClientMessage, &ev) || XCheckWindowEvent(handle->x11.display, handle->x11.window, mask, &ev)) {
if(handle->x11.clipboard_pending && (MwTimeGetTick() - handle->x11.clipboard_time) >= ClipboardTimeout) {
Atom a = handle->x11.selection;
handle->x11.clipboard_pending++;
handle->x11.clipboard_time = MwTimeGetTick();
switch(handle->x11.clipboard_pending) {
case 2:
a = handle->x11.compound_text;
break;
case 3:
a = handle->x11.text;
break;
case 4:
a = XA_STRING;
break;
case 5:
handle->x11.clipboard_pending = 0;
break;
}
if(a != handle->x11.selection) {
XConvertSelection(handle->x11.display, handle->x11.clipboard, a, handle->x11.selection, handle->x11.window, CurrentTime);
}
}
while(XCheckTypedWindowEvent(handle->x11.display, handle->x11.window, ClientMessage, &ev) || XCheckTypedWindowEvent(handle->x11.display, handle->x11.window, SelectionNotify, &ev) || XCheckWindowEvent(handle->x11.display, handle->x11.window, mask, &ev)) {
int render = 0;
if(ev.type == Expose) {
handle->x11.force_render = 0;
render = 1;
} else if(ev.type == ButtonPress) {
MwLLMouse p;
MwMouse p;
p.point.x = ev.xbutton.x;
p.point.y = ev.xbutton.y;
if(ev.xbutton.button == Button1) {
p.button = MwLLMouseLeft;
p.button = MwMOUSE_LEFT;
} else if(ev.xbutton.button == Button2) {
p.button = MwLLMouseMiddle;
p.button = MwMOUSE_MIDDLE;
} else if(ev.xbutton.button == Button3) {
p.button = MwLLMouseRight;
p.button = MwMOUSE_RIGHT;
} else if(ev.xbutton.button == Button4) {
p.button = MwLLMouseWheelUp;
p.button = MwMOUSE_WHEELUP;
} else if(ev.xbutton.button == Button5) {
p.button = MwLLMouseWheelDown;
p.button = MwMOUSE_WHEELDOWN;
}
XSetInputFocus(handle->x11.display, handle->x11.window, RevertToNone, CurrentTime);
MwLLDispatch(handle, down, &p);
} else if(ev.type == ButtonRelease) {
MwLLMouse p;
MwMouse p;
p.point.x = ev.xbutton.x;
p.point.y = ev.xbutton.y;
if(ev.xbutton.button == Button1) {
p.button = MwLLMouseLeft;
p.button = MwMOUSE_LEFT;
} else if(ev.xbutton.button == Button2) {
p.button = MwLLMouseMiddle;
p.button = MwMOUSE_MIDDLE;
} else if(ev.xbutton.button == Button3) {
p.button = MwLLMouseRight;
p.button = MwMOUSE_RIGHT;
} else if(ev.xbutton.button == Button4) {
p.button = MwLLMouseWheelUp;
p.button = MwMOUSE_WHEELUP;
} else if(ev.xbutton.button == Button5) {
p.button = MwLLMouseWheelDown;
p.button = MwMOUSE_WHEELDOWN;
}
MwLLDispatch(handle, up, &p);
@ -471,7 +739,7 @@ static void MwLLNextEventImpl(MwLL handle) {
handle->x11.width = ev.xconfigure.width;
handle->x11.height = ev.xconfigure.height;
} else if(ev.type == ClientMessage) {
if(ev.xclient.data.l[0] == (long)handle->x11.wm_delete) {
if(ev.xclient.message_type == handle->x11.wm_protocols && ev.xclient.data.l[0] == (long)handle->x11.wm_delete) {
MwLLDispatch(handle, close, NULL);
}
} else if(ev.type == FocusIn) {
@ -512,8 +780,7 @@ static void MwLLNextEventImpl(MwLL handle) {
strcpy(str, s);
}
/* HACK: this is bad, you can guess why */
if(strlen(str) == 1) {
if(MwStringIsKeyUTF8(sym)) {
char s = str[0];
if(ev.xkey.state & (ShiftMask | LockMask) && !(ev.xkey.state & (ControlMask | Mod1Mask))) {
@ -559,6 +826,49 @@ static void MwLLNextEventImpl(MwLL handle) {
MwLLDispatch(handle, key_released, &n);
}
}
} else if(ev.type == SelectionNotify) {
handle->x11.clipboard_pending = 0;
if(ev.xselection.property != None) {
Atom type;
int format;
unsigned long nitems, after, size;
unsigned char* pdat;
int ret = XGetWindowProperty(handle->x11.display, handle->x11.window, handle->x11.selection, 0, 0, False, AnyPropertyType, &type, &format, &nitems, &after, &pdat);
if(pdat != NULL) XFree(pdat);
size = after;
if(ret == Success && type != None && format == 8) {
char* buf = malloc(size + 1);
int offset;
for(offset = 0; after > 0; offset += nitems) {
ret = XGetWindowProperty(handle->x11.display, handle->x11.window, handle->x11.selection, offset / 4, after / 4 + 1, False, AnyPropertyType, &type, &format, &nitems, &after, &pdat);
if(ret != Success) {
free(buf);
buf = NULL;
break;
}
memcpy(buf + offset, pdat, nitems);
XFree(pdat);
}
if(buf != NULL) {
buf[size] = 0;
MwLLDispatch(handle, clipboard, buf);
free(buf);
}
}
XDeleteProperty(handle->x11.display, handle->x11.window, handle->x11.selection);
}
}
if(render) {
int x, y;
@ -598,7 +908,9 @@ static MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, int wid
r->x11.handle = handle;
#ifdef USE_XRENDER
if(xsymtbl.has_xrender) {
r->x11.use_xrender = XRenderQueryExtension(handle->x11.display, &evbase, &erbase) ? 1 : 0;
}
#endif
r->x11.image = XCreateImage(handle->x11.display, DefaultVisual(handle->x11.display, DefaultScreen(handle->x11.display)), r->x11.depth, ZPixmap, 0, NULL, width, height, 32, 0);
@ -649,7 +961,7 @@ static void MwLLDestroyPixmapImpl(MwLLPixmap pixmap) {
}
static void MwLLDrawPixmapImpl(MwLL handle, MwRect* rect, MwLLPixmap pixmap) {
if(rect->width == 0 || rect->height == 0 || pixmap->common.width == 0 || pixmap->common.height == 0) return;
if(rect->width <= 0 || rect->height <= 0 || pixmap->common.width <= 0 || pixmap->common.height <= 0) return;
#ifdef USE_XRENDER
if(pixmap->x11.image != NULL && pixmap->x11.use_xrender) {
Pixmap px = XCreatePixmap(handle->x11.display, handle->x11.window, pixmap->common.width, pixmap->common.height, pixmap->x11.depth);
@ -807,8 +1119,8 @@ Cursor MwLLX11CreateCursor(Display* display, MwCursor* image, MwCursor* mask) {
XColor cfg, cbg;
xs = -mask->x + image->x;
ys = MwCursorDataHeight + mask->y;
ys = MwCursorDataHeight + image->y - ys;
ys = mask->height + mask->y;
ys = image->height + image->y - ys;
memset(cimage->data, 0, cimage->bytes_per_line * cimage->height);
memset(cmask->data, 0, cmask->bytes_per_line * cmask->height);
@ -845,7 +1157,7 @@ Cursor MwLLX11CreateCursor(Display* display, MwCursor* image, MwCursor* mask) {
XPutImage(display, pimage, imagegc, cimage, 0, 0, 0, 0, MwCursorDataHeight, MwCursorDataHeight);
XPutImage(display, pmask, maskgc, cmask, 0, 0, 0, 0, MwCursorDataHeight, MwCursorDataHeight);
cur = XCreatePixmapCursor(display, pimage, pmask, &cfg, &cbg, xs, ys);
cur = XCreatePixmapCursor(display, pimage, pmask, &cfg, &cbg, xs - image->x, ys + (MwCursorDataHeight + image->y));
XFreePixmap(display, pimage);
XFreePixmap(display, pmask);
@ -949,52 +1261,23 @@ static void MwLLGrabPointerImpl(MwLL handle, int toggle) {
}
}
static void MwLLSetClipboardImpl(MwLL handle, const char* text) {
static void MwLLSetClipboardImpl(MwLL handle, const char* text, int clipboard_type) {
/* TODO */
(void)handle;
(void)text;
(void)clipboard_type;
}
static char* MwLLGetClipboardImpl(MwLL handle) {
Atom clip, target, prop;
XEvent ev;
XEvent* queue = NULL;
char* r = NULL;
static void MwLLGetClipboardImpl(MwLL handle, int clipboard_type) {
(void)clipboard_type;
clip = XInternAtom(handle->x11.display, "CLIPBOARD", 0);
target = XA_STRING;
prop = XInternAtom(handle->x11.display, "XSEL_DATA", 0);
if(handle->x11.clipboard_pending) return;
XConvertSelection(handle->x11.display, clip, target, prop, handle->x11.window, CurrentTime);
XConvertSelection(handle->x11.display, handle->x11.clipboard, handle->x11.utf8_string, handle->x11.selection, handle->x11.window, CurrentTime);
while(1) {
XNextEvent(handle->x11.display, &ev);
if(ev.type == SelectionNotify) {
if(ev.xselection.selection == clip && ev.xselection.property != 0) {
Atom t;
unsigned long size, N;
char* data;
int format;
XGetWindowProperty(ev.xselection.display, ev.xselection.requestor, ev.xselection.property, 0, (~0L), 0, AnyPropertyType, &t, &format, &size, &N, (unsigned char**)&data);
if(t == target) {
r = MwStringDuplicate(data);
XFree(data);
}
XDeleteProperty(ev.xselection.display, ev.xselection.requestor, ev.xselection.property);
}
break;
}
}
while(arrlen(queue) > 0) {
XPutBackEvent(handle->x11.display, &queue[0]);
arrdel(queue, 0);
}
arrfree(queue);
return r;
handle->x11.clipboard_pending = 1;
handle->x11.clipboard_time = MwTimeGetTick();
}
static void MwLLMakeToolWindowImpl(MwLL handle) {
@ -1036,7 +1319,128 @@ static void MwLLEndStateChangeImpl(MwLL handle) {
MwLLShow(handle, 1);
}
static void MwLLSetDarkThemeImpl(MwLL handle, int toggle) {
(void)handle;
(void)toggle;
}
static int MwLLX11CallInitImpl(void) {
MwBool loadX11 = MwFALSE;
if(getenv("MILSKO_BACKEND")) {
loadX11 |=
(strcmp(getenv("MILSKO_BACKEND"), "x11") == 0);
} else if(getenv("DISPLAY")) {
loadX11 |= (getenv("DISPLAY") != NULL);
}
if(!loadX11) {
return 1;
}
#ifdef __APPLE__
xsymtbl.lib_xlib = MwDynamicOpen("libX11.dylib");
#else
xsymtbl.lib_xlib = MwDynamicOpen("libX11.so");
#endif
if(!xsymtbl.lib_xlib) {
return 1;
}
xsymtbl.has_xrender = MwFALSE;
#if USE_XRENDER
xsymtbl.lib_xrender = MwDynamicOpen("libXrender.so");
if(xsymtbl.lib_xrender) {
xsymtbl.has_xrender = MwTRUE;
}
#endif
#define X11_FUNC_LOAD(x) x = MwDynamicSymbol(xsymtbl.lib_xlib, #x)
X11_FUNC_LOAD(XClearWindow);
X11_FUNC_LOAD(XCreateImage);
X11_FUNC_LOAD(XOpenDisplay);
X11_FUNC_LOAD(XKeysymToString);
X11_FUNC_LOAD(XInternAtom);
X11_FUNC_LOAD(XCreatePixmapCursor);
X11_FUNC_LOAD(XCreateGC);
X11_FUNC_LOAD(XCreatePixmap);
X11_FUNC_LOAD(XCreateSimpleWindow);
X11_FUNC_LOAD(XVisualIDFromVisual);
X11_FUNC_LOAD(XRootWindow);
X11_FUNC_LOAD(XSetWMProtocols);
X11_FUNC_LOAD(XSetTransientForHint);
X11_FUNC_LOAD(XAllocColor);
X11_FUNC_LOAD(XChangeProperty);
X11_FUNC_LOAD(XChangeWindowAttributes);
X11_FUNC_LOAD(XCheckTypedWindowEvent);
X11_FUNC_LOAD(XCheckWindowEvent);
X11_FUNC_LOAD(XCloseDisplay);
X11_FUNC_LOAD(XConfigureWindow);
X11_FUNC_LOAD(XConvertSelection);
X11_FUNC_LOAD(XCopyArea);
X11_FUNC_LOAD(XDefaultScreen);
X11_FUNC_LOAD(XDefineCursor);
X11_FUNC_LOAD(XDeleteProperty);
X11_FUNC_LOAD(XDestroyWindow);
X11_FUNC_LOAD(XDrawLine);
X11_FUNC_LOAD(XFillPolygon);
X11_FUNC_LOAD(XFree);
X11_FUNC_LOAD(XFreeCursor);
X11_FUNC_LOAD(XFreeGC);
X11_FUNC_LOAD(XFreePixmap);
X11_FUNC_LOAD(XGetGeometry);
X11_FUNC_LOAD(XGetWindowProperty);
X11_FUNC_LOAD(XGetWindowAttributes);
X11_FUNC_LOAD(XMapWindow);
X11_FUNC_LOAD(XNextEvent);
X11_FUNC_LOAD(XPending);
X11_FUNC_LOAD(XPutBackEvent);
X11_FUNC_LOAD(XPutImage);
X11_FUNC_LOAD(XQueryPointer);
X11_FUNC_LOAD(XQueryTree);
X11_FUNC_LOAD(XReparentWindow);
X11_FUNC_LOAD(XSelectInput);
X11_FUNC_LOAD(XSendEvent);
X11_FUNC_LOAD(XSetClipMask);
X11_FUNC_LOAD(XSetClipOrigin);
X11_FUNC_LOAD(XSetForeground);
X11_FUNC_LOAD(XSetGraphicsExposures);
X11_FUNC_LOAD(XSetInputFocus);
X11_FUNC_LOAD(XSetWindowBackgroundPixmap);
X11_FUNC_LOAD(XSync);
X11_FUNC_LOAD(XTranslateCoordinates);
X11_FUNC_LOAD(XUnmapWindow);
X11_FUNC_LOAD(XWarpPointer);
X11_FUNC_LOAD(XSetLocaleModifiers);
X11_FUNC_LOAD(XOpenIM);
X11_FUNC_LOAD(XCloseIM);
X11_FUNC_LOAD(XCreateIC);
X11_FUNC_LOAD(XDestroyIC);
X11_FUNC_LOAD(XSetICFocus);
X11_FUNC_LOAD(XAllocSizeHints);
X11_FUNC_LOAD(XGetVisualInfo);
X11_FUNC_LOAD(XGetWMNormalHints);
X11_FUNC_LOAD(XGetWMSizeHints);
X11_FUNC_LOAD(XLookupString);
X11_FUNC_LOAD(XSetStandardProperties);
X11_FUNC_LOAD(XSetWMNormalHints);
X11_FUNC_LOAD(XSetWMSizeHints);
#if USE_XRENDER
#define XRENDER_FUNC_LOAD(x) x = MwDynamicSymbol(xsymtbl.lib_xrender, #x);
XRENDER_FUNC_LOAD(XRenderQueryExtension)
XRENDER_FUNC_LOAD(XRenderFindStandardFormat)
XRENDER_FUNC_LOAD(XRenderCreatePicture)
XRENDER_FUNC_LOAD(XRenderFreePicture)
XRENDER_FUNC_LOAD(XRenderSetPictureTransform)
XRENDER_FUNC_LOAD(XRenderComposite)
#endif
#ifdef USE_DBUS
xsymtbl.has_dbus = MwLLDBusFuncSetup(&xsymtbl.dbus);
#endif
return 0;
}

View file

@ -2,37 +2,73 @@
#include "../external/stb_ds.h"
#ifdef USE_COCOA
#define PERIODIC
#endif
#define DRAW(handle) \
{ \
MwLLBeginDraw(handle->lowlevel); \
\
handle->bgcolor = NULL; \
MwDispatch(handle, draw); \
if(handle->draw_inject != NULL) handle->draw_inject(handle); \
MwDispatchUserHandler(handle, MwNdrawHandler, NULL); \
\
MwLLEndDraw(handle->lowlevel); \
}
static void lldrawhandler(MwLL handle, void* data) {
MwWidget h = (MwWidget)handle->common.user;
#ifdef PERIODIC
MwWidget top;
#endif
(void)data;
MwLLBeginDraw(handle);
h->bgcolor = NULL;
MwDispatch(h, draw);
if(h->draw_inject != NULL) h->draw_inject(h);
MwDispatchUserHandler(h, MwNdrawHandler, NULL);
#ifdef PERIODIC
top = h;
while(top != NULL) {
if(top->top_step) {
break;
}
MwLLEndDraw(handle);
top = top->parent;
}
if(top == NULL) {
DRAW(h); /* fallback */
} else {
int i;
for(i = 0; i < arrlen(top->draw_queue); i++) {
if(top->draw_queue[i] == h) break;
}
if(i == arrlen(top->draw_queue)) arrput(top->draw_queue, h);
}
#else
DRAW(h);
#endif
}
static void lluphandler(MwLL handle, void* data) {
MwWidget h = (MwWidget)handle->common.user;
MwLLMouse* p = data;
MwMouse* p = data;
if(p->button == MwLLMouseLeft) h->pressed = 0;
if(p->button == MwMOUSE_LEFT) h->pressed = 0;
h->mouse_point.x = p->point.x;
h->mouse_point.y = p->point.y;
if(p->button == MwLLMouseLeft) MwDispatch(h, click);
if(p->button == MwMOUSE_LEFT) MwDispatch(h, click);
MwDispatch3(h, mouse_up, data);
MwDispatchUserHandler(h, MwNmouseUpHandler, data);
}
static void lldownhandler(MwLL handle, void* data) {
MwWidget h = (MwWidget)handle->common.user;
MwLLMouse* p = data;
if(p->button == MwLLMouseLeft) h->pressed = 1;
MwMouse* p = data;
if(p->button == MwMOUSE_LEFT) h->pressed = 1;
h->mouse_point.x = p->point.x;
h->mouse_point.y = p->point.y;
@ -49,6 +85,7 @@ static void llresizehandler(MwLL handle, void* data) {
MwDispatchUserHandler(h, MwNresizeHandler, NULL);
for(i = 0; i < arrlen(h->children); i++) {
MwDispatch(h->children[i], parent_resize);
MwDispatch(h->children[i], draw);
}
MwDispatch(h, resize);
}
@ -107,6 +144,39 @@ static void llfocusouthandler(MwLL handle, void* data) {
MwDispatchUserHandler(h, MwNfocusOutHandler, data);
}
static void llclipboardhandler(MwLL handle, void* data) {
MwWidget h = (MwWidget)handle->common.user;
MwDispatch3(h, clipboard, data);
MwDispatchUserHandler(h, MwNclipboardHandler, data);
}
/* if both of them are true
* 1. widget class is not NULL
* 2. parent is NULL
* or parent's widget class is NULL
*
* most likely this widget is first *visible* widget
*
* this macro is not used anywhere else - we could expose it if we have to
*
* (nishi)
*/
#define IsFirstVisible(handle) ((handle)->widget_class != NULL && ((handle)->parent == NULL || (handle)->parent->widget_class == NULL))
static void lldarkthemehandler(MwLL handle, void* data) {
MwWidget h = (MwWidget)handle->common.user;
int* ptr = data;
if(IsFirstVisible(h)) {
MwVaApply(h,
MwNdarkTheme, *ptr,
NULL);
MwDispatchUserHandler(h, MwNdarkThemeHandler, data);
}
}
MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent, int x, int y, unsigned int width, unsigned int height) {
MwWidget h = malloc(sizeof(*h));
@ -114,6 +184,7 @@ MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent,
h->parent = parent;
h->children = NULL;
if(widget_class != NULL) {
if((h->lowlevel = MwLLCreate(parent == NULL ? NULL : parent->lowlevel, x, y, width, height)) == NULL) {
free(h->name);
@ -131,11 +202,18 @@ MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent,
h->draw_inject = NULL;
h->tick_list = NULL;
h->destroyed = 0;
h->dark_theme = 0;
h->bgcolor = NULL;
h->berserk = 0;
h->top_step = 0;
h->draw_queue = NULL;
if(parent == NULL) arrput(h->tick_list, h);
#ifdef PERIODIC
if(parent == NULL) h->top_step = 1;
#endif
if(h->lowlevel != NULL) {
h->lowlevel->common.user = h;
h->lowlevel->common.handler->draw = lldrawhandler;
@ -148,6 +226,8 @@ MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent,
h->lowlevel->common.handler->key_released = llkeyrelhandler;
h->lowlevel->common.handler->focus_in = llfocusinhandler;
h->lowlevel->common.handler->focus_out = llfocusouthandler;
h->lowlevel->common.handler->clipboard = llclipboardhandler;
h->lowlevel->common.handler->dark_theme = lldarkthemehandler;
}
if(parent != NULL) arrput(parent->children, h);
@ -177,6 +257,19 @@ MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent,
MwAddTickList(h);
}
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2)
if(IsFirstVisible(h)) {
h->root_font = MwFontLoad(MwTTFData, MwTTFDataSize);
h->root_boldfont = MwFontLoad(MwBoldTTFData, MwBoldTTFDataSize);
h->root_monofont = MwFontLoad(MwMonospaceTTFData, MwMonospaceTTFDataSize);
h->root_boldmonofont = MwFontLoad(MwBoldMonospaceTTFData, MwBoldMonospaceTTFDataSize);
} else
#endif
{
h->root_font = NULL;
h->root_boldfont = NULL;
}
if(h->parent != NULL) MwDispatch(h->parent, children_update);
return h;
@ -205,6 +298,22 @@ MwWidget MwVaListCreateWidget(MwClass widget_class, const char* name, MwWidget p
static void MwFreeWidget(MwWidget handle) {
int i;
MwWidget root = handle;
MwWidget w;
w = handle;
while(w != NULL) {
if(w->top_step) break;
w = w->parent;
}
if(w != NULL) {
for(i = 0; i < arrlen(w->draw_queue); i++) {
if(w->draw_queue[i] == handle) {
arrdel(w->draw_queue, i);
i--;
}
}
}
handle->destroyed = 0;
MwDispatch(handle, destroy);
@ -241,6 +350,11 @@ static void MwFreeWidget(MwWidget handle) {
arrfree(handle->destroy_queue);
arrfree(handle->tick_list);
arrfree(handle->draw_queue);
if(handle->root_font != NULL) MwFontFree(handle->root_font);
if(handle->root_boldfont != NULL) MwFontFree(handle->root_boldfont);
free(handle);
}
@ -261,6 +375,8 @@ void MwDestroyWidget(MwWidget handle) {
if(i == arrlen(handle->parent->destroy_queue)) {
arrput(handle->parent->destroy_queue, handle);
}
MwDispatch(handle->parent, children_update);
}
destroy_children(handle);
handle->destroyed = 1;
@ -297,6 +413,22 @@ static void clean_destroy_queue(MwWidget handle) {
arrfree(handle->destroy_queue);
}
static void MwAfterStep(MwWidget handle) {
#ifdef PERIODIC
if(handle->top_step) {
int i;
for(i = 0; i < arrlen(handle->draw_queue); i++) {
DRAW(handle->draw_queue[i]);
}
arrfree(handle->draw_queue);
}
#else
(void)handle;
#endif
}
int MwStep(MwWidget handle) {
int i;
MwWidget* widgets = NULL;
@ -310,11 +442,13 @@ int MwStep(MwWidget handle) {
handle->prop_event = 0;
if(handle->lowlevel != NULL && MwLLPending(handle->lowlevel))
while(handle->lowlevel != NULL && MwLLPending(handle->lowlevel))
MwLLNextEvent(handle->lowlevel);
handle->prop_event = 1;
if(handle->top_step) MwAfterStep(handle);
clean_destroy_queue(handle);
if(handle->parent == NULL && handle->destroyed) {
MwFreeWidget(handle);
@ -328,7 +462,7 @@ int MwPending(MwWidget handle) {
for(i = 0; i < arrlen(handle->children); i++) {
if(MwPending(handle->children[i])) return 1;
}
return (arrlen(handle->destroy_queue) > 0 ? 1 : 0) || (handle->widget_class == NULL ? 0 : MwLLPending(handle->lowlevel));
return (arrlen(handle->destroy_queue) > 0) || (handle->widget_class == NULL ? 0 : MwLLPending(handle->lowlevel));
}
void MwLoop(MwWidget handle) {
@ -354,7 +488,7 @@ void MwLoop(MwWidget handle) {
more = over % (wait / 2);
t = (tick + wait - more) - (t2 = MwTimeGetTick());
if(t > 0) {
MwTimeSleep(t);
if(!handle->berserk) MwTimeSleep(t);
tick = MwTimeGetTick();
over -= more;
} else {
@ -364,6 +498,14 @@ void MwLoop(MwWidget handle) {
}
}
static void force_render_all(MwWidget handle) {
int i;
for(i = 0; i < arrlen(handle->children); i++) {
force_render_all(handle->children[i]);
}
if(handle->lowlevel != NULL) MwForceRender(handle);
}
void MwSetInteger(MwWidget handle, const char* key, int n) {
int xy;
int wh = 0;
@ -385,6 +527,20 @@ void MwSetInteger(MwWidget handle, const char* key, int n) {
MwDispatch3(handle, prop_change, key);
if(handle->parent != NULL) MwDispatch4(handle->parent, children_prop_change, handle, key);
}
if(strcmp(key, MwNforceInverted) == 0) {
MwForceRender(handle);
}
if(strcmp(key, MwNmodernLook) == 0 || strcmp(key, MwNdarkTheme) == 0 || strcmp(key, MwNbitmapFont) == 0) {
force_render_all(handle);
}
if(strcmp(key, MwNdarkTheme) == 0) {
MwWidget h = handle;
while(h->parent != NULL && h->parent->widget_class != NULL) h = h->parent;
MwLLSetDarkTheme(h->lowlevel, n);
}
}
void MwSetText(MwWidget handle, const char* key, const char* value) {
@ -428,6 +584,15 @@ void MwSetVoid(MwWidget handle, const char* key, void* value) {
}
}
static int inherit_integer(MwWidget handle, const char* key, int default_v) {
int v;
if(handle->parent != NULL && (v = MwGetInteger(handle->parent, key)) != MwDEFAULT) {
return v;
}
return default_v;
}
int MwGetInteger(MwWidget handle, const char* key) {
if(strcmp(key, MwNx) == 0 || strcmp(key, MwNy) == 0 || strcmp(key, MwNwidth) == 0 || strcmp(key, MwNheight) == 0) {
int x, y;
@ -441,6 +606,20 @@ int MwGetInteger(MwWidget handle, const char* key) {
if(strcmp(key, MwNheight) == 0) return h;
return MwDEFAULT;
} else {
if(shgeti(handle->integer, key) == -1) {
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2)
if(strcmp(key, MwNbitmapFont) == 0) return inherit_integer(handle, key, 0);
#else
if(strcmp(key, MwNbitmapFont) == 0) return inherit_integer(handle, key, 1);
#endif
#ifdef USE_CLASSIC_THEME
if(strcmp(key, MwNmodernLook) == 0) return inherit_integer(handle, key, 0);
#else
if(strcmp(key, MwNmodernLook) == 0) return inherit_integer(handle, key, 1);
#endif
if(strcmp(key, MwNdarkTheme) == 0) return inherit_integer(handle, key, 0);
if(strcmp(key, MwNuseMonospace) == 0) return inherit_integer(handle, key, 0);
}
return shget(handle->integer, key);
}
}
@ -454,7 +633,7 @@ const char* MwGetText(MwWidget handle, const char* key) {
h = h->parent;
}
if(v == NULL) {
if(handle->dark_theme) {
if(MwGetInteger(handle, MwNdarkTheme)) {
if(strcmp(key, MwNbackground) == 0) return MwDefaultDarkBackground;
if(strcmp(key, MwNforeground) == 0) return MwDefaultDarkForeground;
if(strcmp(key, MwNsubBackground) == 0) return MwDefaultDarkSubBackground;
@ -472,8 +651,47 @@ const char* MwGetText(MwWidget handle, const char* key) {
return shget(handle->text, key);
}
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2)
static void* inherit_void(MwWidget handle, const char* key) {
void* v;
if(handle->parent != NULL && (v = MwGetVoid(handle->parent, key)) != NULL) {
return v;
}
return NULL;
}
#endif
void* MwGetVoid(MwWidget handle, const char* key) {
return shget(handle->data, key);
void* v = shget(handle->data, key);
if(v != NULL) return v;
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2)
if(strcmp(key, MwNfont) == 0 || strcmp(key, MwNboldFont) == 0 || strcmp(key, MwNmonospaceFont) == 0 || strcmp(key, MwNboldMonospaceFont) == 0) {
v = inherit_void(handle, key);
if(v == NULL) {
MwWidget w = handle;
while(w != NULL && v == NULL) {
if(strcmp(key, MwNfont) == 0) {
v = w->root_font;
} else if(strcmp(key, MwNboldFont) == 0) {
v = w->root_boldfont;
} else if(strcmp(key, MwNmonospaceFont) == 0) {
v = w->root_monofont;
} else if(strcmp(key, MwNboldMonospaceFont) == 0) {
v = w->root_boldmonofont;
}
w = w->parent;
}
}
}
#endif
return v;
}
void MwVaApply(MwWidget handle, ...) {
@ -541,61 +759,8 @@ void MwVaListApply(MwWidget handle, va_list va) {
}
}
static void inherit_integer(MwWidget handle, const char* key, int default_value) {
int n;
MwWidget h = handle;
while(h != NULL) {
if((n = MwGetInteger(h, key)) != MwDEFAULT) {
MwSetInteger(handle, key, n);
return;
}
h = h->parent;
}
MwSetInteger(handle, key, default_value);
}
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2)
static void set_font(MwWidget handle) {
void* f;
MwWidget h = handle;
while(h != NULL) {
if((f = MwGetVoid(h, MwNfont)) != NULL) {
MwSetVoid(handle, MwNfont, f);
return;
}
h = h->parent;
}
f = MwFontLoad(MwTTFData, MwTTFDataSize);
MwSetVoid(handle, MwNfont, f);
}
static void set_boldfont(MwWidget handle) {
void* f;
MwWidget h = handle;
while(h != NULL) {
if((f = MwGetVoid(h, MwNboldFont)) != NULL) {
MwSetVoid(handle, MwNboldFont, f);
return;
}
h = h->parent;
}
f = MwFontLoad(MwBoldTTFData, MwBoldTTFDataSize);
MwSetVoid(handle, MwNboldFont, f);
}
#endif
void MwSetDefault(MwWidget handle) {
if(handle->lowlevel != NULL) MwLLSetCursor(handle->lowlevel, &MwCursorDefault, &MwCursorDefaultMask);
#ifdef USE_CLASSIC_THEME
inherit_integer(handle, MwNmodernLook, 0);
#else
inherit_integer(handle, MwNmodernLook, 1);
#endif
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2)
set_font(handle);
set_boldfont(handle);
#endif
}
void MwHideCursor(MwWidget handle) {
@ -649,7 +814,7 @@ void MwDispatchError(int code, const char* message) {
} else {
#ifdef _WIN32
char buffer[1024];
sprintf(buffer, "Error: %s\r\nCode : %d\r\n\r\nMilsko is exiting.", message, code);
MwStringPrintIntoBuffer(buffer, 1024, "Error: %s\r\nCode : %d\r\n\r\nMilsko is exiting.", message, code);
MessageBox(NULL, buffer, "Error", MB_ICONERROR | MB_OK);
#else
fprintf(stderr, "Error: %s\nCode : %d\n\nMilsko is exiting.", message, code);
@ -688,21 +853,10 @@ void MwGrabPointer(MwWidget handle, int toggle) {
MwLLGrabPointer(handle->lowlevel, toggle);
}
static void force_render_all(MwWidget handle) {
int i;
for(i = 0; i < arrlen(handle->children); i++) {
force_render_all(handle->children[i]);
}
MwForceRender(handle);
}
void MwToggleDarkTheme(MwWidget handle, int toggle) {
int old = handle->dark_theme;
if(old != toggle) {
handle->dark_theme = toggle;
force_render_all(handle);
}
void MwSetDarkTheme(MwWidget handle, int toggle) {
MwVaApply(handle,
MwNdarkTheme, toggle,
NULL);
}
MwWidget MwGetParent(MwWidget handle) {
@ -715,19 +869,46 @@ int MwLibraryInit(void) {
#ifdef USE_WAYLAND
MwLLWaylandCallInit,
#endif
/* x11 has higher priority then cocoa until it works */
#ifdef USE_X11
MwLLX11CallInit,
#endif
#ifdef USE_COCOA
MwLLCocoaCallInit,
#endif
#ifdef USE_GDI
MwLLGDICallInit,
#endif
#ifdef CLASSIC_MAC_OS
MwLLClassicMacOSCallInit,
#endif
NULL};
int i;
MwFLSetup();
for(i = 0; calls[i] != NULL; i++) {
if(calls[i]() == 0) return 0;
}
printf("[WARNING] No suitable GUI backend found! Enabled:"
#ifdef USE_COCOA
" Cocoa"
#endif
#ifdef USE_WAYLAND
" Wayland"
#endif
#ifdef USE_X11
" X11"
#endif
#ifdef USE_GDI
" GDI"
#endif
#ifdef CLASSIC_MAC_OS
" ClassicMacOS"
#endif
"\n");
return 1;
}
@ -752,6 +933,8 @@ void MwReparent(MwWidget handle, MwWidget new_parent) {
arrput(new_parent->children, handle);
MwDispatch(handle->parent, children_update);
MwForceRender(handle);
}
MwClass MwGetClass(MwWidget handle) {
@ -781,3 +964,15 @@ void MwGetCursorCoord(MwWidget handle, MwPoint* point) {
void MwGetScreenSize(MwWidget handle, MwRect* rect) {
MwLLGetScreenSize(handle->lowlevel, rect);
}
int MwGetCoordinateType(MwWidget handle) {
if(handle->parent == NULL || handle->parent->lowlevel == NULL) {
return handle->lowlevel->common.coordinate_type;
} else {
return MwCOORDINATE_LOCAL;
}
}
void MwGetClipboard(MwWidget handle, int clipboard_type) {
MwLLGetClipboard(handle->lowlevel, clipboard_type);
}

View file

@ -10,6 +10,8 @@ const char* MwDefaultDarkForeground = "#ddd";
const char* MwDefaultDarkSubBackground = "#333";
const char* MwDefaultDarkSubForeground = "#ddd";
const int MwDefaultShadow = -32;
int MwDefaultBorderWidth(MwWidget handle) {
int bw = MwGetInteger(handle, MwNborderWidth);

View file

@ -1,7 +1,7 @@
#include <Mw/Milsko.h>
#define WIN_SIZE 464
#define PICKER_SIZE 360
#define PICKER_SIZE 364
#define IMG_POS_X(w) ((w - PICKER_SIZE) / 2)
#define IMG_POS_Y(h) ((h - PICKER_SIZE) / 2)
#define SCROLL_BAR_WIDTH 16
@ -104,11 +104,16 @@ static void color_picker_image_update(color_picker_t* picker) {
int _y = y - (PICKER_SIZE / 2);
double dist = sqrt(_x * _x + _y * _y);
if(dist >= 180.) {
if(dist >= 182.) {
picker->color_picker_image_data[i] = 0;
picker->color_picker_image_data[i + 1] = 0;
picker->color_picker_image_data[i + 2] = 0;
picker->color_picker_image_data[i + 3] = 0;
} else if(dist >= 180.) {
picker->color_picker_image_data[i] = dist;
picker->color_picker_image_data[i + 1] = dist;
picker->color_picker_image_data[i + 2] = dist;
picker->color_picker_image_data[i + 3] = 255;
} else {
MwHSV hsv_v;
MwRGB color;
@ -155,7 +160,7 @@ static void color_picker_image_update(color_picker_t* picker) {
static void color_picker_click(MwWidget handle, void* user, void* call) {
color_picker_t* picker = user;
MwLLMouse* mouse = call;
MwMouse* mouse = call;
char hexColor[8];
int i;
char fgColor[8];
@ -173,13 +178,13 @@ static void color_picker_click(MwWidget handle, void* user, void* call) {
picker->chosen_color.green = picker->color_picker_image_data[i + 1];
picker->chosen_color.blue = picker->color_picker_image_data[i + 2];
sprintf(hexColor, "#%02X%02X%02X", picker->chosen_color.red & 0xff, picker->chosen_color.green & 0xff, picker->chosen_color.blue & 0xff);
MwStringPrintIntoBuffer(hexColor, 8, "#%02X%02X%02X", picker->chosen_color.red & 0xff, picker->chosen_color.green & 0xff, picker->chosen_color.blue & 0xff);
fr = picker->chosen_color.red > 128 ? 0 : 255;
fg = picker->chosen_color.green > 128 ? 0 : 255;
fb = picker->chosen_color.blue > 128 ? 0 : 255;
sprintf(fgColor, "#%02X%02X%02X", fr, fg, fb);
MwStringPrintIntoBuffer(fgColor, 8, "#%02X%02X%02X", fr, fg, fb);
MwSetText(picker->color_display_text, MwNforeground, fgColor);
MwSetText(picker->color_display_text, MwNbackground, hexColor);
@ -247,7 +252,7 @@ static void color_display_text_change(MwWidget handle, void* user,
fg = color->common.green > 128 ? 0 : 255;
fb = color->common.blue > 128 ? 0 : 255;
sprintf(fgColor, "#%02X%02X%02X", fr, fg, fb);
MwStringPrintIntoBuffer(fgColor, 9, "#%02X%02X%02X", fr, fg, fb);
MwSetText(picker->color_display_text, MwNforeground, fgColor);
MwSetText(picker->color_display_text, MwNbackground, hexColor);

View file

@ -53,7 +53,7 @@ static void destroy(MwWidget handle) {
MwDestroyWidget(handle);
}
static void cancel(MwWidget handle, void* user, void* call) {
static void filecancel(MwWidget handle, void* user, void* call) {
(void)user;
(void)call;
@ -147,7 +147,7 @@ static void nav_activate(MwWidget handle, void* user, void* call) {
(void)user;
if(strcmp(e, "Home") == 0) {
#ifdef _WIN32
#if defined(_WIN32) || defined(CLASSIC_MAC_OS)
#else
struct passwd* p = getpwuid(getuid());
@ -221,7 +221,7 @@ static void layout(MwWidget handle) {
MwNleftPadding, 16,
NULL);
MwListBoxInsert(fc->nav, -1, p);
MwAddUserHandler(fc->nav, MwNactivateHandler, nav_activate, NULL);
MwAddUserHandler(fc->nav, MwNlistBoxActivateHandler, nav_activate, NULL);
MwListBoxDestroyPacket(p);
} else {
@ -242,7 +242,7 @@ static void layout(MwWidget handle) {
MwNhasHeading, 1,
MwNleftPadding, 16,
NULL);
MwAddUserHandler(fc->files, MwNactivateHandler, files_activate, NULL);
MwAddUserHandler(fc->files, MwNlistBoxActivateHandler, files_activate, NULL);
} else {
MwVaApply(fc->files,
MwNx, wx,
@ -383,7 +383,7 @@ static void layout(MwWidget handle) {
MwNtext, "Cancel",
NULL);
MwAddUserHandler(fc->cancel, MwNactivateHandler, cancel, NULL);
MwAddUserHandler(fc->cancel, MwNactivateHandler, filecancel, NULL);
} else {
MwVaApply(fc->cancel,
MwNx, wx,

View file

@ -102,7 +102,7 @@ MwWidget MwMessageBox(MwWidget handle, const char* text, const char* title, unsi
left = 8 + 48 + 8;
}
th = MwTextHeight(handle, text);
th = MwTextHeight(handle, NULL, text);
(void)MwVaCreateWidget(MwLabelClass, "label", window, left, (h - th) / 2, w - left - 8, th,
MwNtext, text,
MwNalignment, MwALIGNMENT_BEGINNING,

View file

@ -1,6 +1,7 @@
#include <Mw/Milsko.h>
#ifdef USE_STB_IMAGE
#ifdef NO_IMAGE
#elif defined(USE_STB_IMAGE)
#include "../external/stb_image.h"
#else
#include <png.h>
@ -12,7 +13,7 @@
static int get_color_diff(MwWidget handle) {
if(MwGetInteger(handle, MwNmodernLook)) {
return 46;
return 40;
} else {
return 80;
}
@ -28,7 +29,7 @@ static int hex(const char* txt, int len) {
n = c - 'a' + 10;
} else if('A' <= c && c <= 'F') {
n = c - 'A' + 10;
} else if('0' <= c && c <= '9') {
} else if('0' <= c && c <= 'g') {
n = c - '0';
}
r = r << 4;
@ -106,11 +107,21 @@ void MwDrawRectFading(MwWidget handle, MwRect* rect, MwLLColor color) {
int y;
double darken = 0.;
int ColorDiff = get_color_diff(handle);
double darkenStep = (ColorDiff / 4.) / rect->height;
double darkenStep = (ColorDiff / 2.) / rect->height;
unsigned long sz = 1 * rect->height * 4;
unsigned char* data = malloc(sz);
MwRect r = *rect;
if(rect->width <= 0 || rect->height <= 0) {
free(data);
return;
}
memset(data, 0, sz);
r.x += 1;
r.y += 1;
r.width -= 2;
r.height -= 2;
for(y = 0; y < rect->height; y++) {
MwLLColor col = MwLightenColor(handle, color, -darken, -darken, -darken);
int idx = y * 4;
@ -123,13 +134,16 @@ void MwDrawRectFading(MwWidget handle, MwRect* rect, MwLLColor color) {
}
pixmap = MwLLCreatePixmap(handle->lowlevel, data, 1, rect->height);
MwLLDrawPixmap(handle->lowlevel, rect, pixmap);
MwLLDrawPixmap(handle->lowlevel, &r, pixmap);
MwLLDestroyPixmap(pixmap);
free(data);
}
void MwDrawFrame(MwWidget handle, MwRect* rect, MwLLColor color, int invert) {
int inv;
if((inv = MwGetInteger(handle, MwNforceInverted)) != MwDEFAULT && inv) invert = 1;
if(MwGetInteger(handle, MwNmodernLook)) {
MwDrawFrameEx(handle, rect, color, invert, MwDefaultBorderWidth(handle), 0, 0);
} else {
@ -151,7 +165,18 @@ void MwDrawFrame(MwWidget handle, MwRect* rect, MwLLColor color, int invert) {
void MwDrawWidgetBack(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int border) {
MwLLColor col;
if(rect->width <= 0 || rect->height <= 0) return;
if(border) {
if(!handle->lowlevel->common.supports_transparency) {
MwLLColor c = handle->parent == NULL ? NULL : MwParseColor(handle->parent, MwGetText(handle->parent, MwNbackground));
if(c != NULL) {
MwDrawRect(handle, rect, c);
MwLLFreeColor(c);
}
}
MwDrawFrame(handle, rect, color, invert);
}
col = invert ? MwLightenColor(handle, color, -8, -8, -8) : color;
@ -166,7 +191,7 @@ void MwDrawWidgetBack(MwWidget handle, MwRect* rect, MwLLColor color, int invert
void MwDrawDiamond(MwWidget handle, MwRect* rect, MwLLColor color, int invert) {
MwPoint p[6];
int border = MwDefaultBorderWidth(handle);
int ColorDiff = get_color_diff(handle);
int ColorDiff = get_color_diff(handle) + (MwGetInteger(handle, MwNmodernLook) ? 48 : 0);
MwLLColor darker = MwLightenColor(handle, color, -ColorDiff, -ColorDiff, -ColorDiff);
MwLLColor lighter = MwLightenColor(handle, color, ColorDiff, ColorDiff, ColorDiff);
MwLLColor col = invert ? MwLightenColor(handle, color, -8, -8, -8) : color;
@ -230,12 +255,11 @@ void MwDrawDiamond(MwWidget handle, MwRect* rect, MwLLColor color, int invert) {
MwLLFreeColor(darker);
}
void MwDrawFrameEx(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int border, int diff, int same) {
MwPoint p[6];
static void MwDrawFrameEx_simple(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int border, int diff, int same) {
MwPoint p[7];
int ColorDiff = get_color_diff(handle);
MwLLColor darker = MwLightenColor(handle, color, -ColorDiff * 3 / 2 + diff, -ColorDiff * 3 / 2 + diff, -ColorDiff * 3 / 2 + diff);
MwLLColor lighter = same ? MwLightenColor(handle, darker, 0, 0, 0) : MwLightenColor(handle, color, ColorDiff - diff, ColorDiff - diff, ColorDiff - diff);
p[0].x = rect->x;
p[0].y = rect->y;
@ -244,7 +268,6 @@ void MwDrawFrameEx(MwWidget handle, MwRect* rect, MwLLColor color, int invert, i
p[2].x = rect->x + rect->width - border;
p[2].y = rect->y + border;
p[3].x = rect->x + border;
p[3].y = rect->y + border;
@ -253,7 +276,6 @@ void MwDrawFrameEx(MwWidget handle, MwRect* rect, MwLLColor color, int invert, i
p[5].x = rect->x;
p[5].y = rect->y + rect->height;
MwLLPolygon(handle->lowlevel, p, 6, invert ? darker : lighter);
p[0].x = rect->x + rect->width;
@ -273,7 +295,6 @@ void MwDrawFrameEx(MwWidget handle, MwRect* rect, MwLLColor color, int invert, i
p[5].x = rect->x + rect->width;
p[5].y = rect->y + rect->height;
MwLLPolygon(handle->lowlevel, p, 6, invert ? lighter : darker);
MwLLFreeColor(lighter);
@ -285,6 +306,81 @@ void MwDrawFrameEx(MwWidget handle, MwRect* rect, MwLLColor color, int invert, i
rect->height -= border * 2;
}
static void frame_border_complex(MwWidget handle, MwRect* rect, MwLLColor lighter, MwLLColor darker, int invert, int border, int diff, int same) {
MwPoint p[7];
(void)diff;
(void)same;
p[0].x = rect->x;
p[0].y = rect->y;
p[1].x = rect->x + rect->width;
p[1].y = rect->y;
p[2].x = rect->x + rect->width - border;
p[2].y = rect->y + border;
p[3].x = rect->x + border;
p[3].y = rect->y + border;
p[4].x = rect->x + border;
p[4].y = rect->y + rect->height - border;
p[5].x = rect->x;
p[5].y = rect->y + rect->height;
MwLLPolygon(handle->lowlevel, p, 6, invert ? lighter : darker);
p[0].x = rect->x + rect->width;
p[0].y = rect->y;
p[1].x = rect->x + rect->width - border;
p[1].y = rect->y + border;
p[2].x = rect->x + rect->width - border;
p[2].y = rect->y + rect->height - border;
p[3].x = rect->x + border;
p[3].y = rect->y + rect->height - border;
p[4].x = rect->x;
p[4].y = rect->y + rect->height;
p[5].x = rect->x + rect->width;
p[5].y = rect->y + rect->height;
MwLLPolygon(handle->lowlevel, p, 6, invert ? lighter : darker);
}
static void MwDrawFrameEx_complex(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int border, int diff, int same) {
int ColorDiff = get_color_diff(handle);
MwLLColor darker = MwLightenColor(handle, color, -ColorDiff * 3 / 2 + diff, -ColorDiff * 3 / 2 + diff, -ColorDiff * 3 / 2 + diff);
MwLLColor lighter = same ? MwLightenColor(handle, darker, 0, 0, 0) : MwLightenColor(handle, color, (ColorDiff / 2) - diff, (ColorDiff / 2) - diff, (ColorDiff / 2) - diff);
MwRect r = *rect;
frame_border_complex(handle, rect, lighter, darker, invert, border, diff, same);
r.x += 1;
r.y += 1;
r.width -= 2;
r.height -= 2;
frame_border_complex(handle, &r, lighter, darker, !invert, border, diff, same);
MwLLFreeColor(lighter);
MwLLFreeColor(darker);
rect->x += border;
rect->y += border;
rect->width -= border * 2;
rect->height -= border * 2;
}
void MwDrawFrameEx(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int border, int diff, int same) {
if(MwGetInteger(handle, MwNmodernLook)) {
MwDrawFrameEx_complex(handle, rect, color, invert, border, diff, same);
} else {
MwDrawFrameEx_simple(handle, rect, color, invert, border, diff, same);
}
}
void MwDrawTriangle(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int direction) {
MwPoint p1[4], p2[4], p3[4], p4[3];
const int border = MwGetInteger(handle, MwNmodernLook) ? 2 : MwDefaultBorderWidth(handle);
@ -502,7 +598,8 @@ void MwDrawTriangle(MwWidget handle, MwRect* rect, MwLLColor color, int invert,
MwLLFreeColor(darker);
}
#ifndef USE_STB_IMAGE
#if defined(NO_IMAGE)
#elif !defined(USE_STB_IMAGE)
static void PNGCAPI user_error(png_structp png, const char* str) {
(void)str;
@ -617,7 +714,9 @@ static unsigned char* load_jpeg(FILE* f, int* w, int* h) {
#endif
static unsigned char* load_image(const char* path, int* w, int* h) {
#ifdef USE_STB_IMAGE
#if defined(NO_IMAGE)
return NULL;
#elif defined(USE_STB_IMAGE)
int ch;
return stbi_load(path, w, h, &ch, 4);

View file

@ -1,23 +0,0 @@
#include <Mw/Milsko.h>
#include "error_internal.h"
#define MAX_ERROR_LEN 512
/* buffer for holding the error. +1 to ensure there's always a null terminator. */
char error[MAX_ERROR_LEN + 1] = {0};
const char* MwGetLastError(void) {
return error;
}
void setLastError(const char* fmt, ...) {
va_list va;
char out[MAX_ERROR_LEN];
memset(out, 0, MAX_ERROR_LEN);
va_start(va, fmt);
vsprintf(out, fmt, va);
va_end(va);
memcpy(error, out, MAX_ERROR_LEN);
}

View file

@ -1,15 +0,0 @@
#ifndef __MW_ERROR_INTERNAL_H__
#define __MW_ERROR_INTERNAL_H__
/**
* This is not to be documented or exposed publically.
* This contains an internal function for setting the error,
* something the user shouldn't want to do and thus we don't want them to.
* (hence also, its placement in the src directory)
*/
#include <Mw/Error.h>
void setLastError(const char* fmt, ...);
#endif

View file

@ -1,61 +1,305 @@
#include <Mw/Milsko.h>
MwLL (*MwLLCreate)(MwLL parent, int x, int y, int width, int height);
void (*MwLLDestroy)(MwLL handle);
MwLL (*MwLLCreate)(MwLL parent, int x, int y, int width, int height) = NULL;
void (*MwLLDestroy)(MwLL handle) = NULL;
void (*MwLLPolygon)(MwLL handle, MwPoint* points, int points_count, MwLLColor color);
void (*MwLLLine)(MwLL handle, MwPoint* points, MwLLColor color);
void (*MwLLPolygon)(MwLL handle, MwPoint* points, int points_count, MwLLColor color) = NULL;
void (*MwLLLine)(MwLL handle, MwPoint* points, MwLLColor color) = NULL;
void (*MwLLBeginDraw)(MwLL handle);
void (*MwLLEndDraw)(MwLL handle);
void (*MwLLBeginDraw)(MwLL handle) = NULL;
void (*MwLLEndDraw)(MwLL handle) = NULL;
MwLLColor (*MwLLAllocColor)(MwLL handle, int r, int g, int b);
void (*MwLLColorUpdate)(MwLL handle, MwLLColor c, int r, int g, int b);
void (*MwLLFreeColor)(MwLLColor color);
MwLLColor (*MwLLAllocColor)(MwLL handle, int r, int g, int b) = NULL;
void (*MwLLColorUpdate)(MwLL handle, MwLLColor c, int r, int g, int b) = NULL;
void (*MwLLFreeColor)(MwLLColor color) = NULL;
void (*MwLLGetXYWH)(MwLL handle, int* x, int* y, unsigned int* w, unsigned int* h);
void (*MwLLSetXY)(MwLL handle, int x, int y);
void (*MwLLSetWH)(MwLL handle, int w, int h);
void (*MwLLGetXYWH)(MwLL handle, int* x, int* y, unsigned int* w, unsigned int* h) = NULL;
void (*MwLLSetXY)(MwLL handle, int x, int y) = NULL;
void (*MwLLSetWH)(MwLL handle, int w, int h) = NULL;
void (*MwLLSetTitle)(MwLL handle, const char* title);
void (*MwLLSetTitle)(MwLL handle, const char* title) = NULL;
int (*MwLLPending)(MwLL handle);
void (*MwLLNextEvent)(MwLL handle);
int (*MwLLPending)(MwLL handle) = NULL;
void (*MwLLNextEvent)(MwLL handle) = NULL;
MwLLPixmap (*MwLLCreatePixmap)(MwLL handle, unsigned char* data, int width, int height);
void (*MwLLPixmapUpdate)(MwLLPixmap pixmap);
void (*MwLLDestroyPixmap)(MwLLPixmap pixmap);
void (*MwLLDrawPixmap)(MwLL handle, MwRect* rect, MwLLPixmap pixmap);
void (*MwLLSetIcon)(MwLL handle, MwLLPixmap pixmap);
MwLLPixmap (*MwLLCreatePixmap)(MwLL handle, unsigned char* data, int width, int height) = NULL;
void (*MwLLPixmapUpdate)(MwLLPixmap pixmap) = NULL;
void (*MwLLDestroyPixmap)(MwLLPixmap pixmap) = NULL;
void (*MwLLDrawPixmap)(MwLL handle, MwRect* rect, MwLLPixmap pixmap) = NULL;
void (*MwLLSetIcon)(MwLL handle, MwLLPixmap pixmap) = NULL;
void (*MwLLForceRender)(MwLL handle);
void (*MwLLForceRender)(MwLL handle) = NULL;
void (*MwLLSetCursor)(MwLL handle, MwCursor* image, MwCursor* mask);
void (*MwLLDetach)(MwLL handle, MwPoint* point);
void (*MwLLShow)(MwLL handle, int show);
void (*MwLLSetCursor)(MwLL handle, MwCursor* image, MwCursor* mask) = NULL;
void (*MwLLDetach)(MwLL handle, MwPoint* point) = NULL;
void (*MwLLShow)(MwLL handle, int show) = NULL;
void (*MwLLSetSizeHints)(MwLL handle, int minx, int miny, int maxx, int maxy);
void (*MwLLMakeBorderless)(MwLL handle, int toggle);
void (*MwLLMakeToolWindow)(MwLL handle);
void (*MwLLMakePopup)(MwLL handle, MwLL parent);
void (*MwLLSetSizeHints)(MwLL handle, int minx, int miny, int maxx, int maxy) = NULL;
void (*MwLLMakeBorderless)(MwLL handle, int toggle) = NULL;
void (*MwLLMakeToolWindow)(MwLL handle) = NULL;
void (*MwLLMakePopup)(MwLL handle, MwLL parent) = NULL;
void (*MwLLBeginStateChange)(MwLL handle);
void (*MwLLEndStateChange)(MwLL handle);
void (*MwLLBeginStateChange)(MwLL handle) = NULL;
void (*MwLLEndStateChange)(MwLL handle) = NULL;
void (*MwLLFocus)(MwLL handle);
void (*MwLLGrabPointer)(MwLL handle, int toggle);
void (*MwLLFocus)(MwLL handle) = NULL;
void (*MwLLGrabPointer)(MwLL handle, int toggle) = NULL;
void (*MwLLSetClipboard)(MwLL handle, const char* text);
char* (*MwLLGetClipboard)(MwLL handle);
void (*MwLLSetClipboard)(MwLL handle, const char* text, int clipboard_type) = NULL;
void (*MwLLGetClipboard)(MwLL, int clipboard_type) = NULL;
void (*MwLLGetCursorCoord)(MwLL handle, MwPoint* point);
void (*MwLLGetScreenSize)(MwLL handle, MwRect* rect);
void (*MwLLGetCursorCoord)(MwLL handle, MwPoint* point) = NULL;
void (*MwLLGetScreenSize)(MwLL handle, MwRect* rect) = NULL;
void (*MwLLSetDarkTheme)(MwLL handle, int toggle) = NULL;
void MwLLCreateCommon(MwLL handle) {
handle->common.handler = malloc(sizeof(*handle->common.handler));
memset(handle->common.handler, 0, sizeof(*handle->common.handler));
handle->common.supports_transparency = 0;
}
void MwLLDestroyCommon(MwLL handle) {
free(handle->common.handler);
}
#ifdef USE_DBUS
MwBool MwLLDBusFuncSetup(MwLLDBusFuncTable* tbl) {
tbl->lib = MwDynamicOpen("libdbus-1.so");
if(!tbl->lib) {
fprintf(stderr, "[WARNING] dbus library (libdbus-1.so) not found, will not be able to check for any XDG settings.\n");
return MwFALSE;
}
#define DBUS_FUNC(x) \
tbl->x = MwDynamicSymbol(tbl->lib, #x); \
if(!tbl->x) { \
fprintf(stderr, "[WARNING] dbus function %s not found, will not be able to check for any XDG settings.\n", #x); \
dlclose(tbl->lib); \
return MwFALSE; \
}
DBUS_FUNC(dbus_error_init);
DBUS_FUNC(dbus_bus_get);
DBUS_FUNC(dbus_bus_add_match);
DBUS_FUNC(dbus_error_is_set);
DBUS_FUNC(dbus_error_free);
DBUS_FUNC(dbus_message_new_method_call);
DBUS_FUNC(dbus_message_is_signal);
DBUS_FUNC(dbus_message_iter_init_append);
DBUS_FUNC(dbus_message_iter_append_basic);
DBUS_FUNC(dbus_connection_flush);
DBUS_FUNC(dbus_connection_pop_message);
DBUS_FUNC(dbus_connection_read_write);
DBUS_FUNC(dbus_connection_send_with_reply_and_block);
DBUS_FUNC(dbus_message_unref);
DBUS_FUNC(dbus_message_iter_init);
DBUS_FUNC(dbus_message_iter_get_arg_type);
DBUS_FUNC(dbus_message_iter_recurse);
DBUS_FUNC(dbus_message_iter_next);
DBUS_FUNC(dbus_connection_unref);
DBUS_FUNC(dbus_message_iter_get_basic);
return MwTRUE;
}
#endif
#ifdef USE_DBUS
MwBool MwLLDBusNewContext(MwLLDBusFuncTable* tbl, MwLLDBusContext* ctx) {
if(!tbl->lib) {
return MwFALSE;
}
tbl->dbus_error_init(&ctx->dbus_err);
ctx->dbus_conn = tbl->dbus_bus_get(DBUS_BUS_SESSION, &ctx->dbus_err);
if(tbl->dbus_error_is_set(&ctx->dbus_err)) {
fprintf(stderr, "[WARNING] Could not initialize dbus: Connection error: %s\n", ctx->dbus_err.message);
tbl->dbus_error_free(&ctx->dbus_err);
return MwFALSE;
}
if(!ctx->dbus_conn) {
fprintf(stderr, "[WARNING] Could not initialize dbus: Failed to connect to session bus\n");
return MwFALSE;
}
return MwTRUE;
};
MWDECL MwBool MwLLDBusPortalGet(MwLLDBusFuncTable* tbl, MwLLDBusContext* ctx, const char* portal, const char* namespace, const char* key, void* out) {
DBusMessageIter dbus_args, dbus_variant, dbus_inner_variant;
char arg_type;
if(!ctx->dbus_conn) {
return MwFALSE;
}
ctx->dbus_msg = tbl->dbus_message_new_method_call(
"org.freedesktop.portal.Desktop",
"/org/freedesktop/portal/desktop",
portal,
"Read");
if(!ctx->dbus_msg) {
fprintf(stderr, "[WARNING] Couldn't get %s::%s: Failed to create message\n", namespace, key);
return MwFALSE;
}
tbl->dbus_message_iter_init_append(ctx->dbus_msg, &dbus_args);
tbl->dbus_message_iter_append_basic(&dbus_args, 's', &namespace);
tbl->dbus_message_iter_append_basic(&dbus_args, 's', &key);
ctx->dbus_reply = tbl->dbus_connection_send_with_reply_and_block(ctx->dbus_conn, ctx->dbus_msg, 100, &ctx->dbus_err);
if(tbl->dbus_error_is_set(&ctx->dbus_err)) {
fprintf(stderr, "[WARNING] Couldn't get %s::%s: Send error: %s\n", namespace, key, ctx->dbus_err.message);
tbl->dbus_error_free(&ctx->dbus_err);
return MwFALSE;
}
if(!ctx->dbus_reply) {
fprintf(stderr, "[WARNING] Couldn't get %s::%s: No reply received\n", namespace, key);
return MwFALSE;
}
if(!tbl->dbus_message_iter_init(ctx->dbus_reply, &dbus_args)) {
fprintf(stderr, "[WARNING] Couldn't get %s::%s: Reply has no arguments\n", namespace, key);
tbl->dbus_message_unref(ctx->dbus_reply);
return MwFALSE;
}
if((arg_type = tbl->dbus_message_iter_get_arg_type(&dbus_args)) != 'v') {
fprintf(stderr, "[WARNING] Couldn't get %s::%s: Expected outer variant, got: %c\n", namespace, key, arg_type);
tbl->dbus_message_unref(ctx->dbus_reply);
return MwFALSE;
}
tbl->dbus_message_iter_recurse(&dbus_args, &dbus_variant);
/* Some portals wrap the value in a second variant */
arg_type = tbl->dbus_message_iter_get_arg_type(&dbus_variant);
if(arg_type == 'v') {
tbl->dbus_message_iter_recurse(&dbus_variant, &dbus_inner_variant);
if((arg_type = tbl->dbus_message_iter_get_arg_type(&dbus_inner_variant)) != 'u') {
fprintf(stderr, "[WARNING] Signal reply for %s::SettingChanged: Expected 'u' (uint32) for 'value', got: %c\n", portal, arg_type);
tbl->dbus_message_unref(ctx->dbus_reply);
return MwFALSE;
}
tbl->dbus_message_iter_get_basic(&dbus_inner_variant, out);
} else if (arg_type == 'u') {
tbl->dbus_message_iter_get_basic(&dbus_variant, out);
} else {
fprintf(stderr, "[WARNING] Couldn't get %s::%s: Expected variant or string, got: %c\n", namespace, key, arg_type);
tbl->dbus_message_unref(ctx->dbus_reply);
return MwFALSE;
}
tbl->dbus_message_unref(ctx->dbus_msg);
return MwTRUE;
}
MWDECL MwBool MwLLDBusPortalWatch(MwLLDBusFuncTable* tbl, MwLLDBusContext* ctx, const char* portal) {
char filter_string[2048];
if(!ctx->dbus_conn) {
return MwFALSE;
}
MwStringPrintIntoBuffer(filter_string, sizeof(filter_string), "type='%s',interface=%s", "signal", portal);
tbl->dbus_bus_add_match(ctx->dbus_conn, filter_string, &ctx->dbus_err);
tbl->dbus_connection_flush(ctx->dbus_conn);
return MwTRUE;
}
/* Technically this will swallow all other results, so this is not usable multiple times.
TODO: Use a hashmap instead */
MWDECL MwBool MwLLDBusPortalPoll(MwLLDBusFuncTable* tbl, MwLLDBusContext* ctx, MwLL handle, const char* portal, const char* namespace, const char* key, MwLLDBusPortalPollListener listener) {
DBusMessageIter args, msg_value, msg_value_inner;
const char* msg_namespace;
const char* msg_key;
MwU32 msg_value_content;
char arg_type;
if(!ctx->dbus_conn) {
return MwFALSE;
}
tbl->dbus_connection_read_write(ctx->dbus_conn, 0);
tbl->dbus_connection_read_write(ctx->dbus_conn, 0);
ctx->dbus_reply = tbl->dbus_connection_pop_message(ctx->dbus_conn);
if(tbl->dbus_error_is_set(&ctx->dbus_err)) {
fprintf(stderr, "[WARNING] Signal reply for %s::SettingChanged: Poll error: %s\n", portal, ctx->dbus_err.message);
tbl->dbus_error_free(&ctx->dbus_err);
return MwFALSE;
}
if(!ctx->dbus_reply) {
return MwFALSE;
}
/* check if the message is a signal from the correct interface and with the correct name */
if(tbl->dbus_message_is_signal(ctx->dbus_reply, portal, "SettingChanged")) {
/* read the parameters */
if(!tbl->dbus_message_iter_init(ctx->dbus_reply, &args))
fprintf(stderr, "[WARNING] Signal reply for %s::SettingChanged has no arguments\n", portal);
else {
if((arg_type = tbl->dbus_message_iter_get_arg_type(&args)) != 's') {
fprintf(stderr, "[WARNING] Signal reply for %s::SettingChanged: Expected 's' (string) for 'namespace', got: %c\n", portal, arg_type);
tbl->dbus_message_unref(ctx->dbus_reply);
return MwFALSE;
}
tbl->dbus_message_iter_get_basic(&args, &msg_namespace);
tbl->dbus_message_iter_next(&args);
if((arg_type = tbl->dbus_message_iter_get_arg_type(&args)) != 's') {
fprintf(stderr, "[WARNING] Signal reply for %s::SettingChanged: Expected 's' (string) for 'key', got: %c\n", portal, arg_type);
tbl->dbus_message_unref(ctx->dbus_reply);
return MwFALSE;
}
tbl->dbus_message_iter_get_basic(&args, &msg_key);
/* Check that key and namespace match */
if(strcmp(msg_namespace, namespace) == 0 && strcmp(msg_key, key) == 0) {
/* Assuming the value is a basic type */
tbl->dbus_message_iter_next(&args);
if((arg_type = tbl->dbus_message_iter_get_arg_type(&args)) != 'v') {
fprintf(stderr, "[WARNING] Couldn't get %s::%s: Expected outer variant, got: %c\n", namespace, key, arg_type);
tbl->dbus_message_unref(ctx->dbus_reply);
return MwFALSE;
}
tbl->dbus_message_iter_recurse(&args, &msg_value);
/* Some portals wrap the value in a second variant */
arg_type = tbl->dbus_message_iter_get_arg_type(&msg_value);
if(arg_type == 'v') {
tbl->dbus_message_iter_recurse(&msg_value, &msg_value_inner);
if((arg_type = tbl->dbus_message_iter_get_arg_type(&msg_value_inner)) != 'u') {
fprintf(stderr, "[WARNING] Signal reply for %s::SettingChanged: Expected 'u' (uint32) for 'value', got: %c\n", portal, arg_type);
tbl->dbus_message_unref(ctx->dbus_reply);
return MwFALSE;
}
tbl->dbus_message_iter_get_basic(&msg_value_inner, &msg_value_content);
} else if (arg_type == 'u') {
tbl->dbus_message_iter_get_basic(&msg_value, &msg_value_content);
} else {
fprintf(stderr, "[WARNING] Couldn't get %s::%s: Expected variant or string, got: %c\n", namespace, key, arg_type);
tbl->dbus_message_unref(ctx->dbus_reply);
return MwFALSE;
}
listener(handle, msg_value_content);
}
}
}
/* free the message */
tbl->dbus_message_unref(ctx->dbus_reply);
return MwTRUE;
}
void MwLLDBusFreeContext(MwLLDBusFuncTable* tbl, MwLLDBusContext* ctx) {
if(!tbl->lib) {
return;
}
if(ctx->dbus_reply) tbl->dbus_message_unref(ctx->dbus_reply);
if(ctx->dbus_conn) tbl->dbus_connection_unref(ctx->dbus_conn);
};
#endif

View file

@ -37,3 +37,80 @@ void MwStringTime(char* out, time_t t) {
sprintf(out, "%s %2d %02d:%02d %d", months[tm->tm_mon], tm->tm_mday, tm->tm_hour, tm->tm_min, 1900 + tm->tm_year);
}
}
void MwStringPrintIntoBuffer(char* out, MwU32 size, const char* fmt, ...) {
va_list va;
va_start(va, fmt);
#if __STDC_VERSION__ >= 199901L
vsnprintf(out, size, fmt, va);
#else
vsprintf(out, fmt, va);
#endif
va_end(va);
};
MWDECL MwBool MwStringIsKeyUTF8(MwU32 key) {
unsigned char bytes[4];
int i;
bytes[0] = (key & 0x000000FF);
bytes[1] = (key & 0x0000FF00) >> 8;
bytes[2] = (key & 0x00FF0000) >> 16;
bytes[3] = (key & 0xFF000000) >> 24;
for(i = 0; i < sizeof(MwU32); i++) {
if(( // ASCII
// use bytes[0] <= 0x7F to allow ASCII control characters
bytes[0] == 0x09 ||
bytes[0] == 0x0A ||
bytes[0] == 0x0D ||
(0x20 <= bytes[0] && bytes[0] <= 0x7E))) {
continue;
}
if(( // non-overlong 2-byte
(0xC2 <= bytes[0] && bytes[0] <= 0xDF) &&
(0x80 <= bytes[1] && bytes[1] <= 0xBF))) {
continue;
}
if(( // excluding overlongs
bytes[0] == 0xE0 &&
(0xA0 <= bytes[1] && bytes[1] <= 0xBF) &&
(0x80 <= bytes[2] && bytes[2] <= 0xBF)) ||
( // straight 3-byte
((0xE1 <= bytes[0] && bytes[0] <= 0xEC) ||
bytes[0] == 0xEE ||
bytes[0] == 0xEF) &&
(0x80 <= bytes[1] && bytes[1] <= 0xBF) &&
(0x80 <= bytes[2] && bytes[2] <= 0xBF)) ||
( // excluding surrogates
bytes[0] == 0xED &&
(0x80 <= bytes[1] && bytes[1] <= 0x9F) &&
(0x80 <= bytes[2] && bytes[2] <= 0xBF))) {
continue;
}
if(( // planes 1-3
bytes[0] == 0xF0 &&
(0x90 <= bytes[1] && bytes[1] <= 0xBF) &&
(0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
(0x80 <= bytes[3] && bytes[3] <= 0xBF)) ||
( // planes 4-15
(0xF1 <= bytes[0] && bytes[0] <= 0xF3) &&
(0x80 <= bytes[1] && bytes[1] <= 0xBF) &&
(0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
(0x80 <= bytes[3] && bytes[3] <= 0xBF)) ||
( // plane 16
bytes[0] == 0xF4 &&
(0x80 <= bytes[1] && bytes[1] <= 0x8F) &&
(0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
(0x80 <= bytes[3] && bytes[3] <= 0xBF))) {
continue;
}
return 0;
}
return 1;
}

View file

@ -1,384 +0,0 @@
#include <Mw/Milsko.h>
#if defined(USE_FREETYPE2)
#include <ft2build.h>
#include FT_FREETYPE_H
typedef struct ttf {
FT_Library library;
FT_Face face;
void* data;
} ttf_t;
#define TTF
#elif defined(USE_STB_TRUETYPE)
#include "../external/stb_truetype.h"
typedef struct ttf {
stbtt_fontinfo font;
void* data;
float scale;
int ascent;
int descent;
} ttf_t;
#define TTF
#endif
#define FontWidth 7
#define FontHeight 14
static void bitmap_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color) {
int i = 0, x, y, sx, sy;
int tw, th;
unsigned char* px;
MwRect r;
MwLLPixmap p;
if(strlen(text) == 0) text = " ";
tw = MwTextWidth(handle, text);
th = MwTextHeight(handle, text);
px = malloc(tw * th * 4);
memset(px, 0, tw * th * 4);
sx = 0;
sy = 0;
while(text[i] != 0) {
int out;
i += MwUTF8ToUTF32(text + i, &out);
if(out > 0xff) {
out = 0;
}
if(out == '\n') {
sx = 0;
sy += FontHeight;
} else {
for(y = 0; y < FontHeight; y++) {
for(x = 0; x < FontWidth; x++) {
unsigned char* ppx = &px[((sy + y) * tw + sx + x) * 4];
if((bold ? MwBoldFontData : MwFontData)[out].data[y] & (1 << ((FontWidth - 1) - x))) {
ppx[0] = color->common.red;
ppx[1] = color->common.green;
ppx[2] = color->common.blue;
ppx[3] = 255;
} else {
ppx[0] = 0;
ppx[1] = 0;
ppx[2] = 0;
ppx[3] = 0;
}
}
}
sx += FontWidth;
}
}
p = MwLoadRaw(handle, px, tw, th);
r.x = point->x;
r.y = point->y - th / 2;
r.width = tw;
r.height = th;
if(align == MwALIGNMENT_CENTER) {
r.x -= tw / 2;
} else if(align == MwALIGNMENT_END) {
r.x -= tw;
}
MwLLDrawPixmap(handle->lowlevel, &r, p);
MwLLDestroyPixmap(p);
free(px);
}
#if defined(USE_STB_TRUETYPE)
static int ttf_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color) {
ttf_t* ttf = MwGetVoid(handle, bold ? MwNboldFont : MwNfont);
unsigned char* px;
int tw, th;
MwRect r;
MwLLPixmap p;
int ax, lsb;
int x = 0, y = 0;
if(ttf == NULL) return 1;
tw = MwTextWidth(handle, text);
th = MwTextHeight(handle, text);
px = malloc(tw * th * 4);
memset(px, 0, tw * th * 4);
while(text[0] != 0) {
int c;
int x0, y0, x1, y1, cx, cy;
int ow, oh;
unsigned char* out;
text += MwUTF8ToUTF32(text, &c);
if(c == '\n') {
x = 0;
y += (ttf->ascent - ttf->descent) * ttf->scale;
continue;
}
stbtt_GetCodepointHMetrics(&ttf->font, c, &ax, &lsb);
stbtt_GetCodepointBitmapBox(&ttf->font, c, ttf->scale, ttf->scale, &x0, &y0, &x1, &y1);
ow = x1 - x0;
oh = y1 - y0;
out = malloc(ow * oh);
stbtt_MakeCodepointBitmap(&ttf->font, out, ow, oh, ow, ttf->scale, ttf->scale, c);
for(cy = 0; cy < oh; cy++) {
for(cx = 0; cx < ow; cx++) {
int ox = x + (lsb * ttf->scale) + cx;
int oy = y + (ttf->ascent * ttf->scale) + y0 + cy;
unsigned char* opx = &px[(oy * tw + ox) * 4];
opx[0] = color->common.red;
opx[1] = color->common.green;
opx[2] = color->common.blue;
opx[3] = out[cy * ow + cx];
}
}
x += ax * ttf->scale;
free(out);
}
p = MwLoadRaw(handle, px, tw, th);
r.x = point->x;
r.y = point->y - th / 2;
r.width = tw;
r.height = th;
if(align == MwALIGNMENT_CENTER) {
r.x -= tw / 2;
} else if(align == MwALIGNMENT_END) {
r.x -= tw;
}
MwLLDrawPixmap(handle->lowlevel, &r, p);
MwLLDestroyPixmap(p);
free(px);
return 0;
}
static int ttf_MwTextWidth(MwWidget handle, const char* text) {
ttf_t* ttf = MwGetVoid(handle, MwNfont);
int ax, lsb;
int tw = 0;
if(ttf == NULL) return -1;
while(text[0] != 0) {
int c;
text += MwUTF8ToUTF32(text, &c);
stbtt_GetCodepointHMetrics(&ttf->font, c, &ax, &lsb);
tw += ax * ttf->scale;
}
return tw;
}
static int ttf_MwTextHeight(MwWidget handle, int count) {
ttf_t* ttf = MwGetVoid(handle, MwNfont);
if(ttf == NULL) return -1;
return (ttf->ascent - ttf->descent) * ttf->scale * count;
}
#elif defined(USE_FREETYPE2)
static int ttf_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color) {
ttf_t* ttf = MwGetVoid(handle, bold ? MwNboldFont : MwNfont);
int tw, th;
unsigned char* px;
MwLLPixmap p;
MwRect r;
int x = 0, y = 0;
if(ttf == NULL) return 1;
tw = MwTextWidth(handle, text);
th = MwTextHeight(handle, text);
px = malloc(tw * th * 4);
memset(px, 0, tw * th * 4);
while(text[0] != 0) {
int c;
FT_Bitmap* bmp;
int cy, cx;
int l = MwUTF8ToUTF32(text, &c);
if(l <= 0) break;
text += l;
if(c == '\n') {
x = 0;
y += ttf->face->height * 14 / ttf->face->units_per_EM;
continue;
}
FT_Load_Char(ttf->face, c, FT_LOAD_RENDER);
bmp = &ttf->face->glyph->bitmap;
for(cy = 0; cy < bmp->rows; cy++) {
for(cx = 0; cx < bmp->width; cx++) {
int ox = x + cx + ttf->face->glyph->bitmap_left;
int oy = y + (ttf->face->height * 14 / ttf->face->units_per_EM) - ttf->face->glyph->bitmap_top + cy + (ttf->face->descender * 14 / ttf->face->units_per_EM);
unsigned char* opx = &px[(oy * tw + ox) * 4];
opx[0] = color->common.red;
opx[1] = color->common.green;
opx[2] = color->common.blue;
opx[3] = bmp->buffer[cy * bmp->pitch + cx];
}
}
x += ttf->face->glyph->metrics.horiAdvance / 64;
}
p = MwLoadRaw(handle, px, tw, th);
r.x = point->x;
r.y = point->y - th / 2;
r.width = tw;
r.height = th;
if(align == MwALIGNMENT_CENTER) {
r.x -= tw / 2;
} else if(align == MwALIGNMENT_END) {
r.x -= tw;
}
MwLLDrawPixmap(handle->lowlevel, &r, p);
MwLLDestroyPixmap(p);
free(px);
return 0;
}
static int ttf_MwTextWidth(MwWidget handle, const char* text) {
ttf_t* ttf = MwGetVoid(handle, MwNfont);
int tw = 0, mtw = 0;
if(ttf == NULL) return -1;
while(text[0] != 0) {
int c;
int l = MwUTF8ToUTF32(text, &c);
if(l <= 0) break;
text += l;
if(c == '\n') {
tw = 0;
continue;
}
FT_Load_Char(ttf->face, c, FT_LOAD_RENDER);
tw += ttf->face->glyph->metrics.horiAdvance / 64;
if(tw > mtw) mtw = tw;
}
return mtw;
}
static int ttf_MwTextHeight(MwWidget handle, int count) {
ttf_t* ttf = MwGetVoid(handle, MwNfont);
if(ttf == NULL) return -1;
return (ttf->face->height * 14 / ttf->face->units_per_EM) * count;
}
#endif
void MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color) {
if(strlen(text) == 0) return;
#ifdef TTF
if(ttf_MwDrawText(handle, point, text, bold, align, color))
#endif
bitmap_MwDrawText(handle, point, text, bold, align, color);
}
int MwTextWidth(MwWidget handle, const char* text) {
/* TODO: check newline */
#ifdef TTF
int st;
if((st = ttf_MwTextWidth(handle, text)) != -1) return st;
#else
(void)handle;
#endif
return MwUTF8Length(text) * FontWidth;
}
int MwTextHeight(MwWidget handle, const char* text) {
int c = 1;
int i = 0;
#ifdef TTF
int st;
#endif
(void)handle;
(void)text;
while(text[i] != 0) {
int out;
int l = MwUTF8ToUTF32(text + i, &out);
if(l == 0) break;
i += l;
if(out == '\n') c++;
}
#ifdef TTF
if((st = ttf_MwTextHeight(handle, c)) != -1) return st;
#endif
return FontHeight * c;
}
void* MwFontLoad(unsigned char* data, unsigned int size) {
#if defined(USE_FREETYPE2)
ttf_t* ttf = malloc(sizeof(*ttf));
ttf->data = malloc(size);
memcpy(ttf->data, data, size);
FT_Init_FreeType(&ttf->library);
FT_New_Memory_Face(ttf->library, ttf->data, size, 0, &ttf->face);
FT_Set_Pixel_Sizes(ttf->face, 0, 14);
return ttf;
#elif defined(USE_STB_TRUETYPE)
ttf_t* ttf = malloc(sizeof(*ttf));
ttf->data = malloc(size);
memcpy(ttf->data, data, size);
stbtt_InitFont(&ttf->font, ttf->data, 0);
ttf->scale = stbtt_ScaleForPixelHeight(&ttf->font, 16);
stbtt_GetFontVMetrics(&ttf->font, &ttf->ascent, &ttf->descent, 0);
return ttf;
#else
(void)data;
(void)size;
return NULL;
#endif
}
void MwFontFree(void* handle) {
#if defined(USE_FREETYPE2)
ttf_t* ttf = handle;
FT_Done_Face(ttf->face);
FT_Done_FreeType(ttf->library);
free(ttf->data);
free(ttf);
#elif defined(USE_STB_TRUETYPE)
ttf_t* ttf = handle;
free(ttf->data);
free(ttf);
#else
(void)handle;
#endif
}

View file

@ -1,7 +1,7 @@
#include <Mw/Milsko.h>
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2)
unsigned char MwBoldTTFData[] = {
unsigned char MwBoldMonospaceTTFData[] = {
0x00, 0x01, 0x00, 0x00, 0x00, 0x11, 0x01, 0x00, 0x00, 0x04, 0x00, 0x10,
0x46, 0x46, 0x54, 0x4d, 0xac, 0x0d, 0xe4, 0x44, 0x00, 0x00, 0x8d, 0x3c,
0x00, 0x00, 0x00, 0x1c, 0x4f, 0x53, 0x2f, 0x32, 0xa4, 0xe6, 0xab, 0x72,
@ -3018,5 +3018,5 @@ unsigned char MwBoldTTFData[] = {
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0xe5, 0x16, 0xe7, 0x6b,
0x00, 0x00, 0x00, 0x00, 0xe1, 0xa9, 0xde, 0x3f, 0x00, 0x00, 0x00, 0x00,
0xe5, 0x4d, 0x1e, 0x99};
unsigned int MwBoldTTFDataSize = 36184;
unsigned int MwBoldMonospaceTTFDataSize = 36184;
#endif

3052
src/text/font/boldttf.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,7 @@
#include <Mw/Milsko.h>
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2)
unsigned char MwTTFData[] = {
unsigned char MwMonospaceTTFData[] = {
0x00, 0x01, 0x00, 0x00, 0x00, 0x11, 0x01, 0x00, 0x00, 0x04, 0x00, 0x10,
0x46, 0x46, 0x54, 0x4d, 0xac, 0x0d, 0xe4, 0x23, 0x00, 0x00, 0x8d, 0x3c,
0x00, 0x00, 0x00, 0x1c, 0x4f, 0x53, 0x2f, 0x32, 0xa3, 0xba, 0xa8, 0x6a,
@ -3018,5 +3018,5 @@ unsigned char MwTTFData[] = {
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0xe5, 0x16, 0xe7, 0x6b,
0x00, 0x00, 0x00, 0x00, 0xe1, 0xa9, 0xde, 0x41, 0x00, 0x00, 0x00, 0x00,
0xe5, 0x4d, 0x1e, 0x76};
unsigned int MwTTFDataSize = 36184;
unsigned int MwMonospaceTTFDataSize = 36184;
#endif

2945
src/text/font/ttf.c Normal file

File diff suppressed because it is too large Load diff

194
src/text/ft2.c Normal file
View file

@ -0,0 +1,194 @@
#ifdef USE_FREETYPE2
#include <Mw/Milsko.h>
#include <ft2build.h>
#include FT_FREETYPE_H
static struct ft_table {
FT_Error (*FT_Init_FreeType)(FT_Library* alibrary);
FT_Error (*FT_New_Memory_Face)(FT_Library library,
const FT_Byte* file_base,
FT_Long file_size,
FT_Long face_index,
FT_Face* aface);
FT_Error (*FT_Set_Pixel_Sizes)(FT_Face face,
FT_UInt pixel_width,
FT_UInt pixel_height);
FT_Error (*FT_Load_Char)(FT_Face face,
FT_ULong char_code,
FT_Int32 load_flags);
FT_Error (*FT_Get_Kerning)(FT_Face face,
FT_UInt left_glyph,
FT_UInt right_glyph,
FT_UInt kern_mode,
FT_Vector* akerning);
FT_Error (*FT_Done_Face)(FT_Face face);
FT_Error (*FT_Done_FreeType)(FT_Library library);
} ft_table;
struct _MwFLFont {
FT_Library library;
FT_Face face;
void* data;
int px;
};
static int ft2_MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text, MwLLColor color) {
int tw, th;
unsigned char* px;
MwLLPixmap p;
MwRect r;
int x = 0, y = 0;
tw = MwTextWidth(handle, ttf, text);
th = MwTextHeight(handle, ttf, text);
px = malloc(tw * th * 4);
memset(px, 0, tw * th * 4);
while(text[0] != 0) {
FT_Bitmap* bmp;
int cy, cx;
int c, c2;
int l = MwUTF8ToUTF32(text, &c);
FT_Vector vec;
const char* old_text;
if(l <= 0) break;
text += l;
if(c == '\n') {
x = 0;
y += ttf->face->height * ttf->px / ttf->face->units_per_EM;
continue;
}
ft_table.FT_Load_Char(ttf->face, c, FT_LOAD_RENDER);
bmp = &ttf->face->glyph->bitmap;
for(cy = 0; cy < bmp->rows; cy++) {
for(cx = 0; cx < bmp->width; cx++) {
int ox = x + (ttf->face->glyph->metrics.horiBearingX / 64) + cx + ttf->face->glyph->bitmap_left;
int oy = y + (ttf->face->height * ttf->px / ttf->face->units_per_EM) - ttf->face->glyph->bitmap_top + cy + (ttf->face->descender * ttf->px / ttf->face->units_per_EM);
unsigned char* opx = &px[(oy * tw + ox) * 4];
opx[0] = color->common.red;
opx[1] = color->common.green;
opx[2] = color->common.blue;
/* overflow check */
if(opx[3] + bmp->buffer[cy * bmp->pitch + cx] < opx[3]) {
opx[3] = 255;
} else {
opx[3] = bmp->buffer[cy * bmp->pitch + cx];
}
}
}
x += (ttf->face->glyph->advance.x >> 6) + (ttf->face->glyph->metrics.horiBearingX >> 6);
old_text = text;
text += MwUTF8ToUTF32(text, &c2);
if(c2 != '\n') {
ft_table.FT_Get_Kerning(ttf->face, c, c2, FT_KERNING_DEFAULT, &vec);
x += vec.x >> 6;
}
text = old_text;
}
p = MwLoadRaw(handle, px, tw, th);
r.x = point->x;
r.y = point->y - th / 2;
r.width = tw;
r.height = th;
MwLLDrawPixmap(handle->lowlevel, &r, p);
MwLLDestroyPixmap(p);
free(px);
return 0;
}
static int ft2_MwTextWidth(MwFLFont ttf, const char* text) {
int tw = 0, mtw = 0;
while(text[0] != 0) {
int c, c2;
FT_Vector vec;
const char* old_text;
text += MwUTF8ToUTF32(text, &c);
if(c == '\n') {
tw = 0;
continue;
}
ft_table.FT_Load_Char(ttf->face, c, FT_LOAD_DEFAULT);
tw += (ttf->face->glyph->advance.x >> 6) + (ttf->face->glyph->metrics.horiBearingX >> 6);
old_text = text;
text += MwUTF8ToUTF32(text, &c2);
if(c2 != '\n') {
ft_table.FT_Get_Kerning(ttf->face, c, c2, FT_KERNING_DEFAULT, &vec);
tw += vec.x >> 6;
}
text = old_text;
if(tw > mtw) mtw = tw;
}
return mtw + 1;
}
static int ft2_MwTextHeight(MwFLFont ttf, int count) {
return ceil((ttf->face->height * ttf->px / ttf->face->units_per_EM) * count);
}
static void* ft2_MwFontLoad(unsigned char* data, unsigned int size, int px) {
MwFLFont ttf = malloc(sizeof(*ttf));
ttf->data = malloc(size);
memcpy(ttf->data, data, size);
ft_table.FT_Init_FreeType(&ttf->library);
ft_table.FT_New_Memory_Face(ttf->library, ttf->data, size, 0, &ttf->face);
ttf->px = px;
ft_table.FT_Set_Pixel_Sizes(ttf->face, 0, ttf->px);
return ttf;
}
static void ft2_MwFontFree(void* handle) {
MwFLFont ttf = handle;
ft_table.FT_Done_Face(ttf->face);
ft_table.FT_Done_FreeType(ttf->library);
free(ttf->data);
free(ttf);
}
int MWFL_FT2Setup(void) {
/* Try and load FreeType2. If it fails, return 1, signifying we default to stbtt. */
void* ftlib;
if(!(ftlib = MwDynamicOpen("libfreetype.so"))) {
return 1;
}
ft_table.FT_Init_FreeType = MwDynamicSymbol(ftlib, "FT_Init_FreeType");
ft_table.FT_New_Memory_Face = MwDynamicSymbol(ftlib, "FT_New_Memory_Face");
ft_table.FT_Set_Pixel_Sizes = MwDynamicSymbol(ftlib, "FT_Set_Pixel_Sizes");
ft_table.FT_Load_Char = MwDynamicSymbol(ftlib, "FT_Load_Char");
ft_table.FT_Get_Kerning = MwDynamicSymbol(ftlib, "FT_Get_Kerning");
ft_table.FT_Done_Face = MwDynamicSymbol(ftlib, "FT_Done_Face");
ft_table.FT_Done_FreeType = MwDynamicSymbol(ftlib, "FT_Done_FreeType");
MwFLDrawText = ft2_MwDrawText;
MwFLTextWidth = ft2_MwTextWidth;
MwFLTextHeight = ft2_MwTextHeight;
MwFLFontLoad = ft2_MwFontLoad;
MwFLFontFree = ft2_MwFontFree;
return 0;
}
#endif

163
src/text/stbtt.c Normal file
View file

@ -0,0 +1,163 @@
#ifdef USE_STB_TRUETYPE
#include <Mw/Milsko.h>
#include "../../external/stb_truetype.h"
struct _MwFLFont {
stbtt_fontinfo font;
void* data;
float scale;
int ascent;
int descent;
};
static int stbtt_MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text, MwLLColor color) {
unsigned char* px;
int tw, th;
MwRect r;
MwLLPixmap p;
int ax, lsb;
int x = 0, y = 0;
tw = MwTextWidth(handle, ttf, text);
th = MwTextHeight(handle, ttf, text);
px = malloc(tw * th * 4);
memset(px, 0, tw * th * 4);
while(text[0] != 0) {
int c, c2;
int x0, y0, x1, y1, cx, cy;
int ow, oh;
unsigned char* out;
int kern;
const char* old_text;
text += MwUTF8ToUTF32(text, &c);
if(c == '\n') {
x = 0;
y += ceil((ttf->ascent - ttf->descent) * ttf->scale);
continue;
}
stbtt_GetCodepointHMetrics(&ttf->font, c, &ax, &lsb);
stbtt_GetCodepointBitmapBox(&ttf->font, c, ttf->scale, ttf->scale, &x0, &y0, &x1, &y1);
ow = x1 - x0;
oh = y1 - y0;
out = malloc(ow * oh);
stbtt_MakeCodepointBitmap(&ttf->font, out, ow, oh, ow, ttf->scale, ttf->scale, c);
for(cy = 0; cy < oh; cy++) {
for(cx = 0; cx < ow; cx++) {
int ox = x + ceil(lsb * ttf->scale) + cx;
int oy = y + ceil(ttf->ascent * ttf->scale) + y0 + cy;
unsigned char* opx = &px[(oy * tw + ox) * 4];
opx[0] = color->common.red;
opx[1] = color->common.green;
opx[2] = color->common.blue;
/* overflow check */
if(opx[3] + out[cy * ow + cx] < opx[3]) {
opx[3] = 255;
} else {
opx[3] = out[cy * ow + cx];
}
}
}
x += ceil(ax * ttf->scale);
old_text = text;
text += MwUTF8ToUTF32(text, &c2);
if(c2 != '\n') {
kern = stbtt_GetCodepointKernAdvance(&ttf->font, c, c2);
x += ceil(kern * ttf->scale);
}
text = old_text;
free(out);
}
p = MwLoadRaw(handle, px, tw, th);
r.x = point->x;
r.y = point->y - th / 2;
r.width = tw;
r.height = th;
MwLLDrawPixmap(handle->lowlevel, &r, p);
MwLLDestroyPixmap(p);
free(px);
return 0;
}
static int stbtt_MwTextWidth(MwFLFont ttf, const char* text) {
int ax, lsb;
int tw = 0, mtw = 0;
while(text[0] != 0) {
int kern;
int c, c2;
const char* old_text;
text += MwUTF8ToUTF32(text, &c);
if(c == '\n') {
tw = 0;
continue;
}
stbtt_GetCodepointHMetrics(&ttf->font, c, &ax, &lsb);
tw += ceil(ax * ttf->scale);
old_text = text;
text += MwUTF8ToUTF32(text, &c2);
if(c2 != '\n') {
kern = stbtt_GetCodepointKernAdvance(&ttf->font, c, c2);
tw += ceil(kern * ttf->scale);
}
text = old_text;
if(tw > mtw) mtw = tw;
}
return mtw + 1;
}
static int stbtt_MwTextHeight(MwFLFont ttf, int count) {
return ceil((ttf->ascent - ttf->descent) * ttf->scale * count);
}
static void* stbtt_MwFontLoad(unsigned char* data, unsigned int size, int px) {
MwFLFont ttf = malloc(sizeof(*ttf));
ttf->data = malloc(size);
memcpy(ttf->data, data, size);
stbtt_InitFont(&ttf->font, ttf->data, 0);
ttf->scale = stbtt_ScaleForMappingEmToPixels(&ttf->font, px);
stbtt_GetFontVMetrics(&ttf->font, &ttf->ascent, &ttf->descent, 0);
return ttf;
}
static void stbtt_MwFontFree(void* handle) {
MwFLFont ttf = handle;
free(ttf->data);
free(ttf);
}
int MwFL_STBTTSetup(void) {
MwFLDrawText = stbtt_MwDrawText;
MwFLTextWidth = stbtt_MwTextWidth;
MwFLTextHeight = stbtt_MwTextHeight;
MwFLFontLoad = stbtt_MwFontLoad;
MwFLFontFree = stbtt_MwFontFree;
return 0;
}
#endif

204
src/text/text.c Normal file
View file

@ -0,0 +1,204 @@
#include <Mw/Milsko.h>
int (*MwFLDrawText)(MwWidget handle, MwFLFont font, MwPoint* point, const char* text, MwLLColor color) = NULL;
int (*MwFLTextWidth)(MwFLFont font, const char* text) = NULL;
int (*MwFLTextHeight)(MwFLFont font, int count) = NULL;
void* (*MwFLFontLoad)(unsigned char* data, unsigned int size, int px) = NULL;
void (*MwFLFontFree)(void* handle) = NULL;
#if defined(USE_FREETYPE2) || defined(USE_STB_TRUETYPE)
#define TTF
#endif
#define FontWidth 7
#define FontHeight 14
static void bitmap_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, MwLLColor color);
static int is_bold(MwWidget handle, MwFLFont ttf) {
size_t u = (size_t)ttf;
int s;
if(u & MwFLFlagBold) return 1;
s = MwGetInteger(handle, MwNbold);
if(s == MwDEFAULT) return 0;
return s;
}
#ifdef TTF
static int is_monospace(MwWidget handle, MwFLFont ttf) {
size_t u = (size_t)ttf;
int s;
if(u & MwFLFlagMonospace) return 1;
s = MwGetInteger(handle, MwNuseMonospace);
if(s == MwDEFAULT) return 0;
return s;
}
#endif
#ifdef TTF
static MwFLFont assume_ttf(MwWidget handle, MwFLFont ttf) {
if(MwGetInteger(handle, MwNbitmapFont)) return NULL;
if(is_monospace(handle, ttf)) return is_bold(handle, ttf) ? MwGetVoid(handle, MwNboldMonospaceFont) : MwGetVoid(handle, MwNmonospaceFont);
return is_bold(handle, ttf) ? MwGetVoid(handle, MwNboldFont) : MwGetVoid(handle, MwNfont);
}
#endif
void MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text, int align, MwLLColor color) {
MwPoint p = *point;
if(strlen(text) == 0) return;
#ifdef TTF
if(ttf <= MwFLBuildFont(0xff)) ttf = assume_ttf(handle, ttf);
#endif
if(align == MwALIGNMENT_CENTER) {
p.x -= MwTextWidth(handle, ttf, text) / 2;
} else if(align == MwALIGNMENT_END) {
p.x -= MwTextWidth(handle, ttf, text);
}
#ifdef TTF
if(MwFLDrawText)
if(MwGetInteger(handle, MwNbitmapFont) || ttf == NULL || MwFLDrawText(handle, ttf, &p, text, color))
#endif
bitmap_MwDrawText(handle, &p, text, is_bold(handle, ttf), color);
}
int MwTextWidth(MwWidget handle, MwFLFont ttf, const char* text) {
/* TODO: check newline */
#ifdef TTF
int st;
if(ttf <= MwFLBuildFont(0xff)) ttf = assume_ttf(handle, ttf);
if(MwFLTextWidth)
if(!MwGetInteger(handle, MwNbitmapFont) && ttf != NULL && (st = MwFLTextWidth(ttf, text)) != -1) return st;
#else
(void)handle;
(void)ttf;
#endif
return MwUTF8Length(text) * FontWidth;
}
int MwTextHeight(MwWidget handle, MwFLFont ttf, const char* text) {
int c = 1;
int i = 0;
#ifdef TTF
int st;
#endif
#ifdef TTF
if(ttf <= MwFLBuildFont(0xff)) ttf = assume_ttf(handle, ttf);
#else
(void)handle;
(void)text;
(void)ttf;
#endif
while(text[i] != 0) {
int out;
int l = MwUTF8ToUTF32(text + i, &out);
if(l == 0) break;
i += l;
if(out == '\n') c++;
}
#ifdef TTF
if(MwFLTextHeight)
if(!MwGetInteger(handle, MwNbitmapFont) && ttf != NULL && (st = MwFLTextHeight(ttf, c)) != -1) return st;
#endif
return FontHeight * c;
}
void* MwFontLoad(unsigned char* data, unsigned int size) {
if(MwFLFontLoad)
return MwFLFontLoad(data, size, 14);
return NULL;
}
void MwFontFree(void* handle) {
if(MwFLFontFree) MwFLFontFree(handle);
}
static void bitmap_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, MwLLColor color) {
int i = 0, x, y, sx, sy;
int tw, th;
unsigned char* px;
MwRect r;
MwLLPixmap p;
if(strlen(text) == 0) text = " ";
tw = MwTextWidth(handle, NULL, text);
th = MwTextHeight(handle, NULL, text);
px = malloc(tw * th * 4);
memset(px, 0, tw * th * 4);
sx = 0;
sy = 0;
while(text[i] != 0) {
int out;
i += MwUTF8ToUTF32(text + i, &out);
if(out > 0xff) {
out = 0;
}
if(out == '\n') {
sx = 0;
sy += FontHeight;
} else {
for(y = 0; y < FontHeight; y++) {
for(x = 0; x < FontWidth; x++) {
unsigned char* ppx = &px[((sy + y) * tw + sx + x) * 4];
if((bold ? MwBoldFontData : MwFontData)[out].data[y] & (1 << ((FontWidth - 1) - x))) {
ppx[0] = color->common.red;
ppx[1] = color->common.green;
ppx[2] = color->common.blue;
ppx[3] = 255;
} else {
ppx[0] = 0;
ppx[1] = 0;
ppx[2] = 0;
ppx[3] = 0;
}
}
}
sx += FontWidth;
}
}
p = MwLoadRaw(handle, px, tw, th);
r.x = point->x;
r.y = point->y - th / 2;
r.width = tw;
r.height = th;
MwLLDrawPixmap(handle->lowlevel, &r, p);
MwLLDestroyPixmap(p);
free(px);
}
typedef int (*call_t)(void);
void MwFLSetup(void) {
call_t calls[] = {
#ifdef USE_FREETYPE2
MWFL_FT2Setup,
#endif
#ifdef USE_STB_TRUETYPE
MwFL_STBTTSetup,
#endif
NULL};
int i;
for(i = 0; calls[i] != NULL; i++) {
if(calls[i]() == 0) return;
}
}

View file

@ -2,27 +2,28 @@
#include "../../external/stb_ds.h"
static int create(MwWidget handle) {
static int wcreate(MwWidget handle) {
MwBox b = malloc(sizeof(*b));
memset(b, 0, sizeof(*b));
handle->internal = b;
MwSetDefault(handle);
MwSetInteger(handle, MwNorientation, MwHORIZONTAL);
MwSetInteger(handle, MwNmargin, 0);
MwSetInteger(handle, MwNpadding, 0);
MwSetInteger(handle, MwNhasBorder, 0);
MwSetInteger(handle, MwNinverted, 1);
b->layout = 0;
return 0;
}
static void draw(MwWidget handle) {
MwRect r;
MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground));
r.x = 0;
r.y = 0;
r.width = MwGetInteger(handle, MwNwidth);
r.height = MwGetInteger(handle, MwNheight);
MwDrawRect(handle, &r, base);
MwLLFreeColor(base);
static void destroy(MwWidget handle) {
MwBox b = handle->internal;
free(b);
}
#define Margin ((i != (arrlen(handle->children) - 1)) ? MwGetInteger(handle, MwNmargin) : 0)
@ -31,19 +32,22 @@ static void layout(MwWidget handle) {
int i;
int sum = 0;
int horiz = MwGetInteger(handle, MwNorientation) == MwHORIZONTAL ? 1 : 0;
int sz = MwGetInteger(handle, horiz ? MwNwidth : MwNheight) - MwGetInteger(handle, MwNpadding) * 2;
int fsz = MwGetInteger(handle, horiz ? MwNheight : MwNwidth) - MwGetInteger(handle, MwNpadding) * 2;
int sk = MwGetInteger(handle, MwNpadding);
int sz = MwGetInteger(handle, horiz ? MwNwidth : MwNheight) - (MwGetInteger(handle, MwNpadding) + (MwGetInteger(handle, MwNhasBorder) ? MwDefaultBorderWidth(handle) : 0)) * 2;
int fsz = MwGetInteger(handle, horiz ? MwNheight : MwNwidth) - (MwGetInteger(handle, MwNpadding) + (MwGetInteger(handle, MwNhasBorder) ? MwDefaultBorderWidth(handle) : 0)) * 2;
int sk = MwGetInteger(handle, MwNpadding) + (MwGetInteger(handle, MwNhasBorder) ? MwDefaultBorderWidth(handle) : 0);
for(i = 0; i < arrlen(handle->children); i++) {
int n = MwGetInteger(handle->children[i], MwNratio);
int s = MwGetInteger(handle->children[i], MwNfixedSize);
if(n == MwDEFAULT) n = 1;
if(handle->children[i]->destroyed) continue;
if(s != MwDEFAULT) {
sz -= s + Margin;
} else {
sum += n;
sz -= Margin;
}
}
@ -53,16 +57,17 @@ static void layout(MwWidget handle) {
int wsz;
if(n == MwDEFAULT) n = 1;
if(handle->children[i]->destroyed) continue;
if(s != MwDEFAULT) {
wsz = s;
} else {
wsz = sz * n / sum;
}
wsz -= Margin;
MwVaApply(handle->children[i],
horiz ? MwNx : MwNy, sk, /* this is what gets changed */
horiz ? MwNy : MwNx, MwGetInteger(handle, MwNpadding), /* fixed between widgets */
horiz ? MwNy : MwNx, MwGetInteger(handle, MwNpadding) + (MwGetInteger(handle, MwNhasBorder) ? MwDefaultBorderWidth(handle) : 0), /* fixed between widgets */
horiz ? MwNwidth : MwNheight, wsz, /* this is what gets changed */
horiz ? MwNheight : MwNwidth, fsz, /* fixed between widgets */
NULL);
@ -70,27 +75,68 @@ static void layout(MwWidget handle) {
}
}
static void draw(MwWidget handle) {
MwRect r;
MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground));
MwBox b = handle->internal;
r.x = 0;
r.y = 0;
r.width = MwGetInteger(handle, MwNwidth);
r.height = MwGetInteger(handle, MwNheight);
if(MwGetInteger(handle, MwNhasBorder)) {
MwDrawFrame(handle, &r, base, MwGetInteger(handle, MwNinverted));
}
MwDrawRect(handle, &r, base);
MwLLFreeColor(base);
if(b->layout) {
layout(handle);
b->layout = 0;
}
}
static void prop_change(MwWidget handle, const char* key) {
if(strcmp(key, MwNorientation) == 0) layout(handle);
if(strcmp(key, MwNorientation) == 0) {
MwBox b = handle->internal;
b->layout = 1;
MwForceRender(handle);
}
}
static void children_prop_change(MwWidget handle, MwWidget child, const char* key) {
(void)child;
if(strcmp(key, MwNratio) == 0 || strcmp(key, MwNfixedSize) == 0) layout(handle);
if(strcmp(key, MwNratio) == 0 || strcmp(key, MwNfixedSize) == 0) {
MwBox b = handle->internal;
b->layout = 1;
MwForceRender(handle);
}
}
static void resize(MwWidget handle) {
layout(handle);
MwBox b = handle->internal;
b->layout = 1;
MwForceRender(handle);
}
static void children_update(MwWidget handle) {
layout(handle);
MwBox b = handle->internal;
b->layout = 1;
MwForceRender(handle);
}
MwClassRec MwBoxClassRec = {
create, /* create */
NULL, /* destroy */
wcreate, /* create */
destroy, /* destroy */
draw, /* draw */
NULL, /* click */
NULL, /* parent_resize */
@ -104,7 +150,7 @@ MwClassRec MwBoxClassRec = {
resize, /* resize */
children_update, /* children_update */
children_prop_change, /* children_prop_change */
NULL,
NULL, /* clipboard */
NULL,
NULL,
NULL,

View file

@ -1,11 +1,14 @@
#include <Mw/Milsko.h>
static int create(MwWidget handle) {
#include "../../external/stb_ds.h"
static int wcreate(MwWidget handle) {
MwSetDefault(handle);
MwSetInteger(handle, MwNflat, 0);
MwSetInteger(handle, MwNpadding, 0);
MwSetInteger(handle, MwNfillArea, 1);
MwSetInteger(handle, MwNroundness, 5);
return 0;
}
@ -18,6 +21,7 @@ static void draw(MwWidget handle) {
const char* str = MwGetText(handle, MwNtext);
MwLLPixmap px = MwGetVoid(handle, MwNpixmap);
MwLLPixmap bgpx = MwGetVoid(handle, MwNbackgroundPixmap);
int inv;
if(str == NULL) str = "";
@ -27,7 +31,7 @@ static void draw(MwWidget handle) {
r.height = MwGetInteger(handle, MwNheight);
if(MwGetInteger(handle, MwNflat)) {
if(handle->pressed) {
if(handle->pressed || ((inv = MwGetInteger(handle, MwNforceInverted)) != MwDEFAULT && inv)) {
MwDrawWidgetBack(handle, &r, base, handle->pressed, 1);
} else {
MwDrawRect(handle, &r, base);
@ -36,7 +40,7 @@ static void draw(MwWidget handle) {
MwDrawWidgetBack(handle, &r, base, handle->pressed, 1);
}
if(bgpx != NULL) MwLLDrawPixmap(handle->lowlevel, &r, bgpx);
if(MwGetInteger(handle, MwNflat) && !handle->pressed) {
if(MwGetInteger(handle, MwNflat) && !(handle->pressed || ((inv = MwGetInteger(handle, MwNforceInverted)) != MwDEFAULT && inv))) {
r.x += MwDefaultBorderWidth(handle);
r.y += MwDefaultBorderWidth(handle);
r.width -= MwDefaultBorderWidth(handle) * 2;
@ -73,7 +77,7 @@ static void draw(MwWidget handle) {
point.x = r.x + r.width / 2;
point.y = r.x + r.height / 2;
MwDrawText(handle, &point, str, 0, MwALIGNMENT_CENTER, text);
MwDrawText(handle, NULL, &point, str, MwALIGNMENT_CENTER, text);
}
MwLLFreeColor(text);
@ -89,7 +93,7 @@ static void prop_change(MwWidget handle, const char* key) {
}
MwClassRec MwButtonClassRec = {
create, /* create */
wcreate, /* create */
NULL, /* destroy */
draw, /* draw */
click, /* click */
@ -104,7 +108,7 @@ MwClassRec MwButtonClassRec = {
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL,
NULL, /* clipboard */
NULL,
NULL,
NULL,

View file

@ -1,6 +1,6 @@
#include <Mw/Milsko.h>
static int create(MwWidget handle) {
static int wcreate(MwWidget handle) {
MwSetDefault(handle);
MwSetInteger(handle, MwNchecked, 0);
@ -38,7 +38,7 @@ static void prop_change(MwWidget handle, const char* key) {
}
MwClassRec MwCheckBoxClassRec = {
create, /* create */
wcreate, /* create */
NULL, /* destroy */
draw, /* draw */
click, /* click */
@ -53,7 +53,7 @@ MwClassRec MwCheckBoxClassRec = {
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL,
NULL, /* clipboard */
NULL,
NULL,
NULL,

View file

@ -2,7 +2,7 @@
#include "../../external/stb_ds.h"
static int create(MwWidget handle) {
static int wcreate(MwWidget handle) {
MwComboBox cb = malloc(sizeof(*cb));
cb->list = NULL;
@ -51,7 +51,7 @@ static void draw(MwWidget handle) {
p.x = MwDefaultBorderWidth(handle) * 2 + 4;
p.y = MwGetInteger(handle, MwNheight) / 2;
MwDrawText(handle, &p, cb->list[MwGetInteger(handle, MwNvalue)], 0, MwALIGNMENT_BEGINNING, text);
MwDrawText(handle, NULL, &p, cb->list[MwGetInteger(handle, MwNvalue)], MwALIGNMENT_BEGINNING, text);
}
r = rc;
@ -89,7 +89,7 @@ static void listbox_activate(MwWidget handle, void* user, void* client) {
MwForceRender(handle->parent);
MwDispatchUserHandler(handle->parent, MwNchangedHandler, client);
MwDispatchUserHandler(handle->parent, MwNcomboBoxChangedHandler, client);
MwDestroyWidget(handle);
}
@ -115,11 +115,11 @@ static void click(MwWidget handle) {
MwLLSetCursor(handle->lowlevel, &MwCursorArrow, &MwCursorArrowMask);
for(i = 0; i < arrlen(cb->list); i++) {
int l = MwTextWidth(handle, cb->list[i]) + MwDefaultBorderWidth(handle) * 2;
int l = MwTextWidth(handle, NULL, cb->list[i]) + MwDefaultBorderWidth(handle) * 2;
if(l > width) width = l;
}
cb->listbox = MwVaCreateWidget(MwListBoxClass, "listbox", handle, 0, MwGetInteger(handle, MwNheight), width, MwTextHeight(handle, "M") * ent + MwDefaultBorderWidth(handle) * 2 + MwTextHeight(handle, "M") / 4,
cb->listbox = MwVaCreateWidget(MwListBoxClass, "listbox", handle, 0, MwGetInteger(handle, MwNheight), width, MwTextHeight(handle, NULL, "M") * ent + MwDefaultBorderWidth(handle) * 2 + MwTextHeight(handle, NULL, "M") / 4,
MwNsingleClickSelectable, 1,
NULL);
@ -189,7 +189,7 @@ static void func_handler(MwWidget handle, const char* name, void* out, va_list v
}
MwClassRec MwComboBoxClassRec = {
create, /* create */
wcreate, /* create */
destroy, /* destroy */
draw, /* draw */
click, /* click */
@ -204,7 +204,7 @@ MwClassRec MwComboBoxClassRec = {
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL,
NULL, /* clipboard */
NULL,
NULL,
NULL,

View file

@ -1,6 +1,6 @@
#include <Mw/Milsko.h>
static int create(MwWidget handle) {
static int wcreate(MwWidget handle) {
MwEntry t = malloc(sizeof(*t));
t->cursor = 0;
@ -11,6 +11,7 @@ static int create(MwWidget handle) {
MwSetDefault(handle);
MwLLSetCursor(handle->lowlevel, &MwCursorText, &MwCursorTextMask);
MwSetInteger(handle, MwNroundness, 5);
return 0;
}
@ -26,6 +27,7 @@ static void draw(MwWidget handle) {
MwLLColor text = MwParseColor(handle, MwGetText(handle, MwNforeground));
const char* str = MwGetText(handle, MwNtext);
MwLLPixmap bgpx = MwGetVoid(handle, MwNbackgroundPixmap);
MwFLFont font = MwFLBuildFont(MwFLFlagMonospace);
if(str == NULL) str = "";
r.x = 0;
@ -36,8 +38,8 @@ static void draw(MwWidget handle) {
MwDrawWidgetBack(handle, &r, base, 1, 1);
if(bgpx != NULL) MwLLDrawPixmap(handle->lowlevel, &r, bgpx);
if(str != NULL) {
int w = MwTextWidth(handle, "M");
int h = MwTextHeight(handle, "M");
int w = MwTextWidth(handle, font, "M");
int h = MwTextHeight(handle, font, "M");
MwPoint p;
char* show;
int len;
@ -52,6 +54,7 @@ static void draw(MwWidget handle) {
len = (r.width - p.x * 2) / w;
if(len > 0) {
show = malloc(len * 4 + 1);
memset(show, 0, len * 4 + 1);
@ -63,13 +66,13 @@ static void draw(MwWidget handle) {
for(i = 0; i < MwUTF8Length(str) - start; i++) show[i] = '*';
}
MwDrawText(handle, &p, show, 0, MwALIGNMENT_BEGINNING, text);
MwDrawText(handle, font, &p, show, MwALIGNMENT_BEGINNING, text);
textlen = (t->cursor - 1) % len + 1;
for(i = 0; i < textlen; i++) show[i] = 'M';
show[i] = 0;
currc.x = p.x + MwTextWidth(handle, show);
currc.x = p.x + MwTextWidth(handle, font, show);
currc.y = (r.height - h) / 2;
currc.width = 1;
currc.height = h;
@ -77,6 +80,7 @@ static void draw(MwWidget handle) {
free(show);
}
}
MwLLFreeColor(text);
MwLLFreeColor(base);
@ -109,20 +113,7 @@ static void key(MwWidget handle, int code) {
} else if(code == MwLLKeyEnter) {
MwDispatchUserHandler(handle, MwNactivateHandler, NULL);
} else if(code == (MwLLControlMask | 'v')) {
char* c = MwLLGetClipboard(handle->lowlevel);
if(c != NULL) {
char* out = malloc(strlen(str) + strlen(c) + 1);
MwUTF8Copy(str, 0, out, 0, t->cursor);
MwUTF8Copy(c, 0, out, t->cursor, MwUTF8Length(c));
MwUTF8Copy(str, t->cursor, out, t->cursor + MwUTF8Length(c), MwUTF8Length(str) - t->cursor);
t->cursor += MwUTF8Length(c);
MwSetText(handle, MwNtext, out);
free(out);
free(c);
}
MwLLGetClipboard(handle->lowlevel, MwCLIPBOARD_MAIN);
} else if(!(code & MwLLKeyMask)) {
int incr = 0;
out = malloc(strlen(str) + 5 + 1);
@ -142,6 +133,20 @@ static void key(MwWidget handle, int code) {
MwForceRender(handle);
}
#if defined(USE_X11) || defined(USE_WAYLAND)
static void mouse_up(MwWidget handle, void* ptr) {
if(handle->lowlevel->common.type == MwLLBackendWayland || handle->lowlevel->common.type == MwLLBackendX11) {
MwMouse* mouse = ptr;
if(mouse->button == MwMOUSE_MIDDLE) {
MwLLGetClipboard(handle->lowlevel, MwCLIPBOARD_PRIMARY);
}
}
MwForceRender2(handle, NULL);
}
#else
#define mouse_up MwForceRender2
#endif
static void prop_change(MwWidget handle, const char* prop) {
if(strcmp(prop, MwNtext) == 0 || strcmp(prop, MwNhideInput) == 0) MwForceRender(handle);
@ -157,15 +162,38 @@ static void prop_change(MwWidget handle, const char* prop) {
}
}
static void clipboard(MwWidget handle, const char* data) {
MwEntry t = handle->internal;
const char* str = MwGetText(handle, MwNtext);
char* out;
if(!str) {
str = "";
}
out = malloc(strlen(str) + strlen(data) + 1);
if(str == NULL) str = "";
MwUTF8Copy(str, 0, out, 0, t->cursor);
MwUTF8Copy(data, 0, out, t->cursor, MwUTF8Length(data));
MwUTF8Copy(str, t->cursor, out, t->cursor + MwUTF8Length(data), MwUTF8Length(str) - t->cursor);
t->cursor += MwUTF8Length(data);
MwSetText(handle, MwNtext, out);
free(out);
MwForceRender(handle);
}
MwClassRec MwEntryClassRec = {
create, /* create */
wcreate, /* create */
destroy, /* destroy */
draw, /* draw */
NULL, /* click */
NULL, /* parent_resize */
prop_change, /* prop_change */
NULL, /* mouse_move */
MwForceRender2, /* mouse_up */
mouse_up, /* mouse_up */
MwForceRender2, /* mouse_down */
key, /* key */
NULL, /* execute */
@ -173,7 +201,7 @@ MwClassRec MwEntryClassRec = {
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL,
clipboard, /* clipboard */
NULL,
NULL,
NULL,

View file

@ -1,6 +1,6 @@
#include <Mw/Milsko.h>
static int create(MwWidget handle) {
static int wcreate(MwWidget handle) {
MwSetDefault(handle);
MwSetInteger(handle, MwNhasBorder, 0);
@ -29,7 +29,6 @@ static void draw(MwWidget handle) {
rr.width = MwGetInteger(handle, MwNwidth) - (MwDefaultBorderWidth(handle) * 2);
rr.height = MwGetInteger(handle, MwNheight) - (MwDefaultBorderWidth(handle) * 2);
} else {
rr.x = 0;
rr.y = 0;
rr.width = MwGetInteger(handle, MwNwidth);
@ -47,7 +46,7 @@ static void prop_change(MwWidget handle, const char* key) {
}
MwClassRec MwFrameClassRec = {
create, /* create */
wcreate, /* create */
NULL, /* destroy */
draw, /* draw */
NULL, /* click */
@ -62,7 +61,7 @@ MwClassRec MwFrameClassRec = {
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL,
NULL, /* clipboard */
NULL,
NULL,
NULL,

View file

@ -1,10 +1,11 @@
#include <Mw/Milsko.h>
static int create(MwWidget handle) {
static int wcreate(MwWidget handle) {
MwSetDefault(handle);
MwSetInteger(handle, MwNhasBorder, 0);
MwSetInteger(handle, MwNinverted, 1);
MwSetInteger(handle, MwNfillArea, 1);
return 0;
}
@ -23,6 +24,13 @@ static void draw(MwWidget handle) {
MwDrawRect(handle, &r, base);
if(px != NULL) {
if(!MwGetInteger(handle, MwNfillArea)) {
r.x = (r.width - px->common.width) / 2;
r.y = (r.height - px->common.height) / 2;
r.width = px->common.width;
r.height = px->common.height;
}
MwLLDrawPixmap(handle->lowlevel, &r, px);
}
@ -34,7 +42,7 @@ static void prop_change(MwWidget handle, const char* key) {
}
MwClassRec MwImageClassRec = {
create, /* create */
wcreate, /* create */
NULL, /* destroy */
draw, /* draw */
NULL, /* click */
@ -49,7 +57,7 @@ MwClassRec MwImageClassRec = {
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL,
NULL, /* clipboard */
NULL,
NULL,
NULL,

View file

@ -1,21 +1,139 @@
#include <Mw/Milsko.h>
static int create(MwWidget handle) {
#include "../../external/stb_ds.h"
#define Spacing 1
static int wcreate(MwWidget handle) {
MwLabel lab = malloc(sizeof(*lab));
lab->segment = NULL;
handle->internal = lab;
MwSetDefault(handle);
MwSetInteger(handle, MwNalignment, MwALIGNMENT_CENTER);
MwSetInteger(handle, MwNbold, 0);
MwSetInteger(handle, MwNsevenSegment, 0);
MwSetInteger(handle, MwNlength, 4);
MwSetInteger(handle, MwNleftPadding, 0);
return 0;
}
static void destroy(MwWidget handle) {
MwLabel lab = handle->internal;
hmfree(lab->segment);
free(handle->internal);
}
static void draw_v(MwWidget handle, unsigned char* raw, int x, int y, int stride, MwLLColor text) {
int cy, cx, b;
int l_one = MwGetInteger(handle, MwNlength) - (MwGetInteger(handle, MwNlength) % 2);
int s_one = (l_one * 3 / 4) - ((l_one * 3 / 4) % 2) + 1;
for(cy = y; cy < y + l_one; cy++) {
for(cx = x; cx < x + s_one; cx++) {
unsigned char* px = &raw[(cy * stride + cx) * 4];
px[0] = text->common.red;
px[1] = text->common.green;
px[2] = text->common.blue;
px[3] = 255;
}
}
b = y - (s_one - 1) / 2;
for(cy = b; cy < b + (s_one - 1) / 2; cy++) {
int w = (cy - b) * 2 + 1;
int b2 = x + (s_one - w) / 2;
for(cx = b2; cx < b2 + w; cx++) {
unsigned char* px;
px = &raw[(cy * stride + cx) * 4];
px[0] = text->common.red;
px[1] = text->common.green;
px[2] = text->common.blue;
px[3] = 255;
}
}
b = y + l_one;
for(cy = b; cy < b + (s_one - 1) / 2; cy++) {
int w = ((s_one - 1) / 2 - 1 - (cy - b)) * 2 + 1;
int b2 = x + (s_one - w) / 2;
for(cx = b2; cx < b2 + w; cx++) {
unsigned char* px;
px = &raw[(cy * stride + cx) * 4];
px[0] = text->common.red;
px[1] = text->common.green;
px[2] = text->common.blue;
px[3] = 255;
}
}
}
static void draw_h(MwWidget handle, unsigned char* raw, int x, int y, int stride, MwLLColor text) {
int cy, cx, b;
int l_one = MwGetInteger(handle, MwNlength) - (MwGetInteger(handle, MwNlength) % 2);
int s_one = (l_one * 3 / 4) - ((l_one * 3 / 4) % 2) + 1;
for(cx = x; cx < x + l_one; cx++) {
for(cy = y; cy < y + s_one; cy++) {
unsigned char* px = &raw[(cy * stride + cx) * 4];
px[0] = text->common.red;
px[1] = text->common.green;
px[2] = text->common.blue;
px[3] = 255;
}
}
b = x - (s_one - 1) / 2;
for(cx = b; cx < b + (s_one - 1) / 2; cx++) {
int w = (cx - b) * 2 + 1;
int b2 = y + (s_one - w) / 2;
for(cy = b2; cy < b2 + w; cy++) {
unsigned char* px;
px = &raw[(cy * stride + cx) * 4];
px[0] = text->common.red;
px[1] = text->common.green;
px[2] = text->common.blue;
px[3] = 255;
}
}
b = x + l_one;
for(cx = b; cx < b + (s_one - 1) / 2; cx++) {
int w = ((s_one - 1) / 2 - 1 - (cx - b)) * 2 + 1;
int b2 = y + (s_one - w) / 2;
for(cy = b2; cy < b2 + w; cy++) {
unsigned char* px;
px = &raw[(cy * stride + cx) * 4];
px[0] = text->common.red;
px[1] = text->common.green;
px[2] = text->common.blue;
px[3] = 255;
}
}
}
static void draw(MwWidget handle) {
MwRect r;
MwPoint p;
MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground));
MwLLColor text = MwParseColor(handle, MwGetText(handle, MwNforeground));
MwLLColor shadow = MwLightenColor(handle, base, MwDefaultShadow, MwDefaultShadow, MwDefaultShadow);
int align;
const char* str = MwGetText(handle, MwNtext);
MwLLPixmap bgpx = MwGetVoid(handle, MwNbackgroundPixmap);
MwLabel lab = handle->internal;
int l_one = MwGetInteger(handle, MwNlength) - (MwGetInteger(handle, MwNlength) % 2);
int s_one = (l_one * 3 / 4) - ((l_one * 3 / 4) % 2) + 1;
if(str == NULL) str = "";
@ -28,27 +146,222 @@ static void draw(MwWidget handle) {
if(bgpx != NULL) MwLLDrawPixmap(handle->lowlevel, &r, bgpx);
align = MwGetInteger(handle, MwNalignment);
if(MwGetInteger(handle, MwNsevenSegment)) {
MwLLPixmap px;
unsigned char* raw;
int w = 0, h = s_one * 3 + l_one * 2, i;
int x = 0;
/* so - this mode cannot do unicode.
* but you wouldn't show unicode on 7 segment anyways
*/
/* L
* S <--->
*
* S
* ^
* |
* L |
* |
* v
*/
for(i = 0; (hmgeti(lab->segment, i) != -1) || str[i] != 0; i++) {
if(i > 0 && ((hmgeti(lab->segment, i) != -1) || str[i] != '.')) w += Spacing;
if(hmgeti(lab->segment, i) != -1 || ('0' <= str[i] && str[i] <= '9') || ('A' <= str[i] && str[i] <= 'F') || ('a' <= str[i] && str[i] <= 'f')) {
w += l_one + s_one * 2;
} else if(str[i] == ':' || str[i] == ' ') {
w += s_one;
}
}
w++;
h++;
raw = malloc(w * h * 4);
memset(raw, 0, w * h * 4);
for(i = 0; (hmgeti(lab->segment, i) != -1) || str[i] != 0; i++) {
if((hmgeti(lab->segment, i) != -1) || ('0' <= str[i] && str[i] <= '9') || ('A' <= str[i] && str[i] <= 'F') || ('a' <= str[i] && str[i] <= 'f')) {
int la = 0, lb = 0, lc = 0, ld = 0, le = 0, lf = 0, lg = 0;
int j;
/* https://en.wikipedia.org/wiki/File:7_Segment_Display_with_Labeled_Segments.svg */
if(hmgeti(lab->segment, i) != -1) {
unsigned char c = hmget(lab->segment, i);
if(c & (1 << 0)) la = 1;
if(c & (1 << 1)) lb = 1;
if(c & (1 << 2)) lc = 1;
if(c & (1 << 3)) ld = 1;
if(c & (1 << 4)) le = 1;
if(c & (1 << 5)) lf = 1;
if(c & (1 << 6)) lg = 1;
} else {
if(str[i] == '0') {
la = lb = lc = ld = le = lf = 1;
} else if(str[i] == '1') {
lb = lc = 1;
} else if(str[i] == '2') {
la = lb = ld = le = lg = 1;
} else if(str[i] == '3') {
la = lb = lc = ld = lg = 1;
} else if(str[i] == '4') {
lb = lc = lf = lg = 1;
} else if(str[i] == '5') {
la = lc = ld = lf = lg = 1;
} else if(str[i] == '6') {
la = lc = ld = le = lf = lg = 1;
} else if(str[i] == '7') {
la = lb = lc = 1;
} else if(str[i] == '8') {
la = lb = lc = ld = le = lf = lg = 1;
} else if(str[i] == '9') {
la = lb = lc = ld = lf = lg = 1;
} else if(str[i] == 'A' || str[i] == 'a') {
la = lb = lc = le = lf = lg = 1;
} else if(str[i] == 'B' || str[i] == 'b') {
lc = ld = le = lf = lg = 1;
} else if(str[i] == 'C' || str[i] == 'c') {
ld = le = lg = 1;
} else if(str[i] == 'D' || str[i] == 'd') {
lb = lc = ld = le = lg = 1;
} else if(str[i] == 'E' || str[i] == 'e') {
la = ld = le = lf = lg = 1;
} else if(str[i] == 'F' || str[i] == 'f') {
la = le = lf = lg = 1;
}
}
for(j = 1; j >= 0; j--) {
MwLLColor cl = j == 1 ? shadow : text;
if(la) draw_h(handle, raw, x + s_one + j, j, w, cl);
if(lb) draw_v(handle, raw, x + s_one + l_one + j, s_one + j, w, cl);
if(lc) draw_v(handle, raw, x + s_one + l_one + j, s_one * 2 + l_one + j, w, cl);
if(ld) draw_h(handle, raw, x + s_one + j, s_one * 2 + l_one * 2 + j, w, cl);
if(le) draw_v(handle, raw, x + j, s_one * 2 + l_one + j, w, cl);
if(lf) draw_v(handle, raw, x + j, s_one + j, w, cl);
if(lg) draw_h(handle, raw, x + s_one + j, s_one + l_one + j, w, cl);
}
x += l_one + s_one * 2;
} else if(str[i] == ':') {
int cy, cx;
int j;
for(j = 1; j >= 0; j--) {
MwLLColor cl = j == 1 ? shadow : text;
for(cy = 1; cy < h - 1; cy++) {
int h = s_one / 2;
int c = (l_one - h) / 2 + s_one;
int c1 = (c <= cy && cy <= (c + h)) ? 1 : 0;
int c2 = ((s_one + l_one + c) <= cy && cy <= (s_one + l_one + c + h)) ? 1 : 0;
if(c1 || c2) {
for(cx = x; cx < x + s_one; cx++) {
unsigned char* px = &raw[((cy + j) * w + (cx + j)) * 4];
px[0] = cl->common.red;
px[1] = cl->common.green;
px[2] = cl->common.blue;
px[3] = 255;
}
}
}
}
x += s_one;
} else if(str[i] == ' ') {
x += s_one;
} else if(str[i] == '.') {
int cy, cx;
int j;
for(j = 1; j >= 0; j--) {
MwLLColor cl = j == 1 ? shadow : text;
for(cy = h - (s_one - 1) / 2 - 1; cy < h; cy++) {
for(cx = x - Spacing - (s_one - 1) / 2 - 1; cx < (x - Spacing); cx++) {
unsigned char* px = &raw[((cy + j) * w + (cx + j)) * 4];
px[0] = cl->common.red;
px[1] = cl->common.green;
px[2] = cl->common.blue;
px[3] = 255;
}
}
}
continue;
}
x += Spacing;
}
px = MwLoadRaw(handle, raw, w, h);
r.y = (r.height - h) / 2;
r.height = h;
if(align == MwALIGNMENT_CENTER) {
r.x = (r.width - w) / 2;
} else if(align == MwALIGNMENT_BEGINNING) {
r.x = 0;
} else if(align == MwALIGNMENT_END) {
r.x = r.width - w;
}
r.width = w;
MwLLDrawPixmap(handle->lowlevel, &r, px);
MwLLDestroyPixmap(px);
} else {
r.width -= MwGetInteger(handle, MwNleftPadding);
if(align == MwALIGNMENT_CENTER) {
p.x = r.width / 2;
} else if(align == MwALIGNMENT_BEGINNING) {
p.x = MwTextWidth(handle, str) / 2;
p.x = MwTextWidth(handle, NULL, str) / 2;
} else if(align == MwALIGNMENT_END) {
p.x = r.width - MwTextWidth(handle, str) / 2;
p.x = r.width - MwTextWidth(handle, NULL, str) / 2;
}
p.y = r.height / 2;
MwDrawText(handle, &p, str, MwGetInteger(handle, MwNbold), MwALIGNMENT_CENTER, text);
p.x += MwGetInteger(handle, MwNleftPadding);
p.x += 1;
p.y += 1;
MwDrawText(handle, NULL, &p, str, MwALIGNMENT_CENTER, shadow);
p.x -= 1;
p.y -= 1;
MwDrawText(handle, NULL, &p, str, MwALIGNMENT_CENTER, text);
}
MwLLFreeColor(shadow);
MwLLFreeColor(text);
MwLLFreeColor(base);
}
static void prop_change(MwWidget handle, const char* key) {
if(strcmp(key, MwNtext) == 0 || strcmp(key, MwNalignment) == 0) MwForceRender(handle);
if(strcmp(key, MwNtext) == 0 || strcmp(key, MwNalignment) == 0 || strcmp(key, MwNsevenSegment) == 0 || strcmp(key, MwNlength) == 0 || strcmp(key, MwNleftPadding) == 0) MwForceRender(handle);
}
static void mwLabelSetSevenSegmentImpl(MwWidget handle, int index, unsigned char data) {
MwLabel lab = handle->internal;
hmput(lab->segment, index, data);
}
static void func_handler(MwWidget handle, const char* name, void* out, va_list va) {
(void)out;
if(strcmp(name, "mwLabelSetSevenSegment") == 0) {
int index = va_arg(va, int);
int data = va_arg(va, int);
mwLabelSetSevenSegmentImpl(handle, index, data);
}
}
MwClassRec MwLabelClassRec = {
create, /* create */
NULL, /* destroy */
wcreate, /* create */
destroy, /* destroy */
draw, /* draw */
NULL, /* click */
NULL, /* parent_resize */
@ -57,12 +370,12 @@ MwClassRec MwLabelClassRec = {
NULL, /* mouse_up */
NULL, /* mouse_down */
NULL, /* key */
NULL, /* execute */
func_handler, /* execute */
NULL, /* tick */
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL,
NULL, /* clipboard */
NULL,
NULL,
NULL,

View file

@ -4,6 +4,8 @@
#define Padding 2
#define Font MwFLBuildFont(MwFLFlagMonospace)
MwListBoxPacket* MwListBoxCreatePacket(void) {
MwListBoxPacket* packet = malloc(sizeof(*packet));
memset(packet, 0, sizeof(*packet));
@ -118,19 +120,19 @@ static void vscroll_changed(MwWidget handle, void* user, void* call) {
static void frame_mouse_down(MwWidget handle, void* user, void* call) {
MwListBox lb = handle->parent->internal;
MwLLMouse* m = call;
MwMouse* m = call;
(void)user;
if(m->button == MwLLMouseLeft) {
if(m->button == MwMOUSE_LEFT) {
int st = 0;
int i;
int y = MwDefaultBorderWidth(handle);
int h = MwGetInteger(handle, MwNheight);
st = get_first_entry(handle->parent, lb);
for(i = 0; (st + i) < arrlen(lb->list) && i < (h - MwDefaultBorderWidth(handle) * 2) / (MwTextHeight(handle, "M") + Padding) + 2; i++) {
if(y <= m->point.y && m->point.y <= (y + MwTextHeight(handle, "M") + Padding)) {
for(i = 0; (st + i) < arrlen(lb->list) && i < (h - MwDefaultBorderWidth(handle) * 2) / (MwTextHeight(handle, Font, "M") + Padding) + 2; i++) {
if(y <= m->point.y && m->point.y <= (y + MwTextHeight(handle, Font, "M") + Padding)) {
unsigned long t;
int old = MwGetInteger(handle->parent, MwNvalue);
@ -138,12 +140,12 @@ static void frame_mouse_down(MwWidget handle, void* user, void* call) {
if((((t = MwTimeGetTick()) - lb->click_time) < MwDoubleClickTimeout && old == st + i) || MwGetInteger(handle->parent, MwNsingleClickSelectable)) {
int n = MwGetInteger(handle->parent, MwNvalue);
MwDispatchUserHandler(handle->parent, MwNactivateHandler, &n);
MwDispatchUserHandler(handle->parent, MwNlistBoxActivateHandler, &n);
}
lb->click_time = t;
}
y += MwTextHeight(handle, "M") + Padding;
y += MwTextHeight(handle, Font, "M") + Padding;
}
MwForceRender(lb->frame);
@ -153,11 +155,11 @@ static void frame_mouse_down(MwWidget handle, void* user, void* call) {
static void frame_mouse_up(MwWidget handle, void* user, void* call) {
MwListBox lb = handle->parent->internal;
MwLLMouse* m = call;
MwMouse* m = call;
(void)user;
if(m->button == MwLLMouseLeft) {
if(m->button == MwMOUSE_LEFT) {
lb->pressed = 0;
}
}
@ -175,11 +177,11 @@ static void frame_mouse_move(MwWidget handle, void* user, void* call) {
int h = MwGetInteger(handle, MwNheight);
st = get_first_entry(handle->parent, lb);
for(i = 0; (st + i) < arrlen(lb->list) && i < (h - MwDefaultBorderWidth(handle) * 2) / (MwTextHeight(handle, "M") + Padding) + 2; i++) {
if(y <= p->y && p->y <= (y + MwTextHeight(handle, "M") + Padding)) {
for(i = 0; (st + i) < arrlen(lb->list) && i < (h - MwDefaultBorderWidth(handle) * 2) / (MwTextHeight(handle, Font, "M") + Padding) + 2; i++) {
if(y <= p->y && p->y <= (y + MwTextHeight(handle, Font, "M") + Padding)) {
MwSetInteger(handle->parent, MwNvalue, st + i);
}
y += MwTextHeight(handle, "M") + Padding;
y += MwTextHeight(handle, Font, "M") + Padding;
}
MwForceRender(lb->frame);
@ -216,7 +218,7 @@ static void frame_draw(MwWidget handle) {
st = get_first_entry(handle->parent, lb);
area = r.height - MwDefaultBorderWidth(handle) * 2;
ent = area / (MwTextHeight(handle, "M") + Padding) + 2;
ent = area / (MwTextHeight(handle, Font, "M") + Padding) + 2;
for(i = st; i < arrlen(lb->list) && i < st + ent; i++) {
int selected = MwGetInteger(handle->parent, MwNvalue) == i ? 1 : 0;
@ -227,20 +229,20 @@ static void frame_draw(MwWidget handle) {
r2.x = MwDefaultBorderWidth(handle) + MwGetInteger(handle->parent, MwNleftPadding);
r2.y = p.y;
r2.width = r.width - r2.x;
r2.height = MwTextHeight(handle, "M") + Padding;
r2.height = MwTextHeight(handle, Font, "M") + Padding;
MwDrawRect(handle, &r2, text2);
handle->bgcolor = text2;
}
if(lb->list[i].pixmap != NULL) {
MwRect r2;
int h = (lb->list[i].pixmap->common.height > (MwTextHeight(handle, "M") + Padding)) ? (MwTextHeight(handle, "M") + Padding) : lb->list[i].pixmap->common.height;
int h = (lb->list[i].pixmap->common.height > (MwTextHeight(handle, Font, "M") + Padding)) ? (MwTextHeight(handle, Font, "M") + Padding) : lb->list[i].pixmap->common.height;
r2.x = MwDefaultBorderWidth(handle);
r2.y = p.y + (MwTextHeight(handle, "M") + Padding - h) / 2;
r2.y = p.y + (MwTextHeight(handle, Font, "M") + Padding - h) / 2;
r2.width = h * lb->list[i].pixmap->common.width / lb->list[i].pixmap->common.height;
r2.height = h;
MwLLDrawPixmap(handle->lowlevel, &r2, lb->list[i].pixmap);
}
p.y += (MwTextHeight(handle, "M") + Padding) / 2;
p.y += (MwTextHeight(handle, Font, "M") + Padding) / 2;
p.x = MwDefaultBorderWidth(handle) + MwGetInteger(handle->parent, MwNleftPadding);
for(j = 0; j < arrlen(lb->list[i].name); j++) {
char* t = lb->list[i].name[j];
@ -250,36 +252,35 @@ static void frame_draw(MwWidget handle) {
if(t == NULL) t = "";
str = MwStringDuplicate(t);
if(MwUTF8Length(str) > (get_col_width(lb, j) - l) / MwTextWidth(handle, "M")) {
int ind = (get_col_width(lb, j) - l) / MwTextWidth(handle, "M");
if(MwUTF8Length(str) > (get_col_width(lb, j) - l) / MwTextWidth(handle, Font, "M")) {
int ind = (get_col_width(lb, j) - l) / MwTextWidth(handle, Font, "M");
str[ind] = 0;
if(ind > 3) memset(str + ind - 3, '.', 3);
}
if(j == (arrlen(lb->list[i].name) - 1)) p.x -= MwDefaultBorderWidth(handle);
if(arrlen(lb->alignment) <= j || lb->alignment[j] == MwALIGNMENT_BEGINNING) {
p.x += 4;
MwDrawText(handle, &p, str, 0, MwALIGNMENT_BEGINNING, selected ? base2 : text2);
MwDrawText(handle, Font, &p, str, MwALIGNMENT_BEGINNING, selected ? base2 : text2);
p.x -= 4;
p.x += get_col_width(lb, j);
} else if(lb->alignment[j] == MwALIGNMENT_CENTER) {
p.x += (get_col_width(lb, j) - l) / 2;
MwDrawText(handle, &p, str, 0, MwALIGNMENT_CENTER, selected ? base2 : text2);
MwDrawText(handle, Font, &p, str, MwALIGNMENT_CENTER, selected ? base2 : text2);
p.x += (get_col_width(lb, j) - l) / 2;
p.x += l;
} else if(lb->alignment[j] == MwALIGNMENT_END) {
p.x += get_col_width(lb, j);
p.x -= 4;
MwDrawText(handle, &p, str, 0, MwALIGNMENT_END, selected ? base2 : text2);
MwDrawText(handle, Font, &p, str, MwALIGNMENT_END, selected ? base2 : text2);
p.x += 4;
}
free(str);
if(j == 0) p.x -= MwGetInteger(handle->parent, MwNleftPadding);
}
p.y += (MwTextHeight(handle, "M") + Padding) / 2;
p.y += (MwTextHeight(handle, Font, "M") + Padding) / 2;
handle->bgcolor = NULL;
}
@ -298,7 +299,7 @@ static void resize(MwWidget handle) {
int ih, y;
int m = 0;
y = MwGetInteger(handle, MwNhasHeading) ? (MwTextHeight(handle, "M") + MwDefaultBorderWidth(handle) * 2) : 0;
y = MwGetInteger(handle, MwNhasHeading) ? (MwTextHeight(handle, NULL, "M") + MwDefaultBorderWidth(handle) * 2) : 0;
if(lb->vscroll == NULL) {
lb->vscroll = MwVaCreateWidget(MwScrollBarClass, "vscroll", handle, w - 16, 0, 16, h, NULL);
@ -317,7 +318,7 @@ static void resize(MwWidget handle) {
h -= y;
if(ih <= (h / (MwTextHeight(handle, "M") + Padding))) {
if(ih <= (h / (MwTextHeight(handle, Font, "M") + Padding))) {
MwLLShow(lb->vscroll->lowlevel, 0);
} else {
MwLLShow(lb->vscroll->lowlevel, 1);
@ -341,12 +342,12 @@ static void resize(MwWidget handle) {
h -= MwDefaultBorderWidth(handle) * 2;
MwVaApply(lb->vscroll,
MwNareaShown, h / (MwTextHeight(handle, "M") + Padding),
MwNareaShown, h / (MwTextHeight(handle, Font, "M") + Padding),
MwNmaxValue, ih,
NULL);
}
static int create(MwWidget handle) {
static int wcreate(MwWidget handle) {
MwListBox lb = malloc(sizeof(*lb));
memset(lb, 0, sizeof(*lb));
@ -401,7 +402,7 @@ static void draw(MwWidget handle) {
r.x = x;
r.y = 0;
r.width = get_col_width(lb, i);
r.height = MwDefaultBorderWidth(handle) * 2 + MwTextHeight(handle, "M");
r.height = MwDefaultBorderWidth(handle) * 2 + MwTextHeight(handle, NULL, "M");
MwDrawFrame(handle, &r, base, 0);
x += MwDefaultBorderWidth(handle);
@ -409,15 +410,15 @@ static void draw(MwWidget handle) {
if(arrlen(lb->alignment) <= i || lb->alignment[i] == MwALIGNMENT_BEGINNING) {
p.x = 4 + x;
p.y = r.y + r.height / 2;
MwDrawText(handle, &p, lb->list[0].name[i], 0, MwALIGNMENT_BEGINNING, text);
MwDrawText(handle, NULL, &p, lb->list[0].name[i], MwALIGNMENT_BEGINNING, text);
} else if(lb->alignment[i] == MwALIGNMENT_CENTER) {
p.x = x + r.width / 2;
p.y = r.y + r.height / 2;
MwDrawText(handle, &p, lb->list[0].name[i], 0, MwALIGNMENT_CENTER, text);
MwDrawText(handle, NULL, &p, lb->list[0].name[i], MwALIGNMENT_CENTER, text);
} else if(lb->alignment[i] == MwALIGNMENT_END) {
p.x = x + r.width - 4;
p.y = r.y + r.height / 2;
MwDrawText(handle, &p, lb->list[0].name[i], 0, MwALIGNMENT_END, text);
MwDrawText(handle, NULL, &p, lb->list[0].name[i], MwALIGNMENT_END, text);
}
x += r.width;
@ -594,7 +595,7 @@ static void tick(MwWidget handle) {
}
MwClassRec MwListBoxClassRec = {
create, /* create */
wcreate, /* create */
destroy, /* destroy */
draw, /* draw */
NULL, /* click */
@ -609,7 +610,7 @@ MwClassRec MwListBoxClassRec = {
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL,
NULL, /* clipboard */
NULL,
NULL,
NULL,

View file

@ -8,7 +8,7 @@ static void set_xywh(MwWidget handle) {
int diff = MwDefaultBorderWidth(handle);
diff = 0;
height = MwTextHeight(handle, "M") + 10;
height = MwTextHeight(handle, NULL, "M") + 10;
MwVaApply(handle,
MwNx, -diff,
@ -18,7 +18,7 @@ static void set_xywh(MwWidget handle) {
NULL);
}
static int create(MwWidget handle) {
static int wcreate(MwWidget handle) {
MwMenu m = malloc(sizeof(*m));
m->name = NULL;
@ -71,8 +71,8 @@ static void destroy(MwWidget handle) {
#define BEGIN_MENU_LOOP \
for(i = 0; i < arrlen(m->sub); i++) { \
int incr = m->sub[i]->name[0] == '?' ? 1 : 0; \
int tw = MwTextWidth(handle, m->sub[i]->name + incr); \
int th = MwTextHeight(handle, m->sub[i]->name + incr); \
int tw = MwTextWidth(handle, NULL, m->sub[i]->name + incr); \
int th = MwTextHeight(handle, NULL, m->sub[i]->name + incr); \
int in_area; \
\
if(incr) { \
@ -104,7 +104,7 @@ static void draw(MwWidget handle) {
MwDrawWidgetBack(handle, &r, base, 0, MwFALSE);
}
MwDrawText(handle, &p, m->sub[i]->name + incr, m->sub[i]->wsub != NULL || (in_area && handle->pressed) ? 1 : 0, MwALIGNMENT_BEGINNING, text);
MwDrawText(handle, MwFLBuildFont((m->sub[i]->wsub != NULL || (in_area && handle->pressed)) ? MwFLFlagBold : 0), &p, m->sub[i]->name + incr, MwALIGNMENT_BEGINNING, text);
END_MENU_LOOP;
MwLLFreeColor(text);
@ -118,7 +118,7 @@ static void parent_resize(MwWidget handle) {
static void mouse_down(MwWidget handle, void* ptr) {
MENU_LOOP_DECL;
if(((MwLLMouse*)ptr)->button != MwLLMouseLeft) return;
if(((MwMouse*)ptr)->button != MwMOUSE_LEFT) return;
BEGIN_MENU_LOOP;
if(in_area) {
@ -129,7 +129,7 @@ static void mouse_down(MwWidget handle, void* ptr) {
p2.y = p.y + th / 2 + 5;
m->sub[i]->wsub = MwCreateWidget(MwSubMenuClass, "submenu", handle, 0, 0, 0, 0);
MwSubMenuAppear(m->sub[i]->wsub, m->sub[i], &p2);
MwSubMenuAppear(m->sub[i]->wsub, m->sub[i], &p2, 0);
} else if(m->sub[i]->wsub != NULL && m->sub[i]->keep) {
MwDestroyWidget(m->sub[i]->wsub);
m->sub[i]->wsub = NULL;
@ -150,7 +150,7 @@ static void mouse_down(MwWidget handle, void* ptr) {
static void mouse_up(MwWidget handle, void* ptr) {
MENU_LOOP_DECL;
if(((MwLLMouse*)ptr)->button != MwLLMouseLeft) return;
if(((MwMouse*)ptr)->button != MwMOUSE_LEFT) return;
BEGIN_MENU_LOOP;
if(in_area && m->sub[i]->wsub != NULL) {
@ -189,7 +189,7 @@ static void func_handler(MwWidget handle, const char* name, void* out, va_list v
}
MwClassRec MwMenuClassRec = {
create, /* create */
wcreate, /* create */
destroy, /* destroy */
draw, /* draw */
NULL, /* click */
@ -204,7 +204,7 @@ MwClassRec MwMenuClassRec = {
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL,
NULL, /* clipboard */
NULL,
NULL,
NULL,

Some files were not shown because too many files have changed in this diff Show more