I’m a dabbler in FLTK, but haven’t used it an a number of years.
I’m drawing some text in a scrolled window. I want some of the text on the
screen to always be the same and not scroll (imagine headers in a table).
That's not what I'm doing, but it's the same principle. Everything else
should scroll.
I draw everything else relative to the y() so it scrolls properly, but I
draw the "headers" at the same location. This results in erratic
behavior. I’ve tried it on a couple of machines, one running 1.1.7 and one
running 1.3; I get the same results.
So I decided to start simple. I started with Erco's “How to make a
Scrollable ‘Canvas’ code. Then at the bottom of the draw() method I added
one line:
fl_line(0,60,200,60);
I would have expected this line to always appear at the same place in the
window as I scroll up and down (i.e. it wouldn’t scroll), but it does not.
Interestingly enough, if I resize the window the line gets redrawn in the
correct location, but not if I scroll.
I’ve included the entire program below.
I've also had have another issue with scrolling text. If the text changes
while scrolling, things look flaky. To demonstrate, I've also added two
lines of text to the program. For the first line I draw the string "60" at
a location of y()+60. This scrolls properly. For the second line I draw a
string containing the value of y() at a location of y()+80. This scrolls,
but the value does not update properly, and if you scroll it off the top
and then back down, the text becomes gibberish; it looks like partial draws
of multiple y values. Again, if I resize the window everything gets
redrawn correctly, but not if I scroll.
I obviously don't understand how scrolling works. I can see the draw()
method being called, and I can print out the value of y() to the terminal
and it is correct, but it doesn't appear correctly when I draw it on the
screen.
Thanks for any help you can give me.
-- John
// DEMONSTRATE HOW TO MAKE A SCROLLABLE "CANVAS" DRAWING OF AN 'X'
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Scroll.H>
#include <FL/fl_draw.H>
#include <stdio.h>
// SCROLLABLE CANVAS EXAMPLE -- JUST DRAWS AN 'X'
class MyCanvas : public Fl_Widget {
public:
MyCanvas(int X,int Y,int W,int H,const char*L=0) :
Fl_Widget(X,Y,W,H,L) {
void draw() {
// DRAW BG
fl_color(color());
fl_rectf(x(),y(),w(),h());
// DRAW 'X' OVER BG
// Do your graphics here..
//
int x1=x(), y1=y(); // Fl_Scroll works by changing
our widget's x() and y(),
int x2=x()+w()-1, y2=y()+h()-1; // so take these into account
for our drawing coordinates
fl_color(FL_BLACK);
fl_line(x1,y1,x2,y2);
fl_line(x1,y2,x2,y1);
///////////////
// NEW CODE HERE
// draw a horizontal line that's always in the same position in
the window (it shouldn't scroll
// since we don't use y() when we calculate the y coordinate.
This does not work.
fl_line(0,60,200,60);
// draw a string that scrolls. This works.
fl_font(FL_HELVETICA,14);
char astring[100];
sprintf(astring, "%d", 60);
fl_draw(astring, 0, y1+60);
// draw a string that scrolls, and that changes as we scroll.
This does not work.
sprintf(astring, "%d", y1);
fl_draw(astring, 0, y1+80);
// END NEW CODE
///////////////
};
int main() {
Fl_Double_Window win(301,251);
Fl_Scroll scroll(0,0,200,200);
MyCanvas canvas(0,0,350,350); // purposely make drawing area
larger than scroll
scroll.end();
win.end();
win.resizable(canvas);
win.show();
return(Fl::run());
I’m drawing some text in a scrolled window. I want some of the text on the
screen to always be the same and not scroll (imagine headers in a table).
That's not what I'm doing, but it's the same principle. Everything else
should scroll.
I draw everything else relative to the y() so it scrolls properly, but I
draw the "headers" at the same location. This results in erratic
behavior. I’ve tried it on a couple of machines, one running 1.1.7 and one
running 1.3; I get the same results.
So I decided to start simple. I started with Erco's “How to make a
Scrollable ‘Canvas’ code. Then at the bottom of the draw() method I added
one line:
fl_line(0,60,200,60);
I would have expected this line to always appear at the same place in the
window as I scroll up and down (i.e. it wouldn’t scroll), but it does not.
Interestingly enough, if I resize the window the line gets redrawn in the
correct location, but not if I scroll.
I’ve included the entire program below.
I've also had have another issue with scrolling text. If the text changes
while scrolling, things look flaky. To demonstrate, I've also added two
lines of text to the program. For the first line I draw the string "60" at
a location of y()+60. This scrolls properly. For the second line I draw a
string containing the value of y() at a location of y()+80. This scrolls,
but the value does not update properly, and if you scroll it off the top
and then back down, the text becomes gibberish; it looks like partial draws
of multiple y values. Again, if I resize the window everything gets
redrawn correctly, but not if I scroll.
I obviously don't understand how scrolling works. I can see the draw()
method being called, and I can print out the value of y() to the terminal
and it is correct, but it doesn't appear correctly when I draw it on the
screen.
Thanks for any help you can give me.
-- John
// DEMONSTRATE HOW TO MAKE A SCROLLABLE "CANVAS" DRAWING OF AN 'X'
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Scroll.H>
#include <FL/fl_draw.H>
#include <stdio.h>
// SCROLLABLE CANVAS EXAMPLE -- JUST DRAWS AN 'X'
class MyCanvas : public Fl_Widget {
public:
MyCanvas(int X,int Y,int W,int H,const char*L=0) :
Fl_Widget(X,Y,W,H,L) {
void draw() {
// DRAW BG
fl_color(color());
fl_rectf(x(),y(),w(),h());
// DRAW 'X' OVER BG
// Do your graphics here..
//
int x1=x(), y1=y(); // Fl_Scroll works by changing
our widget's x() and y(),
int x2=x()+w()-1, y2=y()+h()-1; // so take these into account
for our drawing coordinates
fl_color(FL_BLACK);
fl_line(x1,y1,x2,y2);
fl_line(x1,y2,x2,y1);
///////////////
// NEW CODE HERE
// draw a horizontal line that's always in the same position in
the window (it shouldn't scroll
// since we don't use y() when we calculate the y coordinate.
This does not work.
fl_line(0,60,200,60);
// draw a string that scrolls. This works.
fl_font(FL_HELVETICA,14);
char astring[100];
sprintf(astring, "%d", 60);
fl_draw(astring, 0, y1+60);
// draw a string that scrolls, and that changes as we scroll.
This does not work.
sprintf(astring, "%d", y1);
fl_draw(astring, 0, y1+80);
// END NEW CODE
///////////////
};
int main() {
Fl_Double_Window win(301,251);
Fl_Scroll scroll(0,0,200,200);
MyCanvas canvas(0,0,350,350); // purposely make drawing area
larger than scroll
scroll.end();
win.end();
win.resizable(canvas);
win.show();
return(Fl::run());