Finally the code is working BUT
The load function can not work because of this line in code
" //fl_register_images();" When i keep it , it gives me 23 errors
Can i changed it or do somethingelse to not stick with this problem

also i change the extension from cxx to cpp ?? but i'd like to
know the diffece between both

ANY HELP ANY SUPPORT GUYS

huda

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

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

Fl_Double_Window *main_win;
Fl_Shared_Image *img;
Fl_RGB_Image *img_3 = NULL;

int depth = 0;
int count = 0;
int width = 0;
int height = 0;
const char *datap;
int xoff = 0;
int yoff = 0;

/************************************************************************/
/************************************************************************/
class vw_box : public Fl_Box
{
protected:
        void draw(void);
                int iw;
                int ih;
                int 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;

        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_push_no_clip();

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

    fl_pop_clip();
}
/************************************************************************/
class img_box : public Fl_Box
{
protected:
        int handle(int ev);
public:
     img_box(int X, int Y, int W, int H, const char *L=0) : Fl_Box(X,Y,W,H,L) {}
};
/************************************************************************/
int img_box::handle(int ev)
{
        int ret = Fl_Box::handle(ev);
        if (ev == FL_PUSH)
        {
                // NOTE: This only handles the simple 3 colour case...
                if ((count == 1) && (depth == 3))
                {
                        int xc = (int)Fl::event_x();
                        int yc = (int)Fl::event_y();
                        int idx;
                        unsigned char r, g, b;

                        if ((xc < xoff) || (xc > (200 - xoff)))
                        {
                                puts("X click not in image area");
                                fflush(stdout);
                                return ret;
                        }
                        if ((yc < yoff) || (yc > (200 - yoff)))
                        {
                                puts("Y click not in image area");
                                fflush(stdout);
                                return ret;
                        }

                        xc = xc - xoff;
                        yc = yc - yoff;
                        idx = (width * yc * depth) + (xc * depth);
                        r = (unsigned char)datap[idx];
                        g = (unsigned char)datap[idx + 1];
                        b = (unsigned char)datap[idx + 2];

                        printf("Got a click at (%d, %d) R: %d G: %d B: %d\n", 
xc, yc, r, g, b);
                        fflush(stdout);
                        return(1);
                }
        }
        return(ret);
}

/************************************************************************/
img_box *box_1;
vw_box *box_2;
Fl_Box *box_3;

/************************************************************************/
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;
        }
        if (img->w() > box_1->w() || img->h() > box_1->h()) {
                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->redraw();
}


/************************************************************************/
void quit_cb(Fl_Button *, void *)
{
        exit (0);
}

/************************************************************************/
void process_cb(Fl_Button *, void *)
{
        unsigned long total = width * height * depth;
        char * data = new char [total];
        char * flip = new char [total];

        int idx;
        for (idx = 0; idx < total; idx ++)
        {
                data[idx] = (char)(255 - (unsigned char)datap[idx]);
                flip[total - 1 - idx] = (unsigned char)datap[idx];
        }

        box_2->set_data(data, width, height, depth);
        box_2->redraw();

        if (!img_3)
        {
                img_3 = new Fl_RGB_Image((const uchar *)flip, width, height, 
depth);
                box_3->image(img_3);
                box_3->redraw();
        }
}

/************************************************************************/
int main(int argc, char **argv)
{
        //fl_register_images();
        Fl::get_system_colors();

        main_win = new Fl_Double_Window(615, 300);
                 img_box b(0, 0, 200, 200);
        box_1 = &b;


                box_2 = new vw_box(205, 0, 200, 200);

                box_3 = new Fl_Box(410, 0, 200, 200);

                Fl_Button *quit = new Fl_Button(540, 260, 60, 30);
                quit->label("Quit");
                quit->callback((Fl_Callback *)quit_cb);
                Fl_Button *process = new Fl_Button(470, 260, 60, 30);
                process->label("Process");
                process->callback((Fl_Callback *)process_cb);

                main_win->end();

  /*   if (argv[1]) load_file(argv[1]);

        depth = img->d();
        count = img->count();
        datap = img->data()[0];
        width = img->w();
        height = img->h();

        if (height < b.h())
        {
                yoff = (b.h() - height) / 2;
        }
        if (width < b.w())
        {
                xoff == (b.w() - width) / 2;
        }

        printf("Depth: %d   Count: %d  W: %d H: %d\n", depth, count, width, 
height);
        printf("X offs %d Y offs %d\n", xoff, yoff);
        fflush(stdout);
*/

        main_win->show();
        return Fl::run();
}

/* End of File */




> Still same problem with limkage but i notice when i removed
> shared image library the errors are reduced
> from 175 to 23????
>
> Any help guys ???!!!
>
> > > Thankx i will try it
> >
> > =====================================================================
> > > > i want to click on the image to get to points
> > > > x and y but i can not do it or even start with
> > > > can i find anyone help me?
> > >
> > > For fltk-1.1.x, this HowTo shows how that can be done:
> > >
> > > http://www.fltk.org/articles.php?L468
> > >
> > >
> > > Look in particular at the img_box::handle() method where it extracts the
> > > mosue click from the underlying image.
> > >
> > >
> > >
> > >
> > > 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