1 #ifndef BOARD_HH
2 #define BOARD_HH
3 #include "game.hh"
4 #include "panel.hh"
5 #include "swwidget.hh"
6 #include "tile.hh"
7 class Hint;
8
9 class Board: public GameHooks, public SwWidget {
10
11 Panel *_panel;
12 Game *_game;
13 Tileset *_tileset;
14 bool _redraw_live;
15
16 short _layout_x;
17 short _layout_y;
18 short _topmost_tile;
19 short _botmost_tile;
20 short _leftmost_tile;
21 short _rightmost_tile;
22
23 short _tile_width;
24 short _tile_height;
25 short _tile_xborder;
26 short _tile_yborder;
27 short _tile_shadow;
28 Vector<short> _tile_flags;
29
30 bool _buffering;
31 Pixmap _buffer;
32 int _buffer_w;
33 int _buffer_h;
34 int _buffer_x;
35 int _buffer_y;
36
37 static const int NMASK = 10;
38 Pixmap _mask[NMASK];
39 int _mask_tile[NMASK];
40 int _mask_next_mru[NMASK];
41 int _mask_prev_mru[NMASK];
42 int _mask_mru;
43 int _masking;
44 GC _masking_gc;
45 Tile *_masking_tile;
46
47 GC _copygc;
48 GC _orgc;
49 GC _erasegc;
50 GC _maskgc;
51 GC _mask_one_gc;
52 GC _mask_zero_gc;
53
54 Tile *_selected;
55
56 Hint *_hint;
57
58 Vector<Tile *> _display_order;
59
60 void display_order_dfs(Game *, Tile *);
61
62 void copy_buffer();
63 void buffer_on(int x, int y);
64 void buffer_off();
65
66 void mark_mask_used(int);
67 int lru_mask() const;
68
69 void mark_around(Tile *, bool up, bool down);
70 void draw_neighborhood(Tile *, int);
71
72 public:
73
74 enum TileFlag {
75 fLit = 1,
76 fKeepLit = 2,
77 };
78
79 Board(Panel *, Game *, Tileset *);
80 virtual ~Board();
81
game() const82 Game *game() const { return _game; }
83
84 int topmost_tile_y() const;
85 void tile_layout_size(int *, int *) const;
86
87 void set_tileset(Tileset *);
88 void set_background(Pixmap);
89 void center_layout();
90
91 void position(Tile *, short *x, short *y) const;
92 void unposition(int x, int y, short *r, short *c) const;
93 Tile *find_tile(short, short) const;
94
95 // should be in a common widget structure
96 void move(int, int);
97
98 void set_tile_flag(Tile *, TileFlag, bool);
99 bool tile_flag(Tile *, TileFlag) const;
100
light(Tile * t)101 void light(Tile *t) { set_lit(t, true); }
unlight(Tile * t)102 void unlight(Tile *t) { set_lit(t, false); }
103 void set_lit(Tile *, bool);
104 bool lit(Tile *t) const;
105
106 void draw(Tile *);
107 void draw_area(short rowtop, short colleft, short rowbot, short colright);
108 void draw_marked();
109
110 void draw_subimage(Pixmap, Pixmap, int, int, int, int, int, int);
111
bell()112 void bell() { _panel->bell(); }
flush()113 void flush() { _panel->flush(); }
114
selected() const115 Tile *selected() const { return _selected; }
116 void select(Tile *);
117 void deselect();
118
119 void clear_traversal();
120 Tile *traverse(int);
121
hint() const122 Hint *hint() const { return _hint; }
123
124 void layout_hook(Game *);
125 void start_hook(Game *);
126 void add_tile_hook(Game *, Tile *);
127 void remove_tile_hook(Game *, Tile *);
128
129 };
130
131
132 inline void
set_tile_flag(Tile * t,TileFlag flag,bool on)133 Board::set_tile_flag(Tile *t, TileFlag flag, bool on)
134 {
135 if (on)
136 _tile_flags[t->number()] |= flag;
137 else
138 _tile_flags[t->number()] &= ~flag;
139 }
140
141 inline bool
tile_flag(Tile * t,TileFlag flag) const142 Board::tile_flag(Tile *t, TileFlag flag) const
143 {
144 return _tile_flags[t->number()] & flag;
145 }
146
147 inline bool
lit(Tile * t) const148 Board::lit(Tile *t) const
149 {
150 return tile_flag(t, fLit);
151 }
152
153 #endif
154