Skip to content

Commit

Permalink
GUI: Add drawSquareClip()
Browse files Browse the repository at this point in the history
  • Loading branch information
Tkachov authored and sev- committed Jul 3, 2016
1 parent 559ca37 commit f22d119
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 4 deletions.
3 changes: 2 additions & 1 deletion graphics/VectorRenderer.h
Expand Up @@ -161,6 +161,7 @@ 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.
Expand Down Expand Up @@ -369,7 +370,7 @@ class VectorRenderer {
void drawCallback_SQUARE(const Common::Rect &area, const DrawStep &step, const Common::Rect &clip) { //TODO
uint16 x, y, w, h;
stepGetPositions(step, area, x, y, w, h);
drawSquare(x, y, w, h);
drawSquareClip(x, y, w, h, clip);
}

void drawCallback_LINE(const Common::Rect &area, const DrawStep &step, const Common::Rect &clip) { //TODO
Expand Down
147 changes: 147 additions & 0 deletions graphics/VectorRendererSpec.cpp
Expand Up @@ -1106,6 +1106,65 @@ drawSquare(int x, int y, int w, int h) {
}
}

template<typename PixelType>
void VectorRendererSpec<PixelType>::
drawSquareClip(int x, int y, int w, int h, Common::Rect clipping) {
if (x + w > Base::_activeSurface->w || y + h > Base::_activeSurface->h ||
w <= 0 || h <= 0 || x < 0 || y < 0)
return;

Common::Rect backup = _clippingArea;
_clippingArea = clipping;
bool useClippingVersions = !(_clippingArea.isEmpty() || _clippingArea.contains(Common::Rect(x, y, x + w, y + h)));

if (Base::_fillMode != kFillDisabled && Base::_shadowOffset
&& x + w + Base::_shadowOffset < Base::_activeSurface->w
&& y + h + Base::_shadowOffset < Base::_activeSurface->h) {
if (useClippingVersions)
drawSquareShadowClip(x, y, w, h, Base::_shadowOffset);
else
drawSquareShadow(x, y, w, h, Base::_shadowOffset);
}

switch (Base::_fillMode) {
case kFillDisabled:
if (Base::_strokeWidth)
if (useClippingVersions)
drawSquareAlgClip(x, y, w, h, _fgColor, kFillDisabled);
else
drawSquareAlg(x, y, w, h, _fgColor, kFillDisabled);
break;

case kFillForeground:
if (useClippingVersions)
drawSquareAlgClip(x, y, w, h, _fgColor, kFillForeground);
else
drawSquareAlg(x, y, w, h, _fgColor, kFillForeground);
break;

case kFillBackground:
if (useClippingVersions) {
drawSquareAlgClip(x, y, w, h, _bgColor, kFillBackground);
drawSquareAlgClip(x, y, w, h, _fgColor, kFillDisabled);
} else {
drawSquareAlg(x, y, w, h, _bgColor, kFillBackground);
drawSquareAlg(x, y, w, h, _fgColor, kFillDisabled);
}
break;

case kFillGradient:
VectorRendererSpec::drawSquareAlg(x, y, w, h, 0, kFillGradient);
if (Base::_strokeWidth)
if (useClippingVersions)
drawSquareAlgClip(x, y, w, h, _fgColor, kFillDisabled);
else
drawSquareAlg(x, y, w, h, _fgColor, kFillDisabled);
break;
}

_clippingArea = backup;
}

/** ROUNDED SQUARES **/
template<typename PixelType>
void VectorRendererSpec<PixelType>::
Expand Down Expand Up @@ -1606,6 +1665,46 @@ drawSquareAlg(int x, int y, int w, int h, PixelType color, VectorRenderer::FillM
}
}

