celestar@9913: /* $Id$ */ celestar@9913: celestar@9913: #ifndef BLITTER_BASE_HPP celestar@9913: #define BLITTER_BASE_HPP celestar@9913: celestar@9913: #include "../spritecache.h" celestar@9913: #include "../spriteloader/spriteloader.hpp" celestar@9913: celestar@9913: enum BlitterMode { celestar@9913: BM_NORMAL, celestar@9913: BM_COLOUR_REMAP, celestar@9913: BM_TRANSPARENT, celestar@9913: }; celestar@9913: celestar@9913: /** celestar@9913: * How all blitters should look like. Extend this class to make your own. celestar@9913: */ celestar@9913: class Blitter { celestar@9913: public: celestar@9913: struct BlitterParams { celestar@9913: const void *sprite; ///< Pointer to the sprite how ever the encoder stored it celestar@9913: const byte *remap; ///< XXX -- Temporary storage for remap array celestar@9913: celestar@9913: int skip_left, skip_top; ///< How much pixels of the source to skip on the left and top (based on zoom of dst) celestar@9913: int width, height; ///< The width and height in pixels that needs to be drawn to dst celestar@9913: int sprite_width; ///< Real width of the sprite celestar@9913: int sprite_height; ///< Real height of the sprite celestar@9913: int left, top; ///< The offset in the 'dst' in pixels to start drawing celestar@9913: celestar@9913: void *dst; ///< Destination buffer celestar@9913: int pitch; ///< The pitch of the destination buffer celestar@9913: }; celestar@9913: celestar@9913: typedef void *AllocatorProc(size_t size); celestar@9913: celestar@9913: /** celestar@9913: * Get the screen depth this blitter works for. celestar@9913: * This is either: 8, 16, 24 or 32. celestar@9913: */ celestar@9913: virtual uint8 GetScreenDepth() = 0; celestar@9913: celestar@9913: /** celestar@9913: * Draw an image to the screen, given an amount of params defined above. celestar@9913: */ celestar@9913: virtual void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) = 0; celestar@9913: celestar@9913: /** celestar@9913: * Draw a colortable to the screen. This is: the color of the screen is read celestar@9913: * and is looked-up in the palette to match a new color, which then is put celestar@9913: * on the screen again. celestar@9913: * @param dst the destination pointer (video-buffer). celestar@9913: * @param width the width of the buffer. celestar@9913: * @param height the height of the buffer. celestar@9913: * @param pal the palette to use. celestar@9913: */ celestar@9913: virtual void DrawColorMappingRect(void *dst, int width, int height, int pal) = 0; celestar@9913: celestar@9913: /** celestar@9913: * Convert a sprite from the loader to our own format. celestar@9913: */ celestar@9913: virtual Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator) = 0; celestar@9913: celestar@9913: /** celestar@9913: * Move the destination pointer the requested amount x and y, keeping in mind celestar@9913: * any pitch and bpp of the renderer. celestar@9913: * @param video The destination pointer (video-buffer) to scroll. celestar@9913: * @param x How much you want to scroll to the right. celestar@9913: * @param y How much you want to scroll to the bottom. celestar@9913: * @return A new destination pointer moved the the requested place. celestar@9913: */ celestar@9913: virtual void *MoveTo(const void *video, int x, int y) = 0; celestar@9913: celestar@9913: /** celestar@9913: * Draw a pixel with a given color on the video-buffer. celestar@9913: * @param video The destination pointer (video-buffer). celestar@9913: * @param x The x position within video-buffer. celestar@9913: * @param y The y position within video-buffer. celestar@9913: * @param color A 8bpp mapping color. celestar@9913: */ celestar@9913: virtual void SetPixel(void *video, int x, int y, uint8 color) = 0; celestar@9913: celestar@9913: /** celestar@9913: * Draw a pixel with a given color on the video-buffer if there is currently a black pixel. celestar@9913: * @param video The destination pointer (video-buffer). celestar@9913: * @param x The x position within video-buffer. celestar@9913: * @param y The y position within video-buffer. celestar@9913: * @param color A 8bpp mapping color. celestar@9913: */ celestar@9913: virtual void SetPixelIfEmpty(void *video, int x, int y, uint8 color) = 0; celestar@9913: celestar@9913: /** celestar@9913: * Make a single horizontal line in a single color on the video-buffer. celestar@9913: * @param video The destination pointer (video-buffer). celestar@9913: * @param width The lenght of the line. celestar@9913: * @param color A 8bpp mapping color. celestar@9913: */ celestar@9913: virtual void SetHorizontalLine(void *video, int width, uint8 color) = 0; celestar@9913: celestar@9913: /** celestar@9913: * Copy from a buffer to the screen. celestar@9913: * @param video The destionation pointer (video-buffer). celestar@9913: * @param src The buffer from which the data will be read. celestar@9913: * @param width The width of the buffer. celestar@9913: * @param height The height of the buffer. celestar@9913: * @param src_pitch The pitch (byte per line) of the source buffer. celestar@9913: */ celestar@9913: virtual void CopyFromBuffer(void *video, const void *src, int width, int height, int src_pitch) = 0; celestar@9913: celestar@9913: /** celestar@9913: * Copy from the screen to a buffer. celestar@9913: * @param video The destination pointer (video-buffer). celestar@9913: * @param dst The buffer in which the data will be stored. celestar@9913: * @param width The width of the buffer. celestar@9913: * @param height The height of the buffer. celestar@9913: * @param dst_pitch The pitch (byte per line) of the destination buffer. celestar@9913: */ celestar@9913: virtual void CopyToBuffer(const void *video, void *dst, int width, int height, int dst_pitch) = 0; celestar@9913: celestar@9913: /** celestar@9913: * Move the videobuffer some places (via memmove). celestar@9913: * @param video_dst The destination pointer (video-buffer). celestar@9913: * @param video_src The source pointer (video-buffer). celestar@9913: * @param width The width of the buffer to move. celestar@9913: * @param height The height of the buffer to move. celestar@9913: */ celestar@9913: virtual void MoveBuffer(void *video_dst, const void *video_src, int width, int height) = 0; celestar@9913: celestar@9913: /** celestar@9913: * Calculate how much memory there is needed for an image of this size in the video-buffer. celestar@9913: * @param width The width of the buffer-to-be. celestar@9913: * @param height The height of the buffer-to-be. celestar@9913: * @return The size needed for the buffer. celestar@9913: */ celestar@9913: virtual int BufferSize(int width, int height) = 0; celestar@9913: celestar@9913: virtual ~Blitter() { } celestar@9913: }; celestar@9913: celestar@9913: #endif /* BLITTER_BASE_HPP */