~ubuntu-branches/ubuntu/hardy/groundhog/hardy

« back to all changes in this revision

Viewing changes to src/pocket.cc

  • Committer: Bazaar Package Importer
  • Author(s): Stephen M Moraco
  • Date: 2004-08-20 23:12:32 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040820231232-18s0op2f9g21ag1z
Tags: 1.4-6
Update Policy Version

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Groundhog -- a simple logic game
2
 
 * Copyright (C) 1998-2001 Maurits Rijk
 
2
 * Copyright (C) 1998-2002 Maurits Rijk
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify
5
5
 * it under the terms of the GNU General Public License as published by
22
22
#include "ball.h"
23
23
#include "pocket.h"
24
24
 
25
 
#include "pixmaps/left_blue.xpm"
26
 
#include "pixmaps/left_green.xpm"
27
 
#include "pixmaps/left_red.xpm"
28
 
#include "pixmaps/left_yellow.xpm"
29
 
#include "pixmaps/lower_blue.xpm"
30
 
#include "pixmaps/lower_green.xpm"
31
 
#include "pixmaps/lower_red.xpm"
32
 
#include "pixmaps/lower_yellow.xpm"
33
 
#include "pixmaps/right_blue.xpm"
34
 
#include "pixmaps/right_green.xpm"
35
 
#include "pixmaps/right_red.xpm"
36
 
#include "pixmaps/right_yellow.xpm"
37
 
#include "pixmaps/upper_blue.xpm"
38
 
#include "pixmaps/upper_green.xpm"
39
 
#include "pixmaps/upper_red.xpm"
40
 
#include "pixmaps/upper_yellow.xpm"
41
 
 
42
 
 
43
 
Pocket::Pocket(GtkWidget* table) : _table(table), _element(0), _ball(0)
44
 
{
45
 
}
46
 
 
47
 
void
48
 
Pocket::InsertInTable(int row, int col, GdkPixmap* pixmap)
 
25
 
 
26
Pocket::Pocket(GtkWidget* table, int row, int col) : _table(table), 
 
27
                                                     _element(0), _ball(0)
49
28
{
50
29
   /* a pixmap widget to contain the pixmap */
51
 
   _pixmapwid = gtk_pixmap_new(_red_pixmap, _mask);
52
 
   gtk_widget_show(_pixmapwid);
53
 
 
54
 
   gtk_table_attach_defaults(GTK_TABLE(_table), _pixmapwid, col, col + 1, 
55
 
                             row, row + 1);
56
 
}
57
 
 
58
 
GdkPixmap*
59
 
Pocket::CreateFromXpm(char** data)
60
 
{
61
 
   GtkStyle* style = gtk_widget_get_style(_table);   
62
 
   return gdk_pixmap_colormap_create_from_xpm_d(
63
 
      _table->window, gtk_widget_get_colormap(_table), &_mask,
64
 
      &style->bg[GTK_STATE_NORMAL], data);
 
30
   _pixmapwid = gtk_image_new_from_stock(GROUNDHOG_STOCK_LEFT_RED, 
 
31
                                         Icons::Size());
 
32
/*   gtk_table_attach_defaults(GTK_TABLE(_table), _pixmapwid, col, col + 1, 
 
33
     row, row + 1); */
 
34
   gtk_table_attach(GTK_TABLE(_table), _pixmapwid, col, col + 1, 
 
35
                    row, row + 1, GTK_EXPAND, GTK_EXPAND, 0, 0);
65
36
}
66
37
 
