> My problem is to draw any line or rectangle on any image.
> Suppose if i draw an image (using fl_draw_image) on some part 
> of window. Then i want to draw any rectangle oe line on this 
> image. That i have tried in draw function(after drawing 
> image) and outside the draw function. But line/rectangle never appear.

I'm not sure I understand what you want - but here's a worked example -
probably unnecessarily complex, that I hacked together. Does this help?

/***********************************************************************
*/
// Compile as:
// fltk-config --use-images --compile image_draw.cxx
//
// invoke as:
// image_draw {something.jpg | something.png | etc...}
//
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <FL/Fl.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Shared_Image.H>
#include <Fl/fl_draw.H> 

Fl_Double_Window *outer_win;
Fl_Shared_Image *img;
Fl_RGB_Image *rgbimg = NULL;

/***********************************************************************
*/ 
class vw_box : public Fl_Box { 
protected:
        void draw(void);
        int iw, ih, id;
        char *data; 

public:
        vw_box(int X, int Y, int W, int H, const char *L=0) :
Fl_Box(X,Y,W,H,L) 
        {data = NULL;}
        
        void set_data(char *newdat, int W, int H, int D); 
}; 

/***********************************************************************
*/ 
void vw_box::set_data(char *newdat, int W, int H, int D) {
        iw = W; ih = H; id = D;
        if (data) delete [] data;
        data = newdat; 
} 

/***********************************************************************
*/ 
void vw_box::draw(void) {
        if (!data) return;
        
        short wd = w(); short ht = h();
        short xoff = 0; short yoff = 0; 
        static short xp = 50, yp = 50, dx = 10, dy = 10;
        
        xp += dx; yp += dy;
        if (xp < x()) {xp = x(); dx = -dx;}
        if ((xp+100) > (x()+wd)) {xp = (x()+wd-100); dx = -dx;}
        
        if (yp < y()) {yp = y(); dy = -dy;}
        if ((yp+100) > (y()+ht)) {yp = (y()+ht-100); dy = -dy;}
        
        if (ih < ht) yoff = (ht - ih) / 2; 
        if (iw < wd) xoff = (wd - iw) / 2; 
    short xpos = x() + xoff;
    short ypos = y() + yoff; 

    /* Ensure that the full window is redrawn */
        Fl_Box::draw();
    fl_push_no_clip(); 

    /* Redraw the whole image */
    fl_draw_image((const uchar *)data, xpos, ypos, iw, ih, id); 

        // draw a box on top of the image
        fl_rect(xp, yp, 100, 100, FL_RED);

    fl_pop_clip(); 
} 
/***********************************************************************
*/ 
vw_box *box_1;
/***********************************************************************
*/ 
void load_file(const char *n) {
        if (img) img->release();
        
        img = Fl_Shared_Image::get(n);
        if (!img) {
                puts("Image file format not recognized!");
fflush(stdout);
                return;
        }
        Fl_Image *temp;
        if (img->w() > img->h()) temp = img->copy(box_1->w(), box_1->h()
* img->h() / img->w());
        else temp = img->copy(box_1->w() * img->w() / img->h(),
box_1->h());
        
        img->release();
        img = (Fl_Shared_Image *)temp;
        box_1->image(img);
        box_1->set_data((char *)img->data()[0], img->w(), img->h(),
img->d());
        box_1->redraw();
}
/***********************************************************************
*/
void quit_cb(Fl_Button*, void*) {
        outer_win->hide();
}
/***********************************************************************
*/
void animate_box(void*) {
        box_1->redraw();
        Fl::repeat_timeout(0.1, animate_box);
}
/***********************************************************************
*/
int main(int argc, char **argv) {
        fl_register_images();
        Fl::get_system_colors();
        
        outer_win = new Fl_Double_Window(600, 650, "Picture Window");
        
        box_1 = new vw_box(5, 5, 590, 500);
        box_1->box(FL_FLAT_BOX);

        Fl_Button *quit = new Fl_Button(535, 615, 60, 30);
        quit->label("Quit");
        quit->callback((Fl_Callback*)quit_cb);
        outer_win->end();

        if (argv[1]) load_file(argv[1]);
        
        outer_win->show();
        Fl::add_timeout(0.1, animate_box);
        return Fl::run();
}
/* End of File */


SELEX Sensors and Airborne Systems Limited
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 mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to