From 29c4308c420722088f47b5724d176a3c2e4ef290 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Tue, 10 Jun 2008 11:25:00 +0000 Subject: Changed DrawStep for dynamic surface drawing. svn-id: r32643 --- graphics/VectorRenderer.cpp | 15 ++++++---- graphics/VectorRenderer.h | 61 ++++++++++++-------------------------- gui/InterfaceManager.cpp | 71 +++++---------------------------------------- gui/InterfaceManager.h | 24 ++++++++------- 4 files changed, 48 insertions(+), 123 deletions(-) diff --git a/graphics/VectorRenderer.cpp b/graphics/VectorRenderer.cpp index 43046bafdf..109ae24f03 100644 --- a/graphics/VectorRenderer.cpp +++ b/graphics/VectorRenderer.cpp @@ -51,10 +51,10 @@ VectorRenderer *createRenderer(int mode) { /******************************************************************** * DRAWSTEP handling functions ********************************************************************/ -void VectorRenderer::drawStep(DrawStep *step) { +void VectorRenderer::drawStep(Common::Rect area, DrawStep *step) { if (step->flags & DrawStep::kStepCallbackOnly) { - (this->*(step->drawing_call))(step); + (this->*(step->drawing_call))(&area, step->extra_data); return; } @@ -83,7 +83,7 @@ void VectorRenderer::drawStep(DrawStep *step) { if (step->flags & DrawStep::kStepSettingsOnly) return; - (this->*(step->drawing_call))(step); + (this->*(step->drawing_call))(&area, step->extra_data); } /******************************************************************** @@ -248,7 +248,8 @@ drawLine(int x1, int y1, int x2, int y2) { template void VectorRendererSpec:: drawCircle(int x, int y, int r) { - if (x + r > Base::_activeSurface->w || y + r > Base::_activeSurface->h) + if (x + r > Base::_activeSurface->w || y + r > Base::_activeSurface->h || + x - r < 0 || y - r < 0 || x == 0 || y == 0 || r <= 0) return; if (Base::_fillMode != kFillDisabled && Base::_shadowOffset @@ -286,7 +287,8 @@ drawCircle(int x, int y, int r) { template void VectorRendererSpec:: drawSquare(int x, int y, int w, int h) { - if (x + w > Base::_activeSurface->w || y + h > Base::_activeSurface->h) + if (x + w > Base::_activeSurface->w || y + h > Base::_activeSurface->h || + w <= 0 || h <= 0 || x < 0 || y < 0) return; if (Base::_fillMode != kFillDisabled && Base::_shadowOffset @@ -322,7 +324,8 @@ drawSquare(int x, int y, int w, int h) { template void VectorRendererSpec:: drawRoundedSquare(int x, int y, int r, int w, int h) { - if (x + w > Base::_activeSurface->w || y + h > Base::_activeSurface->h) + if (x + w > Base::_activeSurface->w || y + h > Base::_activeSurface->h || + w <= 0 || h <= 0 || x < 0 || y < 0 || r <= 0 || r > 128) return; if (Base::_fillMode != kFillDisabled && Base::_shadowOffset diff --git a/graphics/VectorRenderer.h b/graphics/VectorRenderer.h index 2226907670..9958714df6 100644 --- a/graphics/VectorRenderer.h +++ b/graphics/VectorRenderer.h @@ -47,14 +47,12 @@ struct DrawStep { color1, /** Foreground color/gradient start */ color2; /** Background color/gradient end */ - uint16 x, y, w, h, r; /** Shape size */ - uint16 offset_x, offset_y; /** Offset when drawing directly to the whole screen */ uint8 shadow, stroke, factor; /** Misc options... */ int fill_mode; /** active fill mode */ - int extra; /** Generic parameter for extra options */ + int extra_data; /** Generic parameter for extra options (radius/orientation/bevel) */ - void (VectorRenderer::*drawing_call)(DrawStep*); /** Pointer to drawing function */ + void (VectorRenderer::*drawing_call)(Common::Rect*, int); /** Pointer to drawing function */ enum DrawStepFlags { kStepCallbackOnly = (1 << 0), @@ -89,8 +87,7 @@ VectorRenderer *createRenderer(int mode); class VectorRenderer { public: VectorRenderer() : _shadowOffset(0), _fillMode(kFillDisabled), - _activeSurface(NULL), _strokeWidth(1), _gradientFactor(1), - _stepOffsetX(0), _stepOffsetY(0) { + _activeSurface(NULL), _strokeWidth(1), _gradientFactor(1) { } @@ -322,41 +319,42 @@ public: /** * DrawStep callback functions for each drawing feature */ - void drawCallback_CIRCLE(DrawStep *step) { - drawCircle(_stepOffsetX + step->x, _stepOffsetY + step->y, step->r); + void drawCallback_CIRCLE(Common::Rect *area, int data) { + drawCircle(area->left + data, area->top + data, data); } - void drawCallback_SQUARE(DrawStep *step) { - drawSquare(_stepOffsetX + step->x, _stepOffsetY + step->y, step->w, step->h); + void drawCallback_SQUARE(Common::Rect *area, int data) { + drawSquare(area->left, area->top, area->width(), area->height()); } - void drawCallback_LINE(DrawStep *step) { - drawLine(_stepOffsetX + step->x, _stepOffsetY + step->y, step->x + step->w, step->y + step->h); + void drawCallback_LINE(Common::Rect *area, int data) { + drawLine(area->left, area->top, area->right, area->bottom); } - void drawCallback_ROUNDSQ(DrawStep *step) { - drawRoundedSquare(_stepOffsetX + step->x, _stepOffsetY + step->y, step->r, step->w, step->h); + void drawCallback_ROUNDSQ(Common::Rect *area, int data) { + drawRoundedSquare(area->left, area->top, data, area->width(), area->height()); } - void drawCallback_FILLSURFACE(DrawStep *step) { + void drawCallback_FILLSURFACE(Common::Rect *area, int data) { fillSurface(); } - void drawCallback_TRIANGLE(DrawStep *step) { - drawTriangle(_stepOffsetX + step->x, _stepOffsetY + step->y, step->w, step->h, (TriangleOrientation)step->extra); + void drawCallback_TRIANGLE(Common::Rect *area, int data) { + drawTriangle(area->top, area->left, area->width(), area->height(), (TriangleOrientation)data); } - void drawCallback_BEVELSQ(DrawStep *step) { - drawBeveledSquare(_stepOffsetX + step->x, _stepOffsetY + step->y, step->w, step->h, step->extra); + void drawCallback_BEVELSQ(Common::Rect *area, int data) { + drawBeveledSquare(area->left, area->top, area->width(), area->height(), data); } /** * Draws the specified draw step on the screen. * * @see DrawStep + * @param area Zone to paint on * @param step Pointer to a DrawStep struct. */ - virtual void drawStep(DrawStep *step); + virtual void drawStep(Common::Rect area, DrawStep *step); /** * Copies the current surface to the system overlay @@ -365,32 +363,9 @@ public: */ virtual void copyFrame(OSystem *sys) = 0; - /** - * Enables drawing offset for all the Draw Step operations, - * i.e. when we are drawing widgets directly on a whole screen - * instead of individual surfaces for caching/blitting. - * - * @param x Horizontal drawing offset. - * @param y Veritcal drawing offset. - */ - void setDrawOffset(int x, int y) { - _stepOffsetX = x; - _stepOffsetY = y; - } - - /** - * Disables the drawing offset for draw step operations. - */ - void disableDrawOffset() { - _stepOffsetX = _stepOffsetY = 0; - } - protected: Surface *_activeSurface; /** Pointer to the surface currently being drawn */ - int _stepOffsetX; /** Offset for all the drawing steps */ - int _stepOffsetY; /** Offset for all the drawing steps */ - FillMode _fillMode; /** Defines in which way (if any) are filled the drawn shapes */ int _shadowOffset; /** offset for drawn shadows */ diff --git a/gui/InterfaceManager.cpp b/gui/InterfaceManager.cpp index ffe19dbe9c..ef7fa31a46 100644 --- a/gui/InterfaceManager.cpp +++ b/gui/InterfaceManager.cpp @@ -72,6 +72,7 @@ void InterfaceManager::setGraphicsMode(Graphics_Mode mode) { return; } + freeRenderer(); _vectorRenderer = createRenderer(mode); _vectorRenderer->setSurface(_screen); } @@ -80,46 +81,6 @@ bool InterfaceManager::init() { return false; } -void InterfaceManager::drawWidgetBackground(int x, int y, uint16 hints, WidgetBackground background, WidgetStateInfo state, float scale){ - -} - -void InterfaceManager::drawButton(int x, int y, const Common::String &str, WidgetStateInfo state, uint16 hints, float scale) { - -} - -void InterfaceManager::drawSurface(int x, int y, const Graphics::Surface &surface, WidgetStateInfo state, int alpha, bool themeTrans, float scale) { - -} - -void InterfaceManager::drawSlider(int x, int y, int width, WidgetStateInfo state, float scale) { - -} - -void InterfaceManager::drawCheckbox(int x, int y, const Common::String &str, bool checked, WidgetStateInfo state, float scale) { - -} - -void InterfaceManager::drawTab(int x, int y, int tabHeight, int tabWidth, const Common::Array &tabs, int active, uint16 hints, int titleVPad, WidgetStateInfo state, float scale) { - -} - -void InterfaceManager::drawScrollbar(int x, int y, int sliderY, int sliderHeight, ScrollbarState, WidgetStateInfo state, float scale) { - -} - -void InterfaceManager::drawPopUpWidget(int x, int y, const Common::String &sel, int deltax, WidgetStateInfo state, TextAlign align, float scale) { - -} - -void InterfaceManager::drawCaret(int x, int y, bool erase, WidgetStateInfo state, float scale) { - -} - -void InterfaceManager::drawLineSeparator(int x, int y, WidgetStateInfo state, float scale) { - -} - int InterfaceManager::runGUI() { Common::EventManager *eventMan = _system->getEventManager(); _system->showOverlay(); @@ -142,42 +103,24 @@ int InterfaceManager::runGUI() { steps[1].color2.r = 173; steps[1].color2.g = 40; steps[1].color2.b = 8; - steps[1].x = 500; - steps[1].y = 95; - steps[1].r = 8; - steps[1].w = 120; - steps[1].h = 30; + steps[1].extra_data = 8; // radius steps[1].drawing_call = &VectorRenderer::drawCallback_ROUNDSQ; steps[1].flags = DrawStep::kStepSetGradient; - steps[2].x = 500; - steps[2].y = 135; - steps[2].r = 8; - steps[2].w = 120; - steps[2].h = 30; + steps[2].extra_data = 8; // radius steps[2].drawing_call = &VectorRenderer::drawCallback_ROUNDSQ; steps[2].flags = DrawStep::kStepCallbackOnly; - steps[3].x = 500; - steps[3].y = 175; - steps[3].r = 8; - steps[3].w = 120; - steps[3].h = 30; steps[3].drawing_call = &VectorRenderer::drawCallback_ROUNDSQ; steps[3].flags = DrawStep::kStepCallbackOnly; bool running = true; while (running) { // draw!! - for (int i = 0; i < 4; ++i) - _vectorRenderer->drawStep(&steps[i]); - - _vectorRenderer->setFillMode(VectorRenderer::kFillGradient); - _vectorRenderer->setFgColor(0, 0, 0); - _vectorRenderer->setBgColor(128, 64, 255); - _vectorRenderer->drawTriangle(32, 32, 64, 64, VectorRenderer::kTriangleUp); - - _vectorRenderer->drawBeveledSquare(128, 128, 256, 64, 4); + _vectorRenderer->drawStep(Common::Rect(), &steps[0]); + _vectorRenderer->drawStep(Common::Rect(32, 32, 256, 256), &steps[1]); + _vectorRenderer->drawStep(Common::Rect(128, 128, 512, 190), &steps[2]); +// _vectorRenderer->drawStep(Common::Rect(32, 32, 256, 256), &steps[3]); _vectorRenderer->copyFrame(_system); diff --git a/gui/InterfaceManager.h b/gui/InterfaceManager.h index ff8eee3de0..7820abd6c7 100644 --- a/gui/InterfaceManager.h +++ b/gui/InterfaceManager.h @@ -45,6 +45,7 @@ class InterfaceManager; class InterfaceManager : public Common::Singleton { friend class Common::Singleton; + typedef Common::String String; public: enum Graphics_Mode { @@ -139,16 +140,16 @@ public: int getCharWidth(byte c, FontStyle font) const { if (_initOk) return _font->getCharWidth(c); return 0; } /** Widget drawing */ - void drawWidgetBackground(int x, int y, uint16 hints, WidgetBackground background, WidgetStateInfo state, float scale = 1.0f); - void drawButton(int x, int y, const Common::String &str, WidgetStateInfo state, uint16 hints, float scale = 1.0f); - void drawSurface(int x, int y, const Graphics::Surface &surface, WidgetStateInfo state, int alpha, bool themeTrans, float scale = 1.0f); - void drawSlider(int x, int y, int width, WidgetStateInfo state, float scale = 1.0f); - void drawCheckbox(int x, int y, const Common::String &str, bool checked, WidgetStateInfo state, float scale = 1.0f); - void drawTab(int x, int y, int tabHeight, int tabWidth, const Common::Array &tabs, int active, uint16 hints, int titleVPad, WidgetStateInfo state, float scale = 1.0f); - void drawScrollbar(int x, int y, int sliderY, int sliderHeight, ScrollbarState, WidgetStateInfo state, float scale = 1.0f); - void drawPopUpWidget(int x, int y, const Common::String &sel, int deltax, WidgetStateInfo state, TextAlign align, float scale = 1.0f); - void drawCaret(int x, int y, bool erase, WidgetStateInfo state, float scale = 1.0f); - void drawLineSeparator(int x, int y, WidgetStateInfo state, float scale = 1.0f); + void drawWidgetBackground(const Common::Rect &r, uint16 hints, WidgetBackground background = kWidgetBackgroundPlain, WidgetStateInfo state = kStateEnabled) {} + void drawButton(const Common::Rect &r, const Common::String &str, WidgetStateInfo state = kStateEnabled, uint16 hints = 0) {} + void drawSurface(const Common::Rect &r, const Graphics::Surface &surface, WidgetStateInfo state = kStateEnabled, int alpha = 256, bool themeTrans = false) {} + void drawSlider(const Common::Rect &r, int width, WidgetStateInfo state = kStateEnabled) {} + void drawCheckbox(const Common::Rect &r, const Common::String &str, bool checked, WidgetStateInfo state = kStateEnabled) {} + void drawTab(const Common::Rect &r, int tabHeight, int tabWidth, const Common::Array &tabs, int active, uint16 hints, int titleVPad, WidgetStateInfo state = kStateEnabled) {} + void drawScrollbar(const Common::Rect &r, int sliderY, int sliderHeight, ScrollbarState, WidgetStateInfo state = kStateEnabled) {} + void drawPopUpWidget(const Common::Rect &r, const Common::String &sel, int deltax, WidgetStateInfo state = kStateEnabled, TextAlign align = kTextAlignLeft) {} + void drawCaret(const Common::Rect &r, bool erase, WidgetStateInfo state = kStateEnabled) {} + void drawLineSeparator(const Common::Rect &r, WidgetStateInfo state = kStateEnabled) {} protected: template void screenInit(); @@ -183,6 +184,9 @@ protected: }; struct WidgetDrawData { + Common::Rect _realSize; + bool _scaled; + Graphics::DrawStep **_steps; int _stepCount; -- cgit v1.2.3