COIN-OR::LEMON - Graph Library

Changeset 1225:4401e1aeafcf in lemon-0.x


Ignore:
Timestamp:
03/17/05 18:20:37 (19 years ago)
Author:
Hegyi Péter
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1645
Message:

Magic anyangle is Faster, harder, Blumchen

Location:
src/work/peter
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/work/peter/Makefile

    r1224 r1225  
    11triangle: canvas-test.cc
    22        g++ canvas-test.cc -W -Wall -ansi -pedantic -o triangle `pkg-config libgnomecanvasmm-2.6 --cflags --libs`
     3
     4run: triangle
     5        ./triangle 100 100 -100 100 0 -100
     6
     7.PHONY: run
  • src/work/peter/canvas-test.cc

    r1224 r1225  
    1919
    2020        ///Event handler function that handles dragging nodes of triangle
    21         bool event_handler(GdkEvent* e, bool b);
     21        bool event_handler(GdkEvent* e, int b);
    2222
    2323        ///Event handler function that handles dragging triangle
    24         bool tri_mover(GdkEvent* e, bool b);
     24        bool tri_mover(GdkEvent* e);
    2525
    2626        ///Coordinates of Weight Point of tirangle
     
    3939        int noe;
    4040
     41        ///Array of coordinates
     42        double * coordinates;
     43
    4144        ///At this location was the mousebutton pressed.
    4245        ///It helps to calculate the distance of dragging.
     
    5356
    5457///When we click on the weight point we can drag the whole triangle. This function resolves it.
    55 bool CanvasExample::tri_mover(GdkEvent* e, bool b)
    56 {
    57         b=b;
     58bool CanvasExample::tri_mover(GdkEvent* e)
     59{
    5860        switch(e->type)
    5961        {
     
    7274                                double dx=e->motion.x-clicked_x;
    7375                                double dy=e->motion.y-clicked_y;
     76
     77                                Gnome::Canvas::Points coos;
     78
    7479                                for(int i=0;i<=noe;i++)
    7580                                {
    7681                                        nodes[i]->move(dx,dy);
     82
     83                                        double x=(coordinates[2*i]+=dx);
     84                                        double y=(coordinates[2*i+1]+=dy);
     85
     86                                        if(i!=noe)coos.push_back(Gnome::Art::Point(x,y));
     87
    7788                                }
     89
    7890                                clicked_x=e->motion.x;
    7991                                clicked_y=e->motion.y;
    8092
    81                                 Gnome::Canvas::Points coos;
    82                                 for(int i=0;i<noe;i++)
    83                                 {
    84                                         double x1,y1,x2,y2;
    85                                         nodes[i]->get_bounds(x1,y1,x2,y2);
    86                                         double x=(x1+x2)/2;
    87                                         double y=(y1+y2)/2;
    88                                         coos.push_back(Gnome::Art::Point(x, y));
    89                                 }
    9093                                sides->property_points().set_value(coos);
    91 
    9294                        }
    9395                default: break;
     
    99101///but recalculate the location of wight point,
    100102///and also redraw the sides of the planefigure.
    101 bool CanvasExample::event_handler(GdkEvent* e, bool b)
    102 {
    103         b=b;
     103bool CanvasExample::event_handler(GdkEvent* e, int b)
     104{
    104105        switch(e->type)
    105106        {
     
    125126                                active_item->move(dx, dy);
    126127
     128                                coordinates[2*b]+=dx;
     129                                coordinates[2*b+1]+=dy;
     130
    127131                                Gnome::Canvas::Points coos;
    128132
     
    132136                                for(int i=0;i<noe;i++)
    133137                                {
    134                                         double x1,y1,x2,y2;
    135                                         nodes[i]->get_bounds(x1,y1,x2,y2);
    136                                         double x=(x1+x2)/2;
    137                                         double y=(y1+y2)/2;
    138                                         coos.push_back(Gnome::Art::Point(x, y));
    139 
    140                                         x_wp+=x;
    141                                         y_wp+=y;
     138                                        coos.push_back(Gnome::Art::Point(coordinates[2*i], coordinates[2*i+1]));
     139
     140                                        x_wp+=coordinates[2*i];
     141                                        y_wp+=coordinates[2*i+1];
    142142                                }
    143143
     
    147147                                y_wp/=noe;
    148148
    149                                 double x1,y1,x2,y2;
    150                                 nodes[noe]->get_bounds(x1,y1,x2,y2);
    151                                 double x=(x1+x2)/2;
    152                                 double y=(y1+y2)/2;
    153 
    154                                 dx=x_wp-x;
    155                                 dy=y_wp-y;
     149                                dx=x_wp-coordinates[noe*2];
     150                                dy=y_wp-coordinates[noe*2+1];
    156151                                nodes[noe]->move(dx, dy);
     152
     153                                coordinates[noe*2]+=dx;
     154                                coordinates[noe*2+1]+=dy;
    157155
    158156                                clicked_x=e->motion.x;
     
    168166        noe=numofcoos/2;
    169167
     168        coordinates=new double [numofcoos+2];
     169
    170170        double x_wp=0;
    171171        double y_wp=0;
     
    174174        for(int i=0;i<numofcoos;i++)
    175175        {
    176                 double x=coosarray[i++];
    177                 double y=coosarray[i];
    178                 coos.push_back(Gnome::Art::Point(x, y));
    179 
    180                 x_wp+=x;
    181                 y_wp+=y;
     176                coordinates[i]=coosarray[i++];
     177                coordinates[i]=coosarray[i];
     178                coos.push_back(Gnome::Art::Point(coordinates[i-1], coordinates[i]));
     179
     180                x_wp+=coordinates[i-1];
     181                y_wp+=coordinates[i];
    182182
    183183        }
     
    194194                *(nodes[i]) << Gnome::Canvas::Properties::fill_color("blue");
    195195                *(nodes[i]) << Gnome::Canvas::Properties::outline_color("black");
    196                 (nodes[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &CanvasExample::event_handler),true));
    197         }
    198 
    199         wp=new Gnome::Art::Point(x_wp/noe,y_wp/noe);
    200 
    201         nodes[noe]= new Gnome::Canvas::Ellipse(triangle, wp->get_x()-20, wp->get_y()-20, wp->get_x()+20, wp->get_y()+20);
     196                (nodes[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &CanvasExample::event_handler),i));
     197        }
     198
     199        coordinates[numofcoos]=x_wp/noe;
     200        coordinates[numofcoos+1]=y_wp/noe;
     201
     202        wp=new Gnome::Art::Point(coordinates[numofcoos],coordinates[numofcoos+1]);
     203
     204        nodes[noe]= new Gnome::Canvas::Ellipse
     205        (
     206                triangle,
     207                coordinates[numofcoos]-20,
     208                coordinates[numofcoos+1]-20,
     209                coordinates[numofcoos]+20,
     210                coordinates[numofcoos+1]+20
     211        );
    202212        *(nodes[noe]) << Gnome::Canvas::Properties::fill_color("blue");
    203213        *(nodes[noe]) << Gnome::Canvas::Properties::outline_color("black");
    204         (nodes[noe])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &CanvasExample::tri_mover),true));
     214        (nodes[noe])->signal_event().connect(sigc::mem_fun(*this, &CanvasExample::tri_mover));
     215
    205216
    206217
Note: See TracChangeset for help on using the changeset viewer.