-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainWindow.cpp
More file actions
49 lines (43 loc) · 1.32 KB
/
mainWindow.cpp
File metadata and controls
49 lines (43 loc) · 1.32 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
#include "mainWindow.h"
#include <string>
#include <wx/choicdlg.h>
wxBEGIN_EVENT_TABLE(mainWindow, wxFrame)
EVT_SIZE(mainWindow::onSize)
EVT_TIMER(TIMER_ID, mainWindow::onFrame)
wxEND_EVENT_TABLE()
mainWindow::mainWindow(wxSize size, threadSafeScreen* tss, int delay) : wxFrame(nullptr, WINDOW_ID, "VirtualScreen", wxPoint(200, 200), size), tss(tss) {
renderSurface = new wxWindow(this, wxID_ANY, wxDefaultPosition, size);
renderSurface->SetBackgroundStyle(wxBG_STYLE_PAINT);
renderSurface->Bind(wxEVT_PAINT, &mainWindow::onPaint, this);
frameTimer = new wxTimer(this, TIMER_ID);
frameTimer->Start(delay);
}
void mainWindow::onPaint(wxPaintEvent& event) {
if (buffer.IsOk()) {
wxPaintDC dc(renderSurface);
dc.DrawBitmap(buffer, 0, 0);
}
}
void mainWindow::onSize(wxSizeEvent& event) {
doRepaint();
}
void mainWindow::doRepaint() {
if (tss->initialized) {
wxSize clientSize = wxFrame::GetClientSize();
int width = clientSize.GetWidth();
int height = clientSize.GetHeight();
if (width > 0 && height > 0) {
renderSurface->SetSize(clientSize);
wxImage scaled = tss->getImage().Scale(width, height);
buffer = wxBitmap(scaled, -1);
renderSurface->Refresh();
renderSurface->Update();
}
}
}
void mainWindow::onFrame(wxTimerEvent& event) {
if (updateNextFrame) {
updateNextFrame = false;
doRepaint();
}
}