GLK: LEVEL9: Title screen graphics now showing

This commit is contained in:
Paul Gilbert 2019-10-24 20:25:24 -07:00
parent fa323c6187
commit 07c8437e26
6 changed files with 74 additions and 31 deletions

View file

@ -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;

View file

@ -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);

View file

@ -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);
}

View file

@ -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;
Graphics::PixelFormat format(4, 8, 8, 8, 8, 24, 16, 8, 0);
Graphics::ManagedSurface s(width, height, format);
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);
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. */

View file

@ -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 {

View file

@ -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