Skip to content
Permalink
Browse files

GRAPHICS: Vector renderer clipping rect related cleanups

Selecting whether a clipping variant of a draw call needs to be used is
no longer the responsibility to the caller. The clipping rect is now
part of the state of the renderer.

Also fix some of the draw calls to better apply the clipping rect.
  • Loading branch information...
bgK committed Aug 27, 2019
1 parent b87ebdc commit 1d764bd787a20ab4b8d6edd79d3bc7db459e3eb0
Showing with 148 additions and 581 deletions.
  1. +3 −29 graphics/VectorRenderer.cpp
  2. +38 −49 graphics/VectorRenderer.h
  3. +70 −456 graphics/VectorRendererSpec.cpp
  4. +10 −23 graphics/VectorRendererSpec.h
  5. +18 −20 gui/ThemeEngine.cpp
  6. +6 −2 gui/ThemeEngine.h
  7. +1 −0 gui/dialog.cpp
  8. +2 −2 gui/widget.cpp
@@ -32,34 +32,7 @@ namespace Graphics {
/********************************************************************
* DRAWSTEP handling functions
********************************************************************/
void VectorRenderer::drawStep(const Common::Rect &area, const DrawStep &step, uint32 extra) {

if (step.bgColor.set)
setBgColor(step.bgColor.r, step.bgColor.g, step.bgColor.b);

if (step.fgColor.set)
setFgColor(step.fgColor.r, step.fgColor.g, step.fgColor.b);

if (step.bevelColor.set)
setBevelColor(step.bevelColor.r, step.bevelColor.g, step.bevelColor.b);

if (step.gradColor1.set && step.gradColor2.set)
setGradientColors(step.gradColor1.r, step.gradColor1.g, step.gradColor1.b,
step.gradColor2.r, step.gradColor2.g, step.gradColor2.b);

setShadowOffset(_disableShadows ? 0 : step.shadow);
setBevel(step.bevel);
setGradientFactor(step.factor);
setStrokeWidth(step.stroke);
setFillMode((FillMode)step.fillMode);

_dynamicData = extra;

Common::Rect noClip = Common::Rect(0, 0, 0, 0);
(this->*(step.drawingCall))(area, step, noClip);
}

void VectorRenderer::drawStepClip(const Common::Rect &area, const Common::Rect &clip, const DrawStep &step, uint32 extra) {
void VectorRenderer::drawStep(const Common::Rect &area, const Common::Rect &clip, const DrawStep &step, uint32 extra) {

if (step.bgColor.set)
setBgColor(step.bgColor.r, step.bgColor.g, step.bgColor.b);
@@ -79,10 +52,11 @@ void VectorRenderer::drawStepClip(const Common::Rect &area, const Common::Rect &
setGradientFactor(step.factor);
setStrokeWidth(step.stroke);
setFillMode((FillMode)step.fillMode);
setClippingRect(clip);

_dynamicData = extra;

(this->*(step.drawingCall))(area, step, clip);
(this->*(step.drawingCall))(area, step);
}

int VectorRenderer::stepGetRadius(const DrawStep &step, const Common::Rect &area) {
@@ -39,7 +39,7 @@ class VectorRenderer;
struct DrawStep;


typedef void (VectorRenderer::*DrawingFunctionCallback)(const Common::Rect &, const Graphics::DrawStep &, const Common::Rect &);
typedef void (VectorRenderer::*DrawingFunctionCallback)(const Common::Rect &, const Graphics::DrawStep &);


struct DrawStep {
@@ -165,7 +165,6 @@ class VectorRenderer {
* @param y2 Vertical (Y) coordinate for the line end
*/
virtual void drawLine(int x1, int y1, int x2, int y2) = 0;
virtual void drawLineClip(int x1, int y1, int x2, int y2, Common::Rect clipping) = 0;

/**
* Draws a circle centered at (x,y) with radius r.
@@ -175,7 +174,6 @@ class VectorRenderer {
* @param r Radius of the circle.
*/
virtual void drawCircle(int x, int y, int r) = 0;
virtual void drawCircleClip(int x, int y, int r, Common::Rect clipping) = 0;

/**
* Draws a square starting at (x,y) with the given width and height.
@@ -186,7 +184,6 @@ class VectorRenderer {
* @param h Height of the square
*/
virtual void drawSquare(int x, int y, int w, int h) = 0;
virtual void drawSquareClip(int x, int y, int w, int h, Common::Rect clipping) = 0;

/**
* Draws a rounded square starting at (x,y) with the given width and height.
@@ -199,7 +196,6 @@ class VectorRenderer {
* @param r Radius of the corners.
*/
virtual void drawRoundedSquare(int x, int y, int r, int w, int h) = 0;
virtual void drawRoundedSquareClip(int x, int y, int r, int w, int h, Common::Rect clipping) = 0;

/**
* Draws a triangle starting at (x,y) with the given base and height.
@@ -213,7 +209,6 @@ class VectorRenderer {
* @param orient Orientation of the triangle.
*/
virtual void drawTriangle(int x, int y, int base, int height, TriangleOrientation orient) = 0;
virtual void drawTriangleClip(int x, int y, int base, int height, TriangleOrientation orient, Common::Rect clipping) = 0;

/**
* Draws a beveled square like the ones in the Classic GUI themes.
@@ -226,8 +221,7 @@ class VectorRenderer {
* @param h Height of the square
* @param bevel Amount of bevel. Must be positive.
*/
virtual void drawBeveledSquare(int x, int y, int w, int h, int bevel) = 0;
virtual void drawBeveledSquareClip(int x, int y, int w, int h, int bevel, Common::Rect clipping) = 0;
virtual void drawBeveledSquare(int x, int y, int w, int h) = 0;

/**
* Draws a tab-like shape, specially thought for the Tab widget.
@@ -241,8 +235,6 @@ class VectorRenderer {
* @param r Radius of the corners of the tab (0 for squared tabs).
*/
virtual void drawTab(int x, int y, int r, int w, int h) = 0;
virtual void drawTabClip(int x, int y, int r, int w, int h, Common::Rect clipping) = 0;


/**
* Simple helper function to draw a cross.
@@ -252,11 +244,6 @@ class VectorRenderer {
drawLine(x + w, y, x, y + h);
}

virtual void drawCrossClip(int x, int y, int w, int h, Common::Rect clipping) {
drawLineClip(x, y, x + w, y + w, clipping);
drawLineClip(x + w, y, x, y + h, clipping);
}

/**
* Set the active foreground painting color for the renderer.
* All the foreground drawing from then on will be done with that color, unless
@@ -320,7 +307,6 @@ class VectorRenderer {
* Defaults to using the active Foreground color for filling.
*/
virtual void fillSurface() = 0;
virtual void fillSurfaceClip(Common::Rect clipping) = 0;

/**
* Clears the active surface.
@@ -383,6 +369,16 @@ class VectorRenderer {
_gradientFactor = factor;
}

/**
* Sets the clipping rectangle to be used by draw calls.
*
* Draw calls are restricted to pixels that are inside of the clipping
* rectangle. Pixels outside the clipping rectangle are not modified.
* To disable the clipping rectangle, call this method with a rectangle
* the same size as the target surface.
*/
virtual void setClippingRect(const Common::Rect &clippingArea) = 0;

/**
* Translates the position data inside a DrawStep into actual
* screen drawing positions.
@@ -398,74 +394,74 @@ class VectorRenderer {
/**
* DrawStep callback functions for each drawing feature
*/
void drawCallback_CIRCLE(const Common::Rect &area, const DrawStep &step, const Common::Rect &clip) {
void drawCallback_CIRCLE(const Common::Rect &area, const DrawStep &step) {
uint16 x, y, w, h, radius;

radius = stepGetRadius(step, area);
stepGetPositions(step, area, x, y, w, h);

drawCircleClip(x + radius, y + radius, radius, clip);
drawCircle(x + radius, y + radius, radius);
}

void drawCallback_SQUARE(const Common::Rect &area, const DrawStep &step, const Common::Rect &clip) {
void drawCallback_SQUARE(const Common::Rect &area, const DrawStep &step) {
uint16 x, y, w, h;
stepGetPositions(step, area, x, y, w, h);
drawSquareClip(x, y, w, h, clip);
drawSquare(x, y, w, h);
}

void drawCallback_LINE(const Common::Rect &area, const DrawStep &step, const Common::Rect &clip) {
void drawCallback_LINE(const Common::Rect &area, const DrawStep &step) {
uint16 x, y, w, h;
stepGetPositions(step, area, x, y, w, h);
drawLineClip(x, y, x + w, y + w, clip);
drawLine(x, y, x + w, y + w);
}

void drawCallback_ROUNDSQ(const Common::Rect &area, const DrawStep &step, const Common::Rect &clip) {
void drawCallback_ROUNDSQ(const Common::Rect &area, const DrawStep &step) {
uint16 x, y, w, h;
stepGetPositions(step, area, x, y, w, h);
drawRoundedSquareClip(x, y, stepGetRadius(step, area), w, h, clip);
drawRoundedSquare(x, y, stepGetRadius(step, area), w, h);
}

void drawCallback_FILLSURFACE(const Common::Rect &area, const DrawStep &step, const Common::Rect &clip) {
fillSurfaceClip(clip);
void drawCallback_FILLSURFACE(const Common::Rect &area, const DrawStep &step) {
fillSurface();
}

void drawCallback_TRIANGLE(const Common::Rect &area, const DrawStep &step, const Common::Rect &clip) {
void drawCallback_TRIANGLE(const Common::Rect &area, const DrawStep &step) {
uint16 x, y, w, h;
stepGetPositions(step, area, x, y, w, h);
drawTriangleClip(x, y, w, h, (TriangleOrientation)step.extraData, clip);
drawTriangle(x, y, w, h, (TriangleOrientation)step.extraData);
}

void drawCallback_BEVELSQ(const Common::Rect &area, const DrawStep &step, const Common::Rect &clip) {
void drawCallback_BEVELSQ(const Common::Rect &area, const DrawStep &step) {
uint16 x, y, w, h;
stepGetPositions(step, area, x, y, w, h);
drawBeveledSquareClip(x, y, w, h, _bevel, clip);
drawBeveledSquare(x, y, w, h);
}

void drawCallback_TAB(const Common::Rect &area, const DrawStep &step, const Common::Rect &clip) {
void drawCallback_TAB(const Common::Rect &area, const DrawStep &step) {
uint16 x, y, w, h;
stepGetPositions(step, area, x, y, w, h);
drawTabClip(x, y, stepGetRadius(step, area), w, h, clip);
drawTab(x, y, stepGetRadius(step, area), w, h);
}

void drawCallback_BITMAP(const Common::Rect &area, const DrawStep &step, const Common::Rect &clip) {
void drawCallback_BITMAP(const Common::Rect &area, const DrawStep &step) {
uint16 x, y, w, h;
stepGetPositions(step, area, x, y, w, h);
blitKeyBitmapClip(step.blitSrc, Common::Rect(x, y, x + w, y + h), clip);
blitKeyBitmap(step.blitSrc, Common::Point(x, y));
}

void drawCallback_ALPHABITMAP(const Common::Rect &area, const DrawStep &step, const Common::Rect &clip) {
void drawCallback_ALPHABITMAP(const Common::Rect &area, const DrawStep &step) {
uint16 x, y, w, h;
stepGetPositions(step, area, x, y, w, h);
blitAlphaBitmap(step.blitAlphaSrc, Common::Rect(x, y, x + w, y + h), step.autoscale, step.xAlign, step.yAlign); // TODO
}

void drawCallback_CROSS(const Common::Rect &area, const DrawStep &step, const Common::Rect &clip) {
void drawCallback_CROSS(const Common::Rect &area, const DrawStep &step) {
uint16 x, y, w, h;
stepGetPositions(step, area, x, y, w, h);
drawCrossClip(x, y, w, h, clip);
drawCross(x, y, w, h);
}

void drawCallback_VOID(const Common::Rect &area, const DrawStep &step, const Common::Rect &clip) {}
void drawCallback_VOID(const Common::Rect &area, const DrawStep &step) {}

/**
* Draws the specified draw step on the screen.
@@ -474,8 +470,7 @@ class VectorRenderer {
* @param area Zone to paint on
* @param step Pointer to a DrawStep struct.
*/
virtual void drawStep(const Common::Rect &area, const DrawStep &step, uint32 extra = 0);
virtual void drawStepClip(const Common::Rect &area, const Common::Rect &clip, const DrawStep &step, uint32 extra = 0);
virtual void drawStep(const Common::Rect &area, const Common::Rect &clip, const DrawStep &step, uint32 extra = 0);

/**
* Copies the part of the current frame to the system overlay.
@@ -509,17 +504,11 @@ class VectorRenderer {
virtual void blitSurface(const Graphics::Surface *source, const Common::Rect &r) = 0;

/**
* Blits a given graphics surface into a small area of the current drawing surface.
*
* Note that the given surface is expected to be smaller than the
* active drawing surface, hence the WHOLE source surface will be
* blitted into the active surface, at the position specified by "r".
* Blits a given graphics surface at the specified position of the current drawing surface.
*/
virtual void blitSubSurface(const Graphics::Surface *source, const Common::Rect &r) = 0;
virtual void blitSubSurfaceClip(const Graphics::Surface *source, const Common::Rect &r, const Common::Rect &clipping) = 0;
virtual void blitSubSurface(const Graphics::Surface *source, const Common::Point &p) = 0;

virtual void blitKeyBitmap(const Graphics::Surface *source, const Common::Rect &r) = 0;
virtual void blitKeyBitmapClip(const Graphics::Surface *source, const Common::Rect &r, const Common::Rect &clipping) = 0;
virtual void blitKeyBitmap(const Graphics::Surface *source, const Common::Point &p) = 0;

virtual void blitAlphaBitmap(Graphics::TransparentSurface *source, const Common::Rect &r,
GUI::ThemeEngine::AutoScaleMode autoscale = GUI::ThemeEngine::kAutoScaleNone,

0 comments on commit 1d764bd

Please sign in to comment.
You can’t perform that action at this time.