From 81e13dc96d75dccc7a7d4de64a33cc72eaff391f Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Wed, 1 May 2002 17:35:30 +0000 Subject: [PATCH] Added layout menu to FLUID. The menu contains many items th align and resize groups of selected widgets. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@2164 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- fluid/Makefile | 5 +- fluid/align_widget.cxx | 324 +++++++++++++++++++++++++++++++++++++++++ fluid/fluid.cxx | 31 +++- visualc/fluid.dsp | 4 + 4 files changed, 359 insertions(+), 5 deletions(-) create mode 100644 fluid/align_widget.cxx diff --git a/fluid/Makefile b/fluid/Makefile index 91fde4c20..650156a20 100644 --- a/fluid/Makefile +++ b/fluid/Makefile @@ -1,5 +1,5 @@ # -# "$Id: Makefile,v 1.10.2.6.2.17 2002/03/28 13:20:11 easysw Exp $" +# "$Id: Makefile,v 1.10.2.6.2.18 2002/05/01 17:35:30 matthiaswm Exp $" # # FLUID makefile for the Fast Light Tool Kit (FLTK). # @@ -37,6 +37,7 @@ CPPFILES = \ factory.cxx \ file.cxx \ fluid.cxx \ + align_widget.cxx \ about_panel.cxx \ widget_panel.cxx \ alignment_panel.cxx \ @@ -87,5 +88,5 @@ rebuild: ./fluid -c widget_panel.fl # -# End of "$Id: Makefile,v 1.10.2.6.2.17 2002/03/28 13:20:11 easysw Exp $". +# End of "$Id: Makefile,v 1.10.2.6.2.18 2002/05/01 17:35:30 matthiaswm Exp $". # diff --git a/fluid/align_widget.cxx b/fluid/align_widget.cxx new file mode 100644 index 000000000..f0777479c --- /dev/null +++ b/fluid/align_widget.cxx @@ -0,0 +1,324 @@ +// +// +// +// alignment code for the Fast Light Tool Kit (FLTK). +// +// Copyright 1998-2002 by Bill Spitzak and others. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Library General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library 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 +// Library General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA. +// +// Please report all bugs and problems to "fltk-bugs@fltk.org". +// + +#include +#include "Fl_Widget_Type.h" + +/** + * the first behaviour always uses the first selected widget as a reference + * the second behaviour uses the larges widget (most extreme positions) as a reference + */ +#define BREAK_ON_FIRST break +//#define BREAK_ON_FIRST + +void align_widget_cb(Fl_Widget*, long how) +{ + const int max = 32768, min = -32768; + int left, right, top, bot, wdt, hgt, n; + Fl_Type *o; + switch ( how ) + { + //---- align + case 10: // align left + left = max; + for (o = Fl_Type::first; o; o = o->next) + if (o->selected && o->is_widget()) + { + Fl_Widget *w = ((Fl_Widget_Type *)o)->o; + if (w->x()x(); + BREAK_ON_FIRST; + } + if (left!=max) + for (Fl_Type *o = Fl_Type::first; o; o = o->next) + if (o->selected && o->is_widget()) + { + Fl_Widget *w = ((Fl_Widget_Type *)o)->o; + w->resize(left, w->y(), w->w(), w->h()); + w->redraw(); + w->window()->redraw(); + } + break; + case 11: // align h.center + left = max; right = min; + for (o = Fl_Type::first; o; o = o->next) + if (o->selected && o->is_widget()) + { + Fl_Widget *w = ((Fl_Widget_Type *)o)->o; + if (w->x()x(); + if (w->x()+w->w()>right) + right = w->x()+w->w(); + BREAK_ON_FIRST; + } + if (left!=max) + { + int center2 = left+right; + for (Fl_Type *o = Fl_Type::first; o; o = o->next) + if (o->selected && o->is_widget()) + { + Fl_Widget *w = ((Fl_Widget_Type *)o)->o; + w->resize((center2-w->w())/2, w->y(), w->w(), w->h()); + w->redraw(); + w->window()->redraw(); + } + } + break; + case 12: // align right + right = min; + for (o = Fl_Type::first; o; o = o->next) + if (o->selected && o->is_widget()) + { + Fl_Widget *w = ((Fl_Widget_Type *)o)->o; + if (w->x()+w->w()>right) + right = w->x()+w->w(); + BREAK_ON_FIRST; + } + if (right!=min) + for (Fl_Type *o = Fl_Type::first; o; o = o->next) + if (o->selected && o->is_widget()) + { + Fl_Widget *w = ((Fl_Widget_Type *)o)->o; + w->resize(right-w->w(), w->y(), w->w(), w->h()); + w->redraw(); + w->window()->redraw(); + } + break; + case 13: // align top + top = max; + for (o = Fl_Type::first; o; o = o->next) + if (o->selected && o->is_widget()) + { + Fl_Widget *w = ((Fl_Widget_Type *)o)->o; + if (w->y()y(); + BREAK_ON_FIRST; + } + if (top!=max) + for (Fl_Type *o = Fl_Type::first; o; o = o->next) + if (o->selected && o->is_widget()) + { + Fl_Widget *w = ((Fl_Widget_Type *)o)->o; + w->resize(w->x(), top, w->w(), w->h()); + w->redraw(); + w->window()->redraw(); + } + break; + case 14: // align v.center + top = max; bot = min; + for (o = Fl_Type::first; o; o = o->next) + if (o->selected && o->is_widget()) + { + Fl_Widget *w = ((Fl_Widget_Type *)o)->o; + if (w->y()y(); + if (w->y()+w->h()>bot) + bot = w->y()+w->h(); + BREAK_ON_FIRST; + } + if (top!=max) + { + int center2 = top+bot; + for (Fl_Type *o = Fl_Type::first; o; o = o->next) + if (o->selected && o->is_widget()) + { + Fl_Widget *w = ((Fl_Widget_Type *)o)->o; + w->resize(w->x(), (center2-w->h())/2, w->w(), w->h()); + w->redraw(); + w->window()->redraw(); + } + } + break; + case 15: // align bottom + bot = min; + for (o = Fl_Type::first; o; o = o->next) + if (o->selected && o->is_widget()) + { + Fl_Widget *w = ((Fl_Widget_Type *)o)->o; + if (w->y()+w->h()>bot) + bot = w->y()+w->h(); + BREAK_ON_FIRST; + } + if (bot!=min) + for (Fl_Type *o = Fl_Type::first; o; o = o->next) + if (o->selected && o->is_widget()) + { + Fl_Widget *w = ((Fl_Widget_Type *)o)->o; + w->resize( w->x(), bot-w->h(), w->w(), w->h()); + w->redraw(); + w->window()->redraw(); + } + break; + //---- space evently + case 20: // space evenly across + left = max; right = min; wdt = 0, n = 0; + for (o = Fl_Type::first; o; o = o->next) + if (o->selected && o->is_widget()) + { + Fl_Widget *w = ((Fl_Widget_Type *)o)->o; + if (w->x()x(); + if (w->x()+w->w()>right) + right = w->x()+w->w(); + wdt += w->w(); + n++; + } + wdt = (right-left)-wdt; + n--; + if (n>0) + { + int cnt = 0, wsum = 0; + for (Fl_Type *o = Fl_Type::first; o; o = o->next) + if (o->selected && o->is_widget()) + { + Fl_Widget *w = ((Fl_Widget_Type *)o)->o; + w->resize(left+wsum+wdt*cnt/n, w->y(), w->w(), w->h()); + w->redraw(); + w->window()->redraw(); + cnt++; + wsum += w->w(); + } + } + break; + case 21: // space evenly down + top = max; bot = min; hgt = 0, n = 0; + for (o = Fl_Type::first; o; o = o->next) + if (o->selected && o->is_widget()) + { + Fl_Widget *w = ((Fl_Widget_Type *)o)->o; + if (w->y()y(); + if (w->y()+w->h()>bot) + bot = w->y()+w->h(); + hgt += w->h(); + n++; + } + hgt = (bot-top)-hgt; + n--; + if (n>0) + { + int cnt = 0, hsum = 0; + for (Fl_Type *o = Fl_Type::first; o; o = o->next) + if (o->selected && o->is_widget()) + { + Fl_Widget *w = ((Fl_Widget_Type *)o)->o; + w->resize(w->x(), top+hsum+hgt*cnt/n, w->w(), w->h()); + w->redraw(); + w->window()->redraw(); + cnt++; + hsum += w->h(); + } + } + break; + //---- make same size + case 30: // same width + wdt = min; + for (o = Fl_Type::first; o; o = o->next) + if (o->selected && o->is_widget()) + { + Fl_Widget *w = ((Fl_Widget_Type *)o)->o; + if (w->w()>wdt) + wdt = w->w(); + BREAK_ON_FIRST; + } + if (wdt!=min) + for (Fl_Type *o = Fl_Type::first; o; o = o->next) + if (o->selected && o->is_widget()) + { + Fl_Widget *w = ((Fl_Widget_Type *)o)->o; + w->resize( w->x(), w->y(), wdt, w->h()); + w->redraw(); + w->window()->redraw(); + } + break; + case 31: // same height + hgt = min; + for (o = Fl_Type::first; o; o = o->next) + if (o->selected && o->is_widget()) + { + Fl_Widget *w = ((Fl_Widget_Type *)o)->o; + if (w->h()>hgt) + hgt = w->h(); + BREAK_ON_FIRST; + } + if (hgt!=min) + for (Fl_Type *o = Fl_Type::first; o; o = o->next) + if (o->selected && o->is_widget()) + { + Fl_Widget *w = ((Fl_Widget_Type *)o)->o; + w->resize( w->x(), w->y(), w->w(), hgt); + w->redraw(); + w->window()->redraw(); + } + break; + case 32: // same size + hgt = min; wdt = min; + for (o = Fl_Type::first; o; o = o->next) + if (o->selected && o->is_widget()) + { + Fl_Widget *w = ((Fl_Widget_Type *)o)->o; + if (w->w()>wdt) + wdt = w->w(); + if (w->h()>hgt) + hgt = w->h(); + BREAK_ON_FIRST; + } + if (hgt!=min) + for (Fl_Type *o = Fl_Type::first; o; o = o->next) + if (o->selected && o->is_widget()) + { + Fl_Widget *w = ((Fl_Widget_Type *)o)->o; + w->resize( w->x(), w->y(), wdt, hgt); + w->redraw(); + w->window()->redraw(); + } + break; + //---- center in group + case 40: // center hor + for (o = Fl_Type::first; o; o = o->next) + if (o->selected && o->is_widget() && o->parent) + { + Fl_Widget *w = ((Fl_Widget_Type *)o)->o; + Fl_Widget *p = ((Fl_Widget_Type *)o->parent)->o; + int center2 = 2*p->x()+p->w(); + w->resize((center2-w->w())/2, w->y(), w->w(), w->h()); + w->redraw(); + w->window()->redraw(); + } + break; + case 41: // center vert + for (o = Fl_Type::first; o; o = o->next) + if (o->selected && o->is_widget() && o->parent) + { + Fl_Widget *w = ((Fl_Widget_Type *)o)->o; + Fl_Widget *p = ((Fl_Widget_Type *)o->parent)->o; + int center2 = 2*p->y()+p->h(); + w->resize(w->x(), (center2-w->h())/2, w->w(), w->h()); + w->redraw(); + w->window()->redraw(); + } + break; + } +} diff --git a/fluid/fluid.cxx b/fluid/fluid.cxx index b5d448890..862d950ad 100644 --- a/fluid/fluid.cxx +++ b/fluid/fluid.cxx @@ -1,5 +1,5 @@ // -// "$Id: fluid.cxx,v 1.15.2.13.2.19 2002/05/01 10:44:55 easysw Exp $" +// "$Id: fluid.cxx,v 1.15.2.13.2.20 2002/05/01 17:35:30 matthiaswm Exp $" // // FLUID main entry for the Fast Light Tool Kit (FLTK). // @@ -335,6 +335,8 @@ static void sort_cb(Fl_Widget *,void *) { void show_alignment_cb(Fl_Widget *, void *); void show_settings_cb(Fl_Widget *, void *); +void align_widget_cb(Fl_Widget *, long); + void about_cb(Fl_Widget *, void *) { if (!about_panel) make_about_panel(); display_group->show(); @@ -418,9 +420,32 @@ Fl_Menu_Item Main_Menu[] = { //{"Activate", 0, nyi, 0, FL_MENU_DIVIDER}, {"Overlays on/off",FL_CTRL+FL_SHIFT+'o',toggle_overlays}, {"Preferences",FL_CTRL+'p',show_alignment_cb}, - {"Settings",FL_CTRL+FL_SHIFT+'p',show_settings_cb}, {0}, {"&New", 0, 0, (void *)New_Menu, FL_SUBMENU_POINTER}, +{"&Layout",0,0,0,FL_SUBMENU}, + {"&Align",0,0,0,FL_SUBMENU}, + {"&Left",0,(Fl_Callback *)align_widget_cb,(void*)10}, + {"&Hor. Center",0,(Fl_Callback *)align_widget_cb,(void*)11}, + {"&Right",0,(Fl_Callback *)align_widget_cb,(void*)12}, + {"&Top",0,(Fl_Callback *)align_widget_cb,(void*)13}, + {"&Vert. Center",0,(Fl_Callback *)align_widget_cb,(void*)14}, + {"&Bottom",0,(Fl_Callback *)align_widget_cb,(void*)15}, + {0}, + {"&Space Evenly",0,0,0,FL_SUBMENU}, + {"&Across",0,(Fl_Callback *)align_widget_cb,(void*)20}, + {"&Down",0,(Fl_Callback *)align_widget_cb,(void*)21}, + {0}, + {"&Make Same Size",0,0,0,FL_SUBMENU}, + {"&Width",0,(Fl_Callback *)align_widget_cb,(void*)30}, + {"&Height",0,(Fl_Callback *)align_widget_cb,(void*)31}, + {"&Both",0,(Fl_Callback *)align_widget_cb,(void*)32}, + {0}, + {"&Center In Group",0,0,0,FL_SUBMENU|FL_MENU_DIVIDER}, + {"&Horizontal",0,(Fl_Callback *)align_widget_cb,(void*)40}, + {"&Vertical",0,(Fl_Callback *)align_widget_cb,(void*)41}, + {0}, + {"&Grid",FL_CTRL+FL_SHIFT+'p',show_settings_cb}, + {0}, {"&Shell",0,0,0,FL_SUBMENU}, {"Execute Command...",FL_ALT+'x',(Fl_Callback *)show_shell_window}, {"Execute Again",FL_ALT+'g',(Fl_Callback *)do_shell_command}, @@ -743,5 +768,5 @@ int main(int argc,char **argv) { } // -// End of "$Id: fluid.cxx,v 1.15.2.13.2.19 2002/05/01 10:44:55 easysw Exp $". +// End of "$Id: fluid.cxx,v 1.15.2.13.2.20 2002/05/01 17:35:30 matthiaswm Exp $". // diff --git a/visualc/fluid.dsp b/visualc/fluid.dsp index e9284045f..e91fa56ff 100644 --- a/visualc/fluid.dsp +++ b/visualc/fluid.dsp @@ -96,6 +96,10 @@ SOURCE=..\fluid\about_panel.cxx # End Source File # Begin Source File +SOURCE=..\fluid\align_widget.cxx +# End Source File +# Begin Source File + SOURCE=..\fluid\alignment_panel.cxx # End Source File # Begin Source File