2012-01-19 07:44:59 -06:00
|
|
|
#include <iostream>
|
2012-08-13 15:08:55 -05:00
|
|
|
#include <typeinfo>
|
2012-01-19 07:44:59 -06:00
|
|
|
|
|
|
|
#include "SaveButton.h"
|
2012-06-07 08:23:26 -05:00
|
|
|
#include "client/SaveInfo.h"
|
2012-07-06 10:06:26 -05:00
|
|
|
#include "graphics/Graphics.h"
|
2012-01-19 07:44:59 -06:00
|
|
|
#include "Engine.h"
|
2012-07-31 13:49:08 -05:00
|
|
|
#include "client/ThumbnailBroker.h"
|
2012-04-03 11:08:56 -05:00
|
|
|
#include "simulation/SaveRenderer.h"
|
2012-09-16 11:09:23 -05:00
|
|
|
#include "Format.h"
|
|
|
|
#include "ContextMenu.h"
|
|
|
|
#include "Keys.h"
|
2012-01-19 07:44:59 -06:00
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
2012-06-07 08:23:26 -05:00
|
|
|
SaveButton::SaveButton(Point position, Point size, SaveInfo * save):
|
2012-01-19 07:44:59 -06:00
|
|
|
Component(position, size),
|
2012-06-07 08:23:26 -05:00
|
|
|
file(NULL),
|
2012-01-19 07:44:59 -06:00
|
|
|
save(save),
|
|
|
|
thumbnail(NULL),
|
|
|
|
isMouseInside(false),
|
|
|
|
isButtonDown(false),
|
2012-01-29 11:12:35 -06:00
|
|
|
actionCallback(NULL),
|
2012-04-06 18:45:24 -05:00
|
|
|
selectable(false),
|
2012-08-13 15:08:55 -05:00
|
|
|
selected(false),
|
2012-08-14 06:03:33 -05:00
|
|
|
waitingForThumb(false),
|
2012-09-10 19:09:22 -05:00
|
|
|
isMouseInsideAuthor(false),
|
2012-09-16 11:09:23 -05:00
|
|
|
isMouseInsideHistory(false),
|
2012-09-10 19:09:22 -05:00
|
|
|
showVotes(false)
|
2012-01-19 07:44:59 -06:00
|
|
|
{
|
2012-09-16 11:09:23 -05:00
|
|
|
menu = new ContextMenu(this);
|
|
|
|
menu->AddItem(ContextMenuItem("Open", 0, true));
|
|
|
|
menu->AddItem(ContextMenuItem("Select", 1, true));
|
|
|
|
menu->AddItem(ContextMenuItem("View History", 2, true));
|
|
|
|
menu->AddItem(ContextMenuItem("More by this user", 3, true));
|
|
|
|
|
2012-04-22 11:13:43 -05:00
|
|
|
if(save)
|
|
|
|
{
|
|
|
|
name = save->name;
|
|
|
|
if(Graphics::textwidth((char *)name.c_str()) > Size.X)
|
|
|
|
{
|
|
|
|
int position = Graphics::textwidthx((char *)name.c_str(), Size.X - 22);
|
|
|
|
name = name.erase(position, name.length()-position);
|
|
|
|
name += "...";
|
|
|
|
}
|
2012-09-16 11:09:23 -05:00
|
|
|
|
|
|
|
std::string votes, icon;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
votes = format::NumberToString<int>(save->GetVotesUp()-save->GetVotesDown());
|
|
|
|
icon += 0xBB;
|
|
|
|
for (int j = 1; j < votes.length(); j++)
|
|
|
|
icon += 0xBC;
|
|
|
|
icon += 0xB9;
|
|
|
|
icon += 0xBA;
|
|
|
|
|
|
|
|
votesBackground = icon;
|
|
|
|
|
|
|
|
for (std::string::iterator iter = icon.begin(), end = icon.end(); iter != end; ++iter)
|
|
|
|
*iter -= 14;
|
|
|
|
|
|
|
|
votesBackground2 = icon;
|
|
|
|
|
|
|
|
for (std::string::iterator iter = votes.begin(), end = votes.end(); iter != end; ++iter)
|
|
|
|
if(*iter != '-')
|
|
|
|
*iter += 127;
|
|
|
|
|
|
|
|
votesString = votes;
|
2012-10-13 16:31:11 -05:00
|
|
|
|
|
|
|
int voteMax = std::max(save->GetVotesUp(),save->GetVotesDown());
|
2012-11-15 07:01:25 -06:00
|
|
|
if (voteMax)
|
2012-10-13 16:31:11 -05:00
|
|
|
{
|
2012-11-15 07:01:25 -06:00
|
|
|
if (voteMax < 34)
|
|
|
|
{
|
|
|
|
float ry = 33.0f/voteMax;
|
|
|
|
if (voteMax<8)
|
|
|
|
ry = ry/(8-voteMax);
|
|
|
|
voteBarHeightUp = (int)(save->GetVotesUp()*ry)-1;
|
|
|
|
voteBarHeightDown = (int)(save->GetVotesDown()*ry)-1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float ry = voteMax/33.0f;
|
|
|
|
voteBarHeightUp = (int)(save->GetVotesUp()/ry)-1;
|
|
|
|
voteBarHeightDown = (int)(save->GetVotesDown()/ry)-1;
|
|
|
|
}
|
2012-10-13 16:31:11 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-15 07:01:25 -06:00
|
|
|
voteBarHeightUp = 0;
|
|
|
|
voteBarHeightDown = 0;
|
2012-10-13 16:31:11 -05:00
|
|
|
}
|
2012-04-22 11:13:43 -05:00
|
|
|
}
|
2012-01-19 07:44:59 -06:00
|
|
|
}
|
|
|
|
|
2012-06-07 08:23:26 -05:00
|
|
|
SaveButton::SaveButton(Point position, Point size, SaveFile * file):
|
|
|
|
Component(position, size),
|
|
|
|
save(NULL),
|
|
|
|
file(file),
|
|
|
|
thumbnail(NULL),
|
|
|
|
isMouseInside(false),
|
|
|
|
isButtonDown(false),
|
|
|
|
actionCallback(NULL),
|
|
|
|
selectable(false),
|
2012-07-27 14:06:17 -05:00
|
|
|
selected(false),
|
2012-07-31 13:49:08 -05:00
|
|
|
wantsDraw(false),
|
2012-08-14 06:03:33 -05:00
|
|
|
waitingForThumb(false),
|
2012-09-10 19:09:22 -05:00
|
|
|
isMouseInsideAuthor(false),
|
2012-09-16 11:09:23 -05:00
|
|
|
isMouseInsideHistory(false),
|
2012-09-10 19:09:22 -05:00
|
|
|
showVotes(false)
|
2012-06-07 08:23:26 -05:00
|
|
|
{
|
|
|
|
if(file)
|
|
|
|
{
|
2012-07-28 19:33:28 -05:00
|
|
|
name = file->GetDisplayName();
|
2012-06-07 08:23:26 -05:00
|
|
|
if(Graphics::textwidth((char *)name.c_str()) > Size.X)
|
|
|
|
{
|
|
|
|
int position = Graphics::textwidthx((char *)name.c_str(), Size.X - 22);
|
|
|
|
name = name.erase(position, name.length()-position);
|
|
|
|
name += "...";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-19 07:44:59 -06:00
|
|
|
SaveButton::~SaveButton()
|
|
|
|
{
|
2012-07-31 13:49:08 -05:00
|
|
|
ThumbnailBroker::Ref().DetachThumbnailListener(this);
|
|
|
|
|
2012-01-19 07:44:59 -06:00
|
|
|
if(thumbnail)
|
|
|
|
delete thumbnail;
|
2012-01-20 17:52:19 -06:00
|
|
|
if(actionCallback)
|
|
|
|
delete actionCallback;
|
2012-01-20 18:17:42 -06:00
|
|
|
if(save)
|
|
|
|
delete save;
|
2012-06-07 08:23:26 -05:00
|
|
|
if(file)
|
|
|
|
delete file;
|
2012-01-19 07:44:59 -06:00
|
|
|
}
|
|
|
|
|
2012-07-31 13:49:08 -05:00
|
|
|
void SaveButton::OnThumbnailReady(Thumbnail * thumb)
|
|
|
|
{
|
|
|
|
if(thumb)
|
|
|
|
{
|
|
|
|
if(thumbnail)
|
|
|
|
delete thumbnail;
|
|
|
|
thumbnail = thumb;
|
|
|
|
waitingForThumb = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-19 07:44:59 -06:00
|
|
|
void SaveButton::Tick(float dt)
|
|
|
|
{
|
2012-07-31 13:49:08 -05:00
|
|
|
if(!thumbnail && !waitingForThumb)
|
|
|
|
{
|
|
|
|
if(save)
|
|
|
|
{
|
|
|
|
if(save->GetGameSave())
|
|
|
|
{
|
|
|
|
waitingForThumb = true;
|
|
|
|
ThumbnailBroker::Ref().RenderThumbnail(save->GetGameSave(), Size.X-3, Size.Y-25, this);
|
|
|
|
}
|
|
|
|
else if(save->GetID())
|
|
|
|
{
|
|
|
|
waitingForThumb = true;
|
2012-09-13 16:39:01 -05:00
|
|
|
ThumbnailBroker::Ref().RetrieveThumbnail(save->GetID(), save->GetVersion(), Size.X-3, Size.Y-25, this);
|
2012-07-31 13:49:08 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(file && file->GetGameSave())
|
|
|
|
{
|
|
|
|
waitingForThumb = true;
|
|
|
|
ThumbnailBroker::Ref().RenderThumbnail(file->GetGameSave(), Size.X-3, Size.Y-25, this);
|
|
|
|
}
|
|
|
|
}
|
2012-01-19 07:44:59 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void SaveButton::Draw(const Point& screenPos)
|
|
|
|
{
|
|
|
|
Graphics * g = ui::Engine::Ref().g;
|
|
|
|
float scaleFactor;
|
2012-01-29 11:12:35 -06:00
|
|
|
ui::Point thumbBoxSize(0, 0);
|
2012-01-19 07:44:59 -06:00
|
|
|
|
2012-07-27 14:06:17 -05:00
|
|
|
wantsDraw = true;
|
|
|
|
|
2012-04-06 18:45:24 -05:00
|
|
|
if(selected && selectable)
|
|
|
|
{
|
|
|
|
g->fillrect(screenPos.X, screenPos.Y, Size.X, Size.Y, 100, 170, 255, 100);
|
|
|
|
}
|
|
|
|
|
2012-01-19 07:44:59 -06:00
|
|
|
if(thumbnail)
|
|
|
|
{
|
2012-01-29 11:12:35 -06:00
|
|
|
thumbBoxSize = ui::Point(thumbnail->Size.X, thumbnail->Size.Y);
|
2012-06-07 08:23:26 -05:00
|
|
|
if(save && save->id)
|
2012-02-11 11:04:39 -06:00
|
|
|
g->draw_image(thumbnail->Data, screenPos.X-3+(Size.X-thumbBoxSize.X)/2, screenPos.Y+(Size.Y-21-thumbBoxSize.Y)/2, thumbnail->Size.X, thumbnail->Size.Y, 255);
|
2012-01-29 11:12:35 -06:00
|
|
|
else
|
2012-02-11 11:04:39 -06:00
|
|
|
g->draw_image(thumbnail->Data, screenPos.X+(Size.X-thumbBoxSize.X)/2, screenPos.Y+(Size.Y-21-thumbBoxSize.Y)/2, thumbnail->Size.X, thumbnail->Size.Y, 255);
|
2012-01-19 07:44:59 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
scaleFactor = (Size.Y-25)/((float)YRES);
|
2012-01-29 11:12:35 -06:00
|
|
|
thumbBoxSize = ui::Point(((float)XRES)*scaleFactor, ((float)YRES)*scaleFactor);
|
|
|
|
}
|
2012-04-19 09:22:18 -05:00
|
|
|
if(save)
|
2012-01-29 11:12:35 -06:00
|
|
|
{
|
2012-04-19 09:22:18 -05:00
|
|
|
if(save->id)
|
|
|
|
{
|
|
|
|
if(isMouseInside)
|
2012-09-14 18:39:01 -05:00
|
|
|
{
|
2012-04-19 09:22:18 -05:00
|
|
|
g->drawrect(screenPos.X-3+(Size.X-thumbBoxSize.X)/2, screenPos.Y+(Size.Y-21-thumbBoxSize.Y)/2, thumbBoxSize.X, thumbBoxSize.Y, 210, 230, 255, 255);
|
2012-09-14 18:39:01 -05:00
|
|
|
g->drawrect(screenPos.X-4+thumbBoxSize.X+(Size.X-thumbBoxSize.X)/2, screenPos.Y+(Size.Y-21-thumbBoxSize.Y)/2, 7, thumbBoxSize.Y, 210, 230, 255, 255);
|
|
|
|
}
|
2012-04-19 09:22:18 -05:00
|
|
|
else
|
2012-09-14 18:39:01 -05:00
|
|
|
{
|
2012-04-19 09:22:18 -05:00
|
|
|
g->drawrect(screenPos.X-3+(Size.X-thumbBoxSize.X)/2, screenPos.Y+(Size.Y-21-thumbBoxSize.Y)/2, thumbBoxSize.X, thumbBoxSize.Y, 180, 180, 180, 255);
|
2012-09-14 18:39:01 -05:00
|
|
|
g->drawrect(screenPos.X-4+thumbBoxSize.X+(Size.X-thumbBoxSize.X)/2, screenPos.Y+(Size.Y-21-thumbBoxSize.Y)/2, 7, thumbBoxSize.Y, 180, 180, 180, 255);
|
|
|
|
}
|
2012-04-19 09:22:18 -05:00
|
|
|
|
2012-10-13 16:31:11 -05:00
|
|
|
g->fillrect(screenPos.X-3+thumbBoxSize.X+(Size.X-thumbBoxSize.X)/2, screenPos.Y+1+(Size.Y-20-thumbBoxSize.Y)/2, 5, (thumbBoxSize.Y+1)/2-1, 0, 107, 10, 255);
|
|
|
|
g->fillrect(screenPos.X-3+thumbBoxSize.X+(Size.X-thumbBoxSize.X)/2, screenPos.Y+(Size.Y-20)/2, 5, thumbBoxSize.Y/2-1, 107, 10, 0, 255);
|
|
|
|
|
|
|
|
g->fillrect(screenPos.X-2+thumbBoxSize.X+(Size.X-thumbBoxSize.X)/2, screenPos.Y+(Size.Y-20)/2-voteBarHeightUp, 3, voteBarHeightUp, 57, 187, 57, 255); //green
|
|
|
|
g->fillrect(screenPos.X-2+thumbBoxSize.X+(Size.X-thumbBoxSize.X)/2, screenPos.Y+(Size.Y-20)/2, 3, voteBarHeightDown, 187, 57, 57, 255); //red
|
2012-04-19 09:22:18 -05:00
|
|
|
}
|
2012-02-11 11:11:07 -06:00
|
|
|
else
|
2012-04-19 09:22:18 -05:00
|
|
|
{
|
|
|
|
if(isMouseInside)
|
|
|
|
g->drawrect(screenPos.X+(Size.X-thumbBoxSize.X)/2, screenPos.Y+(Size.Y-21-thumbBoxSize.Y)/2, thumbBoxSize.X, thumbBoxSize.Y, 210, 230, 255, 255);
|
|
|
|
else
|
|
|
|
g->drawrect(screenPos.X+(Size.X-thumbBoxSize.X)/2, screenPos.Y+(Size.Y-21-thumbBoxSize.Y)/2, thumbBoxSize.X, thumbBoxSize.Y, 180, 180, 180, 255);
|
|
|
|
}
|
2012-01-29 11:12:35 -06:00
|
|
|
|
2012-08-14 06:03:33 -05:00
|
|
|
if(isMouseInside && !isMouseInsideAuthor)
|
2012-04-22 11:13:43 -05:00
|
|
|
g->drawtext(screenPos.X+(Size.X-Graphics::textwidth((char *)name.c_str()))/2, screenPos.Y+Size.Y - 21, name, 255, 255, 255, 255);
|
2012-02-11 11:11:07 -06:00
|
|
|
else
|
2012-04-22 11:13:43 -05:00
|
|
|
g->drawtext(screenPos.X+(Size.X-Graphics::textwidth((char *)name.c_str()))/2, screenPos.Y+Size.Y - 21, name, 180, 180, 180, 255);
|
2012-08-14 06:03:33 -05:00
|
|
|
|
|
|
|
if(isMouseInsideAuthor)
|
|
|
|
g->drawtext(screenPos.X+(Size.X-Graphics::textwidth((char *)save->userName.c_str()))/2, screenPos.Y+Size.Y - 10, save->userName, 200, 230, 255, 255);
|
|
|
|
else
|
2012-04-19 09:22:18 -05:00
|
|
|
g->drawtext(screenPos.X+(Size.X-Graphics::textwidth((char *)save->userName.c_str()))/2, screenPos.Y+Size.Y - 10, save->userName, 100, 130, 160, 255);
|
2012-09-14 18:39:01 -05:00
|
|
|
if (showVotes)// && !isMouseInside)
|
2012-09-10 19:09:22 -05:00
|
|
|
{
|
2012-09-16 11:09:23 -05:00
|
|
|
int x = screenPos.X-7+(Size.X-thumbBoxSize.X)/2+thumbBoxSize.X-Graphics::textwidth(votesBackground.c_str());
|
2012-09-10 19:09:22 -05:00
|
|
|
int y = screenPos.Y-23+(Size.Y-thumbBoxSize.Y)/2+thumbBoxSize.Y;
|
2012-09-16 11:09:23 -05:00
|
|
|
g->drawtext(x, y, votesBackground, 16, 72, 16, 255);
|
|
|
|
g->drawtext(x, y, votesBackground2, 192, 192, 192, 255);
|
|
|
|
g->drawtext(x+3, y, votesString, 255, 255, 255, 255);
|
2012-09-10 19:09:22 -05:00
|
|
|
}
|
2012-09-16 11:09:23 -05:00
|
|
|
if (isMouseInsideHistory && showVotes)
|
2012-09-10 19:09:22 -05:00
|
|
|
{
|
|
|
|
int x = screenPos.X;
|
|
|
|
int y = screenPos.Y-15+(Size.Y-thumbBoxSize.Y)/2+thumbBoxSize.Y;
|
|
|
|
g->fillrect(x+1, y+1, 7, 8, 255, 255, 255, 255);
|
2012-09-16 11:09:23 -05:00
|
|
|
if (isMouseInsideHistory) {
|
2012-09-10 19:09:22 -05:00
|
|
|
g->drawtext(x, y, "\xA6", 200, 100, 80, 255);
|
|
|
|
} else {
|
|
|
|
g->drawtext(x, y, "\xA6", 160, 70, 50, 255);
|
|
|
|
}
|
|
|
|
}
|
2012-09-29 15:24:20 -05:00
|
|
|
if (!save->GetPublished())
|
|
|
|
{
|
|
|
|
g->drawtext(screenPos.X, screenPos.Y-2, "\xCD", 255, 255, 255, 255);
|
|
|
|
g->drawtext(screenPos.X, screenPos.Y-2, "\xCE", 212, 151, 81, 255);
|
|
|
|
}
|
2012-01-19 07:44:59 -06:00
|
|
|
}
|
2012-06-07 08:23:26 -05:00
|
|
|
if(file)
|
|
|
|
{
|
|
|
|
if(isMouseInside)
|
|
|
|
g->drawrect(screenPos.X+(Size.X-thumbBoxSize.X)/2, screenPos.Y+(Size.Y-21-thumbBoxSize.Y)/2, thumbBoxSize.X, thumbBoxSize.Y, 210, 230, 255, 255);
|
|
|
|
else
|
|
|
|
g->drawrect(screenPos.X+(Size.X-thumbBoxSize.X)/2, screenPos.Y+(Size.Y-21-thumbBoxSize.Y)/2, thumbBoxSize.X, thumbBoxSize.Y, 180, 180, 180, 255);
|
|
|
|
|
|
|
|
if(isMouseInside)
|
|
|
|
{
|
|
|
|
g->drawtext(screenPos.X+(Size.X-Graphics::textwidth((char *)name.c_str()))/2, screenPos.Y+Size.Y - 21, name, 255, 255, 255, 255);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g->drawtext(screenPos.X+(Size.X-Graphics::textwidth((char *)name.c_str()))/2, screenPos.Y+Size.Y - 21, name, 180, 180, 180, 255);
|
|
|
|
}
|
|
|
|
}
|
2012-04-06 18:45:24 -05:00
|
|
|
|
|
|
|
if(isMouseInside && selectable)
|
|
|
|
{
|
|
|
|
g->clearrect(screenPos.X+(Size.X-20), screenPos.Y+6, 14, 14);
|
|
|
|
g->drawrect(screenPos.X+(Size.X-20), screenPos.Y+6, 14, 14, 255, 255, 255, 255);
|
|
|
|
if(selected)
|
|
|
|
g->fillrect(screenPos.X+(Size.X-18), screenPos.Y+8, 10, 10, 255, 255, 255, 255);
|
|
|
|
}
|
2012-01-19 07:44:59 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void SaveButton::OnMouseUnclick(int x, int y, unsigned int button)
|
|
|
|
{
|
|
|
|
if(button != 1)
|
|
|
|
{
|
|
|
|
return; //left click only!
|
|
|
|
}
|
|
|
|
|
2012-04-06 18:45:24 -05:00
|
|
|
if(x>=Size.X-20 && y>=6 && y<=20 && x<=Size.X-6 && selectable)
|
|
|
|
{
|
|
|
|
selected = !selected;
|
|
|
|
DoSelection();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-19 07:44:59 -06:00
|
|
|
if(isButtonDown)
|
|
|
|
{
|
2012-09-15 10:45:53 -05:00
|
|
|
isButtonDown = false;
|
2012-08-14 06:03:33 -05:00
|
|
|
if(isMouseInsideAuthor)
|
|
|
|
DoAuthorAction();
|
2012-09-16 11:09:23 -05:00
|
|
|
else if(isMouseInsideHistory)
|
2012-09-10 19:09:22 -05:00
|
|
|
DoHistoryAction();
|
2012-08-14 06:03:33 -05:00
|
|
|
else
|
|
|
|
DoAction();
|
2012-01-19 07:44:59 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-16 11:09:23 -05:00
|
|
|
void SaveButton::OnContextMenuAction(int item)
|
2012-01-19 07:44:59 -06:00
|
|
|
{
|
2012-09-16 11:09:23 -05:00
|
|
|
switch(item)
|
2012-04-06 18:45:24 -05:00
|
|
|
{
|
2012-09-16 11:09:23 -05:00
|
|
|
case 0:
|
|
|
|
DoAction();
|
|
|
|
break;
|
|
|
|
case 1:
|
2012-04-06 18:45:24 -05:00
|
|
|
selected = !selected;
|
|
|
|
DoSelection();
|
2012-09-16 11:09:23 -05:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
DoHistoryAction();
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
DoAuthorAction();
|
|
|
|
break;
|
2012-04-06 18:45:24 -05:00
|
|
|
}
|
2012-09-16 11:09:23 -05:00
|
|
|
}
|
2012-04-06 18:45:24 -05:00
|
|
|
|
2012-09-16 11:09:23 -05:00
|
|
|
void SaveButton::OnMouseClick(int x, int y, unsigned int button)
|
|
|
|
{
|
|
|
|
if(button == BUTTON_RIGHT)
|
|
|
|
{
|
|
|
|
if(menu)
|
|
|
|
menu->Show(GetScreenPos() + ui::Point(x, y));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
isButtonDown = true;
|
|
|
|
if(button !=1 && selectable)
|
|
|
|
{
|
|
|
|
selected = !selected;
|
|
|
|
DoSelection();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2012-01-19 07:44:59 -06:00
|
|
|
}
|
|
|
|
|
2012-08-14 06:03:33 -05:00
|
|
|
void SaveButton::OnMouseMovedInside(int x, int y, int dx, int dy)
|
|
|
|
{
|
|
|
|
if(y > Size.Y-11)
|
|
|
|
isMouseInsideAuthor = true;
|
|
|
|
else
|
|
|
|
isMouseInsideAuthor = false;
|
2012-09-10 19:09:22 -05:00
|
|
|
|
|
|
|
if(showVotes && y > Size.Y-29 && y < Size.Y - 18 && x > 0 && x < 9)
|
2012-09-16 11:09:23 -05:00
|
|
|
isMouseInsideHistory = true;
|
2012-09-10 19:09:22 -05:00
|
|
|
else
|
2012-09-16 11:09:23 -05:00
|
|
|
isMouseInsideHistory = false;
|
2012-08-14 06:03:33 -05:00
|
|
|
}
|
|
|
|
|
2012-01-19 07:44:59 -06:00
|
|
|
void SaveButton::OnMouseEnter(int x, int y)
|
|
|
|
{
|
|
|
|
isMouseInside = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SaveButton::OnMouseLeave(int x, int y)
|
|
|
|
{
|
|
|
|
isMouseInside = false;
|
2012-08-14 06:03:33 -05:00
|
|
|
isMouseInsideAuthor = false;
|
2012-09-16 11:09:23 -05:00
|
|
|
isMouseInsideHistory = false;
|
2012-09-10 19:09:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void SaveButton::DoHistoryAction()
|
|
|
|
{
|
|
|
|
if(actionCallback)
|
|
|
|
actionCallback->HistoryActionCallback(this);
|
2012-08-14 06:03:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void SaveButton::DoAuthorAction()
|
|
|
|
{
|
|
|
|
if(actionCallback)
|
|
|
|
actionCallback->AuthorActionCallback(this);
|
2012-01-19 07:44:59 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void SaveButton::DoAction()
|
|
|
|
{
|
|
|
|
if(actionCallback)
|
|
|
|
actionCallback->ActionCallback(this);
|
|
|
|
}
|
|
|
|
|
2012-04-06 18:45:24 -05:00
|
|
|
void SaveButton::DoSelection()
|
|
|
|
{
|
2012-09-16 11:09:23 -05:00
|
|
|
if(menu)
|
|
|
|
{
|
|
|
|
if(selected)
|
|
|
|
menu->SetItem(1, "Deselect");
|
|
|
|
else
|
|
|
|
menu->SetItem(1, "Select");
|
|
|
|
}
|
|
|
|
if(selectable && actionCallback)
|
2012-04-06 18:45:24 -05:00
|
|
|
actionCallback->SelectedCallback(this);
|
|
|
|
}
|
|
|
|
|
2012-01-19 07:44:59 -06:00
|
|
|
void SaveButton::SetActionCallback(SaveButtonAction * action)
|
|
|
|
{
|
|
|
|
actionCallback = action;
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace ui */
|