// Code based on: http://www.mail-archive.com/fltk@easysw.com/msg04573.html // Lucas Sanner/Ian MacArthur #include "Fl_Splitter.h" void Fl_HSplitter::draw() { Fl_Group::draw(); Fl_Color c = fl_color(); fl_color(FL_BLACK); fl_line_style( FL_DOT, 1); if(splitFl && Fl::event_button1() != 0) { fl_push_clip(x(), y(), w(), h()); yPos = Fl::event_y(); if(Fl::event_y() > h() - (border * 2)) yPos = h() - (border * 2); if(Fl::event_y() < y() + (border * 2)) yPos = y() + (border * 2); fl_line( x() + border, yPos - 1, x() + w() - (border*2), yPos - 1 ); fl_line( x() + border, yPos , x() + w() - (border*2), yPos ); fl_line( x() + border, yPos + 1, x() + w() - (border*2), yPos + 1 ); /* fl_line( x() + border, yPos, x() + w() - (border*2), yPos ); fl_line( x() + border, yPos + 1, x() + w() - (border*2), yPos + 1 ); */ fl_pop_clip(); } else { fl_push_clip(x(), y(), w(), h()); fl_pop_clip(); } fl_color(c); fl_line_style(0); } int Fl_HSplitter::handle(int e) { int ret = Fl_Group::handle(e); switch(e) { case FL_MOVE: if(hCtnl - border < Fl::event_y() && Fl::event_y() < hCtnl + border) { fl_cursor(FL_CURSOR_NS); splitFl = true; } else { fl_cursor(FL_CURSOR_DEFAULT); splitFl = false; } return 1; case FL_PUSH: if(Fl::event_button() == FL_LEFT_MOUSE && splitFl) { redraw(); } return 1; case FL_RELEASE: if(Fl::event_button() == FL_LEFT_MOUSE && splitFl) { c0->resize(x(), y(), w(), yPos - y()); hCtnl = yPos; c1->resize(x(),hCtnl, w(), h() - (yPos - y())); if( stretchTopFl ) init_sizes(); splitFl = false; redraw(); } return 1; case FL_DRAG: if(splitFl && Fl::event_state(FL_BUTTON1) != 0) redraw(); return 1; } return(ret); } Fl_HSplitter::Fl_HSplitter(int x, int y, int w, int h, int h1, const char *l, bool stretchBotFl) : Fl_Group(x, y, w, h, l) { int h2 = h - h1; begin(); c0 = new Splitter_Container(x, y, w, h1); //c0->color((Fl_Color) FL_RED); end(); begin(); c1 = new Splitter_Container(x, y + h1, w, h2); //c1->color((Fl_Color) FL_BLUE); end(); hCtnl = y + h1; splitFl = false; stretchTopFl = !stretchBotFl; border = Fl::box_dy(FL_DOWN_BOX); if( stretchTopFl ) resizable(c0); } void Fl_HSplitter::resize(int x, int y, int w, int h) { Fl_Group::resize(x, y, w, h); if( stretchTopFl ) { hCtnl = c0->h() + y; yPos = hCtnl; //printf("hCtnl:%i\n",hCtnl); } else { c0->resize(x, y, w, hCtnl - y); c1->resize(x, hCtnl, w, h - (hCtnl - y)); } } void Fl_VSplitter::draw() { Fl_Group::draw(); Fl_Color c = fl_color(); fl_color(FL_BLACK); fl_line_style( FL_DOT, 1); if(splitFl && Fl::event_button1() != 0) { fl_push_clip(x(), y(), w(), h()); xPos = Fl::event_x(); if(Fl::event_x() > w() - (border * 2)) xPos = w() - (border * 2); if(Fl::event_x() < x() + (border * 2)) xPos = x() + (border * 2); fl_line(xPos - 1, y() + border, xPos - 1, y() + h() - (border * 2)); fl_line(xPos, y() + border, xPos, y() + h() - (border * 2)); fl_line(xPos + 1, y() + border, xPos + 1, y() + h() - (border * 2)); fl_pop_clip(); } else { fl_push_clip(x(), y(), w(), h()); fl_pop_clip(); } fl_color(c); fl_line_style(0); // restore line style to defaults } int Fl_VSplitter::handle(int e) { int ret = Fl_Group::handle(e); switch(e) { case FL_MOVE: if(Fl::event_x() > wCtn1 - border && Fl::event_x() < wCtn1 + border) { fl_cursor(FL_CURSOR_WE); splitFl = true; } else { fl_cursor(FL_CURSOR_DEFAULT); splitFl = false; } return 1; case FL_PUSH: if(Fl::event_button() == FL_LEFT_MOUSE && splitFl) { redraw(); } return 1; case FL_RELEASE: if(Fl::event_button() == FL_LEFT_MOUSE && splitFl) { c0->resize(x(), y(), xPos, h()); wCtn1 = xPos; c1->resize(wCtn1, y(), w() - wCtn1, h()); splitFl = false; redraw(); } return 1; case FL_DRAG: if(splitFl && Fl::event_state(FL_BUTTON1) != 0) redraw(); return 1; } return(ret); } Fl_VSplitter::Fl_VSplitter(int x, int y, int w, int h, const char *l) : Fl_Group(x, y, w, h, l) { begin(); c0 = new Splitter_Container(x, y, w / 2, h); //c0->color((Fl_Color) FL_RED); end(); begin(); c1 = new Splitter_Container(x + (w / 2), y, w / 2, h); //c1->color((Fl_Color) FL_BLUE); end(); wCtn1 = w / 2; splitFl = false; border = Fl::box_dx(FL_DOWN_BOX); } void Fl_VSplitter::resize_splitter(int x, int y, int w, int h) { resize(x, y, w, h); c0->resize(x, y, wCtn1, h); c1->resize(wCtn1, y, w - wCtn1, h); }