[WIP-THREAD] Encapsulate printer calls for queueing.
VERY ugly and weird...
This commit is contained in:
parent
24cc810eb6
commit
ccd9847672
|
@ -58,6 +58,7 @@ GameArea::GameArea()
|
||||||
Bind(WX_THREAD_REQUEST_UPDATEDRAWPANEL, &GameArea::RequestUpdateDrawPanel, this);
|
Bind(WX_THREAD_REQUEST_UPDATEDRAWPANEL, &GameArea::RequestUpdateDrawPanel, this);
|
||||||
Bind(WX_THREAD_REQUEST_DRAWFRAME, &GameArea::RequestDrawFrame, this);
|
Bind(WX_THREAD_REQUEST_DRAWFRAME, &GameArea::RequestDrawFrame, this);
|
||||||
Bind(WX_THREAD_REQUEST_UPDATESTATUSBAR, &GameArea::RequestUpdateStatusBar, this);
|
Bind(WX_THREAD_REQUEST_UPDATESTATUSBAR, &GameArea::RequestUpdateStatusBar, this);
|
||||||
|
Bind(WX_THREAD_REQUEST_GBPRINTER, &GameArea::ShowPrinter, this);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1149,6 +1150,55 @@ void GameArea::RequestStatusBar(int speed, int frames)
|
||||||
wxQueueEvent(this, event);
|
wxQueueEvent(this, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct PrinterDataDialog {
|
||||||
|
uint16_t* to_print;
|
||||||
|
uint16_t** accum_prdata;
|
||||||
|
int lines, feed;
|
||||||
|
int *accum_prdata_len, *accum_prdata_size;
|
||||||
|
};
|
||||||
|
PrinterDataDialog printerDataDialog;
|
||||||
|
|
||||||
|
void GameArea::RequestGBPrinter(uint16_t* to_print, uint16_t** accum_prdata, int lines, int feed, int *accum_prdata_len, int *accum_prdata_size)
|
||||||
|
{
|
||||||
|
wxThreadEvent *event = new wxThreadEvent(WX_THREAD_REQUEST_GBPRINTER);
|
||||||
|
printerDataDialog = {to_print, accum_prdata, lines, feed, accum_prdata_len, accum_prdata_size};
|
||||||
|
event->SetPayload(&printerDataDialog);
|
||||||
|
wxQueueEvent(this, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameArea::ShowPrinter(wxThreadEvent& event)
|
||||||
|
{
|
||||||
|
wxCriticalSectionLocker lock(MainFrame::emulationCS);
|
||||||
|
PrinterDataDialog *pdd = event.GetPayload<PrinterDataDialog*>();
|
||||||
|
|
||||||
|
uint16_t* to_print = pdd->to_print;
|
||||||
|
uint16_t** accum_prdata = pdd->accum_prdata;
|
||||||
|
int lines = pdd->lines;
|
||||||
|
int feed = pdd->feed;
|
||||||
|
int *accum_prdata_len = pdd->accum_prdata_len;
|
||||||
|
int *accum_prdata_size = pdd->accum_prdata_size;
|
||||||
|
|
||||||
|
PrintDialog dlg(to_print, lines, !(feed & 15));
|
||||||
|
int ret = dlg.ShowModal();
|
||||||
|
|
||||||
|
if (ret == wxID_OK) {
|
||||||
|
*accum_prdata_len = (lines + 1) * 162;
|
||||||
|
|
||||||
|
if (to_print != *accum_prdata) {
|
||||||
|
if (*accum_prdata_size < *accum_prdata_len) {
|
||||||
|
if (!(*accum_prdata_size))
|
||||||
|
*accum_prdata = (uint16_t*)calloc(*accum_prdata_len, 2);
|
||||||
|
else
|
||||||
|
*accum_prdata = (uint16_t*)realloc(*accum_prdata, *accum_prdata_len * 2);
|
||||||
|
|
||||||
|
*accum_prdata_size = *accum_prdata_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(*accum_prdata, to_print, *accum_prdata_len * 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void GameArea::RequestDrawFrame(wxThreadEvent& WXUNUSED(event))
|
void GameArea::RequestDrawFrame(wxThreadEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
wxCriticalSectionLocker lock(MainFrame::emulationCS);
|
wxCriticalSectionLocker lock(MainFrame::emulationCS);
|
||||||
|
|
|
@ -664,53 +664,6 @@ int systemGetSensorZ()
|
||||||
return sensorz[gopts.default_stick - 1] / 10;
|
return sensorz[gopts.default_stick - 1] / 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
class PrintDialog : public wxEvtHandler, public wxPrintout {
|
|
||||||
public:
|
|
||||||
PrintDialog(const uint16_t* data, int lines, bool cont);
|
|
||||||
~PrintDialog();
|
|
||||||
int ShowModal()
|
|
||||||
{
|
|
||||||
dlg->SetWindowStyle(wxCAPTION | wxRESIZE_BORDER);
|
|
||||||
|
|
||||||
if (gopts.keep_on_top)
|
|
||||||
dlg->SetWindowStyle(dlg->GetWindowStyle() | wxSTAY_ON_TOP);
|
|
||||||
else
|
|
||||||
dlg->SetWindowStyle(dlg->GetWindowStyle() & ~wxSTAY_ON_TOP);
|
|
||||||
|
|
||||||
CheckPointer(wxGetApp().frame);
|
|
||||||
return wxGetApp().frame->ShowModal(dlg);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
void DoSave(wxCommandEvent&);
|
|
||||||
void DoPrint(wxCommandEvent&);
|
|
||||||
void ChangeMag(wxCommandEvent&);
|
|
||||||
void ShowImg(wxPaintEvent&);
|
|
||||||
bool OnPrintPage(int pno);
|
|
||||||
void OnPreparePrinting();
|
|
||||||
bool HasPage(int pno) { return pno <= npw * nph; }
|
|
||||||
void GetPageInfo(int* minp, int* maxp, int* pfrom, int* pto)
|
|
||||||
{
|
|
||||||
*minp = 1;
|
|
||||||
*maxp = npw * nph;
|
|
||||||
*pfrom = 1;
|
|
||||||
*pto = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxDialog* dlg;
|
|
||||||
wxPanel* p;
|
|
||||||
wxImage img;
|
|
||||||
wxBitmap* bmp;
|
|
||||||
wxControlWithItems* mag;
|
|
||||||
|
|
||||||
static wxPrintData* printdata;
|
|
||||||
static wxPageSetupDialogData* pagedata;
|
|
||||||
wxRect margins;
|
|
||||||
int npw, nph;
|
|
||||||
|
|
||||||
DECLARE_CLASS(PrintDialog)
|
|
||||||
};
|
|
||||||
|
|
||||||
IMPLEMENT_CLASS(PrintDialog, wxEvtHandler)
|
IMPLEMENT_CLASS(PrintDialog, wxEvtHandler)
|
||||||
|
|
||||||
PrintDialog::PrintDialog(const uint16_t* data, int lines, bool cont):
|
PrintDialog::PrintDialog(const uint16_t* data, int lines, bool cont):
|
||||||
|
@ -1022,6 +975,9 @@ void systemGbPrint(uint8_t* data, int len, int pages, int feed, int pal, int con
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef NO_THREAD_MAINLOOP
|
||||||
|
panel->RequestGBPrinter(to_print, &accum_prdata, lines, feed, &accum_prdata_len, &accum_prdata_size);
|
||||||
|
#else
|
||||||
PrintDialog dlg(to_print, lines, !(feed & 15));
|
PrintDialog dlg(to_print, lines, !(feed & 15));
|
||||||
int ret = dlg.ShowModal();
|
int ret = dlg.ShowModal();
|
||||||
|
|
||||||
|
@ -1041,6 +997,7 @@ void systemGbPrint(uint8_t* data, int len, int pages, int feed, int pal, int con
|
||||||
memcpy(accum_prdata, to_print, accum_prdata_len * 2);
|
memcpy(accum_prdata, to_print, accum_prdata_len * 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void systemScreenMessage(const wxString& msg)
|
void systemScreenMessage(const wxString& msg)
|
||||||
|
|
|
@ -510,6 +510,7 @@ class DrawingPanelBase;
|
||||||
wxDEFINE_EVENT(WX_THREAD_REQUEST_UPDATEDRAWPANEL, wxThreadEvent);
|
wxDEFINE_EVENT(WX_THREAD_REQUEST_UPDATEDRAWPANEL, wxThreadEvent);
|
||||||
wxDEFINE_EVENT(WX_THREAD_REQUEST_DRAWFRAME, wxThreadEvent);
|
wxDEFINE_EVENT(WX_THREAD_REQUEST_DRAWFRAME, wxThreadEvent);
|
||||||
wxDEFINE_EVENT(WX_THREAD_REQUEST_UPDATESTATUSBAR, wxThreadEvent);
|
wxDEFINE_EVENT(WX_THREAD_REQUEST_UPDATESTATUSBAR, wxThreadEvent);
|
||||||
|
wxDEFINE_EVENT(WX_THREAD_REQUEST_GBPRINTER, wxThreadEvent);
|
||||||
#endif // NO_THREAD_MAINLOOP
|
#endif // NO_THREAD_MAINLOOP
|
||||||
|
|
||||||
class GameArea : public wxPanel, public HiDPIAware
|
class GameArea : public wxPanel, public HiDPIAware
|
||||||
|
@ -530,6 +531,8 @@ public:
|
||||||
void RequestUpdateStatusBar(wxThreadEvent&);
|
void RequestUpdateStatusBar(wxThreadEvent&);
|
||||||
void RequestDraw();
|
void RequestDraw();
|
||||||
void RequestStatusBar(int speed, int frames);
|
void RequestStatusBar(int speed, int frames);
|
||||||
|
void RequestGBPrinter(uint16_t*, uint16_t**, int, int, int*, int*);
|
||||||
|
void ShowPrinter(wxThreadEvent&);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void DestroyDrawingPanel();
|
void DestroyDrawingPanel();
|
||||||
|
@ -776,6 +779,53 @@ private:
|
||||||
|
|
||||||
#include "opts.h"
|
#include "opts.h"
|
||||||
|
|
||||||
|
class PrintDialog : public wxEvtHandler, public wxPrintout {
|
||||||
|
public:
|
||||||
|
PrintDialog(const uint16_t* data, int lines, bool cont);
|
||||||
|
~PrintDialog();
|
||||||
|
int ShowModal()
|
||||||
|
{
|
||||||
|
dlg->SetWindowStyle(wxCAPTION | wxRESIZE_BORDER);
|
||||||
|
|
||||||
|
if (gopts.keep_on_top)
|
||||||
|
dlg->SetWindowStyle(dlg->GetWindowStyle() | wxSTAY_ON_TOP);
|
||||||
|
else
|
||||||
|
dlg->SetWindowStyle(dlg->GetWindowStyle() & ~wxSTAY_ON_TOP);
|
||||||
|
|
||||||
|
CheckPointer(wxGetApp().frame);
|
||||||
|
return wxGetApp().frame->ShowModal(dlg);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void DoSave(wxCommandEvent&);
|
||||||
|
void DoPrint(wxCommandEvent&);
|
||||||
|
void ChangeMag(wxCommandEvent&);
|
||||||
|
void ShowImg(wxPaintEvent&);
|
||||||
|
bool OnPrintPage(int pno);
|
||||||
|
void OnPreparePrinting();
|
||||||
|
bool HasPage(int pno) { return pno <= npw * nph; }
|
||||||
|
void GetPageInfo(int* minp, int* maxp, int* pfrom, int* pto)
|
||||||
|
{
|
||||||
|
*minp = 1;
|
||||||
|
*maxp = npw * nph;
|
||||||
|
*pfrom = 1;
|
||||||
|
*pto = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxDialog* dlg;
|
||||||
|
wxPanel* p;
|
||||||
|
wxImage img;
|
||||||
|
wxBitmap* bmp;
|
||||||
|
wxControlWithItems* mag;
|
||||||
|
|
||||||
|
static wxPrintData* printdata;
|
||||||
|
static wxPageSetupDialogData* pagedata;
|
||||||
|
wxRect margins;
|
||||||
|
int npw, nph;
|
||||||
|
|
||||||
|
DECLARE_CLASS(PrintDialog)
|
||||||
|
};
|
||||||
|
|
||||||
// I should add this to SoundDriver, but wxArrayString is wx-specific
|
// I should add this to SoundDriver, but wxArrayString is wx-specific
|
||||||
// I suppose I could make subclass wxSoundDriver. maybe later.
|
// I suppose I could make subclass wxSoundDriver. maybe later.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue