DISTRHO Plugin Framework
 All Classes Functions Variables Modules Pages
ImageButton.hpp
1 /*
2  * DISTRHO Plugin Framework (DPF)
3  * Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com>
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any purpose with
6  * or without fee is hereby granted, provided that the above copyright notice and this
7  * permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
10  * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
11  * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
13  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #ifndef DGL_IMAGE_BUTTON_HPP_INCLUDED
18 #define DGL_IMAGE_BUTTON_HPP_INCLUDED
19 
20 #include "Image.hpp"
21 #include "Widget.hpp"
22 
23 START_NAMESPACE_DGL
24 
25 // -----------------------------------------------------------------------
26 
27 class ImageButton : public Widget
28 {
29 public:
30  class Callback
31  {
32  public:
33  virtual ~Callback() {}
34  virtual void imageButtonClicked(ImageButton* imageButton, int button) = 0;
35  };
36 
37  explicit ImageButton(Window& parent, const Image& image) noexcept;
38  explicit ImageButton(Window& parent, const Image& imageNormal, const Image& imageHover, const Image& imageDown) noexcept;
39  explicit ImageButton(Widget* widget, const Image& image) noexcept;
40  explicit ImageButton(Widget* widget, const Image& imageNormal, const Image& imageHover, const Image& imageDown) noexcept;
41  explicit ImageButton(const ImageButton& imageButton) noexcept;
42  ImageButton& operator=(const ImageButton& imageButton) noexcept;
43 
44  void setCallback(Callback* callback) noexcept;
45 
46 protected:
47  void onDisplay() override;
48  bool onMouse(const MouseEvent&) override;
49  bool onMotion(const MotionEvent&) override;
50 
51 private:
52  Image fImageNormal;
53  Image fImageHover;
54  Image fImageDown;
55  Image* fCurImage;
56  int fCurButton;
57 
58  Callback* fCallback;
59 
60  DISTRHO_LEAK_DETECTOR(ImageButton)
61 };
62 
63 // -----------------------------------------------------------------------
64 
65 END_NAMESPACE_DGL
66 
67 #endif // DGL_IMAGE_BUTTON_HPP_INCLUDED
Definition: Window.hpp:30
void onDisplay() override
Definition: ImageButton.hpp:27
bool onMouse(const MouseEvent &) override
Definition: Widget.hpp:128
Definition: Widget.hpp:51
Definition: Widget.hpp:110
Definition: Image.hpp:38
bool onMotion(const MotionEvent &) override
Definition: ImageButton.hpp:30