![]() |
MechSys
1.0
Computing library for simulations in continuum and discrete mechanics
|
00001 /************************************************************************ 00002 * MechSys - Open Library for Mechanical Systems * 00003 * Copyright (C) 2005 Dorival M. Pedroso * 00004 * * 00005 * This program is free software: you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation, either version 3 of the License, or * 00008 * any later version. * 00009 * * 00010 * This program is distributed in the hope that it will be useful, * 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00013 * GNU General Public License for more details. * 00014 * * 00015 * You should have received a copy of the GNU General Public License * 00016 * along with this program. If not, see <http://www.gnu.org/licenses/> * 00017 ************************************************************************/ 00018 00019 /* Tiled - Copyright (C) 2007 Dorival de Moraes Pedroso */ 00020 00021 #ifndef MPM_TILED_H 00022 #define MPM_TILED_H 00023 00024 // STL 00025 #include <cfloat> // for DBL_MAX 00026 00027 // FLTK 00028 #include <FL/Fl.H> 00029 #include <FL/Fl_Tile.H> 00030 #include <FL/Fl_Group.H> 00031 #include <FL/fl_draw.H> 00032 00033 namespace MPM { 00034 00035 typedef Fl_Group * (*pAllocGroup) (int X, int Y, int W, int H, void * Extra); 00036 00038 00039 class TwoTiledVert : public Fl_Tile 00040 { 00041 public: 00042 // Constructor 00043 TwoTiledVert (int X, int Y, int W, int H, void * Extra, pAllocGroup pAllocG1, pAllocGroup pAllocG2, double Hfactor=0.5) : Fl_Tile (X, Y, W, H) 00044 { 00045 int htop = static_cast<int>(Hfactor*H); 00046 int hbot = H-htop; 00047 _top = (*pAllocG1) (x(), y(), W, htop, Extra); 00048 _bot = (*pAllocG2) (x(), y()+htop, W, hbot, Extra); 00049 end(); 00050 } 00051 00052 // Methods 00053 Fl_Group * T() { return _top; } 00054 Fl_Group * B() { return _bot; } 00055 00056 protected: 00057 // Resize proportionally 00058 void resize(int X, int Y, int W, int H) 00059 { 00060 // Get old proportions so we can preserve through resize 00061 double hfactor = static_cast<double> (_top->h())/h(); 00062 int htop = static_cast<int> (H*hfactor+0.5); 00063 00064 // Resize our widget via Fl_Widget (to prevent children resizing) 00065 Fl_Widget::resize (X, Y, W, H); 00066 00067 // Resize children with custom computations 00068 _top->resize (X, Y , W, htop); 00069 _bot->resize (X, Y+htop, W, H-htop); 00070 } 00071 00072 private: 00073 // Data 00074 Fl_Group * _top; 00075 Fl_Group * _bot; 00076 }; 00077 00079 00080 class TwoTiledHorz : public Fl_Tile 00081 { 00082 public: 00083 // Constructor 00084 TwoTiledHorz (int X, int Y, int W, int H, void * Extra, pAllocGroup pAllocG1, pAllocGroup pAllocG2, double Wfactor=0.5) : Fl_Tile (X, Y, W, H) 00085 { 00086 int wlef = static_cast<int>(Wfactor*W); 00087 int wrig = W-wlef; 00088 _lft = (*pAllocG1) (x(), y(), wlef, H, Extra); 00089 _rig = (*pAllocG2) (x()+wlef, y(), wrig, H, Extra); 00090 end(); 00091 } 00092 00093 // Methods 00094 Fl_Group * L() { return _lft; } 00095 Fl_Group * R() { return _rig; } 00096 00097 protected: 00098 // Resize proportionally 00099 void resize(int X, int Y, int W, int H) 00100 { 00101 // Get old proportions so we can preserve through resize 00102 double wfactor = static_cast<double> (_lft->w())/w(); 00103 int wlef = static_cast<int> (W*wfactor+0.5); 00104 00105 // Resize our widget via Fl_Widget (to prevent children resizing) 00106 Fl_Widget::resize (X, Y, W, H); 00107 00108 // Resize children with custom computations 00109 _lft->resize (X , Y , wlef , H); 00110 _rig->resize (X+wlef , Y , W-wlef , H); 00111 } 00112 00113 private: 00114 // Data 00115 Fl_Group * _lft; 00116 Fl_Group * _rig; 00117 }; 00118 00120 00121 class FourTiled : public Fl_Tile 00122 { 00123 public: 00124 // Constructor 00125 FourTiled (int X, int Y, int W, int H, void * Extra, pAllocGroup pAllocG1, pAllocGroup pAllocG2, pAllocGroup pAllocG3, pAllocGroup pAllocG4, double Wfactor=0.5, double Hfactor=0.5) : Fl_Tile (X, Y, W, H) 00126 { 00127 int htop = static_cast<int>(Hfactor*H); 00128 int hbot = H-htop; 00129 int wlef = static_cast<int>(Wfactor*W); 00130 int wrig = W-wlef; 00131 _toplft = (*pAllocG1) (x(), y(), wlef, htop, Extra); 00132 _toprig = (*pAllocG2) (x()+wlef, y(), wrig, htop, Extra); 00133 _botlft = (*pAllocG3) (x(), y()+htop, wlef, hbot, Extra); 00134 _botrig = (*pAllocG4) (x()+wlef, y()+htop, wrig, hbot, Extra); 00135 end(); 00136 } 00137 00138 // Methods 00139 Fl_Group * TL() { return _toplft; } 00140 Fl_Group * TR() { return _toprig; } 00141 Fl_Group * BL() { return _botlft; } 00142 Fl_Group * BR() { return _botrig; } 00143 00144 protected: 00145 // Resize proportionally 00146 void resize(int X, int Y, int W, int H) 00147 { 00148 // Get old proportions so we can preserve through resize 00149 double wfactor = static_cast<double> (_toplft->w())/w(); 00150 double hfactor = static_cast<double> (_toplft->h())/h(); 00151 int wlef = static_cast<int> (W*wfactor+0.5); 00152 int htop = static_cast<int> (H*hfactor+0.5); 00153 00154 // Resize our widget via Fl_Widget (to prevent children resizing) 00155 Fl_Widget::resize (X, Y, W, H); 00156 00157 // Resize children with custom computations 00158 _toplft->resize (X , Y , wlef , htop); 00159 _toprig->resize (X+wlef , Y , W-wlef , htop); 00160 _botlft->resize (X , Y+htop , wlef , H-htop); 00161 _botrig->resize (X+wlef , Y+htop , W-wlef , H-htop); 00162 } 00163 00164 private: 00165 // Data 00166 Fl_Group * _toplft; 00167 Fl_Group * _toprig; 00168 Fl_Group * _botlft; 00169 Fl_Group * _botrig; 00170 }; 00171 00172 }; // namespace MPM 00173 00174 #endif // MPM_TILED_H