-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcEditorFrame.h
More file actions
139 lines (109 loc) · 2.56 KB
/
cEditorFrame.h
File metadata and controls
139 lines (109 loc) · 2.56 KB
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
138
139
#pragma once
#include "wx/wx.h"
#include "cCanvas.h"
class Sprite
{
public:
Sprite() = default;
Sprite(int w, int h)
{
Create(w, h);
}
Sprite(std::wstring sFile)
{
if (!Load(sFile))
Create(16, 16);
}
~Sprite()
{
delete[] m_Glyphs;
delete[] m_Colours;
}
int nWidth = 0;
int nHeight = 0;
private:
short* m_Glyphs = nullptr;
short* m_Colours = nullptr;
void Create(int w, int h)
{
nWidth = w;
nHeight = h;
m_Glyphs = new short[w * h];
m_Colours = new short[w * h];
for (int i = 0; i < w * h; i++)
{
m_Glyphs[i] = L' ';
m_Colours[i] = 0;
}
}
public:
void SetGlyph(int x, int y, short c)
{
if (x >= 0 && x < nWidth && y >= 0 && y < nHeight)
m_Glyphs[y * nWidth + x] = c;
}
void SetColour(int x, int y, short c)
{
if (x >= 0 && x < nWidth && y >= 0 && y < nHeight)
m_Colours[y * nWidth + x] = c;
}
short GetGlyph(int x, int y)
{
if (x >= 0 && x < nWidth && y >= 0 && y < nHeight)
return m_Glyphs[y * nWidth + x];
return L' ';
}
short GetColour(int x, int y)
{
if (x >= 0 && x < nWidth && y >= 0 && y < nHeight)
return m_Colours[y * nWidth + x];
return L' ';
}
bool Save(const std::wstring& sFile)
{
FILE* f = nullptr;
_wfopen_s(&f, sFile.c_str(), L"wb");
if (f == nullptr)
return false;
fwrite(&nWidth, sizeof(int), 1, f);
fwrite(&nHeight, sizeof(int), 1, f);
fwrite(m_Colours, sizeof(short), nWidth * nHeight, f);
fwrite(m_Glyphs, sizeof(short), nWidth * nHeight, f);
fclose(f);
return true;
}
bool Load(const std::wstring& sFile)
{
nWidth = 0;
nHeight = 0;
FILE* f = nullptr;
_wfopen_s(&f, sFile.c_str(), L"rb");
if (f == nullptr)
return false;
std::fread(&nWidth, sizeof(int), 1, f);
std::fread(&nHeight, sizeof(int), 1, f);
Create(nWidth, nHeight);
std::fread(m_Colours, sizeof(short), nWidth * nHeight, f);
std::fread(m_Glyphs, sizeof(short), nWidth * nHeight, f);
std::fclose(f);
return true;
}
};
class cEditorFrame : public wxMDIChildFrame
{
public:
cEditorFrame(wxMDIParentFrame* parent, const wxString& sName);
virtual ~cEditorFrame();
void SetColour(int c);
bool Save(const wxString& sFileName);
bool Open(const wxString& sFileName);
bool New(int r, int c);
private:
cCanvas *m_Canvas = nullptr;
wxStatusBar *m_StatusBar = nullptr;
wxSlider *m_ZoomSlider = nullptr;
Sprite* m_sprData = nullptr;
unsigned char* m_pSprite = nullptr;
void OnZoomChange(wxCommandEvent& evt);
wxDECLARE_EVENT_TABLE();
};