I have now seen that at least fltk-3.0.x-r9405
favours absolute positioning. But the newer
revisions favour relative positioning.

The code below shows another problem. If the
origin of the ScrollGroup is (0,0) then the
image shown is OK.

But try to change the value of SCROLL_Y. Then
the image shown is broken.

Why? Can this be overcome?

winfried

#include <fltk3/run.h>
#include <fltk3/Window.h>
#include <fltk3/draw.h>
#include <fltk3/Widget.h>
#include <fltk3/ScrollGroup.h>
#include <fltk3/Image.h>
#include <fltk3/RGBImage.h>
#include <fltk3/SharedImage.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static fltk3::Window *win;
static fltk3::ScrollGroup *scroll;
static fltk3::Widget *wid;
static fltk3::SharedImage *img;

#define SCROLL_X 0
#define SCROLL_Y 0

#define WIN_W 740
#define WIN_H 400
#define BORDER_SIZE 5

#define SCROLL_W (WIN_W - SCROLL_X - SCROLL_X)
#define SCROLL_H (WIN_H - SCROLL_Y - BORDER_SIZE)
#define BAR_SIZE 17

static void load_file(const char *fname)
{
    if(fname)
   {
    img = fltk3::SharedImage::get(fname);

    if(img)
  {
    int win_w, win_h, scroll_h, scroll_w, iw, ih;
    int has_hbar, has_vbar;
    unsigned char type;

    has_hbar = has_vbar = 0;
    iw = img->w(); ih = img->h();

    if(iw > SCROLL_W - BAR_SIZE) has_hbar = BAR_SIZE;

    if(ih > SCROLL_H - BAR_SIZE) has_vbar = BAR_SIZE;

    if(has_vbar)
     scroll_h = SCROLL_H;
    else
     scroll_h = ih + has_hbar;

    if(has_hbar)
     scroll_w = SCROLL_W;
    else
     scroll_w = iw + has_vbar;

    win_h = SCROLL_Y + scroll_h + BORDER_SIZE;
    win_w = SCROLL_X + scroll_w + SCROLL_X;

    if(win_w < 120) win_w = 120;

    win->resize(win->x(), win->y(), win_w, win_h);
    scroll->size(scroll_w, scroll_h);

    wid->size(img->w(), img->h());
    wid->image(img);

    type = 0;
    if(has_hbar) type |= fltk3::ScrollGroup::HORIZONTAL;
    if(has_vbar) type |= fltk3::ScrollGroup::VERTICAL;

    scroll->type(type);
    scroll->scroll_to(0,0);

    win->redraw();
  }
   }
}

int main(int argc, char *argv[])
{
    char *fname;
    FILE *fp;

    fltk3::register_images();

    if(argc == 2)
   {
    fname = argv[1];
    fp = fopen(fname, "r");

    if(fp == NULL)
  {
    fname = NULL;
  }
    else
  {
    fclose(fp);
  }
   }
    else
   {
    fname = NULL;
   }
    win = new fltk3::Window(WIN_W, WIN_H, "ScrollGroup Test");
    win->begin();

    scroll = new fltk3::ScrollGroup(SCROLL_X, SCROLL_Y,
                  SCROLL_W, SCROLL_H);
    scroll->box(fltk3::FLAT_BOX);
    scroll->begin();

    wid = new fltk3::Widget(0, 0, SCROLL_W, SCROLL_H);
    wid->box(fltk3::FLAT_BOX);
    wid->color(fltk3::WHITE);

    scroll->end();
//  scroll->resizable(wid);

//  win->resizable(scroll);
    win->end();

    win->show();

    load_file(fname);

    return fltk3::run();
}

_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to