diff --git a/src/avtk/avtk_background.h b/src/avtk/avtk_background.h new file mode 100644 index 0000000..bc0593d --- /dev/null +++ b/src/avtk/avtk_background.h @@ -0,0 +1,167 @@ +/* + * Author: Harry van Haaren 2013 + * harryhaaren@gmail.com + * + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + */ + + +#ifndef AVTK_BACKGROUND_H +#define AVTK_BACKGROUND_H + + +#include +#include +#include + +namespace Avtk +{ + +class Background : public Fl_Widget +{ + public: + Background(int _x, int _y, int _w, int _h, const char *_label): + Fl_Widget(_x, _y, _w, _h, _label) + { + x = _x; + y = _y; + w = _w; + h = _h; + + label = _label; + + highlight = false; + } + bool highlight; + int x, y, w, h; + const char* label; + + void draw() + { + if (damage() & FL_DAMAGE_ALL) + { + cairo_t *cr = Fl::cairo_cc(); + + cairo_save( cr ); + + cairo_set_line_width(cr, 1.5); + + + // fill background + cairo_rectangle( cr, x, y, w, h); + cairo_set_source_rgba( cr, 66 / 255.f, 66 / 255.f , 66 / 255.f , 1 ); + cairo_fill( cr ); + + + // set up dashed lines, 1 px off, 1 px on + double dashes[1]; + dashes[0] = 2.0; + + cairo_set_dash ( cr, dashes, 1, 0.0); + cairo_set_line_width( cr, 1.0); + + // loop over each 2nd line, drawing dots + for ( int i = x; i < x + w; i += 4 ) + { + cairo_move_to( cr, i, y ); + cairo_line_to( cr, i, y + h ); + } + + cairo_set_source_rgba( cr, 28 / 255.f, 28 / 255.f , 28 / 255.f , 0.5 ); + cairo_stroke(cr); + cairo_set_dash ( cr, dashes, 0, 0.0); + + + // draw header + // backing + cairo_rectangle(cr, x, y, w, 20); + cairo_set_source_rgb( cr, 28 / 255.f, 28 / 255.f , 28 / 255.f ); + cairo_fill( cr ); + + // text + cairo_move_to( cr, x + 10, y + 14 ); + cairo_set_source_rgba( cr, 0 / 255.f, 153 / 255.f , 255 / 255.f , 1 ); + cairo_set_font_size( cr, 10 ); + cairo_show_text( cr, label ); + + // lower stripe + cairo_move_to( cr, x , y + 20 ); + cairo_line_to( cr, x + w, y + 20 ); + cairo_stroke( cr ); + + + // stroke rim + cairo_rectangle(cr, x, y, w, h); + cairo_set_source_rgba( cr, 0 / 255.f, 153 / 255.f , 255 / 255.f , 1 ); + cairo_stroke( cr ); + + + cairo_restore( cr ); + } + } + + void resize(int X, int Y, int W, int H) + { + Fl_Widget::resize(X,Y,W,H); + x = X; + y = Y; + w = W; + h = H; + redraw(); + } + + int handle(int event) + { + return 0; + + switch(event) + { + case FL_PUSH: + highlight = 0; + redraw(); + return 1; + case FL_DRAG: { + int t = Fl::event_inside(this); + if (t != highlight) { + redraw(); + } + } + return 1; + case FL_RELEASE: + if (highlight) { + highlight = 0; + redraw(); + do_callback(); + } + return 1; + case FL_SHORTCUT: + if ( test_shortcut() ) + { + do_callback(); + return 1; + } + return 0; + default: + return Fl_Widget::handle(event); + } + } +}; + +} // Avtk + +#endif // AVTK_BACKGROUND_H + diff --git a/src/avtk/avtk_button.h b/src/avtk/avtk_button.h index f45b106..18f2bb7 100644 --- a/src/avtk/avtk_button.h +++ b/src/avtk/avtk_button.h @@ -1,13 +1,37 @@ +/* + * Author: Harry van Haaren 2013 + * harryhaaren@gmail.com + * + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + */ + #ifndef AVTK_BUTTON_H #define AVTK_BUTTON_H #include -class AvtkButton : public Fl_Button +namespace Avtk +{ + +class Button : public Fl_Button { public: - AvtkButton(int _x, int _y, int _w, int _h, const char *_label=0): + Button(int _x, int _y, int _w, int _h, const char *_label): Fl_Button(_x, _y, _w, _h, _label) { x = _x; @@ -112,5 +136,7 @@ class AvtkButton : public Fl_Button } }; +} // Avtk + #endif // AVTK_BUTTON_H diff --git a/src/avtk/avtk_dial.h b/src/avtk/avtk_dial.h new file mode 100644 index 0000000..985a607 --- /dev/null +++ b/src/avtk/avtk_dial.h @@ -0,0 +1,168 @@ +/* + * Author: Harry van Haaren 2013 + * harryhaaren@gmail.com + * + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + */ + + +#ifndef AVTK_DIAL_H +#define AVTK_DIAL_H + +#include +#include + +namespace Avtk +{ + +class Dial : public Fl_Slider +{ + public: + Dial(int _x, int _y, int _w, int _h, const char* _label=0): + Fl_Slider(_x, _y, _w, _h, _label) + { + x = _x; + y = _y; + w = _w; + h = _h; + + // * 0.9 for line width to remain inside redraw area + if ( w > h ) + radius = (h / 2.f)*0.9; + else + radius = (w / 2.f)*0.9; + + lineWidth = 1.4 + radius / 12.f; + + mouseClickedY = 0; + mouseClicked = false; + + highlight = false; + label = _label; + } + + bool highlight; + int x, y, w, h; + const char* label; + + float radius; + float lineWidth; + + int mouseClickedY; + bool mouseClicked; + + void draw() + { + if (damage() & FL_DAMAGE_ALL) + { + draw_label(); + + cairo_t *cr = Fl::cairo_cc(); + + cairo_save( cr ); + + cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND); + cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND); + + cairo_set_line_width(cr, lineWidth-0.2); + cairo_move_to( cr, x+w/2,y+h/2); + cairo_line_to( cr, x+w/2,y+h/2); + cairo_set_source_rgba(cr, 0.1, 0.1, 0.1, 0 ); + cairo_stroke(cr); + + cairo_arc(cr, x+w/2,y+h/2, radius, 2.46, 0.75 ); + cairo_set_source_rgb(cr, 0.1, 0.1, 0.1 ); + cairo_stroke(cr); + + float angle = 2.46 + ( 4.54 * value() ); + cairo_set_line_width(cr, lineWidth); + cairo_arc(cr, x+w/2,y+h/2, radius, 2.46, angle ); + cairo_line_to(cr, x+w/2,y+h/2); + cairo_set_source_rgba(cr, 1.0, 0.48, 0, 0.8); + cairo_stroke(cr); + + cairo_restore( cr ); + + + } + } + + void resize(int X, int Y, int W, int H) + { + Fl_Slider::resize(X,Y,W,H); + x = X; + y = Y; + w = W; + h = H; + redraw(); + } + + int handle(int event) + { + //cout << "handle event type = " << event << " value = " << value() << endl; + + //Fl_Slider::handle( event ); + + switch(event) { + case FL_PUSH: + highlight = 1; + redraw(); + return 1; + case FL_DRAG: + { + if ( Fl::event_state(FL_BUTTON1) ) + { + if ( mouseClicked == false ) // catch the "click" event + { + mouseClickedY = Fl::event_y(); + mouseClicked = true; + } + + float deltaY = mouseClickedY - Fl::event_y(); + + float val = value(); + val += deltaY / 100.f; + + if ( val > 1.0 ) val = 1.0; + if ( val < 0.0 ) val = 0.0; + + set_value( val ); + + mouseClickedY = Fl::event_y(); + redraw(); + do_callback(); // makes FLTK call "extra" code entered in FLUID + } + } + return 1; + case FL_RELEASE: + if (highlight) { + highlight = 0; + redraw(); + // never do anything after a callback, as the callback + // may delete the widget! + } + mouseClicked = false; + return 1; + default: + return Fl_Widget::handle(event); + } + } +}; + +} // Avtk + +#endif // AVTK_DIAL_H diff --git a/src/avtk/avtk_image.h b/src/avtk/avtk_image.h new file mode 100644 index 0000000..c343c68 --- /dev/null +++ b/src/avtk/avtk_image.h @@ -0,0 +1,137 @@ +/* + * Author: Harry van Haaren 2013 + * harryhaaren@gmail.com + * + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + */ + + +#ifndef AVTK_IMAGE_H +#define AVTK_IMAGE_H + +#include +#include +#include +#include +#include + +using namespace std; + +namespace Avtk +{ + +class Image : public Fl_Widget +{ + public: + Image(int _x, int _y, int _w, int _h, const char *_label=0 ): + Fl_Widget(_x, _y, _w, _h, _label) + { + x = _x; + y = _y; + w = _w; + h = _h; + + label = _label; + + imageSurf = 0; + + if ( _label ) + { + //cout << "creating image from label" << endl; + imageSurf = cairo_image_surface_create_from_png( label ); + } + } + + int x, y, w, h; + const char* label; + + cairo_surface_t* imageSurf; + + void draw() + { + if (damage() & FL_DAMAGE_ALL) + { + cairo_t *cr = Fl::cairo_cc(); + + //cairo_save(cr); + + if ( imageSurf == 0 ) + { + // draw X + cairo_move_to( cr, x , y ); + cairo_line_to( cr, x + w, y + h ); + cairo_move_to( cr, x , y + h ); + cairo_line_to( cr, x + w, y ); + cairo_set_source_rgb ( cr, 0.2,0.2,0.2); + cairo_stroke(cr); + + // draw text + cairo_move_to( cr, x + (w/2.f) - 65, y + (h/2.f) + 10 ); + cairo_set_source_rgb ( cr, 0.6,0.6,0.6); + cairo_set_font_size( cr, 20 ); + cairo_show_text( cr, "Image not loaded" ); + + return; + } + + // draw the image to the context + cairo_set_source_surface(cr, imageSurf, x, y); + //cairo_rectangle( cr, x, y, w, h ); + cairo_paint(cr); + + //cairo_restore(cr); + } + } + + void resize(int X, int Y, int W, int H) + { + Fl_Widget::resize(X,Y,W,H); + x = X; + y = Y; + w = W; + h = H; + redraw(); + } + + int handle(int event) + { + switch(event) + { + case FL_PUSH: + do_callback(); + return 1; + case FL_DRAG: + return 1; + case FL_RELEASE: + return 1; + case FL_SHORTCUT: + if ( test_shortcut() ) + { + do_callback(); + return 1; + } + return 0; + default: + return Fl_Widget::handle(event); + } + } +}; + +} // Avtk + +#endif + diff --git a/src/gtrack.hxx b/src/gtrack.hxx index 7745317..2db2e39 100644 --- a/src/gtrack.hxx +++ b/src/gtrack.hxx @@ -6,26 +6,47 @@ #include #include +#include "avtk/avtk_dial.h" #include "avtk/avtk_button.h" +#include "avtk/avtk_background.h" class GTrack : public Fl_Group { public: - GTrack(int x, int y, int w, int h ) : + GTrack(int x, int y, int w, int h, const char* l = 0 ) : Fl_Group(x, y, w, h), - button(x + 5, y + 5, 100, 20,"Quit"), - button2(x + 5, y + 25, 100, 20,"2"), - button3(x + 5, y + 45, 100, 20,"3") - //slider(x, y + 50, w, 20) + bg( x, y , w, h, strdup(l) ), + + button1(x + 5, y + 24, 18, 18,"1"), + button2(x + 5, y + 44, 18, 18,"2"), + button3(x + 5, y + 64, 18, 18,"3"), + button4(x + 5, y + 84, 18, 18,"4"), + button5(x + 5, y +104, 18, 18,"5"), + button6(x + 5, y +124, 18, 18,"6"), + + dial1(x+15, y +155, 24, 24, "A"), + dial2(x+45, y +155, 24, 24, "B"), + dial3(x+75, y +155, 24, 24, "C") { end(); // close the group } private: - AvtkButton button; - AvtkButton button2; - AvtkButton button3; + Avtk::Background bg; + + Avtk::Button button1; + Avtk::Button button2; + Avtk::Button button3; + Avtk::Button button4; + Avtk::Button button5; + Avtk::Button button6; + + Avtk::Dial dial1; + Avtk::Dial dial2; + Avtk::Dial dial3; + + static int privateID; }; #endif // LUPPP_G_TRACK_H diff --git a/src/gui.cxx b/src/gui.cxx index d98517b..a212e14 100644 --- a/src/gui.cxx +++ b/src/gui.cxx @@ -1,18 +1,35 @@ - #include "gui.hxx" +#include "avtk/avtk_image.h" + +#include + +// Hack, move to gtrack.cpp +int GTrack::privateID = 0; + +using namespace std; Gui::Gui() { - window = new Fl_Window(640,280); + window = new Fl_Double_Window(600,280); window->color(FL_BLACK); + window->label("Luppp 5"); + + + Avtk::Image* header = new Avtk::Image(0,0,600,36,"header.png"); + + /* box = new Fl_Box(5, 5, 200, 60, "Luppp 5"); box->box(FL_UP_BOX); box->labelsize(36); box->labeltype(FL_SHADOW_LABEL); - - track = new GTrack(5,80,200,200); - track2 = new GTrack(120,80,200,200); + */ + for (int i = 0; i < 5; i++ ) + { + stringstream s; + s << "Track " << i+1; + tracks.push_back( new GTrack(8 + i * 118, 40, 110, 230, s.str().c_str() ) ); + } window->end(); } diff --git a/src/gui.hxx b/src/gui.hxx index 16dad6d..a061774 100644 --- a/src/gui.hxx +++ b/src/gui.hxx @@ -3,11 +3,15 @@ #define LUPPP_GUI #include -#include +#include #include #include "gtrack.hxx" +#include + +using namespace std; + class Gui { public: @@ -15,10 +19,9 @@ class Gui int show(); private: - Fl_Window* window; + Fl_Double_Window* window; Fl_Box* box; - GTrack* track; - GTrack* track2; + vector tracks; }; #endif // LUPPP_GUI diff --git a/src/resources/header.png b/src/resources/header.png new file mode 100644 index 0000000..85ba4bb Binary files /dev/null and b/src/resources/header.png differ