00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "gui/guildlistbox.h"
00023
00024 #include "graphics.h"
00025
00026 #include "resources/image.h"
00027 #include "resources/resourcemanager.h"
00028
00029 #include <guichan/font.hpp>
00030
00031 GuildListBox::GuildListBox():
00032 ListBox(NULL)
00033 {
00034 onlineIcon = ResourceManager::getInstance()->getImage("graphics/gui/circle-green.png");
00035 offlineIcon = ResourceManager::getInstance()->getImage("graphics/gui/circle-gray.png");
00036 }
00037
00038 void GuildListBox::draw(gcn::Graphics *gcnGraphics)
00039 {
00040 if (!mListModel)
00041 return;
00042
00043 Graphics *graphics = static_cast<Graphics*>(gcnGraphics);
00044
00045 graphics->setColor(gcn::Color(110, 160, 255));
00046 graphics->setFont(getFont());
00047
00048 int fontHeight = getFont()->getHeight();
00049
00050
00051 if (mSelected >= 0) {
00052 graphics->fillRectangle(gcn::Rectangle(0, fontHeight * mSelected,
00053 getWidth(), fontHeight));
00054 }
00055
00056
00057 for (int i = 0, y = 0;
00058 i < mListModel->getNumberOfElements();
00059 ++i, y += fontHeight)
00060 {
00061
00062 bool online = false;
00063 UserMap::iterator itr = mUsers.find(mListModel->getElementAt(i));
00064 if (itr != mUsers.end())
00065 {
00066 online = itr->second;
00067 }
00068 Image *icon = online ? onlineIcon : offlineIcon;
00069 if (icon)
00070 graphics->drawImage(icon, 1, y);
00071
00072 graphics->setColor(gcn::Color(0, 0, 0));
00073 graphics->drawText(mListModel->getElementAt(i), 33, y);
00074 }
00075 }
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 void GuildListBox::mousePressed(gcn::MouseEvent &event)
00104 {
00105 if (event.getButton() == gcn::MouseEvent::LEFT)
00106 {
00107 int y = event.getY();
00108 setSelected(y / getFont()->getHeight());
00109 distributeActionEvent();
00110 }
00111
00112 if (event.getButton() == gcn::MouseEvent::RIGHT)
00113 {
00114
00115 }
00116 }
00117
00118 void GuildListBox::setOnlineStatus(const std::string &user, bool online)
00119 {
00120 UserMap::iterator itr = mUsers.find(user);
00121 if (itr == mUsers.end())
00122 {
00123 mUsers.insert(std::pair<std::string, bool>(user, online));
00124 }
00125 else
00126 {
00127 itr->second = online;
00128 }
00129 adjustSize();
00130 }