git-svn-id: https://scorched3d.svn.sourceforge.net/svnroot/scorched3d/trunk/scorched...
[scorched3d/parasti.git] / src / client / GLW / GLWCheckBox.cpp
blob6778ec9267942c9d54b52082a727c6e05f2aa402
1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2009
3 //
4 // This file is part of Scorched3D.
5 //
6 // Scorched3D 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 of the License, or
9 // (at your option) any later version.
11 // Scorched3D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with Scorched3D; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ////////////////////////////////////////////////////////////////////////////////
21 #include <GLW/GLWCheckBox.h>
22 #include <GLEXT/GLState.h>
24 GLWCheckBoxI::~GLWCheckBoxI()
29 REGISTER_CLASS_SOURCE(GLWCheckBox);
31 GLWCheckBox::GLWCheckBox(float x, float y, bool startState) :
32 GLWidget(x, y, 20.0f, 20.0f), state_(startState), handler_(0)
36 GLWCheckBox::~GLWCheckBox()
40 void GLWCheckBox::setHandler(GLWCheckBoxI *handler)
42 handler_ = handler;
45 void GLWCheckBox::draw()
47 float halfW = h_ / 2.0f;
48 glLineWidth(1.0f);
49 glBegin(GL_LINE_LOOP);
50 drawShadedRoundBox(x_, y_, w_, h_, halfW, false);
51 glEnd();
53 if (state_)
55 // Draw check mark
56 glColor3f(0.2f, 0.2f, 0.2f);
57 glBegin(GL_TRIANGLE_FAN);
58 glVertex2f(x_ + halfW, y_ + halfW);
59 drawCircle(16, -1, x_ + halfW, y_ + halfW, halfW - 3.0f);
60 glEnd();
62 GLWidget::draw();
65 void GLWCheckBox::mouseDown(int button, float x, float y, bool &skipRest)
67 if (x > x_ && x<x_+w_ &&
68 y > y_ && y<y_+h_)
70 state_ = !state_;
71 skipRest = true;
72 if (handler_) handler_->stateChange(state_, getId());
74 GLWidget::mouseDown(button, x, y, skipRest);