Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/gui/src/lib/gui/gl_gui/glgui_checkbutton.cc @ 7929

Last change on this file since 7929 was 7929, checked in by bensch, 18 years ago

gui: click with positional information

File size: 3.0 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GUI
17
18#include "glgui_checkbutton.h"
19
20#include "text.h"
21
22namespace OrxGui
23{
24
25
26  /**
27   * standard constructor
28  */
29  GLGuiCheckButton::GLGuiCheckButton (const std::string& label, bool active)
30  : GLGuiButton(label)
31  {
32    this->init();
33    this->bActive = active;
34
35    this->resize();
36  }
37
38
39  /**
40   * standard deconstructor
41  */
42  GLGuiCheckButton::~GLGuiCheckButton()
43  {
44  }
45
46  /**
47   * initializes the GUI-element
48   */
49  void GLGuiCheckButton::init()
50  {
51    this->setClassID(CL_GLGUI_CHECKBUTTON, "GLGuiCheckButton");
52  }
53
54
55  void GLGuiCheckButton::toggleActiveState()
56  {
57    this->bActive = !this->bActive;
58  }
59
60  void GLGuiCheckButton::resize()
61  {
62    this->label.setRelCoor2D(25, 5);
63    this->setSize2D(this->label.getSizeX2D() + 30, this->label.getSizeY2D() + 10);
64    GLGuiWidget::resize();
65    this->frontRect().setTopLeft(1, 1);
66    this->frontRect().setSize(this->getSizeX2D() -2, this->getSizeY2D() -2);
67  }
68
69
70  void GLGuiCheckButton::released(const Vector2D& pos)
71  {
72    printf("%s released\n", this->getLabel().c_str());
73    GLGuiWidget::released(pos);
74    this->toggleActiveState();
75  }
76
77
78
79  /**
80   * @brief draws the GLGuiPushButton
81   */
82  void GLGuiCheckButton::draw() const
83  {
84    this->beginDraw();
85    GLGuiButton::draw();
86
87    this->frontMaterial().select();
88    this->drawRect(this->frontRect());
89
90    if (this->bActive)
91    {
92      glBegin(GL_QUADS);
93      glColor3f( 1, 1 ,1);
94      glTexCoord2i(0,0); glVertex2d(8, 8);
95      glTexCoord2i(0,1); glVertex2d(8, this->getSizeY2D()-8);
96      glTexCoord2i(1,1); glVertex2d(this->getSizeY2D()-8, this->getSizeY2D()-8);
97      glTexCoord2i(1,0); glVertex2d(this->getSizeY2D()-8, 8);
98      glEnd();
99
100
101      // DRAW a cross :)
102      glColor3f(0,0,0);
103      glLineWidth(3.0);
104      glBegin(GL_LINE_LOOP);
105      glVertex2d(8,8);
106      glVertex2d(this->getSizeY2D()/2, this->getSizeY2D()/2 - 1);
107
108      glVertex2d(this->getSizeY2D() -8, 8);
109      glVertex2d(this->getSizeY2D()/2 +1, this->getSizeY2D()/2);
110
111      glVertex2d(this->getSizeY2D() -8, this->getSizeY2D() - 8);
112      glVertex2d(this->getSizeY2D()/2, this->getSizeY2D()/2+1);
113
114      glVertex2d(8, this->getSizeY2D() - 8);
115      glVertex2d(this->getSizeY2D()/2 -1, this->getSizeY2D()/2);
116      glEnd();
117    }
118    else
119    {
120      glBegin(GL_QUADS);
121      glColor3f(0, 0, 0);
122      glTexCoord2i(0,0); glVertex2d(8, 8);
123      glTexCoord2i(0,1); glVertex2d(8, this->getSizeY2D()-8);
124      glTexCoord2i(1,1); glVertex2d(this->getSizeY2D()-8, this->getSizeY2D()-8);
125      glTexCoord2i(1,0); glVertex2d(this->getSizeY2D()-8, 8);
126      glEnd();
127    }
128
129    this->endDraw();
130  }
131}
Note: See TracBrowser for help on using the repository browser.