From 4deb0f364ca12fa05a3390b6238ef45d3579ffd8 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Fri, 9 Oct 2015 12:33:45 -0400 Subject: [PATCH] Migrated the OS X uiArea back into main. --- darwin/GNUmakeinc.mk | 3 ++ {macarea => darwin}/area.m | 64 ++++++++++--------------- macarea/events.m => darwin/areaevents.m | 3 +- {macarea => darwin}/draw.m | 30 +++++------- darwin/uipriv_darwin.h | 11 +++++ macarea/area.h | 13 ----- macarea/uipriv_darwin.h | 6 --- 7 files changed, 54 insertions(+), 76 deletions(-) rename {macarea => darwin}/area.m (96%) rename macarea/events.m => darwin/areaevents.m (98%) rename {macarea => darwin}/draw.m (94%) delete mode 100644 macarea/area.h delete mode 100644 macarea/uipriv_darwin.h diff --git a/darwin/GNUmakeinc.mk b/darwin/GNUmakeinc.mk index 40d8d7d8..3f0d2a20 100644 --- a/darwin/GNUmakeinc.mk +++ b/darwin/GNUmakeinc.mk @@ -2,6 +2,8 @@ osMFILES = \ darwin/alloc.m \ + darwin/area.m \ + darwin/areaevents.m \ darwin/autolayout.m \ darwin/box.m \ darwin/button.m \ @@ -9,6 +11,7 @@ osMFILES = \ darwin/combobox.m \ darwin/control.m \ darwin/datetimepicker.m \ + darwin/draw.m \ darwin/entry.m \ darwin/group.m \ darwin/label.m \ diff --git a/macarea/area.m b/darwin/area.m similarity index 96% rename from macarea/area.m rename to darwin/area.m index 33ebf814..720c82de 100644 --- a/macarea/area.m +++ b/darwin/area.m @@ -1,23 +1,11 @@ // 9 september 2015 -#include "area.h" +#import "uipriv_darwin.h" // We are basically cloning NSScrollView here, managing scrolling ourselves. // TODOs // - is the page increment set up right? // - do we need to draw anything in the empty corner? -// TODO remove this -void addConstraint(NSView *view, NSString *constraint, NSDictionary *metrics, NSDictionary *views) -{ - NSArray *constraints; - - constraints = [NSLayoutConstraint constraintsWithVisualFormat:constraint - options:0 - metrics:metrics - views:views]; - [view addConstraints:constraints]; -} - // NSScrollers have no intrinsic size; here we give it one @interface areaScroller : NSScroller { BOOL libui_vertical; @@ -103,11 +91,17 @@ void addConstraint(NSView *view, NSString *constraint, NSDictionary *metrics, NS @end struct uiArea { -// uiDarwinControl c; + uiDarwinControl c; areaView *view; uiAreaHandler *ah; }; +uiDarwinDefineControl( + uiArea, // type name + uiAreaType, // type function + view // handle +) + @implementation areaDrawingView - (id)initWithFrame:(NSRect)r area:(uiArea *)a @@ -142,6 +136,8 @@ struct uiArea { dp.VScrollPos = [av vscrollPos]; (*(self->libui_a->ah->Draw))(self->libui_a->ah, self->libui_a, &dp); + + freeContext(dp.Context); } - (BOOL)isFlipped @@ -679,30 +675,7 @@ int sendAreaEvents(NSEvent *e) @end -uiArea *newArea(uiAreaHandler *ah) -{ - uiArea *a; - - // TODO - a = (uiArea *) malloc(sizeof (uiArea)); - - a->ah = ah; - - a->view = [[areaView alloc] initWithFrame:NSZeroRect area:a]; - - // set initial state - // TODO do this on other platforms? - areaUpdateScroll(a); - - return a; -} - -NSView *areaGetView(uiArea *a) -{ - return a->view; -} - -void areaUpdateScroll(uiArea *a) +void uiAreaUpdateScroll(uiArea *a) { /* TODO NSRect frame; @@ -713,3 +686,18 @@ void areaUpdateScroll(uiArea *a) [a->documentView setFrame:frame]; */ } + +uiArea *uiNewArea(uiAreaHandler *ah) +{ + uiArea *a; + + a = (uiArea *) uiNewControl(uiAreaType()); + + a->ah = ah; + + a->view = [[areaView alloc] initWithFrame:NSZeroRect area:a]; + + uiDarwinFinishNewControl(a, uiArea); + + return a; +} diff --git a/macarea/events.m b/darwin/areaevents.m similarity index 98% rename from macarea/events.m rename to darwin/areaevents.m index 44ac9c57..b5e7dab6 100644 --- a/macarea/events.m +++ b/darwin/areaevents.m @@ -1,6 +1,5 @@ // 30 march 2014 -//TODO#include "uipriv_darwin.h" -#include "area.h" +#include "uipriv_darwin.h" /* Mac OS X uses its own set of hardware key codes that are different from PC keyboard scancodes, but are positional (like PC keyboard scancodes). These are defined in , a Carbon header. As far as I can tell, there's no way to include this header without either using an absolute path or linking Carbon into the program, so the constant values are used here instead. diff --git a/macarea/draw.m b/darwin/draw.m similarity index 94% rename from macarea/draw.m rename to darwin/draw.m index 89cea729..553b4718 100644 --- a/macarea/draw.m +++ b/darwin/draw.m @@ -1,5 +1,5 @@ // 6 september 2015 -#include "area.h" +#import "uipriv_darwin.h" struct uiDrawPath { CGMutablePathRef path; @@ -11,24 +11,18 @@ uiDrawPath *uiDrawNewPath(uiDrawFillMode mode) { uiDrawPath *p; - // TODO uiNew - p = malloc(sizeof (uiDrawPath)); + p = uiNew(uiDrawPath); p->path = CGPathCreateMutable(); p->fillMode = mode; -p->ended = NO; return p; } void uiDrawFreePath(uiDrawPath *p) { CGPathRelease((CGPathRef) (p->path)); - // TODO uiFree - free(p); + uiFree(p); } -// TODO -#define complain(...) ; - void uiDrawPathNewFigure(uiDrawPath *p, double x, double y) { if (p->ended) @@ -106,12 +100,16 @@ uiDrawContext *newContext(CGContextRef ctxt) { uiDrawContext *c; - // TODO use uiNew - c = (uiDrawContext *) malloc(sizeof (uiDrawContext)); + c = uiNew(uiDrawContext); c->c = ctxt; return c; } +void freeContext(uiDrawContext *c) +{ + uiFree(c); +} + // a stroke is identical to a fill of a stroked path // we need to do this in order to stroke with a gradient; see http://stackoverflow.com/a/25034854/3408572 // doing this for other brushes works too @@ -192,9 +190,8 @@ static void fillGradient(CGContextRef ctxt, uiDrawPath *p, uiDrawBrush *b) colorspace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB); // make the gradient - // TODO uiAlloc - colors = malloc(b->NumStops * 4 * sizeof (CGFloat)); - locations = malloc(b->NumStops * sizeof (CGFloat)); + colors = uiAlloc(b->NumStops * 4 * sizeof (CGFloat), "CGFloat[]"); + locations = uiAlloc(b->NumStops * sizeof (CGFloat), "CGFloat[]"); for (i = 0; i < b->NumStops; i++) { colors[i * 4 + 0] = b->Stops[i].R; colors[i * 4 + 1] = b->Stops[i].G; @@ -203,9 +200,8 @@ static void fillGradient(CGContextRef ctxt, uiDrawPath *p, uiDrawBrush *b) locations[i] = b->Stops[i].Pos; } gradient = CGGradientCreateWithColorComponents(colorspace, colors, locations, b->NumStops); - // TODO uiFree - free(locations); - free(colors); + uiFree(locations); + uiFree(colors); // because we're mucking with clipping, we need to save the graphics state and restore it later CGContextSaveGState(ctxt); diff --git a/darwin/uipriv_darwin.h b/darwin/uipriv_darwin.h index 2af6aa7a..81e21d1e 100644 --- a/darwin/uipriv_darwin.h +++ b/darwin/uipriv_darwin.h @@ -63,3 +63,14 @@ extern NSSize fittingAlignmentSize(NSView *); extern NSMapTable *newMap(void); extern void *mapGet(NSMapTable *map, id key); extern void mapSet(NSMapTable *map, id key, void *value); + +// area.m +extern int sendAreaEvents(NSEvent *); + +// areaevents.m +extern BOOL fromKeycode(unsigned short keycode, uiAreaKeyEvent *ke); +extern BOOL keycodeModifier(unsigned short keycode, uiModifiers *mod); + +// draw.m +extern uiDrawContext *newContext(CGContextRef); +extern void freeContext(uiDrawContext *); diff --git a/macarea/area.h b/macarea/area.h deleted file mode 100644 index 16c72d57..00000000 --- a/macarea/area.h +++ /dev/null @@ -1,13 +0,0 @@ -// 8 september 2015 -#import -#import -#import "ui.h" -#import "uipriv_darwin.h" - -extern uiArea *newArea(uiAreaHandler *ah); - -extern uiDrawContext *newContext(CGContextRef); - -extern NSView *areaGetView(uiArea *); - -extern void areaUpdateScroll(uiArea *); diff --git a/macarea/uipriv_darwin.h b/macarea/uipriv_darwin.h deleted file mode 100644 index a4ccde37..00000000 --- a/macarea/uipriv_darwin.h +++ /dev/null @@ -1,6 +0,0 @@ -// area.m -extern int sendAreaEvents(NSEvent *e); - -// events.m -extern BOOL fromKeycode(unsigned short keycode, uiAreaKeyEvent *ke); -extern BOOL keycodeModifier(unsigned short keycode, uiModifiers *mod);