diff options
author | Eugenio Favalli <elvenprogrammer@gmail.com> | 2004-12-11 18:08:13 +0000 |
---|---|---|
committer | Eugenio Favalli <elvenprogrammer@gmail.com> | 2004-12-11 18:08:13 +0000 |
commit | b6aca4910aa14cdc7bfe5de07baf3d0548e8ae6f (patch) | |
tree | 97e8aea3ef42629f06bba5fa0925d6aad6e73fe2 /src | |
parent | 82ec93208d55e5f4531034c49b74179c9810cc8f (diff) | |
download | mana-client-b6aca4910aa14cdc7bfe5de07baf3d0548e8ae6f.tar.gz mana-client-b6aca4910aa14cdc7bfe5de07baf3d0548e8ae6f.tar.bz2 mana-client-b6aca4910aa14cdc7bfe5de07baf3d0548e8ae6f.tar.xz mana-client-b6aca4910aa14cdc7bfe5de07baf3d0548e8ae6f.zip |
Core sprite classes of the new graphic engine
Diffstat (limited to 'src')
-rw-r--r-- | src/graphic/image.h | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/src/graphic/image.h b/src/graphic/image.h new file mode 100644 index 00000000..f4e5fc5d --- /dev/null +++ b/src/graphic/image.h @@ -0,0 +1,90 @@ +#ifndef _IMAGE_H +#define _IMAGE_H + +#include <string> +#include <vector> +#include <iostream> +#include <allegro.h> +#include "../log.h" +using namespace std; + +class IMAGE { + protected: + int offset_x, offset_y; + public: + IMAGE(int offset_x, int offset_y) { + this->offset_x = offset_x; + this->offset_y = offset_y; + } + virtual void draw(BITMAP *dest, int x, int y) = 0; +}; + +class RLE_IMAGE : public IMAGE { + private: + RLE_SPRITE *src; + public: + RLE_IMAGE(RLE_SPRITE *src, int offset_x, int offset_y) : IMAGE(offset_x, offset_y) { + this->src = src; + } + ~RLE_IMAGE() { + destroy_rle_sprite(src); + } + void draw(BITMAP *dest, int x, int y) { + draw_rle_sprite(dest, src, x+offset_x, y+offset_y); + } +}; + +class VIDEO_IMAGE : public IMAGE { + private: + BITMAP *src; + public: + VIDEO_IMAGE(BITMAP *src, int offset_x, int offset_y) : IMAGE(offset_x, offset_y) { + this->src = src; + } + ~VIDEO_IMAGE() { + destroy_bitmap(src); + } + void draw(BITMAP *dest, int x, int y) { + masked_blit(src, dest, 0, 0, x+offset_x, y+offset_y, src->w, src->h); + } +}; + +class SPRITESET { + private: + int get_property(DATAFILE *datafile, int type) { + return atoi(get_datafile_property(datafile, type)); + } + public: + vector<IMAGE *> spriteset; + + SPRITESET(string filename) { + DATAFILE *datafile = load_datafile(filename.c_str()); + if(!datafile)error("Unable to load graphic file: " + filename); + int i = 0; + while(datafile[i].type!=DAT_END) { + IMAGE *temp_image; + if(gfx_capabilities & GFX_HW_VRAM_BLIT) { + BITMAP *temp_video_bitmap = create_video_bitmap(((RLE_SPRITE *)datafile[i].dat)->w, ((RLE_SPRITE *)datafile[i].dat)->h); + if(temp_video_bitmap) { + clear_to_color(temp_video_bitmap, makecol(255,0,255)); + draw_rle_sprite(temp_video_bitmap, (RLE_SPRITE *)datafile[i].dat, 0, 0); + temp_image = new VIDEO_IMAGE(temp_video_bitmap, get_property(&datafile[i], DAT_ID('X','C','R','P')), get_property(&datafile[i], DAT_ID('Y','C','R','P'))); + } else { + warning("You run out of video memory"); + RLE_SPRITE *temp_rle_sprite = (RLE_SPRITE *)malloc(datafile[i].size); + memcpy(temp_rle_sprite, datafile[i].dat, datafile[i].size); + temp_image = new RLE_IMAGE(temp_rle_sprite, get_property(&datafile[i], DAT_ID('X','C','R','P')), get_property(&datafile[i], DAT_ID('Y','C','R','P'))); + } + } else { + RLE_SPRITE *temp_rle_sprite = (RLE_SPRITE *)malloc(datafile[i].size); + memcpy(temp_rle_sprite, datafile[i].dat, datafile[i].size); + temp_image = new RLE_IMAGE(temp_rle_sprite, get_property(&datafile[i], DAT_ID('X','C','R','P')), get_property(&datafile[i], DAT_ID('Y','C','R','P'))); + } + spriteset.push_back(temp_image); + i++; + } + unload_datafile(datafile); + } +}; + +#endif |