Back to index

nux  3.0.0
CheckBox.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Inalogic® Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License, as
00006  * published by the  Free Software Foundation; either version 2.1 or 3.0
00007  * of the License.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License along with this program. If not, see <http://www.gnu.org/licenses/>
00017  *
00018  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00019  *
00020  */
00021 
00022 
00023 #include "Nux.h"
00024 #include "HLayout.h"
00025 #include "CheckBox.h"
00026 #include "StaticText.h"
00027 
00028 namespace nux
00029 {
00030   NUX_IMPLEMENT_OBJECT_TYPE(CheckBox);
00031   
00032   CheckBox::CheckBox(const std::string &str, bool state, NUX_FILE_LINE_DECL)
00033     : AbstractCheckedButton(str, state, NUX_FILE_LINE_PARAM)
00034   {
00035   }
00036 
00037   CheckBox::~CheckBox()
00038   {
00039   }
00040 
00041   void CheckBox::Draw(GraphicsEngine &graphics_engine, bool force_draw)
00042   {
00043     Geometry base = GetGeometry();
00044     graphics_engine.PushClippingRectangle(base);
00045 
00046     GetPainter().PaintBackground(graphics_engine, base);
00047 
00048     InteractState is;
00049     is.is_on = active_;
00050 
00051     if (visual_state_ == VISUAL_STATE_PRESSED)
00052     {
00053       is.is_focus = true;
00054     }
00055     else if (visual_state_ == VISUAL_STATE_PRELIGHT)
00056     {
00057       is.is_prelight = true;
00058     }
00059     else
00060     {
00061       is.is_focus = false;
00062       is.is_prelight = false;
00063     }
00064 
00065     GetPainter().PushPaintLayerStack();
00066     {
00067       GetPainter().PaintCheckBox(graphics_engine, check_area_->GetGeometry(), is, Color(0xff000000));
00068       static_text_->ProcessDraw(graphics_engine, true);
00069     }
00070     GetPainter().PopPaintLayerStack();
00071 
00072     graphics_engine.PopClippingRectangle();
00073   }
00074 
00075   void CheckBox::RecvClick(int x, int y, unsigned long button_flags, unsigned long key_flags)
00076   {
00077     active_ = !active_;
00078 
00079     click.emit(this);
00080     state_change.emit(this);
00081     QueueDraw();
00082   }
00083 
00084   void CheckBox::Activate()
00085   {
00086     if (active_ == true)
00087     {
00088       // already active
00089       return;
00090     }
00091 
00092     active_ = true;
00093     state_change.emit(this);
00094     QueueDraw();
00095   }
00096 
00097   void CheckBox::Deactivate()
00098   {
00099     if (active_ == false)
00100       return;
00101 
00102     if (active_ == false)
00103     {
00104       // already deactivated
00105       return;
00106     }
00107 
00108     active_ = false;
00109     state_change.emit(this);
00110     QueueDraw();
00111   }
00112 }