| 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 | |
|---|
| 22 | namespace 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 | void GLGuiCheckButton::setActivity(bool bActive) |
|---|
| 55 | { |
|---|
| 56 | this->bActive = bActive; |
|---|
| 57 | emit(this->toggled(this->bActive)); |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | void GLGuiCheckButton::toggleActiveState() |
|---|
| 61 | { |
|---|
| 62 | this->setActivity(!this->isActive()); |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | void GLGuiCheckButton::resize() |
|---|
| 66 | { |
|---|
| 67 | |
|---|
| 68 | this->labelText().setRelCoor2D( borderLeft() + 15.0, borderTop() + 5); |
|---|
| 69 | this->setSize2D(this->labelText().getSizeX2D() + 15.0 + borderLeft() + borderRight(), this->labelText().getSizeY2D() + 10 + borderTop()+borderBottom()); |
|---|
| 70 | GLGuiWidget::resize(); |
|---|
| 71 | |
|---|
| 72 | this->_checkBox.setSize(10.0, 10.0); |
|---|
| 73 | this->_checkBox.setCenter( borderLeft() + _checkBox.height()/2.0, borderTop() + (this->getSizeY2D() - borderTop() - borderBottom()) / 2.0); |
|---|
| 74 | |
|---|
| 75 | /* this->frontRect().setTopLeft(borderLeft(), borderTop()); |
|---|
| 76 | this->frontRect().setSize(this->getSizeX2D() - (borderLeft() + borderRight()) , this->getSizeY2D() - (borderTop() + borderBottom()));*/ |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | void GLGuiCheckButton::releasing(const Vector2D& pos, bool focused) |
|---|
| 81 | { |
|---|
| 82 | GLGuiButton::releasing(pos, focused); |
|---|
| 83 | if (focused) |
|---|
| 84 | this->toggleActiveState(); |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | /** |
|---|
| 90 | * @brief draws the GLGuiPushButton |
|---|
| 91 | */ |
|---|
| 92 | void GLGuiCheckButton::draw() const |
|---|
| 93 | { |
|---|
| 94 | this->beginDraw(); |
|---|
| 95 | GLGuiButton::draw(); |
|---|
| 96 | |
|---|
| 97 | // this->frontMaterial().select(); |
|---|
| 98 | // this->drawRect(this->frontRect()); |
|---|
| 99 | if (this->bActive) |
|---|
| 100 | { |
|---|
| 101 | glColor3fv( &this->foregroundColor()[0]); |
|---|
| 102 | this->drawRect(this->_checkBox); |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | // DRAW a cross :) |
|---|
| 106 | Vector2D center = this->_checkBox.center(); |
|---|
| 107 | glColor4f(1,1,1, 1.0); |
|---|
| 108 | glLineWidth(3.0); |
|---|
| 109 | |
|---|
| 110 | glBegin(GL_LINE_LOOP); |
|---|
| 111 | glVertex2d(_checkBox.left(), _checkBox.top()); |
|---|
| 112 | glVertex2d(center.x, center.y); |
|---|
| 113 | |
|---|
| 114 | glVertex2d(_checkBox.right(), _checkBox.top()); |
|---|
| 115 | glVertex2d(center.x, center.y); |
|---|
| 116 | |
|---|
| 117 | glVertex2d(_checkBox.right(), _checkBox.bottom()); |
|---|
| 118 | glVertex2d(center.x, center.y); |
|---|
| 119 | |
|---|
| 120 | glVertex2d(_checkBox.left(), _checkBox.bottom()); |
|---|
| 121 | glVertex2d(center.x, center.y); |
|---|
| 122 | glEnd(); |
|---|
| 123 | } |
|---|
| 124 | else |
|---|
| 125 | { |
|---|
| 126 | glColor3fv( &this->foregroundColor()[0]); |
|---|
| 127 | this->drawRect(this->_checkBox); |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | this->endDraw(); |
|---|
| 131 | } |
|---|
| 132 | } |
|---|