-
Notifications
You must be signed in to change notification settings - Fork 0
/
knotEditor.c
140 lines (102 loc) · 3.53 KB
/
knotEditor.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include "knotEditor.h"
#include "feel.h"
#include "palette.h"
#include "proton.h"
#include "renderer.h"
#include "curves.h"
#define EDITOR_WIDTH (WIN_WIDTH - 100)
#define EIDTOR_HEIGHT (WIN_HEIGHT / 2.f - 100)
static IntType
PickedKnot = INACTIVE;
int RealCmp(const void *R1, const void *R2);
void knotEditorUpdate(RealType Delta)
{
IntType i,
NumKnots = BSplineNumKnots(*PickedCurve);
PointStruct p;
AABB_SET(AABB_MENU_ITEM_0,
POINT(10, WIN_HEIGHT / 2.f + 10),
POINT(WIN_WIDTH - 10, WIN_HEIGHT - 10));
AABB_SET(AABB_MENU_ITEM_1,
POINT(50, WIN_HEIGHT / 2.f + 50),
POINT(WIN_WIDTH - 50, WIN_HEIGHT - 50));
if (Buttons[M1] && !LastButtons[M1] &&
TIMER(AABB_CLICK + AABB_MENU_ITEM_0) == INACTIVE)
TIMER_STOP(GS_KNOT_EDITOR);
if (PickedKnot == INACTIVE) {
for (i = 0; i < NumKnots; i++) {
if (TIMER(AABB_CLICK + AABB_MENU_TOTAL + i) != INACTIVE) {
PickedKnot = i;
break;
}
}
}
if (!Buttons[M1])
PickedKnot = INACTIVE;
ProtonPushTransform();
ProtonTranslate(AABB[AABB_MENU_ITEM_1][0]);
for (i = 0; i < NumKnots; i++) {
p = POINT(PickedCurve -> KnotVector[i] * EDITOR_WIDTH,
EIDTOR_HEIGHT / 2.f);
AABB_SET(AABB_MENU_TOTAL + i,
POINT(p.x - 10, p.y - 10),
POINT(p.x + 10, p.y + 10));
}
if (PickedKnot != INACTIVE) {
PickedCurve -> KnotVector[PickedKnot] = MAX(MIN(ProtonScreenToWorld(Mouse).x / EDITOR_WIDTH, 1.f), 0.f);
qsort(PickedCurve -> KnotVector, NumKnots, sizeof(PickedCurve -> KnotVector[0]), RealCmp);
PickedCurve -> NeedsRefresh = TRUE;
}
ProtonPopTransform();
}
void knotEditorDraw()
{
IntType i,
NumKnots = BSplineNumKnots(*PickedCurve);
RealType
t = ANIM_PARAM(TIMER(GS_KNOT_EDITOR), UI_FADE_TIME);
PointStruct p;
ColourStruct c;
t = BezierEval1D(t, EaseOut);
p = AABB[AABB_MENU_ITEM_0][1];
p.y = ANIM(t, AABB[AABB_MENU_ITEM_0][0].y, AABB[AABB_MENU_ITEM_0][1].y);
c = UI_BACKGROUND_COLOUR;
ProtonSetFG(c);
ProtonFillRect(AABB[AABB_MENU_ITEM_0][0], p);
c = UI_BORDER_COLOUR;
ProtonSetFG(c);
ProtonDrawRect(POINT_ADD(AABB[AABB_MENU_ITEM_0][0], POINT(10, 10)),
POINT_ADD(p, POINT(-10, -10)));
t = ANIM_PARAM(TIMER(GS_KNOT_EDITOR) - UI_FADE_TIME, UI_TEXT_FADE_TIME);
t = BezierEval1D(t, EaseOut);
c = UI_FG_COLOUR;
c.a = t * UI_FG_COLOUR.a;
ProtonSetFG(c);
ProtonFillRect(AABB[AABB_MENU_ITEM_1][0], AABB[AABB_MENU_ITEM_1][1]);
c = COLOUR_WHITE;
c.a = t * COLOUR_WHITE.a;
ProtonSetFG(c);
ProtonPushTransform();
ProtonTranslate(AABB[AABB_MENU_ITEM_1][0]);
ProtonDrawLine(POINT(0, EIDTOR_HEIGHT / 2.f),
POINT(EDITOR_WIDTH, EIDTOR_HEIGHT / 2.f));
for (i = 0; i <= 10; i++) {
ProtonDrawLine(POINT(EDITOR_WIDTH * (i / 10.f), EIDTOR_HEIGHT / 2.f + 10),
POINT(EDITOR_WIDTH * (i / 10.f), EIDTOR_HEIGHT / 2.f - 10));
}
c = KNOT_COLOUR;
c.a = t * KNOT_COLOUR.a;
ProtonSetFG(c);
for (i = 0; i < NumKnots; i++) {
ProtonFillCircle(POINT(PickedCurve -> KnotVector[i] * EDITOR_WIDTH,
EIDTOR_HEIGHT / 2.f), 10);
}
ProtonPopTransform();
}
int RealCmp(const void *R1, const void *R2)
{
RealType
Num1 = *(RealType*)R1,
Num2 = *(RealType*)R2;
return Num1 > Num2;
}