xbintsc 0.5.31 → 0.5.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (286) hide show
  1. package/README.md +25 -16
  2. package/README.zh-CN.md +10 -8
  3. package/dist/scripts/check-version.d.ts +27 -0
  4. package/dist/scripts/check-version.js +71 -0
  5. package/dist/scripts/check-version.js.map +1 -0
  6. package/dist/scripts/package-platform.d.ts +58 -0
  7. package/dist/scripts/package-platform.js +142 -0
  8. package/dist/scripts/package-platform.js.map +1 -0
  9. package/dist/scripts/verify-platform-package.d.ts +34 -0
  10. package/dist/scripts/verify-platform-package.js +161 -0
  11. package/dist/scripts/verify-platform-package.js.map +1 -0
  12. package/dist/src/binder/references.js +14 -1
  13. package/dist/src/binder/references.js.map +1 -1
  14. package/dist/src/cli/help.d.ts +1 -1
  15. package/dist/src/cli/main.js +3 -1
  16. package/dist/src/cli/main.js.map +1 -1
  17. package/dist/src/codegen/generator/module.d.ts +1 -0
  18. package/dist/src/codegen/generator/module.js +54 -0
  19. package/dist/src/codegen/generator/module.js.map +1 -1
  20. package/dist/src/codegen/generator/statements/variables.js +6 -4
  21. package/dist/src/codegen/generator/statements/variables.js.map +1 -1
  22. package/dist/src/driver/runtime-lib.d.ts +29 -4
  23. package/dist/src/driver/runtime-lib.js +68 -10
  24. package/dist/src/driver/runtime-lib.js.map +1 -1
  25. package/dist/src/driver/version.d.ts +1 -1
  26. package/dist/src/driver/version.js +1 -1
  27. package/dist/src/extensions/gui/css.d.ts +26 -0
  28. package/dist/src/extensions/gui/css.js +100 -0
  29. package/dist/src/extensions/gui/css.js.map +1 -0
  30. package/dist/src/extensions/gui/html.js +9 -2
  31. package/dist/src/extensions/gui/html.js.map +1 -1
  32. package/dist/src/extensions/gui/index.js +22 -7
  33. package/dist/src/extensions/gui/index.js.map +1 -1
  34. package/dist/src/extensions/gui/three.d.ts +16 -0
  35. package/dist/src/extensions/gui/three.js +22 -0
  36. package/dist/src/extensions/gui/three.js.map +1 -0
  37. package/dist/src/extensions/media/index.d.ts +6 -5
  38. package/dist/src/extensions/media/index.js +15 -16
  39. package/dist/src/extensions/media/index.js.map +1 -1
  40. package/dist/src/parser/context.d.ts +41 -0
  41. package/dist/src/parser/context.js +89 -4
  42. package/dist/src/parser/context.js.map +1 -1
  43. package/dist/src/parser/literals.js +6 -12
  44. package/dist/src/parser/literals.js.map +1 -1
  45. package/dist/tests/driver/platform-package.test.d.ts +1 -0
  46. package/dist/tests/driver/platform-package.test.js +49 -0
  47. package/dist/tests/driver/platform-package.test.js.map +1 -0
  48. package/dist/tests/driver/runtime-lib.test.js +51 -4
  49. package/dist/tests/driver/runtime-lib.test.js.map +1 -1
  50. package/dist/tests/e2e/compile-builtins.test.js +24 -0
  51. package/dist/tests/e2e/compile-builtins.test.js.map +1 -1
  52. package/dist/tests/e2e/compile-objects-classes.test.js +23 -0
  53. package/dist/tests/e2e/compile-objects-classes.test.js.map +1 -1
  54. package/dist/tests/e2e/gui-audio.test.d.ts +14 -0
  55. package/dist/tests/e2e/gui-audio.test.js +287 -0
  56. package/dist/tests/e2e/gui-audio.test.js.map +1 -0
  57. package/dist/tests/e2e/gui-browser.test.js +1 -1
  58. package/dist/tests/e2e/gui-browser.test.js.map +1 -1
  59. package/dist/tests/e2e/gui-effects.test.d.ts +6 -0
  60. package/dist/tests/e2e/gui-effects.test.js +262 -0
  61. package/dist/tests/e2e/gui-effects.test.js.map +1 -0
  62. package/dist/tests/e2e/gui-example-webgl.test.d.ts +10 -0
  63. package/dist/tests/e2e/gui-example-webgl.test.js +75 -0
  64. package/dist/tests/e2e/gui-example-webgl.test.js.map +1 -0
  65. package/dist/tests/e2e/gui-example-webgl2.test.d.ts +8 -0
  66. package/dist/tests/e2e/gui-example-webgl2.test.js +72 -0
  67. package/dist/tests/e2e/gui-example-webgl2.test.js.map +1 -0
  68. package/dist/tests/e2e/gui-helpers.d.ts +7 -0
  69. package/dist/tests/e2e/gui-helpers.js +1 -0
  70. package/dist/tests/e2e/gui-helpers.js.map +1 -1
  71. package/dist/tests/e2e/gui-layout.test.js +48 -0
  72. package/dist/tests/e2e/gui-layout.test.js.map +1 -1
  73. package/dist/tests/e2e/gui-media.test.js +83 -4
  74. package/dist/tests/e2e/gui-media.test.js.map +1 -1
  75. package/dist/tests/e2e/gui-style.test.js +55 -0
  76. package/dist/tests/e2e/gui-style.test.js.map +1 -1
  77. package/dist/tests/e2e/gui-webgl.test.d.ts +11 -0
  78. package/dist/tests/e2e/gui-webgl.test.js +437 -0
  79. package/dist/tests/e2e/gui-webgl.test.js.map +1 -0
  80. package/dist/tests/e2e/gui-webgl2-3d.test.d.ts +4 -0
  81. package/dist/tests/e2e/gui-webgl2-3d.test.js +264 -0
  82. package/dist/tests/e2e/gui-webgl2-3d.test.js.map +1 -0
  83. package/dist/tests/e2e/gui-webgl2-blit.test.d.ts +10 -0
  84. package/dist/tests/e2e/gui-webgl2-blit.test.js +262 -0
  85. package/dist/tests/e2e/gui-webgl2-blit.test.js.map +1 -0
  86. package/dist/tests/e2e/gui-webgl2-formats.test.d.ts +6 -0
  87. package/dist/tests/e2e/gui-webgl2-formats.test.js +395 -0
  88. package/dist/tests/e2e/gui-webgl2-formats.test.js.map +1 -0
  89. package/dist/tests/e2e/gui-webgl2-mrt.test.d.ts +4 -0
  90. package/dist/tests/e2e/gui-webgl2-mrt.test.js +105 -0
  91. package/dist/tests/e2e/gui-webgl2-mrt.test.js.map +1 -0
  92. package/dist/tests/e2e/gui-webgl2-ubo.test.d.ts +8 -0
  93. package/dist/tests/e2e/gui-webgl2-ubo.test.js +112 -0
  94. package/dist/tests/e2e/gui-webgl2-ubo.test.js.map +1 -0
  95. package/dist/tests/e2e/gui-webgl2.test.d.ts +10 -0
  96. package/dist/tests/e2e/gui-webgl2.test.js +282 -0
  97. package/dist/tests/e2e/gui-webgl2.test.js.map +1 -0
  98. package/dist/tests/extensions/gui-index.test.js +1 -0
  99. package/dist/tests/extensions/gui-index.test.js.map +1 -1
  100. package/dist/tests/extensions/gui.test.js +41 -0
  101. package/dist/tests/extensions/gui.test.js.map +1 -1
  102. package/dist/tests/extensions/media.test.js +8 -3
  103. package/dist/tests/extensions/media.test.js.map +1 -1
  104. package/dist/tests/parser/expressions.test.js +30 -0
  105. package/dist/tests/parser/expressions.test.js.map +1 -1
  106. package/dist/tests/platform-tarball.test.d.ts +1 -0
  107. package/dist/tests/platform-tarball.test.js +111 -0
  108. package/dist/tests/platform-tarball.test.js.map +1 -0
  109. package/dist/tests/version.test.js +6 -0
  110. package/dist/tests/version.test.js.map +1 -1
  111. package/doc/ai/contributing.md +11 -0
  112. package/doc/ai/extensions.md +35 -12
  113. package/doc/ai/troubleshooting.md +17 -11
  114. package/doc/ai/zh-CN/contributing.md +9 -0
  115. package/doc/ai/zh-CN/extensions.md +30 -10
  116. package/doc/ai/zh-CN/troubleshooting.md +14 -8
  117. package/doc/gui/api.md +63 -14
  118. package/doc/gui/build.md +79 -16
  119. package/doc/gui/canvas.md +11 -3
  120. package/doc/gui/dom.md +35 -17
  121. package/doc/gui/known-issues.md +57 -24
  122. package/doc/gui/layout.md +18 -0
  123. package/doc/gui/media.md +21 -13
  124. package/doc/gui/rendering.md +50 -3
  125. package/doc/gui/webgl.md +315 -0
  126. package/doc/gui.md +113 -18
  127. package/doc/npm-package.md +59 -29
  128. package/doc/requirements.md +24 -11
  129. package/doc/zh-CN/gui/api.md +53 -11
  130. package/doc/zh-CN/gui/build.md +70 -16
  131. package/doc/zh-CN/gui/canvas.md +9 -2
  132. package/doc/zh-CN/gui/dom.md +22 -7
  133. package/doc/zh-CN/gui/known-issues.md +45 -19
  134. package/doc/zh-CN/gui/layout.md +14 -0
  135. package/doc/zh-CN/gui/media.md +18 -11
  136. package/doc/zh-CN/gui/rendering.md +41 -4
  137. package/doc/zh-CN/gui/webgl.md +121 -0
  138. package/doc/zh-CN/gui.md +91 -15
  139. package/doc/zh-CN/npm-package.md +48 -24
  140. package/doc/zh-CN/requirements.md +16 -7
  141. package/llms.txt +2 -0
  142. package/package.json +17 -1
  143. package/runtime/ext_gui/audio.cpp +365 -153
  144. package/runtime/ext_gui/audio_buffer.cpp +166 -0
  145. package/runtime/ext_gui/audio_buffer.h +37 -0
  146. package/runtime/ext_gui/audio_decode.cpp +219 -0
  147. package/runtime/ext_gui/audio_decode.h +39 -0
  148. package/runtime/ext_gui/audio_device.cpp +87 -0
  149. package/runtime/ext_gui/audio_effects.cpp +163 -0
  150. package/runtime/ext_gui/audio_effects.h +25 -0
  151. package/runtime/ext_gui/audio_internal.h +30 -0
  152. package/runtime/ext_gui/audio_mixer.cpp +494 -0
  153. package/runtime/ext_gui/audio_mixer.h +238 -0
  154. package/runtime/ext_gui/audio_param.cpp +104 -0
  155. package/runtime/ext_gui/audio_param_object.cpp +155 -0
  156. package/runtime/ext_gui/browser.cpp +50 -14
  157. package/runtime/ext_gui/canvas.cpp +3 -18
  158. package/runtime/ext_gui/canvas_internal.h +10 -0
  159. package/runtime/ext_gui/canvas_raster.cpp +60 -0
  160. package/runtime/ext_gui/clip_values.cpp +246 -0
  161. package/runtime/ext_gui/css.cpp +94 -0
  162. package/runtime/ext_gui/css.h +22 -1
  163. package/runtime/ext_gui/css_match.cpp +3 -0
  164. package/runtime/ext_gui/css_selector.cpp +30 -3
  165. package/runtime/ext_gui/css_sheet.cpp +89 -45
  166. package/runtime/ext_gui/document.cpp +4 -1
  167. package/runtime/ext_gui/document.h +2 -0
  168. package/runtime/ext_gui/dom.h +16 -0
  169. package/runtime/ext_gui/dom_api.cpp +1 -0
  170. package/runtime/ext_gui/dom_api_canvas.cpp +17 -80
  171. package/runtime/ext_gui/dom_api_canvas_extra.cpp +130 -1
  172. package/runtime/ext_gui/dom_api_canvas_pending.cpp +41 -0
  173. package/runtime/ext_gui/dom_api_internal.h +275 -0
  174. package/runtime/ext_gui/dom_api_webgl.cpp +383 -0
  175. package/runtime/ext_gui/dom_api_webgl2.cpp +549 -0
  176. package/runtime/ext_gui/dom_api_webgl2_draw.cpp +269 -0
  177. package/runtime/ext_gui/dom_api_webgl_buffer.cpp +216 -0
  178. package/runtime/ext_gui/dom_api_webgl_compressed.cpp +167 -0
  179. package/runtime/ext_gui/dom_api_webgl_framebuffer.cpp +160 -0
  180. package/runtime/ext_gui/dom_api_webgl_rt.h +30 -0
  181. package/runtime/ext_gui/dom_api_webgl_shader.cpp +443 -0
  182. package/runtime/ext_gui/dom_api_webgl_source.cpp +161 -0
  183. package/runtime/ext_gui/dom_api_webgl_state.cpp +590 -0
  184. package/runtime/ext_gui/dom_api_webgl_texture.cpp +485 -0
  185. package/runtime/ext_gui/dom_api_webgl_ubo.cpp +81 -0
  186. package/runtime/ext_gui/effect_values.cpp +312 -0
  187. package/runtime/ext_gui/gradient_values.cpp +476 -0
  188. package/runtime/ext_gui/grid_values.cpp +230 -0
  189. package/runtime/ext_gui/gui.cpp +44 -9
  190. package/runtime/ext_gui/gui_canvas.cpp +50 -2
  191. package/runtime/ext_gui/gui_engine.h +36 -4
  192. package/runtime/ext_gui/gui_events.cpp +4 -1
  193. package/runtime/ext_gui/gui_media.cpp +1 -1
  194. package/runtime/ext_gui/gui_webgl.cpp +83 -0
  195. package/runtime/ext_gui/image_bitmap.cpp +28 -0
  196. package/runtime/ext_gui/image_bitmap.h +26 -0
  197. package/runtime/ext_gui/image_bitmap_browser.cpp +136 -0
  198. package/runtime/ext_gui/layout.cpp +21 -0
  199. package/runtime/ext_gui/layout_flow.cpp +81 -4
  200. package/runtime/ext_gui/layout_flow_internal.h +31 -0
  201. package/runtime/ext_gui/layout_grid.cpp +374 -0
  202. package/runtime/ext_gui/media.cpp +32 -0
  203. package/runtime/ext_gui/media.h +14 -1
  204. package/runtime/ext_gui/media_api.h +25 -2
  205. package/runtime/ext_gui/media_query.cpp +211 -0
  206. package/runtime/ext_gui/paint.cpp +111 -77
  207. package/runtime/ext_gui/paint.h +33 -3
  208. package/runtime/ext_gui/paint_background.cpp +229 -0
  209. package/runtime/ext_gui/paint_clip.cpp +268 -0
  210. package/runtime/ext_gui/paint_effects.cpp +324 -0
  211. package/runtime/ext_gui/paint_internal.h +85 -0
  212. package/runtime/ext_gui/renderer.cpp +8 -31
  213. package/runtime/ext_gui/renderer_clip.cpp +196 -0
  214. package/runtime/ext_gui/renderer_image.cpp +13 -8
  215. package/runtime/ext_gui/renderer_internal.h +15 -8
  216. package/runtime/ext_gui/renderer_text.cpp +6 -31
  217. package/runtime/ext_gui/style.cpp +343 -20
  218. package/runtime/ext_gui/style.h +144 -3
  219. package/runtime/ext_gui/style_print.cpp +134 -1
  220. package/runtime/ext_gui/style_values.cpp +152 -126
  221. package/runtime/ext_gui/style_values_internal.h +35 -0
  222. package/runtime/ext_gui/webgl.h +600 -0
  223. package/runtime/ext_gui/webgl2_constants.h +274 -0
  224. package/runtime/ext_gui/webgl_blit.cpp +95 -0
  225. package/runtime/ext_gui/webgl_buffer.cpp +480 -0
  226. package/runtime/ext_gui/webgl_buffer_objects.cpp +270 -0
  227. package/runtime/ext_gui/webgl_clear.cpp +142 -0
  228. package/runtime/ext_gui/webgl_compressed.cpp +180 -0
  229. package/runtime/ext_gui/webgl_constants.h +317 -0
  230. package/runtime/ext_gui/webgl_context.cpp +551 -0
  231. package/runtime/ext_gui/webgl_draw.cpp +560 -0
  232. package/runtime/ext_gui/webgl_draw_buffers.cpp +75 -0
  233. package/runtime/ext_gui/webgl_glsl.h +165 -0
  234. package/runtime/ext_gui/webgl_glsl_compile.cpp +437 -0
  235. package/runtime/ext_gui/webgl_glsl_rewrite.cpp +367 -0
  236. package/runtime/ext_gui/webgl_glsl_scan.cpp +590 -0
  237. package/runtime/ext_gui/webgl_glsl_scan_block.cpp +126 -0
  238. package/runtime/ext_gui/webgl_glsl_tokens.h +28 -0
  239. package/runtime/ext_gui/webgl_msl.cpp +62 -0
  240. package/runtime/ext_gui/webgl_msl.h +33 -0
  241. package/runtime/ext_gui/webgl_pipeline.cpp +326 -0
  242. package/runtime/ext_gui/webgl_program_blocks.cpp +58 -0
  243. package/runtime/ext_gui/webgl_program_internal.h +24 -0
  244. package/runtime/ext_gui/webgl_shader.cpp +594 -0
  245. package/runtime/ext_gui/webgl_state.cpp +228 -0
  246. package/runtime/ext_gui/webgl_texture.cpp +420 -0
  247. package/runtime/ext_gui/webgl_texture_3d.cpp +215 -0
  248. package/runtime/ext_gui/webgl_uniform.cpp +167 -0
  249. package/runtime/ext_gui/webgl_uniform_block.h +31 -0
  250. package/runtime/ext_gui/webgl_webgl2.cpp +277 -0
  251. package/runtime/ext_media/decode_audio.cpp +308 -0
  252. package/runtime/ext_media/media.cpp +1 -1
  253. package/runtime/ext_media/media_bridge.c +11 -3
  254. package/runtime/rt.h +17 -0
  255. package/runtime/rt_internal.h +1 -0
  256. package/runtime/xt_array_buffer.c +30 -0
  257. package/runtime/xt_containers/access.inc +8 -0
  258. package/runtime/xt_regex/api.inc +2 -0
  259. package/runtime/xt_regex/matcher.inc +16 -3
  260. package/runtime/xt_regex/parser.inc +8 -2
  261. package/runtime/xt_regex/types.inc +3 -0
  262. package/runtime/xt_stdlib2/regexp-match.inc +60 -21
  263. package/runtime/xt_stdlib2/regexp.inc +1 -0
  264. package/runtime/xt_typed_array/elements.inc +13 -0
  265. package/runtime/xt_typed_array.c +1 -1
  266. package/scripts/build-gui.ts +90 -3
  267. package/scripts/build-media.ts +335 -62
  268. package/scripts/build-runtime.ts +21 -16
  269. package/scripts/check-version.ts +39 -9
  270. package/scripts/package-platform.ts +183 -0
  271. package/scripts/set-platform-version.ts +62 -0
  272. package/scripts/setup-vs-toolchain.ps1 +152 -0
  273. package/scripts/verify-platform-package.ts +182 -0
  274. package/src/binder/references.ts +13 -1
  275. package/src/cli/main.ts +5 -1
  276. package/src/codegen/generator/module.ts +50 -0
  277. package/src/codegen/generator/statements/variables.ts +6 -3
  278. package/src/driver/runtime-lib.ts +73 -9
  279. package/src/driver/version.ts +1 -1
  280. package/src/extensions/gui/css.ts +113 -0
  281. package/src/extensions/gui/html.ts +9 -2
  282. package/src/extensions/gui/index.ts +22 -7
  283. package/src/extensions/gui/three.ts +25 -0
  284. package/src/extensions/media/index.ts +16 -18
  285. package/src/parser/context.ts +99 -4
  286. package/src/parser/literals.ts +6 -12
