summaryrefslogtreecommitdiff
path: root/src/gui/interface/AvatarButton.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2013-03-24 12:24:17 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2013-03-24 12:24:17 (GMT)
commit9b5b85f9b01cbda7ef9a7ec2a15b2a35630a5b9d (patch)
treeac7d040253b459ce102e476cb19ab59e3cfa90d7 /src/gui/interface/AvatarButton.cpp
parent6bf98ccdca39936a3c51367862eed7c49f8786ec (diff)
parentbdc69f31c0be94191015838886bdcc2bc67f1acb (diff)
downloadpowder-9b5b85f9b01cbda7ef9a7ec2a15b2a35630a5b9d.zip
powder-9b5b85f9b01cbda7ef9a7ec2a15b2a35630a5b9d.tar.gz
Merge branch 'reorganisation' of github.com:FacialTurd/The-Powder-Toy
Diffstat (limited to 'src/gui/interface/AvatarButton.cpp')
-rw-r--r--src/gui/interface/AvatarButton.cpp117
1 files changed, 117 insertions, 0 deletions
diff --git a/src/gui/interface/AvatarButton.cpp b/src/gui/interface/AvatarButton.cpp
new file mode 100644
index 0000000..e385c77
--- /dev/null
+++ b/src/gui/interface/AvatarButton.cpp
@@ -0,0 +1,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)
+{
+ 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 */