On 8 Jun 2010, at 17:08, Leandro Fanzone wrote:
>
> I know those are many, and perhaps silly questions, but I couldn't  
> find a suitable example among the demos, and I know you said "no  
> examples" ;)

OK, here's something that works, but it is hacked together out of a  
few bits I had lying around, lacks any useful comments, and is  
probably *not* the smartest way to achieve the desired affect...

Tested on OSX only, as I can't be bothered moving over to another PC...

OH - And past experience suggests that the mailing process will  
probably wrap all the longer lines and make the code even more of a  
mess. Be aware!
--------------
// fltk-config --compile text-scale.cxx
#include <stdlib.h>
#include <stdio.h>

#include <FL/Fl.H>
#include <FL/x.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Shared_Image.H>
#include <FL/fl_draw.H>

#include <FL/math.h>

void draw_offscreen();

static Fl_Offscreen offscreen_cxt = NULL;
static Fl_Window *main_win = NULL;
static char message[64];
static int scale = 1;

class scope_view: public Fl_Box
{
        void draw();
public:
        scope_view(int x, int y,int w,int h, const char *l=0) : Fl_Box 
(x,y,w,h,l) {}
};

void scope_view::draw()
{
        int wd = w();
        int ht = h();
        int xo = x();
        int yo = y();

         if(offscreen_cxt){
           fl_copy_offscreen(xo, yo, wd, ht, offscreen_cxt, 0, 0);
         }
         else {
           fl_color(FL_GRAY);
           fl_rectf(xo, yo, wd, ht);
           draw_offscreen();
         }
        
} /* end of draw() method */

static scope_view *scope = 0;

class text_view: public Fl_Box
{
        void draw();
public:
        text_view(int x, int y,int w,int h, const char *l=0) : Fl_Box 
(x,y,w,h,l) {}
};

static uchar *data_p = NULL;
static Fl_Image *img_tmp = NULL;

void text_view::draw()
{
        int wd = scope->w();
        int ht = scope->h();
        int xo = 0;
        int yo = 0;

         if(offscreen_cxt) { // offscreen exists, grab something
                 if(data_p){
                         delete[] data_p;
                         data_p = NULL;
                 }
                 fl_begin_offscreen(offscreen_cxt); /* Open the  
offscreen context for reading */

                 data_p = fl_read_image(data_p, 0, 0, wd, ht, 0);

                 fl_end_offscreen(); // close the offscreen context

                 Fl_RGB_Image rgb(data_p, wd, ht);
                 if(img_tmp){
                         delete img_tmp; // free the previous image  
before copying the new one
                 }
                 img_tmp = rgb.copy(wd * scale, ht); // scale the  
image in the width direction
                 img_tmp->draw(x(), y(), wd, ht, 0, 0);
         }
} /* end of draw() method */

static text_view *zoom = 0;

void draw_offscreen()
{
        int wd = scope->w();
        int ht = scope->h();
        int xo = 0;
        int yo = 0;

        if (!offscreen_cxt) offscreen_cxt = fl_create_offscreen(wd, ht);
        if (!offscreen_cxt) {puts("Bad Offscreen"); exit(-1);}

        fl_begin_offscreen(offscreen_cxt);

        fl_color(FL_WHITE);
        fl_rectf(xo, yo, wd, ht);

        fl_color(FL_BLACK);

         fl_font(FL_HELVETICA, 24);
         int tw, th;
         tw = th = 0;
         fl_measure(message, tw, th);
         fl_draw(message, xo + 10, yo + 10 + th);

        fl_end_offscreen();
        scope->redraw();
         zoom->redraw();
         main_win->redraw();
} /* end of draw() method */

void update_zoom(void *)
{
         static int d = 1;
         scale = scale + d;
         if(scale > 4) {
                 d = -1;
         }
         if(scale < 2) {
                 d = +1;
         }
         sprintf(message, "Scaled by %d", scale);
        draw_offscreen();
        Fl::repeat_timeout(1.0, update_zoom);
} // update_offscreen

int main(int argc, char **argv)
{
         sprintf(message, "Scaled by %d", scale);
        main_win = new Fl_Window(522, 500, "Zoom Text Window");
        main_win->begin();
        scope = new scope_view(5, 5, 512, 200);
        zoom  = new text_view(5, 210, 512, 200);
        main_win->end();
        main_win->show(argc, argv);
        
         draw_offscreen();

         Fl::add_timeout(1.0, update_zoom);
        
        return Fl::run();
}

/* end of file */

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

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

Reply via email to