1 /// 2 module nanogui.common; 3 4 import gfm.math : vec2i, vec2f, vec3f, vec4f, vec4i; 5 public import arsd.nanovega : NVGContext, NVGColor; 6 public import arsd.nanovega; 7 8 alias Vector2i = vec2i; 9 alias Vector2f = vec2f; 10 alias Vector3f = vec3f; 11 alias Vector4i = vec4i; 12 alias Color = vec4f; 13 14 enum MouseButton : int 15 { 16 None = 0, 17 Left = 1, 18 Right = 2, 19 Middle = 4, 20 WheelUp = 8, 21 WheelDown = 16, 22 } 23 24 enum MouseAction : int 25 { 26 Press = 0, 27 Release = 1, 28 Motion = 2, 29 } 30 31 enum KeyAction : int 32 { 33 Press = 0, 34 Release = 1, 35 Repeat = 2, 36 } 37 38 enum KeyMod : int 39 { 40 Shift = 1, 41 Alt, 42 Ctrl, 43 } 44 45 enum Key : int 46 { 47 Left, 48 Right, 49 Up, 50 Down, 51 Home, 52 End, 53 Backspace, 54 Delete, 55 Enter, 56 Shift, 57 System, 58 A, 59 X, 60 C, 61 V, 62 } 63 64 /// Cursor shapes available to use in nanogui. Shape of actual cursor determined by Operating System. 65 enum Cursor { 66 Arrow = 0, /// The arrow cursor. 67 IBeam, /// The I-beam cursor. 68 Crosshair, /// The crosshair cursor. 69 Hand, /// The hand cursor. 70 HResize, /// The horizontal resize cursor. 71 VResize, /// The vertical resize cursor. 72 } 73 74 /// Sets current fill style to a solid color. 75 /// Group: render_styles 76 public void fillColor (NVGContext ctx, Color color) nothrow @trusted @nogc { 77 NVGColor clr = void; 78 clr.rgba = color[]; 79 clr.rgba[] /= 255f; 80 arsd.nanovega.fillColor(ctx, clr); 81 } 82 83 /** Creates and returns a box gradient. Box gradient is a feathered rounded rectangle, it is useful for rendering 84 * drop shadows or highlights for boxes. Parameters (x, y) define the top-left corner of the rectangle, 85 * (w, h) define the size of the rectangle, r defines the corner radius, and f feather. Feather defines how blurry 86 * the border of the rectangle is. Parameter icol specifies the inner color and ocol the outer color of the gradient. 87 * The gradient is transformed by the current transform when it is passed to [fillPaint] or [strokePaint]. 88 * 89 * Group: paints 90 */ 91 public NVGPaint boxGradient (NVGContext ctx, in float x, in float y, in float w, in float h, in float r, in float f, Color icol, Color ocol) nothrow @trusted @nogc 92 { 93 NVGColor clr1 = void, clr2 = void; 94 clr1.rgba = icol[]; 95 clr1.rgba[] /= 255f; 96 clr2.rgba = ocol[]; 97 clr2.rgba[] /= 255f; 98 return arsd.nanovega.boxGradient(ctx, x, y, w, h, r, f, clr1, clr2); 99 } 100 101 /** Creates and returns a linear gradient. Parameters `(sx, sy) (ex, ey)` specify the start and end coordinates 102 * of the linear gradient, icol specifies the start color and ocol the end color. 103 * The gradient is transformed by the current transform when it is passed to [fillPaint] or [strokePaint]. 104 * 105 * Group: paints 106 */ 107 public NVGPaint linearGradient (NVGContext ctx, in float sx, in float sy, in float ex, in float ey, Color icol, Color ocol) nothrow @trusted @nogc 108 { 109 NVGColor clr1 = void, clr2 = void; 110 clr1.rgba = icol[]; 111 clr1.rgba[] /= 255f; 112 clr2.rgba = ocol[]; 113 clr2.rgba[] /= 255f; 114 return arsd.nanovega.linearGradient(ctx, sx, sy, ex, ey, clr1, clr2); 115 } 116 117 /** Creates and returns a radial gradient. Parameters (cx, cy) specify the center, inr and outr specify 118 * the inner and outer radius of the gradient, icol specifies the start color and ocol the end color. 119 * The gradient is transformed by the current transform when it is passed to [fillPaint] or [strokePaint]. 120 * 121 * Group: paints 122 */ 123 public NVGPaint radialGradient (NVGContext ctx, in float cx, in float cy, in float inr, in float outr, Color icol, Color ocol) nothrow @trusted @nogc { 124 NVGColor clr1 = void, clr2 = void; 125 clr1.rgba = icol[]; 126 clr1.rgba[] /= 255f; 127 clr2.rgba = ocol[]; 128 clr2.rgba[] /= 255f; 129 return arsd.nanovega.radialGradient(ctx, cx, cy, inr, outr, clr1, clr2); 130 } 131 132 /// Sets current stroke style to a solid color. 133 /// Group: render_styles 134 public void strokeColor (NVGContext ctx, Color color) nothrow @trusted @nogc 135 { 136 NVGColor clr = void; 137 clr.rgba = color[]; 138 clr.rgba[] /= 255f; 139 arsd.nanovega.strokeColor(ctx, clr); 140 }