aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/glk/glk_api.cpp33
-rw-r--r--engines/glk/glk_api.h7
-rw-r--r--engines/glk/level9/level9.cpp2
-rw-r--r--engines/glk/level9/os_glk.cpp34
-rw-r--r--engines/glk/window_graphics.cpp27
-rw-r--r--engines/glk/window_graphics.h4
6 files changed, 75 insertions, 32 deletions
diff --git a/engines/glk/glk_api.cpp b/engines/glk/glk_api.cpp
index d86bd26e3f..6d34e3a6e1 100644
--- a/engines/glk/glk_api.cpp
+++ b/engines/glk/glk_api.cpp
@@ -911,6 +911,39 @@ bool GlkAPI::glk_image_draw_scaled(winid_t win, uint image, int val1, int val2,
return false;
}
+bool GlkAPI::glk_image_draw(winid_t win, const Graphics::Surface &image, uint transColor,
+ int xp, int yp) {
+ if (!win) {
+ warning("image_draw: invalid ref");
+ } else if (g_conf->_graphics) {
+ GraphicsWindow *gfxWin = dynamic_cast<GraphicsWindow *>(win);
+
+ if (gfxWin)
+ gfxWin->drawPicture(image, 0xff, xp, yp, 0, 0);
+ }
+
+ return true;
+}
+
+bool GlkAPI::glk_image_draw_scaled(winid_t win, const Graphics::Surface &image, uint transColor,
+ int xp, int yp, uint width, uint height) {
+ if (!win) {
+ warning("image_draw_scaled: invalid ref");
+ } else if (g_conf->_graphics) {
+ GraphicsWindow *gfxWin = dynamic_cast<GraphicsWindow *>(win);
+
+ Graphics::ManagedSurface s(width, height);
+ s.clear(transColor);
+ s.transBlitFrom(image, Common::Rect(0, 0, image.w, image.h),
+ Common::Rect(0, 0, width, height), transColor);
+
+ if (gfxWin)
+ gfxWin->drawPicture(s, transColor, xp, yp, s.w, s.h);
+ }
+
+ return true;
+}
+
bool GlkAPI::glk_image_get_info(uint image, uint *width, uint *height) {
if (!g_conf->_graphics)
return false;
diff --git a/engines/glk/glk_api.h b/engines/glk/glk_api.h
index 6ddeb47a7f..a0efb30a6a 100644
--- a/engines/glk/glk_api.h
+++ b/engines/glk/glk_api.h
@@ -198,7 +198,12 @@ public:
bool glk_image_draw(winid_t win, uint image, int val1, int val2);
bool glk_image_draw_scaled(winid_t win, uint image,
- int val1, int val2, uint width, uint height);
+ int val1, int val2, uint width, uint height);
+ bool glk_image_draw(winid_t win, const Graphics::Surface &image, uint transColor = (uint)-1,
+ int xp = 0, int yp = 0);
+ bool glk_image_draw_scaled(winid_t win, const Graphics::Surface &image, uint transColor,
+ int xp, int yp, uint width, uint height);
+
bool glk_image_get_info(uint image, uint *width, uint *height);
void glk_window_flow_break(winid_t win);
diff --git a/engines/glk/level9/level9.cpp b/engines/glk/level9/level9.cpp
index be4ac2216d..7fe85ee485 100644
--- a/engines/glk/level9/level9.cpp
+++ b/engines/glk/level9/level9.cpp
@@ -36,7 +36,6 @@ Level9::Level9(OSystem *syst, const GlkGameDescription &gameDesc) : GlkAPI(syst,
void Level9::runGame() {
initialize();
-
_gameFile.close();
gln_main(getFilename().c_str());
@@ -44,6 +43,7 @@ void Level9::runGame() {
}
bool Level9::initialize() {
+ gln_initialize();
return gln_startup_code(0, nullptr);
}
diff --git a/engines/glk/level9/os_glk.cpp b/engines/glk/level9/os_glk.cpp
index 8c97c5ca38..b2ac4ac727 100644
--- a/engines/glk/level9/os_glk.cpp
+++ b/engines/glk/level9/os_glk.cpp
@@ -1984,21 +1984,23 @@ break_y_max:
}
#endif
-static void gln_graphics_paint_everything(winid_t glk_window, glui32 palette[],
+static void gln_graphics_paint_everything(winid_t glk_window, Colour palette[],
gln_byte off_screen[], int x_offset, int y_offset, gln_uint16 width, gln_uint16 height) {
- gln_byte pixel; /* Reference pixel color */
- int x, y;
-
- for (y = 0; y < height; y++) {
- for (x = 0; x < width; x ++) {
- pixel = off_screen[ y * width + x ];
- g_vm->glk_window_fill_rect(glk_window,
- palette[ pixel ],
- x * GLN_GRAPHICS_PIXEL + x_offset,
- y * GLN_GRAPHICS_PIXEL + y_offset,
- GLN_GRAPHICS_PIXEL, GLN_GRAPHICS_PIXEL);
+ Graphics::PixelFormat format(4, 8, 8, 8, 8, 24, 16, 8, 0);
+ Graphics::ManagedSurface s(width, height, format);
+
+ for (int y = 0; y < height; ++y) {
+ uint32 *lineP = (uint32 *)s.getBasePtr(0, y);
+ for (int x = 0; x < width; ++x, ++lineP) {
+ byte pixel = off_screen[y * width + x];
+ assert(pixel < GLN_PALETTE_SIZE);
+ const Colour &col = palette[pixel];
+
+ *lineP = format.RGBToColor(col.red, col.green, col.blue);
}
}
+
+ g_vm->glk_image_draw(glk_window, s, (uint)-1, x_offset, y_offset);
}
/*
@@ -2260,12 +2262,8 @@ static void gln_graphics_timeout() {
total_regions += regions;
#else
- gln_graphics_paint_everything
- (gln_graphics_window,
- palette, off_screen,
- x_offset, y_offset,
- gln_graphics_width,
- gln_graphics_height);
+ gln_graphics_paint_everything(gln_graphics_window, gln_graphics_palette, off_screen,
+ x_offset, y_offset, gln_graphics_width, gln_graphics_height);
#endif
/* Stop graphics; there's no more to be done until something restarts us. */
diff --git a/engines/glk/window_graphics.cpp b/engines/glk/window_graphics.cpp
index 572d8d983e..f9fd43a878 100644
--- a/engines/glk/window_graphics.cpp
+++ b/engines/glk/window_graphics.cpp
@@ -96,7 +96,7 @@ void GraphicsWindow::redraw() {
}
}
-uint GraphicsWindow::drawPicture(uint image, int xpos, int ypos, int scale,
+bool GraphicsWindow::drawPicture(uint image, int xpos, int ypos, bool scale,
uint imagewidth, uint imageheight) {
Picture *pic = g_vm->_pictures->load(image);
uint hyperlink = _attr.hyper;
@@ -177,26 +177,31 @@ void GraphicsWindow::fillRect(uint color, const Rect &box) {
touch();
}
-void GraphicsWindow::drawPicture(Picture *src, int x0, int y0, int width, int height, uint linkval) {
- int dx1, dy1, x1, y1, sx0, sy0, sx1, sy1;
- int hx0, hx1, hy0, hy1;
- int w, h;
-
+void GraphicsWindow::drawPicture(Picture *src, int x0, int y0, int width, int height, uint linkval) {
if (width != src->w || height != src->h) {
src = g_vm->_pictures->scale(src, width, height);
if (!src)
return;
}
+ drawPicture(*src, src->getTransparentColor(), x0, y0, width, height, linkval);
+}
+
+void GraphicsWindow::drawPicture(const Graphics::Surface &image, uint transColor, int x0, int y0,
+ int width, int height, uint linkval) {
+ int dx1, dy1, x1, y1, sx0, sy0, sx1, sy1;
+ int hx0, hx1, hy0, hy1;
+ int w, h;
+
sx0 = 0;
sy0 = 0;
- sx1 = src->w;
- sy1 = src->h;
+ sx1 = image.w;
+ sy1 = image.h;
dx1 = _w;
dy1 = _h;
- x1 = x0 + src->w;
- y1 = y0 + src->h;
+ x1 = x0 + image.w;
+ y1 = y0 + image.h;
if (x1 <= 0 || x0 >= dx1) return;
if (y1 <= 0 || y0 >= dy1) return;
@@ -228,7 +233,7 @@ void GraphicsWindow::drawPicture(Picture *src, int x0, int y0, int width, int h
w = sx1 - sx0;
h = sy1 - sy0;
- _surface->transBlitFrom(*src, Rect(sx0, sy0, sx0 + w, sy0 + h), Point(x0, y0), src->getTransparentColor());
+ _surface->transBlitFrom(image, Rect(sx0, sy0, sx0 + w, sy0 + h), Point(x0, y0), transColor);
}
void GraphicsWindow::getSize(uint *width, uint *height) const {
diff --git a/engines/glk/window_graphics.h b/engines/glk/window_graphics.h
index a3fe6db856..59b1ce44e3 100644
--- a/engines/glk/window_graphics.h
+++ b/engines/glk/window_graphics.h
@@ -52,8 +52,10 @@ public:
*/
virtual ~GraphicsWindow();
- uint drawPicture(uint image, int xpos, int ypos, int scale,
+ bool drawPicture(uint image, int xpos, int ypos, bool scale,
uint imagewidth, uint imageheight);
+ void drawPicture(const Graphics::Surface &image, uint transColor, int x0, int y0,
+ int width, int height, uint linkval = 0);
/**
* Rearranges the window