00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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 }