Browse Source

Quickdraw removal: option removed from configure, all Qd code removed from sources. Also took this opportunity to sort the ifdef clauses so that USE_X11 shows first. Also added error pragma to enforce proper target checking, thus make even less assumptions.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6423 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
pull/49/head
Fabien Costantini 17 years ago
parent
commit
92051890f1
  1. 3
      FL/Fl_Cairo.H
  2. 20
      configure.in
  3. 66
      src/Fl.cxx
  4. 134
      src/Fl_Bitmap.cxx
  5. 4
      src/Fl_Cairo.cxx
  6. 106
      src/Fl_Double_Window.cxx
  7. 195
      src/Fl_Gl_Choice.cxx
  8. 39
      src/Fl_Gl_Window.cxx
  9. 76
      src/Fl_Image.cxx
  10. 58
      src/Fl_Pixmap.cxx
  11. 12
      src/Fl_Widget.cxx
  12. 8
      src/Fl_Window_fullscreen.cxx
  13. 11
      src/Fl_mac.cxx
  14. 22
      src/fl_arci.cxx
  15. 18
      src/fl_color_mac.cxx
  16. 114
      src/fl_draw_image_mac.cxx
  17. 80
      src/fl_font_mac.cxx
  18. 79
      src/fl_line_style.cxx
  19. 16
      src/fl_overlay.cxx
  20. 358
      src/fl_rect.cxx
  21. 34
      src/fl_scroll_area.cxx
  22. 64
      src/fl_vertex.cxx
  23. 75
      src/gl_draw.cxx
  24. 21
      src/gl_start.cxx

3
FL/Fl_Cairo.H

@ -44,9 +44,6 @@
# include <cairo-win32.h> # include <cairo-win32.h>
# elif defined(__APPLE_QUARTZ__) # elif defined(__APPLE_QUARTZ__)
# include <cairo-quartz.h> # include <cairo-quartz.h>
# elif defined(__APPLE_QD__)
# error Apple Quartz is necessary for Cairo upport.
# else
# error Cairo is not supported on that platform. # error Cairo is not supported on that platform.
# endif # endif

20
configure.in

@ -258,17 +258,9 @@ AC_ARG_WITH(archflags, [ --with-archflags="flags"
use custom architecture flags], use custom architecture flags],
ARCHFLAGS="$withval") ARCHFLAGS="$withval")
case $uname in # QD is not supported anymore since 1.3
Darwin*) AC_DEFINE(USE_QUARTZ, 1)
AC_ARG_ENABLE(quartz, [ --enable-quartz use Quartz instead of Quickdraw (default=yes)]) AC_DEFINE(__APPLE_QUARTZ__)
if test "x$enable_quartz" != "xno"; then
AC_DEFINE(USE_QUARTZ, 1)
AC_DEFINE(__APPLE_QUARTZ__)
else
AC_DEFINE(__APPLE_QD__)
fi
;;
esac
dnl Find commands... dnl Find commands...
AC_PROG_CC AC_PROG_CC
@ -1092,11 +1084,7 @@ case $uname in
graphics="GDI" graphics="GDI"
;; ;;
Darwin*) Darwin*)
if test x$enable_quartz != xno; then graphics="Quartz"
graphics="Quartz"
else
graphics="Quickdraw"
fi
;; ;;
*) *)
graphics="X11" graphics="X11"

66
src/Fl.cxx

