Compare commits

...

208 commits

Author SHA1 Message Date
fa9a16c0d5 auto detect dark theme change via dbus signals 2026-04-16 23:05:41 +02: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
102 changed files with 17767 additions and 8619 deletions

View file

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

10
.gitignore vendored
View file

@ -7,6 +7,8 @@ examples/*/*.exe
!examples/*/*.*
*.exe
*.o
*.obj
*.core
*.so
*.dll
*.lib
@ -16,3 +18,11 @@ examples/*/*.exe
/build
compile_flags.txt
.cache
.DS_Store
*.pef
*.dsk
*.bin
*.rsrc
*.finf
*.gdb

24
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,7 +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\icon\back.obj
del /f /q src\icon\clock.obj
del /f /q src\icon\computer.obj
@ -46,8 +60,10 @@ clean:
del /f /q src\lowlevel.obj
del /f /q src\string.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
@ -76,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\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\boldttf.obj src\text\font\font.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\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\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\boldttf.obj src\text\font\font.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
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

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.25)
project(
milsko
milsko
)
include(CheckIncludeFiles)
@ -9,243 +9,396 @@ include(GNUInstallDirs)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
option(MW_TRY_OPENGL "Try to compile OpenGL widget or not" ON)
option(MW_TRY_VULKAN "Try to compile Vulkan widget or not" 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)
option(MW_USE_FREETYPE2 "Use FreeType 2" ON)
option(MW_BUILD_SHARED "Build a shared library" ON)
option(MW_BUILD_STATIC "Build a static library" 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/widget/*.c src/text/*.c src/text/font/*.c src/dialog/*.c src/abstract/*.c external/*.c
GLOB
SOURCES
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 MW_USE_STB_IMAGE)
list(REMOVE_ITEM SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/external/stb_image.c")
list(REMOVE_ITEM SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/external/stb_image.c")
endif()
if(NOT MW_USE_STB_TRUETYPE)
list(REMOVE_ITEM SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/external/stb_truetype.c")
list(REMOVE_ITEM SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/external/stb_truetype.c")
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
list(APPEND CMAKE_REQUIRED_INCLUDES "/usr/X11R7/include")
list(APPEND CMAKE_REQUIRED_INCLUDES "/usr/pkg/include")
list(APPEND CMAKE_REQUIRED_INCLUDES "/usr/X11R7/include")
list(APPEND CMAKE_REQUIRED_INCLUDES "/usr/pkg/include")
endif()
if(MW_TRY_OPENGL)
check_include_files(GL/gl.h HAVE_GL_GL_H)
if(HAVE_GL_GL_H)
set(MW_BUILD_OPENGL ON)
list(APPEND SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/widget/opengl.c")
message(STATUS "OpenGL widget has been enabled")
else()
message(WARNING "OpenGL widget has been disabled")
endif()
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(MW_TRY_VULKAN)
check_include_files(vulkan/vulkan.h HAVE_VULKAN_VULKAN_H)
if(HAVE_VULKAN_VULKAN_H)
set(MW_BUILD_VULKAN ON)
list(APPEND SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/widget/vulkan.c")
message(STATUS "Vulkan widget has been enabled")
else()
message(WARNING "Vulkan widget has been disabled")
endif()
check_include_files(vulkan/vulkan.h HAVE_VULKAN_VULKAN_H)
if(HAVE_VULKAN_VULKAN_H)
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}
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}
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")
message(ERROR "Must either build a shared library or a static library")
endif()
if(MW_USE_STB_IMAGE)
target_compile_definitions(
Mw
PRIVATE
USE_STB_IMAGE
)
target_compile_definitions(
Mw
PRIVATE
USE_STB_IMAGE
)
else()
file(
GLOB
IMAGE_SOURCES
external/libz/src/*.c external/libjpeg/src/*.c external/libpng/src/*.c
)
target_sources(
Mw
PRIVATE
${MW_IMAGE_SOURCES}
)
target_include_directories(
Mw
PRIVATE
external/libz/include external/libjpeg/include external/libpng/include
)
file(
GLOB
IMAGE_SOURCES
external/libjpeg/src/*.c external/libpng/src/*.c
)
target_sources(
Mw
PRIVATE
${MW_IMAGE_SOURCES}
)
target_include_directories(
Mw
PRIVATE
external/libjpeg/include external/libpng/include
)
endif()
if(MW_USE_STB_TRUETYPE)
target_compile_definitions(
Mw
PRIVATE
USE_STB_TRUETYPE
)
target_compile_definitions(
Mw
PRIVATE
USE_STB_TRUETYPE
)
endif()
if(MW_USE_FREETYPE2)
target_compile_definitions(
Mw
PRIVATE
USE_FREETYPE2
)
target_compile_definitions(
Mw
PRIVATE
USE_FREETYPE2
)
find_package(PkgConfig)
pkg_check_modules(FT2 REQUIRED freetype2)
list(APPEND INCLUDE_DIRS ${FT2_INCLUDE_DIRS})
list(APPEND LIBRARY_DIRS ${FT2_LIBRARY_DIRS})
list(APPEND LIBRARIES ${FT2_LIBRARIES})
find_package(PkgConfig)
pkg_check_modules(FT2 REQUIRED freetype2)
list(APPEND INCLUDE_DIRS ${FT2_INCLUDE_DIRS})
list(APPEND LIBRARY_DIRS ${FT2_LIBRARY_DIRS})
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
PUBLIC
include
Mw
PRIVATE
external/libz/include
)
target_include_directories(
Mw
PUBLIC
include
)
if(MW_CLASSIC_THEME)
target_compile_definitions(
Mw
PRIVATE
USE_CLASSIC_THEME
)
target_compile_definitions(
Mw
PRIVATE
USE_CLASSIC_THEME
)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_sources(
Mw
PRIVATE
src/backend/gdi.c
)
target_compile_definitions(
Mw
PRIVATE
USE_GDI
)
list(APPEND LIBRARIES gdi32)
target_link_options(
Mw
PRIVATE
-static-libgcc
)
target_sources(
Mw
PRIVATE
src/backend/gdi.c
)
target_compile_definitions(
Mw
PRIVATE
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
)
else()
find_package(PkgConfig)
pkg_check_modules(X11 REQUIRED x11)
pkg_check_modules(XRENDER REQUIRED xrender)
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()
target_sources(
Mw
PRIVATE
src/backend/x11.c
)
target_compile_definitions(
Mw
PRIVATE
USE_X11
)
list(APPEND INCLUDE_DIRS ${X11_INCLUDE_DIRS} ${XRENDER_INCLUDE_DIRS})
list(APPEND LIBRARY_DIRS ${X11_LIBRARY_DIRS} ${XRENDER_LIBRARY_DIRS})
list(APPEND LIBRARIES ${X11_LIBRARIES} ${XRENDER_LIBRARIES} m)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
list(APPEND LIBRARIES dl)
endif()
target_compile_definitions(
Mw
PRIVATE
CLASSIC_MAC_OS
)
else()
find_package(PkgConfig)
pkg_check_modules(X11 REQUIRED x11)
pkg_check_modules(XRENDER REQUIRED xrender)
target_sources(
Mw
PRIVATE
src/backend/x11.c
)
target_compile_definitions(
Mw
PRIVATE
USE_X11
)
list(APPEND INCLUDE_DIRS ${X11_INCLUDE_DIRS} ${XRENDER_INCLUDE_DIRS})
list(APPEND LIBRARY_DIRS ${X11_LIBRARY_DIRS} ${XRENDER_LIBRARY_DIRS})
list(APPEND LIBRARIES ${X11_LIBRARIES} ${XRENDER_LIBRARIES} m)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
list(APPEND LIBRARIES dl)
endif()
endif()
target_include_directories(
Mw
PRIVATE
${INCLUDE_DIRS}
Mw
PRIVATE
${INCLUDE_DIRS}
)
target_link_directories(
Mw
PRIVATE
${LIBRARY_DIRS}
Mw
PRIVATE
${LIBRARY_DIRS}
)
target_link_libraries(
Mw
PRIVATE
${LIBRARIES}
Mw
PRIVATE
${LIBRARIES}
)
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(
Mw
PRIVATE
HAS_VK_ENUM_STRING_HELPER
)
endif()
check_include_files(vulkan/vk_enum_string_helper.h HAS_VK_ENUM_STRING_HELPER)
if(HAS_VK_ENUM_STRING_HELPER)
target_compile_definitions(
Mw
PRIVATE
HAS_VK_ENUM_STRING_HELPER
)
endif()
target_compile_definitions(
Mw
PRIVATE
MW_VULKAN
)
endif()
target_compile_definitions(
Mw
PRIVATE
_MILSKO
Mw
PRIVATE
_MILSKO
)
install(
TARGETS Mw
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
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"
)
install(
DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.h"
)
endif()
if(MW_BUILD_EXAMPLES)
add_subdirectory(examples)
add_subdirectory(examples)
endif()

6
Jenkinsfile vendored
View file

@ -7,7 +7,11 @@ pipeline {
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")
@ -50,7 +54,7 @@ pipeline {
sh("make -j4")
}
}
stage("Build for Windows 64-bit (MSVC)") {
stage("Build for Windows 32-bit (MSVC)") {
agent {
label "2012r2"
}

24
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,7 +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\icon\back.obj
del /f /q src\icon\clock.obj
del /f /q src\icon\computer.obj
@ -46,8 +60,10 @@ clean:
del /f /q src\lowlevel.obj
del /f /q src\string.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
@ -76,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\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\boldttf.obj src\text\font\font.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\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\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\boldttf.obj src\text\font\font.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
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:

62
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,7 +40,6 @@ clean: .SYMBOLIC
%erase src/dialog/filechooser.obj
%erase src/dialog/messagebox.obj
%erase src/draw.obj
%erase src/error.obj
%erase src/icon/back.obj
%erase src/icon/clock.obj
%erase src/icon/computer.obj
@ -45,8 +59,10 @@ clean: .SYMBOLIC
%erase src/lowlevel.obj
%erase src/string.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
@ -75,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/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/boldttf.obj src/text/font/font.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/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/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/boldttf.obj file src/text/font/font.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
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
@ -120,8 +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/icon/back.obj: src/icon/back.c
$(CC) $(CFLAGS) -fo=$@ $<
src/icon/clock.obj: src/icon/clock.c
@ -160,10 +204,14 @@ src/string.obj: src/string.c
$(CC) $(CFLAGS) -fo=$@ $<
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

59
configure vendored
View file

@ -14,7 +14,8 @@ 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";
@ -37,8 +38,6 @@ 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);
@ -47,6 +46,7 @@ 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 use libjpeg/libpng",
@ -58,7 +58,8 @@ my %features = (
"vulkan-string-helper" => "use Vulkan string helper",
"shared" => "build shared library",
"static" => "build static library",
"experimental-wayland" => "enable WIP wayland backend",
"wayland" => "enable wayland backend",
"gnustep" => "use gnustep",
);
my @features_keys = (
"1classic-theme", "1stb-image",
@ -66,7 +67,7 @@ my @features_keys = (
"1opengl", "2xrender",
"1vulkan", "2vulkan-string-helper",
"1shared", "1static",
"1experimental-wayland"
"1wayland", "1gnustep",
);
foreach my $l (@ARGV) {
@ -85,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");
@ -98,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");
@ -123,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");
}
@ -161,7 +185,7 @@ 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");
@ -184,7 +208,7 @@ 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\" -or -name \"*.m\"`\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 configure -name \"*.pl\"`\n"
@ -251,9 +275,15 @@ if (param_get("examples")) {
$libs = $examples_libs{$l};
}
print(OUT
"${l}: ${s}${object_suffix} src/${library_prefix}Mw${library_suffix}\n"
);
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"
@ -264,6 +294,15 @@ if (param_get("examples")) {
" \$(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"

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

@ -1,22 +1,26 @@
file(
GLOB
EXAMPLES_BASIC_SOURCES
*.c
GLOB
EXAMPLES_BASIC_SOURCES
*.c
)
foreach(PATH IN LISTS EXAMPLES_BASIC_SOURCES)
get_filename_component(TARGET ${PATH} NAME_WE)
add_executable(${TARGET} ${PATH})
target_link_libraries(
${TARGET}
PRIVATE
Mw
)
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_link_libraries(
${TARGET}
PRIVATE
m
)
endif()
get_filename_component(TARGET ${PATH} NAME_WE)
if(CMAKE_SYSTEM_NAME MATCHES Retro)
add_application(${TARGET} ${PATH})
else()
add_executable(${TARGET} MACOSX_BUNDLE ${PATH})
endif()
target_link_libraries(
${TARGET}
PRIVATE
Mw
)
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_link_libraries(
${TARGET}
PRIVATE
m
)
endif()
endforeach()

View file

@ -82,7 +82,7 @@ static void activate(MwWidget handle, void* client, void* user) {
v = fv / sv;
}
sprintf(buf, "%g", v);
MwStringPrintIntoBuffer(buf, 256, "%g", v);
MwVaApply(inp,
MwNtext, buf,

View file

@ -1,8 +1,8 @@
#include <Mw/Milsko.h>
MwWidget window, instructions, text;
MwWidget window, instructions, text1, text2, cur_text;
void resize(MwWidget handle, void* user_data, void* call_data) {
static void resize(MwWidget handle, void* user_data, void* call_data) {
unsigned int w, h;
(void)user_data;
@ -17,23 +17,34 @@ void resize(MwWidget handle, void* user_data, void* call_data) {
MwNheight, h - 125 - 50 * 3,
NULL);
MwVaApply(text,
MwNy, 200,
MwNwidth, w - 50 * 2,
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);
}
void clipboard(MwWidget handle, void* user_data, void* call_data) {
static void clipboard(MwWidget handle, void* user_data, void* call_data) {
char* clipboard = call_data;
(void)handle;
(void)user_data;
printf("got: %s\n", clipboard);
if(clipboard != NULL) {
MwVaApply(text, MwNtext, clipboard, NULL);
MwForceRender(text);
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);
}
@ -46,12 +57,20 @@ int main() {
instructions = MwVaCreateWidget(MwLabelClass, "button", window, 50, 50, 300, 125,
MwNtext, "clipboard contents will show up below.",
NULL);
text = MwVaCreateWidget(MwLabelClass, "label", window, 50, 200, 300, 125,
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);

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;
MwSetDarkTheme(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

@ -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

@ -12,78 +12,82 @@
static double deg = 0;
static void draw(void) {
int i;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
int i;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(deg, 1, 0, 0);
glRotatef(deg, 0, 1, 0);
glRotatef(deg, 0, 0, 1);
glPushMatrix();
glRotatef(deg, 1, 0, 0);
glRotatef(deg, 0, 1, 0);
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);
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);
glBegin(GL_QUADS);
glNormal3f(0, 1, 0);
glVertex3f(-1, 1, -1);
glVertex3f(-1, 1, 1);
glVertex3f(1, 1, 1);
glVertex3f(1, 1, -1);
glEnd();
glBegin(GL_QUADS);
glNormal3f(0, 1, 0);
glVertex3f(-1, 1, -1);
glVertex3f(-1, 1, 1);
glVertex3f(1, 1, 1);
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);
}
glPopMatrix();
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();
}
static void idle(void) { deg += 1.0; }
static void idle(void) {
deg += 1.0;
}
static void reshape(int width, int height) {
GLfloat lpos[4];
GLfloat lpos[4];
lpos[0] = 1;
lpos[1] = 1;
lpos[2] = 1;
lpos[3] = 0;
lpos[0] = 1;
lpos[1] = 1;
lpos[2] = 1;
lpos[3] = 0;
glViewport(0, 0, width, height);
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (double)width / height, 1, 100);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (double)width / height, 1, 100);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(2, 2, 2, 0, 0, 0, 0, 1, 0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(2, 2, 2, 0, 0, 0, 0, 1, 0);
glLightfv(GL_LIGHT0, GL_POSITION, lpos);
glLightfv(GL_LIGHT0, GL_POSITION, lpos);
}
static void init(void) {
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_CULL_FACE);
glEnable(GL_NORMALIZE);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_CULL_FACE);
glEnable(GL_NORMALIZE);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
}
static void key(int k) { (void)k; }
static void key(int k) {
(void)k;
}

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];
}
@ -232,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);
@ -292,8 +264,8 @@ void vulkan_setup(MwWidget handle) {
swapchainCreateInfo.imageExtent = (VkExtent2D){.width = ow, .height = oh},
swapchainCreateInfo.imageArrayLayers = 1,
swapchainCreateInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
VK_IMAGE_USAGE_TRANSFER_DST_BIT |
VK_IMAGE_USAGE_SAMPLED_BIT;
VK_IMAGE_USAGE_TRANSFER_DST_BIT |
VK_IMAGE_USAGE_SAMPLED_BIT;
// th is how we specify no transformation.
swapchainCreateInfo.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
swapchainCreateInfo.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;

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__)
@ -76,10 +76,10 @@ struct _MwPoint {
};
struct _MwRect {
int x;
int y;
unsigned int width;
unsigned int height;
int x;
int y;
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,6 +295,7 @@ MWDECL void MwHideCursor(MwWidget handle);
* @brief Toggles the dark theme
* @param handle Widget
* @param toggle Toggle
* @deprecated Use MwNdarkTheme instead
*/
MWDECL void MwSetDarkTheme(MwWidget handle, int toggle);
@ -356,9 +357,17 @@ 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

