Scrollable SVG

43 views
Skip to first unread message

Damiano Rocchi

unread,
Jun 8, 2022, 1:27:17 PM6/8/22
to fltk.general
Hi,
I write a little program in C++ with fltk 1.4, and I don't succed to scroll a SVG image, larger the window. Can you help me ?


#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_SVG_Image.H>
#include <Fl/Fl_Scroll.H>
int main(int argc, char **argv) {
  Fl_Window *win = new Fl_Window(720, 486, "svg test");
  Fl_Scroll scroll(0, 0, 720, 486);
  Fl_Box    *box = new Fl_Box(0, 0, win->w(), win->h());
 
  const char *svgpath = "Imm.svg";
  Fl_SVG_Image *svg = new Fl_SVG_Image(svgpath);
  box->image(svg);
 
  win->end();
  win->show();
  return(Fl::run());
}

Ian MacArthur

unread,
Jun 8, 2022, 2:29:35 PM6/8/22
to fltk.general
The SVG image will be drawn at the size of the box you assign it to (since SVG is meant to be scalable) which in this case is the same size as your scroll view.
So there is nowhere to scroll, since the SVG image fits into the view, there is nothing outside the view to scroll to...

Make the box bigger than the scroll, then you will have somewhere to scroll...

Like this: a slightly tweaked version that should work - also note that I fixed the name case on some of your header files - I assume you are on Windows, or that would probably have choked at compile time on another platform...

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_SVG_Image.H>
#include <FL/Fl_Scroll.H>


int main(int argc, char **argv)
{
    Fl_Window *win = new Fl_Window(256, 256, "svg test");
    Fl_Scroll scroll(0, 0, win->w(), win->h());
    Fl_Box    *box = new Fl_Box(0, 0, 512, 512);

    const char *svgpath = "test.svg";

    Fl_SVG_Image *svg = new Fl_SVG_Image(svgpath);
    box->image(svg);

    win->end();
    win->show();
    return(Fl::run());
}

/* End of file */


Damiano Rocchi

unread,
Jun 9, 2022, 8:41:47 AM6/9/22
to fltk.general
I understand, thanks Ian for advices. It works.
Reply all
Reply to author
Forward
0 new messages