67
38
void 
68
39
Pocket::PutBall(Ball* ball)
69
40
{
 
41
   const gchar* stock_id = 0;
 
42
 
70
43
   _ball = ball;
71
44
   switch (ball->GetColor()) {
72
45
   case Ball::Red:
73
 
      gtk_pixmap_set(GTK_PIXMAP(_pixmapwid), _red_pixmap, 0);
 
46
      stock_id = GetRedPixmap();
74
47
      break;
75
48
   case Ball::Green:
76
 
      gtk_pixmap_set(GTK_PIXMAP(_pixmapwid), _green_pixmap, 0);
 
49
      stock_id = GetGreenPixmap();
77
50
      break;
78
51
   case Ball::Blue:
79
 
      gtk_pixmap_set(GTK_PIXMAP(_pixmapwid), _blue_pixmap, 0);
 
52
      stock_id = GetBluePixmap();
80
53
      break;
81
54
   case Ball::Yellow:
82
 
      gtk_pixmap_set(GTK_PIXMAP(_pixmapwid), _yellow_pixmap, 0);
 
55
      stock_id = GetYellowPixmap();
83
56
      break;
84
57
   }
 
58
   gtk_image_set_from_stock(GTK_IMAGE(_pixmapwid), stock_id, Icons::Size());
85
59
   Element::PutBall(ball);
86
60
}
87
61
 
105
79
              std::not1(std::mem_fun(&Pocket::HasRightBall))) == _set.end();
106
80
}
107
81
 
108
 
LeftPocket::LeftPocket(GtkWidget* table, int row, int col) : Pocket(table)
109
 
{
110
 
   _red_pixmap = CreateFromXpm(left_red_xpm);
111
 
   _green_pixmap = CreateFromXpm(left_green_xpm);
112
 
   _blue_pixmap = CreateFromXpm(left_blue_xpm);
113
 
   _yellow_pixmap = CreateFromXpm(left_yellow_xpm);
114
 
   InsertInTable(row, col, _red_pixmap);
115
 
}
116
 
 
117
82
void 
118
83
LeftPocket::MoveBall(Ball* ball)
119
84
{
132
97
   _ball->SetDirection(Ball::MovingRight);
133
98
}
134
99
 
135
 
UpperPocket::UpperPocket(GtkWidget* table, int row, int col) : Pocket(table)
136
 
{
137
 
   _red_pixmap = CreateFromXpm(upper_red_xpm);
138
 
   _green_pixmap = CreateFromXpm(upper_green_xpm);
139
 
   _blue_pixmap = CreateFromXpm(upper_blue_xpm);
140
 
   _yellow_pixmap = CreateFromXpm(upper_yellow_xpm);
141
 
   InsertInTable(row, col, _red_pixmap);
142
 
}
143
 
 
144
100
void 
145
101
UpperPocket::MoveBall(Ball* ball)
146
102
{
159
115
   _ball->SetDirection(Ball::MovingDown);
160
116
}
161
117
 
162
 
RightPocket::RightPocket(GtkWidget* table, int row, int col) : Pocket(table)
163
 
{
164
 
   _red_pixmap = CreateFromXpm(right_red_xpm);
165
 
   _green_pixmap = CreateFromXpm(right_green_xpm);
166
 
   _blue_pixmap = CreateFromXpm(right_blue_xpm);
167
 
   _yellow_pixmap = CreateFromXpm(right_yellow_xpm);
168
 
   InsertInTable(row, col, _red_pixmap);
169
 
}
170
 
 
171
118
void 
172
119
RightPocket::MoveBall(Ball* ball)
173
120
{
186
133
   _ball->SetDirection(Ball::MovingLeft);
187
134
}
188
135
 
189
 
LowerPocket::LowerPocket(GtkWidget* table, int row, int col) : Pocket(table)
190
 
{
191
 
   _red_pixmap = CreateFromXpm(lower_red_xpm);
192
 
   _green_pixmap = CreateFromXpm(lower_green_xpm);
193
 
   _blue_pixmap = CreateFromXpm(lower_blue_xpm);
194
 
   _yellow_pixmap = CreateFromXpm(lower_yellow_xpm);
195
 
   InsertInTable(row, col, _red_pixmap);
196
 
}
197
 
 
198
136
void 
199
137
LowerPocket::MoveBall(Ball* ball)
200
138
{