1 #ifndef _render__hpp__included__
2 #define _render__hpp__included__
11 * \brief Low color (32768 colors) screen from buffer.
16 * \brief Create new screen from bsnes output data.
18 * \param mem The output buffer from bsnes.
19 * \param hires True if in hires mode (512-wide lines instead of 256-wide).
20 * \param interlace True if in interlace mode.
21 * \param overscan True if overscan is enabled.
22 * \param region True if PAL, false if NTSC.
24 lcscreen(const uint16_t* mem
, bool hires
, bool interlace
, bool overscan
, bool region
) throw();
27 lcscreen(const uint16_t* mem
, uint32_t _width
, uint32_t _height
) throw();
28 lcscreen(const lcscreen
& ls
) throw(std::bad_alloc
);
29 lcscreen
& operator=(const lcscreen
& ls
) throw(std::bad_alloc
, std::runtime_error
);
30 void load(const std::vector
<char>& data
) throw(std::bad_alloc
, std::runtime_error
);
31 void save(std::vector
<char>& data
) throw(std::bad_alloc
);
32 void save_png(const std::string
& file
) throw(std::bad_alloc
, std::runtime_error
);
40 * \brief True if memory is allocated by new[] and should be freed by the destructor., false otherwise.
45 * \brief Memory, 1 element per pixel in left-to-right, top-to-bottom order, 15 low bits of each element used.
47 const uint16_t* memory
;
50 * \brief Number of elements (not bytes) between two successive scanlines.
55 * \brief Width of image.
60 * \brief Height of image.
65 * \brief Image allocated size (only valid for user_memory).
71 * \brief Truecolor modifiable screen.
76 * \brief Create new screen
78 * Creates screen. The screen dimensions are initially 0x0.
88 * \brief Set the screen to use specified backing memory.
90 * Sets the backing memory for screen. The specified memory is not freed if screen is reallocated or destroyed.
92 * \param _memory The memory buffer.
93 * \param _width Width of screen.
94 * \param _height Height of screen.
95 * \param _originx X coordinate for origin.
96 * \param _originy Y coordinate for origin.
97 * \param _pitch Distance in bytes between successive scanlines.
99 void set(uint32_t* _memory
, uint32_t _width
, uint32_t _height
, uint32_t _originx
, uint32_t _originy
,
100 uint32_t _pitch
) throw();
103 * \brief Set new size for screen, reallocating backing memory.
105 * Sets the size of the screen. The memory is freed if screen is reallocated or destroyed.
107 * \param _width Width of screen.
108 * \param _height Height of screen.
109 * \param _originx X coordinate for origin.
110 * \param _originy Y coordinate for origin.
111 * \param upside_down If true, image is upside down in memory.
112 * \throws std::bad_alloc Not enough memory.
114 void reallocate(uint32_t _width
, uint32_t _height
, uint32_t _originx
, uint32_t _originy
,
115 bool upside_down
= false) throw(std::bad_alloc
);
118 * \brief Paint low-color screen into screen.
120 * Paints low-color screen into screen. The upper-left of image will be at origin. Scales the image by given factors.
121 * If the image does not fit with specified scale factors, it is clipped.
123 * \param scr The screen to paint.
124 * \param hscale Horizontal scale factor.
125 * \param vscale Vertical scale factor.
127 void copy_from(lcscreen
& scr
, uint32_t hscale
, uint32_t vscale
) throw();
130 * \brief Get pointer into specified row.
132 * \param row Number of row (must be less than height).
134 uint32_t* rowptr(uint32_t row
) throw();
137 * \brief Backing memory for this screen.
142 * \brief True if memory is given by user and must not be freed.
147 * \brief Width of screen.
152 * \brief Height of screen.
157 * \brief Distance between lines in bytes.
162 * \brief True if image is upside down in memory.
167 * \brief X-coordinate of origin.
172 * \brief Y-coordinate of origin.
179 uint32_t palette
[32768];
182 * \brief Set the palette shifts.
184 * Sets the palette shifts, converting the existing image.
186 * \param rshift Shift for red component.
187 * \param gshift Shift for green component.
188 * \param bshift Shift for blue component.
190 void set_palette(uint32_t rshift
, uint32_t gshift
, uint32_t bshift
) throw();
193 * \brief Return a color value.
195 * Returns color value with specified (r,g,b) values (scale 0-255).
197 * \param r Red component.
198 * \param g Green component.
199 * \param b Blue component.
200 * \return color element value.
202 uint32_t make_color(uint8_t r
, uint8_t g
, uint8_t b
) throw();
205 * \brief Current red component shift.
207 uint32_t active_rshift
;
210 * \brief Current green component shift.
212 uint32_t active_gshift
;
215 * \brief Current blue component shift.
217 uint32_t active_bshift
;
219 screen(const screen
&);
220 screen
& operator=(const screen
&);
224 * \brief Base class for objects to render.
231 virtual ~render_object() throw();
234 * \brief Draw the object.
236 * \param scr The screen to draw it on.
238 virtual void operator()(struct screen
& scr
) throw() = 0;
242 * \brief Queue of render operations.
247 * \brief Add object to render queue.
249 * Adds new object to render queue. The object must be allocated by new.
251 * \param obj The object to add
252 * \throws std::bad_alloc Not enough memory.
254 void add(struct render_object
& obj
) throw(std::bad_alloc
);
257 * \brief Apply all objects in order.
259 * Applies all objects in the queue in order, freeing them in progress.
261 * \param scr The screen to apply queue to.
263 void run(struct screen
& scr
) throw();
266 * \brief Clear the queue.
268 * Frees all objects in the queue.
271 void clear() throw();
276 ~render_queue() throw();
278 std::list
<struct render_object
*> q
;
282 * \brief Read font data for glyph.
284 * \param codepoint Code point of glyph.
285 * \param x X position to render into.
286 * \param y Y position to render into.
287 * \param orig_x X position at start of row.
288 * \param next_x X position for next glyph is written here.
289 * \param next_y Y position for next glyph is written here.
290 * \return Two components: First is width of character, second is its offset in font data (0 if blank glyph).
292 std::pair
<uint32_t, size_t> find_glyph(uint32_t codepoint
, int32_t x
, int32_t y
, int32_t orig_x
,
293 int32_t& next_x
, int32_t& next_y
) throw();
297 * \brief Render text into screen.
299 * \param _x The x position to render to (relative to origin).
300 * \param _y The y position to render to (relative to origin).
301 * \param _text The text to render.
302 * \param _fg Foreground color.
303 * \param _fgalpha Foreground alpha (0-256).
304 * \param _bg Background color.
305 * \param _bgalpha Background alpha (0-256).
307 void render_text(struct screen
& scr
, int32_t _x
, int32_t _y
, const std::string
& _text
, uint32_t _fg
= 0xFFFFFFFFU
,
308 uint16_t _fgalpha
= 255, uint32_t _bg
= 0, uint16_t _bgalpha
= 0) throw(std::bad_alloc
);