mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-11 19:04:05 +02:00
Better element buttons, Save preview WIP
This commit is contained in:
@@ -39,6 +39,97 @@ Client::~Client()
|
|||||||
http_done();
|
http_done();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Save * Client::GetSave(int saveID, int saveDate)
|
||||||
|
{
|
||||||
|
lastError = "";
|
||||||
|
std::stringstream urlStream;
|
||||||
|
urlStream << "http://" << SERVER << "/Browse/View.json?ID=" << saveID;
|
||||||
|
if(saveDate)
|
||||||
|
{
|
||||||
|
urlStream << "&Date=" << saveDate;
|
||||||
|
}
|
||||||
|
char * data;
|
||||||
|
int dataStatus, dataLength;
|
||||||
|
//Save(int _id, int _votesUp, int _votesDown, string _userName, string _name, string description_, string date_, bool published_):
|
||||||
|
data = http_simple_get((char *)urlStream.str().c_str(), &dataStatus, &dataLength);
|
||||||
|
if(dataStatus == 200 && data)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
std::istringstream dataStream(data);
|
||||||
|
json::Object objDocument;
|
||||||
|
json::Reader::Read(objDocument, dataStream);
|
||||||
|
|
||||||
|
json::Number tempID = objDocument["ID"];
|
||||||
|
json::Number tempScoreUp = objDocument["ScoreUp"];
|
||||||
|
json::Number tempScoreDown = objDocument["ScoreDown"];
|
||||||
|
json::String tempUsername = objDocument["Username"];
|
||||||
|
json::String tempName = objDocument["Name"];
|
||||||
|
json::String tempDescription = objDocument["Description"];
|
||||||
|
json::String tempDate = objDocument["Date"];
|
||||||
|
json::Boolean tempPublished = objDocument["Published"];
|
||||||
|
return new Save(
|
||||||
|
tempID.Value(),
|
||||||
|
tempScoreUp.Value(),
|
||||||
|
tempScoreDown.Value(),
|
||||||
|
tempUsername.Value(),
|
||||||
|
tempName.Value(),
|
||||||
|
tempDescription.Value(),
|
||||||
|
tempDate.Value(),
|
||||||
|
tempPublished.Value()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (json::Exception &e)
|
||||||
|
{
|
||||||
|
lastError = "Could not read response";
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lastError = http_ret_text(dataStatus);
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
Thumbnail * Client::GetPreview(int saveID, int saveDate)
|
||||||
|
{
|
||||||
|
std::stringstream urlStream;
|
||||||
|
urlStream << "http://" << SERVER << "/Get.api?Op=thumblarge&ID=" << saveID;
|
||||||
|
if(saveDate)
|
||||||
|
{
|
||||||
|
urlStream << "&Date=" << saveDate;
|
||||||
|
}
|
||||||
|
pixel * thumbData;
|
||||||
|
char * data;
|
||||||
|
int status, data_size, imgw, imgh;
|
||||||
|
data = http_simple_get((char *)urlStream.str().c_str(), &status, &data_size);
|
||||||
|
if (status == 200 && data)
|
||||||
|
{
|
||||||
|
thumbData = Graphics::ptif_unpack(data, data_size, &imgw, &imgh);
|
||||||
|
if(data)
|
||||||
|
{
|
||||||
|
free(data);
|
||||||
|
}
|
||||||
|
if(thumbData)
|
||||||
|
{
|
||||||
|
return new Thumbnail(saveID, saveDate, thumbData, ui::Point(imgw, imgh));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new Thumbnail(saveID, saveDate, (pixel *)malloc((128*128) * PIXELSIZE), ui::Point(128, 128));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(data)
|
||||||
|
{
|
||||||
|
free(data);
|
||||||
|
}
|
||||||
|
return new Thumbnail(saveID, saveDate, (pixel *)malloc((128*128) * PIXELSIZE), ui::Point(128, 128));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<Save*> * Client::SearchSaves(int start, int count, string query, string sort, int & resultCount)
|
std::vector<Save*> * Client::SearchSaves(int start, int count, string query, string sort, int & resultCount)
|
||||||
{
|
{
|
||||||
lastError = "";
|
lastError = "";
|
||||||
@@ -66,7 +157,7 @@ std::vector<Save*> * Client::SearchSaves(int start, int count, string query, str
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
std::istringstream dataStream(data); // missing comma!
|
std::istringstream dataStream(data);
|
||||||
json::Object objDocument;
|
json::Object objDocument;
|
||||||
json::Reader::Read(objDocument, dataStream);
|
json::Reader::Read(objDocument, dataStream);
|
||||||
|
|
||||||
|
@@ -25,7 +25,9 @@ public:
|
|||||||
~Client();
|
~Client();
|
||||||
void ClearThumbnailRequests();
|
void ClearThumbnailRequests();
|
||||||
std::vector<Save*> * SearchSaves(int start, int count, string query, string sort, int & resultCount);
|
std::vector<Save*> * SearchSaves(int start, int count, string query, string sort, int & resultCount);
|
||||||
|
Thumbnail * GetPreview(int saveID, int saveDate);
|
||||||
Thumbnail * GetThumbnail(int saveID, int saveDate);
|
Thumbnail * GetThumbnail(int saveID, int saveDate);
|
||||||
|
Save * GetSave(int saveID, int saveDate);
|
||||||
std::string GetLastError() { return lastError; }
|
std::string GetLastError() { return lastError; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
#include "GameView.h"
|
#include "GameView.h"
|
||||||
#include "interface/Window.h"
|
#include "interface/Window.h"
|
||||||
#include "interface/Button.h"
|
#include "interface/Button.h"
|
||||||
|
#include "interface/Colour.h"
|
||||||
|
|
||||||
GameView::GameView():
|
GameView::GameView():
|
||||||
ui::Window(ui::Point(0, 0), ui::Point(XRES+BARSIZE, YRES+MENUSIZE)),
|
ui::Window(ui::Point(0, 0), ui::Point(XRES+BARSIZE, YRES+MENUSIZE)),
|
||||||
@@ -246,6 +247,7 @@ void GameView::NotifyActiveToolChanged(GameModel * sender)
|
|||||||
void GameView::NotifyToolListChanged(GameModel * sender)
|
void GameView::NotifyToolListChanged(GameModel * sender)
|
||||||
{
|
{
|
||||||
int currentX = XRES+BARSIZE-56;
|
int currentX = XRES+BARSIZE-56;
|
||||||
|
int totalColour;
|
||||||
for(int i = 0; i < menuButtons.size(); i++)
|
for(int i = 0; i < menuButtons.size(); i++)
|
||||||
{
|
{
|
||||||
if(((MenuAction*)menuButtons[i]->GetActionCallback())->menu==sender->GetActiveMenu())
|
if(((MenuAction*)menuButtons[i]->GetActionCallback())->menu==sender->GetActiveMenu())
|
||||||
@@ -270,7 +272,22 @@ void GameView::NotifyToolListChanged(GameModel * sender)
|
|||||||
currentX -= 36;
|
currentX -= 36;
|
||||||
tempButton->SetTogglable(true);
|
tempButton->SetTogglable(true);
|
||||||
tempButton->SetActionCallback(new ToolAction(this, toolList[i]));
|
tempButton->SetActionCallback(new ToolAction(this, toolList[i]));
|
||||||
tempButton->SetBackgroundColour(toolList[i]->colRed, toolList[i]->colGreen, toolList[i]->colBlue);
|
|
||||||
|
totalColour = toolList[i]->colRed + 3*toolList[i]->colGreen + 2*toolList[i]->colBlue;
|
||||||
|
|
||||||
|
tempButton->SetBackgroundColour(ui::Colour(toolList[i]->colRed, toolList[i]->colGreen, toolList[i]->colBlue));
|
||||||
|
if (totalColour<544)
|
||||||
|
{
|
||||||
|
tempButton->SetTextColour(ui::Colour(255, 255, 255));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tempButton->SetTextColour(ui::Colour(0, 0, 0));
|
||||||
|
}
|
||||||
|
tempButton->SetBorderColour(ui::Colour(0, 0, 0));
|
||||||
|
tempButton->SetActiveBackgroundColour(ui::Colour(toolList[i]->colRed, toolList[i]->colGreen, toolList[i]->colBlue));
|
||||||
|
tempButton->SetActiveBorderColour(ui::Colour(0, 0, 255));
|
||||||
|
|
||||||
tempButton->SetAlignment(AlignCentre, AlignBottom);
|
tempButton->SetAlignment(AlignCentre, AlignBottom);
|
||||||
AddComponent(tempButton);
|
AddComponent(tempButton);
|
||||||
toolButtons.push_back(tempButton);
|
toolButtons.push_back(tempButton);
|
||||||
@@ -366,6 +383,7 @@ void GameView::OnKeyPress(int key, bool shift, bool ctrl, bool alt)
|
|||||||
{
|
{
|
||||||
case ' ':
|
case ' ':
|
||||||
c->SetPaused();
|
c->SetPaused();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -26,11 +26,10 @@ Button::Button(Window* parent_state, std::string buttonText):
|
|||||||
textPosition(ui::Point(0, 0)),
|
textPosition(ui::Point(0, 0)),
|
||||||
textVAlign(AlignMiddle),
|
textVAlign(AlignMiddle),
|
||||||
textHAlign(AlignCentre),
|
textHAlign(AlignCentre),
|
||||||
Enabled(true),
|
Enabled(true)
|
||||||
colr(0),
|
|
||||||
colg(0),
|
|
||||||
colb(0)
|
|
||||||
{
|
{
|
||||||
|
activeText = background = Colour(0, 0, 0);
|
||||||
|
text = activeBackground = border = activeBorder = Colour(255, 255, 255);
|
||||||
TextPosition();
|
TextPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,11 +44,10 @@ Button::Button(Point position, Point size, std::string buttonText):
|
|||||||
textPosition(ui::Point(0, 0)),
|
textPosition(ui::Point(0, 0)),
|
||||||
textVAlign(AlignMiddle),
|
textVAlign(AlignMiddle),
|
||||||
textHAlign(AlignCentre),
|
textHAlign(AlignCentre),
|
||||||
Enabled(true),
|
Enabled(true)
|
||||||
colr(0),
|
|
||||||
colg(0),
|
|
||||||
colb(0)
|
|
||||||
{
|
{
|
||||||
|
activeText = background = Colour(0, 0, 0);
|
||||||
|
text = activeBackground = border = activeBorder = Colour(255, 255, 255);
|
||||||
TextPosition();
|
TextPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,11 +62,10 @@ Button::Button(std::string buttonText):
|
|||||||
textPosition(ui::Point(0, 0)),
|
textPosition(ui::Point(0, 0)),
|
||||||
textVAlign(AlignMiddle),
|
textVAlign(AlignMiddle),
|
||||||
textHAlign(AlignCentre),
|
textHAlign(AlignCentre),
|
||||||
Enabled(true),
|
Enabled(true)
|
||||||
colr(0),
|
|
||||||
colg(0),
|
|
||||||
colb(0)
|
|
||||||
{
|
{
|
||||||
|
activeText = background = Colour(0, 0, 0);
|
||||||
|
text = activeBackground = border = activeBorder = Colour(255, 255, 255);
|
||||||
TextPosition();
|
TextPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,17 +134,15 @@ void Button::Draw(const Point& screenPos)
|
|||||||
{
|
{
|
||||||
if(isButtonDown || (isTogglable && toggle))
|
if(isButtonDown || (isTogglable && toggle))
|
||||||
{
|
{
|
||||||
g->fillrect(Position.X-1, Position.Y-1, Size.X+2, Size.Y+2, 255, 255, 255, 255);
|
g->fillrect(Position.X-1, Position.Y-1, Size.X+2, Size.Y+2, activeBackground.Red, activeBackground.Green, activeBackground.Blue, 255);
|
||||||
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, ButtonText, 0, 0, 0, 255);
|
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, activeBorder.Red, activeBorder.Green, activeBorder.Blue, 255);
|
||||||
|
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, ButtonText, activeText.Red, activeText.Green, activeText.Blue, 255);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(isMouseInside)
|
g->fillrect(Position.X, Position.Y, Size.X, Size.Y, background.Red, background.Green, background.Blue, 255);
|
||||||
g->fillrect(Position.X, Position.Y, Size.X, Size.Y, 20, 20, 20, 255);
|
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, border.Red, border.Green, border.Blue, 255);
|
||||||
else
|
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, ButtonText, text.Red, text.Green, text.Blue, 255);
|
||||||
g->fillrect(Position.X, Position.Y, Size.X, Size.Y, colr, colg, colb, 255);
|
|
||||||
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 255, 255, 255, 255);
|
|
||||||
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, ButtonText, 255, 255, 255, 255);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@@ -11,6 +11,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include "Misc.h"
|
#include "Misc.h"
|
||||||
#include "Component.h"
|
#include "Component.h"
|
||||||
|
#include "Colour.h"
|
||||||
|
|
||||||
namespace ui
|
namespace ui
|
||||||
{
|
{
|
||||||
@@ -56,12 +57,22 @@ public:
|
|||||||
ButtonAction * GetActionCallback() { return actionCallback; }
|
ButtonAction * GetActionCallback() { return actionCallback; }
|
||||||
void TextPosition();
|
void TextPosition();
|
||||||
void SetText(std::string buttonText);
|
void SetText(std::string buttonText);
|
||||||
|
|
||||||
HorizontalAlignment GetHAlignment() { return textHAlign; }
|
HorizontalAlignment GetHAlignment() { return textHAlign; }
|
||||||
VerticalAlignment GetVAlignment() { return textVAlign; }
|
VerticalAlignment GetVAlignment() { return textVAlign; }
|
||||||
void SetAlignment(HorizontalAlignment hAlign, VerticalAlignment vAlign) { textHAlign = hAlign; textVAlign = vAlign; TextPosition(); }
|
void SetAlignment(HorizontalAlignment hAlign, VerticalAlignment vAlign) { textHAlign = hAlign; textVAlign = vAlign; TextPosition(); }
|
||||||
void SetBackgroundColour(int colr, int colg, int colb) { this->colr = colr; this->colg = colg; this->colb = colb; }
|
|
||||||
|
void SetBackgroundColour(Colour background) { this->background = background; }
|
||||||
|
void SetActiveBackgroundColour(Colour background) { this->activeBackground = background; }
|
||||||
|
void SetBorderColour(Colour border) { this->border = border; }
|
||||||
|
void SetActiveBorderColour(Colour border) { this->activeBorder = border; }
|
||||||
|
void SetTextColour(Colour text) { this->text = text; }
|
||||||
|
void SetActiveTextColour(Colour text) { this->activeText = text; }
|
||||||
protected:
|
protected:
|
||||||
int colr, colg, colb;
|
Colour background, activeBackground;
|
||||||
|
Colour border, activeBorder;
|
||||||
|
Colour text, activeText;
|
||||||
|
|
||||||
bool isButtonDown, state, isMouseInside, isTogglable, toggle;
|
bool isButtonDown, state, isMouseInside, isTogglable, toggle;
|
||||||
ButtonAction * actionCallback;
|
ButtonAction * actionCallback;
|
||||||
ui::Point textPosition;
|
ui::Point textPosition;
|
||||||
|
20
src/interface/Colour.h
Normal file
20
src/interface/Colour.h
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#ifndef COLOUR_H
|
||||||
|
#define COLOUR_H
|
||||||
|
|
||||||
|
namespace ui
|
||||||
|
{
|
||||||
|
class Colour
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
unsigned char Red, Green, Blue;
|
||||||
|
Colour(unsigned char red, unsigned char green, unsigned char blue):
|
||||||
|
Red(red), Green(green), Blue(blue)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
Colour()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@@ -21,7 +21,8 @@ Engine::Engine():
|
|||||||
FpsLimit(60.0f),
|
FpsLimit(60.0f),
|
||||||
windows(stack<Window*>()),
|
windows(stack<Window*>()),
|
||||||
lastBuffer(NULL),
|
lastBuffer(NULL),
|
||||||
prevBuffers(stack<pixel*>())
|
prevBuffers(stack<pixel*>()),
|
||||||
|
windowTargetPosition(0, 0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,6 +54,7 @@ void Engine::Exit()
|
|||||||
|
|
||||||
void Engine::ShowWindow(Window * window)
|
void Engine::ShowWindow(Window * window)
|
||||||
{
|
{
|
||||||
|
windowOpenState = 0.0f;
|
||||||
if(window->Position.X==-1)
|
if(window->Position.X==-1)
|
||||||
{
|
{
|
||||||
window->Position.X = (width_-window->Size.X)/2;
|
window->Position.X = (width_-window->Size.X)/2;
|
||||||
@@ -61,6 +63,11 @@ void Engine::ShowWindow(Window * window)
|
|||||||
{
|
{
|
||||||
window->Position.Y = (height_-window->Size.Y)/2;
|
window->Position.Y = (height_-window->Size.Y)/2;
|
||||||
}
|
}
|
||||||
|
/*if(window->Position.Y > 0)
|
||||||
|
{
|
||||||
|
windowTargetPosition = window->Position;
|
||||||
|
window->Position = Point(windowTargetPosition.X, height_);
|
||||||
|
}*/
|
||||||
if(state_)
|
if(state_)
|
||||||
{
|
{
|
||||||
if(lastBuffer)
|
if(lastBuffer)
|
||||||
@@ -68,7 +75,6 @@ void Engine::ShowWindow(Window * window)
|
|||||||
prevBuffers.push(lastBuffer);
|
prevBuffers.push(lastBuffer);
|
||||||
}
|
}
|
||||||
lastBuffer = (pixel*)malloc((width_ * height_) * PIXELSIZE);
|
lastBuffer = (pixel*)malloc((width_ * height_) * PIXELSIZE);
|
||||||
g->fillrect(0, 0, width_, height_, 0, 0, 0, 100);
|
|
||||||
memcpy(lastBuffer, g->vid, (width_ * height_) * PIXELSIZE);
|
memcpy(lastBuffer, g->vid, (width_ * height_) * PIXELSIZE);
|
||||||
|
|
||||||
windows.push(state_);
|
windows.push(state_);
|
||||||
@@ -123,6 +129,24 @@ void Engine::Tick(float dt)
|
|||||||
if(state_ != NULL)
|
if(state_ != NULL)
|
||||||
state_->DoTick(dt);
|
state_->DoTick(dt);
|
||||||
|
|
||||||
|
|
||||||
|
if(windowOpenState<1.0f)
|
||||||
|
{
|
||||||
|
if(lastBuffer)
|
||||||
|
{
|
||||||
|
pixel * vid = g->vid;
|
||||||
|
g->vid = lastBuffer;
|
||||||
|
g->fillrect(0, 0, width_, height_, 0, 0, 0, 5);
|
||||||
|
g->vid = vid;
|
||||||
|
|
||||||
|
}
|
||||||
|
/*if(windowTargetPosition.Y < state_->Position.Y)
|
||||||
|
{
|
||||||
|
state_->Position.Y += windowTargetPosition.Y/20;
|
||||||
|
}*/
|
||||||
|
windowOpenState += 0.05f*dt;
|
||||||
|
}
|
||||||
|
|
||||||
/*if(statequeued_ != NULL)
|
/*if(statequeued_ != NULL)
|
||||||
{
|
{
|
||||||
if(state_ != NULL)
|
if(state_ != NULL)
|
||||||
|
@@ -59,6 +59,8 @@ namespace ui
|
|||||||
std::stack<Window*> windows;
|
std::stack<Window*> windows;
|
||||||
//Window* statequeued_;
|
//Window* statequeued_;
|
||||||
Window* state_;
|
Window* state_;
|
||||||
|
Point windowTargetPosition;
|
||||||
|
float windowOpenState;
|
||||||
|
|
||||||
bool running_;
|
bool running_;
|
||||||
|
|
||||||
|
@@ -90,13 +90,14 @@ void Window::DoInitialized()
|
|||||||
|
|
||||||
void Window::DoDraw()
|
void Window::DoDraw()
|
||||||
{
|
{
|
||||||
|
OnDraw();
|
||||||
//draw
|
//draw
|
||||||
for(int i = 0, sz = Components.size(); i < sz; ++i)
|
for(int i = 0, sz = Components.size(); i < sz; ++i)
|
||||||
if(Components[i]->Visible)
|
if(Components[i]->Visible)
|
||||||
{
|
{
|
||||||
if(AllowExclusiveDrawing)
|
if(AllowExclusiveDrawing)
|
||||||
{
|
{
|
||||||
Point scrpos(Components[i]->Position.X, Components[i]->Position.Y);
|
Point scrpos(Components[i]->Position.X + Position.X, Components[i]->Position.Y + Position.Y);
|
||||||
Components[i]->Draw(scrpos);
|
Components[i]->Draw(scrpos);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -112,7 +113,6 @@ void Window::DoDraw()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OnDraw();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::DoTick(float dt)
|
void Window::DoTick(float dt)
|
||||||
@@ -164,9 +164,11 @@ void Window::DoKeyRelease(int key, bool shift, bool ctrl, bool alt)
|
|||||||
OnKeyRelease(key, shift, ctrl, alt);
|
OnKeyRelease(key, shift, ctrl, alt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::DoMouseDown(int x, int y, unsigned button)
|
void Window::DoMouseDown(int x_, int y_, unsigned button)
|
||||||
{
|
{
|
||||||
//on mouse click
|
//on mouse click
|
||||||
|
int x = x_ - Position.X;
|
||||||
|
int y = y_ - Position.Y;
|
||||||
bool clickState = false;
|
bool clickState = false;
|
||||||
for(int i = Components.size() - 1; i > -1 ; --i)
|
for(int i = Components.size() - 1; i > -1 ; --i)
|
||||||
{
|
{
|
||||||
@@ -192,12 +194,14 @@ void Window::DoMouseDown(int x, int y, unsigned button)
|
|||||||
Components[i]->OnMouseDown(x, y, button);
|
Components[i]->OnMouseDown(x, y, button);
|
||||||
}
|
}
|
||||||
|
|
||||||
OnMouseDown(x, y, button);
|
OnMouseDown(x_, y_, button);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::DoMouseMove(int x, int y, int dx, int dy)
|
void Window::DoMouseMove(int x_, int y_, int dx, int dy)
|
||||||
{
|
{
|
||||||
//on mouse move (if true, and inside)
|
//on mouse move (if true, and inside)
|
||||||
|
int x = x_ - Position.X;
|
||||||
|
int y = y_ - Position.Y;
|
||||||
for(int i = Components.size() - 1; i > -1 ; --i)
|
for(int i = Components.size() - 1; i > -1 ; --i)
|
||||||
{
|
{
|
||||||
if(!Components[i]->Locked)
|
if(!Components[i]->Locked)
|
||||||
@@ -239,11 +243,13 @@ void Window::DoMouseMove(int x, int y, int dx, int dy)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OnMouseMove(x, y, dx, dy);
|
OnMouseMove(x_, y_, dx, dy);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::DoMouseUp(int x, int y, unsigned button)
|
void Window::DoMouseUp(int x_, int y_, unsigned button)
|
||||||
{
|
{
|
||||||
|
int x = x_ - Position.X;
|
||||||
|
int y = y_ - Position.Y;
|
||||||
//on mouse unclick
|
//on mouse unclick
|
||||||
for(int i = Components.size() - 1; i >= 0 ; --i)
|
for(int i = Components.size() - 1; i >= 0 ; --i)
|
||||||
{
|
{
|
||||||
@@ -264,11 +270,13 @@ void Window::DoMouseUp(int x, int y, unsigned button)
|
|||||||
Components[i]->OnMouseUp(x, y, button);
|
Components[i]->OnMouseUp(x, y, button);
|
||||||
}
|
}
|
||||||
|
|
||||||
OnMouseUp(x, y, button);
|
OnMouseUp(x_, y_, button);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::DoMouseWheel(int x, int y, int d)
|
void Window::DoMouseWheel(int x_, int y_, int d)
|
||||||
{
|
{
|
||||||
|
int x = x_ - Position.X;
|
||||||
|
int y = y_ - Position.Y;
|
||||||
//on mouse wheel focused
|
//on mouse wheel focused
|
||||||
for(int i = Components.size() - 1; i >= 0 ; --i)
|
for(int i = Components.size() - 1; i >= 0 ; --i)
|
||||||
{
|
{
|
||||||
@@ -287,6 +295,6 @@ void Window::DoMouseWheel(int x, int y, int d)
|
|||||||
Components[i]->OnMouseWheel(x - Components[i]->Position.X, y - Components[i]->Position.Y, d);
|
Components[i]->OnMouseWheel(x - Components[i]->Position.X, y - Components[i]->Position.Y, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
OnMouseWheel(x, y, d);
|
OnMouseWheel(x_, y_, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,7 +16,7 @@ PreviewController::PreviewController(int saveID) {
|
|||||||
previewModel->AddObserver(previewView);
|
previewModel->AddObserver(previewView);
|
||||||
previewView->AttachController(this);
|
previewView->AttachController(this);
|
||||||
|
|
||||||
previewModel->UpdateSave(saveID);
|
previewModel->UpdateSave(saveID, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
PreviewController::~PreviewController() {
|
PreviewController::~PreviewController() {
|
||||||
|
@@ -6,21 +6,54 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "PreviewModel.h"
|
#include "PreviewModel.h"
|
||||||
|
#include "client/Client.h"
|
||||||
|
|
||||||
PreviewModel::PreviewModel():
|
PreviewModel::PreviewModel():
|
||||||
save(NULL)
|
save(NULL),
|
||||||
|
savePreview(NULL)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated constructor stub
|
// TODO Auto-generated constructor stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewModel::UpdateSave(int saveID)
|
void PreviewModel::UpdateSave(int saveID, int saveDate)
|
||||||
{
|
{
|
||||||
|
save = Client::Ref().GetSave(saveID, saveDate);
|
||||||
|
notifySaveChanged();
|
||||||
|
savePreview = Client::Ref().GetPreview(saveID, saveDate);
|
||||||
|
notifyPreviewChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
Thumbnail * PreviewModel::GetPreview()
|
||||||
|
{
|
||||||
|
return savePreview;
|
||||||
|
}
|
||||||
|
|
||||||
|
Save * PreviewModel::GetSave()
|
||||||
|
{
|
||||||
|
return save;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PreviewModel::notifyPreviewChanged()
|
||||||
|
{
|
||||||
|
for(int i = 0; i < observers.size(); i++)
|
||||||
|
{
|
||||||
|
observers[i]->NotifyPreviewChanged(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PreviewModel::notifySaveChanged()
|
||||||
|
{
|
||||||
|
for(int i = 0; i < observers.size(); i++)
|
||||||
|
{
|
||||||
|
observers[i]->NotifySaveChanged(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewModel::AddObserver(PreviewView * observer) {
|
void PreviewModel::AddObserver(PreviewView * observer) {
|
||||||
observers.push_back(observer);
|
observers.push_back(observer);
|
||||||
|
observer->NotifyPreviewChanged(this);
|
||||||
|
observer->NotifySaveChanged(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
PreviewModel::~PreviewModel() {
|
PreviewModel::~PreviewModel() {
|
||||||
|
@@ -11,6 +11,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include "PreviewView.h"
|
#include "PreviewView.h"
|
||||||
#include "search/Save.h"
|
#include "search/Save.h"
|
||||||
|
#include "search/Thumbnail.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -18,10 +19,15 @@ class PreviewView;
|
|||||||
class PreviewModel {
|
class PreviewModel {
|
||||||
vector<PreviewView*> observers;
|
vector<PreviewView*> observers;
|
||||||
Save * save;
|
Save * save;
|
||||||
|
Thumbnail * savePreview;
|
||||||
|
void notifyPreviewChanged();
|
||||||
|
void notifySaveChanged();
|
||||||
public:
|
public:
|
||||||
PreviewModel();
|
PreviewModel();
|
||||||
|
Thumbnail * GetPreview();
|
||||||
|
Save * GetSave();
|
||||||
void AddObserver(PreviewView * observer);
|
void AddObserver(PreviewView * observer);
|
||||||
void UpdateSave(int saveID);
|
void UpdateSave(int saveID, int saveDate);
|
||||||
virtual ~PreviewModel();
|
virtual ~PreviewModel();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -8,22 +8,66 @@
|
|||||||
#include "PreviewView.h"
|
#include "PreviewView.h"
|
||||||
#include "interface/Point.h"
|
#include "interface/Point.h"
|
||||||
#include "interface/Window.h"
|
#include "interface/Window.h"
|
||||||
|
#include "search/Thumbnail.h"
|
||||||
|
|
||||||
PreviewView::PreviewView():
|
PreviewView::PreviewView():
|
||||||
ui::Window(ui::Point(-1, -1), ui::Point(200, 200))
|
ui::Window(ui::Point(-1, -1), ui::Point((XRES/2)+200, (YRES/2)+150)),
|
||||||
|
savePreview(NULL)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated constructor stub
|
// TODO Auto-generated constructor stub
|
||||||
|
openButton = new ui::Button(ui::Point(0, Size.Y-16), ui::Point(100, 16), "Open");
|
||||||
|
AddComponent(openButton);
|
||||||
|
|
||||||
|
saveNameLabel = new ui::Label(ui::Point(0, 0), ui::Point(50, 50), "");
|
||||||
|
AddComponent(saveNameLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewView::OnDraw()
|
void PreviewView::OnDraw()
|
||||||
{
|
{
|
||||||
Graphics * g = ui::Engine::Ref().g;
|
Graphics * g = ui::Engine::Ref().g;
|
||||||
|
|
||||||
|
//Window Background+Outline
|
||||||
g->clearrect(Position.X-2, Position.Y-2, Size.X+4, Size.Y+4);
|
g->clearrect(Position.X-2, Position.Y-2, Size.X+4, Size.Y+4);
|
||||||
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 255, 255, 255, 255);
|
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 255, 255, 255, 255);
|
||||||
|
|
||||||
|
//Save preview (top-left)
|
||||||
|
if(savePreview && savePreview->Data)
|
||||||
|
{
|
||||||
|
g->draw_image(savePreview->Data, (Position.X+1)+(((XRES/2)-savePreview->Size.X)/2), (Position.Y+1)+(((YRES/2)-savePreview->Size.Y)/2), savePreview->Size.X, savePreview->Size.Y, 255);
|
||||||
|
}
|
||||||
|
g->drawrect(Position.X, Position.Y, XRES/2, YRES/2, 255, 255, 255, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PreviewView::NotifySaveChanged(PreviewModel * sender)
|
||||||
|
{
|
||||||
|
Save * save = sender->GetSave();
|
||||||
|
if(save)
|
||||||
|
{
|
||||||
|
saveNameLabel->SetText(save->name);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
saveNameLabel->SetText("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PreviewView::NotifyPreviewChanged(PreviewModel * sender)
|
||||||
|
{
|
||||||
|
savePreview = sender->GetPreview();
|
||||||
|
if(savePreview && savePreview->Data && !(savePreview->Size.X == XRES/2 && savePreview->Size.Y == YRES/2))
|
||||||
|
{
|
||||||
|
int newSizeX, newSizeY;
|
||||||
|
float factorX = ((float)XRES/2)/((float)savePreview->Size.X);
|
||||||
|
float factorY = ((float)YRES/2)/((float)savePreview->Size.Y);
|
||||||
|
float scaleFactor = factorY < factorX ? factorY : factorX;
|
||||||
|
savePreview->Data = Graphics::resample_img(savePreview->Data, savePreview->Size.X, savePreview->Size.Y, savePreview->Size.X*scaleFactor, savePreview->Size.Y*scaleFactor);
|
||||||
|
savePreview->Size.X *= scaleFactor;
|
||||||
|
savePreview->Size.Y *= scaleFactor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PreviewView::~PreviewView() {
|
PreviewView::~PreviewView() {
|
||||||
// TODO Auto-generated destructor stub
|
delete openButton;
|
||||||
|
delete saveNameLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -9,13 +9,23 @@
|
|||||||
#define PREVIEWVIEW_H_
|
#define PREVIEWVIEW_H_
|
||||||
#include "interface/Window.h"
|
#include "interface/Window.h"
|
||||||
#include "preview/PreviewController.h"
|
#include "preview/PreviewController.h"
|
||||||
|
#include "preview/PreviewModel.h"
|
||||||
|
#include "interface/Button.h"
|
||||||
|
#include "search/Thumbnail.h"
|
||||||
|
#include "interface/Label.h"
|
||||||
|
|
||||||
|
class PreviewModel;
|
||||||
class PreviewController;
|
class PreviewController;
|
||||||
class PreviewView: public ui::Window {
|
class PreviewView: public ui::Window {
|
||||||
PreviewController * c;
|
PreviewController * c;
|
||||||
|
Thumbnail * savePreview;
|
||||||
|
ui::Button * openButton;
|
||||||
|
ui::Label * saveNameLabel;
|
||||||
public:
|
public:
|
||||||
void AttachController(PreviewController * controller) { c = controller;}
|
void AttachController(PreviewController * controller) { c = controller;}
|
||||||
PreviewView();
|
PreviewView();
|
||||||
|
void NotifyPreviewChanged(PreviewModel * sender);
|
||||||
|
void NotifySaveChanged(PreviewModel * sender);
|
||||||
virtual void OnDraw();
|
virtual void OnDraw();
|
||||||
virtual ~PreviewView();
|
virtual ~PreviewView();
|
||||||
};
|
};
|
||||||
|
@@ -10,19 +10,40 @@ class Save
|
|||||||
private:
|
private:
|
||||||
int id;
|
int id;
|
||||||
int votesUp, votesDown;
|
int votesUp, votesDown;
|
||||||
|
unsigned char * data;
|
||||||
public:
|
public:
|
||||||
Save(int _id, int _votesUp, int _votesDown, string _userName, string _name):
|
Save(int _id, int _votesUp, int _votesDown, string _userName, string _name):
|
||||||
id(_id),
|
id(_id),
|
||||||
votesUp(_votesUp),
|
votesUp(_votesUp),
|
||||||
votesDown(_votesDown),
|
votesDown(_votesDown),
|
||||||
userName(_userName),
|
userName(_userName),
|
||||||
name(_name)
|
name(_name),
|
||||||
|
Description("No description provided"),
|
||||||
|
Date("0/0/0"),
|
||||||
|
Published(true)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Save(int _id, int _votesUp, int _votesDown, string _userName, string _name, string description_, string date_, bool published_):
|
||||||
|
id(_id),
|
||||||
|
votesUp(_votesUp),
|
||||||
|
votesDown(_votesDown),
|
||||||
|
userName(_userName),
|
||||||
|
name(_name),
|
||||||
|
Description(description_),
|
||||||
|
Date(date_),
|
||||||
|
Published(published_)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
string userName;
|
string userName;
|
||||||
string name;
|
string name;
|
||||||
|
|
||||||
|
string Description;
|
||||||
|
string Date;
|
||||||
|
|
||||||
|
bool Published;
|
||||||
|
|
||||||
void SetName(string name){ this->name = name; }
|
void SetName(string name){ this->name = name; }
|
||||||
string GetName(){ return name; }
|
string GetName(){ return name; }
|
||||||
|
|
||||||
@@ -37,6 +58,8 @@ public:
|
|||||||
|
|
||||||
void SetVotesDown(int votesDown){ this->votesDown = votesDown; }
|
void SetVotesDown(int votesDown){ this->votesDown = votesDown; }
|
||||||
int GetVotesDown(){ return votesDown; }
|
int GetVotesDown(){ return votesDown; }
|
||||||
|
|
||||||
|
unsigned char * GetData() { return data; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SAVE_H
|
#endif // SAVE_H
|
||||||
|
Reference in New Issue
Block a user