VCV Rack API v2
Loading...
Searching...
No Matches
TransformWidget.hpp
Go to the documentation of this file.
1#pragma once
2#include <widget/Widget.hpp>
3
4
5namespace rack {
6namespace widget {
7
8
12 float transform[6];
13
15 identity();
16 }
17
18 void identity() {
19 nvgTransformIdentity(transform);
20 }
21
22 void translate(math::Vec delta) {
23 float t[6];
24 nvgTransformTranslate(t, VEC_ARGS(delta));
25 nvgTransformPremultiply(transform, t);
26 }
27
28 void rotate(float angle) {
29 float t[6];
30 nvgTransformRotate(t, angle);
31 nvgTransformPremultiply(transform, t);
32 }
33
34 void rotate(float angle, math::Vec origin) {
35 translate(origin);
36 rotate(angle);
37 translate(origin.neg());
38 }
39
40 void scale(math::Vec s) {
41 float t[6];
42 nvgTransformScale(t, s.x, s.y);
43 nvgTransformPremultiply(transform, t);
44 }
45
46 void draw(const DrawArgs& args) override {
47 // No need to save the state because that is done in the parent
48 nvgTransform(args.vg, transform[0], transform[1], transform[2], transform[3], transform[4], transform[5]);
49 Widget::draw(args);
50 }
51
52 void drawLayer(const DrawArgs& args, int layer) override {
53 // No need to save the state because that is done in the parent
54 nvgTransform(args.vg, transform[0], transform[1], transform[2], transform[3], transform[4], transform[5]);
55 Widget::drawLayer(args, layer);
56 }
57};
58
59
60} // namespace widget
61} // namespace rack
#define VEC_ARGS(v)
Expands a Vec and Rect into a comma-separated list.
Definition math.hpp:541
Root namespace for the Rack API.
Definition AudioDisplay.hpp:9
2-dimensional vector of floats, representing a point on the plane for graphics.
Definition math.hpp:189
float x
Definition math.hpp:190
float y
Definition math.hpp:191
Vec neg() const
Negates the vector.
Definition math.hpp:206
Transforms appearance only, not positions of events.
Definition TransformWidget.hpp:10
void drawLayer(const DrawArgs &args, int layer) override
Draw additional layers.
Definition TransformWidget.hpp:52
void identity()
Definition TransformWidget.hpp:18
void rotate(float angle)
Definition TransformWidget.hpp:28
float transform[6]
The transformation matrix.
Definition TransformWidget.hpp:12
void translate(math::Vec delta)
Definition TransformWidget.hpp:22
void scale(math::Vec s)
Definition TransformWidget.hpp:40
TransformWidget()
Definition TransformWidget.hpp:14
void draw(const DrawArgs &args) override
Draws the widget to the NanoVG context.
Definition TransformWidget.hpp:46
void rotate(float angle, math::Vec origin)
Definition TransformWidget.hpp:34
Definition Widget.hpp:141
NVGcontext * vg
Definition Widget.hpp:142
A node in the 2D scene graph.
Definition Widget.hpp:21
virtual void drawLayer(const DrawArgs &args, int layer)
Draw additional layers.
virtual void draw(const DrawArgs &args)
Draws the widget to the NanoVG context.