aboutsummaryrefslogtreecommitdiff
path: root/cyclone/hammer/mousefilter.c
blob: e2e3cc559eceb366992bdcd1f477b244748b7432 (plain)
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
/* Copyright (c) 2002-2003 krzYszcz and others.
 * For information on usage and redistribution, and for a DISCLAIMER OF ALL
 * WARRANTIES, see the file, "LICENSE.txt," in this distribution.  */

#include "m_pd.h"
#include "hammer/gui.h"

typedef struct _mousefilter
{
    t_object   x_ob;
    int        x_isup;
    int        x_ispending;
    t_float    x_value;
} t_mousefilter;

static t_class *mousefilter_class;

static void mousefilter_float(t_mousefilter *x, t_float f)
{
    if (x->x_isup)
	outlet_float(((t_object *)x)->ob_outlet, f);
    else
    {
	x->x_ispending = 1;
	x->x_value = f;
    }
}

static void mousefilter_anything(t_mousefilter *x,
				 t_symbol *s, int ac, t_atom *av)
{
    /* dummy method, filtering out those messages from gui,
       which are not handled explicitly */
}

static void mousefilter_doup(t_mousefilter *x, t_floatarg f)
{
    if ((x->x_isup = (int)f) && x->x_ispending)
    {
	x->x_ispending = 0;
	outlet_float(((t_object *)x)->ob_outlet, x->x_value);
    }
}

static void mousefilter_free(t_mousefilter *x)
{
    hammergui_unbindmouse((t_pd *)x);
}

static void *mousefilter_new(void)
{
    t_mousefilter *x = (t_mousefilter *)pd_new(mousefilter_class);
    x->x_isup = 0;  /* LATER rethink */
    x->x_ispending = 0;
    outlet_new((t_object *)x, &s_float);
    hammergui_bindmouse((t_pd *)x);
    return (x);
}

void mousefilter_setup(void)
{
    mousefilter_class = class_new(gensym("mousefilter"),
				  (t_newmethod)mousefilter_new,
				  (t_method)mousefilter_free,
				  sizeof(t_mousefilter), 0, 0);
    class_addfloat(mousefilter_class, mousefilter_float);
    class_addanything(mousefilter_class, mousefilter_anything);
    class_addmethod(mousefilter_class, (t_method)mousefilter_doup,
		    gensym("_up"), A_FLOAT, 0);
}