mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-21 05:09:46 -06:00
begin butchering uiArea
This commit is contained in:
@ -432,7 +432,7 @@ void Open(int type)
|
|||||||
uiLabel* dummy = uiNewLabel("");
|
uiLabel* dummy = uiNewLabel("");
|
||||||
uiBoxAppend(in_ctrl, uiControl(dummy), 1);
|
uiBoxAppend(in_ctrl, uiControl(dummy), 1);
|
||||||
|
|
||||||
dlg->keypresscatcher = uiNewArea(&dlg->areahandler);
|
dlg->keypresscatcher = uiNewArea(&dlg->areahandler, 0);
|
||||||
uiControl(dlg->keypresscatcher)->UserData = dlg;
|
uiControl(dlg->keypresscatcher)->UserData = dlg;
|
||||||
uiBoxAppend(in_ctrl, uiControl(dlg->keypresscatcher), 0);
|
uiBoxAppend(in_ctrl, uiControl(dlg->keypresscatcher), 0);
|
||||||
|
|
||||||
|
@ -341,7 +341,7 @@ _UI_EXTERN void uiAreaScrollTo(uiArea *a, double x, double y, double width, doub
|
|||||||
_UI_EXTERN void uiAreaBeginUserWindowMove(uiArea *a);
|
_UI_EXTERN void uiAreaBeginUserWindowMove(uiArea *a);
|
||||||
_UI_EXTERN void uiAreaBeginUserWindowResize(uiArea *a, uiWindowResizeEdge edge);
|
_UI_EXTERN void uiAreaBeginUserWindowResize(uiArea *a, uiWindowResizeEdge edge);
|
||||||
_UI_EXTERN void uiAreaSetBackgroundColor(uiArea *a, int r, int g, int b);
|
_UI_EXTERN void uiAreaSetBackgroundColor(uiArea *a, int r, int g, int b);
|
||||||
_UI_EXTERN uiArea *uiNewArea(uiAreaHandler *ah);
|
_UI_EXTERN uiArea *uiNewArea(uiAreaHandler *ah, int opengl);
|
||||||
_UI_EXTERN uiArea *uiNewScrollingArea(uiAreaHandler *ah, int width, int height);
|
_UI_EXTERN uiArea *uiNewScrollingArea(uiAreaHandler *ah, int width, int height);
|
||||||
|
|
||||||
struct uiAreaDrawParams {
|
struct uiAreaDrawParams {
|
||||||
@ -608,6 +608,7 @@ _UI_EXTERN uiGLContext *uiGLNewContext(uiControl* c, int vermajor, int verminor)
|
|||||||
_UI_EXTERN void uiGLFreeContext(uiGLContext* ctx);
|
_UI_EXTERN void uiGLFreeContext(uiGLContext* ctx);
|
||||||
_UI_EXTERN void uiGLMakeContextCurrent(uiGLContext* ctx);
|
_UI_EXTERN void uiGLMakeContextCurrent(uiGLContext* ctx);
|
||||||
_UI_EXTERN void *uiGLGetProcAddress(const char* proc);
|
_UI_EXTERN void *uiGLGetProcAddress(const char* proc);
|
||||||
|
_UI_EXTERN void uiGLSwapBuffers(uiGLContext* ctx);
|
||||||
|
|
||||||
|
|
||||||
_UI_ENUM(uiModifiers) {
|
_UI_ENUM(uiModifiers) {
|
||||||
|
@ -25,8 +25,11 @@ static LRESULT CALLBACK areaWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
|
|||||||
}
|
}
|
||||||
|
|
||||||
// always recreate the render target if necessary
|
// always recreate the render target if necessary
|
||||||
if (a->rt == NULL)
|
if (!a->openGL)
|
||||||
a->rt = makeHWNDRenderTarget(a->hwnd);
|
{
|
||||||
|
if (a->rt == NULL)
|
||||||
|
a->rt = makeHWNDRenderTarget(a->hwnd);
|
||||||
|
}
|
||||||
|
|
||||||
if (areaDoDraw(a, uMsg, wParam, lParam, &lResult) != FALSE)
|
if (areaDoDraw(a, uMsg, wParam, lParam, &lResult) != FALSE)
|
||||||
return lResult;
|
return lResult;
|
||||||
@ -34,12 +37,14 @@ static LRESULT CALLBACK areaWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
|
|||||||
if (uMsg == WM_WINDOWPOSCHANGED) {
|
if (uMsg == WM_WINDOWPOSCHANGED) {
|
||||||
if ((wp->flags & SWP_NOSIZE) != 0)
|
if ((wp->flags & SWP_NOSIZE) != 0)
|
||||||
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
||||||
|
a->width = -1;
|
||||||
|
a->height = -1;
|
||||||
uiWindowsEnsureGetClientRect(a->hwnd, &client);
|
uiWindowsEnsureGetClientRect(a->hwnd, &client);
|
||||||
areaDrawOnResize(a, &client);
|
areaDrawOnResize(a, &client);
|
||||||
areaScrollOnResize(a, &client);
|
areaScrollOnResize(a, &client);
|
||||||
{
|
{
|
||||||
double w, h;
|
double w, h;
|
||||||
loadAreaSize(a, a->rt, &w, &h);
|
loadAreaSize(a, &w, &h);
|
||||||
a->ah->Resize(a->ah, a, (int)w, (int)h);
|
a->ah->Resize(a->ah, a, (int)w, (int)h);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -176,12 +181,15 @@ void uiAreaSetBackgroundColor(uiArea *a, int r, int g, int b)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uiArea *uiNewArea(uiAreaHandler *ah)
|
uiArea *uiNewArea(uiAreaHandler *ah, int opengl)
|
||||||
{
|
{
|
||||||
uiArea *a;
|
uiArea *a;
|
||||||
|
|
||||||
uiWindowsNewControl(uiArea, a);
|
uiWindowsNewControl(uiArea, a);
|
||||||
|
|
||||||
|
a->width = -1;
|
||||||
|
a->height = -1;
|
||||||
|
|
||||||
a->ah = ah;
|
a->ah = ah;
|
||||||
a->scrolling = FALSE;
|
a->scrolling = FALSE;
|
||||||
clickCounterReset(&(a->cc));
|
clickCounterReset(&(a->cc));
|
||||||
@ -195,6 +203,8 @@ uiArea *uiNewArea(uiAreaHandler *ah)
|
|||||||
|
|
||||||
uiAreaSetBackgroundColor(a, -1, -1, -1);
|
uiAreaSetBackgroundColor(a, -1, -1, -1);
|
||||||
|
|
||||||
|
a->openGL = opengl;
|
||||||
|
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,6 +214,9 @@ uiArea *uiNewScrollingArea(uiAreaHandler *ah, int width, int height)
|
|||||||
|
|
||||||
uiWindowsNewControl(uiArea, a);
|
uiWindowsNewControl(uiArea, a);
|
||||||
|
|
||||||
|
a->width = -1;
|
||||||
|
a->height = -1;
|
||||||
|
|
||||||
a->ah = ah;
|
a->ah = ah;
|
||||||
a->scrolling = TRUE;
|
a->scrolling = TRUE;
|
||||||
a->scrollWidth = width;
|
a->scrollWidth = width;
|
||||||
@ -219,6 +232,8 @@ uiArea *uiNewScrollingArea(uiAreaHandler *ah, int width, int height)
|
|||||||
|
|
||||||
uiAreaSetBackgroundColor(a, -1, -1, -1);
|
uiAreaSetBackgroundColor(a, -1, -1, -1);
|
||||||
|
|
||||||
|
a->openGL = 0; // TODO, eventually???
|
||||||
|
|
||||||
// set initial scrolling parameters
|
// set initial scrolling parameters
|
||||||
areaUpdateScroll(a);
|
areaUpdateScroll(a);
|
||||||
|
|
||||||
|
@ -10,6 +10,8 @@ struct uiArea {
|
|||||||
HWND hwnd;
|
HWND hwnd;
|
||||||
uiAreaHandler *ah;
|
uiAreaHandler *ah;
|
||||||
|
|
||||||
|
int width, height;
|
||||||
|
|
||||||
BOOL scrolling;
|
BOOL scrolling;
|
||||||
int scrollWidth;
|
int scrollWidth;
|
||||||
int scrollHeight;
|
int scrollHeight;
|
||||||
@ -26,6 +28,8 @@ struct uiArea {
|
|||||||
|
|
||||||
int bgR, bgG, bgB;
|
int bgR, bgG, bgB;
|
||||||
|
|
||||||
|
int openGL;
|
||||||
|
|
||||||
ID2D1HwndRenderTarget *rt;
|
ID2D1HwndRenderTarget *rt;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -42,6 +46,6 @@ extern void areaUpdateScroll(uiArea *a);
|
|||||||
extern BOOL areaDoEvents(uiArea *a, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *lResult);
|
extern BOOL areaDoEvents(uiArea *a, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *lResult);
|
||||||
|
|
||||||
// areautil.cpp
|
// areautil.cpp
|
||||||
extern void loadAreaSize(uiArea *a, ID2D1RenderTarget *rt, double *width, double *height);
|
extern void loadAreaSize(uiArea *a, double *width, double *height);
|
||||||
extern void pixelsToDIP(uiArea *a, double *x, double *y);
|
extern void pixelsToDIP(uiArea *a, double *x, double *y);
|
||||||
extern void dipToPixels(uiArea *a, double *x, double *y);
|
extern void dipToPixels(uiArea *a, double *x, double *y);
|
||||||
|
@ -6,6 +6,13 @@ static HRESULT doPaint(uiArea *a, ID2D1RenderTarget *rt, RECT *clip)
|
|||||||
{
|
{
|
||||||
uiAreaHandler *ah = a->ah;
|
uiAreaHandler *ah = a->ah;
|
||||||
uiAreaDrawParams dp;
|
uiAreaDrawParams dp;
|
||||||
|
|
||||||
|
if (a->openGL)
|
||||||
|
{
|
||||||
|
(*(ah->Draw))(ah, a, &dp);
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
|
|
||||||
COLORREF bgcolorref;
|
COLORREF bgcolorref;
|
||||||
D2D1_COLOR_F bgcolor;
|
D2D1_COLOR_F bgcolor;
|
||||||
D2D1_MATRIX_3X2_F scrollTransform;
|
D2D1_MATRIX_3X2_F scrollTransform;
|
||||||
@ -13,7 +20,7 @@ static HRESULT doPaint(uiArea *a, ID2D1RenderTarget *rt, RECT *clip)
|
|||||||
// no need to save or restore the graphics state to reset transformations; it's handled by resetTarget() in draw.c, called during the following
|
// no need to save or restore the graphics state to reset transformations; it's handled by resetTarget() in draw.c, called during the following
|
||||||
dp.Context = newContext(rt);
|
dp.Context = newContext(rt);
|
||||||
|
|
||||||
loadAreaSize(a, rt, &(dp.AreaWidth), &(dp.AreaHeight));
|
loadAreaSize(a, &(dp.AreaWidth), &(dp.AreaHeight));
|
||||||
|
|
||||||
dp.ClipX = clip->left;
|
dp.ClipX = clip->left;
|
||||||
dp.ClipY = clip->top;
|
dp.ClipY = clip->top;
|
||||||
@ -113,6 +120,9 @@ static void onWM_PAINT(uiArea *a)
|
|||||||
|
|
||||||
static void onWM_PRINTCLIENT(uiArea *a, HDC dc)
|
static void onWM_PRINTCLIENT(uiArea *a, HDC dc)
|
||||||
{
|
{
|
||||||
|
// TODO????
|
||||||
|
if (a->openGL) return;
|
||||||
|
|
||||||
ID2D1DCRenderTarget *rt;
|
ID2D1DCRenderTarget *rt;
|
||||||
RECT client;
|
RECT client;
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
@ -143,13 +153,16 @@ BOOL areaDoDraw(uiArea *a, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *lRe
|
|||||||
// TODO only if the render target wasn't just created?
|
// TODO only if the render target wasn't just created?
|
||||||
void areaDrawOnResize(uiArea *a, RECT *newClient)
|
void areaDrawOnResize(uiArea *a, RECT *newClient)
|
||||||
{
|
{
|
||||||
D2D1_SIZE_U size;
|
if (!a->openGL)
|
||||||
|
{
|
||||||
|
D2D1_SIZE_U size;
|
||||||
|
|
||||||
size.width = newClient->right - newClient->left;
|
size.width = newClient->right - newClient->left;
|
||||||
size.height = newClient->bottom - newClient->top;
|
size.height = newClient->bottom - newClient->top;
|
||||||
// don't track the error; we'll get that in EndDraw()
|
// don't track the error; we'll get that in EndDraw()
|
||||||
// see https://msdn.microsoft.com/en-us/library/windows/desktop/dd370994%28v=vs.85%29.aspx
|
// see https://msdn.microsoft.com/en-us/library/windows/desktop/dd370994%28v=vs.85%29.aspx
|
||||||
a->rt->Resize(&size);
|
a->rt->Resize(&size);
|
||||||
|
}
|
||||||
|
|
||||||
// according to Rick Brewster, we must always redraw the entire client area after calling ID2D1RenderTarget::Resize() (see http://stackoverflow.com/a/33222983/3408572)
|
// according to Rick Brewster, we must always redraw the entire client area after calling ID2D1RenderTarget::Resize() (see http://stackoverflow.com/a/33222983/3408572)
|
||||||
// we used to have a uiAreaHandler.RedrawOnResize() method to decide this; now you know why we don't anymore
|
// we used to have a uiAreaHandler.RedrawOnResize() method to decide this; now you know why we don't anymore
|
||||||
|
@ -109,7 +109,7 @@ static void areaMouseEvent(uiArea *a, int down, int up, WPARAM wParam, LPARAM l
|
|||||||
me.Y += a->vscrollpos;
|
me.Y += a->vscrollpos;
|
||||||
}
|
}
|
||||||
|
|
||||||
loadAreaSize(a, NULL, &(me.AreaWidth), &(me.AreaHeight));
|
loadAreaSize(a, &(me.AreaWidth), &(me.AreaHeight));
|
||||||
|
|
||||||
me.Down = down;
|
me.Down = down;
|
||||||
me.Up = up;
|
me.Up = up;
|
||||||
|
@ -2,20 +2,35 @@
|
|||||||
#include "uipriv_windows.hpp"
|
#include "uipriv_windows.hpp"
|
||||||
#include "area.hpp"
|
#include "area.hpp"
|
||||||
|
|
||||||
void loadAreaSize(uiArea *a, ID2D1RenderTarget *rt, double *width, double *height)
|
// TODO: make those int rather than double
|
||||||
|
void loadAreaSize(uiArea *a, double *width, double *height)
|
||||||
{
|
{
|
||||||
D2D1_SIZE_F size;
|
D2D1_SIZE_F size;
|
||||||
|
|
||||||
|
if (a->width != -1)
|
||||||
|
{
|
||||||
|
*width = (double)a->width;
|
||||||
|
*height = (double)a->height;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
*width = 0;
|
*width = 0;
|
||||||
*height = 0;
|
*height = 0;
|
||||||
if (!a->scrolling) {
|
if (!a->scrolling) {
|
||||||
if (rt == NULL)
|
/*if (rt == NULL)
|
||||||
rt = a->rt;
|
rt = a->rt;
|
||||||
size = realGetSize(rt);
|
size = realGetSize(rt);
|
||||||
*width = size.width;
|
*width = size.width;
|
||||||
*height = size.height;
|
*height = size.height;
|
||||||
dipToPixels(a, width, height);
|
dipToPixels(a, width, height);*/
|
||||||
|
RECT rect;
|
||||||
|
GetWindowRect(a->hwnd, &rect);
|
||||||
|
*width = (double)(rect.right - rect.left);
|
||||||
|
*height = (double)(rect.bottom - rect.top);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a->width = (int)*width;
|
||||||
|
a->height = (int)*height;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pixelsToDIP(uiArea *a, double *x, double *y)
|
void pixelsToDIP(uiArea *a, double *x, double *y)
|
||||||
|
@ -134,3 +134,8 @@ void *uiGLGetProcAddress(const char* proc)
|
|||||||
{
|
{
|
||||||
return (void*)wglGetProcAddress(proc);
|
return (void*)wglGetProcAddress(proc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void uiGLSwapBuffers(uiGLContext* ctx)
|
||||||
|
{
|
||||||
|
SwapBuffers(ctx->dc);
|
||||||
|
}
|
||||||
|
@ -568,6 +568,7 @@ int EmuThreadFunc(void* burp)
|
|||||||
if (EmuRunning == 0) break;
|
if (EmuRunning == 0) break;
|
||||||
|
|
||||||
uiAreaQueueRedrawAll(MainDrawArea);
|
uiAreaQueueRedrawAll(MainDrawArea);
|
||||||
|
//uiGLSwapBuffers(GLContext);
|
||||||
|
|
||||||
// framerate limiter based off SDL2_gfx
|
// framerate limiter based off SDL2_gfx
|
||||||
float framerate;
|
float framerate;
|
||||||
@ -619,7 +620,8 @@ int EmuThreadFunc(void* burp)
|
|||||||
|
|
||||||
if (EmuRunning == 2)
|
if (EmuRunning == 2)
|
||||||
{
|
{
|
||||||
uiAreaQueueRedrawAll(MainDrawArea);
|
//uiAreaQueueRedrawAll(MainDrawArea);
|
||||||
|
//uiGLSwapBuffers(GLContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
EmuStatus = EmuRunning;
|
EmuStatus = EmuRunning;
|
||||||
@ -2061,7 +2063,7 @@ int main(int argc, char** argv)
|
|||||||
areahandler.Resize = OnAreaResize;
|
areahandler.Resize = OnAreaResize;
|
||||||
|
|
||||||
ScreenDrawInited = false;
|
ScreenDrawInited = false;
|
||||||
MainDrawArea = uiNewArea(&areahandler);
|
MainDrawArea = uiNewArea(&areahandler, 0);
|
||||||
uiWindowSetChild(MainWindow, uiControl(MainDrawArea));
|
uiWindowSetChild(MainWindow, uiControl(MainDrawArea));
|
||||||
uiControlSetMinSize(uiControl(MainDrawArea), 256, 384);
|
uiControlSetMinSize(uiControl(MainDrawArea), 256, 384);
|
||||||
uiAreaSetBackgroundColor(MainDrawArea, 0, 0, 0); // TODO: make configurable?
|
uiAreaSetBackgroundColor(MainDrawArea, 0, 0, 0); // TODO: make configurable?
|
||||||
|
Reference in New Issue
Block a user