aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt6
-rw-r--r--melonDS.cbp1
-rw-r--r--src/GPU3D.cpp4
-rw-r--r--src/NDS.cpp10
-rw-r--r--src/NDS.h2
-rw-r--r--src/NDSCart.cpp23
-rw-r--r--src/libui_sdl/DlgInputConfig.cpp26
-rw-r--r--src/libui_sdl/Platform.cpp2
-rw-r--r--src/libui_sdl/libui/common/control.c3
-rw-r--r--src/libui_sdl/libui/ui.h1
-rw-r--r--src/libui_sdl/libui/ui_unix.h7
-rw-r--r--src/libui_sdl/libui/ui_windows.h6
-rw-r--r--src/libui_sdl/libui/unix/button.c2
-rw-r--r--src/libui_sdl/libui/unix/window.c75
-rw-r--r--src/libui_sdl/libui/windows/box.cpp9
-rw-r--r--src/libui_sdl/libui/windows/button.cpp3
-rw-r--r--src/libui_sdl/libui/windows/colordialog.cpp1
-rw-r--r--src/libui_sdl/libui/windows/form.cpp6
-rw-r--r--src/libui_sdl/libui/windows/grid.cpp6
-rw-r--r--src/libui_sdl/libui/windows/group.cpp6
-rw-r--r--src/libui_sdl/libui/windows/tab.cpp6
-rw-r--r--src/libui_sdl/libui/windows/window.cpp5
-rw-r--r--src/libui_sdl/main.cpp46
-rw-r--r--src/melon_fopen.h52
24 files changed, 251 insertions, 57 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2076d30..d824f6f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -82,8 +82,10 @@ if (UNIX)
LINK_LIBRARIES(${GTK3_LIBRARIES})
ADD_DEFINITIONS(${GTK3_CFLAGS_OTHER})
-
- LINK_LIBRARIES("dl")
+
+ if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
+ LINK_LIBRARIES("dl")
+ endif ()
endif (UNIX)
find_package(SDL2 REQUIRED)
diff --git a/melonDS.cbp b/melonDS.cbp
index d0485d6..7e83b98 100644
--- a/melonDS.cbp
+++ b/melonDS.cbp
@@ -229,6 +229,7 @@
<Unit filename="src/libui_sdl/libui/windows/winpublic.cpp" />
<Unit filename="src/libui_sdl/libui/windows/winutil.cpp" />
<Unit filename="src/libui_sdl/main.cpp" />
+ <Unit filename="src/melon_fopen.h" />
<Unit filename="src/types.h" />
<Unit filename="src/version.h" />
<Unit filename="xp.manifest" />
diff --git a/src/GPU3D.cpp b/src/GPU3D.cpp
index 988b92b..0b68706 100644
--- a/src/GPU3D.cpp
+++ b/src/GPU3D.cpp
@@ -886,10 +886,10 @@ void SubmitPolygon()
s32 z;
if (FlushAttributes & 0x2)
z = wshifted;
- else if (wshifted)
+ else if (vtx->Position[3])
z = ((((s64)vtx->Position[2] * 0x4000) / vtx->Position[3]) + 0x3FFF) * 0x200;
else
- z = 0x3FFF;
+ z = 0x7FFE00;
// checkme (Z<0 shouldn't be possible, but Z>0xFFFFFF is possible)
if (z < 0) z = 0;
diff --git a/src/NDS.cpp b/src/NDS.cpp
index d25c1ff..d4f6594 100644
--- a/src/NDS.cpp
+++ b/src/NDS.cpp
@@ -352,14 +352,18 @@ void Stop()
SPU::Stop();
}
-void LoadROM(const char* path, bool direct)
+bool LoadROM(const char* path, bool direct)
{
- Reset();
-
if (NDSCart::LoadROM(path, direct))
+ {
Running = true;
+ return true;
+ }
else
+ {
printf("Failed to load ROM %s\n", path);
+ return false;
+ }
}
void LoadBIOS()
diff --git a/src/NDS.h b/src/NDS.h
index 204c67d..6b76451 100644
--- a/src/NDS.h
+++ b/src/NDS.h
@@ -106,7 +106,7 @@ void DeInit();
void Reset();
void Stop();
-void LoadROM(const char* path, bool direct);
+bool LoadROM(const char* path, bool direct);
void LoadBIOS();
void SetupDirectBoot();
diff --git a/src/NDSCart.cpp b/src/NDSCart.cpp
index 216b3fb..03f536a 100644
--- a/src/NDSCart.cpp
+++ b/src/NDSCart.cpp
@@ -22,6 +22,8 @@
#include "NDSCart.h"
#include "ARM.h"
+#include "melon_fopen.h"
+
namespace NDSCart_SRAM
{
@@ -92,7 +94,7 @@ void LoadSave(char* path)
strncpy(SRAMPath, path, 255);
SRAMPath[255] = '\0';
- FILE* f = fopen(path, "rb");
+ FILE* f = melon_fopen(path, "rb");
if (f)
{
fseek(f, 0, SEEK_END);
@@ -624,7 +626,7 @@ void Write(u8 val, u32 hold)
if (islast && (CurCmd == 0x02 || CurCmd == 0x0A) && (SRAMLength > 0))
{
- FILE* f = fopen(SRAMPath, "wb");
+ FILE* f = melon_fopen(SRAMPath, "wb");
if (f)
{
fwrite(SRAM, SRAMLength, 1, f);
@@ -817,15 +819,14 @@ bool LoadROM(const char* path, bool direct)
// TODO: streaming mode? for really big ROMs or systems with limited RAM
// for now we're lazy
- if (CartROM) delete[] CartROM;
-
- FILE* f = fopen(path, "rb");
+ FILE* f = melon_fopen(path, "rb");
if (!f)
{
- printf("Failed to open ROM file %s\n", path);
return false;
}
+ NDS::Reset();
+
fseek(f, 0, SEEK_END);
u32 len = (u32)ftell(f);
@@ -845,6 +846,11 @@ bool LoadROM(const char* path, bool direct)
fclose(f);
//CartROM = f;
+ // generate a ROM ID
+ // note: most games don't check the actual value
+ // it just has to stay the same throughout gameplay
+ CartID = 0x00001FC2;
+
if (direct)
{
NDS::SetupDirectBoot();
@@ -853,11 +859,6 @@ bool LoadROM(const char* path, bool direct)
CartInserted = true;
- // generate a ROM ID
- // note: most games don't check the actual value
- // it just has to stay the same throughout gameplay
- CartID = 0x00001FC2;
-
u32 arm9base = *(u32*)&CartROM[0x20];
if (arm9base < 0x8000)
{
diff --git a/src/libui_sdl/DlgInputConfig.cpp b/src/libui_sdl/DlgInputConfig.cpp
index 4348261..5a98a91 100644
--- a/src/libui_sdl/DlgInputConfig.cpp
+++ b/src/libui_sdl/DlgInputConfig.cpp
@@ -303,53 +303,53 @@ void Open()
{
uiBox* in_ctrl = uiNewHorizontalBox();
uiBoxAppend(top, uiControl(in_ctrl), 0);
-
+ uiBoxSetPadded(in_ctrl, 1);
uiGroup* g_key = uiNewGroup("Keyboard");
uiBoxAppend(in_ctrl, uiControl(g_key), 1);
- uiBox* b_key = uiNewVerticalBox();
+ uiGrid* b_key = uiNewGrid();
uiGroupSetChild(g_key, uiControl(b_key));
+
+ const int width = 120;
for (int i = 0; i < 12; i++)
{
int j = keyorder[i];
- uiBox* box = uiNewHorizontalBox();
- uiBoxAppend(b_key, uiControl(box), 0);
-
uiLabel* label = uiNewLabel(keylabels[j]);
- uiBoxAppend(box, uiControl(label), 1);
+ uiGridAppend(b_key, uiControl(label), 0, i, 1, 1, 1, uiAlignStart, 1, uiAlignCenter);
+ uiControlSetMinSize(uiControl(label), width, 1);
char* keyname = uiKeyName(Config::KeyMapping[j]);
uiButton* btn = uiNewButton(keyname);
- uiBoxAppend(box, uiControl(btn), 1);
+ uiGridAppend(b_key, uiControl(btn), 1, i, 1, 1, 1, uiAlignFill, 1, uiAlignCenter);
uiButtonOnClicked(btn, OnKeyStartConfig, &keyorder[i]);
+ uiControlSetMinSize(uiControl(btn), width, 1);
uiFreeText(keyname);
}
uiGroup* g_joy = uiNewGroup("Joystick");
uiBoxAppend(in_ctrl, uiControl(g_joy), 1);
- uiBox* b_joy = uiNewVerticalBox();
+ uiGrid* b_joy = uiNewGrid();
uiGroupSetChild(g_joy, uiControl(b_joy));
for (int i = 0; i < 12; i++)
{
int j = keyorder[i];
- uiBox* box = uiNewHorizontalBox();
- uiBoxAppend(b_joy, uiControl(box), 0);
-
uiLabel* label = uiNewLabel(keylabels[j]);
- uiBoxAppend(box, uiControl(label), 1);
+ uiGridAppend(b_joy, uiControl(label), 0, i, 1, 1, 1, uiAlignStart, 1, uiAlignCenter);
+ uiControlSetMinSize(uiControl(label), width, 1);
char keyname[16];
JoyMappingName(Config::JoyMapping[j], keyname);
uiButton* btn = uiNewButton(keyname);
- uiBoxAppend(box, uiControl(btn), 1);
+ uiGridAppend(b_joy, uiControl(btn), 1, i, 1, 1, 1, uiAlignFill, 1, uiAlignCenter);
uiButtonOnClicked(btn, OnJoyStartConfig, &keyorder[i]);
+ uiControlSetMinSize(uiControl(btn), width, 1);
}
}
diff --git a/src/libui_sdl/Platform.cpp b/src/libui_sdl/Platform.cpp
index 0b1e0a2..1d7438b 100644
--- a/src/libui_sdl/Platform.cpp
+++ b/src/libui_sdl/Platform.cpp
@@ -32,6 +32,8 @@
#else
#include <unistd.h>
#include <arpa/inet.h>
+ #include <netinet/in.h>
+ #include <sys/select.h>
#include <sys/socket.h>
#define socket_t int
#define sockaddr_t struct sockaddr
diff --git a/src/libui_sdl/libui/common/control.c b/src/libui_sdl/libui/common/control.c
index f811728..78d1e5f 100644
--- a/src/libui_sdl/libui/common/control.c
+++ b/src/libui_sdl/libui/common/control.c
@@ -66,8 +66,7 @@ void uiControlSetMinSize(uiControl *c, int w, int h)
{
c->MinWidth = w;
c->MinHeight = h;
-
- // TODO: resize if needed
+ (*(c->SetMinSize))(c, w, h);
}
#define uiControlSignature 0x7569436F
diff --git a/src/libui_sdl/libui/ui.h b/src/libui_sdl/libui/ui.h
index e78de5e..6e51d44 100644
--- a/src/libui_sdl/libui/ui.h
+++ b/src/libui_sdl/libui/ui.h
@@ -73,6 +73,7 @@ struct uiControl {
void (*Enable)(uiControl *);
void (*Disable)(uiControl *);
void (*SetFocus)(uiControl *);
+ void (*SetMinSize)(uiControl*, int, int);
int MinWidth, MinHeight;
};
diff --git a/src/libui_sdl/libui/ui_unix.h b/src/libui_sdl/libui/ui_unix.h
index 23bd538..fac44bc 100644
--- a/src/libui_sdl/libui/ui_unix.h
+++ b/src/libui_sdl/libui/ui_unix.h
@@ -85,6 +85,11 @@ _UI_EXTERN void uiUnixControlSetContainer(uiUnixControl *, GtkContainer *, gbool
{ \
gtk_widget_grab_focus(type(c)->widget); \
}
+#define uiUnixControlDefaultSetMinSize(type) \
+ static void type ## SetMinSize(uiControl *c, int w, int h) \
+ { \
+ gtk_widget_set_size_request(type(c)->widget, w, h); \
+ }
// TODO this whole addedBefore stuff is a MASSIVE HACK.
#define uiUnixControlDefaultSetContainer(type) \
static void type ## SetContainer(uiUnixControl *c, GtkContainer *container, gboolean remove) \
@@ -112,6 +117,7 @@ _UI_EXTERN void uiUnixControlSetContainer(uiUnixControl *, GtkContainer *, gbool
uiUnixControlDefaultEnable(type) \
uiUnixControlDefaultDisable(type) \
uiUnixControlDefaultSetFocus(type) \
+ uiUnixControlDefaultSetMinSize(type) \
uiUnixControlDefaultSetContainer(type)
#define uiUnixControlAllDefaults(type) \
@@ -133,6 +139,7 @@ _UI_EXTERN void uiUnixControlSetContainer(uiUnixControl *, GtkContainer *, gbool
uiControl(var)->Enable = type ## Enable; \
uiControl(var)->Disable = type ## Disable; \
uiControl(var)->SetFocus = type ## SetFocus; \
+ uiControl(var)->SetMinSize = type ## SetMinSize; \
uiUnixControl(var)->SetContainer = type ## SetContainer;
// TODO document
_UI_EXTERN uiUnixControl *uiUnixAllocControl(size_t n, uint32_t typesig, const char *typenamestr);
diff --git a/src/libui_sdl/libui/ui_windows.h b/src/libui_sdl/libui/ui_windows.h
index 3917c97..85c3137 100644
--- a/src/libui_sdl/libui/ui_windows.h
+++ b/src/libui_sdl/libui/ui_windows.h
@@ -107,6 +107,10 @@ _UI_EXTERN void uiWindowsControlChildVisibilityChanged(uiWindowsControl *);
{ \
SetFocus(type(c)->hwnd); \
}
+#define uiWindowsControlDefaultSetMinSize(type) \
+ static void type ## SetMinSize(uiControl *c, int w, int h) \
+ { \
+ }
#define uiWindowsControlDefaultSyncEnableState(type) \
static void type ## SyncEnableState(uiWindowsControl *c, int enabled) \
{ \
@@ -158,6 +162,7 @@ _UI_EXTERN void uiWindowsControlChildVisibilityChanged(uiWindowsControl *);
uiWindowsControlDefaultEnable(type) \
uiWindowsControlDefaultDisable(type) \
uiWindowsControlDefaultSetFocus(type) \
+ uiWindowsControlDefaultSetMinSize(type) \
uiWindowsControlDefaultSyncEnableState(type) \
uiWindowsControlDefaultSetParentHWND(type) \
uiWindowsControlDefaultMinimumSizeChanged(type) \
@@ -184,6 +189,7 @@ _UI_EXTERN void uiWindowsControlChildVisibilityChanged(uiWindowsControl *);
uiControl(var)->Enable = type ## Enable; \
uiControl(var)->Disable = type ## Disable; \
uiControl(var)->SetFocus = type ## SetFocus; \
+ uiControl(var)->SetMinSize = type ## SetMinSize; \
uiWindowsControl(var)->SyncEnableState = type ## SyncEnableState; \
uiWindowsControl(var)->SetParentHWND = type ## SetParentHWND; \
uiWindowsControl(var)->MinimumSize = type ## MinimumSize; \
diff --git a/src/libui_sdl/libui/unix/button.c b/src/libui_sdl/libui/unix/button.c
index 00a87f4..b0500e3 100644
--- a/src/libui_sdl/libui/unix/button.c
+++ b/src/libui_sdl/libui/unix/button.c
@@ -50,6 +50,8 @@ uiButton *uiNewButton(const char *text)
g_signal_connect(b->widget, "clicked", G_CALLBACK(onClicked), b);
uiButtonOnClicked(b, defaultOnClicked, NULL);
+
+ gtk_widget_set_size_request(b->widget, 64, 1);
return b;
}
diff --git a/src/libui_sdl/libui/unix/window.c b/src/libui_sdl/libui/unix/window.c
index a908f88..a3dde76 100644
--- a/src/libui_sdl/libui/unix/window.c
+++ b/src/libui_sdl/libui/unix/window.c
@@ -19,6 +19,8 @@ struct uiWindow {
uiControl *child;
int margined;
+
+ int width, height;
int (*onClosing)(uiWindow *, void *);
void *onClosingData;
@@ -127,6 +129,20 @@ static void uiWindowShow(uiControl *c)
// don't use gtk_widget_show(); that doesn't bring to front or give keyboard focus
// (gtk_window_present() does call gtk_widget_show() though)
gtk_window_present(w->window);
+
+ // set the size properly
+ int width = w->width;
+ int height = w->height;
+ if (w->menubar)
+ {
+ GtkRequisition min, nat;
+ int menuheight;
+ gtk_widget_get_preferred_size(w->menubar, &min, &nat);
+ menuheight = min.height;
+ if (nat.height > menuheight) menuheight = nat.height;
+ height += menuheight;
+ }
+ gtk_window_resize(w->window, width, height);
}
uiUnixControlDefaultHide(uiWindow)
@@ -134,6 +150,7 @@ uiUnixControlDefaultEnabled(uiWindow)
uiUnixControlDefaultEnable(uiWindow)
uiUnixControlDefaultDisable(uiWindow)
uiUnixControlDefaultSetFocus(uiWindow)
+uiUnixControlDefaultSetMinSize(uiWindow)
// TODO?
uiUnixControlDefaultSetContainer(uiWindow)
@@ -269,9 +286,57 @@ void uiWindowSetMargined(uiWindow *w, int margined)
setMargined(w->childHolderContainer, w->margined);
}
+static void onDragDataReceived(GtkWidget* widget, GdkDragContext* ctx, gint x, gint y, GtkSelectionData* data, guint info, guint time, gpointer userdata)
+{
+ uiWindow* w = (uiWindow*)userdata;
+
+ if (gtk_selection_data_get_length(data) > 0 && gtk_selection_data_get_format(data) == 8)
+ {
+ gchar** files = gtk_selection_data_get_uris(data);
+ if (files != NULL && files[0] != NULL)
+ {
+ // TODO: multi file support?
+
+ gboolean success = FALSE;
+
+ gchar* file = g_filename_from_uri(files[0], NULL, NULL);
+ if (file)
+ {
+ if (w->onDropFile)
+ w->onDropFile(w, file, w->onDropFileData);
+
+ success = TRUE;
+ g_free(file);
+ }
+
+
+ g_strfreev(files);
+ gtk_drag_finish(ctx, success, FALSE, time);
+ return;
+ }
+
+ if (files != NULL) g_strfreev(files);
+ gtk_drag_finish(ctx, FALSE, FALSE, time);
+ }
+}
+
void uiWindowSetDropTarget(uiWindow* w, int drop)
{
- printf("DRAG DROP TODO!!!!!\n");
+ if (!drop)
+ {
+ gtk_drag_dest_unset(w->widget);
+ return;
+ }
+
+ GtkTargetEntry entry;
+ entry.target = "text/uri-list";
+ entry.flags = GTK_TARGET_OTHER_APP;
+ entry.info = 1;
+
+ // CHECKME: action copy?
+ gtk_drag_dest_set(w->widget, GTK_DEST_DEFAULT_ALL, &entry, 1, GDK_ACTION_COPY|GDK_ACTION_MOVE);
+
+ g_signal_connect(w->widget, "drag-data-received", G_CALLBACK(onDragDataReceived), w);
}
uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar, int resizable)
@@ -298,6 +363,8 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar,
w->menubar = makeMenubar(uiWindow(w));
gtk_container_add(w->vboxContainer, w->menubar);
}
+ else
+ w->menubar = NULL;
w->childHolderWidget = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
w->childHolderContainer = GTK_CONTAINER(w->childHolderWidget);
@@ -307,9 +374,6 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar,
gtk_widget_set_valign(w->childHolderWidget, GTK_ALIGN_FILL);
gtk_box_set_homogeneous(GTK_BOX(w->childHolderWidget), TRUE);
gtk_container_add(w->vboxContainer, w->childHolderWidget);
-
- // set client size proper
- gtk_widget_set_size_request(w->childHolderWidget, width, height);
// show everything in the vbox, but not the GtkWindow itself
gtk_widget_show_all(w->vboxWidget);
@@ -332,6 +396,9 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar,
g_object_ref(w->widget);
gtk_window_set_resizable(w->window, resizable?TRUE:FALSE);
+
+ w->width = width;
+ w->height = height;
return w;
}
diff --git a/src/libui_sdl/libui/windows/box.cpp b/src/libui_sdl/libui/windows/box.cpp
index c306989..5ed8447 100644
--- a/src/libui_sdl/libui/windows/box.cpp
+++ b/src/libui_sdl/libui/windows/box.cpp
@@ -38,7 +38,6 @@ static void boxRelayout(uiBox *b)
int i;
int minimumWidth, minimumHeight;
int nVisible;
- uiWindowsSizing *d;
if (b->controls->size() == 0)
return;
@@ -165,10 +164,8 @@ static void uiBoxMinimumSize(uiWindowsControl *c, int *width, int *height)
// these two contain the largest minimum width and height of all stretchy controls in the box
// all stretchy controls will use this value to determine the final minimum size
int maxStretchyWidth, maxStretchyHeight;
- int i;
int minimumWidth, minimumHeight;
int nVisible;
- uiWindowsSizing sizing;
*width = 0;
*height = 0;
@@ -235,6 +232,12 @@ static void uiBoxMinimumSizeChanged(uiWindowsControl *c)
boxRelayout(b);
}
+static void uiBoxSetMinSize(uiControl *c, int w, int h)
+{
+ // checkme
+ uiBoxMinimumSizeChanged(uiWindowsControl(c));
+}
+
uiWindowsControlDefaultLayoutRect(uiBox)
uiWindowsControlDefaultAssignControlIDZOrder(uiBox)
diff --git a/src/libui_sdl/libui/windows/button.cpp b/src/libui_sdl/libui/windows/button.cpp
index 3b12e72..b83d6ec 100644
--- a/src/libui_sdl/libui/windows/button.cpp
+++ b/src/libui_sdl/libui/windows/button.cpp
@@ -32,6 +32,7 @@ uiWindowsControlAllDefaultsExceptDestroy(uiButton)
// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
#define buttonHeight 14
+#define buttonMinWidth 64
static void uiButtonMinimumSize(uiWindowsControl *c, int *width, int *height)
{
@@ -45,6 +46,7 @@ static void uiButtonMinimumSize(uiWindowsControl *c, int *width, int *height)
size.cy = 0;
if (SendMessageW(b->hwnd, BCM_GETIDEALSIZE, 0, (LPARAM) (&size)) != FALSE) {
*width = size.cx;
+ if (*width < buttonMinWidth) *width = buttonMinWidth;
*height = size.cy;
return;
}
@@ -53,6 +55,7 @@ static void uiButtonMinimumSize(uiWindowsControl *c, int *width, int *height)
// Microsoft says to use a fixed width for all buttons; this isn't good enough
// use the text width instead, with some edge padding
*width = uiWindowsWindowTextWidth(b->hwnd) + (2 * GetSystemMetrics(SM_CXEDGE));
+ if (*width < buttonMinWidth) *width = buttonMinWidth;
y = buttonHeight;
uiWindowsGetSizing(b->hwnd, &sizing);
uiWindowsSizingDlgUnitsToPixels(&sizing, NULL, &y);
diff --git a/src/libui_sdl/libui/windows/colordialog.cpp b/src/libui_sdl/libui/windows/colordialog.cpp
index 2efe72c..9c2551a 100644
--- a/src/libui_sdl/libui/windows/colordialog.cpp
+++ b/src/libui_sdl/libui/windows/colordialog.cpp
@@ -87,7 +87,6 @@ static void hsv2RGB(double h, double s, double v, double *r, double *g, double *
int h60;
double x;
double m;
- double c1, c2;
c = v * s;
hPrime = h * 6;
diff --git a/src/libui_sdl/libui/windows/form.cpp b/src/libui_sdl/libui/windows/form.cpp
index 83ed587..65ef539 100644
--- a/src/libui_sdl/libui/windows/form.cpp
+++ b/src/libui_sdl/libui/windows/form.cpp
@@ -232,6 +232,12 @@ static void uiFormMinimumSizeChanged(uiWindowsControl *c)
formRelayout(f);
}
+static void uiFormSetMinSize(uiControl *c, int w, int h)
+{
+ // checkme
+ uiFormMinimumSizeChanged(uiWindowsControl(c));
+}
+
uiWindowsControlDefaultLayoutRect(uiForm)
uiWindowsControlDefaultAssignControlIDZOrder(uiForm)
diff --git a/src/libui_sdl/libui/windows/grid.cpp b/src/libui_sdl/libui/windows/grid.cpp
index 78719ac..0a854c5 100644
--- a/src/libui_sdl/libui/windows/grid.cpp
+++ b/src/libui_sdl/libui/windows/grid.cpp
@@ -516,6 +516,12 @@ static void uiGridMinimumSizeChanged(uiWindowsControl *c)
gridRelayout(g);
}
+static void uiGridSetMinSize(uiControl *c, int w, int h)
+{
+ // checkme
+ uiGridMinimumSizeChanged(uiWindowsControl(c));
+}
+
uiWindowsControlDefaultLayoutRect(uiGrid)
uiWindowsControlDefaultAssignControlIDZOrder(uiGrid)
diff --git a/src/libui_sdl/libui/windows/group.cpp b/src/libui_sdl/libui/windows/group.cpp
index f78e7de..9c36da1 100644
--- a/src/libui_sdl/libui/windows/group.cpp
+++ b/src/libui_sdl/libui/windows/group.cpp
@@ -119,6 +119,12 @@ static void uiGroupMinimumSizeChanged(uiWindowsControl *c)
groupRelayout(g);
}
+static void uiGroupSetMinSize(uiControl *c, int w, int h)
+{
+ // checkme
+ uiGroupMinimumSizeChanged(uiWindowsControl(c));
+}
+
uiWindowsControlDefaultLayoutRect(uiGroup)
uiWindowsControlDefaultAssignControlIDZOrder(uiGroup)
diff --git a/src/libui_sdl/libui/windows/tab.cpp b/src/libui_sdl/libui/windows/tab.cpp
index ea6209b..93373b0 100644
--- a/src/libui_sdl/libui/windows/tab.cpp
+++ b/src/libui_sdl/libui/windows/tab.cpp
@@ -164,6 +164,12 @@ static void uiTabMinimumSizeChanged(uiWindowsControl *c)
tabRelayout(t);
}
+static void uiTabSetMinSize(uiControl *c, int w, int h)
+{
+ // checkme
+ uiTabMinimumSizeChanged(uiWindowsControl(c));
+}
+
uiWindowsControlDefaultLayoutRect(uiTab)
uiWindowsControlDefaultAssignControlIDZOrder(uiTab)
diff --git a/src/libui_sdl/libui/windows/window.cpp b/src/libui_sdl/libui/windows/window.cpp
index 44fb306..50a01c6 100644
--- a/src/libui_sdl/libui/windows/window.cpp
+++ b/src/libui_sdl/libui/windows/window.cpp
@@ -309,6 +309,11 @@ static void uiWindowLayoutRect(uiWindowsControl *c, RECT *r)
uiWindowsEnsureGetClientRect(w->hwnd, r);
}
+static void uiWindowSetMinSize(uiControl *c, int w, int h)
+{
+ // TODO: relayout, eventually
+}
+
uiWindowsControlDefaultAssignControlIDZOrder(uiWindow)
static void uiWindowChildVisibilityChanged(uiWindowsControl *c)
diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp
index dceef64..6797139 100644
--- a/src/libui_sdl/main.cpp
+++ b/src/libui_sdl/main.cpp
@@ -400,6 +400,27 @@ void Stop(bool internal)
uiAreaQueueRedrawAll(MainDrawArea);
}
+void TryLoadROM(char* file, int prevstatus)
+{
+ char oldpath[1024];
+ strncpy(oldpath, ROMPath, 1024);
+
+ strncpy(ROMPath, file, 1023);
+ ROMPath[1023] = '\0';
+
+ if (NDS::LoadROM(ROMPath, Config::DirectBoot))
+ Run();
+ else
+ {
+ uiMsgBoxError(MainWindow,
+ "Failed to load the ROM",
+ "Make sure the file can be accessed and isn't opened in another application.");
+
+ strncpy(ROMPath, oldpath, 1024);
+ EmuRunning = prevstatus;
+ }
+}
+
int OnCloseWindow(uiWindow* window, void* blarg)
{
@@ -410,6 +431,7 @@ int OnCloseWindow(uiWindow* window, void* blarg)
void OnDropFile(uiWindow* window, char* file, void* blarg)
{
char* ext = &file[strlen(file)-3];
+ int prevstatus = EmuRunning;
if (!strcasecmp(ext, "nds") || !strcasecmp(ext, "srl"))
{
@@ -419,11 +441,7 @@ void OnDropFile(uiWindow* window, char* file, void* blarg)
while (EmuStatus != 2);
}
- strncpy(ROMPath, file, 1023);
- ROMPath[1023] = '\0';
-
- NDS::LoadROM(ROMPath, Config::DirectBoot);
- Run();
+ TryLoadROM(file, prevstatus);
}
}
@@ -456,14 +474,8 @@ void OnOpenFile(uiMenuItem* item, uiWindow* window, void* blarg)
return;
}
- strncpy(ROMPath, file, 1023);
- ROMPath[1023] = '\0';
+ TryLoadROM(file, prevstatus);
uiFreeText(file);
- // TODO: change libui to store strings in stack-allocated buffers?
- // so we don't have to free it after use
-
- NDS::LoadROM(ROMPath, Config::DirectBoot);
- Run();
}
void OnRun(uiMenuItem* item, uiWindow* window, void* blarg)
@@ -567,7 +579,11 @@ int main(int argc, char** argv)
// http://stackoverflow.com/questions/14543333/joystick-wont-work-using-sdl
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
- if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
+ if (SDL_Init(SDL_INIT_HAPTIC) < 0)
+ {
+ printf("SDL couldn't init rumble\n");
+ }
+ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0)
{
printf("SDL shat itself :(\n");
return 1;
@@ -685,8 +701,8 @@ int main(int argc, char** argv)
strncpy(ROMPath, file, 1023);
ROMPath[1023] = '\0';
- NDS::LoadROM(ROMPath, Config::DirectBoot);
- Run();
+ if (NDS::LoadROM(ROMPath, Config::DirectBoot))
+ Run();
}
}
diff --git a/src/melon_fopen.h b/src/melon_fopen.h
new file mode 100644
index 0000000..603e15f
--- /dev/null
+++ b/src/melon_fopen.h
@@ -0,0 +1,52 @@
+/*
+ Copyright 2016-2017 StapleButter
+
+ This file is part of melonDS.
+
+ melonDS is free software: you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation, either version 3 of the License, or (at your option)
+ any later version.
+
+ melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with melonDS. If not, see http://www.gnu.org/licenses/.
+*/
+
+#ifndef MELON_FOPEN_H
+#define MELON_FOPEN_H
+
+#ifdef __WIN32__
+
+#include <windows.h>
+
+static FILE* melon_fopen(const char* path, const char* mode)
+{
+ int len = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0);
+ if (len < 1) return NULL;
+ WCHAR* fatass = new WCHAR[len];
+ int res = MultiByteToWideChar(CP_UTF8, 0, path, -1, fatass, len);
+ if (res != len) return NULL; // checkme?
+
+ // this will be more than enough
+ WCHAR fatmode[4];
+ fatmode[0] = mode[0];
+ fatmode[1] = mode[1];
+ fatmode[2] = mode[2];
+ fatmode[3] = 0;
+
+ FILE* ret = _wfopen(fatass, fatmode);
+ delete[] fatass;
+ return ret;
+}
+
+#else
+
+#define melon_fopen fopen
+
+#endif
+
+#endif // MELON_FOPEN_H