diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2013-03-10 18:08:34 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2013-03-10 18:08:34 (GMT) |
| commit | e6bca489c9aae88f1c7bbb44c4e2df71f481cbd3 (patch) | |
| tree | 6781e70afdc32c0322cce0062d523edfbdebae8a /src/interface/AvatarButton.cpp | |
| parent | 6090f0b0aaf302612f363cd3d85408e3b7d1150b (diff) | |
| download | powder-e6bca489c9aae88f1c7bbb44c4e2df71f481cbd3.zip powder-e6bca489c9aae88f1c7bbb44c4e2df71f481cbd3.tar.gz | |
AvatarButton/holder, rename ThumbnailBroker for more general purposes
Diffstat (limited to 'src/interface/AvatarButton.cpp')
| -rw-r--r-- | src/interface/AvatarButton.cpp | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/src/interface/AvatarButton.cpp b/src/interface/AvatarButton.cpp new file mode 100644 index 0000000..0343aed --- /dev/null +++ b/src/interface/AvatarButton.cpp @@ -0,0 +1,110 @@ +#include <iostream> +#include <typeinfo> + +#include "AvatarButton.h" +#include "Format.h" +#include "Engine.h" +#include "client/Client.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() +{ + if(avatar) + delete avatar; + if(actionCallback) + delete actionCallback; +} + +void AvatarButton::Tick(float dt) +{ + if(!avatar && !tried && name.size() > 0) + { + tried = true; + avatar = Client::Ref().GetAvatar(name); + if(avatar) { + if(avatar->Width != Size.X && avatar->Height != Size.Y) + { + avatar->Resize(Size.X, Size.Y, true); + } + } + } +} + +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 */ |
