Fixed up more bits of uiArea on Windows.

This commit is contained in:
Pietro Gagliardi 2015-10-09 11:49:57 -04:00
parent f899bf28c2
commit b0492cbde8
3 changed files with 21 additions and 16 deletions

View File

@ -1,6 +1,9 @@
// 22 april 2015 // 22 april 2015
#include "test.h" #include "test.h"
// TODOs
// - blank page affects menus negatively on Windows
void die(const char *fmt, ...) void die(const char *fmt, ...)
{ {
va_list ap; va_list ap;

View File

@ -89,10 +89,11 @@ void scrollto(uiArea *a, int which, struct scrollParams *p, intmax_t pos)
xamount = 0; xamount = 0;
} }
// TODO this isn't safe with Direct2D
if (ScrollWindowEx(a->hwnd, xamount, yamount, if (ScrollWindowEx(a->hwnd, xamount, yamount,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
SW_ERASE | SW_INVALIDATE) == ERROR) SW_ERASE | SW_INVALIDATE) == ERROR)
;//TODO logLastError("error scrolling area in scrollto()"); logLastError("error scrolling area in scrollto()");
*(p->pos) = pos; *(p->pos) = pos;
@ -513,9 +514,14 @@ static LRESULT CALLBACK areaWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
a->rt = makeHWNDRenderTarget(a->hwnd); a->rt = makeHWNDRenderTarget(a->hwnd);
if (GetClientRect(a->hwnd, &client) == 0) if (GetClientRect(a->hwnd, &client) == 0)
logLastError("error getting client rect in WM_PAINT in areaWndProc()"); logLastError("error getting client rect in WM_PAINT in areaWndProc()");
// TODO really FALSE? // do not clear the update rect; we do that ourselves in doPaint()
if (GetUpdateRect(a->hwnd, &clip, FALSE) == 0) if (GetUpdateRect(a->hwnd, &clip, FALSE) == 0) {
logLastError("error getting clip rect in WM_PAINT in areaWndProc()"); // set a zero clip rect just in case GetUpdateRect() didn't change clip
clip.left = 0;
clip.top = 0;
clip.right = 0;
clip.bottom = 0;
}
hr = doPaint(a, (ID2D1RenderTarget *) (a->rt), &client, &clip); hr = doPaint(a, (ID2D1RenderTarget *) (a->rt), &client, &clip);
switch (hr) { switch (hr) {
case S_OK: case S_OK:
@ -526,6 +532,7 @@ static LRESULT CALLBACK areaWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
// DON'T validate the rect // DON'T validate the rect
// instead, simply drop the render target // instead, simply drop the render target
// we'll get another WM_PAINT and make the render target again // we'll get another WM_PAINT and make the render target again
// TODO would this require us to invalidate the entire client area?
ID2D1HwndRenderTarget_Release(a->rt); ID2D1HwndRenderTarget_Release(a->rt);
a->rt = NULL; a->rt = NULL;
break; break;
@ -632,6 +639,7 @@ static void minimumSize(uiWindowsControl *c, uiWindowsSizing *d, intmax_t *width
} }
// TODO affect visibility properly // TODO affect visibility properly
// TODO what did this mean
void processAreaMessage(HWND active, MSG *msg) void processAreaMessage(HWND active, MSG *msg)
{ {
LRESULT handled; LRESULT handled;

View File

@ -77,11 +77,9 @@ uiDrawPath *uiDrawNewPath(uiDrawFillMode fillmode)
uiDrawPath *p; uiDrawPath *p;
HRESULT hr; HRESULT hr;
// TODO uiNew p = uiNew(uiDrawPath);
p = malloc(sizeof (uiDrawPath));
hr = ID2D1Factory_CreatePathGeometry(d2dfactory, hr = ID2D1Factory_CreatePathGeometry(d2dfactory,
&(p->path)); &(p->path));
// TODO make sure this is the only success code
if (hr != S_OK) if (hr != S_OK)
logHRESULT("error creating path in uiDrawNewPath()", hr); logHRESULT("error creating path in uiDrawNewPath()", hr);
hr = ID2D1PathGeometry_Open(p->path, hr = ID2D1PathGeometry_Open(p->path,
@ -111,8 +109,7 @@ void uiDrawFreePath(uiDrawPath *p)
// TODO close sink first? // TODO close sink first?
ID2D1GeometrySink_Release(p->sink); ID2D1GeometrySink_Release(p->sink);
ID2D1PathGeometry_Release(p->path); ID2D1PathGeometry_Release(p->path);
// TODO uiFree uiFree(p);
free(p);
} }
void uiDrawPathNewFigure(uiDrawPath *p, double x, double y) void uiDrawPathNewFigure(uiDrawPath *p, double x, double y)
@ -260,8 +257,7 @@ uiDrawContext *newContext(ID2D1RenderTarget *rt)
{ {
uiDrawContext *c; uiDrawContext *c;
// TODO use uiNew c = uiNew(uiDrawContext);
c = (uiDrawContext *) malloc(sizeof (uiDrawContext));
c->rt = rt; c->rt = rt;
return c; return c;
} }
@ -293,8 +289,7 @@ static ID2D1GradientStopCollection *mkstops(uiDrawBrush *b, ID2D1RenderTarget *r
size_t i; size_t i;
HRESULT hr; HRESULT hr;
// TODO uiAlloc stops = uiAlloc(b->NumStops * sizeof (D2D1_GRADIENT_STOP), "D2D1_GRADIENT_STOP[]");
stops = malloc(b->NumStops * sizeof (D2D1_GRADIENT_STOP));
for (i = 0; i < b->NumStops; i++) { for (i = 0; i < b->NumStops; i++) {
stops[i].position = b->Stops[i].Pos; stops[i].position = b->Stops[i].Pos;
stops[i].color.r = b->Stops[i].R; stops[i].color.r = b->Stops[i].R;
@ -315,8 +310,7 @@ static ID2D1GradientStopCollection *mkstops(uiDrawBrush *b, ID2D1RenderTarget *r
if (hr != S_OK) if (hr != S_OK)
logHRESULT("error creating stop collection in mkstops()", hr); logHRESULT("error creating stop collection in mkstops()", hr);
// TODO uiFree uiFree(stops);
free(stops);
return s; return s;
} }
@ -398,7 +392,7 @@ static ID2D1Brush *makeBrush(uiDrawBrush *b, ID2D1RenderTarget *rt)
// TODO // TODO
} }
//TODO complain("invalid brush type %d in makeBrush()", b->Type); complain("invalid brush type %d in makeBrush()", b->Type);
return NULL; // make compiler happy return NULL; // make compiler happy
} }