template<typename PixelType>
void VectorRendererSpec<PixelType>::
drawSquareAlgClip(int x, int y, int w, int h, PixelType color, VectorRenderer::FillMode fill_m) {
// Do not draw anything for empty rects.
if (w <= 0 || h <= 0) {
return;
}

PixelType *ptr = (PixelType *)_activeSurface->getBasePtr(x, y);
int pitch = _activeSurface->pitch / _activeSurface->format.bytesPerPixel;
int max_h = h;
int ptr_y = y;

if (fill_m != kFillDisabled) {
while (h--) {
if (fill_m == kFillGradient)
color = calcGradient(max_h - h, max_h);

colorFillClip<PixelType>(ptr, ptr + w, color, x, ptr_y, _clippingArea);
ptr += pitch;
++ptr_y;
}
} else {
int sw = Base::_strokeWidth, sp = 0, hp = pitch * (h - 1);

while (sw--) {
colorFillClip<PixelType>(ptr + sp, ptr + w + sp, color, x, ptr_y + sp/pitch, _clippingArea);
colorFillClip<PixelType>(ptr + hp - sp, ptr + w + hp - sp, color, x, ptr_y + h - sp/pitch, _clippingArea);
sp += pitch;
}

while (h--) {
colorFillClip<PixelType>(ptr, ptr + Base::_strokeWidth, color, x, ptr_y, _clippingArea);
colorFillClip<PixelType>(ptr + w - Base::_strokeWidth, ptr + w, color, x + w - Base::_strokeWidth, ptr_y, _clippingArea);
ptr += pitch;
ptr_y += 1;
}
}
}

/** SQUARE ALGORITHM **/
template<typename PixelType>
void VectorRendererSpec<PixelType>::
Expand Down Expand Up @@ -2627,6 +2726,54 @@ drawSquareShadow(int x, int y, int w, int h, int offset) {
}
}

template<typename PixelType>
void VectorRendererSpec<PixelType>::
drawSquareShadowClip(int x, int y, int w, int h, int offset) {
// Do nothing for empty rects or no shadow offset.
if (w <= 0 || h <= 0 || offset <= 0) {
return;
}

PixelType *ptr = (PixelType *)_activeSurface->getBasePtr(x + w - 1, y + offset);
int pitch = _activeSurface->pitch / _activeSurface->format.bytesPerPixel;
int i, j, ptr_x = x+w-1, ptr_y = y+offset;

i = h - offset;

while (i--) {
j = offset;
while (j--)
blendPixelPtrClip(ptr + j, 0, ((offset - j) << 8) / offset, ptr_x + j, ptr_y);
ptr += pitch;
++ptr_y;
}

ptr = (PixelType *)_activeSurface->getBasePtr(x + offset, y + h - 1);
ptr_x = x + offset;
ptr_y = y + h - 1;

while (i++ < offset) {
j = w - offset;
while (j--)
blendPixelPtrClip(ptr + j, 0, ((offset - i) << 8) / offset, ptr_x + j, ptr_y);
ptr += pitch;
++ptr_y;
}

ptr = (PixelType *)_activeSurface->getBasePtr(x + w, y + h);
ptr_x = x + w;
ptr_y = y + h;

i = 0;
while (i++ < offset) {
j = offset - 1;
while (j--)
blendPixelPtrClip(ptr + j, 0, (((offset - j) * (offset - i)) << 8) / (offset * offset), ptr_x + j, ptr_y);
ptr += pitch;
++ptr_y;
}
}

