20130313
[gdash.git] / src / gfx / cellrenderer.hpp
blobe36770afd80fdda7b62bb1e975eba7f9a368f437
1 /*
2 * Copyright (c) 2007-2013, Czirkos Zoltan http://code.google.com/p/gdash/
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include "config.h"
19 #ifndef _GD_GFX_CELLS
20 #define _GD_GFX_CELLS
22 #include <vector>
24 #include "cave/cavetypes.hpp"
25 #include "cave/helper/colors.hpp"
27 class PixbufFactory;
28 class Pixbuf;
29 class Pixmap;
31 /// @ingroup Graphics
32 /// @brief The class which is responsible for rendering the cave pixbufs.
33 /// In its constructor, it takes a pixbuf factory as a parameter (for the graphics
34 /// subsystem), and the name of a theme file to load.
35 /// If the theme file cannot be loaded, or an empty string is given as file name,
36 /// it switches to the builtin default theme.
37 /// After loading the theme file, select_pixbuf_colors is used to select a color theme.
38 /// A pixbuf of a cell can be retrieved using cell(i).
39 class CellRenderer {
40 protected:
41 /// The pixbuf which was loaded from the disk.
42 Pixbuf *loaded;
44 /// The pixbuf which stores rgb data of all images.
45 Pixbuf *cells_all;
47 bool is_c64_colored;
49 /// The size of the loaded pixbufs
50 unsigned cell_size;
52 /// The cache to store the pixbufs already rendered.
53 Pixbuf *cells_pixbufs[NUM_OF_CELLS];
55 /// The cache to store the pixbufs already rendered.
56 Pixmap *cells[3*NUM_OF_CELLS];
58 /// If using c64 gfx, these store the current color theme.
59 GdColor color0, color1, color2, color3, color4, color5;
61 void create_colorized_cells();
62 bool loadcells_image(Pixbuf *loadcells_image);
63 bool loadcells_file(const std::string& filename);
64 virtual void remove_cached();
66 CellRenderer(const CellRenderer&); // not implemented
67 CellRenderer& operator=(const CellRenderer&); // not implemented
69 public:
70 /// The pixbuf factory which is used to create pixbufs and pixmaps.
71 /// Public, so can be used by other objects - why not.
72 PixbufFactory& pixbuf_factory;
74 /// Constructor. Loads a theme file (or nothing); uses pixbuf_factory as a gfx engine.
75 CellRenderer(PixbufFactory& pixbuf_factory_, const std::string& theme_file);
77 /// Destructor.
78 virtual ~CellRenderer();
80 /// @brief Loads a new theme.
81 /// The theme_file can be a file name of a png file, or empty.
82 void load_theme_file(const std::string& theme_file);
84 /// @brief Returns a particular cell.
85 Pixbuf &cell_pixbuf(unsigned i);
87 /// @brief Returns a particular cell.
88 Pixmap &cell(unsigned i);
90 /// @brief Returns the size of the pixmaps stored.
91 /// They are squares, so there is only one function, not two for width and height.
92 int get_cell_size();
94 /// @brief Returns the size of the pixbufs
95 /// They are squares, so there is only one function, not two for width and height.
96 int get_cell_pixbuf_size()
98 return cell_size;
101 /// Returns the background color currently used.
102 const GdColor& get_background_color() const
104 return color0;
107 /// Returns true if the pixbuf factory used uses pal emulation.
108 bool get_pal_emulation() const;
110 /// @brief Select a color theme, when using C64 graphics.
111 /// If no c64 graphics is used, then this function does nothing.
112 virtual void select_pixbuf_colors(GdColor c0, GdColor c1, GdColor c2, GdColor c3, GdColor c4, GdColor c5);
114 /// @brief This function checks if a file is suitable to be used as a GDash theme.
115 static bool is_image_ok_for_theme(PixbufFactory &pixbuf_factory, const char *image);
116 static bool is_pixbuf_ok_for_theme(Pixbuf const &surface);
117 static bool check_if_pixbuf_c64_png(Pixbuf const &image);
121 #endif