Changeset 150 for trunk/src


Ignore:
Timestamp:
12/02/08 20:43:37 (5 years ago)
Author:
guyru
Message:

improve the design of the dice theme handling classes

Location:
trunk/src
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/dice/theme1/five.xpm

    r131 r150  
    11/* XPM */ 
    2 static char *theme1_five_xpm[] = { 
     2static char *five_xpm[] = { 
    33/* columns rows colors chars-per-pixel */ 
    44"64 64 246 2", 
  • trunk/src/dice/theme1/four.xpm

    r131 r150  
    11/* XPM */ 
    2 static char *theme1_four_xpm[] = { 
     2static char *four_xpm[] = { 
    33/* columns rows colors chars-per-pixel */ 
    44"64 64 221 2", 
  • trunk/src/dice/theme1/one.xpm

    r131 r150  
    11/* XPM */ 
    2 static char *theme1_one_xpm[] = { 
     2static char *one_xpm[] = { 
    33/* columns rows colors chars-per-pixel */ 
    44"64 64 203 2", 
  • trunk/src/dice/theme1/six.xpm

    r131 r150  
    11/* XPM */ 
    2 static char *theme1_six_xpm[] = { 
     2static char *six_xpm[] = { 
    33/* columns rows colors chars-per-pixel */ 
    44"64 64 255 2", 
  • trunk/src/dice/theme1/three.xpm

    r131 r150  
    11/* XPM */ 
    2 static char *theme1_three_xpm[] = { 
     2static char *three_xpm[] = { 
    33/* columns rows colors chars-per-pixel */ 
    44"64 64 227 2", 
  • trunk/src/dice/theme1/two.xpm

    r131 r150  
    11/* XPM */ 
    2 static char *theme1_two_xpm[] = { 
     2static char *two_xpm[] = { 
    33/* columns rows colors chars-per-pixel */ 
    44"64 64 218 2", 
  • trunk/src/dice/theme2/five.xpm

    r131 r150  
    11/* XPM */ 
    2 static char *theme2_five_xpm[] = { 
     2static char *five_xpm[] = { 
    33/* columns rows colors chars-per-pixel */ 
    44"64 64 190 2", 
  • trunk/src/dice/theme2/four.xpm

    r131 r150  
    11/* XPM */ 
    2 static char *theme2_four_xpm[] = { 
     2static char *four_xpm[] = { 
    33/* columns rows colors chars-per-pixel */ 
    44"64 64 171 2", 
  • trunk/src/dice/theme2/one.xpm

    r131 r150  
    11/* XPM */ 
    2 static char *theme2_one_xpm[] = { 
     2static char *one_xpm[] = { 
    33/* columns rows colors chars-per-pixel */ 
    44"64 64 200 2", 
  • trunk/src/dice/theme2/six.xpm

    r131 r150  
    11/* XPM */ 
    2 static char *theme2_six_xpm[] = { 
     2static char *six_xpm[] = { 
    33/* columns rows colors chars-per-pixel */ 
    44"64 64 206 2", 
  • trunk/src/dice/theme2/three.xpm

    r131 r150  
    11/* XPM */ 
    2 static char *theme2_three_xpm[] = { 
     2static char *three_xpm[] = { 
    33/* columns rows colors chars-per-pixel */ 
    44"64 64 159 2", 
  • trunk/src/dice/theme2/two.xpm

    r131 r150  
    11/* XPM */ 
    2 static char *theme2_two_xpm[] = { 
     2static char *two_xpm[] = { 
    33/* columns rows colors chars-per-pixel */ 
    44"64 64 131 2", 
  • trunk/src/dice/theme3/1.xpm

    r131 r150  
    11/* XPM */ 
    2 static char *theme3_1_xpm[] = { 
     2static char *one_xpm[] = { 
    33/* columns rows colors chars-per-pixel */ 
    44"64 64 53 1", 
  • trunk/src/dice/theme3/2.xpm

    r131 r150  
    11/* XPM */ 
    2 static char *theme3_2_xpm[] = { 
     2static char *two_xpm[] = { 
    33/* columns rows colors chars-per-pixel */ 
    44"64 64 58 1", 
  • trunk/src/dice/theme3/3.xpm

    r131 r150  
    11/* XPM */ 
    2 static char *theme3_3_xpm[] = { 
     2static char *three_xpm[] = { 
    33/* columns rows colors chars-per-pixel */ 
    44"64 64 61 1", 
  • trunk/src/dice/theme3/4.xpm

    r131 r150  
    11/* XPM */ 
    2 static char *theme3_4_xpm[] = { 
     2static char *four_xpm[] = { 
    33/* columns rows colors chars-per-pixel */ 
    44"64 64 61 1", 
  • trunk/src/dice/theme3/5.xpm

    r131 r150  
    11/* XPM */ 
    2 static char *theme3_5_xpm[] = { 
     2static char *five_xpm[] = { 
    33/* columns rows colors chars-per-pixel */ 
    44"64 64 61 1", 
  • trunk/src/dice/theme3/6.xpm

    r131 r150  
    11/* XPM */ 
    2 static char *theme3_6_xpm[] = { 
     2static char *six_xpm[] = { 
    33/* columns rows colors chars-per-pixel */ 
    44"64 64 61 1", 
  • trunk/src/dice_graphics.cpp

    r131 r150  
    2121#include "dice_graphics.h" 
    2222 
    23 #include "dice/theme1/one.xpm" 
    24 #include "dice/theme1/two.xpm" 
    25 #include "dice/theme1/three.xpm" 
    26 #include "dice/theme1/four.xpm" 
    27 #include "dice/theme1/five.xpm" 
    28 #include "dice/theme1/six.xpm" 
    29  
    30 #include "dice/theme2/one.xpm" 
    31 #include "dice/theme2/two.xpm" 
    32 #include "dice/theme2/three.xpm" 
    33 #include "dice/theme2/four.xpm" 
    34 #include "dice/theme2/five.xpm" 
    35 #include "dice/theme2/six.xpm" 
    36  
    37 #include "dice/theme3/1.xpm" 
    38 #include "dice/theme3/2.xpm" 
    39 #include "dice/theme3/3.xpm" 
    40 #include "dice/theme3/4.xpm" 
    41 #include "dice/theme3/5.xpm" 
    42 #include "dice/theme3/6.xpm" 
    4323 
    4424DiceGraphics::DiceGraphics() 
    4525{ 
    46         m_theme = 0; 
    47  
    48         LoadTheme1(); 
    49         LoadTheme2(); 
    50         LoadTheme3(); 
     26        m_theme = (DiceTheme*)new DiceTheme1(); 
    5127} 
    5228 
    53 void DiceGraphics::LoadTheme1() 
     29DiceGraphics::~DiceGraphics() 
    5430{ 
    55         m_bitmaps[0][0] = new wxBitmap(theme1_one_xpm); 
    56         m_bitmaps[0][1] = new wxBitmap(theme1_two_xpm); 
    57         m_bitmaps[0][2] = new wxBitmap(theme1_three_xpm); 
    58         m_bitmaps[0][3] = new wxBitmap(theme1_four_xpm); 
    59         m_bitmaps[0][4] = new wxBitmap(theme1_five_xpm); 
    60         m_bitmaps[0][5] = new wxBitmap(theme1_six_xpm); 
     31        delete m_theme; 
    6132} 
    6233 
    63 void DiceGraphics::LoadTheme2() 
    64 { 
    65         m_bitmaps[1][0] = new wxBitmap(theme2_one_xpm); 
    66         m_bitmaps[1][1] = new wxBitmap(theme2_two_xpm); 
    67         m_bitmaps[1][2] = new wxBitmap(theme2_three_xpm); 
    68         m_bitmaps[1][3] = new wxBitmap(theme2_four_xpm); 
    69         m_bitmaps[1][4] = new wxBitmap(theme2_five_xpm); 
    70         m_bitmaps[1][5] = new wxBitmap(theme2_six_xpm); 
    71 } 
    72  
    73 void DiceGraphics::LoadTheme3() 
    74 { 
    75         m_bitmaps[2][0] = new wxBitmap(theme3_1_xpm); 
    76         m_bitmaps[2][1] = new wxBitmap(theme3_2_xpm); 
    77         m_bitmaps[2][2] = new wxBitmap(theme3_3_xpm); 
    78         m_bitmaps[2][3] = new wxBitmap(theme3_4_xpm); 
    79         m_bitmaps[2][4] = new wxBitmap(theme3_5_xpm); 
    80         m_bitmaps[2][5] = new wxBitmap(theme3_6_xpm); 
    81 } 
    8234/** 
    8335 * \param i the number of the dice (1 to 6) 
     
    8638wxBitmap *DiceGraphics::GetDice(int i) 
    8739{ 
    88         return m_bitmaps[m_theme][i-1]; 
     40        return m_theme->GetDice(i); 
    8941} 
     42 
     43namespace dicetheme1 { 
     44        #include "dice/theme1/one.xpm" 
     45        #include "dice/theme1/two.xpm" 
     46        #include "dice/theme1/three.xpm" 
     47        #include "dice/theme1/four.xpm" 
     48        #include "dice/theme1/five.xpm" 
     49        #include "dice/theme1/six.xpm" 
     50} 
     51DiceTheme1::DiceTheme1() { 
     52        m_bitmaps[0] = new wxBitmap(dicetheme1::one_xpm); 
     53        m_bitmaps[1] = new wxBitmap(dicetheme1::two_xpm); 
     54        m_bitmaps[2] = new wxBitmap(dicetheme1::three_xpm); 
     55        m_bitmaps[3] = new wxBitmap(dicetheme1::four_xpm); 
     56        m_bitmaps[4] = new wxBitmap(dicetheme1::five_xpm); 
     57        m_bitmaps[5] = new wxBitmap(dicetheme1::six_xpm); 
     58} 
     59 
     60/** 
     61 * \param i the number of the dice (1 to 6) 
     62 * \return a pointer to wxBitmap 
     63 */ 
     64wxBitmap* DiceTheme1::GetDice(int i) 
     65{ 
     66        return m_bitmaps[i-1]; 
     67} 
     68 
     69namespace dicetheme2 { 
     70        #include "dice/theme2/one.xpm" 
     71        #include "dice/theme2/two.xpm" 
     72        #include "dice/theme2/three.xpm" 
     73        #include "dice/theme2/four.xpm" 
     74        #include "dice/theme2/five.xpm" 
     75        #include "dice/theme2/six.xpm" 
     76} 
     77DiceTheme2::DiceTheme2() { 
     78        m_bitmaps[0] = new wxBitmap(dicetheme2::one_xpm); 
     79        m_bitmaps[1] = new wxBitmap(dicetheme2::two_xpm); 
     80        m_bitmaps[2] = new wxBitmap(dicetheme2::three_xpm); 
     81        m_bitmaps[3] = new wxBitmap(dicetheme2::four_xpm); 
     82        m_bitmaps[4] = new wxBitmap(dicetheme2::five_xpm); 
     83        m_bitmaps[5] = new wxBitmap(dicetheme2::six_xpm); 
     84} 
     85 
     86/** 
     87 * \param i the number of the dice (1 to 6) 
     88 * \return a pointer to wxBitmap 
     89 */ 
     90wxBitmap* DiceTheme2::GetDice(int i) 
     91{ 
     92        return m_bitmaps[i-1]; 
     93} 
     94 
     95namespace dicetheme3 { 
     96        #include "dice/theme3/1.xpm" 
     97        #include "dice/theme3/2.xpm" 
     98        #include "dice/theme3/3.xpm" 
     99        #include "dice/theme3/4.xpm" 
     100        #include "dice/theme3/5.xpm" 
     101        #include "dice/theme3/6.xpm" 
     102} 
     103DiceTheme3::DiceTheme3() { 
     104        m_bitmaps[0] = new wxBitmap(dicetheme3::one_xpm); 
     105        m_bitmaps[1] = new wxBitmap(dicetheme3::two_xpm); 
     106        m_bitmaps[2] = new wxBitmap(dicetheme3::three_xpm); 
     107        m_bitmaps[3] = new wxBitmap(dicetheme3::four_xpm); 
     108        m_bitmaps[4] = new wxBitmap(dicetheme3::five_xpm); 
     109        m_bitmaps[5] = new wxBitmap(dicetheme3::six_xpm); 
     110} 
     111 
     112/** 
     113 * \param i the number of the dice (1 to 6) 
     114 * \return a pointer to wxBitmap 
     115 */ 
     116wxBitmap *DiceTheme3::GetDice(int i) 
     117{ 
     118        return m_bitmaps[i-1]; 
     119} 
  • trunk/src/dice_graphics.h

    r131 r150  
    2424#define NUM_OF_THEMES 3 
    2525 
     26/** 
     27 * This is the base class for the DiceThemes. It implements a Strategy design 
     28 * pattern 
     29 */ 
     30class DiceTheme { 
     31public: 
     32        virtual wxBitmap* GetDice(int i) = 0; 
     33}; 
     34 
    2635class DiceGraphics { 
    2736public: 
    2837        DiceGraphics(); 
     38        DiceGraphics(DiceTheme* theme); 
     39        ~DiceGraphics(); 
    2940        wxBitmap *GetDice(int i); 
    3041 
    3142private: 
    32         void LoadTheme1(); 
    33         void LoadTheme2(); 
    34         void LoadTheme3(); 
    35         wxBitmap *m_bitmaps[ NUM_OF_THEMES ][6]; 
    36         int m_theme; 
     43        DiceTheme *m_theme; 
     44}; 
    3745 
     46class DiceTheme1 : public DiceTheme { 
     47        wxBitmap *m_bitmaps[6]; 
     48public: 
     49        DiceTheme1(); 
     50        virtual wxBitmap* GetDice(int i); 
     51}; 
     52 
     53class DiceTheme2 : public DiceTheme { 
     54        wxBitmap *m_bitmaps[6]; 
     55public: 
     56        DiceTheme2(); 
     57        virtual wxBitmap* GetDice(int i); 
     58}; 
     59 
     60class DiceTheme3 : public DiceTheme { 
     61        wxBitmap *m_bitmaps[6]; 
     62public: 
     63        virtual wxBitmap* GetDice(int i); 
     64        DiceTheme3(); 
    3865}; 
    3966 
Note: See TracChangeset for help on using the changeset viewer.