@ -555,12 +555,12 @@ Fl_X* Fl_X::first;
Fl_Window* fl_find(Window xid) { 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)
#ifdef __APPLE_QD__ #if defined(WIN32) || defined(USE_X11)
if (window->xid == xid && !window->w->window()) { 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
if (window->xid == xid) { # 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
@ -632,19 +632,15 @@ void Fl::flush() {
if (i->region) {XDestroyRegion(i->region); i->region = 0;} if (i->region) {XDestroyRegion(i->region); i->region = 0;}
} }
} }
#if defined(USE_X11)
#ifdef WIN32 if (fl_display) XFlush(fl_display);
#elif defined(WIN32)
GdiFlush(); GdiFlush();
#elif defined(__APPLE_QD__)
GrafPtr port;
GetPort( &port );
if ( port )
QDFlushPortBuffer( port, 0 );
#elif defined (__APPLE_QUARTZ__) #elif defined (__APPLE_QUARTZ__)
if (fl_gc) if (fl_gc)
CGContextFlush(fl_gc); CGContextFlush(fl_gc);
#else #else
if (fl_display) XFlush(fl_display); # error unsupported platform
#endif #endif
} }
@ -1170,7 +1166,7 @@ void Fl_Window::hide() {
fl_throw_focus(this); fl_throw_focus(this);
handle(FL_HIDE); handle(FL_HIDE);
#ifdef WIN32 #if defined(WIN32)
// this little trick keeps the current clipboard alive, even if we are about // this little trick keeps the current clipboard alive, even if we are about
// to destroy the window that owns the selection. // to destroy the window that owns the selection.
if (GetClipboardOwner()==ip->xid) { if (GetClipboardOwner()==ip->xid) {
@ -1192,9 +1188,6 @@ void Fl_Window::hide() {
if (Fl::cairo_autolink_context()) Fl::cairo_make_current((Fl_Window*) 0); if (Fl::cairo_autolink_context()) Fl::cairo_make_current((Fl_Window*) 0);
# endif # endif
} }
#elif defined(__APPLE_QD__)
if ( ip->xid == fl_window && !parent() )
fl_window = 0;
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
Fl_X::q_release_context(ip); Fl_X::q_release_context(ip);
if ( ip->xid == fl_window && !parent() ) if ( ip->xid == fl_window && !parent() )
@ -1203,7 +1196,12 @@ void Fl_Window::hide() {
if (ip->region) XDestroyRegion(ip->region); if (ip->region) XDestroyRegion(ip->region);
#ifdef WIN32 #if defined(USE_X11)
# if USE_XFT
fl_destroy_xft_draw(ip->xid);
# endif
XDestroyWindow(fl_display, ip->xid);
#elif defined(WIN32)
// this little trickery seems to avoid the popup window stacking problem // this little trickery seems to avoid the popup window stacking problem
HWND p = GetForegroundWindow(); HWND p = GetForegroundWindow();
if (p==GetParent(ip->xid)) { if (p==GetParent(ip->xid)) {
@ -1211,15 +1209,10 @@ void Fl_Window::hide() {
ShowWindow(p, SW_SHOWNA); ShowWindow(p, SW_SHOWNA);
} }
XDestroyWindow(fl_display, ip->xid); XDestroyWindow(fl_display, ip->xid);
#elif defined(__APPLE_QD__)
MacDestroyWindow(this, ip->xid);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
MacDestroyWindow(this, ip->xid); MacDestroyWindow(this, ip->xid);
#else #else
# if USE_XFT # error unsupported platform
fl_destroy_xft_draw(ip->xid);
# endif
XDestroyWindow(fl_display, ip->xid);
#endif #endif
#ifdef WIN32 #ifdef WIN32
@ -1249,12 +1242,12 @@ int Fl_Window::handle(int ev)
case FL_SHOW: case FL_SHOW:
if (!shown()) show(); if (!shown()) show();
else { else {
#ifdef __APPLE_QD__ #if defined(USE_X11) || defined(WIN32)
MacMapWindow(this, fl_xid(this)); XMapWindow(fl_display, fl_xid(this)); // extra map calls are harmless
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
MacMapWindow(this, fl_xid(this)); MacMapWindow(this, fl_xid(this));
#else #else
XMapWindow(fl_display, fl_xid(this)); // extra map calls are harmless # error unsupported platform
#endif // __APPLE__ #endif // __APPLE__
} }
break; break;
@ -1271,13 +1264,13 @@ int Fl_Window::handle(int ev)
Fl_Widget* p = parent(); for (;p->visible();p = p->parent()) {} Fl_Widget* p = parent(); for (;p->visible();p = p->parent()) {}
if (p->type() >= FL_WINDOW) break; // don't do the unmap if (p->type() >= FL_WINDOW) break; // don't do the unmap
} }
#ifdef __APPLE_QD__ #if defined(USE_X11) || defined(WIN32)
MacUnmapWindow(this, fl_xid(this)); XUnmapWindow(fl_display, fl_xid(this));
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
MacUnmapWindow(this, fl_xid(this)); MacUnmapWindow(this, fl_xid(this));
#else #else
XUnmapWindow(fl_display, fl_xid(this)); # error platform unsupported
#endif // __APPLE__ #endif
} }
break; break;
} }
@ -1418,24 +1411,21 @@ void Fl_Widget::damage(uchar fl, int X, int Y, int W, int H) {
if (wi->damage()) { if (wi->damage()) {
// if we already have damage we must merge with existing region: // if we already have damage we must merge with existing region:
if (i->region) { if (i->region) {
#ifdef WIN32 #if defined(USE_X11)
XRectangle R;
R.x = X; R.y = Y; R.width = W; R.height = H;
XUnionRectWithRegion(&R, i->region, i->region);
#elif defined(WIN32)
Fl_Region R = XRectangleRegion(X, Y, W, H); Fl_Region R = XRectangleRegion(X, Y, W, H);
CombineRgn(i->region, i->region, R, RGN_OR); CombineRgn(i->region, i->region, R, RGN_OR);
XDestroyRegion(R); XDestroyRegion(R);
#elif defined(__APPLE_QD__)
Fl_Region R = NewRgn();
SetRectRgn(R, X, Y, X+W, Y+H);
UnionRgn(R, i->region, i->region);
DisposeRgn(R);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
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);
#else #else
XRectangle R; # error unsupported platform
R.x = X; R.y = Y; R.width = W; R.height = H;
XUnionRectWithRegion(&R, i->region, i->region);
#endif #endif
} }
wi->damage_ |= fl; wi->damage_ |= fl;

134
src/Fl_Bitmap.cxx

@ -39,53 +39,7 @@
#include <FL/Fl_Bitmap.H> #include <FL/Fl_Bitmap.H>
#include "flstring.h" #include "flstring.h"
#ifdef __APPLE_QD__ // MacOS bitmask functions #if defined(__APPLE_QUARTZ__)
Fl_Bitmask fl_create_bitmask(int w, int h, const uchar *array) {
Rect srcRect;
srcRect.left = 0; srcRect.right = w;
srcRect.top = 0; srcRect.bottom = h;
GrafPtr savePort;
GetPort(&savePort); // remember the current port
Fl_Bitmask gw;
NewGWorld( &gw, 1, &srcRect, 0L, 0L, 0 );
PixMapHandle pm = GetGWorldPixMap( gw );
if ( pm )
{
LockPixels( pm );
if ( *pm )
{
uchar *base = (uchar*)GetPixBaseAddr( pm );
if ( base )
{
PixMapPtr pmp = *pm;
// verify the parameters for direct memory write
if ( pmp->pixelType == 0 || pmp->pixelSize == 1 || pmp->cmpCount == 1 || pmp->cmpSize == 1 )
{
static uchar reverse[16] = /* Bit reversal lookup table */
{ 0x00, 0x88, 0x44, 0xcc, 0x22, 0xaa, 0x66, 0xee, 0x11, 0x99, 0x55, 0xdd, 0x33, 0xbb, 0x77, 0xff };
uchar *dst = base;
const uchar *src = array;
int rowBytesSrc = (w+7)>>3 ;
int rowPatch = (pmp->rowBytes&0x3fff) - rowBytesSrc;
for ( int j=0; j<h; j++,dst+=rowPatch )
for ( int i=0; i<rowBytesSrc; i++,src++ )
*dst++ = (reverse[*src & 0x0f] & 0xf0) | (reverse[(*src >> 4) & 0x0f] & 0x0f);
}
}
UnlockPixels( pm );
}
}
SetPort(savePort);
return gw; /* tell caller we succeeded! */
}
void fl_delete_bitmask(Fl_Bitmask id) {
if (id) DisposeGWorld(id);
}
#elif defined(__APPLE_QUARTZ__)
Fl_Bitmask fl_create_bitmask(int w, int h, const uchar *array) { Fl_Bitmask fl_create_bitmask(int w, int h, const uchar *array) {
static uchar reverse[16] = /* Bit reversal lookup table */ static uchar reverse[16] = /* Bit reversal lookup table */
{ 0x00, 0x88, 0x44, 0xcc, 0x22, 0xaa, 0x66, 0xee, { 0x00, 0x88, 0x44, 0xcc, 0x22, 0xaa, 0x66, 0xee,
@ -236,54 +190,6 @@ void fl_delete_bitmask(Fl_Bitmask bm) {
#endif // __APPLE__ #endif // __APPLE__
// MRS: Currently it appears that CopyDeepMask() does not work with an 8-bit alpha mask.
// If you want to test/fix this, uncomment the "#ifdef __APPLE__" and comment out
// the "#if 0" here. Also see Fl_Image.cxx for a similar check...
//#ifdef __APPLE_QD__
#if 0
// Create an 8-bit mask used for alpha blending
Fl_Bitmask fl_create_alphamask(int w, int h, int d, int ld, const uchar *array) {
Rect srcRect;
srcRect.left = 0; srcRect.right = w;
srcRect.top = 0; srcRect.bottom = h;
GrafPtr savePort;
GetPort(&savePort); // remember the current port
Fl_Bitmask gw;
NewGWorld( &gw, 8, &srcRect, 0L, 0L, 0 );
PixMapHandle pm = GetGWorldPixMap( gw );
if ( pm )
{
LockPixels( pm );
if ( *pm )
{
uchar *base = (uchar*)GetPixBaseAddr( pm );
if ( base )
{
PixMapPtr pmp = *pm;
// verify the parameters for direct memory write
if ( pmp->pixelType == 0 || pmp->pixelSize == 8 || pmp->cmpCount == 1 || pmp->cmpSize == 8 )
{
// Copy alpha values from the source array to the pixmap...
array += d - 1;
int rowoffset = (pmp->rowBytes & 0x3fff) - w;
for (int y = h; y > 0; y --, array += ld, base += rowoffset) {
for (int x = w; x > 0; x --, array += d) {
*base++ = 255 /*255 - *array*/;
}
}
}
}
UnlockPixels( pm );
}
}
SetPort(savePort);
return gw; /* tell caller we succeeded! */
}
#else
// Create a 1-bit mask used for alpha blending // Create a 1-bit mask used for alpha blending
Fl_Bitmask fl_create_alphamask(int w, int h, int d, int ld, const uchar *array) { Fl_Bitmask fl_create_alphamask(int w, int h, int d, int ld, const uchar *array) {
Fl_Bitmask mask; Fl_Bitmask mask;
@ -356,7 +262,6 @@ Fl_Bitmask fl_create_alphamask(int w, int h, int d, int ld, const uchar *array)
return (mask); return (mask);
} }
#endif // __APPLE__
void Fl_Bitmap::draw(int XP, int YP, int WP, int HP, int cx, int cy) { void Fl_Bitmap::draw(int XP, int YP, int WP, int HP, int cx, int cy) {
if (!array) { if (!array) {
@ -374,7 +279,18 @@ void Fl_Bitmap::draw(int XP, int YP, int WP, int HP, int cx, int cy) {
if (cy < 0) {H += cy; Y -= cy; cy = 0;} if (cy < 0) {H += cy; Y -= cy; cy = 0;}
if ((cy+H) > h()) H = h()-cy; if ((cy+H) > h()) H = h()-cy;
if (H <= 0) return; if (H <= 0) return;
#ifdef WIN32
#if defined(USE_X11)
if (!id) id = fl_create_bitmask(w(), h(), array);
XSetStipple(fl_display, fl_gc, id);
int ox = X-cx; if (ox < 0) ox += w();
int oy = Y-cy; if (oy < 0) oy += h();
XSetTSOrigin(fl_display, fl_gc, ox, oy);
XSetFillStyle(fl_display, fl_gc, FillStippled);
XFillRectangle(fl_display, fl_window, fl_gc, X, Y, W, H);
XSetFillStyle(fl_display, fl_gc, FillSolid);
#elif defined(WIN32)
if (!id) id = fl_create_bitmap(w(), h(), array); if (!id) id = fl_create_bitmap(w(), h(), array);
HDC tempdc = CreateCompatibleDC(fl_gc); HDC tempdc = CreateCompatibleDC(fl_gc);
@ -385,20 +301,6 @@ void Fl_Bitmap::draw(int XP, int YP, int WP, int HP, int cx, int cy) {
BitBlt(fl_gc, X, Y, W, H, tempdc, cx, cy, 0xE20746L); BitBlt(fl_gc, X, Y, W, H, tempdc, cx, cy, 0xE20746L);
RestoreDC(tempdc, save); RestoreDC(tempdc, save);
DeleteDC(tempdc); DeleteDC(tempdc);
#elif defined(__APPLE_QD__)
if (!id) id = fl_create_bitmask(w(), h(), array);
GrafPtr dstPort;
GetPort( &dstPort );
Rect src, dst;
GetPortBounds( (Fl_Offscreen)id, &src );
SetRect( &src, cx, cy, cx+W, cy+H );
SetRect( &dst, X, Y, X+W, Y+H );
CopyBits(GetPortBitMapForCopyBits((Fl_Offscreen)id), // srcBits
GetPortBitMapForCopyBits(dstPort), // dstBits
&src, // src bounds
&dst, // dst bounds
srcOr, // mode
0L); // mask region
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
if (!id) id = fl_create_bitmask(w(), h(), array); if (!id) id = fl_create_bitmask(w(), h(), array);
if (id && fl_gc) { if (id && fl_gc) {
@ -408,15 +310,7 @@ void Fl_Bitmap::draw(int XP, int YP, int WP, int HP, int cx, int cy) {
Fl_X::q_end_image(); Fl_X::q_end_image();
} }
#else #else
if (!id) id = fl_create_bitmask(w(), h(), array); # error unsupported platform
XSetStipple(fl_display, fl_gc, id);
int ox = X-cx; if (ox < 0) ox += w();
int oy = Y-cy; if (oy < 0) oy += h();
XSetTSOrigin(fl_display, fl_gc, ox, oy);
XSetFillStyle(fl_display, fl_gc, FillStippled);
XFillRectangle(fl_display, fl_window, fl_gc, X, Y, W, H);
XSetFillStyle(fl_display, fl_gc, FillSolid);
#endif #endif
} }

4
src/Fl_Cairo.cxx

@ -79,14 +79,12 @@ cairo_t * Fl::cairo_make_current(Fl_Window* wi) {
gc is an HDC context in WIN32, a CGContext* in Quartz, a display on X11 gc is an HDC context in WIN32, a CGContext* in Quartz, a display on X11
*/ */
static cairo_surface_t * cairo_create_surface(void * gc, int W, int H) { static cairo_surface_t * cairo_create_surface(void * gc, int W, int H) {
# if defined(USE_X11) // X11 # if defined(USE_X11)
return cairo_xlib_surface_create(fl_display, fl_window, fl_visual->visual, W, H); return cairo_xlib_surface_create(fl_display, fl_window, fl_visual->visual, W, H);
# elif defined(WIN32) # elif defined(WIN32)
return cairo_win32_surface_create((HDC) gc); return cairo_win32_surface_create((HDC) gc);
# elif defined(__APPLE_QUARTZ__) # elif defined(__APPLE_QUARTZ__)
return cairo_quartz_surface_create_for_cg_context((CGContext*) gc, W, H); return cairo_quartz_surface_create_for_cg_context((CGContext*) gc, W, H);
# elif defined(__APPLE_QD__)
# error Cairo is not supported under Apple Quickdraw, please use Apple Quartz.
# else # else
# error Cairo is not supported under this platform. # error Cairo is not supported under this platform.
# endif # endif

106
src/Fl_Double_Window.cxx

@ -64,7 +64,13 @@ void Fl_Double_Window::show() {
Fl_Window::show(); Fl_Window::show();
} }
#ifdef WIN32 #if defined(X11)
// maybe someone feels inclined to implement alpha blending on X11?
char fl_can_do_alpha_blending() {
return 0;
}
#elif defined(WIN32)
// Code used to switch output to an off-screen window. See macros in // Code used to switch output to an off-screen window. See macros in
// win32.H which save the old state in local variables. // win32.H which save the old state in local variables.
@ -154,83 +160,6 @@ void fl_copy_offscreen_with_alpha(int x,int y,int w,int h,HBITMAP bitmap,int src
extern void fl_restore_clip(); extern void fl_restore_clip();
#elif defined(__APPLE_QD__)
char fl_can_do_alpha_blending() {
return 0;
}
GWorldPtr fl_create_offscreen(int w, int h) {
GWorldPtr gw;
Rect bounds;
bounds.left=0; bounds.right=w; bounds.top=0; bounds.bottom=h;
QDErr err = NewGWorld(&gw, 0, &bounds, 0L, 0L, 0); // 'useTempMem' should not be used (says the Carbon port manual)
if ( err == -108 )
{ }
// fl_message( "The application memory is low. Please increase the initial memory assignment.\n" );
if (err!=noErr || gw==0L) return 0L;
return gw;
}
void fl_copy_offscreen(int x,int y,int w,int h,GWorldPtr gWorld,int srcx,int srcy) {
Rect src;
if ( !gWorld ) return;
src.top = srcy; src.left = srcx; src.bottom = srcy+h; src.right = srcx+w;
Rect dst;
GrafPtr dstPort; GetPort(&dstPort);
dst.top = y; dst.left = x; dst.bottom = y+h; dst.right = x+w;
RGBColor rgb, oldbg, oldfg;
GetForeColor(&oldfg);
GetBackColor(&oldbg);
rgb.red = 0xffff; rgb.green = 0xffff; rgb.blue = 0xffff;
RGBBackColor( &rgb );
rgb.red = 0x0000; rgb.green = 0x0000; rgb.blue = 0x0000;
RGBForeColor( &rgb );
CopyBits(GetPortBitMapForCopyBits(gWorld), GetPortBitMapForCopyBits(dstPort), &src, &dst, srcCopy, 0L);
RGBBackColor(&oldbg);
RGBForeColor(&oldfg);
}
void fl_delete_offscreen(GWorldPtr gWorld) {
DisposeGWorld(gWorld);
}
static GrafPtr prevPort;
static GDHandle prevGD;
void fl_begin_offscreen(GWorldPtr gWorld) {
GetGWorld( &prevPort, &prevGD );
if ( gWorld )
{
SetGWorld( gWorld, 0 ); // sets the correct port
PixMapHandle pm = GetGWorldPixMap(gWorld);
Boolean ret = LockPixels(pm);
if ( ret == false )
{
Rect rect;
GetPortBounds( gWorld, &rect );
UpdateGWorld( &gWorld, 0, &rect, 0, 0, 0 );
pm = GetGWorldPixMap( gWorld );
LockPixels( pm );
}
fl_window = 0;
}
fl_push_no_clip();
}
void fl_end_offscreen() {
GWorldPtr currPort;
GDHandle currGD;
GetGWorld( &currPort, &currGD );
fl_pop_clip();
PixMapHandle pm = GetGWorldPixMap(currPort);
UnlockPixels(pm);
SetGWorld( prevPort, prevGD );
fl_window = GetWindowFromPort( prevPort );
}
extern void fl_restore_clip();
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
char fl_can_do_alpha_blending() { char fl_can_do_alpha_blending() {
@ -318,13 +247,8 @@ void fl_end_offscreen() {
extern void fl_restore_clip(); extern void fl_restore_clip();
#else // X11 #else
# error unsupported platform
// maybe someone feels inclined to implement alpha blending on X11?
char fl_can_do_alpha_blending() {
return 0;
}
#endif #endif
/** /**
@ -351,20 +275,16 @@ void Fl_Double_Window::flush(int eraseoverlay) {
myi->backbuffer_bad = 1; myi->backbuffer_bad = 1;
} else } else
#endif #endif
#ifdef __APPLE_QD__ #if defined(USE_X11) || defined(WIN32)
if ( ( !QDIsPortBuffered( GetWindowPort(myi->xid) ) ) myi->other_xid = fl_create_offscreen(w(), h());
|| force_doublebuffering_ ) { clear_damage(FL_DAMAGE_ALL);
myi->other_xid = fl_create_offscreen(w(), h());
clear_damage(FL_DAMAGE_ALL);
}
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
if (force_doublebuffering_) { if (force_doublebuffering_) {
myi->other_xid = fl_create_offscreen(w(), h()); myi->other_xid = fl_create_offscreen(w(), h());
clear_damage(FL_DAMAGE_ALL); clear_damage(FL_DAMAGE_ALL);
} }
#else #else
myi->other_xid = fl_create_offscreen(w(), h()); # error unsupported platform
clear_damage(FL_DAMAGE_ALL);
#endif #endif
} }
#if USE_XDBE #if USE_XDBE

195
src/Fl_Gl_Choice.cxx

@ -56,7 +56,7 @@ Fl_Gl_Choice *Fl_Gl_Choice::find(int m, const int *alistp) {
if (g->mode == m && g->alist == alistp) if (g->mode == m && g->alist == alistp)
return g; return g;
# ifdef __APPLE_QD__ #if defined(USE_X11)
const int *blist; const int *blist;
int list[32]; int list[32];
@ -65,45 +65,55 @@ Fl_Gl_Choice *Fl_Gl_Choice::find(int m, const int *alistp) {
else { else {
int n = 0; int n = 0;
if (m & FL_INDEX) { if (m & FL_INDEX) {
list[n++] = AGL_BUFFER_SIZE; list[n++] = GLX_BUFFER_SIZE;
list[n++] = 8; // glut tries many sizes, but this should work... list[n++] = 8; // glut tries many sizes, but this should work...
} else { } else {
list[n++] = AGL_RGBA; list[n++] = GLX_RGBA;
list[n++] = AGL_GREEN_SIZE; list[n++] = GLX_GREEN_SIZE;
list[n++] = (m & FL_RGB8) ? 8 : 1; list[n++] = (m & FL_RGB8) ? 8 : 1;
if (m & FL_ALPHA) { if (m & FL_ALPHA) {
list[n++] = AGL_ALPHA_SIZE; list[n++] = GLX_ALPHA_SIZE;
list[n++] = (m & FL_RGB8) ? 8 : 1; list[n++] = (m & FL_RGB8) ? 8 : 1;
} }
if (m & FL_ACCUM) { if (m & FL_ACCUM) {
list[n++] = AGL_ACCUM_GREEN_SIZE; list[n++] = GLX_ACCUM_GREEN_SIZE;
list[n++] = 1; list[n++] = 1;
if (m & FL_ALPHA) { if (m & FL_ALPHA) {
list[n++] = AGL_ACCUM_ALPHA_SIZE; list[n++] = GLX_ACCUM_ALPHA_SIZE;
list[n++] = 1; list[n++] = 1;
} }
} }
} }
if (m & FL_DOUBLE) { if (m & FL_DOUBLE) {
list[n++] = AGL_DOUBLEBUFFER; list[n++] = GLX_DOUBLEBUFFER;
} }
if (m & FL_DEPTH) { if (m & FL_DEPTH) {
list[n++] = AGL_DEPTH_SIZE; list[n++] = 24; list[n++] = GLX_DEPTH_SIZE; list[n++] = 1;
} }
if (m & FL_STENCIL) { if (m & FL_STENCIL) {
list[n++] = AGL_STENCIL_SIZE; list[n++] = 1; list[n++] = GLX_STENCIL_SIZE; list[n++] = 1;
} }
# ifdef AGL_STEREO
if (m & FL_STEREO) { if (m & FL_STEREO) {
list[n++] = AGL_STEREO; list[n++] = GLX_STEREO;
}
# if defined(GLX_VERSION_1_1) && defined(GLX_SGIS_multisample)
if (m & FL_MULTISAMPLE) {
list[n++] = GLX_SAMPLES_SGIS;
list[n++] = 4; // value Glut uses
} }
# endif # endif
list[n] = AGL_NONE; list[n] = 0;
blist = list; blist = list;
} }
fl_open_display(); fl_open_display();
AGLPixelFormat fmt = aglChoosePixelFormat(NULL, 0, (GLint*)blist); XVisualInfo *visp = glXChooseVisual(fl_display, fl_screen, (int *)blist);
if (!fmt) return 0; if (!visp) {
# if defined(GLX_VERSION_1_1) && defined(GLX_SGIS_multisample)
if (m&FL_MULTISAMPLE) return find(m&~FL_MULTISAMPLE,0);
# endif
return 0;
}
#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
@ -155,67 +165,7 @@ Fl_Gl_Choice *Fl_Gl_Choice::find(int m, const int *alistp) {
AGLPixelFormat fmt = aglChoosePixelFormat(NULL, 0, (GLint*)blist); AGLPixelFormat fmt = aglChoosePixelFormat(NULL, 0, (GLint*)blist);
if (!fmt) return 0; if (!fmt) return 0;
# elif !defined(WIN32) #elif defined(WIN32)
const int *blist;
int list[32];
if (alistp)
blist = alistp;
else {
int n = 0;
if (m & FL_INDEX) {
list[n++] = GLX_BUFFER_SIZE;
list[n++] = 8; // glut tries many sizes, but this should work...
} else {
list[n++] = GLX_RGBA;
list[n++] = GLX_GREEN_SIZE;
list[n++] = (m & FL_RGB8) ? 8 : 1;
if (m & FL_ALPHA) {
list[n++] = GLX_ALPHA_SIZE;
list[n++] = (m & FL_RGB8) ? 8 : 1;
}
if (m & FL_ACCUM) {
list[n++] = GLX_ACCUM_GREEN_SIZE;
list[n++] = 1;
if (m & FL_ALPHA) {
list[n++] = GLX_ACCUM_ALPHA_SIZE;
list[n++] = 1;
}
}
}
if (m & FL_DOUBLE) {
list[n++] = GLX_DOUBLEBUFFER;
}
if (m & FL_DEPTH) {
list[n++] = GLX_DEPTH_SIZE; list[n++] = 1;
}
if (m & FL_STENCIL) {
list[n++] = GLX_STENCIL_SIZE; list[n++] = 1;
}
if (m & FL_STEREO) {
list[n++] = GLX_STEREO;
}
# if defined(GLX_VERSION_1_1) && defined(GLX_SGIS_multisample)
if (m & FL_MULTISAMPLE) {
list[n++] = GLX_SAMPLES_SGIS;
list[n++] = 4; // value Glut uses
}
# endif
list[n] = 0;
blist = list;
}
fl_open_display();
XVisualInfo *visp = glXChooseVisual(fl_display, fl_screen, (int *)blist);
if (!visp) {
# if defined(GLX_VERSION_1_1) && defined(GLX_SGIS_multisample)
if (m&FL_MULTISAMPLE) return find(m&~FL_MULTISAMPLE,0);
# endif
return 0;
}
# else
// Replacement for ChoosePixelFormat() that finds one with an overlay // Replacement for ChoosePixelFormat() that finds one with an overlay
// if possible: // if possible:
@ -250,8 +200,9 @@ Fl_Gl_Choice *Fl_Gl_Choice::find(int m, const int *alistp) {
} }
//printf("Chosen pixel format is %d\n", pixelformat); //printf("Chosen pixel format is %d\n", pixelformat);
if (!pixelformat) return 0; if (!pixelformat) return 0;
#else
# endif # error platform unsupported
#endif
g = new Fl_Gl_Choice; g = new Fl_Gl_Choice;
g->mode = m; g->mode = m;
@ -259,15 +210,7 @@ Fl_Gl_Choice *Fl_Gl_Choice::find(int m, const int *alistp) {
g->next = first; g->next = first;
first = g; first = g;
# ifdef WIN32 #if defined(USE_X11)
g->pixelformat = pixelformat;
g->pfd = chosen_pfd;
# elif defined(__APPLE_QD__)
g->pixelformat = fmt;
# elif defined(__APPLE_QUARTZ__)
// warning: the Quartz version should probably use Core GL (CGL) instead of AGL
g->pixelformat = fmt;
# else
g->vis = visp; g->vis = visp;
if (/*MaxCmapsOfScreen(ScreenOfDisplay(fl_display,fl_screen))==1 && */ if (/*MaxCmapsOfScreen(ScreenOfDisplay(fl_display,fl_screen))==1 && */
@ -277,6 +220,14 @@ Fl_Gl_Choice *Fl_Gl_Choice::find(int m, const int *alistp) {
else else
g->colormap = XCreateColormap(fl_display, RootWindow(fl_display,fl_screen), g->colormap = XCreateColormap(fl_display, RootWindow(fl_display,fl_screen),
visp->visual, AllocNone); visp->visual, AllocNone);
# elif defined(WIN32)
g->pixelformat = pixelformat;
g->pfd = chosen_pfd;
# elif defined(__APPLE_QUARTZ__)
// warning: the Quartz version should probably use Core GL (CGL) instead of AGL
g->pixelformat = fmt;
# else
# error unsupported platform
# endif # endif
return g; return g;
@ -309,7 +260,17 @@ static void del_context(GLContext ctx) {
if (!nContext) gl_remove_displaylist_fonts(); if (!nContext) gl_remove_displaylist_fonts();
} }
# ifdef WIN32 #if defined(USE_X11)
GLContext fl_create_gl_context(XVisualInfo* vis) {
GLContext shared_ctx = context_list ? context_list[0] : 0;
GLContext context = glXCreateContext(fl_display, vis, shared_ctx, 1);
if (context)
add_context(context);
return context;
}
#elif defined(WIN32)
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) {
Fl_X* i = Fl_X::i(window); Fl_X* i = Fl_X::i(window);
@ -332,21 +293,6 @@ GLContext fl_create_gl_context(Fl_Window* window, const Fl_Gl_Choice* g, int lay
return context; return context;
} }
# elif defined(__APPLE_QD__)
GLContext fl_create_gl_context(Fl_Window* window, const Fl_Gl_Choice* g, int layer) {
GLContext context, shared_ctx = context_list ? context_list[0] : 0;
context = aglCreateContext( g->pixelformat, shared_ctx);
if (!context) return 0;
add_context((GLContext)context);
if ( window->parent() ) {
Rect wrect; GetWindowPortBounds( fl_xid(window), &wrect );
GLint rect[] = { window->x(), wrect.bottom-window->h()-window->y(), window->w(), window->h() };
aglSetInteger( (GLContext)context, AGL_BUFFER_RECT, rect );
aglEnable( (GLContext)context, AGL_BUFFER_RECT );
}
aglSetDrawable( context, GetWindowPort( fl_xid(window) ) );
return (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
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) {
@ -364,15 +310,7 @@ GLContext fl_create_gl_context(Fl_Window* window, const Fl_Gl_Choice* g, int lay
return (context); return (context);
} }
# else # else
# error unsupported platform
GLContext fl_create_gl_context(XVisualInfo* vis) {
GLContext shared_ctx = context_list ? context_list[0] : 0;
GLContext context = glXCreateContext(fl_display, vis, shared_ctx, 1);
if (context)
add_context(context);
return context;
}
# endif # endif
static GLContext cached_context; static GLContext cached_context;
@ -382,17 +320,10 @@ void fl_set_gl_context(Fl_Window* w, GLContext context) {
if (context != cached_context || w != cached_window) { if (context != cached_context || w != cached_window) {
cached_context = context; cached_context = context;
cached_window = w; cached_window = w;
# ifdef WIN32 # if defined(USE_X11)
glXMakeCurrent(fl_display, fl_xid(w), context);
# elif defined(WIN32)
wglMakeCurrent(Fl_X::i(w)->private_dc, context); wglMakeCurrent(Fl_X::i(w)->private_dc, context);
# elif defined(__APPLE_QD__)
if ( w->parent() ) { //: resize our GL buffer rectangle
Rect wrect; GetWindowPortBounds( fl_xid(w), &wrect );
GLint rect[] = { w->x(), wrect.bottom-w->h()-w->y(), w->w(), w->h() };
aglSetInteger( context, AGL_BUFFER_RECT, rect );
aglEnable( context, AGL_BUFFER_RECT );
}
aglSetDrawable(context, GetWindowPort( fl_xid(w) ) );
aglSetCurrentContext(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
@ -404,7 +335,7 @@ void fl_set_gl_context(Fl_Window* w, GLContext context) {
aglSetDrawable(context, GetWindowPort( fl_xid(w) ) ); aglSetDrawable(context, GetWindowPort( fl_xid(w) ) );
aglSetCurrentContext(context); aglSetCurrentContext(context);
# else # else
glXMakeCurrent(fl_display, fl_xid(w), context); # error unsupported platform
# endif # endif
} }
} }
@ -412,33 +343,31 @@ void fl_set_gl_context(Fl_Window* w, GLContext context) {
void fl_no_gl_context() { void fl_no_gl_context() {
cached_context = 0; cached_context = 0;
cached_window = 0; cached_window = 0;
# ifdef WIN32 # if defined(USE_X11)
glXMakeCurrent(fl_display, 0, 0);
# elif defined(WIN32)
wglMakeCurrent(0, 0); wglMakeCurrent(0, 0);
# elif defined(__APPLE_QD__)
aglSetCurrentContext(0);
# 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
aglSetCurrentContext(0); aglSetCurrentContext(0);
# else # else
glXMakeCurrent(fl_display, 0, 0); # error unsupported platform
# endif # endif
} }
void fl_delete_gl_context(GLContext context) { void fl_delete_gl_context(GLContext context) {
if (cached_context == context) fl_no_gl_context(); if (cached_context == context) fl_no_gl_context();
# ifdef WIN32 # if defined(USE_X11)
glXDestroyContext(fl_display, context);
# elif defined(WIN32)
wglDeleteContext(context); wglDeleteContext(context);
# elif defined(__APPLE_QD__)
aglSetCurrentContext( NULL );
aglSetDrawable( context, NULL );
aglDestroyContext( 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
aglSetCurrentContext( NULL ); aglSetCurrentContext( NULL );
aglSetDrawable( context, NULL ); aglSetDrawable( context, NULL );
aglDestroyContext( context ); aglDestroyContext( context );
# else # else
glXDestroyContext(fl_display, context); # error unsupported platform
# endif # endif
del_context(context); del_context(context);
} }

39
src/Fl_Gl_Window.cxx

@ -122,22 +122,23 @@ int Fl_Gl_Window::mode(int m, const int *a) {
mode_ = m; alist = a; mode_ = m; alist = a;
if (shown()) { if (shown()) {
g = Fl_Gl_Choice::find(m, a); g = Fl_Gl_Choice::find(m, a);
#if defined(WIN32)
#if defined(USE_X11)
// under X, if the visual changes we must make a new X window (yuck!):
if (!g || g->vis->visualid!=oldg->vis->visualid || (oldmode^m)&FL_DOUBLE) {
hide();
show();
}
#elif defined(WIN32)
if (!g || (oldmode^m)&(FL_DOUBLE|FL_STEREO)) { if (!g || (oldmode^m)&(FL_DOUBLE|FL_STEREO)) {
hide(); hide();
show(); show();
} }
#elif defined(__APPLE_QD__)
redraw();
#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
redraw(); redraw();
#else #else
// under X, if the visual changes we must make a new X window (yuck!): # error unsupported platform
if (!g || g->vis->visualid!=oldg->vis->visualid || (oldmode^m)&FL_DOUBLE) {
hide();
show();
}
#endif #endif
} else { } else {
g = 0; g = 0;
@ -224,7 +225,9 @@ void Fl_Gl_Window::ortho() {
It is called automatically after the draw() method is called. It is called automatically after the draw() method is called.
*/ */
void Fl_Gl_Window::swap_buffers() { void Fl_Gl_Window::swap_buffers() {
#ifdef WIN32 #if defined(USE_X11)
glXSwapBuffers(fl_display, fl_xid(this));
#elif defined(WIN32)
# if HAVE_GL_OVERLAY # if HAVE_GL_OVERLAY
// Do not swap the overlay, to match GLX: // Do not swap the overlay, to match GLX:
BOOL ret = wglSwapLayerBuffers(Fl_X::i(this)->private_dc, WGL_SWAP_MAIN_PLANE); BOOL ret = wglSwapLayerBuffers(Fl_X::i(this)->private_dc, WGL_SWAP_MAIN_PLANE);
@ -232,13 +235,11 @@ void Fl_Gl_Window::swap_buffers() {
# else # else
SwapBuffers(Fl_X::i(this)->private_dc); SwapBuffers(Fl_X::i(this)->private_dc);
# endif # endif
#elif defined(__APPLE_QD__)
aglSwapBuffers((AGLContext)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
aglSwapBuffers((AGLContext)context_); aglSwapBuffers((AGLContext)context_);
#else #else
glXSwapBuffers(fl_display, fl_xid(this)); # error unsupported platform
#endif #endif
} }
@ -253,15 +254,7 @@ void Fl_Gl_Window::flush() {
uchar save_valid_f = valid_f_; uchar save_valid_f = valid_f_;
#endif #endif
#ifdef __APPLE_QD__ #if defined(__APPLE_QUARTZ__)
//: clear previous clipping in this shared port
GrafPtr port = GetWindowPort( fl_xid(this) );
Rect rect; SetRect( &rect, 0, 0, 0x7fff, 0x7fff );
GrafPtr old; GetPort( &old );
SetPort( port );
ClipRect( &rect );
SetPort( old );
#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
//: clear previous clipping in this shared port //: clear previous clipping in this shared port
GrafPtr port = GetWindowPort( fl_xid(this) ); GrafPtr port = GetWindowPort( fl_xid(this) );
@ -309,9 +302,7 @@ void Fl_Gl_Window::flush() {
glDrawBuffer(GL_BACK); glDrawBuffer(GL_BACK);
if (!SWAP_TYPE) { if (!SWAP_TYPE) {
#ifdef __APPLE_QD__ #if defined __APPLE_QUARTZ__
SWAP_TYPE = COPY;
#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
SWAP_TYPE = COPY; SWAP_TYPE = COPY;
#else #else

76
src/Fl_Image.cxx

@ -482,56 +482,8 @@ void Fl_RGB_Image::draw(int XP, int YP, int WP, int HP, int cx, int cy) {
} }
#endif #endif
} }
#ifdef WIN32
if (mask) { #if defined(USE_X11)
HDC new_gc = CreateCompatibleDC(fl_gc);
int save = SaveDC(new_gc);
SelectObject(new_gc, (void*)mask);
BitBlt(fl_gc, X, Y, W, H, new_gc, cx, cy, SRCAND);
SelectObject(new_gc, (void*)id);
BitBlt(fl_gc, X, Y, W, H, new_gc, cx, cy, SRCPAINT);
RestoreDC(new_gc,save);
DeleteDC(new_gc);
} else if (d()==2 || d()==4) {
fl_copy_offscreen_with_alpha(X, Y, W, H, (Fl_Offscreen)id, cx, cy);
} else {
fl_copy_offscreen(X, Y, W, H, (Fl_Offscreen)id, cx, cy);
}
#elif defined(__APPLE_QD__)
if (mask) {
Rect src, dst;
// MRS: STR #114 says we should be using cx, cy, W, and H...
// src.left = 0; src.right = w();
// src.top = 0; src.bottom = h();
// dst.left = X; dst.right = X+w();
// dst.top = Y; dst.bottom = Y+h();
src.left = cx; src.right = cx+W;
src.top = cy; src.bottom = cy+H;
dst.left = X; dst.right = X+W;
dst.top = Y; dst.bottom = Y+H;
RGBColor rgb;
rgb.red = 0xffff; rgb.green = 0xffff; rgb.blue = 0xffff;
RGBBackColor(&rgb);
rgb.red = 0x0000; rgb.green = 0x0000; rgb.blue = 0x0000;
RGBForeColor(&rgb);
CopyMask(GetPortBitMapForCopyBits((GrafPtr)id),
GetPortBitMapForCopyBits((GrafPtr)mask),
GetPortBitMapForCopyBits(GetWindowPort(fl_window)),
&src, &src, &dst);
} else if (id) fl_copy_offscreen(X, Y, W, H, (Fl_Offscreen)id, cx, cy);
else {
// Composite image with alpha manually each time...
alpha_blend(this, X, Y, W, H, cx, cy);
}
#elif defined(__APPLE_QUARTZ__)
if (id && fl_gc) {
CGRect rect = { { X, Y }, { W, H } };
Fl_X::q_begin_image(rect, cx, cy, w(), h());
CGContextDrawImage(fl_gc, rect, (CGImageRef)id);
Fl_X::q_end_image();
}
#else
if (id) { if (id) {
if (mask) { if (mask) {
// I can't figure out how to combine a mask with existing region, // I can't figure out how to combine a mask with existing region,
@ -557,6 +509,30 @@ void Fl_RGB_Image::draw(int XP, int YP, int WP, int HP, int cx, int cy) {
// Composite image with alpha manually each time... // Composite image with alpha manually each time...
alpha_blend(this, X, Y, W, H, cx, cy); alpha_blend(this, X, Y, W, H, cx, cy);
} }
#elif defined(WIN32)
if (mask) {
HDC new_gc = CreateCompatibleDC(fl_gc);
int save = SaveDC(new_gc);
SelectObject(new_gc, (void*)mask);
BitBlt(fl_gc, X, Y, W, H, new_gc, cx, cy, SRCAND);
SelectObject(new_gc, (void*)id);
BitBlt(fl_gc, X, Y, W, H, new_gc, cx, cy, SRCPAINT);
RestoreDC(new_gc,save);
DeleteDC(new_gc);
} else if (d()==2 || d()==4) {
fl_copy_offscreen_with_alpha(X, Y, W, H, (Fl_Offscreen)id, cx, cy);
} else {
fl_copy_offscreen(X, Y, W, H, (Fl_Offscreen)id, cx, cy);
}
#elif defined(__APPLE_QUARTZ__)
if (id && fl_gc) {
CGRect rect = { { X, Y }, { W, H } };
Fl_X::q_begin_image(rect, cx, cy, w(), h());
CGContextDrawImage(fl_gc, rect, (CGImageRef)id);
Fl_X::q_end_image();
}
#else
# error unsupported platform
#endif #endif
} }

58
src/Fl_Pixmap.cxx

@ -118,45 +118,8 @@ void Fl_Pixmap::draw(int XP, int YP, int WP, int HP, int cx, int cy) {
fl_end_offscreen(); fl_end_offscreen();
#endif #endif
} }
#ifdef WIN32
if (mask) { #if defined(USE_X11)
HDC new_gc = CreateCompatibleDC(fl_gc);
int save = SaveDC(new_gc);
SelectObject(new_gc, (void*)mask);
BitBlt(fl_gc, X, Y, W, H, new_gc, cx, cy, SRCAND);
SelectObject(new_gc, (void*)id);
BitBlt(fl_gc, X, Y, W, H, new_gc, cx, cy, SRCPAINT);
RestoreDC(new_gc,save);
DeleteDC(new_gc);
} else {
fl_copy_offscreen(X, Y, W, H, (Fl_Offscreen)id, cx, cy);
}
#elif defined(__APPLE_QD__)
if (mask) {
Rect src, dst;
src.left = cx; src.right = cx+W;
src.top = cy; src.bottom = cy+H;
dst.left = X; dst.right = X+W;
dst.top = Y; dst.bottom = Y+H;
RGBColor rgb, oldfg, oldbg;
GetForeColor(&oldfg);
GetBackColor(&oldbg);
rgb.red = 0xffff; rgb.green = 0xffff; rgb.blue = 0xffff;
RGBBackColor(&rgb);
rgb.red = 0x0000; rgb.green = 0x0000; rgb.blue = 0x0000;
RGBForeColor(&rgb);
CopyMask(GetPortBitMapForCopyBits((GrafPtr)id),
GetPortBitMapForCopyBits((GrafPtr)mask),
GetPortBitMapForCopyBits(GetWindowPort(fl_window)),
&src, &src, &dst);
RGBBackColor(&oldbg);
RGBForeColor(&oldfg);
} else {
fl_copy_offscreen(X, Y, W, H, (Fl_Offscreen)id, cx, cy);
}
#elif defined(__APPLE_QUARTZ__)
fl_copy_offscreen(X, Y, W, H, (Fl_Offscreen)id, cx, cy);
#else
if (mask) { if (mask) {
// I can't figure out how to combine a mask with existing region, // I can't figure out how to combine a mask with existing region,
// so cut the image down to a clipped rectangle: // so cut the image down to a clipped rectangle:
@ -175,6 +138,23 @@ void Fl_Pixmap::draw(int XP, int YP, int WP, int HP, int cx, int cy) {
XSetClipOrigin(fl_display, fl_gc, 0, 0); XSetClipOrigin(fl_display, fl_gc, 0, 0);
fl_restore_clip(); fl_restore_clip();
} }
#elif defined(WIN32)
if (mask) {
HDC new_gc = CreateCompatibleDC(fl_gc);
int save = SaveDC(new_gc);
SelectObject(new_gc, (void*)mask);
BitBlt(fl_gc, X, Y, W, H, new_gc, cx, cy, SRCAND);
SelectObject(new_gc, (void*)id);
BitBlt(fl_gc, X, Y, W, H, new_gc, cx, cy, SRCPAINT);
RestoreDC(new_gc,save);
DeleteDC(new_gc);
} else {
fl_copy_offscreen(X, Y, W, H, (Fl_Offscreen)id, cx, cy);
}
#elif defined(__APPLE_QUARTZ__)
fl_copy_offscreen(X, Y, W, H, (Fl_Offscreen)id, cx, cy);
#else
# error unsupported platform
#endif #endif
} }

12
src/Fl_Widget.cxx

@ -164,7 +164,12 @@ Fl_Widget::draw_focus(Fl_Boxtype B, int X, int Y, int W, int H) const {
fl_color(fl_contrast(FL_BLACK, color())); fl_color(fl_contrast(FL_BLACK, color()));
#if defined(WIN32) || defined(__APPLE_QD__) #if defined(USE_X11) || defined(__APPLE_QUARTZ__)
fl_line_style(FL_DOT);
fl_rect(X + Fl::box_dx(B), Y + Fl::box_dy(B),
W - Fl::box_dw(B) - 1, H - Fl::box_dh(B) - 1);
fl_line_style(FL_SOLID);
#elif defined(WIN32)
// Windows 95/98/ME do not implement the dotted line style, so draw // Windows 95/98/ME do not implement the dotted line style, so draw
// every other pixel around the focus area... // every other pixel around the focus area...
// //
@ -183,10 +188,7 @@ Fl_Widget::draw_focus(Fl_Boxtype B, int X, int Y, int W, int H) const {
for (xx = W; xx > 0; xx --, i ++) if (i & 1) fl_point(X + xx, Y + H); for (xx = W; xx > 0; xx --, i ++) if (i & 1) fl_point(X + xx, Y + H);
for (yy = H; yy > 0; yy --, i ++) if (i & 1) fl_point(X, Y + yy); for (yy = H; yy > 0; yy --, i ++) if (i & 1) fl_point(X, Y + yy);
#else #else
fl_line_style(FL_DOT); # error unsupported platform
fl_rect(X + Fl::box_dx(B), Y + Fl::box_dy(B),
W - Fl::box_dw(B) - 1, H - Fl::box_dh(B) - 1);
fl_line_style(FL_SOLID);
#endif // WIN32 #endif // WIN32
} }

8
src/Fl_Window_fullscreen.cxx

@ -50,15 +50,15 @@ void Fl_Window::border(int b) {
if (!border()) return; if (!border()) return;
set_flag(FL_NOBORDER); set_flag(FL_NOBORDER);
} }
#ifdef WIN32 #if defined(USE_X11)
if (shown()) Fl_X::i(this)->sendxjunk();
#elif defined(WIN32)
// not yet implemented, but it's possible // not yet implemented, but it's possible
// for full fullscreen we have to make the window topmost as well // for full fullscreen we have to make the window topmost as well
#elif defined(__APPLE_QD__)
// warning: not implemented in Quickdraw/Carbon
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
// warning: not implemented in Quartz/Carbon // warning: not implemented in Quartz/Carbon
#else #else
if (shown()) Fl_X::i(this)->sendxjunk(); # error unsupported platform
#endif #endif
} }

11
src/Fl_mac.cxx

@ -680,7 +680,7 @@ static pascal void do_timer(EventLoopTimerRef timer, void* data)
*/ */
static double do_queued_events( double time = 0.0 ) static double do_queued_events( double time = 0.0 )
{ {
static bool been_here = 0; static bool been_here = false;
static RgnHandle rgn; static RgnHandle rgn;
// initialize events and a region that enables mouse move events // initialize events and a region that enables mouse move events
@ -690,7 +690,7 @@ static double do_queued_events( double time = 0.0 )
GetMouse(&mp); GetMouse(&mp);
SetRectRgn(rgn, mp.h, mp.v, mp.h, mp.v); SetRectRgn(rgn, mp.h, mp.v, mp.h, mp.v);
SetEventMask(everyEvent); SetEventMask(everyEvent);
been_here = 1; been_here = true;
} }
OSStatus ret; OSStatus ret;
static EventTargetRef target = 0; static EventTargetRef target = 0;
@ -1569,15 +1569,8 @@ unsigned short mac2fltk(ulong macKey)
void Fl_X::flush() void Fl_X::flush()
{ {
w->flush(); w->flush();
#ifdef __APPLE_QD__
GrafPtr port;
GetPort( &port );
if ( port )
QDFlushPortBuffer( port, 0 );
#elif defined (__APPLE_QUARTZ__)
if (fl_gc) if (fl_gc)
CGContextFlush(fl_gc); CGContextFlush(fl_gc);
#endif
SetOrigin( 0, 0 ); SetOrigin( 0, 0 );
} }

22
src/fl_arci.cxx

@ -73,7 +73,10 @@
*/ */
void fl_arc(int x,int y,int w,int h,double a1,double a2) { void fl_arc(int x,int y,int w,int h,double a1,double a2) {
if (w <= 0 || h <= 0) return; if (w <= 0 || h <= 0) return;
#ifdef WIN32
#if defined(USE_X11)
XDrawArc(fl_display, fl_window, fl_gc, x,y,w-1,h-1, int(a1*64),int((a2-a1)*64));
#elif defined(WIN32)
int xa = x+w/2+int(w*cos(a1/180.0*M_PI)); int xa = x+w/2+int(w*cos(a1/180.0*M_PI));
int ya = y+h/2-int(h*sin(a1/180.0*M_PI)); int ya = y+h/2-int(h*sin(a1/180.0*M_PI));
int xb = x+w/2+int(w*cos(a2/180.0*M_PI)); int xb = x+w/2+int(w*cos(a2/180.0*M_PI));
@ -82,10 +85,6 @@ void fl_arc(int x,int y,int w,int h,double a1,double a2) {
if (xa == xb && ya == yb) SetPixel(fl_gc, xa, ya, fl_RGB()); if (xa == xb && ya == yb) SetPixel(fl_gc, xa, ya, fl_RGB());
else Arc(fl_gc, x, y, x+w, y+h, xa, ya, xb, yb); else Arc(fl_gc, x, y, x+w, y+h, xa, ya, xb, yb);
} else Arc(fl_gc, x, y, x+w, y+h, xa, ya, xb, yb); } else Arc(fl_gc, x, y, x+w, y+h, xa, ya, xb, yb);
#elif defined(__APPLE_QD__)
Rect r; r.left=x; r.right=x+w; r.top=y; r.bottom=y+h;
a1 = a2-a1; a2 = 450-a2;
FrameArc(&r, (short int)a2, (short int)a1);
#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;
@ -101,7 +100,7 @@ void fl_arc(int x,int y,int w,int h,double a1,double a2) {
} }
CGContextStrokePath(fl_gc); CGContextStrokePath(fl_gc);
#else #else
XDrawArc(fl_display, fl_window, fl_gc, x,y,w-1,h-1, int(a1*64),int((a2-a1)*64)); # error unsupported platform
#endif #endif
} }
@ -119,7 +118,10 @@ void fl_arc(int x,int y,int w,int h,double a1,double a2) {
*/ */
void fl_pie(int x,int y,int w,int h,double a1,double a2) { void fl_pie(int x,int y,int w,int h,double a1,double a2) {
if (w <= 0 || h <= 0) return; if (w <= 0 || h <= 0) return;
#ifdef WIN32
#if defined(USE_X11)
XFillArc(fl_display, fl_window, fl_gc, x,y,w-1,h-1, int(a1*64),int((a2-a1)*64));
#elif defined(WIN32)
if (a1 == a2) return; if (a1 == a2) return;
int xa = x+w/2+int(w*cos(a1/180.0*M_PI)); int xa = x+w/2+int(w*cos(a1/180.0*M_PI));
int ya = y+h/2-int(h*sin(a1/180.0*M_PI)); int ya = y+h/2-int(h*sin(a1/180.0*M_PI));
@ -133,10 +135,6 @@ void fl_pie(int x,int y,int w,int h,double a1,double a2) {
SetPixel(fl_gc, xa, ya, fl_RGB()); SetPixel(fl_gc, xa, ya, fl_RGB());
} else Pie(fl_gc, x, y, x+w, y+h, xa, ya, xb, yb); } else Pie(fl_gc, x, y, x+w, y+h, xa, ya, xb, yb);
} else Pie(fl_gc, x, y, x+w, y+h, xa, ya, xb, yb); } else Pie(fl_gc, x, y, x+w, y+h, xa, ya, xb, yb);
#elif defined(__APPLE_QD__)
Rect r; r.left=x; r.right=x+w; r.top=y; r.bottom=y+h;
a1 = a2-a1; a2 = 450-a2;
PaintArc(&r, (short int)a2, (short int)a1);
#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;
@ -156,7 +154,7 @@ void fl_pie(int x,int y,int w,int h,double a1,double a2) {
} }
CGContextFillPath(fl_gc); CGContextFillPath(fl_gc);
#else #else
XFillArc(fl_display, fl_window, fl_gc, x,y,w-1,h-1, int(a1*64),int((a2-a1)*64)); # error unsupported platform
#endif #endif
} }

18
src/fl_color_mac.cxx

@ -66,13 +66,7 @@ void fl_color(Fl_Color i) {
g = c>>16; g = c>>16;
b = c>> 8; b = c>> 8;
} }
#ifdef __APPLE_QD__ #if defined(__APPLE_QUARTZ__)
RGBColor rgb;
rgb.red = (r<<8)|r;
rgb.green = (g<<8)|g;
rgb.blue = (b<<8)|b;
RGBForeColor(&rgb);
#elif defined(__APPLE_QUARTZ__)
if (!fl_gc) return; // no context yet? We will assign the color later. if (!fl_gc) return; // no context yet? We will assign the color later.
float fr = r/255.0f; float fr = r/255.0f;
float fg = g/255.0f; float fg = g/255.0f;
@ -86,20 +80,14 @@ void fl_color(Fl_Color i) {
void fl_color(uchar r, uchar g, uchar b) { void fl_color(uchar r, uchar g, uchar b) {
fl_color_ = fl_rgb_color(r, g, b); fl_color_ = fl_rgb_color(r, g, b);
#ifdef __APPLE_QD__ #if defined(__APPLE_QUARTZ__)
RGBColor rgb;
rgb.red = (r<<8)|r;
rgb.green = (g<<8)|g;
rgb.blue = (b<<8)|b;
RGBForeColor(&rgb);
#elif defined(__APPLE_QUARTZ__)
float fr = r/255.0f; float fr = r/255.0f;
float fg = g/255.0f; float fg = g/255.0f;
float fb = b/255.0f; float fb = b/255.0f;
CGContextSetRGBFillColor(fl_gc, fr, fg, fb, 1.0f); CGContextSetRGBFillColor(fl_gc, fr, fg, fb, 1.0f);
CGContextSetRGBStrokeColor(fl_gc, fr, fg, fb, 1.0f); CGContextSetRGBStrokeColor(fl_gc, fr, fg, fb, 1.0f);
#else #else
# error : neither Quickdraw nor Quartz defined # error : Quartz not defined
#endif #endif
} }

114
src/fl_draw_image_mac.cxx

@ -56,117 +56,7 @@ static void innards(const uchar *buf, int X, int Y, int W, int H,
{ {
if (!linedelta) linedelta = W*delta; if (!linedelta) linedelta = W*delta;
#ifdef __APPLE_QD__ #if defined(__APPLE_QUARTZ__)
// theoretically, if the current GPort permits, we could write
// directly into it, avoiding the temporary GWorld. For now I
// will go the safe way... .
char direct = 0;
GWorldPtr gw;
Rect bounds;
bounds.left=0; bounds.right=W; bounds.top=0; bounds.bottom=H;
QDErr err = NewGWorld( &gw, 32, &bounds, 0L, 0L, useTempMem );
if (err==noErr && gw) {
PixMapHandle pm = GetGWorldPixMap( gw );
if ( pm ) {
LockPixels( pm );
if ( *pm ) {
uchar *base = (uchar*)GetPixBaseAddr( pm );
if ( base ) {
PixMapPtr pmp = *pm;
// make absolutely sure that we can use a direct memory write to
// create the pixmap!
if ( pmp->pixelType == 16 || pmp->pixelSize == 32 || pmp->cmpCount == 3 || pmp->cmpSize == 8 ) {
int rowBytes = pmp->rowBytes & 0x3fff;
if ( cb )
{
uchar *tmpBuf = new uchar[ W*delta ];
if ( mono ) delta -= 1; else delta -= 3;
for ( int i=0; i<H; i++ )
{
uchar *src = tmpBuf;
uchar *dst = base + i*rowBytes;
cb( userdata, 0, i, W, tmpBuf );
if ( mono ) {
for ( int j=0; j<W; j++ )
{ uchar c = *src++; *dst++ = 0; *dst++ = c; *dst++ = c; *dst++ = c; src += delta; }
} else {
for ( int j=0; j<W; j++ )
{ *dst++ = 0; *dst++ = *src++; *dst++ = *src++; *dst++ = *src++; src += delta; }
}
}
delete[] tmpBuf;
}
else
{
if ( mono ) delta -= 1; else delta -= 3;
for ( int i=0; i<H; i++ )
{
const uchar *src = buf+i*linedelta;
uchar *dst = base + i*rowBytes;
if ( mono ) {
for ( int j=0; j<W; j++ )
{ uchar c = *src++; *dst++ = 0; *dst++ = c; *dst++ = c; *dst++ = c; src += delta; }
} else {
for ( int j=0; j<W; j++ )
{ *dst++ = 0; *dst++ = *src++; *dst++ = *src++; *dst++ = *src++; src += delta; }
}
}
}
fl_copy_offscreen( X, Y, W, H, gw, 0, 0 );
direct = 1;
}
}
}
UnlockPixels( pm );
}
DisposeGWorld( gw );
}
// great. We were able to write the pixels directly into memory, so we can return now.
if ( direct )
return;
// following the very save (and very slow) way to write the image into the give port
if ( cb )
{
uchar *tmpBuf = new uchar[ W*3 ];
for ( int i=0; i<H; i++ )
{
uchar *src = tmpBuf;
cb( userdata, 0, i, W, tmpBuf );
for ( int j=0; j<W; j++ )
{
if ( mono )
{ fl_color( src[0], src[0], src[0] ); src++; }
else
{ fl_color( src[0], src[1], src[2] ); src+=3; }
MoveTo( X+j, Y+i );
Line( 0, 0 );
}
}
delete[] tmpBuf;
}
else
{
for ( int i=0; i<H; i++ )
{
const uchar *src = buf+i*linedelta;
for ( int j=0; j<W; j++ )
{
if ( mono )
fl_color( src[0], src[0], src[0] );
else
fl_color( src[0], src[1], src[2] );
MoveTo( X+j, Y+i );
Line( 0, 0 );
src += delta;
}
}
}
#elif defined(__APPLE_QUARTZ__)
const void *array = buf; const void *array = buf;
uchar *tmpBuf = 0; uchar *tmpBuf = 0;
if (cb) { if (cb) {
@ -245,7 +135,7 @@ static void innards(const uchar *buf, int X, int Y, int W, int H,
} }
CGContextSetShouldAntialias(fl_gc, true); CGContextSetShouldAntialias(fl_gc, true);
#else #else
# error : you must defined __APPLE_QD__ or __APPLE_QUARTZ__ # error : you must define __APPLE_QUARTZ__
#endif #endif
} }

80
src/fl_font_mac.cxx

@ -38,25 +38,7 @@ Fl_Font_Descriptor::Fl_Font_Descriptor(const char* name, Fl_Fontsize Size) {
# if HAVE_GL # if HAVE_GL
listbase = 0; listbase = 0;
# endif # endif
#if defined(__APPLE_QD__)
knowMetrics = 0;
switch (*name++) {
case 'I': face = italic; break;
case 'P': face = italic | bold; break;
case 'B': face = bold; break;
default: face = 0; break;
}
unsigned char fn[80];
fn[0] = strlen(name); strcpy((char*)(fn+1), name);
GetFNum(fn, &font);
size = Size;
FMInput fIn = { font, size, face, 0, 0, { 1, 1}, { 1, 1} };
FMOutput *fOut = FMSwapFont(&fIn);
ascent = fOut->ascent; //: the following three lines give only temporary aproimations
descent = fOut->descent;
for (int i=0; i<256; i++) width[i] = fOut->widMax;
minsize = maxsize = size;
#elif defined(__APPLE_QUARTZ__)
// knowWidths = 0; // knowWidths = 0;
// OpenGL needs those for its font handling // OpenGL needs those for its font handling
q_name = strdup(name); q_name = strdup(name);
@ -130,7 +112,6 @@ 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 // defined(__APPLE_QD__)
} }
Fl_Font_Descriptor* fl_fontsize = 0L; Fl_Font_Descriptor* fl_fontsize = 0L;
@ -151,33 +132,13 @@ Fl_Font_Descriptor::~Fl_Font_Descriptor() {
#endif #endif
*/ */
if (this == fl_fontsize) fl_fontsize = 0; if (this == fl_fontsize) fl_fontsize = 0;
#ifdef __APPLE_QUARTZ__
ATSUDisposeTextLayout(layout); ATSUDisposeTextLayout(layout);
ATSUDisposeStyle(style); ATSUDisposeStyle(style);
#endif
} }
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
static Fl_Fontdesc built_in_table[] = { static Fl_Fontdesc built_in_table[] = {
#ifdef __APPLE_QD__
{" Arial"},
{"BArial"},
{"IArial"},
{"PArial"},
{" Courier New"},
{"BCourier New"},
{"ICourier New"},
{"PCourier New"},
{" Times New Roman"},
{"BTimes New Roman"},
{"ITimes New Roman"},
{"PTimes New Roman"},
{" Symbol"},
{" Chicago"},
{"BChicago"},
{" Webdings"},
#elif defined(__APPLE_QUARTZ__)
{"Arial"}, {"Arial"},
{"Arial Bold"}, {"Arial Bold"},
{"Arial Italic"}, {"Arial Italic"},
@ -194,7 +155,6 @@ static Fl_Fontdesc built_in_table[] = {
{"Monaco"}, {"Monaco"},
{"Andale Mono"}, // there is no bold Monaco font on standard Mac {"Andale Mono"}, // there is no bold Monaco font on standard Mac
{"Webdings"}, {"Webdings"},
#endif
}; };
static UniChar *utfWbuf = 0; static UniChar *utfWbuf = 0;
@ -218,22 +178,7 @@ Fl_Fontdesc* fl_fonts = built_in_table;
void fl_font(Fl_Font_Descriptor* s) { void fl_font(Fl_Font_Descriptor* s) {
fl_fontsize = s; fl_fontsize = s;
#ifdef __APPLE_QD__ #if defined(__APPLE_QUARTZ__)
if (fl_window) SetPort( GetWindowPort(fl_window) );
TextFont(fl_fontsize->font); //: select font into current QuickDraw GC
TextFace(fl_fontsize->face);
TextSize(fl_fontsize->size);
if (!fl_fontsize->knowMetrics) { //: get the true metrics for the current GC
//: (fails on multiple monitors with different dpi's!)
FontInfo fi; GetFontInfo(&fi);
fl_fontsize->ascent = fi.ascent;
fl_fontsize->descent = fi.descent;
FMetricRec mr; FontMetrics(&mr);
short *f = (short*)*mr.wTabHandle; //: get the char size table
for (int i=0; i<256; i++) fl_fontsize->width[i] = f[2*i];
fl_fontsize->knowMetrics = 1;
}
#elif defined(__APPLE_QUARTZ__)
// we will use fl_fontsize later to access the required style and layout // we will use fl_fontsize later to access the required style and layout
#else #else
# error : need to defined either Quartz or Quickdraw # error : need to defined either Quartz or Quickdraw
@ -281,9 +226,6 @@ int fl_descent() {
} }
double fl_width(const UniChar* txt, int n) { double fl_width(const UniChar* txt, int n) {
#ifdef __APPLE_QD__
return (double)TextWidth( txt, 0, n );
#else
if (!fl_fontsize) { if (!fl_fontsize) {
check_default_font(); // avoid a crash! check_default_font(); // avoid a crash!
if (!fl_fontsize) if (!fl_fontsize)
@ -310,7 +252,6 @@ 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
} }
double fl_width(const char* txt, int n) { double fl_width(const char* txt, int n) {
@ -330,18 +271,10 @@ double fl_width(unsigned int wc) {
void fl_draw(const char *str, int n, float x, float y); void fl_draw(const char *str, int n, float x, float y);
void fl_draw(const char* str, int n, int x, int y) { void fl_draw(const char* str, int n, int x, int y) {
#ifdef __APPLE_QD__
MoveTo(x, y);
DrawText((const char *)str, 0, n);
#elif defined(__APPLE_QUARTZ__)
fl_draw(str, n, (float)x-0.0f, (float)y-0.5f); fl_draw(str, n, (float)x-0.0f, (float)y-0.5f);
#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) {
#ifdef __APPLE_QD__
fl_draw(str, n, (int)x, (int)y); // FIXME no utf8 rtl impl for QD
#elif defined(__APPLE_QUARTZ__)
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);
@ -358,15 +291,9 @@ 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));
#else
# error : neither Quartz no Quickdraw chosen
#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) {
#if defined __APPLE_QD__
fl_draw(c, n, x, y);
#elif defined __APPLE_QUARTZ__
// I guess with ATSU the thing to do is force the layout mode to RTL and let ATSU draw the text... // 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;
@ -383,9 +310,6 @@ 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));
#else
# error : neither Quartz no Quickdraw chosen
#endif
} }
// //

79
src/fl_line_style.cxx

@ -46,7 +46,39 @@ void fl_quartz_restore_line_style_() {
#endif #endif
void fl_line_style(int style, int width, char* dashes) { void fl_line_style(int style, int width, char* dashes) {
#ifdef WIN32
#if defined(USE_X11)
int ndashes = dashes ? strlen(dashes) : 0;
// emulate the WIN32 dash patterns on X
char buf[7];
if (!ndashes && (style&0xff)) {
int w = width ? width : 1;
char dash, dot, gap;
// adjust lengths to account for cap:
if (style & 0x200) {
dash = char(2*w);
dot = 1; // unfortunately 0 does not work
gap = char(2*w-1);
} else {
dash = char(3*w);
dot = gap = char(w);
}
char* p = dashes = buf;
switch (style & 0xff) {
case FL_DASH: *p++ = dash; *p++ = gap; break;
case FL_DOT: *p++ = dot; *p++ = gap; break;
case FL_DASHDOT: *p++ = dash; *p++ = gap; *p++ = dot; *p++ = gap; break;
case FL_DASHDOTDOT: *p++ = dash; *p++ = gap; *p++ = dot; *p++ = gap; *p++ = dot; *p++ = gap; break;
}
ndashes = p-buf;
}
static int Cap[4] = {CapButt, CapButt, CapRound, CapProjecting};
static int Join[4] = {JoinMiter, JoinMiter, JoinRound, JoinBevel};
XSetLineAttributes(fl_display, fl_gc, width,
ndashes ? LineOnOffDash : LineSolid,
Cap[(style>>8)&3], Join[(style>>12)&3]);
if (ndashes) XSetDashes(fl_display, fl_gc, 0, dashes, ndashes);
#elif defined(WIN32)
// According to Bill, the "default" cap and join should be the // According to Bill, the "default" cap and join should be the
// "fastest" mode supported for the platform. I don't know why // "fastest" mode supported for the platform. I don't know why
// they should be different (same graphics cards, etc., right?) MRS // they should be different (same graphics cards, etc., right?) MRS
@ -71,20 +103,6 @@ void fl_line_style(int style, int width, char* dashes) {
DeleteObject(oldpen); DeleteObject(oldpen);
DeleteObject(fl_current_xmap->pen); DeleteObject(fl_current_xmap->pen);
fl_current_xmap->pen = newpen; fl_current_xmap->pen = newpen;
#elif defined(__APPLE_QD__)
// QuickDraw supports pen size and pattern, but no arbitrary line styles.
static Pattern styles[] = {
{ { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } }, // FL_SOLID
{ { 0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f } }, // FL_DASH
{ { 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55 } } // FL_DOT
};
if (!width) width = 1;
PenSize(width, width);
style &= 0xff;
if (style > 2) style = 2;
PenPat(styles + style);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
static enum CGLineCap Cap[4] = { kCGLineCapButt, kCGLineCapButt, static enum CGLineCap Cap[4] = { kCGLineCapButt, kCGLineCapButt,
kCGLineCapRound, kCGLineCapSquare }; kCGLineCapRound, kCGLineCapSquare };
@ -126,36 +144,7 @@ void fl_line_style(int style, int width, char* dashes) {
} }
fl_quartz_restore_line_style_(); fl_quartz_restore_line_style_();
#else #else
int ndashes = dashes ? strlen(dashes) : 0; # error unsupported platform
// emulate the WIN32 dash patterns on X
char buf[7];
if (!ndashes && (style&0xff)) {
int w = width ? width : 1;
char dash, dot, gap;
// adjust lengths to account for cap:
if (style & 0x200) {
dash = char(2*w);
dot = 1; // unfortunately 0 does not work
gap = char(2*w-1);
} else {
dash = char(3*w);
dot = gap = char(w);
}
char* p = dashes = buf;
switch (style & 0xff) {
case FL_DASH: *p++ = dash; *p++ = gap; break;
case FL_DOT: *p++ = dot; *p++ = gap; break;
case FL_DASHDOT: *p++ = dash; *p++ = gap; *p++ = dot; *p++ = gap; break;
case FL_DASHDOTDOT: *p++ = dash; *p++ = gap; *p++ = dot; *p++ = gap; *p++ = dot; *p++ = gap; break;
}
ndashes = p-buf;
}
static int Cap[4] = {CapButt, CapButt, CapRound, CapProjecting};
static int Join[4] = {JoinMiter, JoinMiter, JoinRound, JoinBevel};
XSetLineAttributes(fl_display, fl_gc, width,
ndashes ? LineOnOffDash : LineSolid,
Cap[(style>>8)&3], Join[(style>>12)&3]);
if (ndashes) XSetDashes(fl_display, fl_gc, 0, dashes, ndashes);
#endif #endif
} }

16
src/fl_overlay.cxx

@ -48,24 +48,22 @@ static int bgx, bgy, bgw, bgh;
static void draw_current_rect() { static void draw_current_rect() {
#ifdef USE_XOR #ifdef USE_XOR
# ifdef WIN32 # if defined(USE_X11)
XSetFunction(fl_display, fl_gc, GXxor);
XSetForeground(fl_display, fl_gc, 0xffffffff);
XDrawRectangle(fl_display, fl_window, fl_gc, px, py, pw, ph);
XSetFunction(fl_display, fl_gc, GXcopy);
# elif defined(WIN32)
int old = SetROP2(fl_gc, R2_NOT); int old = SetROP2(fl_gc, R2_NOT);
fl_rect(px, py, pw, ph); fl_rect(px, py, pw, ph);
SetROP2(fl_gc, old); SetROP2(fl_gc, old);
# elif defined(__APPLE_QD__)
PenMode( patXor );
fl_rect(px, py, pw, ph);
PenMode( patCopy );
# elif defined(__APPLE_QUARTZ__) # elif defined(__APPLE_QUARTZ__)
// warning: Quartz does not support xor drawing // warning: Quartz does not support xor drawing
// Use the Fl_Overlay_Window instead. // Use the Fl_Overlay_Window instead.
fl_color(FL_WHITE); fl_color(FL_WHITE);
fl_rect(px, py, pw, ph); fl_rect(px, py, pw, ph);
# else # else
XSetFunction(fl_display, fl_gc, GXxor); # error unsupported platform
XSetForeground(fl_display, fl_gc, 0xffffffff);
XDrawRectangle(fl_display, fl_window, fl_gc, px, py, pw, ph);
XSetFunction(fl_display, fl_gc, GXcopy);
# endif # endif
#else #else
if (bgN) { free(bgN); bgN = 0L; } if (bgN) { free(bgN); bgN = 0L; }

358
src/fl_rect.cxx

@ -50,23 +50,21 @@ extern float fl_quartz_line_width_;
*/ */
void fl_rect(int x, int y, int w, int h) { void fl_rect(int x, int y, int w, int h) {
if (w<=0 || h<=0) return; if (w<=0 || h<=0) return;
#ifdef WIN32 #if defined(USE_X11)
XDrawRectangle(fl_display, fl_window, fl_gc, x, y, w-1, h-1);
#elif defined(WIN32)
MoveToEx(fl_gc, x, y, 0L); MoveToEx(fl_gc, x, y, 0L);
LineTo(fl_gc, x+w-1, y); LineTo(fl_gc, x+w-1, y);
LineTo(fl_gc, x+w-1, y+h-1); LineTo(fl_gc, x+w-1, y+h-1);
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_QD__)
Rect rect;
SetRect(&rect, x, y, x+w, y+h);
FrameRect(&rect);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
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);
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#else #else
XDrawRectangle(fl_display, fl_window, fl_gc, x, y, w-1, h-1); # error unsupported platform
#endif #endif
} }
@ -75,22 +73,20 @@ void fl_rect(int x, int y, int w, int h) {
*/ */
void fl_rectf(int x, int y, int w, int h) { void fl_rectf(int x, int y, int w, int h) {
if (w<=0 || h<=0) return; if (w<=0 || h<=0) return;
#ifdef WIN32 #if defined(USE_X11)
if (w && h) XFillRectangle(fl_display, fl_window, fl_gc, x, y, w, h);
#elif defined(WIN32)
RECT rect; RECT rect;
rect.left = x; rect.top = y; rect.left = x; rect.top = y;
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_QD__)
Rect rect;
SetRect(&rect, x, y, x+w, y+h);
PaintRect(&rect);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
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);
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#else #else
if (w && h) XFillRectangle(fl_display, fl_window, fl_gc, x, y, w, h); # error unsupported platform
#endif #endif
} }
@ -98,10 +94,10 @@ void fl_rectf(int x, int y, int w, int h) {
Draw horizontal line from x,y to x1,y Draw horizontal line from x,y to x1,y
*/ */
void fl_xyline(int x, int y, int x1) { void fl_xyline(int x, int y, int x1) {
#ifdef WIN32 #if defined(USE_X11)
XDrawLine(fl_display, fl_window, fl_gc, x, y, x1, y);
#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_QD__)
MoveTo(x, y); LineTo(x1, y);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
CGContextMoveToPoint(fl_gc, x, y); CGContextMoveToPoint(fl_gc, x, y);
@ -109,7 +105,7 @@ void fl_xyline(int x, int y, int x1) {
CGContextStrokePath(fl_gc); CGContextStrokePath(fl_gc);
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#else #else
XDrawLine(fl_display, fl_window, fl_gc, x, y, x1, y); # error unsupported platform
#endif #endif
} }
@ -117,16 +113,17 @@ void fl_xyline(int x, int y, int x1) {
Draw horizontal line from x,y to x1,y, then vertical from x1,y to x1,y2 Draw horizontal line from x,y to x1,y, then vertical from x1,y to x1,y2
*/ */
void fl_xyline(int x, int y, int x1, int y2) { void fl_xyline(int x, int y, int x1, int y2) {
#ifdef WIN32 #if defined (USE_X11)
XPoint p[3];
p[0].x = x; p[0].y = p[1].y = y;
p[1].x = p[2].x = x1; p[2].y = y2;
XDrawLines(fl_display, fl_window, fl_gc, p, 3, 0);
#elif defined(WIN32)
if (y2 < y) y2--; if (y2 < y) y2--;
else y2++; else y2++;
MoveToEx(fl_gc, x, y, 0L); MoveToEx(fl_gc, x, y, 0L);
LineTo(fl_gc, x1, y); LineTo(fl_gc, x1, y);
LineTo(fl_gc, x1, y2); LineTo(fl_gc, x1, y2);
#elif defined(__APPLE_QD__)
MoveTo(x, y);
LineTo(x1, y);
LineTo(x1, y2);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
CGContextMoveToPoint(fl_gc, x, y); CGContextMoveToPoint(fl_gc, x, y);
@ -135,10 +132,7 @@ void fl_xyline(int x, int y, int x1, int y2) {
CGContextStrokePath(fl_gc); CGContextStrokePath(fl_gc);
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#else #else
XPoint p[3]; #error unsupported platform
p[0].x = x; p[0].y = p[1].y = y;
p[1].x = p[2].x = x1; p[2].y = y2;
XDrawLines(fl_display, fl_window, fl_gc, p, 3, 0);
#endif #endif
} }
@ -147,18 +141,19 @@ void fl_xyline(int x, int y, int x1, int y2) {
and then another horizontal from x1,y2 to x3,y2 and then another horizontal from x1,y2 to x3,y2
*/ */
void fl_xyline(int x, int y, int x1, int y2, int x3) { void fl_xyline(int x, int y, int x1, int y2, int x3) {
#ifdef WIN32 #if defined(USE_X11)
XPoint p[4];
p[0].x = x; p[0].y = p[1].y = y;
p[1].x = p[2].x = x1; p[2].y = p[3].y = y2;
p[3].x = x3;
XDrawLines(fl_display, fl_window, fl_gc, p, 4, 0);
#elif defined(WIN32)
if(x3 < x1) x3--; if(x3 < x1) x3--;
else x3++; else x3++;
MoveToEx(fl_gc, x, y, 0L); MoveToEx(fl_gc, x, y, 0L);
LineTo(fl_gc, x1, y); LineTo(fl_gc, x1, y);
LineTo(fl_gc, x1, y2); LineTo(fl_gc, x1, y2);
LineTo(fl_gc, x3, y2); LineTo(fl_gc, x3, y2);
#elif defined(__APPLE_QD__)
MoveTo(x, y);
LineTo(x1, y);
LineTo(x1, y2);
LineTo(x3, y2);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
CGContextMoveToPoint(fl_gc, x, y); CGContextMoveToPoint(fl_gc, x, y);
@ -168,11 +163,7 @@ void fl_xyline(int x, int y, int x1, int y2, int x3) {
CGContextStrokePath(fl_gc); CGContextStrokePath(fl_gc);
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#else #else
XPoint p[4]; # error unsupported platform
p[0].x = x; p[0].y = p[1].y = y;
p[1].x = p[2].x = x1; p[2].y = p[3].y = y2;
p[3].x = x3;
XDrawLines(fl_display, fl_window, fl_gc, p, 4, 0);
#endif #endif
} }
@ -180,12 +171,12 @@ void fl_xyline(int x, int y, int x1, int y2, int x3) {
Draw a vertical line from x,y to x,y1 Draw a vertical line from x,y to x,y1
*/ */
void fl_yxline(int x, int y, int y1) { void fl_yxline(int x, int y, int y1) {
#ifdef WIN32 #if defined(USE_X11)
XDrawLine(fl_display, fl_window, fl_gc, x, y, x, y1);
#elif defined(WIN32)
if (y1 < y) y1--; if (y1 < y) 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_QD__)
MoveTo(x, y); LineTo(x, y1);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
CGContextMoveToPoint(fl_gc, x, y); CGContextMoveToPoint(fl_gc, x, y);
@ -193,7 +184,7 @@ void fl_yxline(int x, int y, int y1) {
CGContextStrokePath(fl_gc); CGContextStrokePath(fl_gc);
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#else #else
XDrawLine(fl_display, fl_window, fl_gc, x, y, x, y1); # error unsupported platform
#endif #endif
} }
@ -201,16 +192,17 @@ void fl_yxline(int x, int y, int y1) {
Draw a vertical line from x,y to x,y1 then a horizontal from x,y1 to x2,y1 Draw a vertical line from x,y to x,y1 then a horizontal from x,y1 to x2,y1
*/ */
void fl_yxline(int x, int y, int y1, int x2) { void fl_yxline(int x, int y, int y1, int x2) {
#ifdef WIN32 #if defined(USE_X11)
XPoint p[3];
p[0].x = p[1].x = x; p[0].y = y;
p[1].y = p[2].y = y1; p[2].x = x2;
XDrawLines(fl_display, fl_window, fl_gc, p, 3, 0);
#elif defined(WIN32)
if (x2 > x) x2++; if (x2 > x) x2++;
else x2--; else x2--;
MoveToEx(fl_gc, x, y, 0L); MoveToEx(fl_gc, x, y, 0L);
LineTo(fl_gc, x, y1); LineTo(fl_gc, x, y1);
LineTo(fl_gc, x2, y1); LineTo(fl_gc, x2, y1);
#elif defined(__APPLE_QD__)
MoveTo(x, y);
LineTo(x, y1);
LineTo(x2, y1);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
CGContextMoveToPoint(fl_gc, x, y); CGContextMoveToPoint(fl_gc, x, y);
@ -219,10 +211,7 @@ void fl_yxline(int x, int y, int y1, int x2) {
CGContextStrokePath(fl_gc); CGContextStrokePath(fl_gc);
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#else #else
XPoint p[3]; # error unsupported platform
p[0].x = p[1].x = x; p[0].y = y;
p[1].y = p[2].y = y1; p[2].x = x2;
XDrawLines(fl_display, fl_window, fl_gc, p, 3, 0);
#endif #endif
} }
@ -231,18 +220,19 @@ void fl_yxline(int x, int y, int y1, int x2) {
then another vertical from x2,y1 to x2,y3 then another vertical from x2,y1 to x2,y3
*/ */
void fl_yxline(int x, int y, int y1, int x2, int y3) { void fl_yxline(int x, int y, int y1, int x2, int y3) {
#ifdef WIN32 #if defined(USE_X11)
XPoint p[4];
p[0].x = p[1].x = x; p[0].y = y;
p[1].y = p[2].y = y1; p[2].x = p[3].x = x2;
p[3].y = y3;
XDrawLines(fl_display, fl_window, fl_gc, p, 4, 0);
#elif defined(WIN32)
if(y3<y1) y3--; if(y3<y1) y3--;
else y3++; else y3++;
MoveToEx(fl_gc, x, y, 0L); MoveToEx(fl_gc, x, y, 0L);
LineTo(fl_gc, x, y1); LineTo(fl_gc, x, y1);
LineTo(fl_gc, x2, y1); LineTo(fl_gc, x2, y1);
LineTo(fl_gc, x2, y3); LineTo(fl_gc, x2, y3);
#elif defined(__APPLE_QD__)
MoveTo(x, y);
LineTo(x, y1);
LineTo(x2, y1);
LineTo(x2, y3);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
CGContextMoveToPoint(fl_gc, x, y); CGContextMoveToPoint(fl_gc, x, y);
@ -252,11 +242,7 @@ void fl_yxline(int x, int y, int y1, int x2, int y3) {
CGContextStrokePath(fl_gc); CGContextStrokePath(fl_gc);
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#else #else
XPoint p[4]; # error unsupported platform
p[0].x = p[1].x = x; p[0].y = y;
p[1].y = p[2].y = y1; p[2].x = p[3].x = x2;
p[3].y = y3;
XDrawLines(fl_display, fl_window, fl_gc, p, 4, 0);
#endif #endif
} }
@ -264,15 +250,14 @@ void fl_yxline(int x, int y, int y1, int x2, int y3) {
Draw a line from x,y to x1,y1 Draw a line from x,y to x1,y1
*/ */
void fl_line(int x, int y, int x1, int y1) { void fl_line(int x, int y, int x1, int y1) {
#ifdef WIN32 #if defined(USE_X11)
XDrawLine(fl_display, fl_window, fl_gc, x, y, x1, y1);
#elif defined(WIN32)
MoveToEx(fl_gc, x, y, 0L); MoveToEx(fl_gc, x, y, 0L);
LineTo(fl_gc, x1, y1); LineTo(fl_gc, x1, y1);
// Draw the last point *again* because the GDI line drawing // Draw the last point *again* because the GDI line drawing
// 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_QD__)
MoveTo(x, y);
LineTo(x1, y1);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
if (fl_quartz_line_width_==1.0f ) CGContextSetShouldAntialias(fl_gc, false); if (fl_quartz_line_width_==1.0f ) CGContextSetShouldAntialias(fl_gc, false);
CGContextMoveToPoint(fl_gc, x, y); CGContextMoveToPoint(fl_gc, x, y);
@ -280,7 +265,7 @@ void fl_line(int x, int y, int x1, int y1) {
CGContextStrokePath(fl_gc); CGContextStrokePath(fl_gc);
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#else #else
XDrawLine(fl_display, fl_window, fl_gc, x, y, x1, y1); # error unsupported platform
#endif #endif
} }
@ -288,17 +273,19 @@ void fl_line(int x, int y, int x1, int y1) {
Draw a line from x,y to x1,y1 and another from x1,y1 to x2,y2 Draw a line from x,y to x1,y1 and another from x1,y1 to x2,y2
*/ */
void fl_line(int x, int y, int x1, int y1, int x2, int y2) { void fl_line(int x, int y, int x1, int y1, int x2, int y2) {
#ifdef WIN32 #if defined(USE_X11)
XPoint p[3];
p[0].x = x; p[0].y = y;
p[1].x = x1; p[1].y = y1;
p[2].x = x2; p[2].y = y2;
XDrawLines(fl_display, fl_window, fl_gc, p, 3, 0);
#elif defined(WIN32)
MoveToEx(fl_gc, x, y, 0L); MoveToEx(fl_gc, x, y, 0L);
LineTo(fl_gc, x1, y1); LineTo(fl_gc, x1, y1);
LineTo(fl_gc, x2, y2); LineTo(fl_gc, x2, y2);
// Draw the last point *again* because the GDI line drawing // Draw the last point *again* because the GDI line drawing
// 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_QD__)
MoveTo(x, y);
LineTo(x1, y1);
LineTo(x2, y2);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
if (fl_quartz_line_width_==1.0f ) CGContextSetShouldAntialias(fl_gc, false); if (fl_quartz_line_width_==1.0f ) CGContextSetShouldAntialias(fl_gc, false);
CGContextMoveToPoint(fl_gc, x, y); CGContextMoveToPoint(fl_gc, x, y);
@ -307,11 +294,7 @@ void fl_line(int x, int y, int x1, int y1, int x2, int y2) {
CGContextStrokePath(fl_gc); CGContextStrokePath(fl_gc);
if (fl_quartz_line_width_==1.0f ) CGContextSetShouldAntialias(fl_gc, true); if (fl_quartz_line_width_==1.0f ) CGContextSetShouldAntialias(fl_gc, true);
#else #else
XPoint p[3]; # error unsupported platform
p[0].x = x; p[0].y = y;
p[1].x = x1; p[1].y = y1;
p[2].x = x2; p[2].y = y2;
XDrawLines(fl_display, fl_window, fl_gc, p, 3, 0);
#endif #endif
} }
@ -319,16 +302,18 @@ void fl_line(int x, int y, int x1, int y1, int x2, int y2) {
Outline a 3-sided polygon with lines Outline a 3-sided polygon with lines
*/ */
void fl_loop(int x, int y, int x1, int y1, int x2, int y2) { void fl_loop(int x, int y, int x1, int y1, int x2, int y2) {
#ifdef WIN32 #if defined(USE_X11)
XPoint p[4];
p[0].x = x; p[0].y = y;
p[1].x = x1; p[1].y = y1;
p[2].x = x2; p[2].y = y2;
p[3].x = x; p[3].y = y;
XDrawLines(fl_display, fl_window, fl_gc, p, 4, 0);
#elif defined(WIN32)
MoveToEx(fl_gc, x, y, 0L); MoveToEx(fl_gc, x, y, 0L);
LineTo(fl_gc, x1, y1); LineTo(fl_gc, x1, y1);
LineTo(fl_gc, x2, y2); LineTo(fl_gc, x2, y2);
LineTo(fl_gc, x, y); LineTo(fl_gc, x, y);
#elif defined(__APPLE_QD__)
MoveTo(x, y);
LineTo(x1, y1);
LineTo(x2, y2);
LineTo(x, y);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
CGContextMoveToPoint(fl_gc, x, y); CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x1, y1); CGContextAddLineToPoint(fl_gc, x1, y1);
@ -336,12 +321,7 @@ void fl_loop(int x, int y, int x1, int y1, int x2, int y2) {
CGContextClosePath(fl_gc); CGContextClosePath(fl_gc);
CGContextStrokePath(fl_gc); CGContextStrokePath(fl_gc);
#else #else
XPoint p[4]; # error unsupported platform
p[0].x = x; p[0].y = y;
p[1].x = x1; p[1].y = y1;
p[2].x = x2; p[2].y = y2;
p[3].x = x; p[3].y = y;
XDrawLines(fl_display, fl_window, fl_gc, p, 4, 0);
#endif #endif
} }
@ -349,18 +329,20 @@ void fl_loop(int x, int y, int x1, int y1, int x2, int y2) {
Outline a 4-sided polygon with lines Outline a 4-sided polygon with lines
*/ */
void fl_loop(int x, int y, int x1, int y1, int x2, int y2, int x3, int y3) { void fl_loop(int x, int y, int x1, int y1, int x2, int y2, int x3, int y3) {
#ifdef WIN32 #if defined(USE_X11)
XPoint p[5];
p[0].x = x; p[0].y = y;
p[1].x = x1; p[1].y = y1;
p[2].x = x2; p[2].y = y2;
p[3].x = x3; p[3].y = y3;
p[4].x = x; p[4].y = y;
XDrawLines(fl_display, fl_window, fl_gc, p, 5, 0);
#elif defined(WIN32)
MoveToEx(fl_gc, x, y, 0L); MoveToEx(fl_gc, x, y, 0L);
LineTo(fl_gc, x1, y1); LineTo(fl_gc, x1, y1);
LineTo(fl_gc, x2, y2); LineTo(fl_gc, x2, y2);
LineTo(fl_gc, x3, y3); LineTo(fl_gc, x3, y3);
LineTo(fl_gc, x, y); LineTo(fl_gc, x, y);
#elif defined(__APPLE_QD__)
MoveTo(x, y);
LineTo(x1, y1);
LineTo(x2, y2);
LineTo(x3, y3);
LineTo(x, y);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
CGContextMoveToPoint(fl_gc, x, y); CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x1, y1); CGContextAddLineToPoint(fl_gc, x1, y1);
@ -369,13 +351,7 @@ void fl_loop(int x, int y, int x1, int y1, int x2, int y2, int x3, int y3) {
CGContextClosePath(fl_gc); CGContextClosePath(fl_gc);
CGContextStrokePath(fl_gc); CGContextStrokePath(fl_gc);
#else #else
XPoint p[5]; # error unsupported platform
p[0].x = x; p[0].y = y;
p[1].x = x1; p[1].y = y1;
p[2].x = x2; p[2].y = y2;
p[3].x = x3; p[3].y = y3;
p[4].x = x; p[4].y = y;
XDrawLines(fl_display, fl_window, fl_gc, p, 5, 0);
#endif #endif
} }
@ -387,19 +363,13 @@ void fl_polygon(int x, int y, int x1, int y1, int x2, int y2) {
p[0].x = x; p[0].y = y; p[0].x = x; p[0].y = y;
p[1].x = x1; p[1].y = y1; p[1].x = x1; p[1].y = y1;
p[2].x = x2; p[2].y = y2; p[2].x = x2; p[2].y = y2;
#ifdef WIN32 #if defined (USE_X11)
p[3].x = x; p[3].y = y;
XFillPolygon(fl_display, fl_window, fl_gc, p, 3, Convex, 0);
XDrawLines(fl_display, fl_window, fl_gc, p, 4, 0);
#elif defined(WIN32)
SelectObject(fl_gc, fl_brush()); SelectObject(fl_gc, fl_brush());
Polygon(fl_gc, p, 3); Polygon(fl_gc, p, 3);
#elif defined(__APPLE_QD__)
PolyHandle poly = OpenPoly();
MoveTo(x, y);
LineTo(x1, y1);
LineTo(x2, y2);
LineTo(x, y);
ClosePoly();
PaintPoly(poly);
FramePoly(poly);
KillPoly(poly);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
CGContextMoveToPoint(fl_gc, x, y); CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x1, y1); CGContextAddLineToPoint(fl_gc, x1, y1);
@ -407,9 +377,7 @@ void fl_polygon(int x, int y, int x1, int y1, int x2, int y2) {
CGContextClosePath(fl_gc); CGContextClosePath(fl_gc);
CGContextFillPath(fl_gc); CGContextFillPath(fl_gc);
#else #else
p[3].x = x; p[3].y = y; # error unsupported platform
XFillPolygon(fl_display, fl_window, fl_gc, p, 3, Convex, 0);
XDrawLines(fl_display, fl_window, fl_gc, p, 4, 0);
#endif #endif
} }
@ -422,20 +390,13 @@ void fl_polygon(int x, int y, int x1, int y1, int x2, int y2, int x3, int y3) {
p[1].x = x1; p[1].y = y1; p[1].x = x1; p[1].y = y1;
p[2].x = x2; p[2].y = y2; p[2].x = x2; p[2].y = y2;
p[3].x = x3; p[3].y = y3; p[3].x = x3; p[3].y = y3;
#ifdef WIN32 #if defined(USE_X11)
p[4].x = x; p[4].y = y;
XFillPolygon(fl_display, fl_window, fl_gc, p, 4, Convex, 0);
XDrawLines(fl_display, fl_window, fl_gc, p, 5, 0);
#elif defined(WIN32)
SelectObject(fl_gc, fl_brush()); SelectObject(fl_gc, fl_brush());
Polygon(fl_gc, p, 4); Polygon(fl_gc, p, 4);
#elif defined(__APPLE_QD__)
PolyHandle poly = OpenPoly();
MoveTo(x, y);
LineTo(x1, y1);
LineTo(x2, y2);
LineTo(x3, y3);
LineTo(x, y);
ClosePoly();
PaintPoly(poly);
FramePoly(poly);
KillPoly(poly);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
CGContextMoveToPoint(fl_gc, x, y); CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x1, y1); CGContextAddLineToPoint(fl_gc, x1, y1);
@ -444,9 +405,7 @@ void fl_polygon(int x, int y, int x1, int y1, int x2, int y2, int x3, int y3) {
CGContextClosePath(fl_gc); CGContextClosePath(fl_gc);
CGContextFillPath(fl_gc); CGContextFillPath(fl_gc);
#else #else
p[4].x = x; p[4].y = y; # error unsupported platform
XFillPolygon(fl_display, fl_window, fl_gc, p, 4, Convex, 0);
XDrawLines(fl_display, fl_window, fl_gc, p, 5, 0);
#endif #endif
} }
@ -454,10 +413,10 @@ void fl_polygon(int x, int y, int x1, int y1, int x2, int y2, int x3, int y3) {
Draw a single pixel at the given coordinates Draw a single pixel at the given coordinates
*/ */
void fl_point(int x, int y) { void fl_point(int x, int y) {
#ifdef WIN32 #if defined(USE_X11)
XDrawPoint(fl_display, fl_window, fl_gc, x, y);
#elif defined(WIN32)
SetPixel(fl_gc, x, y, fl_RGB()); SetPixel(fl_gc, x, y, fl_RGB());
#elif defined(__APPLE_QD__)
MoveTo(x, y); Line(0, 0);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
CGContextMoveToPoint(fl_gc, x, y); CGContextMoveToPoint(fl_gc, x, y);
@ -465,7 +424,7 @@ void fl_point(int x, int y) {
CGContextStrokePath(fl_gc); CGContextStrokePath(fl_gc);
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#else #else
XDrawPoint(fl_display, fl_window, fl_gc, x, y); # error unsupported platform
#endif #endif
} }
@ -489,51 +448,22 @@ Fl_Region XRectangleRegion(int x, int y, int w, int h) {
} }
#endif #endif
#ifdef __APPLE_QD__ #if defined(__APPLE_QUARTZ__)
extern Fl_Region fl_window_region;
#elif defined(__APPLE_QUARTZ__)
// warning: the Quartz implementation currently uses Quickdraw calls to achieve // warning: the Quartz implementation currently uses Quickdraw calls to achieve
// clipping. A future version should instead use 'CGContectClipToRect' // clipping. A future version should instead use 'CGContectClipToRect'
// and friends. // and friends.
extern Fl_Region fl_window_region; extern Fl_Region fl_window_region;
#endif #endif
// undo any clobbering of clip done by your program: /** Undoes any clobbering of clip done by your program */
void fl_restore_clip() { void fl_restore_clip() {
fl_clip_state_number++; fl_clip_state_number++;
Fl_Region r = rstack[rstackptr]; Fl_Region r = rstack[rstackptr];
#ifdef WIN32 #if defined(USE_X11)
if (r) XSetRegion(fl_display, fl_gc, r);
else XSetClipMask(fl_display, fl_gc, 0);
#elif defined(WIN32)
SelectClipRgn(fl_gc, r); //if r is NULL, clip is automatically cleared SelectClipRgn(fl_gc, r); //if r is NULL, clip is automatically cleared
#elif defined(__APPLE_QD__)
# if 1
// This code is required to allow true subwindows to work on Mac.
// During regular operation however, this seems overkill.
// See also: Fl_Window::make_current()
if ( fl_window ) {
GrafPtr port = GetWindowPort( fl_window );
if ( port ) { // port will be NULL if we are using a GWorld (and fl_window_region is invalid)
RgnHandle portClip = NewRgn();
CopyRgn( fl_window_region, portClip ); // changed
if ( r )
SectRgn( portClip, r, portClip );
SetPortClipRegion( port, portClip );
DisposeRgn( portClip );
}
} else {
if (r)
SetClip(r);
else {
Rect rect; rect.left=0; rect.top=0; rect.right=0x7fff; rect.bottom=0x7fff;
ClipRect(&rect);
}
}
# else
if (r) SetClip(r);
else {
Rect rect; rect.left=0; rect.top=0; rect.right=0x7fff; rect.bottom=0x7fff;
ClipRect(&rect);
}
# endif
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
if ( fl_window ) // clipping for a true window if ( fl_window ) // clipping for a true window
{ {
@ -561,8 +491,7 @@ void fl_restore_clip() {
Fl_X::q_fill_context(); Fl_X::q_fill_context();
} }
#else #else
if (r) XSetRegion(fl_display, fl_gc, r); # error unsupported platform
else XSetClipMask(fl_display, fl_gc, 0);
#endif #endif
} }
@ -596,30 +525,29 @@ void fl_push_clip(int x, int y, int w, int h) {
r = XRectangleRegion(x,y,w,h); r = XRectangleRegion(x,y,w,h);
Fl_Region current = rstack[rstackptr]; Fl_Region current = rstack[rstackptr];
if (current) { if (current) {
#ifdef WIN32 #if defined(USE_X11)
CombineRgn(r,r,current,RGN_AND);
#elif defined(__APPLE_QD__)
SectRgn(r, current, r);
#elif defined(__APPLE_QUARTZ__)
SectRgn(r, current, r);
#else
Fl_Region temp = XCreateRegion(); Fl_Region temp = XCreateRegion();
XIntersectRegion(current, r, temp); XIntersectRegion(current, r, temp);
XDestroyRegion(r); XDestroyRegion(r);
r = temp; r = temp;
#elif defined(WIN32)
CombineRgn(r,r,current,RGN_AND);
#elif defined(__APPLE_QUARTZ__)
SectRgn(r, current, r);
#else
# error unsupported platform
#endif #endif
} }
} else { // make empty clip region: } else { // make empty clip region:
#ifdef WIN32 #if defined(USE_X11)
r = XCreateRegion();
#elif defined(WIN32)
r = CreateRectRgn(0,0,0,0); r = CreateRectRgn(0,0,0,0);
#elif defined(__APPLE_QD__)
r = NewRgn();
SetEmptyRgn(r);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
r = NewRgn(); r = NewRgn();
SetEmptyRgn(r); SetEmptyRgn(r);
#else #else
r = XCreateRegion(); # error unsupported platform
#endif #endif
} }
if (rstackptr < STACK_MAX) rstack[++rstackptr] = r; if (rstackptr < STACK_MAX) rstack[++rstackptr] = r;
@ -665,23 +593,20 @@ void fl_pop_clip() {
int fl_not_clipped(int x, int y, int w, int h) { int fl_not_clipped(int x, int y, int w, int h) {
if (x+w <= 0 || y+h <= 0) return 0; if (x+w <= 0 || y+h <= 0) return 0;
Fl_Region r = rstack[rstackptr]; Fl_Region r = rstack[rstackptr];
#ifdef WIN32 #if defined (USE_X11)
return r ? XRectInRegion(r, x, y, w, h) : 1;
#elif defined(WIN32)
if (!r) return 1; if (!r) return 1;
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 RectInRegion(r,&rect); return RectInRegion(r,&rect);
#elif defined(__APPLE_QD__)
if (!r) return 1;
Rect rect;
rect.left = x; rect.top = y; rect.right = x+w; rect.bottom = y+h;
return RectInRgn(&rect, r);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
if (!r) return 1; if (!r) return 1;
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);
#else #else
return r ? XRectInRegion(r, x, y, w, h) : 1; # error unsupported platform
#endif #endif
} }
@ -703,7 +628,26 @@ int fl_clip_box(int x, int y, int w, int h, int& X, int& Y, int& W, int& H){
X = x; Y = y; W = w; H = h; X = x; Y = y; W = w; H = h;
Fl_Region r = rstack[rstackptr]; Fl_Region r = rstack[rstackptr];
if (!r) return 0; if (!r) return 0;
#ifdef WIN32 #if defined(USE_X11)
switch (XRectInRegion(r, x, y, w, h)) {
case 0: // completely outside
W = H = 0;
return 2;
case 1: // completely inside:
return 0;
default: // partial:
break;
}
Fl_Region rr = XRectangleRegion(x,y,w,h);
Fl_Region temp = XCreateRegion();
XIntersectRegion(r, rr, temp);
XRectangle rect;
XClipBox(temp, &rect);
X = rect.x; Y = rect.y; W = rect.width; H = rect.height;
XDestroyRegion(temp);
XDestroyRegion(rr);
return 1;
#elif defined(WIN32)
// The win32 API makes no distinction between partial and complete // The win32 API makes no distinction between partial and complete
// intersection, so we have to check for partial intersection ourselves. // intersection, so we have to check for partial intersection ourselves.
// However, given that the regions may be composite, we have to do // However, given that the regions may be composite, we have to do
@ -725,19 +669,6 @@ int fl_clip_box(int x, int y, int w, int h, int& X, int& Y, int& W, int& H){
DeleteObject(temp); DeleteObject(temp);
DeleteObject(rr); DeleteObject(rr);
return ret; return ret;
#elif defined(__APPLE_QD__)
RgnHandle rr = NewRgn();
SetRectRgn( rr, x, y, x+w, y+h );
SectRgn( r, rr, rr );
Rect rp; GetRegionBounds(rr, &rp);
X = rp.left;
Y = rp.top;
W = rp.right - X;
H = rp.bottom - Y;
DisposeRgn( rr );
if ( H==0 ) return 2;
if ( h==H && w==W ) return 0;
return 0;
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
RgnHandle rr = NewRgn(); RgnHandle rr = NewRgn();
SetRectRgn( rr, x, y, x+w, y+h ); SetRectRgn( rr, x, y, x+w, y+h );
@ -752,24 +683,7 @@ int fl_clip_box(int x, int y, int w, int h, int& X, int& Y, int& W, int& H){
if ( h==H && w==W ) return 0; if ( h==H && w==W ) return 0;
return 0; return 0;
#else #else
switch (XRectInRegion(r, x, y, w, h)) { # error unsupported platform
case 0: // completely outside
W = H = 0;
return 2;
case 1: // completely inside:
return 0;
default: // partial:
break;
}
Fl_Region rr = XRectangleRegion(x,y,w,h);
Fl_Region temp = XCreateRegion();
XIntersectRegion(r, rr, temp);
XRectangle rect;
XClipBox(temp, &rect);
X = rect.x; Y = rect.y; W = rect.width; H = rect.height;
XDestroyRegion(temp);
XDestroyRegion(rr);
return 1;
#endif #endif
} }

34
src/fl_scroll_area.cxx

@ -72,7 +72,20 @@ void fl_scroll(int X, int Y, int W, int H, int dx, int dy,
clip_y = Y+src_h; clip_y = Y+src_h;
clip_h = H-src_h; clip_h = H-src_h;
} }
#ifdef WIN32
#if defined(USE_X11)
XCopyArea(fl_display, fl_window, fl_window, fl_gc,
src_x, src_y, src_w, src_h, dest_x, dest_y);
// we have to sync the display and get the GraphicsExpose events! (sigh)
for (;;) {
XEvent e; XWindowEvent(fl_display, fl_window, ExposureMask, &e);
if (e.type == NoExpose) break;
// otherwise assumme it is a GraphicsExpose event:
draw_area(data, e.xexpose.x, e.xexpose.y,
e.xexpose.width, e.xexpose.height);
if (!e.xgraphicsexpose.count) break;
}
#elif defined(WIN32)
typedef int (WINAPI* fl_GetRandomRgn_func)(HDC, HRGN, INT); typedef int (WINAPI* fl_GetRandomRgn_func)(HDC, HRGN, INT);
static fl_GetRandomRgn_func fl_GetRandomRgn = 0L; static fl_GetRandomRgn_func fl_GetRandomRgn = 0L;
static char first_time = 1; static char first_time = 1;
@ -126,13 +139,6 @@ void fl_scroll(int X, int Y, int W, int H, int dx, int dy,
// Great, we can do an accelerated scroll insteasd of re-rendering // Great, we can do an accelerated scroll insteasd of re-rendering
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_QD__)
Rect src = { src_y, src_x, src_y+src_h, src_x+src_w };
Rect dst = { dest_y, dest_x, dest_y+src_h, dest_x+src_w };
static RGBColor bg = { 0xffff, 0xffff, 0xffff }; RGBBackColor( &bg );
static RGBColor fg = { 0x0000, 0x0000, 0x0000 }; RGBForeColor( &fg );
CopyBits( GetPortBitMapForCopyBits( GetWindowPort(fl_window) ),
GetPortBitMapForCopyBits( GetWindowPort(fl_window) ), &src, &dst, srcCopy, 0L);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
// 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.
@ -145,17 +151,7 @@ void fl_scroll(int X, int Y, int W, int H, int dx, int dy,
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);
#else #else
XCopyArea(fl_display, fl_window, fl_window, fl_gc, # error unsupported platform
src_x, src_y, src_w, src_h, dest_x, dest_y);
// we have to sync the display and get the GraphicsExpose events! (sigh)
for (;;) {
XEvent e; XWindowEvent(fl_display, fl_window, ExposureMask, &e);
if (e.type == NoExpose) break;
// otherwise assumme it is a GraphicsExpose event:
draw_area(data, e.xexpose.x, e.xexpose.y,
e.xexpose.width, e.xexpose.height);
if (!e.xgraphicsexpose.count) break;
}
#endif #endif
if (dx) draw_area(data, clip_x, dest_y, clip_w, src_h); if (dx) draw_area(data, clip_x, dest_y, clip_w, src_h);
if (dy) draw_area(data, X, clip_y, W, clip_h); if (dy) draw_area(data, X, clip_y, W, clip_h);

64
src/fl_vertex.cxx

@ -150,10 +150,10 @@ void fl_vertex(double x,double y) {
} }
void fl_end_points() { void fl_end_points() {
#ifdef WIN32 #if defined(USE_X11)
if (n>1) XDrawPoints(fl_display, fl_window, fl_gc, p, n, 0);
#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_QD__)
for (int i=0; i<n; i++) { MoveTo(p[i].x, p[i].y); Line(0, 0); }
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
for (int i=0; i<n; i++) { for (int i=0; i<n; i++) {
@ -163,7 +163,7 @@ void fl_end_points() {
} }
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false); if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
#else #else
if (n>1) XDrawPoints(fl_display, fl_window, fl_gc, p, n, 0); # error unsupported platform
#endif #endif
} }
@ -172,12 +172,10 @@ void fl_end_line() {
fl_end_points(); fl_end_points();
return; return;
} }
#ifdef WIN32 #if defined(USE_X11)
if (n>1) XDrawLines(fl_display, fl_window, fl_gc, p, n, 0);
#elif defined(WIN32)
if (n>1) Polyline(fl_gc, p, n); if (n>1) Polyline(fl_gc, p, n);
#elif defined(__APPLE_QD__)
if (n<=1) return;
MoveTo(p[0].x, p[0].y);
for (int i=1; i<n; i++) LineTo(p[i].x, p[i].y);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
if (n<=1) return; if (n<=1) return;
CGContextMoveToPoint(fl_gc, p[0].x, p[0].y); CGContextMoveToPoint(fl_gc, p[0].x, p[0].y);
@ -185,7 +183,7 @@ void fl_end_line() {
CGContextAddLineToPoint(fl_gc, p[i].x, p[i].y); CGContextAddLineToPoint(fl_gc, p[i].x, p[i].y);
CGContextStrokePath(fl_gc); CGContextStrokePath(fl_gc);
#else #else
if (n>1) XDrawLines(fl_display, fl_window, fl_gc, p, n, 0); # error unsupported platform
#endif #endif
} }
@ -205,19 +203,13 @@ void fl_end_polygon() {
fl_end_line(); fl_end_line();
return; return;
} }
#ifdef WIN32 #if defined(USE_X11)
if (n>2) XFillPolygon(fl_display, fl_window, fl_gc, p, n, Convex, 0);
#elif defined(WIN32)
if (n>2) { if (n>2) {
SelectObject(fl_gc, fl_brush()); SelectObject(fl_gc, fl_brush());
Polygon(fl_gc, p, n); Polygon(fl_gc, p, n);
} }
#elif defined(__APPLE_QD__)
if (n<=1) return;
PolyHandle ph = OpenPoly();
MoveTo(p[0].x, p[0].y);
for (int i=1; i<n; i++) LineTo(p[i].x, p[i].y);
ClosePoly();
PaintPoly(ph);
KillPoly(ph);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
if (n<=1) return; if (n<=1) return;
CGContextMoveToPoint(fl_gc, p[0].x, p[0].y); CGContextMoveToPoint(fl_gc, p[0].x, p[0].y);
@ -226,12 +218,12 @@ void fl_end_polygon() {
CGContextClosePath(fl_gc); CGContextClosePath(fl_gc);
CGContextFillPath(fl_gc); CGContextFillPath(fl_gc);
#else #else
if (n>2) XFillPolygon(fl_display, fl_window, fl_gc, p, n, Convex, 0); # error unsupported platform
#endif #endif
} }
static int gap; static int gap;
#ifdef WIN32 #if defined(WIN32)
static int counts[20]; static int counts[20];
static int numcount; static int numcount;
#endif #endif
@ -239,7 +231,7 @@ static int numcount;
void fl_begin_complex_polygon() { void fl_begin_complex_polygon() {
fl_begin_polygon(); fl_begin_polygon();
gap = 0; gap = 0;
#ifdef WIN32 #if defined(WIN32)
numcount = 0; numcount = 0;
#endif #endif
} }
@ -248,7 +240,7 @@ void fl_gap() {
while (n>gap+2 && p[n-1].x == p[gap].x && p[n-1].y == p[gap].y) n--; while (n>gap+2 && p[n-1].x == p[gap].x && p[n-1].y == p[gap].y) n--;
if (n > gap+2) { if (n > gap+2) {
fl_transformed_vertex((COORD_T)p[gap].x, (COORD_T)p[gap].y); fl_transformed_vertex((COORD_T)p[gap].x, (COORD_T)p[gap].y);
#ifdef WIN32 #if defined(WIN32)
counts[numcount++] = n-gap; counts[numcount++] = n-gap;
#endif #endif
gap = n; gap = n;
@ -263,19 +255,13 @@ void fl_end_complex_polygon() {
fl_end_line(); fl_end_line();
return; return;
} }
#ifdef WIN32 #if defined(USE_X11)
if (n>2) XFillPolygon(fl_display, fl_window, fl_gc, p, n, 0, 0);
#elif defined(WIN32)
if (n>2) { if (n>2) {
SelectObject(fl_gc, fl_brush()); SelectObject(fl_gc, fl_brush());
PolyPolygon(fl_gc, p, counts, numcount); PolyPolygon(fl_gc, p, counts, numcount);
} }
#elif defined(__APPLE_QD__)
if (n<=1) return;
PolyHandle ph = OpenPoly();
MoveTo(p[0].x, p[0].y);
for (int i=1; i<n; i++) LineTo(p[i].x, p[i].y);
ClosePoly();
PaintPoly(ph);
KillPoly(ph);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
if (n<=1) return; if (n<=1) return;
CGContextMoveToPoint(fl_gc, p[0].x, p[0].y); CGContextMoveToPoint(fl_gc, p[0].x, p[0].y);
@ -284,7 +270,7 @@ void fl_end_complex_polygon() {
CGContextClosePath(fl_gc); CGContextClosePath(fl_gc);
CGContextFillPath(fl_gc); CGContextFillPath(fl_gc);
#else #else
if (n>2) XFillPolygon(fl_display, fl_window, fl_gc, p, n, 0, 0); # error unsupported platform
#endif #endif
} }
@ -301,22 +287,22 @@ void fl_circle(double x, double y,double r) {
int w = (int)rint(xt+rx)-llx; int w = (int)rint(xt+rx)-llx;
int lly = (int)rint(yt-ry); int lly = (int)rint(yt-ry);
int h = (int)rint(yt+ry)-lly; int h = (int)rint(yt+ry)-lly;
#ifdef WIN32
#if defined(USE_X11)
(what == POLYGON ? XFillArc : XDrawArc)
(fl_display, fl_window, fl_gc, llx, lly, w, h, 0, 360*64);
#elif defined(WIN32)
if (what==POLYGON) { if (what==POLYGON) {
SelectObject(fl_gc, fl_brush()); SelectObject(fl_gc, fl_brush());
Pie(fl_gc, llx, lly, llx+w, lly+h, 0,0, 0,0); Pie(fl_gc, llx, lly, llx+w, lly+h, 0,0, 0,0);
} else } else
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_QD__)
Rect rt; rt.left=llx; rt.right=llx+w; rt.top=lly; rt.bottom=lly+h;
(what == POLYGON ? PaintOval : FrameOval)(&rt);
#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); CGContextAddArc(fl_gc, xt, yt, (w+h)*0.25f, 0, 2.0f*M_PI, 1);
(what == POLYGON ? CGContextFillPath : CGContextStrokePath)(fl_gc); (what == POLYGON ? CGContextFillPath : CGContextStrokePath)(fl_gc);
#else #else
(what == POLYGON ? XFillArc : XDrawArc) # error unsupported platform
(fl_display, fl_window, fl_gc, llx, lly, w, h, 0, 360*64);
#endif #endif
} }

75
src/gl_draw.cxx

@ -73,32 +73,9 @@ void gl_font(int fontid, int size) {
fl_fontsize->listbase = glGenLists(0x10000); fl_fontsize->listbase = glGenLists(0x10000);
#else // Fltk-1.1.8 style GL font selection #else // Fltk-1.1.8 style GL font selection
# ifdef WIN32 #if defined (USE_X11) // X-windows options follow, either XFT or "plain" X
int base = fl_fontsize->metr.tmFirstChar;
int count = fl_fontsize->metr.tmLastChar-base+1;
HFONT oldFid = (HFONT)SelectObject(fl_gc, fl_fontsize->fid);
fl_fontsize->listbase = glGenLists(256);
wglUseFontBitmaps(fl_gc, base, count, fl_fontsize->listbase+base);
SelectObject(fl_gc, oldFid);
# elif defined(__APPLE_QD__)
// undefined characters automatically receive an empty GL list in aglUseFont
fl_fontsize->listbase = glGenLists(256);
aglUseFont(aglGetCurrentContext(), fl_fontsize->font, fl_fontsize->face,
fl_fontsize->size, 0, 256, fl_fontsize->listbase);
# elif defined(__APPLE_QUARTZ__)
short font, face, size;
uchar fn[256];
fn[0]=strlen(fl_fontsize->q_name);
strcpy((char*)(fn+1), fl_fontsize->q_name);
GetFNum(fn, &font);
face = 0;
size = fl_fontsize->size;
fl_fontsize->listbase = glGenLists(256);
aglUseFont(aglGetCurrentContext(), font, face,
size, 0, 256, fl_fontsize->listbase);
# else // X-windows options follow, either XFT or "plain" X
# if USE_XFT // XFT case # if USE_XFT // XFT case
#warning We really need a glXUseXftFont implementation here... # warning We really need a glXUseXftFont implementation here...
// fl_xfont = fl_xxfont(); // fl_xfont = fl_xxfont();
XFontStruct *font = fl_xxfont(); XFontStruct *font = fl_xxfont();
int base = font->min_char_or_byte2; int base = font->min_char_or_byte2;
@ -106,7 +83,7 @@ void gl_font(int fontid, int size) {
fl_fontsize->listbase = glGenLists(256); fl_fontsize->listbase = glGenLists(256);
glXUseXFont(font->fid, base, count, fl_fontsize->listbase+base); glXUseXFont(font->fid, base, count, fl_fontsize->listbase+base);
# else // plain X # else // plain X
#warning GL font selection is basically wrong here # warning GL font selection is basically wrong here
/* OksiD has a fairly sophisticated scheme for storing multiple X fonts in a XUtf8FontStruct, /* OksiD has a fairly sophisticated scheme for storing multiple X fonts in a XUtf8FontStruct,
* then sorting through them at draw time (for normal X rendering) to find which one can * then sorting through them at draw time (for normal X rendering) to find which one can
* render the current glyph... But for now, just use the first font in the list for GL... * render the current glyph... But for now, just use the first font in the list for GL...
@ -117,6 +94,26 @@ void gl_font(int fontid, int size) {
fl_fontsize->listbase = glGenLists(256); fl_fontsize->listbase = glGenLists(256);
glXUseXFont(tmp_font->fid, base, count, fl_fontsize->listbase+base); glXUseXFont(tmp_font->fid, base, count, fl_fontsize->listbase+base);
# endif // USE_XFT # endif // USE_XFT
# elif defined(WIN32)
int base = fl_fontsize->metr.tmFirstChar;
int count = fl_fontsize->metr.tmLastChar-base+1;
HFONT oldFid = (HFONT)SelectObject(fl_gc, fl_fontsize->fid);
fl_fontsize->listbase = glGenLists(256);
wglUseFontBitmaps(fl_gc, base, count, fl_fontsize->listbase+base);
SelectObject(fl_gc, oldFid);
# elif defined(__APPLE_QUARTZ__)
short font, face, size;
uchar fn[256];
fn[0]=strlen(fl_fontsize->q_name);
strcpy((char*)(fn+1), fl_fontsize->q_name);
GetFNum(fn, &font);
face = 0;
size = fl_fontsize->size;
fl_fontsize->listbase = glGenLists(256);
aglUseFont(aglGetCurrentContext(), font, face,
size, 0, 256, fl_fontsize->listbase);
# else
# error unsupported platform
# endif # endif
#endif // USE_OksiD_style_GL_font_selection #endif // USE_OksiD_style_GL_font_selection
@ -130,18 +127,10 @@ void gl_font(int fontid, int size) {
// The OSX build does not use this at present... It probbaly should, though... // The OSX build does not use this at present... It probbaly should, though...
static void get_list(int r) { static void get_list(int r) {
gl_fontsize->glok[r] = 1; gl_fontsize->glok[r] = 1;
#ifdef WIN32 #if defined(USE_X11)
unsigned int ii = r * 0x400; # if USE_XFT
HFONT oldFid = (HFONT)SelectObject(fl_gc, gl_fontsize->fid);
wglUseFontBitmapsW(fl_gc, ii, ii + 0x03ff, gl_fontsize->listbase+ii);
SelectObject(fl_gc, oldFid);
#elif defined(__APPLE_QD__)
// FIXME // FIXME
#elif defined(__APPLE_QUARTZ__) # else
// FIXME
#elif USE_XFT
// FIXME
#else
unsigned int ii = r * 0x400; unsigned int ii = r * 0x400;
for (int i = 0; i < 0x400; i++) { for (int i = 0; i < 0x400; i++) {
XFontStruct *font = NULL; XFontStruct *font = NULL;
@ -150,6 +139,16 @@ static void get_list(int r) {
if (font) glXUseXFont(font->fid, id, 1, gl_fontsize->listbase+ii); if (font) glXUseXFont(font->fid, id, 1, gl_fontsize->listbase+ii);
ii++; ii++;
} }
# endif
#elif defined(WIN32)
unsigned int ii = r * 0x400;
HFONT oldFid = (HFONT)SelectObject(fl_gc, gl_fontsize->fid);
wglUseFontBitmapsW(fl_gc, ii, ii + 0x03ff, gl_fontsize->listbase+ii);
SelectObject(fl_gc, oldFid);
#elif defined(__APPLE_QUARTZ__)
// FIXME
#else
# error unsupported platform
#endif #endif
} // get_list } // get_list
#endif #endif
@ -279,7 +278,7 @@ extern int fl_overlay_depth;
void gl_color(Fl_Color i) { void gl_color(Fl_Color i) {
#if HAVE_GL_OVERLAY #if HAVE_GL_OVERLAY
#ifdef WIN32 #if defined(WIN32)
if (fl_overlay && fl_overlay_depth) { if (fl_overlay && fl_overlay_depth) {
if (fl_overlay_depth < 8) { if (fl_overlay_depth < 8) {
// only black & white produce the expected colors. This could // only black & white produce the expected colors. This could

21
src/gl_start.cxx

@ -64,17 +64,16 @@ Fl_Region XRectangleRegion(int x, int y, int w, int h); // in fl_rect.cxx
void gl_start() { void gl_start() {
if (!context) { if (!context) {
#ifdef WIN32 #if defined(USE_X11)
context = fl_create_gl_context(fl_visual);
#elif defined(WIN32)
if (!gl_choice) Fl::gl_visual(0); if (!gl_choice) Fl::gl_visual(0);
context = fl_create_gl_context(Fl_Window::current(), gl_choice); context = fl_create_gl_context(Fl_Window::current(), gl_choice);
#elif defined(__APPLE_QD__)
// \todo Mac : We need to check the code and verify it with Apple Sample code. The 'shiny'-test should at least work with the software OpenGL emulator
context = fl_create_gl_context(Fl_Window::current(), gl_choice);
#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
context = fl_create_gl_context(Fl_Window::current(), gl_choice); context = fl_create_gl_context(Fl_Window::current(), gl_choice);
#else #else
context = fl_create_gl_context(fl_visual); # error Unsupported platform
#endif #endif
} }
fl_set_gl_context(Fl_Window::current(), context); fl_set_gl_context(Fl_Window::current(), context);
@ -109,23 +108,23 @@ void gl_finish() {
glXWaitGL(); glXWaitGL();
#endif #endif
} }
int Fl::gl_visual(int mode, int *alist) { int Fl::gl_visual(int mode, int *alist) {
Fl_Gl_Choice *c = Fl_Gl_Choice::find(mode,alist); Fl_Gl_Choice *c = Fl_Gl_Choice::find(mode,alist);
if (!c) return 0; if (!c) return 0;
#ifdef WIN32 #if defined(USE_X11)
gl_choice = c; fl_visual = c->vis;
#elif defined(__APPLE_QD__) fl_colormap = c->colormap;
#elif defined(WIN32)
gl_choice = c; gl_choice = c;
#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
gl_choice = c; gl_choice = c;
#else #else
fl_visual = c->vis; # error Unsupported platform
fl_colormap = c->colormap;
#endif #endif
return 1; return 1;
} }
#endif #endif
// //

Loading…
Cancel
Save