Can anyone guide me on making a simple FLTK app with Cairo that can scroll 
images (in both horizontal and vertical direction if they are larger than the 
window size) and rotate images.

I modified the cairo_test.cxx file and was *somewhat* able to rotate an image 
by 90 degrees but I am completely dumbfounded on making a scrollable image.

It is so much easier to have a scrollable image embedded in html code and open 
using Fl_Help_View but the speed of image rendering is quite slow. Therefore, I 
wanted to use Cairo for faster image rendering and rotation.

Here is my code -

#include <config.h>
#ifdef HAVE_CAIRO
#include <FL/Fl_Cairo_Window.H>
#include <FL/Fl_Box.H>
#include <FL/x.H>
#include <FL/fl_draw.H>
#include <FL/math.h>
#define DEF_WIDTH 0.03
#include <FL/Fl_Scroll.H>
#include <FL/fl_draw.H>
static void my_cairo_draw_cb(Fl_Cairo_Window* window, cairo_t* cr) {
double im_w, im_h;
double cur_w, cur_h;
cairo_surface_t *image;

image = cairo_image_surface_create_from_png ("Test.png");
im_w = cairo_image_surface_get_width (image);
im_h = cairo_image_surface_get_height (image);
printf("width = %g, height = %g\n",im_w, im_h);
if (im_w > window->w() || im_h > window->h())
          {
                if (im_w > im_h)
                {
                        cur_h = window->h();
                        cur_w = window->h()*im_w/im_h;
                }
                else
                {
                        cur_w = window->w();
                        cur_h = window->w()*im_h/im_w;
                }
                printf("cur width = %g, cur height = %g\n",cur_w, cur_h);
                cairo_scale  (cr, cur_w/im_w, cur_h/im_h);

}
cairo_translate (cr, window->w(), 0);
cairo_rotate (cr, 90* M_PI/180);
cairo_set_source_surface (cr, image, 20, 20);
cairo_paint (cr);
cairo_surface_destroy (image);

}

int main(int argc, char** argv) {
#ifdef AUTOLINK
  Fl::cairo_autolink_context(true);
#endif
    Fl_Cairo_Window window(800,800);
    window.color(FL_WHITE);
    window.show(argc,argv);
    window.set_draw_cb(my_cairo_draw_cb);
    window.end();
    return Fl::run();
}
#else
#include <FL/fl_ask.H>

int main(int argc, char** argv) {
  fl_message("please configure fltk with CAIRO enabled (--enable-cairo or 
--enable-cairoext)");
  return 0;
}
#endif
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to