@@ -0,0 +1,324 @@
1
+ /*
2
+ * xbintsc GUI engine — CSS filter and shadow approximations.
3
+ *
4
+ * Colour functions are applied per painted shape (a group would need an
5
+ * offscreen layer). `blur()` is approximated by spreading nine translucent
6
+ * copies around the shape, and `drop-shadow()` by a shadow silhouette per box.
7
+ * Both are deterministic and need no render-target pass, which keeps the
8
+ * single-pass painter intact; `backdrop-filter` still needs a backdrop snapshot
9
+ * and is documented as not composited.
10
+ */
11
+
12
+ #include "paint_internal.h"
13
+
14
+ #include <algorithm>
15
+ #include <cmath>
16
+ #include <utility>
17
+ #include <vector>
18
+
19
+ #include "style_internal.h"
20
+
21
+ namespace xtgui {
22
+ namespace paint_detail {
23
+
24
+ namespace {
25
+
26
+ float clamp01(float value) { return value < 0.0f ? 0.0f : (value > 1.0f ? 1.0f : value); }
27
+
28
+ Color lerpColor(const Color &from, const Color &to, float amount) {
29
+ Color out;
30
+ out.r = from.r + (to.r - from.r) * amount;
31
+ out.g = from.g + (to.g - from.g) * amount;
32
+ out.b = from.b + (to.b - from.b) * amount;
33
+ out.a = from.a + (to.a - from.a) * amount;
34
+ out.valid = true;
35
+ return out;
36
+ }
37
+
38
+ float luminance(const Color &color) {
39
+ return color.r * 0.2126f + color.g * 0.7152f + color.b * 0.0722f;
40
+ }
41
+
42
+ Color applySepia(const Color &color, float amount) {
43
+ Color sepia;
44
+ sepia.r = color.r * 0.393f + color.g * 0.769f + color.b * 0.189f;
45
+ sepia.g = color.r * 0.349f + color.g * 0.686f + color.b * 0.168f;
46
+ sepia.b = color.r * 0.272f + color.g * 0.534f + color.b * 0.131f;
47
+ sepia.a = color.a;
48
+ sepia.valid = true;
49
+ return lerpColor(color, sepia, amount);
50
+ }
51
+
52
+ Color applySaturate(const Color &color, float amount) {
53
+ float luma = luminance(color);
54
+ Color out;
55
+ out.r = luma + (color.r - luma) * amount;
56
+ out.g = luma + (color.g - luma) * amount;
57
+ out.b = luma + (color.b - luma) * amount;
58
+ out.a = color.a;
59
+ out.valid = true;
60
+ return out;
61
+ }
62
+
63
+ Color applyHueRotate(const Color &color, float degrees) {
64
+ float radians = degrees * 3.141592653589793f / 180.0f;
65
+ float c = std::cos(radians);
66
+ float s = std::sin(radians);
67
+ Color out;
68
+ out.r = color.r * (0.213f + c * 0.787f - s * 0.213f) +
69
+ color.g * (0.715f - c * 0.715f - s * 0.715f) +
70
+ color.b * (0.072f - c * 0.072f + s * 0.928f);
71
+ out.g = color.r * (0.213f - c * 0.213f + s * 0.143f) +
72
+ color.g * (0.715f + c * 0.285f + s * 0.140f) +
73
+ color.b * (0.072f - c * 0.072f - s * 0.283f);
74
+ out.b = color.r * (0.213f - c * 0.213f - s * 0.787f) +
75
+ color.g * (0.715f - c * 0.715f + s * 0.715f) +
76
+ color.b * (0.072f + c * 0.928f + s * 0.072f);
77
+ out.a = color.a;
78
+ out.valid = true;
79
+ return out;
80
+ }
81
+
82
+ struct Tap {
83
+ float dx;
84
+ float dy;
85
+ };
86
+ constexpr float kBlurTapWeight = 0.12f;
87
+
88
+ std::vector<Tap> blurTaps(float radius) {
89
+ if (radius <= 0.0f) return {Tap{0.0f, 0.0f}};
90
+ std::vector<Tap> taps;
91
+ for (int y = -1; y <= 1; y++) {
92
+ for (int x = -1; x <= 1; x++) taps.push_back(Tap{x * radius, y * radius});
93
+ }
94
+ return taps;
95
+ }
96
+
97
+ } // namespace
98
+
99
+ float resolveLength(const Length &length, float base, float em, float viewportWidth,
100
+ float viewportHeight) {
101
+ return xt_style_resolve_absolute(length, base, em, 16.0f, viewportWidth, viewportHeight);
102
+ }
103
+
104
+ FilterChain extendFilter(const FilterChain &parent, const std::vector<FilterOp> &filters,
105
+ const XtStyle &style, float viewportWidth, float viewportHeight) {
106
+ FilterChain chain = parent;
107
+ /* Drop shadows are silhouettes of one box, never inherited. */
108
+ chain.shadows.clear();
109
+ for (const FilterOp &filter : filters) {
110
+ if (filter.kind == FilterKind::Blur) {
111
+ float blur = resolveLength(filter.blur, 0.0f, style.font_size, viewportWidth, viewportHeight);
112
+ if (blur > 0.0f) chain.blur += blur;
113
+ } else if (filter.kind == FilterKind::DropShadow) {
114
+ FilterChain::Shadow shadow;
115
+ shadow.dx = resolveLength(filter.dx, 0.0f, style.font_size, viewportWidth, viewportHeight);
116
+ shadow.dy = resolveLength(filter.dy, 0.0f, style.font_size, viewportWidth, viewportHeight);
117
+ shadow.blur =
118
+ resolveLength(filter.blur, 0.0f, style.font_size, viewportWidth, viewportHeight);
119
+ shadow.color = filter.has_color ? filter.color : style.color;
120
+ chain.shadows.push_back(shadow);
121
+ } else {
122
+ chain.ops.push_back(filter);
123
+ }
124
+ }
125
+ return chain;
126
+ }
127
+
128
+ Color filterColor(const FilterChain &chain, Color color) {
129
+ for (const FilterOp &filter : chain.ops) {
130
+ switch (filter.kind) {
131
+ case FilterKind::Brightness:
132
+ color.r *= filter.amount;
133
+ color.g *= filter.amount;
134
+ color.b *= filter.amount;
135
+ break;
136
+ case FilterKind::Contrast:
137
+ color.r = (color.r - 0.5f) * filter.amount + 0.5f;
138
+ color.g = (color.g - 0.5f) * filter.amount + 0.5f;
139
+ color.b = (color.b - 0.5f) * filter.amount + 0.5f;
140
+ break;
141
+ case FilterKind::Grayscale: {
142
+ float luma = luminance(color);
143
+ Color gray{luma, luma, luma, color.a, true};
144
+ color = lerpColor(color, gray, filter.amount);
145
+ break;
146
+ }
147
+ case FilterKind::Sepia:
148
+ color = applySepia(color, filter.amount);
149
+ break;
150
+ case FilterKind::Invert:
151
+ color.r = color.r + (1.0f - 2.0f * color.r) * filter.amount;
152
+ color.g = color.g + (1.0f - 2.0f * color.g) * filter.amount;
153
+ color.b = color.b + (1.0f - 2.0f * color.b) * filter.amount;
154
+ break;
155
+ case FilterKind::Saturate:
156
+ color = applySaturate(color, filter.amount);
157
+ break;
158
+ case FilterKind::HueRotate:
159
+ color = applyHueRotate(color, filter.amount);
160
+ break;
161
+ case FilterKind::Opacity:
162
+ color.a *= filter.amount;
163
+ break;
164
+ default:
165
+ break;
166
+ }
167
+ color.r = clamp01(color.r);
168
+ color.g = clamp01(color.g);
169
+ color.b = clamp01(color.b);
170
+ color.a = clamp01(color.a);
171
+ }
172
+ return color;
173
+ }
174
+
175
+ Color imageTint(const FilterChain &chain) {
176
+ /* The image shader multiplies the sampled texel by this colour, which can
177
+ * express brightness and opacity exactly. Other colour functions need a
178
+ * per-pixel pass; leaving the tint neutral is less wrong than a channel
179
+ * multiply, so they are skipped for images. */
180
+ Color tint{1.0f, 1.0f, 1.0f, 1.0f};
181
+ for (const FilterOp &filter : chain.ops) {
182
+ if (filter.kind == FilterKind::Brightness) {
183
+ tint.r *= filter.amount;
184
+ tint.g *= filter.amount;
185
+ tint.b *= filter.amount;
186
+ } else if (filter.kind == FilterKind::Opacity) {
187
+ tint.a *= filter.amount;
188
+ }
189
+ }
190
+ tint.r = clamp01(tint.r);
191
+ tint.g = clamp01(tint.g);
192
+ tint.b = clamp01(tint.b);
193
+ tint.a = clamp01(tint.a);
194
+ return tint;
195
+ }
196
+
197
+ void addRect(DisplayList &out, float x, float y, float width, float height, float radius,
198
+ const Color &color, const PaintClip &clip, const Matrix2D &transform) {
199
+ if (width <= 0.0f || height <= 0.0f || color.a <= 0.0f) return;
200
+ PaintRect rect;
201
+ rect.x = x;
202
+ rect.y = y;
203
+ rect.width = width;
204
+ rect.height = height;
205
+ rect.radius = radius;
206
+ rect.color = color;
207
+ rect.transform = transform;
208
+ out.rects.push_back(rect);
209
+ out.ops.push_back(PaintOp{PaintKind::Rect, (uint32_t)(out.rects.size() - 1), clip});
210
+ }
211
+
212
+ void addRectFiltered(DisplayList &out, float x, float y, float width, float height, float radius,
213
+ const Color &color, const PaintClip &clip, const Matrix2D &transform,
214
+ const FilterChain &chain) {
215
+ Color filtered = filterColor(chain, color);
216
+ if (filtered.a <= 0.0f) return;
217
+ if (chain.blur <= 0.0f) {
218
+ addRect(out, x, y, width, height, radius, filtered, clip, transform);
219
+ return;
220
+ }
221
+ for (const Tap &tap : blurTaps(chain.blur)) {
222
+ Color copy = filtered;
223
+ copy.a *= kBlurTapWeight;
224
+ addRect(out, x + tap.dx, y + tap.dy, width, height, radius, copy, clip, transform);
225
+ }
226
+ }
227
+
228
+ void addBoxDropShadows(DisplayList &out, const LayoutBox &box, const XtStyle &style,
229
+ const FilterChain &chain, const PaintClip &clip) {
230
+ if (chain.shadows.empty()) return;
231
+ for (const FilterChain::Shadow &shadow : chain.shadows) {
232
+ Color color = filterColor(chain, shadow.color);
233
+ if (color.a <= 0.0f) continue;
234
+ std::vector<Tap> taps = blurTaps(shadow.blur);
235
+ for (const Tap &tap : taps) {
236
+ Color copy = color;
237
+ if (shadow.blur > 0.0f) copy.a *= kBlurTapWeight;
238
+ addRect(out, box.x + shadow.dx + tap.dx, box.y + shadow.dy + tap.dy, box.width, box.height,
239
+ style.border_radius, copy, clip, box.world);
240
+ }
241
+ }
242
+ }
243
+
244
+ void addTextRun(DisplayList &out, float x, float baseline, float width, float height,
245
+ const std::string &text, const FontSpec &font, const Color &color,
246
+ const Matrix2D &transform, const PaintClip &clip, const XtStyle &style,
247
+ const FilterChain &chain, float viewportWidth, float viewportHeight) {
248
+ if (text.empty() || color.a <= 0.0f) return;
249
+ auto emit = [&](float dx, float dy, Color runColor, bool shadow) {
250
+ if (runColor.a <= 0.0f) return;
251
+ PaintText run;
252
+ run.x = x + dx;
253
+ run.baseline = baseline + dy;
254
+ run.width = width;
255
+ run.height = height;
256
+ run.color = runColor;
257
+ run.text = text;
258
+ run.font = font;
259
+ run.transform = transform;
260
+ run.shadow = shadow;
261
+ out.texts.push_back(std::move(run));
262
+ out.ops.push_back(PaintOp{PaintKind::Text, (uint32_t)(out.texts.size() - 1), clip});
263
+ };
264
+
265
+ /* `filter: drop-shadow()` first (behind the glyphs). */
266
+ for (const FilterChain::Shadow &shadow : chain.shadows) {
267
+ Color shadowColor = filterColor(chain, shadow.color);
268
+ for (const Tap &tap : blurTaps(shadow.blur)) {
269
+ Color copy = shadowColor;
270
+ if (shadow.blur > 0.0f) copy.a *= kBlurTapWeight;
271
+ emit(shadow.dx + tap.dx, shadow.dy + tap.dy, copy, true);
272
+ }
273
+ }
274
+
275
+ /* `text-shadow`, bottom-most first: CSS paints later layers under earlier
276
+ * ones, so reverse the declaration list. */
277
+ for (size_t index = style.text_shadow.size(); index-- > 0;) {
278
+ const TextShadow &shadow = style.text_shadow[index];
279
+ float dx = resolveLength(shadow.dx, 0.0f, style.font_size, viewportWidth, viewportHeight);
280
+ float dy = resolveLength(shadow.dy, 0.0f, style.font_size, viewportWidth, viewportHeight);
281
+ float blur =
282
+ resolveLength(shadow.blur, 0.0f, style.font_size, viewportWidth, viewportHeight);
283
+ Color shadowColor = shadow.has_color ? filterColor(chain, shadow.color) : color;
284
+ for (const Tap &tap : blurTaps(blur)) {
285
+ Color copy = shadowColor;
286
+ if (blur > 0.0f) copy.a *= kBlurTapWeight;
287
+ emit(dx + tap.dx, dy + tap.dy, copy, true);
288
+ }
289
+ }
290
+
291
+ /* `filter: blur()` spreads the glyphs themselves. */
292
+ if (chain.blur > 0.0f) {
293
+ for (const Tap &tap : blurTaps(chain.blur)) {
294
+ Color copy = color;
295
+ copy.a *= kBlurTapWeight;
296
+ emit(tap.dx, tap.dy, copy, false);
297
+ }
298
+ return;
299
+ }
300
+ emit(0.0f, 0.0f, color, false);
301
+ }
302
+
303
+ void addImage(DisplayList &out, PaintImage image, const PaintClip &clip,
304
+ const FilterChain &chain) {
305
+ if (image.width <= 0.0f || image.height <= 0.0f) return;
306
+ image.tint = imageTint(chain);
307
+ if (image.tint.a <= 0.0f) return;
308
+ if (chain.blur <= 0.0f) {
309
+ out.images.push_back(std::move(image));
310
+ out.ops.push_back(PaintOp{PaintKind::Image, (uint32_t)(out.images.size() - 1), clip});
311
+ return;
312
+ }
313
+ for (const Tap &tap : blurTaps(chain.blur)) {
314
+ PaintImage copy = image;
315
+ copy.x += tap.dx;
316
+ copy.y += tap.dy;
317
+ copy.tint.a *= kBlurTapWeight;
318
+ out.images.push_back(std::move(copy));
319
+ out.ops.push_back(PaintOp{PaintKind::Image, (uint32_t)(out.images.size() - 1), clip});
320
+ }
321
+ }
322
+
323
+ } // namespace paint_detail
324
+ } // namespace xtgui
@@ -0,0 +1,85 @@
1
+ /*
2
+ * xbintsc GUI engine — shared paint helpers.
3
+ *
4
+ * `paint.cpp` owns the tree walk; the background, effect and clip-path
5
+ * translation units fill in the shapes. They all append through the small
6
+ * `addRect` / `addText` / `addImage` helpers here so painter order and the
7
+ * active clip stay consistent.
8
+ */
9
+ #ifndef XT_GUI_PAINT_INTERNAL_H
10
+ #define XT_GUI_PAINT_INTERNAL_H
11
+
12
+ #include <string>
13
+ #include <vector>
14
+
15
+ #include "paint.h"
16
+ #include "style.h"
17
+
18
+ namespace xtgui {
19
+ namespace paint_detail {
20
+
21
+ /** A resolved chain of `filter` functions. `filter` applies to the element and
22
+ * its subtree, so it accumulates down the tree. Only the colour functions are
23
+ * group-accurate; blur and drop-shadow are approximated per shape (see the
24
+ * docs). */
25
+ struct FilterChain {
26
+ std::vector<FilterOp> ops; // colour functions (and any unknown no-ops)
27
+ float blur = 0.0f; // resolved px
28
+ struct Shadow {
29
+ float dx = 0.0f;
30
+ float dy = 0.0f;
31
+ float blur = 0.0f;
32
+ Color color;
33
+ };
34
+ std::vector<Shadow> shadows;
35
+
36
+ bool empty() const { return ops.empty() && blur <= 0.0f && shadows.empty(); }
37
+ };
38
+
39
+ /** Append `filters` (declared on a box with `style`) to `parent`. */
40
+ FilterChain extendFilter(const FilterChain &parent, const std::vector<FilterOp> &filters,
41
+ const XtStyle &style, float viewportWidth, float viewportHeight);
42
+
43
+ /** Apply the colour half of a filter chain. */
44
+ Color filterColor(const FilterChain &chain, Color color);
45
+
46
+ /** The multiplicative tint an image shader can carry (brightness/opacity). */
47
+ Color imageTint(const FilterChain &chain);
48
+
49
+ float resolveLength(const Length &length, float base, float em, float viewportWidth,
50
+ float viewportHeight);
51
+
52
+ /** Append one shape; skips empty geometry and fully transparent colours. */
53
+ void addRect(DisplayList &out, float x, float y, float width, float height, float radius,
54
+ const Color &color, const PaintClip &clip, const Matrix2D &transform);
55
+ /** Solid rectangle with the chain's blur spread into offset copies. */
56
+ void addRectFiltered(DisplayList &out, float x, float y, float width, float height, float radius,
57
+ const Color &color, const PaintClip &clip, const Matrix2D &transform,
58
+ const FilterChain &chain);
59
+ /** Add a text run (and its shadows/blur copies) for one laid-out fragment. */
60
+ void addTextRun(DisplayList &out, float x, float baseline, float width, float height,
61
+ const std::string &text, const FontSpec &font, const Color &color,
62
+ const Matrix2D &transform, const PaintClip &clip, const XtStyle &style,
63
+ const FilterChain &chain, float viewportWidth, float viewportHeight);
64
+ void addImage(DisplayList &out, PaintImage image, const PaintClip &clip, const FilterChain &chain);
65
+
66
+ /** Paint the `background-color` and every `background-image` layer. */
67
+ void paintBackgrounds(DisplayList &out, const LayoutBox &box, const XtStyle &style,
68
+ const FilterChain &chain, const PaintClip &clip, float viewportWidth,
69
+ float viewportHeight);
70
+
71
+ /** Append the drop-shadow silhouettes of a box (once, before its content). */
72
+ void addBoxDropShadows(DisplayList &out, const LayoutBox &box, const XtStyle &style,
73
+ const FilterChain &chain, const PaintClip &clip);
74
+
75
+ /** Resolve `clip-path` into a device-space triangulated polygon. */
76
+ int addClipPathForBox(DisplayList &out, const LayoutBox &box, const XtStyle &style,
77
+ float viewportWidth, float viewportHeight);
78
+
79
+ /** Push `index` onto a clip chain (at most two survive). */
80
+ PaintClip addClipPath(PaintClip clip, int index);
81
+
82
+ } // namespace paint_detail
83
+ } // namespace xtgui
84
+
85
+ #endif /* XT_GUI_PAINT_INTERNAL_H */
@@ -39,35 +39,6 @@ bool g_atlas_dirty = false;
39
39
  int g_atlas_dirty_x0 = 0, g_atlas_dirty_y0 = 0, g_atlas_dirty_x1 = 0, g_atlas_dirty_y1 = 0;
