[gnome-games/cplusplus] Try using more sany polymorphism
- From: Jason Clinton <jclinton src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-games/cplusplus] Try using more sany polymorphism
- Date: Fri, 8 May 2009 17:34:49 -0400 (EDT)
commit 7c657c5fa4f501725b9283d3106980fbc4fb569e
Author: Jason D. Clinton <me jasonclinton com>
Date: Fri May 8 16:32:50 2009 -0500
Try using more sany polymorphism
---
gnometris/renderer.cpp | 20 +++++++++++---------
gnometris/renderer.h | 2 +-
2 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/gnometris/renderer.cpp b/gnometris/renderer.cpp
index d488996..9b93fd5 100644
--- a/gnometris/renderer.cpp
+++ b/gnometris/renderer.cpp
@@ -55,15 +55,21 @@ gint themeNameToNumber (const gchar *id)
Renderer * rendererFactory (gint id, gint pxw, gint pxh)
{
+ Renderer *tmp;
switch (id) {
case 2:
- return new TangoBlock (pxw, pxh, TRUE);
+ tmp = new TangoBlock (pxw, pxh, TRUE);
+ ((TangoBlock*)tmp)->rescaleCache (pxw, pxh);
case 1:
- return new TangoBlock (pxw, pxh, FALSE);
+ tmp = new TangoBlock (pxw, pxh, FALSE);
+ ((TangoBlock*)tmp)->rescaleCache (pxw, pxh);
case 0:
default:
- return new Renderer (pxw, pxh, FALSE);
+ tmp = new Renderer (pxw, pxh);
+ tmp->rescaleCache (pxw, pxh);
}
+
+ return tmp;
}
/* The Renderer class is a basic drawing class that is structured to
@@ -80,15 +86,13 @@ Renderer * rendererFactory (gint id, gint pxw, gint pxh)
for the preview widget and possibly the theme previewer, so make no
assumptions. */
-Renderer::Renderer (gint pxw, gint pxh, bool initFromSubclass)
+Renderer::Renderer (gint pxw, gint pxh)
{
pxwidth = pxw == 0 ? 1 : pxw;
pxheight = pxh == 0 ? 1 : pxh;
for (int i = 0; i < NCOLOURS; i++) {
cache[i] = NULL;
}
- if (!initFromSubclass)
- rescaleCache (pxwidth, pxheight);
}
Renderer::~Renderer ()
@@ -152,15 +156,13 @@ void Renderer::drawCell (cairo_t *cr, guint color)
cairo_paint (cr);
}
-TangoBlock::TangoBlock (gint pxw, gint pxh, gboolean grad) : Renderer (pxw, pxh, TRUE)
+TangoBlock::TangoBlock (gint pxw, gint pxh, gboolean grad) : Renderer (pxw, pxh)
{
usegrads = grad;
- rescaleCache (pxwidth, pxheight);
}
void TangoBlock::drawCell (cairo_t *cr, guint color)
{
-
cairo_pattern_t *pat = NULL;
/* the following garbage is derived from the official tango style guide */
const gdouble colours[8][3][3] = {
diff --git a/gnometris/renderer.h b/gnometris/renderer.h
index c647634..08d2176 100644
--- a/gnometris/renderer.h
+++ b/gnometris/renderer.h
@@ -40,7 +40,7 @@ extern const ThemeTableEntry ThemeTable[];
class Renderer {
public:
- Renderer (gint pxw, gint pxh, bool initFromSubclass);
+ Renderer (gint pxw, gint pxh);
virtual ~ Renderer ();
void rescaleCache (gint pxw, gint pxh);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]