@ -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,11 +6,10 @@
#ifndef __MW_LOWLEVEL_H__
#define __MW_LOWLEVEL_H__
#include "Mw/BaseTypes.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;
@ -34,10 +33,11 @@ enum MwLLBackends {
};
struct _MwLLCommon {
void* user;
int copy_buffer;
int type;
int coordinate_type;
void* user;
int copy_buffer;
int type;
int coordinate_type;
MwBool supports_transparency;
MwLLHandler handler;
};
@ -55,6 +55,47 @@ 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);
DBusMessage* (*dbus_connection_send_with_reply_and_block)(DBusConnection* connection, DBusMessage* message, int timeout_milliseconds, DBusError* error);
void (*dbus_message_unref)(DBusMessage* message);
dbus_bool_t (*dbus_message_iter_init)(DBusMessage* message, DBusMessageIter* iter);
int (*dbus_message_iter_get_arg_type)(DBusMessageIter* iter);
void (*dbus_message_iter_recurse)(DBusMessageIter* iter, DBusMessageIter* sub);
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;
DBusMessageIter dbus_args, dbus_variant, dbus_inner_variant;
} 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>
@ -68,6 +109,9 @@ struct _MwLLCommonPixmap {
#ifdef USE_COCOA
#include <Mw/LowLevel/Cocoa.h>
#endif
#ifdef CLASSIC_MAC_OS
#include <Mw/LowLevel/ClassicMacOS.h>
#endif
union _MwLL {
struct _MwLLCommon common;
@ -83,6 +127,9 @@ union _MwLL {
#ifdef USE_COCOA
struct _MwLLCocoa cocoa;
#endif
#ifdef CLASSIC_MAC_OS
struct _MwLLClassicMacOS cmacos;
#endif
};
union _MwLLColor {
@ -115,6 +162,9 @@ union _MwLLPixmap {
#ifdef USE_COCOA
struct _MwLLCocoaPixmap cocoa;
#endif
#ifdef CLASSIC_MAC_OS
struct _MwLLClassicMacOSPixmap cmacos;
#endif
};
#endif
#include <Mw/TypeDefs.h>
@ -140,19 +190,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);
@ -176,6 +213,10 @@ struct _MwLLTextDispatchTable {
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
@ -229,12 +270,14 @@ 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 void (*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);
@ -245,10 +288,10 @@ MWDECL int MWFL_FT2Setup(void);
MWDECL int MwFL_STBTTSetup(void);
#endif
MWDECL int (*MwFLDrawText)(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color);
MWDECL int (*MwFLTextWidth)(MwWidget handle, const char* text);
MWDECL int (*MwFLTextHeight)(MwWidget handle, int count);
MWDECL void* (*MwFLFontLoad)(unsigned char* data, unsigned int size);
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

View file

@ -0,0 +1,32 @@
/*!
* @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;
WindowRef window;
EventRecord event;
Rect winRect;
};
struct _MwLLClassicMacOSColor {
struct _MwLLCommonColor common;
};
struct _MwLLClassicMacOSPixmap {
struct _MwLLCommonPixmap common;
BitMap bmp;
};
MWDECL int MwLLClassicMacOSCallInit(void);
#endif

View file

@ -10,22 +10,45 @@
#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>
#ifdef __APPLE__
#import <CoreServices/CoreServices.h>
#else
#import <CoreGraphics/CoreGraphics.h>
#endif
@interface MilskoCocoaApplication : NSApplication {
MwBool doPending;
}
- (MwBool)pending;
@end
// Note: implements NSApplicationDelegate
@interface MilskoCocoaApplicationDelegate : NSObject {
NSApplication *appl;
MilskoCocoaApplication* appl;
}
- (MilskoCocoaApplicationDelegate *)initWithAppl:(NSApplication *)appl;
- (MilskoCocoaApplicationDelegate*)initWithAppl:(MilskoCocoaApplication*)appl;
@end
@interface MilskoCocoaWindow : NSWindow {
@ -34,9 +57,9 @@
// Note: implements NSWindowDelegate
@interface MilskoCocoaWindowDelegate : NSObject {
MilskoCocoaWindow *w;
NSWindow* w;
}
- (MilskoCocoaWindowDelegate *)initWithWin:(MilskoCocoaWindow *)win;
- (MilskoCocoaWindowDelegate*)initWithWin:(NSWindow*)win;
@end
/*
@ -52,139 +75,106 @@
retrieved appropriately.
*/
@interface MilskoFakePointer : NSView {
void *ptr;
void* ptr;
}
- (void)setPointer:(void *)ptr;
- (void *)pointer;
- (void)setPointer:(void*)ptr;
- (void*)pointer;
@end
@interface MilskoCocoaPixmap : NSObject {
MwBool valid;
int width;
int height;
unsigned char *buf;
NSImage *image;
NSBitmapImageRep *rep;
@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;
+ (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;
- (NSImage*)image;
@end
@interface MilskoCocoaView : NSView {
NSBitmapImageRep *rep;
NSGraphicsContext *context;
MwBool valid;
CGColorSpaceRef space;
CGDataProviderRef provider;
float width;
float height;
MwBool _child;
@public
draw_command* commands;
}
- (void)initRepAndContextWithWidth:(float)w Height:(float)h;
- (NSGraphicsContext *)context;
- (void)destroy;
- (NSBitmapImageRep *)getRep;
- (void)setChild;
@end
@interface MilskoCocoaSubView : MilskoCocoaView {
}
@end
@interface MilskoCocoa : NSObject {
NSApplication *application;
MwBool _forceRender;
MilskoCocoaWindow *window;
NSRect rect;
MilskoCocoaView *view;
MwLL parent;
MilskoFakePointer *handle;
unsigned int strHash;
NSEvent *lastEvent;
@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;
MilskoCocoaPixmap* cursorPixmap;
NSCursor* cursor;
NSModalSession modalSession;
MwBool pointerLocked;
MwBool mouseMoved;
MwBool pointerLocked;
MwBool mouseMoved;
MwBool rejectFirstTest;
}
+ (MilskoCocoa *)newWithParent:(MwLL)parent
x:(int)x
y:(int)y
width:(int)width
height:(int)height
handle:(MwLL)handle;
- (void)polygonWithPoints:(MwPoint *)points
points_count:(int)points_count
color:(MwLLColor)color;
- (void)lineWithPoints:(MwPoint *)points color:(MwLLColor)color;
- (void)getX:(int *)x Y:(int *)y W:(unsigned int *)w H:(unsigned int *)h;
- (void)setX:(int)x Y:(int)y;
- (void)setW:(int)w H:(int)h;
- (int)pending;
- (void)eventProcess:(NSEvent *)ev;
- (void)handleKeyEvent:(NSEvent *)ev ll:(MwLL)ll;
- (void)handleMouseEvent:(NSEvent *)ev ll:(MwLL)ll;
- (void)getNextEvent;
- (void)setTitle:(const char *)title;
- (void)drawPixmap:(MwLLPixmap)pixmap rect:(MwRect *)rect;
- (void)setIcon:(MwLLPixmap)pixmap;
- (void)forceRender;
- (void)setCursor:(MwCursor *)image mask:(MwCursor *)mask;
- (void)detachWithPoint:(MwPoint *)point;
- (void)show:(int)show;
- (void)makePopupWithParent:(MwLL)parent;
- (void)setSizeHintsWithMinX:(int)minx
MinY:(int)miny
MaxX:(int)maxx
MaxY:(int)maxy;
- (void)makeBorderless:(int)toggle;
- (void)focus;
- (void)grabPointer:(int)toggle;
- (void)setClipboard:(const char *)text;
- (void)makeToolWindow;
- (void)getCursorCoord:(MwPoint *)point;
- (void)getScreenSize:(MwRect *)rect;
- (void)destroy;
- (void)sendClipboardEvent;
- (MwLL)getParent;
- (NSView *)getView;
- (MilskoCocoaWindow *)getWindow;
- (NSView*)getView;
- (NSWindow*)getWindow;
- (void)nudge;
- (MilskoFakePointer *)getHandle;
+ (void)eventCanceller:(MilskoCocoa *)this;
- (void)pushCursor;
- (void)popCursor;
- (MilskoFakePointer*)getHandle;
@end
#define OBJC(x) x
#else
#define OBJC(x) void *
#define OBJC(x) void*
#endif
MWDECL int MwLLCocoaCallInit(void);
struct _MwLLCocoa {
struct _MwLLCommon common;
OBJC(MilskoCocoa *)
real;
struct _MwLLCommon common;
OBJC(MilskoCocoa*)
real;
};
struct _MwLLCocoaColor {
struct _MwLLCommonColor common;
struct _MwLLCommonColor common;
};
struct _MwLLCocoaPixmap {
struct _MwLLCommonPixmap common;
OBJC(MilskoCocoaPixmap *)
real;
struct _MwLLCommonPixmap common;
OBJC(MilskoCocoaPixmap*)
real;
};
#endif

View file

@ -1,46 +1,307 @@
/*!
* @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__
#include "Mw/BaseTypes.h"
#include <Mw/MachDep.h>
#include <Mw/TypeDefs.h>
#include <Mw/LowLevel.h>
#include <Mw/Abstract/Dynamic.h>
#include <wayland-client-protocol.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/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/xdg-toplevel-icon-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
#define CSD_LEFT_OFFSET(handle) handle->wayland.has_decorations ? 0 : CSD_BORDER_FRAME_LEFT
#define CSD_TOP_OFFSET(handle) handle->wayland.has_decorations ? 0 : CSD_BORDER_FRAME_TOP
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_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 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_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)
#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_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 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;
@ -60,10 +321,6 @@ 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;
@ -78,7 +335,7 @@ struct _MwLLWaylandSublevel {
MwLL parent;
struct xdg_surface* parent_xdg_surface;
struct xdg_surface* xdg_surface;
};
struct _MwLLWaylandPopup {
@ -95,12 +352,16 @@ 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;
};
@ -144,6 +405,8 @@ struct _MwLLWayland {
MwBool detatching;
MwPoint detach_point;
MwBool did_initial_resize;
/* Map of Wayland interfaces to their relevant setup functions. */
struct {
const char* key;
@ -156,11 +419,13 @@ struct _MwLLWayland {
wayland_protocol_t* value;
}* wl_protocol_map;
MwBool always_render;
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;
@ -171,10 +436,23 @@ struct _MwLLWayland {
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;
/* 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.*/
union {
struct {
struct wl_data_device_manager* wl;
struct zwp_primary_selection_device_manager_v1* zwp;
} clipboard_manager;
@ -186,7 +464,8 @@ struct _MwLLWayland {
MwBool supports_zwp;
uint32_t clipboard_serial;
wl_clipboard_device_context_t** clipboard_devices;
wl_clipboard_device_context_t** clipboard_devices_wl;
wl_clipboard_device_context_t** clipboard_devices_zwp;
struct wl_pointer* pointer;
MwU32 pointer_serial;
@ -215,6 +494,8 @@ struct _MwLLWayland {
MwBool force_render;
MwBool did_event_loop_early;
MwBool dispatching_resize;
struct _MwLLWaylandShmBuffer framebuffer;
struct _MwLLWaylandShmBuffer backbuffer;
struct _MwLLWaylandShmBuffer cursor;
@ -230,8 +511,6 @@ struct _MwLLWayland {
MwBool moving;
struct wl_surface* curSurface;
cairo_surface_t* front_cs;
cairo_surface_t* back_cs;
cairo_t* front_cairo;

View file

@ -30,9 +30,17 @@ struct _MwLLX11 {
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;
@ -49,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,33 +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

@ -39,6 +39,10 @@
#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"
@ -53,25 +57,30 @@
#define MwNfont "Vfont"
#define MwNboldFont "VboldFont"
#define MwNbackgroundPixmap "VbackgroundPixmap"
#define MwNmonospaceFont "VmonospaceFont"
#define MwNboldMonospaceFont "VboldMonospaceFont"
#define MwNactivateHandler "Cactivate" /* NULL/int* (MwListBox)/void* (MwTreeView) */
#define MwNresizeHandler "Cresize" /* NULL */
#define MwNtickHandler "Ctick" /* NULL */
#define MwNmenuHandler "Cmenu" /* MwMenu */
#define MwNmouseDownHandler "CmouseDown" /* MwLLMouse* */
#define MwNmouseUpHandler "CmouseUp" /* same as MwNmouseDownHandler */
#define MwNmouseMoveHandler "CmouseMove" /* MwPoint* */
#define MwNchangedHandler "Cchanged" /* NULL/int* (MwComboBox) */
#define MwNkeyHandler "Ckey" /* int* (MwLLKeyEnum or character code) */
#define MwNkeyReleaseHandler "CkeyRelease" /* same as MwNkeyHandler */
#define MwNcloseHandler "Cclose" /* NULL */
#define MwNfocusInHandler "CfocusIn" /* NULL */
#define MwNfocusOutHandler "CfocusOut" /* NULL */
#define MwNfileChosenHandler "CfileChosen" /* char* */
#define MwNdirectoryChosenHandler "CdirectoryChosen" /* char* */
#define MwNcolorChosenHandler "CcolorChosen" /* MwRGB* */
#define MwNdrawHandler "Cdraw" /* NULL */
#define MwNclipboardHandler "Cclipboard" /* char* */
#define MwNdarkThemeHandler "CdarkTheme" /* int* */
#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" /* MwMouse* */
#define MwNmouseUpHandler "CmouseUp" /* same as MwNmouseDownHandler */
#define MwNmouseMoveHandler "CmouseMove" /* MwPoint* */
#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 */
#define MwNfocusInHandler "CfocusIn" /* NULL */
#define MwNfocusOutHandler "CfocusOut" /* NULL */
#define MwNfileChosenHandler "CfileChosen" /* char* */
#define MwNdirectoryChosenHandler "CdirectoryChosen" /* char* */
#define MwNcolorChosenHandler "CcolorChosen" /* MwRGB* */
#define MwNdrawHandler "Cdraw" /* NULL */
#define MwNclipboardHandler "Cclipboard" /* char* */
#define MwNdarkThemeHandler "CdarkTheme" /* int* */
#endif

View file

@ -27,6 +27,8 @@ 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
@ -75,7 +77,6 @@ struct _MwVoidKeyValue {
struct _MwWidget {
char* name;
MwLLColor bgcolor;
int dark_theme;
MwLL lowlevel;
MwWidget parent;
@ -104,6 +105,11 @@ struct _MwWidget {
void* root_font;
void* root_boldfont;
void* root_monofont;
void* root_boldmonofont;
int top_step;
MwWidget* draw_queue;
int berserk;
};
@ -201,6 +207,15 @@ struct _MwListBoxPacket {
char*** names;
};
struct _MwBox {
int layout;
};
struct _MwMouse {
MwPoint point;
int button;
};
struct _MwClass {
MwHandlerWithStatus create;
MwHandler destroy;
@ -224,10 +239,4 @@ struct _MwClass {
void* reserved4;
};
/* Whether or not GetXY/SetXY works with global or local coordinates */
enum MwCoordinateType {
MwCoordinatesGlobal = 0,
MwCoordinatesLocal,
};
#endif

View file

@ -43,7 +43,7 @@ MWDECL MwClass MwOpenGLClass;
* @param handle Widget
*/
MwInline void MwOpenGLMakeCurrent(MwWidget handle) {
MwVaWidgetExecute(handle, "mwOpenGLMakeCurrent", NULL);
MwVaWidgetExecute(handle, "mwOpenGLMakeCurrent", NULL);
}
/*!
@ -52,10 +52,10 @@ MwInline void MwOpenGLMakeCurrent(MwWidget handle) {
* @param name Name
* @return Procedure
*/
MwInline void *MwOpenGLGetProcAddress(MwWidget handle, const char *name) {
void *out;
MwVaWidgetExecute(handle, "mwOpenGLGetProcAddress", &out, name);
return out;
MwInline void* MwOpenGLGetProcAddress(MwWidget handle, const char* name) {
void* out;
MwVaWidgetExecute(handle, "mwOpenGLGetProcAddress", &out, name);
return out;
}
/*!
@ -63,7 +63,7 @@ MwInline void *MwOpenGLGetProcAddress(MwWidget handle, const char *name) {
* @param handle Widget
*/
MwInline void MwOpenGLSwapBuffer(MwWidget handle) {
MwVaWidgetExecute(handle, "mwOpenGLSwapBuffer", NULL);
MwVaWidgetExecute(handle, "mwOpenGLSwapBuffer", NULL);
}
#ifdef __cplusplus

View file

@ -15,13 +15,14 @@
#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

@ -1,4 +1,4 @@
<?xml version="1.0"?>
<?xml version="1.0" ?>
<!--
Basically, you have to implement 10+n types:
- Integer (int)
@ -38,21 +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
- MwNbitmapFont
- MwNforceInverted
All widgets have properties that are common="yes".
Integer properties must be prefixed with I.
String properties must be prefixed with S.
@ -60,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" />
@ -78,51 +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" />
<integer name="bitmapFont" common="yes" />
<integer name="sevenSegment" />
<integer name="length" />
<integer name="forceInverted" />
<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" />
<handler name="clipboard">
<string />
</handler>
<handler name="darkTheme">
<integer pointer="yes" />
</handler>
</properties>
<enumerations>
<enumeration name="MwDIRECTION">
@ -149,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>
@ -402,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>
@ -493,7 +562,23 @@
</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>
@ -609,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" />
@ -713,15 +784,48 @@
</properties>
<functions>
<function name="Add">
<pointer name="parent" />
<pixmap name="pixmap" />
<string name="item" />
<arguments>
<pointer name="parent" />
<pixmap name="pixmap" />
<string name="item" />
</arguments>
</function>
<function name="Delete">
<pointer name="item" />
<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;

View file

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

View file

@ -1,7 +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,36 +30,56 @@ 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");
add_cflags(`pkg-config --cflags cairo wayland-client xkbcommon`);
add_libs(`pkg-config --libs cairo wayland-client xkbcommon`);
if (param_get("opengl")) {
add_libs(`pkg-config --libs egl wayland-egl`);
add_cflags("-DWAYLAND_LOAD_OPENGL");
}
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_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(/^cocoa$/, @backends)) {
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
# 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";
@ -63,19 +87,26 @@ if (grep(/^cocoa$/, @backends)) {
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`);
}
}
@ -108,11 +139,14 @@ new_object("src/widget/treeview.c");
new_object("src/widget/viewport.c");
new_object("src/widget/window.c");
new_object("src/widget/opengl.c");
new_object("src/widget/vulkan.c");
if (param_get("opengl")) {
new_object("src/widget/opengl.c");
add_cflags("-DMW_OPENGL");
}
if (param_get("vulkan")) {
new_object("src/widget/vulkan.c");
add_cflags("-DMW_VULKAN");
}
new_object("src/dialog/*.c");
@ -120,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");
@ -138,6 +173,7 @@ 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;
@ -58,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,6 +12,36 @@ void* MwDynamicSymbol(void* handle, const char* symbol) {
void MwDynamicClose(void* handle) {
FreeLibrary(handle);
}
#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;
}
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;
}
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

@ -32,6 +32,29 @@ void MwTimeSleep(int ms) {
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;

View file

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

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

@ -0,0 +1,216 @@
#include <Mw/Milsko.h>
#include "../../external/stb_ds.h"
static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
MwLL r;
MwLLCreateCommon(r);
/* 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) {
(void)handle;
}
static void MwLLEndDrawImpl(MwLL handle) {
(void)handle;
}
static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLLColor color) {
int i;
PolyHandle p = OpenPoly();
RGBColor col;
col.red = color->common.red;
col.green = color->common.green;
col.blue = color->common.blue;
RGBBackColor(&col);
RGBForeColor(&col);
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();
PaintPoly(p);
KillPoly(p);
}
static void MwLLLineImpl(MwLL handle, MwPoint* points, MwLLColor color) {
RGBColor col;
col.red = color->common.red;
col.green = color->common.green;
col.blue = color->common.blue;
RGBBackColor(&col);
RGBForeColor(&col);
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) {
return GetNextEvent(everyEvent, &handle->cmacos.event);
}
static void MwLLNextEventImpl(MwLL handle) {
}
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) {
/* TODO */
(void)handle;
(void)text;
}
static void MwLLGetClipboardImpl(MwLL handle) {
}
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);

File diff suppressed because it is too large Load diff

View file

@ -8,6 +8,14 @@ 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);
@ -26,6 +34,11 @@ static void detect_darktheme(MwLL handle) {
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);
}
@ -66,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;
int d = GET_WHEEL_DELTA_WPARAM(wp);
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);
@ -265,7 +278,7 @@ 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 = 1;
r->gdi.get_clipboard = 0;
if(parent == NULL) r->gdi.get_darktheme = 1;
r->gdi.force_render = 0;
r->gdi.grabbed = 0;
@ -589,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);
@ -621,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);
@ -735,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;
@ -753,7 +767,8 @@ static void MwLLSetClipboardImpl(MwLL handle, const char* text) {
}
}
static void MwLLGetClipboardImpl(MwLL handle) {
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 */
}
@ -804,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, ...) _X_SENTINEL(0);
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,16 +193,16 @@ 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),
MWM_FUNC_MINIMIZE = (1L << 3),
MWM_FUNC_MAXIMIZE = (1L << 4),
MWM_FUNC_CLOSE = (1L << 5)
MWM_FUNC_ALL = (1L << 0),
MWM_FUNC_RESIZE = (1L << 1),
MWM_FUNC_MOVE = (1L << 2),
MWM_FUNC_MINIMIZE = (1L << 3),
MWM_FUNC_MAXIMIZE = (1L << 4),
MWM_FUNC_CLOSE = (1L << 5)
};
static unsigned long mask = ExposureMask | StructureNotifyMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | KeymapNotify | FocusChangeMask;
@ -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;
@ -188,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");
@ -200,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;
@ -215,6 +413,14 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
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);
@ -240,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);
@ -258,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);
}
@ -267,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) {
@ -414,7 +638,21 @@ 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;
}
@ -424,44 +662,70 @@ 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);
@ -516,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))) {
@ -563,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;
@ -602,7 +908,9 @@ static MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, int wid
r->x11.handle = handle;
#ifdef USE_XRENDER
r->x11.use_xrender = XRenderQueryExtension(handle->x11.display, &evbase, &erbase) ? 1 : 0;
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);
@ -653,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);
@ -811,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);
@ -849,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);
@ -953,17 +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 void MwLLGetClipboardImpl(MwLL handle) {
/* TODO */
static void MwLLGetClipboardImpl(MwLL handle, int clipboard_type) {
(void)clipboard_type;
(void)handle;
if(handle->x11.clipboard_pending) return;
XConvertSelection(handle->x11.display, handle->x11.clipboard, handle->x11.utf8_string, handle->x11.selection, handle->x11.window, CurrentTime);
handle->x11.clipboard_pending = 1;
handle->x11.clipboard_time = MwTimeGetTick();
}
static void MwLLMakeToolWindowImpl(MwLL handle) {
@ -1005,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;
MwWidget h = (MwWidget)handle->common.user;
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;
MwWidget h = (MwWidget)handle->common.user;
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;
@ -133,7 +169,9 @@ static void lldarkthemehandler(MwLL handle, void* data) {
int* ptr = data;
if(IsFirstVisible(h)) {
MwSetDarkTheme(h, *ptr);
MwVaApply(h,
MwNdarkTheme, *ptr,
NULL);
MwDispatchUserHandler(h, MwNdarkThemeHandler, data);
}
@ -164,12 +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;
@ -215,8 +259,10 @@ MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent,
#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_font = MwFontLoad(MwTTFData, MwTTFDataSize);
h->root_boldfont = MwFontLoad(MwBoldTTFData, MwBoldTTFDataSize);
h->root_monofont = MwFontLoad(MwMonospaceTTFData, MwMonospaceTTFDataSize);
h->root_boldmonofont = MwFontLoad(MwBoldMonospaceTTFData, MwBoldMonospaceTTFDataSize);
} else
#endif
{
@ -252,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);
@ -288,6 +350,8 @@ 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);
@ -349,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;
@ -362,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);
@ -380,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) {
@ -416,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;
@ -440,6 +530,17 @@ void MwSetInteger(MwWidget handle, const char* key, int n) {
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) {
@ -516,6 +617,8 @@ int MwGetInteger(MwWidget handle, const char* key) {
#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);
}
@ -530,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;
@ -565,7 +668,7 @@ void* MwGetVoid(MwWidget handle, const char* key) {
if(v != NULL) return v;
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2)
if(strcmp(key, MwNfont) == 0 || strcmp(key, MwNboldFont) == 0) {
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) {
@ -574,8 +677,12 @@ void* MwGetVoid(MwWidget handle, const char* key) {
while(w != NULL && v == NULL) {
if(strcmp(key, MwNfont) == 0) {
v = w->root_font;
} else {
} 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;
@ -707,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);
@ -746,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]);
}
if(handle->lowlevel != NULL) MwForceRender(handle);
}
void MwSetDarkTheme(MwWidget handle, int toggle) {
int old = handle->dark_theme;
if(old != toggle) {
handle->dark_theme = toggle;
force_render_all(handle);
}
MwVaApply(handle,
MwNdarkTheme, toggle,
NULL);
}
MwWidget MwGetParent(MwWidget handle) {
@ -770,15 +866,16 @@ MwWidget MwGetParent(MwWidget handle) {
typedef int (*call_t)(void);
int MwLibraryInit(void) {
call_t calls[] = {
#ifdef USE_COCOA
MwLLCocoaCallInit,
#endif
#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
@ -791,6 +888,21 @@ int MwLibraryInit(void) {
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
"\n");
return 1;
}
@ -851,6 +963,10 @@ int MwGetCoordinateType(MwWidget handle) {
if(handle->parent == NULL || handle->parent->lowlevel == NULL) {
return handle->lowlevel->common.coordinate_type;
} else {
return MwCoordinatesLocal;
return MwCOORDINATE_LOCAL;
}
};
}
void MwGetClipboard(MwWidget handle, int clipboard_type) {
MwLLGetClipboard(handle->lowlevel, clipboard_type);
}

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

@ -13,7 +13,7 @@
static int get_color_diff(MwWidget handle) {
if(MwGetInteger(handle, MwNmodernLook)) {
return 46;
return 40;
} else {
return 80;
}
@ -29,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;
@ -107,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;
@ -124,7 +134,7 @@ 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);
@ -155,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;
@ -170,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;
@ -234,21 +255,19 @@ 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;
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;
@ -257,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;
@ -277,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);
@ -289,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);

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

@ -45,17 +45,205 @@ void (*MwLLEndStateChange)(MwLL handle) = NULL;
void (*MwLLFocus)(MwLL handle) = NULL;
void (*MwLLGrabPointer)(MwLL handle, int toggle) = NULL;
void (*MwLLSetClipboard)(MwLL handle, const char* text) = NULL;
void (*MwLLGetClipboard)(MwLL handle) = NULL;
void (*MwLLSetClipboard)(MwLL handle, const char* text, int clipboard_type) = NULL;
void (*MwLLGetClipboard)(MwLL, int clipboard_type) = NULL;
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_error_is_set);
DBUS_FUNC(dbus_error_free);
DBUS_FUNC(dbus_message_new_method_call);
DBUS_FUNC(dbus_message_iter_init_append);
DBUS_FUNC(dbus_message_iter_append_basic);
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_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) {
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, &ctx->dbus_args);
tbl->dbus_message_iter_append_basic(&ctx->dbus_args, 's', &namespace);
tbl->dbus_message_iter_append_basic(&ctx->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, &ctx->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(tbl->dbus_message_iter_get_arg_type(&ctx->dbus_args) != 'v') {
fprintf(stderr, "[WARNING] Couldn't get %s::%s: Expected outer variant\n", namespace, key);
tbl->dbus_message_unref(ctx->dbus_reply);
return MwFALSE;
}
tbl->dbus_message_iter_recurse(&ctx->dbus_args, &ctx->dbus_variant);
/* Some portals wrap the value in a second variant */
if(tbl->dbus_message_iter_get_arg_type(&ctx->dbus_variant) == 'v') {
tbl->dbus_message_iter_recurse(&ctx->dbus_variant, &ctx->dbus_inner_variant);
tbl->dbus_message_iter_get_basic(&ctx->dbus_inner_variant, out);
} else {
tbl->dbus_message_iter_get_basic(&ctx->dbus_variant, out);
}
tbl->dbus_message_unref(ctx->dbus_msg);
return MwTRUE;
}
MWDECL MwBool MwLLDBusPortalWatch(MwLLDBusFuncTable* tbl, MwLLDBusContext* ctx, const char* portal) {
if(!ctx->dbus_conn) {
return MwFALSE;
}
char filter_string[2048];
MwStringPrintIntoBuffer(filter_string, sizeof(filter_string), "type='%s',interface=%s", "signal", portal);
dbus_bus_add_match(ctx->dbus_conn, filter_string, &ctx->dbus_err);
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) {
DBusMessage* msg;
DBusMessageIter args, msg_value;
const char* msg_namespace;
const char* msg_key;
MwU32 msg_value_content;
if(!ctx->dbus_conn) {
return MwFALSE;
}
dbus_connection_read_write(ctx->dbus_conn, 0);
msg = dbus_connection_pop_message(ctx->dbus_conn);
if (NULL == msg) {
return MwFALSE;
}
// check if the message is a signal from the correct interface and with the correct name
if (dbus_message_is_signal(msg, portal, "SettingChanged")) {
// read the parameters
if (!dbus_message_iter_init(msg, &args))
fprintf(stderr, "[WARNING] Message has no arguments\n");
else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args))
fprintf(stderr, "[WARNING] Argument is not string\n");
else {
dbus_message_iter_get_basic(&args, &msg_namespace);
dbus_message_iter_next(&args);
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
dbus_message_iter_next(&args);
dbus_message_iter_recurse(&args, &msg_value);
dbus_message_iter_get_basic(&msg_value, &msg_value_content);
listener(handle, msg_value_content);
}
}
}
// free the message
dbus_message_unref(msg);
}
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;
}

3022
src/text/font/boldmonottf.c Normal file

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

3022
src/text/font/monottf.c Normal file

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -4,56 +4,95 @@
#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, MwPoint* point, const char* text, int bold, int align, MwLLColor color) {
MwFLFont ttf = MwGetVoid(handle, bold ? MwNboldFont : MwNfont);
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;
if(ttf == NULL) return 1;
tw = MwTextWidth(handle, text);
th = MwTextHeight(handle, text);
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;
FT_Bitmap* bmp;
int cy, cx;
int l = MwUTF8ToUTF32(text, &c);
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 * 14 / ttf->face->units_per_EM;
y += ttf->face->height * ttf->px / ttf->face->units_per_EM;
continue;
}
FT_Load_Char(ttf->face, c, FT_LOAD_RENDER);
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 + 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);
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;
opx[3] = bmp->buffer[cy * bmp->pitch + cx];
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->metrics.horiAdvance / 64;
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);
@ -62,12 +101,6 @@ static int ft2_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int
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);
@ -75,45 +108,53 @@ static int ft2_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int
return 0;
}
static int ft2_MwTextWidth(MwWidget handle, const char* text) {
MwFLFont ttf = MwGetVoid(handle, MwNfont);
int tw = 0, mtw = 0;
if(ttf == NULL) return -1;
static int ft2_MwTextWidth(MwFLFont ttf, const char* text) {
int tw = 0, mtw = 0;
while(text[0] != 0) {
int c;
int l = MwUTF8ToUTF32(text, &c);
if(l <= 0) break;
text += l;
int c, c2;
FT_Vector vec;
const char* old_text;
text += MwUTF8ToUTF32(text, &c);
if(c == '\n') {
tw = 0;
continue;
}
FT_Load_Char(ttf->face, c, FT_LOAD_RENDER);
ft_table.FT_Load_Char(ttf->face, c, FT_LOAD_DEFAULT);
tw += ttf->face->glyph->metrics.horiAdvance / 64;
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;
return mtw + 1;
}
static int ft2_MwTextHeight(MwWidget handle, int count) {
MwFLFont ttf = MwGetVoid(handle, MwNfont);
if(ttf == NULL) return -1;
return (ttf->face->height * 14 / ttf->face->units_per_EM) * count;
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) {
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_Init_FreeType(&ttf->library);
FT_New_Memory_Face(ttf->library, ttf->data, size, 0, &ttf->face);
ft_table.FT_Init_FreeType(&ttf->library);
ft_table.FT_New_Memory_Face(ttf->library, ttf->data, size, 0, &ttf->face);
FT_Set_Pixel_Sizes(ttf->face, 0, 14);
ttf->px = px;
ft_table.FT_Set_Pixel_Sizes(ttf->face, 0, ttf->px);
return ttf;
}
@ -121,14 +162,28 @@ static void* ft2_MwFontLoad(unsigned char* data, unsigned int size) {
static void ft2_MwFontFree(void* handle) {
MwFLFont ttf = handle;
FT_Done_Face(ttf->face);
FT_Done_FreeType(ttf->library);
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;

View file

@ -11,31 +11,31 @@ struct _MwFLFont {
int descent;
};
static int stbtt_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color) {
MwFLFont ttf = MwGetVoid(handle, bold ? MwNboldFont : MwNfont);
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;
if(ttf == NULL) return 1;
tw = MwTextWidth(handle, text);
th = MwTextHeight(handle, text);
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;
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 += (ttf->ascent - ttf->descent) * ttf->scale;
y += ceil((ttf->ascent - ttf->descent) * ttf->scale);
continue;
}
@ -49,18 +49,33 @@ static int stbtt_MwDrawText(MwWidget handle, MwPoint* point, const char* text, i
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;
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;
opx[3] = out[cy * ow + cx];
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 += ax * ttf->scale;
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);
}
@ -71,12 +86,6 @@ static int stbtt_MwDrawText(MwWidget handle, MwPoint* point, const char* text, i
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);
@ -84,38 +93,52 @@ static int stbtt_MwDrawText(MwWidget handle, MwPoint* point, const char* text, i
return 0;
}
static int stbtt_MwTextWidth(MwWidget handle, const char* text) {
MwFLFont ttf = MwGetVoid(handle, MwNfont);
int ax, lsb;
int tw = 0;
if(ttf == NULL) return -1;
static int stbtt_MwTextWidth(MwFLFont ttf, const char* text) {
int ax, lsb;
int tw = 0, mtw = 0;
while(text[0] != 0) {
int c;
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 += ax * ttf->scale;
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 tw;
return mtw + 1;
}
static int stbtt_MwTextHeight(MwWidget handle, int count) {
MwFLFont ttf = MwGetVoid(handle, MwNfont);
if(ttf == NULL) return -1;
return (ttf->ascent - ttf->descent) * ttf->scale * count;
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) {
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_ScaleForPixelHeight(&ttf->font, 16);
ttf->scale = stbtt_ScaleForMappingEmToPixels(&ttf->font, px);
stbtt_GetFontVMetrics(&ttf->font, &ttf->ascent, &ttf->descent, 0);
return ttf;

View file

@ -1,10 +1,10 @@
#include <Mw/Milsko.h>
int (*MwFLDrawText)(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color) = NULL;
int (*MwFLTextWidth)(MwWidget handle, const char* text) = NULL;
int (*MwFLTextHeight)(MwWidget handle, int count) = NULL;
void* (*MwFLFontLoad)(unsigned char* data, unsigned int size) = NULL;
void (*MwFLFontFree)(void* handle) = NULL;
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
@ -13,40 +13,93 @@ void (*MwFLFontFree)(void* handle) = NULL;
#define FontWidth 7
#define FontHeight 14
static void bitmap_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color);
static void bitmap_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, MwLLColor color);
void MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color) {
if(strlen(text) == 0) return;
#ifdef TTF
if(MwFLDrawText)
if(MwGetInteger(handle, MwNbitmapFont) || MwFLDrawText(handle, point, text, bold, align, color))
#endif
bitmap_MwDrawText(handle, point, text, bold, align, 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;
}
int MwTextWidth(MwWidget handle, const char* text) {
#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) && (st = MwFLTextWidth(handle, text)) != -1) return st;
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, const char* text) {
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;
@ -58,23 +111,22 @@ int MwTextHeight(MwWidget handle, const char* text) {
}
#ifdef TTF
if(MwFLTextHeight)
if(!MwGetInteger(handle, MwNbitmapFont) && (st = MwFLTextHeight(handle, c)) != -1) return st;
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);
return MwFLFontLoad(data, size, 14);
return NULL;
}
void MwFontFree(void* handle) {
if(MwFLFontFree)
return MwFLFontFree(handle);
if(MwFLFontFree) MwFLFontFree(handle);
}
static void bitmap_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color) {
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;
@ -82,8 +134,8 @@ static void bitmap_MwDrawText(MwWidget handle, MwPoint* point, const char* text,
MwLLPixmap p;
if(strlen(text) == 0) text = " ";
tw = MwTextWidth(handle, text);
th = MwTextHeight(handle, text);
tw = MwTextWidth(handle, NULL, text);
th = MwTextHeight(handle, NULL, text);
px = malloc(tw * th * 4);
memset(px, 0, tw * th * 4);
@ -129,12 +181,6 @@ static void bitmap_MwDrawText(MwWidget handle, MwPoint* point, const char* text,
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);

View file

@ -2,7 +2,12 @@
#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);
@ -11,25 +16,14 @@ static int create(MwWidget handle) {
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);
if(MwGetInteger(handle, MwNhasBorder)) {
MwDrawFrame(handle, &r, base, MwGetInteger(handle, MwNinverted));
}
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)
@ -53,6 +47,7 @@ static void layout(MwWidget handle) {
sz -= s + Margin;
} else {
sum += n;
sz -= Margin;
}
}
@ -80,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 */

View file

@ -2,12 +2,13 @@
#include "../../external/stb_ds.h"
static int create(MwWidget handle) {
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;
}
@ -76,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);
@ -92,7 +93,7 @@ static void prop_change(MwWidget handle, const char* key) {
}
MwClassRec MwButtonClassRec = {
create, /* create */
wcreate, /* create */
NULL, /* destroy */
draw, /* draw */
click, /* click */

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 */

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 */

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,30 +54,32 @@ static void draw(MwWidget handle) {
len = (r.width - p.x * 2) / w;
show = malloc(len * 4 + 1);
memset(show, 0, len * 4 + 1);
if(len > 0) {
show = malloc(len * 4 + 1);
memset(show, 0, len * 4 + 1);
start = (t->cursor - 1) / len;
start *= len;
if((attr = MwGetInteger(handle, MwNhideInput)) == MwDEFAULT || !attr) {
MwUTF8Copy(str, start, show, 0, len);
} else {
for(i = 0; i < MwUTF8Length(str) - start; i++) show[i] = '*';
start = (t->cursor - 1) / len;
start *= len;
if((attr = MwGetInteger(handle, MwNhideInput)) == MwDEFAULT || !attr) {
MwUTF8Copy(str, start, show, 0, len);
} else {
for(i = 0; i < MwUTF8Length(str) - start; i++) show[i] = '*';
}
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, font, show);
currc.y = (r.height - h) / 2;
currc.width = 1;
currc.height = h;
MwDrawRect(handle, &currc, text);
free(show);
}
MwDrawText(handle, &p, show, 0, 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.y = (r.height - h) / 2;
currc.width = 1;
currc.height = h;
MwDrawRect(handle, &currc, text);
free(show);
}
MwLLFreeColor(text);
@ -109,7 +113,7 @@ static void key(MwWidget handle, int code) {
} else if(code == MwLLKeyEnter) {
MwDispatchUserHandler(handle, MwNactivateHandler, NULL);
} else if(code == (MwLLControlMask | 'v')) {
MwLLGetClipboard(handle->lowlevel);
MwLLGetClipboard(handle->lowlevel, MwCLIPBOARD_MAIN);
} else if(!(code & MwLLKeyMask)) {
int incr = 0;
out = malloc(strlen(str) + 5 + 1);
@ -129,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);
@ -147,7 +165,11 @@ 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 = malloc(strlen(str) + strlen(data) + 1);
char* out;
if(!str) {
str = "";
}
out = malloc(strlen(str) + strlen(data) + 1);
if(str == NULL) str = "";
@ -159,17 +181,19 @@ static void clipboard(MwWidget handle, const char* 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 */

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);
@ -46,7 +46,7 @@ static void prop_change(MwWidget handle, const char* key) {
}
MwClassRec MwFrameClassRec = {
create, /* create */
wcreate, /* create */
NULL, /* destroy */
draw, /* draw */
NULL, /* click */

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);
@ -42,7 +42,7 @@ static void prop_change(MwWidget handle, const char* key) {
}
MwClassRec MwImageClassRec = {
create, /* create */
wcreate, /* create */
NULL, /* destroy */
draw, /* draw */
NULL, /* click */

View file

@ -4,7 +4,7 @@
#define Spacing 1
static int create(MwWidget handle) {
static int wcreate(MwWidget handle) {
MwLabel lab = malloc(sizeof(*lab));
lab->segment = NULL;
@ -316,9 +316,9 @@ static void draw(MwWidget handle) {
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;
@ -326,11 +326,11 @@ static void draw(MwWidget handle) {
p.x += 1;
p.y += 1;
MwDrawText(handle, &p, str, MwGetInteger(handle, MwNbold), MwALIGNMENT_CENTER, shadow);
MwDrawText(handle, NULL, &p, str, MwALIGNMENT_CENTER, shadow);
p.x -= 1;
p.y -= 1;
MwDrawText(handle, &p, str, MwGetInteger(handle, MwNbold), MwALIGNMENT_CENTER, text);
MwDrawText(handle, NULL, &p, str, MwALIGNMENT_CENTER, text);
}
MwLLFreeColor(shadow);
@ -360,7 +360,7 @@ static void func_handler(MwWidget handle, const char* name, void* out, va_list v
}
MwClassRec MwLabelClassRec = {
create, /* create */
wcreate, /* create */
destroy, /* destroy */
draw, /* draw */
NULL, /* click */

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));
@ -117,20 +119,20 @@ 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;
MwListBox lb = handle->parent->internal;
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);
@ -152,12 +154,12 @@ 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;
MwListBox lb = handle->parent->internal;
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,8 +252,8 @@ 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);
}
@ -259,26 +261,26 @@ static void frame_draw(MwWidget handle) {
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;
}
@ -297,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);
@ -316,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);
@ -340,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));
@ -400,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);
@ -408,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;
@ -593,7 +595,7 @@ static void tick(MwWidget handle) {
}
MwClassRec MwListBoxClassRec = {
create, /* create */
wcreate, /* create */
destroy, /* destroy */
draw, /* draw */
NULL, /* click */

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) {
@ -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 */

View file

@ -1,6 +1,6 @@
#include <Mw/Milsko.h>
static int create(MwWidget handle) {
static int wcreate(MwWidget handle) {
int st;
MwEntry e;
@ -98,14 +98,14 @@ static void mouse_up(MwWidget handle, void* ptr) {
int h = MwGetInteger(handle, MwNheight);
const char* str = MwGetText(handle, MwNtext);
if(((MwLLMouse*)ptr)->button != MwLLMouseLeft) return;
if(((MwMouse*)ptr)->button != MwMOUSE_LEFT) return;
if(e->mouse.x >= (w - e->right)) {
char s[512];
if(e->mouse.y >= (h / 2)) {
sprintf(s, "%g", atof(str) - 1);
MwStringPrintIntoBuffer(s, 512, "%g", atof(str) - 1);
} else {
sprintf(s, "%g", atof(str) + 1);
MwStringPrintIntoBuffer(s, 512, "%g", atof(str) + 1);
}
MwSetText(handle, MwNtext, s);
}
@ -116,7 +116,7 @@ static void mouse_up(MwWidget handle, void* ptr) {
static void mouse_down(MwWidget handle, void* ptr) {
MwEntry e = handle->internal;
if(((MwLLMouse*)ptr)->button != MwLLMouseLeft) return;
if(((MwMouse*)ptr)->button != MwMOUSE_LEFT) return;
e->mouse = handle->mouse_point;
@ -128,7 +128,7 @@ static void prop_change(MwWidget handle, const char* prop) {
}
MwClassRec MwNumberEntryClassRec = {
create, /* create */
wcreate, /* create */
destroy, /* destroy */
draw, /* draw */
NULL, /* click */

View file

@ -1,8 +1,13 @@
#ifndef __APPLE__
#include <Mw/Milsko.h>
#ifndef MW_OPENGL
#define MW_OPENGL_NO_INCLUDE
#endif
#include <Mw/Widget/OpenGL.h>
#ifdef MW_OPENGL
#ifdef USE_GDI
typedef HGLRC(WINAPI* MWwglCreateContext)(HDC);
typedef BOOL(WINAPI* MWwglMakeCurrent)(HDC, HGLRC);
@ -57,10 +62,51 @@ typedef struct waylandopengl {
EGLContext egl_context;
EGLSurface egl_surface;
EGLConfig egl_config;
void* gllib;
void* wlgllib;
EGLBoolean (*eglGetConfigs)(EGLDisplay display,
EGLConfig* configs,
EGLint config_size,
EGLint* num_config);
EGLBoolean (*eglInitialize)(EGLDisplay display,
EGLint* major,
EGLint* minor);
EGLContext (*eglCreateContext)(EGLDisplay display,
EGLConfig config,
EGLContext share_context,
EGLint const* attrib_list);
EGLBoolean (*eglMakeCurrent)(EGLDisplay display,
EGLSurface draw,
EGLSurface read,
EGLContext context);
void* (*eglGetProcAddress)(char const* procname);
EGLBoolean (*eglSwapBuffers)(EGLDisplay display,
EGLSurface surface);
EGLBoolean (*eglSwapInterval)(EGLDisplay display,
EGLint interval);
EGLint (*eglGetError)(void);
EGLBoolean (*eglBindAPI)(EGLenum api);
EGLDisplay (*eglGetDisplay)(NativeDisplayType native_display);
EGLSurface (*eglCreateWindowSurface)(EGLDisplay display,
EGLConfig config,
NativeWindowType native_window,
EGLint const* attrib_list);
EGLBoolean (*eglChooseConfig)(EGLDisplay display,
EGLint const* attrib_list,
EGLConfig* configs,
EGLint config_size,
EGLint* num_config);
struct wl_egl_window* (*wl_egl_window_create)(struct wl_surface* surface,
int width, int height);
void (*wl_egl_window_resize)(struct wl_egl_window* egl_window,
int width, int height,
int dx, int dy);
} waylandopengl_t;
#endif
static int create(MwWidget handle) {
static int wcreate(MwWidget handle) {
void* r = NULL;
MwWidget w = handle;
@ -136,7 +182,6 @@ static int create(MwWidget handle) {
#endif
#ifdef USE_WAYLAND
if(handle->lowlevel->common.type == MwLLBackendWayland) {
int err;
EGLint numConfigs;
EGLint majorVersion;
EGLint minorVersion;
@ -165,15 +210,60 @@ static int create(MwWidget handle) {
1,
EGL_NONE};
EGLDisplay display;
waylandopengl_t* o = r = malloc(sizeof(*o));
MwLL topmost_parent = handle->lowlevel->wayland.parent;
handle->lowlevel->wayland.always_render = MwTRUE;
topmost_parent->wayland.always_render = MwTRUE;
waylandopengl_t* o = r = malloc(sizeof(*o));
MwWaylandAlwaysRender = MwTRUE;
while(topmost_parent->wayland.parent != NULL) {
topmost_parent = topmost_parent->wayland.parent;
topmost_parent->wayland.always_render = MwTRUE;
o->gllib = MwDynamicOpen("libEGL.so");
if(!o->gllib) {
printf("Could not load OpenGL widget under Wayland! libEGL.so missing.\n");
return 1;
}
o->wlgllib = MwDynamicOpen("libwayland-egl.so");
if(!o->gllib) {
printf("Could not load OpenGL widget under Wayland! libwayland-egl.so missing.\n");
return 1;
}
#define EGL_FUNC(x) \
o->x = MwDynamicSymbol(o->gllib, #x); \
if(!o->x) { \
printf("Could not load OpenGL widget under Wayland! " #x " missing.\n"); \
return 1; \
};
#define WAYLAND_EGL_FUNC(x) \
o->x = MwDynamicSymbol(o->wlgllib, #x); \
if(!o->x) { \
printf("Could not load OpenGL widget under Wayland! " #x " missing.\n"); \
return 1; \
};
EGL_FUNC(eglGetConfigs)
EGL_FUNC(eglInitialize)
EGL_FUNC(eglCreateContext)
EGL_FUNC(eglMakeCurrent)
EGL_FUNC(eglGetProcAddress)
EGL_FUNC(eglSwapBuffers)
EGL_FUNC(eglSwapInterval)
EGL_FUNC(eglGetError)
EGL_FUNC(eglBindAPI)
EGL_FUNC(eglGetDisplay)
EGL_FUNC(eglCreateWindowSurface)
EGL_FUNC(eglChooseConfig)
WAYLAND_EGL_FUNC(wl_egl_window_create)
WAYLAND_EGL_FUNC(wl_egl_window_resize)
#define eglGetConfigs o->eglGetConfigs
#define eglInitialize o->eglInitialize
#define eglCreateContext o->eglCreateContext
#define eglMakeCurrent o->eglMakeCurrent
#define eglGetProcAddress o->eglGetProcAddress
#define eglSwapBuffers o->eglSwapBuffers
#define eglSwapInterval o->eglSwapInterval
#define eglGetError o->eglGetError
#define wl_egl_window_create o->wl_egl_window_create
#define eglBindAPI o->eglBindAPI
#define eglGetDisplay o->eglGetDisplay
#define wl_egl_window_resize o->wl_egl_window_resize
#define eglCreateWindowSurface o->eglCreateWindowSurface
#define eglChooseConfig o->eglChooseConfig
display =
eglGetDisplay((EGLNativeDisplayType)handle->lowlevel->wayland.display);
@ -231,6 +321,7 @@ static int create(MwWidget handle) {
if(!eglMakeCurrent(display, surface, surface, context)) {
printf("ERROR: eglMakeCurrent (setup): %0X\n", eglGetError());
}
eglSwapInterval(o->egl_display, 0);
o->egl_display = display;
o->egl_surface = surface;
@ -294,8 +385,8 @@ static void mwOpenGLMakeCurrentImpl(MwWidget handle) {
#ifdef USE_GDI
if(handle->lowlevel->common.type == MwLLBackendGDI) {
gdiopengl_t* o = handle->internal;
void (*swap_interval_ext)(int) = NULL;
gdiopengl_t* o = handle->internal;
BOOL(APIENTRY * swap_interval_ext)(int) = NULL;
o->wglMakeCurrent(o->dc, o->gl);
@ -340,8 +431,6 @@ static void mwOpenGLMakeCurrentImpl(MwWidget handle) {
o->egl_context)) {
printf("ERROR: eglMakeCurrent, %0X\n", eglGetError());
}
eglSwapInterval(o->egl_display, 1);
}
#endif
}
@ -365,6 +454,7 @@ static void mwOpenGLSwapBufferImpl(MwWidget handle) {
#ifdef USE_WAYLAND
if(handle->lowlevel->common.type == MwLLBackendWayland) {
waylandopengl_t* o = handle->internal;
eglSwapInterval(o->egl_display, 0);
if(!eglSwapBuffers(o->egl_display, o->egl_surface)) {
printf("ERROR: eglSwapBuffers, %0X\n", eglGetError());
};
@ -392,6 +482,7 @@ static void* mwOpenGLGetProcAddressImpl(MwWidget handle, const char* name) {
#endif
#ifdef USE_WAYLAND
if(handle->lowlevel->common.type == MwLLBackendWayland) {
waylandopengl_t* o = handle->internal;
return eglGetProcAddress(name);
}
#endif
@ -412,7 +503,7 @@ static void func_handler(MwWidget handle, const char* name, void* out,
}
}
MwClassRec MwOpenGLClassRec = {create, /* create */
MwClassRec MwOpenGLClassRec = {wcreate, /* create */
destroy, /* destroy */
NULL, /* draw */
NULL, /* click */
@ -430,5 +521,10 @@ MwClassRec MwOpenGLClassRec = {create, /* create */
NULL, /* clipboard */
NULL, NULL, NULL, NULL};
MwClass MwOpenGLClass = &MwOpenGLClassRec;
#else
MWDECL MwClass MwOpenGLClass;
MwClass MwOpenGLClass = NULL;
#endif
#endif

View file

@ -7,124 +7,125 @@
#import <mach-o/dyld.h>
@interface MacOpenGLWidget : NSObject {
NSOpenGLPixelFormat *pixelFormat;
NSOpenGLContext *glc;
MilskoCocoa *_win;
NSOpenGLPixelFormat* pixelFormat;
NSOpenGLContext* glc;
MilskoCocoa* _win;
}
- (MacOpenGLWidget *)initWithWindow:(MilskoCocoa *)w;
- (MacOpenGLWidget*)initWithWindow:(MilskoCocoa*)w;
- (void)destroy;
- (void)makeCurrent;
- (void)swapBuffer;
- (void *)getProcAddressWithName:(const char *)name;
- (void*)getProcAddressWithName:(const char*)name;
@end
static int create(MwWidget handle) {
void *r = NULL;
MwWidget w = handle;
static int wcreate(MwWidget handle) {
void* r = NULL;
MwWidget w = handle;
int x = MwGetInteger(w, MwNx);
int y = MwGetInteger(w, MwNy);
int width = MwGetInteger(w, MwNwidth);
int height = MwGetInteger(w, MwNheight);
int x = MwGetInteger(w, MwNx);
int y = MwGetInteger(w, MwNy);
int width = MwGetInteger(w, MwNwidth);
int height = MwGetInteger(w, MwNheight);
printf("%d %d\n", width, height);
printf("%d %d\n", width, height);
handle->internal =
[[MacOpenGLWidget alloc] initWithWindow:handle->lowlevel->cocoa.real];
handle->lowlevel->common.copy_buffer = 0;
handle->internal =
[[MacOpenGLWidget alloc] initWithWindow:handle->lowlevel->cocoa.real];
handle->lowlevel->common.copy_buffer = 0;
MwSetDefault(handle);
MwSetDefault(handle);
while (w->parent != NULL)
w = w->parent;
while(w->parent != NULL)
w = w->parent;
w->berserk++;
w->berserk++;
return 0;
return 0;
}
static void destroy(MwWidget handle) {
[(MacOpenGLWidget *)handle->internal destroy];
[(MacOpenGLWidget*)handle->internal destroy];
}
static void mwOpenGLMakeCurrentImpl(MwWidget handle) {
[(MacOpenGLWidget *)handle->internal makeCurrent];
[(MacOpenGLWidget*)handle->internal makeCurrent];
}
static void mwOpenGLSwapBufferImpl(MwWidget handle) {
[(MacOpenGLWidget *)handle->internal swapBuffer];
[(MacOpenGLWidget*)handle->internal swapBuffer];
}
static void *mwOpenGLGetProcAddressImpl(MwWidget handle, const char *name) {
return [(MacOpenGLWidget *)handle->internal getProcAddressWithName:name];
static void* mwOpenGLGetProcAddressImpl(MwWidget handle, const char* name) {
return [(MacOpenGLWidget*)handle->internal getProcAddressWithName:name];
}
static void func_handler(MwWidget handle, const char *name, void *out,
va_list va) {
if (strcmp(name, "mwOpenGLMakeCurrent") == 0) {
mwOpenGLMakeCurrentImpl(handle);
}
if (strcmp(name, "mwOpenGLSwapBuffer") == 0) {
mwOpenGLSwapBufferImpl(handle);
}
if (strcmp(name, "mwOpenGLGetProcAddress") == 0) {
const char *_name = va_arg(va, const char *);
*(void **)out = mwOpenGLGetProcAddressImpl(handle, _name);
}
static void func_handler(MwWidget handle, const char* name, void* out,
va_list va) {
if(strcmp(name, "mwOpenGLMakeCurrent") == 0) {
mwOpenGLMakeCurrentImpl(handle);
}
if(strcmp(name, "mwOpenGLSwapBuffer") == 0) {
mwOpenGLSwapBufferImpl(handle);
}
if(strcmp(name, "mwOpenGLGetProcAddress") == 0) {
const char* _name = va_arg(va, const char*);
*(void**)out = mwOpenGLGetProcAddressImpl(handle, _name);
}
}
@implementation MacOpenGLWidget
- (MacOpenGLWidget *)initWithWindow:(MilskoCocoa *)w {
NSOpenGLPixelFormatAttribute pixelFormatAttributes[] = {
NSOpenGLPFAColorSize, 24,
NSOpenGLPFAStencilSize, 8,
NSOpenGLPFAAlphaSize, 8,
NSOpenGLPFADoubleBuffer, NSOpenGLPFAAccelerated,
NSOpenGLPFANoRecovery, 0};
self->pixelFormat =
[[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes];
self->glc =
[[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil];
[self->glc setView:[w getView]];
self->_win = w;
return self;
- (MacOpenGLWidget*)initWithWindow:(MilskoCocoa*)w {
NSOpenGLPixelFormatAttribute pixelFormatAttributes[] = {
NSOpenGLPFAColorSize, 24,
NSOpenGLPFAStencilSize, 8,
NSOpenGLPFAAlphaSize, 8,
NSOpenGLPFADoubleBuffer, NSOpenGLPFAAccelerated,
NSOpenGLPFANoRecovery, 0};
self->pixelFormat =
[[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes];
self->glc =
[[NSOpenGLContext alloc] initWithFormat:pixelFormat
shareContext:nil];
[self->glc setView:[w getView]];
self->_win = w;
return self;
};
- (void)destroy {
};
- (void)makeCurrent {
[self->glc makeCurrentContext];
[self->glc makeCurrentContext];
};
- (void)swapBuffer {
[self->glc flushBuffer];
[self->glc flushBuffer];
};
- (void *)getProcAddressWithName:(const char *)name {
if (NSIsSymbolNameDefined(name)) {
return NSAddressOfSymbol(NSLookupAndBindSymbol(name));
} else {
return NULL;
}
- (void*)getProcAddressWithName:(const char*)name {
if(NSIsSymbolNameDefined(name)) {
return NSAddressOfSymbol(NSLookupAndBindSymbol(name));
} else {
return NULL;
}
};
@end
MwClassRec MwOpenGLClassRec = {create, /* create */
destroy, /* destroy */
NULL, /* draw */
NULL, /* click */
NULL, /* parent_resize */
NULL, /* prop_change */
NULL, /* mouse_move */
NULL, /* mouse_up */
NULL, /* mouse_down */
NULL, /* key */
func_handler, /* execute */
NULL, /* tick */
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL, /* clipboard */
NULL, NULL, NULL, NULL};
MwClass MwOpenGLClass = &MwOpenGLClassRec;
MwClassRec MwOpenGLClassRec = {wcreate, /* create */
destroy, /* destroy */
NULL, /* draw */
NULL, /* click */
NULL, /* parent_resize */
NULL, /* prop_change */
NULL, /* mouse_move */
NULL, /* mouse_up */
NULL, /* mouse_down */
NULL, /* key */
func_handler, /* execute */
NULL, /* tick */
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL, /* clipboard */
NULL, NULL, NULL, NULL};
MwClass MwOpenGLClass = &MwOpenGLClassRec;

View file

@ -1,6 +1,6 @@
#include <Mw/Milsko.h>
static int create(MwWidget handle) {
static int wcreate(MwWidget handle) {
MwSetDefault(handle);
MwVaApply(handle,
MwNminValue, 0,
@ -46,7 +46,7 @@ static void prop_change(MwWidget handle, const char* key) {
}
MwClassRec MwProgressBarClassRec = {
create, /* create */
wcreate, /* create */
NULL, /* destroy */
draw, /* draw */
NULL, /* click */

View file

@ -2,7 +2,7 @@
#include "../../external/stb_ds.h"
static int create(MwWidget handle) {
static int wcreate(MwWidget handle) {
MwSetDefault(handle);
MwSetInteger(handle, MwNchecked, 0);
@ -47,7 +47,7 @@ static void prop_change(MwWidget handle, const char* key) {
}
MwClassRec MwRadioBoxClassRec = {
create, /* create */
wcreate, /* create */
NULL, /* destroy */
draw, /* draw */
click, /* click */

View file

@ -1,6 +1,6 @@
#include <Mw/Milsko.h>
static int create(MwWidget handle) {
static int wcreate(MwWidget handle) {
MwScrollBar scr = malloc(sizeof(*scr));
handle->internal = scr;
@ -131,7 +131,7 @@ static void draw(MwWidget handle) {
}
}
MwDrawWidgetBack(handle, &rbar, base, 0, MwTRUE);
if(rbar.height >= 0) MwDrawWidgetBack(handle, &rbar, base, 0, MwTRUE);
MwLLFreeColor(dark);
MwLLFreeColor(base);
@ -170,9 +170,9 @@ static void mouse_down(MwWidget handle, void* ptr) {
int wh = MwGetInteger(handle, MwNheight);
int or = MwGetInteger(handle, MwNorientation);
MwScrollBar scr = handle->internal;
MwLLMouse* m = ptr;
MwMouse* m = ptr;
if(m->button == MwLLMouseWheelUp) {
if(m->button == MwMOUSE_WHEELUP) {
int min = MwGetInteger(handle, MwNminValue);
int val = MwGetInteger(handle, MwNvalue);
int diff = MwGetInteger(handle, MwNareaShown);
@ -184,7 +184,7 @@ static void mouse_down(MwWidget handle, void* ptr) {
MwSetInteger(handle, MwNvalue, val);
MwSetInteger(handle, MwNchangedBy, -diff);
MwDispatchUserHandler(handle, MwNchangedHandler, NULL);
} else if(m->button == MwLLMouseWheelDown) {
} else if(m->button == MwMOUSE_WHEELDOWN) {
int max = MwGetInteger(handle, MwNmaxValue);
int val = MwGetInteger(handle, MwNvalue);
int diff = MwGetInteger(handle, MwNareaShown);
@ -197,7 +197,7 @@ static void mouse_down(MwWidget handle, void* ptr) {
MwSetInteger(handle, MwNchangedBy, diff);
MwDispatchUserHandler(handle, MwNchangedHandler, NULL);
}
if(m->button != MwLLMouseLeft) return;
if(m->button != MwMOUSE_LEFT) return;
scr->point = handle->mouse_point;
scr->drag = 0;
@ -257,7 +257,7 @@ static void func_handler(MwWidget handle, const char* name, void* out, va_list v
}
MwClassRec MwScrollBarClassRec = {
create, /* create */
wcreate, /* create */
destroy, /* destroy */
draw, /* draw */
NULL, /* click */

View file

@ -1,6 +1,6 @@
#include <Mw/Milsko.h>
static int create(MwWidget handle) {
static int wcreate(MwWidget handle) {
MwSetDefault(handle);
MwSetInteger(handle, MwNorientation, MwHORIZONTAL);
@ -35,7 +35,7 @@ static void prop_change(MwWidget handle, const char* key) {
}
MwClassRec MwSeparatorClassRec = {
create, /* create */
wcreate, /* create */
NULL, /* destroy */
draw, /* draw */
NULL, /* click */

View file

@ -2,7 +2,7 @@
#include "../../external/stb_ds.h"
static int create(MwWidget handle) {
static int wcreate(MwWidget handle) {
MwLLBeginStateChange(handle->lowlevel);
MwSetDefault(handle);
@ -63,8 +63,8 @@ static void draw(MwWidget handle) {
p.y += 2 + 1;
} else {
int tw = MwTextWidth(handle, menu->sub[i]->name);
int th = MwTextHeight(handle, menu->sub[i]->name);
int tw = MwTextWidth(handle, NULL, menu->sub[i]->name);
int th = MwTextHeight(handle, NULL, menu->sub[i]->name);
if(menu->sub[i]->wsub != NULL) {
r.x = MwGetInteger(handle, MwNleftPadding);
@ -77,7 +77,7 @@ static void draw(MwWidget handle) {
p.x = 5 + tw / 2 + MwGetInteger(handle, MwNleftPadding);
p.y += th / 2;
MwDrawText(handle, &p, menu->sub[i]->name, menu->sub[i]->wsub != NULL ? 1 : 0, MwALIGNMENT_CENTER, text);
MwDrawText(handle, MwFLBuildFont(menu->sub[i]->wsub != NULL ? MwFLFlagBold : 0), &p, menu->sub[i]->name, MwALIGNMENT_CENTER, text);
if(arrlen(menu->sub[i]->sub) > 0) {
MwRect tr;
@ -110,13 +110,13 @@ static void click(MwWidget handle) {
rc.x = 5;
rc.y = 3;
for(i = 0; i < arrlen(menu->sub); i++) {
int tw = MwTextWidth(handle, menu->sub[i]->name);
int tw = MwTextWidth(handle, NULL, menu->sub[i]->name);
if(tw > ww) ww = tw;
}
rc.width = ww + 15;
for(i = 0; i < arrlen(menu->sub); i++) {
int th = MwTextHeight(handle, menu->sub[i]->name);
int th = MwTextHeight(handle, NULL, menu->sub[i]->name);
rc.height = th;
if(strcmp(menu->sub[i]->name, "----") == 0) {
@ -183,7 +183,7 @@ static void mwSubMenuAppearImpl(MwWidget handle, MwMenu menu, MwPoint* point, in
MwLLMakeToolWindow(handle->lowlevel);
MwLLDetach(handle->lowlevel, &p);
if(handle->lowlevel->common.coordinate_type == MwCoordinatesGlobal) {
if(handle->lowlevel->common.coordinate_type == MwCOORDINATE_GLOBAL) {
if(MwGetInteger(handle, MwNy) + sz.height > rc.height) {
MwVaApply(handle,
MwNy, rc.height - sz.height,
@ -209,8 +209,8 @@ static void mwSubMenuGetSizeImpl(MwWidget handle, MwMenu menu, MwRect* rect) {
if(strcmp(menu->sub[i]->name, "----") == 0) {
rect->height += 2 + 2;
} else {
int tw = MwTextWidth(handle, menu->sub[i]->name);
rect->height += MwTextHeight(handle, menu->sub[i]->name) + 3;
int tw = MwTextWidth(handle, NULL, menu->sub[i]->name);
rect->height += MwTextHeight(handle, NULL, menu->sub[i]->name) + 3;
if(tw > rect->width) {
rect->width = tw;
}
@ -241,7 +241,7 @@ static void func_handler(MwWidget handle, const char* name, void* out, va_list v
}
MwClassRec MwSubMenuClassRec = {
create, /* create */
wcreate, /* create */
destroy, /* destroy */
draw, /* draw */
click, /* click */

View file

@ -30,11 +30,11 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwTreeViewEntry**
if((*skip) > 0) {
(*skip)--;
skipped = 1;
if(p->y == MwDefaultBorderWidth(handle)) p->y -= MwTextHeight(handle, "M");
} else if((*shared) < (MwGetInteger(handle, MwNheight) / MwTextHeight(handle, "M") + 2)) {
if(p->y == MwDefaultBorderWidth(handle)) p->y -= MwTextHeight(handle, NULL, "M");
} else if((*shared) < (MwGetInteger(handle, MwNheight) / MwTextHeight(handle, NULL, "M") + 2)) {
MwRect r;
p->x += shift;
p->y += MwTextHeight(handle, "M") / 2 + LinePadding;
p->y += MwTextHeight(handle, NULL, "M") / 2 + LinePadding;
if(tree->tree != NULL || shift > LineSpace) {
l[0] = *p;
@ -47,9 +47,9 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwTreeViewEntry**
l[0] = *p;
l[0].x -= LineSpace / 2;
l[1] = l[0];
l[0].y -= MwTextHeight(handle, "M") / 2 + LinePadding;
l[0].y -= MwTextHeight(handle, NULL, "M") / 2 + LinePadding;
if(next) {
l[1].y += MwTextHeight(handle, "M") / 2;
l[1].y += MwTextHeight(handle, NULL, "M") / 2;
}
if(draw) MwLLLine(handle->lowlevel, &l[0], text2);
}
@ -57,7 +57,7 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwTreeViewEntry**
r.width = OpenerSize;
r.height = OpenerSize;
r.x = p->x - LineSpace + (LineSpace - r.width) / 2;
r.y = p->y - MwTextHeight(handle, "M") / 2 + (MwTextHeight(handle, "M") - r.height) / 2;
r.y = p->y - MwTextHeight(handle, NULL, "M") / 2 + (MwTextHeight(handle, NULL, "M") - r.height) / 2;
if(draw) {
MwLLColor col = tree->opened ? MwLightenColor(handle, base, -8, -8, -8) : base;
MwRect r2 = r;
@ -101,11 +101,11 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwTreeViewEntry**
}
}
if(tree->pixmap != NULL) {
r.height = MwTextHeight(handle, "M");
r.height = MwTextHeight(handle, NULL, "M");
r.width = r.height * tree->pixmap->common.width / tree->pixmap->common.height;
r.x = p->x;
r.y = p->y - MwTextHeight(handle, "M") / 2;
r.y = p->y - MwTextHeight(handle, NULL, "M") / 2;
if(draw) MwLLDrawPixmap(handle->lowlevel, &r, tree->pixmap);
}
@ -113,22 +113,22 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwTreeViewEntry**
if(draw) {
if(tree->selected) {
r.x = p->x;
r.y = p->y - MwTextHeight(handle, "M") / 2;
r.y = p->y - MwTextHeight(handle, NULL, "M") / 2;
r.width = MwGetInteger(handle, MwNwidth) - MwGetInteger(handle, MwNleftPadding) - shift;
r.height = MwTextHeight(handle, "M");
r.height = MwTextHeight(handle, NULL, "M");
MwDrawRect(handle, &r, text2);
}
handle->bgcolor = tree->selected ? text2 : base2;
MwDrawText(handle, p, tree->label, 0, MwALIGNMENT_BEGINNING, tree->selected ? base2 : text2);
MwDrawText(handle, NULL, p, tree->label, MwALIGNMENT_BEGINNING, tree->selected ? base2 : text2);
handle->bgcolor = NULL;
} else {
if(p->x <= mouse->x && mouse->x <= (p->x + MwTextWidth(handle, tree->label)) && (p->y - MwTextHeight(handle, "M") / 2) <= mouse->y && mouse->y <= (p->y + MwTextHeight(handle, "M") / 2)) {
if(p->x <= mouse->x && mouse->x <= (p->x + MwTextWidth(handle, NULL, tree->label)) && (p->y - MwTextHeight(handle, NULL, "M") / 2) <= mouse->y && mouse->y <= (p->y + MwTextHeight(handle, NULL, "M") / 2)) {
unsigned long t;
set_all(root, 0);
tree->selected = 1;
if(((t = MwTimeGetTick()) - tree->click_time) < MwDoubleClickTimeout || MwGetInteger(handle->parent, MwNsingleClickSelectable)) {
MwDispatchUserHandler(handle->parent, MwNactivateHandler, tree);
MwDispatchUserHandler(handle->parent, MwNtreeViewActivateHandler, tree);
}
tree->click_time = t;
@ -136,7 +136,7 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwTreeViewEntry**
}
p->x -= MwGetInteger(handle->parent, MwNleftPadding);
p->y += MwTextHeight(handle, "M") / 2;
p->y += MwTextHeight(handle, NULL, "M") / 2;
p->x -= shift;
(*shared)++;
@ -145,7 +145,7 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwTreeViewEntry**
for(i = 0; i < arrlen(tree->tree); i++) {
l[0] = *p;
l[0].x += shift + LineSpace / 2;
l[0].y += MwTextHeight(handle, "M") - (MwTextHeight(handle, "M") - OpenerSize) / 2;
l[0].y += MwTextHeight(handle, NULL, "M") - (MwTextHeight(handle, NULL, "M") - OpenerSize) / 2;
if(tree->tree[i]->tree != NULL) {
l[0].y += OpenerSize / 2;
}
@ -189,7 +189,7 @@ static void frame_draw(MwWidget handle) {
r = r2;
for(i = 0; i < arrlen(tv->tree); i++) {
if(shared > (r.height / MwTextHeight(handle, "M"))) break;
if(shared > (r.height / MwTextHeight(handle, NULL, "M"))) break;
recursion(handle, tv->tree[i], tv->tree, base, text, base2, text2, &p, 0, LineSpace, &skip, &shared, 1, NULL);
}
@ -213,11 +213,11 @@ static int recursive_length(MwTreeViewEntry** e) {
static void frame_mouse_down(MwWidget handle, void* user, void* call) {
MwTreeView tv = handle->parent->internal;
MwLLMouse* mouse = call;
MwMouse* mouse = call;
(void)user;
if(mouse->button == MwLLMouseLeft) tv->pressed = mouse->point;
if(mouse->button == MwMOUSE_LEFT) tv->pressed = mouse->point;
}
static void resize(MwWidget handle);
@ -227,16 +227,16 @@ static void frame_mouse_up(MwWidget handle, void* user, void* call) {
int shared = 0;
int skip = MwGetInteger(tv->vscroll, MwNvalue) * (MwGetInteger(tv->vscroll, MwNmaxValue) - MwGetInteger(tv->vscroll, MwNareaShown)) / MwGetInteger(tv->vscroll, MwNmaxValue);
MwPoint p;
MwLLMouse* mouse = call;
MwMouse* mouse = call;
(void)user;
if(mouse->button == MwLLMouseLeft) {
if(mouse->button == MwMOUSE_LEFT) {
int i;
p.x = MwDefaultBorderWidth(tv->frame);
p.y = MwDefaultBorderWidth(tv->frame);
for(i = 0; i < arrlen(tv->tree); i++) {
if(shared > (MwGetInteger(tv->frame, MwNheight) / MwTextHeight(tv->frame, "M"))) break;
if(shared > (MwGetInteger(tv->frame, MwNheight) / MwTextHeight(tv->frame, NULL, "M"))) break;
recursion(tv->frame, tv->tree[i], tv->tree, NULL, NULL, NULL, NULL, &p, 0, LineSpace, &skip, &shared, 0, &tv->pressed);
}
resize(handle->parent);
@ -267,7 +267,7 @@ static void resize(MwWidget handle) {
ih = recursive_length(tv->tree);
if(ih == 0) ih = 1;
if(ih <= (h / (LinePadding + MwTextHeight(handle, "M")))) {
if(ih <= (h / (LinePadding + MwTextHeight(handle, NULL, "M")))) {
MwLLShow(tv->vscroll->lowlevel, 0);
} else {
MwLLShow(tv->vscroll->lowlevel, 1);
@ -292,12 +292,12 @@ static void resize(MwWidget handle) {
}
MwVaApply(tv->vscroll,
MwNareaShown, h / (LinePadding + MwTextHeight(handle, "M")),
MwNareaShown, h / (LinePadding + MwTextHeight(handle, NULL, "M")),
MwNmaxValue, ih,
NULL);
}
static int create(MwWidget handle) {
static int wcreate(MwWidget handle) {
MwTreeView tv = malloc(sizeof(*tv));
memset(tv, 0, sizeof(*tv));
@ -481,7 +481,7 @@ static void tick(MwWidget handle) {
}
MwClassRec MwTreeViewClassRec = {
create, /* create */
wcreate, /* create */
destroy, /* destroy */
draw, /* draw */
NULL, /* click */

View file

@ -74,7 +74,7 @@ static void resize(MwWidget handle) {
NULL);
}
static int create(MwWidget handle) {
static int wcreate(MwWidget handle) {
MwViewport vp = malloc(sizeof(*vp));
memset(vp, 0, sizeof(*vp));
@ -176,7 +176,7 @@ static void tick(MwWidget handle) {
}
MwClassRec MwViewportClassRec = {
create, /* create */
wcreate, /* create */
destroy, /* destroy */
draw, /* draw */
NULL, /* click */

View file

@ -1,12 +1,15 @@
#include <Mw/Milsko.h>
#include <Mw/Widget/Vulkan.h>
#include "../error_internal.h"
/**
* ioixd maintains this file. nishi doesn't know vulkan at all
*/
#ifndef MW_VULKAN
#define MW_VULKAN_NO_INCLUDE
#endif
#include <Mw/Widget/Vulkan.h>
#ifdef MW_VULKAN
#ifdef USE_GDI
#define VK_USE_PLATFORM_WIN32_KHR 1
#endif
@ -28,6 +31,9 @@
#ifdef USE_WAYLAND
#include <vulkan/vulkan_wayland.h>
#endif
#ifdef USE_COCOA
#include <vulkan/vulkan_metal.h>
#endif
#ifdef HAS_VK_ENUM_STRING_HELPER
#include <vulkan/vk_enum_string_helper.h>
@ -49,15 +55,19 @@ MwVulkanConfig vulkan_config = {
#define VK_CMD(func) \
vk_res = func; \
if(vk_res != VK_SUCCESS) { \
setLastError("Vulkan error (%s:%d): %s\n", __FILE__, __LINE__, string_VkResult(vk_res)); \
return MwEerror; \
char buf[1024]; \
MwStringPrintIntoBuffer(buf, 1024, "Vulkan error (%s:%d): %s\n", __FILE__, __LINE__, string_VkResult(vk_res)); \
MwDispatchError(1, buf); \
return 1; \
}
#else
#define VK_CMD(func) \
vk_res = func; \
if(vk_res != VK_SUCCESS) { \
setLastError("Vulkan error (%s:%d): (error %d)\n", __FILE__, __LINE__, vk_res); \
return MwEerror; \
char buf[1024]; \
MwStringPrintIntoBuffer(buf, 1024, "Vulkan error (%s:%d): (error %d)\n", __FILE__, __LINE__, vk_res); \
MwDispatchError(1, buf); \
return 1; \
}
#endif
@ -69,8 +79,10 @@ MwVulkanConfig vulkan_config = {
/* convienence macro to return an error if an assert goes wrong */
#define VK_ASSERT(val) \
if(!val) { \
setLastError("Vulkan error (%s:%d): Assertion Failed (%s != NULL)\n", __FILE__, __LINE__, #val); \
return MwEerror; \
char buf[1024]; \
MwStringPrintIntoBuffer(buf, 1024, "Vulkan error (%s:%d): Assertion Failed (%s != NULL)\n", __FILE__, __LINE__, #val); \
MwDispatchError(1, buf); \
return 1; \
}
const char** enabledExtensions;
@ -105,29 +117,26 @@ typedef struct vulkan {
int vkLayerCount;
} vulkan_t;
static MwErrorEnum vulkan_instance_setup(MwWidget handle, vulkan_t* o);
static MwErrorEnum vulkan_surface_setup(MwWidget handle, vulkan_t* o);
static MwErrorEnum vulkan_devices_setup(MwWidget handle, vulkan_t* o);
static int vulkan_instance_setup(MwWidget handle, vulkan_t* o);
static int vulkan_surface_setup(MwWidget handle, vulkan_t* o);
static int vulkan_devices_setup(MwWidget handle, vulkan_t* o);
static int create(MwWidget handle) {
vulkan_t* o = malloc(sizeof(*o));
MwErrorEnum err;
static int wcreate(MwWidget handle) {
vulkan_t* o = malloc(sizeof(*o));
int err;
memset(o, 0, sizeof(*o));
err = vulkan_instance_setup(handle, o);
if(err != MwEsuccess) {
printf("%s", MwGetLastError());
if(err != 0) {
return 1;
}
err = vulkan_surface_setup(handle, o);
if(err != MwEsuccess) {
printf("%s", MwGetLastError());
if(err != 0) {
return 1;
}
err = vulkan_devices_setup(handle, o);
if(err != MwEsuccess) {
printf("%s", MwGetLastError());
if(err != 0) {
return 1;
}
@ -139,7 +148,7 @@ static int create(MwWidget handle) {
return 0;
}
static MwErrorEnum _destroy(MwWidget handle) {
static int _destroy(MwWidget handle) {
vulkan_t* o = (vulkan_t*)handle->internal;
LOAD_VK_FUNCTION(vkDestroyInstance);
@ -156,25 +165,26 @@ static MwErrorEnum _destroy(MwWidget handle) {
free(o);
return MwEsuccess;
return 0;
}
static void destroy(MwWidget handle) {
MwErrorEnum err = _destroy(handle);
if(err == MwEerror) {
printf("[Vulkan Widget] %s", MwGetLastError());
}
int err = _destroy(handle);
(void)err;
}
static void* vulkan_lib_load() {
#ifdef _WIN32
return MwDynamicOpen("vulkan-1.dll");
#elif defined(__APPLE__)
return MwDynamicOpen("libvulkan.dylib");
#else
return MwDynamicOpen("libvulkan.so");
#endif
}
static MwErrorEnum vulkan_instance_setup(MwWidget handle, vulkan_t* o) {
static int vulkan_instance_setup(MwWidget handle, vulkan_t* o) {
uint32_t vulkan_version = vulkan_config.vk_version;
uint32_t api_version = vulkan_config.api_version;
uint32_t extension_count = 0;
@ -199,7 +209,7 @@ static MwErrorEnum vulkan_instance_setup(MwWidget handle, vulkan_t* o) {
o->vulkanLibrary = vulkan_lib_load();
if(!o->vulkanLibrary) {
vulkan_supported = VULKAN_SUPPORTED_NO;
setLastError("Vulkan not found.");
MwDispatchError(1, "Vulkan not found.");
} else {
vulkan_supported = VULKAN_SUPPORTED_YES;
}
@ -227,16 +237,14 @@ static MwErrorEnum vulkan_instance_setup(MwWidget handle, vulkan_t* o) {
#endif
#ifdef USE_WAYLAND
if(handle->lowlevel->common.type == MwLLBackendWayland) {
MwLL topmost_parent = handle->lowlevel->wayland.parent;
arrput(enabledExtensions, VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
/* take this opprutunity to set the widget to always render */
handle->lowlevel->wayland.always_render = MwTRUE;
while(topmost_parent->wayland.parent != NULL) {
topmost_parent = topmost_parent->wayland.parent;
topmost_parent->wayland.always_render = MwTRUE;
}
MwWaylandAlwaysRender = MwTRUE;
}
#endif
#ifdef USE_COCOA
if(handle->lowlevel->common.type == MwLLBackendCocoa) {
arrput(enabledExtensions, VK_EXT_METAL_SURFACE_EXTENSION_NAME);
}
#endif
@ -299,10 +307,10 @@ static MwErrorEnum vulkan_instance_setup(MwWidget handle, vulkan_t* o) {
instance_create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
VK_CMD(_vkCreateInstance(&instance_create_info, NULL, &o->vkInstance));
return MwEsuccess;
return 0;
}
static MwErrorEnum vulkan_surface_setup(MwWidget handle, vulkan_t* o) {
static int vulkan_surface_setup(MwWidget handle, vulkan_t* o) {
int vk_res;
#ifdef USE_GDI
if(handle->lowlevel->common.type == MwLLBackendGDI) {
@ -348,10 +356,20 @@ static MwErrorEnum vulkan_surface_setup(MwWidget handle, vulkan_t* o) {
VK_CMD(_vkCreateWaylandSurfaceKHR(o->vkInstance, &createInfo, NULL, &o->vkSurface));
}
#endif
return MwEsuccess;
#ifdef USE_COCOA
if(handle->lowlevel->common.type == MwLLBackendCocoa) {
VkMetalSurfaceCreateInfoEXT MwCocoaGetMetalSurfaceCreateInfo(MwWidget handle);
VkMetalSurfaceCreateInfoEXT inf = MwCocoaGetMetalSurfaceCreateInfo(handle);
LOAD_VK_FUNCTION(vkCreateMetalSurfaceEXT);
VK_CMD(_vkCreateMetalSurfaceEXT(o->vkInstance, &inf, NULL, &o->vkSurface));
}
#endif
return 0;
}
static MwErrorEnum vulkan_devices_setup(MwWidget handle, vulkan_t* o) {
static int vulkan_devices_setup(MwWidget handle, vulkan_t* o) {
(void)(handle);
int vk_res;
@ -407,8 +425,8 @@ static MwErrorEnum vulkan_devices_setup(MwWidget handle, vulkan_t* o) {
}
if(!has_graphics && !has_present) {
/* rare, yes, but idk maybe some shitty drivers will present this dillema idk. */
setLastError("There were no devices with either a graphics or presentation queue.\n");
return MwEerror;
MwDispatchError(1, "There were no devices with either a graphics or presentation queue.\n");
return 1;
}
/* create the logical device */
@ -468,11 +486,11 @@ static MwErrorEnum vulkan_devices_setup(MwWidget handle, vulkan_t* o) {
_vkGetDeviceQueue(o->vkLogicalDevice, o->vkPresentFamilyIDX, 0, &o->vkPresentQueue);
}
free(devices);
return MwEsuccess;
return 0;
}
void MwVulkanConfigure(MwVulkanConfig cfg) {
vulkan_config = cfg;
void MwVulkanConfigure(MwVulkanConfig* cfg) {
vulkan_config = *cfg;
}
void MwVulkanEnableExtension(const char* name) {
@ -483,7 +501,7 @@ void MwVulkanEnableLayer(const char* name) {
arrput(enabledLayers, name);
}
VkBool32 MwVulkanSupported(void) {
int MwVulkanSupported(void) {
if(vulkan_supported == VULKAN_SUPPORTED_UNKNOWN) {
void* lib = vulkan_lib_load();
if(lib == NULL) {
@ -494,56 +512,58 @@ VkBool32 MwVulkanSupported(void) {
}
}
if(vulkan_supported == VULKAN_SUPPORTED_YES) {
return VK_TRUE;
return 1;
} else {
return VK_FALSE;
return 0;
}
};
static void* mwVulkanGetFieldImpl(MwWidget handle, MwVulkanField field, MwErrorEnum* out) {
static void* mwVulkanGetFieldImpl(MwWidget handle, int field, int* err) {
vulkan_t* o = handle->internal;
char buf[1024];
switch(field) {
case MwVulkanField_GetInstanceProcAddr:
case MwVULKANFIELD_GETINSTANCEPROCADDR:
return o->vkGetInstanceProcAddr;
case MwVulkanField_Instance:
case MwVULKANFIELD_INSTANCE:
return o->vkInstance;
case MwVulkanField_Surface:
case MwVULKANFIELD_SURFACE:
return o->vkSurface;
case MwVulkanField_PhysicalDevice:
case MwVULKANFIELD_PHYSICALDEVICE:
return o->vkPhysicalDevice;
case MwVulkanField_LogicalDevice:
case MwVULKANFIELD_LOGICALDEVICE:
return o->vkLogicalDevice;
case MwVulkanField_GraphicsQueueIndex:
case MwVULKANFIELD_GRAPHICSQUEUEINDEX:
return &o->vkGraphicsFamilyIDX;
case MwVulkanField_PresentQueueIndex:
case MwVULKANFIELD_PRESENTQUEUEINDEX:
return &o->vkPresentFamilyIDX;
case MwVulkanField_GraphicsQueue:
case MwVULKANFIELD_GRAPHICSQUEUE:
return o->vkGraphicsQueue;
case MwVulkanField_PresentQueue:
case MwVULKANFIELD_PRESENTQUEUE:
return o->vkPresentQueue;
default:
setLastError("Unknown vulkan field request (%d given)", field);
if(out != NULL) {
*out = MwEerror;
MwStringPrintIntoBuffer(buf, 1024, "Unknown vulkan field request (%d given)", field);
MwDispatchError(1, buf);
if(err != NULL) {
*err = 1;
}
return NULL;
}
if(out != NULL) {
*out = MwEsuccess;
if(err != NULL) {
*err = 0;
}
};
static void func_handler(MwWidget handle, const char* name, void* out, va_list va) {
static void func_handler(MwWidget handle, const char* name, void* output, va_list va) {
if(strcmp(name, "mwVulkanGetField") == 0) {
MwVulkanField field = va_arg(va, MwVulkanField);
MwErrorEnum* err = va_arg(va, MwErrorEnum*);
*(void**)out = mwVulkanGetFieldImpl(handle, field, err);
int field = va_arg(va, int);
int* err = va_arg(va, int*);
*(void**)output = mwVulkanGetFieldImpl(handle, field, err);
}
}
MwClassRec MwVulkanClassRec = {
create, /* create */
wcreate, /* create */
destroy, /* destroy */
NULL, /* draw */
NULL, /* click */
@ -564,3 +584,22 @@ MwClassRec MwVulkanClassRec = {
NULL,
NULL};
MwClass MwVulkanClass = &MwVulkanClassRec;
#else
MwClass MwVulkanClass = NULL;
void MwVulkanEnableExtension(const char* ext_name) {
(void)ext_name;
}
void MwVulkanEnableLayer(const char* ext_name) {
(void)ext_name;
}
void MwVulkanConfigure(MwVulkanConfig* cfg) {
(void)cfg;
}
int MwVulkanSupported(void) {
return 0;
}
#endif

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);
@ -44,7 +44,7 @@ static void func_handler(MwWidget handle, const char* name, void* out, va_list v
}
}
MwClassRec MwWindowClassRec = {
create, /* create */
wcreate, /* create */
NULL, /* destroy */
draw, /* draw */
NULL, /* click */

View file

@ -93,7 +93,7 @@ sub generate {
print(OUT "LD = $link\n");
print(OUT "\n");
print(OUT
"CFLAGS = ${inc}include ${def}_MILSKO ${def}USE_GDI ${def}USE_STB_TRUETYPE ${def}USE_STB_IMAGE ${def}STBI_NO_SIMD\n"
"CFLAGS = ${inc}include ${inc}external${dir}libz${dir}include ${def}_MILSKO ${def}USE_GDI ${def}USE_STB_TRUETYPE ${def}USE_STB_IMAGE ${def}STBI_NO_SIMD\n"
);
print(OUT "LDFLAGS = $dll");
print(OUT "\n");
@ -121,7 +121,8 @@ sub generate {
print(OUT "src${dir}Mw.dll: " . cobjs($dir) . "\n");
print( OUT " \$(LD) \$(LDFLAGS) $c_dllout $dllout\$@ "
. cobjs($dir, $prefobj)
. " $needlibs ${lib}opengl32.lib ${lib}gdi32.lib ${lib}user32.lib\n");
. " $needlibs ${lib}opengl32.lib ${lib}gdi32.lib ${lib}user32.lib ${lib}advapi32.lib\n"
);
print(OUT " $c_dllafter\n");
print(OUT "\n");
@ -143,6 +144,7 @@ sub generate {
scan("src");
scan("external");
scan("external/libz/src");
scan("src/icon");
scan("src/cursor");
scan("src/widget");

View file

@ -58,8 +58,7 @@ l(
l("");
c("Requirements");
l("");
l(
" Milsko requires either");
l(" Milsko requires either");
l(" * A Windows environment with GDI (so anything NT or 9x)");
l(" * A MacOS environment with Cocoa (10.4 or above supported)");
l(" * A Unix-like environment with X11 for runtime.");

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