truelight@6937: /* $Id$ */ truelight@6937: truelight@6937: #ifndef BLITTER_BASE_HPP truelight@6937: #define BLITTER_BASE_HPP truelight@6937: truelight@6937: #include "../spritecache.h" truelight@6937: #include "../spriteloader/spriteloader.hpp" truelight@6937: truelight@6937: enum BlitterMode { truelight@6937: BM_NORMAL, truelight@6937: BM_COLOUR_REMAP, truelight@6937: BM_TRANSPARENT, truelight@6937: }; truelight@6937: truelight@6937: /** truelight@6937: * How all blitters should look like. Extend this class to make your own. truelight@6937: */ truelight@6937: class Blitter { truelight@6937: public: truelight@6937: struct BlitterParams { truelight@6937: const void *sprite; ///< Pointer to the sprite how ever the encoder stored it truelight@6937: const byte *remap; ///< XXX -- Temporary storage for remap array truelight@6937: truelight@6937: int skip_left, skip_top; ///< How much pixels of the source to skip on the left and top (based on zoom of dst) truelight@6937: int width, height; ///< The width and height in pixels that needs to be drawn to dst truelight@6937: int sprite_width; ///< Real width of the sprite truelight@6937: int sprite_height; ///< Real height of the sprite truelight@6937: int left, top; ///< The offset in the 'dst' in pixels to start drawing truelight@6937: truelight@6937: void *dst; ///< Destination buffer truelight@6937: int pitch; ///< The pitch of the destination buffer truelight@6937: }; truelight@6937: truelight@6960: enum PaletteAnimation { truelight@6960: PALETTE_ANIMATION_NONE, ///< No palette animation truelight@6960: PALETTE_ANIMATION_VIDEO_BACKEND, ///< Palette animation should be done by video backend (8bpp only!) truelight@6960: PALETTE_ANIMATION_BLITTER, ///< The blitter takes care of the palette animation truelight@6960: }; truelight@6960: truelight@6937: typedef void *AllocatorProc(size_t size); truelight@6937: truelight@6937: /** truelight@6937: * Get the screen depth this blitter works for. truelight@6937: * This is either: 8, 16, 24 or 32. truelight@6937: */ truelight@6937: virtual uint8 GetScreenDepth() = 0; truelight@6937: truelight@6937: /** truelight@6937: * Draw an image to the screen, given an amount of params defined above. truelight@6937: */ truelight@6937: virtual void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) = 0; truelight@6937: truelight@6937: /** truelight@6937: * Draw a colortable to the screen. This is: the color of the screen is read truelight@6937: * and is looked-up in the palette to match a new color, which then is put truelight@6937: * on the screen again. truelight@6937: * @param dst the destination pointer (video-buffer). truelight@6937: * @param width the width of the buffer. truelight@6937: * @param height the height of the buffer. truelight@6937: * @param pal the palette to use. truelight@6937: */ truelight@6937: virtual void DrawColorMappingRect(void *dst, int width, int height, int pal) = 0; truelight@6937: truelight@6937: /** truelight@6937: * Convert a sprite from the loader to our own format. truelight@6937: */ truelight@6937: virtual Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator) = 0; truelight@6937: truelight@6937: /** truelight@6937: * Move the destination pointer the requested amount x and y, keeping in mind truelight@6937: * any pitch and bpp of the renderer. truelight@6937: * @param video The destination pointer (video-buffer) to scroll. truelight@6937: * @param x How much you want to scroll to the right. truelight@6937: * @param y How much you want to scroll to the bottom. truelight@6937: * @return A new destination pointer moved the the requested place. truelight@6937: */ truelight@6937: virtual void *MoveTo(const void *video, int x, int y) = 0; truelight@6937: truelight@6937: /** truelight@6937: * Draw a pixel with a given color on the video-buffer. truelight@6937: * @param video The destination pointer (video-buffer). truelight@6937: * @param x The x position within video-buffer. truelight@6937: * @param y The y position within video-buffer. truelight@6937: * @param color A 8bpp mapping color. truelight@6937: */ truelight@6937: virtual void SetPixel(void *video, int x, int y, uint8 color) = 0; truelight@6937: truelight@6937: /** truelight@6937: * Draw a pixel with a given color on the video-buffer if there is currently a black pixel. truelight@6937: * @param video The destination pointer (video-buffer). truelight@6937: * @param x The x position within video-buffer. truelight@6937: * @param y The y position within video-buffer. truelight@6937: * @param color A 8bpp mapping color. truelight@6937: */ truelight@6937: virtual void SetPixelIfEmpty(void *video, int x, int y, uint8 color) = 0; truelight@6937: truelight@6937: /** truelight@6937: * Make a single horizontal line in a single color on the video-buffer. truelight@6937: * @param video The destination pointer (video-buffer). truelight@6937: * @param width The lenght of the line. truelight@6937: * @param color A 8bpp mapping color. truelight@6937: */ peter1138@6947: virtual void DrawRect(void *video, int width, int height, uint8 color) = 0; truelight@6937: truelight@6937: /** truelight@6948: * Draw a line with a given color. truelight@6948: * @param video The destination pointer (video-buffer). truelight@6948: * @param x The x coordinate from where the line starts. truelight@6948: * @param y The y coordinate from where the line starts. truelight@6948: * @param x2 The x coordinate to where the line goes. truelight@6948: * @param y2 The y coordinate to where the lines goes. truelight@6948: * @param screen_width The width of the screen you are drawing in (to avoid buffer-overflows). truelight@6948: * @param screen_height The height of the screen you are drawing in (to avoid buffer-overflows). truelight@6948: * @param color A 8bpp mapping color. truelight@6948: */ truelight@6948: virtual void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 color) = 0; truelight@6948: truelight@6948: /** truelight@6937: * Copy from a buffer to the screen. truelight@6937: * @param video The destionation pointer (video-buffer). truelight@6937: * @param src The buffer from which the data will be read. truelight@6937: * @param width The width of the buffer. truelight@6937: * @param height The height of the buffer. truelight@6985: * @note You can not do anything with the content of the buffer, as the blitter can store non-pixel data in it too! truelight@6937: */ truelight@6985: virtual void CopyFromBuffer(void *video, const void *src, int width, int height) = 0; truelight@6937: truelight@6937: /** truelight@6937: * Copy from the screen to a buffer. truelight@6937: * @param video The destination pointer (video-buffer). truelight@6937: * @param dst The buffer in which the data will be stored. truelight@6937: * @param width The width of the buffer. truelight@6937: * @param height The height of the buffer. truelight@6985: * @note You can not do anything with the content of the buffer, as the blitter can store non-pixel data in it too! truelight@6937: */ truelight@6985: virtual void CopyToBuffer(const void *video, void *dst, int width, int height) = 0; truelight@6937: truelight@6937: /** truelight@6985: * Copy from the screen to a buffer in a palette format for 8bpp and RGBA format for 32bpp. truelight@6985: * @param video The destination pointer (video-buffer). truelight@6985: * @param dst The buffer in which the data will be stored. truelight@6985: * @param width The width of the buffer. truelight@6985: * @param height The height of the buffer. truelight@6985: * @param dst_pitch The pitch (byte per line) of the destination buffer. truelight@6937: */ truelight@6985: virtual void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch) = 0; truelight@6937: truelight@6937: /** truelight@6951: * Scroll the videobuffer some 'x' and 'y' value. truelight@6951: * @param video The buffer to scroll into. truelight@6951: * @param left The left value of the screen to scroll. truelight@6951: * @param top The top value of the screen to scroll. truelight@6951: * @param width The width of the screen to scroll. truelight@6951: * @param height The height of the screen to scroll. truelight@6951: * @param scroll_x How much to scroll in X. truelight@6951: * @param scroll_y How much to scroll in Y. truelight@6951: */ truelight@6951: virtual void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y) = 0; truelight@6951: truelight@6951: /** truelight@6937: * Calculate how much memory there is needed for an image of this size in the video-buffer. truelight@6937: * @param width The width of the buffer-to-be. truelight@6937: * @param height The height of the buffer-to-be. truelight@6937: * @return The size needed for the buffer. truelight@6937: */ truelight@6937: virtual int BufferSize(int width, int height) = 0; truelight@6937: truelight@6960: /** truelight@6960: * Called when the 8bpp palette is changed; you should redraw all pixels on the screen that truelight@6960: * are equal to the 8bpp palette indexes 'start' to 'start + count'. truelight@6960: * @param start The start index in the 8bpp palette. truelight@6960: * @param count The amount of indexes that are (possible) changed. truelight@6960: */ truelight@6960: virtual void PaletteAnimate(uint start, uint count) = 0; truelight@6960: truelight@6960: /** truelight@6960: * Check if the blitter uses palette animation at all. truelight@6960: * @return True if it uses palette animation. truelight@6960: */ truelight@6960: virtual Blitter::PaletteAnimation UsePaletteAnimation() = 0; truelight@6960: truelight@6989: /** truelight@6989: * Get the naem of the blitter, the same as the Factory-instance returns. truelight@6989: */ truelight@6989: virtual const char *GetName() = 0; truelight@6989: truelight@6937: virtual ~Blitter() { } truelight@6937: }; truelight@6937: truelight@6937: #endif /* BLITTER_BASE_HPP */