#define GC_BACK_COLOR(gc) (&(gc)->back_color)
#define GC_FONT(gc) ((gc)->xgcv.font)
#define FRAME_NORMAL_GC(f) ((f)->output_data.mac->normal_gc)
+#define CG_SET_FILL_COLOR(context, color) \
+ CGContextSetRGBFillColor (context, \
+ RED_FROM_ULONG (color) / 255.0f, \
+ GREEN_FROM_ULONG (color) / 255.0f, \
+ BLUE_FROM_ULONG (color) / 255.0f, 1.0f)
+#define CG_SET_STROKE_COLOR(context, color) \
+ CGContextSetRGBStrokeColor (context, \
+ RED_FROM_ULONG (color) / 255.0f, \
+ GREEN_FROM_ULONG (color) / 255.0f, \
+ BLUE_FROM_ULONG (color) / 255.0f, 1.0f)
+#if USE_CG_DRAWING
+#define FRAME_CG_CONTEXT(f) ((f)->output_data.mac->cg_context)
+
+static CGContextRef
+mac_begin_cg_clip (f, gc)
+ struct frame *f;
+ GC gc;
+{
+ CGContextRef context = FRAME_CG_CONTEXT (f);
+
+ if (!context)
+ {
+ QDBeginCGContext (GetWindowPort (FRAME_MAC_WINDOW (f)), &context);
+ FRAME_CG_CONTEXT (f) = context;
+ }
+
+ CGContextSaveGState (context);
+ CGContextTranslateCTM (context, 0, FRAME_PIXEL_HEIGHT (f));
+ CGContextScaleCTM (context, 1, -1);
+ if (gc && gc->n_clip_rects)
+ CGContextClipToRects (context, gc->clip_rects, gc->n_clip_rects);
+
+ return context;
+}
+
+static void
+mac_end_cg_clip (f)
+ struct frame *f;
+{
+ CGContextRestoreGState (FRAME_CG_CONTEXT (f));
+}
+
+void
+mac_prepare_for_quickdraw (f)
+ struct frame *f;
+{
+ if (f == NULL)
+ {
+ Lisp_Object rest, frame;
+ FOR_EACH_FRAME (rest, frame)
+ if (FRAME_MAC_P (XFRAME (frame)))
+ mac_prepare_for_quickdraw (XFRAME (frame));
+ }
+ else
+ {
+ CGContextRef context = FRAME_CG_CONTEXT (f);
+
+ if (context)
+ {
+ CGContextSynchronize (context);
+ QDEndCGContext (GetWindowPort (FRAME_MAC_WINDOW (f)),
+ &FRAME_CG_CONTEXT (f));
+ }
+ }
+}
+#endif
static RgnHandle saved_port_clip_region = NULL;
GC gc;
int x1, y1, x2, y2;
{
+#if USE_CG_DRAWING
+ CGContextRef context;
+
+ context = mac_begin_cg_clip (f, gc);
+ CG_SET_STROKE_COLOR (context, gc->xgcv.foreground);
+ CGContextBeginPath (context);
+ CGContextMoveToPoint (context, x1 + 0.5f, y1 + 0.5f);
+ CGContextAddLineToPoint (context, x2 + 0.5f, y2 + 0.5f);
+ CGContextClosePath (context);
+ CGContextStrokePath (context);
+ mac_end_cg_clip (f);
+#else
SetPortWindowPort (FRAME_MAC_WINDOW (f));
RGBForeColor (GC_FORE_COLOR (gc));
MoveTo (x1, y1);
LineTo (x2, y2);
mac_end_clip (gc);
+#endif
}
void
int x, y;
unsigned int width, height;
{
+#if USE_CG_DRAWING
+ CGContextRef context;
+
+ context = mac_begin_cg_clip (f, gc);
+ CG_SET_FILL_COLOR (context, gc->xgcv.background);
+ CGContextFillRect (context, CGRectMake (x, y, width, height));
+ mac_end_cg_clip (f);
+#else
Rect r;
SetPortWindowPort (FRAME_MAC_WINDOW (f));
mac_end_clip (gc);
RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f)));
+#endif
}
mac_clear_window (f)
struct frame *f;
{
+#if USE_CG_DRAWING
+ CGContextRef context;
+ GC gc = FRAME_NORMAL_GC (f);
+
+ context = mac_begin_cg_clip (f, NULL);
+ CG_SET_FILL_COLOR (context, gc->xgcv.background);
+ CGContextFillRect (context, CGRectMake (0, 0, FRAME_PIXEL_WIDTH (f),
+ FRAME_PIXEL_HEIGHT (f)));
+ mac_end_cg_clip (f);
+#else
SetPortWindowPort (FRAME_MAC_WINDOW (f));
RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f)));
#else /* not TARGET_API_MAC_CARBON */
EraseRect (&(FRAME_MAC_WINDOW (f)->portRect));
#endif /* not TARGET_API_MAC_CARBON */
+#endif
}
bitmap.baseAddr = (char *)bits;
SetRect (&(bitmap.bounds), 0, 0, width, height);
+#if USE_CG_DRAWING
+ mac_prepare_for_quickdraw (f);
+#endif
SetPortWindowPort (FRAME_MAC_WINDOW (f));
RGBForeColor (GC_FORE_COLOR (gc));
int x, y;
unsigned int width, height;
{
+#if USE_CG_DRAWING
+ CGContextRef context;
+
+ context = mac_begin_cg_clip (f, gc);
+ CG_SET_FILL_COLOR (context, gc->xgcv.foreground);
+ CGContextFillRect (context, CGRectMake (x, y, width, height));
+ mac_end_cg_clip (f);
+#else
Rect r;
SetPortWindowPort (FRAME_MAC_WINDOW (f));
mac_begin_clip (gc);
PaintRect (&r); /* using foreground color of gc */
mac_end_clip (gc);
+#endif
}
int x, y;
unsigned int width, height;
{
+#if USE_CG_DRAWING
+ CGContextRef context;
+
+ context = mac_begin_cg_clip (f, gc);
+ CG_SET_STROKE_COLOR (context, gc->xgcv.foreground);
+ CGContextStrokeRect (context,
+ CGRectMake (x + 0.5f, y + 0.5f, width, height));
+ mac_end_cg_clip (f);
+#else
Rect r;
SetPortWindowPort (FRAME_MAC_WINDOW (f));
RGBForeColor (GC_FORE_COLOR (gc));
- SetRect (&r, x, y, x + width, y + height);
+ SetRect (&r, x, y, x + width + 1, y + height + 1);
mac_begin_clip (gc);
FrameRect (&r); /* using foreground color of gc */
mac_end_clip (gc);
+#endif
}
{
Rect r;
+#if USE_CG_DRAWING
+ mac_prepare_for_quickdraw (f);
+#endif
SetPortWindowPort (FRAME_MAC_WINDOW (f));
SetRect (&r, x, y, x + width, y + height);
#ifdef MAC_OSX
if (!mac_use_core_graphics)
{
+#endif
+#if USE_CG_DRAWING
+ mac_prepare_for_quickdraw (f);
#endif
mac_begin_clip (gc);
RGBForeColor (GC_FORE_COLOR (gc));
ByteCount sizes[] = {sizeof (CGContextRef)};
ATSUAttributeValuePtr values[] = {&context};
+#if USE_CG_DRAWING
+ context = mac_begin_cg_clip (f, gc);
+#else
GetPort (&port);
QDBeginCGContext (port, &context);
if (gc->n_clip_rects || bg_width)
if (gc->n_clip_rects)
CGContextClipToRects (context, gc->clip_rects,
gc->n_clip_rects);
+#endif
if (bg_width)
{
- CGContextSetRGBFillColor
- (context,
- RED_FROM_ULONG (gc->xgcv.background) / 255.0f,
- GREEN_FROM_ULONG (gc->xgcv.background) / 255.0f,
- BLUE_FROM_ULONG (gc->xgcv.background) / 255.0f,
- 1.0);
+ CG_SET_FILL_COLOR (context, gc->xgcv.background);
CGContextFillRect
(context,
CGRectMake (x, y - FONT_BASE (GC_FONT (gc)),
}
CGContextScaleCTM (context, 1, -1);
CGContextTranslateCTM (context, 0, -port_height);
+#if !USE_CG_DRAWING
}
- CGContextSetRGBFillColor
- (context,
- RED_FROM_ULONG (gc->xgcv.foreground) / 255.0f,
- GREEN_FROM_ULONG (gc->xgcv.foreground) / 255.0f,
- BLUE_FROM_ULONG (gc->xgcv.foreground) / 255.0f,
- 1.0);
+#endif
+ CG_SET_FILL_COLOR (context, gc->xgcv.foreground);
err = ATSUSetLayoutControls (text_layout,
sizeof (tags) / sizeof (tags[0]),
tags, sizes, values);
ATSUDrawText (text_layout,
kATSUFromTextBeginning, kATSUToTextEnd,
Long2Fix (x), Long2Fix (port_height - y));
+#if USE_CG_DRAWING
+ mac_end_cg_clip (f);
+ context = NULL;
+#else
CGContextSynchronize (context);
QDEndCGContext (port, &context);
+#endif
#if 0
/* This doesn't work on Mac OS X 10.1. */
ATSUClearLayoutControls (text_layout,
if (mac_use_core_graphics)
savedFlags = SwapQDTextFlags (kQDUseCGTextRendering);
+#endif
+#if USE_CG_DRAWING
+ mac_prepare_for_quickdraw (f);
#endif
mac_begin_clip (gc);
RGBForeColor (GC_FORE_COLOR (gc));
buf++;
}
+#if USE_CG_DRAWING
+ context = mac_begin_cg_clip (f, gc);
+#else
QDBeginCGContext (port, &context);
if (gc->n_clip_rects || bg_width)
{
CGContextScaleCTM (context, 1, -1);
if (gc->n_clip_rects)
CGContextClipToRects (context, gc->clip_rects, gc->n_clip_rects);
+#endif
if (bg_width)
{
- CGContextSetRGBFillColor
- (context,
- RED_FROM_ULONG (gc->xgcv.background) / 255.0f,
- GREEN_FROM_ULONG (gc->xgcv.background) / 255.0f,
- BLUE_FROM_ULONG (gc->xgcv.background) / 255.0f,
- 1.0);
+ CG_SET_FILL_COLOR (context, gc->xgcv.background);
CGContextFillRect
(context,
CGRectMake (gx, y - FONT_BASE (GC_FONT (gc)),
}
CGContextScaleCTM (context, 1, -1);
CGContextTranslateCTM (context, 0, -port_height);
+#if !USE_CG_DRAWING
}
- CGContextSetRGBFillColor (context,
- RED_FROM_ULONG (gc->xgcv.foreground) / 255.0f,
- GREEN_FROM_ULONG (gc->xgcv.foreground) / 255.0f,
- BLUE_FROM_ULONG (gc->xgcv.foreground) / 255.0f,
- 1.0);
+#endif
+ CG_SET_FILL_COLOR (context, gc->xgcv.foreground);
CGContextSetFont (context, GC_FONT (gc)->cg_font);
CGContextSetFontSize (context, GC_FONT (gc)->mac_fontsize);
if (GC_FONT (gc)->mac_fontsize <= cg_text_anti_aliasing_threshold)
gx += advances[i].width;
}
#endif
+#if USE_CG_DRAWING
+ mac_end_cg_clip (f);
+#else
CGContextSynchronize (context);
QDEndCGContext (port, &context);
+#endif
return 1;
}
{
Rect src_r, dest_r;
+#if USE_CG_DRAWING
+ mac_prepare_for_quickdraw (f);
+#endif
SetPortWindowPort (FRAME_MAC_WINDOW (f));
SetRect (&src_r, src_x, src_y, src_x + width, src_y + height);
{
Rect src_r, dest_r;
+#if USE_CG_DRAWING
+ mac_prepare_for_quickdraw (f);
+#endif
SetPortWindowPort (FRAME_MAC_WINDOW (f));
SetRect (&src_r, src_x, src_y, src_x + width, src_y + height);
RgnHandle dummy = NewRgn (); /* For avoiding update events. */
SetRect (&src_r, src_x, src_y, src_x + width, src_y + height);
+#if USE_CG_DRAWING
+ mac_prepare_for_quickdraw (f);
+#endif
ScrollWindowRect (FRAME_MAC_WINDOW (f),
&src_r, dest_x - src_x, dest_y - src_y,
kScrollWindowNoOptions, dummy);
{
#if TARGET_API_MAC_CARBON
BLOCK_INPUT;
+#if USE_CG_DRAWING
+ mac_prepare_for_quickdraw (f);
+#endif
if (f)
QDFlushPortBuffer (GetWindowPort (FRAME_MAC_WINDOW (f)), NULL);
else
{
struct glyph *g = s->first_glyph + i;
mac_draw_rectangle (s->f, s->gc, x, s->y,
- g->pixel_width, s->height);
+ g->pixel_width - 1, s->height - 1);
x += g->pixel_width;
}
}
{
if (s->gidx == 0)
mac_draw_rectangle (s->f, s->gc, x, s->y,
- s->width, s->height);
+ s->width - 1, s->height - 1);
}
else
{
int r = s->img->relief;
if (r < 0) r = -r;
mac_draw_rectangle (s->f, s->gc, x - r, y - r,
- s->slice.width + r*2,
- s->slice.height + r*2);
+ s->slice.width + r*2 - 1,
+ s->slice.height + r*2 - 1);
}
}
}
else
/* Draw a rectangle if image could not be loaded. */
mac_draw_rectangle (s->f, s->gc, x, y,
- s->slice.width, s->slice.height);
+ s->slice.width - 1, s->slice.height - 1);
}
r.right = left + width;
r.bottom = disp_top + disp_height;
+#if USE_CG_DRAWING
+ mac_prepare_for_quickdraw (f);
+#endif
#if TARGET_API_MAC_CARBON
ch = NewControl (FRAME_MAC_WINDOW (f), &r, "\p",
#if USE_TOOLKIT_SCROLL_BARS
BLOCK_INPUT;
+#if USE_CG_DRAWING
+ mac_prepare_for_quickdraw (f);
+#endif
/* Destroy the Mac scroll bar control */
DisposeControl (SCROLL_BAR_CONTROL_HANDLE (bar));
for them on the frame, we have to clear "under" them. */
mac_clear_area (f, left, top, width, height);
+#if USE_CG_DRAWING
+ mac_prepare_for_quickdraw (f);
+#endif
HideControl (ch);
MoveControl (ch, sb_left + VERTICAL_SCROLL_BAR_WIDTH_TRIM, disp_top);
SizeControl (ch, sb_width - VERTICAL_SCROLL_BAR_WIDTH_TRIM * 2,
/* Compute frame-relative coordinates for phys cursor. */
x = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x);
y = get_phys_cursor_geometry (w, row, cursor_glyph, &h);
- wd = w->phys_cursor_width + 1;
+ wd = w->phys_cursor_width;
/* The foreground of cursor_gc is typically the same as the normal
background color, which can cause the cursor box to be invisible. */
/* Set clipping, draw the rectangle, and reset clipping again. */
x_clip_to_row (w, row, TEXT_AREA, gc);
- mac_draw_rectangle (f, gc, x, y, wd, h);
+ mac_draw_rectangle (f, gc, x, y, wd, h - 1);
mac_reset_clip_rectangles (dpy, gc);
}
SizeWindow (FRAME_MAC_WINDOW (f), pixelwidth, pixelheight, 0);
#if TARGET_API_MAC_CARBON
if (f->output_data.mac->hourglass_control)
- MoveControl (f->output_data.mac->hourglass_control,
- pixelwidth - HOURGLASS_WIDTH, 0);
+ {
+#if USE_CG_DRAWING
+ mac_prepare_for_quickdraw (f);
+#endif
+ MoveControl (f->output_data.mac->hourglass_control,
+ pixelwidth - HOURGLASS_WIDTH, 0);
+ }
#endif
/* Now, strictly speaking, we can't be sure that this is accurate,
#if USE_CARBON_EVENTS
toolbox_dispatcher = GetEventDispatcherTarget ();
- while (!ReceiveNextEvent (0, NULL, kEventDurationNoWait,
+ while (
+#if USE_CG_DRAWING
+ mac_prepare_for_quickdraw (NULL),
+#endif
+ !ReceiveNextEvent (0, NULL, kEventDurationNoWait,
kEventRemoveFromQueue, &eventRef))
#else /* !USE_CARBON_EVENTS */
while (mac_wait_next_event (&er, 0, true))