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
This commit is contained in:
Max Horn 2004-10-30 22:34:08 +00:00
parent 06c46fe423
commit 4126001b86
11 changed files with 39 additions and 63 deletions

View file

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

View file

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

View file

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

View file

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

View file

@ -82,20 +82,22 @@ struct SURFACE : Graphics::Surface {
#define GREEN_WEIGHT 0.587
#define BLUE_WEIGHT 0.114
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 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 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);
bool hitTestPoly(const Point *points, unsigned int npoints, const Point& test_point);
class Gfx {
public:
Gfx(OSystem *system, int width, int height);
SURFACE *getBackBuffer();
int getWhite();
@ -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);

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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