mirror of
https://github.com/macvim-dev/macvim.git
synced 2026-06-11 15:37:29 +02:00
Draw modeless selection
This commit is contained in:
@@ -96,6 +96,8 @@ enum {
|
||||
- (void)clearAll;
|
||||
- (void)drawInsertionPointAtRow:(int)row column:(int)col shape:(int)shape
|
||||
fraction:(int)percent color:(NSColor *)color;
|
||||
- (void)drawInvertedRectAtRow:(int)row column:(int)col numRows:(int)nrows
|
||||
numColumns:(int)ncols;
|
||||
@end
|
||||
|
||||
|
||||
@@ -599,6 +601,19 @@ enum {
|
||||
[self drawInsertionPointAtRow:row column:col shape:shape
|
||||
fraction:percent
|
||||
color:[NSColor colorWithRgbInt:color]];
|
||||
} else if (DrawInvertedRectDrawType == type) {
|
||||
int row = *((int*)bytes); bytes += sizeof(int);
|
||||
int col = *((int*)bytes); bytes += sizeof(int);
|
||||
int nr = *((int*)bytes); bytes += sizeof(int);
|
||||
int nc = *((int*)bytes); bytes += sizeof(int);
|
||||
/*int invert = *((int*)bytes);*/ bytes += sizeof(int);
|
||||
|
||||
#if MM_DEBUG_DRAWING
|
||||
NSLog(@" Draw inverted rect: row=%d col=%d nrows=%d ncols=%d",
|
||||
row, col, nr, nc);
|
||||
#endif
|
||||
[self drawInvertedRectAtRow:row column:col numRows:nr
|
||||
numColumns:nc];
|
||||
} else if (SetCursorPosDrawType == type) {
|
||||
// TODO: This is used for Voice Over support in MMTextView,
|
||||
// MMAtsuiTextView currently does not support Voice Over.
|
||||
@@ -1133,4 +1148,20 @@ enum {
|
||||
}
|
||||
}
|
||||
|
||||
- (void)drawInvertedRectAtRow:(int)row column:(int)col numRows:(int)nrows
|
||||
numColumns:(int)ncols
|
||||
{
|
||||
// TODO: THIS CODE HAS NOT BEEN TESTED!
|
||||
CGContextRef cgctx = [[NSGraphicsContext currentContext] graphicsPort];
|
||||
CGContextSaveGState(cgctx);
|
||||
CGContextSetBlendMode(cgctx, kCGBlendModeDifference);
|
||||
CGContextSetRGBFillColor(cgctx, 1.0, 1.0, 1.0, 1.0);
|
||||
|
||||
CGRect rect = { col * cellSize.width, row * cellSize.height,
|
||||
ncols * cellSize.width, nrows * cellSize.height };
|
||||
CGContextFillRect(cgctx, rect);
|
||||
|
||||
CGContextRestoreGState(cgctx);
|
||||
}
|
||||
|
||||
@end // MMAtsuiTextView (Drawing)
|
||||
|
||||
@@ -71,6 +71,8 @@
|
||||
scrollBottom:(int)bottom left:(int)left right:(int)right;
|
||||
- (void)drawCursorAtRow:(int)row column:(int)col shape:(int)shape
|
||||
fraction:(int)percent color:(int)color;
|
||||
- (void)drawInvertedRectAtRow:(int)row column:(int)col numRows:(int)nr
|
||||
numColumns:(int)nc invert:(int)invert;
|
||||
- (void)update;
|
||||
- (void)flushQueue:(BOOL)force;
|
||||
- (BOOL)waitForInput:(int)milliseconds;
|
||||
|
||||
@@ -429,6 +429,19 @@ static NSString *MMSymlinkWarningString =
|
||||
[drawData appendBytes:&percent length:sizeof(int)];
|
||||
}
|
||||
|
||||
- (void)drawInvertedRectAtRow:(int)row column:(int)col numRows:(int)nr
|
||||
numColumns:(int)nc invert:(int)invert
|
||||
{
|
||||
int type = DrawInvertedRectDrawType;
|
||||
[drawData appendBytes:&type length:sizeof(int)];
|
||||
|
||||
[drawData appendBytes:&row length:sizeof(int)];
|
||||
[drawData appendBytes:&col length:sizeof(int)];
|
||||
[drawData appendBytes:&nr length:sizeof(int)];
|
||||
[drawData appendBytes:&nc length:sizeof(int)];
|
||||
[drawData appendBytes:&invert length:sizeof(int)];
|
||||
}
|
||||
|
||||
- (void)update
|
||||
{
|
||||
// Tend to the run loop, returning immediately if there are no events
|
||||
|
||||
@@ -29,14 +29,14 @@
|
||||
int preEditColumn;
|
||||
int mouseShape;
|
||||
BOOL antialias;
|
||||
NSRect *invertRects;
|
||||
int numInvertRects;
|
||||
}
|
||||
|
||||
- (id)initWithFrame:(NSRect)frame;
|
||||
|
||||
- (void)setShouldDrawInsertionPoint:(BOOL)on;
|
||||
- (void)setPreEditRow:(int)row column:(int)col;
|
||||
- (void)drawInsertionPointAtRow:(int)row column:(int)col shape:(int)shape
|
||||
fraction:(int)percent color:(NSColor *)color;
|
||||
- (void)hideMarkedTextField;
|
||||
- (void)performBatchDrawWithData:(NSData *)data;
|
||||
- (void)setMouseShape:(int)shape;
|
||||
|
||||
+102
-17
@@ -50,6 +50,8 @@ enum {
|
||||
- (void)setCursor;
|
||||
- (BOOL)convertPoint:(NSPoint)point toRow:(int *)row column:(int *)column;
|
||||
- (BOOL)convertRow:(int)row column:(int)column toPoint:(NSPoint *)point;
|
||||
- (BOOL)convertRow:(int)row column:(int)column numRows:(int)nr
|
||||
numColumns:(int)nc toRect:(NSRect *)rect;
|
||||
- (NSRect)trackingRect;
|
||||
- (void)dispatchKeyEvent:(NSEvent *)event;
|
||||
- (MMWindowController *)windowController;
|
||||
@@ -58,6 +60,10 @@ enum {
|
||||
- (void)dragTimerFired:(NSTimer *)timer;
|
||||
- (void)sendKeyDown:(const char *)chars length:(int)len modifiers:(int)flags;
|
||||
- (void)hideMouseCursor;
|
||||
- (void)drawInsertionPointAtRow:(int)row column:(int)col shape:(int)shape
|
||||
fraction:(int)percent color:(NSColor *)color;
|
||||
- (void)drawInvertedRectAtRow:(int)row column:(int)col numRows:(int)nrows
|
||||
numColumns:(int)ncols invert:(int)invert;
|
||||
@end
|
||||
|
||||
|
||||
@@ -130,6 +136,12 @@ enum {
|
||||
markedTextField = nil;
|
||||
}
|
||||
|
||||
if (invertRects) {
|
||||
free(invertRects);
|
||||
invertRects = NULL;
|
||||
numInvertRects = 0;
|
||||
}
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@@ -153,23 +165,6 @@ enum {
|
||||
preEditColumn = col;
|
||||
}
|
||||
|
||||
- (void)drawInsertionPointAtRow:(int)row column:(int)col shape:(int)shape
|
||||
fraction:(int)percent color:(NSColor *)color
|
||||
{
|
||||
//NSLog(@"drawInsertionPointAtRow:%d column:%d shape:%d color:%@",
|
||||
// row, col, shape, color);
|
||||
|
||||
// This only stores where to draw the insertion point, the actual drawing
|
||||
// is done in drawRect:.
|
||||
shouldDrawInsertionPoint = YES;
|
||||
insertionPointRow = row;
|
||||
insertionPointColumn = col;
|
||||
insertionPointShape = shape;
|
||||
insertionPointFraction = percent;
|
||||
|
||||
[self setInsertionPointColor:color];
|
||||
}
|
||||
|
||||
- (void)hideMarkedTextField
|
||||
{
|
||||
if (markedTextField) {
|
||||
@@ -300,6 +295,19 @@ enum {
|
||||
[self drawInsertionPointAtRow:row column:col shape:shape
|
||||
fraction:percent
|
||||
color:[NSColor colorWithRgbInt:color]];
|
||||
} else if (DrawInvertedRectDrawType == type) {
|
||||
int row = *((int*)bytes); bytes += sizeof(int);
|
||||
int col = *((int*)bytes); bytes += sizeof(int);
|
||||
int nr = *((int*)bytes); bytes += sizeof(int);
|
||||
int nc = *((int*)bytes); bytes += sizeof(int);
|
||||
int invert = *((int*)bytes); bytes += sizeof(int);
|
||||
|
||||
#if MM_DEBUG_DRAWING
|
||||
NSLog(@" Draw inverted rect: row=%d col=%d nrows=%d ncols=%d",
|
||||
row, col, nr, nc);
|
||||
#endif
|
||||
[self drawInvertedRectAtRow:row column:col numRows:nr numColumns:nc
|
||||
invert:invert];
|
||||
} else if (SetCursorPosDrawType == type) {
|
||||
cursorRow = *((int*)bytes); bytes += sizeof(int);
|
||||
cursorCol = *((int*)bytes); bytes += sizeof(int);
|
||||
@@ -452,6 +460,24 @@ enum {
|
||||
|
||||
[super drawRect:rect];
|
||||
|
||||
if (invertRects) {
|
||||
CGContextRef cgctx = (CGContextRef)[context graphicsPort];
|
||||
CGContextSaveGState(cgctx);
|
||||
CGContextSetBlendMode(cgctx, kCGBlendModeDifference);
|
||||
CGContextSetRGBFillColor(cgctx, 1.0, 1.0, 1.0, 1.0);
|
||||
|
||||
int i;
|
||||
CGRect *rect = (CGRect*)invertRects;
|
||||
for (i = 0; i < numInvertRects; ++i)
|
||||
CGContextFillRect(cgctx, rect[i]);
|
||||
|
||||
CGContextRestoreGState(cgctx);
|
||||
|
||||
free(invertRects);
|
||||
invertRects = NULL;
|
||||
numInvertRects = 0;
|
||||
}
|
||||
|
||||
if (shouldDrawInsertionPoint) {
|
||||
MMTextStorage *ts = (MMTextStorage*)[self textStorage];
|
||||
|
||||
@@ -1242,6 +1268,23 @@ enum {
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)convertRow:(int)row column:(int)column numRows:(int)nr
|
||||
numColumns:(int)nc toRect:(NSRect *)rect
|
||||
{
|
||||
MMTextStorage *ts = (MMTextStorage*)[self textStorage];
|
||||
NSSize cellSize = [ts cellSize];
|
||||
if (!(rect && cellSize.width > 0 && cellSize.height > 0))
|
||||
return NO;
|
||||
|
||||
rect->origin = [self textContainerOrigin];
|
||||
rect->origin.x += column * cellSize.width;
|
||||
rect->origin.y += row * cellSize.height;
|
||||
rect->size.width = cellSize.width * nc;
|
||||
rect->size.height = cellSize.height * nr;
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (NSRect)trackingRect
|
||||
{
|
||||
NSRect rect = [self frame];
|
||||
@@ -1392,4 +1435,46 @@ enum {
|
||||
[NSCursor setHiddenUntilMouseMoves:YES];
|
||||
}
|
||||
|
||||
- (void)drawInsertionPointAtRow:(int)row column:(int)col shape:(int)shape
|
||||
fraction:(int)percent color:(NSColor *)color
|
||||
{
|
||||
//NSLog(@"drawInsertionPointAtRow:%d column:%d shape:%d color:%@",
|
||||
// row, col, shape, color);
|
||||
|
||||
// This only stores where to draw the insertion point, the actual drawing
|
||||
// is done in drawRect:.
|
||||
shouldDrawInsertionPoint = YES;
|
||||
insertionPointRow = row;
|
||||
insertionPointColumn = col;
|
||||
insertionPointShape = shape;
|
||||
insertionPointFraction = percent;
|
||||
|
||||
[self setInsertionPointColor:color];
|
||||
}
|
||||
|
||||
- (void)drawInvertedRectAtRow:(int)row column:(int)col numRows:(int)nrows
|
||||
numColumns:(int)ncols invert:(int)invert
|
||||
{
|
||||
if (invert) {
|
||||
// The result should be inverted.
|
||||
int n = numInvertRects++;
|
||||
invertRects = reallocf(invertRects,
|
||||
numInvertRects*sizeof(NSRect));
|
||||
if (NULL != invertRects) {
|
||||
[self convertRow:row column:col numRows:nrows numColumns:ncols
|
||||
toRect:&invertRects[n]];
|
||||
[self setNeedsDisplayInRect:invertRects[n]];
|
||||
} else {
|
||||
n = numInvertRects = 0;
|
||||
}
|
||||
} else {
|
||||
// The result should look normal; all we need to do is to mark
|
||||
// the rect for redrawing and Cocoa will redraw the text.
|
||||
NSRect rect;
|
||||
[self convertRow:row column:col numRows:nrows numColumns:ncols
|
||||
toRect:&rect];
|
||||
[self setNeedsDisplayInRect:rect];
|
||||
}
|
||||
}
|
||||
|
||||
@end // MMTextView (Private)
|
||||
|
||||
@@ -176,6 +176,7 @@ enum {
|
||||
InsertLinesDrawType,
|
||||
DrawCursorDrawType,
|
||||
SetCursorPosDrawType,
|
||||
DrawInvertedRectDrawType,
|
||||
};
|
||||
|
||||
enum {
|
||||
|
||||
+11
-9
@@ -426,6 +426,17 @@ gui_mch_new_colors(void)
|
||||
foreground:gui.def_norm_pixel];
|
||||
}
|
||||
|
||||
/*
|
||||
* Invert a rectangle from row r, column c, for nr rows and nc columns.
|
||||
*/
|
||||
void
|
||||
gui_mch_invert_rectangle(int r, int c, int nr, int nc, int invert)
|
||||
{
|
||||
[[MMBackend sharedInstance] drawInvertedRectAtRow:r column:c numRows:nr
|
||||
numColumns:nc invert:invert];
|
||||
}
|
||||
|
||||
|
||||
|
||||
// -- Tabline ---------------------------------------------------------------
|
||||
|
||||
@@ -1454,15 +1465,6 @@ gui_mch_iconify(void)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Invert a rectangle from row r, column c, for nr rows and nc columns.
|
||||
*/
|
||||
void
|
||||
gui_mch_invert_rectangle(int r, int c, int nr, int nc)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
#if defined(FEAT_EVAL) || defined(PROTO)
|
||||
/*
|
||||
* Bring the Vim window to the foreground.
|
||||
|
||||
@@ -124,7 +124,7 @@ gui_mch_haskey(char_u *name);
|
||||
void
|
||||
gui_mch_iconify(void);
|
||||
void
|
||||
gui_mch_invert_rectangle(int r, int c, int nr, int nc);
|
||||
gui_mch_invert_rectangle(int r, int c, int nr, int nc, int invert);
|
||||
void
|
||||
gui_mch_new_colors(void);
|
||||
void
|
||||
|
||||
@@ -1126,7 +1126,11 @@ clip_invert_rectangle(row, col, height, width, invert)
|
||||
{
|
||||
#ifdef FEAT_GUI
|
||||
if (gui.in_use)
|
||||
# ifdef FEAT_GUI_MACVIM
|
||||
gui_mch_invert_rectangle(row, col, height, width, invert);
|
||||
# else
|
||||
gui_mch_invert_rectangle(row, col, height, width);
|
||||
#endif
|
||||
else
|
||||
#endif
|
||||
screen_draw_rectangle(row, col, height, width, invert);
|
||||
|
||||
Reference in New Issue
Block a user