Page principale | Liste des namespaces | Hiérarchie des classes | Liste alphabétique | Liste des classes | Liste des fichiers | Membres de namespace | Membres de classe | Membres de fichier

src/gwili-resize-bar.cpp

Aller à la documentation de ce fichier.
00001 /* 
00002  * GWiLi (GLUT Widget Library): GWiLi is a widget manager for GLUT.
00003  * Copyright (C) 2005, Nicolas GUIARD, n.guiard@libertysurf.fr
00004  *               http://nicolas.guiard.free.fr/gwili/
00005  * 
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  * 
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 // #define DEBUG_MESSAGES
00022 #include "gwili-debug.hpp"
00023 
00024 #include "gl-headers.hpp"
00025 #include "gwili-resize-bar.hpp"
00026 #include "gwili-tools.hpp"
00027 #include "gwili-window.hpp"
00028 
00029 using namespace GWILI;
00030 
00031 ResizeBar::ResizeBar(Widget * w, int horizontal, int vertical)
00032   : Widget(), target(w), x_coef(horizontal), y_coef(vertical),
00033     resize_widget(false)
00034 {
00035   setMinSize(4, 4);
00036 }
00037 
00038 ResizeBar::~ResizeBar()
00039 {
00040   DEBUG_FUNCTION;
00041 }
00042 
00043 void ResizeBar::draw()
00044 {
00045 }
00046 
00047 void ResizeBar::onMouseClick(int button, int state, int x, int y)
00048 {
00049   Widget::onMouseClick(button, state, x, y);
00050 
00051   if (getMouseClick() == GLUT_LEFT_BUTTON) {
00052     resize_widget = true;
00053     changeGlutWindow(getMotherWindow()->getGlutWindowId());
00054     old_x = glutGet(GLUT_WINDOW_X) + x;
00055     old_y = glutGet(GLUT_WINDOW_Y) + y;
00056     restoreGlutWindow();
00057     old_size_x = target->getWidth();
00058     old_size_y = target->getHeight();
00059     old_pos_x = target->getPosX();
00060     old_pos_y = target->getPosY();
00061   }
00062   else
00063     resize_widget = false;
00064 }
00065 
00066 void ResizeBar::onMouseMotion(int x, int y)
00067 {
00068   Widget::onMouseMotion(x, y);
00069 
00070   if (resize_widget && !target->needRedisplay()) {
00071     changeGlutWindow(getMotherWindow()->getGlutWindowId());
00072     int pos_x = glutGet(GLUT_WINDOW_X) + x;
00073     int pos_y = glutGet(GLUT_WINDOW_Y) + y;
00074     restoreGlutWindow();
00075 
00076     int dx = (pos_x - old_x) * x_coef;
00077     int dy = (pos_y - old_y) * y_coef;
00078 
00079     int res = target->setSize(old_size_x + dx, old_size_y + dy, true, false);
00080     target->setPosition(x_coef < 0 && (res & GWILI_WIDTH_CHANGED) ?
00081                         old_pos_x - dx : target->getPosX(),
00082                         y_coef < 0 && (res & GWILI_HEIGHT_CHANGED) ?
00083                         old_pos_y - dy : target->getPosY());
00084   }
00085 }
00086 
00087 void ResizeBar::onLeavingClick()
00088 {
00089   unsetMouseCursor(this);
00090   resize_widget = false;
00091 }
00092 
00093 void ResizeBar::onEnteringUnderMouse()
00094 {
00095   if (x_coef > 0)
00096     if (y_coef > 0)
00097       current_cursor = GLUT_CURSOR_BOTTOM_RIGHT_CORNER;
00098     else if (y_coef < 0)
00099       current_cursor = GLUT_CURSOR_TOP_RIGHT_CORNER;
00100     else
00101       current_cursor = GLUT_CURSOR_RIGHT_SIDE;
00102   else if (x_coef < 0)
00103     if (y_coef > 0)
00104       current_cursor = GLUT_CURSOR_BOTTOM_LEFT_CORNER;
00105     else if (y_coef < 0)
00106       current_cursor = GLUT_CURSOR_TOP_LEFT_CORNER;
00107     else
00108       current_cursor = GLUT_CURSOR_LEFT_SIDE;
00109   else
00110     if (y_coef > 0)
00111       current_cursor = GLUT_CURSOR_BOTTOM_SIDE;
00112     else if (y_coef < 0)
00113       current_cursor = GLUT_CURSOR_TOP_SIDE;
00114 
00115   setMouseCursor(this, current_cursor);
00116 }
00117 
00118 void ResizeBar::onLeavingUnderMouse()
00119 {
00120   if (!isClicked())
00121     unsetMouseCursor(this);
00122 }

Généré le Sun Sep 4 09:46:30 2005 pour GLUT Widget Library par  doxygen 1.4.3-20050530