summaryrefslogtreecommitdiffhomepage
path: root/Tobii-EyeX/samples/ActivatableBoardGame/BoardWindow.h
blob: 50dc34694b3365a5dc4db815692c140f6714d9aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * BoardWindow class: Responsible for the game window and the GDI+ drawing.
 * Listens to notifications from the Board.
 * Owns the EyeX host.
 *
 * Copyright 2013 Tobii Technology AB. All rights reserved.
 */

#pragma once

#include <Windows.h>
#include <objidl.h>
#include <gdiplus.h>
#include "Observer.h"
#include "EyeXHost.h"

class Board;

class BoardWindow : Observer
{
public:
	BoardWindow(Board& board, HINSTANCE hInstance, int nCmdShow);
	virtual ~BoardWindow();

	// registers the window class; must be called once at application initialization.
	static void RegisterWindowClass(HINSTANCE hInstance);

	// From Observer
	void SubjectChanged();

private:
	// window procedure for the main window.
	static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

	// window procedure for the About dialog.
	static INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);

	// GDI+ drawing methods.
	void OnDraw(HDC hdc);
	void DrawGrid(Gdiplus::Graphics *graphics);
	void DrawHighlight(Gdiplus::Graphics* graphics, int row, int column);
	void DrawXMarker(Gdiplus::Graphics* graphics, Gdiplus::Pen* pen, int row, int column);
	void DrawOMarker(Gdiplus::Graphics* graphics, Gdiplus::Pen* pen, int row, int column);
	void DrawGameOver(Gdiplus::Graphics* graphics, WCHAR* message, const Gdiplus::Color& messageColor);

	// coordinate/board position mapping methods.
	int	BoardToClientAreaX(int column);
	int	BoardToClientAreaY(int row);
	int	ClientAreaToBoardColumn(int x);
	int	ClientAreaToBoardRow(int y);

	// region id/board position mapping methods.
	int	BoardPositionToRegionId(int row, int column);
	int	RegionIdToBoardRow(int regionId);
	int	RegionIdToBoardColumn(int regionId);

	// re-calculates the margins based on the size of the window.
	void UpdateMargins();

	// reports all vacant board positions as activatable regions to the EyeX host.
	void UpdateActivatableRegions();

	// makes a move at the given position.
	void MakeHumanPlayerMove(int row, int column);

	// event handlers.
	void OnSquareClicked(POINTS point);
	void OnSquareActivated(UINT regionId);
	void OnNewGameClicked();

	static const Gdiplus::Color BackgroundGazeInteractionFunctionalColor;
	static const Gdiplus::Color BackgroundMouseOnlyColor;
	static const Gdiplus::Color GridColor;
	static const Gdiplus::Color MarkerColor;
	static const Gdiplus::Color HighlightColor;
	static const Gdiplus::Color WonMessageColor;
	static const Gdiplus::Color LostMessageColor;
	static const int SquareSize;
	static const int MarkerMargin;
	static const int MarkerDiameter;
	static const TCHAR* WindowClassName;

	Board& _board;
	EyeXHost _eyeXHost;
	HINSTANCE _hInstance;
	HWND _hWnd;
	HMENU _hMenu;
	int _leftMargin;
	int _upperMargin;
	
	// private copy constructor and operator making the class non-copyable (declared but not implemented).
	BoardWindow(const BoardWindow&);
	BoardWindow& operator = (const BoardWindow&);
};