00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "list_box_w_label.h"
00023 #include <algorithm>
00024 #include <SDL_gfxPrimitives.h>
00025 #include "../graphic/font.h"
00026 #include "../include/app.h"
00027 #include "../tool/math_tools.h"
00028 #include "../tool/resource_manager.h"
00029
00030
00031
00032 ListBoxWithLabel::ListBoxWithLabel (const std::string &label, const Rectanglei &rect) : ListBox(rect)
00033 {
00034 txt_label = new Text(label, dark_gray_color, Font::GetInstance(Font::FONT_NORMAL, Font::BOLD), false);
00035 SetSizePosition(rect);
00036 txt_label->SetMaxWidth(GetSizeX());
00037 }
00038
00039 ListBoxWithLabel::~ListBoxWithLabel()
00040 {
00041 delete txt_label;
00042 }
00043
00044 void ListBoxWithLabel::Draw(const Point2i &mousePosition, Surface& surf) const
00045 {
00046 int item = MouseIsOnWhichItem(mousePosition);
00047
00048 Rectanglei rect (GetPositionX(),GetPositionY(),GetSizeX(),
00049 GetSizeY()- 2 - txt_label->GetHeight());
00050
00051 surf.BoxColor(rect, defaultListColor1);
00052 surf.RectangleColor(rect, white_color);
00053
00054 for(uint i=0; i < nb_visible_items; i++){
00055 Rectanglei rect(GetPositionX() + 1,
00056 GetPositionY() + i * height_item + 1,
00057 GetSizeX() - 2,
00058 height_item - 2);
00059
00060 if( int(i + first_visible_item) == selected_item) {
00061 surf.BoxColor(rect, defaultListColor2);
00062 }
00063 else if( i + first_visible_item == uint(item) ) {
00064 surf.BoxColor(rect, defaultListColor3);
00065 }
00066
00067 (*Font::GetInstance(Font::FONT_SMALL)).WriteLeft(
00068 GetPosition() + Point2i(5, i*height_item),
00069 m_items[i + first_visible_item]->GetLabel(),
00070 white_color);
00071 if(!m_items[i]->IsEnabled())
00072 surf.BoxColor(rect, defaultDisabledColorBox);
00073 }
00074
00075
00076 txt_label->DrawTopLeft( GetPositionX(), GetPositionY() + GetSizeY() - txt_label->GetHeight() );
00077
00078
00079 if (m_items.size() > nb_visible_items_max){
00080 m_up->Draw(mousePosition, surf);
00081 m_down->Draw(mousePosition, surf);
00082 #ifdef SCROLLBAR
00083 uint tmp_y, tmp_h;
00084 tmp_y = y+10+ first_visible_item* (h-20) / m_items.size();
00085 tmp_h = nb_visible_items_max * (h-20) / m_items.size();
00086 if (tmp_h < 5) tmp_h =5;
00087
00088 boxRGBA(surf,
00089 x+w-10, tmp_y,
00090 x+w-1, tmp_y+tmp_h,
00091 white_color);
00092 #endif
00093 }
00094 }
00095
00096 void ListBoxWithLabel::SetSizePosition(const Rectanglei &rect)
00097 {
00098 StdSetSizePosition(rect);
00099 txt_label->SetMaxWidth(GetSizeX());
00100
00101 m_up->SetSizePosition( Rectanglei(GetPositionX() + GetSizeX() - m_up->GetSizeX() - 2,
00102 GetPositionY()+2,
00103 m_up->GetSizeX(), m_up->GetSizeY()) );
00104
00105 m_down->SetSizePosition( Rectanglei(GetPositionX() + GetSizeX() - m_down->GetSizeX() - 2,
00106 GetPositionY() + GetSizeY() - m_down->GetSizeY() - 2 -
00107 txt_label->GetHeight() - 2,
00108 m_down->GetSizeX(),
00109 m_down->GetSizeY()) );
00110
00111 nb_visible_items_max = GetSizeY()/height_item;
00112 }