GLK: COMPREHEND: Refactoring drawing code

This commit is contained in:
Paul Gilbert 2020-05-30 18:23:34 -07:00
parent 687ed8be04
commit 4fc86e1bc9
6 changed files with 285 additions and 470 deletions

View File

@ -1024,7 +1024,7 @@ void comprehend_load_game(ComprehendGame *game) {
game->_itemImages.load(game->_itemGraphicFiles);
if (game->_colorTable)
g_set_color_table(game->_colorTable);
DrawSurface::setColorTable(game->_colorTable);
}
/* FIXME - This can be merged, don't need to keep start room around */

View File

@ -37,7 +37,7 @@ namespace Comprehend {
static bool graphics_enabled;
static unsigned pen_colors[] = {
const uint32 DrawSurface::PEN_COLORS[8] = {
G_COLOR_BLACK,
RGB(0x00, 0x66, 0x00),
RGB(0x00, 0xff, 0x00),
@ -48,31 +48,8 @@ static unsigned pen_colors[] = {
RGB(0xff, 0x00, 0x00),
};
struct GraphicsContext {
Window *screen;
/*
* FIXME - Currently using two renderers. One for drawing the (possibly
* scaled) image to the screen and the other for getting pixel
* data for floodfill boundaries. This is almost certainly not
* the best way to do this.
*/
// SDL_Renderer *renderer[2];
/* Used for pixel access for flood fills */
// SDL_Surface *surface;
};
#ifdef TODO
static GraphicsContext ctx;
#endif
unsigned g_set_pen_color(uint8 opcode) {
return pen_colors[opcode - IMAGE_OP_PEN_COLOR_A];
}
/* Used by Transylvania and Crimson Crown */
static unsigned default_color_table[] = {
const uint32 DrawSurface::DEFAULT_COLOR_TABLE[256] = {
G_COLOR_WHITE, // 00
G_COLOR_DARK_BLUE, // 01
G_COLOR_GRAY1, // 02
@ -117,55 +94,10 @@ static unsigned default_color_table[] = {
/* Used by OO-topos */
/* FIXME - incomplete */
static unsigned color_table_1[] = {
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
const uint32 DrawSurface::COLOR_TABLE_1[256] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0,
0,
0,
@ -234,172 +166,44 @@ static unsigned color_table_1[] = {
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
const uint32 *DrawSurface::COLOR_TABLES[2] = {
DEFAULT_COLOR_TABLE,
COLOR_TABLE_1,
};
static unsigned *color_tables[] = {
default_color_table,
color_table_1,
};
const uint32 *DrawSurface::_colorTable = DEFAULT_COLOR_TABLE;
static unsigned *color_table = default_color_table;
uint32 DrawSurface::_renderColor;
void g_set_color_table(unsigned index) {
if (index >= ARRAY_SIZE(color_tables)) {
printf("Bad color table %d - using default\n", index);
color_table = default_color_table;
}
/*-------------------------------------------------------*/
color_table = color_tables[index];
void DrawSurface::reset() {
create(G_RENDER_WIDTH, G_RENDER_HEIGHT,
Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0));
}
unsigned g_set_fill_color(uint8 index) {
void DrawSurface::setColorTable(uint index) {
if (index >= ARRAY_SIZE(COLOR_TABLES)) {
warning("Bad color table %d - using default", index);
_colorTable = DEFAULT_COLOR_TABLE;
}
_colorTable = COLOR_TABLES[index];
}
uint DrawSurface::getPenColor(uint8 opcode) const {
return PEN_COLORS[opcode - IMAGE_OP_PEN_COLOR_A];
}
uint32 DrawSurface::getFillColor(uint8 index) {
unsigned color;
color = color_table[index];
color = _colorTable[index];
if (!color) {
/* Unknown color - use ugly purple */
debug_printf(DEBUG_IMAGE_DRAW, "Unknown color %.2x\n", index);
@ -409,6 +213,181 @@ unsigned g_set_fill_color(uint8 index) {
return color;
}
void DrawSurface::drawLine(uint16 x1, uint16 y1, uint16 x2, uint16 y2, uint32 color) {
Graphics::ManagedSurface::drawLine(x1, y1, x2, y2, color);
}
void DrawSurface::drawBox(uint16 x1, uint16 y1, uint16 x2, uint16 y2,
uint32 color) {
Common::Rect r(x1, y1, x2, y2);
frameRect(r, color);
}
void DrawSurface::drawFilledBox(uint16 x1, uint16 y1,
uint16 x2, uint16 y2, uint32 color) {
Common::Rect r(x1, y1, x2, y2);
fillRect(r, color);
}
void DrawSurface::drawShape(int x, int y, int shape_type, uint32 fill_color) {
int i, j;
switch (shape_type) {
case IMAGE_OP_SHAPE_PIXEL:
x += 7;
y += 7;
drawPixel(x, y, fill_color);
break;
case IMAGE_OP_SHAPE_BOX:
x += 6;
y += 7;
drawFilledBox(x, y, x + 2, y + 2, fill_color);
break;
case IMAGE_OP_SHAPE_CIRCLE_TINY:
x += 5;
y += 5;
drawFilledBox(x + 1, y, x + 3, y + 4, fill_color);
drawFilledBox(x, y + 1, x + 4, y + 3, fill_color);
break;
case IMAGE_OP_SHAPE_CIRCLE_SMALL:
x += 4;
y += 4;
drawFilledBox(x + 1, y, x + 5, y + 6, fill_color);
drawFilledBox(x, y + 1, x + 6, y + 5, fill_color);
break;
case IMAGE_OP_SHAPE_CIRCLE_MED:
x += 1;
y += 1;
drawFilledBox(x + 1,
y + 1,
x + 1 + (2 + 4 + 2),
y + 1 + (2 + 4 + 2),
fill_color);
drawFilledBox(x + 3,
y,
x + 3 + 4,
y + (1 + 2 + 4 + 2 + 1),
fill_color);
drawFilledBox(x,
y + 3,
x + (1 + 2 + 4 + 2 + 1),
y + 3 + 4,
fill_color);
break;
case IMAGE_OP_SHAPE_CIRCLE_LARGE:
drawFilledBox(x + 2,
y + 1,
x + 2 + (3 + 4 + 3),
y + 1 + (1 + 3 + 4 + 3 + 1),
fill_color);
drawFilledBox(x + 1,
y + 2,
x + 1 + (1 + 3 + 4 + 3 + 1),
y + 2 + (3 + 4 + 3),
fill_color);
drawFilledBox(x + 5,
y,
x + 5 + 4,
y + 1 + 1 + 3 + 4 + 3 + 1 + 1,
fill_color);
drawFilledBox(x,
y + 5,
x + 1 + 1 + 3 + 4 + 3 + 1 + 1,
y + 5 + 4,
fill_color);
break;
case IMAGE_OP_SHAPE_A:
/* FIXME - very large circle? */
break;
case IMAGE_OP_SHAPE_SPRAY: {
char spray[13][13] = {
{0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0},
{0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
{0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1},
{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
{1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0},
{0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0},
{1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0},
{0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0},
{1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0},
{0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0},
{0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0},
};
for (i = 0; i < 13; i++)
for (j = 0; j < 13; j++)
if (spray[i][j])
drawPixel(x + i, y + j, fill_color);
break;
}
default:
/* Unknown shape */
break;
}
}
void DrawSurface::floodFill(int x, int y, uint32 fill_color, uint32 old_color) {
int x1, x2, i;
if (getPixelColor(x, y) != old_color || fill_color == old_color)
return;
/* Left end of scanline */
for (x1 = x; x1 > 0; x1--)
if (getPixelColor(x1 - 1, y) != old_color)
break;
/* Right end of scanline */
for (x2 = x; x2 < RENDER_X_MAX; x2++)
if (getPixelColor(x2 + 1, y) != old_color)
break;
drawLine(x1, y, x2, y, fill_color);
#ifdef TODO
SDL_RenderPresent(ctx.renderer[RENDERER_SCREEN]);
#endif
/* Scanline above */
for (i = x1; i < x2; i++)
if (y > 0 && getPixelColor(i, y - 1) == old_color)
floodFill(i, y - 1, fill_color, old_color);
/* Scanline below */
for (i = x1; i < x2; i++)
if (y < RENDER_Y_MAX && getPixelColor(i, y + 1) == old_color)
floodFill(i, y + 1, fill_color, old_color);
}
void DrawSurface::drawPixel(uint16 x, uint16 y, uint32 color) {
uint32 *ptr = (uint32 *)getBasePtr(x, y);
*ptr = color;
}
uint32 DrawSurface::getPixelColor(uint16 x, uint16 y) {
uint32 *ptr = (uint32 *)getBasePtr(x, y);
return *ptr;
}
void DrawSurface::clearScreen(uint32 color) {
fillRect(Common::Rect(0, 0, this->w, this->h), color);
render();
}
void DrawSurface::render() {
GraphicsWindow *win = g_comprehend->_topWindow;
win->drawPicture(*this, (uint)-2, 0, 0, win->_w, win->_h);
}
/*-------------------------------------------------------*/
#ifdef TODO
static void set_color(unsigned color) {
int i;
@ -422,202 +401,13 @@ static void set_color(unsigned color) {
}
#endif
void g_draw_box(unsigned x1, unsigned y1, unsigned x2, unsigned y2,
unsigned color) {
Rect r(x1, y1, x2, y2);
g_comprehend->_topWindow->frameRect(color, r);
}
static void g_draw_filled_box(unsigned x1, unsigned y1,
unsigned x2, unsigned y2, unsigned color) {
Rect r(x1, y1, x2, y2);
g_comprehend->_topWindow->fillRect(color, r);
}
unsigned g_get_pixel_color(int x, int y) {
#ifdef TODO
uint32 *pixels, val;
pixels = ctx.surface->pixels;
val = pixels[(y * G_RENDER_WIDTH) + x];
/* FIXME - correct endianess on all platforms? */
return be32toh(val);
#else
return 0;
#endif
}
void g_draw_pixel(unsigned x, unsigned y, unsigned color) {
#ifdef TODO
int i;
set_color(color);
for (i = 0; i < ARRAY_SIZE(ctx.renderer); i++)
SDL_RenderDrawPoint(ctx.renderer[i], x, y);
#endif
}
void g_draw_line(unsigned x1, unsigned y1, unsigned x2, unsigned y2,
unsigned color) {
g_comprehend->_topWindow->drawLine(color, Point(x1, y1), Point(x2, y2));
}
void g_draw_shape(int x, int y, int shape_type, unsigned fill_color)
{
int i, j;
switch (shape_type) {
case IMAGE_OP_SHAPE_PIXEL:
x += 7; y += 7;
g_draw_pixel(x, y, fill_color);
break;
case IMAGE_OP_SHAPE_BOX:
x += 6; y += 7;
g_draw_filled_box(x, y, x + 2, y + 2, fill_color);
break;
case IMAGE_OP_SHAPE_CIRCLE_TINY:
x += 5;
y += 5;
g_draw_filled_box(x + 1, y, x + 3, y + 4, fill_color);
g_draw_filled_box(x, y + 1, x + 4, y + 3, fill_color);
break;
case IMAGE_OP_SHAPE_CIRCLE_SMALL:
x += 4; y += 4;
g_draw_filled_box(x + 1, y, x + 5, y + 6, fill_color);
g_draw_filled_box(x, y + 1, x + 6, y + 5, fill_color);
break;
case IMAGE_OP_SHAPE_CIRCLE_MED:
x += 1; y += 1;
g_draw_filled_box(x + 1,
y + 1,
x + 1 + (2 + 4 + 2),
y + 1 + (2 + 4 + 2),
fill_color);
g_draw_filled_box(x + 3,
y,
x + 3 + 4,
y + (1 + 2 + 4 + 2 + 1),
fill_color);
g_draw_filled_box(x,
y + 3,
x + (1 + 2 + 4 + 2 + 1),
y + 3 + 4,
fill_color);
break;
case IMAGE_OP_SHAPE_CIRCLE_LARGE:
g_draw_filled_box(x + 2,
y + 1,
x + 2 + (3 + 4 + 3),
y + 1 + (1 + 3 + 4 + 3 + 1),
fill_color);
g_draw_filled_box(x + 1,
y + 2,
x + 1 + (1 + 3 + 4 + 3 + 1),
y + 2 + (3 + 4 + 3),
fill_color);
g_draw_filled_box(x + 5,
y,
x + 5 + 4,
y + 1 + 1 + 3 + 4 + 3 + 1 + 1,
fill_color);
g_draw_filled_box(x,
y + 5,
x + 1 + 1 + 3 + 4 + 3 + 1 + 1,
y + 5 + 4,
fill_color);
break;
case IMAGE_OP_SHAPE_A:
/* FIXME - very large circle? */
break;
case IMAGE_OP_SHAPE_SPRAY:
{
char spray[13][13] = {
{0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0},
{0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
{0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1},
{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
{1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0},
{0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0},
{1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0},
{0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0},
{1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0},
{0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0},
{0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0},
};
for (i = 0; i < 13; i++)
for (j = 0; j < 13; j++)
if (spray[i][j])
g_draw_pixel(x + i, y + j, fill_color);
break;
}
default:
/* Unknown shape */
break;
}
}
void g_floodfill(int x, int y, unsigned fill_color,
unsigned old_color)
{
int x1, x2, i;
if (g_get_pixel_color(x, y) != old_color || fill_color == old_color)
return;
/* Left end of scanline */
for (x1 = x; x1 > 0; x1--)
if (g_get_pixel_color(x1 - 1, y) != old_color)
break;
/* Right end of scanline */
for (x2 = x; x2 < RENDER_X_MAX; x2++)
if (g_get_pixel_color(x2 + 1, y) != old_color)
break;
g_draw_line(x1, y, x2, y, fill_color);
#ifdef TODO
SDL_RenderPresent(ctx.renderer[RENDERER_SCREEN]);
#endif
/* Scanline above */
for (i = x1; i < x2; i++)
if (y > 0 && g_get_pixel_color(i, y - 1) == old_color)
g_floodfill(i, y - 1, fill_color, old_color);
/* Scanline below */
for (i = x1; i < x2; i++)
if (y < RENDER_Y_MAX && g_get_pixel_color(i, y + 1) == old_color)
g_floodfill(i, y + 1, fill_color, old_color);
}
void g_flip_buffers(void) {
#ifdef TODO
SDL_RenderPresent(ctx.renderer[RENDERER_SCREEN]);
#endif
}
void g_clear_screen(unsigned color) {
GraphicsWindow *win = g_comprehend->_topWindow;
win->fillRect(color, Rect(0, 0, win->_w, win->_h));
}
void g_init() {
graphics_enabled = true;
DrawSurface::setColorTable(0);
DrawSurface::_renderColor = 0;
}
bool g_enabled(void)
{
bool g_enabled(void) {
return graphics_enabled;
}

View File

@ -24,6 +24,7 @@
#define GLK_COMPREHEND_GRAPHICS_H
#include "common/scummsys.h"
#include "graphics/managed_surface.h"
namespace Glk {
namespace Comprehend {
@ -62,23 +63,45 @@ namespace Comprehend {
#define G_COLOR_BROWN1 0x7a5200ff
#define G_COLOR_BROWN2 0x663300ff
void g_set_color_table(unsigned index);
class DrawSurface : public Graphics::ManagedSurface {
private:
static const uint32 PEN_COLORS[8];
static const uint32 DEFAULT_COLOR_TABLE[256];
static const uint32 COLOR_TABLE_1[256];
static const uint32 *COLOR_TABLES[2];
static const uint32 *_colorTable;
unsigned g_set_fill_color(uint8 index);
unsigned g_set_pen_color(uint8 opcode);
public:
static uint32 _renderColor;
public:
DrawSurface() {
reset();
}
unsigned g_get_pixel_color(int x, int y);
/**
* Sets up the surface to the correct size and pixel format
*/
void reset();
void g_draw_pixel(unsigned x, unsigned y, unsigned color);
void g_draw_line(unsigned x1, unsigned y1, unsigned x2, unsigned y2,
unsigned color);
void g_draw_box(unsigned x1, unsigned y1, unsigned x2, unsigned y2,
unsigned color);
void g_draw_shape(int x, int y, int shape_type, unsigned fill_color);
void g_floodfill(int x, int y, unsigned fill_color, unsigned old_color);
static void setColorTable(uint index);
uint getPenColor(uint8 opcode) const;
uint32 getFillColor(uint8 index);
void drawLine(uint16 x1, uint16 y1, uint16 x2, uint16 y2, uint32 color);
void drawBox(uint16 x1, uint16 y1, uint16 x2, uint16 y2, uint32 color);
void drawFilledBox(uint16 x1, uint16 y1, uint16 x2, uint16 y2, uint32 color);
void drawShape(int x, int y, int shape_type, uint32 fill_color);
void floodFill(int x, int y, uint32 fill_color, uint32 old_color);
void drawPixel(uint16 x, uint16 y, uint32 color);
uint32 getPixelColor(uint16 x, uint16 y);
void clearScreen(uint32 color);
/**
* Render the surface to the screen's picture window
*/
void render();
};
void g_clear_screen(unsigned color);
void g_flip_buffers(void);
void g_init();
bool g_enabled(void);

View File

@ -34,9 +34,9 @@ namespace Comprehend {
#define IMAGES_PER_FILE 16
struct ImageContext {
unsigned x;
unsigned y;
unsigned pen_color;
unsigned _x;
unsigned _y;
unsigned _penColor;
unsigned fill_color;
unsigned shape;
@ -76,17 +76,18 @@ void ImageFileData::load(const char *filename) {
void ImageFileData::draw(uint index, ImageContext *ctx) {
_fb.seek(_imageOffsets[index]);
DrawSurface ds;
for (bool done = false; !done;) {
done = doImageOp(ctx);
done = doImageOp(&ds, ctx);
if (!done && (draw_flags & IMAGEF_OP_WAIT_KEYPRESS)) {
getchar();
g_flip_buffers();
ds.render();
}
}
}
bool ImageFileData::doImageOp(ImageContext *ctx) {
bool ImageFileData::doImageOp(DrawSurface *ds, ImageContext *ctx) {
uint8 opcode;
uint16 a, b;
@ -109,7 +110,7 @@ bool ImageFileData::doImageOp(ImageContext *ctx) {
case IMAGE_OP_PEN_COLOR_G:
case IMAGE_OP_PEN_COLOR_H:
debug_printf(DEBUG_IMAGE_DRAW, "set_pen_color(%.2x)\n", opcode);
ctx->pen_color = g_set_pen_color(opcode);
ctx->_penColor = ds->getPenColor(opcode);
break;
case IMAGE_OP_DRAW_LINE:
@ -122,11 +123,11 @@ bool ImageFileData::doImageOp(ImageContext *ctx) {
debug_printf(DEBUG_IMAGE_DRAW,
"draw_line (%d, %d) - (%d, %d)\n", opcode,
ctx->x, ctx->y, a, b);
g_draw_line(ctx->x, ctx->y, a, b, ctx->pen_color);
ctx->_x, ctx->_y, a, b);
ds->drawLine(ctx->_x, ctx->_y, a, b, ctx->_penColor);
ctx->x = a;
ctx->y = b;
ctx->_x = a;
ctx->_y = b;
break;
case IMAGE_OP_DRAW_BOX:
@ -139,9 +140,9 @@ bool ImageFileData::doImageOp(ImageContext *ctx) {
debug_printf(DEBUG_IMAGE_DRAW,
"draw_box (%d, %d) - (%d, %d)\n", opcode,
ctx->x, ctx->y, a, b);
ctx->_x, ctx->_y, a, b);
g_draw_box(ctx->x, ctx->y, a, b, ctx->pen_color);
ds->drawBox(ctx->_x, ctx->_y, a, b, ctx->_penColor);
break;
case IMAGE_OP_MOVE_TO:
@ -154,8 +155,8 @@ bool ImageFileData::doImageOp(ImageContext *ctx) {
a += 255;
debug_printf(DEBUG_IMAGE_DRAW, "move_to(%d, %d)\n", a, b);
ctx->x = a;
ctx->y = b;
ctx->_x = a;
ctx->_y = b;
break;
case IMAGE_OP_SHAPE_PIXEL:
@ -192,7 +193,7 @@ bool ImageFileData::doImageOp(ImageContext *ctx) {
"draw_shape(%d, %d), style=%.2x, fill=%.2x\n",
a, b, ctx->shape, ctx->fill_color);
g_draw_shape(a, b, ctx->shape, ctx->fill_color);
ds->drawShape(a, b, ctx->shape, ctx->fill_color);
break;
case IMAGE_OP_PAINT:
@ -206,14 +207,14 @@ bool ImageFileData::doImageOp(ImageContext *ctx) {
debug_printf(DEBUG_IMAGE_DRAW, "paint(%d, %d)\n", a, b);
if (!(draw_flags & IMAGEF_NO_FLOODFILL))
g_floodfill(a, b, ctx->fill_color,
g_get_pixel_color(a, b));
ds->floodFill(a, b, ctx->fill_color,
ds->getPixelColor(a, b));
break;
case IMAGE_OP_FILL_COLOR:
a = imageGetOperand();
debug_printf(DEBUG_IMAGE_DRAW, "set_fill_color(%.2x)\n", a);
ctx->fill_color = g_set_fill_color(a);
ctx->fill_color = ds->getFillColor(a);
break;
case IMAGE_OP_SET_TEXT_POS:
@ -230,7 +231,7 @@ bool ImageFileData::doImageOp(ImageContext *ctx) {
debug_printf(DEBUG_IMAGE_DRAW, "draw_char(%c)\n",
a >= 0x20 && a < 0x7f ? a : '?');
g_draw_box(ctx->text_x, ctx->text_y,
ds->drawBox(ctx->text_x, ctx->text_y,
ctx->text_x + 6, ctx->text_y + 7, ctx->fill_color);
ctx->text_x += 8;
break;
@ -267,7 +268,7 @@ bool ImageFileData::doImageOp(ImageContext *ctx) {
debug_printf(DEBUG_IMAGE_DRAW,
"unknown(%.2x, %.2x)\n", a, b);
g_draw_pixel(a, b, 0x00ff00ff);
ds->drawPixel(a, b, 0x00ff00ff);
break;
}
@ -318,19 +319,19 @@ void draw_image(ImageData *info, unsigned index) {
(*info)[index / IMAGES_PER_FILE].draw(index % IMAGES_PER_FILE, &ctx);
}
void draw_dark_room(void)
{
g_clear_screen(G_COLOR_BLACK);
void draw_dark_room() {
DrawSurface ds;
ds.clearScreen(G_COLOR_BLACK);
}
void draw_bright_room(void)
{
g_clear_screen(G_COLOR_WHITE);
void draw_bright_room() {
DrawSurface ds;
ds.clearScreen(G_COLOR_WHITE);
}
void draw_location_image(ImageData *info, unsigned index)
{
g_clear_screen(G_COLOR_WHITE);
void draw_location_image(ImageData *info, unsigned index) {
DrawSurface ds;
ds.clearScreen(G_COLOR_WHITE);
draw_image(info, index);
}

View File

@ -24,6 +24,7 @@
#define GLK_COMPREHEND_IMAGE_DATA_H
#include "glk/comprehend/file_buf.h"
#include "glk/comprehend/graphics.h"
#include "common/scummsys.h"
namespace Glk {
@ -39,7 +40,7 @@ private:
FileBuffer _fb;
private:
bool doImageOp(ImageContext *ctx);
bool doImageOp(DrawSurface *ds, ImageContext *ctx);
uint16 imageGetOperand();
public:

View File

@ -119,7 +119,7 @@ public:
* @return The actual area where the string is drawn.
*/
Common::Rect getBoundingBox(const Common::String &str, int x = 0, int y = 0, const int w = 0, TextAlign align = kTextAlignLeft, int deltax = 0, bool useEllipsis = false) const;
Common::Rect getBoundingBox(const Common::U32String &str, int x = 0, int y = 0, const int w = 0, TextAlign align = kTextAlignLeft) const;
Common::Rect getBoundingBox(const Common::U32String &str, int x = 0, int _y = 0, const int w = 0, TextAlign align = kTextAlignLeft) const;
/**
* Draw a character at a specific point on a surface.
@ -147,7 +147,7 @@ public:
// TODO: Add doxygen comments to this
void drawString(Surface *dst, const Common::String &str, int x, int y, int w, uint32 color, TextAlign align = kTextAlignLeft, int deltax = 0, bool useEllipsis = true) const;
void drawString(Surface *dst, const Common::U32String &str, int x, int y, int w, uint32 color, TextAlign align = kTextAlignLeft, int deltax = 0) const;
void drawString(ManagedSurface *dst, const Common::String &str, int x, int y, int w, uint32 color, TextAlign align = kTextAlignLeft, int deltax = 0, bool useEllipsis = true) const;
void drawString(ManagedSurface *dst, const Common::String &str, int x, int _y, int w, uint32 color, TextAlign align = kTextAlignLeft, int deltax = 0, bool useEllipsis = true) const;
void drawString(ManagedSurface *dst, const Common::U32String &str, int x, int y, int w, uint32 color, TextAlign align = kTextAlignLeft, int deltax = 0) const;
/**