2016-01-27 22:35:58 +00:00
|
|
|
//
|
|
|
|
|
// Rectangle drawing routines for the Fast Light Tool Kit (FLTK).
|
|
|
|
|
//
|
2018-01-31 21:17:17 +00:00
|
|
|
// Copyright 1998-2018 by Bill Spitzak and others.
|
2016-01-27 22:35:58 +00:00
|
|
|
//
|
|
|
|
|
// This library is free software. Distribution and use rights are outlined in
|
|
|
|
|
// the file "COPYING" which should have been included with this file. If this
|
|
|
|
|
// file is missing or damaged, see the license at:
|
|
|
|
|
//
|
2020-07-01 16:03:10 +00:00
|
|
|
// https://www.fltk.org/COPYING.php
|
2016-01-27 22:35:58 +00:00
|
|
|
//
|
2020-07-01 16:03:10 +00:00
|
|
|
// Please see the following page on how to report bugs and issues:
|
2016-01-27 22:35:58 +00:00
|
|
|
//
|
2020-07-01 16:03:10 +00:00
|
|
|
// https://www.fltk.org/bugs.php
|
2016-01-27 22:35:58 +00:00
|
|
|
//
|
|
|
|
|
|
2021-02-16 10:08:30 +00:00
|
|
|
#include <config.h>
|
2016-03-24 22:26:13 +00:00
|
|
|
#include "Fl_Quartz_Graphics_Driver.H"
|
2016-09-23 07:47:57 +00:00
|
|
|
#include "../Darwin/Fl_Darwin_System_Driver.H"
|
2018-01-31 21:17:17 +00:00
|
|
|
#include <FL/platform.H>
|
2017-12-26 16:07:51 +00:00
|
|
|
#include <FL/fl_draw.H>
|
|
|
|
|
#include <FL/Fl_Image_Surface.H>
|
2016-01-27 22:35:58 +00:00
|
|
|
|
2016-10-14 09:17:15 +00:00
|
|
|
#if HAS_ATSU && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
|
2016-10-10 21:19:39 +00:00
|
|
|
Fl_Quartz_Graphics_Driver::pter_to_draw_member Fl_Quartz_Graphics_Driver::CoreText_or_ATSU_draw;
|
|
|
|
|
Fl_Quartz_Graphics_Driver::pter_to_width_member Fl_Quartz_Graphics_Driver::CoreText_or_ATSU_width;
|
|
|
|
|
|
|
|
|
|
int Fl_Quartz_Graphics_Driver::CoreText_or_ATSU = 0;
|
|
|
|
|
|
|
|
|
|
void Fl_Quartz_Graphics_Driver::init_CoreText_or_ATSU()
|
|
|
|
|
{
|
|
|
|
|
if (Fl_Darwin_System_Driver::calc_mac_os_version() < 100500) {
|
|
|
|
|
// before Mac OS 10.5, only ATSU is available
|
|
|
|
|
CoreText_or_ATSU = use_ATSU;
|
|
|
|
|
CoreText_or_ATSU_draw = &Fl_Quartz_Graphics_Driver::draw_ATSU;
|
|
|
|
|
CoreText_or_ATSU_width = &Fl_Quartz_Graphics_Driver::width_ATSU;
|
|
|
|
|
} else {
|
|
|
|
|
CoreText_or_ATSU = use_CoreText;
|
|
|
|
|
CoreText_or_ATSU_draw = &Fl_Quartz_Graphics_Driver::draw_CoreText;
|
2020-07-01 16:03:10 +00:00
|
|
|
CoreText_or_ATSU_width = &Fl_Quartz_Graphics_Driver::width_CoreText;
|
2016-10-10 21:19:39 +00:00
|
|
|
}
|
|
|
|
|
}
|
2016-10-14 09:17:15 +00:00
|
|
|
#endif
|
2016-10-10 21:19:39 +00:00
|
|
|
|
2016-02-09 12:33:49 +00:00
|
|
|
/*
|
2016-04-09 10:42:17 +00:00
|
|
|
* By linking this module, the following static method will instantiate the
|
2016-02-09 12:33:49 +00:00
|
|
|
* OS X Quartz Graphics driver as the main display driver.
|
|
|
|
|
*/
|
|
|
|
|
Fl_Graphics_Driver *Fl_Graphics_Driver::newMainGraphicsDriver()
|
|
|
|
|
{
|
2016-10-10 21:19:39 +00:00
|
|
|
return new Fl_Quartz_Graphics_Driver();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Fl_Quartz_Graphics_Driver::Fl_Quartz_Graphics_Driver() : Fl_Graphics_Driver(), gc_(NULL), p_size(0), p(NULL) {
|
|
|
|
|
quartz_line_width_ = 1.f;
|
|
|
|
|
quartz_line_cap_ = kCGLineCapButt;
|
|
|
|
|
quartz_line_join_ = kCGLineJoinMiter;
|
|
|
|
|
quartz_line_pattern = 0;
|
|
|
|
|
quartz_line_pattern_size = 0;
|
|
|
|
|
high_resolution_ = false;
|
2016-10-14 09:17:15 +00:00
|
|
|
#if HAS_ATSU && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
|
2016-10-10 21:19:39 +00:00
|
|
|
if (!CoreText_or_ATSU) init_CoreText_or_ATSU();
|
2016-10-14 09:17:15 +00:00
|
|
|
#endif
|
2016-02-09 12:33:49 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-09 21:54:38 +00:00
|
|
|
char Fl_Quartz_Graphics_Driver::can_do_alpha_blending() {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void bmProviderRelease (void *src, const void *data, size_t size) {
|
|
|
|
|
CFIndex count = CFGetRetainCount(src);
|
|
|
|
|
CFRelease(src);
|
|
|
|
|
if(count == 1) free((void*)data);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-17 14:45:25 +00:00
|
|
|
/* Reference to the current CGContext
|
|
|
|
|
For back-compatibility only. The preferred procedure to get this reference is
|
|
|
|
|
Fl_Surface_Device::surface()->driver()->gc().
|
|
|
|
|
*/
|
|
|
|
|
CGContextRef fl_gc = 0;
|
|
|
|
|
|
|
|
|
|
void Fl_Quartz_Graphics_Driver::global_gc()
|
|
|
|
|
{
|
|
|
|
|
fl_gc = (CGContextRef)gc();
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 16:07:51 +00:00
|
|
|
void Fl_Quartz_Graphics_Driver::copy_offscreen(int x, int y, int w, int h, Fl_Offscreen osrc, int srcx, int srcy) {
|
|
|
|
|
// draw portion srcx,srcy,w,h of osrc to position x,y (top-left) of the graphics driver's surface
|
2016-02-09 21:54:38 +00:00
|
|
|
CGContextRef src = (CGContextRef)osrc;
|
|
|
|
|
void *data = CGBitmapContextGetData(src);
|
|
|
|
|
int sw = CGBitmapContextGetWidth(src);
|
|
|
|
|
int sh = CGBitmapContextGetHeight(src);
|
2020-01-15 17:18:59 +00:00
|
|
|
CGImageRef img;
|
|
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
|
|
|
|
|
if (fl_mac_os_version >= 100400) img = CGBitmapContextCreateImage(src); // requires 10.4
|
|
|
|
|
else
|
|
|
|
|
#endif
|
|
|
|
|
{
|
|
|
|
|
CGImageAlphaInfo alpha = CGBitmapContextGetAlphaInfo(src);
|
|
|
|
|
CGColorSpaceRef lut = CGColorSpaceCreateDeviceRGB();
|
|
|
|
|
// when output goes to a Quartz printercontext, release of the bitmap must be
|
|
|
|
|
// delayed after the end of the printed page
|
|
|
|
|
CFRetain(src);
|
|
|
|
|
CGDataProviderRef src_bytes = CGDataProviderCreateWithData( src, data, sw*sh*4, bmProviderRelease);
|
|
|
|
|
img = CGImageCreate( sw, sh, 8, 4*8, 4*sw, lut, alpha,
|
|
|
|
|
src_bytes, 0L, false, kCGRenderingIntentDefault);
|
|
|
|
|
CGDataProviderRelease(src_bytes);
|
|
|
|
|
CGColorSpaceRelease(lut);
|
|
|
|
|
}
|
2018-04-19 10:39:46 +00:00
|
|
|
float s = scale();
|
2017-12-26 16:07:51 +00:00
|
|
|
Fl_Surface_Device *current = Fl_Surface_Device::surface();
|
|
|
|
|
// test whether osrc was created by fl_create_offscreen()
|
|
|
|
|
fl_begin_offscreen(osrc); // does nothing if osrc was not created by fl_create_offscreen()
|
|
|
|
|
if (current != Fl_Surface_Device::surface()) { // osrc was created by fl_create_offscreen()
|
|
|
|
|
Fl_Image_Surface *imgs = (Fl_Image_Surface*)Fl_Surface_Device::surface();
|
|
|
|
|
int pw, ph;
|
|
|
|
|
imgs->printable_rect(&pw, &ph);
|
|
|
|
|
s = sw / float(pw);
|
|
|
|
|
fl_end_offscreen();
|
|
|
|
|
}
|
|
|
|
|
draw_CGImage(img, x, y, w, h, srcx, srcy, sw/s, sh/s);
|
|
|
|
|
CGImageRelease(img);
|
2016-02-09 21:54:38 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-30 20:16:40 +00:00
|
|
|
// so a CGRect matches exactly what is denoted x,y,w,h for clipping purposes
|
|
|
|
|
CGRect Fl_Quartz_Graphics_Driver::fl_cgrectmake_cocoa(int x, int y, int w, int h) {
|
|
|
|
|
return CGRectMake(x - 0.5, y - 0.5, w, h);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-17 15:36:23 +00:00
|
|
|
void Fl_Quartz_Graphics_Driver::add_rectangle_to_region(Fl_Region r, int X, int Y, int W, int H) {
|
2016-03-30 20:16:40 +00:00
|
|
|
CGRect arg = Fl_Quartz_Graphics_Driver::fl_cgrectmake_cocoa(X, Y, W, H);
|
2016-03-24 22:26:13 +00:00
|
|
|
int j; // don't add a rectangle totally inside the Fl_Region
|
|
|
|
|
for(j = 0; j < r->count; j++) {
|
|
|
|
|
if(CGRectContainsRect(r->rects[j], arg)) break;
|
|
|
|
|
}
|
|
|
|
|
if( j >= r->count) {
|
|
|
|
|
r->rects = (CGRect*)realloc(r->rects, (++(r->count)) * sizeof(CGRect));
|
|
|
|
|
r->rects[r->count - 1] = arg;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-17 15:36:23 +00:00
|
|
|
Fl_Region Fl_Quartz_Graphics_Driver::XRectangleRegion(int x, int y, int w, int h) {
|
2016-03-30 20:16:40 +00:00
|
|
|
Fl_Region R = (Fl_Region)malloc(sizeof(*R));
|
|
|
|
|
R->count = 1;
|
|
|
|
|
R->rects = (CGRect *)malloc(sizeof(CGRect));
|
|
|
|
|
*(R->rects) = Fl_Quartz_Graphics_Driver::fl_cgrectmake_cocoa(x, y, w, h);
|
|
|
|
|
return R;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-17 15:36:23 +00:00
|
|
|
void Fl_Quartz_Graphics_Driver::XDestroyRegion(Fl_Region r) {
|
2016-03-30 20:16:40 +00:00
|
|
|
if(r) {
|
|
|
|
|
free(r->rects);
|
|
|
|
|
free(r);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-30 15:41:22 +00:00
|
|
|
|
2020-11-12 06:46:00 +00:00
|
|
|
void Fl_Quartz_Graphics_Driver::cache_size(Fl_Image *img, int &width, int &height) {
|
2020-07-30 15:41:22 +00:00
|
|
|
width *= 2 * scale();
|
|
|
|
|
height *= 2 * scale();
|
|
|
|
|
}
|