Compare commits

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

111 commits

Author SHA1 Message Date
ca9a24a2b0 watcom opengl fix
Some checks are pending
pyrite-dev/milsko/pipeline/head Build started...
2026-08-10 04:32:44 +09:00
df1972e91c remove winmm
Some checks are pending
pyrite-dev/milsko/pipeline/head Build started...
2026-08-10 01:55:27 +09:00
ca41b5936b Update src/core.c
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-08-09 15:32:56 +09:00
f652523963 fix another c89 issue
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
2026-08-09 15:27:54 +09:00
6a205453a7 fix c89 discrepency
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
2026-08-09 15:26:48 +09:00
87f6dff101 Update include/Mw/MachDep.h
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
2026-08-09 15:19:31 +09:00
8e4774054e Update src/lowlevel.c
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
2026-08-09 15:16:32 +09:00
ff823028cd Update include/Mw/LowLevel.h
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
2026-08-09 15:16:00 +09:00
054b085bcd fix compiles on machines where we have no vulkan
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
2026-08-08 16:32:11 -07:00
9856979906 Dynload winmm, which is weird but it fixes vs2022 builds 2026-08-08 16:24:23 -07:00
6f976ae0ce more fuller suite of error mutes for vs2022 2026-08-08 16:02:53 -07:00
bde66f13a5 fix the wall of warnings on VS2022 2026-08-08 15:26:42 -07:00
85b66d0d9a fix font rendering
Some checks are pending
pyrite-dev/milsko/pipeline/head Build started...
2026-07-26 01:44:01 +09:00
974947b400 remove warnings
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-26 01:21:50 +09:00
7c2ab989fa formatting
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-24 20:51:17 -07:00
39a458d80f win32: remove unused urlmon dep
Some checks are pending
pyrite-dev/milsko/pipeline/head Build started...
2026-07-23 18:24:56 +09:00
f6c129b31c win32: pass utf8 function to dnd
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-23 01:00:56 -07:00
e20684f89b remove mime type stuff for now
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
Windows's built in function for getting mime type sucks, and I don't want to have to vendor in libmagic. We'll leave this as something the user can handle themselves.
2026-07-23 00:56:13 -07:00
9dd96d9cec dynload drag functions
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-23 00:34:38 -07:00
f35e781762 win32: move away from com for drag and drop to avoid conflicts (and because com sucks)
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
2026-07-23 00:10:26 -07:00
c404e9e14b remove some leftover debug prints oops
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-22 21:33:37 -07:00
7e339cfd60 gdi: properly quit drag and drop after its finished
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-22 21:31:03 -07:00
0fd0611a99 dynload CoInitializeEx
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-22 20:02:08 -07:00
fb6c7a4772 replace FMFD_DEFAULT with 0
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
2026-07-22 19:55:40 -07:00
981591120c linke to uuid
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
2026-07-22 19:54:27 -07:00
b3e24df2f6 include urlmon.h in MachDep.h
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
2026-07-22 19:51:11 -07:00
27b4f83840 linke to ole32
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
2026-07-22 19:49:05 -07:00
d3af13ebd6 drag and drop beginnings
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
Reviewed-on: #33
2026-07-23 11:45:01 +09:00
7d6f6ca93a fix gdi text on mingw
Some checks are pending
pyrite-dev/milsko/pipeline/head Build started...
2026-07-21 19:37:34 -07:00
90f69b63d4 version bump
Some checks are pending
pyrite-dev/milsko/pipeline/head Build started...
2026-07-21 01:45:29 -07:00
6a635fc1df changelog should mention newest entry change
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-21 01:30:33 -07:00
6843d6ae05 changelog had item in wrong place
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-21 01:26:37 -07:00
6db8ce17c3 changelog
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-21 01:25:20 -07:00
639f8e619f fix stb_ds include
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-21 00:26:58 -07:00
1103751f57 fix stb_ds include
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
2026-07-21 00:24:37 -07:00
2c19489acd entry ending box should tick
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
2026-07-21 00:15:33 -07:00
80e3d25147 gdi text loading should be loading the right functions Oops
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-20 23:39:02 -07:00
5a660bfe90 remove accidental debug print
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-20 22:02:13 -07:00
529309df37 wayland: fix size hints
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-20 21:56:42 -07:00
e2aa8dec7b wayland size limit should only apply to toplevels oops
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-20 21:18:26 -07:00
6c6b97d92e classicmacos: remove dupl setrgb/penmode call
Some checks are pending
pyrite-dev/milsko/pipeline/head Build started...
2026-07-19 23:06:26 -07:00
d2191ef33a accidentally removed classic mac os init code from core.c
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-19 23:03:09 -07:00
f91fc66fb6 make some updates to get classicmacos.c working but its probably over
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-19 23:01:43 -07:00
2c2e21503f MwFALMwFALSE -> MwFALSE
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-19 20:58:32 -07:00
d0d2339d6b fix
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
2026-07-19 20:56:34 -07:00
3dc4641ff9 underscore prefix for gdi dynloaded functions
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
2026-07-19 20:52:07 -07:00
d9bf9bbb95 support gdi text under win95
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
2026-07-19 20:44:49 -07:00
74a800b3ef fix reparent freeze
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-20 09:07:41 +09:00
d056d1b7fb wayland: min width/height of 50
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-19 15:06:10 -07:00
a30d306da0 fix perl files
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-20 06:21:25 +09:00
ad8173d562 have cmake not prefix the library
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-19 14:20:43 -07:00
1fe59521bf remove directwrite in favor of gdi
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-19 14:16:14 -07:00
b7ed160614 generate makefile
Some checks are pending
pyrite-dev/milsko/pipeline/head Build started...
2026-07-20 04:00:56 +09:00
8a6bfb62de work
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
2026-07-20 03:58:29 +09:00
d36c9190ec better timer
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
2026-07-20 03:45:50 +09:00
b285d1ba8d fix tick
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-20 03:36:31 +09:00
09fc854aba fix memleak
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-19 21:11:43 +09:00
84531e9be1 fix documentation
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-19 21:06:32 +09:00
bc5fc10816 faster gdi text rendering
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-19 21:04:33 +09:00
6bc00c6dca better naming
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-19 20:39:31 +09:00
8ebc8108ed implement gdi text renderer
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-19 20:37:04 +09:00
9a29682915 fix cmake
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-19 17:53:30 +09:00
2c9d0c78e4 allow null for name
Some checks are pending
pyrite-dev/milsko/pipeline/head Build started...
2026-07-17 22:15:33 -07:00
b20a54fb76 new function MwWindowShouldClose
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-17 21:55:42 -07:00
f260c3c11e win32: missed a break under WM_CLOSE
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-17 20:47:28 -07:00
42802313cb win32: migrate if/else chain to switch case
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-17 20:45:50 -07:00
575b8eaee1 DirectWrite support (#28)
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
Reviewed-on: #28
2026-07-18 11:39:52 +09:00
610c63228e have CMakeLists.txt install a pkgconfig file (+ other fixes for building with MSYS) (#27)
Some checks are pending
pyrite-dev/milsko/pipeline/head Build started...
Reviewed-on: #27
2026-07-17 07:48:06 +09:00
4b6eae99dc fixed some memleaks while also trying to fix popups not being destroyed correctly
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-13 15:54:58 -07:00
a4d095cabf wayland: fix popup positioning when CSD is active. fix CSD stride
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-13 14:00:32 -07:00
1a75d6cea1 wrongful stb_ds include
Some checks are pending
pyrite-dev/milsko/pipeline/head Build started...
2026-07-09 21:54:46 -07:00
82b68c9c53 only do MwLibraryInit wayland/cairo if USE_WAYLAND
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
2026-07-09 21:51:21 -07:00
c2bb601311 seperate wayland's cairo functionality into a backend that can be used seperately
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
2026-07-09 21:45:30 -07:00
14d010f9a2 wayland: have MwLLEndStateChange use the right x/y when not detaching
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-09 16:00:39 -07:00
53878b08ee fix cmake
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-09 15:55:11 -07:00
070ee6025b fix wayland warnings
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-09 15:34:59 -07:00
044b067f7f several fixes. layer surfaces now work
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-09 15:19:25 -07:00
a16e48edd5 started on layer surface
Some checks are pending
pyrite-dev/milsko/pipeline/head Build started...
2026-07-07 23:04:58 -07:00
7dad6806c3 allow tool windows without a parent; currently fake them, should use layer surfaces later
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-07 20:47:32 -07:00
b860c26505 actually fix Borderless on wayland and confirm it working
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-07 18:29:02 -07:00
5ea01c80c5 wayland: fix popup positioning
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-07 18:22:59 -07:00
d3b0996561 wayland: fix MakeBorderless not working w CSD
Some checks are pending
pyrite-dev/milsko/pipeline/head Build started...
2026-07-05 00:44:54 -07:00
0826afb334 fix color leak 2
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-05 06:51:49 +09:00
1f4fddfa67 fix color leak 2026-07-05 06:30:54 +09:00
541499f43c add RESIZE_ON_TICK and fix CMake
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-07-05 05:24:03 +09:00
7d40eff3e5 fix
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-05-27 15:45:57 +09:00
884c05acb7 wayland: oops! we have MwTimeGetTick, we should use that (even though I'm not sure if that's consistent across platforms. but it will at least compile
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-05-24 23:01:48 -07:00
052863dcfe wayland: set a default for keyboard_repeat/keyboard_rate in case a compostior doesn't send key_repeat_info
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-05-24 22:54:50 -07:00
e8a4e266b3 wayland: do keyboard repeat
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-05-24 22:51:10 -07:00
3c1bd9956f wayland: 'focused' widgets should also have key events sent
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-05-24 22:18:29 -07:00
fcca66d1e4 cmake builds shouldn't be linking to libraries that we dynload
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-05-24 14:13:02 -07:00
3727c9f587 fix wayland csd
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-05-23 23:34:38 -07:00
6ecbe998f8 fix wayland csd
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-05-23 23:32:43 -07:00
314cc0da85 format
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-05-23 06:15:20 +09:00
add02b695b make label respect alignment
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-05-23 06:14:37 +09:00
3dac44ed92 use proper method
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-05-23 03:53:13 +09:00
f7df6df342 better fix
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
2026-05-23 03:49:47 +09:00
732b47a300 fix
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
2026-05-23 03:47:09 +09:00
143167761c fix warning
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
2026-05-23 03:42:23 +09:00
149f99622a add disabled widgets
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
2026-05-22 11:41:17 -07:00
9e165b71d4 add MwNiconPixmap to frame and MwTabFocus
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-05-23 03:16:37 +09:00
3d6e08541a fix
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-05-22 14:17:40 +09:00
e7506922d2 finalize tab fix a bit more
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-05-21 18:21:50 -07:00
262019b1d4 fix
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-05-22 09:19:19 +09:00
95e7db9607 Mw/TypeDefs.h: new -> _new
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-05-21 15:45:26 -05:00
2e2833f57b color
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-05-21 10:56:12 +09:00
1fe971e1df fix
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-05-21 08:43:45 +09:00
31df1aa72c wayland: don't incl dbus
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-05-20 16:33:43 -07:00
9ee96a71c4 wayland: overhaul CSD, functions/looks much better.
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-05-20 16:29:43 -07:00
632f63dee8 backport fix
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-05-21 06:04:04 +09:00
6f204af3e6 wayland: fix comment
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
2026-05-20 14:02:41 -07:00
74 changed files with 4268 additions and 5547 deletions

2
.gitignore vendored
View file

@ -21,6 +21,8 @@ compile_flags.txt
.DS_Store
/vms
/BorMakefile
*.err
*.zip
*.pef
*.dsk

17
CHANGELOG.txt Normal file
View file

@ -0,0 +1,17 @@
========================= 1.4 =========================
- CMakeLists.txt downgraded to version 3.13 to allow compiling on Windows XP
- CMake build now generates a pkgconfig file.
- GDI backend now natively uses GDI for text rendering
- Widgets can now be disabled with MwNdisabled
- Added `MwTabFocus` for letting a tab widget steal focus.
- New table widget (`MwTableClass`).
- Added `MwWindowShouldClose` for letting custom loops know when a window should close.
- Remove VMS build files
- Entry widgets now have blinking cursor that appears only when you hover over the widget.
- Wayland backend:
- Can now create layer surfaces (Use `MwLLMakeToolWindow` on a parentless window)
- Now properly handles keys being held down
- has drastically improved CSD (functionality wise)
- Uses KMSDRM directly for the OpenGL widget instead of wl_egl for a smoother experience
- Various overall performance improvements putting it on the same level as the X11 backend finally
- Menu widget works better under compositors that use CSD.

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.25)
cmake_minimum_required(VERSION 3.13)
project(
milsko
)
@ -9,6 +9,12 @@ include(GNUInstallDirs)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(WIN32)
set(CMAKE_STATIC_LIBRARY_PREFIX "")
set(CMAKE_SHARED_LIBRARY_PREFIX "")
endif()
option(MW_CLASSIC_THEME "Use classic theme" OFF)
option(MW_BUILD_EXAMPLES "Build examples" OFF)
@ -29,12 +35,18 @@ endif()
option(MW_INSTALL_HEADERS "Install headers" ON)
if(${CMAKE_SYSTEM_NAME} STREQUAL Darwin OR ${CMAKE_SYSTEM_NAME} MATCHES Retro)
if( ${CMAKE_SYSTEM_NAME} STREQUAL Darwin
OR ${CMAKE_SYSTEM_NAME} MATCHES Retro
OR ${CMAKE_SYSTEM_NAME} MATCHES Windows)
option(MW_USE_FREETYPE2 "Use FreeType 2" OFF)
else()
option(MW_USE_FREETYPE2 "Use FreeType 2" ON)
endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL Windows)
option(MW_USE_GDI_TEXT "Use GDI for text rendering" ON)
endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL Linux OR ${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD)
option(MW_USE_WAYLAND "Enable Wayland backend" ON)
endif()
@ -69,8 +81,8 @@ if(MW_TRY_OPENGL)
endif()
if(MW_TRY_VULKAN)
check_include_files(vulkan/vulkan.h HAVE_VULKAN_VULKAN_H)
if(HAVE_VULKAN_VULKAN_H)
find_package(Vulkan)
if(${Vulkan_FOUND})
set(MW_BUILD_VULKAN ON)
message(STATUS "Vulkan widget has been enabled")
else()
@ -130,21 +142,29 @@ endif()
if(MW_USE_FREETYPE2)
find_package(Freetype)
if(Freetype_FOUND)
message(STATUS "FreeType2 found")
message(STATUS "FreeType2 found")
target_compile_definitions(
Mw
PRIVATE
USE_FREETYPE2
)
Mw
PRIVATE
USE_FREETYPE2
)
list(APPEND INCLUDE_DIRS ${FREETYPE_INCLUDE_DIRS})
list(APPEND LIBRARY_DIRS ${FREETYPE_LIBRARY_DIRS})
list(APPEND LIBRARIES ${FREETYPE_LIBRARIES})
else()
message(WARNING "FreeType2 not found")
message(WARNING "FreeType2 not found")
endif()
endif()
if(MW_USE_GDI_TEXT)
target_compile_definitions(
Mw
PRIVATE
USE_GDI_TEXT
)
endif()
if(MW_USE_WAYLAND)
function(scan_wayland_protocol_core)
execute_process(
@ -198,7 +218,32 @@ if(MW_USE_WAYLAND)
)
endfunction()
function(scan_wayland_protocol_from_file proto file)
SET(proto_c ${CMAKE_CURRENT_SOURCE_DIR}/src/backend/wayland/wayland-${proto}-protocol.c)
execute_process(
COMMAND wayland-scanner private-code ${CMAKE_CURRENT_SOURCE_DIR}/resource/wayland/${file} ${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 ${CMAKE_CURRENT_SOURCE_DIR}/resource/wayland/${file} ${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)
@ -216,10 +261,12 @@ if(MW_USE_WAYLAND)
scan_wayland_protocol("unstable" "primary-selection" "-unstable-v1")
scan_wayland_protocol("unstable" "pointer-constraints" "-unstable-v1")
scan_wayland_protocol("unstable" "relative-pointer" "-unstable-v1")
scan_wayland_protocol_from_file("wlr-layer-shell" "wlr-layer-shell-unstable-v1.xml")
target_sources(
Mw
PRIVATE
src/backend/cairo.c
src/backend/wayland/wayland.c
src/backend/wayland/buffer.c
src/backend/wayland/interfaces.c
@ -270,7 +317,8 @@ if(MW_CLASSIC_THEME)
)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
message("Building Milsko for ${CMAKE_SYSTEM_NAME}")
if(CMAKE_SYSTEM_NAME STREQUAL "Windows" OR CMAKE_SYSTEM_NAME STREQUAL "MSYS")
target_sources(
Mw
PRIVATE
@ -281,12 +329,14 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
PRIVATE
USE_GDI
)
list(APPEND LIBRARIES gdi32)
list(APPEND LIBRARIES gdi32 ole32 uuid)
if(NOT MSVC)
target_link_options(
Mw
PRIVATE
-static-libgcc
)
endif()
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
# target_sources(
# Mw
@ -310,6 +360,7 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
-framework Cocoa
)
elseif(CMAKE_SYSTEM_NAME MATCHES "Retro")
target_sources(
Mw
PRIVATE
@ -328,6 +379,7 @@ elseif(CMAKE_SYSTEM_NAME MATCHES "Retro")
CLASSIC_MAC_OS
)
else()
find_package(PkgConfig)
find_package(X11)
pkg_check_modules(DBUS dbus-1)
@ -341,7 +393,6 @@ else()
if(${X11_FOUND})
list(APPEND INCLUDE_DIRS ${X11_INCLUDE_DIRS})
list(APPEND LIBRARY_DIRS ${X11_LIBRARY_DIRS})
list(APPEND LIBRARIES ${X11_LIBRARIES} m)
target_compile_definitions(
Mw
PRIVATE
@ -351,7 +402,6 @@ else()
if(${X11_Xrender_FOUND})
list(APPEND INCLUDE_DIRS ${XRENDER_INCLUDE_DIRS})
list(APPEND LIBRARY_DIRS ${XRENDER_LIBRARY_DIRS})
list(APPEND LIBRARIES ${XRENDER_LIBRARIES} m)
target_compile_definitions(
Mw
PRIVATE
@ -362,19 +412,24 @@ else()
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
list(APPEND LIBRARIES dl)
endif()
find_package(DBus1)
if(${DBus1_FOUND})
list(APPEND INCLUDE_DIRS ${DBUS_INCLUDE_DIRS})
list(APPEND LIBRARY_DIRS ${DBUS_LIBRARY_DIRS})
target_compile_definitions(
Mw
PRIVATE
USE_DBUS
)
endif()
endif()
find_package(DBus1)
if(${DBus1_FOUND})
list(APPEND INCLUDE_DIRS ${DBUS_INCLUDE_DIRS})
list(APPEND LIBRARY_DIRS ${DBUS_LIBRARY_DIRS})
list(APPEND LIBRARIES ${DBUS_LIBRARIES})
target_compile_definitions(
Mw
PRIVATE
USE_DBUS
)
if(UNIX)
list(APPEND LIBRARIES m)
endif()
target_include_directories(
@ -411,17 +466,20 @@ if(MW_BUILD_VULKAN)
)
endif()
check_include_files(vulkan/VULKAN.h HAS_VK_HEADER)
if(HAS_VK_HEADER)
target_compile_definitions(
Mw
PRIVATE
MW_VULKAN
)
endif()
endif()
target_compile_definitions(
Mw
PRIVATE
_MILSKO
_MILSKO _MILSKO_BUILD
)
install(
@ -431,6 +489,17 @@ install(
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/resource/${PROJECT_NAME}.pc.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
@ONLY
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
DESTINATION $ENV{MINGW_PREFIX}/${CMAKE_INSTALL_DATADIR}/pkgconfig
)
if(MW_INSTALL_HEADERS)
install(
DIRECTORY include/

8
NTMakefile generated
View file

@ -1,7 +1,7 @@
CC = cl /TC /c /nologo
LD = link /nologo
MW_CFLAGS = /Iinclude /Iexternal\libz\include /D_MILSKO /D_MILSKO_BUILD /DUSE_GDI /DUSE_STB_TRUETYPE /DUSE_STB_IMAGE /DSTBI_NO_SIMD
MW_CFLAGS = /Iinclude /Iexternal\libz\include /D_MILSKO /D_MILSKO_BUILD /DUSE_GDI /DUSE_STB_IMAGE /DSTBI_NO_SIMD /DUSE_GDI_TEXT /DMW_OPENGL
MW_LDFLAGS = /DLL
EXE_CFLAGS = /Iinclude
EXE_LDFLAGS =
@ -71,8 +71,10 @@ clean:
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\gdi.obj
del /f /q src\text\stbtt.obj
del /f /q src\text\text.obj
del /f /q src\truetype.obj
del /f /q src\unicode.obj
del /f /q src\widget\box.obj
del /f /q src\widget\button.obj
@ -318,8 +320,8 @@ examples\gldemos\tripaint.obj: examples/gldemos/tripaint.c
$(CC) $(EXE_CFLAGS) /Fo$@ examples/gldemos/tripaint.c
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\charset.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\calendar.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\subwindow.obj src\widget\tab.obj src\widget\table.obj src\widget\treeview.obj src\widget\viewport.obj src\widget\window.obj
$(LD) $(MW_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\charset.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\calendar.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\subwindow.obj src\widget\tab.obj src\widget\table.obj src\widget\treeview.obj src\widget\viewport.obj src\widget\window.obj opengl32.lib gdi32.lib user32.lib advapi32.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\charset.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\gdi.obj src\text\stbtt.obj src\text\text.obj src\truetype.obj src\unicode.obj src\widget\box.obj src\widget\button.obj src\widget\calendar.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\subwindow.obj src\widget\tab.obj src\widget\table.obj src\widget\treeview.obj src\widget\viewport.obj src\widget\window.obj
$(LD) $(MW_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\charset.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\gdi.obj src\text\stbtt.obj src\text\text.obj src\truetype.obj src\unicode.obj src\widget\box.obj src\widget\button.obj src\widget\calendar.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\subwindow.obj src\widget\tab.obj src\widget\table.obj src\widget\treeview.obj src\widget\viewport.obj src\widget\window.obj opengl32.lib gdi32.lib ole32.lib uuid.lib user32.lib advapi32.lib
.c.obj:

View file

@ -1,5 +1,5 @@
Greetings - Welcome to the Milsko GUI Toolkit (Version 1.3)
Greetings - Welcome to the Milsko GUI Toolkit (Version 1.4)
This document contains a brief summary of the contents of this source
distributions and building instructions for Milsko GUI Toolkit.

12
WatMakefile generated
View file

@ -1,7 +1,7 @@
CC = wcc386 -bt=nt -q
LD = wlink option quiet
MW_CFLAGS = -bd -i=include -i=external/libz/include -d_MILSKO -d_MILSKO_BUILD -dUSE_GDI -dUSE_STB_TRUETYPE -dUSE_STB_IMAGE -dSTBI_NO_SIMD
MW_CFLAGS = -bd -i=include -i=external/libz/include -d_MILSKO -d_MILSKO_BUILD -dUSE_GDI -dUSE_STB_IMAGE -dSTBI_NO_SIMD -dUSE_GDI_TEXT -dMW_OPENGL
MW_LDFLAGS = system nt_dll
EXE_CFLAGS = -i=include
EXE_LDFLAGS = system nt
@ -70,8 +70,10 @@ clean: .SYMBOLIC
%erase src/text/font/monottf.obj
%erase src/text/font/ttf.obj
%erase src/text/ft2.obj
%erase src/text/gdi.obj
%erase src/text/stbtt.obj
%erase src/text/text.obj
%erase src/truetype.obj
%erase src/unicode.obj
%erase src/widget/box.obj
%erase src/widget/button.obj
@ -317,8 +319,8 @@ examples/gldemos/tripaint.obj: examples/gldemos/tripaint.c
$(CC) $(EXE_CFLAGS) -fo=$@ examples/gldemos/tripaint.c
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/charset.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/calendar.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/subwindow.obj src/widget/tab.obj src/widget/table.obj src/widget/treeview.obj src/widget/viewport.obj src/widget/window.obj
$(LD) $(MW_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/charset.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/calendar.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/subwindow.obj file src/widget/tab.obj file src/widget/table.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
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/charset.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/gdi.obj src/text/stbtt.obj src/text/text.obj src/truetype.obj src/unicode.obj src/widget/box.obj src/widget/button.obj src/widget/calendar.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/subwindow.obj src/widget/tab.obj src/widget/table.obj src/widget/treeview.obj src/widget/viewport.obj src/widget/window.obj
$(LD) $(MW_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/charset.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/gdi.obj file src/text/stbtt.obj file src/text/text.obj file src/truetype.obj file src/unicode.obj file src/widget/box.obj file src/widget/button.obj file src/widget/calendar.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/subwindow.obj file src/widget/tab.obj file src/widget/table.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 ole32.lib library uuid.lib library user32.lib library advapi32.lib
@ -444,10 +446,14 @@ src/text/font/ttf.obj: src/text/font/ttf.c
$(CC) $(MW_CFLAGS) -fo=$@ src/text/font/ttf.c
src/text/ft2.obj: src/text/ft2.c
$(CC) $(MW_CFLAGS) -fo=$@ src/text/ft2.c
src/text/gdi.obj: src/text/gdi.c
$(CC) $(MW_CFLAGS) -fo=$@ src/text/gdi.c
src/text/stbtt.obj: src/text/stbtt.c
$(CC) $(MW_CFLAGS) -fo=$@ src/text/stbtt.c
src/text/text.obj: src/text/text.c
$(CC) $(MW_CFLAGS) -fo=$@ src/text/text.c
src/truetype.obj: src/truetype.c
$(CC) $(MW_CFLAGS) -fo=$@ src/truetype.c
src/unicode.obj: src/unicode.c
$(CC) $(MW_CFLAGS) -fo=$@ src/unicode.c
src/widget/box.obj: src/widget/box.c

24
configure vendored
View file

@ -2,6 +2,11 @@
our $target = `uname -s`;
$target =~ s/\r?\n$//;
# MSYS with MinGW gives us some other shit idk
if (index($target, "MINGW") != -1) {
$target = "Windows";
}
foreach my $l (@ARGV) {
if ($l =~ /^--.+$/) {
}
@ -39,14 +44,12 @@ require("./pl/utils.pl");
param_set("classic-theme", 0);
param_set("stb-image", 1);
param_set("xrender", 1);
param_set("opengl", 0);
param_set("vulkan", 0);
param_set("vulkan-string-helper", 1);
param_set("shared", 1);
param_set("static", 1);
param_set("examples", 1);
param_set("dbus", 1);
# (option that only makes sense on x11)
param_set("allow-sloppy-focus", 0);
@ -56,7 +59,8 @@ my %features = (
"stb-image" => "use stb_image, instead use libjpeg/libpng",
"stb-truetype" => "use stb_truetype",
"freetype2" => "use FreeType2",
"xrender" => "use XRender",
"gdi-text" => "(Windows only) use GDI Text",
"xrender" => "(X11 only) use XRender",
"opengl" => "build OpenGL widget",
"vulkan" => "build Vulkan widget",
"vulkan-string-helper" => "use Vulkan string helper",
@ -69,7 +73,7 @@ my %features = (
);
my @features_keys = (
"1classic-theme", "1stb-image",
"1stb-truetype", "1freetype2",
"1stb-truetype", "1freetype2", "1gdi-text",
"1opengl", "2xrender",
"1vulkan", "2vulkan-string-helper",
"1shared", "1static",
@ -78,7 +82,10 @@ my @features_keys = (
);
sub def_platform {
if($target ne "Darwin" and $target ne "ClassicMacOS" and $target ne "Windows" and $target ne "Haiku") {
if($target eq "Windows") {
param_set("freetype2", 0);
param_set("stb-truetype", 0);
} elsif($target ne "Darwin" and $target ne "ClassicMacOS" and $target ne "Haiku") {
param_set("freetype2", 1);
param_set("stb-truetype", 0);
} else {
@ -87,13 +94,20 @@ sub def_platform {
}
if($target eq "Linux" || $target eq "FreeBSD") {
param_set("x11", 1);
param_set("xrender", 1);
if(!param_get("tiny")){
param_set("wayland", 1);
}
param_set("dbus", 1);
}
if($target eq "NetBSD" || $target eq "OpenBSD") {
param_set("x11", 1);
}
if($target eq "Windows") {
param_set("gdi-text", 1);
} else {
param_set("gdi-text", 0);
}
}
foreach my $l (@ARGV) {

View file

@ -1,6 +1,6 @@
#include <Mw/Milsko.h>
MwWidget window, menu, button, button2, button3, button4, button5, button6;
MwWidget window, menu, button, button2, button3, button4, button5, button6, button7;
void MWAPI handler(MwWidget handle, void* user_data, void* call_data) {
(void)handle;
@ -51,24 +51,29 @@ void MWAPI resize(MwWidget handle, void* user_data, void* call_data) {
MwVaApply(button,
MwNy, 50 + mh,
MwNwidth, (w - 50 * 2) / 3,
MwNwidth, (w - 50 * 2) / 4,
MwNheight, h - 125 - 50 * 3,
NULL);
MwVaApply(button2,
MwNx, 50 + (w - 50 * 2) / 3,
MwNx, 50 + (w - 50 * 2) / 4,
MwNy, 50 + mh,
MwNwidth, (w - 50 * 2) / 3,
MwNwidth, (w - 50 * 2) / 4,
MwNheight, h - 125 - 50 * 3,
NULL);
MwVaApply(button3,
MwNx, 50 + (w - 50 * 2) / 3 * 2,
MwNx, 50 + (w - 50 * 2) / 4 * 2,
MwNy, 50 + mh,
MwNwidth, (w - 50 * 2) / 3,
MwNwidth, (w - 50 * 2) / 4,
MwNheight, h - 125 - 50 * 3,
NULL);
MwVaApply(button7,
MwNx, 50 + (w - 50 * 2) / 4 * 3,
MwNy, 50 + mh,
MwNwidth, (w - 50 * 2) / 4,
MwNheight, h - 125 - 50 * 3,
NULL);
MwVaApply(button4,
MwNx, 50 + (w - 50 * 2) / 3 * 0,
MwNy, h - 50 - 125 + mh,
@ -121,6 +126,10 @@ int main() {
MwNbackground, "#66f",
MwNforeground, "#000",
NULL);
button7 = MwVaCreateWidget(MwButtonClass, "button", window, 250, 50, 100, 125,
MwNtext, "disabled",
MwNdisabled, 1,
NULL);
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
MwAddUserHandler(button, MwNactivateHandler, handler_theme, NULL);

View file

@ -202,9 +202,16 @@ int main() {
MwNcolumns, 5,
NULL);
f = frame("Button", -PaddingContent, -PaddingContent, MwButtonClass,
MwNtext, "Press me",
f = frame("Button", -PaddingContent, -PaddingContent, MwBoxClass,
MwNorientation, MwVERTICAL,
NULL);
b = MwVaCreateWidget(MwButtonClass, "btn", child(f), 0, 0, 0, 0,
MwNtext, "Press me",
NULL);
b = MwVaCreateWidget(MwButtonClass, "btn_disabled", child(f), 0, 0, 0, 0,
MwNtext, "Cannot press me",
MwNdisabled, 1,
NULL);
MwVaCreateWidget(MwLabelClass, "label", table, 0, 0, 0, 0,
MwNbold, 1,
@ -221,11 +228,11 @@ int main() {
MwNorientation, MwVERTICAL,
MwNfixedSize, 16,
NULL);
for(j = 0; j < 5; j++) MwCreateWidget(i == 0 ? MwCheckBoxClass : MwRadioBoxClass, i == 0 ? "cb" : "rb", b, 0, 0, 0, 0);
for(j = 0; j < 6; j++) MwVaCreateWidget(i == 0 ? MwCheckBoxClass : MwRadioBoxClass, i == 0 ? "cb" : "rb", b, 0, 0, 0, 0, MwNdisabled, (j == 5) ? 1 : 0, NULL);
b = MwVaCreateWidget(MwBoxClass, "table1", w, 0, 0, 0, 0,
MwNorientation, MwVERTICAL,
NULL);
for(j = 0; j < 5; j++) {
for(j = 0; j < 6; j++) {
char buf[32];
sprintf(buf, "%sBox %d", i == 0 ? "Check" : "Radio", j + 1);
MwVaCreateWidget(MwLabelClass, "label", b, 0, 0, 0, 0,

View file

@ -31,6 +31,10 @@ int main() {
MwTabAdd(tab, buf);
}
MwVaApply(MwTabGetFrame(tab, "Tab 1"),
MwNiconPixmap, MwLoadIcon(tab, MwIconWarning),
NULL);
MwAddUserHandler(w, MwNresizeHandler, resize, NULL);
resize(w, NULL, NULL);

View file

@ -1,28 +1,30 @@
file(
GLOB
EXAMPLES_VULKAN_SOURCES
*.c
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()
if(${Vulkan_FOUND})
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()
endif()

View file

@ -1,10 +1,3 @@
/**
* this example is quite minimal, you may need to modify it if your graphics card is more esoteric
*
* ioixd maintains this file. nishi doesn't know vulkan at all
*/
#include <Mw/Milsko.h>
#include <Mw/Widget/Vulkan.h>

View file

@ -28,6 +28,12 @@ MWDECL MwLLColor MWAPI MwParseColor(MwWidget handle, const char* text);
*/
MWDECL void MWAPI MwParseColorNoAllocate(const char* text, MwRGB* rgb);
/*!
* @brief Initialize color table
* @warning This is called in MwLibraryInit - you do not have to call this
*/
MWDECL void MWAPI MwColorTableInit(void);
/*!
* @brief Lighten a color
* @param handle Widget

View file

@ -132,6 +132,7 @@ union _MwLL {
#endif
#ifdef USE_WAYLAND
struct _MwLLWayland wayland;
struct _MwLLCairo cairo;
#endif
#ifdef USE_COCOA
struct _MwLLCocoa cocoa;
@ -153,7 +154,7 @@ union _MwLLColor {
struct _MwLLGDIColor gdi;
#endif
#ifdef USE_WAYLAND
struct _MwLLWaylandColor wayland;
struct _MwLLCairoColor wayland;
#endif
#ifdef USE_COCOA
struct _MwLLCocoaColor cocoa;
@ -173,6 +174,7 @@ union _MwLLPixmap {
#endif
#ifdef USE_WAYLAND
struct _MwLLWaylandPixmap wayland;
struct _MwLLCairoPixmap cairo; /* same structure but we do this for code clarity */
#endif
#ifdef USE_COCOA
struct _MwLLCocoaPixmap cocoa;
@ -203,6 +205,7 @@ struct _MwLLHandler {
void (*focus_out)(MwLL handle, void* data);
void (*clipboard)(MwLL handle, void* data);
void (*dark_theme)(MwLL handle, void* data);
void (*drag_and_drop)(MwLL handle, void* data);
};
struct _MwLLTextDispatchTable {
@ -313,6 +316,12 @@ MWDECL void (*MwLLGetClipboard)(MwLL handle, int clipboard_type);
MWDECL void (*MwLLGetCursorCoord)(MwLL handle, MwPoint* point);
MWDECL void (*MwLLGetScreenSize)(MwLL handle, MwRect* rect);
/*!
* @brief Setup drag and drop capabilities, should the user request it with MwNacceptsDnD
* @param handle Handle
*/
MWDECL void (*MwLLSetupDragAndDrop)(MwLL handle);
/*!
* @brief Set any extra parameters for dark theme
* @param handle Handle
@ -337,18 +346,29 @@ MWDECL void (*MwLLClip)(MwLL handle, MwRect* rect);
MWDECL void MwFLSetup(void);
#ifdef USE_FREETYPE2
MWDECL int MWFL_FT2Setup(void);
MWDECL int MwFL_FT2Setup(void);
#endif
#ifdef USE_STB_TRUETYPE
MWDECL int MwFL_STBTTSetup(void);
#endif
#ifdef USE_GDI_TEXT
MWDECL int MwFL_GDISetup(void);
#endif
MWDECL int (*MwFLDrawText)(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text, MwLLColor color);
MWDECL int (*MwFLTextWidth)(MwFLFont ttf, const char* text);
MWDECL int (*MwFLTextHeight)(MwFLFont ttf, int count);
MWDECL int (*MwFLTextHeightWithText)(MwFLFont ttf, const char* text);
MWDECL void* (*MwFLFontLoad)(unsigned char* data, unsigned int size, int px);
MWDECL void (*MwFLFontFree)(void* handle);
#ifdef _WIN32
MWDECL void *MwLL_winmmLib;
MWDECL long (__stdcall* MwLL_PFN_timeGetTime)(void);
MWDECL unsigned int (__stdcall* MwLL_PFN_timeBeginPeriod)(unsigned int period);
#endif
#ifdef __cplusplus
}
#endif

229
include/Mw/LowLevel/Cairo.h Normal file
View file

@ -0,0 +1,229 @@
/*!
* @file Mw/LowLevel/Cairo.h
* @brief Cairo Backend
* @warning This is used MEGA internally.
*/
#ifndef __MW_LOWLEVEL_CAIRO_H__
#define __MW_LOWLEVEL_CAIRO_H__
#include <Mw/MachDep.h>
#include <Mw/TypeDefs.h>
#include <Mw/LowLevel.h>
#include <Mw/Abstract/Dynamic.h>
#include <cairo/cairo.h>
#ifdef __cplusplus
extern "C" {
#endif
MWDECL int MwLLCairoCallInit(void);
#ifdef __cplusplus
}
#endif
#define CSD_BORDER_FRAME_LEFT 5
#define CSD_BORDER_FRAME_RIGHT 5
#define CSD_BORDER_FRAME_TOP 23
#define CSD_BORDER_FRAME_BOTTOM 4
typedef struct cairo_call_table {
void* cairo_lib;
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);
cairo_status_t (*cairo_surface_write_to_png)(cairo_surface_t* surface, const char* filename);
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_save)(cairo_t* cr);
void (*cairo_restore)(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);
} cairo_call_table_t;
extern cairo_call_table_t cairo_call_tbl;
/* defined inline right here so that it doesn't conflict with the other macros */
MwInline int cairo_load_funcs() {
#ifdef __APPLE__
cairo_call_tbl.cairo_lib = MwDynamicOpen("libcairo.dylib");
#else
cairo_call_tbl.cairo_lib = MwDynamicOpen("libcairo.so");
#endif
if(!cairo_call_tbl.cairo_lib) {
printf("(libcairo not found, cannot use Wayland or Cairo backend.)\n");
return 1;
}
#define CAIRO_FUNC(x) \
cairo_call_tbl.x = MwDynamicSymbol(cairo_call_tbl.cairo_lib, #x); \
if(!cairo_call_tbl.x) { \
printf("WARNING: Could use Wayland/Cairo backend if " #x " was not 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_write_to_png);
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_save);
CAIRO_FUNC(cairo_restore);
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
return 0;
}
#define cairo_set_line_width cairo_call_tbl.cairo_set_line_width
#define cairo_scale cairo_call_tbl.cairo_scale
#define cairo_create cairo_call_tbl.cairo_create
#define cairo_move_to cairo_call_tbl.cairo_move_to
#define cairo_rectangle cairo_call_tbl.cairo_rectangle
#define cairo_new_path cairo_call_tbl.cairo_new_path
#define cairo_set_line_cap cairo_call_tbl.cairo_set_line_cap
#define cairo_set_antialias cairo_call_tbl.cairo_set_antialias
#define cairo_set_source_rgba cairo_call_tbl.cairo_set_source_rgba
#define cairo_set_source_rgb cairo_call_tbl.cairo_set_source_rgb
#define cairo_reset_clip cairo_call_tbl.cairo_reset_clip
#define cairo_image_surface_get_data cairo_call_tbl.cairo_image_surface_get_data
#define cairo_line_to cairo_call_tbl.cairo_line_to
#define cairo_surface_write_to_png cairo_call_tbl.cairo_surface_write_to_png
#define cairo_surface_destroy cairo_call_tbl.cairo_surface_destroy
#define cairo_image_surface_create_for_data cairo_call_tbl.cairo_image_surface_create_for_data
#define cairo_image_surface_create cairo_call_tbl.cairo_image_surface_create
#define cairo_destroy cairo_call_tbl.cairo_destroy
#define cairo_get_source cairo_call_tbl.cairo_get_source
#define cairo_close_path cairo_call_tbl.cairo_close_path
#define cairo_paint cairo_call_tbl.cairo_paint
#define cairo_surface_flush cairo_call_tbl.cairo_surface_flush
#define cairo_clip cairo_call_tbl.cairo_clip
#define cairo_save cairo_call_tbl.cairo_save
#define cairo_restore cairo_call_tbl.cairo_restore
#define cairo_surface_mark_dirty cairo_call_tbl.cairo_surface_mark_dirty
#define cairo_stroke cairo_call_tbl.cairo_stroke
#define cairo_set_source_surface cairo_call_tbl.cairo_set_source_surface
#define cairo_fill cairo_call_tbl.cairo_fill
#define cairo_set_operator cairo_call_tbl.cairo_set_operator
#define cairo_pattern_set_filter cairo_call_tbl.cairo_pattern_set_filter
struct _MwLLCairo {
struct _MwLLCommon common;
cairo_surface_t* front_cs;
cairo_surface_t* back_cs;
cairo_t* front_cairo;
cairo_t* back_cairo;
/* The cairo to actually use for draw operations. Typically is front_cairo, but wayland's MwLLBeginDraw can change this to the back_cairo so it can be used to draw window decorations. */
cairo_t* selected_cairo;
int x;
int y;
int width;
int height;
MwBool toplevel;
MwLL parent;
};
struct _MwLLCairoColor {
struct _MwLLCommonColor common;
};
struct _MwLLCairoPixmap {
struct _MwLLCommonPixmap common;
cairo_surface_t* cs;
};
void MwLLCairoFrontSetup(struct _MwLLCairo* cairo, MwU8* data, MwU32 width, MwU32 height);
void MwLLCairoBackSetup(struct _MwLLCairo* cairo, MwU8* data, MwU32 width, MwU32 height);
void MwLLCairoFrontDestroy(struct _MwLLCairo* cairo);
void MwLLCairoBackDestroy(struct _MwLLCairo* cairo);
void MwLLCairoPolygon(struct _MwLLCairo handle, MwPoint* points, int points_count, MwLLColor color);
void MwLLCairoLine(struct _MwLLCairo handle, MwPoint* points, MwLLColor color);
MwLLPixmap MwLLCairoCreatePixmap(struct _MwLLCairo handle, unsigned char* data, int width, int height);
void MwLLCairoPixmapUpdate(MwLLPixmap handle);
void MwLLCairoDestroyPixmap(MwLLPixmap pixmap);
void MwLLCairoDrawPixmap(struct _MwLLCairo handle, MwRect* rect, MwLLPixmap pixmap);
void MwLLCairoDestroy(struct _MwLLCairo handle);
#endif

View file

@ -11,10 +11,10 @@
#include <Mw/LowLevel.h>
#include <Mw/Abstract/Dynamic.h>
#include <Mw/LowLevel/Cairo.h>
#include <xkbcommon/xkbcommon.h>
#include <cairo/cairo.h>
#include <pthread.h>
#include <dbus/dbus.h>
#ifdef __cplusplus
extern "C" {
@ -28,8 +28,8 @@ MWDECL int MwLLWaylandCallInit(void);
#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_BORDER_FRAME_TOP 23
#define CSD_BORDER_FRAME_BOTTOM 4
struct _MwLLWayland;
@ -43,7 +43,6 @@ struct _MwLLWayland;
typedef struct wayland_call_table {
void* lib;
void* xkb_lib;
void* cairo_lib;
#ifdef USE_DBUS
MwLLDBusFuncTable dbus;
MwBool has_dbus;
@ -80,67 +79,6 @@ typedef struct wayland_call_table {
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_save)(cairo_t* cr);
void (*cairo_restore)(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;
@ -150,6 +88,8 @@ extern MwBool MwWaylandVulkan;
#define MwWaylandVulkan 0
#endif
MWDECL MwBool MwWaylandCairoOnly;
/* defined inline right here so that it doesn't conflict with the other macros */
MwInline int wayland_load_funcs() {
#ifdef __APPLE__
@ -170,15 +110,7 @@ MwInline int wayland_load_funcs() {
printf("(libxkbcommon not found, cannot use Wayland backend.)\n");
return 1;
}
#ifdef __APPLE__
wl_call_tbl.cairo_lib = MwDynamicOpen("libcairo.dylib");
#else
wl_call_tbl.cairo_lib = MwDynamicOpen("libcairo.so");
#endif
if(!wl_call_tbl.cairo_lib) {
printf("(libcairo 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) { \
@ -224,44 +156,9 @@ MwInline int wayland_load_funcs() {
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_save);
CAIRO_FUNC(cairo_restore);
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
if(cairo_load_funcs() != 0) {
return 1;
}
#ifdef USE_DBUS
wl_call_tbl.has_dbus = MwLLDBusFuncSetup(&wl_call_tbl.dbus);
@ -298,37 +195,6 @@ MwInline int wayland_load_funcs() {
#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_save wl_call_tbl.cairo_save
#define cairo_restore wl_call_tbl.cairo_restore
#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"
@ -340,6 +206,7 @@ MwInline int wayland_load_funcs() {
#include "Wayland/pointer-constraints-client-protocol.h"
#include "Wayland/relative-pointer-client-protocol.h"
#include "Wayland/xdg-toplevel-icon-client-protocol.h"
#include "Wayland/wlr-layer-shell-client-protocol.h"
#endif
typedef struct wayland_protocol {
@ -347,7 +214,7 @@ typedef struct wayland_protocol {
void* context;
} wayland_protocol_t;
typedef wayland_protocol_t*(wl_setup_func)(MwU32, struct _MwLLWayland*);
typedef wayland_protocol_t*(wl_setup_func)(MwU32, struct _MwLLWayland*, MwU32 version);
typedef void(wl_destroy_func)(struct _MwLLWayland* wayland, wayland_protocol_t* data);
typedef struct wayland_protocol_callback_table {
@ -360,6 +227,7 @@ struct _MwLLWaylandTopLevel {
struct xdg_toplevel* xdg_top_level;
struct xdg_toplevel_listener xdg_toplevel_listener;
struct xdg_surface_listener xdg_surface_listener;
MwBool maxim_state;
MwBool compositor_created;
MwBool xdg_wm_base_created;
@ -387,6 +255,10 @@ struct _MwLLWaylandPopup {
MwLL topmost_parent;
};
struct _MwLLWaylandLayerSurface {
struct zwlr_layer_surface_v1* surface;
};
/* Shared set of anything needed for a shm buffer. */
struct _MwLLWaylandShmBuffer {
struct wl_shm* shm;
@ -410,6 +282,7 @@ enum _MwLLWaylandType {
MwLL_WAYLAND_TOPLEVEL,
MwLL_WAYLAND_SUBLEVEL,
MwLL_WAYLAND_POPUP,
MwLL_WAYLAND_LAYER_SURFACE,
};
typedef struct wl_clipboard_device_context {
@ -428,6 +301,7 @@ typedef struct wl_clipboard_device_context {
struct _MwLLWayland {
struct _MwLLCommon common;
struct _MwLLCairo cairo;
union {
/* Pointer for data that's only loaded if the widget is a toplevel */
@ -436,6 +310,8 @@ struct _MwLLWayland {
struct _MwLLWaylandSublevel* sublevel;
/* Pointer for data that's only loaded if the widget is a popup */
struct _MwLLWaylandPopup* popup;
/* Pointer for data that's only loaded if the widget is a layer surface */
struct _MwLLWaylandLayerSurface* layer_surface;
};
enum _MwLLWaylandType type;
@ -444,6 +320,7 @@ struct _MwLLWayland {
MwRect clipping_rect;
MwBool no;
MwBool changing;
MwBool detatching;
MwPoint detach_point;
@ -466,6 +343,7 @@ struct _MwLLWayland {
wayland_protocol_t* value;
}* wl_protocol_map;
MwBool do_csd;
MwBool has_decorations;
char title[256];
@ -537,6 +415,7 @@ struct _MwLLWayland {
MwU32 ww, wh; /* Window position */
MwPoint cur_mouse_pos; /* Currently known mouse position */
MwLL currentlyHeldWidget;
MwLL focusedWidget;
int resizing;
int setting_wh;
@ -550,11 +429,15 @@ struct _MwLLWayland {
MwBool dispatching_resize;
MwBool is_toplevel_menu;
struct _MwLLWaylandShmBuffer framebuffer;
struct _MwLLWaylandShmBuffer backbuffer;
struct _MwLLWaylandShmBuffer cursor;
struct _MwLLWaylandShmBuffer* icon;
MwLLPixmap icon_pixmap;
pthread_mutex_t eventsMutex;
int cancelEvent;
@ -564,23 +447,20 @@ struct _MwLLWayland {
MwBool moving;
cairo_surface_t* front_cs;
cairo_surface_t* back_cs;
cairo_t* front_cairo;
cairo_t* back_cairo;
/* The cairo to actually use for draw operations. Typically is front_cairo, but MwLLBeginDraw can change this to the back_cairo so it can be used to draw window decorations. */
cairo_t* selected_cairo;
MwI64 keyboard_rate;
MwI32 keyboard_delay;
int last_pressed_key;
MwBool holding_key;
MwU64 next_elapsed;
long start_time;
long end_time;
};
struct _MwLLWaylandColor {
struct _MwLLCommonColor common;
};
struct _MwLLWaylandPixmap {
struct _MwLLCommonPixmap common;
cairo_surface_t* cs;
};
#define _MwLLWaylandPixmap _MwLLCairoPixmap
/* Setup the framebuffer with the saved width/height */
void MwLLWaylandFramebufferSetup(struct _MwLLWayland* wayland);

View file

@ -25,6 +25,7 @@
#ifdef _MILSKO
#include <windows.h>
#include <mmsystem.h>
#ifndef GWLP_USERDATA
#define GWLP_USERDATA GWL_USERDATA
#define GWLP_WNDPROC GWL_WNDPROC

View file

@ -17,6 +17,7 @@
#include <Mw/String.h>
#include <Mw/Draw.h>
#include <Mw/Version.h>
#include <Mw/TrueType.h>
#include <Mw/Abstract/Dynamic.h>
#include <Mw/Abstract/Directory.h>

View file

@ -52,6 +52,8 @@
#define MwNcolumns "Icolumns"
#define MwNcolumnSpan "IcolumnSpan"
#define MwNrowSpan "IrowSpan"
#define MwNdisabled "Idisabled"
#define MwNacceptsDnD "IacceptsDnD"
#define MwNtitle "Stitle"
#define MwNtext "Stext"
@ -97,5 +99,6 @@
#define MwNdrawHandler "Cdraw"
#define MwNclipboardHandler "Cclipboard"
#define MwNdarkThemeHandler "CdarkTheme"
#define MwNdragAndDropHandler "CdragAndDrop"
#endif

33
include/Mw/TrueType.h Normal file
View file

@ -0,0 +1,33 @@
/*!
* @file Mw/TrueType.h
* @brief TrueType utilities
*/
#ifndef __MW_TRUETYPE_H__
#define __MW_TRUETYPE_H__
#include <Mw/MachDep.h>
#include <Mw/TypeDefs.h>
#ifdef __cplusplus
extern "C" {
#endif
/*!
* @brief Get the TrueType font information
* @param data Font data
* @param size Font size
* @return Information
*/
MWDECL MwTTFInfo MwTTFGetInfo(unsigned char* data, int size);
/*!
* @brief Free the TrueType font information
* @param info Information
*/
MWDECL void MwTTFFreeInfo(MwTTFInfo info);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -31,6 +31,7 @@ typedef struct _MwSubWindow* MwSubWindow;
typedef struct _MwTab* MwTab;
typedef struct _MwTable* MwTable;
typedef struct _MwMouse MwMouse;
typedef struct _MwTTFInfo* MwTTFInfo;
#ifdef _MILSKO
typedef struct _MwWidget* MwWidget;
#else
@ -40,7 +41,7 @@ typedef void (*MwHandler)(MwWidget handle);
typedef int (*MwHandlerWithStatus)(MwWidget handle);
typedef void (*MwHandlerProps)(MwWidget handle, char** key);
typedef void (*MwHandlerProp)(MwWidget handle, const char* key);
typedef void (*MwHandlerChildrenUpdate)(MwWidget handle, MwWidget child, int new);
typedef void (*MwHandlerChildrenUpdate)(MwWidget handle, MwWidget child, int new_child);
typedef void (*MwHandlerChildrenProp)(MwWidget handle, MwWidget child, const char* key);
typedef void (*MwHandlerKey)(MwWidget handle, int key);
typedef void (*MwHandlerMouse)(MwWidget handle, void* ptr);
@ -115,9 +116,13 @@ struct _MwWidget {
int top_step;
MwWidget* draw_queue;
MwWidget* resize_queue;
MwWidget* monitored_entries;
int berserk;
long last_tick;
MwBool is_menu;
};
#endif
@ -134,6 +139,8 @@ struct _MwEntry {
int cursor;
int right;
int length;
int active;
int cursor_blink_timer;
MwPoint mouse;
};
@ -244,6 +251,11 @@ struct _MwMouse {
int button;
};
struct _MwTTFInfo {
char* family;
int weight;
};
struct _MwClass {
MwHandlerWithStatus create;
MwHandler destroy;
@ -262,7 +274,7 @@ struct _MwClass {
MwHandlerChildrenProp children_prop_change;
MwHandlerClipboardReceived clipboard;
MwHandlerProps props_change;
void* reserved1;
MwHandler drag_and_drop;
void* reserved2;
void* reserved3;
};

View file

@ -23,7 +23,7 @@
/*!
* @brief Version in string
*/
#define MwVERSION "1.3"
#define MwVERSION "1.4"
/*!
* @brief Version in string

View file

@ -42,6 +42,16 @@ MwInline MwWidget MwTabGetFrame(MwWidget handle, const char* name) {
return out;
}
/*!
* @brief Focus on a tab frame
* @param handle Widget
* @param name Tab name
* @return Frame
*/
MwInline void MwTabFocus(MwWidget handle, const char* name) {
MwVaWidgetExecute(handle, "mwTabFocus", NULL, name);
}
#ifdef __cplusplus
}
#endif

View file

@ -27,6 +27,17 @@ MwInline void MwWindowMakeBorderless(MwWidget handle, int toggle) {
MwVaWidgetExecute(handle, "mwWindowMakeBorderless", NULL, toggle);
}
/*!
* @brief Whether the window should close
* @param handle Widget
* @return bool
*/
MwInline MwBool MwWindowShouldClose(MwWidget handle) {
MwBool res = MwFALSE;
MwVaWidgetExecute(handle, "mwWindowShouldClose", NULL, &res);
return res;
}
#ifdef __cplusplus
}
#endif

View file

@ -668,6 +668,7 @@
<properties>
<property name="hasBorder" />
<property name="inverted" />
<property name="iconPixmap" />
</properties>
</widget>
<widget name="Image">
@ -961,6 +962,11 @@
<string name="name" />
</arguments>
</function>
<function name="Focus">
<arguments>
<string name="name" />
</arguments>
</function>
</functions>
</widget>

View file

@ -4,5 +4,7 @@ $executable_suffix = ".exe";
$math = "";
add_ldflags("-Wl,--out-implib,src/libMw.dll.a -static-libgcc");
use_backend("gdi");
add_libs("-lole32");
add_libs("-luuid");
1;

View file

@ -46,6 +46,7 @@ if (grep(/^classicmacos$/, @backends)) {
if (grep(/^wayland$/, @backends)) {
add_cflags("-DUSE_WAYLAND");
new_object("src/backend/cairo.c");
new_object("src/backend/wayland/wayland.c");
new_object("src/backend/wayland/buffer.c");
new_object("src/backend/wayland/interfaces.c");
@ -65,6 +66,8 @@ if (grep(/^wayland$/, @backends)) {
scan_wayland_protocol("unstable", "primary-selection", "-unstable-v1");
scan_wayland_protocol("unstable", "pointer-constraints", "-unstable-v1");
scan_wayland_protocol("unstable", "relative-pointer", "-unstable-v1");
scan_wayland_protocol_from_file("wlr-layer-shell",
"wlr-layer-shell-unstable-v1.xml");
$gl_libs = "-lGL -lGLU";
}
@ -132,6 +135,10 @@ if (param_get("freetype2")) {
}
}
if (param_get("gdi-text")) {
add_cflags("-DUSE_GDI_TEXT");
}
if (param_get("vulkan") && param_get("vulkan-string-helper")) {
add_cflags("-DHAS_VK_ENUM_STRING_HELPER");
}

View file

@ -125,6 +125,35 @@ sub scan_wayland_protocol {
}
}
sub scan_wayland_protocol_from_file {
my $proto = $_[0];
my $file = $_[1];
my $proto_c = "src/backend/wayland/wayland-${proto}-protocol.c";
if (
system(
"wayland-scanner private-code ./resource/wayland/${file} ${proto_c}"
) != 0
)
{
print(
"^ Error on getting private code for ./resource/wayland/${file}\n");
}
else {
new_object($proto_c);
}
if (
system(
"wayland-scanner client-header ./resource/wayland/${file} include/Mw/LowLevel/Wayland/${proto}-client-protocol.h"
)
)
{
print(
"^ Error on getting client header for ./resource/wayland/${file}\n"
);
}
}
our %params = ();
sub param_set {

10
resource/milsko.pc.in Normal file
View file

@ -0,0 +1,10 @@
prefix="@CMAKE_INSTALL_PREFIX@"
includedir="@CMAKE_INSTALL_PREFIX@/include"
libdir="@CMAKE_INSTALL_PREFIX@/bin"
Name: @PROJECT_NAME@
Description: @PROJECT_DESCRIPTION@
URL: @PROJECT_HOMEPAGE_URL@
Version: @PROJECT_VERSION@
Cflags: -I"${includedir}"/
Libs: -L"${libdir}" -lMw

View file

@ -0,0 +1,451 @@
<?xml version="1.0" encoding="UTF-8" ?>
<protocol name="wlr_layer_shell_unstable_v1">
<copyright>
Copyright © 2017 Drew DeVault
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
without fee, provided that the above copyright notice appear in
all copies and that both that copyright notice and this permission
notice appear in supporting documentation, and that the name of
the copyright holders not be used in advertising or publicity
pertaining to distribution of the software without specific,
written prior permission. The copyright holders make no
representations about the suitability of this software for any
purpose. It is provided "as is" without express or implied
warranty.
THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.
</copyright>
<interface name="zwlr_layer_shell_v1" version="4">
<description summary="create surfaces that are layers of the desktop">
Clients can use this interface to assign the surface_layer role to
wl_surfaces. Such surfaces are assigned to a "layer" of the output and
rendered with a defined z-depth respective to each other. They may also be
anchored to the edges and corners of a screen and specify input handling
semantics. This interface should be suitable for the implementation of
many desktop shell components, and a broad number of other applications
that interact with the desktop.
</description>
<request name="get_layer_surface">
<description summary="create a layer_surface from a surface">
Create a layer surface for an existing surface. This assigns the role of
layer_surface, or raises a protocol error if another role is already
assigned.
Creating a layer surface from a wl_surface which has a buffer attached
or committed is a client error, and any attempts by a client to attach
or manipulate a buffer prior to the first layer_surface.configure call
must also be treated as errors.
After creating a layer_surface object and setting it up, the client
must perform an initial commit without any buffer attached.
The compositor will reply with a layer_surface.configure event.
The client must acknowledge it and is then allowed to attach a buffer
to map the surface.
You may pass NULL for output to allow the compositor to decide which
output to use. Generally this will be the one that the user most
recently interacted with.
Clients can specify a namespace that defines the purpose of the layer
surface.
</description>
<arg name="id" type="new_id" interface="zwlr_layer_surface_v1" />
<arg name="surface" type="object" interface="wl_surface" />
<arg
name="output"
type="object"
interface="wl_output"
allow-null="true"
/>
<arg
name="layer"
type="uint"
enum="layer"
summary="layer to add this surface to"
/>
<arg
name="namespace"
type="string"
summary="namespace for the layer surface"
/>
</request>
<enum name="error">
<entry name="role" value="0" summary="wl_surface has another role" />
<entry name="invalid_layer" value="1" summary="layer value is invalid" />
<entry
name="already_constructed"
value="2"
summary="wl_surface has a buffer attached or committed"
/>
</enum>
<enum name="layer">
<description summary="available layers for surfaces">
These values indicate which layers a surface can be rendered in. They
are ordered by z depth, bottom-most first. Traditional shell surfaces
will typically be rendered between the bottom and top layers.
Fullscreen shell surfaces are typically rendered at the top layer.
Multiple surfaces can share a single layer, and ordering within a
single layer is undefined.
</description>
<entry name="background" value="0" />
<entry name="bottom" value="1" />
<entry name="top" value="2" />
<entry name="overlay" value="3" />
</enum>
<!-- Version 3 additions -->
<request name="destroy" type="destructor" since="3">
<description summary="destroy the layer_shell object">
This request indicates that the client will not use the layer_shell
object any more. Objects that have been created through this instance
are not affected.
</description>
</request>
</interface>
<interface name="zwlr_layer_surface_v1" version="4">
<description summary="layer metadata interface">
An interface that may be implemented by a wl_surface, for surfaces that
are designed to be rendered as a layer of a stacked desktop-like
environment.
Layer surface state (layer, size, anchor, exclusive zone,
margin, interactivity) is double-buffered, and will be applied at the
time wl_surface.commit of the corresponding wl_surface is called.
Attaching a null buffer to a layer surface unmaps it.
Unmapping a layer_surface means that the surface cannot be shown by the
compositor until it is explicitly mapped again. The layer_surface
returns to the state it had right after layer_shell.get_layer_surface.
The client can re-map the surface by performing a commit without any
buffer attached, waiting for a configure event and handling it as usual.
</description>
<request name="set_size">
<description summary="sets the size of the surface">
Sets the size of the surface in surface-local coordinates. The
compositor will display the surface centered with respect to its
anchors.
If you pass 0 for either value, the compositor will assign it and
inform you of the assignment in the configure event. You must set your
anchor to opposite edges in the dimensions you omit; not doing so is a
protocol error. Both values are 0 by default.
Size is double-buffered, see wl_surface.commit.
</description>
<arg name="width" type="uint" />
<arg name="height" type="uint" />
</request>
<request name="set_anchor">
<description summary="configures the anchor point of the surface">
Requests that the compositor anchor the surface to the specified edges
and corners. If two orthogonal edges are specified (e.g. 'top' and
'left'), then the anchor point will be the intersection of the edges
(e.g. the top left corner of the output); otherwise the anchor point
will be centered on that edge, or in the center if none is specified.
Anchor is double-buffered, see wl_surface.commit.
</description>
<arg name="anchor" type="uint" enum="anchor" />
</request>
<request name="set_exclusive_zone">
<description summary="configures the exclusive geometry of this surface">
Requests that the compositor avoids occluding an area with other
surfaces. The compositor's use of this information is
implementation-dependent - do not assume that this region will not
actually be occluded.
A positive value is only meaningful if the surface is anchored to one
edge or an edge and both perpendicular edges. If the surface is not
anchored, anchored to only two perpendicular edges (a corner), anchored
to only two parallel edges or anchored to all edges, a positive value
will be treated the same as zero.
A positive zone is the distance from the edge in surface-local
coordinates to consider exclusive.
Surfaces that do not wish to have an exclusive zone may instead specify
how they should interact with surfaces that do. If set to zero, the
surface indicates that it would like to be moved to avoid occluding
surfaces with a positive exclusive zone. If set to -1, the surface
indicates that it would not like to be moved to accommodate for other
surfaces, and the compositor should extend it all the way to the edges
it is anchored to.
For example, a panel might set its exclusive zone to 10, so that
maximized shell surfaces are not shown on top of it. A notification
might set its exclusive zone to 0, so that it is moved to avoid
occluding the panel, but shell surfaces are shown underneath it. A
wallpaper or lock screen might set their exclusive zone to -1, so that
they stretch below or over the panel.
The default value is 0.
Exclusive zone is double-buffered, see wl_surface.commit.
</description>
<arg name="zone" type="int" />
</request>
<request name="set_margin">
<description summary="sets a margin from the anchor point">
Requests that the surface be placed some distance away from the anchor
point on the output, in surface-local coordinates. Setting this value
for edges you are not anchored to has no effect.
The exclusive zone includes the margin.
Margin is double-buffered, see wl_surface.commit.
</description>
<arg name="top" type="int" />
<arg name="right" type="int" />
<arg name="bottom" type="int" />
<arg name="left" type="int" />
</request>
<enum name="keyboard_interactivity">
<description
summary="types of keyboard interaction possible for a layer shell surface"
>
Types of keyboard interaction possible for layer shell surfaces. The
rationale for this is twofold: (1) some applications are not interested
in keyboard events and not allowing them to be focused can improve the
desktop experience; (2) some applications will want to take exclusive
keyboard focus.
</description>
<entry name="none" value="0">
<description summary="no keyboard focus is possible">
This value indicates that this surface is not interested in keyboard
events and the compositor should never assign it the keyboard focus.
This is the default value, set for newly created layer shell surfaces.
This is useful for e.g. desktop widgets that display information or
only have interaction with non-keyboard input devices.
</description>
</entry>
<entry name="exclusive" value="1">
<description summary="request exclusive keyboard focus">
Request exclusive keyboard focus if this surface is above the shell surface layer.
For the top and overlay layers, the seat will always give
exclusive keyboard focus to the top-most layer which has keyboard
interactivity set to exclusive. If this layer contains multiple
surfaces with keyboard interactivity set to exclusive, the compositor
determines the one receiving keyboard events in an implementation-
defined manner. In this case, no guarantee is made when this surface
will receive keyboard focus (if ever).
For the bottom and background layers, the compositor is allowed to use
normal focus semantics.
This setting is mainly intended for applications that need to ensure
they receive all keyboard events, such as a lock screen or a password
prompt.
</description>
</entry>
<entry name="on_demand" value="2" since="4">
<description summary="request regular keyboard focus semantics">
This requests the compositor to allow this surface to be focused and
unfocused by the user in an implementation-defined manner. The user
should be able to unfocus this surface even regardless of the layer
it is on.
Typically, the compositor will want to use its normal mechanism to
manage keyboard focus between layer shell surfaces with this setting
and regular toplevels on the desktop layer (e.g. click to focus).
Nevertheless, it is possible for a compositor to require a special
interaction to focus or unfocus layer shell surfaces (e.g. requiring
a click even if focus follows the mouse normally, or providing a
keybinding to switch focus between layers).
This setting is mainly intended for desktop shell components (e.g.
panels) that allow keyboard interaction. Using this option can allow
implementing a desktop shell that can be fully usable without the
mouse.
</description>
</entry>
</enum>
<request name="set_keyboard_interactivity">
<description summary="requests keyboard events">
Set how keyboard events are delivered to this surface. By default,
layer shell surfaces do not receive keyboard events; this request can
be used to change this.
This setting is inherited by child surfaces set by the get_popup
request.
Layer surfaces receive pointer, touch, and tablet events normally. If
you do not want to receive them, set the input region on your surface
to an empty region.
Keyboard interactivity is double-buffered, see wl_surface.commit.
</description>
<arg
name="keyboard_interactivity"
type="uint"
enum="keyboard_interactivity"
/>
</request>
<request name="get_popup">
<description summary="assign this layer_surface as an xdg_popup parent">
This assigns an xdg_popup's parent to this layer_surface. This popup
should have been created via xdg_surface::get_popup with the parent set
to NULL, and this request must be invoked before committing the popup's
initial state.
See the documentation of xdg_popup for more details about what an
xdg_popup is and how it is used.
</description>
<arg name="popup" type="object" interface="xdg_popup" />
</request>
<request name="ack_configure">
<description summary="ack a configure event">
When a configure event is received, if a client commits the
surface in response to the configure event, then the client
must make an ack_configure request sometime before the commit
request, passing along the serial of the configure event.
If the client receives multiple configure events before it
can respond to one, it only has to ack the last configure event.
A client is not required to commit immediately after sending
an ack_configure request - it may even ack_configure several times
before its next surface commit.
A client may send multiple ack_configure requests before committing, but
only the last request sent before a commit indicates which configure
event the client really is responding to.
</description>
<arg
name="serial"
type="uint"
summary="the serial from the configure event"
/>
</request>
<request name="destroy" type="destructor">
<description summary="destroy the layer_surface">
This request destroys the layer surface.
</description>
</request>
<event name="configure">
<description summary="suggest a surface change">
The configure event asks the client to resize its surface.
Clients should arrange their surface for the new states, and then send
an ack_configure request with the serial sent in this configure event at
some point before committing the new surface.
The client is free to dismiss all but the last configure event it
received.
The width and height arguments specify the size of the window in
surface-local coordinates.
The size is a hint, in the sense that the client is free to ignore it if
it doesn't resize, pick a smaller size (to satisfy aspect ratio or
resize in steps of NxM pixels). If the client picks a smaller size and
is anchored to two opposite anchors (e.g. 'top' and 'bottom'), the
surface will be centered on this axis.
If the width or height arguments are zero, it means the client should
decide its own window dimension.
</description>
<arg name="serial" type="uint" />
<arg name="width" type="uint" />
<arg name="height" type="uint" />
</event>
<event name="closed">
<description summary="surface should be closed">
The closed event is sent by the compositor when the surface will no
longer be shown. The output may have been destroyed or the user may
have asked for it to be removed. Further changes to the surface will be
ignored. The client should destroy the resource after receiving this
event, and create a new surface if they so choose.
</description>
</event>
<enum name="error">
<entry
name="invalid_surface_state"
value="0"
summary="provided surface state is invalid"
/>
<entry name="invalid_size" value="1" summary="size is invalid" />
<entry
name="invalid_anchor"
value="2"
summary="anchor bitfield is invalid"
/>
<entry
name="invalid_keyboard_interactivity"
value="3"
summary="keyboard interactivity is invalid"
/>
</enum>
<enum name="anchor" bitfield="true">
<entry
name="top"
value="1"
summary="the top edge of the anchor rectangle"
/>
<entry
name="bottom"
value="2"
summary="the bottom edge of the anchor rectangle"
/>
<entry
name="left"
value="4"
summary="the left edge of the anchor rectangle"
/>
<entry
name="right"
value="8"
summary="the right edge of the anchor rectangle"
/>
</enum>
<!-- Version 2 additions -->
<request name="set_layer" since="2">
<description summary="change the layer of the surface">
Change the layer that the surface is rendered on.
Layer is double-buffered, see wl_surface.commit.
</description>
<arg
name="layer"
type="uint"
enum="zwlr_layer_shell_v1.layer"
summary="layer to move this surface to"
/>
</request>
</interface>
</protocol>

View file

@ -19,7 +19,7 @@ char* MwACPToUTF8(const char* input) {
return MwStringDuplicate(input);
}
wout = malloc(wbytes);
wout = malloc(wbytes + sizeof(wchar_t));
len = wbytes / sizeof(wchar_t);
memset(wout, 0, wbytes);
@ -64,7 +64,7 @@ char* MwUTF8ToACP(const char* input) {
return MwStringDuplicate(input);
}
wout = malloc(wbytes);
wout = malloc(wbytes + sizeof(wchar_t));
len = wbytes / sizeof(wchar_t);
memset(wout, 0, wbytes);

View file

@ -19,15 +19,19 @@ typedef struct dir {
void* MwDirectoryOpen(const char* path) {
dir_t* dir = malloc(sizeof(*dir));
#ifdef _WIN32
char* p = malloc(strlen(path) + 2 + 1);
strcpy(p, path);
if(strchr(path, '/') != NULL) {
strcat(p, "/");
} else {
strcat(p, "\\");
char * p;
if(!dir) {
printf("Out Of Memory\n");
return NULL;
}
strcat(p, "*");
#ifdef _WIN32
p = MwStringDuplicate(path);
if(strchr(path, '/') != NULL) {
MwStringConcat(p, "/");
} else {
MwStringConcat(p, "\\");
}
MwStringConcat(p, "*");
if((dir->hFind = FindFirstFile(p, &dir->ffd)) == INVALID_HANDLE_VALUE) {
free(p);
free(dir);
@ -66,8 +70,19 @@ MwDirectoryEntry* MwDirectoryRead(void* handle) {
dir_t* dir = handle;
MwDirectoryEntry* entry = malloc(sizeof(*entry));
#ifdef _WIN32
ULARGE_INTEGER* l;
ULARGE_INTEGER* l;
#elif defined(CLASSIC_MAC_OS)
#else
struct dirent* d;
struct stat s;
char* p;
#endif
if(!entry) {
printf("Out Of Memory\n");
return NULL;
}
#ifdef _WIN32
if(!dir->next) return NULL;
entry->name = MwStringDuplicate(dir->ffd.cFileName);
@ -91,9 +106,6 @@ MwDirectoryEntry* MwDirectoryRead(void* handle) {
#elif defined(CLASSIC_MAC_OS)
/* todo */
#else
struct dirent* d;
struct stat s;
char* p;
if((d = readdir(dir->dir)) == NULL) {
free(entry);
return NULL;
@ -170,8 +182,8 @@ static void MwDirectoryJoinSingle(char* target, char* p) {
b[0] = DIRSEP;
b[1] = 0;
strcat(target, b);
strcat(target, p);
MwStringConcat(target, b);
MwStringConcat(target, p);
}
for(i = strlen(target) - 1; i >= 0; i--) {
@ -187,17 +199,16 @@ static void MwDirectoryJoinSingle(char* target, char* p) {
b[0] = DIRSEP;
b[1] = 0;
strcat(target, b);
MwStringConcat(target, b);
}
}
char* MwDirectoryJoin(char* a, char* b) {
char* p = malloc(strlen(a) + 1 + strlen(b) + 1);
char* p = MwStringDuplicate(a);
char* bdup = MwStringDuplicate(b);
char* b2 = bdup;
int i;
strcpy(p, a);
for(i = strlen(p) - 1; i >= 0; i--) {
if(p[i] == DIRSEP) {
p[i] = 0;

View file

@ -2,7 +2,7 @@
#if defined(_WIN32)
long MwTimeGetTick(void) {
return GetTickCount();
return MwLL_PFN_timeGetTime();
}
void MwTimeSleep(int ms) {

266
src/backend/cairo.c Normal file
View file

@ -0,0 +1,266 @@
#include <Mw/Milsko.h>
#include "../../external/stb_ds.h"
cairo_call_table_t cairo_call_tbl;
void MwLLCairoPolygon(struct _MwLLCairo handle, MwPoint* points, int points_count, MwLLColor color) {
int i;
cairo_set_source_rgba(handle.front_cairo, color->common.red / 255.0, color->common.green / 255.0, color->common.blue / 255.0, 1.0);
cairo_new_path(handle.front_cairo);
for(i = 0; i < points_count; i++) {
if(i == 0) {
cairo_move_to(handle.front_cairo, points[i].x, points[i].y);
} else {
cairo_line_to(handle.front_cairo, points[i].x, points[i].y);
}
}
cairo_close_path(handle.front_cairo);
cairo_set_operator(handle.front_cairo, CAIRO_OPERATOR_SOURCE);
cairo_fill(handle.front_cairo);
cairo_set_operator(handle.front_cairo, CAIRO_OPERATOR_OVER);
};
void MwLLCairoLine(struct _MwLLCairo handle, MwPoint* points, MwLLColor color) {
int i;
cairo_set_antialias(handle.front_cairo, CAIRO_ANTIALIAS_NONE);
cairo_set_line_cap(handle.front_cairo, CAIRO_LINE_CAP_SQUARE);
cairo_set_source_rgba(handle.front_cairo, color->common.red / 255.0, color->common.green / 255.0, color->common.blue / 255.0, 1.0);
cairo_new_path(handle.front_cairo);
for(i = 0; i < 2; i++) {
if(i == 0) {
cairo_move_to(handle.front_cairo, points[i].x, points[i].y);
} else {
cairo_line_to(handle.front_cairo, points[i].x, points[i].y);
}
}
cairo_close_path(handle.front_cairo);
cairo_stroke(handle.front_cairo);
};
MwLLPixmap MwLLCairoCreatePixmap(struct _MwLLCairo handle, unsigned char* data, int width, int height) {
MwLLPixmap r = malloc(sizeof(*r));
(void)handle;
if(width >= INT16_MAX) width = INT16_MAX;
if(height >= INT16_MAX) height = INT16_MAX;
r->common.width = width;
r->common.height = height;
r->common.raw = malloc(4 * width * height);
memcpy(r->common.raw, data, 4 * width * height);
r->wayland.cs = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
MwLLPixmapUpdate(r);
return r;
}
void MwLLCairoPixmapUpdate(MwLLPixmap r) {
int i;
unsigned char* d;
cairo_surface_flush(r->wayland.cs);
d = cairo_image_surface_get_data(r->wayland.cs);
for(i = 0; i < r->common.width * r->common.height * 4; i += 4) {
MwU32* p = (MwU32*)&d[i];
*p <<= 8;
*p |= r->common.raw[i + 3];
*p <<= 8;
*p |= r->common.raw[i + 0];
*p <<= 8;
*p |= r->common.raw[i + 1];
*p <<= 8;
*p |= r->common.raw[i + 2];
}
cairo_surface_mark_dirty(r->wayland.cs);
}
void MwLLCairoDestroyPixmap(MwLLPixmap pixmap) {
cairo_surface_destroy(pixmap->wayland.cs);
free(pixmap->common.raw);
free(pixmap);
}
void MwLLCairoDrawPixmap(struct _MwLLCairo handle, MwRect* rect, MwLLPixmap pixmap) {
cairo_t* c;
cairo_surface_t* cs;
cairo_t* selected_cairo = handle.selected_cairo ? handle.selected_cairo : handle.front_cairo;
cs = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, rect->width, rect->height);
c = cairo_create(cs);
if(rect->width <= 0 || rect->height <= 0 || pixmap->common.width <= 0 || pixmap->common.height <= 0) return;
if(rect->width >= INT16_MAX) rect->width = INT16_MAX;
if(rect->height >= INT16_MAX) rect->height = INT16_MAX;
cairo_scale(c, (double)rect->width / pixmap->common.width, (double)rect->height / pixmap->common.height);
cairo_set_source_surface(c, pixmap->cairo.cs, 0, 0);
cairo_pattern_set_filter(cairo_get_source(c), CAIRO_FILTER_NEAREST);
cairo_set_operator(handle.front_cairo, CAIRO_OPERATOR_OVER);
cairo_paint(c);
cairo_set_source_surface(selected_cairo, cs, rect->x, rect->y);
cairo_paint(selected_cairo);
cairo_destroy(c);
cairo_surface_destroy(cs);
};
void MwLLCairoFrontSetup(struct _MwLLCairo* cairo, MwU8* data, MwU32 width, MwU32 height) {
if(data) {
cairo->front_cs = cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32, width, height, width * 4);
} else {
cairo->front_cs = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
}
cairo->front_cairo = cairo_create(cairo->front_cs);
}
void MwLLCairoBackSetup(struct _MwLLCairo* cairo, MwU8* data, MwU32 width, MwU32 height) {
if(data) {
cairo->back_cs = cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32, width, height, width * 4);
} else {
cairo->back_cs = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
}
cairo->back_cairo = cairo_create(cairo->back_cs);
}
void MwLLCairoFrontDestroy(struct _MwLLCairo* cairo) {
cairo_destroy(cairo->front_cairo);
cairo_surface_destroy(cairo->front_cs);
};
void MwLLCairoBackDestroy(struct _MwLLCairo* cairo) {
cairo_destroy(cairo->back_cairo);
cairo_surface_destroy(cairo->back_cs);
};
void MwLLCairoDestroy(struct _MwLLCairo handle) {
// MwLLCairoFrontDestroy(&handle);
// MwLLCairoBackDestroy(&handle);
}
static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
MwLL r;
r = malloc(sizeof(*r));
memset(r, 0, sizeof(*r));
MwLLCreateCommon(r);
r->cairo.width = width;
r->cairo.height = height;
r->cairo.x = x;
r->cairo.y = x;
r->cairo.toplevel = !parent;
r->cairo.parent = parent;
MwLLCairoFrontSetup(&r->cairo, NULL, r->cairo.width, r->cairo.height);
MwLLCairoBackSetup(&r->cairo, NULL, r->cairo.width, r->cairo.height);
return r;
}
static void MwLLDestroyImpl(MwLL handle) {
MwLLCairoDestroy(handle->cairo);
free(handle);
}
static void MwLLBeginDrawImpl(MwLL handle) {
handle->cairo.selected_cairo = handle->cairo.front_cairo;
}
static void MwLLEndDrawImpl(MwLL handle) {
}
static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLLColor color) {
MwLLCairoPolygon(handle->cairo, points, points_count, color);
}
static void MwLLLineImpl(MwLL handle, MwPoint* points, MwLLColor color) {
MwLLCairoLine(handle->cairo, points, color);
}
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) {
(void)handle;
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) {
(void)handle;
*x = handle->cairo.x;
*y = handle->cairo.y;
*w = handle->cairo.width;
*h = handle->cairo.height;
}
static void MwLLSetXYImpl(MwLL handle, int x, int y) {
handle->cairo.x = x;
handle->cairo.y = y;
}
static void MwLLSetWHImpl(MwLL handle, int w, int h) {
handle->cairo.width = w;
handle->cairo.height = h;
}
static void MwLLFreeColorImpl(MwLLColor color) {}
static MwBool lmao = MwFALSE;
static int MwLLPendingImpl(MwLL handle) {
lmao = !lmao;
return lmao;
}
static void MwLLNextEventImpl(MwLL handle) {
MwLLDispatch(handle, draw, NULL);
}
static void MwLLSetTitleImpl(MwLL handle, const char* title) {}
static MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, int width, int height) {
return MwLLCairoCreatePixmap(handle->cairo, data, width, height);
}
static void MwLLPixmapUpdateImpl(MwLLPixmap r) {
MwLLCairoPixmapUpdate(r);
}
static void MwLLDestroyPixmapImpl(MwLLPixmap pixmap) {
MwLLCairoPixmapUpdate(pixmap);
}
static void MwLLDrawPixmapImpl(MwLL handle, MwRect* rect, MwLLPixmap pixmap) {
MwLLCairoDrawPixmap(handle->cairo, rect, 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) {}
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) {}
static void MwLLGrabPointerImpl(MwLL handle, int toggle) {}
static void MwLLSetClipboardImpl(MwLL handle, const char* text, int clipboard_type) {}
static void MwLLGetClipboardImpl(MwLL handle, int clipboard_type) {}
static void MwLLMakeToolWindowImpl(MwLL handle) {}
static void MwLLGetCursorCoordImpl(MwLL handle, MwPoint* point) {}
static void MwLLGetScreenSizeImpl(MwLL handle, MwRect* rect) {}
static void MwLLBeginStateChangeImpl(MwLL handle) {}
static void MwLLEndStateChangeImpl(MwLL handle) {}
static void MwLLSetDarkThemeImpl(MwLL handle, int toggle) {}
static MwBool MwLLDoModernImpl(MwLL handle) {
return MwFALSE;
}
static void MwLLRaiseImpl(MwLL handle) {}
static void MwLLClipImpl(MwLL handle, MwRect* rect) {}
static void MwLLSetupDragAndDropImpl(MwLL handle) {}
static int MwLLCairoCallInitImpl(void) {
if(cairo_load_funcs() != 0) {
return 1;
}
return 0;
}
#include "call.c"
CALL(Cairo);

View file

@ -52,8 +52,9 @@
MwLLSetClipboard = MwLLSetClipboardImpl; \
MwLLGetClipboard = MwLLGetClipboardImpl; \
\
MwLLGetCursorCoord = MwLLGetCursorCoordImpl; \
MwLLGetScreenSize = MwLLGetScreenSizeImpl; \
MwLLGetCursorCoord = MwLLGetCursorCoordImpl; \
MwLLGetScreenSize = MwLLGetScreenSizeImpl; \
MwLLSetupDragAndDrop = MwLLSetupDragAndDropImpl; \
\
MwLLSetDarkTheme = MwLLSetDarkThemeImpl; \
MwLLDoModern = MwLLDoModernImpl; \

View file

@ -1,6 +1,5 @@
#include <Mw/Milsko.h>
#include <Threads.h>
#include <QuickDraw.h>
#include "../../external/stb_ds.h"
@ -53,9 +52,6 @@ static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLL
col.green = color->common.green * 0x101;
col.blue = color->common.blue * 0x101;
RGBForeColor(&col);
PenMode(patCopy);
for(i = 0; i < points_count; i++) {
if(i == 0) {
MoveTo(points[i].x, points[i].y);
@ -65,7 +61,11 @@ static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLL
}
ClosePoly();
FillCPoly(p, &qd.ltGray);
PenMode(patCopy);
RGBForeColor(&col);
PaintPoly(p);
KillPoly(p);
EndUpdate(handle->cmacos.window);
@ -132,9 +132,23 @@ static void MwLLNextEventImpl(MwLL handle) {
switch(event.what) {
case updateEvt:
{
}
// MwLLDispatch(handle, draw, NULL);
break;
/*
This is our blocker for getting anything running.
This needs to be called at this point to start drawing anything.
...It locks up and/or crashes the entire system. At least on SheepShaver.
It's not a stack overflow, it's not anything in the drawing functions.
It's *something* else. But because Classic Mac OS development is like
digging up forbidden tombs while stabbing yourself in the eye several times,
I don't know what.
Fun fact: for as much as everyone loves to glaze about AI being the future
of programming, even Claude got confused when I gave up and tried to ask it
for help. Information about Classic Mac OS probably takes up 0.0001% of its
knowledge base; god knows it's hard enough finding information online about
this!
*/
MwLLDispatch(handle, draw, NULL);
} break;
case osEvt:
break;
case mouseUp:
@ -333,6 +347,10 @@ static void MwLLGetCursorCoordImpl(MwLL handle, MwPoint* point) {
static void MwLLGetScreenSizeImpl(MwLL handle, MwRect* rect) {
}
static void MwLLSetupDragAndDropImpl(MwLL handle) {
(void)handle;
}
static void MwLLBeginStateChangeImpl(MwLL handle) {
MwLLShow(handle, 0);
}

View file

@ -1146,6 +1146,10 @@ static void MwLLGetScreenSizeImpl(MwLL handle, MwRect* rect) {
rect->height = [screen frame].size.height;
}
static void MwLLSetupDragAndDropImpl(MwLL handle) {
(void)handle;
}
static void MwLLBeginStateChangeImpl(MwLL handle) {
MwLLShow(handle, 0);
}

View file

@ -1,5 +1,7 @@
#include <Mw/Milsko.h>
#include "../../external/stb_ds.h"
typedef struct userdata {
MwLL ll;
POINT min;
@ -10,8 +12,14 @@ typedef struct userdata {
static struct symtbl {
void* lib_dwmapi;
void* shell32lib;
MwBool has_drag_and_drop;
HRESULT(WINAPI* DwmSetWindowAttribute)(HWND hwnd, DWORD dwAttribute, LPCVOID pvAttribute, DWORD cbAttribute);
UINT(WINAPI* DragQueryFileW)(HDROP hDrop, UINT iFile, LPWSTR lpszFile, UINT cch);
void (*DragAcceptFiles)(HWND hWnd, BOOL fAccept);
void (*DragFinish)(HDROP hDrop);
} wsymtbl;
static int is_plgblt_reliable = 0;
@ -67,7 +75,11 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
if(u == NULL) return DefWindowProc(hWnd, msg, wp, lp);
if(msg == WM_PAINT) {
switch(msg) {
case WM_INITDIALOG:
return TRUE;
case WM_PAINT:
{
PAINTSTRUCT ps;
RECT rc;
HBITMAP hbmp;
@ -98,7 +110,12 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
MwLLDispatch(u->ll, draw, NULL);
EndPaint(hWnd, &ps);
}
} else if(msg == WM_LBUTTONDOWN || msg == WM_MBUTTONDOWN || msg == WM_RBUTTONDOWN) {
break;
}
case WM_LBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_RBUTTONDOWN:
{
MwMouse p;
p.point.x = LOWORD(lp);
p.point.y = HIWORD(lp);
@ -113,7 +130,12 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
SetCapture(hWnd);
SetFocus(hWnd);
MwLLDispatch(u->ll, down, &p);
} else if(msg == WM_LBUTTONUP || msg == WM_MBUTTONUP || msg == WM_RBUTTONUP) {
break;
}
case WM_LBUTTONUP:
case WM_MBUTTONUP:
case WM_RBUTTONUP:
{
MwMouse p;
p.point.x = LOWORD(lp);
p.point.y = HIWORD(lp);
@ -127,7 +149,10 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
SetCapture(NULL);
MwLLDispatch(u->ll, up, &p);
} else if(msg == WM_MOUSEWHEEL) {
break;
}
case WM_MOUSEWHEEL:
{
int d = GET_WHEEL_DELTA_WPARAM(wp);
MwMouse p;
p.point.x = LOWORD(lp);
@ -141,7 +166,31 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
MwLLDispatch(u->ll, down, &p);
MwLLDispatch(u->ll, up, &p);
} else if(msg == WM_MOUSEMOVE) {
break;
}
case WM_DROPFILES:
{
HDROP hDrop = (HDROP)wp;
UINT count;
UINT i;
count = wsymtbl.DragQueryFileW(hDrop, 0xFFFFFFFF, NULL, 0);
for(i = 0; i < count; i++) {
wchar_t wpath[MAX_PATH];
char path[MAX_PATH];
wsymtbl.DragQueryFileW(hDrop, i, wpath, MAX_PATH);
memset(path, 0, sizeof(path));
WideCharToMultiByte(CP_UTF8, 0, wpath, -1, path, sizeof(path) - 1, NULL, NULL);
MwLLDispatch(u->ll, drag_and_drop, path);
}
wsymtbl.DragFinish(hDrop);
break;
}
case WM_MOUSEMOVE:
{
MwPoint p;
p.x = LOWORD(lp);
p.y = HIWORD(lp);
@ -169,19 +218,37 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
SetCursorPos(p.x, p.y);
}
} else if(msg == WM_SIZE) {
break;
}
case WM_SIZE:
{
MwLLDispatch(u->ll, resize, NULL);
} else if(msg == WM_ERASEBKGND) {
break;
}
case WM_ERASEBKGND:
{
return 1;
} else if(msg == WM_NCHITTEST) {
}
case WM_NCHITTEST:
{
LPARAM style = GetWindowLongPtr(hWnd, GWL_STYLE);
if(style & WS_CHILD) return HTCLIENT;
return DefWindowProc(hWnd, msg, wp, lp);
} else if(msg == WM_DESTROY) {
}
case WM_DESTROY:
{
PostQuitMessage(0);
} else if(msg == WM_CLOSE) {
break;
}
case WM_CLOSE:
{
MwLLDispatch(u->ll, close, NULL);
} else if(msg == WM_CHAR || msg == WM_SYSCHAR) {
break;
}
case WM_CHAR:
case WM_SYSCHAR:
{
int n = wp;
const int base = 'A' - 1;
@ -193,24 +260,61 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
if(msg == WM_SYSCHAR) n |= MwKEY_ALT_FLAG;
if((0x20 <= n && n <= 0x7f) || (n & MwKEY_FLAG)) MwLLDispatch(u->ll, key, &n);
} else if(msg == WM_SETFOCUS) {
break;
}
case WM_SETFOCUS:
{
MwLLDispatch(u->ll, focus_in, NULL);
} else if(msg == WM_KILLFOCUS) {
break;
}
case WM_KILLFOCUS:
{
MwLLDispatch(u->ll, focus_out, NULL);
} else if(msg == WM_KEYDOWN || msg == WM_KEYUP || msg == WM_SYSKEYDOWN || msg == WM_SYSKEYUP) {
break;
}
case WM_KEYDOWN:
case WM_KEYUP:
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
{
int n = -1;
if(wp == VK_MENU && msg == WM_KEYUP) return 0;
if(wp == VK_LEFT) n = MwKEY_LEFT;
if(wp == VK_RIGHT) n = MwKEY_RIGHT;
if(wp == VK_UP) n = MwKEY_UP;
if(wp == VK_DOWN) n = MwKEY_DOWN;
if(wp == VK_RETURN) n = MwKEY_ENTER;
if(wp == VK_BACK) n = MwKEY_BACKSPACE;
if(wp == VK_ESCAPE) n = MwKEY_ESCAPE;
if(wp == VK_LSHIFT) n = MwKEY_LEFTSHIFT;
if(wp == VK_RSHIFT) n = MwKEY_RIGHTSHIFT;
if(wp == VK_MENU) n = MwKEY_ALT;
if(wp == VK_CONTROL) n = MwKEY_CONTROL;
switch(wp) {
case VK_LEFT:
n = MwKEY_LEFT;
break;
case VK_RIGHT:
n = MwKEY_RIGHT;
break;
case VK_UP:
n = MwKEY_UP;
break;
case VK_DOWN:
n = MwKEY_DOWN;
break;
case VK_RETURN:
n = MwKEY_ENTER;
break;
case VK_BACK:
n = MwKEY_BACKSPACE;
break;
case VK_ESCAPE:
n = MwKEY_ESCAPE;
break;
case VK_LSHIFT:
n = MwKEY_LEFTSHIFT;
break;
case VK_RSHIFT:
n = MwKEY_RIGHTSHIFT;
break;
case VK_MENU:
n = MwKEY_ALT;
break;
case VK_CONTROL:
n = MwKEY_CONTROL;
break;
}
if((msg == WM_SYSKEYDOWN || msg == WM_SYSKEYUP) && n != -1 && wp != VK_MENU) {
n |= MwKEY_ALT_FLAG;
@ -222,7 +326,10 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
MwLLDispatch(u->ll, key_released, &n);
}
}
} else if(msg == WM_GETMINMAXINFO) {
break;
}
case WM_GETMINMAXINFO:
{
if(u->min_set || u->max_set) {
LPARAM style = GetWindowLongPtr(hWnd, GWL_STYLE);
MINMAXINFO* mmi = (MINMAXINFO*)lp;
@ -253,22 +360,35 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
} else {
return DefWindowProc(hWnd, msg, wp, lp);
}
} else if(msg == WM_SETCURSOR) {
break;
}
case WM_SETCURSOR:
{
if(LOWORD(lp) != HTCLIENT) return DefWindowProc(hWnd, msg, wp, lp);
if(u->ll->gdi.cursor != NULL) SetCursor(u->ll->gdi.cursor);
} else if(msg == WM_USER) {
break;
}
case WM_USER:
{
InvalidateRect(hWnd, NULL, FALSE);
UpdateWindow(hWnd);
} else if(msg == WM_WININICHANGE) {
break;
}
case WM_WININICHANGE:
{
char* s = (char*)lp;
LPARAM style = GetWindowLongPtr(hWnd, GWL_STYLE);
if(!(style & WS_CHILD)) {
if(s != NULL && strcmp(s, "ImmersiveColorSet") == 0) detect_darktheme(u->ll);
}
} else {
break;
}
default:
{
return DefWindowProc(hWnd, msg, wp, lp);
}
}
return 0;
}
@ -277,6 +397,11 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
userdata_t* u = malloc(sizeof(*u));
WNDCLASSEX wc;
if(!r || !u) {
printf("Out Of Memory\n");
return NULL;
}
memset(&wc, 0, sizeof(wc));
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
@ -362,6 +487,11 @@ static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLL
HPEN pen = CreatePen(PS_NULL, 0, RGB(0, 0, 0));
int i;
if(!p) {
printf("Out Of Memory\n");
return;
}
for(i = 0; i < points_count; i++) {
p[i].x = points[i].x;
p[i].y = points[i].y;
@ -396,6 +526,11 @@ static void MwLLLineImpl(MwLL handle, MwPoint* points, MwLLColor color) {
static MwLLColor MwLLAllocColorImpl(MwLL handle, int r, int g, int b) {
MwLLColor c = malloc(sizeof(*c));
if(!c) {
printf("Out Of Memory\n");
return NULL;
}
c->gdi.brush = NULL;
MwLLColorUpdate(handle, c, r, g, b);
@ -404,7 +539,8 @@ static MwLLColor MwLLAllocColorImpl(MwLL handle, int r, int g, int b) {
}
static void MwLLColorUpdateImpl(MwLL handle, MwLLColor c, int r, int g, int b) {
HDC dc = GetDC(handle->gdi.hWnd);
HDC dc = GetDC(handle->gdi.hWnd);
COLORREF color;
if(r > 255) r = 255;
if(g > 255) g = 255;
@ -413,8 +549,10 @@ static void MwLLColorUpdateImpl(MwLL handle, MwLLColor c, int r, int g, int b) {
if(g < 0) g = 0;
if(b < 0) b = 0;
color = GetNearestColor(dc, RGB(r, g, b));
if(c->gdi.brush != NULL) DeleteObject(c->gdi.brush);
c->gdi.brush = CreateSolidBrush(GetNearestColor(dc, RGB(r, g, b)));
c->gdi.brush = CreateSolidBrush(color);
c->common.red = r;
c->common.green = g;
c->common.blue = b;
@ -470,10 +608,20 @@ static void MwLLNextEventImpl(MwLL handle) {
if(handle->gdi.get_clipboard) {
HGLOBAL hg;
if(OpenClipboard(handle->gdi.hWnd) != 0 && (hg = GetClipboardData(CF_TEXT)) != NULL) {
char* txt = malloc(GlobalSize(hg));
int sz = GlobalSize(hg);
char* txt = malloc(sz);
char* clp = GlobalLock(hg);
if(!txt || !clp) {
printf("Out of Memory\n");
return;
}
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
strcpy_s(txt, sz, clp);
#else
strcpy(txt, clp);
#endif
GlobalUnlock(hg);
CloseClipboard();
@ -490,10 +638,11 @@ static void MwLLNextEventImpl(MwLL handle) {
handle->gdi.get_darktheme = 0;
}
while(PeekMessage(&msg, handle->gdi.hWnd, 0, 0, PM_NOREMOVE)) {
GetMessage(&msg, handle->gdi.hWnd, 0, 0);
TranslateMessage(&msg);
DispatchMessage(&msg);
while(PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) {
if(GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
@ -502,7 +651,17 @@ static MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, int wid
HDC dc = GetDC(handle->gdi.hWnd);
BITMAPINFOHEADER bmih;
if(!r) {
printf("Out Of Memory\n");
return NULL;
}
r->common.raw = malloc(width * height * 4);
if(!r->common.raw) {
printf("Out Of Memory\n");
return NULL;
}
memcpy(r->common.raw, data, 4 * width * height);
r->common.width = width;
@ -542,6 +701,12 @@ static void MwLLPixmapUpdateImpl(MwLLPixmap r) {
words = malloc(w * r->common.height);
words2 = malloc(w * r->common.height);
if(!words || !words2) {
printf("Out Of Memory\n");
return;
}
memset(words, 0, w * r->common.height);
memset(words2, 0, w * r->common.height);
for(y = 0; y < r->common.height; y++) {
@ -793,12 +958,30 @@ static void MwLLSetClipboardImpl(MwLL handle, const char* text, int clipboard_ty
(void)clipboard_type;
if(OpenClipboard(handle->gdi.hWnd) != 0) {
char* lock;
int sz = strlen(text) + 1;
EmptyClipboard();
hg = GlobalAlloc(GHND | GMEM_SHARE, strlen(text) + 1);
hg = GlobalAlloc(GHND | GMEM_SHARE, sz);
if(!hg) {
printf("Out of Memory\n");
return;
}
lock = GlobalLock(hg);
if(!lock) {
printf("Out Of Memory\n");
GlobalUnlock(hg);
CloseClipboard();
return;
}
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
strcpy_s(lock, sz, text);
#else
strcpy(lock, text);
#endif
GlobalUnlock(hg);
SetClipboardData(CF_TEXT, hg);
@ -905,6 +1088,10 @@ static void MwLLClipImpl(MwLL handle, MwRect* rect) {
}
}
static void MwLLSetupDragAndDropImpl(MwLL handle) {
wsymtbl.DragAcceptFiles(handle->gdi.hWnd, TRUE);
}
static int MwLLGDICallInitImpl(void) {
void* ntdll;
@ -920,6 +1107,28 @@ static int MwLLGDICallInitImpl(void) {
is_plgblt_reliable = 1;
}
wsymtbl.has_drag_and_drop = MwFALSE;
/* Drag and Drop initialization */
{
if(!(wsymtbl.shell32lib = LoadLibrary("shell32.dll"))) {
goto dnd_error;
};
#define SHELL32_FUNC(x) \
if(!(wsymtbl.x = (void*)GetProcAddress(wsymtbl.shell32lib, #x))) { \
printf(#x "not found, drag and drop will not be supported"); \
goto dnd_error; \
}
SHELL32_FUNC(DragQueryFileW);
SHELL32_FUNC(DragAcceptFiles);
SHELL32_FUNC(DragFinish);
wsymtbl.has_drag_and_drop = MwTRUE;
}
dnd_error:
/* TODO: check properly */
return 0;
}

View file

@ -879,6 +879,10 @@ static void MwLLGetScreenSizeImpl(MwLL handle, MwRect* rect) {
delete screen;
}
static void MwLLSetupDragAndDropImpl(MwLL handle) {
(void)handle;
}
static void MwLLSetDarkThemeImpl(MwLL handle, int toggle) {
(void)handle;
(void)toggle;

View file

@ -4,8 +4,7 @@
void MwLLWaylandFramebufferSetup(struct _MwLLWayland* wayland) {
MwLLWaylandBufferSetup(&wayland->framebuffer, wayland->ww, wayland->wh);
wayland->front_cs = cairo_image_surface_create_for_data(wayland->framebuffer.buf_back, CAIRO_FORMAT_ARGB32, wayland->ww, wayland->wh, 4 * wayland->ww);
wayland->front_cairo = cairo_create(wayland->front_cs);
MwLLCairoFrontSetup(&wayland->cairo, wayland->framebuffer.buf_back, wayland->ww, wayland->wh);
memset(wayland->framebuffer.buf_back, 0, wayland->framebuffer.buf_size);
if(wayland->configured)
@ -16,9 +15,9 @@ void MwLLWaylandFramebufferSetup(struct _MwLLWayland* wayland) {
MwLLWaylandBufferUpdate((MwLL)wayland, &wayland->framebuffer);
};
void MwLLWaylandFramebufferDestroy(struct _MwLLWayland* wayland) {
wl_surface_attach(wayland->framebuffer.surface, NULL, 0, 0);
MwLLWaylandBufferDestroy(&wayland->framebuffer);
cairo_destroy(wayland->front_cairo);
cairo_surface_destroy(wayland->front_cs);
MwLLCairoFrontDestroy(&wayland->cairo);
};
void MwLLWaylandBackbufferSetup(struct _MwLLWayland* wayland) {
@ -27,14 +26,13 @@ void MwLLWaylandBackbufferSetup(struct _MwLLWayland* wayland) {
}
MwU32 w = wayland->ww;
MwU32 h = wayland->wh;
if(!wayland->has_decorations) {
if(!wayland->has_decorations && wayland->do_csd) {
w += (CSD_BORDER_FRAME_LEFT + CSD_BORDER_FRAME_RIGHT);
h += (CSD_BORDER_FRAME_TOP + CSD_BORDER_FRAME_BOTTOM);
}
MwLLWaylandBufferSetup(&wayland->backbuffer, w, h);
wayland->back_cs = cairo_image_surface_create_for_data(wayland->backbuffer.buf_back, CAIRO_FORMAT_ARGB32, w, h, 4 * w);
wayland->back_cairo = cairo_create(wayland->back_cs);
MwLLCairoBackSetup(&wayland->cairo, wayland->backbuffer.buf_back, w, h);
memset(wayland->backbuffer.buf_back, 255, wayland->backbuffer.buf_size);
if(wayland->configured)
@ -44,9 +42,9 @@ void MwLLWaylandBackbufferSetup(struct _MwLLWayland* wayland) {
MwLLWaylandBufferUpdate((MwLL)wayland, &wayland->backbuffer);
};
void MwLLWaylandBackbufferDestroy(struct _MwLLWayland* wayland) {
// wl_surface_attach(wayland->backbuffer.surface, NULL, 0, 0);
MwLLWaylandBufferDestroy(&wayland->backbuffer);
cairo_destroy(wayland->back_cairo);
cairo_surface_destroy(wayland->back_cs);
MwLLCairoBackDestroy(&wayland->cairo);
};
void MwLLWaylandBufferSetup(struct _MwLLWaylandShmBuffer* buffer, MwU32 width, MwU32 height) {

View file

@ -16,6 +16,9 @@
static void setup_clipboard(MwLL self, struct wl_seat* wl_seat);
static void setup_zwp_clipboard(MwLL self, struct wl_seat* wl_seat);
static void destroy_clipboard(MwLL self, struct wl_seat* wl_seat);
static void destroy_zwp_clipboard(MwLL self, struct wl_seat* wl_seat);
/* Recursively dispatch a move event to a widget and its children */
static void recursive_dispatch_move(MwLL handle, MwMouse* p) {
MwWidget h = (MwWidget)handle->common.user;
@ -42,7 +45,7 @@ static void new_protocol(void* data, struct wl_registry* registry,
wayland_protocol_callback_table_t* cb = shget(self->wayland.wl_protocol_setup_map, interface);
if(cb != NULL) {
shput(self->wayland.wl_protocol_map, interface, cb->setup(name, data));
shput(self->wayland.wl_protocol_map, interface, cb->setup(name, data, version));
/* we don't care for adding this protocol, we just use it to know if the compositor will let us have transparent surfaces */
} else if(strcmp(interface, "wp_alpha_modifier_v1") == 0) {
self->common.supports_transparency = MwTRUE;
@ -313,7 +316,8 @@ struct zwp_primary_selection_source_v1_listener zwp_primary_selection_source_v1_
};
/* wl_data_device_manager setup function */
static wayland_protocol_t* wl_data_device_manager_setup(MwU32 name, struct _MwLLWayland* wayland) {
static wayland_protocol_t* wl_data_device_manager_setup(MwU32 name, struct _MwLLWayland* wayland, MwU32 version) {
(void)version;
wayland->clipboard_manager.wl = wl_registry_bind(wayland->registry, name, &wl_data_device_manager_interface, 2);
wayland->clipboard_source.wl = wl_data_device_manager_create_data_source(wayland->clipboard_manager.wl);
@ -346,7 +350,8 @@ static void wl_data_device_manager_interface_destroy(struct _MwLLWayland* waylan
}
/* zwp_primary_selection_device_manager_v1 setup function */
static wayland_protocol_t* zwp_primary_selection_device_manager_v1_setup(MwU32 name, struct _MwLLWayland* wayland) {
static wayland_protocol_t* zwp_primary_selection_device_manager_v1_setup(MwU32 name, struct _MwLLWayland* wayland, MwU32 version) {
(void)version;
wayland->clipboard_manager.zwp = wl_registry_bind(wayland->registry, name, &zwp_primary_selection_device_manager_v1_interface, 1);
wayland->clipboard_source.zwp = zwp_primary_selection_device_manager_v1_create_source(wayland->clipboard_manager.zwp);
@ -374,7 +379,8 @@ static void zwp_primary_selection_device_manager_v1_interface_destroy(struct _Mw
}
/* zwp_primary_selection_device_manager_v1 setup function */
static wayland_protocol_t* zwp_pointer_constraints_v1_setup(MwU32 name, struct _MwLLWayland* wayland) {
static wayland_protocol_t* zwp_pointer_constraints_v1_setup(MwU32 name, struct _MwLLWayland* wayland, MwU32 version) {
(void)version;
wayland->pointer_constraints = wl_registry_bind(wayland->registry, name, &zwp_pointer_constraints_v1_interface, 1);
return NULL;
}
@ -406,6 +412,10 @@ static void pointer_enter(void* data, struct wl_pointer* wl_pointer, MwU32 seria
wl_pointer_set_cursor(self->wayland.pointer, self->wayland.pointer_serial, topmost_parent->wayland.cursor.surface, 0, 0);
}
if(self->wayland.backbuffer.surface == surface) {
curSurface = surface;
}
WAYLAND_EVENT_OP_END(self);
};
@ -421,7 +431,7 @@ static void pointer_leave(void* data, struct wl_pointer* wl_pointer, MwU32 seria
WAYLAND_EVENT_OP_END(self);
};
static void xdg_borderless_step(MwLL self, MwMouse p, MwU32 serial) {
static void xdg_borderless_step_mdown(MwLL self, MwMouse p, MwU32 serial) {
if(self->wayland.type == MwLL_WAYLAND_TOPLEVEL && self->wayland.backbuffer.surface == curSurface) {
if(p.point.y >= (self->wayland.wh + CSD_BORDER_FRAME_TOP + CSD_BORDER_FRAME_BOTTOM) - 5) {
if(p.point.x >= (self->wayland.ww + CSD_BORDER_FRAME_LEFT + CSD_BORDER_FRAME_RIGHT) - 5) {
@ -440,7 +450,33 @@ static void xdg_borderless_step(MwLL self, MwMouse p, MwU32 serial) {
} else if(p.point.x <= 5) {
xdg_toplevel_resize(self->wayland.toplevel->xdg_top_level, self->wayland.pointer_seat, serial, XDG_TOPLEVEL_RESIZE_EDGE_LEFT);
} else if(p.point.y <= CSD_BORDER_FRAME_TOP) {
xdg_toplevel_move(self->wayland.toplevel->xdg_top_level, self->wayland.pointer_seat, serial);
if(p.point.x >= CSD_BORDER_FRAME_LEFT && p.point.x <= CSD_BORDER_FRAME_LEFT + 18) {
} else if(p.point.x >= (self->wayland.ww + CSD_BORDER_FRAME_LEFT + CSD_BORDER_FRAME_RIGHT) - 21) {
} else if(p.point.x >= (self->wayland.ww + CSD_BORDER_FRAME_LEFT + CSD_BORDER_FRAME_RIGHT) - 38) {
} else {
xdg_toplevel_move(self->wayland.toplevel->xdg_top_level, self->wayland.pointer_seat, serial);
}
}
};
}
static void xdg_borderless_step_mup(MwLL self, MwMouse p, MwU32 serial) {
(void)serial;
if(self->wayland.type == MwLL_WAYLAND_TOPLEVEL && self->wayland.backbuffer.surface == curSurface) {
if(p.point.y <= CSD_BORDER_FRAME_TOP) {
if(p.point.x >= CSD_BORDER_FRAME_LEFT && p.point.x <= CSD_BORDER_FRAME_LEFT + 18) {
MwLLDispatch(self, close, NULL);
} else if(p.point.x >= (self->wayland.ww + CSD_BORDER_FRAME_LEFT + CSD_BORDER_FRAME_RIGHT) - 21) {
self->wayland.toplevel->maxim_state = !self->wayland.toplevel->maxim_state;
if(self->wayland.toplevel->maxim_state == 0) {
xdg_toplevel_unset_maximized(self->wayland.toplevel->xdg_top_level);
} else {
xdg_toplevel_set_maximized(self->wayland.toplevel->xdg_top_level);
}
self->wayland.setting_wh = 1;
MwLLWaylandRegionSetup(self);
} else if(p.point.x >= (self->wayland.ww + CSD_BORDER_FRAME_LEFT + CSD_BORDER_FRAME_RIGHT) - 38) {
xdg_toplevel_set_minimized(self->wayland.toplevel->xdg_top_level);
}
}
};
}
@ -478,7 +514,8 @@ struct zwp_relative_pointer_v1_listener MwLLWaylandRelativePointerListener =
relative_pointer_motion};
/* zwp_primary_selection_device_manager_v1 setup function */
static wayland_protocol_t* zwp_relative_pointer_manager_v1_setup(MwU32 name, struct _MwLLWayland* wayland) {
static wayland_protocol_t* zwp_relative_pointer_manager_v1_setup(MwU32 name, struct _MwLLWayland* wayland, MwU32 version) {
(void)version;
wayland->relative_pointer_manager = wl_registry_bind(wayland->registry, name, &zwp_relative_pointer_manager_v1_interface, 1);
return NULL;
}
@ -571,6 +608,9 @@ static void pointer_button(void* data, struct wl_pointer* wl_pointer, MwU32 seri
switch(state) {
case WL_POINTER_BUTTON_STATE_PRESSED:
if(button == BTN_LEFT) {
topmost_parent->wayland.focusedWidget = self;
}
MwLLDispatch(self, down, &p);
topmost_parent->wayland.currentlyHeldWidget = self;
@ -586,8 +626,11 @@ static void pointer_button(void* data, struct wl_pointer* wl_pointer, MwU32 seri
}
}
if(!self->wayland.has_decorations) {
xdg_borderless_step(self, p, serial);
if(!self->wayland.has_decorations && self->wayland.do_csd) {
if(state != WL_POINTER_BUTTON_STATE_RELEASED)
xdg_borderless_step_mdown(self, p, serial);
else
xdg_borderless_step_mup(self, p, serial);
}
WAYLAND_EVENT_OP_END(self);
@ -620,7 +663,7 @@ static void keyboard_keymap(void* data,
MwLL self = data;
(void)wl_keyboard;
if(self->wayland.type == MwLL_WAYLAND_TOPLEVEL) {
if(!self->wayland.parent) {
assert(format == WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1);
char* map_shm = (char*)mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
@ -683,15 +726,18 @@ static void keyboard_leave(void* data,
static void keyboard_key(void* data,
struct wl_keyboard* wl_keyboard,
MwU32 serial,
MwU32 time,
MwU32 _time,
MwU32 key,
MwU32 state) {
MwLL self = data;
MwBool inArea = 0;
MwLL self = data;
MwBool inArea = 0;
MwLL topmost_parent = self;
(void)wl_keyboard;
(void)serial;
(void)time;
(void)_time;
while(topmost_parent->wayland.parent) topmost_parent = topmost_parent->wayland.parent;
WAYLAND_EVENT_OP_START(self);
@ -702,6 +748,9 @@ static void keyboard_key(void* data,
if(self->wayland.backbuffer.surface) {
inArea |= self->wayland.backbuffer.surface == curSurface;
}
inArea |= (self == topmost_parent->wayland.focusedWidget);
if(inArea) {
xkb_layout_index_t layout;
MwU32 levels;
@ -791,9 +840,14 @@ static void keyboard_key(void* data,
MwLLDispatch(topmost_parent, key, &key);
topmost_parent = topmost_parent->wayland.parent;
}
self->wayland.holding_key = MwTRUE;
self->wayland.last_pressed_key = key;
} else {
MwLLDispatch(self, key_released, &key);
self->wayland.holding_key = MwFALSE;
}
self->wayland.start_time = MwTimeGetTick();
self->wayland.next_elapsed = self->wayland.keyboard_delay;
}
}
}
@ -848,12 +902,25 @@ static void setup_clipboard(MwLL self, struct wl_seat* wl_seat) {
arrpush(self->wayland.clipboard_devices_wl, device_ctx_wl);
};
static void keyboard_repeat_info(void* data,
struct wl_keyboard* wl_keyboard,
int32_t rate,
int32_t delay) {
MwLL self = data;
(void)wl_keyboard;
self->wayland.keyboard_rate = rate;
self->wayland.keyboard_delay = delay;
};
struct wl_keyboard_listener keyboard_listener = {
.keymap = keyboard_keymap,
.enter = keyboard_enter,
.leave = keyboard_leave,
.key = keyboard_key,
.modifiers = keyboard_modifiers,
.keymap = keyboard_keymap,
.enter = keyboard_enter,
.leave = keyboard_leave,
.key = keyboard_key,
.modifiers = keyboard_modifiers,
.repeat_info = keyboard_repeat_info,
};
/* `wl_seat.name` callback */
@ -937,14 +1004,15 @@ void xdg_wm_base_ping(void* data,
};
/* wl_seat setup function */
static wayland_protocol_t* wl_seat_setup(MwU32 name, MwLL ll) {
static wayland_protocol_t* wl_seat_setup(MwU32 name, MwLL ll, MwU32 version) {
wayland_protocol_t* proto = malloc(sizeof(wayland_protocol_t));
MwU32 ver = (version >= 4) ? 4 : 1;
proto->listener = malloc(sizeof(struct wl_seat_listener));
((struct wl_seat_listener*)proto->listener)->name = wl_seat_name;
((struct wl_seat_listener*)proto->listener)->capabilities = wl_seat_capabilities;
wl_seat_add_listener(wl_registry_bind(ll->wayland.registry, name, &wl_seat_interface, 1), proto->listener, ll);
wl_seat_add_listener(wl_registry_bind(ll->wayland.registry, name, &wl_seat_interface, ver), proto->listener, ll);
return proto;
}
@ -952,10 +1020,12 @@ static wayland_protocol_t* wl_seat_setup(MwU32 name, MwLL ll) {
static void wl_seat_interface_destroy(struct _MwLLWayland* wayland, wayland_protocol_t* data) {
(void)wayland;
free(data->listener);
free(data);
}
/* wl_output setup function */
static wayland_protocol_t* wl_output_setup(MwU32 name, MwLL ll) {
static wayland_protocol_t* wl_output_setup(MwU32 name, MwLL ll, MwU32 version) {
(void)version;
ll->wayland.output = wl_registry_bind(ll->wayland.registry, name, &wl_output_interface, 1);
wl_output_add_listener(ll->wayland.output, &output_listener, ll);
@ -968,7 +1038,8 @@ static void wl_output_interface_destroy(struct _MwLLWayland* wayland, wayland_pr
}
/* wl_compositor setup function */
static wayland_protocol_t* wl_compositor_setup(MwU32 name, struct _MwLLWayland* wayland) {
static wayland_protocol_t* wl_compositor_setup(MwU32 name, struct _MwLLWayland* wayland, MwU32 version) {
(void)version;
wayland->compositor = wl_registry_bind(wayland->registry, name, &wl_compositor_interface, 1);
return NULL;
@ -980,7 +1051,8 @@ static void wl_compositor_interface_destroy(struct _MwLLWayland* wayland, waylan
}
/* wl_subcompositor setup function */
static wayland_protocol_t* wl_subcompositor_setup(MwU32 name, struct _MwLLWayland* wayland) {
static wayland_protocol_t* wl_subcompositor_setup(MwU32 name, struct _MwLLWayland* wayland, MwU32 version) {
(void)version;
if(wayland->type == MwLL_WAYLAND_TOPLEVEL) {
wayland->toplevel->scompositor = wl_registry_bind(wayland->registry, name, &wl_subcompositor_interface, 1);
} else {
@ -992,13 +1064,18 @@ static wayland_protocol_t* wl_subcompositor_setup(MwU32 name, struct _MwLLWaylan
static void wl_subcompositor_interface_destroy(struct _MwLLWayland* wayland, wayland_protocol_t* data) {
(void)data;
wl_subcompositor_destroy(wayland->sublevel->subcompositor);
if(wayland->type == MwLL_WAYLAND_TOPLEVEL) {
wl_subcompositor_destroy(wayland->toplevel->scompositor);
} else {
wl_subcompositor_destroy(wayland->sublevel->subcompositor);
}
}
/* xdg_wm_base setup function */
static wayland_protocol_t* xdg_wm_base_setup(MwU32 name, struct _MwLLWayland* wayland) {
static wayland_protocol_t* xdg_wm_base_setup(MwU32 name, struct _MwLLWayland* wayland, MwU32 version) {
wayland_protocol_t* proto = malloc(sizeof(wayland_protocol_t));
proto->listener = malloc(sizeof(struct xdg_wm_base_listener));
(void)version;
proto->listener = malloc(sizeof(struct xdg_wm_base_listener));
((struct xdg_wm_base_listener*)proto->listener)->ping = xdg_wm_base_ping;
@ -1011,12 +1088,14 @@ static wayland_protocol_t* xdg_wm_base_setup(MwU32 name, struct _MwLLWayland* wa
static void xdg_wm_base_interface_destroy(struct _MwLLWayland* wayland, wayland_protocol_t* data) {
(void)wayland;
free(data->listener);
free(data);
}
/* xdg_wm_base setup function */
static wayland_protocol_t* wp_viewporter_setup(MwU32 name, struct _MwLLWayland* wayland) {
static wayland_protocol_t* wp_viewporter_setup(MwU32 name, struct _MwLLWayland* wayland, MwU32 version) {
wayland_protocol_t* proto = malloc(sizeof(wayland_protocol_t));
proto->context = wl_registry_bind(wayland->registry, name, &wp_viewporter_interface, 1);
(void)version;
proto->context = wl_registry_bind(wayland->registry, name, &wp_viewporter_interface, 1);
return proto;
}
@ -1027,10 +1106,11 @@ static void wp_viewporter_interface_destroy(struct _MwLLWayland* wayland, waylan
}
/* zxdg_decoration_manager_v1 setup function */
static wayland_protocol_t* zxdg_decoration_manager_v1_setup(MwU32 name, struct _MwLLWayland* wayland) {
static wayland_protocol_t* zxdg_decoration_manager_v1_setup(MwU32 name, struct _MwLLWayland* wayland, MwU32 version) {
wayland_protocol_t* proto = malloc(sizeof(wayland_protocol_t));
zxdg_decoration_manager_v1_context_t* ctx = malloc(sizeof(zxdg_decoration_manager_v1_context_t));
proto->listener = NULL;
(void)version;
proto->listener = NULL;
ctx->manager = wl_registry_bind(wayland->registry, name, &zxdg_decoration_manager_v1_interface, 1);
;
@ -1046,7 +1126,8 @@ static void zxdg_decoration_manager_v1_interface_destroy(struct _MwLLWayland* wa
}
/* wl_shm setup function */
static wayland_protocol_t* wl_shm_setup(MwU32 name, struct _MwLLWayland* wayland) {
static wayland_protocol_t* wl_shm_setup(MwU32 name, struct _MwLLWayland* wayland, MwU32 version) {
(void)version;
wayland->framebuffer.shm = wl_registry_bind(wayland->registry, name, &wl_shm_interface, 1);
wayland->backbuffer.shm = wl_registry_bind(wayland->registry, name, &wl_shm_interface, 1);
wayland->cursor.shm = wl_registry_bind(wayland->registry, name, &wl_shm_interface, 1);
@ -1059,9 +1140,11 @@ static void wl_shm_interface_destroy(struct _MwLLWayland* wayland, wayland_proto
(void)data;
}
static wayland_protocol_t* xdg_toplevel_icon_manager_v1_setup(MwU32 name, struct _MwLLWayland* wayland) {
static wayland_protocol_t* xdg_toplevel_icon_manager_v1_setup(MwU32 name, struct _MwLLWayland* wayland, MwU32 version) {
wayland_protocol_t* proto = malloc(sizeof(wayland_protocol_t));
(void)version;
proto->context = wl_registry_bind(wayland->registry, name, &xdg_toplevel_icon_manager_v1_interface, 1);
proto->listener = NULL;
@ -1071,6 +1154,22 @@ static wayland_protocol_t* xdg_toplevel_icon_manager_v1_setup(MwU32 name, struct
static void xdg_toplevel_icon_manager_v1_interface_destroy(struct _MwLLWayland* wayland, wayland_protocol_t* data) {
(void)wayland;
free(data->listener);
free(data);
}
static wayland_protocol_t* zwlr_layer_shell_v1_setup(MwU32 name, struct _MwLLWayland* wayland, MwU32 version) {
wayland_protocol_t* proto = malloc(sizeof(wayland_protocol_t));
proto->context = wl_registry_bind(wayland->registry, name, &zwlr_layer_shell_v1_interface, version);
proto->listener = NULL;
return proto;
}
static void zwlr_layer_shell_v1_interface_destroy(struct _MwLLWayland* wayland, wayland_protocol_t* data) {
(void)wayland;
free(data);
}
/* Function for setting up the callbacks/structs that will be registered upon the relevant interfaces being found. */
@ -1086,8 +1185,16 @@ void MwLLWaylandSetupCallbacks(struct _MwLLWayland* wayland) {
wayland->registry_listener.global = new_protocol;
wayland->registry_listener.global_remove = protocol_removed;
wayland->wl_protocol_setup_map = NULL;
wayland->wl_protocol_map = NULL;
if(wayland->wl_protocol_map) {
shfree(wayland->wl_protocol_map);
}
if(wayland->wl_protocol_setup_map) {
shfree(wayland->wl_protocol_setup_map);
}
wayland->wl_protocol_setup_map = NULL;
wayland->wl_protocol_map = NULL;
sh_new_arena(wayland->wl_protocol_map);
sh_new_arena(wayland->wl_protocol_setup_map);
@ -1101,12 +1208,16 @@ void MwLLWaylandSetupCallbacks(struct _MwLLWayland* wayland) {
WL_INTERFACE(zwp_pointer_constraints_v1);
WL_INTERFACE(zwp_relative_pointer_manager_v1);
WL_INTERFACE(xdg_wm_base);
WL_INTERFACE(zwlr_layer_shell_v1); /* Only used for layer surface, but we use it always if it's turned into a tool window */
if(wayland->type == MwLL_WAYLAND_TOPLEVEL) {
WL_INTERFACE(wp_viewporter);
WL_INTERFACE(zxdg_decoration_manager_v1);
WL_INTERFACE(xdg_toplevel_icon_manager_v1);
WL_INTERFACE(wl_subcompositor);
} else if(wayland->type == MwLL_WAYLAND_POPUP) {
} else if(wayland->type == MwLL_WAYLAND_LAYER_SURFACE) {
WL_INTERFACE(wp_viewporter);
WL_INTERFACE(wl_subcompositor);
} else {
WL_INTERFACE(wl_subcompositor);
}

View file

@ -7,10 +7,13 @@ void MwLLWaylandRegionInvalidate(MwLL handle) {
wl_region_subtract(handle->wayland.region, 0, 0, handle->wayland.ww, handle->wayland.wh);
}
void MwLLWaylandRegionSetup(MwLL handle) {
MwLL parent = handle->wayland.parent;
int width = (handle->wayland.clipping_rect.width == 0) ? handle->wayland.ww : handle->wayland.clipping_rect.width;
int height = (handle->wayland.clipping_rect.height == 0) ? handle->wayland.wh : handle->wayland.clipping_rect.height;
int width = (handle->wayland.clipping_rect.width == 0) ? handle->wayland.ww : handle->wayland.clipping_rect.width;
int height = (handle->wayland.clipping_rect.height == 0) ? handle->wayland.wh : handle->wayland.clipping_rect.height;
if(!handle->wayland.has_decorations && handle->wayland.do_csd && handle->wayland.type == MwLL_WAYLAND_TOPLEVEL) {
width += CSD_BORDER_FRAME_LEFT + CSD_BORDER_FRAME_RIGHT;
height += CSD_BORDER_FRAME_TOP + CSD_BORDER_FRAME_BOTTOM;
}
if(!handle->wayland.configured) {
return;
}

File diff suppressed because it is too large Load diff

View file

@ -1361,6 +1361,10 @@ static void MwLLGetScreenSizeImpl(MwLL handle, MwRect* rect) {
rect->height = xwa.height;
}
static void MwLLSetupDragAndDropImpl(MwLL handle) {
(void)handle;
}
static void MwLLBeginStateChangeImpl(MwLL handle) {
MwLLShow(handle, 0);
}

File diff suppressed because it is too large Load diff

View file

@ -6,6 +6,8 @@
#define PERIODIC
#endif
#define RESIZE_ON_TICK
#define DRAW(handle) \
{ \
MwLLBeginDraw(handle->lowlevel); \
@ -18,7 +20,17 @@
MwLLEndDraw(handle->lowlevel); \
}
static void MWAPI MwVaListApply_Internal(MwWidget handle, va_list va, int only_early);
#define RESIZE(handle) \
{ \
int RESIZE_i; \
MwDispatchUserHandler(handle, MwNresizeHandler, NULL); \
for(RESIZE_i = 0; RESIZE_i < arrlen(handle->children); RESIZE_i++) { \
MwDispatch(handle->children[RESIZE_i], parent_resize); \
} \
MwDispatch(handle, resize); \
}
static void MWAPI MwVaListApply_Internal(MwWidget handle, va_list va, int only_early);
static MwWidget MWAPI MwCreateWidget_Internal(MwClass widget_class, const char* name, MwWidget parent, int x, int y, unsigned int width, unsigned int height, int do_prop, va_list prop);
static void lldrawhandler(MwLL handle, void* data) {
@ -57,6 +69,7 @@ static void lldrawhandler(MwLL handle, void* data) {
static void lluphandler(MwLL handle, void* data) {
MwWidget h = (MwWidget)handle->common.user;
MwMouse* p = data;
if(MwGetInteger(h, MwNdisabled) == 1) return;
if(p->button == MwMOUSE_LEFT) h->pressed = 0;
h->mouse_point.x = p->point.x;
@ -70,6 +83,7 @@ static void lluphandler(MwLL handle, void* data) {
static void lldownhandler(MwLL handle, void* data) {
MwWidget h = (MwWidget)handle->common.user;
MwMouse* p = data;
if(MwGetInteger(h, MwNdisabled) == 1) return;
if(p->button == MwMOUSE_LEFT) h->pressed = 1;
h->mouse_point.x = p->point.x;
@ -81,16 +95,35 @@ static void lldownhandler(MwLL handle, void* data) {
static void llresizehandler(MwLL handle, void* data) {
MwWidget h = (MwWidget)handle->common.user;
int i;
#ifdef RESIZE_ON_TICK
MwWidget top;
#endif
(void)data;
MwDispatchUserHandler(h, MwNresizeHandler, NULL);
for(i = 0; i < arrlen(h->children); i++) {
MwDispatch(h->children[i], parent_resize);
MwDispatch(h->children[i], draw);
#ifdef RESIZE_ON_TICK
top = h;
while(top != NULL) {
if(top->top_step) {
break;
}
top = top->parent;
}
MwDispatch(h, resize);
if(top == NULL) {
RESIZE(h); /* fallback */
} else {
int i;
for(i = 0; i < arrlen(top->resize_queue); i++) {
if(top->resize_queue[i] == h) break;
}
if(i == arrlen(top->resize_queue)) arrput(top->resize_queue, h);
}
#else
RESIZE(h);
#endif
}
static void llclosehandler(MwLL handle, void* data) {
@ -112,8 +145,9 @@ static void llclosehandler(MwLL handle, void* data) {
}
static void llmovehandler(MwLL handle, void* data) {
MwWidget h = (MwWidget)handle->common.user;
MwPoint* p = data;
MwWidget h = (MwWidget)handle->common.user;
MwPoint* p = data;
h->mouse_point.x = p->x;
h->mouse_point.y = p->y;
@ -124,6 +158,7 @@ static void llmovehandler(MwLL handle, void* data) {
static void llkeyhandler(MwLL handle, void* data) {
MwWidget h = (MwWidget)handle->common.user;
int key = *(int*)data;
if(MwGetInteger(h, MwNdisabled) == 1) return;
MwDispatch3(h, key, key);
MwDispatchUserHandler(h, MwNkeyHandler, data);
@ -131,29 +166,40 @@ static void llkeyhandler(MwLL handle, void* data) {
static void llkeyrelhandler(MwLL handle, void* data) {
MwWidget h = (MwWidget)handle->common.user;
if(MwGetInteger(h, MwNdisabled) == 1) return;
MwDispatchUserHandler(h, MwNkeyReleaseHandler, data);
}
static void llfocusinhandler(MwLL handle, void* data) {
MwWidget h = (MwWidget)handle->common.user;
if(MwGetInteger(h, MwNdisabled) == 1) return;
MwDispatchUserHandler(h, MwNfocusInHandler, data);
}
static void llfocusouthandler(MwLL handle, void* data) {
MwWidget h = (MwWidget)handle->common.user;
if(MwGetInteger(h, MwNdisabled) == 1) return;
MwDispatchUserHandler(h, MwNfocusOutHandler, data);
}
static void llclipboardhandler(MwLL handle, void* data) {
MwWidget h = (MwWidget)handle->common.user;
if(MwGetInteger(h, MwNdisabled) == 1) return;
MwDispatch3(h, clipboard, data);
MwDispatchUserHandler(h, MwNclipboardHandler, data);
}
static void lldraganddrophandler(MwLL handle, void* data) {
MwWidget h = (MwWidget)handle->common.user;
if(MwGetInteger(h, MwNdisabled) == 1) return;
MwDispatchUserHandler(h, MwNdragAndDropHandler, data);
}
/* if both of them are true
* 1. widget class is not NULL
* 2. parent is NULL
@ -187,14 +233,19 @@ static void lldarkthemehandler(MwLL handle, void* data) {
static MwWidget MwCreateWidget_Internal(MwClass widget_class, const char* name, MwWidget parent, int x, int y, unsigned int width, unsigned int height, int do_prop, va_list prop) {
MwWidget h = malloc(sizeof(*h));
h->name = MwStringDuplicate(name);
if(name)
h->name = MwStringDuplicate(name);
else
h->name = NULL;
h->parent = parent;
h->children = NULL;
if(widget_class != NULL) {
if((h->lowlevel = MwLLCreate(parent == NULL ? NULL : parent->lowlevel, x, y, width, height)) == NULL) {
free(h->name);
if(h->name) {
free(h->name);
}
free(h);
return NULL;
}
@ -219,27 +270,30 @@ static MwWidget MwCreateWidget_Internal(MwClass widget_class, const char* name,
h->opaque = NULL;
h->user = NULL;
h->top_step = 0;
h->draw_queue = NULL;
h->top_step = 0;
h->draw_queue = NULL;
h->resize_queue = NULL;
h->monitored_entries = NULL;
if(parent == NULL) arrput(h->tick_list, h);
if(parent == NULL) h->top_step = 1;
if(h->lowlevel != NULL) {
h->lowlevel->common.user = h;
h->lowlevel->common.handler->draw = lldrawhandler;
h->lowlevel->common.handler->up = lluphandler;
h->lowlevel->common.handler->down = lldownhandler;
h->lowlevel->common.handler->resize = llresizehandler;
h->lowlevel->common.handler->close = llclosehandler;
h->lowlevel->common.handler->move = llmovehandler;
h->lowlevel->common.handler->key = llkeyhandler;
h->lowlevel->common.handler->key_released = llkeyrelhandler;
h->lowlevel->common.handler->focus_in = llfocusinhandler;
h->lowlevel->common.handler->focus_out = llfocusouthandler;
h->lowlevel->common.handler->clipboard = llclipboardhandler;
h->lowlevel->common.handler->dark_theme = lldarkthemehandler;
h->lowlevel->common.user = h;
h->lowlevel->common.handler->draw = lldrawhandler;
h->lowlevel->common.handler->up = lluphandler;
h->lowlevel->common.handler->down = lldownhandler;
h->lowlevel->common.handler->resize = llresizehandler;
h->lowlevel->common.handler->close = llclosehandler;
h->lowlevel->common.handler->move = llmovehandler;
h->lowlevel->common.handler->key = llkeyhandler;
h->lowlevel->common.handler->key_released = llkeyrelhandler;
h->lowlevel->common.handler->focus_in = llfocusinhandler;
h->lowlevel->common.handler->focus_out = llfocusouthandler;
h->lowlevel->common.handler->clipboard = llclipboardhandler;
h->lowlevel->common.handler->dark_theme = lldarkthemehandler;
h->lowlevel->common.handler->drag_and_drop = lldraganddrophandler;
}
if(parent != NULL) arrput(parent->children, h);
@ -271,12 +325,21 @@ static MwWidget MwCreateWidget_Internal(MwClass widget_class, const char* name,
MwAddTickList(h);
}
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2)
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2) || defined(USE_GDI_TEXT)
if(IsFirstVisible(h)) {
#ifdef USE_STB_TRUETYPE
font_setup:
#endif
h->root_font = MwFontLoad(MwTTFData, MwTTFDataSize);
h->root_boldfont = MwFontLoad(MwBoldTTFData, MwBoldTTFDataSize);
h->root_monofont = MwFontLoad(MwMonospaceTTFData, MwMonospaceTTFDataSize);
h->root_boldmonofont = MwFontLoad(MwBoldMonospaceTTFData, MwBoldMonospaceTTFDataSize);
if(!h->root_font) {
#ifdef USE_STB_TRUETYPE
MwFL_STBTTSetup();
goto font_setup;
#endif
}
} else
#endif
{
@ -365,7 +428,7 @@ void MwFreeWidget(MwWidget handle) {
}
}
free(handle->name);
if(handle->name) free(handle->name);
if(handle->lowlevel != NULL) MwLLDestroy(handle->lowlevel);
@ -386,6 +449,7 @@ void MwFreeWidget(MwWidget handle) {
arrfree(handle->tick_list);
arrfree(handle->draw_queue);
arrfree(handle->resize_queue);
if(handle->root_font != NULL) MwFontFree(handle->root_font);
if(handle->root_boldfont != NULL) MwFontFree(handle->root_boldfont);
@ -465,7 +529,17 @@ static void MwAfterStep(MwWidget handle) {
}
#endif
if(arrlen(handle->tick_list) > 0 && (MwTimeGetTick() - handle->last_tick) >= MwWaitMS) {
#ifdef RESIZE_ON_TICK
if(handle->top_step) {
for(i = 0; i < arrlen(handle->resize_queue); i++) {
RESIZE(handle->resize_queue[i]);
}
arrfree(handle->resize_queue);
}
#endif
if(arrlen(handle->tick_list) > 0 && (MwTimeGetTick() - handle->last_tick) >= (MwGetInteger(handle, MwNwaitMS) == MwDEFAULT ? MwWaitMS : MwGetInteger(handle, MwNwaitMS))) {
for(i = 0; i < arrlen(handle->tick_list); i++) {
MwDispatch(handle->tick_list[i], tick);
MwDispatchUserHandler(handle->tick_list[i], MwNtickHandler, NULL);
@ -499,6 +573,7 @@ int MwStep(MwWidget handle) {
MwFreeWidget(handle);
return 1;
}
return 0;
}
@ -507,7 +582,7 @@ int MwPending(MwWidget handle) {
for(i = 0; i < arrlen(handle->children); i++) {
if(MwPending(handle->children[i])) return 1;
}
return (arrlen(handle->tick_list) > 0 && (MwTimeGetTick() - handle->last_tick) >= MwWaitMS) || (arrlen(handle->destroy_queue) > 0) || (handle->widget_class == NULL ? 0 : MwLLPending(handle->lowlevel));
return (arrlen(handle->tick_list) > 0 && (MwTimeGetTick() - handle->last_tick) >= (MwGetInteger(handle, MwNwaitMS) == MwDEFAULT ? MwWaitMS : MwGetInteger(handle, MwNwaitMS))) || (arrlen(handle->destroy_queue) > 0) || (handle->widget_class == NULL ? 0 : MwLLPending(handle->lowlevel));
}
void MwLoop(MwWidget handle) {
@ -571,8 +646,12 @@ void MwSetInteger(MwWidget handle, const char* key, int n) {
arrfree(keys);
MwDispatch3(handle, prop_change, key);
}
if(handle->parent != NULL && handle->parent->prop_event) {
if(handle->parent != NULL) MwDispatch4(handle->parent, children_prop_change, handle, key);
}
if(strcmp(key, MwNforceInverted) == 0) {
MwForceRender(handle);
}
@ -591,6 +670,10 @@ void MwSetInteger(MwWidget handle, const char* key, int n) {
if(h->lowlevel != NULL) MwLLSetDarkTheme(h->lowlevel, n);
}
if(strcmp(key, MwNacceptsDnD) == 0) {
if(handle->lowlevel != NULL) MwLLSetupDragAndDrop(handle->lowlevel);
}
}
void MwSetText(MwWidget handle, const char* key, const char* value) {
@ -616,8 +699,12 @@ void MwSetText(MwWidget handle, const char* key, const char* value) {
arrfree(keys);
MwDispatch3(handle, prop_change, key);
}
if(handle->parent != NULL && handle->parent->prop_event) {
if(handle->parent != NULL) MwDispatch4(handle->parent, children_prop_change, handle, key);
}
if(strcmp(key, MwNbackground) == 0 || strcmp(key, MwNforeground) == 0 || strcmp(key, MwNsubBackground) == 0 || strcmp(key, MwNsubForeground) == 0) {
MwForceRender(handle);
}
@ -644,6 +731,9 @@ void MwSetVoid(MwWidget handle, const char* key, void* value) {
arrfree(keys);
MwDispatch3(handle, prop_change, key);
}
if(handle->parent != NULL && handle->parent->prop_event) {
if(handle->parent != NULL) MwDispatch4(handle->parent, children_prop_change, handle, key);
}
}
@ -671,7 +761,7 @@ int MwGetInteger(MwWidget handle, const char* key) {
return MwDEFAULT;
} else {
if(shgeti(handle->integer, key) == -1) {
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2)
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2) || defined(USE_GDI_TEXT)
if(strcmp(key, MwNbitmapFont) == 0) return inherit_integer(handle, key, 0);
#else
if(strcmp(key, MwNbitmapFont) == 0) return inherit_integer(handle, key, 1);
@ -683,6 +773,7 @@ int MwGetInteger(MwWidget handle, const char* key) {
#endif
if(strcmp(key, MwNdarkTheme) == 0) return inherit_integer(handle, key, 0);
if(strcmp(key, MwNuseMonospace) == 0) return inherit_integer(handle, key, 0);
if(strcmp(key, MwNdisabled) == 0) return inherit_integer(handle, key, 0);
}
return shget(handle->integer, key);
}
@ -721,7 +812,7 @@ const char* MwGetText(MwWidget handle, const char* key) {
return shget(handle->text, key);
}
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2)
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2) || defined(USE_GDI_TEXT)
static void* inherit_void(MwWidget handle, const char* key) {
void* v;
@ -737,7 +828,7 @@ void* MwGetVoid(MwWidget handle, const char* key) {
if(v != NULL) return v;
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2)
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2) || defined(USE_GDI_TEXT)
if(strcmp(key, MwNfont) == 0 || strcmp(key, MwNboldFont) == 0 || strcmp(key, MwNmonospaceFont) == 0 || strcmp(key, MwNboldMonospaceFont) == 0) {
v = inherit_void(handle, key);
@ -978,7 +1069,7 @@ typedef int (*call_t)(void);
int MwLibraryInit(void) {
call_t calls[] = {
#ifdef USE_WAYLAND
MwLLWaylandCallInit,
NULL, /* set in a bit */
#endif
#ifdef USE_X11
MwLLX11CallInit,
@ -998,6 +1089,29 @@ int MwLibraryInit(void) {
NULL};
int i;
#ifdef _WIN32
/*
There's no Windows configuration that Milsko supports that doesn't have winmm.
However, uhh, Visual Studio 2022. For some fucking reason.
Thanks for coming to my TED Talk.
*/
MwLL_winmmLib = LoadLibrary("winmm.dll");
MwLL_PFN_timeGetTime = (void *)GetProcAddress(MwLL_winmmLib, "timeGetTime");
MwLL_PFN_timeBeginPeriod = (void *)GetProcAddress(MwLL_winmmLib, "timeBeginPeriod");
MwLL_PFN_timeBeginPeriod(10);
#endif
#ifdef USE_WAYLAND
if(MwWaylandCairoOnly) {
calls[0] = MwLLCairoCallInit;
} else {
calls[0] = MwLLWaylandCallInit;
}
#endif
MwColorTableInit();
MwFLSetup();
for(i = 0; calls[i] != NULL; i++) {
@ -1055,8 +1169,10 @@ void MwReparent(MwWidget handle, MwWidget new_parent) {
if(new_parent == NULL) {
handle->top_step = 1;
arrput(handle->tick_list, handle);
} else {
handle->top_step = 0;
arrfree(handle->tick_list);
}
MwForceRender(handle);

View file

@ -110,9 +110,9 @@ static void color_picker_image_update(color_picker_t* picker) {
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] = (unsigned char)dist;
picker->color_picker_image_data[i + 1] = (unsigned char)dist;
picker->color_picker_image_data[i + 2] = (unsigned char)dist;
picker->color_picker_image_data[i + 3] = 255;
} else {
MwHSV hsv_v;
@ -121,26 +121,26 @@ static void color_picker_image_update(color_picker_t* picker) {
double xd = (M_PI / 180.) * ((double)_x);
double yd = (M_PI / 180.) * ((double)_y);
float angle = atan2(yd, xd) - M_PI;
float hue = (angle * 180.) / M_PI;
double angle = atan2(yd, xd) - M_PI;
double hue = (angle * 180.) / M_PI;
if(hue < 0.0) {
hue += 360;
}
hsv_v.h = (hue) * (HSV_HUE_STEPS / 360.);
hsv_v.s = (dist) * (HSV_SAT_MAX / 180.);
hsv_v.h = (MwU8)((hue) * (HSV_HUE_STEPS / 360.));
hsv_v.s = (MwU8)((dist) * (HSV_SAT_MAX / 180.));
picker->hue_table[n] = hsv_v;
picker->hue_table[n].generated = 1;
}
hsv_v = picker->hue_table[n];
hsv_v.v = HSV_VAL_MAX - (picker->value * HSV_VAL_MAX);
hsv_v.v = (MwU8)(HSV_VAL_MAX - (picker->value * HSV_VAL_MAX));
hsv2rgb(hsv_v.h, hsv_v.s, hsv_v.v, &color.red, &color.green, &color.blue);
picker->color_picker_image_data[i] = color.red;
picker->color_picker_image_data[i + 1] = color.green;
picker->color_picker_image_data[i + 2] = color.blue;
picker->color_picker_image_data[i] = (unsigned char)color.red;
picker->color_picker_image_data[i + 1] = (unsigned char)color.green;
picker->color_picker_image_data[i + 2] = (unsigned char)color.blue;
picker->color_picker_image_data[i + 3] = 255;
n++;

View file

@ -68,9 +68,9 @@ MwWidget MwMessageBox(MwWidget handle, const char* text, const char* title, unsi
if(flag & MwMB_BUTTONYES) spawn_button(window, w - (x += 8 + 80), h - 8 - 24, MwMB_BUTTONYES, "Yes");
if((flag & MwMB_ICONMASK) != 0) {
MwWidget icon;
MwLLPixmap px;
unsigned int* data = NULL;
MwWidget icon;
MwLLPixmap px;
MwU32* data = NULL;
icon = MwCreateWidget(MwImageClass, "image", window, 8, (h - 48) / 2, 48, 48);

View file

@ -38,6 +38,21 @@ static int hex(const char* txt, int len) {
return r;
}
static void color_set_disabled_if_disabled(MwWidget handle, MwLLColor rgb) {
if(MwGetInteger(handle, MwNdisabled) == 1) {
MwLLColor c = handle->parent == NULL ? NULL : MwParseColor(handle->parent, MwGetText(handle->parent, MwNbackground));
if(c != NULL) {
rgb->common.red = (MwU8)(rgb->common.red + (c->common.red - rgb->common.red) * 0.5);
rgb->common.green = (MwU8)(rgb->common.green + (c->common.green - rgb->common.green) * 0.5);
rgb->common.blue = (MwU8)(rgb->common.blue + (c->common.blue - rgb->common.blue) * 0.5);
MwLLColorUpdate(handle->lowlevel, rgb, rgb->common.red, rgb->common.green, rgb->common.blue);
MwLLFreeColor(c);
}
}
};
void MwParseColorNoAllocate(const char* text, MwRGB* rgb) {
if(text[0] == '#' && strlen(text) == 4) {
rgb->red = hex(text + 1, 1);
@ -109,8 +124,11 @@ void MwDrawRectFading(MwWidget handle, MwRect* rect, MwLLColor color) {
int ColorDiff = get_color_diff(handle);
double darkenStep = (ColorDiff / 2.) / rect->height;
unsigned long sz = 1 * rect->height * 4;
unsigned char* data = malloc(sz);
unsigned char* data = malloc(sz*2);
MwRect r = *rect;
if(!data) {
return;
}
if(rect->width <= 0 || rect->height <= 0) {
free(data);
return;
@ -123,8 +141,9 @@ void MwDrawRectFading(MwWidget handle, MwRect* rect, MwLLColor color) {
r.height -= 2;
for(y = 0; y < rect->height; y++) {
MwLLColor col = MwLightenColor(handle, color, -darken, -darken, -darken);
MwLLColor col = MwLightenColor(handle, color, (int)-darken, (int)-darken, (int)-darken);
int idx = y * 4;
color_set_disabled_if_disabled(handle, col);
data[idx] = col->common.red;
data[idx + 1] = col->common.green;
data[idx + 2] = col->common.blue;
@ -203,13 +222,15 @@ void MwDrawWidgetBack(MwWidget handle, MwRect* rect, MwLLColor color, int invert
if(rect->width <= 0 || rect->height <= 0) return;
col = invert ? MwLightenColor(handle, color, -8, -8, -8) : color;
col = invert ? MwLightenColor(handle, color, -8, -8, -8) : MwLightenColor(handle, color, 0, 0, 0);
color_set_disabled_if_disabled(handle, col);
if(MwGetInteger(handle, MwNmodernLook)) {
MwDrawRectFading(handle, rect, col);
} else {
MwDrawRect(handle, rect, col);
}
if(col != color) MwLLFreeColor(col);
MwLLFreeColor(col);
}
void MwDrawDiamond(MwWidget handle, MwRect* rect, MwLLColor color, int invert) {
@ -218,7 +239,10 @@ void MwDrawDiamond(MwWidget handle, MwRect* rect, MwLLColor color, int invert) {
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;
MwLLColor col = invert ? MwLightenColor(handle, color, -8, -8, -8) : MwLightenColor(handle, color, 0, 0, 0);
color_set_disabled_if_disabled(handle, col);
color_set_disabled_if_disabled(handle, darker);
color_set_disabled_if_disabled(handle, lighter);
p[0].x = rect->x;
p[0].y = rect->y + rect->height / 2;
@ -274,7 +298,7 @@ void MwDrawDiamond(MwWidget handle, MwRect* rect, MwLLColor color, int invert) {
MwLLPolygon(handle->lowlevel, p, 4, col);
if(col != color) MwLLFreeColor(col);
MwLLFreeColor(col);
MwLLFreeColor(lighter);
MwLLFreeColor(darker);
}
@ -284,8 +308,11 @@ static void MwDrawFrameEx_simple(MwWidget handle, MwRect* rect, MwLLColor color,
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;
color_set_disabled_if_disabled(handle, darker);
color_set_disabled_if_disabled(handle, lighter);
p[0].x = rect->x;
p[0].y = rect->y;
p[1].x = rect->x + rect->width;
p[1].y = rect->y;
@ -380,6 +407,9 @@ static void MwDrawFrameEx_complex(MwWidget handle, MwRect* rect, MwLLColor color
MwLLColor lighter = same ? MwLightenColor(handle, darker, 0, 0, 0) : MwLightenColor(handle, color, (ColorDiff / 2) - diff, (ColorDiff / 2) - diff, (ColorDiff / 2) - diff);
MwRect r = *rect;
color_set_disabled_if_disabled(handle, darker);
color_set_disabled_if_disabled(handle, lighter);
frame_border_complex(handle, rect, lighter, darker, invert, border == 1 ? 1 : (border / 2), diff, same);
if(border > 1) {
@ -415,11 +445,14 @@ void MwDrawTriangle(MwWidget handle, MwRect* rect, MwLLColor color, int invert,
int ColorDiff = get_color_diff(handle);
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;
MwLLColor col = invert ? MwLightenColor(handle, color, -8, -8, -8) : MwLightenColor(handle, color, 0, 0, 0);
double deg = 30 * ((direction == MwEAST || direction == MwWEST) ? 2 : 1);
double c = cos(deg / 180 * M_PI);
double s = sin(deg / 180 * M_PI);
double deg = 30 * ((direction == MwEAST || direction == MwWEST) ? 2 : 1);
double c = cos(deg / 180 * M_PI);
double s = sin(deg / 180 * M_PI);
color_set_disabled_if_disabled(handle, col);
color_set_disabled_if_disabled(handle, darker);
color_set_disabled_if_disabled(handle, lighter);
if(direction == MwNORTH) {
p1[0].x = rect->x + rect->width / 2;
@ -428,11 +461,11 @@ void MwDrawTriangle(MwWidget handle, MwRect* rect, MwLLColor color, int invert,
p1[1].x = rect->x;
p1[1].y = rect->y + rect->height;
p1[2].x = rect->x + c * border;
p1[2].y = rect->y + rect->height - s * border;
p1[2].x = (int)(rect->x + c * border);
p1[2].y = (int)(rect->y + rect->height - s * border);
p1[3].x = rect->x + rect->width / 2;
p1[3].y = rect->y + border;
p1[3].y = (int)(rect->y + border);
p2[0].x = rect->x + rect->width / 2;
p2[0].y = rect->y;
@ -440,14 +473,14 @@ void MwDrawTriangle(MwWidget handle, MwRect* rect, MwLLColor color, int invert,
p2[1].x = rect->x + rect->width;
p2[1].y = rect->y + rect->height;
p2[2].x = rect->x + rect->width - c * border;
p2[2].y = rect->y + rect->height - s * border;
p2[2].x = (int)(rect->x + rect->width - c * border);
p2[2].y = (int)(rect->y + rect->height - s * border);
p2[3].x = rect->x + rect->width / 2;
p2[3].y = rect->y + border;
p2[3].y = (int)(rect->y + border);
p3[0].x = rect->x + c * border;
p3[0].y = rect->y + rect->height - s * border;
p3[0].x = (int)(rect->x + c * border);
p3[0].y = (int)(rect->y + rect->height - s * border);
p3[1].x = rect->x;
p3[1].y = rect->y + rect->height;
@ -455,30 +488,30 @@ void MwDrawTriangle(MwWidget handle, MwRect* rect, MwLLColor color, int invert,
p3[2].x = rect->x + rect->width;
p3[2].y = rect->y + rect->height;
p3[3].x = rect->x + rect->width - c * border;
p3[3].y = rect->y + rect->height - s * border;
p3[3].x = (int)(rect->x + rect->width - c * border);
p3[3].y = (int)(rect->y + rect->height - s * border);
MwLLPolygon(handle->lowlevel, p1, 4, invert ? darker : lighter);
MwLLPolygon(handle->lowlevel, p2, 4, invert ? lighter : darker);
MwLLPolygon(handle->lowlevel, p3, 4, invert ? lighter : darker);
p4[0].x = rect->x + c * border;
p4[0].y = rect->y + rect->height - s * border;
p4[0].x = (int)(rect->x + c * border);
p4[0].y = (int)(rect->y + rect->height - s * border);
p4[1].x = rect->x + rect->width - c * border;
p4[1].y = rect->y + rect->height - s * border;
p4[1].x = (int)(rect->x + rect->width - c * border);
p4[1].y = (int)(rect->y + rect->height - s * border);
p4[2].x = rect->x + rect->width / 2;
p4[2].y = rect->y + border;
p4[2].y = (int)(rect->y + border);
} else if(direction == MwSOUTH) {
p1[0].x = rect->x;
p1[0].y = rect->y;
p1[1].x = rect->x + c * border;
p1[1].y = rect->y + s * border;
p1[1].x = (int)(rect->x + c * border);
p1[1].y = (int)(rect->y + s * border);
p1[2].x = rect->x + rect->width - c * border;
p1[2].y = rect->y + s * border;
p1[2].x = (int)(rect->x + rect->width - c * border);
p1[2].y = (int)(rect->y + s * border);
p1[3].x = rect->x + rect->width;
p1[3].y = rect->y;
@ -486,11 +519,11 @@ void MwDrawTriangle(MwWidget handle, MwRect* rect, MwLLColor color, int invert,
p2[0].x = rect->x;
p2[0].y = rect->y;
p2[1].x = rect->x + c * border;
p2[1].y = rect->y + s * border;
p2[1].x = (int)(rect->x + c * border);
p2[1].y = (int)(rect->y + s * border);
p2[2].x = rect->x + rect->width / 2;
p2[2].y = rect->y + rect->height - border;
p2[2].y = (int)(rect->y + rect->height - border);
p2[3].x = rect->x + rect->width / 2;
p2[3].y = rect->y + rect->height;
@ -502,32 +535,32 @@ void MwDrawTriangle(MwWidget handle, MwRect* rect, MwLLColor color, int invert,
p3[1].y = rect->y + rect->height;
p3[2].x = rect->x + rect->width / 2;
p3[2].y = rect->y + rect->height - border;
p3[2].y = (int)(rect->y + rect->height - border);
p3[3].x = rect->x + rect->width - c * border;
p3[3].y = rect->y + s * border;
p3[3].x = (int)(rect->x + rect->width - c * border);
p3[3].y = (int)(rect->y + s * border);
MwLLPolygon(handle->lowlevel, p1, 4, invert ? darker : lighter);
MwLLPolygon(handle->lowlevel, p2, 4, invert ? darker : lighter);
MwLLPolygon(handle->lowlevel, p3, 4, invert ? lighter : darker);
p4[0].x = rect->x + c * border;
p4[0].y = rect->y + s * border;
p4[0].x = (int)(rect->x + c * border);
p4[0].y = (int)(rect->y + s * border);
p4[1].x = rect->x + rect->width - c * border;
p4[1].y = rect->y + s * border;
p4[1].x = (int)(rect->x + rect->width - c * border);
p4[1].y = (int)(rect->y + s * border);
p4[2].x = rect->x + rect->width / 2;
p4[2].y = rect->y + rect->height - border;
p4[2].y = (int)(rect->y + rect->height - border);
} else if(direction == MwEAST) {
p1[0].x = rect->x;
p1[0].y = rect->y;
p1[1].x = rect->x + c * border;
p1[1].y = rect->y + s * border;
p1[1].x = (int)(rect->x + c * border);
p1[1].y = (int)(rect->y + s * border);
p1[2].x = rect->x + c * border;
p1[2].y = rect->y + rect->height - s * border;
p1[2].x = (int)(rect->x + c * border);
p1[2].y = (int)(rect->y + rect->height - s * border);
p1[3].x = rect->x;
p1[3].y = rect->y + rect->height;
@ -538,14 +571,14 @@ void MwDrawTriangle(MwWidget handle, MwRect* rect, MwLLColor color, int invert,
p2[1].x = rect->x + rect->width;
p2[1].y = rect->y + rect->height / 2;
p2[2].x = rect->x + rect->width - border;
p2[2].x = (int)(rect->x + rect->width - border);
p2[2].y = rect->y + rect->height / 2;
p2[3].x = rect->x + c * border;
p2[3].y = rect->y + s * border;
p2[3].x = (int)(rect->x + c * border);
p2[3].y = (int)(rect->y + s * border);
p3[0].x = rect->x + c * border;
p3[0].y = rect->y + rect->height - s * border;
p3[0].x = (int)(rect->x + c * border);
p3[0].y = (int)(rect->y + rect->height - s * border);
p3[1].x = rect->x;
p3[1].y = rect->y + rect->height;
@ -553,30 +586,30 @@ void MwDrawTriangle(MwWidget handle, MwRect* rect, MwLLColor color, int invert,
p3[2].x = rect->x + rect->width;
p3[2].y = rect->y + rect->height / 2;
p3[3].x = rect->x + rect->width - border;
p3[3].x = (int)(rect->x + rect->width - border);
p3[3].y = rect->y + rect->height / 2;
MwLLPolygon(handle->lowlevel, p1, 4, invert ? darker : lighter);
MwLLPolygon(handle->lowlevel, p2, 4, invert ? darker : lighter);
MwLLPolygon(handle->lowlevel, p3, 4, invert ? lighter : darker);
p4[0].x = rect->x + rect->width - border;
p4[0].x = (int)(rect->x + rect->width - border);
p4[0].y = rect->y + rect->height / 2;
p4[1].x = rect->x + c * border;
p4[1].y = rect->y + rect->height - s * border;
p4[1].x = (int)(rect->x + c * border);
p4[1].y = (int)(rect->y + rect->height - s * border);
p4[2].x = rect->x + c * border;
p4[2].y = rect->y + s * border;
p4[2].x = (int)(rect->x + c * border);
p4[2].y = (int)(rect->y + s * border);
} else if(direction == MwWEST) {
p1[0].x = rect->x;
p1[0].y = rect->y + rect->height / 2;
p1[1].x = rect->x + border;
p1[1].x = (int)(rect->x + border);
p1[1].y = rect->y + rect->height / 2;
p1[2].x = rect->x + rect->width - c * border;
p1[2].y = rect->y + s * border;
p1[2].x = (int)(rect->x + rect->width - c * border);
p1[2].y = (int)(rect->y + s * border);
p1[3].x = rect->x + rect->width;
p1[3].y = rect->y;
@ -584,11 +617,11 @@ void MwDrawTriangle(MwWidget handle, MwRect* rect, MwLLColor color, int invert,
p2[0].x = rect->x;
p2[0].y = rect->y + rect->height / 2;
p2[1].x = rect->x + border;
p2[1].x = (int)(rect->x + border);
p2[1].y = rect->y + rect->height / 2;
p2[2].x = rect->x + rect->width - c * border;
p2[2].y = rect->y + rect->height - s * border;
p2[2].x = (int)(rect->x + rect->width - c * border);
p2[2].y = (int)(rect->y + rect->height - s * border);
p2[3].x = rect->x + rect->width;
p2[3].y = rect->y + rect->height;
@ -596,11 +629,11 @@ void MwDrawTriangle(MwWidget handle, MwRect* rect, MwLLColor color, int invert,
p3[0].x = rect->x + rect->width;
p3[0].y = rect->y;
p3[1].x = rect->x + rect->width - c * border;
p3[1].y = rect->y + s * border;
p3[1].x = (int)(rect->x + rect->width - c * border);
p3[1].y = (int)(rect->y + s * border);
p3[2].x = rect->x + rect->width - c * border;
p3[2].y = rect->y + rect->height - s * border;
p3[2].x = (int)(rect->x + rect->width - c * border);
p3[2].y = (int)(rect->y + rect->height - s * border);
p3[3].x = rect->x + rect->width;
p3[3].y = rect->y + rect->height;
@ -609,19 +642,18 @@ void MwDrawTriangle(MwWidget handle, MwRect* rect, MwLLColor color, int invert,
MwLLPolygon(handle->lowlevel, p2, 4, invert ? lighter : darker);
MwLLPolygon(handle->lowlevel, p3, 4, invert ? lighter : darker);
p4[0].x = rect->x + border;
p4[0].x = (int)(rect->x + border);
p4[0].y = rect->y + rect->height / 2;
p4[1].x = rect->x + rect->width - c * border;
p4[1].y = rect->y + rect->height - s * border;
p4[1].x = (int)(rect->x + rect->width - c * border);
p4[1].y = (int)(rect->y + rect->height - s * border);
p4[2].x = rect->x + rect->width - c * border;
p4[2].y = rect->y + s * border;
p4[2].x = (int)(rect->x + rect->width - c * border);
p4[2].y = (int)(rect->y + s * border);
}
MwLLPolygon(handle->lowlevel, p4, 3, col);
if(color != col) MwLLFreeColor(col);
MwLLFreeColor(col);
MwLLFreeColor(lighter);
MwLLFreeColor(darker);
}
@ -801,13 +833,13 @@ void MwPixmapReloadRaw(MwLLPixmap px, unsigned char* rgb) {
a /= 255;
if(a != 0) {
pout[0] = pin[0] * a;
pout[1] = pin[1] * a;
pout[2] = pin[2] * a;
pout[0] = (unsigned char)(pin[0] * a);
pout[1] = (unsigned char)(pin[1] * a);
pout[2] = (unsigned char)(pin[2] * a);
pout[0] += base->common.red * (1 - a);
pout[1] += base->common.green * (1 - a);
pout[2] += base->common.blue * (1 - a);
pout[0] += (unsigned char)(base->common.red * (1 - a));
pout[1] += (unsigned char)(base->common.green * (1 - a));
pout[2] += (unsigned char)(base->common.blue * (1 - a));
pout[3] = 255;
}
}
@ -839,6 +871,11 @@ MwLLPixmap MwLoadIcon(MwWidget handle, MwU32* data) {
MwLLPixmap px;
int i;
if(!rgba) {
printf("Null malloc! out of memory?\n");
return NULL;
}
memset(rgba, 0, width * height * 4);
for(i = 0; i < width * height; i++) {
@ -876,7 +913,11 @@ MwLLPixmap MwLoadXPM(MwWidget handle, char** data) {
sh_new_strdup(c);
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
sscanf_s(data[0], "%d %d %d %d", &col, &row, &colors, &cpp);
#else
sscanf(data[0], "%d %d %d %d", &col, &row, &colors, &cpp);
#endif
for(i = 0; i < colors; i++) {
char k[128];
@ -913,6 +954,10 @@ MwLLPixmap MwLoadXPM(MwWidget handle, char** data) {
rgb = malloc(row * col * 4);
comp = malloc(cpp + 1);
if(!rgb || !comp) {
printf("Null malloc! Out of memory?");
return NULL;
}
comp[cpp] = 0;
for(y = 0; y < row; y++) {
for(x = 0; x < col; x++) {

View file

@ -1,5 +1,11 @@
#include <Mw/Milsko.h>
#ifdef _WIN32
void *MwLL_winmmLib;
long (__stdcall* MwLL_PFN_timeGetTime)(void);
unsigned int (__stdcall* MwLL_PFN_timeBeginPeriod)(unsigned int period);
#endif
MwLL (*MwLLCreate)(MwLL parent, int x, int y, int width, int height) = NULL;
void (*MwLLDestroy)(MwLL handle) = NULL;
@ -50,8 +56,8 @@ 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 (*MwLLSetupDragAndDrop)(MwLL handle) = NULL;
void (*MwLLSetDarkTheme)(MwLL handle, int toggle) = NULL;
MwBool (*MwLLDoModern)(MwLL handle) = NULL;

View file

@ -1,21 +1,53 @@
#include <Mw/Milsko.h>
char* MwStringDuplicate(const char* str) {
char* r = malloc(strlen(str) + 1);
int sz = strlen(str) + 1;
char* r = malloc(sz);
if(!r) {
printf("Out Of Memory\n");
return NULL;
}
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
strcpy_s(r, sz, str);
#else
strcpy(r, str);
#endif
return r;
}
char* MwStringConcat(const char* str1, const char* str2) {
char* r = malloc(strlen(str1) + strlen(str2) + 1);
int sz = strlen(str1) + strlen(str2) + 1;
char* r = malloc(sz);
if(!r) {
printf("Out Of Memory\n");
return NULL;
}
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
strcpy_s(r, sz, str1);
strcat_s(r, sz, str2);
#else
strcpy(r, str1);
strcat(r, str2);
#endif
return r;
}
void MwStringSize(char* out, MwOffset size) {
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
if(size / 1024 == 0) {
sprintf_s(out, 255, "%d", (int)size);
} else if(size / 1024 / 1024 == 0) {
sprintf_s(out, 255, "%.1fK", (double)size / 1024);
} else if(size / 1024 / 1024 / 1024 == 0) {
sprintf_s(out, 255, "%.1fM", (double)size / 1024 / 1024);
} else {
sprintf_s(out, 255, "%.1fG", (double)size / 1024 / 1024 / 1024);
}
#else
if(size / 1024 == 0) {
sprintf(out, "%d", (int)size);
} else if(size / 1024 / 1024 == 0) {
@ -25,16 +57,28 @@ void MwStringSize(char* out, MwOffset size) {
} else {
sprintf(out, "%.1fG", (double)size / 1024 / 1024 / 1024);
}
#endif
}
void MwStringTime(char* out, time_t t) {
struct tm* tm = localtime(&t);
const char* months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
if(tm == NULL) {
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
sprintf_s(out, 255, "localtime error");
#else
sprintf(out, "localtime error");
#endif
} else {
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
sprintf_s(out, 255, "%s %2d %02d:%02d %d", months[tm->tm_mon], tm->tm_mday, tm->tm_hour, tm->tm_min, 1900 + tm->tm_year);
#else
sprintf(out, "%s %2d %02d:%02d %d", months[tm->tm_mon], tm->tm_mday, tm->tm_hour, tm->tm_min, 1900 + tm->tm_year);
#endif
}
}
void MwStringPrintIntoBuffer(char* out, MwU32 size, const char* fmt, ...) {
@ -43,6 +87,9 @@ void MwStringPrintIntoBuffer(char* out, MwU32 size, const char* fmt, ...) {
#if __STDC_VERSION__ >= 199901L
vsnprintf(out, size, fmt, va);
/* MSVC2022 reports the STDC_VERSION as fucking 1994. Thanks Bill Gates. */
#elif defined(_MSC_VER) && (_MSC_VER >= 1400)
vsprintf_s(out, size, fmt, va);
#else
vsprintf(out, fmt, va);
#endif

View file

@ -1,6 +1,6 @@
#include <Mw/Milsko.h>
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2)
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2) || defined(USE_GDI_TEXT)
unsigned char MwBoldMonospaceTTFData[] = {
0x00, 0x01, 0x00, 0x00, 0x00, 0x11, 0x01, 0x00, 0x00, 0x04, 0x00, 0x10,
0x46, 0x46, 0x54, 0x4d, 0xac, 0x0d, 0xe4, 0x44, 0x00, 0x00, 0x8d, 0x3c,

View file

@ -1,6 +1,6 @@
#include <Mw/Milsko.h>
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2)
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2) || defined(USE_GDI_TEXT)
unsigned char MwBoldTTFData[] = {
0x00, 0x01, 0x00, 0x00, 0x00, 0x12, 0x01, 0x00, 0x00, 0x04, 0x00, 0x20,
0x46, 0x46, 0x54, 0x4d, 0x94, 0x9f, 0x60, 0x18, 0x00, 0x00, 0x8e, 0xa8,

View file

@ -1,6 +1,6 @@
#include <Mw/Milsko.h>
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2)
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2) || defined(USE_GDI_TEXT)
unsigned char MwMonospaceTTFData[] = {
0x00, 0x01, 0x00, 0x00, 0x00, 0x11, 0x01, 0x00, 0x00, 0x04, 0x00, 0x10,
0x46, 0x46, 0x54, 0x4d, 0xac, 0x0d, 0xe4, 0x23, 0x00, 0x00, 0x8d, 0x3c,

View file

@ -1,6 +1,6 @@
#include <Mw/Milsko.h>
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2)
#if defined(USE_STB_TRUETYPE) || defined(USE_FREETYPE2) || defined(USE_GDI_TEXT)
unsigned char MwTTFData[] = {
0x00, 0x01, 0x00, 0x00, 0x00, 0x12, 0x01, 0x00, 0x00, 0x04, 0x00, 0x20,
0x46, 0x46, 0x54, 0x4d, 0x94, 0x92, 0x79, 0xd4, 0x00, 0x00, 0x89, 0xa4,

View file

@ -159,7 +159,7 @@ static void ft2_MwFontFree(void* handle) {
free(ttf);
}
int MWFL_FT2Setup(void) {
int MwFL_FT2Setup(void) {
/* Try and load FreeType2. If it fails, return 1, signifying we default to stbtt. */
void* ftlib;
#ifdef __APPLE__

268
src/text/gdi.c Normal file
View file

@ -0,0 +1,268 @@
#ifdef USE_GDI_TEXT
#include <Mw/Milsko.h>
static HANDLE(WINAPI* _AddFontMemResourceEx)(PVOID pFileView, DWORD cjSize, PVOID pvResrved, DWORD* pNumFonts) = NULL;
static BOOL(WINAPI* _RemoveFontMemResourceEx)(HANDLE h) = NULL;
static HANDLE WINAPI _AddFontMemResourceExPolyFill(PVOID pFileView, DWORD cjSize, PVOID pvResrved, DWORD* pNumFonts);
static BOOL WINAPI _RemoveFontMemResourceExPolyFill(HANDLE h);
struct _MwFLFont {
HANDLE handle;
HFONT font;
HDC dc;
};
static int GDI_MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text, MwLLColor color) {
BITMAPINFOHEADER bmih;
int tw;
int th;
HBITMAP hbm;
RGBQUAD* bits = NULL;
HDC hmdc;
char* t = MwUTF8ToACP(text);
unsigned char* px;
int y, x;
MwRect r;
MwLLPixmap p;
tw = MwTextWidth(handle, ttf, text);
th = MwTextHeight(handle, ttf, text);
if(handle->lowlevel->common.type == MwLLBackendGDI) {
HFONT old_font = SelectObject(handle->lowlevel->gdi.hDC, ttf->font);
int old_bkmode = SetBkMode(handle->lowlevel->gdi.hDC, TRANSPARENT);
COLORREF old_color = SetTextColor(handle->lowlevel->gdi.hDC, RGB(color->common.red, color->common.green, color->common.blue));
TextOut(handle->lowlevel->gdi.hDC, point->x, point->y - th / 2, t, strlen(t));
SetTextColor(handle->lowlevel->gdi.hDC, old_color);
SetBkMode(handle->lowlevel->gdi.hDC, old_bkmode);
SelectObject(handle->lowlevel->gdi.hDC, old_font);
free(t);
return 0;
}
px = malloc(tw * th * 4);
bmih.biSize = sizeof(bmih);
bmih.biWidth = tw;
bmih.biHeight = -(LONG)th;
bmih.biPlanes = 1;
bmih.biBitCount = 32;
bmih.biCompression = BI_RGB;
bmih.biSizeImage = 0;
bmih.biXPelsPerMeter = 0;
bmih.biYPelsPerMeter = 0;
bmih.biClrUsed = 0;
bmih.biClrImportant = 0;
hbm = CreateDIBSection(ttf->dc, (BITMAPINFO*)&bmih, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
hmdc = CreateCompatibleDC(ttf->dc);
SelectObject(hmdc, hbm);
SelectObject(hmdc, ttf->font);
TextOut(hmdc, 0, 0, t, strlen(t));
DeleteDC(hmdc);
for(y = 0; y < th; y++) {
for(x = 0; x < tw; x++) {
unsigned char* opx = &px[(y * tw + x) * 4];
opx[0] = color->common.red;
opx[1] = color->common.green;
opx[2] = color->common.blue;
opx[3] = 255 - bits[y * tw + x].rgbRed;
}
}
p = MwLoadRaw(handle, px, tw, th);
r.x = point->x;
r.y = point->y - th / 2;
r.width = tw;
r.height = th;
MwLLDrawPixmap(handle->lowlevel, &r, p);
MwLLDestroyPixmap(p);
free(px);
DeleteObject(hbm);
free(t);
return 0;
}
static int GDI_MwTextWidth(MwFLFont ttf, const char* text) {
char* t = MwUTF8ToACP(text);
SIZE sz;
GetTextExtentPoint32(ttf->dc, t, strlen(t), &sz);
free(t);
return sz.cx;
}
static int GDI_MwTextHeight(MwFLFont ttf, int count) {
TEXTMETRIC tm;
GetTextMetrics(ttf->dc, &tm);
return tm.tmHeight * count;
}
static void* GDI_MwFontLoad(unsigned char* data, unsigned int size, int px) {
MwFLFont ttf = malloc(sizeof(*ttf));
DWORD c;
MwTTFInfo info;
if((info = MwTTFGetInfo(data, size)) == NULL) {
free(ttf);
return NULL;
}
ttf->dc = GetDC(NULL);
ttf->handle = NULL;
if(_AddFontMemResourceEx) {
if((ttf->handle = _AddFontMemResourceEx(data, size, 0, &c)) == NULL) {
ReleaseDC(NULL, ttf->dc);
MwTTFFreeInfo(info);
free(ttf);
return NULL;
}
} /*else {
if((ttf->handle = _AddFontMemResourceExPolyFill(data, size, 0, &c)) == NULL) {
ReleaseDC(NULL, ttf->dc);
MwTTFFreeInfo(info);
free(ttf);
return NULL;
}
}*/
if((ttf->font = CreateFont(-px, 0, 0, 0, info->weight, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, ttf->handle ? info->family : "Sans Serif")) == NULL) {
if(_RemoveFontMemResourceEx) {
_RemoveFontMemResourceEx(ttf->handle);
} else {
_RemoveFontMemResourceExPolyFill(ttf->handle);
}
ReleaseDC(NULL, ttf->dc);
MwTTFFreeInfo(info);
free(ttf);
return NULL;
}
MwTTFFreeInfo(info);
SelectObject(ttf->dc, ttf->font);
return ttf;
}
static void GDI_MwFontFree(void* handle) {
MwFLFont ttf = handle;
DeleteObject(ttf->font);
if(_RemoveFontMemResourceEx) {
_RemoveFontMemResourceEx(ttf->handle);
} else {
_RemoveFontMemResourceExPolyFill(ttf->handle);
}
ReleaseDC(NULL, ttf->dc);
free(ttf);
}
static HANDLE WINAPI _AddFontMemResourceExPolyFill(PVOID pFileView, DWORD cjSize, PVOID pvResrved, DWORD* pNumFonts) {
CHAR temp_path_dir[MAX_PATH];
CHAR temp_path_name[MAX_PATH];
HANDLE tempFile = NULL;
DWORD hr;
(void)pvResrved;
hr = GetTempPathA(MAX_PATH, temp_path_dir);
if(hr == 0) {
printf("GetTempPathA error %08lX\n", hr);
return NULL;
}
hr = GetTempFileNameA(temp_path_dir, TEXT("MILSKO"), 0, temp_path_name);
if(hr == 0) {
printf("GetTempFileNameA error %08lX\n", hr);
return NULL;
}
printf("extracting mem font to %s\n", temp_path_name);
tempFile = CreateFileA(temp_path_name,
GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE,
NULL);
if(tempFile == INVALID_HANDLE_VALUE) {
DWORD err = GetLastError();
if(err == ERROR_ALREADY_EXISTS) {
tempFile = CreateFileA(temp_path_name,
GENERIC_WRITE,
0,
NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE,
NULL);
if(tempFile != INVALID_HANDLE_VALUE) {
goto success;
} else {
err = GetLastError();
}
}
printf("CreateFileA error %08lX\n", err);
return NULL;
}
success:
hr = WriteFile(tempFile, pFileView, cjSize, NULL, NULL);
if(hr != 0) {
printf("WriteFile error %08lX\n", hr);
return NULL;
}
*pNumFonts = AddFontResource(temp_path_name);
return tempFile;
};
static BOOL WINAPI _RemoveFontMemResourceExPolyFill(HANDLE h) {
if(h)
CloseHandle(h);
return TRUE;
};
int MwFL_GDISetup(void) {
void* gdilib = LoadLibrary("gdi32.dll");
if(!gdilib) {
printf("gdi32.dll not found(what)\n");
} else {
_AddFontMemResourceEx = (void*)GetProcAddress(gdilib, "AddFontMemResourceEx");
if(!_AddFontMemResourceEx) {
_AddFontMemResourceEx = _AddFontMemResourceExPolyFill;
}
_RemoveFontMemResourceEx = (void*)GetProcAddress(gdilib, "RemoveFontMemResourceEx");
if(!_RemoveFontMemResourceEx) {
_RemoveFontMemResourceEx = _RemoveFontMemResourceExPolyFill;
}
}
MwFLDrawText = GDI_MwDrawText;
MwFLTextWidth = GDI_MwTextWidth;
MwFLTextHeight = GDI_MwTextHeight;
MwFLFontLoad = GDI_MwFontLoad;
MwFLFontFree = GDI_MwFontFree;
return 0;
}
#endif

View file

@ -3,10 +3,11 @@
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;
int (*MwFLTextHeightWithText)(MwFLFont ttf, const char* text) = 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)
#if defined(USE_FREETYPE2) || defined(USE_STB_TRUETYPE) || defined(USE_GDI_TEXT)
#define TTF
#endif
@ -76,10 +77,25 @@ static MwFLFont assume_ttf(MwWidget handle, MwFLFont ttf) {
#endif
void MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text, int align, MwLLColor color) {
MwPoint p = *point;
char* input = (char*)text;
char* last = input;
int cp;
MwPoint p = *point;
char* input = (char*)text;
char* last = input;
int cp;
MwLLColor fadedColor = NULL;
if(MwGetInteger(handle, MwNdisabled) == 1) {
MwLLColor c = handle->parent == NULL ? NULL : MwParseColor(handle->parent, MwGetText(handle->parent, MwNbackground));
if(c != NULL) {
fadedColor = MwLLAllocColor(handle->lowlevel, color->common.red, color->common.blue, color->common.green);
fadedColor->common.red = (MwU8)(fadedColor->common.red + (c->common.red - fadedColor->common.red) * 0.5);
fadedColor->common.green = (MwU8)(fadedColor->common.green + (c->common.green - fadedColor->common.green) * 0.5);
fadedColor->common.blue = (MwU8)(fadedColor->common.blue + (c->common.blue - fadedColor->common.blue) * 0.5);
MwLLColorUpdate(handle->lowlevel, fadedColor, fadedColor->common.red, fadedColor->common.green, fadedColor->common.blue);
MwLLFreeColor(c);
}
}
#ifdef TTF
if(ttf <= MwFLBuildFont(0xff) && !is_bitmap(handle, ttf)) ttf = assume_ttf(handle, ttf);
@ -94,6 +110,11 @@ void MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text,
char* line = malloc(input - last + 1);
int i;
if(!line) {
printf("Out Of Memory\n");
return;
}
memcpy(line, last, input - last);
line[input - last] = 0;
@ -122,9 +143,9 @@ void MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text,
#ifdef TTF
if(MwFLDrawText)
if(is_bitmap(handle, ttf) || ttf == NULL || MwFLDrawText(handle, ttf, &p, line, color))
if(is_bitmap(handle, ttf) || ttf == NULL || MwFLDrawText(handle, ttf, &p, line, fadedColor ? fadedColor : color))
#endif
bitmap_MwDrawText(handle, &p, line, is_bold(handle, ttf), color);
bitmap_MwDrawText(handle, &p, line, is_bold(handle, ttf), fadedColor ? fadedColor : color);
p.y += MwTextHeight(handle, ttf, line);
@ -133,6 +154,10 @@ void MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text,
last = input;
}
}
if(fadedColor) {
MwLLFreeColor(fadedColor);
}
}
int MwTextWidth(MwWidget handle, MwFLFont ttf, const char* text) {
@ -157,6 +182,11 @@ int MwTextWidth(MwWidget handle, MwFLFont ttf, const char* text) {
char* line = malloc(input - last + 1);
int i;
if(!line) {
printf("Out Of Memory\n");
return 1;
}
memcpy(line, last, input - last);
line[input - last] = 0;
@ -202,6 +232,8 @@ int MwTextHeight(MwWidget handle, MwFLFont ttf, const char* text) {
#ifdef TTF
if(MwFLTextHeight)
if(!MwGetInteger(handle, MwNbitmapFont) && ttf != NULL && (st = MwFLTextHeight(ttf, c)) != -1) return st;
if(MwFLTextHeightWithText)
if(!MwGetInteger(handle, MwNbitmapFont) && ttf != NULL && (st = MwFLTextHeightWithText(ttf, text)) != -1) return st;
#endif
return FontHeight * c;
}
@ -228,6 +260,11 @@ static void bitmap_MwDrawText(MwWidget handle, MwPoint* point, const char* text,
th = MwTextHeight(handle, NULL, text);
px = malloc(tw * th * 4);
if(!px) {
printf("Out of Memory\n");
return;
}
memset(px, 0, tw * th * 4);
sx = 0;
@ -279,8 +316,11 @@ static void bitmap_MwDrawText(MwWidget handle, MwPoint* point, const char* text,
typedef int (*call_t)(void);
void MwFLSetup(void) {
call_t calls[] = {
#ifdef USE_GDI_TEXT
MwFL_GDISetup,
#endif
#ifdef USE_FREETYPE2
MWFL_FT2Setup,
MwFL_FT2Setup,
#endif
#ifdef USE_STB_TRUETYPE
MwFL_STBTTSetup,

142
src/truetype.c Normal file
View file

@ -0,0 +1,142 @@
#include <Mw/Milsko.h>
#define REMAIN (size - (data - old))
MwTTFInfo MwTTFGetInfo(unsigned char* data, int size) {
unsigned short n = 0;
int i;
unsigned char* old = data;
MwTTFInfo info = malloc(sizeof(*info));
memset(info, 0, sizeof(*info));
if(size < 12) {
MwTTFFreeInfo(info);
return NULL;
}
n |= data[4 + 0];
n = n << 8;
n |= data[4 + 1];
data += 12;
for(i = 0; REMAIN > 0 && i < n; i++) {
unsigned int offset = 0;
unsigned int length = 0;
int j;
if(REMAIN < (4 + 4 + 4 + 4)) {
MwTTFFreeInfo(info);
return NULL;
}
for(j = 0; j < 4; j++) {
offset = offset << 8;
offset |= data[4 + 4 + j];
length = length << 8;
length |= data[4 + 4 + 4 + j];
}
if(memcmp(data, "OS/2", 4) == 0) {
if(length >= 68) {
unsigned char* rev = data;
unsigned short us_weight = 0;
data = old + offset;
if(REMAIN < 68) {
MwTTFFreeInfo(info);
return NULL;
}
for(j = 0; j < 2; j++) {
us_weight = us_weight << 8;
us_weight |= data[0x4 + j];
}
info->weight = us_weight;
data = rev;
}
} else if(memcmp(data, "name", 4) == 0) {
if(length >= 6) {
unsigned short count = 0;
unsigned char* rev = data;
unsigned short str_off = 0;
unsigned char* beg;
data = old + offset;
if(REMAIN < (2 + 2 + 2)) {
MwTTFFreeInfo(info);
return NULL;
}
beg = data;
for(j = 0; j < 2; j++) {
count = count << 8;
count |= data[2 + j];
str_off = str_off << 8;
str_off |= data[2 + 2 + j];
}
data += 2 + 2 + 2;
for(j = 0; j < count; j++) {
unsigned short platform = 0;
unsigned short name = 0;
unsigned short nam_len = 0;
unsigned short nam_off = 0;
int k;
if(REMAIN < (2 + 2 + 2 + 2 + 2 + 2)) {
MwTTFFreeInfo(info);
return NULL;
}
for(k = 0; k < 2; k++) {
platform = platform << 8;
platform |= data[0 + k];
name = name << 8;
name |= data[2 + 2 + 2 + k];
nam_len = nam_len << 8;
nam_len |= data[2 + 2 + 2 + 2 + k];
nam_off = nam_off << 8;
nam_off |= data[2 + 2 + 2 + 2 + 2 + k];
}
/* FIXME: this does not work with surrogate */
if((platform == 0 || platform == 3) && name == 1) {
data = beg + str_off + nam_off;
if(REMAIN < nam_len) {
MwTTFFreeInfo(info);
return NULL;
}
if(info->family != NULL) free(info->family);
info->family = malloc(nam_len / 2 + 1);
for(k = 0; k < nam_len / 2; k++) info->family[k] = data[k * 2 + 1];
info->family[k] = 0;
}
data += 2 + 2 + 2 + 2 + 2 + 2;
}
data = rev;
}
}
data += 4 + 4 + 4 + 4;
}
return info;
}
void MwTTFFreeInfo(MwTTFInfo info) {
if(info->family != NULL) free(info->family);
free(info);
}

View file

@ -120,11 +120,11 @@ static void resize(MwWidget handle) {
MwForceRender(handle);
}
static void children_update(MwWidget handle, MwWidget child, int new) {
static void children_update(MwWidget handle, MwWidget child, int new_child) {
MwBox b = handle->internal;
(void)child;
(void)new;
(void)new_child;
b->layout = 1;

View file

@ -55,11 +55,11 @@ static void draw(MwWidget handle) {
double sh = (double)oh / px->common.height;
if(sw < sh) {
r.width = px->common.width * sw;
r.height = px->common.height * sw;
r.width = (int)(px->common.width * sw);
r.height = (int)(px->common.height * sw);
} else {
r.width = px->common.width * sh;
r.height = px->common.height * sh;
r.width = (int)(px->common.width * sh);
r.height = (int)(px->common.height * sh);
}
r.width -= MwGetInteger(handle, MwNpadding) * 2;
r.height -= MwGetInteger(handle, MwNpadding) * 2;
@ -68,8 +68,8 @@ static void draw(MwWidget handle) {
r.height = px->common.height;
}
r.x += (double)(ow - r.width) / 2;
r.y += (double)(oh - r.height) / 2;
r.x += (int)((double)(ow - r.width) / 2);
r.y += (int)((double)(oh - r.height) / 2);
MwLLDrawPixmap(handle->lowlevel, &r, px);
} else {

View file

@ -1,12 +1,19 @@
#include <Mw/Milsko.h>
#include "../../external/stb_ds.h"
static int wcreate(MwWidget handle) {
MwEntry t = malloc(sizeof(*t));
MwEntry t = malloc(sizeof(*t));
MwWidget topmost_parent = handle->parent;
t->cursor = 0;
t->right = 0;
t->length = 0;
handle->internal = t;
t->cursor = 0;
t->right = 0;
t->length = 0;
t->cursor_blink_timer = 0;
t->active = 0;
handle->internal = t;
while(topmost_parent->parent) topmost_parent = topmost_parent->parent;
arrpush(topmost_parent->monitored_entries, handle);
MwSetDefault(handle);
@ -16,9 +23,27 @@ static int wcreate(MwWidget handle) {
}
static void destroy(MwWidget handle) {
int i;
MwWidget topmost_parent = handle->parent;
while(topmost_parent->parent) topmost_parent = topmost_parent->parent;
for(i = 0; i < arrlen(topmost_parent->monitored_entries); i++) {
if(topmost_parent->monitored_entries[i] == handle) {
arrdel(topmost_parent->monitored_entries, i);
break;
}
}
free(handle->internal);
}
static void tick(MwWidget handle) {
MwEntry t = handle->internal;
if(t->active) {
if(++t->cursor_blink_timer >= 30) {
t->cursor_blink_timer = 0;
}
MwForceRender(handle);
}
}
static void draw(MwWidget handle) {
MwRect r;
MwEntry t = handle->internal;
@ -71,11 +96,13 @@ static void draw(MwWidget handle) {
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 + MwDefaultBorderWidth(handle);
currc.width = 1;
currc.height = h;
MwDrawRect(handle, &currc, text);
if(t->active && t->cursor_blink_timer <= 15) {
currc.x = p.x + MwTextWidth(handle, font, show);
currc.y = (r.height - h) / 2 + MwDefaultBorderWidth(handle);
currc.width = 1;
currc.height = h;
MwDrawRect(handle, &currc, text);
}
free(show);
}
@ -148,6 +175,25 @@ static void mouse_up(MwWidget handle, void* ptr) {
#define mouse_up MwForceRender2
#endif
static void mouse_down(MwWidget handle, void* ptr) {
int i = 0;
MwEntry t = handle->internal;
MwWidget topmost_parent = handle->parent;
(void)ptr;
while(topmost_parent->parent) topmost_parent = topmost_parent->parent;
for(i = 0; i < arrlen(topmost_parent->monitored_entries); i++) {
MwEntry t = topmost_parent->monitored_entries[i]->internal;
t->active = MwFALSE;
t->cursor_blink_timer = 0;
MwForceRender(topmost_parent->monitored_entries[i]);
}
t->active = MwTRUE;
MwForceRender2(handle, NULL);
}
static void prop_change(MwWidget handle, const char* prop) {
if(strcmp(prop, MwNtext) == 0 || strcmp(prop, MwNhideInput) == 0) MwForceRender(handle);
@ -187,23 +233,23 @@ static void clipboard(MwWidget handle, const char* data) {
}
MwClassRec MwEntryClassRec = {
wcreate, /* create */
destroy, /* destroy */
draw, /* draw */
NULL, /* click */
NULL, /* parent_resize */
prop_change, /* prop_change */
NULL, /* mouse_move */
mouse_up, /* mouse_up */
MwForceRender2, /* mouse_down */
key, /* key */
NULL, /* execute */
NULL, /* tick */
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
clipboard, /* clipboard */
NULL, /* props_change */
wcreate, /* create */
destroy, /* destroy */
draw, /* draw */
NULL, /* click */
NULL, /* parent_resize */
prop_change, /* prop_change */
NULL, /* mouse_move */
mouse_up, /* mouse_up */
mouse_down, /* mouse_down */
key, /* key */
NULL, /* execute */
tick, /* tick */
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
clipboard, /* clipboard */
NULL, /* props_change */
NULL,
NULL,
NULL};

View file

@ -319,8 +319,8 @@ static void draw_normal(MwWidget handle) {
MwLLColor text = MwParseColor(handle, MwGetText(handle, MwNforeground));
MwLLColor shadow = MwLightenColor(handle, base, MwDefaultShadow, MwDefaultShadow, MwDefaultShadow);
int align;
const char* str = MwGetText(handle, MwNtext);
MwLLPixmap bgpx = MwGetVoid(handle, MwNbackgroundPixmap);
const char* str = MwGetText(handle, MwNtext);
MwLLPixmap bgpx = MwGetVoid(handle, MwNbackgroundPixmap);
if(str == NULL) str = "";
@ -336,6 +336,7 @@ static void draw_normal(MwWidget handle) {
r.width -= MwGetInteger(handle, MwNleftPadding);
#if 1
if(align == MwALIGNMENT_CENTER) {
p.x = r.width / 2;
} else if(align == MwALIGNMENT_BEGINNING) {
@ -343,6 +344,9 @@ static void draw_normal(MwWidget handle) {
} else if(align == MwALIGNMENT_END) {
p.x = r.width - MwTextWidth(handle, NULL, str) / 2;
}
#else
p.x = 0;
#endif
p.y = r.height / 2;
p.x += MwGetInteger(handle, MwNleftPadding);

View file

@ -203,11 +203,16 @@ static void frame_draw(MwWidget handle) {
int seek = 0;
int l = 0;
char* old = str;
int sz = strlen(old) + 5;
if(ind < 0) ind = 0;
str = malloc(strlen(old) + 5);
str = malloc(sz);
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
strcpy_s(str, sz, old);
#else
strcpy(str, old);
#endif
free(old);
while(str[seek] != 0) {
@ -317,6 +322,11 @@ static void resize(MwWidget handle, int no_resize) {
static int wcreate(MwWidget handle) {
MwListBox lb = malloc(sizeof(*lb));
if(!lb) {
printf("Out Of Memory\n");
return 1;
}
memset(lb, 0, sizeof(*lb));
handle->internal = lb;
@ -400,8 +410,8 @@ static void draw(MwWidget handle) {
}
static void prop_change(MwWidget handle, const char* prop) {
MwListBox lb = handle->internal;
if(strcmp(prop, MwNleftPadding) == 0) {
MwListBox lb = handle->internal;
MwForceRender(lb->frame);
}
if(strcmp(prop, MwNhasHeading) == 0) {

View file

@ -24,6 +24,7 @@ static int wcreate(MwWidget handle) {
m->wsub = NULL;
m->sub = NULL;
handle->internal = m;
handle->is_menu = MwTRUE;
MwSetDefault(handle);

View file

@ -239,7 +239,7 @@ static int wcreate(MwWidget handle) {
EGLDisplay display;
waylandopengl_t* o = r = malloc(sizeof(*o));
int gbm_format = 0;
EGLConfig egl_configs[1024];
EGLConfig egl_configs[1024];
memset(o, 0, sizeof(waylandopengl_t));
o->gllib = MwDynamicOpen("libEGL.so");
@ -346,7 +346,7 @@ static int wcreate(MwWidget handle) {
} else {
if(gbm_format == GBM_FORMAT_ARGB8888) {
o->egl_config = egl_configs[i];
break;
break;
}
}
}
@ -513,8 +513,8 @@ static void mwOpenGLSwapBufferImpl(MwWidget handle) {
#ifdef USE_WAYLAND
if(handle->lowlevel->common.type == MwLLBackendWayland) {
waylandopengl_t* o = handle->internal;
struct gbm_bo* bo;
eglSwapInterval(o->egl_display, 0);
struct gbm_bo* bo;
eglSwapInterval(o->egl_display, 0);
if(!eglSwapBuffers(o->egl_display, o->egl_surface)) {
printf("ERROR: eglSwapBuffers, %0X\n", eglGetError());
}
@ -682,4 +682,4 @@ MWDECL MwClass MwOpenGLClass;
MwClass MwOpenGLClass = NULL;
#endif
#endif
#endif

View file

@ -34,7 +34,7 @@ static void draw(MwWidget handle) {
r.width -= MwDefaultBorderWidth(handle) * 2;
r.height -= MwDefaultBorderWidth(handle) * 2;
r.width = r.width * w;
r.width = (int)(r.width * w);
MwDrawRect(handle, &r, fill);
MwLLFreeColor(fill);

View file

@ -28,7 +28,7 @@ static int calc_length(MwWidget handle) {
int area = MwGetInteger(handle, MwNareaShown);
if(area > len) area = len;
return max * (double)area / len;
return (int)(max * (double)area / len);
}
static int calc_position(MwWidget handle) {
@ -36,7 +36,7 @@ static int calc_position(MwWidget handle) {
int len = MwGetInteger(handle, MwNmaxValue) - MwGetInteger(handle, MwNminValue);
int val = MwGetInteger(handle, MwNvalue);
return (max - calc_length(handle)) * (double)val / len;
return (int)((max - calc_length(handle)) * (double)val / len);
}
static void add_value(MwWidget handle, int mul) {
@ -54,7 +54,7 @@ static void add_value(MwWidget handle, int mul) {
}
static void draw(MwWidget handle) {
MwRect r, rt, rbar;
MwRect r = {0}, rt = {0}, rbar = {0};
MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground));
MwLLColor dark = MwLightenColor(handle, base, -64, -64, -64);
MwScrollBar scr = handle->internal;

View file

@ -39,6 +39,23 @@ static int tab_height(MwWidget handle) {
return MwTextHeight(handle, NULL, "M") + 10;
}
static int icon_width(MwWidget handle, const char* text) {
MwTab t = handle->internal;
int i;
for(i = 0; i < arrlen(t->names); i++) {
if(strcmp(t->names[i], text) == 0) {
MwLLPixmap px = MwGetVoid(t->frames[i], MwNiconPixmap);
if(px == NULL) return 0;
return px->common.width * tab_height(handle) / px->common.height;
}
}
return 0;
}
static void draw(MwWidget handle) {
MwTab t = handle->internal;
MwLLColor c = MwParseColor(handle, MwGetText(handle, MwNbackground));
@ -60,6 +77,7 @@ static void draw(MwWidget handle) {
x = 0;
for(i = 0; i < arrlen(t->names); i++) {
int render = 0;
int iw = icon_width(handle, t->names[i]);
if(i == MwGetInteger(handle, MwNvalue) && n == 1) {
r.y += h;
@ -73,11 +91,26 @@ static void draw(MwWidget handle) {
r2.x = x;
r2.y = 0;
r2.width = tab_width(handle, t->names[i]);
r2.width = tab_width(handle, t->names[i]) + iw;
r2.height = tab_height(handle) + MwDefaultBorderWidth(handle);
x += r2.width;
if(iw > 0) {
MwLLPixmap px = MwGetVoid(t->frames[i], MwNiconPixmap);
MwRect rp;
rp = r2;
rp.x += 5;
rp.y += 5;
rp.width = iw - 10;
rp.height = rp.height * (iw - 10) / iw;
MwLLDrawPixmap(handle->lowlevel, &rp, px);
}
if(render) {
MwPoint p;
@ -151,7 +184,7 @@ static void draw(MwWidget handle) {
MwDrawRect(handle, &r3, c);
}
p.x = r2.x + r2.width / 2;
p.x = r2.x + (r2.width + iw / 2) / 2;
p.y = r2.y + r2.height / 2;
MwDrawText(handle, NULL, &p, t->names[i], MwALIGNMENT_CENTER, ct);
}
@ -177,7 +210,10 @@ static void click(MwWidget handle) {
int h = tab_height(handle);
for(i = 0; i < arrlen(t->names); i++) {
int w = tab_width(handle, t->names[i]);
int w = tab_width(handle, t->names[i]);
int iw = icon_width(handle, t->names[i]);
w += iw;
if(MwGetInteger(handle, MwNvalue) != i && x <= handle->mouse_point.x && handle->mouse_point.x <= (x + w) && 0 <= handle->mouse_point.y && handle->mouse_point.y <= h) {
MwSetInteger(handle, MwNvalue, i);
@ -188,9 +224,15 @@ static void click(MwWidget handle) {
}
}
static void prop_change(MwWidget handle, const char* key) {
if(strcmp(key, MwNvalue) == 0) {
show_frame(handle);
}
}
static MwWidget mwTabAddImpl(MwWidget handle, const char* name) {
MwTab t = handle->internal;
MwWidget f = MwCreateWidget(MwFrameClass, "tabframe", handle, 0, MwGetInteger(handle, MwNheight), MwGetInteger(handle, MwNwidth) - MwDefaultBorderWidth(handle) * 2, MwGetInteger(handle, MwNheight) - tab_height(handle) - MwDefaultBorderWidth(handle) * 2);
MwWidget f = MwCreateWidget(MwFrameClass, "tabframe", handle, MwDefaultBorderWidth(handle), tab_height(handle) + MwDefaultBorderWidth(handle), MwGetInteger(handle, MwNwidth) - MwDefaultBorderWidth(handle) * 2, MwGetInteger(handle, MwNheight) - tab_height(handle) - MwDefaultBorderWidth(handle) * 2);
char* n = MwStringDuplicate(name);
arrput(t->frames, f);
@ -201,6 +243,8 @@ static MwWidget mwTabAddImpl(MwWidget handle, const char* name) {
if(MwGetInteger(handle, MwNvalue) == -1) {
MwSetInteger(handle, MwNvalue, arrlen(t->frames) - 1);
show_frame(handle);
} else {
MwLLShow(f->lowlevel, 0);
}
return f;
@ -217,6 +261,19 @@ static MwWidget mwTabGetFrameImpl(MwWidget handle, const char* name) {
return NULL;
}
static void mwTabFocusImpl(MwWidget handle, const char* name) {
MwTab t = handle->internal;
int i;
for(i = 0; i < arrlen(t->names); i++) {
if(strcmp(t->names[i], name) == 0) {
MwSetInteger(handle, MwNvalue, i);
show_frame(handle);
break;
}
}
}
static void func_handler(MwWidget handle, const char* name, void* out, va_list va) {
if(strcmp(name, "mwTabAdd") == 0) {
const char* name = va_arg(va, const char*);
@ -226,6 +283,10 @@ static void func_handler(MwWidget handle, const char* name, void* out, va_list v
const char* name = va_arg(va, const char*);
*(MwWidget*)out = mwTabGetFrameImpl(handle, name);
} else if(strcmp(name, "mwTabFocus") == 0) {
const char* name = va_arg(va, const char*);
mwTabFocusImpl(handle, name);
}
}
@ -237,6 +298,7 @@ static void resize(MwWidget handle) {
for(i = 0; i < arrlen(t->frames); i++) {
int y = MwGetInteger(handle, MwNheight);
MwLLShow(t->frames[i]->lowlevel, i == v);
if(i == v) y = tab_height(handle) + MwDefaultBorderWidth(handle);
MwVaApply(t->frames[i],
@ -248,24 +310,65 @@ static void resize(MwWidget handle) {
}
}
static void children_update(MwWidget handle, MwWidget child, int new_child) {
MwTab t = handle->internal;
int v = MwGetInteger(handle, MwNvalue);
int n;
int i;
if(new_child) return;
for(i = 0; i < arrlen(t->frames); i++) {
if(t->frames[i] == child) {
n = i;
break;
}
}
free(t->names[n]);
arrdel(t->frames, n);
arrdel(t->names, n);
if(n <= v) {
if(v > 0) v--;
MwSetInteger(handle, MwNvalue, v);
show_frame(handle);
} else {
MwSetInteger(handle, MwNvalue, v);
show_frame(handle);
}
MwForceRender(handle);
}
static void children_prop_change(MwWidget handle, MwWidget child, const char* key) {
(void)child;
if(strcmp(key, MwNiconPixmap) == 0) {
MwForceRender(handle);
}
}
MwClassRec MwTabClassRec = {
wcreate, /* create */
destroy, /* destroy */
draw, /* draw */
click, /* click */
NULL, /* parent_resize */
NULL, /* prop_change */
NULL, /* mouse_move */
NULL, /* mouse_up */
NULL, /* mouse_down */
NULL, /* key */
func_handler, /* execute */
NULL, /* tick */
resize, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL, /* clipboard */
NULL, /* props_change */
wcreate, /* create */
destroy, /* destroy */
draw, /* draw */
click, /* click */
NULL, /* parent_resize */
prop_change, /* prop_change */
NULL, /* mouse_move */
NULL, /* mouse_up */
NULL, /* mouse_down */
NULL, /* key */
func_handler, /* execute */
NULL, /* tick */
resize, /* resize */
children_update, /* children_update */
children_prop_change, /* children_prop_change */
NULL, /* clipboard */
NULL, /* props_change */
NULL,
NULL,
NULL};

View file

@ -170,11 +170,11 @@ static void resize(MwWidget handle) {
MwForceRender(handle);
}
static void children_update(MwWidget handle, MwWidget child, int new) {
static void children_update(MwWidget handle, MwWidget child, int new_child) {
MwTable t = handle->internal;
t->layout = 1;
if(new) {
if(new_child) {
arrput(t->widgets, child);
} else {
int i;

View file

@ -76,6 +76,12 @@ static void resize(MwWidget handle) {
static int wcreate(MwWidget handle) {
MwViewport vp = malloc(sizeof(*vp));
if(!vp) {
printf("Out Of Memory\n");
return 1;
}
memset(vp, 0, sizeof(*vp));
handle->internal = vp;
@ -151,7 +157,7 @@ static void tick(MwWidget handle) {
v = MwGetInteger(vp->vscroll, MwNvalue);
mv = MwGetInteger(vp->vscroll, MwNmaxValue);
l = MwGetInteger(vp->frame, MwNheight);
v = (mv - l) * (double)v / mv;
v = (int)((mv - l) * (double)v / mv);
if(v < 0) v = 0;
MwVaApply(vp->inframe,
@ -166,7 +172,7 @@ static void tick(MwWidget handle) {
v = MwGetInteger(vp->hscroll, MwNvalue);
mv = MwGetInteger(vp->hscroll, MwNmaxValue);
l = MwGetInteger(vp->frame, MwNwidth);
v = (mv - l) * (double)v / mv;
v = (int)((mv - l) * (double)v / mv);
if(v < 0) v = 0;
MwVaApply(vp->inframe,

View file

@ -35,6 +35,10 @@ static void mwWindowMakeBorderlessImpl(MwWidget handle, int toggle) {
MwLLEndStateChange(handle->lowlevel);
}
static void mwWindowShouldCloseImpl(MwWidget handle, MwBool* out) {
*out = handle->close;
}
static void func_handler(MwWidget handle, const char* name, void* out, va_list va) {
(void)out;
@ -42,6 +46,10 @@ static void func_handler(MwWidget handle, const char* name, void* out, va_list v
int toggle = va_arg(va, int);
mwWindowMakeBorderlessImpl(handle, toggle);
}
if(strcmp(name, "mwWindowShouldClose") == 0) {
MwBool* out = va_arg(va, MwBool*);
mwWindowShouldCloseImpl(handle, out);
}
}
MwClassRec MwWindowClassRec = {
wcreate, /* create */

View file

@ -4,6 +4,15 @@ open(OUT, ">", "src/color.c");
print(OUT "#include <Mw/Milsko.h>\n");
print(OUT "\n");
print(OUT "#include \"../external/stb_ds.h\"\n");
print(OUT "\n");
print(OUT "struct color {\n");
print(OUT " char* key;\n");
print(OUT " MwU32 value;\n");
print(OUT "};\n");
print(OUT "\n");
print(OUT "static struct color* colors = NULL;\n");
print(OUT "\n");
print(OUT "MwLLColor MwParseColorName(MwWidget handle, const char* color){\n");
print(OUT " MwRGB rgb;\n");
print(OUT " MwParseColorNameNoAllocate(color, &rgb);\n");
@ -13,21 +22,29 @@ print(OUT
print(OUT "}\n");
print(OUT "\n");
print(OUT "void MwParseColorNameNoAllocate(const char* color, MwRGB* rgb){\n");
print(OUT " MwU32 v = shget(colors, color);");
print(OUT " rgb->red = (v >> 16) & 0xff;");
print(OUT " rgb->green = (v >> 8) & 0xff;");
print(OUT " rgb->blue = (v >> 0) & 0xff;");
print(OUT "}\n");
print(OUT "\n");
print(OUT
"static void add_color(const char* name, int red, int green, int blue){\n"
);
print(OUT " MwU32 v = (red << 16) | (green << 8) | (blue << 0);\n");
print(OUT " shput(colors, name, v);\n");
print(OUT "}\n");
print(OUT "\n");
print(OUT "void MwColorTableInit(void){\n");
print(OUT " sh_new_strdup(colors);\n");
print(OUT " shdefault(colors, 0);\n");
while (my $l = <IN>) {
$l =~ s/\r?\n$//;
if ($l =~ /^[ \t]*([0-9]+)[ \t]+([0-9]+)[ \t]+([0-9]+)[ \t]+(.+)$/) {
print(OUT " if(strcmp(color, \"$4\") == 0){\n");
print(OUT " rgb->red = $1;\n");
print(OUT " rgb->green = $2;\n");
print(OUT " rgb->blue = $3;\n");
print(OUT " return;\n");
print(OUT " }\n");
print(OUT " add_color(\"$4\", $1, $2, $3);\n");
}
}
print(OUT " rgb->red = 0;\n");
print(OUT " rgb->green = 0;\n");
print(OUT " rgb->blue = 0;\n");
print(OUT "}\n");
close(OUT);

View file

@ -116,7 +116,7 @@ sub generate {
print(OUT "LD = $link\n");
print(OUT "\n");
print(OUT
"MW_CFLAGS = ${cdll} ${inc}include ${inc}external${dir}libz${dir}include ${def}_MILSKO ${def}_MILSKO_BUILD ${def}USE_GDI ${def}USE_STB_TRUETYPE ${def}USE_STB_IMAGE ${def}STBI_NO_SIMD\n"
"MW_CFLAGS = ${cdll} ${inc}include ${inc}external${dir}libz${dir}include ${def}_MILSKO ${def}_MILSKO_BUILD ${def}USE_GDI ${def}USE_STB_IMAGE ${def}STBI_NO_SIMD ${def}USE_GDI_TEXT ${def}MW_OPENGL\n"
);
print(OUT "MW_LDFLAGS = $dll\n");
print(OUT "EXE_CFLAGS = ${inc}include\n");
@ -190,7 +190,7 @@ sub generate {
print(OUT "src${dir}Mw.dll: " . cobjs($dir) . "\n");
print( OUT " \$(LD) \$(MW_LDFLAGS) $c_dllout $dllout\$@ "
. cobjs($dir, $prefobj)
. " $needlibs ${lib}opengl32.lib ${lib}gdi32.lib ${lib}user32.lib ${lib}advapi32.lib\n"
. " $needlibs ${lib}opengl32.lib ${lib}gdi32.lib ${lib}ole32.lib ${lib}uuid.lib ${lib}user32.lib ${lib}advapi32.lib\n"
);
print(OUT " $c_dllafter\n");
print(OUT "\n");