Skip to content

Commit

Permalink
Added AppKit framework for MACOSX
Browse files Browse the repository at this point in the history
Refactored to allow Cairo but no TK builds
  • Loading branch information
highperformancecoder committed Sep 10, 2024
1 parent 1ff0359 commit d98e897
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 32 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ endif
ifdef MAC_OSX_TK
CXXFLAGS+=-DMAC_OSX_TK
OBJS+=src/getContext.o
LIBS+=-framework AppKit
endif

CDHDRS=ref.cd random.cd random_basic.cd TCL_obj_base.cd RESTProcess_base.cd signature.cd netcomplexity.cd graph.cd cachedDBM.cd sparse_mat.cd analysis.cd analysisBLT.cd analysisCairo.cd plot.cd cairoSurfaceImage.cd polyRESTProcess.cd
Expand Down
2 changes: 1 addition & 1 deletion include/cairoSurfaceImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#ifndef CAIROSURFACEIMAGE_H
#define CAIROSURFACEIMAGE_H
#if defined(CAIRO) && defined(TK)
#if defined(CAIRO)
#include "cairo_base.h"

namespace ecolab
Expand Down
41 changes: 20 additions & 21 deletions include/cairo_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,26 @@ namespace ecolab
typedef std::tr1::shared_ptr<Surface> SurfacePtr;
#endif

/// RAII object wrapping a cairo_path_t, along with its transformation
class Path
{
cairo_path_t* m_path;
cairo_matrix_t m_transformation;
Path(const Path&);
void operator=(const Path&);
public:
Path(cairo_t* cairo): m_path(cairo_copy_path(cairo))
{cairo_get_matrix(cairo, &m_transformation);}
~Path() {cairo_path_destroy(m_path);}
void appendToCurrent(cairo_t* cairo) {
// apply saved transformation along with path
cairo_save(cairo);
cairo_set_matrix(cairo,&m_transformation);
cairo_append_path(cairo,m_path);
cairo_restore(cairo);
}
};

#ifdef TK
struct PhotoImageBlock: public Tk_PhotoImageBlock
{
Expand Down Expand Up @@ -319,27 +339,6 @@ namespace ecolab

};

/// RAII object wrapping a cairo_path_t, along with its transformation
class Path
{
cairo_path_t* m_path;
cairo_matrix_t m_transformation;
Path(const Path&);
void operator=(const Path&);
public:
Path(cairo_t* cairo): m_path(cairo_copy_path(cairo))
{cairo_get_matrix(cairo, &m_transformation);}
~Path() {cairo_path_destroy(m_path);}
void appendToCurrent(cairo_t* cairo) {
// apply saved transformation along with path
cairo_save(cairo);
cairo_set_matrix(cairo,&m_transformation);
cairo_append_path(cairo,m_path);
cairo_restore(cairo);
}
};


/// internal structure used for Tk Canvas cairo image items
struct ImageItem {
Tk_Item header; /* Generic stuff that's the same for all
Expand Down
18 changes: 12 additions & 6 deletions src/cairoSurfaceImage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
Open source licensed under the MIT license. See LICENSE for details.
*/

#if defined(CAIRO) && defined(TK)
#ifdef CAIRO
#include "cairoSurfaceImage.h"
#include "tcl++.h"
#include "pango.h"

#include "ecolab_epilogue.h"
Expand All @@ -20,12 +19,19 @@
#include <cairo/cairo-pdf.h>
#include <cairo/cairo-svg.h>

using namespace ecolab;
using namespace std;

#ifdef TK
#include "tcl++.h"

#ifdef _WIN32
#undef Realloc
#include <windows.h>
#include <wingdi.h>
#ifdef USE_WIN32_SURFACE
#include <cairo/cairo-win32.h>

// undocumented internal function for extracting the HDC from a Drawable
extern "C" HDC TkWinGetDrawableDC(Display*, Drawable, void*);
extern "C" HDC TkWinReleaseDrawableDC(Drawable, HDC, void*);
Expand All @@ -47,9 +53,6 @@ extern "C" HDC TkWinReleaseDrawableDC(Drawable, HDC, void*);
#define CONST86
#endif

using namespace ecolab;
using namespace std;

namespace
{
struct TkWinSurface: public ecolab::cairo::Surface
Expand Down Expand Up @@ -193,11 +196,14 @@ namespace

}

#endif // TK
void CairoSurface::registerImage()
{
#ifdef TK
// ensure Tk_Init is called.
if (!Tk_MainWindow(interp())) Tk_Init(interp());
Tk_CreateImageType(&canvasImage);
#endif
}

cairo::SurfacePtr CairoSurface::vectorRender(const char* filename, cairo_surface_t* (*s)(const char *,double,double))
Expand Down Expand Up @@ -293,4 +299,4 @@ void CairoSurface::renderToEMF(const string& filename)

#endif

#endif
#endif //CAIRO
10 changes: 6 additions & 4 deletions src/cairo_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
#include "ecolab_epilogue.h"

const char *ecolab::Pango::defaultFamily=NULL;
double ecolab::Pango::scaleFactor=1;

#if defined(CAIRO) && defined(TK)
#if defined(CAIRO)

#if CAIRO_VERSION_MAJOR <= 1 && CAIRO_VERSION_MINOR < 10
//#error "Cairo 1.10.x minimum required"
Expand All @@ -22,6 +23,7 @@ bool cairo_in_clip(cairo_t*,double,double) {return true;}
#endif

using namespace std;
#if defined(TK)

namespace
{
Expand Down Expand Up @@ -90,7 +92,6 @@ namespace

namespace ecolab
{
double Pango::scaleFactor=1;

namespace cairo
{
Expand Down Expand Up @@ -136,7 +137,7 @@ namespace ecolab
else
throw error("image %s not found", imgName.c_str());
}

double CairoImage::distanceFrom(double x, double y) const
{
if (cairoSurface)
Expand Down Expand Up @@ -225,4 +226,5 @@ namespace ecolab
}
}

#endif
#endif // TK
#endif // CAIRO

0 comments on commit d98e897

Please sign in to comment.