From 4126001b861aa6abd1633ae42b7b259ad646df9c Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 30 Oct 2004 22:34:08 +0000 Subject: Turn some methods into functions (potentially gives better code, and we may want to move some of those into the graphics/ module one day) svn-id: r15703 --- saga/actionmap.cpp | 6 +++--- saga/console.cpp | 2 +- saga/events.cpp | 2 +- saga/gfx.cpp | 45 ++++++++++----------------------------------- saga/gfx.h | 25 +++++++++++++------------ saga/interface.cpp | 8 ++++---- saga/isomap.cpp | 2 +- saga/objectmap.cpp | 6 +++--- saga/render.cpp | 2 +- saga/scene.cpp | 2 +- saga/sprite.cpp | 2 +- 11 files changed, 39 insertions(+), 63 deletions(-) (limited to 'saga') diff --git a/saga/actionmap.cpp b/saga/actionmap.cpp index c424743728..c5b4e945eb 100644 --- a/saga/actionmap.cpp +++ b/saga/actionmap.cpp @@ -147,7 +147,7 @@ int ActionMap::hitTest(const Point& imouse) { } } else if (n_points > 2) { // Hit-test a polygon - if (_vm->_gfx->hitTestPoly(points, n_points, imouse)) { + if (hitTestPoly(points, n_points, imouse)) { return i; } } @@ -170,10 +170,10 @@ int ActionMap::draw(SURFACE *ds, int color) { clickarea = &exmap_entry->clickareas[k]; if (clickarea->n_points == 2) { // 2 points represent a box - _vm->_gfx->drawFrame(ds, &clickarea->points[0], &clickarea->points[1], color); + drawFrame(ds, &clickarea->points[0], &clickarea->points[1], color); } else if (clickarea->n_points > 2) { // Otherwise draw a polyline - _vm->_gfx->drawPolyLine(ds, clickarea->points, clickarea->n_points, color); + drawPolyLine(ds, clickarea->points, clickarea->n_points, color); } } } diff --git a/saga/console.cpp b/saga/console.cpp index f626443395..a22e9aa1ea 100644 --- a/saga/console.cpp +++ b/saga/console.cpp @@ -208,7 +208,7 @@ int Console::draw(SURFACE *ds) { fill_rect.bottom = _yPos + 1; fill_rect.right = ds->w; - _vm->_gfx->drawRect(ds, &fill_rect, _vm->_gfx->matchColor(CONSOLE_BGCOLOR)); + drawRect(ds, &fill_rect, _vm->_gfx->matchColor(CONSOLE_BGCOLOR)); txt_fgcolor = _vm->_gfx->matchColor(CONSOLE_TXTCOLOR); txt_shcolor = _vm->_gfx->matchColor(CONSOLE_TXTSHADOW); diff --git a/saga/events.cpp b/saga/events.cpp index 9d28c8ea72..b1ee1bdfcd 100644 --- a/saga/events.cpp +++ b/saga/events.cpp @@ -332,7 +332,7 @@ int Events::handleOneShot(EVENT *event) { bg_pt.x = bginfo.bg_x; bg_pt.y = bginfo.bg_y; - _vm->_gfx->bufToBuffer(rbuf_info.bg_buf, rbuf_info.bg_buf_w, rbuf_info.bg_buf_h, + bufToBuffer(rbuf_info.bg_buf, rbuf_info.bg_buf_w, rbuf_info.bg_buf_h, bginfo.bg_buf, bginfo.bg_w, bginfo.bg_h, NULL, &bg_pt); if (event->param == SET_PALETTE) { PALENTRY *pal_p; diff --git a/saga/gfx.cpp b/saga/gfx.cpp index 4cb679625c..ab3342e8f2 100644 --- a/saga/gfx.cpp +++ b/saga/gfx.cpp @@ -70,7 +70,7 @@ Gfx::Gfx(OSystem *system, int width, int height) { } */ -int Gfx::drawPalette(SURFACE *dst_s) { +int drawPalette(SURFACE *dst_s) { int x; int y; int color = 0; @@ -93,31 +93,6 @@ int Gfx::drawPalette(SURFACE *dst_s) { return 0; } -int Gfx::simpleBlit(SURFACE *dst_s, SURFACE *src_s) { - byte *src_p; - byte *dst_p; - int y, w, p; - - assert((dst_s != NULL) && (src_s != NULL)); - assert(dst_s->w == src_s->w); - assert(dst_s->h == src_s->h); - - src_p = (byte *)src_s->pixels; - dst_p = (byte *)dst_s->pixels; - - w = src_s->w; - p = src_s->pitch; - - for (y = 0; y < src_s->h; y++) { - memcpy(dst_p, src_p, w); - - dst_p += p; - src_p += p; - } - - return SUCCESS; -} - // TODO: I've fixed at least one clipping bug here, but I have a feeling there // are several more. @@ -130,7 +105,7 @@ int Gfx::simpleBlit(SURFACE *dst_s, SURFACE *src_s) { // - If src_rect is NULL, the entire buffer is copied./ // - The surface must match the logical dimensions of the buffer exactly. // - Returns FAILURE on error -int Gfx::bufToSurface(SURFACE *ds, const byte *src, int src_w, int src_h, +int bufToSurface(SURFACE *ds, const byte *src, int src_w, int src_h, Rect *src_rect, Point *dst_pt) { const byte *read_p; byte *write_p; @@ -256,7 +231,7 @@ int Gfx::bufToSurface(SURFACE *ds, const byte *src, int src_w, int src_h, return SUCCESS; } -int Gfx::bufToBuffer(byte *dst_buf, int dst_w, int dst_h, const byte *src, +int bufToBuffer(byte *dst_buf, int dst_w, int dst_h, const byte *src, int src_w, int src_h, Rect *src_rect, Point *dst_pt) { const byte *read_p; byte *write_p; @@ -378,7 +353,7 @@ int Gfx::bufToBuffer(byte *dst_buf, int dst_w, int dst_h, const byte *src, // Fills a rectangle in the surface ds from point 'p1' to point 'p2' using // the specified color. -int Gfx::drawRect(SURFACE *ds, Rect *dst_rect, int color) { +int drawRect(SURFACE *ds, Rect *dst_rect, int color) { byte *write_p; int w; @@ -418,7 +393,7 @@ int Gfx::drawRect(SURFACE *ds, Rect *dst_rect, int color) { return SUCCESS; } -int Gfx::drawFrame(SURFACE *ds, const Point *p1, const Point *p2, int color) { +int drawFrame(SURFACE *ds, const Point *p1, const Point *p2, int color) { int left, top, right, bottom; int min_x; @@ -460,7 +435,7 @@ int Gfx::drawFrame(SURFACE *ds, const Point *p1, const Point *p2, int color) { return SUCCESS; } -int Gfx::drawPolyLine(SURFACE *ds, const Point *pts, int pt_ct, int draw_color) { +int drawPolyLine(SURFACE *ds, const Point *pts, int pt_ct, int draw_color) { const Point *first_pt = pts; int last_i = 1; int i; @@ -481,7 +456,7 @@ int Gfx::drawPolyLine(SURFACE *ds, const Point *pts, int pt_ct, int draw_color) return SUCCESS; } -int Gfx::getClipInfo(CLIPINFO *clipinfo) { +int getClipInfo(CLIPINFO *clipinfo) { Common::Rect s; int d_x, d_y; @@ -565,7 +540,7 @@ int Gfx::getClipInfo(CLIPINFO *clipinfo) { return SUCCESS; } -int Gfx::clipLine(SURFACE *ds, const Point *src_p1, const Point *src_p2, +int clipLine(SURFACE *ds, const Point *src_p1, const Point *src_p2, Point *dst_p1, Point *dst_p2) { const Point *n_p1; const Point *n_p2; @@ -637,7 +612,7 @@ int Gfx::clipLine(SURFACE *ds, const Point *src_p1, const Point *src_p2, // Coriolis Group Books, 1997 // // Performs no clipping -void Gfx::drawLine(SURFACE *ds, const Point *p1, const Point *p2, int color) { +void drawLine(SURFACE *ds, const Point *p1, const Point *p2, int color) { byte *write_p; int clip_result; int temp; @@ -1079,7 +1054,7 @@ void Gfx::setCursor(int best_white) { _system->setMouseCursor(cursor_img, CURSOR_W, CURSOR_H, 4, 4, keycolor); } -bool Gfx::hitTestPoly(const Point *points, unsigned int npoints, const Point& test_point) { +bool hitTestPoly(const Point *points, unsigned int npoints, const Point& test_point) { int yflag0; int yflag1; bool inside_flag = false; diff --git a/saga/gfx.h b/saga/gfx.h index b99881d0c9..3adb33243f 100644 --- a/saga/gfx.h +++ b/saga/gfx.h @@ -82,19 +82,21 @@ struct SURFACE : Graphics::Surface { #define GREEN_WEIGHT 0.587 #define BLUE_WEIGHT 0.114 +int drawPalette(SURFACE *dst_s); +int bufToSurface(SURFACE *ds, const byte *src, int src_w, int src_h, Rect *src_rect, Point *dst_pt); +int bufToBuffer(byte * dst_buf, int dst_w, int dst_h, const byte *src, + int src_w, int src_h, Rect *src_rect, Point *dst_pt); +int getClipInfo(CLIPINFO *clipinfo); +int drawRect(SURFACE *ds, Rect *dst_rect, int color); +int drawFrame(SURFACE *ds, const Point *p1, const Point *p2, int color); +int drawPolyLine(SURFACE *ds, const Point *pts, int pt_ct, int draw_color); +int clipLine(SURFACE *ds, const Point *src_p1, const Point *src_p2, Point *dst_p1, Point *dst_p2); +void drawLine(SURFACE * ds, const Point *p1, const Point *p2, int color); + +bool hitTestPoly(const Point *points, unsigned int npoints, const Point& test_point); + class Gfx { public: - int simpleBlit(SURFACE *dst_s, SURFACE *src_s); - int drawPalette(SURFACE *dst_s); - int bufToSurface(SURFACE *ds, const byte *src, int src_w, int src_h, Rect *src_rect, Point *dst_pt); - int bufToBuffer(byte * dst_buf, int dst_w, int dst_h, const byte *src, - int src_w, int src_h, Rect *src_rect, Point *dst_pt); - int drawRect(SURFACE *ds, Rect *dst_rect, int color); - int drawFrame(SURFACE *ds, const Point *p1, const Point *p2, int color); - int drawPolyLine(SURFACE *ds, const Point *pts, int pt_ct, int draw_color); - int getClipInfo(CLIPINFO *clipinfo); - int clipLine(SURFACE *ds, const Point *src_p1, const Point *src_p2, Point *dst_p1, Point *dst_p2); - void drawLine(SURFACE * ds, const Point *p1, const Point *p2, int color); Gfx(OSystem *system, int width, int height); SURFACE *getBackBuffer(); @@ -105,7 +107,6 @@ public: int getCurrentPal(PALENTRY *src_pal); int palToBlack(SURFACE *surface, PALENTRY *src_pal, double percent); int blackToPal(SURFACE *surface, PALENTRY *src_pal, double percent); - bool hitTestPoly(const Point *points, unsigned int npoints, const Point& test_point); private: void setCursor(int best_white); diff --git a/saga/interface.cpp b/saga/interface.cpp index 420ec11986..fb6c550606 100644 --- a/saga/interface.cpp +++ b/saga/interface.cpp @@ -308,7 +308,7 @@ int Interface::draw() { rect.right = g_di.logical_w; rect.bottom = _iDesc.status_y + _iDesc.status_h; - _vm->_gfx->drawRect(back_buf, &rect, _iDesc.status_bgcol); + drawRect(back_buf, &rect, _iDesc.status_bgcol); // Draw command panel background if (_panelMode == kPanelCommand) { @@ -318,7 +318,7 @@ int Interface::draw() { origin.x = 0; origin.y = g_di.logical_h - _cPanel.img_h; - _vm->_gfx->bufToSurface(back_buf, _cPanel.img, _cPanel.img_w, + bufToSurface(back_buf, _cPanel.img, _cPanel.img_w, _cPanel.img_h, NULL, &origin); } else { xbase = _dPanel.x; @@ -327,7 +327,7 @@ int Interface::draw() { origin.x = 0; origin.y = g_di.logical_h - _cPanel.img_h; - _vm->_gfx->bufToSurface(back_buf, _dPanel.img, _dPanel.img_w, + bufToSurface(back_buf, _dPanel.img, _dPanel.img_w, _dPanel.img_h, NULL, &origin); } @@ -405,7 +405,7 @@ int Interface::drawStatusBar(SURFACE *ds) { rect.right = g_di.logical_w; rect.bottom = _iDesc.status_y + _iDesc.status_h; - _vm->_gfx->drawRect(ds, &rect, _iDesc.status_bgcol); + drawRect(ds, &rect, _iDesc.status_bgcol); string_w = _vm->_font->getStringWidth(SMALL_FONT_ID, _statusText, 0, 0); diff --git a/saga/isomap.cpp b/saga/isomap.cpp index 8fbf46ea56..8b8397812b 100644 --- a/saga/isomap.cpp +++ b/saga/isomap.cpp @@ -135,7 +135,7 @@ int IsoMap::draw(SURFACE *dst_s) { GAME_DISPLAYINFO disp_info; GAME_GetDisplayInfo(&disp_info); Rect iso_rect(disp_info.logical_w, disp_info.scene_h); - _gfx->drawRect(dst_s, &iso_rect, 0); + drawRect(dst_s, &iso_rect, 0); drawMetamap(dst_s, -1000, -500); return SUCCESS; diff --git a/saga/objectmap.cpp b/saga/objectmap.cpp index c959256160..32d377d45f 100644 --- a/saga/objectmap.cpp +++ b/saga/objectmap.cpp @@ -285,10 +285,10 @@ int ObjectMap::draw(SURFACE *ds, const Point& imousePt, int color, int color2) { clickarea = &object_map->clickareas[k]; if (clickarea->n_points == 2) { // 2 points represent a box - _vm->_gfx->drawFrame(ds, &clickarea->points[0], &clickarea->points[1], draw_color); + drawFrame(ds, &clickarea->points[0], &clickarea->points[1], draw_color); } else if (clickarea->n_points > 2) { // Otherwise draw a polyline - _vm->_gfx->drawPolyLine(ds, clickarea->points, clickarea->n_points, draw_color); + drawPolyLine(ds, clickarea->points, clickarea->n_points, draw_color); } } } @@ -332,7 +332,7 @@ int ObjectMap::hitTest(const Point& imousePt) { } } else if (n_points > 2) { // Hit-test a polygon - if (_vm->_gfx->hitTestPoly(points, n_points, imouse)) { + if (hitTestPoly(points, n_points, imouse)) { return object_map->objectNum; } } diff --git a/saga/render.cpp b/saga/render.cpp index 819fdecfb7..c015329b0b 100644 --- a/saga/render.cpp +++ b/saga/render.cpp @@ -179,7 +179,7 @@ int Render::drawScene() { // Display palette test, if applicable if (_flags & RF_PALETTE_TEST) { - _vm->_gfx->drawPalette(backbuf_surface); + drawPalette(backbuf_surface); } // Draw console diff --git a/saga/scene.cpp b/saga/scene.cpp index d03a67d1fe..bccc198b5c 100644 --- a/saga/scene.cpp +++ b/saga/scene.cpp @@ -822,7 +822,7 @@ int Scene::draw(SURFACE *dst_s) { switch (_sceneMode) { case SCENE_MODE_NORMAL: - _vm->_gfx->bufToSurface(dst_s, buf_info.bg_buf, disp_info.logical_w, + bufToSurface(dst_s, buf_info.bg_buf, disp_info.logical_w, MAX(disp_info.scene_h, _bg.h), NULL, &bg_pt); break; case SCENE_MODE_ISO: diff --git a/saga/sprite.cpp b/saga/sprite.cpp index 44df015a91..102b2360f8 100644 --- a/saga/sprite.cpp +++ b/saga/sprite.cpp @@ -349,7 +349,7 @@ int Sprite::drawOccluded(SURFACE *ds, SPRITELIST *sprite_list, int sprite_num, i ci.src_rect = &spr_src_rect; ci.dst_pt = &spr_pt; - _vm->_gfx->getClipInfo(&ci); + getClipInfo(&ci); if (ci.nodraw) { return SUCCESS; -- cgit v1.2.3