From d5ed45c25651f04dc3972047d279c8eeb4ca9e51 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Mon, 6 Jun 2016 21:37:26 +0200 Subject: New TexturedBox class. --- plugingui/Makefile.am.plugingui | 2 + plugingui/button.cc | 44 ++-------- plugingui/button.h | 12 ++- plugingui/checkbox.cc | 13 ++- plugingui/checkbox.h | 16 ++-- plugingui/image.h | 10 ++- plugingui/imagecache.h | 4 +- plugingui/knob.cc | 2 +- plugingui/knob.h | 4 +- plugingui/painter.cc | 7 +- plugingui/painter.h | 12 ++- plugingui/resource_data.cc | 89 +++++++++++++++++++ plugingui/resources/pushbutton.png | Bin 0 -> 1396 bytes plugingui/resources/pushbutton_b.png | Bin 205 -> 0 bytes plugingui/resources/pushbutton_bl.png | Bin 396 -> 0 bytes plugingui/resources/pushbutton_br.png | Bin 388 -> 0 bytes plugingui/resources/pushbutton_c.png | Bin 188 -> 0 bytes plugingui/resources/pushbutton_l.png | Bin 258 -> 0 bytes plugingui/resources/pushbutton_r.png | Bin 256 -> 0 bytes plugingui/resources/pushbutton_t.png | Bin 192 -> 0 bytes plugingui/resources/pushbutton_tl.png | Bin 307 -> 0 bytes plugingui/resources/pushbutton_tr.png | Bin 326 -> 0 bytes plugingui/resources/pushbuttondown_b.png | Bin 197 -> 0 bytes plugingui/resources/pushbuttondown_bl.png | Bin 340 -> 0 bytes plugingui/resources/pushbuttondown_br.png | Bin 338 -> 0 bytes plugingui/resources/pushbuttondown_c.png | Bin 188 -> 0 bytes plugingui/resources/pushbuttondown_l.png | Bin 237 -> 0 bytes plugingui/resources/pushbuttondown_r.png | Bin 234 -> 0 bytes plugingui/resources/pushbuttondown_t.png | Bin 190 -> 0 bytes plugingui/resources/pushbuttondown_tl.png | Bin 312 -> 0 bytes plugingui/resources/pushbuttondown_tr.png | Bin 336 -> 0 bytes plugingui/texturedbox.cc | 136 ++++++++++++++++++++++++++++++ plugingui/texturedbox.h | 118 ++++++++++++++++++++++++++ plugingui/widget.cc | 10 ++- plugingui/widget.h | 3 + plugingui/window.cc | 5 ++ plugingui/window.h | 5 ++ 37 files changed, 417 insertions(+), 75 deletions(-) create mode 100644 plugingui/resources/pushbutton.png delete mode 100644 plugingui/resources/pushbutton_b.png delete mode 100644 plugingui/resources/pushbutton_bl.png delete mode 100644 plugingui/resources/pushbutton_br.png delete mode 100644 plugingui/resources/pushbutton_c.png delete mode 100644 plugingui/resources/pushbutton_l.png delete mode 100644 plugingui/resources/pushbutton_r.png delete mode 100644 plugingui/resources/pushbutton_t.png delete mode 100644 plugingui/resources/pushbutton_tl.png delete mode 100644 plugingui/resources/pushbutton_tr.png delete mode 100644 plugingui/resources/pushbuttondown_b.png delete mode 100644 plugingui/resources/pushbuttondown_bl.png delete mode 100644 plugingui/resources/pushbuttondown_br.png delete mode 100644 plugingui/resources/pushbuttondown_c.png delete mode 100644 plugingui/resources/pushbuttondown_l.png delete mode 100644 plugingui/resources/pushbuttondown_r.png delete mode 100644 plugingui/resources/pushbuttondown_t.png delete mode 100644 plugingui/resources/pushbuttondown_tl.png delete mode 100644 plugingui/resources/pushbuttondown_tr.png create mode 100644 plugingui/texturedbox.cc create mode 100644 plugingui/texturedbox.h (limited to 'plugingui') diff --git a/plugingui/Makefile.am.plugingui b/plugingui/Makefile.am.plugingui index 4c8b5eb..1f921cf 100644 --- a/plugingui/Makefile.am.plugingui +++ b/plugingui/Makefile.am.plugingui @@ -19,6 +19,8 @@ PLUGIN_GUI_SOURCES = \ $(top_srcdir)/plugingui/slider.cc \ $(top_srcdir)/plugingui/scrollbar.cc \ $(top_srcdir)/plugingui/textedit.cc \ + $(top_srcdir)/plugingui/texture.cc \ + $(top_srcdir)/plugingui/texturedbox.cc \ $(top_srcdir)/plugingui/layout.cc \ $(top_srcdir)/plugingui/listbox.cc \ $(top_srcdir)/plugingui/listboxthin.cc \ diff --git a/plugingui/button.cc b/plugingui/button.cc index b4e3fee..5270658 100644 --- a/plugingui/button.cc +++ b/plugingui/button.cc @@ -38,47 +38,10 @@ Button::Button(Widget *parent) , draw_state(up) , button_state(up) { - box_up.topLeft = new Image(":pushbutton_tl.png"); - box_up.top = new Image(":pushbutton_t.png"); - box_up.topRight = new Image(":pushbutton_tr.png"); - box_up.left = new Image(":pushbutton_l.png"); - box_up.right = new Image(":pushbutton_r.png"); - box_up.bottomLeft = new Image(":pushbutton_bl.png"); - box_up.bottom = new Image(":pushbutton_b.png"); - box_up.bottomRight = new Image(":pushbutton_br.png"); - box_up.center = new Image(":pushbutton_c.png"); - - box_down.topLeft = new Image(":pushbuttondown_tl.png"); - box_down.top = new Image(":pushbuttondown_t.png"); - box_down.topRight = new Image(":pushbuttondown_tr.png"); - box_down.left = new Image(":pushbuttondown_l.png"); - box_down.right = new Image(":pushbuttondown_r.png"); - box_down.bottomLeft = new Image(":pushbuttondown_bl.png"); - box_down.bottom = new Image(":pushbuttondown_b.png"); - box_down.bottomRight = new Image(":pushbuttondown_br.png"); - box_down.center = new Image(":pushbuttondown_c.png"); } Button::~Button() { - delete(box_up.topLeft); - delete(box_up.top); - delete(box_up.topRight); - delete(box_up.left); - delete(box_up.right); - delete(box_up.bottomLeft); - delete(box_up.bottom); - delete(box_up.bottomRight); - delete(box_up.center); - delete(box_down.topLeft); - delete(box_down.top); - delete(box_down.topRight); - delete(box_down.left); - delete(box_down.right); - delete(box_down.bottomLeft); - delete(box_down.bottom); - delete(box_down.bottomRight); - delete(box_down.center); } void Button::buttonEvent(ButtonEvent* buttonEvent) @@ -122,10 +85,13 @@ void Button::repaintEvent(RepaintEvent* repaintEvent) switch(draw_state) { case up: - p.drawBox(padLeft, padTop, box_up, w - padLeft, h - padTop); + box_up.setSize(w - padLeft, h - padTop); + p.drawImage(padLeft, padTop, box_up); + break; case down: - p.drawBox(padLeft, padTop, box_down, w - padLeft, h - padTop); + box_down.setSize(w - padLeft, h - padTop); + p.drawImage(padLeft, padTop, box_down); break; } diff --git a/plugingui/button.h b/plugingui/button.h index 1bfeb2d..f409a55 100644 --- a/plugingui/button.h +++ b/plugingui/button.h @@ -33,6 +33,7 @@ #include "widget.h" #include "painter.h" #include "font.h" +#include "texturedbox.h" namespace GUI { @@ -61,8 +62,15 @@ protected: private: bool in_button{false}; - Painter::Box box_up; - Painter::Box box_down; + TexturedBox box_up{getImageCache(), ":pushbutton.png", + 0, 0, // atlas offset (x, y) + 11, 1, 11, // dx1, dx2, dx3 + 10, 72, 12}; // dy1, dy2, dy3 + + TexturedBox box_down{getImageCache(), ":pushbutton.png", + 23, 0, // atlas offset (x, y) + 11, 1, 11, // dx1, dx2, dx3 + 10, 72, 12}; // dy1, dy2, dy3 typedef enum { up, diff --git a/plugingui/checkbox.cc b/plugingui/checkbox.cc index 6419fc3..a218d44 100644 --- a/plugingui/checkbox.cc +++ b/plugingui/checkbox.cc @@ -28,17 +28,14 @@ #include "painter.h" -#include - -namespace GUI { +namespace GUI +{ CheckBox::CheckBox(Widget* parent) : Widget(parent) - , bg_on(":switch_back_on.png") - , bg_off(":switch_back_off.png") - , knob(":switch_front.png") - , state(false) - , middle(false) + , bg_on(getImageCache(), ":switch_back_on.png") + , bg_off(getImageCache(), ":switch_back_off.png") + , knob(getImageCache(), ":switch_front.png") { } diff --git a/plugingui/checkbox.h b/plugingui/checkbox.h index 5c658a5..f26c8d6 100644 --- a/plugingui/checkbox.h +++ b/plugingui/checkbox.h @@ -29,7 +29,7 @@ #include #include "widget.h" -#include "image.h" +#include "texture.h" namespace GUI { @@ -59,14 +59,14 @@ protected: private: void internalSetChecked(bool checked); - Image bg_on; - Image bg_off; - Image knob; + Texture bg_on; + Texture bg_off; + Texture knob; - bool state; - bool middle; - bool buttonDown = false; - bool inCheckbox = false; + bool state{false}; + bool middle{false}; + bool buttonDown{false}; + bool inCheckbox{false}; std::string _text; }; diff --git a/plugingui/image.h b/plugingui/image.h index 4f591aa..ae0e051 100644 --- a/plugingui/image.h +++ b/plugingui/image.h @@ -29,25 +29,27 @@ #include #include +#include "drawable.h" #include "colour.h" #include "resource.h" namespace GUI { class Image + : public Drawable { public: Image(const char* data, size_t size); Image(const std::string& filename); Image(Image&& other); - ~Image(); + virtual ~Image(); Image& operator=(Image&& other); - size_t width() const; - size_t height() const; + size_t width() const override; + size_t height() const override; - const Colour& getPixel(size_t x, size_t y) const; + const Colour& getPixel(size_t x, size_t y) const override; private: void setError(); diff --git a/plugingui/imagecache.h b/plugingui/imagecache.h index 9ca28fb..d31a844 100644 --- a/plugingui/imagecache.h +++ b/plugingui/imagecache.h @@ -41,14 +41,14 @@ class ScopedImageBorrower public: ScopedImageBorrower(ImageCache& imageCache, const std::string& filename); ScopedImageBorrower(ScopedImageBorrower&& other); - ~ScopedImageBorrower(); + virtual ~ScopedImageBorrower(); ScopedImageBorrower& operator=(ScopedImageBorrower&& other); Image& operator*(); Image& operator()(); -private: +protected: ImageCache& imageCache; std::string filename; Image& image; diff --git a/plugingui/knob.cc b/plugingui/knob.cc index 845d95a..27d4083 100644 --- a/plugingui/knob.cc +++ b/plugingui/knob.cc @@ -41,7 +41,7 @@ namespace GUI { Knob::Knob(Widget *parent) : Widget(parent) - , img_knob(":knob.png") + , img_knob(getImageCache(), ":knob.png") { state = up; diff --git a/plugingui/knob.h b/plugingui/knob.h index d144184..220ee80 100644 --- a/plugingui/knob.h +++ b/plugingui/knob.h @@ -29,7 +29,7 @@ #include #include "widget.h" -#include "image.h" +#include "texture.h" #include "font.h" namespace GUI { @@ -72,7 +72,7 @@ private: float maximum; float minimum; - Image img_knob; + Texture img_knob; int mouse_offset_x; Font font; diff --git a/plugingui/painter.cc b/plugingui/painter.cc index 71e4b33..7d55294 100644 --- a/plugingui/painter.cc +++ b/plugingui/painter.cc @@ -30,7 +30,8 @@ #include -namespace GUI { +namespace GUI +{ Painter::Painter(Widget& widget) : widget(widget) @@ -345,7 +346,7 @@ void Painter::drawFilledCircle(int cx, int cy, int radius) } } -void Painter::drawImage(int x0, int y0, const Image& image) +void Painter::drawImage(int x0, int y0, const Drawable& image) { size_t fw = image.width(); size_t fh = image.height(); @@ -371,7 +372,7 @@ void Painter::drawImage(int x0, int y0, const Image& image) } } -void Painter::drawImageStretched(int x0, int y0, const Image& image, +void Painter::drawImageStretched(int x0, int y0, const Drawable& image, int width, int height) { if((width < 1) || (height < 1)) diff --git a/plugingui/painter.h b/plugingui/painter.h index 42426bc..233d157 100644 --- a/plugingui/painter.h +++ b/plugingui/painter.h @@ -32,11 +32,15 @@ #include "colour.h" #include "pixelbuffer.h" #include "font.h" +#include "drawable.h" +#include "texture.h" #include "image.h" -namespace GUI { +namespace GUI +{ -class Painter { +class Painter +{ public: Painter(Widget& widget); ~Painter(); @@ -53,8 +57,8 @@ public: void drawPoint(int x, int y); void drawCircle(int x, int y, double r); void drawFilledCircle(int x, int y, int r); - void drawImage(int x, int y, const Image& image); - void drawImageStretched(int x, int y, const Image& image, + void drawImage(int x, int y, const Drawable& image); + void drawImageStretched(int x, int y, const Drawable& image, int width, int height); typedef struct { diff --git a/plugingui/resource_data.cc b/plugingui/resource_data.cc index ce29fd8..1d1136e 100644 --- a/plugingui/resource_data.cc +++ b/plugingui/resource_data.cc @@ -2371,6 +2371,95 @@ const rc_data_t rc_data[] = "\357\135\130\153\111\51\171\132\153\40\354\275\377\271\367\202" "\37\224\360\23\34\221\167\121\131\0\0\0\0\111\105\116" "\104\256\102\140\202" }, + { ":pushbutton.png", 1396, + "\211\120\116\107\15\12\32\12\0\0\0\15\111\110\104\122" + "\0\0\0\56\0\0\0\136\10\6\0\0\0\134\233\46" + "\366\0\0\0\6\142\113\107\104\0\377\0\377\0\377\240" + "\275\247\223\0\0\0\11\160\110\131\163\0\0\15\327\0" + "\0\15\327\1\102\50\233\170\0\0\0\7\164\111\115\105" + "\7\340\6\6\23\25\16\276\326\315\144\0\0\0\35\151" + "\124\130\164\103\157\155\155\145\156\164\0\0\0\0\0\103" + "\162\145\141\164\145\144\40\167\151\164\150\40\107\111\115\120" + "\144\56\145\7\0\0\4\330\111\104\101\124\170\332\355\234" + "\317\117\33\107\24\307\277\343\131\23\147\41\256\114\161\53" + "\127\252\24\131\124\101\112\11\27\324\106\110\110\275\244\352" + "\325\160\344\17\40\22\247\36\375\107\104\125\17\105\342\340" + "\43\267\300\301\271\124\364\200\42\44\52\71\71\100\150\25" + "\254\106\361\301\50\166\153\130\67\301\306\330\336\335\351\201" + "\267\311\260\306\306\77\110\252\252\157\244\47\377\332\371\316" + "\167\337\174\346\331\227\147\201\177\147\10\12\150\217\372\120" + "\332\243\152\47\320\315\42\355\206\352\303\160\0\200\101\41" + "\351\265\360\151\272\0\34\0\66\205\333\355\132\242\126\253" + "\335\255\327\353\17\33\215\306\101\243\321\120\27\304\101\275" + "\136\177\130\253\325\356\366\220\200\40\200\160\42\221\270\225" + "\311\144\36\344\363\371\347\107\107\107\312\37\371\174\376\171" + "\46\223\171\220\110\44\156\1\10\323\74\321\51\233\2\200" + "\260\54\153\111\112\371\203\343\70\122\51\5\245\132\157\126" + "\10\1\41\4\244\224\216\343\70\337\217\216\216\376\324\141" + "\153\5\145\170\144\145\145\345\333\271\271\271\125\41\204\274" + "\354\116\225\122\316\372\372\372\302\342\342\342\6\200\12\145" + "\137\371\215\13\0\142\167\167\367\116\54\26\173\332\215\260" + "\276\100\241\120\230\236\232\232\172\326\306\274\4\60\74\73" + "\73\73\276\266\266\226\351\125\173\176\176\376\253\255\255\255" + "\27\0\252\204\20\2\276\303\142\230\246\271\244\224\222\275" + "\200\253\224\222\246\151\56\121\126\305\5\11\61\0\214\44" + "\223\311\373\275\230\246\235\225\311\144\362\76\200\21\115\377" + "\234\161\3\100\110\112\371\15\231\351\72\0\200\346\205\164" + "\161\237\166\70\36\217\337\353\105\327\213\170\74\176\217\130" + "\177\253\255\147\310\0\140\32\206\61\356\31\357\145\320\74" + "\223\70\164\56\100\345\172\44\22\271\331\253\56\0\104\42" + "\221\233\0\256\223\16\74\343\136\346\207\0\334\20\102\240" + "\37\161\41\4\0\334\0\160\12\240\251\231\367\112\140\260" + "\37\135\155\4\365\322\351\75\221\144\174\70\30\14\366\247" + "\172\66\157\230\164\144\233\372\75\310\70\127\357\15\75\43" + "\0\102\3\146\45\244\145\246\145\123\6\324\76\127\272\15" + "\355\115\171\105\333\51\333\175\41\15\250\335\222\176\275\34" + "\312\1\365\344\5\345\360\275\14\303\377\5\164\5\333\51" + "\72\324\373\367\142\374\312\305\331\170\7\306\377\163\203\121" + "\141\124\30\25\106\205\121\141\343\314\70\243\302\250\60\52" + "\154\234\31\147\124\30\25\106\205\121\141\124\330\70\63\316" + "\214\63\52\214\12\33\147\306\231\161\106\205\121\141\124\30" + "\25\106\205\31\147\306\31\25\106\205\121\141\306\231\161\106" + "\205\121\141\124\30\25\106\205\215\63\343\214\312\377\24\25" + "\333\266\41\145\357\75\36\216\343\164\221\360\201\62\256\72" + "\146\334\262\254\242\353\272\75\365\242\271\256\13\313\262\212" + "\227\54\352\132\226\165\320\117\257\233\145\131\7\360\65\243" + "\266\30\317\345\162\331\146\263\331\223\160\263\331\104\56\227" + "\313\166\62\15\240\231\315\146\237\364\143\74\233\315\76\301" + "\131\33\332\133\363\1\337\2\52\235\116\77\56\227\313\312" + "\165\335\256\366\317\165\135\224\313\145\225\116\247\37\243\175" + "\43\252\3\240\226\112\245\36\51\245\334\36\17\264\233\112" + "\245\36\1\250\101\153\376\363\172\206\15\234\165\357\205\213" + "\305\142\120\112\31\212\104\42\161\51\245\10\4\2\10\4" + "\132\317\260\155\333\250\126\253\50\24\12\152\143\143\343\227" + "\315\315\315\137\1\224\0\374\15\340\204\62\344\15\1\100" + "\126\52\25\303\262\254\362\364\364\364\327\350\242\311\111\51" + "\345\56\57\57\377\270\263\263\223\1\360\12\132\43\252\327" + "\155\165\15\100\4\300\347\0\276\0\20\237\230\230\270\63" + "\63\63\63\35\215\106\307\114\323\64\375\242\47\47\47\47" + "\245\122\351\160\173\173\373\351\376\376\376\63\0\57\1\374" + "\1\40\17\240\114\346\365\4\15\3\210\1\30\37\33\33" + "\273\275\260\260\360\335\344\344\344\227\321\150\64\352\327\56" + "\225\112\245\275\275\275\337\126\127\127\177\76\74\74\374\35" + "\300\13\0\5\277\161\257\45\62\14\340\63\0\161\212\30" + "\200\217\360\256\133\120\340\254\11\357\224\160\160\0\64\0" + "\274\46\321\227\24\257\0\274\241\353\364\214\33\70\353\202" + "\375\204\326\371\224\326\14\341\174\253\232\103\163\337\0\370" + "\223\364\376\202\257\147\331\360\231\250\122\266\216\150\27\100" + "\10\351\35\203\65\357\260\321\163\213\256\57\323\374\6\132" + "\33\121\25\55\132\241\317\52\164\263\272\266\320\17\62\151" + "\37\123\324\164\323\172\35\167\151\301\143\62\21\242\367\117" + "\51\113\103\164\255\111\10\330\164\175\205\214\27\151\336\61" + "\275\357\266\251\56\66\335\134\235\316\102\337\175\371\206\126" + "\11\154\62\145\151\246\137\23\233\327\150\221\60\155\241\103" + "\213\353\73\144\151\67\245\72\224\106\107\313\52\320\347\77" + "\41\30\276\154\234\352\345\213\114\171\315\245\222\16\160\231" + "\76\157\322\365\125\312\174\225\136\167\62\216\313\14\165\73" + "\132\372\362\361\356\357\25\206\50\364\346\322\217\51\273\112" + "\63\337\240\260\65\323\352\103\376\126\361\26\263\65\276\116" + "\65\6\275\70\322\314\271\32\217\352\103\231\6\200\177\0" + "\340\140\375\366\365\353\25\220\0\0\0\0\111\105\116\104" + "\256\102\140\202" }, { ":pushbutton_b.png", 205, "\211\120\116\107\15\12\32\12\0\0\0\15\111\110\104\122" "\0\0\0\1\0\0\0\14\10\6\0\0\0\243\213\327" diff --git a/plugingui/resources/pushbutton.png b/plugingui/resources/pushbutton.png new file mode 100644 index 0000000..4145e9a Binary files /dev/null and b/plugingui/resources/pushbutton.png differ diff --git a/plugingui/resources/pushbutton_b.png b/plugingui/resources/pushbutton_b.png deleted file mode 100644 index 9767ce9..0000000 Binary files a/plugingui/resources/pushbutton_b.png and /dev/null differ diff --git a/plugingui/resources/pushbutton_bl.png b/plugingui/resources/pushbutton_bl.png deleted file mode 100644 index 8fa6f81..0000000 Binary files a/plugingui/resources/pushbutton_bl.png and /dev/null differ diff --git a/plugingui/resources/pushbutton_br.png b/plugingui/resources/pushbutton_br.png deleted file mode 100644 index 8fcb9f7..0000000 Binary files a/plugingui/resources/pushbutton_br.png and /dev/null differ diff --git a/plugingui/resources/pushbutton_c.png b/plugingui/resources/pushbutton_c.png deleted file mode 100644 index bff0c40..0000000 Binary files a/plugingui/resources/pushbutton_c.png and /dev/null differ diff --git a/plugingui/resources/pushbutton_l.png b/plugingui/resources/pushbutton_l.png deleted file mode 100644 index 52adfe0..0000000 Binary files a/plugingui/resources/pushbutton_l.png and /dev/null differ diff --git a/plugingui/resources/pushbutton_r.png b/plugingui/resources/pushbutton_r.png deleted file mode 100644 index 74af818..0000000 Binary files a/plugingui/resources/pushbutton_r.png and /dev/null differ diff --git a/plugingui/resources/pushbutton_t.png b/plugingui/resources/pushbutton_t.png deleted file mode 100644 index add473f..0000000 Binary files a/plugingui/resources/pushbutton_t.png and /dev/null differ diff --git a/plugingui/resources/pushbutton_tl.png b/plugingui/resources/pushbutton_tl.png deleted file mode 100644 index 2b49cd1..0000000 Binary files a/plugingui/resources/pushbutton_tl.png and /dev/null differ diff --git a/plugingui/resources/pushbutton_tr.png b/plugingui/resources/pushbutton_tr.png deleted file mode 100644 index 8f5a293..0000000 Binary files a/plugingui/resources/pushbutton_tr.png and /dev/null differ diff --git a/plugingui/resources/pushbuttondown_b.png b/plugingui/resources/pushbuttondown_b.png deleted file mode 100644 index ed17c18..0000000 Binary files a/plugingui/resources/pushbuttondown_b.png and /dev/null differ diff --git a/plugingui/resources/pushbuttondown_bl.png b/plugingui/resources/pushbuttondown_bl.png deleted file mode 100644 index 820253b..0000000 Binary files a/plugingui/resources/pushbuttondown_bl.png and /dev/null differ diff --git a/plugingui/resources/pushbuttondown_br.png b/plugingui/resources/pushbuttondown_br.png deleted file mode 100644 index 7c1b1e1..0000000 Binary files a/plugingui/resources/pushbuttondown_br.png and /dev/null differ diff --git a/plugingui/resources/pushbuttondown_c.png b/plugingui/resources/pushbuttondown_c.png deleted file mode 100644 index d5a8d80..0000000 Binary files a/plugingui/resources/pushbuttondown_c.png and /dev/null differ diff --git a/plugingui/resources/pushbuttondown_l.png b/plugingui/resources/pushbuttondown_l.png deleted file mode 100644 index 5f65187..0000000 Binary files a/plugingui/resources/pushbuttondown_l.png and /dev/null differ diff --git a/plugingui/resources/pushbuttondown_r.png b/plugingui/resources/pushbuttondown_r.png deleted file mode 100644 index a3013f7..0000000 Binary files a/plugingui/resources/pushbuttondown_r.png and /dev/null differ diff --git a/plugingui/resources/pushbuttondown_t.png b/plugingui/resources/pushbuttondown_t.png deleted file mode 100644 index dd02350..0000000 Binary files a/plugingui/resources/pushbuttondown_t.png and /dev/null differ diff --git a/plugingui/resources/pushbuttondown_tl.png b/plugingui/resources/pushbuttondown_tl.png deleted file mode 100644 index 662275d..0000000 Binary files a/plugingui/resources/pushbuttondown_tl.png and /dev/null differ diff --git a/plugingui/resources/pushbuttondown_tr.png b/plugingui/resources/pushbuttondown_tr.png deleted file mode 100644 index 114aff1..0000000 Binary files a/plugingui/resources/pushbuttondown_tr.png and /dev/null differ diff --git a/plugingui/texturedbox.cc b/plugingui/texturedbox.cc new file mode 100644 index 0000000..02f695c --- /dev/null +++ b/plugingui/texturedbox.cc @@ -0,0 +1,136 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * texturedbox.cc + * + * Sun Jun 5 12:22:15 CEST 2016 + * Copyright 2016 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of DrumGizmo. + * + * DrumGizmo is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DrumGizmo 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with DrumGizmo; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "texturedbox.h" + +#include + +namespace GUI +{ + +TexturedBox::TexturedBox(ImageCache& image_cache, const std::string& filename, + std::size_t x0, std::size_t y0, + std::size_t dx1, std::size_t dx2, std::size_t dx3, + std::size_t dy1, std::size_t dy2, std::size_t dy3) + : seg_a(image_cache, filename, x0 , y0 , dx1, dy1) + , seg_b(image_cache, filename, x0 + dx1 , y0 , dx2, dy1) + , seg_c(image_cache, filename, x0 + dx1 + dx2, y0 , dx3, dy1) + , seg_d(image_cache, filename, x0 , y0 + dy1 , dx1, dy2) + , seg_e(image_cache, filename, x0 + dx1 , y0 + dy1 , dx2, dy2) + , seg_f(image_cache, filename, x0 + dx1 + dx2, y0 + dy1 , dx3, dy2) + , seg_g(image_cache, filename, x0 , y0 + dy1 + dy2, dx1, dy3) + , seg_h(image_cache, filename, x0 + dx1 , y0 + dy1 + dy2, dx2, dy3) + , seg_i(image_cache, filename, x0 + dx1 + dx2, y0 + dy1 + dy2, dx3, dy3) + , _x(x0) + , _y(y0) + , dx1(dx1) + , dx2(dx2) + , dx3(dx3) + , dy1(dy1) + , dy2(dy2) + , dy3(dy3) +{ +} + +std::size_t TexturedBox::width() const +{ + return _width; +} + +std::size_t TexturedBox::height() const +{ + return _height; +} + +void TexturedBox::setSize(std::size_t width, std::size_t height) +{ + _width = width; + _height = height; +} + +const Colour& TexturedBox::getPixel(std::size_t x, std::size_t y) const +{ + assert(x < _width); + assert(y < _height); + + if(y < dy1) // row 1 + { + if(x < dx1) // col 1 + { + return seg_a.getPixel(x, y); + } + else if(x < (_width - dx3)) // col 2 + { + float scale = (float)(x - dx1) / (float)(_width - dx1 - dx3); + assert(seg_b.width() == dx2); + return seg_b.getPixel(scale * dx2, y); + } + else // col 3 + { + return seg_c.getPixel(x - (_width - dx3), y); + } + } + else if(y < (_height - dy3)) // row 2 + { + if(x < dx1) // col 1 + { + // TODO: Apply vertical scale + float scale = (float)(y - dy1) / (float)(_height - dy1 - dy3); + return seg_d.getPixel(x, scale * dy2); + } + else if(x < (_width - dx3)) // col 2 + { + float scale_x = (float)(x - dx1) / (float)(_width - dx1 - dx3); + float scale_y = (float)(y - dy1) / (float)(_height - dy1 - dy3); + return seg_e.getPixel(scale_x * dx2, scale_y * dy2); + } + else // col 3 + { + float scale = (float)(y - dy1) / (float)(_height - dy1 - dy3); + return seg_f.getPixel(x - (_width - dx3), scale * dy2); + } + } + else // row 3 + { + if(x < dx1) // col 1 + { + return seg_g.getPixel(x, y - (_height - dy3)); + } + else if(x < (_width - dx3)) // col 2 + { + float scale = (float)(x - dx1) / (float)(_width - dx1 - dx3); + return seg_h.getPixel(scale * dx2, y - (_height - dy3)); + } + else // col 3 + { + return seg_i.getPixel(x - (_width - dx3), y - (_height - dy3)); + } + } + + return outOfRange; +} + +} // GUI:: diff --git a/plugingui/texturedbox.h b/plugingui/texturedbox.h new file mode 100644 index 0000000..51aead5 --- /dev/null +++ b/plugingui/texturedbox.h @@ -0,0 +1,118 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * texturedbox.h + * + * Sun Jun 5 12:22:14 CEST 2016 + * Copyright 2016 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of DrumGizmo. + * + * DrumGizmo is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DrumGizmo 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with DrumGizmo; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#pragma once + +#include "drawable.h" +#include "imagecache.h" +#include "texture.h" + +namespace GUI +{ + +class TexturedBox + : public Drawable +{ +public: + //! Draw a box from 9 image segments nested inside the same image. + //! An image says more than a thousand words: + //! .----------------------------------------. + //! | (x0, y0) | + //! | \ dx1 dx2 dx3 | + //! | .-----+-----------+-----. \ | + //! | dy1 | A | <--B--> | C | | | + //! | +-----+-----------+-----+ | | + //! | | /|\ | /|\ | /|\ | | h | + //! | | | | | | | | | e | + //! | dy2 | D | <--E--> | F | > i | + //! | | | | | | | | | g | + //! | | \|/ | \|/ | \|/ | | h | + //! | +-----+-----------+-----+ | t | + //! | dy3 | G | <--H--> | I | | | + //! | `-----+-----------+-----` / | + //! | | + //! | \___________ ___________/ | + //! | V | + //! | width | + //! `----------------------------------------` + //! + //! \param image_cache A reference to the image cache object. + //! \param filename The filename of the texture image to use. + //! \param (x0, y0) is coordinate of the upper left corner of the A segment. + //! \param (width, height) is the total rendered size of the Box. + //! \param dx1 is the width of the A, C and F segments. + //! \param dx2 is the width of the B, E and H segments. + //! \param dx3 is the width of the C, F and I segments. + //! \param dy1 is the height of the A, B and C segments. + //! \param dy2 is the height of the D, E and F segments. + //! \param dy3 is the height of the G, G and I segments. + //! + //! Segments A, C, G and I are drawn with no stretch. + //! Segments B and H are stretched horizontally to fill the + //! gaps between A, C and G, I so that resulting width is 'width' + //! Segments D and F are stretched vertically to fill the + //! gaps between A, G and C, I so that resulting height is 'height' + //! Segment E will be stretched both horizontally and vertically + //! to fill the inner space between B, H and D, F. + TexturedBox(ImageCache& image_cache, const std::string& filename, + std::size_t x0, std::size_t y0, + std::size_t dx1, std::size_t dx2, std::size_t dx3, + std::size_t dy1, std::size_t dy2, std::size_t dy3); + + // From Drawable: + std::size_t width() const override; + std::size_t height() const override; + + void setSize(std::size_t width, std::size_t height); + + const Colour& getPixel(std::size_t x, std::size_t y) const override; + +private: + Texture seg_a; + Texture seg_b; + Texture seg_c; + Texture seg_d; + Texture seg_e; + Texture seg_f; + Texture seg_g; + Texture seg_h; + Texture seg_i; + + std::size_t _x; + std::size_t _y; + std::size_t _width{100}; + std::size_t _height{100}; + std::size_t dx1; + std::size_t dx2; + std::size_t dx3; + std::size_t dy1; + std::size_t dy2; + std::size_t dy3; + + Colour outOfRange{0.0f, 0.0f, 0.0f, 0.0f}; +}; + +} // GUI:: diff --git a/plugingui/widget.cc b/plugingui/widget.cc index 9bac566..5cd013d 100644 --- a/plugingui/widget.cc +++ b/plugingui/widget.cc @@ -26,11 +26,11 @@ */ #include "widget.h" +#include + #include "painter.h" #include "window.h" -#include - namespace GUI { Widget::Widget(Widget* parent) @@ -155,6 +155,12 @@ size_t Widget::windowY() return window_y; } +ImageCache& Widget::getImageCache() +{ + assert(parent); + return parent->getImageCache(); +} + Widget* Widget::find(int x, int y) { for(auto i = children.rbegin(); i != children.rend(); ++i) diff --git a/plugingui/widget.h b/plugingui/widget.h index 02b8c07..bbe85d0 100644 --- a/plugingui/widget.h +++ b/plugingui/widget.h @@ -35,6 +35,7 @@ namespace GUI { +class ImageCache; class Window; class Widget : public Listener, public LayoutItem { @@ -71,6 +72,8 @@ public: virtual void mouseLeaveEvent() {} virtual void mouseEnterEvent() {} + virtual ImageCache& getImageCache(); + Widget* find(int x, int y); virtual Window* window(); diff --git a/plugingui/window.cc b/plugingui/window.cc index 8d56926..7449607 100644 --- a/plugingui/window.cc +++ b/plugingui/window.cc @@ -127,6 +127,11 @@ Window* Window::window() return this; } +ImageCache& Window::getImageCache() +{ + return image_cache; +} + EventHandler* Window::eventHandler() { return eventhandler; diff --git a/plugingui/window.h b/plugingui/window.h index 0c93658..9eb9d6d 100644 --- a/plugingui/window.h +++ b/plugingui/window.h @@ -32,6 +32,7 @@ #include "nativewindow.h" #include "image.h" #include "eventhandler.h" +#include "imagecache.h" namespace GUI { @@ -52,6 +53,8 @@ public: void hide() override; Window* window() override; + ImageCache& getImageCache() override; + EventHandler* eventHandler(); Widget* keyboardFocus(); @@ -91,6 +94,8 @@ protected: EventHandler* eventhandler{nullptr}; size_t maxRefcount{0}; + + ImageCache image_cache; }; } // GUI:: -- cgit v1.2.3