penguins  1.0.0
canvas.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include "game.h"
4 #include "utils.h"
5 #include <wx/bitmap.h>
6 #include <wx/dc.h>
7 #include <wx/dcmemory.h>
8 #include <wx/defs.h>
9 #include <wx/event.h>
10 #include <wx/gdicmn.h>
11 #include <wx/types.h>
12 #include <wx/window.h>
13 
14 class GamePanel;
15 
17 class CanvasPanel : public wxWindow {
18 public:
19  static const wxCoord TILE_SIZE = 40;
20 
22 
23  virtual bool AcceptsFocus() const override {
24  return true;
25  }
26 
27  wxSize get_canvas_size() const;
28  Coords tile_coords_at_point(wxPoint point) const;
29  wxRect get_tile_rect(Coords coords) const;
30  wxPoint get_tile_centre(Coords coords) const;
31 
33 
34  bool mouse_within_window = false;
35  bool mouse_is_down = false;
36  bool mouse_is_down_real = false;
40 
41  void paint_selected_tile_outline(wxDC& dc, Coords coords, bool blocked = false);
42  void paint_move_arrow(wxDC& dc, Coords start, Coords end);
43  void paint_move_arrow(wxDC& dc, Coords start, Coords end, Coords fail, bool valid);
44 
48  };
49 
50  void paint_arrow_head(
51  wxDC& dc,
52  wxPoint start,
53  wxPoint end,
54  wxSize head_size,
56  );
57 
58 protected:
59  void on_paint(wxPaintEvent& event);
60  void draw_bitmap(wxDC& dc, const wxBitmap& bitmap, const wxPoint& pos);
61  void paint_tiles(wxDC& dc, const wxRect& update_region);
62  void paint_board(wxDC& dc, const wxRect& update_region, wxDC& tiles_dc);
63 
64  void on_any_mouse_event(wxMouseEvent& event);
65 
70 
71 #ifdef __WXMSW__
72  wxMemoryDC draw_bitmap_dc;
73 #endif
74 
77 
79 };
Responsible for drawing the board and painting the UI overlays.
Definition: canvas.hh:17
wxRect get_tile_rect(Coords coords) const
Definition: canvas.cc:50
wxPoint mouse_pos
Definition: canvas.hh:37
GamePanel * panel
Definition: canvas.hh:75
void paint_selected_tile_outline(wxDC &dc, Coords coords, bool blocked=false)
Definition: canvas.cc:263
wxMemoryDC board_dc
Definition: canvas.hh:67
Game * game
Definition: canvas.hh:76
void on_paint(wxPaintEvent &event)
Definition: canvas.cc:72
void paint_tiles(wxDC &dc, const wxRect &update_region)
Definition: canvas.cc:142
bool mouse_is_down
Definition: canvas.hh:35
virtual bool AcceptsFocus() const override
Definition: canvas.hh:23
void paint_arrow_head(wxDC &dc, wxPoint start, wxPoint end, wxSize head_size, ArrowHeadType head_type=ARROW_HEAD_NORMAL)
Definition: canvas.cc:306
void paint_move_arrow(wxDC &dc, Coords start, Coords end)
Definition: canvas.cc:269
void on_any_mouse_event(wxMouseEvent &event)
Definition: canvas.cc:325
static const wxCoord TILE_SIZE
Definition: canvas.hh:19
Coords tile_coords_at_point(wxPoint point) const
Definition: canvas.cc:46
wxBitmap board_bitmap
Definition: canvas.hh:66
@ ARROW_HEAD_NORMAL
Definition: canvas.hh:46
@ ARROW_HEAD_CROSS
Definition: canvas.hh:47
CanvasPanel(wxWindow *parent, wxWindowID id, GamePanel *panel)
Definition: canvas.cc:33
bool mouse_is_down_real
Definition: canvas.hh:36
wxDECLARE_EVENT_TABLE()
wxPoint get_tile_centre(Coords coords) const
Definition: canvas.cc:54
Coords get_selected_penguin_coords() const
Definition: canvas.cc:59
wxBitmap tiles_bitmap
Definition: canvas.hh:68
void draw_bitmap(wxDC &dc, const wxBitmap &bitmap, const wxPoint &pos)
Definition: canvas.cc:131
void paint_board(wxDC &dc, const wxRect &update_region, wxDC &tiles_dc)
Definition: canvas.cc:216
bool mouse_within_window
Definition: canvas.hh:34
wxSize get_canvas_size() const
Definition: canvas.cc:42
wxMemoryDC tiles_dc
Definition: canvas.hh:69
wxPoint prev_mouse_pos
Definition: canvas.hh:38
wxPoint mouse_drag_pos
Definition: canvas.hh:39
int wxCoord
The core of the unified game logic library, contains the Game struct.
const wxPoint wxDefaultPosition
A pair of 2D coordinates, used for addressing the Game::board_grid.
Definition: utils.h:15
The central struct of the application, holds the game data and settings.
Definition: game.h:237
int wxWindowID