00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "check_box.h"
00023 #include "../graphic/font.h"
00024 #include "../graphic/sprite.h"
00025 #include "../tool/resource_manager.h"
00026
00027 CheckBox::CheckBox(const std::string &label, const Rectanglei &rect, bool value)
00028 {
00029 Profile *res = resource_manager.LoadXMLProfile( "graphism.xml", false);
00030 m_checked_image = resource_manager.LoadSprite( res, "menu/check");
00031 resource_manager.UnLoadXMLProfile( res);
00032
00033 m_checked_image->cache.EnableLastFrameCache();
00034
00035 SetPosition( rect.GetPosition() );
00036 SetSize( rect.GetSize() );
00037
00038 SetSizeY( (*Font::GetInstance(Font::FONT_SMALL)).GetHeight() );
00039 m_value = value;
00040
00041 txt_label = new Text(label, white_color, Font::GetInstance(Font::FONT_SMALL));
00042 hidden = false;
00043 }
00044
00045 CheckBox::~CheckBox()
00046 {
00047 delete m_checked_image;
00048 delete txt_label;
00049 }
00050
00051 void CheckBox::Draw(const Point2i &mousePosition, Surface& surf) const
00052 {
00053 if (!hidden)
00054 {
00055 txt_label->DrawTopLeft( GetPosition() );
00056
00057 if (m_value)
00058 m_checked_image->SetCurrentFrame(0);
00059 else
00060 m_checked_image->SetCurrentFrame(1);
00061
00062 m_checked_image->Blit(surf, GetPositionX() + GetSizeX() - 16, GetPositionY());
00063 }
00064 }
00065
00066 Widget* CheckBox::Clic(const Point2i &mousePosition, uint button)
00067 {
00068 need_redrawing = true;
00069 m_value = !m_value;
00070 return this ;
00071 }
00072
00073 void CheckBox::SetSizePosition(const Rectanglei &rect)
00074 {
00075 StdSetSizePosition(rect);
00076 }
00077
00078 bool CheckBox::GetValue() const
00079 {
00080 return m_value;
00081 }
00082
00083 void CheckBox::SetValue(bool value)
00084 {
00085 m_value = value;
00086 }
00087
00088 void CheckBox::SetVisible(bool visible)
00089 {
00090 if (hidden == visible) {
00091 hidden = !visible;
00092 need_redrawing = true;
00093 }
00094 }