Migrated the OS X uiArea back into main.

This commit is contained in:
Pietro Gagliardi 2015-10-09 12:33:45 -04:00
parent b0492cbde8
commit 4deb0f364c
7 changed files with 54 additions and 76 deletions

View File

@ -2,6 +2,8 @@
osMFILES = \ osMFILES = \
darwin/alloc.m \ darwin/alloc.m \
darwin/area.m \
darwin/areaevents.m \
darwin/autolayout.m \ darwin/autolayout.m \
darwin/box.m \ darwin/box.m \
darwin/button.m \ darwin/button.m \
@ -9,6 +11,7 @@ osMFILES = \
darwin/combobox.m \ darwin/combobox.m \
darwin/control.m \ darwin/control.m \
darwin/datetimepicker.m \ darwin/datetimepicker.m \
darwin/draw.m \
darwin/entry.m \ darwin/entry.m \
darwin/group.m \ darwin/group.m \
darwin/label.m \ darwin/label.m \

View File

@ -1,23 +1,11 @@
// 9 september 2015 // 9 september 2015
#include "area.h" #import "uipriv_darwin.h"
// We are basically cloning NSScrollView here, managing scrolling ourselves. // We are basically cloning NSScrollView here, managing scrolling ourselves.
// TODOs // TODOs
// - is the page increment set up right? // - is the page increment set up right?
// - do we need to draw anything in the empty corner? // - 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 // NSScrollers have no intrinsic size; here we give it one
@interface areaScroller : NSScroller { @interface areaScroller : NSScroller {
BOOL libui_vertical; BOOL libui_vertical;
@ -103,11 +91,17 @@ void addConstraint(NSView *view, NSString *constraint, NSDictionary *metrics, NS
@end @end
struct uiArea { struct uiArea {
// uiDarwinControl c; uiDarwinControl c;
areaView *view; areaView *view;
uiAreaHandler *ah; uiAreaHandler *ah;
}; };
uiDarwinDefineControl(
uiArea, // type name
uiAreaType, // type function
view // handle
)
@implementation areaDrawingView @implementation areaDrawingView
- (id)initWithFrame:(NSRect)r area:(uiArea *)a - (id)initWithFrame:(NSRect)r area:(uiArea *)a
@ -142,6 +136,8 @@ struct uiArea {
dp.VScrollPos = [av vscrollPos]; dp.VScrollPos = [av vscrollPos];
(*(self->libui_a->ah->Draw))(self->libui_a->ah, self->libui_a, &dp); (*(self->libui_a->ah->Draw))(self->libui_a->ah, self->libui_a, &dp);
freeContext(dp.Context);
} }
- (BOOL)isFlipped - (BOOL)isFlipped
@ -679,30 +675,7 @@ int sendAreaEvents(NSEvent *e)
@end @end
uiArea *newArea(uiAreaHandler *ah) void uiAreaUpdateScroll(uiArea *a)
{
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)
{ {
/* TODO /* TODO
NSRect frame; NSRect frame;
@ -713,3 +686,18 @@ void areaUpdateScroll(uiArea *a)
[a->documentView setFrame:frame]; [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;
}

View File

@ -1,6 +1,5 @@
// 30 march 2014 // 30 march 2014
//TODO#include "uipriv_darwin.h" #include "uipriv_darwin.h"
#include "area.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 <HIToolbox/Events.h>, 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. 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 <HIToolbox/Events.h>, 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.

View File

@ -1,5 +1,5 @@
// 6 september 2015 // 6 september 2015
#include "area.h" #import "uipriv_darwin.h"
struct uiDrawPath { struct uiDrawPath {
CGMutablePathRef path; CGMutablePathRef path;
@ -11,24 +11,18 @@ uiDrawPath *uiDrawNewPath(uiDrawFillMode mode)
{ {
uiDrawPath *p; uiDrawPath *p;
// TODO uiNew p = uiNew(uiDrawPath);
p = malloc(sizeof (uiDrawPath));
p->path = CGPathCreateMutable(); p->path = CGPathCreateMutable();
p->fillMode = mode; p->fillMode = mode;
p->ended = NO;
return p; return p;
} }
void uiDrawFreePath(uiDrawPath *p) void uiDrawFreePath(uiDrawPath *p)
{ {
CGPathRelease((CGPathRef) (p->path)); CGPathRelease((CGPathRef) (p->path));
// TODO uiFree uiFree(p);
free(p);
} }
// TODO
#define complain(...) ;
void uiDrawPathNewFigure(uiDrawPath *p, double x, double y) void uiDrawPathNewFigure(uiDrawPath *p, double x, double y)
{ {
if (p->ended) if (p->ended)
@ -106,12 +100,16 @@ uiDrawContext *newContext(CGContextRef ctxt)
{ {
uiDrawContext *c; uiDrawContext *c;
// TODO use uiNew c = uiNew(uiDrawContext);
c = (uiDrawContext *) malloc(sizeof (uiDrawContext));
c->c = ctxt; c->c = ctxt;
return c; return c;
} }
void freeContext(uiDrawContext *c)
{
uiFree(c);
}
// a stroke is identical to a fill of a stroked path // 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 // 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 // doing this for other brushes works too
@ -192,9 +190,8 @@ static void fillGradient(CGContextRef ctxt, uiDrawPath *p, uiDrawBrush *b)
colorspace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB); colorspace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
// make the gradient // make the gradient
// TODO uiAlloc colors = uiAlloc(b->NumStops * 4 * sizeof (CGFloat), "CGFloat[]");
colors = malloc(b->NumStops * 4 * sizeof (CGFloat)); locations = uiAlloc(b->NumStops * sizeof (CGFloat), "CGFloat[]");
locations = malloc(b->NumStops * sizeof (CGFloat));
for (i = 0; i < b->NumStops; i++) { for (i = 0; i < b->NumStops; i++) {
colors[i * 4 + 0] = b->Stops[i].R; colors[i * 4 + 0] = b->Stops[i].R;
colors[i * 4 + 1] = b->Stops[i].G; 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; locations[i] = b->Stops[i].Pos;
} }
gradient = CGGradientCreateWithColorComponents(colorspace, colors, locations, b->NumStops); gradient = CGGradientCreateWithColorComponents(colorspace, colors, locations, b->NumStops);
// TODO uiFree uiFree(locations);
free(locations); uiFree(colors);
free(colors);
// because we're mucking with clipping, we need to save the graphics state and restore it later // because we're mucking with clipping, we need to save the graphics state and restore it later
CGContextSaveGState(ctxt); CGContextSaveGState(ctxt);

View File

@ -63,3 +63,14 @@ extern NSSize fittingAlignmentSize(NSView *);
extern NSMapTable *newMap(void); extern NSMapTable *newMap(void);
extern void *mapGet(NSMapTable *map, id key); extern void *mapGet(NSMapTable *map, id key);
extern void mapSet(NSMapTable *map, id key, void *value); 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 *);

View File

@ -1,13 +0,0 @@
// 8 september 2015
#import <Cocoa/Cocoa.h>
#import <stdint.h>
#import "ui.h"
#import "uipriv_darwin.h"
extern uiArea *newArea(uiAreaHandler *ah);
extern uiDrawContext *newContext(CGContextRef);
extern NSView *areaGetView(uiArea *);
extern void areaUpdateScroll(uiArea *);

View File

@ -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);