40
40
  bool g_atlas_full_logged = false;
41
41
 
42
- void pushRect(std::vector<Vertex> &verts, const xtgui::PaintRect &rect) {
43
- float hw = rect.width * 0.5f;
44
- float hh = rect.height * 0.5f;
45
- float cx = rect.x + hw;
46
- float cy = rect.y + hh;
47
- float radius = std::min(rect.radius, std::min(hw, hh));
48
-
49
- const float local_x[4] = {-hw, hw, hw, -hw};
50
- const float local_y[4] = {-hh, -hh, hh, hh};
51
- Vertex corners[4];
52
- for (int i = 0; i < 4; i++) {
53
- /* `local` keeps the distance-field coordinates in the box's own frame, so
54
- * a rotated/scaled shape still gets a rounded rectangle (the radius scales
55
- * with the matrix instead of staying circular). */
56
- rect.transform.apply(cx + local_x[i], cy + local_y[i], &corners[i].x, &corners[i].y);
57
- corners[i].lx = local_x[i];
58
- corners[i].ly = local_y[i];
59
- corners[i].hx = hw;
60
- corners[i].hy = hh;
61
- corners[i].radius = radius;
62
- corners[i].r = rect.color.r;
63
- corners[i].g = rect.color.g;
64
- corners[i].b = rect.color.b;
65
- corners[i].a = rect.color.a;
66
- }
67
- static const int order[6] = {0, 1, 2, 0, 2, 3};
68
- for (int i = 0; i < 6; i++) verts.push_back(corners[order[i]]);
69
- }
70
-
71
42
  /** Upload `count` vertices (of `stride` bytes) into `geometry`, reusing or
72
43
  * growing its GPU buffer. Does nothing when `count` is zero. */
