Migrated the OS X uiArea back into main.
This commit is contained in:
parent
b0492cbde8
commit
4deb0f364c
|
@ -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 \
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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 <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.
|
|
@ -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);
|
|
@ -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 *);
|
||||
|
|
|
@ -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 *);
|
|
@ -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);
|
Loading…
Reference in New Issue