diff --git a/CMakeLists.txt b/CMakeLists.txt index 1256a526da15fb3ee6001fd9693f4d770519628c..18fba98a133206a62c9e0a7ae9fb3a1abf14dc66 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -572,10 +572,10 @@ if(ENABLE_CAIRO) find_library(CAIRO_LIB cairo) find_path(CAIRO_INC "cairo/cairo.h" PATH_SUFFIXES include) if(CAIRO_INC AND CAIRO_LIB) - set_config_option(HAVE_CAIRO "cairo") + set_config_option(HAVE_CAIRO "Cairo") list(APPEND EXTERNAL_LIBRARIES ${CAIRO_LIB}) list(APPEND EXTERNAL_INCLUDES ${CAIRO_INC}) - endif(CAIRO_LIB AND CAIRO_INC) + endif(CAIRO_INC AND CAIRO_LIB) endif(ENABLE_CAIRO) if(ENABLE_DINTEGRATION) @@ -590,7 +590,6 @@ if(ENABLE_OPTHOM) set_config_option(HAVE_OPTHOM "OptHom") endif(ENABLE_OPTHOM) - if(ENABLE_KBIPACK) set_config_option(HAVE_KBIPACK "Kbipack") add_subdirectory(contrib/kbipack) diff --git a/Fltk/drawContextFltkCairo.cpp b/Fltk/drawContextFltkCairo.cpp index 2fa3bb9506337754f6dcad5b82650e2d00f5582b..3b7ac09ae12580da69426959724ab763651c329f 100644 --- a/Fltk/drawContextFltkCairo.cpp +++ b/Fltk/drawContextFltkCairo.cpp @@ -1,10 +1,19 @@ +// Gmsh - Copyright (C) 1997-2013 C. Geuzaine, J.-F. Remacle +// +// See the LICENSE.txt file for license information. Please report all +// bugs and problems to the public mailing list <gmsh@geuz.org>. +// +// Contributed by Jonathan Lambrechts + #include "drawContextFltkCairo.h" + #if defined(HAVE_CAIRO) #include <cairo/cairo.h> -#include "GL/gl.h" -//mostly borrowed from fltk function gl_texture_fifo::display_texture -static void _data2gl (int width, int height, unsigned char *data, int Lx, int Ly, unsigned int _textureId) { +//mostly borrowed from fltk function gl_texture_fifo::display_texture +static void _data2gl (int width, int height, unsigned char *data, + int Lx, int Ly, unsigned int _textureId) +{ //setup matrices GLint matrixMode; glGetIntegerv (GL_MATRIX_MODE, &matrixMode); @@ -21,30 +30,31 @@ static void _data2gl (int width, int height, unsigned char *data, int Lx, int Ly //write the texture on screen GLfloat pos[4]; glGetFloatv(GL_CURRENT_RASTER_POSITION, pos); - - glEnable (GL_TEXTURE_RECTANGLE_ARB); - glPushAttrib(GL_ENABLE_BIT | GL_TEXTURE_BIT | GL_COLOR_BUFFER_BIT); + + glEnable (GL_TEXTURE_RECTANGLE_ARB); + glPushAttrib(GL_ENABLE_BIT | GL_TEXTURE_BIT | GL_COLOR_BUFFER_BIT); glDisable(GL_LIGHTING); glDisable (GL_DEPTH_TEST); - glEnable (GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glBindTexture (GL_TEXTURE_RECTANGLE_ARB, _textureId); - glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, data); - glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_SRC0_ALPHA); + glEnable (GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBindTexture (GL_TEXTURE_RECTANGLE_ARB, _textureId); + glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_ALPHA, width, height, 0, + GL_ALPHA, GL_UNSIGNED_BYTE, data); + glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_SRC0_ALPHA); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - + glTranslatef(pos[0] /*+ rect->x_bearing*/, pos[1] /*+ rect->y_bearing*/, pos[2]); - glBegin (GL_QUADS); - glTexCoord2f (0, 0); - glVertex2f (0.0f, Ly); - glTexCoord2f (Lx, 0); - glVertex2f (Lx, Ly); - glTexCoord2f (Lx, Ly); - glVertex2f (Lx, 0.0f); - glTexCoord2f (0, Ly); - glVertex2f (0.0f, 0.0f); - glEnd (); + glBegin (GL_QUADS); + glTexCoord2f (0, 0); + glVertex2f (0.0f, Ly); + glTexCoord2f (Lx, 0); + glVertex2f (Lx, Ly); + glTexCoord2f (Lx, Ly); + glVertex2f (Lx, 0.0f); + glTexCoord2f (0, Ly); + glVertex2f (0.0f, 0.0f); + glEnd (); glPopAttrib(); @@ -55,7 +65,8 @@ static void _data2gl (int width, int height, unsigned char *data, int Lx, int Ly glMatrixMode (matrixMode); } -double drawContextFltkCairo::getStringWidth(const char *str) { +double drawContextFltkCairo::getStringWidth(const char *str) +{ cairo_text_extents_t e; cairo_text_extents(_cr, str, &e); return e.width; @@ -69,7 +80,8 @@ void drawContextFltkCairo::draw() //ensure the surface is large enough void drawContextFltkCairo::_resizeSurface(int w, int h) { - if (w > cairo_image_surface_get_width(_surface) || h > cairo_image_surface_get_height(_surface)) { + if (w > cairo_image_surface_get_width(_surface) || + h > cairo_image_surface_get_height(_surface)) { cairo_font_face_t *face = cairo_get_font_face(_cr); cairo_matrix_t matrix; cairo_get_font_matrix(_cr, &matrix); @@ -99,7 +111,10 @@ void drawContextFltkCairo::drawString(const char *str) cairo_move_to(cr, 1-extent.x_bearing, 1-extent.y_bearing); cairo_set_source_rgba(cr, 1, 1, 1, 1); cairo_show_text(cr, str); - _data2gl(cairo_image_surface_get_width(surface), cairo_image_surface_get_height(surface), cairo_image_surface_get_data(surface), extent.width + 1, extent.height + 1, _textureId); + _data2gl(cairo_image_surface_get_width(surface), + cairo_image_surface_get_height(surface), + cairo_image_surface_get_data(surface), + extent.width + 1, extent.height + 1, _textureId); // fltk version (fl_read_image is too slow) /*Fl_Offscreen offscreen = fl_create_offscreen(100, 100); @@ -125,7 +140,7 @@ drawContextFltkCairo::~drawContextFltkCairo() { cairo_destroy(_cr); cairo_surface_destroy(_surface); - glDeleteTextures(1, &_textureId); + glDeleteTextures(1, &_textureId); } drawContextFltkCairo::drawContextFltkCairo() @@ -136,7 +151,8 @@ drawContextFltkCairo::drawContextFltkCairo() _currentFontId = -1; } -void drawContextFltkCairo::setFont(int fontid, int fontsize) { +void drawContextFltkCairo::setFont(int fontid, int fontsize) +{ if (_currentFontId != fontid) { switch (fontid) { case FL_HELVETICA : @@ -170,4 +186,5 @@ void drawContextFltkCairo::setFont(int fontid, int fontsize) { } cairo_set_font_size(_cr, fontsize); } + #endif diff --git a/Fltk/drawContextFltkCairo.h b/Fltk/drawContextFltkCairo.h index daccf7ec3a1bc2a4d3888f3cd7fc2f6d937858ba..28f043cb19a503f405c9b7eb43c08070a4fb7981 100644 --- a/Fltk/drawContextFltkCairo.h +++ b/Fltk/drawContextFltkCairo.h @@ -1,10 +1,21 @@ +// Gmsh - Copyright (C) 1997-2013 C. Geuzaine, J.-F. Remacle +// +// See the LICENSE.txt file for license information. Please report all +// bugs and problems to the public mailing list <gmsh@geuz.org>. +// +// Contributed by Jonathan Lambrechts + #ifndef _DRAW_CONTEXT_FLTK_CAIRO_H_ #define _DRAW_CONTEXT_FLTK_CAIRO_H_ + #include "GmshConfig.h" + #if defined(HAVE_CAIRO) #include "drawContextFltk.h" + typedef struct _cairo_surface cairo_surface_t; typedef struct _cairo cairo_t; + class drawContextFltkCairo : public drawContextFltk { cairo_surface_t *_surface; cairo_t *_cr; @@ -22,5 +33,7 @@ class drawContextFltkCairo : public drawContextFltk { void drawString(const char *str); void setFont(int fontid, int fontsize); }; + #endif + #endif