73
44
  void uploadVertices(SDL_GPUDevice *device, XtGuiGeometry *geometry, const void *data,
@@ -277,8 +248,14 @@ void xt_gui_geometry_upload(SDL_GPUDevice *device, XtGuiGeometry *geometry,
277
248
  using namespace xtgui::renderer_detail;
278
249
  std::vector<Vertex> verts;
279
250
  verts.reserve(list.rects.size() * 6);
280
- geometry->op_counts.assign(list.rects.size(), 6);
281
- for (const xtgui::PaintRect &rect : list.rects) pushRect(verts, rect);
251
+ geometry->op_counts.assign(list.rects.size(), 0);
252
+ /* Walk painter order so each rectangle carries its op's clip path. */
253
+ for (const xtgui::PaintOp &op : list.ops) {
254
+ if (op.kind != xtgui::PaintKind::Rect || op.index >= list.rects.size()) continue;
255
+ uint32_t before = (uint32_t)verts.size();
256
+ pushShape(verts, list.rects[op.index], op.clip, list);
257
+ geometry->op_counts[op.index] = (uint32_t)verts.size() - before;
258
+ }
282
259
  uploadVertices(device, geometry, verts.data(), (uint32_t)verts.size(), sizeof(Vertex));
283
260
  }
284
261
 
@@ -0,0 +1,196 @@
1
+ /*
2
+ * xbintsc GUI engine — CPU geometry clipping for `clip-path`.
3
+ *
4
+ * Every painted shape is a convex quad. The paint pass leaves each clip path as
5
+ * a triangulated device-space polygon; clipping a convex quad by one triangle
6
+ * keeps it convex, so the result is emitted as a triangle fan. Clipping against
7
+ * a concave path is correct because its triangles partition the path.
8
+ */
9
+
10
+ #include "renderer_internal.h"
11
+
12
+ #include <algorithm>
13
+ #include <vector>
14
+
15
+ namespace xtgui {
16
+ namespace renderer_detail {
17
+
18
+ namespace {
19
+
20
+ float side(const ClipTriangle &triangle, int edge, float x, float y) {
21
+ int next = (edge + 1) % 3;
22
+ float ax = triangle.x[edge];
23
+ float ay = triangle.y[edge];
24
+ float bx = triangle.x[next];
25
+ float by = triangle.y[next];
26
+ return (bx - ax) * (y - ay) - (by - ay) * (x - ax);
27
+ }
28
+
29
+ bool triangleOrientation(const ClipTriangle &triangle, float *orientation) {
30
+ float cross = (triangle.x[1] - triangle.x[0]) * (triangle.y[2] - triangle.y[0]) -
31
+ (triangle.y[1] - triangle.y[0]) * (triangle.x[2] - triangle.x[0]);
32
+ if (cross > -0.00001f && cross < 0.00001f) return false;
33
+ *orientation = cross > 0.0f ? 1.0f : -1.0f;
34
+ return true;
35
+ }
36
+
37
+ template <typename V, typename Mix>
38
+ std::vector<V> clipToTriangle(const std::vector<V> &subject, const ClipTriangle &triangle,
39
+ Mix mix) {
40
+ float orientation = 0.0f;
41
+ if (!triangleOrientation(triangle, &orientation)) return std::vector<V>();
42
+ std::vector<V> out = subject;
43
+ for (int edge = 0; edge < 3 && !out.empty(); edge++) {
44
+ std::vector<V> input = out;
45
+ out.clear();
46
+ for (size_t i = 0; i < input.size(); i++) {
47
+ const V &current = input[i];
48
+ const V &previous = input[(i + input.size() - 1) % input.size()];
49
+ float currentSide = side(triangle, edge, current.x, current.y) * orientation;
50
+ float previousSide = side(triangle, edge, previous.x, previous.y) * orientation;
51
+ bool currentInside = currentSide >= -0.0001f;
52
+ bool previousInside = previousSide >= -0.0001f;
53
+ if (currentInside) {
54
+ if (!previousInside) {
55
+ float t = previousSide / (previousSide - currentSide);
56
+ out.push_back(mix(previous, current, t));
57
+ }
58
+ out.push_back(current);
59
+ } else if (previousInside) {
60
+ float t = previousSide / (previousSide - currentSide);
61
+ out.push_back(mix(previous, current, t));
62
+ }
63
+ }
64
+ }
65
+ return out;
66
+ }
67
+
68
+ template <typename V>
69
+ void appendFan(const std::vector<V> &polygon, std::vector<V> *out) {
70
+ for (size_t i = 1; i + 1 < polygon.size(); i++) {
71
+ out->push_back(polygon[0]);
72
+ out->push_back(polygon[i]);
73
+ out->push_back(polygon[i + 1]);
74
+ }
75
+ }
76
+
77
+ const ClipPathGeometry *pathAt(const DisplayList &list, int index) {
78
+ if (index < 0 || (size_t)index >= list.clip_paths.size()) return nullptr;
79
+ return &list.clip_paths[(size_t)index];
80
+ }
81
+
82
+ template <typename V, typename Mix>
83
+ uint32_t appendClipped(std::vector<V> &out, const std::vector<V> &quad, const PaintClip &clip,
84
+ const DisplayList &list, Mix mix) {
85
+ if (clip.path_count <= 0) {
86
+ appendFan(quad, &out);
87
+ return 6;
88
+ }
89
+ const ClipPathGeometry *first = pathAt(list, clip.paths[0]);
90
+ if (first == nullptr || first->triangles.empty()) return 0;
91
+ uint32_t before = (uint32_t)out.size();
92
+ if (clip.path_count == 1) {
93
+ for (const ClipTriangle &triangle : first->triangles) {
94
+ std::vector<V> clipped = clipToTriangle(quad, triangle, mix);
95
+ if (clipped.size() >= 3) appendFan(clipped, &out);
96
+ }
97
+ } else {
98
+ const ClipPathGeometry *second = pathAt(list, clip.paths[1]);
99
+ if (second == nullptr || second->triangles.empty()) return 0;
100
+ for (const ClipTriangle &outer : first->triangles) {
101
+ std::vector<V> firstClip = clipToTriangle(quad, outer, mix);
102
+ if (firstClip.size() < 3) continue;
103
+ for (const ClipTriangle &inner : second->triangles) {
104
+ std::vector<V> secondClip = clipToTriangle(firstClip, inner, mix);
105
+ if (secondClip.size() >= 3) appendFan(secondClip, &out);
106
+ }
107
+ }
108
+ }
109
+ return (uint32_t)out.size() - before;
110
+ }
111
+
112
+ Vertex mixVertex(const Vertex &a, const Vertex &b, float t) {
113
+ Vertex out;
114
+ out.x = a.x + (b.x - a.x) * t;
115
+ out.y = a.y + (b.y - a.y) * t;
116
+ out.lx = a.lx + (b.lx - a.lx) * t;
117
+ out.ly = a.ly + (b.ly - a.ly) * t;
118
+ out.hx = a.hx + (b.hx - a.hx) * t;
119
+ out.hy = a.hy + (b.hy - a.hy) * t;
120
+ out.radius = a.radius + (b.radius - a.radius) * t;
121
+ out.r = a.r + (b.r - a.r) * t;
122
+ out.g = a.g + (b.g - a.g) * t;
123
+ out.b = a.b + (b.b - a.b) * t;
124
+ out.a = a.a + (b.a - a.a) * t;
125
+ return out;
126
+ }
127
+
128
+ TextVertex mixTextVertex(const TextVertex &a, const TextVertex &b, float t) {
129
+ TextVertex out;
130
+ out.x = a.x + (b.x - a.x) * t;
131
+ out.y = a.y + (b.y - a.y) * t;
132
+ out.u = a.u + (b.u - a.u) * t;
133
+ out.v = a.v + (b.v - a.v) * t;
134
+ out.r = a.r + (b.r - a.r) * t;
135
+ out.g = a.g + (b.g - a.g) * t;
136
+ out.b = a.b + (b.b - a.b) * t;
137
+ out.a = a.a + (b.a - a.a) * t;
138
+ return out;
139
+ }
140
+
141
+ } // namespace
142
+
143
+ uint32_t pushShape(std::vector<Vertex> &verts, const PaintRect &rect, const PaintClip &clip,
144
+ const DisplayList &list) {
145
+ float hw = rect.width * 0.5f;
146
+ float hh = rect.height * 0.5f;
147
+ float cx = rect.x + hw;
148
+ float cy = rect.y + hh;
149
+ float radius = std::min(rect.radius, std::min(hw, hh));
150
+ const float local_x[4] = {-hw, hw, hw, -hw};
151
+ const float local_y[4] = {-hh, -hh, hh, hh};
152
+ std::vector<Vertex> quad(4);
153
+ for (int i = 0; i < 4; i++) {
154
+ rect.transform.apply(cx + local_x[i], cy + local_y[i], &quad[i].x, &quad[i].y);
155
+ quad[i].lx = local_x[i];
156
+ quad[i].ly = local_y[i];
157
+ quad[i].hx = hw;
158
+ quad[i].hy = hh;
159
+ quad[i].radius = radius;
160
+ quad[i].r = rect.color.r;
161
+ quad[i].g = rect.color.g;
162
+ quad[i].b = rect.color.b;
163
+ quad[i].a = rect.color.a;
164
+ }
165
+ return appendClipped(verts, quad, clip, list, mixVertex);
166
+ }
167
+
168
+ uint32_t pushQuad(std::vector<TextVertex> &verts, const float corners_x[4],
169
+ const float corners_y[4], const float u[4], const float v[4],
170
+ const Color &color, const Matrix2D &transform, const PaintClip &clip,
171
+ const DisplayList &list) {
172
+ std::vector<TextVertex> quad(4);
173
+ for (int i = 0; i < 4; i++) {
174
+ transform.apply(corners_x[i], corners_y[i], &quad[i].x, &quad[i].y);
175
+ quad[i].u = u[i];
176
+ quad[i].v = v[i];
177
+ quad[i].r = color.r;
178
+ quad[i].g = color.g;
179
+ quad[i].b = color.b;
180
+ quad[i].a = color.a;
181
+ }
182
+ return appendClipped(verts, quad, clip, list, mixTextVertex);
183
+ }
184
+
185
+ uint32_t pushGlyph(std::vector<TextVertex> &verts, float x, float y, float width, float height,
186
+ const GlyphEntry &entry, const Color &color, const Matrix2D &transform,
187
+ const PaintClip &clip, const DisplayList &list) {
188
+ const float corners_x[4] = {x, x + width, x + width, x};
189
+ const float corners_y[4] = {y, y, y + height, y + height};
190
+ const float u[4] = {entry.u0, entry.u1, entry.u1, entry.u0};
191
+ const float v[4] = {entry.v0, entry.v0, entry.v1, entry.v1};
192
+ return pushQuad(verts, corners_x, corners_y, u, v, color, transform, clip, list);
193
+ }
194
+
195
+ } // namespace renderer_detail
196
+ } // namespace xtgui