"Fossies" - the Fresh Open Source Software Archive

Member "mapgenerator-1.1.2/src/opolygon.cpp" (26 Oct 2003, 4810 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 "opolygon.cpp" see the Fossies "Dox" file reference documentation.

    1 /***************************************************************************
    2                           opolygon.cpp  -  description
    3                              -------------------
    4     begin                : Mon Aug 13 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 "opolygon.h"
   19 
   20 oPolygon::oPolygon(int x,int y,const std::string & alt, const std::string &oth):Objects(alt,oth){
   21     startx=x;
   22     starty=y;
   23     objnum=0;
   24     end=false;
   25 }
   26 
   27 oPolygon::~oPolygon(){
   28 }
   29 
   30 void oPolygon::draw(int xpos,int ypos){
   31     Objects::draw();
   32     if(selectedobj==-1){
   33         fl_line_style(FL_SOLID);
   34         fl_color(FL_BLACK);
   35         fl_circle(startx-xpos,starty-ypos,3);
   36         fl_circle(startx-xpos,starty-ypos,1);
   37         fl_color(FL_WHITE);
   38         fl_circle(startx-xpos,starty-ypos,2);
   39         fl_color(black_line);
   40         fl_line_style(FL_DASH);
   41     }
   42     else{
   43         fl_circle(startx-xpos,starty-ypos,2);
   44         fl_color(white_line);
   45         fl_circle(startx-xpos,starty-ypos,1);
   46         fl_color(black_line);
   47     }
   48     for(int i=0;i<objnum;i++){
   49         if(i==0){
   50             fl_line(startx-xpos,starty-ypos,px[i]-xpos,py[i]-ypos);
   51             fl_color(white_line);
   52             fl_line(startx-xpos-1,starty-ypos-1,px[i]-xpos-1,py[i]-ypos-1);
   53             fl_color(black_line);
   54         }
   55         else{
   56             fl_line(px[i-1]-xpos,py[i-1]-ypos,px[i]-xpos,py[i]-ypos);
   57             fl_color(white_line);
   58             fl_line(px[i-1]-xpos-1,py[i-1]-ypos-1,px[i]-xpos-1,py[i]-ypos-1);
   59             fl_color(black_line);
   60         }
   61         if(i==selectedobj){
   62             fl_line_style(FL_SOLID);
   63             fl_color(FL_BLACK);
   64             fl_circle(px[i]-xpos,py[i]-ypos,3);
   65             fl_circle(px[i]-xpos,py[i]-ypos,1);
   66             fl_color(FL_WHITE);
   67             fl_circle(px[i]-xpos,py[i]-ypos,2);
   68             fl_color(black_line);
   69             fl_line_style(FL_DASH);
   70         }
   71         else{           
   72             fl_circle(px[i]-xpos,py[i]-ypos,2);
   73             fl_color(white_line);
   74             fl_circle(px[i]-xpos,py[i]-ypos,1);
   75             fl_color(black_line);
   76         }
   77     }
   78     if(end){
   79         if(objnum==0);
   80         else{
   81             fl_line(px[objnum-1]-xpos,py[objnum-1]-ypos,startx-xpos,starty-ypos);
   82             fl_color(white_line);
   83             fl_line(px[objnum-1]-xpos-1,py[objnum-1]-ypos-1,startx-xpos-1,
   84                 starty-ypos-1);
   85             fl_color(black_line);
   86         }
   87     }
   88 }
   89 
   90 void oPolygon::add_size(int x,int y){
   91     if(x==-1){ end=true; return;}
   92     px.push_back(x);
   93     py.push_back(y);
   94     objnum++;
   95 }
   96 
   97 int oPolygon::select(int x,int y){
   98     int vx=abs(startx-x);
   99     int vy=abs(starty-y);
  100     int vlen=(int)abs((int)(sqrt(pow(vx,2)+pow(vy,2))));
  101     if(vlen<=3){
  102         selectedobj=-1;
  103         return 1;
  104     }
  105     for(int i=0;i<objnum;i++){
  106         vx=abs(px[i]-x);
  107         vy=abs(py[i]-y);
  108         vlen=(int)abs((int)(sqrt(pow(vx,2)+pow(vy,2))));
  109         if(vlen<=3){
  110             selectedobj=i;
  111             return 1;
  112         }
  113     }
  114     return 0;
  115 }
  116 
  117 void oPolygon::save(htmlfile *html){
  118     html->sav_polygon(URL,startx,starty);
  119     for(int i=0;i<objnum;i++)
  120         html->sav_addpoly(px[i],py[i]);
  121     html->close_polygon(alt_text,oth_atr);
  122 }
  123 
  124 void oPolygon::move(int x,int y){
  125     int mx,my;
  126     if(selectedobj==-1){
  127         mx=x-startx;
  128         my=y-starty;
  129     }
  130     else{
  131         mx=x-px[selectedobj];
  132         my=y-py[selectedobj];
  133     }
  134     for(int i=0;i<objnum;i++){
  135         px[i]=px[i]+mx;
  136         py[i]=py[i]+my;
  137     }
  138     startx+=mx;
  139     starty+=my;
  140 }
  141 
  142 void oPolygon::add_item(){
  143     int x,y;
  144     int choice=fl_choice("Where do you want to enter the new item?","cancel","before","behind");
  145     if(choice==1){  
  146     if(selectedobj==-1) selectedobj=objnum-1;
  147         else selectedobj--;
  148         choice=2;
  149     }
  150     if(choice==2){
  151         if(selectedobj==-1){
  152             x=(startx+px[0])/2;
  153             y=(starty+py[0])/2;
  154         }
  155         else{
  156         if(selectedobj==objnum-1){
  157             x=(startx+px[objnum-1])/2;
  158             y=(starty+py[objnum-1])/2;
  159         }
  160         else{
  161             x=(px[selectedobj]+px[selectedobj+1])/2;
  162             y=(py[selectedobj]+py[selectedobj+1])/2;
  163         }}
  164         px.push_back(0);
  165         py.push_back(0);
  166         objnum++;
  167         for(int i=objnum-1;i>selectedobj+1;i--){
  168             px[i]=px[i-1];
  169             py[i]=py[i-1];
  170         }
  171         px[selectedobj+1]=x;
  172         py[selectedobj+1]=y;
  173     }
  174 }
  175 
  176 bool oPolygon::del_item(){
  177     if(selectedobj==-1){
  178         startx=px[0];
  179         starty=py[0];
  180         selectedobj++;
  181     }
  182     for(int i=selectedobj;i<objnum-1;i++){
  183         px[i]=px[i+1];
  184         py[i]=py[i+1];
  185     }
  186     px.pop_back();
  187     py.pop_back();
  188     objnum--;
  189     selectedobj=-1;
  190     if(objnum==-1) return true;
  191     return false;
  192 }
  193 
  194 void oPolygon::moveitem(int x,int y){
  195     if(selectedobj==-1){
  196         startx=x;
  197         starty=y;
  198     }
  199     else{
  200         px[selectedobj]=x;
  201         py[selectedobj]=y;
  202     }
  203 }