File: button.cc

package info (click to toggle)
ebumeter 0.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 916 kB
  • sloc: cpp: 2,310; makefile: 45
file content (130 lines) | stat: -rw-r--r-- 2,557 bytes parent folder | download
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
// ----------------------------------------------------------------------------
//
//  Copyright (C) 2010-2023 Fons Adriaensen <fons@linuxaudio.org>
//    
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------


#include "button.h"


int PushButton::_keymod = 0;
int PushButton::_button = 0;


PushButton::PushButton (X_window     *parent,
                        X_callback   *cbobj,
			int           cbind,
                        XImage       *image,
		        int  xp,
                        int  yp,
			int  xs,
			int  ys) :
    X_window (parent, xp, yp, xs, ys, 0),
    _cbobj (cbobj),
    _cbind (cbind),
    _image (image),
    _state (0),
    _xs (xs),
    _ys (ys)
{
    x_add_events (ExposureMask | ButtonPressMask | ButtonReleaseMask);
} 


PushButton::~PushButton (void)
{
}


void PushButton::init (X_display *disp)
{
}


void PushButton::fini (void)
{
}


void PushButton::handle_event (XEvent *E)
{
    switch (E->type)
    {
    case Expose:
	render ();
	break;  
 
    case ButtonPress:
	bpress ((XButtonEvent *) E);
	break;  

    case ButtonRelease:
	brelse ((XButtonEvent *) E);
	break;

    default: 
	fprintf (stderr, "PushButton: event %d\n", E->type );
    }
}


void PushButton::bpress (XButtonEvent *E)
{
    int r = 0;

    if (E->button < 4)
    {
        _keymod = E->state;
        _button = E->button;
        r = handle_press ();
    }
    render ();
    if (r) callback (r);
}


void PushButton::brelse (XButtonEvent *E)
{
    int r = 0;

    if (E->button < 4)
    {
        _keymod = E->state;
        _button = E->button;
        r = handle_relse ();
    }
    render ();
    if (r) callback (r);
}


void PushButton::set_state (int s)
{
    if (_state != s)
    {
        _state = s;	
        render ();
    }
}


void PushButton::render (void)
{
    XPutImage (dpy (), win (), dgc (), _image, 0, _state * _ys, 0, 0, _xs, _ys);
}