template<typename PixelType>
void VectorRendererSpec<PixelType>::
drawRoundedSquareShadow(int x1, int y1, int r, int w, int h, int offset) {
Expand Down
9 changes: 7 additions & 2 deletions graphics/VectorRendererSpec.h
Expand Up @@ -52,10 +52,11 @@ class VectorRendererSpec : public VectorRenderer {

void drawLine(int x1, int y1, int x2, int y2); //TODO
void drawCircle(int x, int y, int r); //TODO
void drawSquare(int x, int y, int w, int h); //TODO
void drawSquare(int x, int y, int w, int h);
void drawSquareClip(int x, int y, int w, int h, Common::Rect clipping);
void drawRoundedSquare(int x, int y, int r, int w, int h);
void drawRoundedSquareClip(int x, int y, int r, int w, int h, int cx, int cy, int cw, int ch);
void drawTriangle(int x, int y, int base, int height, TriangleOrientation orient); //TODO
void drawTriangle(int x, int y, int base, int height, TriangleOrientation orient);
void drawTriangleClip(int x, int y, int base, int height, TriangleOrientation orient, Common::Rect clipping);
void drawTab(int x, int y, int r, int w, int h); //TODO
void drawBeveledSquare(int x, int y, int w, int h, int bevel) { //TODO
Expand Down Expand Up @@ -181,6 +182,9 @@ class VectorRendererSpec : public VectorRenderer {
virtual void drawSquareAlg(int x, int y, int w, int h,
PixelType color, FillMode fill_m);

virtual void drawSquareAlgClip(int x, int y, int w, int h,
PixelType color, FillMode fill_m);

virtual void drawTriangleVertAlg(int x, int y, int w, int h,
bool inverted, PixelType color, FillMode fill_m);

Expand Down Expand Up @@ -214,6 +218,7 @@ class VectorRendererSpec : public VectorRenderer {
* @param offset Intensity/size of the shadow.
*/
virtual void drawSquareShadow(int x, int y, int w, int h, int offset);
virtual void drawSquareShadowClip(int x, int y, int w, int h, int offset);
virtual void drawRoundedSquareShadow(int x, int y, int r, int w, int h, int offset);
virtual void drawRoundedSquareShadowClip(int x, int y, int r, int w, int h, int offset);

Expand Down
40 changes: 40 additions & 0 deletions gui/ThemeEngine.cpp
Expand Up @@ -1177,6 +1177,35 @@ void ThemeEngine::drawDialogBackground(const Common::Rect &r, DialogBackground b
}
}

void ThemeEngine::drawDialogBackgroundClip(const Common::Rect &r, const Common::Rect &clip, DialogBackground bgtype, WidgetStateInfo state) {
if (!ready())
return;

switch (bgtype) {
case kDialogBackgroundMain:
queueDDClip(kDDMainDialogBackground, r, clip);
break;

case kDialogBackgroundSpecial:
queueDDClip(kDDSpecialColorBackground, r, clip);
break;

case kDialogBackgroundPlain:
queueDDClip(kDDPlainColorBackground, r, clip);
break;

case kDialogBackgroundTooltip:
queueDDClip(kDDTooltipBackground, r, clip);
break;

case kDialogBackgroundDefault:
queueDDClip(kDDDefaultBackground, r, clip);
break;
case kDialogBackgroundNone:
break;
}
}

void ThemeEngine::drawCaret(const Common::Rect &r, bool erase, WidgetStateInfo state) {
if (!ready())
return;
Expand All @@ -1188,6 +1217,17 @@ void ThemeEngine::drawCaret(const Common::Rect &r, bool erase, WidgetStateInfo s
queueDD(kDDCaret, r);
}

void ThemeEngine::drawCaretClip(const Common::Rect &r, const Common::Rect &clip, bool erase, WidgetStateInfo state) {
if (!ready())
return;

if (erase) {
restoreBackground(r);
addDirtyRect(r);
} else
queueDDClip(kDDCaret, r, clip);
}

void ThemeEngine::drawPopUpWidget(const Common::Rect &r, const Common::String &sel, int deltax, WidgetStateInfo state, Graphics::TextAlign align) {
if (!ready())
return;
Expand Down
4 changes: 4 additions & 0 deletions gui/ThemeEngine.h
Expand Up @@ -379,9 +379,13 @@ class ThemeEngine {
void drawCaret(const Common::Rect &r, bool erase,
WidgetStateInfo state = kStateEnabled);

void drawCaretClip(const Common::Rect &r, const Common::Rect &clip, bool erase,
WidgetStateInfo state = kStateEnabled);

void drawLineSeparator(const Common::Rect &r, WidgetStateInfo state = kStateEnabled);

void drawDialogBackground(const Common::Rect &r, DialogBackground type, WidgetStateInfo state = kStateEnabled);
void drawDialogBackgroundClip(const Common::Rect &r, const Common::Rect &clip, DialogBackground type, WidgetStateInfo state = kStateEnabled);

void drawText(const Common::Rect &r, const Common::String &str, WidgetStateInfo state = kStateEnabled, Graphics::TextAlign align = Graphics::kTextAlignCenter, TextInversionState inverted = kTextInversionNone, int deltax = 0, bool useEllipsis = true, FontStyle font = kFontStyleBold, FontColor color = kFontColorNormal, bool restore = true, const Common::Rect &drawableTextArea = Common::Rect(0, 0, 0, 0));

Expand Down
2 changes: 1 addition & 1 deletion gui/widgets/editable.cpp
Expand Up @@ -274,7 +274,7 @@ void EditableWidget::drawCaret(bool erase) {
x += getAbsX();
y += getAbsY();

g_gui.theme()->drawCaret(Common::Rect(x, y, x + 1, y + editRect.height()), erase);
g_gui.theme()->drawCaretClip(Common::Rect(x, y, x + 1, y + editRect.height()), getBossClipRect(), erase);

if (erase) {
GUI::EditableWidget::String character;
Expand Down

0 comments on commit f22d119

Please sign in to comment.