This repository has been archived on 2025-03-20. You can view files and clone it, but cannot push or open issues or pull requests.
The-Powder-Toy/src/gui/interface/AvatarButton.h
Tamás Bálint Misius 91a9973bfd
Refactor HTTP
Request ownership is no longer flaky. Requests are now owned by the code that makes requests, and Requests and the RequestManager co-own RequestHandles. RequestManager disowns a RequestHandle if it's done with it or if Request code reports that it's no longer needed.

All libcurl code has been moved to RequestManager. This is nice because once NOHTTP is removed, we can add any number of RequestManager implementations, for example one for Android.

Client outliving RequestManager is still a problem, this will have to be addressed later.
2023-01-27 09:26:40 +01:00

52 lines
1.2 KiB
C++

#pragma once
#include "common/String.h"
#include "Component.h"
#include "graphics/Graphics.h"
#include "gui/interface/Colour.h"
#include "client/http/ImageRequest.h"
#include <memory>
#include <functional>
namespace ui
{
class AvatarButton : public Component
{
std::unique_ptr<VideoBuffer> avatar;
ByteString name;
bool tried;
struct AvatarButtonAction
{
std::function<void ()> action;
};
AvatarButtonAction actionCallback;
std::unique_ptr<http::ImageRequest> imageRequest;
public:
AvatarButton(Point position, Point size, ByteString username);
virtual ~AvatarButton() = default;
void OnMouseClick(int x, int y, unsigned int button) override;
void OnMouseUnclick(int x, int y, unsigned int button) override;
void OnMouseEnter(int x, int y) override;
void OnMouseLeave(int x, int y) override;
void OnContextMenuAction(int item) override;
void Draw(const Point& screenPos) override;
void Tick(float dt) override;
void DoAction();
void SetUsername(ByteString username) { name = username; }
ByteString GetUsername() { return name; }
inline void SetActionCallback(AvatarButtonAction const &action) { actionCallback = action; };
protected:
bool isMouseInside, isButtonDown;
};
}