"Fossies" - the Fresh Open Source Software Archive

Member "mapgenerator-1.1.2/src/image_scroll_box.cpp" (26 Oct 2003, 9328 Bytes) of package /linux/www/old/mapgenerator-1.1.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "image_scroll_box.cpp" see the Fossies "Dox" file reference documentation.

    1 /***************************************************************************
    2                           image_scroll_box.cpp  -  description
    3                              -------------------
    4     begin                : Tue Aug 14 2001
    5     copyright            : (C) 2001 by Gabriel Huber
    6     email                : Gabriel-Huber@gmx.de
    7  ***************************************************************************/
    8 
    9 /***************************************************************************
   10  *                                                                         *
   11  *   This program is free software; you can redistribute it and/or modify  *
   12  *   it under the terms of the GNU General Public License as published by  *
   13  *   the Free Software Foundation; either version 2 of the License, or     *
   14  *   (at your option) any later version.                                   *
   15  *                                                                         *
   16  ***************************************************************************/
   17 
   18 #include "image_scroll_box.h"
   19 #include <string>
   20 #include <math.h>
   21 
   22 Image_scroll_box::Image_scroll_box(int x,int y,int w,int h):Fl_Overlay_Window(x,y,w,h){
   23     Image_box=new Fl_Scroll(0,0,w,h);
   24     Image_box->box(FL_DOWN_BOX);
   25     Image_box->end();
   26     Image_grp=0;
   27     Image=0;
   28     objnum=0;
   29     html=0;
   30     MousePressed=false;
   31     this->resizable(Image_box);
   32     Selector=false;
   33     Circle=false;
   34     Square=false;
   35     Polygon=false;
   36     editPolygon=false;
   37     selected=-1;
   38     eventhandling=true;
   39     moveobj=false;
   40     resizeobj=false;
   41     moveitemobj=false;
   42 }
   43 
   44 Image_scroll_box::~Image_scroll_box(){
   45     for(int i=0;i<objnum;i++)
   46         delete obj[i];
   47     if(html!=0) delete html;
   48 }
   49 
   50 void Image_scroll_box::draw_overlay(){
   51     this->edit();
   52     for(int i=0;i<objnum;i++){
   53     obj[i]->draw(Image_box->xposition(),Image_box->yposition());
   54     }
   55     fl_line_style(FL_SOLID);
   56     fl_color(FL_GRAY);
   57 }
   58 
   59 void Image_scroll_box::redraw_overlay(){
   60     this->Fl_Overlay_Window::redraw_overlay();
   61 }
   62 
   63 void Image_scroll_box::show(){
   64     this->Fl_Overlay_Window::show();
   65 }
   66 
   67 bool Image_scroll_box::open(){
   68     if(html!=0) delete html;
   69     html=new htmlfile();
   70     if(html->open(width,height)==false) return false;
   71     if(width<0) width=html->width();
   72     if(height<0) height=html->height();
   73     imgfb=html->framebuffer()->resize(width,height);
   74     Fl::visual(FL_RGB);
   75     if(Image_grp!=0){
   76         Image_grp->remove((Fl_Widget*)Image);
   77         delete Image;
   78         Image_box->remove(Image_grp);
   79         delete Image_grp;
   80     }
   81     Image_box->begin();
   82     Image=new Fl_RGB_Image(imgfb->buffer(),width,height,imgfb->components());
   83     Image_grp=new Fl_Group(0,0,width,height);
   84     Image_grp->align(FL_ALIGN_INSIDE);
   85     Image->label(Image_grp);
   86     Image_box->end();
   87     if(html->getmap(oth_atr)){
   88         int object;
   89         std::string url;
   90         std::string alt;
   91         std::string oth;
   92         while(html->getobj(object,url,alt,oth)){
   93             if(object==objCircle){
   94                 int x,y,r;
   95                 html->get_coords(x,y);
   96                 html->get_coords(r);
   97                 obj.push_back(0);
   98                 obj[objnum]=new oCircle(x,y,r,alt,oth);
   99                 selected=objnum;
  100                 objnum++;
  101             }
  102             if(object==objSquare){
  103                 int x1,y1,x2,y2;
  104                 html->get_coords(x1,y1);
  105                 html->get_coords(x2,y2);
  106                 obj.push_back(0);
  107                 obj[objnum]=new oSquare(x1,y1,x2-x1,y2-y1,alt,oth);
  108                 selected=objnum;
  109                 objnum++;
  110             }
  111             if(object==objPolygon){
  112                 int x,y;
  113                 html->get_coords(x,y);
  114                 obj.push_back(0);
  115                 obj[objnum]=new oPolygon(x,y,alt,oth);
  116                 selected=objnum;
  117                 objnum++;
  118                 while(html->get_coords(x,y)){
  119                     obj[objnum-1]->add_size(x,y);
  120                 }
  121                 obj[objnum-1]->add_size(-1,0);
  122             }
  123             obj[objnum-1]->setURL(url);
  124         }
  125     }
  126     html->close_map();
  127     this->show();
  128     this->redraw();
  129     this->redraw_overlay();
  130     return true;
  131 }
  132 
  133 void Image_scroll_box::tool(int selected){
  134     if(MousePressed){
  135         obj[objnum-1]->editURL();
  136         MousePressed=false;
  137     }
  138     if(editPolygon){
  139         obj[objnum-1]->add_size(-1,0);
  140         this->redraw_overlay();
  141         editPolygon=false;
  142         obj[objnum-1]->editURL();
  143     }
  144     Circle=false;
  145     Square=false;
  146     Polygon=false;
  147     Selector=false;
  148     if(selected==objCircle) Circle=true;
  149     if(selected==objSquare) Square=true;
  150     if(selected==objPolygon) Polygon=true;
  151     if(selected==objSelector) Selector=true;
  152 }
  153     
  154 int Image_scroll_box::handle(int event){
  155     if (int q=Fl_Overlay_Window::handle(event)) return q;
  156     if(eventhandling==false) return 1;
  157     switch(event){
  158         case FL_DRAG:
  159             if(Image_grp==0) break;
  160             if(moveobj){
  161                 obj[selected]->move(Fl::event_x()+Image_box->xposition(),
  162                     Fl::event_y()+Image_box->yposition());
  163                 this->redraw_overlay();
  164                 break;
  165             }
  166             if(resizeobj){
  167                 obj[selected]->resize(Fl::event_x()+Image_box->xposition(),
  168                     Fl::event_y()+Image_box->yposition());
  169                 this->redraw_overlay();
  170                 break;
  171             }
  172             if(moveitemobj){
  173                 obj[selected]->moveitem(Fl::event_x()+Image_box->xposition(),
  174                     Fl::event_y()+Image_box->yposition());
  175                 this->redraw_overlay();
  176                 break;
  177             }
  178             if(Circle){
  179                 if(MousePressed==false){
  180                     obj.push_back(0);
  181                     obj[objnum]=new oCircle(Fl::event_x()+Image_box->xposition(),
  182                         Fl::event_y()+Image_box->yposition(),1);
  183                     selected=objnum;
  184                     objnum++;
  185                     MousePressed=true;
  186                     this->redraw_overlay();
  187                     break;
  188                 }
  189                 else{
  190                     obj[objnum-1]->add_size(Fl::event_x()+Image_box->xposition(),
  191                         Fl::event_y()+Image_box->yposition());
  192                     this->redraw_overlay();
  193                     break;
  194                 }
  195                 break;
  196             }
  197             if(Square){
  198                 if(MousePressed==false){
  199                     obj.push_back(0);
  200                     obj[objnum]=new oSquare(Fl::event_x()+Image_box->xposition(),
  201                         Fl::event_y()+Image_box->yposition(),1,1);
  202                     selected=objnum;
  203                     objnum++;
  204                     MousePressed=true;
  205                     this->redraw_overlay();
  206                     break;
  207                 }
  208                 else{
  209                     obj[objnum-1]->add_size(Fl::event_x()+Image_box->xposition(),
  210                         Fl::event_y()+Image_box->yposition());
  211                     this->redraw_overlay();
  212                     break;
  213                 }
  214                 break;
  215             }
  216         break;
  217         case FL_RELEASE:
  218             if(Image_grp==0) break;
  219             if(MousePressed){
  220                 obj[objnum-1]->editURL();
  221                 MousePressed=false;
  222                 break;
  223             }
  224             moveobj=false;
  225             resizeobj=false;
  226             moveitemobj=false;
  227         break;
  228         case FL_PUSH:
  229             if(Image_grp==0 || moveobj || resizeobj || moveitemobj) break;
  230             if(Selector){
  231                 for(selected=0;selected<objnum;selected++){
  232                     select_num=obj[selected]->select(Fl::event_x()+Image_box->xposition(),
  233                         Fl::event_y()+Image_box->yposition());
  234                     if(select_num!=0)
  235                         break;
  236                 }
  237                 if(selected==objnum) selected=-1;
  238                 this->redraw_overlay();
  239                 if(FL_RIGHT_MOUSE==Fl::event_button()){
  240                     if(selected==-1) break;
  241                     eventhandling=false;
  242                     make_menu();
  243                     eventhandling=true;
  244                     break;
  245                 }
  246                 break;
  247             }
  248             if(Polygon){
  249                 if(FL_RIGHT_MOUSE==Fl::event_button()){
  250                     if(editPolygon){
  251                         obj[objnum-1]->add_size(-1,0);
  252                         this->redraw_overlay();
  253                         editPolygon=false;
  254                         obj[objnum-1]->editURL();
  255                         break;
  256                     }
  257                     break;
  258                 }
  259                 if(editPolygon==false){
  260                     obj.push_back(0);
  261                     obj[objnum]=new oPolygon(Fl::event_x()+Image_box->xposition(),
  262                         Fl::event_y()+Image_box->yposition());
  263                     selected=objnum;
  264                     objnum++;
  265                     this->redraw_overlay();
  266                     editPolygon=true;
  267                     break;
  268                 }
  269                 else{
  270                     obj[objnum-1]->add_size(Fl::event_x()+Image_box->xposition(),
  271                         Fl::event_y()+Image_box->yposition());
  272                     this->redraw_overlay();
  273                     break;
  274                 }
  275                 break;
  276             }
  277         break;
  278         case FL_KEYBOARD:
  279             if(Fl::event_key()==65361){
  280                 selected--;
  281                 if(selected==-1) selected=objnum-1;
  282                 this->redraw_overlay();
  283             }
  284             if(Fl::event_key()==65363){
  285                 selected++;
  286                 if(selected==objnum) selected=0;
  287                 this->redraw_overlay();
  288             }
  289             if(Fl::event_key()==65535){
  290                 obj[selected]=obj[objnum-1];
  291                 obj.pop_back();
  292                 objnum--;
  293                 this->redraw_overlay();
  294             }
  295             break;
  296     }
  297     return 1;
  298 }
  299 
  300 void Image_scroll_box::del(){
  301     for(int i=0;i<objnum;i++)
  302         delete obj[i];
  303     if(Image_grp!=0){
  304         Image_box->remove(Image_grp);
  305         delete Image_grp;
  306     }
  307     Image_grp=0;
  308     if(Image!=0) delete Image;
  309     Image=0;
  310     objnum=0;
  311     MousePressed=false;
  312     Selector=false;
  313     Circle=false;
  314     Square=false;
  315     Polygon=false;
  316     editPolygon=false;
  317     if(html!=0) delete html;
  318     html=0;
  319     this->show();
  320     this->redraw();
  321 }
  322 
  323 void Image_scroll_box::edit(){
  324     for(int i=0;i<objnum;i++)
  325         obj[i]->edit(false);
  326     if(selected>=objnum)
  327         selected=-1;
  328     if(selected>=0)
  329         obj[selected]->edit(true);
  330 }
  331 
  332 void Image_scroll_box::save(){
  333     if(objnum<1) return;
  334     html->save(oth_atr,false);
  335     for(int i=0;i<objnum;i++)
  336         obj[i]->save(html);
  337     html->close_save();
  338 }
  339 
  340     
  341 void Image_scroll_box::make_menu(){
  342     this->begin();
  343     menu=new Fl_Menu_Button(Fl::event_x(),Fl::event_y(),0,0);
  344     Fl_Menu_Item items[]={
  345         {"do nothing"},
  346         {"edit URL"},
  347         {"delete"},
  348         {"move"},
  349         {"resize"},
  350         {0}
  351     };
  352     menu->menu(items);
  353     if(obj[selected]->type()==objPolygon){
  354         menu->add("move item");
  355         menu->add("add item");
  356         menu->add("del item");
  357         menu->remove(4);
  358     }
  359     menu->popup();
  360     this->end();
  361     this->show();
  362     this->redraw();
  363     if(menu->value()==1) obj[selected]->editURL();
  364     if(menu->value()==2){
  365         obj[selected]=obj[objnum-1];
  366         obj.pop_back();
  367         objnum--;
  368     }
  369     if(menu->value()==3) moveobj=true;
  370     if(menu->value()==4 && obj[selected]->type()!=objPolygon) resizeobj=true;
  371     if(menu->value()==4 && obj[selected]->type()==objPolygon) moveitemobj=true;
  372     if(menu->value()==5) obj[selected]->add_item();
  373     if(menu->value()==6){
  374         if(obj[selected]->del_item()){
  375             obj[selected]=obj[objnum-1];
  376             obj.pop_back();
  377             objnum--;
  378         }
  379     }
  380     this->remove(menu);
  381     delete menu;
  382     this->show();
  383     this->redraw();
  384 }