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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
|
/* (C) Guenter Geiger <geiger@epy.co.at> */
#include <ggee.h>
#include <m_pd.h>
#include "g_canvas.h"
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
/* ------------------------ ticker ----------------------------- */
#define DEFAULTSIZE 15
#define DEFAULTCOLOR "black"
static t_class *ticker_class;
typedef struct _ticker
{
t_object x_obj;
t_glist * x_glist;
int x_width;
int x_height;
t_float x_on;
} t_ticker;
/* widget helper functions */
static void draw_inlets(t_ticker *x, t_glist *glist, int firsttime, int nin, int nout)
{
int n = nin;
int nplus, i;
nplus = (n == 1 ? 1 : n-1);
for (i = 0; i < n; i++)
{
int onset = x->x_obj.te_xpix + (x->x_width - IOWIDTH) * i / nplus;
if (firsttime)
sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xo%d\n",
glist_getcanvas(glist),
onset, x->x_obj.te_ypix + x->x_height - 1,
onset + IOWIDTH, x->x_obj.te_ypix + x->x_height,
x, i);
else
sys_vgui(".x%x.c coords %xo%d %d %d %d %d\n",
glist_getcanvas(glist), x, i,
onset, x->x_obj.te_ypix + x->x_height - 1,
onset + IOWIDTH, x->x_obj.te_ypix + x->x_height);
}
n = nout;
nplus = (n == 1 ? 1 : n-1);
for (i = 0; i < n; i++)
{
int onset = x->x_obj.te_xpix + (x->x_width - IOWIDTH) * i / nplus;
if (firsttime)
sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xi%d\n",
glist_getcanvas(glist),
onset, x->x_obj.te_ypix,
onset + IOWIDTH, x->x_obj.te_ypix + 1,
x, i);
else
sys_vgui(".x%x.c coords %xi%d %d %d %d %d\n",
glist_getcanvas(glist), x, i,
onset, x->x_obj.te_ypix,
onset + IOWIDTH, x->x_obj.te_ypix + 1);
}
}
void ticker_draw(t_ticker *x,t_glist *glist)
{
if (x->x_on) {
sys_vgui(".x%x.c create line \
%d %d %d %d -tags %xB\n",glist_getcanvas(glist),
x->x_obj.te_xpix+1,x->x_obj.te_ypix+1,
x->x_obj.te_xpix + x->x_width -1,
x->x_obj.te_ypix + x->x_height -1,x);
sys_vgui(".x%x.c create line \
%d %d %d %d -tags %xC\n",glist_getcanvas(glist),
x->x_obj.te_xpix+1,x->x_obj.te_ypix + x->x_height -1,
x->x_obj.te_xpix + x->x_width -1,x->x_obj.te_ypix+1,
x);
}
else {
sys_vgui(".x%x.c delete %xB\n",
glist_getcanvas(glist), x);
sys_vgui(".x%x.c delete %xC\n",
glist_getcanvas(glist), x);
}
}
void ticker_update(t_ticker *x,t_glist *glist)
{
if (glist_isvisible(glist)) {
if (x->x_on) {
sys_vgui(".x%x.c coords %xB \
%d %d %d %d\n",glist_getcanvas(glist),
x,x->x_obj.te_xpix+1,x->x_obj.te_ypix+1,
x->x_obj.te_xpix + x->x_width -1,
x->x_obj.te_ypix + x->x_height -1);
sys_vgui(".x%x.c coords %xC \
%d %d %d %d\n",glist_getcanvas(glist),
x,x->x_obj.te_xpix+1,x->x_obj.te_ypix + x->x_height -1,
x->x_obj.te_xpix + x->x_width -1,x->x_obj.te_ypix+1);
}
}
}
void ticker_drawme(t_ticker *x, t_glist *glist, int firsttime)
{
if (firsttime) {
sys_vgui(".x%x.c create rectangle \
%d %d %d %d -tags %xS "BACKGROUND"\n",
glist_getcanvas(glist),
x->x_obj.te_xpix, x->x_obj.te_ypix,
x->x_obj.te_xpix + x->x_width, x->x_obj.te_ypix + x->x_height,
x);
ticker_draw(x,glist);
}
else {
sys_vgui(".x%x.c coords %xS \
%d %d %d %d\n",
glist_getcanvas(glist), x,
x->x_obj.te_xpix, x->x_obj.te_ypix,
x->x_obj.te_xpix + x->x_width, x->x_obj.te_ypix + x->x_height);
ticker_update(x,glist);
}
draw_inlets(x, glist, firsttime, 1,1);
}
void ticker_erase(t_ticker* x,t_glist* glist)
{
int n;
sys_vgui(".x%x.c delete %xS\n",
glist_getcanvas(glist), x);
sys_vgui(".x%x.c delete %xP\n",
glist_getcanvas(glist), x);
n = 1;
sys_vgui(".x%x.c delete %xB\n",
glist_getcanvas(glist), x);
sys_vgui(".x%x.c delete %xC\n",
glist_getcanvas(glist), x);
while (n--) {
sys_vgui(".x%x.c delete %xi%d\n",glist_getcanvas(glist),x,n);
sys_vgui(".x%x.c delete %xo%d\n",glist_getcanvas(glist),x,n);
}
}
/* ------------------------ ticker widgetbehaviour----------------------------- */
static void ticker_getrect(t_gobj *z, t_glist *owner,
int *xp1, int *yp1, int *xp2, int *yp2)
{
int width, height;
t_ticker* s = (t_ticker*)z;
width = s->x_width;
height = s->x_height;
*xp1 = s->x_obj.te_xpix;
*yp1 = s->x_obj.te_ypix;
*xp2 = s->x_obj.te_xpix + width;
*yp2 = s->x_obj.te_ypix + height;
}
static void ticker_displace(t_gobj *z, t_glist *glist,
int dx, int dy)
{
t_ticker *x = (t_ticker *)z;
x->x_obj.te_xpix += dx;
x->x_obj.te_ypix += dy;
ticker_drawme(x, glist, 0);
canvas_fixlinesfor(glist_getcanvas(glist),(t_text*) x);
}
static void ticker_select(t_gobj *z, t_glist *glist, int state)
{
t_ticker *x = (t_ticker *)z;
sys_vgui(".x%x.c itemconfigure %xS -fill %s\n", glist,
x, (state? "blue" : BACKGROUNDCOLOR));
}
static void ticker_activate(t_gobj *z, t_glist *glist, int state)
{
/* t_text *x = (t_text *)z;
t_rtext *y = glist_findrtext(glist, x);
if (z->g_pd != gatom_class) rtext_activate(y, state);*/
}
static void ticker_delete(t_gobj *z, t_glist *glist)
{
t_text *x = (t_text *)z;
canvas_deletelinesfor(glist_getcanvas(glist), x);
}
static void ticker_vis(t_gobj *z, t_glist *glist, int vis)
{
t_ticker* s = (t_ticker*)z;
if (vis)
ticker_drawme(s, glist, 1);
else
ticker_erase(s,glist);
}
/* can we use the normal text save function ?? */
static void ticker_save(t_gobj *z, t_binbuf *b)
{
t_ticker *x = (t_ticker *)z;
binbuf_addv(b, "ssiisii", gensym("#X"),gensym("obj"),
(t_int)x->x_obj.te_xpix, (t_int)x->x_obj.te_ypix,
gensym("ticker"),x->x_width,x->x_height);
binbuf_addv(b, ";");
}
static void ticker_click(t_ticker *x,
t_floatarg xpos, t_floatarg ypos, t_floatarg shift, t_floatarg ctrl,
t_floatarg alt)
{
x->x_on = x->x_on == 0.0 ? 1.0:0.0;
ticker_draw(x,x->x_glist);
outlet_float(x->x_obj.ob_outlet,x->x_on);
}
#if (PD_VERSION_MINOR > 31)
static int ticker_newclick(t_gobj *z, struct _glist *glist,
int xpix, int ypix, int shift, int alt, int dbl, int doit)
{
if (doit)
ticker_click((t_ticker *)z, (t_floatarg)xpix, (t_floatarg)ypix,
(t_floatarg)shift, 0, (t_floatarg)alt);
return (1);
}
#endif
t_widgetbehavior ticker_widgetbehavior;
void ticker_size(t_ticker* x,t_floatarg w,t_floatarg h) {
x->x_width = w;
x->x_height = h;
ticker_drawme(x, x->x_glist, 0);
}
static void ticker_bang(t_ticker* x)
{
x->x_on = x->x_on == 0.0 ? 1.0:0.0;
if (glist_isvisible(x->x_glist))
ticker_draw(x,x->x_glist);
outlet_float(x->x_obj.ob_outlet,x->x_on);
}
static void ticker_float(t_ticker* x,t_floatarg f)
{
x->x_on = f;
if (glist_isvisible(x->x_glist))
ticker_draw(x,x->x_glist);
outlet_float(x->x_obj.ob_outlet,x->x_on);
}
static void ticker_set(t_ticker* x,t_floatarg f)
{
x->x_on = f;
}
static void *ticker_new(t_floatarg h,t_floatarg o)
{
t_ticker *x = (t_ticker *)pd_new(ticker_class);
x->x_glist = (t_glist*) canvas_getcurrent();
if (h) x->x_width = h;
else
x->x_width = DEFAULTSIZE;
if (o) x->x_height = o;
else
x->x_height = DEFAULTSIZE;
x->x_on = 0;
outlet_new(&x->x_obj, &s_float);
return (x);
}
void ticker_setup(void)
{
ticker_class = class_new(gensym("ticker"), (t_newmethod)ticker_new, 0,
sizeof(t_ticker),0, A_DEFFLOAT,A_DEFFLOAT,0);
class_addmethod(ticker_class, (t_method)ticker_click, gensym("click"),
A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
class_addmethod(ticker_class, (t_method)ticker_size, gensym("size"),
A_FLOAT, A_FLOAT, 0);
class_addfloat(ticker_class, ticker_float);
class_addbang(ticker_class,ticker_bang);
class_addmethod(ticker_class,(t_method) ticker_set,gensym("set"),A_FLOAT,0);
class_setwidget(ticker_class,&ticker_widgetbehavior);
ticker_widgetbehavior.w_getrectfn = ticker_getrect;
ticker_widgetbehavior.w_displacefn = ticker_displace;
ticker_widgetbehavior.w_selectfn = ticker_select;
ticker_widgetbehavior.w_activatefn = ticker_activate;
ticker_widgetbehavior.w_deletefn = ticker_delete;
ticker_widgetbehavior.w_visfn = ticker_vis;
#if (PD_VERSION_MINOR > 31)
ticker_widgetbehavior.w_clickfn = ticker_newclick;
ticker_widgetbehavior.w_propertiesfn = NULL;
#endif
ticker_widgetbehavior.w_savefn = ticker_save;
}
|