1 #ifndef SAVEBUTTON_H_
2 #define SAVEBUTTON_H_
3 
4 #include "common/String.h"
5 
6 #include "Component.h"
7 #include "client/http/ThumbnailRequest.h"
8 #include "client/http/RequestMonitor.h"
9 
10 #include <memory>
11 #include <functional>
12 
13 class VideoBuffer;
14 class SaveFile;
15 class SaveInfo;
16 class ThumbnailRendererTask;
17 namespace ui
18 {
19 class SaveButton : public Component, public http::RequestMonitor<http::ThumbnailRequest>
20 {
21 	SaveFile * file;
22 	SaveInfo * save;
23 	std::unique_ptr<VideoBuffer> thumbnail;
24 	ui::Point thumbSize = ui::Point(0, 0);
25 	String name;
26 	String votesString;
27 	String votesBackground;
28 	String votesBackground2;
29 	int voteBarHeightUp;
30 	int voteBarHeightDown;
31 	bool wantsDraw;
32 	bool triedThumbnail;
33 	bool isMouseInsideAuthor;
34 	bool isMouseInsideHistory;
35 	bool showVotes;
36 	ThumbnailRendererTask *thumbnailRenderer;
37 
38 	struct SaveButtonAction
39 	{
40 		std::function<void ()> action, altAction, altAltAction, selected;
41 	};
42 	SaveButtonAction actionCallback;
43 
44 	SaveButton(Point position, Point size);
45 
46 public:
47 	SaveButton(Point position, Point size, SaveInfo * save);
48 	SaveButton(Point position, Point size, SaveFile * file);
49 	virtual ~SaveButton();
50 
51 	void OnMouseClick(int x, int y, unsigned int button) override;
52 	void OnMouseUnclick(int x, int y, unsigned int button) override;
53 
54 	void OnMouseEnter(int x, int y) override;
55 	void OnMouseLeave(int x, int y) override;
56 
57 	void OnMouseMovedInside(int x, int y, int dx, int dy) override;
58 
59 	void AddContextMenu(int menuType);
60 	void OnContextMenuAction(int item) override;
61 
62 	void Draw(const Point& screenPos) override;
63 	void Tick(float dt) override;
64 
65 	void OnResponse(std::unique_ptr<VideoBuffer> thumbnail) override;
66 
SetSelected(bool selected_)67 	void SetSelected(bool selected_) { selected = selected_; }
GetSelected()68 	bool GetSelected() { return selected; }
SetSelectable(bool selectable_)69 	void SetSelectable(bool selectable_) { selectable = selectable_; }
GetSelectable()70 	bool GetSelectable() { return selectable; }
SetShowVotes(bool showVotes_)71 	void SetShowVotes(bool showVotes_) { showVotes = showVotes_; }
72 
GetSave()73 	SaveInfo * GetSave() { return save; }
GetSaveFile()74 	SaveFile * GetSaveFile() { return file; }
GetState()75 	inline bool GetState() { return state; }
76 	void DoAction();
77 	void DoAltAction();
78 	void DoAltAction2();
79 	void DoSelection();
SetActionCallback(SaveButtonAction action)80 	inline void SetActionCallback(SaveButtonAction action) { actionCallback = action; }
81 protected:
82 	bool isButtonDown, state, isMouseInside, selected, selectable;
83 };
84 }
85 #endif /* BUTTON_H_ */
86 
87