Browse Source

Moved OS X code base to the more moder Cocoa toolkit thanks to the awesome work of Manolo Gouy (STR #2221). This is a big one! I tested all test applications under 32-bit autoconf and Xcode, and a few apps under 64bit intel. No PPC testing was done. Please verify this patch if you have the machine!

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6951 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
pull/49/head
Matthias Melcher 16 years ago
parent
commit
b2cffc688e
  1. 2
      CHANGES
  2. 69
      FL/mac.H
  3. 1
      configh.in
  4. 3
      configure.in
  5. 4484
      ide/Xcode3.1/FLTK.xcodeproj/project.pbxproj
  6. 4
      ide/Xcode3.1/plists/tabs-Info.plist
  7. 6
      makeinclude.in
  8. 42
      src/Fl.cxx
  9. 4
      src/Fl_Bitmap.cxx
  10. 3
      src/Fl_Font.H
  11. 38
      src/Fl_Gl_Choice.cxx
  12. 27
      src/Fl_Gl_Window.cxx
  13. 12
      src/Fl_Input.cxx
  14. 141
      src/Fl_Sys_Menu_Bar.cxx
  15. 5
      src/Fl_Window.cxx
  16. 4
      src/Fl_Window_iconize.cxx
  17. 7
      src/Fl_arg.cxx
  18. 3105
      src/Fl_cocoa.mm
  19. 12
      src/Fl_compose.cxx
  20. 14
      src/Fl_grab.cxx
  21. 1
      src/cgdebug.h
  22. 12
      src/fl_arci.cxx
  23. 3
      src/fl_ask.cxx
  24. 109
      src/fl_cursor.cxx
  25. 6
      src/fl_dnd_mac.cxx
  26. 193
      src/fl_font_mac.cxx
  27. 11
      src/fl_line_style.cxx
  28. 32
      src/fl_read_image_mac.cxx
  29. 178
      src/fl_rect.cxx
  30. 12
      src/fl_scroll_area.cxx
  31. 31
      src/fl_set_fonts_mac.cxx
  32. 37
      src/fl_vertex.cxx
  33. 109
      src/gl_draw.cxx
  34. 8
      src/makedepend
  35. 5
      src/screen_xywh.cxx
  36. 10
      test/browser.cxx
  37. 4
      test/color_chooser.cxx
  38. 30
      test/demo.cxx
  39. 4
      test/fullscreen.cxx

2
CHANGES

@ -1,5 +1,7 @@
CHANGES IN FLTK 1.3.0 CHANGES IN FLTK 1.3.0
- Moved OS X code base to the more moder Cocoa toolkit thanks
to the awesome work of Manolo Gouy (STR #2221)
- Added template to generate new projects with Xcode. - Added template to generate new projects with Xcode.
- Managing all Widget flags in a single location now (STR #2161) - Managing all Widget flags in a single location now (STR #2161)
- Fixed all color related call to Fl_Color type (STR #2208) - Fixed all color related call to Fl_Color type (STR #2208)

69
FL/mac.H

@ -36,16 +36,47 @@
// Standard MacOS Carbon API includes... // Standard MacOS Carbon API includes...
#include <Carbon/Carbon.h> #include <Carbon/Carbon.h>
#if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5) && !__LP64__
typedef float CGFloat;
#endif
#include <config.h>
// Now make some fixes to the headers... // Now make some fixes to the headers...
#undef check // Dunno where this comes from... #undef check // Dunno where this comes from...
// Some random X equivalents // Some random X equivalents
typedef WindowPtr Window;
struct XPoint { int x, y; }; struct XPoint { int x, y; };
struct XRectangle {int x, y, width, height;}; struct XRectangle {int x, y, width, height;};
#ifdef __APPLE_COCOA__
typedef void *Window; //this is really a pter to the subclass FLWindow of NSWindow
typedef struct flCocoaRegion{
int count;
CGRect *rects;
} *Fl_Region; // a region is the union of a series of rectangles
inline Fl_Region XRectangleRegion(int x, int y, int w, int h) {
Fl_Region R = (Fl_Region)malloc(sizeof(*R));
R->count = 1;
R->rects = (CGRect *)malloc(sizeof(CGRect));
*(R->rects) = CGRectMake(x, y, w - 1, h - 1);
return R;
}
inline void XDestroyRegion(Fl_Region r) {
if(r) {
free(r->rects);
free(r);
}
}
extern void *fl_default_cursor;
extern void *fl_system_menu;
typedef CGContextRef Fl_Offscreen;
typedef CGImageRef Fl_Bitmask;
#else
typedef WindowRef Window;
typedef RgnHandle Fl_Region; typedef RgnHandle Fl_Region;
void fl_clip_region(Fl_Region);
inline Fl_Region XRectangleRegion(int x, int y, int w, int h) { inline Fl_Region XRectangleRegion(int x, int y, int w, int h) {
Fl_Region R = NewRgn(); Fl_Region R = NewRgn();
SetRectRgn(R, x, y, x+w, y+h); SetRectRgn(R, x, y, x+w, y+h);
@ -54,6 +85,14 @@ inline Fl_Region XRectangleRegion(int x, int y, int w, int h) {
inline void XDestroyRegion(Fl_Region r) { inline void XDestroyRegion(Fl_Region r) {
DisposeRgn(r); DisposeRgn(r);
} }
extern CursHandle fl_default_cursor;
extern Handle fl_system_menu;
typedef GWorldPtr Fl_Offscreen;
typedef GWorldPtr Fl_Bitmask; // Carbon requires a 1-bit GWorld instead of a BitMap
#endif
void fl_clip_region(Fl_Region);
# include "Fl_Window.H" # include "Fl_Window.H"
@ -62,15 +101,19 @@ inline void XDestroyRegion(Fl_Region r) {
class Fl_X class Fl_X
{ {
public: public:
Window xid; // Mac WindowPtr Window xid; // Cocoa: FLWindow* ; Carbon: WindowRef
GWorldPtr other_xid; // pointer for offscreen bitmaps (doublebuffer) Fl_Offscreen other_xid; // pointer for offscreen bitmaps (doublebuffer)
Fl_Window *w; // FLTK window for Fl_Window *w; // FLTK window for
Fl_Region region; Fl_Region region;
Fl_Region subRegion; // region for this specific subwindow Fl_Region subRegion; // region for this specific subwindow
Fl_X *next; // linked tree to support subwindows Fl_X *next; // linked tree to support subwindows
Fl_X *xidChildren, *xidNext; // more subwindow tree Fl_X *xidChildren, *xidNext; // more subwindow tree
int wait_for_expose; int wait_for_expose;
#ifdef __APPLE_COCOA__
void *cursor; // is really NSCursor*
#else
CursHandle cursor; CursHandle cursor;
#endif
static Fl_X* first; static Fl_X* first;
static Fl_X* i(const Fl_Window* w) {return w->i;} static Fl_X* i(const Fl_Window* w) {return w->i;}
static int fake_X_wm(const Fl_Window*,int&,int&,int&,int&,int&); static int fake_X_wm(const Fl_Window*,int&,int&,int&,int&,int&);
@ -78,8 +121,10 @@ public:
void flush(); void flush();
// Quartz additions: // Quartz additions:
CGContextRef gc; // graphics context (NULL when using QD) CGContextRef gc; // graphics context (NULL when using QD)
#ifndef __APPLE_COCOA__
static ATSUTextLayout atsu_layout; // windows share a global font static ATSUTextLayout atsu_layout; // windows share a global font
static ATSUStyle atsu_style; static ATSUStyle atsu_style;
#endif
static void q_fill_context(); // fill a Quartz context with current FLTK state static void q_fill_context(); // fill a Quartz context with current FLTK state
static void q_clear_clipping(); // remove all clipping from a Quartz context static void q_clear_clipping(); // remove all clipping from a Quartz context
static void q_release_context(Fl_X *x=0); // free all resources associated with fl_gc static void q_release_context(Fl_X *x=0); // free all resources associated with fl_gc
@ -87,18 +132,27 @@ public:
static void q_end_image(); static void q_end_image();
}; };
#ifdef __APPLE_COCOA__
extern void MacDestroyWindow(Fl_Window*,void *);
extern void MacMapWindow(Fl_Window*,void *);
extern void MacUnmapWindow(Fl_Window*,void *);
extern WindowRef MACwindowRef(Fl_Window *w);
extern Fl_Region MacRectRegionIntersect(Fl_Region current, int x,int y,int w, int h);
extern void MacCollapseWindow(Window w);
#else
extern void MacDestroyWindow(Fl_Window*,WindowPtr); extern void MacDestroyWindow(Fl_Window*,WindowPtr);
extern void MacMapWindow(Fl_Window*,WindowPtr); extern void MacMapWindow(Fl_Window*,WindowPtr);
extern void MacUnmapWindow(Fl_Window*,WindowPtr); extern void MacUnmapWindow(Fl_Window*,WindowPtr);
#endif
extern int MacUnlinkWindow(Fl_X*,Fl_X*start=0L); extern int MacUnlinkWindow(Fl_X*,Fl_X*start=0L);
extern void fl_open_callback(void (*cb)(const char *));
inline Window fl_xid(const Fl_Window*w) inline Window fl_xid(const Fl_Window*w)
{ {
return Fl_X::i(w)->xid; return Fl_X::i(w)->xid;
} }
extern CursHandle fl_default_cursor;
extern struct Fl_XMap { extern struct Fl_XMap {
RGBColor rgb; RGBColor rgb;
ulong pen; ulong pen;
@ -107,10 +161,8 @@ extern struct Fl_XMap {
extern FL_EXPORT void *fl_display; extern FL_EXPORT void *fl_display;
extern FL_EXPORT Window fl_window; extern FL_EXPORT Window fl_window;
extern FL_EXPORT CGContextRef fl_gc; extern FL_EXPORT CGContextRef fl_gc;
extern FL_EXPORT Handle fl_system_menu;
extern FL_EXPORT class Fl_Sys_Menu_Bar *fl_sys_menu_bar; extern FL_EXPORT class Fl_Sys_Menu_Bar *fl_sys_menu_bar;
typedef GWorldPtr Fl_Offscreen;
extern Fl_Offscreen fl_create_offscreen(int w, int h); extern Fl_Offscreen fl_create_offscreen(int w, int h);
extern void fl_copy_offscreen(int x,int y,int w,int h, Fl_Offscreen gWorld, int srcx,int srcy); extern void fl_copy_offscreen(int x,int y,int w,int h, Fl_Offscreen gWorld, int srcx,int srcy);
@ -118,7 +170,6 @@ extern void fl_delete_offscreen(Fl_Offscreen gWorld);
extern void fl_begin_offscreen(Fl_Offscreen gWorld); extern void fl_begin_offscreen(Fl_Offscreen gWorld);
extern void fl_end_offscreen(); extern void fl_end_offscreen();
typedef GWorldPtr Fl_Bitmask; // Carbon requires a 1-bit GWorld instead of a BitMap
extern FL_EXPORT Fl_Bitmask fl_create_bitmask(int w, int h, const uchar *data); extern FL_EXPORT Fl_Bitmask fl_create_bitmask(int w, int h, const uchar *data);
extern FL_EXPORT Fl_Bitmask fl_create_alphamask(int w, int h, int d, int ld, const uchar *data); extern FL_EXPORT Fl_Bitmask fl_create_alphamask(int w, int h, int d, int ld, const uchar *data);

1
configh.in

@ -128,6 +128,7 @@
#define USE_QUARTZ 0 #define USE_QUARTZ 0
#undef __APPLE_QUARTZ__ #undef __APPLE_QUARTZ__
#undef __APPLE_COCOA__
#undef __APPLE_QD__ #undef __APPLE_QD__

3
configure.in

@ -364,6 +364,7 @@ case $uname in
# QD is not supported anymore since 1.3 # QD is not supported anymore since 1.3
AC_DEFINE(USE_QUARTZ, 1) AC_DEFINE(USE_QUARTZ, 1)
AC_DEFINE(__APPLE_QUARTZ__) AC_DEFINE(__APPLE_QUARTZ__)
AC_DEFINE(__APPLE_COCOA__)
;; ;;
esac esac
@ -828,7 +829,7 @@ case $uname_GUI in
Darwin*) Darwin*)
# MacOS X uses Carbon for graphics... # MacOS X uses Carbon for graphics...
LIBS="$LIBS -framework Carbon -framework ApplicationServices" LIBS="$LIBS -framework Carbon -framework Cocoa -framework ApplicationServices"
if test x$have_pthread = xyes; then if test x$have_pthread = xyes; then
AC_DEFINE(HAVE_PTHREAD) AC_DEFINE(HAVE_PTHREAD)

4484
ide/Xcode3.1/FLTK.xcodeproj/project.pbxproj

File diff suppressed because it is too large Load Diff

4
ide/Xcode3.1/plists/tabs-Info.plist

@ -7,13 +7,13 @@
<key>CFBundleExecutable</key> <key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string> <string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key> <key>CFBundleIdentifier</key>
<string>com.yourcompany.tabs</string> <string>org.fltk.table</string>
<key>CFBundleInfoDictionaryVersion</key> <key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string> <string>6.0</string>
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>APPL</string> <string>APPL</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>FLTK</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>1.0</string> <string>1.0</string>
</dict> </dict>

6
makeinclude.in

@ -152,7 +152,11 @@ UNINSTALL_DESKTOP = @UNINSTALL_DESKTOP@
.cxx.o: .cxx.o:
echo Compiling $<... echo Compiling $<...
$(CXX) -I.. $(ARCHFLAGS) @PNGINC@ @JPEGINC@ @ZLIBINC@ $(CXXFLAGS) -c $< -o $@ @if [ $< = Fl.cxx ]; then \
$(CXX) -I.. $(ARCHFLAGS) @PNGINC@ @JPEGINC@ @ZLIBINC@ $(CXXFLAGS) -x objective-c++ -c $< -o $@; \
else \
$(CXX) -I.. $(ARCHFLAGS) @PNGINC@ @JPEGINC@ @ZLIBINC@ $(CXXFLAGS) -c $< -o $@; \
fi
.man.0 .man.1 .man.3 .man.6: .man.0 .man.1 .man.3 .man.6:
echo Formatting $<... echo Formatting $<...

42
src/Fl.cxx

@ -40,6 +40,10 @@
#include <stdlib.h> #include <stdlib.h>
#include "flstring.h" #include "flstring.h"
#if defined(__APPLE__) && defined(__APPLE_COCOA__)
#import <Cocoa/Cocoa.h>
#endif
#ifdef DEBUG #ifdef DEBUG
# include <stdio.h> # include <stdio.h>
#endif // DEBUG #endif // DEBUG
@ -406,10 +410,17 @@ double Fl::wait(double time_to_wait) {
// the idle function may turn off idle, we can then wait: // the idle function may turn off idle, we can then wait:
if (idle) time_to_wait = 0.0; if (idle) time_to_wait = 0.0;
} }
#ifdef __APPLE_COCOA__
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
#endif
flush(); flush();
if (idle && !in_idle) // 'idle' may have been set within flush() if (idle && !in_idle) // 'idle' may have been set within flush()
time_to_wait = 0.0; time_to_wait = 0.0;
return fl_wait(time_to_wait); double retval = fl_wait(time_to_wait);
#ifdef __APPLE_COCOA__
[pool release];
#endif
return retval;
#else #else
@ -586,12 +597,13 @@ Fl_Window* fl_find(Window xid) {
Fl_X *window; Fl_X *window;
for (Fl_X **pp = &Fl_X::first; (window = *pp); pp = &window->next) for (Fl_X **pp = &Fl_X::first; (window = *pp); pp = &window->next)
#if defined(WIN32) || defined(USE_X11) #if defined(WIN32) || defined(USE_X11)
if (window->xid == xid) { if (window->xid == xid)
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
if (window->xid == xid && !window->w->window()) { if (window->xid == xid && !window->w->window())
#else #else
# error unsupported platform # error unsupported platform
#endif // __APPLE__ #endif // __APPLE__
{
if (window != Fl_X::first && !Fl::modal()) { if (window != Fl_X::first && !Fl::modal()) {
// make this window be first to speed up searches // make this window be first to speed up searches
// this is not done if modal is true to avoid messing up modal stack // this is not done if modal is true to avoid messing up modal stack
@ -1278,7 +1290,11 @@ int Fl_Window::handle(int ev)
#if defined(USE_X11) || defined(WIN32) #if defined(USE_X11) || defined(WIN32)
XMapWindow(fl_display, fl_xid(this)); // extra map calls are harmless XMapWindow(fl_display, fl_xid(this)); // extra map calls are harmless
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
MacMapWindow(this, i->xid);
#else
MacMapWindow(this, fl_xid(this)); MacMapWindow(this, fl_xid(this));
#endif
#else #else
# error unsupported platform # error unsupported platform
#endif // __APPLE__ #endif // __APPLE__
@ -1300,7 +1316,11 @@ int Fl_Window::handle(int ev)
#if defined(USE_X11) || defined(WIN32) #if defined(USE_X11) || defined(WIN32)
XUnmapWindow(fl_display, fl_xid(this)); XUnmapWindow(fl_display, fl_xid(this));
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
MacUnmapWindow(this, i->xid);
#else
MacUnmapWindow(this, fl_xid(this)); MacUnmapWindow(this, fl_xid(this));
#endif
#else #else
# error platform unsupported # error platform unsupported
#endif #endif
@ -1453,10 +1473,22 @@ void Fl_Widget::damage(uchar fl, int X, int Y, int W, int H) {
CombineRgn(i->region, i->region, R, RGN_OR); CombineRgn(i->region, i->region, R, RGN_OR);
XDestroyRegion(R); XDestroyRegion(R);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
CGRect arg = CGRectMake(X,Y,W - 1,H - 1);
int j;//don't add a rectangle totally inside the Fl_Region
for(j = 0; j < i->region->count; j++) {
if(CGRectContainsRect(i->region->rects[j], arg)) break;
}
if( j >= i->region->count) {
i->region->rects = (CGRect*)realloc(i->region->rects, (++(i->region->count)) * sizeof(CGRect));
i->region->rects[i->region->count - 1] = arg;
}
#else
Fl_Region R = NewRgn(); Fl_Region R = NewRgn();
SetRectRgn(R, X, Y, X+W, Y+H); SetRectRgn(R, X, Y, X+W, Y+H);
UnionRgn(R, i->region, i->region); UnionRgn(R, i->region, i->region);
DisposeRgn(R); DisposeRgn(R);
#endif
#else #else
# error unsupported platform # error unsupported platform
#endif #endif
@ -1480,8 +1512,12 @@ void Fl_Window::flush() {
#ifdef WIN32 #ifdef WIN32
# include "Fl_win32.cxx" # include "Fl_win32.cxx"
#elif defined(__APPLE__) #elif defined(__APPLE__)
#ifdef __APPLE_COCOA__
# include "Fl_cocoa.mm"
#else
# include "Fl_mac.cxx" # include "Fl_mac.cxx"
#endif #endif
#endif
// //
// The following methods allow callbacks to schedule the deletion of // The following methods allow callbacks to schedule the deletion of

4
src/Fl_Bitmap.cxx

@ -325,7 +325,11 @@ Fl_Bitmap::~Fl_Bitmap() {
void Fl_Bitmap::uncache() { void Fl_Bitmap::uncache() {
if (id) { if (id) {
#if defined(__APPLE__) && defined(__APPLE_COCOA__)
fl_delete_bitmask((Fl_Bitmask)id);
#else
fl_delete_bitmask((Fl_Offscreen)id); fl_delete_bitmask((Fl_Offscreen)id);
#endif
id = 0; id = 0;
} }
} }

3
src/Fl_Font.H

@ -67,6 +67,9 @@ public:
# elif defined(__APPLE_QUARTZ__) # elif defined(__APPLE_QUARTZ__)
FL_EXPORT Fl_Font_Descriptor(const char* fontname, Fl_Fontsize size); FL_EXPORT Fl_Font_Descriptor(const char* fontname, Fl_Fontsize size);
ATSUTextLayout layout; ATSUTextLayout layout;
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
CTFontRef fontref;
#endif
ATSUStyle style; ATSUStyle style;
short ascent, descent, q_width; short ascent, descent, q_width;
// short width[256]; // short width[256];

38
src/Fl_Gl_Choice.cxx

@ -295,20 +295,34 @@ GLContext fl_create_gl_context(Fl_Window* window, const Fl_Gl_Choice* g, int lay
} }
# elif defined(__APPLE_QUARTZ__) # elif defined(__APPLE_QUARTZ__)
// warning: the Quartz version should probably use Core GL (CGL) instead of AGL // warning: the Quartz version should probably use Core GL (CGL) instead of AGL
GLContext fl_create_gl_context(Fl_Window* window, const Fl_Gl_Choice* g, int layer) { GLContext fl_create_gl_context(Fl_Window* window, const Fl_Gl_Choice* g, int layer) {
GLContext context, shared_ctx = 0; GLContext context, shared_ctx = 0;
if (context_list && nContext) shared_ctx = context_list[0]; if (context_list && nContext) shared_ctx = context_list[0];
context = aglCreateContext( g->pixelformat, shared_ctx); context = aglCreateContext( g->pixelformat, shared_ctx);
if (!context) return 0; if (!context) return 0;
add_context((GLContext)context); add_context((GLContext)context);
if ( window->parent() ) { if ( window->parent() ) {
Rect wrect; GetWindowPortBounds( fl_xid(window), &wrect ); #ifdef __APPLE_COCOA__
int H = window->window()->h();
GLint rect[] = { window->x(), H-window->h()-window->y(), window->w(), window->h() };
#else
Rect wrect;
GetWindowPortBounds( fl_xid(window), &wrect );
GLint rect[] = { window->x(), wrect.bottom-window->h()-window->y(), window->w(), window->h() }; GLint rect[] = { window->x(), wrect.bottom-window->h()-window->y(), window->w(), window->h() };
#endif
aglSetInteger( (GLContext)context, AGL_BUFFER_RECT, rect ); aglSetInteger( (GLContext)context, AGL_BUFFER_RECT, rect );
aglEnable( (GLContext)context, AGL_BUFFER_RECT ); aglEnable( (GLContext)context, AGL_BUFFER_RECT );
} }
#if defined(__APPLE_COCOA__)
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
aglSetWindowRef(context, MACwindowRef(window) );
#else
aglSetDrawable( context, GetWindowPort( MACwindowRef(window) ) );
#endif
#else
aglSetDrawable( context, GetWindowPort( fl_xid(window) ) ); aglSetDrawable( context, GetWindowPort( fl_xid(window) ) );
#endif
return (context); return (context);
} }
# else # else
@ -329,12 +343,26 @@ void fl_set_gl_context(Fl_Window* w, GLContext context) {
# elif defined(__APPLE_QUARTZ__) # elif defined(__APPLE_QUARTZ__)
// warning: the Quartz version should probably use Core GL (CGL) instead of AGL // warning: the Quartz version should probably use Core GL (CGL) instead of AGL
if ( w->parent() ) { //: resize our GL buffer rectangle if ( w->parent() ) { //: resize our GL buffer rectangle
Rect wrect; GetWindowPortBounds( fl_xid(w), &wrect ); #ifdef __APPLE_COCOA__
int H = w->window()->h();
GLint rect[] = { w->x(), H-w->h()-w->y(), w->w(), w->h() };
#else
Rect wrect;
GetWindowPortBounds( fl_xid(w), &wrect );
GLint rect[] = { w->x(), wrect.bottom-w->h()-w->y(), w->w(), w->h() }; GLint rect[] = { w->x(), wrect.bottom-w->h()-w->y(), w->w(), w->h() };
#endif
aglSetInteger( context, AGL_BUFFER_RECT, rect ); aglSetInteger( context, AGL_BUFFER_RECT, rect );
aglEnable( context, AGL_BUFFER_RECT ); aglEnable( context, AGL_BUFFER_RECT );
} }
aglSetDrawable(context, GetWindowPort( fl_xid(w) ) ); #if defined(__APPLE_COCOA__)
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
aglSetWindowRef(context, MACwindowRef(w) );
#else
aglSetDrawable( context, GetWindowPort( MACwindowRef(w) ) );
#endif
#else
aglSetDrawable( context, GetWindowPort( fl_xid(w) ) );
#endif
aglSetCurrentContext(context); aglSetCurrentContext(context);
# else # else
# error unsupported platform # error unsupported platform

27
src/Fl_Gl_Window.cxx

@ -66,6 +66,9 @@ int Fl_Gl_Window::can_do(int a, const int *b) {
} }
void Fl_Gl_Window::show() { void Fl_Gl_Window::show() {
#if defined(__APPLE__) && defined(__APPLE_COCOA__)
int need_redraw = 0;
#endif
if (!shown()) { if (!shown()) {
if (!g) { if (!g) {
g = Fl_Gl_Choice::find(mode_,alist); g = Fl_Gl_Choice::find(mode_,alist);
@ -83,12 +86,19 @@ void Fl_Gl_Window::show() {
#if !defined(WIN32) && !defined(__APPLE__) #if !defined(WIN32) && !defined(__APPLE__)
Fl_X::make_xid(this, g->vis, g->colormap); Fl_X::make_xid(this, g->vis, g->colormap);
if (overlay && overlay != this) ((Fl_Gl_Window*)overlay)->show(); if (overlay && overlay != this) ((Fl_Gl_Window*)overlay)->show();
#elif defined(__APPLE__) && defined(__APPLE_COCOA__)
extern void MACsetContainsGLsubwindow(Fl_Window *);
if( ! parent() ) need_redraw=1;
else MACsetContainsGLsubwindow( window() );
#endif #endif
} }
Fl_Window::show(); Fl_Window::show();
#ifdef __APPLE__ #ifdef __APPLE__
set_visible(); set_visible();
#ifdef __APPLE_COCOA__
if(need_redraw) redraw();//necessary only after creation of a top-level GL window
#endif
#endif /* __APPLE__ */ #endif /* __APPLE__ */
} }
@ -154,6 +164,7 @@ int Fl_Gl_Window::mode(int m, const int *a) {
being called and can also be used to implement feedback and/or being called and can also be used to implement feedback and/or
selection within the handle() method. selection within the handle() method.
*/ */
void Fl_Gl_Window::make_current() { void Fl_Gl_Window::make_current() {
// puts("Fl_Gl_Window::make_current()"); // puts("Fl_Gl_Window::make_current()");
// printf("make_current: context_=%p\n", context_); // printf("make_current: context_=%p\n", context_);
@ -237,6 +248,15 @@ void Fl_Gl_Window::swap_buffers() {
# endif # endif
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
// warning: the Quartz version should probably use Core GL (CGL) instead of AGL // warning: the Quartz version should probably use Core GL (CGL) instead of AGL
#ifdef __APPLE_COCOA__
if(overlay != NULL) {
//aglSwapBuffers does not work well with overlays under cocoa
glReadBuffer(GL_BACK);
glDrawBuffer(GL_FRONT);
glCopyPixels(0,0,w(),h(),GL_COLOR);
}
else
#endif
aglSwapBuffers((AGLContext)context_); aglSwapBuffers((AGLContext)context_);
#else #else
# error unsupported platform # error unsupported platform
@ -248,6 +268,7 @@ uchar fl_overlay; // changes how fl_color() works
int fl_overlay_depth = 0; int fl_overlay_depth = 0;
#endif #endif
void Fl_Gl_Window::flush() { void Fl_Gl_Window::flush() {
uchar save_valid = valid_f_ & 1; uchar save_valid = valid_f_ & 1;
#if HAVE_GL_OVERLAY && defined(WIN32) #if HAVE_GL_OVERLAY && defined(WIN32)
@ -257,13 +278,19 @@ void Fl_Gl_Window::flush() {
#if defined(__APPLE_QUARTZ__) #if defined(__APPLE_QUARTZ__)
// warning: the Quartz version should probably use Core GL (CGL) instead of AGL // warning: the Quartz version should probably use Core GL (CGL) instead of AGL
//: clear previous clipping in this shared port //: clear previous clipping in this shared port
#if ! __LP64__
#ifdef __APPLE_COCOA__
GrafPtr port = GetWindowPort( MACwindowRef(this) );
#else
GrafPtr port = GetWindowPort( fl_xid(this) ); GrafPtr port = GetWindowPort( fl_xid(this) );
#endif
Rect rect; SetRect( &rect, 0, 0, 0x7fff, 0x7fff ); Rect rect; SetRect( &rect, 0, 0, 0x7fff, 0x7fff );
GrafPtr old; GetPort( &old ); GrafPtr old; GetPort( &old );
SetPort( port ); SetPort( port );
ClipRect( &rect ); ClipRect( &rect );
SetPort( old ); SetPort( old );
#endif #endif
#endif
#if HAVE_GL_OVERLAY && defined(WIN32) #if HAVE_GL_OVERLAY && defined(WIN32)

12
src/Fl_Input.cxx

@ -365,13 +365,13 @@ int Fl_Input::handle_key() {
case 'v' : case 'v' :
case 'x' : case 'x' :
case 'z' : case 'z' :
// printf("'%c' (0x%02x) pressed with%s%s%s%s\n", ascii, ascii, // printf("'%c' (0x%02x) pressed with%s%s%s%s\n", ascii, ascii,
// Fl::event_state(FL_SHIFT) ? " FL_SHIFT" : "", // Fl::event_state(FL_SHIFT) ? " FL_SHIFT" : "",
// Fl::event_state(FL_CTRL) ? " FL_CTRL" : "", // Fl::event_state(FL_CTRL) ? " FL_CTRL" : "",
// Fl::event_state(FL_ALT) ? " FL_ALT" : "", // Fl::event_state(FL_ALT) ? " FL_ALT" : "",
// Fl::event_state(FL_META) ? " FL_META" : ""); // Fl::event_state(FL_META) ? " FL_META" : "");
if (Fl::event_state(FL_META)) ascii -= 0x60; if (Fl::event_state(FL_META)) ascii -= 0x60;
// printf("using '%c' (0x%02x)...\n", ascii, ascii); // printf("using '%c' (0x%02x)...\n", ascii, ascii);
break; break;
#endif // __APPLE__ #endif // __APPLE__
} }

141
src/Fl_Sys_Menu_Bar.cxx

@ -61,6 +61,12 @@
#include "flstring.h" #include "flstring.h"
#include <stdio.h> #include <stdio.h>
#include <ctype.h> #include <ctype.h>
#include <stdarg.h>
#ifdef __APPLE_COCOA__
extern void *MACMenuOrItemOperation(const char *operation, ...);
#define MenuHandle void *
#endif
typedef const Fl_Menu_Item *pFl_Menu_Item; typedef const Fl_Menu_Item *pFl_Menu_Item;
@ -69,7 +75,9 @@ typedef const Fl_Menu_Item *pFl_Menu_Item;
* Skip all '&' which would mark the shortcut in FLTK * Skip all '&' which would mark the shortcut in FLTK
* Skip all Mac control characters ('(', '<', ';', '^', '!' ) * Skip all Mac control characters ('(', '<', ';', '^', '!' )
*/ */
static void catMenuText( const char *src, char *dst )
#ifndef __APPLE_COCOA__
static void catMenuText( const char *src, char *dst )
{ {
char c; char c;
while ( *dst ) while ( *dst )
@ -88,6 +96,7 @@ static void catMenuText( const char *src, char *dst )
* append a marker to identify the menu font style * append a marker to identify the menu font style
* <B, I, U, O, and S * <B, I, U, O, and S
*/ */
static void catMenuFont( const Fl_Menu_Item *m, char *dst ) static void catMenuFont( const Fl_Menu_Item *m, char *dst )
{ {
if ( !m->labeltype_ && !m->labelfont_ ) if ( !m->labeltype_ && !m->labelfont_ )
@ -122,7 +131,9 @@ enum {
kMenuControlModifier = (1 << 2), kMenuControlModifier = (1 << 2),
kMenuNoCommandModifier = (1 << 3) kMenuNoCommandModifier = (1 << 3)
}; };
*/ */
#endif
static void setMenuShortcut( MenuHandle mh, int miCnt, const Fl_Menu_Item *m ) static void setMenuShortcut( MenuHandle mh, int miCnt, const Fl_Menu_Item *m )
{ {
if ( !m->shortcut_ ) if ( !m->shortcut_ )
@ -135,6 +146,11 @@ static void setMenuShortcut( MenuHandle mh, int miCnt, const Fl_Menu_Item *m )
if ( !isalnum( key ) ) if ( !isalnum( key ) )
return; return;
#ifdef __APPLE_COCOA__
void *menuItem = MACMenuOrItemOperation("itemAtIndex", mh, miCnt);
MACMenuOrItemOperation("setKeyEquivalent", menuItem, key );
MACMenuOrItemOperation("setKeyEquivalentModifierMask", menuItem, m->shortcut_ );
#else
long macMod = kMenuNoCommandModifier; long macMod = kMenuNoCommandModifier;
if ( m->shortcut_ & FL_META ) macMod = kMenuNoModifiers; if ( m->shortcut_ & FL_META ) macMod = kMenuNoModifiers;
if ( m->shortcut_ & FL_SHIFT || isupper(key) ) macMod |= kMenuShiftModifier; if ( m->shortcut_ & FL_SHIFT || isupper(key) ) macMod |= kMenuShiftModifier;
@ -144,8 +160,10 @@ static void setMenuShortcut( MenuHandle mh, int miCnt, const Fl_Menu_Item *m )
//SetMenuItemKeyGlyph( mh, miCnt, key ); //SetMenuItemKeyGlyph( mh, miCnt, key );
SetItemCmd( mh, miCnt, toupper(key) ); SetItemCmd( mh, miCnt, toupper(key) );
SetMenuItemModifiers( mh, miCnt, macMod ); SetMenuItemModifiers( mh, miCnt, macMod );
#endif
} }
#if 0 #if 0
// this function needs to be verified before we compile it back in. // this function needs to be verified before we compile it back in.
static void catMenuShortcut( const Fl_Menu_Item *m, char *dst ) static void catMenuShortcut( const Fl_Menu_Item *m, char *dst )
@ -166,16 +184,113 @@ static void catMenuShortcut( const Fl_Menu_Item *m, char *dst )
} }
#endif #endif
static void setMenuFlags( MenuHandle mh, int miCnt, const Fl_Menu_Item *m ) static void setMenuFlags( MenuHandle mh, int miCnt, const Fl_Menu_Item *m )
{ {
if ( m->flags & FL_MENU_TOGGLE ) if ( m->flags & FL_MENU_TOGGLE )
{ {
#ifdef __APPLE_COCOA__
void *menuItem = MACMenuOrItemOperation("itemAtIndex", mh, miCnt);
MACMenuOrItemOperation("setState", menuItem, m->flags & FL_MENU_VALUE );
#else
SetItemMark( mh, miCnt, ( m->flags & FL_MENU_VALUE ) ? 0x12 : 0 ); SetItemMark( mh, miCnt, ( m->flags & FL_MENU_VALUE ) ? 0x12 : 0 );
#endif
} }
else if ( m->flags & FL_MENU_RADIO ) else if ( m->flags & FL_MENU_RADIO ) {
#ifndef __APPLE_COCOA__
SetItemMark( mh, miCnt, ( m->flags & FL_MENU_VALUE ) ? 0x13 : 0 ); SetItemMark( mh, miCnt, ( m->flags & FL_MENU_VALUE ) ? 0x13 : 0 );
#endif
}
}
#ifdef __APPLE_COCOA__
/**
* create a sub menu for a specific menu handle
*/
static void createSubMenu( void * mh, pFl_Menu_Item &mm )
{
void *submenu;
int miCnt, flags;
void *menuItem;
submenu = MACMenuOrItemOperation("initWithTitle", mm->text);
int cnt;
MACMenuOrItemOperation("numberOfItems", mh, &cnt);
cnt--;
menuItem = MACMenuOrItemOperation("itemAtIndex", mh, cnt);
MACMenuOrItemOperation("setSubmenu", menuItem, submenu);
if ( mm->flags & FL_MENU_INACTIVE ) {
MACMenuOrItemOperation("setEnabled", menuItem, 0);
}
mm++;
while ( mm->text )
{
MACMenuOrItemOperation("addNewItem", submenu, mm->text, mm->callback_, mm->user_data_, &miCnt);
setMenuFlags( submenu, miCnt, mm );
setMenuShortcut( submenu, miCnt, mm );
if ( mm->flags & FL_MENU_INACTIVE ) {
void *item = MACMenuOrItemOperation("itemAtIndex", submenu, miCnt);
MACMenuOrItemOperation("setEnabled", item, 0);
}
flags = mm->flags;
if ( mm->flags & FL_SUBMENU )
{
createSubMenu( submenu, mm );
}
else if ( mm->flags & FL_SUBMENU_POINTER )
{
const Fl_Menu_Item *smm = (Fl_Menu_Item*)mm->user_data_;
createSubMenu( submenu, smm );
}
if ( flags & FL_MENU_DIVIDER ) {
MACMenuOrItemOperation("addSeparatorItem", submenu);
}
mm++;
}
} }
/**
* create a system menu bar using the given list of menu structs
*
* \author Matthias Melcher
*
* @param m list of Fl_Menu_Item
*/
extern void *MACmainMenu(void);
void Fl_Sys_Menu_Bar::menu(const Fl_Menu_Item *m)
{
fl_open_display();
Fl_Menu_Bar::menu( m );
fl_sys_menu_bar = this;
const Fl_Menu_Item *mm = m;
for (;;)
{
if ( !mm || !mm->text )
break;
char visible = mm->visible() ? 1 : 0;
MACMenuOrItemOperation("addNewItem", MACmainMenu(), mm->text, NULL, NULL, NULL);
if ( mm->flags & FL_SUBMENU )
createSubMenu( MACmainMenu(), mm );
else if ( mm->flags & FL_SUBMENU_POINTER ) {
const Fl_Menu_Item *smm = (Fl_Menu_Item*)mm->user_data_;
createSubMenu( MACmainMenu(), smm );
}
if ( visible ) {
// InsertMenu( mh, 0 );
}
mm++;
}
}
#else
static void catMenuFlags( const Fl_Menu_Item *m, char *dst ) static void catMenuFlags( const Fl_Menu_Item *m, char *dst )
{ {
if ( !m->flags ) if ( !m->flags )
@ -184,6 +299,7 @@ static void catMenuFlags( const Fl_Menu_Item *m, char *dst )
strcat( dst, "(" ); strcat( dst, "(" );
} }
/** /**
* create a sub menu for a specific menu handle * create a sub menu for a specific menu handle
*/ */
@ -276,6 +392,8 @@ void Fl_Sys_Menu_Bar::menu(const Fl_Menu_Item *m)
DrawMenuBar(); DrawMenuBar();
} }
#endif //__APPLE_COCOA__
/* /*
const Fl_Menu_Item* Fl_Sys_Menu_Bar::picked(const Fl_Menu_Item* v) { const Fl_Menu_Item* Fl_Sys_Menu_Bar::picked(const Fl_Menu_Item* v) {
Fl_menu_Item *ret = Fl_Menu_Bar::picked( v ); Fl_menu_Item *ret = Fl_Menu_Bar::picked( v );
@ -290,21 +408,10 @@ const Fl_Menu_Item* Fl_Sys_Menu_Bar::picked(const Fl_Menu_Item* v) {
*/ */
void Fl_Sys_Menu_Bar::draw() { void Fl_Sys_Menu_Bar::draw() {
/* -- nothing to do, system should take care of this
draw_box();
if (!menu() || !menu()->text) return;
const Fl_Menu_Item* m;
int X = x()+6;
for (m=menu(); m->text; m = m->next()) {
int W = m->measure(0,this) + 16;
m->draw(X, y(), W, h(), this);
X += W;
}
*/
} }
/* /*
int Fl_Menu_Bar::handle(int event) { int Fl_Menu_Bar::handle(int event) {
const Fl_Menu_Item* v; const Fl_Menu_Item* v;
if (menu() && menu()->text) switch (event) { if (menu() && menu()->text) switch (event) {
case FL_ENTER: case FL_ENTER:
@ -324,8 +431,8 @@ int Fl_Menu_Bar::handle(int event) {
return test_shortcut() != 0; return test_shortcut() != 0;
} }
return 0; return 0;
} }
*/ */
#endif /* __APPLE__ */ #endif /* __APPLE__ */

5
src/Fl_Window.cxx

@ -31,6 +31,7 @@
// equivalent (but totally different) crap for MSWindows is in Fl_win32.cxx // equivalent (but totally different) crap for MSWindows is in Fl_win32.cxx
#include "config.h" #include "config.h"
#include <FL/Fl.H> #include <FL/Fl.H>
#include <FL/x.H>
#include <FL/Fl_Window.H> #include <FL/Fl_Window.H>
#include <stdlib.h> #include <stdlib.h>
#include "flstring.h" #include "flstring.h"
@ -125,6 +126,10 @@ void Fl_Window::draw() {
int i; int i;
for (i=dx; i<12; i++) { for (i=dx; i<12; i++) {
fl_color(c[i&3]); fl_color(c[i&3]);
#ifdef __APPLE_COCOA__
extern CGContextRef fl_gc;
if(fl_gc)
#endif
fl_line(x1--, y1, x2, y2--); fl_line(x1--, y1, x2, y2--);
} }
} }

4
src/Fl_Window_iconize.cxx

@ -37,7 +37,11 @@ void Fl_Window::iconize() {
#ifdef WIN32 #ifdef WIN32
ShowWindow(i->xid, SW_SHOWMINNOACTIVE); ShowWindow(i->xid, SW_SHOWMINNOACTIVE);
#elif defined(__APPLE__) #elif defined(__APPLE__)
#ifdef __APPLE_COCOA__
MacCollapseWindow((Window)i->xid);
#else
CollapseWindow( i->xid, true ); CollapseWindow( i->xid, true );
#endif
#else #else
XIconifyWindow(fl_display, i->xid, fl_screen); XIconifyWindow(fl_display, i->xid, fl_screen);
#endif #endif

7
src/Fl_arg.cxx

@ -88,13 +88,6 @@ int Fl::arg(int argc, char **argv, int &i) {
if (s[0] != '-' || s[1] == '-' || !s[1]) {return_i = 1; return 0;} if (s[0] != '-' || s[1] == '-' || !s[1]) {return_i = 1; return 0;}
s++; // point after the dash s++; // point after the dash
#ifdef __APPLE__
if (!strncmp(s, "psn", 3)) {
// Skip process serial number...
i++;
}
else
#endif // __APPLE__
if (fl_match(s, "iconic")) { if (fl_match(s, "iconic")) {
fl_show_iconic = 1; fl_show_iconic = 1;
i++; i++;

3105
src/Fl_cocoa.mm

File diff suppressed because it is too large Load Diff

12
src/Fl_compose.cxx

@ -26,6 +26,7 @@
// //
#include <FL/Fl.H> #include <FL/Fl.H>
#include <FL/x.H>
// //
// MRS: Uncomment the following define to get the original (pre-1.1.2) // MRS: Uncomment the following define to get the original (pre-1.1.2)
@ -38,6 +39,15 @@
#ifdef __APPLE__ #ifdef __APPLE__
#ifdef __APPLE_COCOA__
static const char* const compose_pairs =
" ! % # $ y=| & : c a <<~ - r _ * +-2 3 ' u p . , 1 o >>141234? "//00A0 ...
"`A'A^A~A:A*AAE,C`E'E^E:E`I'I^I:I-D~N`O'O^O~O:Ox O/`U'U^U:U'YTHss" //00C0 ...
"`a'a^a~a:a*aae,c`e'e^e:e`i'i^i:i-d~n`o'o^o~o:o-:o/`u'u^u:u'yth:y";//00E0 ...
#else
static const char* const compose_pairs = static const char* const compose_pairs =
":A*A,C'E~N:O:U'a`a^a:a~a*a,c'e`e" ":A*A,C'E~N:O:U'a`a^a:a~a*a,c'e`e"
"^e:e'i`i^i:i~n'o`o^o:o~o'u`u^u:u" "^e:e'i`i^i:i~n'o`o^o:o~o'u`u^u:u"
@ -48,6 +58,8 @@ static const char* const compose_pairs =
"++..,,_\"%%^A^E'A:E`E'I^I:I`I'O^O" "++..,,_\"%%^A^E'A:E`E'I^I:I`I'O^O"
"mc`O'U^U`U||^ ~^_ u . * , ~-; v "; "mc`O'U^U`U||^ ~^_ u . * , ~-; v ";
#endif
#else #else
static const char* const compose_pairs = static const char* const compose_pairs =

14
src/Fl_grab.cxx

@ -48,7 +48,12 @@ extern HWND fl_capture;
#ifdef __APPLE__ #ifdef __APPLE__
// MacOS Carbon does not seem to have a mechanism to grab the mouse pointer // MacOS Carbon does not seem to have a mechanism to grab the mouse pointer
extern WindowRef fl_capture; #ifdef __APPLE_COCOA__
extern void MACsetkeywindow(void *nsw);
extern void *fl_capture;
#else
extern Window fl_capture;
#endif
#endif #endif
void Fl::grab(Fl_Window* win) { void Fl::grab(Fl_Window* win) {
@ -58,8 +63,13 @@ void Fl::grab(Fl_Window* win) {
SetActiveWindow(fl_capture = fl_xid(first_window())); SetActiveWindow(fl_capture = fl_xid(first_window()));
SetCapture(fl_capture); SetCapture(fl_capture);
#elif defined(__APPLE__) #elif defined(__APPLE__)
#ifdef __APPLE_COCOA__
fl_capture = Fl_X::i(first_window())->xid;
MACsetkeywindow(fl_capture);
#else
fl_capture = fl_xid( first_window() ); fl_capture = fl_xid( first_window() );
SetUserFocusWindow( fl_capture ); SetUserFocusWindow( fl_capture );
#endif
#else #else
XGrabPointer(fl_display, XGrabPointer(fl_display,
fl_xid(first_window()), fl_xid(first_window()),
@ -87,7 +97,9 @@ void Fl::grab(Fl_Window* win) {
ReleaseCapture(); ReleaseCapture();
#elif defined(__APPLE__) #elif defined(__APPLE__)
fl_capture = 0; fl_capture = 0;
#ifndef __APPLE_COCOA__
SetUserFocusWindow( (WindowRef)kUserFocusAuto ); SetUserFocusWindow( (WindowRef)kUserFocusAuto );
#endif
#else #else
XUngrabKeyboard(fl_display, fl_event_time); XUngrabKeyboard(fl_display, fl_event_time);
XUngrabPointer(fl_display, fl_event_time); XUngrabPointer(fl_display, fl_event_time);

1
src/cgdebug.h

@ -212,3 +212,4 @@ inline void dbgCGContextRestoreGState(CGContextRef context)
// //
// End of "$Id$". // End of "$Id$".
// //

12
src/fl_arci.cxx

@ -86,6 +86,9 @@ void fl_arc(int x,int y,int w,int h,double a1,double a2) {
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
a1 = (-a1)/180.0f*M_PI; a2 = (-a2)/180.0f*M_PI; a1 = (-a1)/180.0f*M_PI; a2 = (-a2)/180.0f*M_PI;
float cx = x + 0.5f*w - 0.5f, cy = y + 0.5f*h - 0.5f; float cx = x + 0.5f*w - 0.5f, cy = y + 0.5f*h - 0.5f;
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, true);
#endif
if (w!=h) { if (w!=h) {
CGContextSaveGState(fl_gc); CGContextSaveGState(fl_gc);
CGContextTranslateCTM(fl_gc, cx, cy); CGContextTranslateCTM(fl_gc, cx, cy);
@ -97,6 +100,9 @@ void fl_arc(int x,int y,int w,int h,double a1,double a2) {
CGContextAddArc(fl_gc, cx, cy, r, a1, a2, 1); CGContextAddArc(fl_gc, cx, cy, r, a1, a2, 1);
} }
CGContextStrokePath(fl_gc); CGContextStrokePath(fl_gc);
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, false);
#endif
#else #else
# error unsupported platform # error unsupported platform
#endif #endif
@ -136,6 +142,9 @@ void fl_pie(int x,int y,int w,int h,double a1,double a2) {
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
a1 = (-a1)/180.0f*M_PI; a2 = (-a2)/180.0f*M_PI; a1 = (-a1)/180.0f*M_PI; a2 = (-a2)/180.0f*M_PI;
float cx = x + 0.5f*w - 0.5f, cy = y + 0.5f*h - 0.5f; float cx = x + 0.5f*w - 0.5f, cy = y + 0.5f*h - 0.5f;
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, true);
#endif
if (w!=h) { if (w!=h) {
CGContextSaveGState(fl_gc); CGContextSaveGState(fl_gc);
CGContextTranslateCTM(fl_gc, cx, cy); CGContextTranslateCTM(fl_gc, cx, cy);
@ -151,6 +160,9 @@ void fl_pie(int x,int y,int w,int h,double a1,double a2) {
CGContextClosePath(fl_gc); CGContextClosePath(fl_gc);
} }
CGContextFillPath(fl_gc); CGContextFillPath(fl_gc);
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, false);
#endif
#else #else
# error unsupported platform # error unsupported platform
#endif #endif

3
src/fl_ask.cxx

@ -273,7 +273,8 @@ void fl_beep(int type) {
switch (type) { switch (type) {
case FL_BEEP_DEFAULT : case FL_BEEP_DEFAULT :
case FL_BEEP_ERROR : case FL_BEEP_ERROR :
SysBeep(30); // SysBeep(30);
AlertSoundPlay();
break; break;
default : default :
break; break;

109
src/fl_cursor.cxx

@ -134,6 +134,113 @@ void Fl_Window::cursor(Fl_Cursor c, Fl_Color c1, Fl_Color c2) {
# error "Either __LITTLE_ENDIAN__ or __BIG_ENDIAN__ must be defined" # error "Either __LITTLE_ENDIAN__ or __BIG_ENDIAN__ must be defined"
#endif #endif
#ifdef __APPLE_COCOA__
extern void *MACSetCursor(Fl_Cursor c);
extern Fl_Offscreen fl_create_offscreen_with_alpha(int w, int h);
CGContextRef CreateHelpImage(void)
{
int w = 20, h = 20;
Fl_Offscreen off = fl_create_offscreen_with_alpha(w, h);
fl_begin_offscreen(off);
CGContextSetRGBFillColor( (CGContextRef)off, 0,0,0,0);
fl_rectf(0,0,w,h);
fl_color(FL_BLACK);
fl_font(FL_COURIER_BOLD, 20);
fl_draw("?", 1, h-1);
fl_end_offscreen();
return (CGContextRef)off;
}
CGContextRef CreateNoneImage(void)
{
int w = 20, h = 20;
Fl_Offscreen off = fl_create_offscreen_with_alpha(w, h);
fl_begin_offscreen(off);
CGContextSetRGBFillColor( (CGContextRef)off, 0,0,0,0);
fl_rectf(0,0,w,h);
fl_end_offscreen();
return (CGContextRef)off;
}
CGContextRef CreateWatchImage(void)
{
int w, h, r = 5;
w = 2*r+6;
h = 4*r;
Fl_Offscreen off = fl_create_offscreen_with_alpha(w, h);
fl_begin_offscreen(off);
CGContextSetRGBFillColor( (CGContextRef)off, 0,0,0,0);
fl_rectf(0,0,w,h);
CGContextTranslateCTM( (CGContextRef)off, w/2, h/2);
fl_color(FL_WHITE);
fl_circle(0, 0, r+1);
fl_color(FL_BLACK);
fl_rectf(-r*0.7, -r*1.7, 1.4*r, 3.4*r);
fl_rectf(r-1, -1, 3, 3);
fl_color(FL_WHITE);
fl_pie(-r, -r, 2*r, 2*r, 0, 360);
fl_color(FL_BLACK);
fl_circle(0,0,r);
fl_xyline(0, 0, -r*.7);
fl_xyline(0, 0, 0, -r*.7);
fl_end_offscreen();
return (CGContextRef)off;
}
CGContextRef CreateNESWImage(void)
{
int c = 7, r = 2*c;
int w = r, h = r;
Fl_Offscreen off = fl_create_offscreen_with_alpha(w, h);
fl_begin_offscreen(off);
CGContextSetRGBFillColor( (CGContextRef)off, 0,0,0,0);
fl_rectf(0,0,w,h);
CGContextTranslateCTM( (CGContextRef)off, 0, h);
CGContextScaleCTM( (CGContextRef)off, 1, -1);
fl_color(FL_BLACK);
fl_polygon(0, 0, c, 0, 0, c);
fl_polygon(r, r, r, r-c, r-c, r);
fl_line_style(FL_SOLID, 2, 0);
fl_line(0,1, r,r+1);
fl_line_style(FL_SOLID, 0, 0);
fl_end_offscreen();
return (CGContextRef)off;
}
CGContextRef CreateNWSEImage(void)
{
int c = 7, r = 2*c;
int w = r, h = r;
Fl_Offscreen off = fl_create_offscreen_with_alpha(w, h);
fl_begin_offscreen(off);
CGContextSetRGBFillColor( (CGContextRef)off, 0,0,0,0);
fl_rectf(0,0,w,h);
CGContextTranslateCTM( (CGContextRef)off, 0, h);
CGContextScaleCTM( (CGContextRef)off, 1, -1);
fl_color(FL_BLACK);
fl_polygon(r-1, 0, r-1, c, r-1-c, 0);
fl_polygon(-1, r, c-1, r, -1, r-c);
fl_line_style(FL_SOLID, 2, 0);
fl_line(r-1,1, -1,r+1);
fl_line_style(FL_SOLID, 0, 0);
fl_end_offscreen();
return (CGContextRef)off;
}
void Fl_Window::cursor(Fl_Cursor c, Fl_Color, Fl_Color) {
if (c == FL_CURSOR_DEFAULT) {
c = cursor_default;
}
void *cursor = MACSetCursor( c );
if (i) {
i->cursor = cursor;
}
}
#else
static Cursor crsrHAND = static Cursor crsrHAND =
{ {
{ E(0x0600), E(0x0900), E(0x0900), E(0x0900), E(0x09C0), E(0x0938), E(0x6926), E(0x9805), { E(0x0600), E(0x0900), E(0x0900), E(0x0900), E(0x09C0), E(0x0938), E(0x6926), E(0x9805),
@ -246,6 +353,8 @@ void Fl_Window::cursor(Fl_Cursor c, Fl_Color, Fl_Color) {
} }
} }
#endif //__APPLE_COCOA__
#else #else
// I like the MSWindows resize cursors, so I duplicate them here: // I like the MSWindows resize cursors, so I duplicate them here:

6
src/fl_dnd_mac.cxx

@ -46,6 +46,11 @@ extern int fl_selection_length;
*/ */
int Fl::dnd() int Fl::dnd()
{ {
#ifdef __APPLE_COCOA__
extern int MACpreparedrag(void);
return MACpreparedrag();
#else
OSErr result; OSErr result;
DragReference dragRef; DragReference dragRef;
result = NewDrag( &dragRef ); result = NewDrag( &dragRef );
@ -82,6 +87,7 @@ int Fl::dnd()
DisposeRgn( region ); DisposeRgn( region );
DisposeDrag( dragRef ); DisposeDrag( dragRef );
return true; return true;
#endif //__APPLE_COCOA__
} }

193
src/fl_font_mac.cxx

@ -33,6 +33,8 @@ extern unsigned fl_utf8toUtf16(const char* src, unsigned srclen, unsigned short*
// if no font has been selected yet by the user, get one. // if no font has been selected yet by the user, get one.
#define check_default_font() {if (!fl_fontsize) fl_font(0, 12);} #define check_default_font() {if (!fl_fontsize) fl_font(0, 12);}
static const CGAffineTransform font_mx = { 1, 0, 0, -1, 0, 0 };
Fl_Font_Descriptor::Fl_Font_Descriptor(const char* name, Fl_Fontsize Size) { Fl_Font_Descriptor::Fl_Font_Descriptor(const char* name, Fl_Fontsize Size) {
next = 0; next = 0;
# if HAVE_GL # if HAVE_GL
@ -43,12 +45,38 @@ Fl_Font_Descriptor::Fl_Font_Descriptor(const char* name, Fl_Fontsize Size) {
// OpenGL needs those for its font handling // OpenGL needs those for its font handling
q_name = strdup(name); q_name = strdup(name);
size = Size; size = Size;
minsize = maxsize = Size;
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
if(CTFontCreateWithName != NULL) {
CFStringRef str = CFStringCreateWithCString(NULL, name, kCFStringEncodingUTF8);
fontref = CTFontCreateWithName(str, size, NULL);
CGGlyph glyph[2];
const UniChar A[2]={'W','.'};
CTFontGetGlyphsForCharacters(fontref, A, glyph, 2);
CGSize advances[2];
double w;
CTFontGetAdvancesForGlyphs(fontref, kCTFontHorizontalOrientation, glyph, advances, 2);
w = advances[0].width;
if( abs(advances[0].width - advances[1].width) < 1E-2 ) {//this is a fixed-width font
//slightly rescale fixed-width fonts so the character width has an integral value
CFRelease(fontref);
CGFloat fsize = size / ( w/floor(w + 0.5) );
fontref = CTFontCreateWithName(str, fsize, NULL);
w = CTFontGetAdvancesForGlyphs(fontref, kCTFontHorizontalOrientation, glyph, NULL, 1);
}
CFRelease(str);
ascent = (short)(CTFontGetAscent(fontref) + 0.5);
descent = (short)(CTFontGetDescent(fontref) + 0.5);
q_width = w + 0.5;
}
else {
#endif
#if ! __LP64__
OSStatus err; OSStatus err;
// fill our structure with a few default values // fill our structure with a few default values
ascent = Size*3/4; ascent = Size*3/4;
descent = Size-ascent; descent = Size-ascent;
q_width = Size*2/3; q_width = Size*2/3;
minsize = maxsize = Size;
// now use ATS to get the actual Glyph size information // now use ATS to get the actual Glyph size information
// say that our passed-in name is encoded as UTF-8, since this works for plain ASCII names too... // say that our passed-in name is encoded as UTF-8, since this works for plain ASCII names too...
CFStringRef cfname = CFStringCreateWithCString(0L, name, kCFStringEncodingUTF8); CFStringRef cfname = CFStringCreateWithCString(0L, name, kCFStringEncodingUTF8);
@ -112,6 +140,10 @@ Fl_Font_Descriptor::Fl_Font_Descriptor(const char* name, Fl_Fontsize Size) {
// cause ATSU to find a suitable font to render any chars the current font can't do... // cause ATSU to find a suitable font to render any chars the current font can't do...
ATSUSetTransientFontMatching (layout, true); ATSUSetTransientFontMatching (layout, true);
# endif # endif
#endif//__LP64__
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
}
#endif
} }
Fl_Font_Descriptor* fl_fontsize = 0L; Fl_Font_Descriptor* fl_fontsize = 0L;
@ -132,8 +164,12 @@ Fl_Font_Descriptor::~Fl_Font_Descriptor() {
#endif #endif
*/ */
if (this == fl_fontsize) fl_fontsize = 0; if (this == fl_fontsize) fl_fontsize = 0;
ATSUDisposeTextLayout(layout); #if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
ATSUDisposeStyle(style); if(CTFontCreateWithName != NULL) CFRelease(fontref);
#else
/* ATSUDisposeTextLayout(layout);
ATSUDisposeStyle(style); */
#endif
} }
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
@ -235,6 +271,24 @@ double fl_width(const UniChar* txt, int n) {
if (!fl_fontsize) if (!fl_fontsize)
return 8*n; // user must select a font first! return 8*n; // user must select a font first!
} }
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
if(CTFontCreateWithName != NULL) {
CTFontRef fontref = fl_fontsize->fontref;
CFStringRef str = CFStringCreateWithBytes(NULL, (const UInt8*)txt, n * sizeof(UniChar), kCFStringEncodingUTF16, false);
CFAttributedStringRef astr = CFAttributedStringCreate(NULL, str, NULL);
CFMutableAttributedStringRef mastr = CFAttributedStringCreateMutableCopy(NULL, 0, astr);
CFRelease(astr);
CFAttributedStringSetAttribute(mastr, CFRangeMake(0, CFStringGetLength(str)), kCTFontAttributeName, fontref);
CFRelease(str);
CTLineRef ctline = CTLineCreateWithAttributedString(mastr);
CFRelease(mastr);
double retval = CTLineGetTypographicBounds(ctline, NULL, NULL, NULL);
CFRelease(ctline);
return retval;
}
else {
#endif
#if ! __LP64__
OSStatus err; OSStatus err;
Fixed bBefore, bAfter, bAscent, bDescent; Fixed bBefore, bAfter, bAscent, bDescent;
ATSUTextLayout layout; ATSUTextLayout layout;
@ -256,6 +310,10 @@ double fl_width(const UniChar* txt, int n) {
// If err is OK then return length, else return 0. Or something... // If err is OK then return length, else return 0. Or something...
int len = FixedToInt(bAfter); int len = FixedToInt(bAfter);
return len; return len;
#endif
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
}
#endif
} }
double fl_width(const char* txt, int n) { double fl_width(const char* txt, int n) {
@ -281,6 +339,30 @@ void fl_text_extents(const UniChar* txt, int n, int &dx, int &dy, int &w, int &h
h = 8.0; h = 8.0;
return; return;
} }
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
if(CTFontCreateWithName != NULL) {
CTFontRef fontref = fl_fontsize->fontref;
CFStringRef str16 = CFStringCreateWithBytes(NULL, (const UInt8*)txt, n *sizeof(UniChar), kCFStringEncodingUTF16, false);
CFAttributedStringRef astr = CFAttributedStringCreate(NULL, str16, NULL);
CFMutableAttributedStringRef mastr = CFAttributedStringCreateMutableCopy(NULL, 0, astr);
CFRelease(astr);
CFAttributedStringSetAttribute(mastr, CFRangeMake(0, CFStringGetLength(str16)), kCTFontAttributeName, fontref);
CFRelease(str16);
CTLineRef ctline = CTLineCreateWithAttributedString(mastr);
CFRelease(mastr);
CGContextSetTextPosition(fl_gc, 0, 0);
CGContextSetShouldAntialias(fl_gc, true);
CGRect rect = CTLineGetImageBounds(ctline, fl_gc);
CGContextSetShouldAntialias(fl_gc, false);
CFRelease(ctline);
dx = floor(rect.origin.x + 0.5);
dy = floor(- rect.origin.y - rect.size.height + 0.5);
w = rect.size.width + 0.5;
h = rect.size.height + 0.5;
}
else {
#endif
#if ! __LP64__
OSStatus err; OSStatus err;
ATSUTextLayout layout; ATSUTextLayout layout;
ByteCount iSize; ByteCount iSize;
@ -304,6 +386,10 @@ void fl_text_extents(const UniChar* txt, int n, int &dx, int &dy, int &w, int &h
dx = bbox.left; dx = bbox.left;
dy = -bbox.bottom; dy = -bbox.bottom;
//printf("r: %d l: %d t: %d b: %d w: %d h: %d\n", bbox.right, bbox.left, bbox.top, bbox.bottom, w, h); //printf("r: %d l: %d t: %d b: %d w: %d h: %d\n", bbox.right, bbox.left, bbox.top, bbox.bottom, w, h);
#endif
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
}
#endif
return; return;
} // fl_text_extents } // fl_text_extents
@ -320,13 +406,76 @@ void fl_draw(const char* str, int n, int x, int y) {
fl_draw(str, n, (float)x-0.0f, (float)y-0.5f); fl_draw(str, n, (float)x-0.0f, (float)y-0.5f);
} }
#if defined(__APPLE_COCOA__)
static unsigned fl_cmap[256] = {
#include "fl_cmap.h" // this is a file produced by "cmap.cxx":
};
CGColorRef flcolortocgcolor(Fl_Color i)
{
int index;
uchar r, g, b;
if (i & 0xFFFFFF00) {
// translate rgb colors into color index
r = i>>24;
g = i>>16;
b = i>> 8;
} else {
// translate index into rgb:
index = i;
unsigned c = fl_cmap[i];
r = c>>24;
g = c>>16;
b = c>> 8;
}
CGFloat components[4] = {r/255.0f, g/255.0f, b/255.0f, 1.};
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
return CGColorCreate(CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB), components);
#else
return CGColorCreate(CGColorSpaceCreateWithName(kCGColorSpaceUserRGB), components);
#endif
}
#endif
void fl_draw(const char *str, int n, float x, float y) { void fl_draw(const char *str, int n, float x, float y) {
OSStatus err;
// convert to UTF-16 first
UniChar *uniStr = mac_Utf8_to_Utf16(str, n, &n);
// avoid a crash if no font has been selected by user yet ! // avoid a crash if no font has been selected by user yet !
check_default_font(); check_default_font();
// convert to UTF-16 first
UniChar *uniStr = mac_Utf8_to_Utf16(str, n, &n);
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
if(CTFontCreateWithName != NULL) {
CFStringRef keys[2];
CFTypeRef values[2];
CFStringRef str16 = CFStringCreateWithBytes(NULL, (const UInt8*)uniStr, n * sizeof(UniChar), kCFStringEncodingUTF16, false);
CGColorRef color = flcolortocgcolor(fl_color());
keys[0] = kCTFontAttributeName;
keys[1] = kCTForegroundColorAttributeName;
values[0] = fl_fontsize->fontref;
values[1] = color;
CFDictionaryRef attributes = CFDictionaryCreate(kCFAllocatorDefault,
(const void**)&keys,
(const void**)&values,
2,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFAttributedStringRef mastr = CFAttributedStringCreate(kCFAllocatorDefault, str16, attributes);
CFRelease(str16);
CFRelease(attributes);
CFRelease(color);
CTLineRef ctline = CTLineCreateWithAttributedString(mastr);
CFRelease(mastr);
CGContextSetTextMatrix(fl_gc, font_mx);
CGContextSetTextPosition(fl_gc, x, y);
CGContextSetShouldAntialias(fl_gc, true);
CTLineDraw(ctline, fl_gc);
CGContextSetShouldAntialias(fl_gc, false);
CFRelease(ctline);
}
else {
#endif
#if ! __LP64__
OSStatus err;
// now collect our ATSU resources // now collect our ATSU resources
ATSUTextLayout layout = fl_fontsize->layout; ATSUTextLayout layout = fl_fontsize->layout;
@ -337,9 +486,24 @@ void fl_draw(const char *str, int n, float x, float y) {
err = ATSUSetTextPointerLocation(layout, uniStr, kATSUFromTextBeginning, n, n); err = ATSUSetTextPointerLocation(layout, uniStr, kATSUFromTextBeginning, n, n);
err = ATSUDrawText(layout, kATSUFromTextBeginning, n, FloatToFixed(x), FloatToFixed(y)); err = ATSUDrawText(layout, kATSUFromTextBeginning, n, FloatToFixed(x), FloatToFixed(y));
#endif
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
}
#endif
} }
void fl_draw(int angle, const char *str, int n, int x, int y) { void fl_draw(int angle, const char *str, int n, int x, int y) {
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
if(CTFontCreateWithName != NULL) {
CGContextSaveGState(fl_gc);
CGContextTranslateCTM(fl_gc, x, y);
CGContextRotateCTM(fl_gc, - angle*(M_PI/180) );
fl_draw(str, n, (float)0., (float)0.);
CGContextRestoreGState(fl_gc);
}
else {
#endif
#if ! __LP64__
OSStatus err; OSStatus err;
// convert to UTF-16 first // convert to UTF-16 first
UniChar *uniStr = mac_Utf8_to_Utf16(str, n, &n); UniChar *uniStr = mac_Utf8_to_Utf16(str, n, &n);
@ -360,10 +524,21 @@ void fl_draw(int angle, const char *str, int n, int x, int y) {
//restore layout baseline //restore layout baseline
ang = IntToFixed(0); ang = IntToFixed(0);
ATSUSetLayoutControls(layout, 2, iTag, iSize, aAttr); ATSUSetLayoutControls(layout, 2, iTag, iSize, aAttr);
#endif
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
}
#endif
} }
void fl_rtl_draw(const char* c, int n, int x, int y) { void fl_rtl_draw(const char* c, int n, int x, int y) {
// I guess with ATSU the thing to do is force the layout mode to RTL and let ATSU draw the text... #if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
if(CTFontCreateWithName != NULL) {
fl_draw(c, n, x - fl_width(c, n), y); //to check;
}
else {
#endif
#if ! __LP64__
// I guess with ATSU the thing to do is force the layout mode to RTL and let ATSU draw the text...
double offs = fl_width(c, n); double offs = fl_width(c, n);
OSStatus err; OSStatus err;
// convert to UTF-16 first // convert to UTF-16 first
@ -379,6 +554,10 @@ void fl_rtl_draw(const char* c, int n, int x, int y) {
err = ATSUSetTextPointerLocation(layout, uniStr, kATSUFromTextBeginning, n, n); err = ATSUSetTextPointerLocation(layout, uniStr, kATSUFromTextBeginning, n, n);
err = ATSUDrawText(layout, kATSUFromTextBeginning, n, FloatToFixed(x-offs), FloatToFixed(y)); err = ATSUDrawText(layout, kATSUFromTextBeginning, n, FloatToFixed(x-offs), FloatToFixed(y));
#endif
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
}
#endif
} }
// //

11
src/fl_line_style.cxx

@ -40,7 +40,7 @@
float fl_quartz_line_width_ = 1.0f; float fl_quartz_line_width_ = 1.0f;
static enum CGLineCap fl_quartz_line_cap_ = kCGLineCapButt; static enum CGLineCap fl_quartz_line_cap_ = kCGLineCapButt;
static enum CGLineJoin fl_quartz_line_join_ = kCGLineJoinMiter; static enum CGLineJoin fl_quartz_line_join_ = kCGLineJoinMiter;
static float *fl_quartz_line_pattern = 0; static CGFloat *fl_quartz_line_pattern = 0;
static int fl_quartz_line_pattern_size = 0; static int fl_quartz_line_pattern_size = 0;
void fl_quartz_restore_line_style_() { void fl_quartz_restore_line_style_() {
CGContextSetLineWidth(fl_gc, fl_quartz_line_width_); CGContextSetLineWidth(fl_gc, fl_quartz_line_width_);
@ -145,9 +145,9 @@ void fl_line_style(int style, int width, char* dashes) {
fl_quartz_line_cap_ = Cap[(style>>8)&3]; fl_quartz_line_cap_ = Cap[(style>>8)&3];
fl_quartz_line_join_ = Join[(style>>12)&3]; fl_quartz_line_join_ = Join[(style>>12)&3];
char *d = dashes; char *d = dashes;
static float pattern[16]; static CGFloat pattern[16];
if (d && *d) { if (d && *d) {
float *p = pattern; CGFloat *p = pattern;
while (*d) { *p++ = (float)*d++; } while (*d) { *p++ = (float)*d++; }
fl_quartz_line_pattern = pattern; fl_quartz_line_pattern = pattern;
fl_quartz_line_pattern_size = d-dashes; fl_quartz_line_pattern_size = d-dashes;
@ -162,7 +162,7 @@ void fl_line_style(int style, int width, char* dashes) {
dash = char(3*width); dash = char(3*width);
dot = gap = char(width); dot = gap = char(width);
} }
float *p = pattern; CGFloat *p = pattern;
switch (style & 0xff) { switch (style & 0xff) {
case FL_DASH: *p++ = dash; *p++ = gap; break; case FL_DASH: *p++ = dash; *p++ = gap; break;
case FL_DOT: *p++ = dot; *p++ = gap; break; case FL_DOT: *p++ = dot; *p++ = gap; break;
@ -172,7 +172,8 @@ void fl_line_style(int style, int width, char* dashes) {
fl_quartz_line_pattern_size = p-pattern; fl_quartz_line_pattern_size = p-pattern;
fl_quartz_line_pattern = pattern; fl_quartz_line_pattern = pattern;
} else { } else {
fl_quartz_line_pattern = 0; fl_quartz_line_pattern_size = 0; fl_quartz_line_pattern = 0;
fl_quartz_line_pattern_size = 0;
} }
fl_quartz_restore_line_style_(); fl_quartz_restore_line_style_();
#else #else

32
src/fl_read_image_mac.cxx

@ -26,9 +26,9 @@
// //
#include <config.h> #include <config.h>
#ifdef __APPLE_COCOA__
// warning: this function is only implemented in Quickdraw. The function extern unsigned char *MACbitmapFromRectOfWindow(Fl_Window *win, int x, int y, int w, int h, int *bytesPerPixel);
// below may not work If FLTK is compiled with Quartz enabled #endif
// //
// 'fl_read_image()' - Read an image from the current window. // 'fl_read_image()' - Read an image from the current window.
@ -41,6 +41,29 @@ fl_read_image(uchar *p, // I - Pixel buffer or NULL to allocate
int w, // I - Width of area to read int w, // I - Width of area to read
int h, // I - Height of area to read int h, // I - Height of area to read
int alpha) { // I - Alpha value for image (0 for none) int alpha) { // I - Alpha value for image (0 for none)
#if defined(__APPLE_COCOA__)
Fl_Window *window = Fl_Window::current();
while(window->window()) window = window->window();
int delta;
uchar *base = MACbitmapFromRectOfWindow(window,x,y,w,h,&delta);
int rowBytes = delta*w;
// Allocate the image data array as needed...
int d = alpha ? 4 : 3;
if (!p) p = new uchar[w * h * d];
// Initialize the default colors/alpha in the whole image...
memset(p, alpha, w * h * d);
// Copy the image from the off-screen buffer to the memory buffer.
int idx, idy; // Current X & Y in image
uchar *pdst, *psrc;
for (idy = 0, pdst = p; idy < h; idy ++) {
for (idx = 0, psrc = base + idy * rowBytes; idx < w; idx ++, psrc += delta, pdst += d) {
/*R*/ pdst[0] = psrc[0];
/*G*/ pdst[1] = psrc[1];
/*B*/ pdst[2] = psrc[2];
}
}
delete base;
#else
Rect src, // Source rectangle Rect src, // Source rectangle
dst; // Destination rectangle dst; // Destination rectangle
GWorldPtr osbuffer; // Temporary off-screen buffer for copy GWorldPtr osbuffer; // Temporary off-screen buffer for copy
@ -128,7 +151,8 @@ fl_read_image(uchar *p, // I - Pixel buffer or NULL to allocate
DisposeGWorld(osbuffer); DisposeGWorld(osbuffer);
SetPort(srcPort); SetPort(srcPort);
return p; #endif
return p;
} }

178
src/fl_rect.cxx

@ -59,10 +59,18 @@ void fl_rect(int x, int y, int w, int h) {
LineTo(fl_gc, x, y+h-1); LineTo(fl_gc, x, y+h-1);
LineTo(fl_gc, x, y); LineTo(fl_gc, x, y);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, true);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
#endif
CGRect rect = CGRectMake(x, y, w-1, h-1); CGRect rect = CGRectMake(x, y, w-1, h-1);
CGContextStrokeRect(fl_gc, rect); CGContextStrokeRect(fl_gc, rect);
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, false);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#endif
#else #else
# error unsupported platform # error unsupported platform
#endif #endif
@ -81,10 +89,18 @@ void fl_rectf(int x, int y, int w, int h) {
rect.right = x + w; rect.bottom = y + h; rect.right = x + w; rect.bottom = y + h;
FillRect(fl_gc, &rect, fl_brush()); FillRect(fl_gc, &rect, fl_brush());
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, true);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
#endif
CGRect rect = CGRectMake(x, y, w-1, h-1); CGRect rect = CGRectMake(x, y, w-1, h-1);
CGContextFillRect(fl_gc, rect); CGContextFillRect(fl_gc, rect);
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, false);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#endif
#else #else
# error unsupported platform # error unsupported platform
#endif #endif
@ -99,11 +115,19 @@ void fl_xyline(int x, int y, int x1) {
#elif defined(WIN32) #elif defined(WIN32)
MoveToEx(fl_gc, x, y, 0L); LineTo(fl_gc, x1+1, y); MoveToEx(fl_gc, x, y, 0L); LineTo(fl_gc, x1+1, y);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, true);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
#endif
CGContextMoveToPoint(fl_gc, x, y); CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x1, y); CGContextAddLineToPoint(fl_gc, x1, y);
CGContextStrokePath(fl_gc); CGContextStrokePath(fl_gc);
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, false);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#endif
#else #else
# error unsupported platform # error unsupported platform
#endif #endif
@ -125,12 +149,20 @@ void fl_xyline(int x, int y, int x1, int y2) {
LineTo(fl_gc, x1, y); LineTo(fl_gc, x1, y);
LineTo(fl_gc, x1, y2); LineTo(fl_gc, x1, y2);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, true);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
#endif
CGContextMoveToPoint(fl_gc, x, y); CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x1, y); CGContextAddLineToPoint(fl_gc, x1, y);
CGContextAddLineToPoint(fl_gc, x1, y2); CGContextAddLineToPoint(fl_gc, x1, y2);
CGContextStrokePath(fl_gc); CGContextStrokePath(fl_gc);
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, false);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#endif
#else #else
#error unsupported platform #error unsupported platform
#endif #endif
@ -155,13 +187,21 @@ void fl_xyline(int x, int y, int x1, int y2, int x3) {
LineTo(fl_gc, x1, y2); LineTo(fl_gc, x1, y2);
LineTo(fl_gc, x3, y2); LineTo(fl_gc, x3, y2);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, true);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
#endif
CGContextMoveToPoint(fl_gc, x, y); CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x1, y); CGContextAddLineToPoint(fl_gc, x1, y);
CGContextAddLineToPoint(fl_gc, x1, y2); CGContextAddLineToPoint(fl_gc, x1, y2);
CGContextAddLineToPoint(fl_gc, x3, y2); CGContextAddLineToPoint(fl_gc, x3, y2);
CGContextStrokePath(fl_gc); CGContextStrokePath(fl_gc);
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, false);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#endif
#else #else
# error unsupported platform # error unsupported platform
#endif #endif
@ -178,11 +218,19 @@ void fl_yxline(int x, int y, int y1) {
else y1++; else y1++;
MoveToEx(fl_gc, x, y, 0L); LineTo(fl_gc, x, y1); MoveToEx(fl_gc, x, y, 0L); LineTo(fl_gc, x, y1);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, true);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
#endif
CGContextMoveToPoint(fl_gc, x, y); CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x, y1); CGContextAddLineToPoint(fl_gc, x, y1);
CGContextStrokePath(fl_gc); CGContextStrokePath(fl_gc);
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, false);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#endif
#else #else
# error unsupported platform # error unsupported platform
#endif #endif
@ -204,12 +252,20 @@ void fl_yxline(int x, int y, int y1, int x2) {
LineTo(fl_gc, x, y1); LineTo(fl_gc, x, y1);
LineTo(fl_gc, x2, y1); LineTo(fl_gc, x2, y1);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, true);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
#endif
CGContextMoveToPoint(fl_gc, x, y); CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x, y1); CGContextAddLineToPoint(fl_gc, x, y1);
CGContextAddLineToPoint(fl_gc, x2, y1); CGContextAddLineToPoint(fl_gc, x2, y1);
CGContextStrokePath(fl_gc); CGContextStrokePath(fl_gc);
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, false);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#endif
#else #else
# error unsupported platform # error unsupported platform
#endif #endif
@ -234,13 +290,21 @@ void fl_yxline(int x, int y, int y1, int x2, int y3) {
LineTo(fl_gc, x2, y1); LineTo(fl_gc, x2, y1);
LineTo(fl_gc, x2, y3); LineTo(fl_gc, x2, y3);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, true);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
#endif
CGContextMoveToPoint(fl_gc, x, y); CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x, y1); CGContextAddLineToPoint(fl_gc, x, y1);
CGContextAddLineToPoint(fl_gc, x2, y1); CGContextAddLineToPoint(fl_gc, x2, y1);
CGContextAddLineToPoint(fl_gc, x2, y3); CGContextAddLineToPoint(fl_gc, x2, y3);
CGContextStrokePath(fl_gc); CGContextStrokePath(fl_gc);
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, false);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#endif
#else #else
# error unsupported platform # error unsupported platform
#endif #endif
@ -259,11 +323,19 @@ void fl_line(int x, int y, int x1, int y1) {
// functions will not draw the last point ("it's a feature!"...) // functions will not draw the last point ("it's a feature!"...)
SetPixel(fl_gc, x1, y1, fl_RGB()); SetPixel(fl_gc, x1, y1, fl_RGB());
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
if (fl_quartz_line_width_==1.0f ) CGContextSetShouldAntialias(fl_gc, false); #ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, true);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
#endif
CGContextMoveToPoint(fl_gc, x, y); CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x1, y1); CGContextAddLineToPoint(fl_gc, x1, y1);
CGContextStrokePath(fl_gc); CGContextStrokePath(fl_gc);
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, false);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#endif
#else #else
# error unsupported platform # error unsupported platform
#endif #endif
@ -287,12 +359,20 @@ void fl_line(int x, int y, int x1, int y1, int x2, int y2) {
// functions will not draw the last point ("it's a feature!"...) // functions will not draw the last point ("it's a feature!"...)
SetPixel(fl_gc, x2, y2, fl_RGB()); SetPixel(fl_gc, x2, y2, fl_RGB());
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
if (fl_quartz_line_width_==1.0f ) CGContextSetShouldAntialias(fl_gc, false); #ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, true);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
#endif
CGContextMoveToPoint(fl_gc, x, y); CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x1, y1); CGContextAddLineToPoint(fl_gc, x1, y1);
CGContextAddLineToPoint(fl_gc, x2, y2); CGContextAddLineToPoint(fl_gc, x2, y2);
CGContextStrokePath(fl_gc); CGContextStrokePath(fl_gc);
if (fl_quartz_line_width_==1.0f ) CGContextSetShouldAntialias(fl_gc, true); #ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, false);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#endif
#else #else
# error unsupported platform # error unsupported platform
#endif #endif
@ -315,11 +395,17 @@ void fl_loop(int x, int y, int x1, int y1, int x2, int y2) {
LineTo(fl_gc, x2, y2); LineTo(fl_gc, x2, y2);
LineTo(fl_gc, x, y); LineTo(fl_gc, x, y);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, true);
#endif
CGContextMoveToPoint(fl_gc, x, y); CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x1, y1); CGContextAddLineToPoint(fl_gc, x1, y1);
CGContextAddLineToPoint(fl_gc, x2, y2); CGContextAddLineToPoint(fl_gc, x2, y2);
CGContextClosePath(fl_gc); CGContextClosePath(fl_gc);
CGContextStrokePath(fl_gc); CGContextStrokePath(fl_gc);
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, false);
#endif
#else #else
# error unsupported platform # error unsupported platform
#endif #endif
@ -344,12 +430,18 @@ void fl_loop(int x, int y, int x1, int y1, int x2, int y2, int x3, int y3) {
LineTo(fl_gc, x3, y3); LineTo(fl_gc, x3, y3);
LineTo(fl_gc, x, y); LineTo(fl_gc, x, y);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, true);
#endif
CGContextMoveToPoint(fl_gc, x, y); CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x1, y1); CGContextAddLineToPoint(fl_gc, x1, y1);
CGContextAddLineToPoint(fl_gc, x2, y2); CGContextAddLineToPoint(fl_gc, x2, y2);
CGContextAddLineToPoint(fl_gc, x3, y3); CGContextAddLineToPoint(fl_gc, x3, y3);
CGContextClosePath(fl_gc); CGContextClosePath(fl_gc);
CGContextStrokePath(fl_gc); CGContextStrokePath(fl_gc);
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, false);
#endif
#else #else
# error unsupported platform # error unsupported platform
#endif #endif
@ -371,11 +463,17 @@ void fl_polygon(int x, int y, int x1, int y1, int x2, int y2) {
SelectObject(fl_gc, fl_brush()); SelectObject(fl_gc, fl_brush());
Polygon(fl_gc, p, 3); Polygon(fl_gc, p, 3);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, true);
#endif
CGContextMoveToPoint(fl_gc, x, y); CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x1, y1); CGContextAddLineToPoint(fl_gc, x1, y1);
CGContextAddLineToPoint(fl_gc, x2, y2); CGContextAddLineToPoint(fl_gc, x2, y2);
CGContextClosePath(fl_gc); CGContextClosePath(fl_gc);
CGContextFillPath(fl_gc); CGContextFillPath(fl_gc);
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, false);
#endif
#else #else
# error unsupported platform # error unsupported platform
#endif #endif
@ -398,12 +496,18 @@ void fl_polygon(int x, int y, int x1, int y1, int x2, int y2, int x3, int y3) {
SelectObject(fl_gc, fl_brush()); SelectObject(fl_gc, fl_brush());
Polygon(fl_gc, p, 4); Polygon(fl_gc, p, 4);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, true);
#endif
CGContextMoveToPoint(fl_gc, x, y); CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x1, y1); CGContextAddLineToPoint(fl_gc, x1, y1);
CGContextAddLineToPoint(fl_gc, x2, y2); CGContextAddLineToPoint(fl_gc, x2, y2);
CGContextAddLineToPoint(fl_gc, x3, y3); CGContextAddLineToPoint(fl_gc, x3, y3);
CGContextClosePath(fl_gc); CGContextClosePath(fl_gc);
CGContextFillPath(fl_gc); CGContextFillPath(fl_gc);
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, false);
#endif
#else #else
# error unsupported platform # error unsupported platform
#endif #endif
@ -418,11 +522,19 @@ void fl_point(int x, int y) {
#elif defined(WIN32) #elif defined(WIN32)
SetPixel(fl_gc, x, y, fl_RGB()); SetPixel(fl_gc, x, y, fl_RGB());
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, true);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
#endif
CGContextMoveToPoint(fl_gc, x-.5, y); // Quartz needs a line that is one pixel long, or it will not draw anything CGContextMoveToPoint(fl_gc, x-.5, y); // Quartz needs a line that is one pixel long, or it will not draw anything
CGContextAddLineToPoint(fl_gc, x+.5, y); CGContextAddLineToPoint(fl_gc, x+.5, y);
CGContextStrokePath(fl_gc); CGContextStrokePath(fl_gc);
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, false);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#endif
#else #else
# error unsupported platform # error unsupported platform
#endif #endif
@ -467,6 +579,16 @@ void fl_restore_clip() {
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
if ( fl_window ) // clipping for a true window if ( fl_window ) // clipping for a true window
{ {
#ifdef __APPLE_COCOA__
Fl_X::q_clear_clipping();
Fl_X::q_fill_context();//flip coords and translate if subwindow
//apply window's clip
CGContextClipToRects(fl_gc, fl_window_region->rects, fl_window_region->count );
//apply additional program clip
if(r) {
CGContextClipToRects(fl_gc, r->rects, r->count);
}
#else
GrafPtr port = GetWindowPort( fl_window ); GrafPtr port = GetWindowPort( fl_window );
if ( port ) { if ( port ) {
RgnHandle portClip = NewRgn(); RgnHandle portClip = NewRgn();
@ -479,6 +601,7 @@ void fl_restore_clip() {
Fl_X::q_fill_context(); Fl_X::q_fill_context();
DisposeRgn( portClip ); DisposeRgn( portClip );
} }
#endif
} else if (fl_gc) { // clipping for an offscreen drawing world (CGBitmap) } else if (fl_gc) { // clipping for an offscreen drawing world (CGBitmap)
Rect portRect; Rect portRect;
portRect.top = 0; portRect.top = 0;
@ -486,8 +609,13 @@ void fl_restore_clip() {
portRect.bottom = CGBitmapContextGetHeight(fl_gc); portRect.bottom = CGBitmapContextGetHeight(fl_gc);
portRect.right = CGBitmapContextGetWidth(fl_gc); portRect.right = CGBitmapContextGetWidth(fl_gc);
Fl_X::q_clear_clipping(); Fl_X::q_clear_clipping();
if (r) if (r) {
#ifdef __APPLE_COCOA__
CGContextClipToRects(fl_gc, r->rects, r->count);
#else
ClipCGContextToRegion(fl_gc, &portRect, r); ClipCGContextToRegion(fl_gc, &portRect, r);
#endif
}
Fl_X::q_fill_context(); Fl_X::q_fill_context();
} }
#else #else
@ -534,19 +662,33 @@ void fl_push_clip(int x, int y, int w, int h) {
#elif defined(WIN32) #elif defined(WIN32)
CombineRgn(r,r,current,RGN_AND); CombineRgn(r,r,current,RGN_AND);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
XDestroyRegion(r);
r = MacRectRegionIntersect(current, x,y,w,h);
#else
SectRgn(r, current, r); SectRgn(r, current, r);
#endif
#else #else
# error unsupported platform # error unsupported platform
#endif #endif
} }
#if defined(__APPLE_QUARTZ__)
else {
r = XRectangleRegion(x,y,w,h);
}
#endif
} else { // make empty clip region: } else { // make empty clip region:
#if defined(USE_X11) #if defined(USE_X11)
r = XCreateRegion(); r = XCreateRegion();
#elif defined(WIN32) #elif defined(WIN32)
r = CreateRectRgn(0,0,0,0); r = CreateRectRgn(0,0,0,0);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
r = NULL;
#else
r = NewRgn(); r = NewRgn();
SetEmptyRgn(r); SetEmptyRgn(r);
#endif
#else #else
# error unsupported platform # error unsupported platform
#endif #endif
@ -604,9 +746,18 @@ int fl_not_clipped(int x, int y, int w, int h) {
return RectInRegion(r,&rect); return RectInRegion(r,&rect);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
if (!r) return 1; if (!r) return 1;
#ifdef __APPLE_COCOA__
CGRect arg = CGRectMake(x,y,w - 1,h - 1);
for(int i = 0; i < r->count; i++) {
CGRect test = CGRectIntersection(r->rects[i], arg);
if( ! CGRectIsEmpty(test)) return 1;
}
return 0;
#else
Rect rect; Rect rect;
rect.left = x; rect.top = y; rect.right = x+w; rect.bottom = y+h; rect.left = x; rect.top = y; rect.right = x+w; rect.bottom = y+h;
return RectInRgn(&rect, r); return RectInRgn(&rect, r);
#endif
#else #else
# error unsupported platform # error unsupported platform
#endif #endif
@ -673,6 +824,24 @@ int fl_clip_box(int x, int y, int w, int h, int& X, int& Y, int& W, int& H){
DeleteObject(rr); DeleteObject(rr);
return ret; return ret;
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
CGRect arg = CGRectMake(x,y,w - 1,h - 1);
CGRect u = CGRectMake(0,0,0,0);
CGRect test;
for(int i = 0; i < r->count; i++) {
test = CGRectIntersection(r->rects[i], arg);
if( ! CGRectIsEmpty(test) ) {
if(CGRectIsEmpty(u)) u = test;
else u = CGRectUnion(u, test);
}
}
X = u.origin.x;
Y = u.origin.y;
W = u.size.width;
H = u.size.height;
if(CGRectIsEmpty(u)) W = H = 0;
return ! CGRectEqualToRect(arg, u);
#else
RgnHandle rr = NewRgn(); RgnHandle rr = NewRgn();
SetRectRgn( rr, x, y, x+w, y+h ); SetRectRgn( rr, x, y, x+w, y+h );
SectRgn( r, rr, rr ); SectRgn( r, rr, rr );
@ -685,6 +854,7 @@ int fl_clip_box(int x, int y, int w, int h, int& X, int& Y, int& W, int& H){
if ( H==0 ) return 2; if ( H==0 ) return 2;
if ( h==H && w==W ) return 0; if ( h==H && w==W ) return 0;
return 0; return 0;
#endif
#else #else
# error unsupported platform # error unsupported platform
#endif #endif

12
src/fl_scroll_area.cxx

@ -151,6 +151,16 @@ void fl_scroll(int X, int Y, int W, int H, int dx, int dy,
BitBlt(fl_gc, dest_x, dest_y, src_w, src_h, fl_gc, src_x, src_y,SRCCOPY); BitBlt(fl_gc, dest_x, dest_y, src_w, src_h, fl_gc, src_x, src_y,SRCCOPY);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
#if defined(__APPLE_COCOA__)
extern CGImageRef MAC_CGImageFromRectOfWindow(Fl_Window*, int x, int y, int w, int h);
CGImageRef img = MAC_CGImageFromRectOfWindow(Fl_Window::current(), src_x, src_y, src_w, src_h);
CGRect rect = { { dest_x, dest_y }, { src_w, src_h } };
Fl_X::q_begin_image(rect, 0, 0, src_w, src_h);
CGContextDrawImage(fl_gc, rect, img);
Fl_X::q_end_image();
CFRelease(img);
#else
// warning: there does not seem to be an equivalent to this function in Quartz // warning: there does not seem to be an equivalent to this function in Quartz
// ScrollWindowRect is a QuickDraw function and won't work here. // ScrollWindowRect is a QuickDraw function and won't work here.
// Since on OS X all windows are fully double buffered, we need not // Since on OS X all windows are fully double buffered, we need not
@ -161,6 +171,8 @@ void fl_scroll(int X, int Y, int W, int H, int dx, int dy,
static RGBColor fg = { 0x0000, 0x0000, 0x0000 }; RGBForeColor( &fg ); static RGBColor fg = { 0x0000, 0x0000, 0x0000 }; RGBForeColor( &fg );
CopyBits( GetPortBitMapForCopyBits( GetWindowPort(fl_window) ), CopyBits( GetPortBitMapForCopyBits( GetWindowPort(fl_window) ),
GetPortBitMapForCopyBits( GetWindowPort(fl_window) ), &src, &dst, srcCopy, 0L); GetPortBitMapForCopyBits( GetWindowPort(fl_window) ), &src, &dst, srcCopy, 0L);
#endif
#else #else
# error unsupported platform # error unsupported platform
#endif #endif

31
src/fl_set_fonts_mac.cxx

@ -60,6 +60,33 @@ static int fl_free_font = FL_FREE_FONT;
Fl_Font Fl::set_fonts(const char* xstarname) { Fl_Font Fl::set_fonts(const char* xstarname) {
#pragma unused ( xstarname ) #pragma unused ( xstarname )
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
if(CTFontCreateWithFontDescriptor != NULL) {
int value[1] = {1};
CFDictionaryRef dict = CFDictionaryCreate(NULL, (const void **)kCTFontCollectionRemoveDuplicatesOption,
(const void **)&value, 1, NULL, NULL);
CTFontCollectionRef fcref = CTFontCollectionCreateFromAvailableFonts(dict);
CFRelease(dict);
CFArrayRef arrayref = CTFontCollectionCreateMatchingFontDescriptors(fcref);
CFRelease(fcref);
CFIndex count = CFArrayGetCount(arrayref);
CFIndex i;
for (i = 0; i < count; i++) {
CTFontDescriptorRef fdesc = (CTFontDescriptorRef)CFArrayGetValueAtIndex(arrayref, i);
CTFontRef font = CTFontCreateWithFontDescriptor(fdesc, 0., NULL);
CFStringRef cfname = CTFontCopyPostScriptName(font);
CFRelease(font);
static char fname[100];
CFStringGetCString(cfname, fname, sizeof(fname), kCFStringEncodingUTF8);
CFRelease(cfname);
Fl::set_font((Fl_Font)(fl_free_font++), strdup(fname));
}
CFRelease(arrayref);
return (Fl_Font)fl_free_font;
}
else {
#endif
#if ! __LP64__
#if defined(OLD__APPLE_QUARTZ__) #if defined(OLD__APPLE_QUARTZ__)
ATSFontIterator it; ATSFontIterator it;
ATSFontIteratorCreate(kATSFontContextGlobal, 0L, 0L, kATSOptionFlagsUnRestrictedScope, &it); ATSFontIteratorCreate(kATSFontContextGlobal, 0L, 0L, kATSOptionFlagsUnRestrictedScope, &it);
@ -114,6 +141,10 @@ Fl_Font Fl::set_fonts(const char* xstarname) {
} }
free(oFontIDs); free(oFontIDs);
return (Fl_Font)fl_free_font; return (Fl_Font)fl_free_font;
#endif //OLD__APPLE_QUARTZ__
#endif //__LP64__
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
}
#endif #endif
} }

37
src/fl_vertex.cxx

@ -229,13 +229,21 @@ void fl_end_points() {
#elif defined(WIN32) #elif defined(WIN32)
for (int i=0; i<n; i++) SetPixel(fl_gc, p[i].x, p[i].y, fl_RGB()); for (int i=0; i<n; i++) SetPixel(fl_gc, p[i].x, p[i].y, fl_RGB());
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, true);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
#endif
for (int i=0; i<n; i++) { for (int i=0; i<n; i++) {
CGContextMoveToPoint(fl_gc, p[i].x, p[i].y); CGContextMoveToPoint(fl_gc, p[i].x, p[i].y);
CGContextAddLineToPoint(fl_gc, p[i].x, p[i].y); CGContextAddLineToPoint(fl_gc, p[i].x, p[i].y);
CGContextStrokePath(fl_gc); CGContextStrokePath(fl_gc);
} }
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false); #ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, false);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#endif
#else #else
# error unsupported platform # error unsupported platform
#endif #endif
@ -255,10 +263,16 @@ void fl_end_line() {
if (n>1) Polyline(fl_gc, p, n); if (n>1) Polyline(fl_gc, p, n);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
if (n<=1) return; if (n<=1) return;
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, true);
#endif
CGContextMoveToPoint(fl_gc, p[0].x, p[0].y); CGContextMoveToPoint(fl_gc, p[0].x, p[0].y);
for (int i=1; i<n; i++) for (int i=1; i<n; i++)
CGContextAddLineToPoint(fl_gc, p[i].x, p[i].y); CGContextAddLineToPoint(fl_gc, p[i].x, p[i].y);
CGContextStrokePath(fl_gc); CGContextStrokePath(fl_gc);
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, false);
#endif
#else #else
# error unsupported platform # error unsupported platform
#endif #endif
@ -295,11 +309,17 @@ void fl_end_polygon() {
} }
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
if (n<=1) return; if (n<=1) return;
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, true);
#endif
CGContextMoveToPoint(fl_gc, p[0].x, p[0].y); CGContextMoveToPoint(fl_gc, p[0].x, p[0].y);
for (int i=1; i<n; i++) for (int i=1; i<n; i++)
CGContextAddLineToPoint(fl_gc, p[i].x, p[i].y); CGContextAddLineToPoint(fl_gc, p[i].x, p[i].y);
CGContextClosePath(fl_gc); CGContextClosePath(fl_gc);
CGContextFillPath(fl_gc); CGContextFillPath(fl_gc);
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, false);
#endif
#else #else
# error unsupported platform # error unsupported platform
#endif #endif
@ -370,11 +390,17 @@ void fl_end_complex_polygon() {
} }
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
if (n<=1) return; if (n<=1) return;
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, true);
#endif
CGContextMoveToPoint(fl_gc, p[0].x, p[0].y); CGContextMoveToPoint(fl_gc, p[0].x, p[0].y);
for (int i=1; i<n; i++) for (int i=1; i<n; i++)
CGContextAddLineToPoint(fl_gc, p[i].x, p[i].y); CGContextAddLineToPoint(fl_gc, p[i].x, p[i].y);
CGContextClosePath(fl_gc); CGContextClosePath(fl_gc);
CGContextFillPath(fl_gc); CGContextFillPath(fl_gc);
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, false);
#endif
#else #else
# error unsupported platform # error unsupported platform
#endif #endif
@ -412,8 +438,15 @@ void fl_circle(double x, double y,double r) {
Arc(fl_gc, llx, lly, llx+w, lly+h, 0,0, 0,0); Arc(fl_gc, llx, lly, llx+w, lly+h, 0,0, 0,0);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
// Quartz warning : circle won't scale to current matrix! // Quartz warning : circle won't scale to current matrix!
CGContextAddArc(fl_gc, xt, yt, (w+h)*0.25f, 0, 2.0f*M_PI, 1); //last argument must be 0 (counterclockwise) or it draws nothing under __LP64__ !!!!
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, true);
#endif
CGContextAddArc(fl_gc, xt, yt, (w+h)*0.25f, 0, 2.0f*M_PI, 0);
(what == POLYGON ? CGContextFillPath : CGContextStrokePath)(fl_gc); (what == POLYGON ? CGContextFillPath : CGContextStrokePath)(fl_gc);
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, false);
#endif
#else #else
# error unsupported platform # error unsupported platform
#endif #endif

109
src/gl_draw.cxx

@ -110,6 +110,9 @@ void gl_font(int fontid, int size) {
wglUseFontBitmaps(fl_gc, base, count, fl_fontsize->listbase+base); wglUseFontBitmaps(fl_gc, base, count, fl_fontsize->listbase+base);
SelectObject(fl_gc, oldFid); SelectObject(fl_gc, oldFid);
# elif defined(__APPLE_QUARTZ__) # elif defined(__APPLE_QUARTZ__)
#if ! __LP64__
//AGL is not supported for use in 64-bit applications:
//http://developer.apple.com/mac/library/documentation/Carbon/Conceptual/Carbon64BitGuide/OtherAPIChanges/OtherAPIChanges.html
short font, face, size; short font, face, size;
uchar fn[256]; uchar fn[256];
fn[0]=strlen(fl_fontsize->q_name); fn[0]=strlen(fl_fontsize->q_name);
@ -120,6 +123,7 @@ void gl_font(int fontid, int size) {
fl_fontsize->listbase = glGenLists(256); fl_fontsize->listbase = glGenLists(256);
aglUseFont(aglGetCurrentContext(), font, face, aglUseFont(aglGetCurrentContext(), font, face,
size, 0, 256, fl_fontsize->listbase); size, 0, 256, fl_fontsize->listbase);
#endif
# else # else
# error unsupported platform # error unsupported platform
# endif # endif
@ -128,7 +132,9 @@ void gl_font(int fontid, int size) {
} }
gl_fontsize = fl_fontsize; gl_fontsize = fl_fontsize;
#if !( defined(__APPLE__) && __LP64__ )
glListBase(fl_fontsize->listbase); glListBase(fl_fontsize->listbase);
#endif
} }
#ifndef __APPLE__ #ifndef __APPLE__
@ -204,10 +210,20 @@ void gl_remove_displaylist_fonts()
Draws an array of n characters of the string in the current font Draws an array of n characters of the string in the current font
at the current position. at the current position.
*/ */
#if defined(__APPLE__) && __LP64__
static void gl_draw_cocoa(const char* str, int n);
#endif
void gl_draw(const char* str, int n) { void gl_draw(const char* str, int n) {
#ifdef __APPLE__ #ifdef __APPLE__
#if __LP64__
gl_draw_cocoa(str, n);
#else
// Should be converting the text here, as for other platforms??? // Should be converting the text here, as for other platforms???
glCallLists(n, GL_UNSIGNED_BYTE, str); glCallLists(n, GL_UNSIGNED_BYTE, str);
#endif
#else #else
static xchar *buf = NULL; static xchar *buf = NULL;
static int l = 0; static int l = 0;
@ -236,7 +252,7 @@ void gl_draw(const char* str, int n) {
} }
/** /**
Draws n charachters of the string in the current font at the given position Draws n characters of the string in the current font at the given position
*/ */
void gl_draw(const char* str, int n, int x, int y) { void gl_draw(const char* str, int n, int x, int y) {
glRasterPos2i(x, y); glRasterPos2i(x, y);
@ -244,7 +260,7 @@ void gl_draw(const char* str, int n, int x, int y) {
} }
/** /**
Draws n charachters of the string in the current font at the given position Draws n characters of the string in the current font at the given position
*/ */
void gl_draw(const char* str, int n, float x, float y) { void gl_draw(const char* str, int n, float x, float y) {
glRasterPos2f(x, y); glRasterPos2f(x, y);
@ -351,6 +367,95 @@ void gl_draw_image(const uchar* b, int x, int y, int w, int h, int d, int ld) {
glDrawPixels(w,h,d<4?GL_RGB:GL_RGBA,GL_UNSIGNED_BYTE,(const ulong*)b); glDrawPixels(w,h,d<4?GL_RGB:GL_RGBA,GL_UNSIGNED_BYTE,(const ulong*)b);
} }
#if defined(__APPLE__) && defined(__APPLE_COCOA__) && __LP64__
#include <FL/glu.h>
static void gl_draw_cocoa(const char* str, int n)
{
//setup matrices
GLint matrixMode;
glGetIntegerv (GL_MATRIX_MODE, &matrixMode);
glMatrixMode (GL_PROJECTION);
glPushMatrix();
glLoadIdentity ();
glMatrixMode (GL_MODELVIEW);
glPushMatrix();
glLoadIdentity ();
float winw = Fl_Window::current()->w();
float winh = Fl_Window::current()->h();
glScalef (2.0f / winw, 2.0f / winh, 1.0f);
glTranslatef (-winw / 2.0f, -winh / 2.0f, 0.0f);
//write str to a bitmap just big enough
int w = 0, h = 0;
fl_measure(str, w, h, 0);
CGColorSpaceRef lut = CGColorSpaceCreateDeviceRGB();
void *base = calloc(4*w, h);
if(base == NULL) return;
fl_gc = CGBitmapContextCreate(base, w, h, 8, w*4, lut, kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(lut);
fl_fontsize = gl_fontsize;
fl_draw(str, 0, h - fl_descent());
//put this bitmap in a texture
static GLuint texName = 0;
glPushAttrib(GL_TEXTURE_BIT);
if (0 == texName) glGenTextures (1, &texName);
glBindTexture (GL_TEXTURE_RECTANGLE_EXT, texName);
glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, base);
glPopAttrib();
CGContextRelease(fl_gc);
fl_gc = NULL;
free(base);
GLfloat pos[4];
glGetFloatv(GL_CURRENT_RASTER_POSITION, pos);
if (texName) {//write the texture on screen
CGRect bounds = CGRectMake (pos[0], pos[1] - fl_descent(), w, h);
glPushAttrib(GL_ENABLE_BIT | GL_TEXTURE_BIT | GL_COLOR_BUFFER_BIT); // GL_COLOR_BUFFER_BIT for glBlendFunc, GL_ENABLE_BIT for glEnable / glDisable
glDisable (GL_DEPTH_TEST); // ensure text is not removed by depth buffer test.
glEnable (GL_BLEND); // for text fading
glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); // ditto
glEnable (GL_TEXTURE_RECTANGLE_EXT);
glBindTexture (GL_TEXTURE_RECTANGLE_EXT, texName);
glBegin (GL_QUADS);
glTexCoord2f (0.0f, 0.0f); // draw lower left in world coordinates
glVertex2f (bounds.origin.x, bounds.origin.y);
glTexCoord2f (0.0f, h); // draw upper left in world coordinates
glVertex2f (bounds.origin.x, bounds.origin.y + bounds.size.height);
glTexCoord2f (w, h); // draw upper right in world coordinates
glVertex2f (bounds.origin.x + bounds.size.width, bounds.origin.y + bounds.size.height);
glTexCoord2f (w, 0.0f); // draw lower right in world coordinates
glVertex2f (bounds.origin.x + bounds.size.width, bounds.origin.y);
glEnd ();
glPopAttrib();
glDeleteTextures(1, &texName);
}
// reset original matrices
glPopMatrix(); // GL_MODELVIEW
glMatrixMode (GL_PROJECTION);
glPopMatrix();
glMatrixMode (matrixMode);
//set the raster position to end of string
pos[0] += w;
GLdouble modelmat[16];
glGetDoublev (GL_MODELVIEW_MATRIX, modelmat);
GLdouble projmat[16];
glGetDoublev (GL_PROJECTION_MATRIX, projmat);
GLdouble objX, objY, objZ;
GLint viewport[4];
glGetIntegerv (GL_VIEWPORT, viewport);
gluUnProject(pos[0], pos[1], pos[2], modelmat, projmat, viewport, &objX, &objY, &objZ);
glRasterPos2d(objX, objY);
}
#endif
#endif #endif
// //

8
src/makedepend

@ -383,9 +383,9 @@ Fl_Widget.o: ../FL/Fl_Tooltip.H ../FL/fl_draw.H ../FL/Fl_Window.H flstring.h
Fl_Widget.o: ../config.h Fl_Widget.o: ../config.h
Fl_Window.o: ../config.h ../FL/Fl.H ../FL/fl_utf8.h ../FL/Fl_Export.H Fl_Window.o: ../config.h ../FL/Fl.H ../FL/fl_utf8.h ../FL/Fl_Export.H
Fl_Window.o: ../FL/fl_types.h ../FL/Xutf8.h ../FL/Enumerations.H Fl_Window.o: ../FL/fl_types.h ../FL/Xutf8.h ../FL/Enumerations.H
Fl_Window.o: ../FL/Fl_Export.H ../FL/fl_types.h ../FL/Fl_Window.H Fl_Window.o: ../FL/Fl_Export.H ../FL/fl_types.h ../FL/x.H ../FL/Fl_Window.H
Fl_Window.o: ../FL/Fl_Group.H ../FL/Fl_Widget.H flstring.h ../FL/fl_draw.H Fl_Window.o: ../FL/Fl_Window.H ../FL/Fl_Group.H ../FL/Fl_Widget.H flstring.h
Fl_Window.o: ../FL/Fl_Window.H Fl_Window.o: ../FL/fl_draw.H
Fl_Window_fullscreen.o: ../FL/Fl.H ../FL/fl_utf8.h ../FL/Fl_Export.H Fl_Window_fullscreen.o: ../FL/Fl.H ../FL/fl_utf8.h ../FL/Fl_Export.H
Fl_Window_fullscreen.o: ../FL/fl_types.h ../FL/Xutf8.h ../FL/Enumerations.H Fl_Window_fullscreen.o: ../FL/fl_types.h ../FL/Xutf8.h ../FL/Enumerations.H
Fl_Window_fullscreen.o: ../FL/Fl_Export.H ../FL/fl_types.h ../FL/x.H Fl_Window_fullscreen.o: ../FL/Fl_Export.H ../FL/fl_types.h ../FL/x.H
@ -423,7 +423,7 @@ Fl_arg.o: ../FL/Fl_Widget.H ../FL/filename.H ../FL/fl_draw.H flstring.h
Fl_arg.o: ../config.h Fl_arg.o: ../config.h
Fl_compose.o: ../FL/Fl.H ../FL/fl_utf8.h ../FL/Fl_Export.H ../FL/fl_types.h Fl_compose.o: ../FL/Fl.H ../FL/fl_utf8.h ../FL/Fl_Export.H ../FL/fl_types.h
Fl_compose.o: ../FL/Xutf8.h ../FL/Enumerations.H ../FL/Fl_Export.H Fl_compose.o: ../FL/Xutf8.h ../FL/Enumerations.H ../FL/Fl_Export.H
Fl_compose.o: ../FL/fl_types.h Fl_compose.o: ../FL/fl_types.h ../FL/x.H ../FL/Fl_Window.H
Fl_display.o: ../FL/Fl.H ../FL/fl_utf8.h ../FL/Fl_Export.H ../FL/fl_types.h Fl_display.o: ../FL/Fl.H ../FL/fl_utf8.h ../FL/Fl_Export.H ../FL/fl_types.h
Fl_display.o: ../FL/Xutf8.h ../FL/Enumerations.H ../FL/Fl_Export.H Fl_display.o: ../FL/Xutf8.h ../FL/Enumerations.H ../FL/Fl_Export.H
Fl_display.o: ../FL/fl_types.h flstring.h ../config.h Fl_display.o: ../FL/fl_types.h flstring.h ../config.h

5
src/screen_xywh.cxx

@ -107,7 +107,11 @@ static void screen_init() {
#elif defined(__APPLE__) #elif defined(__APPLE__)
XRectangle screens[16]; XRectangle screens[16];
extern int MACscreen_init(XRectangle screens[]);
static void screen_init() { static void screen_init() {
#ifdef __APPLE_COCOA__
num_screens = MACscreen_init(screens);
#else
GDHandle gd; GDHandle gd;
for (gd = GetDeviceList(), num_screens = 0; gd; gd = GetNextDevice(gd)) { for (gd = GetDeviceList(), num_screens = 0; gd; gd = GetNextDevice(gd)) {
@ -120,6 +124,7 @@ static void screen_init() {
num_screens ++; num_screens ++;
if (num_screens >= 16) break; if (num_screens >= 16) break;
} }
#endif
} }
#elif HAVE_XINERAMA #elif HAVE_XINERAMA
# include <X11/extensions/Xinerama.h> # include <X11/extensions/Xinerama.h>

10
test/browser.cxx

@ -148,13 +148,17 @@ int main(int argc, char **argv) {
#elif defined(USING_XCODE) #elif defined(USING_XCODE)
if ( i == argc ) if ( i == argc )
{ {
fname = "../../../../test/browser.cxx"; char buf[2048];
done = browser->load(fname); strcpy(buf, argv[0]);
char *slash = strrchr(buf, '/');
if (slash)
strcpy(slash, "/../Resources/browser.cxx");
done = browser->load(buf);
} }
#endif #endif
if ( !done ) if ( !done )
{ {
printf("Can't load %s, %s\n", fname, strerror(errno)); fl_message("Can't load %s, %s\n", fname, strerror(errno));
exit(1); exit(1);
} }
} }

4
test/color_chooser.cxx

@ -112,7 +112,7 @@ int main(int argc, char ** argv) {
Pens p(80,200,3*8,120,"lines"); Pens p(80,200,3*8,120,"lines");
p.align(FL_ALIGN_TOP); p.align(FL_ALIGN_TOP);
int i = 1; int i = 1;
if (!Fl::args(argc,argv,i) || i != argc-1) { if (!Fl::args(argc,argv,i) || i < argc-1) {
printf("usage: %s <switches> visual-number\n" printf("usage: %s <switches> visual-number\n"
" - : default visual\n" " - : default visual\n"
" r : call Fl::visual(FL_RGB)\n" " r : call Fl::visual(FL_RGB)\n"
@ -124,6 +124,7 @@ int main(int argc, char ** argv) {
puts(Fl::help); puts(Fl::help);
exit(1); exit(1);
} }
if (i!=argc) {
if (argv[i][0] == 'r') { if (argv[i][0] == 'r') {
if (!Fl::visual(FL_RGB)) printf("Fl::visual(FL_RGB) returned false.\n"); if (!Fl::visual(FL_RGB)) printf("Fl::visual(FL_RGB) returned false.\n");
} else if (argv[i][0] == 'c') { } else if (argv[i][0] == 'c') {
@ -143,6 +144,7 @@ int main(int argc, char ** argv) {
Fl::fatal("Visual id's not supported on MSWindows or MacOS."); Fl::fatal("Visual id's not supported on MSWindows or MacOS.");
#endif #endif
} }
}
window.show(argc,argv); window.show(argc,argv);
return Fl::run(); return Fl::run();
} }

30
test/demo.cxx

@ -154,7 +154,7 @@ int b2n[][9] = {
{ 0, -1, 1, 2, 3, 4, 5, -1, 6}, { 0, -1, 1, 2, 3, 4, 5, -1, 6},
{ 0, 1, 2, 3, -1, 4, 5, 6, 7}, { 0, 1, 2, 3, -1, 4, 5, 6, 7},
{ 0, 1, 2, 3, 4, 5, 6, 7, 8} { 0, 1, 2, 3, 4, 5, 6, 7, 8}
}; };
int n2b[][9] = { int n2b[][9] = {
{ 4, -1, -1, -1, -1, -1, -1, -1, -1}, { 4, -1, -1, -1, -1, -1, -1, -1, -1},
{ 3, 5, -1, -1, -1, -1, -1, -1, -1}, { 3, 5, -1, -1, -1, -1, -1, -1, -1},
@ -165,17 +165,17 @@ int n2b[][9] = {
{ 0, 2, 3, 4, 5, 6, 8, -1, -1}, { 0, 2, 3, 4, 5, 6, 8, -1, -1},
{ 0, 1, 2, 3, 5, 6, 7, 8, -1}, { 0, 1, 2, 3, 5, 6, 7, 8, -1},
{ 0, 1, 2, 3, 4, 5, 6, 7, 8} { 0, 1, 2, 3, 4, 5, 6, 7, 8}
}; };
int but2numb(int bnumb, int maxnumb) int but2numb(int bnumb, int maxnumb)
/* Transforms a button number to an item number when there are /* Transforms a button number to an item number when there are
maxnumb items in total. -1 if the button should not exist. */ maxnumb items in total. -1 if the button should not exist. */
{ return b2n[maxnumb][bnumb]; } { return b2n[maxnumb][bnumb]; }
int numb2but(int inumb, int maxnumb) int numb2but(int inumb, int maxnumb)
/* Transforms an item number to a button number when there are /* Transforms an item number to a button number when there are
maxnumb items in total. -1 if the item should not exist. */ maxnumb items in total. -1 if the item should not exist. */
{ return n2b[maxnumb][inumb]; } { return n2b[maxnumb][inumb]; }
/* Pushing and Popping menus */ /* Pushing and Popping menus */
@ -276,15 +276,23 @@ void dobut(Fl_Widget *, long arg)
delete[] copy_of_icommand; delete[] copy_of_icommand;
#elif defined USING_XCODE #elif defined USING_XCODE
char *cmd = strdup(menus[men].icommand[bn]);
int icommand_length = strlen(menus[men].icommand[bn]); char *arg = strchr(cmd, ' ');
char* command = new char[icommand_length+24]; // extraspace for 'open ../../(name).app &\0'
char command[2048];
sprintf(command, "open ../../../%s.app &", menus[men].icommand[bn]); if (arg) {
*arg = 0;
if (strcmp(cmd, "../fluid/fluid")==0)
sprintf(command, "open ../../../Fluid.app --args %s", arg+1);
else
sprintf(command, "open ../../../%s.app --args %s", cmd, arg+1);
} else {
sprintf(command, "open ../../../%s.app", cmd);
}
puts(command);
system(command); system(command);
delete[] command; free(cmd);
#else // NON WIN32 systems. #else // NON WIN32 systems.
int icommand_length = strlen(menus[men].icommand[bn]); int icommand_length = strlen(menus[men].icommand[bn]);

4
test/fullscreen.cxx

@ -161,6 +161,10 @@ void fullscreen_cb(Fl_Widget *o, void *p) {
py = w->y(); py = w->y();
pw = w->w(); pw = w->w();
ph = w->h(); ph = w->h();
#ifndef WIN32//necessary because fullscreen removes border
border_button->value(0);
border_button->do_callback();
#endif
w->fullscreen(); w->fullscreen();
} else { } else {
w->fullscreen_off(px,py,pw,ph); w->fullscreen_off(px,py,pw,ph);

Loading…
Cancel
Save