begin butchering uiArea

This commit is contained in:
Arisotura 2019-05-15 16:43:56 +02:00
parent 4d427c9d2d
commit a89366cb5a
9 changed files with 75 additions and 20 deletions

View File

@ -432,7 +432,7 @@ void Open(int type)
uiLabel* dummy = uiNewLabel("");
uiBoxAppend(in_ctrl, uiControl(dummy), 1);
dlg->keypresscatcher = uiNewArea(&dlg->areahandler);
dlg->keypresscatcher = uiNewArea(&dlg->areahandler, 0);
uiControl(dlg->keypresscatcher)->UserData = dlg;
uiBoxAppend(in_ctrl, uiControl(dlg->keypresscatcher), 0);

View File

@ -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 uiAreaBeginUserWindowResize(uiArea *a, uiWindowResizeEdge edge);
_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);
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 uiGLMakeContextCurrent(uiGLContext* ctx);
_UI_EXTERN void *uiGLGetProcAddress(const char* proc);
_UI_EXTERN void uiGLSwapBuffers(uiGLContext* ctx);
_UI_ENUM(uiModifiers) {

View File

@ -25,8 +25,11 @@ static LRESULT CALLBACK areaWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
}
// always recreate the render target if necessary
if (a->rt == NULL)
a->rt = makeHWNDRenderTarget(a->hwnd);
if (!a->openGL)
{
if (a->rt == NULL)
a->rt = makeHWNDRenderTarget(a->hwnd);
}
if (areaDoDraw(a, uMsg, wParam, lParam, &lResult) != FALSE)
return lResult;
@ -34,12 +37,14 @@ static LRESULT CALLBACK areaWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
if (uMsg == WM_WINDOWPOSCHANGED) {
if ((wp->flags & SWP_NOSIZE) != 0)
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
a->width = -1;
a->height = -1;
uiWindowsEnsureGetClientRect(a->hwnd, &client);
areaDrawOnResize(a, &client);
areaScrollOnResize(a, &client);
{
double w, h;
loadAreaSize(a, a->rt, &w, &h);
loadAreaSize(a, &w, &h);
a->ah->Resize(a->ah, a, (int)w, (int)h);
}
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;
uiWindowsNewControl(uiArea, a);
a->width = -1;
a->height = -1;
a->ah = ah;
a->scrolling = FALSE;
clickCounterReset(&(a->cc));
@ -195,6 +203,8 @@ uiArea *uiNewArea(uiAreaHandler *ah)
uiAreaSetBackgroundColor(a, -1, -1, -1);
a->openGL = opengl;
return a;
}
@ -204,6 +214,9 @@ uiArea *uiNewScrollingArea(uiAreaHandler *ah, int width, int height)
uiWindowsNewControl(uiArea, a);
a->width = -1;
a->height = -1;
a->ah = ah;
a->scrolling = TRUE;
a->scrollWidth = width;
@ -219,6 +232,8 @@ uiArea *uiNewScrollingArea(uiAreaHandler *ah, int width, int height)
uiAreaSetBackgroundColor(a, -1, -1, -1);
a->openGL = 0; // TODO, eventually???
// set initial scrolling parameters
areaUpdateScroll(a);

View File

@ -10,6 +10,8 @@ struct uiArea {
HWND hwnd;
uiAreaHandler *ah;
int width, height;
BOOL scrolling;
int scrollWidth;
int scrollHeight;
@ -26,6 +28,8 @@ struct uiArea {
int bgR, bgG, bgB;
int openGL;
ID2D1HwndRenderTarget *rt;
};
@ -42,6 +46,6 @@ extern void areaUpdateScroll(uiArea *a);
extern BOOL areaDoEvents(uiArea *a, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *lResult);
// 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 dipToPixels(uiArea *a, double *x, double *y);

View File

@ -6,6 +6,13 @@ static HRESULT doPaint(uiArea *a, ID2D1RenderTarget *rt, RECT *clip)
{
uiAreaHandler *ah = a->ah;
uiAreaDrawParams dp;
if (a->openGL)
{
(*(ah->Draw))(ah, a, &dp);
return S_OK;
}
COLORREF bgcolorref;
D2D1_COLOR_F bgcolor;
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
dp.Context = newContext(rt);
loadAreaSize(a, rt, &(dp.AreaWidth), &(dp.AreaHeight));
loadAreaSize(a, &(dp.AreaWidth), &(dp.AreaHeight));
dp.ClipX = clip->left;
dp.ClipY = clip->top;
@ -113,6 +120,9 @@ static void onWM_PAINT(uiArea *a)
static void onWM_PRINTCLIENT(uiArea *a, HDC dc)
{
// TODO????
if (a->openGL) return;
ID2D1DCRenderTarget *rt;
RECT client;
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?
void areaDrawOnResize(uiArea *a, RECT *newClient)
{
D2D1_SIZE_U size;
if (!a->openGL)
{
D2D1_SIZE_U size;
size.width = newClient->right - newClient->left;
size.height = newClient->bottom - newClient->top;
// 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
a->rt->Resize(&size);
size.width = newClient->right - newClient->left;
size.height = newClient->bottom - newClient->top;
// 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
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)
// we used to have a uiAreaHandler.RedrawOnResize() method to decide this; now you know why we don't anymore

View File

@ -109,7 +109,7 @@ static void areaMouseEvent(uiArea *a, int down, int up, WPARAM wParam, LPARAM l
me.Y += a->vscrollpos;
}
loadAreaSize(a, NULL, &(me.AreaWidth), &(me.AreaHeight));
loadAreaSize(a, &(me.AreaWidth), &(me.AreaHeight));
me.Down = down;
me.Up = up;

View File

@ -2,20 +2,35 @@
#include "uipriv_windows.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;
if (a->width != -1)
{
*width = (double)a->width;
*height = (double)a->height;
return;
}
*width = 0;
*height = 0;
if (!a->scrolling) {
if (rt == NULL)
/*if (rt == NULL)
rt = a->rt;
size = realGetSize(rt);
*width = size.width;
*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)

View File

@ -134,3 +134,8 @@ void *uiGLGetProcAddress(const char* proc)
{
return (void*)wglGetProcAddress(proc);
}
void uiGLSwapBuffers(uiGLContext* ctx)
{
SwapBuffers(ctx->dc);
}

View File

@ -568,6 +568,7 @@ int EmuThreadFunc(void* burp)
if (EmuRunning == 0) break;
uiAreaQueueRedrawAll(MainDrawArea);
//uiGLSwapBuffers(GLContext);
// framerate limiter based off SDL2_gfx
float framerate;
@ -619,7 +620,8 @@ int EmuThreadFunc(void* burp)
if (EmuRunning == 2)
{
uiAreaQueueRedrawAll(MainDrawArea);
//uiAreaQueueRedrawAll(MainDrawArea);
//uiGLSwapBuffers(GLContext);
}
EmuStatus = EmuRunning;
@ -2061,7 +2063,7 @@ int main(int argc, char** argv)
areahandler.Resize = OnAreaResize;
ScreenDrawInited = false;
MainDrawArea = uiNewArea(&areahandler);
MainDrawArea = uiNewArea(&areahandler, 0);
uiWindowSetChild(MainWindow, uiControl(MainDrawArea));
uiControlSetMinSize(uiControl(MainDrawArea), 256, 384);
uiAreaSetBackgroundColor(MainDrawArea, 0, 0, 0); // TODO: make configurable?