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.

1586 lines
56KB

  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 4 (2014-07-09)
  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 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. // if that typedef is provided elsewhere, you may define
  57. // BLENDISH_NO_NVG_TYPEDEFS before including the header.
  58. #ifndef BLENDISH_NO_NVG_TYPEDEFS
  59. typedef struct NVGcontext NVGcontext;
  60. typedef struct NVGcolor NVGcolor;
  61. typedef struct NVGglyphPosition NVGglyphPosition;
  62. #endif
  63. // describes the theme used to draw a single widget or widget box;
  64. // these values correspond to the same values that can be retrieved from
  65. // the Theme panel in the Blender preferences
  66. typedef struct BNDwidgetTheme {
  67. // color of widget box outline
  68. NVGcolor outlineColor;
  69. // color of widget item (meaning changes depending on class)
  70. NVGcolor itemColor;
  71. // fill color of widget box
  72. NVGcolor innerColor;
  73. // fill color of widget box when active
  74. NVGcolor innerSelectedColor;
  75. // color of text label
  76. NVGcolor textColor;
  77. // color of text label when active
  78. NVGcolor textSelectedColor;
  79. // delta modifier for upper part of gradient (-100 to 100)
  80. int shadeTop;
  81. // delta modifier for lower part of gradient (-100 to 100)
  82. int shadeDown;
  83. } BNDwidgetTheme;
  84. // describes the theme used to draw nodes
  85. typedef struct BNDnodeTheme {
  86. // inner color of selected node (and downarrow)
  87. NVGcolor nodeSelectedColor;
  88. // outline of wires
  89. NVGcolor wiresColor;
  90. // color of text label when active
  91. NVGcolor textSelectedColor;
  92. // inner color of active node (and dragged wire)
  93. NVGcolor activeNodeColor;
  94. // color of selected wire
  95. NVGcolor wireSelectColor;
  96. // color of background of node
  97. NVGcolor nodeBackdropColor;
  98. // how much a noodle curves (0 to 10)
  99. int noodleCurving;
  100. } BNDnodeTheme;
  101. // describes the theme used to draw widgets
  102. typedef struct BNDtheme {
  103. // the background color of panels and windows
  104. NVGcolor backgroundColor;
  105. // theme for labels
  106. BNDwidgetTheme regularTheme;
  107. // theme for tool buttons
  108. BNDwidgetTheme toolTheme;
  109. // theme for radio buttons
  110. BNDwidgetTheme radioTheme;
  111. // theme for text fields
  112. BNDwidgetTheme textFieldTheme;
  113. // theme for option buttons (checkboxes)
  114. BNDwidgetTheme optionTheme;
  115. // theme for choice buttons (comboboxes)
  116. // Blender calls them "menu buttons"
  117. BNDwidgetTheme choiceTheme;
  118. // theme for number fields
  119. BNDwidgetTheme numberFieldTheme;
  120. // theme for slider controls
  121. BNDwidgetTheme sliderTheme;
  122. // theme for scrollbars
  123. BNDwidgetTheme scrollBarTheme;
  124. // theme for tooltips
  125. BNDwidgetTheme tooltipTheme;
  126. // theme for menu backgrounds
  127. BNDwidgetTheme menuTheme;
  128. // theme for menu items
  129. BNDwidgetTheme menuItemTheme;
  130. // theme for nodes
  131. BNDnodeTheme nodeTheme;
  132. } BNDtheme;
  133. // how text on a control is aligned
  134. typedef enum BNDtextAlignment {
  135. BND_LEFT = 0,
  136. BND_CENTER,
  137. } BNDtextAlignment;
  138. // states altering the styling of a widget
  139. typedef enum BNDwidgetState {
  140. // not interacting
  141. BND_DEFAULT = 0,
  142. // the mouse is hovering over the control
  143. BND_HOVER,
  144. // the widget is activated (pressed) or in an active state (toggled)
  145. BND_ACTIVE
  146. } BNDwidgetState;
  147. // flags indicating which corners are sharp (for grouping widgets)
  148. typedef enum BNDcornerFlags {
  149. // all corners are round
  150. BND_CORNER_NONE = 0,
  151. // sharp top left corner
  152. BND_CORNER_TOP_LEFT = 1,
  153. // sharp top right corner
  154. BND_CORNER_TOP_RIGHT = 2,
  155. // sharp bottom right corner
  156. BND_CORNER_DOWN_RIGHT = 4,
  157. // sharp bottom left corner
  158. BND_CORNER_DOWN_LEFT = 8,
  159. // all corners are sharp;
  160. // you can invert a set of flags using ^= BND_CORNER_ALL
  161. BND_CORNER_ALL = 0xF,
  162. // top border is sharp
  163. BND_CORNER_TOP = 3,
  164. // bottom border is sharp
  165. BND_CORNER_DOWN = 0xC,
  166. // left border is sharp
  167. BND_CORNER_LEFT = 9,
  168. // right border is sharp
  169. BND_CORNER_RIGHT = 6
  170. } BNDcornerFlags;
  171. // build an icon ID from two coordinates into the icon sheet, where
  172. // (0,0) designates the upper-leftmost icon, (1,0) the one right next to it,
  173. // and so on.
  174. #define BND_ICONID(x,y) ((x)|((y)<<8))
  175. // default widget height
  176. #define BND_WIDGET_HEIGHT 21
  177. // default toolbutton width (if icon only)
  178. #define BND_TOOL_WIDTH 20
  179. // default radius of node ports
  180. #define BND_NODE_PORT_RADIUS 5
  181. // top margin of node content
  182. #define BND_NODE_MARGIN_TOP 25
  183. // bottom margin of node content
  184. #define BND_NODE_MARGIN_DOWN 5
  185. // left and right margin of node content
  186. #define BND_NODE_MARGIN_SIDE 10
  187. // height of node title bar
  188. #define BND_NODE_TITLE_HEIGHT 20
  189. // width of node title arrow click area
  190. #define BND_NODE_ARROW_AREA_WIDTH 20
  191. // width of vertical scrollbar
  192. #define BND_SCROLLBAR_WIDTH 13
  193. // height of horizontal scrollbar
  194. #define BND_SCROLLBAR_HEIGHT 14
  195. // default vertical spacing
  196. #define BND_VSPACING 1
  197. // default vertical spacing between groups
  198. #define BND_VSPACING_GROUP 8
  199. // default horizontal spacing
  200. #define BND_HSPACING 8
  201. // alpha of disabled widget groups
  202. // can be used in conjunction with nvgGlobalAlpha()
  203. #define BND_DISABLED_ALPHA 0.5
  204. ////////////////////////////////////////////////////////////////////////////////
  205. // set the current theme all widgets will be drawn with.
  206. // the default Blender 2.6 theme is set by default.
  207. void bndSetTheme(BNDtheme theme);
  208. // Returns the currently set theme
  209. const BNDtheme *bndGetTheme();
  210. // designates an image handle as returned by nvgCreateImage*() as the themes'
  211. // icon sheet. The icon sheet format must be compatible to Blender 2.6's icon
  212. // sheet; the order of icons does not matter.
  213. // A valid icon sheet is e.g. shown at
  214. // http://wiki.blender.org/index.php/Dev:2.5/Doc/How_to/Add_an_icon
  215. void bndSetIconImage(int image);
  216. // designates an image handle as returned by nvgCreateFont*() as the themes'
  217. // UI font. Blender's original UI font Droid Sans is perfectly suited and
  218. // available here:
  219. // https://svn.blender.org/svnroot/bf-blender/trunk/blender/release/datafiles/fonts/
  220. void bndSetFont(int font);
  221. ////////////////////////////////////////////////////////////////////////////////
  222. // High Level Functions
  223. // --------------------
  224. // Use these functions to draw themed widgets with your NVGcontext.
  225. // Draw a label with its lower left origin at (x,y) and size of (w,h).
  226. // if iconid >= 0, an icon will be added to the widget
  227. // if label is not NULL, a label will be added to the widget
  228. // widget looks best when height is BND_WIDGET_HEIGHT
  229. void bndLabel(NVGcontext *ctx,
  230. float x, float y, float w, float h, int iconid, const char *label);
  231. // Draw a tool button with its lower left origin at (x,y) and size of (w,h),
  232. // where flags is one or multiple flags from BNDcornerFlags and state denotes
  233. // the widgets current UI state.
  234. // if iconid >= 0, an icon will be added to the widget
  235. // if label is not NULL, a label will be added to the widget
  236. // widget looks best when height is BND_WIDGET_HEIGHT
  237. void bndToolButton(NVGcontext *ctx,
  238. float x, float y, float w, float h, int flags, BNDwidgetState state,
  239. int iconid, const char *label);
  240. // Draw a radio button with its lower left origin at (x,y) and size of (w,h),
  241. // where flags is one or multiple flags from BNDcornerFlags and state denotes
  242. // the widgets current UI state.
  243. // if iconid >= 0, an icon will be added to the widget
  244. // if label is not NULL, a label will be added to the widget
  245. // widget looks best when height is BND_WIDGET_HEIGHT
  246. void bndRadioButton(NVGcontext *ctx,
  247. float x, float y, float w, float h, int flags, BNDwidgetState state,
  248. int iconid, const char *label);
  249. // Draw a text field with its lower left origin at (x,y) and size of (w,h),
  250. // where flags is one or multiple flags from BNDcornerFlags and state denotes
  251. // the widgets current UI state.
  252. // if iconid >= 0, an icon will be added to the widget
  253. // if text is not NULL, text will be printed to the widget
  254. // cbegin must be >= 0 and <= strlen(text) and denotes the beginning of the caret
  255. // cend must be >= cbegin and <= strlen(text) and denotes the end of the caret
  256. // if cend < cbegin, then no caret will be drawn
  257. // widget looks best when height is BND_WIDGET_HEIGHT
  258. void bndTextField(NVGcontext *ctx,
  259. float x, float y, float w, float h, int flags, BNDwidgetState state,
  260. int iconid, const char *text, int cbegin, int cend);
  261. // Draw an option button with its lower left origin at (x,y) and size of (w,h),
  262. // where flags is one or multiple flags from BNDcornerFlags and state denotes
  263. // the widgets current UI state.
  264. // if label is not NULL, a label will be added to the widget
  265. // widget looks best when height is BND_WIDGET_HEIGHT
  266. void bndOptionButton(NVGcontext *ctx,
  267. float x, float y, float w, float h, BNDwidgetState state,
  268. const char *label);
  269. // Draw a choice button with its lower left origin at (x,y) and size of (w,h),
  270. // where flags is one or multiple flags from BNDcornerFlags and state denotes
  271. // the widgets current UI state.
  272. // if iconid >= 0, an icon will be added to the widget
  273. // if label is not NULL, a label will be added to the widget
  274. // widget looks best when height is BND_WIDGET_HEIGHT
  275. void bndChoiceButton(NVGcontext *ctx,
  276. float x, float y, float w, float h, int flags, BNDwidgetState state,
  277. int iconid, const char *label);
  278. // Draw a number field with its lower left origin at (x,y) and size of (w,h),
  279. // where flags is one or multiple flags from BNDcornerFlags and state denotes
  280. // the widgets current UI state.
  281. // if label is not NULL, a label will be added to the widget
  282. // if value is not NULL, a value will be added to the widget, along with
  283. // a ":" separator
  284. // widget looks best when height is BND_WIDGET_HEIGHT
  285. void bndNumberField(NVGcontext *ctx,
  286. float x, float y, float w, float h, int flags, BNDwidgetState state,
  287. const char *label, const char *value);
  288. // Draw slider control with its lower left origin at (x,y) and size of (w,h),
  289. // where flags is one or multiple flags from BNDcornerFlags and state denotes
  290. // the widgets current UI state.
  291. // progress must be in the range 0..1 and controls the size of the slider bar
  292. // if label is not NULL, a label will be added to the widget
  293. // if value is not NULL, a value will be added to the widget, along with
  294. // a ":" separator
  295. // widget looks best when height is BND_WIDGET_HEIGHT
  296. void bndSlider(NVGcontext *ctx,
  297. float x, float y, float w, float h, int flags, BNDwidgetState state,
  298. float progress, const char *label, const char *value);
  299. // Draw scrollbar with its lower left origin at (x,y) and size of (w,h),
  300. // where state denotes the widgets current UI state.
  301. // offset is in the range 0..1 and controls the position of the scroll handle
  302. // size is in the range 0..1 and controls the size of the scroll handle
  303. // horizontal widget looks best when height is BND_SCROLLBAR_HEIGHT,
  304. // vertical looks best when width is BND_SCROLLBAR_WIDTH
  305. void bndScrollBar(NVGcontext *ctx,
  306. float x, float y, float w, float h, BNDwidgetState state,
  307. float offset, float size);
  308. // Draw a menu background with its lower left origin at (x,y) and size of (w,h),
  309. // where flags is one or multiple flags from BNDcornerFlags.
  310. void bndMenuBackground(NVGcontext *ctx,
  311. float x, float y, float w, float h, int flags);
  312. // Draw a menu label with its lower left origin at (x,y) and size of (w,h).
  313. // if iconid >= 0, an icon will be added to the widget
  314. // if label is not NULL, a label will be added to the widget
  315. // widget looks best when height is BND_WIDGET_HEIGHT
  316. void bndMenuLabel(NVGcontext *ctx,
  317. float x, float y, float w, float h, int iconid, const char *label);
  318. // Draw a menu item with its lower left origin at (x,y) and size of (w,h),
  319. // where state denotes the widgets current UI state.
  320. // if iconid >= 0, an icon will be added to the widget
  321. // if label is not NULL, a label will be added to the widget
  322. // widget looks best when height is BND_WIDGET_HEIGHT
  323. void bndMenuItem(NVGcontext *ctx,
  324. float x, float y, float w, float h, BNDwidgetState state,
  325. int iconid, const char *label);
  326. // Draw a tooltip background with its lower left origin at (x,y) and size of (w,h)
  327. void bndTooltipBackground(NVGcontext *ctx, float x, float y, float w, float h);
  328. // Draw a node port at the given position filled with the given color
  329. void bndNodePort(NVGcontext *ctx, float x, float y, BNDwidgetState state,
  330. NVGcolor color);
  331. // Draw a node wire originating at (x0,y0) and floating to (x1,y1), with
  332. // a colored gradient based on the states state0 and state1:
  333. // BND_DEFAULT: default wire color
  334. // BND_HOVER: selected wire color
  335. // BND_ACTIVE: dragged wire color
  336. void bndNodeWire(NVGcontext *ctx, float x0, float y0, float x1, float y1,
  337. BNDwidgetState state0, BNDwidgetState state1);
  338. // Draw a node background with its upper left origin at (x,y) and size of (w,h)
  339. // where titleColor provides the base color for the title bar
  340. void bndNodeBackground(NVGcontext *ctx, float x, float y, float w, float h,
  341. BNDwidgetState state, int iconid, const char *label, NVGcolor titleColor);
  342. ////////////////////////////////////////////////////////////////////////////////
  343. // Estimator Functions
  344. // -------------------
  345. // Use these functions to estimate sizes for widgets with your NVGcontext.
  346. // returns the ideal width for a label with given icon and text
  347. float bndLabelWidth(NVGcontext *ctx, int iconid, const char *label);
  348. ////////////////////////////////////////////////////////////////////////////////
  349. // Low Level Functions
  350. // -------------------
  351. // these are part of the implementation detail and can be used to theme
  352. // new kinds of controls in a similar fashion.
  353. // make color transparent using the default alpha value
  354. NVGcolor bndTransparent(NVGcolor color);
  355. // offset a color by a given integer delta in the range -100 to 100
  356. NVGcolor bndOffsetColor(NVGcolor color, int delta);
  357. // assigns radius r to the four entries of array radiuses depending on whether
  358. // the corner is marked as sharp or not; see BNDcornerFlags for possible
  359. // flag values.
  360. void bndSelectCorners(float *radiuses, float r, int flags);
  361. // computes the upper and lower gradient colors for the inner box from a widget
  362. // theme and the widgets state. If flipActive is set and the state is
  363. // BND_ACTIVE, the upper and lower colors will be swapped.
  364. void bndInnerColors(NVGcolor *shade_top, NVGcolor *shade_down,
  365. const BNDwidgetTheme *theme, BNDwidgetState state, int flipActive);
  366. // computes the text color for a widget label from a widget theme and the
  367. // widgets state.
  368. NVGcolor bndTextColor(const BNDwidgetTheme *theme, BNDwidgetState state);
  369. // computes the bounds of the scrollbar handle from the scrollbar size
  370. // and the handles offset and size.
  371. // offset is in the range 0..1 and defines the position of the scroll handle
  372. // size is in the range 0..1 and defines the size of the scroll handle
  373. void bndScrollHandleRect(float *x, float *y, float *w, float *h,
  374. float offset, float size);
  375. // Add a rounded box path at position (x,y) with size (w,h) and a separate
  376. // radius for each corner listed in clockwise order, so that cr0 = top left,
  377. // cr1 = top right, cr2 = bottom right, cr3 = bottom left;
  378. // this is a low level drawing function: the path must be stroked or filled
  379. // to become visible.
  380. void bndRoundedBox(NVGcontext *ctx, float x, float y, float w, float h,
  381. float cr0, float cr1, float cr2, float cr3);
  382. // Draw a flat panel without any decorations at position (x,y) with size (w,h)
  383. // and fills it with backgroundColor
  384. void bndBackground(NVGcontext *ctx, float x, float y, float w, float h);
  385. // Draw a beveled border at position (x,y) with size (w,h) shaded with
  386. // lighter and darker versions of backgroundColor
  387. void bndBevel(NVGcontext *ctx, float x, float y, float w, float h);
  388. // Draw a lower inset for a rounded box at position (x,y) with size (w,h)
  389. // that gives the impression the surface has been pushed in.
  390. // cr2 and cr3 contain the radiuses of the bottom right and bottom left
  391. // corners of the rounded box.
  392. void bndBevelInset(NVGcontext *ctx, float x, float y, float w, float h,
  393. float cr2, float cr3);
  394. // Draw an icon with (x,y) as its upper left coordinate; the iconid selects
  395. // the icon from the sheet; use the BND_ICONID macro to build icon IDs.
  396. void bndIcon(NVGcontext *ctx, float x, float y, int iconid);
  397. // Draw a drop shadow around the rounded box at (x,y) with size (w,h) and
  398. // radius r, with feather as its maximum range in pixels.
  399. // No shadow will be painted inside the rounded box.
  400. void bndDropShadow(NVGcontext *ctx, float x, float y, float w, float h,
  401. float r, float feather, float alpha);
  402. // Draw the inner part of a widget box, with a gradient from shade_top to
  403. // shade_down. If h>w, the gradient will be horizontal instead of
  404. // vertical.
  405. void bndInnerBox(NVGcontext *ctx, float x, float y, float w, float h,
  406. float cr0, float cr1, float cr2, float cr3,
  407. NVGcolor shade_top, NVGcolor shade_down);
  408. // Draw the outline part of a widget box with the given color
  409. void bndOutlineBox(NVGcontext *ctx, float x, float y, float w, float h,
  410. float cr0, float cr1, float cr2, float cr3, NVGcolor color);
  411. // Draw an optional icon specified by <iconid> and an optional label with
  412. // given alignment (BNDtextAlignment), fontsize and color within a widget box.
  413. // if iconid is >= 0, an icon will be drawn and the labels remaining space
  414. // will be adjusted.
  415. // if label is not NULL, it will be drawn with the specified alignment, fontsize
  416. // and color.
  417. // if value is not NULL, label and value will be drawn with a ":" separator
  418. // inbetween.
  419. void bndIconLabelValue(NVGcontext *ctx, float x, float y, float w, float h,
  420. int iconid, NVGcolor color, int align, float fontsize, const char *label,
  421. const char *value);
  422. // Draw an optional icon specified by <iconid> and an optional label with
  423. // given alignment (BNDtextAlignment), fontsize and color within a node title bar
  424. // if iconid is >= 0, an icon will be drawn
  425. // if label is not NULL, it will be drawn with the specified alignment, fontsize
  426. // and color.
  427. void bndNodeIconLabel(NVGcontext *ctx, float x, float y, float w, float h,
  428. int iconid, NVGcolor color, NVGcolor shadowColor, int align,
  429. float fontsize, const char *label);
  430. // Draw an optional icon specified by <iconid>, an optional label and
  431. // a caret with given fontsize and color within a widget box.
  432. // if iconid is >= 0, an icon will be drawn and the labels remaining space
  433. // will be adjusted.
  434. // if label is not NULL, it will be drawn with the specified alignment, fontsize
  435. // and color.
  436. // cbegin must be >= 0 and <= strlen(text) and denotes the beginning of the caret
  437. // cend must be >= cbegin and <= strlen(text) and denotes the end of the caret
  438. // if cend < cbegin, then no caret will be drawn
  439. void bndIconLabelCaret(NVGcontext *ctx, float x, float y, float w, float h,
  440. int iconid, NVGcolor color, float fontsize, const char *label,
  441. NVGcolor caretcolor, int cbegin, int cend);
  442. // Draw a checkmark for an option box with the given upper left coordinates
  443. // (ox,oy) with the specified color.
  444. void bndCheck(NVGcontext *ctx, float ox, float oy, NVGcolor color);
  445. // Draw a horizontal arrow for a number field with its center at (x,y) and
  446. // size s; if s is negative, the arrow points to the left.
  447. void bndArrow(NVGcontext *ctx, float x, float y, float s, NVGcolor color);
  448. // Draw an up/down arrow for a choice box with its center at (x,y) and size s
  449. void bndUpDownArrow(NVGcontext *ctx, float x, float y, float s, NVGcolor color);
  450. // Draw a node down-arrow with its tip at (x,y) and size s
  451. void bndNodeArrowDown(NVGcontext *ctx, float x, float y, float s, NVGcolor color);
  452. // return the color of a node wire based on state
  453. // BND_HOVER indicates selected state,
  454. // BND_ACTIVE indicates dragged state
  455. NVGcolor bndNodeWireColor(const BNDnodeTheme *theme, BNDwidgetState state);
  456. #ifdef __cplusplus
  457. };
  458. #endif
  459. #endif // BLENDISH_H
  460. ////////////////////////////////////////////////////////////////////////////////
  461. ////////////////////////////////////////////////////////////////////////////////
  462. #ifdef BLENDISH_IMPLEMENTATION
  463. #include <memory.h>
  464. #include <math.h>
  465. #ifdef _MSC_VER
  466. #pragma warning (disable: 4996) // Switch off security warnings
  467. #pragma warning (disable: 4100) // Switch off unreferenced formal parameter warnings
  468. #ifdef __cplusplus
  469. #define BND_INLINE inline
  470. #else
  471. #define BND_INLINE
  472. #endif
  473. #else
  474. #define BND_INLINE inline
  475. #endif
  476. ////////////////////////////////////////////////////////////////////////////////
  477. // default text size
  478. #define BND_LABEL_FONT_SIZE 13
  479. // default text padding in inner box
  480. #define BND_PAD_LEFT 8
  481. #define BND_PAD_RIGHT 8
  482. // label: value separator string
  483. #define BND_LABEL_SEPARATOR ": "
  484. // alpha intensity of transparent items (0xa4)
  485. #define BND_TRANSPARENT_ALPHA 0.643
  486. // shade intensity of beveled panels
  487. #define BND_BEVEL_SHADE 30
  488. // shade intensity of beveled insets
  489. #define BND_INSET_BEVEL_SHADE 30
  490. // shade intensity of hovered inner boxes
  491. #define BND_HOVER_SHADE 15
  492. // width of icon sheet
  493. #define BND_ICON_SHEET_WIDTH 602
  494. // height of icon sheet
  495. #define BND_ICON_SHEET_HEIGHT 640
  496. // gridsize of icon sheet in both dimensions
  497. #define BND_ICON_SHEET_GRID 21
  498. // offset of first icon tile relative to left border
  499. #define BND_ICON_SHEET_OFFSET_X 5
  500. // offset of first icon tile relative to top border
  501. #define BND_ICON_SHEET_OFFSET_Y 10
  502. // resolution of single icon
  503. #define BND_ICON_SHEET_RES 16
  504. // size of number field arrow
  505. #define BND_NUMBER_ARROW_SIZE 4
  506. // default text color
  507. #define BND_COLOR_TEXT {{{ 0,0,0,1 }}}
  508. // default highlighted text color
  509. #define BND_COLOR_TEXT_SELECTED {{{ 1,1,1,1 }}}
  510. // radius of tool button
  511. #define BND_TOOL_RADIUS 4
  512. // radius of option button
  513. #define BND_OPTION_RADIUS 4
  514. // width of option button checkbox
  515. #define BND_OPTION_WIDTH 14
  516. // height of option button checkbox
  517. #define BND_OPTION_HEIGHT 15
  518. // radius of text field
  519. #define BND_TEXT_RADIUS 4
  520. // radius of number button
  521. #define BND_NUMBER_RADIUS 10
  522. // radius of menu popup
  523. #define BND_MENU_RADIUS 3
  524. // feather of menu popup shadow
  525. #define BND_SHADOW_FEATHER 12
  526. // alpha of menu popup shadow
  527. #define BND_SHADOW_ALPHA 0.5
  528. // radius of scrollbar
  529. #define BND_SCROLLBAR_RADIUS 7
  530. // shade intensity of active scrollbar
  531. #define BND_SCROLLBAR_ACTIVE_SHADE 15
  532. // max glyphs for position testing
  533. #define BND_MAX_GLYPHS 1024
  534. // text distance from bottom
  535. #define BND_TEXT_PAD_DOWN 7
  536. // stroke width of wire outline
  537. #define BND_NODE_WIRE_OUTLINE_WIDTH 4
  538. // stroke width of wire
  539. #define BND_NODE_WIRE_WIDTH 2
  540. // radius of node box
  541. #define BND_NODE_RADIUS 8
  542. // feather of node title text
  543. #define BND_NODE_TITLE_FEATHER 1
  544. // size of node title arrow
  545. #define BND_NODE_ARROW_SIZE 9
  546. ////////////////////////////////////////////////////////////////////////////////
  547. BND_INLINE float bnd_clamp(float v, float mn, float mx) {
  548. return (v > mx)?mx:(v < mn)?mn:v;
  549. }
  550. ////////////////////////////////////////////////////////////////////////////////
  551. // the initial theme
  552. static BNDtheme bnd_theme = {
  553. // backgroundColor
  554. {{{ 0.447, 0.447, 0.447, 1.0 }}},
  555. // regularTheme
  556. {
  557. {{{ 0.098,0.098,0.098,1 }}}, // color_outline
  558. {{{ 0.098,0.098,0.098,1 }}}, // color_item
  559. {{{ 0.6,0.6,0.6,1 }}}, // color_inner
  560. {{{ 0.392,0.392,0.392,1 }}}, // color_inner_selected
  561. BND_COLOR_TEXT, // color_text
  562. BND_COLOR_TEXT_SELECTED, // color_text_selected
  563. 0, // shade_top
  564. 0, // shade_down
  565. },
  566. // toolTheme
  567. {
  568. {{{ 0.098,0.098,0.098,1 }}}, // color_outline
  569. {{{ 0.098,0.098,0.098,1 }}}, // color_item
  570. {{{ 0.6,0.6,0.6,1 }}}, // color_inner
  571. {{{ 0.392,0.392,0.392,1 }}}, // color_inner_selected
  572. BND_COLOR_TEXT, // color_text
  573. BND_COLOR_TEXT_SELECTED, // color_text_selected
  574. 15, // shade_top
  575. -15, // shade_down
  576. },
  577. // radioTheme
  578. {
  579. {{{ 0,0,0,1 }}}, // color_outline
  580. {{{ 1,1,1,1 }}}, // color_item
  581. {{{ 0.275,0.275,0.275,1 }}}, // color_inner
  582. {{{ 0.337,0.502,0.761,1 }}}, // color_inner_selected
  583. BND_COLOR_TEXT_SELECTED, // color_text
  584. BND_COLOR_TEXT, // color_text_selected
  585. 15, // shade_top
  586. -15, // shade_down
  587. },
  588. // textFieldTheme
  589. {
  590. {{{ 0.098,0.098,0.098,1 }}}, // color_outline
  591. {{{ 0.353, 0.353, 0.353,1 }}}, // color_item
  592. {{{ 0.6, 0.6, 0.6,1 }}}, // color_inner
  593. {{{ 0.6, 0.6, 0.6,1 }}}, // color_inner_selected
  594. BND_COLOR_TEXT, // color_text
  595. BND_COLOR_TEXT_SELECTED, // color_text_selected
  596. 0, // shade_top
  597. 25, // shade_down
  598. },
  599. // optionTheme
  600. {
  601. {{{ 0,0,0,1 }}}, // color_outline
  602. {{{ 1,1,1,1 }}}, // color_item
  603. {{{ 0.275,0.275,0.275,1 }}}, // color_inner
  604. {{{ 0.275,0.275,0.275,1 }}}, // color_inner_selected
  605. BND_COLOR_TEXT, // color_text
  606. BND_COLOR_TEXT_SELECTED, // color_text_selected
  607. 15, // shade_top
  608. -15, // shade_down
  609. },
  610. // choiceTheme
  611. {
  612. {{{ 0,0,0,1 }}}, // color_outline
  613. {{{ 1,1,1,1 }}}, // color_item
  614. {{{ 0.275,0.275,0.275,1 }}}, // color_inner
  615. {{{ 0.275,0.275,0.275,1 }}}, // color_inner_selected
  616. BND_COLOR_TEXT_SELECTED, // color_text
  617. {{{ 0.8,0.8,0.8,1 }}}, // color_text_selected
  618. 15, // shade_top
  619. -15, // shade_down
  620. },
  621. // numberFieldTheme
  622. {
  623. {{{ 0.098,0.098,0.098,1 }}}, // color_outline
  624. {{{ 0.353, 0.353, 0.353,1 }}}, // color_item
  625. {{{ 0.706, 0.706, 0.706,1 }}}, // color_inner
  626. {{{ 0.6, 0.6, 0.6,1 }}}, // color_inner_selected
  627. BND_COLOR_TEXT, // color_text
  628. BND_COLOR_TEXT_SELECTED, // color_text_selected
  629. -20, // shade_top
  630. 0, // shade_down
  631. },
  632. // sliderTheme
  633. {
  634. {{{ 0.098,0.098,0.098,1 }}}, // color_outline
  635. {{{ 0.502,0.502,0.502,1 }}}, // color_item
  636. {{{ 0.706, 0.706, 0.706,1 }}}, // color_inner
  637. {{{ 0.6, 0.6, 0.6,1 }}}, // color_inner_selected
  638. BND_COLOR_TEXT, // color_text
  639. BND_COLOR_TEXT_SELECTED, // color_text_selected
  640. -20, // shade_top
  641. 0, // shade_down
  642. },
  643. // scrollBarTheme
  644. {
  645. {{{ 0.196,0.196,0.196,1 }}}, // color_outline
  646. {{{ 0.502,0.502,0.502,1 }}}, // color_item
  647. {{{ 0.314, 0.314, 0.314,0.706 }}}, // color_inner
  648. {{{ 0.392, 0.392, 0.392,0.706 }}}, // color_inner_selected
  649. BND_COLOR_TEXT, // color_text
  650. BND_COLOR_TEXT_SELECTED, // color_text_selected
  651. 5, // shade_top
  652. -5, // shade_down
  653. },
  654. // tooltipTheme
  655. {
  656. {{{ 0,0,0,1 }}}, // color_outline
  657. {{{ 0.392,0.392,0.392,1 }}}, // color_item
  658. {{{ 0.098, 0.098, 0.098, 0.902 }}}, // color_inner
  659. {{{ 0.176, 0.176, 0.176, 0.902 }}}, // color_inner_selected
  660. {{{ 0.627, 0.627, 0.627, 1 }}}, // color_text
  661. BND_COLOR_TEXT_SELECTED, // color_text_selected
  662. 0, // shade_top
  663. 0, // shade_down
  664. },
  665. // menuTheme
  666. {
  667. {{{ 0,0,0,1 }}}, // color_outline
  668. {{{ 0.392,0.392,0.392,1 }}}, // color_item
  669. {{{ 0.098, 0.098, 0.098, 0.902 }}}, // color_inner
  670. {{{ 0.176, 0.176, 0.176, 0.902 }}}, // color_inner_selected
  671. {{{ 0.627, 0.627, 0.627, 1 }}}, // color_text
  672. BND_COLOR_TEXT_SELECTED, // color_text_selected
  673. 0, // shade_top
  674. 0, // shade_down
  675. },
  676. // menuItemTheme
  677. {
  678. {{{ 0,0,0,1 }}}, // color_outline
  679. {{{ 0.675,0.675,0.675,0.502 }}}, // color_item
  680. {{{ 0,0,0,0 }}}, // color_inner
  681. {{{ 0.337,0.502,0.761,1 }}}, // color_inner_selected
  682. BND_COLOR_TEXT_SELECTED, // color_text
  683. BND_COLOR_TEXT, // color_text_selected
  684. 38, // shade_top
  685. 0, // shade_down
  686. },
  687. // nodeTheme
  688. {
  689. {{{ 0.945,0.345,0,1 }}}, // nodeSelectedColor
  690. {{{ 0,0,0,1 }}}, // wiresColor
  691. {{{ 0.498,0.439,0.439,1 }}}, // textSelectedColor
  692. {{{ 1,0.667,0.251,1 }}}, // activeNodeColor
  693. {{{ 1,1,1,1 }}}, // wireSelectColor
  694. {{{ 0.608,0.608,0.608,0.627 }}}, // nodeBackdropColor
  695. 5, // noodleCurving
  696. },
  697. };
  698. ////////////////////////////////////////////////////////////////////////////////
  699. void bndSetTheme(BNDtheme theme) {
  700. bnd_theme = theme;
  701. }
  702. const BNDtheme *bndGetTheme() {
  703. return &bnd_theme;
  704. }
  705. // the handle to the image containing the icon sheet
  706. static int bnd_icon_image = -1;
  707. void bndSetIconImage(int image) {
  708. bnd_icon_image = image;
  709. }
  710. // the handle to the UI font
  711. static int bnd_font = -1;
  712. void bndSetFont(int font) {
  713. bnd_font = font;
  714. }
  715. ////////////////////////////////////////////////////////////////////////////////
  716. void bndLabel(NVGcontext *ctx,
  717. float x, float y, float w, float h, int iconid, const char *label) {
  718. bndIconLabelValue(ctx,x,y,w,h,iconid,
  719. bnd_theme.regularTheme.textColor, BND_LEFT,
  720. BND_LABEL_FONT_SIZE, label, NULL);
  721. }
  722. void bndToolButton(NVGcontext *ctx,
  723. float x, float y, float w, float h, int flags, BNDwidgetState state,
  724. int iconid, const char *label) {
  725. float cr[4];
  726. NVGcolor shade_top, shade_down;
  727. bndSelectCorners(cr, BND_TOOL_RADIUS, flags);
  728. bndBevelInset(ctx,x,y,w,h,cr[2],cr[3]);
  729. bndInnerColors(&shade_top, &shade_down, &bnd_theme.toolTheme, state, 1);
  730. bndInnerBox(ctx,x,y,w,h,cr[0],cr[1],cr[2],cr[3], shade_top, shade_down);
  731. bndOutlineBox(ctx,x,y,w,h,cr[0],cr[1],cr[2],cr[3],
  732. bndTransparent(bnd_theme.toolTheme.outlineColor));
  733. bndIconLabelValue(ctx,x,y,w,h,iconid,
  734. bndTextColor(&bnd_theme.toolTheme, state), BND_CENTER,
  735. BND_LABEL_FONT_SIZE, label, NULL);
  736. }
  737. void bndRadioButton(NVGcontext *ctx,
  738. float x, float y, float w, float h, int flags, BNDwidgetState state,
  739. int iconid, const char *label) {
  740. float cr[4];
  741. NVGcolor shade_top, shade_down;
  742. bndSelectCorners(cr, BND_OPTION_RADIUS, flags);
  743. bndBevelInset(ctx,x,y,w,h,cr[2],cr[3]);
  744. bndInnerColors(&shade_top, &shade_down, &bnd_theme.radioTheme, state, 1);
  745. bndInnerBox(ctx,x,y,w,h,cr[0],cr[1],cr[2],cr[3], shade_top, shade_down);
  746. bndOutlineBox(ctx,x,y,w,h,cr[0],cr[1],cr[2],cr[3],
  747. bndTransparent(bnd_theme.radioTheme.outlineColor));
  748. bndIconLabelValue(ctx,x,y,w,h,iconid,
  749. bndTextColor(&bnd_theme.radioTheme, state), BND_CENTER,
  750. BND_LABEL_FONT_SIZE, label, NULL);
  751. }
  752. void bndTextField(NVGcontext *ctx,
  753. float x, float y, float w, float h, int flags, BNDwidgetState state,
  754. int iconid, const char *text, int cbegin, int cend) {
  755. float cr[4];
  756. NVGcolor shade_top, shade_down;
  757. bndSelectCorners(cr, BND_TEXT_RADIUS, flags);
  758. bndBevelInset(ctx,x,y,w,h,cr[2],cr[3]);
  759. bndInnerColors(&shade_top, &shade_down, &bnd_theme.textFieldTheme, state, 0);
  760. bndInnerBox(ctx,x,y,w,h,cr[0],cr[1],cr[2],cr[3], shade_top, shade_down);
  761. bndOutlineBox(ctx,x,y,w,h,cr[0],cr[1],cr[2],cr[3],
  762. bndTransparent(bnd_theme.textFieldTheme.outlineColor));
  763. if (state != BND_ACTIVE) {
  764. cend = -1;
  765. }
  766. bndIconLabelCaret(ctx,x,y,w,h,iconid,
  767. bndTextColor(&bnd_theme.textFieldTheme, state), BND_LABEL_FONT_SIZE,
  768. text, bnd_theme.textFieldTheme.itemColor, cbegin, cend);
  769. }
  770. void bndOptionButton(NVGcontext *ctx,
  771. float x, float y, float w, float h, BNDwidgetState state,
  772. const char *label) {
  773. float ox, oy;
  774. NVGcolor shade_top, shade_down;
  775. ox = x;
  776. oy = y+h-BND_OPTION_HEIGHT-3;
  777. bndBevelInset(ctx,ox,oy,
  778. BND_OPTION_WIDTH,BND_OPTION_HEIGHT,
  779. BND_OPTION_RADIUS,BND_OPTION_RADIUS);
  780. bndInnerColors(&shade_top, &shade_down, &bnd_theme.optionTheme, state, 1);
  781. bndInnerBox(ctx,ox,oy,
  782. BND_OPTION_WIDTH,BND_OPTION_HEIGHT,
  783. BND_OPTION_RADIUS,BND_OPTION_RADIUS,BND_OPTION_RADIUS,BND_OPTION_RADIUS,
  784. shade_top, shade_down);
  785. bndOutlineBox(ctx,ox,oy,
  786. BND_OPTION_WIDTH,BND_OPTION_HEIGHT,
  787. BND_OPTION_RADIUS,BND_OPTION_RADIUS,BND_OPTION_RADIUS,BND_OPTION_RADIUS,
  788. bndTransparent(bnd_theme.optionTheme.outlineColor));
  789. if (state == BND_ACTIVE) {
  790. bndCheck(ctx,ox,oy, bndTransparent(bnd_theme.optionTheme.itemColor));
  791. }
  792. bndIconLabelValue(ctx,x+12,y,w-12,h,-1,
  793. bndTextColor(&bnd_theme.optionTheme, state), BND_LEFT,
  794. BND_LABEL_FONT_SIZE, label, NULL);
  795. }
  796. void bndChoiceButton(NVGcontext *ctx,
  797. float x, float y, float w, float h, int flags, BNDwidgetState state,
  798. int iconid, const char *label) {
  799. float cr[4];
  800. NVGcolor shade_top, shade_down;
  801. bndSelectCorners(cr, BND_OPTION_RADIUS, flags);
  802. bndBevelInset(ctx,x,y,w,h,cr[2],cr[3]);
  803. bndInnerColors(&shade_top, &shade_down, &bnd_theme.choiceTheme, state, 1);
  804. bndInnerBox(ctx,x,y,w,h,cr[0],cr[1],cr[2],cr[3], shade_top, shade_down);
  805. bndOutlineBox(ctx,x,y,w,h,cr[0],cr[1],cr[2],cr[3],
  806. bndTransparent(bnd_theme.choiceTheme.outlineColor));
  807. bndIconLabelValue(ctx,x,y,w,h,iconid,
  808. bndTextColor(&bnd_theme.choiceTheme, state), BND_LEFT,
  809. BND_LABEL_FONT_SIZE, label, NULL);
  810. bndUpDownArrow(ctx,x+w-10,y+10,5,
  811. bndTransparent(bnd_theme.choiceTheme.itemColor));
  812. }
  813. void bndNumberField(NVGcontext *ctx,
  814. float x, float y, float w, float h, int flags, BNDwidgetState state,
  815. const char *label, const char *value) {
  816. float cr[4];
  817. NVGcolor shade_top, shade_down;
  818. bndSelectCorners(cr, BND_NUMBER_RADIUS, flags);
  819. bndBevelInset(ctx,x,y,w,h,cr[2],cr[3]);
  820. bndInnerColors(&shade_top, &shade_down, &bnd_theme.numberFieldTheme, state, 0);
  821. bndInnerBox(ctx,x,y,w,h,cr[0],cr[1],cr[2],cr[3], shade_top, shade_down);
  822. bndOutlineBox(ctx,x,y,w,h,cr[0],cr[1],cr[2],cr[3],
  823. bndTransparent(bnd_theme.numberFieldTheme.outlineColor));
  824. bndIconLabelValue(ctx,x,y,w,h,-1,
  825. bndTextColor(&bnd_theme.numberFieldTheme, state), BND_CENTER,
  826. BND_LABEL_FONT_SIZE, label, value);
  827. bndArrow(ctx,x+8,y+10,-BND_NUMBER_ARROW_SIZE,
  828. bndTransparent(bnd_theme.numberFieldTheme.itemColor));
  829. bndArrow(ctx,x+w-8,y+10,BND_NUMBER_ARROW_SIZE,
  830. bndTransparent(bnd_theme.numberFieldTheme.itemColor));
  831. }
  832. void bndSlider(NVGcontext *ctx,
  833. float x, float y, float w, float h, int flags, BNDwidgetState state,
  834. float progress, const char *label, const char *value) {
  835. float cr[4];
  836. NVGcolor shade_top, shade_down;
  837. bndSelectCorners(cr, BND_NUMBER_RADIUS, flags);
  838. bndBevelInset(ctx,x,y,w,h,cr[2],cr[3]);
  839. bndInnerColors(&shade_top, &shade_down, &bnd_theme.sliderTheme, state, 0);
  840. bndInnerBox(ctx,x,y,w,h,cr[0],cr[1],cr[2],cr[3], shade_top, shade_down);
  841. if (state == BND_ACTIVE) {
  842. shade_top = bndOffsetColor(
  843. bnd_theme.sliderTheme.itemColor, bnd_theme.sliderTheme.shadeTop);
  844. shade_down = bndOffsetColor(
  845. bnd_theme.sliderTheme.itemColor, bnd_theme.sliderTheme.shadeDown);
  846. } else {
  847. shade_top = bndOffsetColor(
  848. bnd_theme.sliderTheme.itemColor, bnd_theme.sliderTheme.shadeDown);
  849. shade_down = bndOffsetColor(
  850. bnd_theme.sliderTheme.itemColor, bnd_theme.sliderTheme.shadeTop);
  851. }
  852. nvgScissor(ctx,x,y,8+(w-8)*bnd_clamp(progress,0,1),h);
  853. bndInnerBox(ctx,x,y,w,h,cr[0],cr[1],cr[2],cr[3], shade_top, shade_down);
  854. nvgResetScissor(ctx);
  855. bndOutlineBox(ctx,x,y,w,h,cr[0],cr[1],cr[2],cr[3],
  856. bndTransparent(bnd_theme.sliderTheme.outlineColor));
  857. bndIconLabelValue(ctx,x,y,w,h,-1,
  858. bndTextColor(&bnd_theme.sliderTheme, state), BND_CENTER,
  859. BND_LABEL_FONT_SIZE, label, value);
  860. }
  861. void bndScrollBar(NVGcontext *ctx,
  862. float x, float y, float w, float h, BNDwidgetState state,
  863. float offset, float size) {
  864. bndBevelInset(ctx,x,y,w,h,
  865. BND_SCROLLBAR_RADIUS, BND_SCROLLBAR_RADIUS);
  866. bndInnerBox(ctx,x,y,w,h,
  867. BND_SCROLLBAR_RADIUS,BND_SCROLLBAR_RADIUS,
  868. BND_SCROLLBAR_RADIUS,BND_SCROLLBAR_RADIUS,
  869. bndOffsetColor(
  870. bnd_theme.scrollBarTheme.innerColor, 3*bnd_theme.scrollBarTheme.shadeDown),
  871. bndOffsetColor(
  872. bnd_theme.scrollBarTheme.innerColor, 3*bnd_theme.scrollBarTheme.shadeTop));
  873. bndOutlineBox(ctx,x,y,w,h,
  874. BND_SCROLLBAR_RADIUS,BND_SCROLLBAR_RADIUS,
  875. BND_SCROLLBAR_RADIUS,BND_SCROLLBAR_RADIUS,
  876. bndTransparent(bnd_theme.scrollBarTheme.outlineColor));
  877. NVGcolor itemColor = bndOffsetColor(
  878. bnd_theme.scrollBarTheme.itemColor,
  879. (state == BND_ACTIVE)?BND_SCROLLBAR_ACTIVE_SHADE:0);
  880. bndScrollHandleRect(&x,&y,&w,&h,offset,size);
  881. bndInnerBox(ctx,x,y,w,h,
  882. BND_SCROLLBAR_RADIUS,BND_SCROLLBAR_RADIUS,
  883. BND_SCROLLBAR_RADIUS,BND_SCROLLBAR_RADIUS,
  884. bndOffsetColor(
  885. itemColor, 3*bnd_theme.scrollBarTheme.shadeTop),
  886. bndOffsetColor(
  887. itemColor, 3*bnd_theme.scrollBarTheme.shadeDown));
  888. bndOutlineBox(ctx,x,y,w,h,
  889. BND_SCROLLBAR_RADIUS,BND_SCROLLBAR_RADIUS,
  890. BND_SCROLLBAR_RADIUS,BND_SCROLLBAR_RADIUS,
  891. bndTransparent(bnd_theme.scrollBarTheme.outlineColor));
  892. }
  893. void bndMenuBackground(NVGcontext *ctx,
  894. float x, float y, float w, float h, int flags) {
  895. float cr[4];
  896. NVGcolor shade_top, shade_down;
  897. bndSelectCorners(cr, BND_MENU_RADIUS, flags);
  898. bndInnerColors(&shade_top, &shade_down, &bnd_theme.menuTheme,
  899. BND_DEFAULT, 0);
  900. bndInnerBox(ctx,x,y,w,h+1,cr[0],cr[1],cr[2],cr[3], shade_top, shade_down);
  901. bndOutlineBox(ctx,x,y,w,h+1,cr[0],cr[1],cr[2],cr[3],
  902. bndTransparent(bnd_theme.menuTheme.outlineColor));
  903. bndDropShadow(ctx,x,y,w,h,BND_MENU_RADIUS,
  904. BND_SHADOW_FEATHER,BND_SHADOW_ALPHA);
  905. }
  906. void bndTooltipBackground(NVGcontext *ctx, float x, float y, float w, float h) {
  907. NVGcolor shade_top, shade_down;
  908. bndInnerColors(&shade_top, &shade_down, &bnd_theme.tooltipTheme,
  909. BND_DEFAULT, 0);
  910. bndInnerBox(ctx,x,y,w,h+1,
  911. BND_MENU_RADIUS,BND_MENU_RADIUS,BND_MENU_RADIUS,BND_MENU_RADIUS,
  912. shade_top, shade_down);
  913. bndOutlineBox(ctx,x,y,w,h+1,
  914. BND_MENU_RADIUS,BND_MENU_RADIUS,BND_MENU_RADIUS,BND_MENU_RADIUS,
  915. bndTransparent(bnd_theme.tooltipTheme.outlineColor));
  916. bndDropShadow(ctx,x,y,w,h,BND_MENU_RADIUS,
  917. BND_SHADOW_FEATHER,BND_SHADOW_ALPHA);
  918. }
  919. void bndMenuLabel(NVGcontext *ctx,
  920. float x, float y, float w, float h, int iconid, const char *label) {
  921. bndIconLabelValue(ctx,x,y,w,h,iconid,
  922. bnd_theme.menuTheme.textColor, BND_LEFT,
  923. BND_LABEL_FONT_SIZE, label, NULL);
  924. }
  925. void bndMenuItem(NVGcontext *ctx,
  926. float x, float y, float w, float h, BNDwidgetState state,
  927. int iconid, const char *label) {
  928. if (state != BND_DEFAULT) {
  929. bndInnerBox(ctx,x,y,w,h,0,0,0,0,
  930. bndOffsetColor(bnd_theme.menuItemTheme.innerSelectedColor,
  931. bnd_theme.menuItemTheme.shadeTop),
  932. bndOffsetColor(bnd_theme.menuItemTheme.innerSelectedColor,
  933. bnd_theme.menuItemTheme.shadeDown));
  934. state = BND_ACTIVE;
  935. }
  936. bndIconLabelValue(ctx,x,y,w,h,iconid,
  937. bndTextColor(&bnd_theme.menuItemTheme, state), BND_LEFT,
  938. BND_LABEL_FONT_SIZE, label, NULL);
  939. }
  940. void bndNodePort(NVGcontext *ctx, float x, float y, BNDwidgetState state,
  941. NVGcolor color) {
  942. nvgBeginPath(ctx);
  943. nvgCircle(ctx, x, y, BND_NODE_PORT_RADIUS);
  944. nvgStrokeColor(ctx,bnd_theme.nodeTheme.wiresColor);
  945. nvgStrokeWidth(ctx,1.0f);
  946. nvgStroke(ctx);
  947. nvgFillColor(ctx,(state != BND_DEFAULT)?
  948. bndOffsetColor(color, BND_HOVER_SHADE):color);
  949. nvgFill(ctx);
  950. }
  951. void bndNodeWire(NVGcontext *ctx, float x0, float y0, float x1, float y1,
  952. BNDwidgetState state0, BNDwidgetState state1) {
  953. float delta = fabsf(x1 - x0)*(float)bnd_theme.nodeTheme.noodleCurving/10.0f;
  954. nvgBeginPath(ctx);
  955. nvgMoveTo(ctx, x0, y0);
  956. nvgBezierTo(ctx,
  957. x0 + delta, y0,
  958. x1 - delta, y1,
  959. x1, y1);
  960. nvgStrokeColor(ctx, bnd_theme.nodeTheme.wiresColor);
  961. nvgStrokeWidth(ctx, BND_NODE_WIRE_OUTLINE_WIDTH);
  962. nvgStroke(ctx);
  963. nvgStrokePaint(ctx, nvgLinearGradient(ctx,
  964. x0, y0, x1, y1,
  965. bndNodeWireColor(&bnd_theme.nodeTheme, state0),
  966. bndNodeWireColor(&bnd_theme.nodeTheme, state1)));
  967. nvgStrokeWidth(ctx,BND_NODE_WIRE_WIDTH);
  968. nvgStroke(ctx);
  969. }
  970. void bndNodeBackground(NVGcontext *ctx, float x, float y, float w, float h,
  971. BNDwidgetState state, int iconid, const char *label, NVGcolor titleColor) {
  972. bndInnerBox(ctx,x,y,w,BND_NODE_TITLE_HEIGHT+2,
  973. BND_NODE_RADIUS,BND_NODE_RADIUS,0,0,
  974. bndTransparent(bndOffsetColor(titleColor, BND_BEVEL_SHADE)),
  975. bndTransparent(titleColor));
  976. bndInnerBox(ctx,x,y+BND_NODE_TITLE_HEIGHT-1,w,h+2-BND_NODE_TITLE_HEIGHT,
  977. 0,0,BND_NODE_RADIUS,BND_NODE_RADIUS,
  978. bndTransparent(bnd_theme.nodeTheme.nodeBackdropColor),
  979. bndTransparent(bnd_theme.nodeTheme.nodeBackdropColor));
  980. bndNodeIconLabel(ctx,
  981. x+BND_NODE_ARROW_AREA_WIDTH,y,
  982. w-BND_NODE_ARROW_AREA_WIDTH-BND_NODE_MARGIN_SIDE,BND_NODE_TITLE_HEIGHT,
  983. iconid, bnd_theme.regularTheme.textColor,
  984. bndOffsetColor(titleColor, BND_BEVEL_SHADE*2),
  985. BND_LEFT, BND_LABEL_FONT_SIZE, label);
  986. NVGcolor arrowColor;
  987. NVGcolor borderColor;
  988. switch(state) {
  989. default:
  990. case BND_DEFAULT: {
  991. borderColor = nvgRGBf(0,0,0);
  992. arrowColor = bndOffsetColor(titleColor, -BND_BEVEL_SHADE);
  993. } break;
  994. case BND_HOVER: {
  995. borderColor = bnd_theme.nodeTheme.nodeSelectedColor;
  996. arrowColor = bnd_theme.nodeTheme.nodeSelectedColor;
  997. } break;
  998. case BND_ACTIVE: {
  999. borderColor = bnd_theme.nodeTheme.activeNodeColor;
  1000. arrowColor = bnd_theme.nodeTheme.nodeSelectedColor;
  1001. } break;
  1002. }
  1003. bndOutlineBox(ctx,x,y,w,h+1,
  1004. BND_NODE_RADIUS,BND_NODE_RADIUS,BND_NODE_RADIUS,BND_NODE_RADIUS,
  1005. bndTransparent(borderColor));
  1006. bndNodeArrowDown(ctx,
  1007. x + BND_NODE_MARGIN_SIDE, y + BND_NODE_TITLE_HEIGHT-4,
  1008. BND_NODE_ARROW_SIZE, arrowColor);
  1009. bndDropShadow(ctx,x,y,w,h,BND_NODE_RADIUS,
  1010. BND_SHADOW_FEATHER,BND_SHADOW_ALPHA);
  1011. }
  1012. ////////////////////////////////////////////////////////////////////////////////
  1013. float bndLabelWidth(NVGcontext *ctx, int iconid, const char *label) {
  1014. int w = BND_PAD_LEFT + BND_PAD_RIGHT;
  1015. if (iconid >= 0) {
  1016. w += BND_ICON_SHEET_RES;
  1017. }
  1018. if (label && (bnd_font >= 0)) {
  1019. nvgFontFaceId(ctx, bnd_font);
  1020. nvgFontSize(ctx, BND_LABEL_FONT_SIZE);
  1021. w += nvgTextBounds(ctx, 1, 1, label, NULL, NULL);
  1022. }
  1023. return w;
  1024. }
  1025. ////////////////////////////////////////////////////////////////////////////////
  1026. void bndRoundedBox(NVGcontext *ctx, float x, float y, float w, float h,
  1027. float cr0, float cr1, float cr2, float cr3) {
  1028. float d;
  1029. w = fmaxf(0, w);
  1030. h = fmaxf(0, h);
  1031. d = fminf(w, h);
  1032. nvgMoveTo(ctx, x,y+h*0.5f);
  1033. nvgArcTo(ctx, x,y, x+w,y, fminf(cr0, d/2));
  1034. nvgArcTo(ctx, x+w,y, x+w,y+h, fminf(cr1, d/2));
  1035. nvgArcTo(ctx, x+w,y+h, x,y+h, fminf(cr2, d/2));
  1036. nvgArcTo(ctx, x,y+h, x,y, fminf(cr3, d/2));
  1037. nvgClosePath(ctx);
  1038. }
  1039. NVGcolor bndTransparent(NVGcolor color) {
  1040. color.a *= BND_TRANSPARENT_ALPHA;
  1041. return color;
  1042. }
  1043. NVGcolor bndOffsetColor(NVGcolor color, int delta) {
  1044. float offset = (float)delta / 255.0f;
  1045. return delta?(
  1046. nvgRGBAf(
  1047. bnd_clamp(color.r+offset,0,1),
  1048. bnd_clamp(color.g+offset,0,1),
  1049. bnd_clamp(color.b+offset,0,1),
  1050. color.a)
  1051. ):color;
  1052. }
  1053. void bndBevel(NVGcontext *ctx, float x, float y, float w, float h) {
  1054. nvgStrokeWidth(ctx, 1);
  1055. x += 0.5f;
  1056. y += 0.5f;
  1057. w -= 1;
  1058. h -= 1;
  1059. nvgBeginPath(ctx);
  1060. nvgMoveTo(ctx, x, y+h);
  1061. nvgLineTo(ctx, x+w, y+h);
  1062. nvgLineTo(ctx, x+w, y);
  1063. nvgStrokeColor(ctx, bndTransparent(
  1064. bndOffsetColor(bnd_theme.backgroundColor, -BND_BEVEL_SHADE)));
  1065. nvgStroke(ctx);
  1066. nvgBeginPath(ctx);
  1067. nvgMoveTo(ctx, x, y+h);
  1068. nvgLineTo(ctx, x, y);
  1069. nvgLineTo(ctx, x+w, y);
  1070. nvgStrokeColor(ctx, bndTransparent(
  1071. bndOffsetColor(bnd_theme.backgroundColor, BND_BEVEL_SHADE)));
  1072. nvgStroke(ctx);
  1073. }
  1074. void bndBevelInset(NVGcontext *ctx, float x, float y, float w, float h,
  1075. float cr2, float cr3) {
  1076. float d;
  1077. y -= 0.5f;
  1078. d = fminf(w, h);
  1079. cr2 = fminf(cr2, d/2);
  1080. cr3 = fminf(cr3, d/2);
  1081. nvgBeginPath(ctx);
  1082. nvgMoveTo(ctx, x+w,y+h-cr2);
  1083. nvgArcTo(ctx, x+w,y+h, x,y+h, cr2);
  1084. nvgArcTo(ctx, x,y+h, x,y, cr3);
  1085. NVGcolor bevelColor = bndOffsetColor(bnd_theme.backgroundColor,
  1086. BND_INSET_BEVEL_SHADE);
  1087. nvgStrokeWidth(ctx, 1);
  1088. nvgStrokePaint(ctx,
  1089. nvgLinearGradient(ctx,
  1090. x,y+h-fmaxf(cr2,cr3)-1,
  1091. x,y+h-1,
  1092. nvgRGBAf(bevelColor.r, bevelColor.g, bevelColor.b, 0),
  1093. bevelColor));
  1094. nvgStroke(ctx);
  1095. }
  1096. void bndBackground(NVGcontext *ctx, float x, float y, float w, float h) {
  1097. nvgBeginPath(ctx);
  1098. nvgRect(ctx, x, y, w, h);
  1099. nvgFillColor(ctx, bnd_theme.backgroundColor);
  1100. nvgFill(ctx);
  1101. }
  1102. void bndIcon(NVGcontext *ctx, float x, float y, int iconid) {
  1103. int ix, iy, u, v;
  1104. if (bnd_icon_image < 0) return; // no icons loaded
  1105. ix = iconid & 0xff;
  1106. iy = (iconid>>8) & 0xff;
  1107. u = BND_ICON_SHEET_OFFSET_X + ix*BND_ICON_SHEET_GRID;
  1108. v = BND_ICON_SHEET_OFFSET_Y + iy*BND_ICON_SHEET_GRID;
  1109. nvgBeginPath(ctx);
  1110. nvgRect(ctx,x,y,BND_ICON_SHEET_RES,BND_ICON_SHEET_RES);
  1111. nvgFillPaint(ctx,
  1112. nvgImagePattern(ctx,x-u,y-v,
  1113. BND_ICON_SHEET_WIDTH,
  1114. BND_ICON_SHEET_HEIGHT,
  1115. 0,bnd_icon_image,0,1));
  1116. nvgFill(ctx);
  1117. }
  1118. void bndDropShadow(NVGcontext *ctx, float x, float y, float w, float h,
  1119. float r, float feather, float alpha) {
  1120. nvgBeginPath(ctx);
  1121. y += feather;
  1122. h -= feather;
  1123. nvgMoveTo(ctx, x-feather, y-feather);
  1124. nvgLineTo(ctx, x, y-feather);
  1125. nvgLineTo(ctx, x, y+h-feather);
  1126. nvgArcTo(ctx, x,y+h,x+r,y+h,r);
  1127. nvgArcTo(ctx, x+w,y+h,x+w,y+h-r,r);
  1128. nvgLineTo(ctx, x+w, y-feather);
  1129. nvgLineTo(ctx, x+w+feather, y-feather);
  1130. nvgLineTo(ctx, x+w+feather, y+h+feather);
  1131. nvgLineTo(ctx, x-feather, y+h+feather);
  1132. nvgClosePath(ctx);
  1133. nvgFillPaint(ctx, nvgBoxGradient(ctx,
  1134. x - feather*0.5f,y - feather*0.5f,
  1135. w + feather,h+feather,
  1136. r+feather*0.5f,
  1137. feather,
  1138. nvgRGBAf(0,0,0,alpha*alpha),
  1139. nvgRGBAf(0,0,0,0)));
  1140. nvgFill(ctx);
  1141. }
  1142. void bndInnerBox(NVGcontext *ctx, float x, float y, float w, float h,
  1143. float cr0, float cr1, float cr2, float cr3,
  1144. NVGcolor shade_top, NVGcolor shade_down) {
  1145. nvgBeginPath(ctx);
  1146. bndRoundedBox(ctx,x+1,y+1,w-2,h-3,
  1147. fmaxf(0,cr0-1),fmaxf(0,cr1-1),fmaxf(0,cr2-1),fmaxf(0,cr3-1));
  1148. nvgFillPaint(ctx,((h-2)>w)?
  1149. nvgLinearGradient(ctx,x,y,x+w,y,shade_top,shade_down):
  1150. nvgLinearGradient(ctx,x,y,x,y+h,shade_top,shade_down));
  1151. nvgFill(ctx);
  1152. }
  1153. void bndOutlineBox(NVGcontext *ctx, float x, float y, float w, float h,
  1154. float cr0, float cr1, float cr2, float cr3, NVGcolor color) {
  1155. nvgBeginPath(ctx);
  1156. bndRoundedBox(ctx,x+0.5f,y+0.5f,w-1,h-2,cr0,cr1,cr2,cr3);
  1157. nvgStrokeColor(ctx,color);
  1158. nvgStrokeWidth(ctx,1);
  1159. nvgStroke(ctx);
  1160. }
  1161. void bndSelectCorners(float *radiuses, float r, int flags) {
  1162. radiuses[0] = (flags & BND_CORNER_TOP_LEFT)?0:r;
  1163. radiuses[1] = (flags & BND_CORNER_TOP_RIGHT)?0:r;
  1164. radiuses[2] = (flags & BND_CORNER_DOWN_RIGHT)?0:r;
  1165. radiuses[3] = (flags & BND_CORNER_DOWN_LEFT)?0:r;
  1166. }
  1167. void bndInnerColors(
  1168. NVGcolor *shade_top, NVGcolor *shade_down,
  1169. const BNDwidgetTheme *theme, BNDwidgetState state, int flipActive) {
  1170. switch(state) {
  1171. default:
  1172. case BND_DEFAULT: {
  1173. *shade_top = bndOffsetColor(theme->innerColor, theme->shadeTop);
  1174. *shade_down = bndOffsetColor(theme->innerColor, theme->shadeDown);
  1175. } break;
  1176. case BND_HOVER: {
  1177. NVGcolor color = bndOffsetColor(theme->innerColor, BND_HOVER_SHADE);
  1178. *shade_top = bndOffsetColor(color, theme->shadeTop);
  1179. *shade_down = bndOffsetColor(color, theme->shadeDown);
  1180. } break;
  1181. case BND_ACTIVE: {
  1182. *shade_top = bndOffsetColor(theme->innerSelectedColor,
  1183. flipActive?theme->shadeDown:theme->shadeTop);
  1184. *shade_down = bndOffsetColor(theme->innerSelectedColor,
  1185. flipActive?theme->shadeTop:theme->shadeDown);
  1186. } break;
  1187. }
  1188. }
  1189. NVGcolor bndTextColor(const BNDwidgetTheme *theme, BNDwidgetState state) {
  1190. return (state == BND_ACTIVE)?theme->textSelectedColor:theme->textColor;
  1191. }
  1192. void bndIconLabelValue(NVGcontext *ctx, float x, float y, float w, float h,
  1193. int iconid, NVGcolor color, int align, float fontsize, const char *label,
  1194. const char *value) {
  1195. float pleft = BND_PAD_LEFT;
  1196. if (label) {
  1197. if (iconid >= 0) {
  1198. bndIcon(ctx,x+4,y+2,iconid);
  1199. pleft += BND_ICON_SHEET_RES;
  1200. }
  1201. if (bnd_font < 0) return;
  1202. nvgFontFaceId(ctx, bnd_font);
  1203. nvgFontSize(ctx, fontsize);
  1204. nvgBeginPath(ctx);
  1205. nvgFillColor(ctx, color);
  1206. if (value) {
  1207. float label_width = nvgTextBounds(ctx, 1, 1, label, NULL, NULL);
  1208. float sep_width = nvgTextBounds(ctx, 1, 1,
  1209. BND_LABEL_SEPARATOR, NULL, NULL);
  1210. nvgTextAlign(ctx, NVG_ALIGN_LEFT|NVG_ALIGN_BASELINE);
  1211. x += pleft;
  1212. if (align == BND_CENTER) {
  1213. float width = label_width + sep_width
  1214. + nvgTextBounds(ctx, 1, 1, value, NULL, NULL);
  1215. x += ((w-BND_PAD_RIGHT-pleft)-width)*0.5f;
  1216. }
  1217. y += h-BND_TEXT_PAD_DOWN;
  1218. nvgText(ctx, x, y, label, NULL);
  1219. x += label_width;
  1220. nvgText(ctx, x, y, BND_LABEL_SEPARATOR, NULL);
  1221. x += sep_width;
  1222. nvgText(ctx, x, y, value, NULL);
  1223. } else {
  1224. nvgTextAlign(ctx,
  1225. (align==BND_LEFT)?(NVG_ALIGN_LEFT|NVG_ALIGN_BASELINE):
  1226. (NVG_ALIGN_CENTER|NVG_ALIGN_BASELINE));
  1227. nvgTextBox(ctx,x+pleft,y+h-BND_TEXT_PAD_DOWN,
  1228. w-BND_PAD_RIGHT-pleft,label, NULL);
  1229. }
  1230. } else if (iconid >= 0) {
  1231. bndIcon(ctx,x+2,y+2,iconid);
  1232. }
  1233. }
  1234. void bndNodeIconLabel(NVGcontext *ctx, float x, float y, float w, float h,
  1235. int iconid, NVGcolor color, NVGcolor shadowColor,
  1236. int align, float fontsize, const char *label) {
  1237. float pleft = BND_PAD_LEFT;
  1238. if (label && (bnd_font >= 0)) {
  1239. nvgFontFaceId(ctx, bnd_font);
  1240. nvgFontSize(ctx, fontsize);
  1241. nvgBeginPath(ctx);
  1242. nvgTextAlign(ctx,
  1243. (align==BND_LEFT)?(NVG_ALIGN_LEFT|NVG_ALIGN_BASELINE):
  1244. (NVG_ALIGN_CENTER|NVG_ALIGN_BASELINE));
  1245. nvgFillColor(ctx, shadowColor);
  1246. nvgFontBlur(ctx, BND_NODE_TITLE_FEATHER);
  1247. nvgTextBox(ctx,x+pleft+1,y+h+3-BND_TEXT_PAD_DOWN,
  1248. w-BND_PAD_RIGHT-pleft,label, NULL);
  1249. nvgFillColor(ctx, color);
  1250. nvgFontBlur(ctx, 0);
  1251. nvgTextBox(ctx,x+pleft,y+h+2-BND_TEXT_PAD_DOWN,
  1252. w-BND_PAD_RIGHT-pleft,label, NULL);
  1253. }
  1254. if (iconid >= 0) {
  1255. bndIcon(ctx,x+w-BND_ICON_SHEET_RES,y+3,iconid);
  1256. }
  1257. }
  1258. void bndIconLabelCaret(NVGcontext *ctx, float x, float y, float w, float h,
  1259. int iconid, NVGcolor color, float fontsize, const char *label,
  1260. NVGcolor caretcolor, int cbegin, int cend) {
  1261. float bounds[4];
  1262. float pleft = BND_TEXT_RADIUS;
  1263. if (!label) return;
  1264. if (iconid >= 0) {
  1265. bndIcon(ctx,x+4,y+2,iconid);
  1266. pleft += BND_ICON_SHEET_RES;
  1267. }
  1268. if (bnd_font < 0) return;
  1269. x+=pleft;
  1270. y+=h-BND_TEXT_PAD_DOWN;
  1271. nvgFontFaceId(ctx, bnd_font);
  1272. nvgFontSize(ctx, fontsize);
  1273. nvgTextAlign(ctx, NVG_ALIGN_LEFT|NVG_ALIGN_BASELINE);
  1274. if (cend >= cbegin) {
  1275. float c0,c1;
  1276. const char *cb;const char *ce;
  1277. static NVGglyphPosition glyphs[BND_MAX_GLYPHS];
  1278. int nglyphs = nvgTextGlyphPositions(
  1279. ctx, x, y, label, label+cend+1, glyphs, BND_MAX_GLYPHS);
  1280. c0=glyphs[0].x;
  1281. c1=glyphs[nglyphs-1].x;
  1282. cb = label+cbegin; ce = label+cend;
  1283. // TODO: this is slow
  1284. for (int i=0; i < nglyphs; ++i) {
  1285. if (glyphs[i].str == cb)
  1286. c0 = glyphs[i].x;
  1287. if (glyphs[i].str == ce)
  1288. c1 = glyphs[i].x;
  1289. }
  1290. nvgTextBounds(ctx,x,y,label,NULL, bounds);
  1291. nvgBeginPath(ctx);
  1292. if (cbegin == cend) {
  1293. nvgFillColor(ctx, nvgRGBf(0.337,0.502,0.761));
  1294. nvgRect(ctx, c0-1, bounds[1], 2, bounds[3]-bounds[1]);
  1295. } else {
  1296. nvgFillColor(ctx, caretcolor);
  1297. nvgRect(ctx, c0-1, bounds[1], c1-c0+1, bounds[3]-bounds[1]);
  1298. }
  1299. nvgFill(ctx);
  1300. }
  1301. nvgBeginPath(ctx);
  1302. nvgFillColor(ctx, color);
  1303. nvgTextBox(ctx,x,y,w-BND_TEXT_RADIUS-pleft,label, NULL);
  1304. }
  1305. void bndCheck(NVGcontext *ctx, float ox, float oy, NVGcolor color) {
  1306. nvgBeginPath(ctx);
  1307. nvgStrokeWidth(ctx,2);
  1308. nvgStrokeColor(ctx,color);
  1309. nvgLineCap(ctx,NVG_BUTT);
  1310. nvgLineJoin(ctx,NVG_MITER);
  1311. nvgMoveTo(ctx,ox+4,oy+5);
  1312. nvgLineTo(ctx,ox+7,oy+8);
  1313. nvgLineTo(ctx,ox+14,oy+1);
  1314. nvgStroke(ctx);
  1315. }
  1316. void bndArrow(NVGcontext *ctx, float x, float y, float s, NVGcolor color) {
  1317. nvgBeginPath(ctx);
  1318. nvgMoveTo(ctx,x,y);
  1319. nvgLineTo(ctx,x-s,y+s);
  1320. nvgLineTo(ctx,x-s,y-s);
  1321. nvgClosePath(ctx);
  1322. nvgFillColor(ctx,color);
  1323. nvgFill(ctx);
  1324. }
  1325. void bndUpDownArrow(NVGcontext *ctx, float x, float y, float s, NVGcolor color) {
  1326. float w;
  1327. nvgBeginPath(ctx);
  1328. w = 1.1f*s;
  1329. nvgMoveTo(ctx,x,y-1);
  1330. nvgLineTo(ctx,x+0.5*w,y-s-1);
  1331. nvgLineTo(ctx,x+w,y-1);
  1332. nvgClosePath(ctx);
  1333. nvgMoveTo(ctx,x,y+1);
  1334. nvgLineTo(ctx,x+0.5*w,y+s+1);
  1335. nvgLineTo(ctx,x+w,y+1);
  1336. nvgClosePath(ctx);
  1337. nvgFillColor(ctx,color);
  1338. nvgFill(ctx);
  1339. }
  1340. void bndNodeArrowDown(NVGcontext *ctx, float x, float y, float s, NVGcolor color) {
  1341. float w;
  1342. nvgBeginPath(ctx);
  1343. w = 1.0f*s;
  1344. nvgMoveTo(ctx,x,y);
  1345. nvgLineTo(ctx,x+0.5*w,y-s);
  1346. nvgLineTo(ctx,x-0.5*w,y-s);
  1347. nvgClosePath(ctx);
  1348. nvgFillColor(ctx,color);
  1349. nvgFill(ctx);
  1350. }
  1351. void bndScrollHandleRect(float *x, float *y, float *w, float *h,
  1352. float offset, float size) {
  1353. size = bnd_clamp(size,0,1);
  1354. offset = bnd_clamp(offset,0,1);
  1355. if ((*h) > (*w)) {
  1356. float hs = fmaxf(size*(*h), (*w)+1);
  1357. *y = (*y) + ((*h)-hs)*offset;
  1358. *h = hs;
  1359. } else {
  1360. float ws = fmaxf(size*(*w), (*h)-1);
  1361. *x = (*x) + ((*w)-ws)*offset;
  1362. *w = ws;
  1363. }
  1364. }
  1365. NVGcolor bndNodeWireColor(const BNDnodeTheme *theme, BNDwidgetState state) {
  1366. switch(state) {
  1367. default:
  1368. case BND_DEFAULT: return nvgRGBf(0.5f,0.5f,0.5f);
  1369. case BND_HOVER: return theme->wireSelectColor;
  1370. case BND_ACTIVE: return theme->activeNodeColor;
  1371. }
  1372. }
  1373. ////////////////////////////////////////////////////////////////////////////////
  1374. #ifdef BND_INLINE
  1375. #undef BND_INLINE
  1376. #endif
  1377. #endif // BLENDISH_IMPLEMENTATION