1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
#include <iostream>
#include <typeinfo>
#include "AvatarButton.h"
#include "Format.h"
#include "Engine.h"
#include "client/Client.h"
#include "client/requestbroker/RequestBroker.h"
#include "graphics/Graphics.h"
#include "ContextMenu.h"
#include "Keys.h"
namespace ui {
AvatarButton::AvatarButton(Point position, Point size, std::string username):
Component(position, size),
name(username),
actionCallback(NULL),
avatar(NULL),
tried(false)
{
}
AvatarButton::~AvatarButton()
{
RequestBroker::Ref().DetachRequestListener(this);
if(avatar)
delete avatar;
if(actionCallback)
delete actionCallback;
}
void AvatarButton::Tick(float dt)
{
if(!avatar && !tried && name.size() > 0)
{
tried = true;
RequestBroker::Ref().RetrieveAvatar(name, Size.X, Size.Y, this);
}
}
void AvatarButton::OnResponseReady(void * imagePtr, int identifier)
{
VideoBuffer * image = (VideoBuffer*)imagePtr;
if(image)
{
if(avatar)
delete avatar;
avatar = image;
}
}
void AvatarButton::Draw(const Point& screenPos)
{
Graphics * g = ui::Engine::Ref().g;
if(avatar)
{
g->draw_image(avatar, screenPos.X, screenPos.Y, 255);
}
}
void AvatarButton::OnMouseUnclick(int x, int y, unsigned int button)
{
if(button != 1)
{
return; //left click only!
}
if(isButtonDown)
{
isButtonDown = false;
DoAction();
}
}
void AvatarButton::OnContextMenuAction(int item)
{
//Do nothing
}
void AvatarButton::OnMouseClick(int x, int y, unsigned int button)
{
if(button == BUTTON_RIGHT)
{
if(menu)
menu->Show(GetScreenPos() + ui::Point(x, y));
}
else
{
isButtonDown = true;
}
}
void AvatarButton::OnMouseEnter(int x, int y)
{
isMouseInside = true;
}
void AvatarButton::OnMouseLeave(int x, int y)
{
isMouseInside = false;
}
void AvatarButton::DoAction()
{
if(actionCallback)
actionCallback->ActionCallback(this);
}
void AvatarButton::SetActionCallback(AvatarButtonAction * action)
{
actionCallback = action;
}
} /* namespace ui */
|