Changes to wxWidgets/SDL2 port :

- Updated UI
- OpenGL 3.0 with GLSL/GLSLP-support
- Improvements to Windows version
- Minor changes/bugfixes
Patch from bit.
This commit is contained in:
pcem_emulator 2017-07-30 10:39:27 +01:00
commit 2881d35680
90 changed files with 15042 additions and 5351 deletions

View file

@ -8,12 +8,20 @@
#include <wx/spinctrl.h>
#include <wx/xrc/xmlres.h>
#include <wx/stdpaths.h>
#include <wx/fileconf.h>
#include <wx/wfstream.h>
#include <wx/progdlg.h>
#include "wx-dialogbox.h"
#include "wx-app.h"
#include "wx-common.h"
#include "wx-status.h"
extern "C"
{
#include "thread.h"
}
int confirm()
{
if (emulation_state != EMULATION_STOPPED) {
@ -24,10 +32,22 @@ int confirm()
int wx_messagebox(void* window, const char* message, const char* title = NULL, int style = 5)
{
return wxMessageBox(message, title, style | wxCENTRE, (wxWindow*) window);
return wxMessageBox(message, title, style | wxCENTRE | wxSTAY_ON_TOP, (wxWindow*) window);
}
int wx_textentrydialog(void* window, const char* message, const char* title, const char* value, int min_length, int max_length, LONG_PARAM result)
void wx_simple_messagebox(const char* title, const char *format, ...)
{
char message[2048];
va_list ap;
va_start(ap, format);
vsnprintf(message, 2047, format, ap);
message[2047] = 0;
va_end(ap);
wx_messagebox(0, message, title, WX_MB_OK);
}
int wx_textentrydialog(void* window, const char* message, const char* title, const char* value, unsigned int min_length, unsigned int max_length, LONG_PARAM result)
{
while (1)
{
@ -39,7 +59,7 @@ int wx_textentrydialog(void* window, const char* message, const char* title, con
wxString value = dlg.GetValue();
if (value.Length() >= min_length)
{
strcpy((char*)result, value);
strcpy((char*)result, value.mb_str());
return TRUE;
}
}
@ -63,7 +83,7 @@ int wx_filedialog(void* window, const char* title, const char* path,
const char* extensions, const char* extension, int open, char* file)
{
wxFileDialog dlg((wxWindow*) window, title, "", path, extensions,
open ? wxFD_OPEN : wxFD_SAVE);
open ? (wxFD_OPEN | wxFD_FILE_MUST_EXIST) : (wxFD_SAVE | wxFD_OVERWRITE_PROMPT));
if (dlg.ShowModal() == wxID_OK)
{
wxString p = dlg.GetPath();
@ -74,10 +94,10 @@ int wx_filedialog(void* window, const char* title, const char* path,
if (!p.EndsWith("."))
p += ".";
p += extension;
strcpy(file, p);
strcpy(file, p.mb_str());
}
else
strcpy(file, p);
strcpy(file, p.mb_str());
return 0;
}
return 1;
@ -120,6 +140,30 @@ void* wx_getsubmenu(void* menu, int id)
return 0;
}
void* wx_getnativemenu(void* menu)
{
#ifdef _WIN32
return ((wxMenu*)menu)->GetHMenu();
#endif
return 0;
}
void* wx_getnativewindow(void* window)
{
#ifdef _WIN32
return ((wxWindow*)window)->GetHWND();
#endif
return 0;
}
#ifdef _WIN32
void wx_winsendmessage(void* window, int msg, INT_PARAM wParam, LONG_PARAM lParam)
{
WinSendMessageEvent* event = new WinSendMessageEvent(wx_getnativewindow(window), msg, wParam, lParam);
wxQueueEvent((wxWindow*)window, event);
}
#endif
void wx_appendmenu(void* sub_menu, int id, const char* title, enum wxItemKind type)
{
((wxMenu*) sub_menu)->Append(id, title, wxEmptyString, type);
@ -173,14 +217,19 @@ void wx_showwindow(void* window, int show)
wxQueueEvent((wxWindow*)window, event);
}
int wx_iswindowvisible(void* window)
{
return ((wxWindow*) window)->IsShown();
}
void wx_togglewindow(void* window)
{
wx_showwindow(window, -1);
}
void wx_callback(void* window, WX_CALLBACK callback)
void wx_callback(void* window, WX_CALLBACK callback, void* data)
{
CallbackEvent* event = new CallbackEvent(callback);
CallbackEvent* event = new CallbackEvent(callback, data);
wxQueueEvent((wxWindow*)window, event);
}
@ -231,17 +280,19 @@ int wx_sendmessage(void* window, int type, INT_PARAM param1, LONG_PARAM param2)
((wxComboBox*) window)->Append((char*) param2);
break;
case WX_CB_SETCURSEL:
((wxComboBox*) window)->Select(param1);
if (param1 >= 0 && param1 < ((wxComboBox*) window)->GetCount())
((wxComboBox*) window)->Select(param1);
break;
case WX_CB_GETCURSEL:
return ((wxComboBox*) window)->GetCurrentSelection();
break;
case WX_CB_GETLBTEXT:
strcpy((char*) param2, ((wxComboBox*) window)->GetString(param1));
strcpy((char*) param2, ((wxComboBox*) window)->GetString(param1).mb_str());
break;
case WX_CB_RESETCONTENT:
{
#ifndef __WXOSX_MAC__
((wxComboBox*) window)->SetValue("");
((wxComboBox*) window)->Clear();
#else
/* Clear() does not work on OSX */
@ -268,9 +319,9 @@ int wx_sendmessage(void* window, int type, INT_PARAM param1, LONG_PARAM param2)
break;
case WX_WM_GETTEXT:
if (((wxWindow*) window)->GetClassInfo()->IsKindOf(CLASSINFO(wxTextCtrl)))
strcpy((char*) param2, ((wxTextCtrl*) window)->GetValue());
strcpy((char*) param2, ((wxTextCtrl*) window)->GetValue().mb_str());
else
strcpy((char*) param2, ((wxStaticText*) window)->GetLabel());
strcpy((char*) param2, ((wxStaticText*) window)->GetLabel().mb_str());
break;
case WX_UDM_SETPOS:
((wxSpinCtrl*) window)->SetValue(param2);
@ -300,9 +351,14 @@ int wx_sendmessage(void* window, int type, INT_PARAM param1, LONG_PARAM param2)
{
return ((wxListBox*) window)->GetSelection();
}
case WX_LB_SETCURSEL:
{
((wxListBox*) window)->SetSelection(param1);
break;
}
case WX_LB_GETTEXT:
{
strcpy((char*) param2, ((wxListBox*) window)->GetString(param1));
strcpy((char*) param2, ((wxListBox*) window)->GetString(param1).mb_str());
break;
}
case WX_LB_INSERTSTRING:
@ -315,6 +371,11 @@ int wx_sendmessage(void* window, int type, INT_PARAM param1, LONG_PARAM param2)
((wxListBox*) window)->Delete(param1);
break;
}
case WX_LB_RESETCONTENT:
{
((wxListBox*) window)->Clear();
break;
}
}
((wxWindow*)window)->Fit();
@ -447,7 +508,7 @@ void wx_get_home_directory(char* path)
if (!home.EndsWith(wxFileName::GetPathSeparator())) {
home.Append(wxFileName::GetPathSeparator());
}
strcpy(path, home);
strcpy(path, home.mb_str());
}
int wx_create_directory(char* path)
@ -477,6 +538,11 @@ int wx_setup(char* path)
if (!nvr.DirExists() && !nvr.Mkdir())
return FALSE;
wxFileName screenshots(p);
screenshots.AppendDir("screenshots");
if (!screenshots.DirExists() && !screenshots.Mkdir())
return FALSE;
wxFileName logs(p);
logs.AppendDir("logs");
if (!logs.DirExists() && !logs.Mkdir())
@ -497,3 +563,210 @@ int wx_dir_exists(char* path)
wxFileName p(path);
return p.DirExists();
}
int wx_image_save(const char* path, const char* name, const char* format, unsigned char* rgba, int width, int height, int alpha)
{
int x, y;
wxLogNull logNull;
wxImage image(width, height);
if (alpha)
{
unsigned char* rgb = (unsigned char*)malloc(width*height*3);
unsigned char* a = (unsigned char*)malloc(width*height);
for (x = 0; x < width; ++x)
{
for (y = 0; y < height; ++y)
{
rgb[(y*width+x)*3+0] = rgba[(y*width+x)*4+0];
rgb[(y*width+x)*3+1] = rgba[(y*width+x)*4+1];
rgb[(y*width+x)*3+2] = rgba[(y*width+x)*4+2];
a[y*width+x] = rgba[(y*width+x)*4+3];
}
}
image.SetData(rgb);
image.SetAlpha(a);
}
else
image.SetData(rgba, true);
wxImageHandler* h;
wxString ext;
if (!strcmp(format, IMAGE_TIFF))
{
h = new wxTIFFHandler();
ext = "tif";
}
else if (!strcmp(format, IMAGE_BMP))
{
h = new wxBMPHandler();
ext = "bmp";
}
else if (!strcmp(format, IMAGE_JPG))
{
h = new wxJPEGHandler();
ext = "jpg";
}
else
{
h = new wxPNGHandler();
ext = "png";
}
int res = 0;
if (h)
{
wxString p(path);
if (!p.EndsWith("/"))
p = p.Append("/");
p = p.Append(name).Append(".").Append(ext);
wxFileOutputStream stream(p);
res = h->SaveFile(&image, stream, false);
delete h;
}
return res;
}
void* wx_image_load(const char* path)
{
wxLogNull logNull; /* removes sRGB-warnings on Windows */
wxImage* image = new wxImage(path);
if (image->IsOk())
return image;
delete image;
return 0;
}
void wx_image_free(void* image)
{
delete (wxImage*)image;
}
void wx_image_rescale(void* image, int width, int height)
{
((wxImage*)image)->Rescale(width, height);
}
void wx_image_get_size(void* image, int* width, int* height)
{
*width = ((wxImage*)image)->GetWidth();
*height = ((wxImage*)image)->GetHeight();
}
unsigned char* wx_image_get_data(void* image)
{
return ((wxImage*)image)->GetData();
}
unsigned char* wx_image_get_alpha(void* image)
{
return ((wxImage*)image)->GetAlpha();
}
/* wxFileConfig */
void* wx_config_load(const char* path)
{
if (!wxFileExists(path))
return 0;
wxFileInputStream stream(path);
if (stream.IsOk())
return new wxFileConfig(stream);
return 0;
}
int wx_config_get_string(void* config, const char* name, char* dst, int size, const char* defVal)
{
wxFileConfig* c = ((wxFileConfig*)config);
wxString val;
bool res = c->Read(name, &val, wxString(defVal));
strncpy(dst, val.GetData().AsChar(), size-1);
dst[size-1] = 0;
return res;
}
int wx_config_get_int(void* config, const char* name, int* dst, int defVal)
{
wxFileConfig* c = ((wxFileConfig*)config);
return c->Read(name, dst, defVal);
}
int wx_config_get_float(void* config, const char* name, float* dst, float defVal)
{
wxFileConfig* c = ((wxFileConfig*)config);
return c->Read(name, dst, defVal);
}
int wx_config_get_bool(void* config, const char* name, int* dst, int defVal)
{
wxFileConfig* c = ((wxFileConfig*)config);
wxString val;
bool res = 1;
if (c->Read(name, &val))
{
val.LowerCase();
if (val.StartsWith("true"))
*dst = 1;
else if (val.StartsWith("false"))
*dst = 0;
else
res = 0;
}
if (!res)
res = c->Read(name, (bool*)dst, (bool)defVal);
return res;
}
int wx_config_has_entry(void* config, const char* name)
{
wxFileConfig* c = ((wxFileConfig*)config);
return c->HasEntry(name);
}
void wx_config_free(void* config)
{
delete (wxFileConfig*)config;
}
typedef struct progress_data_t {
WX_CALLBACK callback;
void* data;
int active;
int result;
} progress_data_t;
static void progress_callback(void* data)
{
progress_data_t* d = (progress_data_t*) data;
d->result = d->callback(d->data);
d->active = 0;
}
int wx_progressdialogpulse(void* window, const char* title, const char* message, WX_CALLBACK callback, void* data)
{
struct progress_data_t pdata;
pdata.callback = callback;
pdata.data = data;
pdata.active = 1;
pdata.result = 0;
thread_t* t = thread_create(progress_callback, &pdata);
wxProgressDialog dlg(title, message, 100, (wxWindow*)window, wxPD_APP_MODAL | wxPD_SMOOTH | wxPD_AUTO_HIDE);
while (pdata.active)
{
dlg.Pulse();
wxMilliSleep(50);
}
thread_kill(t);
return pdata.result;
}
void wx_date_format(char* s, const char* format)
{
wxString res = wxDateTime::Now().Format(format);
strcpy(s, res.mb_str());
}