Added some graphic primitives
svn-id: r15885
This commit is contained in:
parent
e79e0dec74
commit
f5da05f80d
3 changed files with 136 additions and 1 deletions
|
@ -3,8 +3,9 @@ MODULE := graphics
|
|||
MODULE_OBJS := \
|
||||
graphics/animation.o \
|
||||
graphics/font.o \
|
||||
graphics/newfont.o \
|
||||
graphics/scummfont.o \
|
||||
graphics/newfont.o
|
||||
graphics/surface.o
|
||||
|
||||
MODULE_DIRS += \
|
||||
graphics
|
||||
|
|
124
graphics/surface.cpp
Normal file
124
graphics/surface.cpp
Normal file
|
@ -0,0 +1,124 @@
|
|||
/* ScummVM - Scumm Interpreter
|
||||
* Copyright (C) 2002-2004 The ScummVM project
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* $Header$
|
||||
*/
|
||||
|
||||
#include "common/stdafx.h"
|
||||
#include "common/util.h"
|
||||
#include "graphics/surface.h"
|
||||
|
||||
namespace Graphics {
|
||||
|
||||
void Surface::hLine(int x, int y, int x2, uint32 color) const {
|
||||
// Clipping
|
||||
if (y < 0 || y >= h)
|
||||
return;
|
||||
|
||||
if (x2 < x)
|
||||
SWAP(x2, x);
|
||||
|
||||
if (x < 0)
|
||||
x = 0;
|
||||
if (x2 >= w)
|
||||
x2 = w - 1;
|
||||
|
||||
if (bytesPerPixel == 1) {
|
||||
byte *ptr = (byte *)getBasePtr(x, y);
|
||||
while (x++ <= x2) {
|
||||
*ptr++ = (byte)color;
|
||||
}
|
||||
} else if (bytesPerPixel == 2) {
|
||||
uint16 *ptr = (uint16 *)getBasePtr(x, y);
|
||||
while (x++ <= x2) {
|
||||
*ptr++ = (uint16)color;
|
||||
}
|
||||
} else {
|
||||
error("Surface::hLine: bytesPerPixel must be 1 or 2");
|
||||
}
|
||||
}
|
||||
|
||||
void Surface::vLine(int x, int y, int y2, uint32 color) const {
|
||||
// Clipping
|
||||
if (x < 0 || x >= w)
|
||||
return;
|
||||
|
||||
if (y2 < y)
|
||||
SWAP(y2, y);
|
||||
|
||||
if (y < 0)
|
||||
y = 0;
|
||||
if (y2 >= h)
|
||||
y2 = h - 1;
|
||||
|
||||
if (bytesPerPixel == 1) {
|
||||
byte *ptr = (byte *)getBasePtr(x, y);
|
||||
while (y++ <= y2) {
|
||||
*ptr = (byte)color;
|
||||
ptr += pitch;
|
||||
}
|
||||
} else if (bytesPerPixel == 2) {
|
||||
uint16 *ptr = (uint16 *)getBasePtr(x, y);
|
||||
while (y++ <= y2) {
|
||||
*ptr = (uint16)color;
|
||||
ptr += pitch/2;
|
||||
}
|
||||
} else {
|
||||
error("Surface::vLine: bytesPerPixel must be 1 or 2");
|
||||
}
|
||||
}
|
||||
|
||||
void Surface::fillRect(const Common::Rect &rOld, uint32 color) const {
|
||||
Common::Rect r(rOld);
|
||||
r.clip(w, h);
|
||||
|
||||
if (!r.isValidRect())
|
||||
return;
|
||||
|
||||
int width = r.width();
|
||||
int height = r.height();
|
||||
int i;
|
||||
|
||||
if (bytesPerPixel == 1) {
|
||||
byte *ptr = (byte *)getBasePtr(r.left, r.top);
|
||||
while (height--) {
|
||||
for (i = 0; i < width; i++) {
|
||||
ptr[i] = (byte)color;
|
||||
}
|
||||
ptr += pitch;
|
||||
}
|
||||
} else if (bytesPerPixel == 2) {
|
||||
uint16 *ptr = (uint16 *)getBasePtr(r.left, r.top);
|
||||
while (height--) {
|
||||
for (i = 0; i < width; i++) {
|
||||
ptr[i] = (uint16)color;
|
||||
}
|
||||
ptr += pitch/2;
|
||||
}
|
||||
} else {
|
||||
error("Surface::vLine: bytesPerPixel must be 1 or 2");
|
||||
}
|
||||
}
|
||||
|
||||
void Surface::frameRect(const Common::Rect &r, uint32 color) const {
|
||||
hLine(r.left, r.top, r.right-1, color);
|
||||
hLine(r.left, r.bottom-1, r.right-1, color);
|
||||
vLine(r.left, r.top, r.bottom-1, color);
|
||||
vLine(r.right-1, r.top, r.bottom-1, color);
|
||||
}
|
||||
|
||||
} // End of namespace Graphics
|
|
@ -22,6 +22,7 @@
|
|||
#define GRAPHICS_SURFACE_H
|
||||
|
||||
#include "common/scummsys.h"
|
||||
#include "common/rect.h"
|
||||
|
||||
namespace Graphics {
|
||||
|
||||
|
@ -37,6 +38,15 @@ struct Surface {
|
|||
uint16 pitch;
|
||||
uint8 bytesPerPixel;
|
||||
Surface() : pixels(0), w(0), h(0), pitch(0), bytesPerPixel(0) {}
|
||||
|
||||
inline void *getBasePtr(int x, int y) const {
|
||||
return (void *)((byte *)pixels + y * pitch + x * bytesPerPixel);
|
||||
}
|
||||
|
||||
void hLine(int x, int y, int x2, uint32 color) const;
|
||||
void vLine(int x, int y, int y2, uint32 color) const;
|
||||
void fillRect(const Common::Rect &r, uint32 color) const;
|
||||
void frameRect(const Common::Rect &r, uint32 color) const;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue