1 /*
2  * Audacious - a cross-platform multimedia player
3  * Copyright (c) 2007 Tomasz Moń
4  * Copyright (c) 2011 John Lindgren
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; under version 3 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses>.
17  *
18  * The Audacious team does not consider modular code linking to
19  * Audacious or using our public API to be a derived work.
20  */
21 
22 #ifndef SKINS_UI_SKINNED_BUTTON_H
23 #define SKINS_UI_SKINNED_BUTTON_H
24 
25 #include "widget.h"
26 #include "skin.h"
27 
28 class Button;
29 
30 typedef void (* ButtonCB) (Button * button, QMouseEvent * event);
31 
32 class Button : public Widget
33 {
34 public:
35     // transparent button
Button(int w,int h)36     Button (int w, int h) :
37         Button (Small, w, h, 0, 0, 0, 0, 0, 0, 0, 0, SKIN_MAIN, SKIN_MAIN) {}
38 
39     // basic skinned button
Button(int w,int h,int nx,int ny,int px,int py,SkinPixmapId si1,SkinPixmapId si2)40     Button (int w, int h, int nx, int ny, int px, int py, SkinPixmapId si1, SkinPixmapId si2) :
41         Button (Normal, w, h, nx, ny, px, py, 0, 0, 0, 0, si1, si2) {}
42 
43     // skinned toggle button
Button(int w,int h,int nx,int ny,int px,int py,int pnx,int pny,int ppx,int ppy,SkinPixmapId si1,SkinPixmapId si2)44     Button (int w, int h, int nx, int ny, int px, int py, int pnx, int pny,
45      int ppx, int ppy, SkinPixmapId si1, SkinPixmapId si2) :
46         Button (Toggle, w, h, nx, ny, px, py, pnx, pny, ppx, ppy, si1, si2) {}
47 
on_press(ButtonCB callback)48     void on_press (ButtonCB callback) { press = callback; }
on_release(ButtonCB callback)49     void on_release (ButtonCB callback) { release = callback; }
on_rpress(ButtonCB callback)50     void on_rpress (ButtonCB callback) { rpress = callback; }
on_rrelease(ButtonCB callback)51     void on_rrelease (ButtonCB callback) { rrelease = callback; }
52 
get_active()53     bool get_active () { return m_active; }
54     void set_active (bool active);
55 
56 private:
57     enum Type {Normal, Toggle, Small};
58 
59     Button (Type type, int w, int h, int nx, int ny, int px, int py, int pnx,
60      int pny, int ppx, int ppy, SkinPixmapId si1, SkinPixmapId si2);
61 
62     void draw (QPainter & cr);
63     bool button_press (QMouseEvent * event);
64     bool button_release (QMouseEvent * event);
65 
66     Type m_type;
67     int m_w, m_h;
68     int m_nx, m_ny, m_px, m_py;
69     int m_pnx, m_pny, m_ppx, m_ppy;
70     SkinPixmapId m_si1, m_si2;
71 
72     bool m_pressed = false, m_rpressed = false, m_active = false;
73 
74     ButtonCB press = nullptr, release = nullptr;
75     ButtonCB rpress = nullptr, rrelease = nullptr;
76 };
77 
78 #endif
79