/
main_panel.cpp
137 lines (111 loc) · 3.88 KB
/
main_panel.cpp
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#ifdef WX_PRECOMP
#include "wx_pch.h"
#endif
#ifdef __BORLANDC__
#pragma hdrstop
#endif //__BORLANDC__
#include "wx/dcbuffer.h"
#include "business/Board.h"
#include "UISettings.h"
#include "eight_puzzleMain.h"
#include "SolutionLog.h"
#include "BoardPanel.h"
#include "main_panel.h"
//helper functions
enum wxbuildinfoformat {
short_f, long_f };
wxString wxbuildinfo(wxbuildinfoformat format)
{
wxString wxbuild(wxVERSION_STRING);
if (format == long_f )
{
#if defined(__WXMSW__)
wxbuild << _T("-Windows");
#elif defined(__WXMAC__)
wxbuild << _T("-Mac");
#elif defined(__UNIX__)
wxbuild << _T("-Linux");
#endif
#if wxUSE_UNICODE
wxbuild << _T("-Unicode build");
#else
wxbuild << _T("-ANSI build");
#endif // wxUSE_UNICODE
}
return wxbuild;
}
//MainPanel::MainPanel(wxFrame *frame, int x, int y, int w, int h): wxPanel( frame, wxID_ANY, wxPoint(x, y), wxSize(w, h))
MainPanel::MainPanel(wxFrame *frame): wxPanel( frame, wxID_ANY ), frame(frame)
{
bgImage = new wxImage();
bgImage->LoadFile(wxString(_("bg/")) + UISettings::BG_FILE_NAME, UISettings::BG_BITMAP_TYPE);
bgBitmap = new wxBitmap(*bgImage);
topSizer = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *leftSizer = new wxBoxSizer(wxVERTICAL);
//messageContainer = new wxStaticText(this, -1, _("Puzzle solved!"));
//leftSizer->Add(messageContainer, wxSizerFlags().Align(wxALIGN_RIGHT).Border(wxALL & ~wxBOTTOM, 5));
//messageContainer->Hide();
boardPanel = new BoardPanel(this);
leftSizer->Add(boardPanel, 0, wxALL, 5);
wxButton *btnGeneratePuzzle = new wxButton(this, idBtnGeneratePuzzle, wxT("&Generate Puzzle"), wxDefaultPosition, wxDefaultSize, 0);
leftSizer->Add(btnGeneratePuzzle, 0, wxLEFT|wxRIGHT|wxBOTTOM, 5);
wxButton *btnSolvePuzzle = new wxButton(this, idBtnSolvePuzzle, wxT("&Solve Puzzle"), wxDefaultPosition, wxDefaultSize, 0);
leftSizer->Add(btnSolvePuzzle, 0, wxLEFT|wxRIGHT|wxBOTTOM, 5);
wxButton *btnStopPuzzle = new wxButton(this, idBtnStopPuzzle, wxT("S&top Puzzle"), wxDefaultPosition, wxDefaultSize, 0);
leftSizer->Add(btnStopPuzzle, 0, wxLEFT|wxRIGHT|wxBOTTOM, 5);
topSizer->Add(leftSizer, 0, wxALL, 0);
wxBoxSizer* rightSizer = new wxBoxSizer(wxVERTICAL);
solutionLog = new SolutionLog( this );
solutionLog->SetMaxLength(10000000);
rightSizer->Add(solutionLog, wxSizerFlags(1).Expand().Border(wxALL, 5));
topSizer->Add(rightSizer, 1, wxEXPAND, 5);
this->SetSizer(topSizer);
topSizer->Fit(this);
topSizer->SetSizeHints( frame );
frame->SetSize(wxSize(1024 - 130, 768 - 40));
}
MainPanel::~MainPanel()
{
if (bgBitmap != NULL) {
delete bgBitmap;
}
if (bgImage != NULL) {
delete bgImage;
}
}
BEGIN_EVENT_TABLE(MainPanel, wxPanel)
EVT_PAINT(MainPanel::OnPaint)
EVT_BUTTON(idBtnQuit, MainPanel::OnQuit)
EVT_BUTTON(idBtnAbout, MainPanel::OnAbout)
EVT_BUTTON(idBtnGeneratePuzzle, MainPanel::OnGeneratePuzzle)
EVT_BUTTON(idBtnSolvePuzzle, MainPanel::OnSolvePuzzle)
EVT_BUTTON(idBtnStopPuzzle, MainPanel::OnStopPuzzle)
END_EVENT_TABLE()
void MainPanel::OnPaint(wxPaintEvent &event)
{
wxBufferedPaintDC pdc(this, m_bufferBitmap);
wxDC &dc = pdc ;
PrepareDC(dc);
wxBitmap subBitmap = bgBitmap->GetSubBitmap(wxRect(0 + 145, 0 + 95, 1024 - 145, 768 - 95));
dc.DrawBitmap(subBitmap, 0, 0);
}
void MainPanel::OnQuit(wxCommandEvent &event)
{
((eight_puzzleDialog *) frame)->OnQuit(event);
}
void MainPanel::OnAbout(wxCommandEvent &event)
{
((eight_puzzleDialog *) frame)->OnAbout(event);
}
void MainPanel::OnGeneratePuzzle(wxCommandEvent &event)
{
((eight_puzzleDialog *) frame)->OnGeneratePuzzle(event);
}
void MainPanel::OnSolvePuzzle(wxCommandEvent &event)
{
((eight_puzzleDialog *) frame)->OnSolvePuzzle(event);
}
void MainPanel::OnStopPuzzle(wxCommandEvent &event)
{
((eight_puzzleDialog *) frame)->OnStopPuzzle(event);
}