1 /*
2  *  This file is part of RawTherapee.
3  *
4  *  Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com>
5  *
6  *  RawTherapee 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, either version 3 of the License, or
9  *  (at your option) any later version.
10  *
11  *  RawTherapee is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with RawTherapee.  If not, see <https://www.gnu.org/licenses/>.
18  */
19 #pragma once
20 
21 #include <gtkmm.h>
22 #include "rtsurface.h"
23 class LWButton;
24 
25 class LWButtonListener
26 {
27 public:
28     virtual ~LWButtonListener() = default;
29     virtual void buttonPressed(LWButton* button, int actionCode, void* actionData)  = 0;
30     virtual void redrawNeeded(LWButton* button) = 0;
31 };
32 
33 class LWButton
34 {
35 
36 public:
37     enum Alignment {Left, Right, Top, Bottom, Center};
38     enum State { Normal, Over, Pressed_In, Pressed_Out};
39 
40 private:
41     int xpos, ypos, w, h;
42     Alignment halign, valign;
43     Cairo::RefPtr<RTSurface> icon;
44     double bgr, bgg, bgb;
45     double fgr, fgg, fgb;
46     State state;
47     LWButtonListener* listener;
48     int actionCode;
49     void* actionData;
50     Glib::ustring* toolTip;
51 
52 public:
53     LWButton (Cairo::RefPtr<RTSurface> i, int aCode, void* aData, Alignment ha = Left, Alignment va = Center, Glib::ustring* tooltip = nullptr);
54 
55     void    getSize             (int& minw, int& minh) const;
56     void    getAlignment        (Alignment& ha, Alignment& va) const;
57     void    setPosition         (int x, int y);
58     void    addPosition         (int x, int y);
59     void    getPosition         (int& x, int& y) const;
60     bool    inside              (int x, int y) const;
61     void    setIcon             (Cairo::RefPtr<RTSurface> i);
62     Cairo::RefPtr<RTSurface> getIcon () const;
63     void    setColors           (const Gdk::RGBA& bg, const Gdk::RGBA& fg);
64     void    setToolTip          (Glib::ustring* tooltip);
65 
66     bool    motionNotify        (int x, int y);
67     bool    pressNotify         (int x, int y);
68     bool    releaseNotify       (int x, int y);
69 
70     Glib::ustring getToolTip (int x, int y) const;
71 
setButtonListener(LWButtonListener * bl)72     void    setButtonListener   (LWButtonListener* bl)
73     {
74         listener = bl;
75     }
76 
77     void    redraw              (Cairo::RefPtr<Cairo::Context> context);
78 };
79