summaryrefslogtreecommitdiff
path: root/src/interface
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-01-15 19:35:40 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-01-15 19:35:40 (GMT)
commit2511afec8bfaa0582928406b37e8b579fa267e4f (patch)
treeaae1674f5f076db275ec1c6b32271a69cff1489a /src/interface
parent2c9295007a287dc01ff63fcf7b3da141f7474e37 (diff)
downloadpowder-2511afec8bfaa0582928406b37e8b579fa267e4f.zip
powder-2511afec8bfaa0582928406b37e8b579fa267e4f.tar.gz
More stuff, better events and starting on interface
Diffstat (limited to 'src/interface')
-rw-r--r--src/interface/Button.cpp45
-rw-r--r--src/interface/Component.cpp3
-rw-r--r--src/interface/ControlFactory.cpp51
-rw-r--r--src/interface/Engine.cpp31
-rw-r--r--src/interface/Label.cpp4
-rw-r--r--src/interface/Sandbox.cpp12
6 files changed, 113 insertions, 33 deletions
diff --git a/src/interface/Button.cpp b/src/interface/Button.cpp
index e34f66c..6ea9854 100644
--- a/src/interface/Button.cpp
+++ b/src/interface/Button.cpp
@@ -9,6 +9,7 @@
#include "interface/Button.h"
#include "Graphics.h"
+#include "Global.h"
namespace ui {
@@ -16,7 +17,8 @@ Button::Button(State* parent_state, std::string buttonText):
Component(parent_state),
ButtonText(buttonText),
isMouseInside(false),
- isButtonDown(false)
+ isButtonDown(false),
+ isTogglable(false)
{
}
@@ -25,7 +27,8 @@ Button::Button(Point position, Point size, std::string buttonText):
Component(position, size),
ButtonText(buttonText),
isMouseInside(false),
- isButtonDown(false)
+ isButtonDown(false),
+ isTogglable(false)
{
}
@@ -34,17 +37,42 @@ Button::Button(std::string buttonText):
Component(),
ButtonText(buttonText),
isMouseInside(false),
- isButtonDown(false)
+ isButtonDown(false),
+ isTogglable(false)
{
}
+void Button::SetTogglable(bool togglable)
+{
+ toggle = false;
+ isTogglable = togglable;
+}
+
+bool Button::GetTogglable()
+{
+ return isTogglable;
+}
+
+inline bool Button::GetToggleState()
+{
+ return toggle;
+}
+
+inline void Button::SetToggleState(bool state)
+{
+ toggle = state;
+}
+
+
+
void Button::Draw(const Point& screenPos)
{
- Graphics * g = ui::Engine::Ref().g;
+ Graphics * g = Global::Ref().g;
+ Point Position = screenPos;
// = reinterpret_cast<Graphics*>(userdata);
//TODO: Cache text location, that way we don't have the text alignment code here
- if(isButtonDown)
+ if(isButtonDown || (isTogglable && toggle))
{
g->fillrect(Position.X, Position.Y, Size.X, Size.Y, 255, 255, 255, 255);
g->drawtext(Position.X+(Size.X-Graphics::textwidth((char *)ButtonText.c_str()))/2, Position.Y+(Size.Y-10)/2, ButtonText, 0, 0, 0, 255);
@@ -111,20 +139,21 @@ void Button::OnMouseUnclick(int x, int y, unsigned int button)
void Button::OnMouseClick(int x, int y, unsigned int button)
{
- std::cout << "Click!" << std::endl;
if(button != 1) return; //left click only!
+ if(isTogglable)
+ {
+ toggle = !toggle;
+ }
isButtonDown = true;
}
void Button::OnMouseEnter(int x, int y)
{
- std::cout << "Enter!"<<std::endl;
isMouseInside = true;
}
void Button::OnMouseLeave(int x, int y)
{
- std::cout << "Leave!"<<std::endl;
isMouseInside = false;
}
diff --git a/src/interface/Component.cpp b/src/interface/Component.cpp
index ac66f92..49ff7f8 100644
--- a/src/interface/Component.cpp
+++ b/src/interface/Component.cpp
@@ -76,7 +76,8 @@ void Component::SetParent(Panel* new_parent)
else
{
// remove from parent state (if in parent state) and place in new parent
- GetParentState()->RemoveComponent(this);
+ if(GetParentState())
+ GetParentState()->RemoveComponent(this);
new_parent->children.push_back(this);
}
this->_parent = new_parent;
diff --git a/src/interface/ControlFactory.cpp b/src/interface/ControlFactory.cpp
index 25822cd..372ed31 100644
--- a/src/interface/ControlFactory.cpp
+++ b/src/interface/ControlFactory.cpp
@@ -4,9 +4,56 @@
#include "interface/Panel.h"
#include "interface/Engine.h"
-ui::Panel * ControlFactory::MainMenu(GameSession * session, int x, int y, int width, int height)
+ui::Panel * ControlFactory::MainMenu(int x, int y, int width, int height)
{
+ int currentX = 1;
+ width -= 2;
+ ui::Button * tempButton;
ui::Panel * mainMenu = new ui::Panel(ui::Point(x, y), ui::Point(width, height));
- //mainMenu->Add(new ui::Button(0, 0, 20, 20, "Turd"));
+
+ tempButton = new ui::Button(ui::Point(currentX, 1), ui::Point(16, height-2), "\x81");
+ mainMenu->AddChild(tempButton); //Open
+ currentX += 18;
+
+ tempButton = new ui::Button(ui::Point(currentX, 1), ui::Point(16, height-2), "\x91");
+ mainMenu->AddChild(tempButton); //Reload
+ currentX += 18;
+
+ tempButton = new ui::Button(ui::Point(currentX, 1), ui::Point(width/4, height-2), "\x82 [Save]"); //Save
+ mainMenu->AddChild(tempButton);
+ currentX += tempButton->Size.X+2;
+
+ tempButton = new ui::Button(ui::Point(currentX, 1), ui::Point(16, height-2), "\xCB");
+ mainMenu->AddChild(tempButton); //Vote Up
+ currentX += 16;
+ tempButton = new ui::Button(ui::Point(currentX, 1), ui::Point(16, height-2), "\xCA");
+ mainMenu->AddChild(tempButton); //Vote Down
+ currentX += 18;
+
+ tempButton = new ui::Button(ui::Point(currentX, 1), ui::Point(width - currentX - (4 * 18) - (width / 5), height-2), "[Tags]"); //Tags
+ currentX += tempButton->Size.X+2;
+ mainMenu->AddChild(tempButton);
+
+ tempButton = new ui::Button(ui::Point(currentX, 1), ui::Point(16, height-2), "\xCF");
+ mainMenu->AddChild(tempButton); //Settings
+ currentX += 18;
+
+ tempButton = new ui::Button(ui::Point(currentX, 1), ui::Point(16, height-2), "\x92");
+ mainMenu->AddChild(tempButton); //Clear
+ currentX += 18;
+
+ tempButton = new ui::Button(ui::Point(currentX, 1), ui::Point(width - currentX - (2 * 18), height-2), "\x84 [Login]"); //Login
+ currentX += tempButton->Size.X+2;
+ mainMenu->AddChild(tempButton);
+
+ tempButton = new ui::Button(ui::Point(currentX, 1), ui::Point(16, height-2), "\xD8");
+ mainMenu->AddChild(tempButton); //Render options
+ currentX += 18;
+
+ tempButton = new ui::Button(ui::Point(currentX, 1), ui::Point(16, height-2), "\x90"); //Pause
+ tempButton->SetTogglable(true);
+ mainMenu->AddChild(tempButton);
+ currentX += 18;
+
return mainMenu;
}
diff --git a/src/interface/Engine.cpp b/src/interface/Engine.cpp
index 4468561..25f2038 100644
--- a/src/interface/Engine.cpp
+++ b/src/interface/Engine.cpp
@@ -1,3 +1,7 @@
+#include <iostream>
+
+#include "Config.h"
+#include "Global.h"
#include "interface/Platform.h"
#include "interface/Engine.h"
#include "interface/State.h"
@@ -5,15 +9,14 @@
using namespace ui;
-Engine::Engine()
-:
- g(NULL),
-state_(NULL),
-statequeued_(NULL),
-mousex_(0),
-mousey_(0),
-mousexp_(0),
-mouseyp_(0)
+Engine::Engine():
+ state_(NULL),
+ statequeued_(NULL),
+ mousex_(0),
+ mousey_(0),
+ mousexp_(0),
+ mouseyp_(0),
+ FpsLimit(60.0f)
{
}
@@ -23,10 +26,8 @@ Engine::~Engine()
delete state_;
}
-void Engine::Begin(int width, int height, SDL_Surface * surface)
+void Engine::Begin(int width, int height)
{
- g = new Graphics();
- g->AttachSDLSurface(surface);
//engine is now ready
running_ = true;
@@ -82,8 +83,8 @@ void Engine::Draw()
{
if(state_)
state_->DoDraw();
- g->Blit();
- g->Clear();
+ Global::Ref().g->Blit();
+ Global::Ref().g->Clear();
}
void Engine::onKeyPress(int key, bool shift, bool ctrl, bool alt)
@@ -115,7 +116,9 @@ void Engine::onMouseMove(int x, int y)
mousex_ = x;
mousey_ = y;
if(state_)
+ {
state_->DoMouseMove(x, y, mousex_ - mousexp_, mousey_ - mouseyp_);
+ }
mousexp_ = x;
mouseyp_ = y;
}
diff --git a/src/interface/Label.cpp b/src/interface/Label.cpp
index 3a5ea85..c77b6bf 100644
--- a/src/interface/Label.cpp
+++ b/src/interface/Label.cpp
@@ -1,4 +1,6 @@
#include <string>
+#include "Config.h"
+#include "Global.h"
#include "interface/Point.h"
#include "interface/Label.h"
@@ -33,6 +35,6 @@ Label::~Label()
void Label::Draw(const Point& screenPos)
{
- Graphics * g = ui::Engine::Ref().g;
+ Graphics * g = Global::Ref().g;
g->drawtext(Position.X+(Size.X-Graphics::textwidth((char *)LabelText.c_str()))/2, Position.Y+(Size.Y-10)/2, LabelText, 255, 255, 255, 255);
}
diff --git a/src/interface/Sandbox.cpp b/src/interface/Sandbox.cpp
index a9f1d9c..a9760e7 100644
--- a/src/interface/Sandbox.cpp
+++ b/src/interface/Sandbox.cpp
@@ -9,6 +9,7 @@
#include <queue>
#include "Config.h"
+#include "Global.h"
#include "interface/Point.h"
#include "interface/Sandbox.h"
@@ -48,7 +49,7 @@ void Sandbox::OnMouseClick(int localx, int localy, unsigned int button)
pointQueue.push(new Point(localx, localy));
}
-void Sandbox::OnMouseUnclick(int localx, int localy, unsigned int button)
+void Sandbox::OnMouseUp(int localx, int localy, unsigned int button)
{
if(isMouseDown)
{
@@ -59,7 +60,7 @@ void Sandbox::OnMouseUnclick(int localx, int localy, unsigned int button)
void Sandbox::Draw(const Point& screenPos)
{
- Graphics * g = ui::Engine::Ref().g;
+ Graphics * g = Global::Ref().g;
if(!ren)
ren = new Renderer(g, sim);
ren->render_parts();
@@ -76,16 +77,13 @@ void Sandbox::Tick(float delta)
pointQueue.pop();
if(sPoint)
{
- sim->create_line(fPoint->X, fPoint->Y, sPoint->X, sPoint->Y, 2, 2, activeElement, 0);
+ sim->create_line(fPoint->X, fPoint->Y, sPoint->X, sPoint->Y, 1, 1, activeElement, 0);
delete sPoint;
- sPoint = fPoint;
}
else
{
- sim->create_parts(fPoint->X, fPoint->Y, 2, 2, activeElement, 0);
+ sim->create_parts(fPoint->X, fPoint->Y, 1, 1, activeElement, 0);
}
- if(sPoint)
- delete sPoint;
sPoint = fPoint;
}
if(sPoint)