An easy way to use a scrollbar inside a GlWindow is to create your window and a 
scrollbar, then as the value of the scrollbar changes, modify a global variable 
(or static class member) and call redraw() on the glWindow. Inside your draw 
function, use glTranslatef() with the values your scrollbar sets. This 
effectively works as a crude way to scroll, though it can get expensive.
You can further optimise this with a boolean flag if you don't need to redraw 
your entire window's contents.
A brief example is shown below. I've stolen some of Greg's code to draw an X as 
an example, but feel free to fill in your own drawing code as you see fit.

Regards,
Ben

----------------------------------------------------------------

// Scrollbar + GlWindow
// Compile with fltk2-config --use-gl --compile 
#include <fltk/Scrollbar.h>
#include <fltk/GlWindow.h>
#include <fltk/run.h>
#include <fltk/Window.h>
#include <fltk/gl.h>

using namespace fltk;

float xpan;

class myGlWindow : public GlWindow {
public:
    bool changed;
    void draw(){
        glPushMatrix();
        glTranslatef(0, xpan, 0);
        if(changed) {
            // First time? init viewport, etc.
                   if (!valid()) {
                valid(1);
                glLoadIdentity();
                glViewport(0,0,w(),h());
                glOrtho(-w(),w(),-h(),h(),-1,1);
            }
                // Clear screen
                glClear(GL_COLOR_BUFFER_BIT);
                // Draw white 'X'
                glColor3f(1.0, 1.0, 1.0);
                glBegin(GL_LINE_STRIP); glVertex2f(w(), h()); 
glVertex2f(-w(),-h()); glEnd();
                glBegin(GL_LINE_STRIP); glVertex2f(w(),-h()); glVertex2f(-w(), 
h()); glEnd();
            changed = 0;
        }
        glPopMatrix();
    }
    // HANDLE WINDOW RESIZING
    // If window reshaped, need to readjust viewport/ortho
    //
    void resize(int X,int Y,int W,int H) {
        GlWindow::resize(X,Y,W,H);
        glLoadIdentity();
        glViewport(0,0,W,H);
        glOrtho(-W,W,-H,H,-1,1);
        redraw();
    }
    myGlWindow(int x, int y, int w, int h) : GlWindow(x,y,w,h), changed(1) {};
};

void scrollCB(Widget* w, void* v){
    xpan = ((Scrollbar*)w)->value();
    ((myGlWindow*)v)->changed = 1;
    ((myGlWindow*)v)->redraw();
}

int main(){
    Window win(800, 600);
    win.begin();
    myGlWindow mainWin(20, 0, 780, 600);
    Scrollbar scroll(0, 0, 20, 600);
    scroll.align(ALIGN_LEFT);
    scroll.set_vertical();
    scroll.minimum(25);
    scroll.maximum(-25);
    scroll.step(0.1);
    scroll.callback(scrollCB, (void*)&mainWin);
    win.end();
    win.show();
    return run();
}


> Date: Mon, 21 Feb 2011 15:59:32 +0000
> From: [email protected]
> To: [email protected]
> Subject: Re: [fltk.development] glwindow inside scrollgroup,fltk2
> 
> 
> > after few experiments I noticed in documentation that I can't 
> > use glwindow within scrollGroup, therefore I can't have 
> > scrollbars for glwindow.
> > 
> > I was wondering if exists any workaround how to achieve 
> > scrollbars for glwindow.
> 
> 
> Presumably you have looked at the CubeView demo?
> Does that not do what you want?
> Maybe want to use Fl_Scrollbar widgets in place of the Fl_Sliders that
> the CubeView demo uses, but otherwise the idea would be the same, I
> think.
> 
> 
> 
> 
> 
> 
> SELEX Galileo Ltd
> Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 
> 3EL
> A company registered in England & Wales.  Company no. 02426132
> ********************************************************************
> This email and any attachments are confidential to the intended
> recipient and may also be privileged. If you are not the intended
> recipient please delete it from your system and notify the sender.
> You should not copy it or use it for any purpose nor disclose or
> distribute its contents to any other person.
> ********************************************************************
> 
> _______________________________________________
> fltk-dev mailing list
> [email protected]
> http://lists.easysw.com/mailman/listinfo/fltk-dev
                                          
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to