diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-01-23 22:53:57 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-01-23 22:53:57 (GMT) |
| commit | df72f2580f68a7d0055fcf20dcd65c0be90c52dd (patch) | |
| tree | ada3c6d3fdc2009f5236ec2a39d661c0bfaaf3e5 /src/interface | |
| parent | 2bd571e1598e6baffc717bcb086d89d01929604b (diff) | |
| download | powder-df72f2580f68a7d0055fcf20dcd65c0be90c52dd.zip powder-df72f2580f68a7d0055fcf20dcd65c0be90c52dd.tar.gz | |
Better element buttons, Save preview WIP
Diffstat (limited to 'src/interface')
| -rw-r--r-- | src/interface/Button.cpp | 35 | ||||
| -rw-r--r-- | src/interface/Button.h | 15 | ||||
| -rw-r--r-- | src/interface/Colour.h | 20 | ||||
| -rw-r--r-- | src/interface/Engine.cpp | 28 | ||||
| -rw-r--r-- | src/interface/Engine.h | 2 | ||||
| -rw-r--r-- | src/interface/Window.cpp | 28 |
6 files changed, 94 insertions, 34 deletions
diff --git a/src/interface/Button.cpp b/src/interface/Button.cpp index 2694de5..782d89b 100644 --- a/src/interface/Button.cpp +++ b/src/interface/Button.cpp @@ -26,11 +26,10 @@ Button::Button(Window* parent_state, std::string buttonText): textPosition(ui::Point(0, 0)), textVAlign(AlignMiddle), textHAlign(AlignCentre), - Enabled(true), - colr(0), - colg(0), - colb(0) + Enabled(true) { + activeText = background = Colour(0, 0, 0); + text = activeBackground = border = activeBorder = Colour(255, 255, 255); TextPosition(); } @@ -45,11 +44,10 @@ Button::Button(Point position, Point size, std::string buttonText): textPosition(ui::Point(0, 0)), textVAlign(AlignMiddle), textHAlign(AlignCentre), - Enabled(true), - colr(0), - colg(0), - colb(0) + Enabled(true) { + activeText = background = Colour(0, 0, 0); + text = activeBackground = border = activeBorder = Colour(255, 255, 255); TextPosition(); } @@ -64,11 +62,10 @@ Button::Button(std::string buttonText): textPosition(ui::Point(0, 0)), textVAlign(AlignMiddle), textHAlign(AlignCentre), - Enabled(true), - colr(0), - colg(0), - colb(0) + Enabled(true) { + activeText = background = Colour(0, 0, 0); + text = activeBackground = border = activeBorder = Colour(255, 255, 255); TextPosition(); } @@ -137,17 +134,15 @@ void Button::Draw(const Point& screenPos) { if(isButtonDown || (isTogglable && toggle)) { - g->fillrect(Position.X-1, Position.Y-1, Size.X+2, Size.Y+2, 255, 255, 255, 255); - g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, ButtonText, 0, 0, 0, 255); + g->fillrect(Position.X-1, Position.Y-1, Size.X+2, Size.Y+2, activeBackground.Red, activeBackground.Green, activeBackground.Blue, 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 { - if(isMouseInside) - g->fillrect(Position.X, Position.Y, Size.X, Size.Y, 20, 20, 20, 255); - else - 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); + g->fillrect(Position.X, Position.Y, Size.X, Size.Y, background.Red, background.Green, background.Blue, 255); + g->drawrect(Position.X, Position.Y, Size.X, Size.Y, border.Red, border.Green, border.Blue, 255); + g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, ButtonText, text.Red, text.Green, text.Blue, 255); } } else diff --git a/src/interface/Button.h b/src/interface/Button.h index bff54c9..fe4e9f9 100644 --- a/src/interface/Button.h +++ b/src/interface/Button.h @@ -11,6 +11,7 @@ #include <string> #include "Misc.h" #include "Component.h" +#include "Colour.h" namespace ui { @@ -56,12 +57,22 @@ public: ButtonAction * GetActionCallback() { return actionCallback; } void TextPosition(); void SetText(std::string buttonText); + HorizontalAlignment GetHAlignment() { return textHAlign; } VerticalAlignment GetVAlignment() { return textVAlign; } 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: - int colr, colg, colb; + Colour background, activeBackground; + Colour border, activeBorder; + Colour text, activeText; + bool isButtonDown, state, isMouseInside, isTogglable, toggle; ButtonAction * actionCallback; ui::Point textPosition; diff --git a/src/interface/Colour.h b/src/interface/Colour.h new file mode 100644 index 0000000..ad7d8a1 --- /dev/null +++ b/src/interface/Colour.h @@ -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 diff --git a/src/interface/Engine.cpp b/src/interface/Engine.cpp index 85a6293..7eec6b5 100644 --- a/src/interface/Engine.cpp +++ b/src/interface/Engine.cpp @@ -21,7 +21,8 @@ Engine::Engine(): FpsLimit(60.0f), windows(stack<Window*>()), lastBuffer(NULL), - prevBuffers(stack<pixel*>()) + prevBuffers(stack<pixel*>()), + windowTargetPosition(0, 0) { } @@ -53,6 +54,7 @@ void Engine::Exit() void Engine::ShowWindow(Window * window) { + windowOpenState = 0.0f; if(window->Position.X==-1) { 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; } + /*if(window->Position.Y > 0) + { + windowTargetPosition = window->Position; + window->Position = Point(windowTargetPosition.X, height_); + }*/ if(state_) { if(lastBuffer) @@ -68,7 +75,6 @@ void Engine::ShowWindow(Window * window) prevBuffers.push(lastBuffer); } lastBuffer = (pixel*)malloc((width_ * height_) * PIXELSIZE); - g->fillrect(0, 0, width_, height_, 0, 0, 0, 100); memcpy(lastBuffer, g->vid, (width_ * height_) * PIXELSIZE); windows.push(state_); @@ -123,6 +129,24 @@ void Engine::Tick(float dt) if(state_ != NULL) 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(state_ != NULL) diff --git a/src/interface/Engine.h b/src/interface/Engine.h index a648119..8f599b7 100644 --- a/src/interface/Engine.h +++ b/src/interface/Engine.h @@ -59,6 +59,8 @@ namespace ui std::stack<Window*> windows; //Window* statequeued_; Window* state_; + Point windowTargetPosition; + float windowOpenState; bool running_; diff --git a/src/interface/Window.cpp b/src/interface/Window.cpp index ca29be0..b399ab8 100644 --- a/src/interface/Window.cpp +++ b/src/interface/Window.cpp @@ -90,13 +90,14 @@ void Window::DoInitialized() void Window::DoDraw() { + OnDraw(); //draw for(int i = 0, sz = Components.size(); i < sz; ++i) if(Components[i]->Visible) { 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); } else @@ -112,7 +113,6 @@ void Window::DoDraw() } } - OnDraw(); } 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); } -void Window::DoMouseDown(int x, int y, unsigned button) +void Window::DoMouseDown(int x_, int y_, unsigned button) { //on mouse click + int x = x_ - Position.X; + int y = y_ - Position.Y; bool clickState = false; 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); } - 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) + int x = x_ - Position.X; + int y = y_ - Position.Y; for(int i = Components.size() - 1; i > -1 ; --i) { 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 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); } - 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 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); } - OnMouseWheel(x, y, d); + OnMouseWheel(x_, y_, d); } |
