Draw steps.
svn-id: r32296
This commit is contained in:
parent
862a3d575a
commit
4e1aa5328a
2 changed files with 118 additions and 42 deletions
|
@ -60,28 +60,53 @@ void vector_renderer_test(OSystem *_system) {
|
|||
|
||||
_system->showOverlay();
|
||||
|
||||
DrawStep *steps = new DrawStep[5];
|
||||
|
||||
steps[0].color1.r = 214;
|
||||
steps[0].color1.g = 113;
|
||||
steps[0].color1.b = 8;
|
||||
steps[0].color2.r = 240;
|
||||
steps[0].color2.g = 200;
|
||||
steps[0].color2.b = 25;
|
||||
steps[0].fill_mode = kFillMode_Gradient;
|
||||
steps[0].drawing_call = &VectorRenderer::drawCallback_FILLSURFACE;
|
||||
steps[0].flags = kDrawStep_SetGradient | kDrawStep_SetFillMode;
|
||||
|
||||
steps[1].color1.r = 206;
|
||||
steps[1].color1.g = 121;
|
||||
steps[1].color1.b = 99;
|
||||
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].drawing_call = &VectorRenderer::drawCallback_ROUNDSQ;
|
||||
steps[1].flags = kDrawStep_SetGradient;
|
||||
|
||||
steps[2].x = 500;
|
||||
steps[2].y = 135;
|
||||
steps[2].r = 8;
|
||||
steps[2].w = 120;
|
||||
steps[2].h = 30;
|
||||
steps[2].drawing_call = &VectorRenderer::drawCallback_ROUNDSQ;
|
||||
steps[2].flags = kDrawStep_CallbackOnly;
|
||||
|
||||
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 = kDrawStep_CallbackOnly;
|
||||
|
||||
bool running = true;
|
||||
while (running) { // draw!!
|
||||
vr->setFgColor(255, 0, 206);
|
||||
vr->setGradientFactor(1);
|
||||
vr->setGradientColors(214, 113, 8, 240, 200, 25);
|
||||
vr->fillSurface(kFillMode_Gradient);
|
||||
|
||||
vr->setBgColor(25, 25, 175);
|
||||
vr->shadowEnable(3);
|
||||
vr->setFgColor(240, 204, 120);
|
||||
vr->setStrokeWidth(1);
|
||||
vr->setFillMode(kFillMode_Gradient);
|
||||
|
||||
vr->setGradientFactor(3);
|
||||
vr->setGradientColors(255, 231, 140, 255, 243, 206);
|
||||
vr->drawRoundedSquare(25, 95, 18, 465, 290);
|
||||
|
||||
vr->setGradientFactor(1);
|
||||
vr->setGradientColors(206, 121, 99, 173, 40, 8);
|
||||
vr->drawRoundedSquare(500, 95, 8, 120, 30);
|
||||
vr->drawRoundedSquare(500, 135, 8, 120, 30);
|
||||
vr->drawRoundedSquare(500, 175, 8, 120, 30);
|
||||
for (int i = 0; i < 4; ++i)
|
||||
vr->drawStep(&steps[i]);
|
||||
|
||||
_system->copyRectToOverlay((OverlayColor*)_screen.getBasePtr(0, 0), _screen.w, 0, 0, _screen.w, _screen.w);
|
||||
_system->updateScreen();
|
||||
|
@ -97,6 +122,44 @@ void vector_renderer_test(OSystem *_system) {
|
|||
_system->hideOverlay();
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
* DRAWSTEP handling functions
|
||||
********************************************************************/
|
||||
void VectorRenderer::drawStep(DrawStep *step) {
|
||||
|
||||
if (step->flags & kDrawStep_CallbackOnly) {
|
||||
(this->*(step->drawing_call))(step);
|
||||
return;
|
||||
}
|
||||
|
||||
if (step->flags & kDrawStep_SetBG)
|
||||
setBgColor(step->color2.r, step->color2.g, step->color2.b);
|
||||
|
||||
if (step->flags & kDrawStep_SetFG)
|
||||
setFgColor(step->color1.r, step->color1.g, step->color1.b);
|
||||
|
||||
if (step->flags & kDrawStep_SetGradient)
|
||||
setGradientColors(step->color1.r, step->color1.g, step->color1.b,
|
||||
step->color2.r, step->color2.g, step->color2.b);
|
||||
|
||||
if (step->flags & kDrawStep_SetShadow)
|
||||
shadowEnable(step->shadow);
|
||||
|
||||
if (step->flags & kDrawStep_SetGradientFactor)
|
||||
setGradientFactor(step->factor);
|
||||
|
||||
if (step->flags & kDrawStep_SetStroke)
|
||||
setStrokeWidth(step->stroke);
|
||||
|
||||
if (step->flags & kDrawStep_SetFillMode)
|
||||
setFillMode(step->fill_mode);
|
||||
|
||||
if (step->flags & kDrawStep_SettingsOnly)
|
||||
return;
|
||||
|
||||
(this->*(step->drawing_call))(step);
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
* MISCELANEOUS functions
|
||||
********************************************************************/
|
||||
|
|
|
@ -34,8 +34,9 @@
|
|||
namespace Graphics {
|
||||
|
||||
void vector_renderer_test(OSystem *_system);
|
||||
class VectorRenderer;
|
||||
|
||||
/** Specified the way in which a shape is filled */
|
||||
/** Specifies the way in which a shape is filled */
|
||||
enum FillMode {
|
||||
kFillMode_Disabled = 0,
|
||||
kFillMode_Foreground = 1,
|
||||
|
@ -44,22 +45,33 @@ enum FillMode {
|
|||
};
|
||||
|
||||
struct DrawStep {
|
||||
bool set_fg, set_bg, set_grad;
|
||||
uint32 flags; /** Step flags, see DrawStepFlags */
|
||||
|
||||
uint8 fg_r, fg_g, fg_b;
|
||||
uint8 bg_r, bg_g, bg_b;
|
||||
struct {
|
||||
uint8 r, g, b;
|
||||
}
|
||||
color1, /** Foreground color/gradient start */
|
||||
color2; /** Background color/gradient end */
|
||||
|
||||
uint8 grad_r1, grad_g1, grad_b1;
|
||||
uint8 grad_r2, grad_g2, grad_b2;
|
||||
uint16 x, y, w, h, r; /** Shape size */
|
||||
uint8 shadow, stroke, factor; /** Misc options... */
|
||||
|
||||
uint16 x, y, w, h, r;
|
||||
uint8 shadows, stroke, factor;
|
||||
FillMode fill_mode; /** active fill mode */
|
||||
|
||||
FillMode fill_mode;
|
||||
|
||||
void (*drawing_call)(DrawStep *step);
|
||||
void (VectorRenderer::*drawing_call)(DrawStep*); /** Pointer to drawing function */
|
||||
};
|
||||
|
||||
enum DrawStepFlags {
|
||||
kDrawStep_CallbackOnly = (1 << 0),
|
||||
kDrawStep_SettingsOnly = (1 << 1),
|
||||
kDrawStep_SetBG = (1 << 2),
|
||||
kDrawStep_SetFG = (1 << 3),
|
||||
kDrawStep_SetGradient = (1 << 4),
|
||||
kDrawStep_SetShadow = (1 << 5),
|
||||
kDrawStep_SetGradientFactor = (1 << 6),
|
||||
kDrawStep_SetStroke = (1 << 7),
|
||||
kDrawStep_SetFillMode = (1 << 8)
|
||||
};
|
||||
|
||||
/**
|
||||
* VectorRenderer: The core Vector Renderer Class
|
||||
|
@ -199,7 +211,7 @@ public:
|
|||
*
|
||||
* @param mode Fill mode (bg, fg or gradient) used to fill the surface
|
||||
*/
|
||||
virtual void fillSurface(FillMode mode = kFillMode_Foreground) = 0;
|
||||
virtual void fillSurface() = 0;
|
||||
|
||||
/**
|
||||
* Clears the active surface.
|
||||
|
@ -263,27 +275,28 @@ public:
|
|||
_gradientFactor = factor;
|
||||
}
|
||||
|
||||
void drawStep_CIRCLE(DrawStep *step) {
|
||||
void drawCallback_CIRCLE(DrawStep *step) {
|
||||
drawCircle(step->x, step->y, step->r);
|
||||
}
|
||||
|
||||
void drawStep_SQUARE(DrawStep *step) {
|
||||
void drawCallback_SQUARE(DrawStep *step) {
|
||||
drawSquare(step->x, step->y, step->w, step->h);
|
||||
}
|
||||
|
||||
void drawStep_LINE(DrawStep *step) {
|
||||
void drawCallback_LINE(DrawStep *step) {
|
||||
drawLine(step->x, step->y, step->x + step->w, step->y + step->h);
|
||||
}
|
||||
|
||||
void drawStep_ROUNDEDSQ(DrawStep *step) {
|
||||
void drawCallback_ROUNDSQ(DrawStep *step) {
|
||||
drawRoundedSquare(step->x, step->y, step->r, step->w, step->h);
|
||||
}
|
||||
|
||||
|
||||
virtual void drawStep(DrawStep *step) {
|
||||
|
||||
void drawCallback_FILLSURFACE(DrawStep *step) {
|
||||
fillSurface();
|
||||
}
|
||||
|
||||
virtual void drawStep(DrawStep *step);
|
||||
|
||||
protected:
|
||||
Surface *_activeSurface; /** Pointer to the surface currently being drawn */
|
||||
|
||||
|
@ -370,18 +383,18 @@ public:
|
|||
/**
|
||||
* @see VectorRenderer::fillSurface()
|
||||
*/
|
||||
void fillSurface(FillMode mode = kFillMode_Foreground) {
|
||||
void fillSurface() {
|
||||
PixelType *ptr = (PixelType *)_activeSurface->getBasePtr(0, 0);
|
||||
|
||||
int w = _activeSurface->w;
|
||||
int h = _activeSurface->h ;
|
||||
int pitch = surfacePitch();
|
||||
|
||||
if (mode == kFillMode_Background)
|
||||
if (Base::_fillMode == kFillMode_Background)
|
||||
colorFill(ptr, ptr + w * h, _bgColor);
|
||||
else if (mode == kFillMode_Foreground)
|
||||
else if (Base::_fillMode == kFillMode_Foreground)
|
||||
colorFill(ptr, ptr + w * h, _fgColor);
|
||||
else if (mode == kFillMode_Gradient) {
|
||||
else if (Base::_fillMode == kFillMode_Gradient) {
|
||||
int i = h;
|
||||
while (i--) {
|
||||
colorFill(ptr, ptr + w, calcGradient(h - i, h));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue