Skip to content

Commit

Permalink
darwin: Cursor shapes
Browse files Browse the repository at this point in the history
  • Loading branch information
tweekmonster committed Mar 24, 2017
1 parent 6ba4d39 commit 47bbede
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gui/app_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (w *window) Flush(mode int, character string, width int, cursor screen.Vect
fg, bg = bg, fg
}
cbytes := []byte(character + "\x00")
C.flush(C.uintptr_t(w.id), C.int(mode), C.int(cursor.X), C.int(cursor.Y), (*C.char)(unsafe.Pointer(&cbytes[0])), C.int(width), C.uint8_t(attrs.Attrs), bg, fg, C.int32_t(attrs.Sp))
C.flush(C.uintptr_t(w.id), C.int(mode), C.int(cursor.X), C.int(cursor.Y), (*C.char)(unsafe.Pointer(&cbytes[0])), C.int(width), C.uint8_t(attrs.Attrs), fg, bg, C.int32_t(attrs.Sp))
return nil
}

Expand Down
2 changes: 2 additions & 0 deletions gui/nmux_darwin/ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
@interface DrawTextOp : DrawOp
{
NSString *_text;
BOOL _cursor;
}
@property (atomic, retain) NSString *text;
@property (atomic) BOOL cursor;

+ (DrawTextOp *)opWithText:(NSString *)text x:(int)x y:(int)y
attrs:(TextAttr)attrs;
Expand Down
23 changes: 20 additions & 3 deletions gui/nmux_darwin/screen.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ - (Mode)state {
}

- (void)setState:(Mode)state {
cursorUpdate = (state & ModeRedraw) != ModeRedraw;
cursorUpdate = ((state & ModeRedraw) != ModeRedraw
|| (state & ModeNormal) != (_state & ModeNormal)
|| (state & ModeInsert) != (_state & ModeInsert)
|| (state & ModeReplace) != (_state & ModeReplace));
_state = state;
}

Expand Down Expand Up @@ -519,10 +522,23 @@ - (void)setGridSize:(NSSize)size {
}

- (void)drawTextContext:(CGContextRef)ctx op:(DrawTextOp *)op rect:(CGRect)rect {
CGColorRef fg = CGRGB([op attrs].fg);
CGColorRef bg = CGRGB([op attrs].bg);

CGContextSaveGState(ctx);
CGContextSetFillColorWithColor(ctx, CGRGB([op attrs].bg));
CGContextSetFillColorWithColor(ctx, bg);
CGContextFillRect(ctx, rect);

if ([op cursor]) {
CGContextSetFillColorWithColor(ctx, fg);
if ((_state & ModeInsert) == ModeInsert) {
rect.size.width = 1;
} else if ((_state & ModeReplace) == ModeReplace) {
rect.size.height = 2;
}
CGContextFillRect(ctx, rect);
}

size_t runLength = (size_t)[[op text] length];

if (runLength > runMaxLength) {
Expand Down Expand Up @@ -550,7 +566,7 @@ - (void)drawTextContext:(CGContextRef)ctx op:(DrawTextOp *)op rect:(CGRect)rect
runPositions[i] = CGPointMake(i * cellSize.width, 0);
}

CGContextSetFillColorWithColor(ctx, CGRGB([op attrs].fg));
CGContextSetFillColorWithColor(ctx, ([op cursor] && (_state & ModeNormal) == ModeNormal) ? bg : fg);
CGContextSetTextDrawingMode(ctx, kCGTextFill);

CGContextTranslateCTM(ctx, o.x, o.y);
Expand Down Expand Up @@ -730,6 +746,7 @@ - (void)flushDrawOps:(NSString *)character charWidth:(int)width
repeats:YES];

DrawTextOp *op = [DrawTextOp opWithText:character x:0 y:0 attrs:attrs];
[op setCursor:true];
CGSize cellSize = nmux_CellSize();
CGPoint pos = CGPointMake(cursorPos.x * cellSize.width,
(cursorPos.y ) * cellSize.height);
Expand Down

0 comments on commit 47bbede

Please sign in to comment.