You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2401 lines
85KB

  1. /*
  2. Blendish - Blender 2.5 UI based theming functions for NanoVG
  3. Copyright (c) 2014 Leonard Ritter <leonard.ritter@duangle.com>
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. */
  20. #ifndef BLENDISH_H
  21. #define BLENDISH_H
  22. #ifndef NANOVG_H
  23. #error "nanovg.h must be included first."
  24. #endif
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. /*
  29. Revision 6 (2014-09-21)
  30. Summary
  31. -------
  32. Blendish is a small collection of drawing functions for NanoVG, designed to
  33. replicate the look of the Blender 2.5+ User Interface. You can use these
  34. functions to theme your UI library. Several metric constants for faithful
  35. reproduction are also included.
  36. Blendish supports the original Blender icon sheet; As the licensing of Blenders
  37. icons is unclear, they are not included in Blendishes repository, but a SVG
  38. template, "icons_template.svg" is provided, which you can use to build your own
  39. icon sheet.
  40. To use icons, you must first load the icon sheet using one of the
  41. nvgCreateImage*() functions and then pass the image handle to bndSetIconImage();
  42. otherwise, no icons will be drawn. See bndSetIconImage() for more information.
  43. Blendish will not render text until a suitable UI font has been passed to
  44. bndSetFont() has been called. See bndSetFont() for more information.
  45. Drawbacks
  46. ---------
  47. There is no support for varying dpi resolutions yet. The library is hardcoded
  48. to the equivalent of 72 dpi in the Blender system settings.
  49. Support for label truncation is missing. Text rendering breaks when widgets are
  50. too short to contain their labels.
  51. Usage
  52. -----
  53. To use this header file in implementation mode, define BLENDISH_IMPLEMENTATION
  54. before including blendish.h, otherwise the file will be in header-only mode.
  55. */
  56. // you can override this from the outside to pick
  57. // the export level you need
  58. #ifndef BND_EXPORT
  59. #define BND_EXPORT
  60. #endif
  61. // if that typedef is provided elsewhere, you may define
  62. // BLENDISH_NO_NVG_TYPEDEFS before including the header.
  63. #ifndef BLENDISH_NO_NVG_TYPEDEFS
  64. typedef struct NVGcontext NVGcontext;
  65. typedef struct NVGcolor NVGcolor;
  66. typedef struct NVGglyphPosition NVGglyphPosition;
  67. #endif
  68. // describes the theme used to draw a single widget or widget box;
  69. // these values correspond to the same values that can be retrieved from
  70. // the Theme panel in the Blender preferences
  71. typedef struct BNDwidgetTheme {
  72. // color of widget box outline
  73. NVGcolor outlineColor;
  74. // color of widget item (meaning changes depending on class)
  75. NVGcolor itemColor;
  76. // fill color of widget box
  77. NVGcolor innerColor;
  78. // fill color of widget box when active
  79. NVGcolor innerSelectedColor;
  80. // color of text label
  81. NVGcolor textColor;
  82. // color of text label when active
  83. NVGcolor textSelectedColor;
  84. // delta modifier for upper part of gradient (-100 to 100)
  85. int shadeTop;
  86. // delta modifier for lower part of gradient (-100 to 100)
  87. int shadeDown;
  88. } BNDwidgetTheme;
  89. // describes the theme used to draw nodes
  90. typedef struct BNDnodeTheme {
  91. // inner color of selected node (and downarrow)
  92. NVGcolor nodeSelectedColor;
  93. // outline of wires
  94. NVGcolor wiresColor;
  95. // color of text label when active
  96. NVGcolor textSelectedColor;
  97. // inner color of active node (and dragged wire)
  98. NVGcolor activeNodeColor;
  99. // color of selected wire
  100. NVGcolor wireSelectColor;
  101. // color of background of node
  102. NVGcolor nodeBackdropColor;
  103. // how much a noodle curves (0 to 10)
  104. int noodleCurving;
  105. } BNDnodeTheme;
  106. // describes the theme used to draw widgets
  107. typedef struct BNDtheme {
  108. // the background color of panels and windows
  109. NVGcolor backgroundColor;
  110. // theme for labels
  111. BNDwidgetTheme regularTheme;
  112. // theme for tool buttons
  113. BNDwidgetTheme toolTheme;
  114. // theme for radio buttons
  115. BNDwidgetTheme radioTheme;
  116. // theme for text fields
  117. BNDwidgetTheme textFieldTheme;
  118. // theme for option buttons (checkboxes)
  119. BNDwidgetTheme optionTheme;
  120. // theme for choice buttons (comboboxes)
  121. // Blender calls them "menu buttons"
  122. BNDwidgetTheme choiceTheme;
  123. // theme for number fields
  124. BNDwidgetTheme numberFieldTheme;
  125. // theme for slider controls
  126. BNDwidgetTheme sliderTheme;
  127. // theme for scrollbars
  128. BNDwidgetTheme scrollBarTheme;
  129. // theme for tooltips
  130. BNDwidgetTheme tooltipTheme;
  131. // theme for menu backgrounds
  132. BNDwidgetTheme menuTheme;
  133. // theme for menu items
  134. BNDwidgetTheme menuItemTheme;
  135. // theme for nodes
  136. BNDnodeTheme nodeTheme;
  137. } BNDtheme;
  138. // how text on a control is aligned
  139. typedef enum BNDtextAlignment {
  140. BND_LEFT = 0,
  141. BND_CENTER,
  142. } BNDtextAlignment;
  143. // states altering the styling of a widget
  144. typedef enum BNDwidgetState {
  145. // not interacting
  146. BND_DEFAULT = 0,
  147. // the mouse is hovering over the control
  148. BND_HOVER,
  149. // the widget is activated (pressed) or in an active state (toggled)
  150. BND_ACTIVE
  151. } BNDwidgetState;
  152. // flags indicating which corners are sharp (for grouping widgets)
  153. typedef enum BNDcornerFlags {
  154. // all corners are round
  155. BND_CORNER_NONE = 0,
  156. // sharp top left corner
  157. BND_CORNER_TOP_LEFT = 1,
  158. // sharp top right corner
  159. BND_CORNER_TOP_RIGHT = 2,
  160. // sharp bottom right corner
  161. BND_CORNER_DOWN_RIGHT = 4,
  162. // sharp bottom left corner
  163. BND_CORNER_DOWN_LEFT = 8,
  164. // all corners are sharp;
  165. // you can invert a set of flags using ^= BND_CORNER_ALL
  166. BND_CORNER_ALL = 0xF,
  167. // top border is sharp
  168. BND_CORNER_TOP = 3,
  169. // bottom border is sharp
  170. BND_CORNER_DOWN = 0xC,
  171. // left border is sharp
  172. BND_CORNER_LEFT = 9,
  173. // right border is sharp
  174. BND_CORNER_RIGHT = 6
  175. } BNDcornerFlags;
  176. // build an icon ID from two coordinates into the icon sheet, where
  177. // (0,0) designates the upper-leftmost icon, (1,0) the one right next to it,
  178. // and so on.
  179. #define BND_ICONID(x,y) ((x)|((y)<<8))
  180. // alpha of disabled widget groups
  181. // can be used in conjunction with nvgGlobalAlpha()
  182. #define BND_DISABLED_ALPHA 0.5
  183. enum {
  184. // default widget height
  185. BND_WIDGET_HEIGHT = 21,
  186. // default toolbutton width (if icon only)
  187. BND_TOOL_WIDTH = 20,
  188. // default radius of node ports
  189. BND_NODE_PORT_RADIUS = 5,
  190. // top margin of node content
  191. BND_NODE_MARGIN_TOP = 25,
  192. // bottom margin of node content
  193. BND_NODE_MARGIN_DOWN = 5,
  194. // left and right margin of node content
  195. BND_NODE_MARGIN_SIDE = 10,
  196. // height of node title bar
  197. BND_NODE_TITLE_HEIGHT = 20,
  198. // width of node title arrow click area
  199. BND_NODE_ARROW_AREA_WIDTH = 20,
  200. // size of splitter corner click area
  201. BND_SPLITTER_AREA_SIZE = 12,
  202. // width of vertical scrollbar
  203. BND_SCROLLBAR_WIDTH = 13,
  204. // height of horizontal scrollbar
  205. BND_SCROLLBAR_HEIGHT = 14,
  206. // default vertical spacing
  207. BND_VSPACING = 1,
  208. // default vertical spacing between groups
  209. BND_VSPACING_GROUP = 8,
  210. // default horizontal spacing
  211. BND_HSPACING = 8,
  212. };
  213. typedef enum BNDicon {
  214. BND_ICON_NONE = BND_ICONID(0,29),
  215. BND_ICON_QUESTION = BND_ICONID(1,29),
  216. BND_ICON_ERROR = BND_ICONID(2,29),
  217. BND_ICON_CANCEL = BND_ICONID(3,29),
  218. BND_ICON_TRIA_RIGHT = BND_ICONID(4,29),
  219. BND_ICON_TRIA_DOWN = BND_ICONID(5,29),
  220. BND_ICON_TRIA_LEFT = BND_ICONID(6,29),
  221. BND_ICON_TRIA_UP = BND_ICONID(7,29),
  222. BND_ICON_ARROW_LEFTRIGHT = BND_ICONID(8,29),
  223. BND_ICON_PLUS = BND_ICONID(9,29),
  224. BND_ICON_DISCLOSURE_TRI_DOWN = BND_ICONID(10,29),
  225. BND_ICON_DISCLOSURE_TRI_RIGHT = BND_ICONID(11,29),
  226. BND_ICON_RADIOBUT_OFF = BND_ICONID(12,29),
  227. BND_ICON_RADIOBUT_ON = BND_ICONID(13,29),
  228. BND_ICON_MENU_PANEL = BND_ICONID(14,29),
  229. BND_ICON_BLENDER = BND_ICONID(15,29),
  230. BND_ICON_GRIP = BND_ICONID(16,29),
  231. BND_ICON_DOT = BND_ICONID(17,29),
  232. BND_ICON_COLLAPSEMENU = BND_ICONID(18,29),
  233. BND_ICON_X = BND_ICONID(19,29),
  234. BND_ICON_GO_LEFT = BND_ICONID(21,29),
  235. BND_ICON_PLUG = BND_ICONID(22,29),
  236. BND_ICON_UI = BND_ICONID(23,29),
  237. BND_ICON_NODE = BND_ICONID(24,29),
  238. BND_ICON_NODE_SEL = BND_ICONID(25,29),
  239. BND_ICON_FULLSCREEN = BND_ICONID(0,28),
  240. BND_ICON_SPLITSCREEN = BND_ICONID(1,28),
  241. BND_ICON_RIGHTARROW_THIN = BND_ICONID(2,28),
  242. BND_ICON_BORDERMOVE = BND_ICONID(3,28),
  243. BND_ICON_VIEWZOOM = BND_ICONID(4,28),
  244. BND_ICON_ZOOMIN = BND_ICONID(5,28),
  245. BND_ICON_ZOOMOUT = BND_ICONID(6,28),
  246. BND_ICON_PANEL_CLOSE = BND_ICONID(7,28),
  247. BND_ICON_COPY_ID = BND_ICONID(8,28),
  248. BND_ICON_EYEDROPPER = BND_ICONID(9,28),
  249. BND_ICON_LINK_AREA = BND_ICONID(10,28),
  250. BND_ICON_AUTO = BND_ICONID(11,28),
  251. BND_ICON_CHECKBOX_DEHLT = BND_ICONID(12,28),
  252. BND_ICON_CHECKBOX_HLT = BND_ICONID(13,28),
  253. BND_ICON_UNLOCKED = BND_ICONID(14,28),
  254. BND_ICON_LOCKED = BND_ICONID(15,28),
  255. BND_ICON_UNPINNED = BND_ICONID(16,28),
  256. BND_ICON_PINNED = BND_ICONID(17,28),
  257. BND_ICON_SCREEN_BACK = BND_ICONID(18,28),
  258. BND_ICON_RIGHTARROW = BND_ICONID(19,28),
  259. BND_ICON_DOWNARROW_HLT = BND_ICONID(20,28),
  260. BND_ICON_DOTSUP = BND_ICONID(21,28),
  261. BND_ICON_DOTSDOWN = BND_ICONID(22,28),
  262. BND_ICON_LINK = BND_ICONID(23,28),
  263. BND_ICON_INLINK = BND_ICONID(24,28),
  264. BND_ICON_PLUGIN = BND_ICONID(25,28),
  265. BND_ICON_HELP = BND_ICONID(0,27),
  266. BND_ICON_GHOST_ENABLED = BND_ICONID(1,27),
  267. BND_ICON_COLOR = BND_ICONID(2,27),
  268. BND_ICON_LINKED = BND_ICONID(3,27),
  269. BND_ICON_UNLINKED = BND_ICONID(4,27),
  270. BND_ICON_HAND = BND_ICONID(5,27),
  271. BND_ICON_ZOOM_ALL = BND_ICONID(6,27),
  272. BND_ICON_ZOOM_SELECTED = BND_ICONID(7,27),
  273. BND_ICON_ZOOM_PREVIOUS = BND_ICONID(8,27),
  274. BND_ICON_ZOOM_IN = BND_ICONID(9,27),
  275. BND_ICON_ZOOM_OUT = BND_ICONID(10,27),
  276. BND_ICON_RENDER_REGION = BND_ICONID(11,27),
  277. BND_ICON_BORDER_RECT = BND_ICONID(12,27),
  278. BND_ICON_BORDER_LASSO = BND_ICONID(13,27),
  279. BND_ICON_FREEZE = BND_ICONID(14,27),
  280. BND_ICON_STYLUS_PRESSURE = BND_ICONID(15,27),
  281. BND_ICON_GHOST_DISABLED = BND_ICONID(16,27),
  282. BND_ICON_NEW = BND_ICONID(17,27),
  283. BND_ICON_FILE_TICK = BND_ICONID(18,27),
  284. BND_ICON_QUIT = BND_ICONID(19,27),
  285. BND_ICON_URL = BND_ICONID(20,27),
  286. BND_ICON_RECOVER_LAST = BND_ICONID(21,27),
  287. BND_ICON_FULLSCREEN_ENTER = BND_ICONID(23,27),
  288. BND_ICON_FULLSCREEN_EXIT = BND_ICONID(24,27),
  289. BND_ICON_BLANK1 = BND_ICONID(25,27),
  290. BND_ICON_LAMP = BND_ICONID(0,26),
  291. BND_ICON_MATERIAL = BND_ICONID(1,26),
  292. BND_ICON_TEXTURE = BND_ICONID(2,26),
  293. BND_ICON_ANIM = BND_ICONID(3,26),
  294. BND_ICON_WORLD = BND_ICONID(4,26),
  295. BND_ICON_SCENE = BND_ICONID(5,26),
  296. BND_ICON_EDIT = BND_ICONID(6,26),
  297. BND_ICON_GAME = BND_ICONID(7,26),
  298. BND_ICON_RADIO = BND_ICONID(8,26),
  299. BND_ICON_SCRIPT = BND_ICONID(9,26),
  300. BND_ICON_PARTICLES = BND_ICONID(10,26),
  301. BND_ICON_PHYSICS = BND_ICONID(11,26),
  302. BND_ICON_SPEAKER = BND_ICONID(12,26),
  303. BND_ICON_TEXTURE_SHADED = BND_ICONID(13,26),
  304. BND_ICON_VIEW3D = BND_ICONID(0,25),
  305. BND_ICON_IPO = BND_ICONID(1,25),
  306. BND_ICON_OOPS = BND_ICONID(2,25),
  307. BND_ICON_BUTS = BND_ICONID(3,25),
  308. BND_ICON_FILESEL = BND_ICONID(4,25),
  309. BND_ICON_IMAGE_COL = BND_ICONID(5,25),
  310. BND_ICON_INFO = BND_ICONID(6,25),
  311. BND_ICON_SEQUENCE = BND_ICONID(7,25),
  312. BND_ICON_TEXT = BND_ICONID(8,25),
  313. BND_ICON_IMASEL = BND_ICONID(9,25),
  314. BND_ICON_SOUND = BND_ICONID(10,25),
  315. BND_ICON_ACTION = BND_ICONID(11,25),
  316. BND_ICON_NLA = BND_ICONID(12,25),
  317. BND_ICON_SCRIPTWIN = BND_ICONID(13,25),
  318. BND_ICON_TIME = BND_ICONID(14,25),
  319. BND_ICON_NODETREE = BND_ICONID(15,25),
  320. BND_ICON_LOGIC = BND_ICONID(16,25),
  321. BND_ICON_CONSOLE = BND_ICONID(17,25),
  322. BND_ICON_PREFERENCES = BND_ICONID(18,25),
  323. BND_ICON_CLIP = BND_ICONID(19,25),
  324. BND_ICON_ASSET_MANAGER = BND_ICONID(20,25),
  325. BND_ICON_OBJECT_DATAMODE = BND_ICONID(0,24),
  326. BND_ICON_EDITMODE_HLT = BND_ICONID(1,24),
  327. BND_ICON_FACESEL_HLT = BND_ICONID(2,24),
  328. BND_ICON_VPAINT_HLT = BND_ICONID(3,24),
  329. BND_ICON_TPAINT_HLT = BND_ICONID(4,24),
  330. BND_ICON_WPAINT_HLT = BND_ICONID(5,24),
  331. BND_ICON_SCULPTMODE_HLT = BND_ICONID(6,24),
  332. BND_ICON_POSE_HLT = BND_ICONID(7,24),
  333. BND_ICON_PARTICLEMODE = BND_ICONID(8,24),
  334. BND_ICON_LIGHTPAINT = BND_ICONID(9,24),
  335. BND_ICON_SCENE_DATA = BND_ICONID(0,23),
  336. BND_ICON_RENDERLAYERS = BND_ICONID(1,23),
  337. BND_ICON_WORLD_DATA = BND_ICONID(2,23),
  338. BND_ICON_OBJECT_DATA = BND_ICONID(3,23),
  339. BND_ICON_MESH_DATA = BND_ICONID(4,23),
  340. BND_ICON_CURVE_DATA = BND_ICONID(5,23),
  341. BND_ICON_META_DATA = BND_ICONID(6,23),
  342. BND_ICON_LATTICE_DATA = BND_ICONID(7,23),
  343. BND_ICON_LAMP_DATA = BND_ICONID(8,23),
  344. BND_ICON_MATERIAL_DATA = BND_ICONID(9,23),
  345. BND_ICON_TEXTURE_DATA = BND_ICONID(10,23),
  346. BND_ICON_ANIM_DATA = BND_ICONID(11,23),
  347. BND_ICON_CAMERA_DATA = BND_ICONID(12,23),
  348. BND_ICON_PARTICLE_DATA = BND_ICONID(13,23),
  349. BND_ICON_LIBRARY_DATA_DIRECT = BND_ICONID(14,23),
  350. BND_ICON_GROUP = BND_ICONID(15,23),
  351. BND_ICON_ARMATURE_DATA = BND_ICONID(16,23),
  352. BND_ICON_POSE_DATA = BND_ICONID(17,23),
  353. BND_ICON_BONE_DATA = BND_ICONID(18,23),
  354. BND_ICON_CONSTRAINT = BND_ICONID(19,23),
  355. BND_ICON_SHAPEKEY_DATA = BND_ICONID(20,23),
  356. BND_ICON_CONSTRAINT_BONE = BND_ICONID(21,23),
  357. BND_ICON_CAMERA_STEREO = BND_ICONID(22,23),
  358. BND_ICON_PACKAGE = BND_ICONID(23,23),
  359. BND_ICON_UGLYPACKAGE = BND_ICONID(24,23),
  360. BND_ICON_BRUSH_DATA = BND_ICONID(0,22),
  361. BND_ICON_IMAGE_DATA = BND_ICONID(1,22),
  362. BND_ICON_FILE = BND_ICONID(2,22),
  363. BND_ICON_FCURVE = BND_ICONID(3,22),
  364. BND_ICON_FONT_DATA = BND_ICONID(4,22),
  365. BND_ICON_RENDER_RESULT = BND_ICONID(5,22),
  366. BND_ICON_SURFACE_DATA = BND_ICONID(6,22),
  367. BND_ICON_EMPTY_DATA = BND_ICONID(7,22),
  368. BND_ICON_SETTINGS = BND_ICONID(8,22),
  369. BND_ICON_RENDER_ANIMATION = BND_ICONID(9,22),
  370. BND_ICON_RENDER_STILL = BND_ICONID(10,22),
  371. BND_ICON_BOIDS = BND_ICONID(12,22),
  372. BND_ICON_STRANDS = BND_ICONID(13,22),
  373. BND_ICON_LIBRARY_DATA_INDIRECT = BND_ICONID(14,22),
  374. BND_ICON_GREASEPENCIL = BND_ICONID(15,22),
  375. BND_ICON_LINE_DATA = BND_ICONID(16,22),
  376. BND_ICON_GROUP_BONE = BND_ICONID(18,22),
  377. BND_ICON_GROUP_VERTEX = BND_ICONID(19,22),
  378. BND_ICON_GROUP_VCOL = BND_ICONID(20,22),
  379. BND_ICON_GROUP_UVS = BND_ICONID(21,22),
  380. BND_ICON_RNA = BND_ICONID(24,22),
  381. BND_ICON_RNA_ADD = BND_ICONID(25,22),
  382. BND_ICON_OUTLINER_OB_EMPTY = BND_ICONID(0,20),
  383. BND_ICON_OUTLINER_OB_MESH = BND_ICONID(1,20),
  384. BND_ICON_OUTLINER_OB_CURVE = BND_ICONID(2,20),
  385. BND_ICON_OUTLINER_OB_LATTICE = BND_ICONID(3,20),
  386. BND_ICON_OUTLINER_OB_META = BND_ICONID(4,20),
  387. BND_ICON_OUTLINER_OB_LAMP = BND_ICONID(5,20),
  388. BND_ICON_OUTLINER_OB_CAMERA = BND_ICONID(6,20),
  389. BND_ICON_OUTLINER_OB_ARMATURE = BND_ICONID(7,20),
  390. BND_ICON_OUTLINER_OB_FONT = BND_ICONID(8,20),
  391. BND_ICON_OUTLINER_OB_SURFACE = BND_ICONID(9,20),
  392. BND_ICON_OUTLINER_OB_SPEAKER = BND_ICONID(10,20),
  393. BND_ICON_RESTRICT_VIEW_OFF = BND_ICONID(19,20),
  394. BND_ICON_RESTRICT_VIEW_ON = BND_ICONID(20,20),
  395. BND_ICON_RESTRICT_SELECT_OFF = BND_ICONID(21,20),
  396. BND_ICON_RESTRICT_SELECT_ON = BND_ICONID(22,20),
  397. BND_ICON_RESTRICT_RENDER_OFF = BND_ICONID(23,20),
  398. BND_ICON_RESTRICT_RENDER_ON = BND_ICONID(24,20),
  399. BND_ICON_OUTLINER_DATA_EMPTY = BND_ICONID(0,19),
  400. BND_ICON_OUTLINER_DATA_MESH = BND_ICONID(1,19),
  401. BND_ICON_OUTLINER_DATA_CURVE = BND_ICONID(2,19),
  402. BND_ICON_OUTLINER_DATA_LATTICE = BND_ICONID(3,19),
  403. BND_ICON_OUTLINER_DATA_META = BND_ICONID(4,19),
  404. BND_ICON_OUTLINER_DATA_LAMP = BND_ICONID(5,19),
  405. BND_ICON_OUTLINER_DATA_CAMERA = BND_ICONID(6,19),
  406. BND_ICON_OUTLINER_DATA_ARMATURE = BND_ICONID(7,19),
  407. BND_ICON_OUTLINER_DATA_FONT = BND_ICONID(8,19),
  408. BND_ICON_OUTLINER_DATA_SURFACE = BND_ICONID(9,19),
  409. BND_ICON_OUTLINER_DATA_SPEAKER = BND_ICONID(10,19),
  410. BND_ICON_OUTLINER_DATA_POSE = BND_ICONID(11,19),
  411. BND_ICON_MESH_PLANE = BND_ICONID(0,18),
  412. BND_ICON_MESH_CUBE = BND_ICONID(1,18),
  413. BND_ICON_MESH_CIRCLE = BND_ICONID(2,18),
  414. BND_ICON_MESH_UVSPHERE = BND_ICONID(3,18),
  415. BND_ICON_MESH_ICOSPHERE = BND_ICONID(4,18),
  416. BND_ICON_MESH_GRID = BND_ICONID(5,18),
  417. BND_ICON_MESH_MONKEY = BND_ICONID(6,18),
  418. BND_ICON_MESH_CYLINDER = BND_ICONID(7,18),
  419. BND_ICON_MESH_TORUS = BND_ICONID(8,18),
  420. BND_ICON_MESH_CONE = BND_ICONID(9,18),
  421. BND_ICON_LAMP_POINT = BND_ICONID(12,18),
  422. BND_ICON_LAMP_SUN = BND_ICONID(13,18),
  423. BND_ICON_LAMP_SPOT = BND_ICONID(14,18),
  424. BND_ICON_LAMP_HEMI = BND_ICONID(15,18),
  425. BND_ICON_LAMP_AREA = BND_ICONID(16,18),
  426. BND_ICON_META_EMPTY = BND_ICONID(19,18),
  427. BND_ICON_META_PLANE = BND_ICONID(20,18),
  428. BND_ICON_META_CUBE = BND_ICONID(21,18),
  429. BND_ICON_META_BALL = BND_ICONID(22,18),
  430. BND_ICON_META_ELLIPSOID = BND_ICONID(23,18),
  431. BND_ICON_META_CAPSULE = BND_ICONID(24,18),
  432. BND_ICON_SURFACE_NCURVE = BND_ICONID(0,17),
  433. BND_ICON_SURFACE_NCIRCLE = BND_ICONID(1,17),
  434. BND_ICON_SURFACE_NSURFACE = BND_ICONID(2,17),
  435. BND_ICON_SURFACE_NCYLINDER = BND_ICONID(3,17),
  436. BND_ICON_SURFACE_NSPHERE = BND_ICONID(4,17),
  437. BND_ICON_SURFACE_NTORUS = BND_ICONID(5,17),
  438. BND_ICON_CURVE_BEZCURVE = BND_ICONID(9,17),
  439. BND_ICON_CURVE_BEZCIRCLE = BND_ICONID(10,17),
  440. BND_ICON_CURVE_NCURVE = BND_ICONID(11,17),
  441. BND_ICON_CURVE_NCIRCLE = BND_ICONID(12,17),
  442. BND_ICON_CURVE_PATH = BND_ICONID(13,17),
  443. BND_ICON_COLOR_RED = BND_ICONID(19,17),
  444. BND_ICON_COLOR_GREEN = BND_ICONID(20,17),
  445. BND_ICON_COLOR_BLUE = BND_ICONID(21,17),
  446. BND_ICON_FORCE_FORCE = BND_ICONID(0,16),
  447. BND_ICON_FORCE_WIND = BND_ICONID(1,16),
  448. BND_ICON_FORCE_VORTEX = BND_ICONID(2,16),
  449. BND_ICON_FORCE_MAGNETIC = BND_ICONID(3,16),
  450. BND_ICON_FORCE_HARMONIC = BND_ICONID(4,16),
  451. BND_ICON_FORCE_CHARGE = BND_ICONID(5,16),
  452. BND_ICON_FORCE_LENNARDJONES = BND_ICONID(6,16),
  453. BND_ICON_FORCE_TEXTURE = BND_ICONID(7,16),
  454. BND_ICON_FORCE_CURVE = BND_ICONID(8,16),
  455. BND_ICON_FORCE_BOID = BND_ICONID(9,16),
  456. BND_ICON_FORCE_TURBULENCE = BND_ICONID(10,16),
  457. BND_ICON_FORCE_DRAG = BND_ICONID(11,16),
  458. BND_ICON_FORCE_SMOKEFLOW = BND_ICONID(12,16),
  459. BND_ICON_MODIFIER = BND_ICONID(0,12),
  460. BND_ICON_MOD_WAVE = BND_ICONID(1,12),
  461. BND_ICON_MOD_BUILD = BND_ICONID(2,12),
  462. BND_ICON_MOD_DECIM = BND_ICONID(3,12),
  463. BND_ICON_MOD_MIRROR = BND_ICONID(4,12),
  464. BND_ICON_MOD_SOFT = BND_ICONID(5,12),
  465. BND_ICON_MOD_SUBSURF = BND_ICONID(6,12),
  466. BND_ICON_HOOK = BND_ICONID(7,12),
  467. BND_ICON_MOD_PHYSICS = BND_ICONID(8,12),
  468. BND_ICON_MOD_PARTICLES = BND_ICONID(9,12),
  469. BND_ICON_MOD_BOOLEAN = BND_ICONID(10,12),
  470. BND_ICON_MOD_EDGESPLIT = BND_ICONID(11,12),
  471. BND_ICON_MOD_ARRAY = BND_ICONID(12,12),
  472. BND_ICON_MOD_UVPROJECT = BND_ICONID(13,12),
  473. BND_ICON_MOD_DISPLACE = BND_ICONID(14,12),
  474. BND_ICON_MOD_CURVE = BND_ICONID(15,12),
  475. BND_ICON_MOD_LATTICE = BND_ICONID(16,12),
  476. BND_ICON_CONSTRAINT_DATA = BND_ICONID(17,12),
  477. BND_ICON_MOD_ARMATURE = BND_ICONID(18,12),
  478. BND_ICON_MOD_SHRINKWRAP = BND_ICONID(19,12),
  479. BND_ICON_MOD_CAST = BND_ICONID(20,12),
  480. BND_ICON_MOD_MESHDEFORM = BND_ICONID(21,12),
  481. BND_ICON_MOD_BEVEL = BND_ICONID(22,12),
  482. BND_ICON_MOD_SMOOTH = BND_ICONID(23,12),
  483. BND_ICON_MOD_SIMPLEDEFORM = BND_ICONID(24,12),
  484. BND_ICON_MOD_MASK = BND_ICONID(25,12),
  485. BND_ICON_MOD_CLOTH = BND_ICONID(0,11),
  486. BND_ICON_MOD_EXPLODE = BND_ICONID(1,11),
  487. BND_ICON_MOD_FLUIDSIM = BND_ICONID(2,11),
  488. BND_ICON_MOD_MULTIRES = BND_ICONID(3,11),
  489. BND_ICON_MOD_SMOKE = BND_ICONID(4,11),
  490. BND_ICON_MOD_SOLIDIFY = BND_ICONID(5,11),
  491. BND_ICON_MOD_SCREW = BND_ICONID(6,11),
  492. BND_ICON_MOD_VERTEX_WEIGHT = BND_ICONID(7,11),
  493. BND_ICON_MOD_DYNAMICPAINT = BND_ICONID(8,11),
  494. BND_ICON_MOD_REMESH = BND_ICONID(9,11),
  495. BND_ICON_MOD_OCEAN = BND_ICONID(10,11),
  496. BND_ICON_MOD_WARP = BND_ICONID(11,11),
  497. BND_ICON_MOD_SKIN = BND_ICONID(12,11),
  498. BND_ICON_MOD_TRIANGULATE = BND_ICONID(13,11),
  499. BND_ICON_MOD_WIREFRAME = BND_ICONID(14,11),
  500. BND_ICON_REC = BND_ICONID(0,10),
  501. BND_ICON_PLAY = BND_ICONID(1,10),
  502. BND_ICON_FF = BND_ICONID(2,10),
  503. BND_ICON_REW = BND_ICONID(3,10),
  504. BND_ICON_PAUSE = BND_ICONID(4,10),
  505. BND_ICON_PREV_KEYFRAME = BND_ICONID(5,10),
  506. BND_ICON_NEXT_KEYFRAME = BND_ICONID(6,10),
  507. BND_ICON_PLAY_AUDIO = BND_ICONID(7,10),
  508. BND_ICON_PLAY_REVERSE = BND_ICONID(8,10),
  509. BND_ICON_PREVIEW_RANGE = BND_ICONID(9,10),
  510. BND_ICON_ACTION_TWEAK = BND_ICONID(10,10),
  511. BND_ICON_PMARKER_ACT = BND_ICONID(11,10),
  512. BND_ICON_PMARKER_SEL = BND_ICONID(12,10),
  513. BND_ICON_PMARKER = BND_ICONID(13,10),
  514. BND_ICON_MARKER_HLT = BND_ICONID(14,10),
  515. BND_ICON_MARKER = BND_ICONID(15,10),
  516. BND_ICON_SPACE2 = BND_ICONID(16,10),
  517. BND_ICON_SPACE3 = BND_ICONID(17,10),
  518. BND_ICON_KEYINGSET = BND_ICONID(18,10),
  519. BND_ICON_KEY_DEHLT = BND_ICONID(19,10),
  520. BND_ICON_KEY_HLT = BND_ICONID(20,10),
  521. BND_ICON_MUTE_IPO_OFF = BND_ICONID(21,10),
  522. BND_ICON_MUTE_IPO_ON = BND_ICONID(22,10),
  523. BND_ICON_VISIBLE_IPO_OFF = BND_ICONID(23,10),
  524. BND_ICON_VISIBLE_IPO_ON = BND_ICONID(24,10),
  525. BND_ICON_DRIVER = BND_ICONID(25,10),
  526. BND_ICON_SOLO_OFF = BND_ICONID(0,9),
  527. BND_ICON_SOLO_ON = BND_ICONID(1,9),
  528. BND_ICON_FRAME_PREV = BND_ICONID(2,9),
  529. BND_ICON_FRAME_NEXT = BND_ICONID(3,9),
  530. BND_ICON_NLA_PUSHDOWN = BND_ICONID(4,9),
  531. BND_ICON_IPO_CONSTANT = BND_ICONID(5,9),
  532. BND_ICON_IPO_LINEAR = BND_ICONID(6,9),
  533. BND_ICON_IPO_BEZIER = BND_ICONID(7,9),
  534. BND_ICON_IPO_SINE = BND_ICONID(8,9),
  535. BND_ICON_IPO_QUAD = BND_ICONID(9,9),
  536. BND_ICON_IPO_CUBIC = BND_ICONID(10,9),
  537. BND_ICON_IPO_QUART = BND_ICONID(11,9),
  538. BND_ICON_IPO_QUINT = BND_ICONID(12,9),
  539. BND_ICON_IPO_EXPO = BND_ICONID(13,9),
  540. BND_ICON_IPO_CIRC = BND_ICONID(14,9),
  541. BND_ICON_IPO_BOUNCE = BND_ICONID(15,9),
  542. BND_ICON_IPO_ELASTIC = BND_ICONID(16,9),
  543. BND_ICON_IPO_BACK = BND_ICONID(17,9),
  544. BND_ICON_IPO_EASE_IN = BND_ICONID(18,9),
  545. BND_ICON_IPO_EASE_OUT = BND_ICONID(19,9),
  546. BND_ICON_IPO_EASE_IN_OUT = BND_ICONID(20,9),
  547. BND_ICON_VERTEXSEL = BND_ICONID(0,8),
  548. BND_ICON_EDGESEL = BND_ICONID(1,8),
  549. BND_ICON_FACESEL = BND_ICONID(2,8),
  550. BND_ICON_LOOPSEL = BND_ICONID(3,8),
  551. BND_ICON_ROTATE = BND_ICONID(5,8),
  552. BND_ICON_CURSOR = BND_ICONID(6,8),
  553. BND_ICON_ROTATECOLLECTION = BND_ICONID(7,8),
  554. BND_ICON_ROTATECENTER = BND_ICONID(8,8),
  555. BND_ICON_ROTACTIVE = BND_ICONID(9,8),
  556. BND_ICON_ALIGN = BND_ICONID(10,8),
  557. BND_ICON_SMOOTHCURVE = BND_ICONID(12,8),
  558. BND_ICON_SPHERECURVE = BND_ICONID(13,8),
  559. BND_ICON_ROOTCURVE = BND_ICONID(14,8),
  560. BND_ICON_SHARPCURVE = BND_ICONID(15,8),
  561. BND_ICON_LINCURVE = BND_ICONID(16,8),
  562. BND_ICON_NOCURVE = BND_ICONID(17,8),
  563. BND_ICON_RNDCURVE = BND_ICONID(18,8),
  564. BND_ICON_PROP_OFF = BND_ICONID(19,8),
  565. BND_ICON_PROP_ON = BND_ICONID(20,8),
  566. BND_ICON_PROP_CON = BND_ICONID(21,8),
  567. BND_ICON_SCULPT_DYNTOPO = BND_ICONID(22,8),
  568. BND_ICON_PARTICLE_POINT = BND_ICONID(23,8),
  569. BND_ICON_PARTICLE_TIP = BND_ICONID(24,8),
  570. BND_ICON_PARTICLE_PATH = BND_ICONID(25,8),
  571. BND_ICON_MAN_TRANS = BND_ICONID(0,7),
  572. BND_ICON_MAN_ROT = BND_ICONID(1,7),
  573. BND_ICON_MAN_SCALE = BND_ICONID(2,7),
  574. BND_ICON_MANIPUL = BND_ICONID(3,7),
  575. BND_ICON_SNAP_OFF = BND_ICONID(4,7),
  576. BND_ICON_SNAP_ON = BND_ICONID(5,7),
  577. BND_ICON_SNAP_NORMAL = BND_ICONID(6,7),
  578. BND_ICON_SNAP_INCREMENT = BND_ICONID(7,7),
  579. BND_ICON_SNAP_VERTEX = BND_ICONID(8,7),
  580. BND_ICON_SNAP_EDGE = BND_ICONID(9,7),
  581. BND_ICON_SNAP_FACE = BND_ICONID(10,7),
  582. BND_ICON_SNAP_VOLUME = BND_ICONID(11,7),
  583. BND_ICON_STICKY_UVS_LOC = BND_ICONID(13,7),
  584. BND_ICON_STICKY_UVS_DISABLE = BND_ICONID(14,7),
  585. BND_ICON_STICKY_UVS_VERT = BND_ICONID(15,7),
  586. BND_ICON_CLIPUV_DEHLT = BND_ICONID(16,7),
  587. BND_ICON_CLIPUV_HLT = BND_ICONID(17,7),
  588. BND_ICON_SNAP_PEEL_OBJECT = BND_ICONID(18,7),
  589. BND_ICON_GRID = BND_ICONID(19,7),
  590. BND_ICON_PASTEDOWN = BND_ICONID(0,6),
  591. BND_ICON_COPYDOWN = BND_ICONID(1,6),
  592. BND_ICON_PASTEFLIPUP = BND_ICONID(2,6),
  593. BND_ICON_PASTEFLIPDOWN = BND_ICONID(3,6),
  594. BND_ICON_SNAP_SURFACE = BND_ICONID(8,6),
  595. BND_ICON_AUTOMERGE_ON = BND_ICONID(9,6),
  596. BND_ICON_AUTOMERGE_OFF = BND_ICONID(10,6),
  597. BND_ICON_RETOPO = BND_ICONID(11,6),
  598. BND_ICON_UV_VERTEXSEL = BND_ICONID(12,6),
  599. BND_ICON_UV_EDGESEL = BND_ICONID(13,6),
  600. BND_ICON_UV_FACESEL = BND_ICONID(14,6),
  601. BND_ICON_UV_ISLANDSEL = BND_ICONID(15,6),
  602. BND_ICON_UV_SYNC_SELECT = BND_ICONID(16,6),
  603. BND_ICON_BBOX = BND_ICONID(0,5),
  604. BND_ICON_WIRE = BND_ICONID(1,5),
  605. BND_ICON_SOLID = BND_ICONID(2,5),
  606. BND_ICON_SMOOTH = BND_ICONID(3,5),
  607. BND_ICON_POTATO = BND_ICONID(4,5),
  608. BND_ICON_ORTHO = BND_ICONID(6,5),
  609. BND_ICON_LOCKVIEW_OFF = BND_ICONID(9,5),
  610. BND_ICON_LOCKVIEW_ON = BND_ICONID(10,5),
  611. BND_ICON_AXIS_SIDE = BND_ICONID(12,5),
  612. BND_ICON_AXIS_FRONT = BND_ICONID(13,5),
  613. BND_ICON_AXIS_TOP = BND_ICONID(14,5),
  614. BND_ICON_NDOF_DOM = BND_ICONID(15,5),
  615. BND_ICON_NDOF_TURN = BND_ICONID(16,5),
  616. BND_ICON_NDOF_FLY = BND_ICONID(17,5),
  617. BND_ICON_NDOF_TRANS = BND_ICONID(18,5),
  618. BND_ICON_LAYER_USED = BND_ICONID(19,5),
  619. BND_ICON_LAYER_ACTIVE = BND_ICONID(20,5),
  620. BND_ICON_SORTALPHA = BND_ICONID(0,3),
  621. BND_ICON_SORTBYEXT = BND_ICONID(1,3),
  622. BND_ICON_SORTTIME = BND_ICONID(2,3),
  623. BND_ICON_SORTSIZE = BND_ICONID(3,3),
  624. BND_ICON_LONGDISPLAY = BND_ICONID(4,3),
  625. BND_ICON_SHORTDISPLAY = BND_ICONID(5,3),
  626. BND_ICON_GHOST = BND_ICONID(6,3),
  627. BND_ICON_IMGDISPLAY = BND_ICONID(7,3),
  628. BND_ICON_SAVE_AS = BND_ICONID(8,3),
  629. BND_ICON_SAVE_COPY = BND_ICONID(9,3),
  630. BND_ICON_BOOKMARKS = BND_ICONID(10,3),
  631. BND_ICON_FONTPREVIEW = BND_ICONID(11,3),
  632. BND_ICON_FILTER = BND_ICONID(12,3),
  633. BND_ICON_NEWFOLDER = BND_ICONID(13,3),
  634. BND_ICON_OPEN_RECENT = BND_ICONID(14,3),
  635. BND_ICON_FILE_PARENT = BND_ICONID(15,3),
  636. BND_ICON_FILE_REFRESH = BND_ICONID(16,3),
  637. BND_ICON_FILE_FOLDER = BND_ICONID(17,3),
  638. BND_ICON_FILE_BLANK = BND_ICONID(18,3),
  639. BND_ICON_FILE_BLEND = BND_ICONID(19,3),
  640. BND_ICON_FILE_IMAGE = BND_ICONID(20,3),
  641. BND_ICON_FILE_MOVIE = BND_ICONID(21,3),
  642. BND_ICON_FILE_SCRIPT = BND_ICONID(22,3),
  643. BND_ICON_FILE_SOUND = BND_ICONID(23,3),
  644. BND_ICON_FILE_FONT = BND_ICONID(24,3),
  645. BND_ICON_FILE_TEXT = BND_ICONID(25,3),
  646. BND_ICON_RECOVER_AUTO = BND_ICONID(0,2),
  647. BND_ICON_SAVE_PREFS = BND_ICONID(1,2),
  648. BND_ICON_LINK_BLEND = BND_ICONID(2,2),
  649. BND_ICON_APPEND_BLEND = BND_ICONID(3,2),
  650. BND_ICON_IMPORT = BND_ICONID(4,2),
  651. BND_ICON_EXPORT = BND_ICONID(5,2),
  652. BND_ICON_EXTERNAL_DATA = BND_ICONID(6,2),
  653. BND_ICON_LOAD_FACTORY = BND_ICONID(7,2),
  654. BND_ICON_LOOP_BACK = BND_ICONID(13,2),
  655. BND_ICON_LOOP_FORWARDS = BND_ICONID(14,2),
  656. BND_ICON_BACK = BND_ICONID(15,2),
  657. BND_ICON_FORWARD = BND_ICONID(16,2),
  658. BND_ICON_FILE_BACKUP = BND_ICONID(24,2),
  659. BND_ICON_DISK_DRIVE = BND_ICONID(25,2),
  660. BND_ICON_MATPLANE = BND_ICONID(0,1),
  661. BND_ICON_MATSPHERE = BND_ICONID(1,1),
  662. BND_ICON_MATCUBE = BND_ICONID(2,1),
  663. BND_ICON_MONKEY = BND_ICONID(3,1),
  664. BND_ICON_HAIR = BND_ICONID(4,1),
  665. BND_ICON_ALIASED = BND_ICONID(5,1),
  666. BND_ICON_ANTIALIASED = BND_ICONID(6,1),
  667. BND_ICON_MAT_SPHERE_SKY = BND_ICONID(7,1),
  668. BND_ICON_WORDWRAP_OFF = BND_ICONID(12,1),
  669. BND_ICON_WORDWRAP_ON = BND_ICONID(13,1),
  670. BND_ICON_SYNTAX_OFF = BND_ICONID(14,1),
  671. BND_ICON_SYNTAX_ON = BND_ICONID(15,1),
  672. BND_ICON_LINENUMBERS_OFF = BND_ICONID(16,1),
  673. BND_ICON_LINENUMBERS_ON = BND_ICONID(17,1),
  674. BND_ICON_SCRIPTPLUGINS = BND_ICONID(18,1),
  675. BND_ICON_SEQ_SEQUENCER = BND_ICONID(0,0),
  676. BND_ICON_SEQ_PREVIEW = BND_ICONID(1,0),
  677. BND_ICON_SEQ_LUMA_WAVEFORM = BND_ICONID(2,0),
  678. BND_ICON_SEQ_CHROMA_SCOPE = BND_ICONID(3,0),
  679. BND_ICON_SEQ_HISTOGRAM = BND_ICONID(4,0),
  680. BND_ICON_SEQ_SPLITVIEW = BND_ICONID(5,0),
  681. BND_ICON_IMAGE_RGB = BND_ICONID(9,0),
  682. BND_ICON_IMAGE_RGB_ALPHA = BND_ICONID(10,0),
  683. BND_ICON_IMAGE_ALPHA = BND_ICONID(11,0),
  684. BND_ICON_IMAGE_ZDEPTH = BND_ICONID(12,0),
  685. BND_ICON_IMAGEFILE = BND_ICONID(13,0),
  686. } BNDicon;
  687. ////////////////////////////////////////////////////////////////////////////////
  688. // set the current theme all widgets will be drawn with.
  689. // the default Blender 2.6 theme is set by default.
  690. BND_EXPORT void bndSetTheme(BNDtheme theme);
  691. // Returns the currently set theme
  692. BND_EXPORT const BNDtheme *bndGetTheme();
  693. // designates an image handle as returned by nvgCreateImage*() as the themes'
  694. // icon sheet. The icon sheet format must be compatible to Blender 2.6's icon
  695. // sheet; the order of icons does not matter.
  696. // A valid icon sheet is e.g. shown at
  697. // http://wiki.blender.org/index.php/Dev:2.5/Doc/How_to/Add_an_icon
  698. BND_EXPORT void bndSetIconImage(int image);
  699. // designates an image handle as returned by nvgCreateFont*() as the themes'
  700. // UI font. Blender's original UI font Droid Sans is perfectly suited and
  701. // available here:
  702. // https://svn.blender.org/svnroot/bf-blender/trunk/blender/release/datafiles/fonts/
  703. BND_EXPORT void bndSetFont(int font);
  704. ////////////////////////////////////////////////////////////////////////////////
  705. // High Level Functions
  706. // --------------------
  707. // Use these functions to draw themed widgets with your NVGcontext.
  708. // Draw a label with its lower left origin at (x,y) and size of (w,h).
  709. // if iconid >= 0, an icon will be added to the widget
  710. // if label is not NULL, a label will be added to the widget
  711. // widget looks best when height is BND_WIDGET_HEIGHT
  712. BND_EXPORT void bndLabel(NVGcontext *ctx,
  713. float x, float y, float w, float h, int iconid, const char *label);
  714. // Draw a tool button with its lower left origin at (x,y) and size of (w,h),
  715. // where flags is one or multiple flags from BNDcornerFlags and state denotes
  716. // the widgets current UI state.
  717. // if iconid >= 0, an icon will be added to the widget
  718. // if label is not NULL, a label will be added to the widget
  719. // widget looks best when height is BND_WIDGET_HEIGHT
  720. BND_EXPORT void bndToolButton(NVGcontext *ctx,
  721. float x, float y, float w, float h, int flags, BNDwidgetState state,
  722. int iconid, const char *label);
  723. // Draw a radio button with its lower left origin at (x,y) and size of (w,h),
  724. // where flags is one or multiple flags from BNDcornerFlags and state denotes
  725. // the widgets current UI state.
  726. // if iconid >= 0, an icon will be added to the widget
  727. // if label is not NULL, a label will be added to the widget
  728. // widget looks best when height is BND_WIDGET_HEIGHT
  729. BND_EXPORT void bndRadioButton(NVGcontext *ctx,
  730. float x, float y, float w, float h, int flags, BNDwidgetState state,
  731. int iconid, const char *label);
  732. // Calculate the corresponding text position for given coordinates px/py
  733. // in a text field.
  734. // See bndTextField for more info.
  735. BND_EXPORT int bndTextFieldTextPosition(NVGcontext *ctx, float x, float y, float w, float h,
  736. int iconid, const char *text, int px, int py);
  737. // Draw a text field with its lower left origin at (x,y) and size of (w,h),
  738. // where flags is one or multiple flags from BNDcornerFlags and state denotes
  739. // the widgets current UI state.
  740. // if iconid >= 0, an icon will be added to the widget
  741. // if text is not NULL, text will be printed to the widget
  742. // cbegin must be >= 0 and <= strlen(text) and denotes the beginning of the caret
  743. // cend must be >= cbegin and <= strlen(text) and denotes the end of the caret
  744. // if cend < cbegin, then no caret will be drawn
  745. // widget looks best when height is BND_WIDGET_HEIGHT
  746. BND_EXPORT void bndTextField(NVGcontext *ctx,
  747. float x, float y, float w, float h, int flags, BNDwidgetState state,
  748. int iconid, const char *text, int cbegin, int cend);
  749. // Draw an option button with its lower left origin at (x,y) and size of (w,h),
  750. // where flags is one or multiple flags from BNDcornerFlags and state denotes
  751. // the widgets current UI state.
  752. // if label is not NULL, a label will be added to the widget
  753. // widget looks best when height is BND_WIDGET_HEIGHT
  754. BND_EXPORT void bndOptionButton(NVGcontext *ctx,
  755. float x, float y, float w, float h, BNDwidgetState state,
  756. const char *label);
  757. // Draw a choice button with its lower left origin at (x,y) and size of (w,h),
  758. // where flags is one or multiple flags from BNDcornerFlags and state denotes
  759. // the widgets current UI state.
  760. // if iconid >= 0, an icon will be added to the widget
  761. // if label is not NULL, a label will be added to the widget
  762. // widget looks best when height is BND_WIDGET_HEIGHT
  763. BND_EXPORT void bndChoiceButton(NVGcontext *ctx,
  764. float x, float y, float w, float h, int flags, BNDwidgetState state,
  765. int iconid, const char *label);
  766. // Draw a color button with its lower left origin at (x,y) and size of (w,h),
  767. // where flags is one or multiple flags from BNDcornerFlags and state denotes
  768. // the widgets current UI state.
  769. // widget looks best when height is BND_WIDGET_HEIGHT
  770. BND_EXPORT void bndColorButton(NVGcontext *ctx,
  771. float x, float y, float w, float h, int flags, NVGcolor color);
  772. // Draw a number field with its lower left origin at (x,y) and size of (w,h),
  773. // where flags is one or multiple flags from BNDcornerFlags and state denotes
  774. // the widgets current UI state.
  775. // if label is not NULL, a label will be added to the widget
  776. // if value is not NULL, a value will be added to the widget, along with
  777. // a ":" separator
  778. // widget looks best when height is BND_WIDGET_HEIGHT
  779. BND_EXPORT void bndNumberField(NVGcontext *ctx,
  780. float x, float y, float w, float h, int flags, BNDwidgetState state,
  781. const char *label, const char *value);
  782. // Draw slider control with its lower left origin at (x,y) and size of (w,h),
  783. // where flags is one or multiple flags from BNDcornerFlags and state denotes
  784. // the widgets current UI state.
  785. // progress must be in the range 0..1 and controls the size of the slider bar
  786. // if label is not NULL, a label will be added to the widget
  787. // if value is not NULL, a value will be added to the widget, along with
  788. // a ":" separator
  789. // widget looks best when height is BND_WIDGET_HEIGHT
  790. BND_EXPORT void bndSlider(NVGcontext *ctx,
  791. float x, float y, float w, float h, int flags, BNDwidgetState state,
  792. float progress, const char *label, const char *value);
  793. // Draw scrollbar with its lower left origin at (x,y) and size of (w,h),
  794. // where state denotes the widgets current UI state.
  795. // offset is in the range 0..1 and controls the position of the scroll handle
  796. // size is in the range 0..1 and controls the size of the scroll handle
  797. // horizontal widget looks best when height is BND_SCROLLBAR_HEIGHT,
  798. // vertical looks best when width is BND_SCROLLBAR_WIDTH
  799. BND_EXPORT void bndScrollBar(NVGcontext *ctx,
  800. float x, float y, float w, float h, BNDwidgetState state,
  801. float offset, float size);
  802. // Draw a menu background with its lower left origin at (x,y) and size of (w,h),
  803. // where flags is one or multiple flags from BNDcornerFlags.
  804. BND_EXPORT void bndMenuBackground(NVGcontext *ctx,
  805. float x, float y, float w, float h, int flags);
  806. // Draw a menu label with its lower left origin at (x,y) and size of (w,h).
  807. // if iconid >= 0, an icon will be added to the widget
  808. // if label is not NULL, a label will be added to the widget
  809. // widget looks best when height is BND_WIDGET_HEIGHT
  810. BND_EXPORT void bndMenuLabel(NVGcontext *ctx,
  811. float x, float y, float w, float h, int iconid, const char *label);
  812. // Draw a menu item with its lower left origin at (x,y) and size of (w,h),
  813. // where state denotes the widgets current UI state.
  814. // if iconid >= 0, an icon will be added to the widget
  815. // if label is not NULL, a label will be added to the widget
  816. // widget looks best when height is BND_WIDGET_HEIGHT
  817. BND_EXPORT void bndMenuItem(NVGcontext *ctx,
  818. float x, float y, float w, float h, BNDwidgetState state,
  819. int iconid, const char *label);
  820. // Draw a tooltip background with its lower left origin at (x,y) and size of (w,h)
  821. BND_EXPORT void bndTooltipBackground(NVGcontext *ctx, float x, float y, float w, float h);
  822. // Draw a node port at the given position filled with the given color
  823. BND_EXPORT void bndNodePort(NVGcontext *ctx, float x, float y, BNDwidgetState state,
  824. NVGcolor color);
  825. // Draw a node wire originating at (x0,y0) and floating to (x1,y1), with
  826. // a colored gradient based on the states state0 and state1:
  827. // BND_DEFAULT: default wire color
  828. // BND_HOVER: selected wire color
  829. // BND_ACTIVE: dragged wire color
  830. BND_EXPORT void bndNodeWire(NVGcontext *ctx, float x0, float y0, float x1, float y1,
  831. BNDwidgetState state0, BNDwidgetState state1);
  832. // Draw a node wire originating at (x0,y0) and floating to (x1,y1), with
  833. // a colored gradient based on the two colors color0 and color1
  834. BND_EXPORT void bndColoredNodeWire(NVGcontext *ctx, float x0, float y0, float x1, float y1,
  835. NVGcolor color0, NVGcolor color1);
  836. // Draw a node background with its upper left origin at (x,y) and size of (w,h)
  837. // where titleColor provides the base color for the title bar
  838. BND_EXPORT void bndNodeBackground(NVGcontext *ctx, float x, float y, float w, float h,
  839. BNDwidgetState state, int iconid, const char *label, NVGcolor titleColor);
  840. // Draw a window with the upper right and lower left splitter widgets into
  841. // the rectangle at origin (x,y) and size (w, h)
  842. BND_EXPORT void bndSplitterWidgets(NVGcontext *ctx, float x, float y, float w, float h);
  843. // Draw the join area overlay stencil into the rectangle
  844. // at origin (x,y) and size (w,h)
  845. // vertical is 0 or 1 and designates the arrow orientation,
  846. // mirror is 0 or 1 and flips the arrow side
  847. BND_EXPORT void bndJoinAreaOverlay(NVGcontext *ctx, float x, float y, float w, float h,
  848. int vertical, int mirror);
  849. ////////////////////////////////////////////////////////////////////////////////
  850. // Estimator Functions
  851. // -------------------
  852. // Use these functions to estimate sizes for widgets with your NVGcontext.
  853. // returns the ideal width for a label with given icon and text
  854. BND_EXPORT float bndLabelWidth(NVGcontext *ctx, int iconid, const char *label);
  855. // returns the height for a label with given icon, text and width; this
  856. // function is primarily useful in conjunction with multiline labels and textboxes
  857. BND_EXPORT float bndLabelHeight(NVGcontext *ctx, int iconid, const char *label,
  858. float width);
  859. ////////////////////////////////////////////////////////////////////////////////
  860. // Low Level Functions
  861. // -------------------
  862. // these are part of the implementation detail and can be used to theme
  863. // new kinds of controls in a similar fashion.
  864. // make color transparent using the default alpha value
  865. BND_EXPORT NVGcolor bndTransparent(NVGcolor color);
  866. // offset a color by a given integer delta in the range -100 to 100
  867. BND_EXPORT NVGcolor bndOffsetColor(NVGcolor color, int delta);
  868. // assigns radius r to the four entries of array radiuses depending on whether
  869. // the corner is marked as sharp or not; see BNDcornerFlags for possible
  870. // flag values.
  871. BND_EXPORT void bndSelectCorners(float *radiuses, float r, int flags);
  872. // computes the upper and lower gradient colors for the inner box from a widget
  873. // theme and the widgets state. If flipActive is set and the state is
  874. // BND_ACTIVE, the upper and lower colors will be swapped.
  875. BND_EXPORT void bndInnerColors(NVGcolor *shade_top, NVGcolor *shade_down,
  876. const BNDwidgetTheme *theme, BNDwidgetState state, int flipActive);
  877. // computes the text color for a widget label from a widget theme and the
  878. // widgets state.
  879. BND_EXPORT NVGcolor bndTextColor(const BNDwidgetTheme *theme, BNDwidgetState state);
  880. // computes the bounds of the scrollbar handle from the scrollbar size
  881. // and the handles offset and size.
  882. // offset is in the range 0..1 and defines the position of the scroll handle
  883. // size is in the range 0..1 and defines the size of the scroll handle
  884. BND_EXPORT void bndScrollHandleRect(float *x, float *y, float *w, float *h,
  885. float offset, float size);
  886. // Add a rounded box path at position (x,y) with size (w,h) and a separate
  887. // radius for each corner listed in clockwise order, so that cr0 = top left,
  888. // cr1 = top right, cr2 = bottom right, cr3 = bottom left;
  889. // this is a low level drawing function: the path must be stroked or filled
  890. // to become visible.
  891. BND_EXPORT void bndRoundedBox(NVGcontext *ctx, float x, float y, float w, float h,
  892. float cr0, float cr1, float cr2, float cr3);
  893. // Draw a flat panel without any decorations at position (x,y) with size (w,h)
  894. // and fills it with backgroundColor
  895. BND_EXPORT void bndBackground(NVGcontext *ctx, float x, float y, float w, float h);
  896. // Draw a beveled border at position (x,y) with size (w,h) shaded with
  897. // lighter and darker versions of backgroundColor
  898. BND_EXPORT void bndBevel(NVGcontext *ctx, float x, float y, float w, float h);
  899. // Draw a lower inset for a rounded box at position (x,y) with size (w,h)
  900. // that gives the impression the surface has been pushed in.
  901. // cr2 and cr3 contain the radiuses of the bottom right and bottom left
  902. // corners of the rounded box.
  903. BND_EXPORT void bndBevelInset(NVGcontext *ctx, float x, float y, float w, float h,
  904. float cr2, float cr3);
  905. // Draw an icon with (x,y) as its upper left coordinate; the iconid selects
  906. // the icon from the sheet; use the BND_ICONID macro to build icon IDs.
  907. BND_EXPORT void bndIcon(NVGcontext *ctx, float x, float y, int iconid);
  908. // Draw a drop shadow around the rounded box at (x,y) with size (w,h) and
  909. // radius r, with feather as its maximum range in pixels.
  910. // No shadow will be painted inside the rounded box.
  911. BND_EXPORT void bndDropShadow(NVGcontext *ctx, float x, float y, float w, float h,
  912. float r, float feather, float alpha);
  913. // Draw the inner part of a widget box, with a gradient from shade_top to
  914. // shade_down. If h>w, the gradient will be horizontal instead of
  915. // vertical.
  916. BND_EXPORT void bndInnerBox(NVGcontext *ctx, float x, float y, float w, float h,
  917. float cr0, float cr1, float cr2, float cr3,
  918. NVGcolor shade_top, NVGcolor shade_down);
  919. // Draw the outline part of a widget box with the given color
  920. BND_EXPORT void bndOutlineBox(NVGcontext *ctx, float x, float y, float w, float h,
  921. float cr0, float cr1, float cr2, float cr3, NVGcolor color);
  922. // Draw an optional icon specified by <iconid> and an optional label with
  923. // given alignment (BNDtextAlignment), fontsize and color within a widget box.
  924. // if iconid is >= 0, an icon will be drawn and the labels remaining space
  925. // will be adjusted.
  926. // if label is not NULL, it will be drawn with the specified alignment, fontsize
  927. // and color.
  928. // if value is not NULL, label and value will be drawn with a ":" separator
  929. // inbetween.
  930. BND_EXPORT void bndIconLabelValue(NVGcontext *ctx, float x, float y, float w, float h,
  931. int iconid, NVGcolor color, int align, float fontsize, const char *label,
  932. const char *value);
  933. // Draw an optional icon specified by <iconid> and an optional label with
  934. // given alignment (BNDtextAlignment), fontsize and color within a node title bar
  935. // if iconid is >= 0, an icon will be drawn
  936. // if label is not NULL, it will be drawn with the specified alignment, fontsize
  937. // and color.
  938. BND_EXPORT void bndNodeIconLabel(NVGcontext *ctx, float x, float y, float w, float h,
  939. int iconid, NVGcolor color, NVGcolor shadowColor, int align,
  940. float fontsize, const char *label);
  941. // Calculate the corresponding text position for given coordinates px/py
  942. // in an iconLabel.
  943. // See bndIconLabelCaret for more info.
  944. BND_EXPORT int bndIconLabelTextPosition(NVGcontext *ctx, float x, float y, float w, float h,
  945. int iconid, float fontsize, const char *label, int px, int py);
  946. // Draw an optional icon specified by <iconid>, an optional label and
  947. // a caret with given fontsize and color within a widget box.
  948. // if iconid is >= 0, an icon will be drawn and the labels remaining space
  949. // will be adjusted.
  950. // if label is not NULL, it will be drawn with the specified alignment, fontsize
  951. // and color.
  952. // cbegin must be >= 0 and <= strlen(text) and denotes the beginning of the caret
  953. // cend must be >= cbegin and <= strlen(text) and denotes the end of the caret
  954. // if cend < cbegin, then no caret will be drawn
  955. BND_EXPORT void bndIconLabelCaret(NVGcontext *ctx, float x, float y, float w, float h,
  956. int iconid, NVGcolor color, float fontsize, const char *label,
  957. NVGcolor caretcolor, int cbegin, int cend);
  958. // Draw a checkmark for an option box with the given upper left coordinates
  959. // (ox,oy) with the specified color.
  960. BND_EXPORT void bndCheck(NVGcontext *ctx, float ox, float oy, NVGcolor color);
  961. // Draw a horizontal arrow for a number field with its center at (x,y) and
  962. // size s; if s is negative, the arrow points to the left.
  963. BND_EXPORT void bndArrow(NVGcontext *ctx, float x, float y, float s, NVGcolor color);
  964. // Draw an up/down arrow for a choice box with its center at (x,y) and size s
  965. BND_EXPORT void bndUpDownArrow(NVGcontext *ctx, float x, float y, float s, NVGcolor color);
  966. // Draw a node down-arrow with its tip at (x,y) and size s
  967. BND_EXPORT void bndNodeArrowDown(NVGcontext *ctx, float x, float y, float s, NVGcolor color);
  968. // return the color of a node wire based on state
  969. // BND_HOVER indicates selected state,
  970. // BND_ACTIVE indicates dragged state
  971. BND_EXPORT NVGcolor bndNodeWireColor(const BNDnodeTheme *theme, BNDwidgetState state);
  972. #ifdef __cplusplus
  973. };
  974. #endif
  975. #endif // BLENDISH_H
  976. ////////////////////////////////////////////////////////////////////////////////
  977. ////////////////////////////////////////////////////////////////////////////////
  978. #ifdef BLENDISH_IMPLEMENTATION
  979. #include <memory.h>
  980. #include <math.h>
  981. #ifdef _MSC_VER
  982. #pragma warning (disable: 4996) // Switch off security warnings
  983. #pragma warning (disable: 4100) // Switch off unreferenced formal parameter warnings
  984. #pragma warning (disable: 4244)
  985. #pragma warning (disable: 4305)
  986. #ifdef __cplusplus
  987. #define BND_INLINE inline
  988. #else
  989. #define BND_INLINE
  990. #endif
  991. #include <float.h>
  992. static float bnd_fminf ( float a, float b )
  993. {
  994. return _isnan(a) ? b : ( _isnan(b) ? a : ((a < b) ? a : b));
  995. }
  996. static float bnd_fmaxf ( float a, float b )
  997. {
  998. return _isnan(a) ? b : ( _isnan(b) ? a : ((a > b) ? a : b));
  999. }
  1000. static double bnd_fmin ( double a, double b )
  1001. {
  1002. return _isnan(a) ? b : ( _isnan(b) ? a : ((a < b) ? a : b));
  1003. }
  1004. static double bnd_fmax ( double a, double b )
  1005. {
  1006. return _isnan(a) ? b : ( _isnan(b) ? a : ((a > b) ? a : b));
  1007. }
  1008. #else
  1009. #define BND_INLINE inline
  1010. #define bnd_fminf(a, b) fminf(a, b)
  1011. #define bnd_fmaxf(a, b) fmaxf(a, b)
  1012. #define bnd_fmin(a, b) fmin(a, b)
  1013. #define bnd_fmax(a, b) fmax(a, b)
  1014. #endif
  1015. ////////////////////////////////////////////////////////////////////////////////
  1016. // default text size
  1017. #define BND_LABEL_FONT_SIZE 13
  1018. // default text padding in inner box
  1019. #define BND_PAD_LEFT 8
  1020. #define BND_PAD_RIGHT 8
  1021. // label: value separator string
  1022. #define BND_LABEL_SEPARATOR ": "
  1023. // alpha intensity of transparent items (0xa4)
  1024. #define BND_TRANSPARENT_ALPHA 0.9
  1025. // shade intensity of beveled panels
  1026. #define BND_BEVEL_SHADE 30
  1027. // shade intensity of beveled insets
  1028. #define BND_INSET_BEVEL_SHADE 30
  1029. // shade intensity of hovered inner boxes
  1030. #define BND_HOVER_SHADE 15
  1031. // shade intensity of splitter bevels
  1032. #define BND_SPLITTER_SHADE 100
  1033. // width of icon sheet
  1034. #define BND_ICON_SHEET_WIDTH 602
  1035. // height of icon sheet
  1036. #define BND_ICON_SHEET_HEIGHT 640
  1037. // gridsize of icon sheet in both dimensions
  1038. #define BND_ICON_SHEET_GRID 21
  1039. // offset of first icon tile relative to left border
  1040. #define BND_ICON_SHEET_OFFSET_X 5
  1041. // offset of first icon tile relative to top border
  1042. #define BND_ICON_SHEET_OFFSET_Y 10
  1043. // resolution of single icon
  1044. #define BND_ICON_SHEET_RES 16
  1045. // size of number field arrow
  1046. #define BND_NUMBER_ARROW_SIZE 4
  1047. // default text color
  1048. #define BND_COLOR_TEXT {{{ 0,0,0,1 }}}
  1049. // default highlighted text color
  1050. #define BND_COLOR_TEXT_SELECTED {{{ 1,1,1,1 }}}
  1051. // radius of tool button
  1052. #define BND_TOOL_RADIUS 4
  1053. // radius of option button
  1054. #define BND_OPTION_RADIUS 4
  1055. // width of option button checkbox
  1056. #define BND_OPTION_WIDTH 14
  1057. // height of option button checkbox
  1058. #define BND_OPTION_HEIGHT 15
  1059. // radius of text field
  1060. #define BND_TEXT_RADIUS 4
  1061. // radius of number button
  1062. #define BND_NUMBER_RADIUS 10
  1063. // radius of menu popup
  1064. #define BND_MENU_RADIUS 3
  1065. // feather of menu popup shadow
  1066. #define BND_SHADOW_FEATHER 12
  1067. // alpha of menu popup shadow
  1068. #define BND_SHADOW_ALPHA 0.5
  1069. // radius of scrollbar
  1070. #define BND_SCROLLBAR_RADIUS 7
  1071. // shade intensity of active scrollbar
  1072. #define BND_SCROLLBAR_ACTIVE_SHADE 15
  1073. // max glyphs for position testing
  1074. #define BND_MAX_GLYPHS 1024
  1075. // max rows for position testing
  1076. #define BND_MAX_ROWS 32
  1077. // text distance from bottom
  1078. #define BND_TEXT_PAD_DOWN 7
  1079. // stroke width of wire outline
  1080. #define BND_NODE_WIRE_OUTLINE_WIDTH 4
  1081. // stroke width of wire
  1082. #define BND_NODE_WIRE_WIDTH 2
  1083. // radius of node box
  1084. #define BND_NODE_RADIUS 8
  1085. // feather of node title text
  1086. #define BND_NODE_TITLE_FEATHER 1
  1087. // size of node title arrow
  1088. #define BND_NODE_ARROW_SIZE 9
  1089. ////////////////////////////////////////////////////////////////////////////////
  1090. BND_INLINE float bnd_clamp(float v, float mn, float mx) {
  1091. return (v > mx)?mx:(v < mn)?mn:v;
  1092. }
  1093. ////////////////////////////////////////////////////////////////////////////////
  1094. // the initial theme
  1095. static BNDtheme bnd_theme = {
  1096. // backgroundColor
  1097. {{{ 0.447, 0.447, 0.447, 1.0 }}},
  1098. // regularTheme
  1099. {
  1100. {{{ 0.098,0.098,0.098,1 }}}, // color_outline
  1101. {{{ 0.098,0.098,0.098,1 }}}, // color_item
  1102. {{{ 0.6,0.6,0.6,1 }}}, // color_inner
  1103. {{{ 0.392,0.392,0.392,1 }}}, // color_inner_selected
  1104. BND_COLOR_TEXT, // color_text
  1105. BND_COLOR_TEXT_SELECTED, // color_text_selected
  1106. 0, // shade_top
  1107. 0, // shade_down
  1108. },
  1109. // toolTheme
  1110. {
  1111. {{{ 0.098,0.098,0.098,1 }}}, // color_outline
  1112. {{{ 0.098,0.098,0.098,1 }}}, // color_item
  1113. {{{ 0.6,0.6,0.6,1 }}}, // color_inner
  1114. {{{ 0.392,0.392,0.392,1 }}}, // color_inner_selected
  1115. BND_COLOR_TEXT, // color_text
  1116. BND_COLOR_TEXT_SELECTED, // color_text_selected
  1117. 15, // shade_top
  1118. -15, // shade_down
  1119. },
  1120. // radioTheme
  1121. {
  1122. {{{ 0,0,0,1 }}}, // color_outline
  1123. {{{ 1,1,1,1 }}}, // color_item
  1124. {{{ 0.275,0.275,0.275,1 }}}, // color_inner
  1125. {{{ 0.337,0.502,0.761,1 }}}, // color_inner_selected
  1126. BND_COLOR_TEXT_SELECTED, // color_text
  1127. BND_COLOR_TEXT, // color_text_selected
  1128. 15, // shade_top
  1129. -15, // shade_down
  1130. },
  1131. // textFieldTheme
  1132. {
  1133. {{{ 0.098,0.098,0.098,1 }}}, // color_outline
  1134. {{{ 0.353, 0.353, 0.353,1 }}}, // color_item
  1135. {{{ 0.6, 0.6, 0.6,1 }}}, // color_inner
  1136. {{{ 0.6, 0.6, 0.6,1 }}}, // color_inner_selected
  1137. BND_COLOR_TEXT, // color_text
  1138. BND_COLOR_TEXT_SELECTED, // color_text_selected
  1139. 0, // shade_top
  1140. 25, // shade_down
  1141. },
  1142. // optionTheme
  1143. {
  1144. {{{ 0,0,0,1 }}}, // color_outline
  1145. {{{ 1,1,1,1 }}}, // color_item
  1146. {{{ 0.275,0.275,0.275,1 }}}, // color_inner
  1147. {{{ 0.275,0.275,0.275,1 }}}, // color_inner_selected
  1148. BND_COLOR_TEXT, // color_text
  1149. BND_COLOR_TEXT_SELECTED, // color_text_selected
  1150. 15, // shade_top
  1151. -15, // shade_down
  1152. },
  1153. // choiceTheme
  1154. {
  1155. {{{ 0,0,0,1 }}}, // color_outline
  1156. {{{ 1,1,1,1 }}}, // color_item
  1157. {{{ 0.275,0.275,0.275,1 }}}, // color_inner
  1158. {{{ 0.275,0.275,0.275,1 }}}, // color_inner_selected
  1159. BND_COLOR_TEXT_SELECTED, // color_text
  1160. {{{ 0.8,0.8,0.8,1 }}}, // color_text_selected
  1161. 15, // shade_top
  1162. -15, // shade_down
  1163. },
  1164. // numberFieldTheme
  1165. {
  1166. {{{ 0.098,0.098,0.098,1 }}}, // color_outline
  1167. {{{ 0.353, 0.353, 0.353,1 }}}, // color_item
  1168. {{{ 0.706, 0.706, 0.706,1 }}}, // color_inner
  1169. {{{ 0.6, 0.6, 0.6,1 }}}, // color_inner_selected
  1170. BND_COLOR_TEXT, // color_text
  1171. BND_COLOR_TEXT_SELECTED, // color_text_selected
  1172. -20, // shade_top
  1173. 0, // shade_down
  1174. },
  1175. // sliderTheme
  1176. {
  1177. {{{ 0.098,0.098,0.098,1 }}}, // color_outline
  1178. {{{ 0.502,0.502,0.502,1 }}}, // color_item
  1179. {{{ 0.706, 0.706, 0.706,1 }}}, // color_inner
  1180. {{{ 0.6, 0.6, 0.6,1 }}}, // color_inner_selected
  1181. BND_COLOR_TEXT, // color_text
  1182. BND_COLOR_TEXT_SELECTED, // color_text_selected
  1183. -20, // shade_top
  1184. 0, // shade_down
  1185. },
  1186. // scrollBarTheme
  1187. {
  1188. {{{ 0.196,0.196,0.196,1 }}}, // color_outline
  1189. {{{ 0.502,0.502,0.502,1 }}}, // color_item
  1190. {{{ 0.314, 0.314, 0.314,0.706 }}}, // color_inner
  1191. {{{ 0.392, 0.392, 0.392,0.706 }}}, // color_inner_selected
  1192. BND_COLOR_TEXT, // color_text
  1193. BND_COLOR_TEXT_SELECTED, // color_text_selected
  1194. 5, // shade_top
  1195. -5, // shade_down
  1196. },
  1197. // tooltipTheme
  1198. {
  1199. {{{ 0,0,0,1 }}}, // color_outline
  1200. {{{ 0.392,0.392,0.392,1 }}}, // color_item
  1201. {{{ 0.098, 0.098, 0.098, 0.902 }}}, // color_inner
  1202. {{{ 0.176, 0.176, 0.176, 0.902 }}}, // color_inner_selected
  1203. {{{ 0.627, 0.627, 0.627, 1 }}}, // color_text
  1204. BND_COLOR_TEXT_SELECTED, // color_text_selected
  1205. 0, // shade_top
  1206. 0, // shade_down
  1207. },
  1208. // menuTheme
  1209. {
  1210. {{{ 0,0,0,1 }}}, // color_outline
  1211. {{{ 0.392,0.392,0.392,1 }}}, // color_item
  1212. {{{ 0.098, 0.098, 0.098, 0.902 }}}, // color_inner
  1213. {{{ 0.176, 0.176, 0.176, 0.902 }}}, // color_inner_selected
  1214. {{{ 0.627, 0.627, 0.627, 1 }}}, // color_text
  1215. BND_COLOR_TEXT_SELECTED, // color_text_selected
  1216. 0, // shade_top
  1217. 0, // shade_down
  1218. },
  1219. // menuItemTheme
  1220. {
  1221. {{{ 0,0,0,1 }}}, // color_outline
  1222. {{{ 0.675,0.675,0.675,0.502 }}}, // color_item
  1223. {{{ 0,0,0,0 }}}, // color_inner
  1224. {{{ 0.337,0.502,0.761,1 }}}, // color_inner_selected
  1225. BND_COLOR_TEXT_SELECTED, // color_text
  1226. BND_COLOR_TEXT, // color_text_selected
  1227. 38, // shade_top
  1228. 0, // shade_down
  1229. },
  1230. // nodeTheme
  1231. {
  1232. {{{ 0.945,0.345,0,1 }}}, // nodeSelectedColor
  1233. {{{ 0,0,0,1 }}}, // wiresColor
  1234. {{{ 0.498,0.439,0.439,1 }}}, // textSelectedColor
  1235. {{{ 1,0.667,0.251,1 }}}, // activeNodeColor
  1236. {{{ 1,1,1,1 }}}, // wireSelectColor
  1237. {{{ 0.608,0.608,0.608,0.627 }}}, // nodeBackdropColor
  1238. 5, // noodleCurving
  1239. },
  1240. };
  1241. ////////////////////////////////////////////////////////////////////////////////
  1242. void bndSetTheme(BNDtheme theme) {
  1243. bnd_theme = theme;
  1244. }
  1245. const BNDtheme *bndGetTheme() {
  1246. return &bnd_theme;
  1247. }
  1248. // the handle to the image containing the icon sheet
  1249. static int bnd_icon_image = -1;
  1250. void bndSetIconImage(int image) {
  1251. bnd_icon_image = image;
  1252. }
  1253. // the handle to the UI font
  1254. static int bnd_font = -1;
  1255. void bndSetFont(int font) {
  1256. bnd_font = font;
  1257. }
  1258. ////////////////////////////////////////////////////////////////////////////////
  1259. void bndLabel(NVGcontext *ctx,
  1260. float x, float y, float w, float h, int iconid, const char *label) {
  1261. bndIconLabelValue(ctx,x,y,w,h,iconid,
  1262. bnd_theme.regularTheme.textColor, BND_LEFT,
  1263. BND_LABEL_FONT_SIZE, label, NULL);
  1264. }
  1265. void bndToolButton(NVGcontext *ctx,
  1266. float x, float y, float w, float h, int flags, BNDwidgetState state,
  1267. int iconid, const char *label) {
  1268. float cr[4];
  1269. NVGcolor shade_top, shade_down;
  1270. bndSelectCorners(cr, BND_TOOL_RADIUS, flags);
  1271. bndBevelInset(ctx,x,y,w,h,cr[2],cr[3]);
  1272. bndInnerColors(&shade_top, &shade_down, &bnd_theme.toolTheme, state, 1);
  1273. bndInnerBox(ctx,x,y,w,h,cr[0],cr[1],cr[2],cr[3], shade_top, shade_down);
  1274. bndOutlineBox(ctx,x,y,w,h,cr[0],cr[1],cr[2],cr[3],
  1275. bndTransparent(bnd_theme.toolTheme.outlineColor));
  1276. bndIconLabelValue(ctx,x,y,w,h,iconid,
  1277. bndTextColor(&bnd_theme.toolTheme, state), BND_CENTER,
  1278. BND_LABEL_FONT_SIZE, label, NULL);
  1279. }
  1280. void bndRadioButton(NVGcontext *ctx,
  1281. float x, float y, float w, float h, int flags, BNDwidgetState state,
  1282. int iconid, const char *label) {
  1283. float cr[4];
  1284. NVGcolor shade_top, shade_down;
  1285. bndSelectCorners(cr, BND_OPTION_RADIUS, flags);
  1286. bndBevelInset(ctx,x,y,w,h,cr[2],cr[3]);
  1287. bndInnerColors(&shade_top, &shade_down, &bnd_theme.radioTheme, state, 1);
  1288. bndInnerBox(ctx,x,y,w,h,cr[0],cr[1],cr[2],cr[3], shade_top, shade_down);
  1289. bndOutlineBox(ctx,x,y,w,h,cr[0],cr[1],cr[2],cr[3],
  1290. bndTransparent(bnd_theme.radioTheme.outlineColor));
  1291. bndIconLabelValue(ctx,x,y,w,h,iconid,
  1292. bndTextColor(&bnd_theme.radioTheme, state), BND_CENTER,
  1293. BND_LABEL_FONT_SIZE, label, NULL);
  1294. }
  1295. int bndTextFieldTextPosition(NVGcontext *ctx, float x, float y, float w, float h,
  1296. int iconid, const char *text, int px, int py) {
  1297. return bndIconLabelTextPosition(ctx, x, y, w, h,
  1298. iconid, BND_LABEL_FONT_SIZE, text, px, py);
  1299. }
  1300. void bndTextField(NVGcontext *ctx,
  1301. float x, float y, float w, float h, int flags, BNDwidgetState state,
  1302. int iconid, const char *text, int cbegin, int cend) {
  1303. float cr[4];
  1304. NVGcolor shade_top, shade_down;
  1305. bndSelectCorners(cr, BND_TEXT_RADIUS, flags);
  1306. bndBevelInset(ctx,x,y,w,h,cr[2],cr[3]);
  1307. bndInnerColors(&shade_top, &shade_down, &bnd_theme.textFieldTheme, state, 0);
  1308. bndInnerBox(ctx,x,y,w,h,cr[0],cr[1],cr[2],cr[3], shade_top, shade_down);
  1309. bndOutlineBox(ctx,x,y,w,h,cr[0],cr[1],cr[2],cr[3],
  1310. bndTransparent(bnd_theme.textFieldTheme.outlineColor));
  1311. if (state != BND_ACTIVE) {
  1312. cend = -1;
  1313. }
  1314. bndIconLabelCaret(ctx,x,y,w,h,iconid,
  1315. bndTextColor(&bnd_theme.textFieldTheme, state), BND_LABEL_FONT_SIZE,
  1316. text, bnd_theme.textFieldTheme.itemColor, cbegin, cend);
  1317. }
  1318. void bndOptionButton(NVGcontext *ctx,
  1319. float x, float y, float w, float h, BNDwidgetState state,
  1320. const char *label) {
  1321. float ox, oy;
  1322. NVGcolor shade_top, shade_down;
  1323. ox = x;
  1324. oy = y+h-BND_OPTION_HEIGHT-3;
  1325. bndBevelInset(ctx,ox,oy,
  1326. BND_OPTION_WIDTH,BND_OPTION_HEIGHT,
  1327. BND_OPTION_RADIUS,BND_OPTION_RADIUS);
  1328. bndInnerColors(&shade_top, &shade_down, &bnd_theme.optionTheme, state, 1);
  1329. bndInnerBox(ctx,ox,oy,
  1330. BND_OPTION_WIDTH,BND_OPTION_HEIGHT,
  1331. BND_OPTION_RADIUS,BND_OPTION_RADIUS,BND_OPTION_RADIUS,BND_OPTION_RADIUS,
  1332. shade_top, shade_down);
  1333. bndOutlineBox(ctx,ox,oy,
  1334. BND_OPTION_WIDTH,BND_OPTION_HEIGHT,
  1335. BND_OPTION_RADIUS,BND_OPTION_RADIUS,BND_OPTION_RADIUS,BND_OPTION_RADIUS,
  1336. bndTransparent(bnd_theme.optionTheme.outlineColor));
  1337. if (state == BND_ACTIVE) {
  1338. bndCheck(ctx,ox,oy, bndTransparent(bnd_theme.optionTheme.itemColor));
  1339. }
  1340. bndIconLabelValue(ctx,x+12,y,w-12,h,-1,
  1341. bndTextColor(&bnd_theme.optionTheme, state), BND_LEFT,
  1342. BND_LABEL_FONT_SIZE, label, NULL);
  1343. }
  1344. void bndChoiceButton(NVGcontext *ctx,
  1345. float x, float y, float w, float h, int flags, BNDwidgetState state,
  1346. int iconid, const char *label) {
  1347. float cr[4];
  1348. NVGcolor shade_top, shade_down;
  1349. bndSelectCorners(cr, BND_OPTION_RADIUS, flags);
  1350. bndBevelInset(ctx,x,y,w,h,cr[2],cr[3]);
  1351. bndInnerColors(&shade_top, &shade_down, &bnd_theme.choiceTheme, state, 1);
  1352. bndInnerBox(ctx,x,y,w,h,cr[0],cr[1],cr[2],cr[3], shade_top, shade_down);
  1353. bndOutlineBox(ctx,x,y,w,h,cr[0],cr[1],cr[2],cr[3],
  1354. bndTransparent(bnd_theme.choiceTheme.outlineColor));
  1355. bndIconLabelValue(ctx,x,y,w,h,iconid,
  1356. bndTextColor(&bnd_theme.choiceTheme, state), BND_LEFT,
  1357. BND_LABEL_FONT_SIZE, label, NULL);
  1358. bndUpDownArrow(ctx,x+w-10,y+10,5,
  1359. bndTransparent(bnd_theme.choiceTheme.itemColor));
  1360. }
  1361. void bndColorButton(NVGcontext *ctx,
  1362. float x, float y, float w, float h, int flags, NVGcolor color) {
  1363. float cr[4];
  1364. bndSelectCorners(cr, BND_TOOL_RADIUS, flags);
  1365. bndBevelInset(ctx,x,y,w,h,cr[2],cr[3]);
  1366. bndInnerBox(ctx,x,y,w,h,cr[0],cr[1],cr[2],cr[3], color, color);
  1367. bndOutlineBox(ctx,x,y,w,h,cr[0],cr[1],cr[2],cr[3],
  1368. bndTransparent(bnd_theme.toolTheme.outlineColor));
  1369. }
  1370. void bndNumberField(NVGcontext *ctx,
  1371. float x, float y, float w, float h, int flags, BNDwidgetState state,
  1372. const char *label, const char *value) {
  1373. float cr[4];
  1374. NVGcolor shade_top, shade_down;
  1375. bndSelectCorners(cr, BND_NUMBER_RADIUS, flags);
  1376. bndBevelInset(ctx,x,y,w,h,cr[2],cr[3]);
  1377. bndInnerColors(&shade_top, &shade_down, &bnd_theme.numberFieldTheme, state, 0);
  1378. bndInnerBox(ctx,x,y,w,h,cr[0],cr[1],cr[2],cr[3], shade_top, shade_down);
  1379. bndOutlineBox(ctx,x,y,w,h,cr[0],cr[1],cr[2],cr[3],
  1380. bndTransparent(bnd_theme.numberFieldTheme.outlineColor));
  1381. bndIconLabelValue(ctx,x,y,w,h,-1,
  1382. bndTextColor(&bnd_theme.numberFieldTheme, state), BND_CENTER,
  1383. BND_LABEL_FONT_SIZE, label, value);
  1384. bndArrow(ctx,x+8,y+10,-BND_NUMBER_ARROW_SIZE,
  1385. bndTransparent(bnd_theme.numberFieldTheme.itemColor));
  1386. bndArrow(ctx,x+w-8,y+10,BND_NUMBER_ARROW_SIZE,
  1387. bndTransparent(bnd_theme.numberFieldTheme.itemColor));
  1388. }
  1389. void bndSlider(NVGcontext *ctx,
  1390. float x, float y, float w, float h, int flags, BNDwidgetState state,
  1391. float progress, const char *label, const char *value) {
  1392. float cr[4];
  1393. NVGcolor shade_top, shade_down;
  1394. bndSelectCorners(cr, BND_NUMBER_RADIUS, flags);
  1395. bndBevelInset(ctx,x,y,w,h,cr[2],cr[3]);
  1396. bndInnerColors(&shade_top, &shade_down, &bnd_theme.sliderTheme, state, 0);
  1397. bndInnerBox(ctx,x,y,w,h,cr[0],cr[1],cr[2],cr[3], shade_top, shade_down);
  1398. if (state == BND_ACTIVE) {
  1399. shade_top = bndOffsetColor(
  1400. bnd_theme.sliderTheme.itemColor, bnd_theme.sliderTheme.shadeTop);
  1401. shade_down = bndOffsetColor(
  1402. bnd_theme.sliderTheme.itemColor, bnd_theme.sliderTheme.shadeDown);
  1403. } else {
  1404. shade_top = bndOffsetColor(
  1405. bnd_theme.sliderTheme.itemColor, bnd_theme.sliderTheme.shadeDown);
  1406. shade_down = bndOffsetColor(
  1407. bnd_theme.sliderTheme.itemColor, bnd_theme.sliderTheme.shadeTop);
  1408. }
  1409. nvgScissor(ctx,x,y,8+(w-8)*bnd_clamp(progress,0,1),h);
  1410. bndInnerBox(ctx,x,y,w,h,cr[0],cr[1],cr[2],cr[3], shade_top, shade_down);
  1411. nvgResetScissor(ctx);
  1412. bndOutlineBox(ctx,x,y,w,h,cr[0],cr[1],cr[2],cr[3],
  1413. bndTransparent(bnd_theme.sliderTheme.outlineColor));
  1414. bndIconLabelValue(ctx,x,y,w,h,-1,
  1415. bndTextColor(&bnd_theme.sliderTheme, state), BND_CENTER,
  1416. BND_LABEL_FONT_SIZE, label, value);
  1417. }
  1418. void bndScrollBar(NVGcontext *ctx,
  1419. float x, float y, float w, float h, BNDwidgetState state,
  1420. float offset, float size) {
  1421. bndBevelInset(ctx,x,y,w,h,
  1422. BND_SCROLLBAR_RADIUS, BND_SCROLLBAR_RADIUS);
  1423. bndInnerBox(ctx,x,y,w,h,
  1424. BND_SCROLLBAR_RADIUS,BND_SCROLLBAR_RADIUS,
  1425. BND_SCROLLBAR_RADIUS,BND_SCROLLBAR_RADIUS,
  1426. bndOffsetColor(
  1427. bnd_theme.scrollBarTheme.innerColor, 3*bnd_theme.scrollBarTheme.shadeDown),
  1428. bndOffsetColor(
  1429. bnd_theme.scrollBarTheme.innerColor, 3*bnd_theme.scrollBarTheme.shadeTop));
  1430. bndOutlineBox(ctx,x,y,w,h,
  1431. BND_SCROLLBAR_RADIUS,BND_SCROLLBAR_RADIUS,
  1432. BND_SCROLLBAR_RADIUS,BND_SCROLLBAR_RADIUS,
  1433. bndTransparent(bnd_theme.scrollBarTheme.outlineColor));
  1434. NVGcolor itemColor = bndOffsetColor(
  1435. bnd_theme.scrollBarTheme.itemColor,
  1436. (state == BND_ACTIVE)?BND_SCROLLBAR_ACTIVE_SHADE:0);
  1437. bndScrollHandleRect(&x,&y,&w,&h,offset,size);
  1438. bndInnerBox(ctx,x,y,w,h,
  1439. BND_SCROLLBAR_RADIUS,BND_SCROLLBAR_RADIUS,
  1440. BND_SCROLLBAR_RADIUS,BND_SCROLLBAR_RADIUS,
  1441. bndOffsetColor(
  1442. itemColor, 3*bnd_theme.scrollBarTheme.shadeTop),
  1443. bndOffsetColor(
  1444. itemColor, 3*bnd_theme.scrollBarTheme.shadeDown));
  1445. bndOutlineBox(ctx,x,y,w,h,
  1446. BND_SCROLLBAR_RADIUS,BND_SCROLLBAR_RADIUS,
  1447. BND_SCROLLBAR_RADIUS,BND_SCROLLBAR_RADIUS,
  1448. bndTransparent(bnd_theme.scrollBarTheme.outlineColor));
  1449. }
  1450. void bndMenuBackground(NVGcontext *ctx,
  1451. float x, float y, float w, float h, int flags) {
  1452. float cr[4];
  1453. NVGcolor shade_top, shade_down;
  1454. bndSelectCorners(cr, BND_MENU_RADIUS, flags);
  1455. bndInnerColors(&shade_top, &shade_down, &bnd_theme.menuTheme,
  1456. BND_DEFAULT, 0);
  1457. bndInnerBox(ctx,x,y,w,h+1,cr[0],cr[1],cr[2],cr[3], shade_top, shade_down);
  1458. bndOutlineBox(ctx,x,y,w,h+1,cr[0],cr[1],cr[2],cr[3],
  1459. bndTransparent(bnd_theme.menuTheme.outlineColor));
  1460. bndDropShadow(ctx,x,y,w,h,BND_MENU_RADIUS,
  1461. BND_SHADOW_FEATHER,BND_SHADOW_ALPHA);
  1462. }
  1463. void bndTooltipBackground(NVGcontext *ctx, float x, float y, float w, float h) {
  1464. NVGcolor shade_top, shade_down;
  1465. bndInnerColors(&shade_top, &shade_down, &bnd_theme.tooltipTheme,
  1466. BND_DEFAULT, 0);
  1467. bndInnerBox(ctx,x,y,w,h+1,
  1468. BND_MENU_RADIUS,BND_MENU_RADIUS,BND_MENU_RADIUS,BND_MENU_RADIUS,
  1469. shade_top, shade_down);
  1470. bndOutlineBox(ctx,x,y,w,h+1,
  1471. BND_MENU_RADIUS,BND_MENU_RADIUS,BND_MENU_RADIUS,BND_MENU_RADIUS,
  1472. bndTransparent(bnd_theme.tooltipTheme.outlineColor));
  1473. bndDropShadow(ctx,x,y,w,h,BND_MENU_RADIUS,
  1474. BND_SHADOW_FEATHER,BND_SHADOW_ALPHA);
  1475. }
  1476. void bndMenuLabel(NVGcontext *ctx,
  1477. float x, float y, float w, float h, int iconid, const char *label) {
  1478. bndIconLabelValue(ctx,x,y,w,h,iconid,
  1479. bnd_theme.menuTheme.textColor, BND_LEFT,
  1480. BND_LABEL_FONT_SIZE, label, NULL);
  1481. }
  1482. void bndMenuItem(NVGcontext *ctx,
  1483. float x, float y, float w, float h, BNDwidgetState state,
  1484. int iconid, const char *label) {
  1485. if (state != BND_DEFAULT) {
  1486. bndInnerBox(ctx,x,y,w,h,0,0,0,0,
  1487. bndOffsetColor(bnd_theme.menuItemTheme.innerSelectedColor,
  1488. bnd_theme.menuItemTheme.shadeTop),
  1489. bndOffsetColor(bnd_theme.menuItemTheme.innerSelectedColor,
  1490. bnd_theme.menuItemTheme.shadeDown));
  1491. state = BND_ACTIVE;
  1492. }
  1493. bndIconLabelValue(ctx,x,y,w,h,iconid,
  1494. bndTextColor(&bnd_theme.menuItemTheme, state), BND_LEFT,
  1495. BND_LABEL_FONT_SIZE, label, NULL);
  1496. }
  1497. void bndNodePort(NVGcontext *ctx, float x, float y, BNDwidgetState state,
  1498. NVGcolor color) {
  1499. nvgBeginPath(ctx);
  1500. nvgCircle(ctx, x, y, BND_NODE_PORT_RADIUS);
  1501. nvgStrokeColor(ctx,bnd_theme.nodeTheme.wiresColor);
  1502. nvgStrokeWidth(ctx,1.0f);
  1503. nvgStroke(ctx);
  1504. nvgFillColor(ctx,(state != BND_DEFAULT)?
  1505. bndOffsetColor(color, BND_HOVER_SHADE):color);
  1506. nvgFill(ctx);
  1507. }
  1508. void bndColoredNodeWire(NVGcontext *ctx, float x0, float y0, float x1, float y1,
  1509. NVGcolor color0, NVGcolor color1) {
  1510. float length = bnd_fmaxf(fabsf(x1 - x0),fabsf(y1 - y0));
  1511. float delta = length*(float)bnd_theme.nodeTheme.noodleCurving/10.0f;
  1512. nvgBeginPath(ctx);
  1513. nvgMoveTo(ctx, x0, y0);
  1514. nvgBezierTo(ctx,
  1515. x0 + delta, y0,
  1516. x1 - delta, y1,
  1517. x1, y1);
  1518. NVGcolor colorw = bnd_theme.nodeTheme.wiresColor;
  1519. colorw.a = (color0.a<color1.a)?color0.a:color1.a;
  1520. nvgStrokeColor(ctx, colorw);
  1521. nvgStrokeWidth(ctx, BND_NODE_WIRE_OUTLINE_WIDTH);
  1522. nvgStroke(ctx);
  1523. nvgStrokePaint(ctx, nvgLinearGradient(ctx,
  1524. x0, y0, x1, y1,
  1525. color0,
  1526. color1));
  1527. nvgStrokeWidth(ctx,BND_NODE_WIRE_WIDTH);
  1528. nvgStroke(ctx);
  1529. }
  1530. void bndNodeWire(NVGcontext *ctx, float x0, float y0, float x1, float y1,
  1531. BNDwidgetState state0, BNDwidgetState state1) {
  1532. bndColoredNodeWire(ctx, x0, y0, x1, y1,
  1533. bndNodeWireColor(&bnd_theme.nodeTheme, state0),
  1534. bndNodeWireColor(&bnd_theme.nodeTheme, state1));
  1535. }
  1536. void bndNodeBackground(NVGcontext *ctx, float x, float y, float w, float h,
  1537. BNDwidgetState state, int iconid, const char *label, NVGcolor titleColor) {
  1538. bndInnerBox(ctx,x,y,w,BND_NODE_TITLE_HEIGHT+2,
  1539. BND_NODE_RADIUS,BND_NODE_RADIUS,0,0,
  1540. bndTransparent(bndOffsetColor(titleColor, BND_BEVEL_SHADE)),
  1541. bndTransparent(titleColor));
  1542. bndInnerBox(ctx,x,y+BND_NODE_TITLE_HEIGHT-1,w,h+2-BND_NODE_TITLE_HEIGHT,
  1543. 0,0,BND_NODE_RADIUS,BND_NODE_RADIUS,
  1544. bndTransparent(bnd_theme.nodeTheme.nodeBackdropColor),
  1545. bndTransparent(bnd_theme.nodeTheme.nodeBackdropColor));
  1546. bndNodeIconLabel(ctx,
  1547. x+BND_NODE_ARROW_AREA_WIDTH,y,
  1548. w-BND_NODE_ARROW_AREA_WIDTH-BND_NODE_MARGIN_SIDE,BND_NODE_TITLE_HEIGHT,
  1549. iconid, bnd_theme.regularTheme.textColor,
  1550. bndOffsetColor(titleColor, BND_BEVEL_SHADE),
  1551. BND_LEFT, BND_LABEL_FONT_SIZE, label);
  1552. NVGcolor arrowColor;
  1553. NVGcolor borderColor;
  1554. switch(state) {
  1555. default:
  1556. case BND_DEFAULT: {
  1557. borderColor = nvgRGBf(0,0,0);
  1558. arrowColor = bndOffsetColor(titleColor, -BND_BEVEL_SHADE);
  1559. } break;
  1560. case BND_HOVER: {
  1561. borderColor = bnd_theme.nodeTheme.nodeSelectedColor;
  1562. arrowColor = bnd_theme.nodeTheme.nodeSelectedColor;
  1563. } break;
  1564. case BND_ACTIVE: {
  1565. borderColor = bnd_theme.nodeTheme.activeNodeColor;
  1566. arrowColor = bnd_theme.nodeTheme.nodeSelectedColor;
  1567. } break;
  1568. }
  1569. bndOutlineBox(ctx,x,y,w,h+1,
  1570. BND_NODE_RADIUS,BND_NODE_RADIUS,BND_NODE_RADIUS,BND_NODE_RADIUS,
  1571. bndTransparent(borderColor));
  1572. /*
  1573. bndNodeArrowDown(ctx,
  1574. x + BND_NODE_MARGIN_SIDE, y + BND_NODE_TITLE_HEIGHT-4,
  1575. BND_NODE_ARROW_SIZE, arrowColor);
  1576. */
  1577. bndDropShadow(ctx,x,y,w,h,BND_NODE_RADIUS,
  1578. BND_SHADOW_FEATHER,BND_SHADOW_ALPHA);
  1579. }
  1580. void bndSplitterWidgets(NVGcontext *ctx, float x, float y, float w, float h) {
  1581. NVGcolor insetLight = bndTransparent(
  1582. bndOffsetColor(bnd_theme.backgroundColor, BND_SPLITTER_SHADE));
  1583. NVGcolor insetDark = bndTransparent(
  1584. bndOffsetColor(bnd_theme.backgroundColor, -BND_SPLITTER_SHADE));
  1585. NVGcolor inset = bndTransparent(bnd_theme.backgroundColor);
  1586. float x2 = x+w;
  1587. float y2 = y+h;
  1588. nvgBeginPath(ctx);
  1589. nvgMoveTo(ctx, x, y2-13);
  1590. nvgLineTo(ctx, x+13, y2);
  1591. nvgMoveTo(ctx, x, y2-9);
  1592. nvgLineTo(ctx, x+9, y2);
  1593. nvgMoveTo(ctx, x, y2-5);
  1594. nvgLineTo(ctx, x+5, y2);
  1595. nvgMoveTo(ctx, x2-11, y);
  1596. nvgLineTo(ctx, x2, y+11);
  1597. nvgMoveTo(ctx, x2-7, y);
  1598. nvgLineTo(ctx, x2, y+7);
  1599. nvgMoveTo(ctx, x2-3, y);
  1600. nvgLineTo(ctx, x2, y+3);
  1601. nvgStrokeColor(ctx, insetDark);
  1602. nvgStroke(ctx);
  1603. nvgBeginPath(ctx);
  1604. nvgMoveTo(ctx, x, y2-11);
  1605. nvgLineTo(ctx, x+11, y2);
  1606. nvgMoveTo(ctx, x, y2-7);
  1607. nvgLineTo(ctx, x+7, y2);
  1608. nvgMoveTo(ctx, x, y2-3);
  1609. nvgLineTo(ctx, x+3, y2);
  1610. nvgMoveTo(ctx, x2-13, y);
  1611. nvgLineTo(ctx, x2, y+13);
  1612. nvgMoveTo(ctx, x2-9, y);
  1613. nvgLineTo(ctx, x2, y+9);
  1614. nvgMoveTo(ctx, x2-5, y);
  1615. nvgLineTo(ctx, x2, y+5);
  1616. nvgStrokeColor(ctx, insetLight);
  1617. nvgStroke(ctx);
  1618. nvgBeginPath(ctx);
  1619. nvgMoveTo(ctx, x, y2-12);
  1620. nvgLineTo(ctx, x+12, y2);
  1621. nvgMoveTo(ctx, x, y2-8);
  1622. nvgLineTo(ctx, x+8, y2);
  1623. nvgMoveTo(ctx, x, y2-4);
  1624. nvgLineTo(ctx, x+4, y2);
  1625. nvgMoveTo(ctx, x2-12, y);
  1626. nvgLineTo(ctx, x2, y+12);
  1627. nvgMoveTo(ctx, x2-8, y);
  1628. nvgLineTo(ctx, x2, y+8);
  1629. nvgMoveTo(ctx, x2-4, y);
  1630. nvgLineTo(ctx, x2, y+4);
  1631. nvgStrokeColor(ctx, inset);
  1632. nvgStroke(ctx);
  1633. }
  1634. void bndJoinAreaOverlay(NVGcontext *ctx, float x, float y, float w, float h,
  1635. int vertical, int mirror) {
  1636. if (vertical) {
  1637. float u = w;
  1638. w = h; h = u;
  1639. }
  1640. float s = (w<h)?w:h;
  1641. float x0,y0,x1,y1;
  1642. if (mirror) {
  1643. x0 = w;
  1644. y0 = h;
  1645. x1 = 0;
  1646. y1 = 0;
  1647. s = -s;
  1648. } else {
  1649. x0 = 0;
  1650. y0 = 0;
  1651. x1 = w;
  1652. y1 = h;
  1653. }
  1654. float yc = (y0+y1)*0.5f;
  1655. float s2 = s/2.0f;
  1656. float s4 = s/4.0f;
  1657. float s8 = s/8.0f;
  1658. float x4 = x0+s4;
  1659. float points[][2] = {
  1660. { x0,y0 },
  1661. { x1,y0 },
  1662. { x1,y1 },
  1663. { x0,y1 },
  1664. { x0,yc+s8 },
  1665. { x4,yc+s8 },
  1666. { x4,yc+s4 },
  1667. { x0+s2,yc },
  1668. { x4,yc-s4 },
  1669. { x4,yc-s8 },
  1670. { x0,yc-s8 }
  1671. };
  1672. nvgBeginPath(ctx);
  1673. int count = sizeof(points) / (sizeof(float)*2);
  1674. nvgMoveTo(ctx,x+points[0][vertical&1],y+points[0][(vertical&1)^1]);
  1675. for (int i = 1; i < count; ++i) {
  1676. nvgLineTo(ctx,x+points[i][vertical&1],y+points[i][(vertical&1)^1]);
  1677. }
  1678. nvgFillColor(ctx, nvgRGBAf(0,0,0,0.3));
  1679. nvgFill(ctx);
  1680. }
  1681. ////////////////////////////////////////////////////////////////////////////////
  1682. float bndLabelWidth(NVGcontext *ctx, int iconid, const char *label) {
  1683. int w = BND_PAD_LEFT + BND_PAD_RIGHT;
  1684. if (iconid >= 0) {
  1685. w += BND_ICON_SHEET_RES;
  1686. }
  1687. if (label && (bnd_font >= 0)) {
  1688. nvgFontFaceId(ctx, bnd_font);
  1689. nvgFontSize(ctx, BND_LABEL_FONT_SIZE);
  1690. w += nvgTextBounds(ctx, 1, 1, label, NULL, NULL);
  1691. }
  1692. return w;
  1693. }
  1694. float bndLabelHeight(NVGcontext *ctx, int iconid, const char *label, float width) {
  1695. int h = BND_WIDGET_HEIGHT;
  1696. width -= BND_TEXT_RADIUS*2;
  1697. if (iconid >= 0) {
  1698. width -= BND_ICON_SHEET_RES;
  1699. }
  1700. if (label && (bnd_font >= 0)) {
  1701. nvgFontFaceId(ctx, bnd_font);
  1702. nvgFontSize(ctx, BND_LABEL_FONT_SIZE);
  1703. float bounds[4];
  1704. nvgTextBoxBounds(ctx, 1, 1, width, label, NULL, bounds);
  1705. int bh = int(bounds[3] - bounds[1]) + BND_TEXT_PAD_DOWN;
  1706. if (bh > h)
  1707. h = bh;
  1708. }
  1709. return h;
  1710. }
  1711. ////////////////////////////////////////////////////////////////////////////////
  1712. void bndRoundedBox(NVGcontext *ctx, float x, float y, float w, float h,
  1713. float cr0, float cr1, float cr2, float cr3) {
  1714. float d;
  1715. w = bnd_fmaxf(0, w);
  1716. h = bnd_fmaxf(0, h);
  1717. d = bnd_fminf(w, h);
  1718. nvgMoveTo(ctx, x,y+h*0.5f);
  1719. nvgArcTo(ctx, x,y, x+w,y, bnd_fminf(cr0, d/2));
  1720. nvgArcTo(ctx, x+w,y, x+w,y+h, bnd_fminf(cr1, d/2));
  1721. nvgArcTo(ctx, x+w,y+h, x,y+h, bnd_fminf(cr2, d/2));
  1722. nvgArcTo(ctx, x,y+h, x,y, bnd_fminf(cr3, d/2));
  1723. nvgClosePath(ctx);
  1724. }
  1725. NVGcolor bndTransparent(NVGcolor color) {
  1726. color.a *= BND_TRANSPARENT_ALPHA;
  1727. return color;
  1728. }
  1729. NVGcolor bndOffsetColor(NVGcolor color, int delta) {
  1730. float offset = (float)delta / 255.0f;
  1731. return delta?(
  1732. nvgRGBAf(
  1733. bnd_clamp(color.r+offset,0,1),
  1734. bnd_clamp(color.g+offset,0,1),
  1735. bnd_clamp(color.b+offset,0,1),
  1736. color.a)
  1737. ):color;
  1738. }
  1739. void bndBevel(NVGcontext *ctx, float x, float y, float w, float h) {
  1740. // Disable bevel
  1741. return;
  1742. nvgStrokeWidth(ctx, 1);
  1743. x += 0.5f;
  1744. y += 0.5f;
  1745. w -= 1;
  1746. h -= 1;
  1747. nvgBeginPath(ctx);
  1748. nvgMoveTo(ctx, x, y+h);
  1749. nvgLineTo(ctx, x+w, y+h);
  1750. nvgLineTo(ctx, x+w, y);
  1751. nvgStrokeColor(ctx, bndTransparent(
  1752. bndOffsetColor(bnd_theme.backgroundColor, -BND_BEVEL_SHADE)));
  1753. nvgStroke(ctx);
  1754. nvgBeginPath(ctx);
  1755. nvgMoveTo(ctx, x, y+h);
  1756. nvgLineTo(ctx, x, y);
  1757. nvgLineTo(ctx, x+w, y);
  1758. nvgStrokeColor(ctx, bndTransparent(
  1759. bndOffsetColor(bnd_theme.backgroundColor, BND_BEVEL_SHADE)));
  1760. nvgStroke(ctx);
  1761. }
  1762. void bndBevelInset(NVGcontext *ctx, float x, float y, float w, float h,
  1763. float cr2, float cr3) {
  1764. float d;
  1765. y -= 0.5f;
  1766. d = bnd_fminf(w, h);
  1767. cr2 = bnd_fminf(cr2, d/2);
  1768. cr3 = bnd_fminf(cr3, d/2);
  1769. nvgBeginPath(ctx);
  1770. nvgMoveTo(ctx, x+w,y+h-cr2);
  1771. nvgArcTo(ctx, x+w,y+h, x,y+h, cr2);
  1772. nvgArcTo(ctx, x,y+h, x,y, cr3);
  1773. NVGcolor bevelColor = bndOffsetColor(bnd_theme.backgroundColor,
  1774. BND_INSET_BEVEL_SHADE);
  1775. nvgStrokeWidth(ctx, 1);
  1776. nvgStrokePaint(ctx,
  1777. nvgLinearGradient(ctx,
  1778. x,y+h-bnd_fmaxf(cr2,cr3)-1,
  1779. x,y+h-1,
  1780. nvgRGBAf(bevelColor.r, bevelColor.g, bevelColor.b, 0),
  1781. bevelColor));
  1782. nvgStroke(ctx);
  1783. }
  1784. void bndBackground(NVGcontext *ctx, float x, float y, float w, float h) {
  1785. nvgBeginPath(ctx);
  1786. nvgRect(ctx, x, y, w, h);
  1787. nvgFillColor(ctx, bnd_theme.backgroundColor);
  1788. nvgFill(ctx);
  1789. }
  1790. void bndIcon(NVGcontext *ctx, float x, float y, int iconid) {
  1791. int ix, iy, u, v;
  1792. if (bnd_icon_image < 0) return; // no icons loaded
  1793. ix = iconid & 0xff;
  1794. iy = (iconid>>8) & 0xff;
  1795. u = BND_ICON_SHEET_OFFSET_X + ix*BND_ICON_SHEET_GRID;
  1796. v = BND_ICON_SHEET_OFFSET_Y + iy*BND_ICON_SHEET_GRID;
  1797. nvgBeginPath(ctx);
  1798. nvgRect(ctx,x,y,BND_ICON_SHEET_RES,BND_ICON_SHEET_RES);
  1799. nvgFillPaint(ctx,
  1800. nvgImagePattern(ctx,x-u,y-v,
  1801. BND_ICON_SHEET_WIDTH,
  1802. BND_ICON_SHEET_HEIGHT,
  1803. 0,bnd_icon_image,1));
  1804. nvgFill(ctx);
  1805. }
  1806. void bndDropShadow(NVGcontext *ctx, float x, float y, float w, float h,
  1807. float r, float feather, float alpha) {
  1808. nvgBeginPath(ctx);
  1809. y += feather;
  1810. h -= feather;
  1811. nvgMoveTo(ctx, x-feather, y-feather);
  1812. nvgLineTo(ctx, x, y-feather);
  1813. nvgLineTo(ctx, x, y+h-feather);
  1814. nvgArcTo(ctx, x,y+h,x+r,y+h,r);
  1815. nvgArcTo(ctx, x+w,y+h,x+w,y+h-r,r);
  1816. nvgLineTo(ctx, x+w, y-feather);
  1817. nvgLineTo(ctx, x+w+feather, y-feather);
  1818. nvgLineTo(ctx, x+w+feather, y+h+feather);
  1819. nvgLineTo(ctx, x-feather, y+h+feather);
  1820. nvgClosePath(ctx);
  1821. nvgFillPaint(ctx, nvgBoxGradient(ctx,
  1822. x - feather*0.5f,y - feather*0.5f,
  1823. w + feather,h+feather,
  1824. r+feather*0.5f,
  1825. feather,
  1826. nvgRGBAf(0,0,0,alpha*alpha),
  1827. nvgRGBAf(0,0,0,0)));
  1828. nvgFill(ctx);
  1829. }
  1830. void bndInnerBox(NVGcontext *ctx, float x, float y, float w, float h,
  1831. float cr0, float cr1, float cr2, float cr3,
  1832. NVGcolor shade_top, NVGcolor shade_down) {
  1833. nvgBeginPath(ctx);
  1834. bndRoundedBox(ctx,x+1,y+1,w-2,h-3,bnd_fmaxf(0,cr0-1),
  1835. bnd_fmaxf(0,cr1-1),bnd_fmaxf(0,cr2-1),bnd_fmaxf(0,cr3-1));
  1836. nvgFillPaint(ctx,((h-2)>w)?
  1837. nvgLinearGradient(ctx,x,y,x+w,y,shade_top,shade_down):
  1838. nvgLinearGradient(ctx,x,y,x,y+h,shade_top,shade_down));
  1839. nvgFill(ctx);
  1840. }
  1841. void bndOutlineBox(NVGcontext *ctx, float x, float y, float w, float h,
  1842. float cr0, float cr1, float cr2, float cr3, NVGcolor color) {
  1843. nvgBeginPath(ctx);
  1844. bndRoundedBox(ctx,x+0.5f,y+0.5f,w-1,h-2,cr0,cr1,cr2,cr3);
  1845. nvgStrokeColor(ctx,color);
  1846. nvgStrokeWidth(ctx,1);
  1847. nvgStroke(ctx);
  1848. }
  1849. void bndSelectCorners(float *radiuses, float r, int flags) {
  1850. radiuses[0] = (flags & BND_CORNER_TOP_LEFT)?0:r;
  1851. radiuses[1] = (flags & BND_CORNER_TOP_RIGHT)?0:r;
  1852. radiuses[2] = (flags & BND_CORNER_DOWN_RIGHT)?0:r;
  1853. radiuses[3] = (flags & BND_CORNER_DOWN_LEFT)?0:r;
  1854. }
  1855. void bndInnerColors(
  1856. NVGcolor *shade_top, NVGcolor *shade_down,
  1857. const BNDwidgetTheme *theme, BNDwidgetState state, int flipActive) {
  1858. switch(state) {
  1859. default:
  1860. case BND_DEFAULT: {
  1861. *shade_top = bndOffsetColor(theme->innerColor, theme->shadeTop);
  1862. *shade_down = bndOffsetColor(theme->innerColor, theme->shadeDown);
  1863. } break;
  1864. case BND_HOVER: {
  1865. NVGcolor color = bndOffsetColor(theme->innerColor, BND_HOVER_SHADE);
  1866. *shade_top = bndOffsetColor(color, theme->shadeTop);
  1867. *shade_down = bndOffsetColor(color, theme->shadeDown);
  1868. } break;
  1869. case BND_ACTIVE: {
  1870. *shade_top = bndOffsetColor(theme->innerSelectedColor,
  1871. flipActive?theme->shadeDown:theme->shadeTop);
  1872. *shade_down = bndOffsetColor(theme->innerSelectedColor,
  1873. flipActive?theme->shadeTop:theme->shadeDown);
  1874. } break;
  1875. }
  1876. }
  1877. NVGcolor bndTextColor(const BNDwidgetTheme *theme, BNDwidgetState state) {
  1878. return (state == BND_ACTIVE)?theme->textSelectedColor:theme->textColor;
  1879. }
  1880. void bndIconLabelValue(NVGcontext *ctx, float x, float y, float w, float h,
  1881. int iconid, NVGcolor color, int align, float fontsize, const char *label,
  1882. const char *value) {
  1883. float pleft = BND_PAD_LEFT;
  1884. if (label) {
  1885. if (iconid >= 0) {
  1886. bndIcon(ctx,x+4,y+2,iconid);
  1887. pleft += BND_ICON_SHEET_RES;
  1888. }
  1889. if (bnd_font < 0) return;
  1890. nvgFontFaceId(ctx, bnd_font);
  1891. nvgFontSize(ctx, fontsize);
  1892. nvgBeginPath(ctx);
  1893. nvgFillColor(ctx, color);
  1894. if (value) {
  1895. float label_width = nvgTextBounds(ctx, 1, 1, label, NULL, NULL);
  1896. float sep_width = nvgTextBounds(ctx, 1, 1,
  1897. BND_LABEL_SEPARATOR, NULL, NULL);
  1898. nvgTextAlign(ctx, NVG_ALIGN_LEFT|NVG_ALIGN_BASELINE);
  1899. x += pleft;
  1900. if (align == BND_CENTER) {
  1901. float width = label_width + sep_width
  1902. + nvgTextBounds(ctx, 1, 1, value, NULL, NULL);
  1903. x += ((w-BND_PAD_RIGHT-pleft)-width)*0.5f;
  1904. }
  1905. y += BND_WIDGET_HEIGHT-BND_TEXT_PAD_DOWN;
  1906. nvgText(ctx, x, y, label, NULL);
  1907. x += label_width;
  1908. nvgText(ctx, x, y, BND_LABEL_SEPARATOR, NULL);
  1909. x += sep_width;
  1910. nvgText(ctx, x, y, value, NULL);
  1911. } else {
  1912. nvgTextAlign(ctx,
  1913. (align==BND_LEFT)?(NVG_ALIGN_LEFT|NVG_ALIGN_BASELINE):
  1914. (NVG_ALIGN_CENTER|NVG_ALIGN_BASELINE));
  1915. nvgTextBox(ctx,x+pleft,y+BND_WIDGET_HEIGHT-BND_TEXT_PAD_DOWN,
  1916. w-BND_PAD_RIGHT-pleft,label, NULL);
  1917. }
  1918. } else if (iconid >= 0) {
  1919. bndIcon(ctx,x+2,y+2,iconid);
  1920. }
  1921. }
  1922. void bndNodeIconLabel(NVGcontext *ctx, float x, float y, float w, float h,
  1923. int iconid, NVGcolor color, NVGcolor shadowColor,
  1924. int align, float fontsize, const char *label) {
  1925. if (label && (bnd_font >= 0)) {
  1926. nvgFontFaceId(ctx, bnd_font);
  1927. nvgFontSize(ctx, fontsize);
  1928. nvgBeginPath(ctx);
  1929. nvgTextAlign(ctx, NVG_ALIGN_LEFT|NVG_ALIGN_BASELINE);
  1930. nvgFillColor(ctx, shadowColor);
  1931. nvgFontBlur(ctx, BND_NODE_TITLE_FEATHER);
  1932. nvgTextBox(ctx,x+1,y+h+3-BND_TEXT_PAD_DOWN,
  1933. w,label, NULL);
  1934. nvgFillColor(ctx, color);
  1935. nvgFontBlur(ctx, 0);
  1936. nvgTextBox(ctx,x,y+h+2-BND_TEXT_PAD_DOWN,
  1937. w,label, NULL);
  1938. }
  1939. if (iconid >= 0) {
  1940. bndIcon(ctx,x+w-BND_ICON_SHEET_RES,y+3,iconid);
  1941. }
  1942. }
  1943. int bndIconLabelTextPosition(NVGcontext *ctx, float x, float y, float w, float h,
  1944. int iconid, float fontsize, const char *label, int px, int py) {
  1945. float bounds[4];
  1946. float pleft = BND_TEXT_RADIUS;
  1947. if (!label) return -1;
  1948. if (iconid >= 0)
  1949. pleft += BND_ICON_SHEET_RES;
  1950. if (bnd_font < 0) return -1;
  1951. x += pleft;
  1952. y += BND_WIDGET_HEIGHT - BND_TEXT_PAD_DOWN;
  1953. nvgFontFaceId(ctx, bnd_font);
  1954. nvgFontSize(ctx, fontsize);
  1955. nvgTextAlign(ctx, NVG_ALIGN_LEFT | NVG_ALIGN_BASELINE);
  1956. w -= BND_TEXT_RADIUS + pleft;
  1957. float asc, desc, lh;
  1958. static NVGtextRow rows[BND_MAX_ROWS];
  1959. int nrows = nvgTextBreakLines(
  1960. ctx, label, NULL, w, rows, BND_MAX_ROWS);
  1961. if (nrows == 0) return 0;
  1962. nvgTextBoxBounds(ctx, x, y, w, label, NULL, bounds);
  1963. nvgTextMetrics(ctx, &asc, &desc, &lh);
  1964. // calculate vertical position
  1965. int row = bnd_clamp((int)((float)(py - bounds[1]) / lh), 0, nrows - 1);
  1966. // search horizontal position
  1967. static NVGglyphPosition glyphs[BND_MAX_GLYPHS];
  1968. int nglyphs = nvgTextGlyphPositions(
  1969. ctx, x, y, rows[row].start, rows[row].end + 1, glyphs, BND_MAX_GLYPHS);
  1970. int col, p = 0;
  1971. for (col = 0; col < nglyphs && glyphs[col].x < px; ++col)
  1972. p = glyphs[col].str - label;
  1973. // see if we should move one character further
  1974. if (col > 0 && col < nglyphs && glyphs[col].x - px < px - glyphs[col - 1].x)
  1975. p = glyphs[col].str - label;
  1976. return p;
  1977. }
  1978. static void bndCaretPosition(NVGcontext *ctx, float x, float y,
  1979. float desc, float lineHeight, const char *caret, NVGtextRow *rows,int nrows,
  1980. int *cr, float *cx, float *cy) {
  1981. static NVGglyphPosition glyphs[BND_MAX_GLYPHS];
  1982. int r,nglyphs;
  1983. for (r=0; r < nrows-1 && rows[r].end < caret; ++r);
  1984. *cr = r;
  1985. *cx = x;
  1986. *cy = y-lineHeight-desc + r*lineHeight;
  1987. if (nrows == 0) return;
  1988. *cx = rows[r].minx;
  1989. nglyphs = nvgTextGlyphPositions(
  1990. ctx, x, y, rows[r].start, rows[r].end+1, glyphs, BND_MAX_GLYPHS);
  1991. for (int i=0; i < nglyphs; ++i) {
  1992. *cx=glyphs[i].x;
  1993. if (glyphs[i].str == caret) break;
  1994. }
  1995. }
  1996. void bndIconLabelCaret(NVGcontext *ctx, float x, float y, float w, float h,
  1997. int iconid, NVGcolor color, float fontsize, const char *label,
  1998. NVGcolor caretcolor, int cbegin, int cend) {
  1999. float pleft = BND_TEXT_RADIUS;
  2000. if (!label) return;
  2001. if (iconid >= 0) {
  2002. bndIcon(ctx,x+4,y+2,iconid);
  2003. pleft += BND_ICON_SHEET_RES;
  2004. }
  2005. if (bnd_font < 0) return;
  2006. x+=pleft;
  2007. y+=BND_WIDGET_HEIGHT-BND_TEXT_PAD_DOWN;
  2008. nvgFontFaceId(ctx, bnd_font);
  2009. nvgFontSize(ctx, fontsize);
  2010. nvgTextAlign(ctx, NVG_ALIGN_LEFT|NVG_ALIGN_BASELINE);
  2011. w -= BND_TEXT_RADIUS+pleft;
  2012. if (cend >= cbegin) {
  2013. int c0r,c1r;
  2014. float c0x,c0y,c1x,c1y;
  2015. float desc,lh;
  2016. static NVGtextRow rows[BND_MAX_ROWS];
  2017. int nrows = nvgTextBreakLines(
  2018. ctx, label, label+cend+1, w, rows, BND_MAX_ROWS);
  2019. nvgTextMetrics(ctx, NULL, &desc, &lh);
  2020. bndCaretPosition(ctx, x, y, desc, lh, label+cbegin,
  2021. rows, nrows, &c0r, &c0x, &c0y);
  2022. bndCaretPosition(ctx, x, y, desc, lh, label+cend,
  2023. rows, nrows, &c1r, &c1x, &c1y);
  2024. nvgBeginPath(ctx);
  2025. if (cbegin == cend) {
  2026. nvgFillColor(ctx, nvgRGBf(0.337,0.502,0.761));
  2027. nvgRect(ctx, c0x-1, c0y, 2, lh+1);
  2028. } else {
  2029. nvgFillColor(ctx, caretcolor);
  2030. if (c0r == c1r) {
  2031. nvgRect(ctx, c0x-1, c0y, c1x-c0x+1, lh+1);
  2032. } else {
  2033. int blk=c1r-c0r-1;
  2034. nvgRect(ctx, c0x-1, c0y, x+w-c0x+1, lh+1);
  2035. nvgRect(ctx, x, c1y, c1x-x+1, lh+1);
  2036. if (blk)
  2037. nvgRect(ctx, x, c0y+lh, w, blk*lh+1);
  2038. }
  2039. }
  2040. nvgFill(ctx);
  2041. }
  2042. nvgBeginPath(ctx);
  2043. nvgFillColor(ctx, color);
  2044. nvgTextBox(ctx,x,y,w,label, NULL);
  2045. }
  2046. void bndCheck(NVGcontext *ctx, float ox, float oy, NVGcolor color) {
  2047. nvgBeginPath(ctx);
  2048. nvgStrokeWidth(ctx,2);
  2049. nvgStrokeColor(ctx,color);
  2050. nvgLineCap(ctx,NVG_BUTT);
  2051. nvgLineJoin(ctx,NVG_MITER);
  2052. nvgMoveTo(ctx,ox+4,oy+5);
  2053. nvgLineTo(ctx,ox+7,oy+8);
  2054. nvgLineTo(ctx,ox+14,oy+1);
  2055. nvgStroke(ctx);
  2056. }
  2057. void bndArrow(NVGcontext *ctx, float x, float y, float s, NVGcolor color) {
  2058. nvgBeginPath(ctx);
  2059. nvgMoveTo(ctx,x,y);
  2060. nvgLineTo(ctx,x-s,y+s);
  2061. nvgLineTo(ctx,x-s,y-s);
  2062. nvgClosePath(ctx);
  2063. nvgFillColor(ctx,color);
  2064. nvgFill(ctx);
  2065. }
  2066. void bndUpDownArrow(NVGcontext *ctx, float x, float y, float s, NVGcolor color) {
  2067. float w;
  2068. nvgBeginPath(ctx);
  2069. w = 1.1f*s;
  2070. nvgMoveTo(ctx,x,y-1);
  2071. nvgLineTo(ctx,x+0.5*w,y-s-1);
  2072. nvgLineTo(ctx,x+w,y-1);
  2073. nvgClosePath(ctx);
  2074. nvgMoveTo(ctx,x,y+1);
  2075. nvgLineTo(ctx,x+0.5*w,y+s+1);
  2076. nvgLineTo(ctx,x+w,y+1);
  2077. nvgClosePath(ctx);
  2078. nvgFillColor(ctx,color);
  2079. nvgFill(ctx);
  2080. }
  2081. void bndNodeArrowDown(NVGcontext *ctx, float x, float y, float s, NVGcolor color) {
  2082. float w;
  2083. nvgBeginPath(ctx);
  2084. w = 1.0f*s;
  2085. nvgMoveTo(ctx,x,y);
  2086. nvgLineTo(ctx,x+0.5*w,y-s);
  2087. nvgLineTo(ctx,x-0.5*w,y-s);
  2088. nvgClosePath(ctx);
  2089. nvgFillColor(ctx,color);
  2090. nvgFill(ctx);
  2091. }
  2092. void bndScrollHandleRect(float *x, float *y, float *w, float *h,
  2093. float offset, float size) {
  2094. size = bnd_clamp(size,0,1);
  2095. offset = bnd_clamp(offset,0,1);
  2096. if ((*h) > (*w)) {
  2097. float hs = bnd_fmaxf(size*(*h), (*w)+1);
  2098. *y = (*y) + ((*h)-hs)*offset;
  2099. *h = hs;
  2100. } else {
  2101. float ws = bnd_fmaxf(size*(*w), (*h)-1);
  2102. *x = (*x) + ((*w)-ws)*offset;
  2103. *w = ws;
  2104. }
  2105. }
  2106. NVGcolor bndNodeWireColor(const BNDnodeTheme *theme, BNDwidgetState state) {
  2107. switch(state) {
  2108. default:
  2109. case BND_DEFAULT: return nvgRGBf(0.5f,0.5f,0.5f);
  2110. case BND_HOVER: return theme->wireSelectColor;
  2111. case BND_ACTIVE: return theme->activeNodeColor;
  2112. }
  2113. }
  2114. ////////////////////////////////////////////////////////////////////////////////
  2115. #ifdef BND_INLINE
  2116. #undef BND_INLINE
  2117. #endif
  2118. #endif // BLENDISH_IMPLEMENTATION