2
* Copyright (C) 1999, 2008 Philippe Banwarth
3
* email: bwt@altern.org
4
* smail: Philippe Banwarth, 8 sente du milieu des Gaudins, 95150 Taverny, France.
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 3 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, see <http://www.gnu.org/licenses/>.
20
#include "gcompris/gcompris.h"
22
#include <glib/gstdio.h>
25
/* Added by Florian Ernst <florian_ernst@gmx.net> for lines 193 and 194 */
27
/* End of added section */
30
#include "gtans_interface.h"
31
#include "gtans_support.h"
33
void taninitstart(void);
37
static void start_board (GcomprisBoard *agcomprisBoard);
38
static void pause_board (gboolean pause);
39
static void end_board (void);
40
static gboolean is_our_board (GcomprisBoard *gcomprisBoard);
42
static gint actual_figure = -2;
44
/* Description of this plugin */
47
static BoardPlugin menu_bp =
53
"Bruno Coudoin <bruno.coudoin@free.fr>",
71
GET_BPLUGIN_INFO(gtans)
73
static GcomprisBoard *gcomprisBoard = NULL;
75
static GooCanvasItem *boardRootItem = NULL;
77
static gboolean board_paused = FALSE;
79
static void start_board (GcomprisBoard *agcomprisBoard)
82
if(agcomprisBoard!=NULL)
84
gcomprisBoard=agcomprisBoard;
86
gcomprisBoard->level = 1;
87
gcomprisBoard->maxlevel = 1;
90
gc_set_background(goo_canvas_get_root_item(gcomprisBoard->canvas),
91
"tangram/gtans_bg.svgz");
93
selectedgrande = FALSE;
98
static void end_board (void)
100
goo_canvas_item_remove(boardRootItem);
101
boardRootItem = NULL;
116
selectedgrande = FALSE;
120
is_our_board (GcomprisBoard *gcomprisBoard)
124
if(g_strcasecmp(gcomprisBoard->type, "tangram")==0)
126
/* Set the plugin entry */
127
gcomprisBoard->plugin=&menu_bp;
135
static void pause_board (gboolean pause)
138
if(gcomprisBoard==NULL)
141
board_paused = pause;
143
if ((!pause) && figpetite.reussi) {
144
gtk_widget_show(widgetgrande);
145
gtk_widget_show(widgetpetite);
148
tansetnewfigurepart1(actual_figure);
149
tansetnewfigurepart2();
152
gtk_widget_hide(widgetgrande);
153
gtk_widget_hide(widgetpetite);
156
gtk_widget_show(widgetgrande);
157
gtk_widget_show(widgetpetite);
163
void change_figure(gboolean next){
165
tansetnewfigurepart1((actual_figure+1)%figtabsize);
167
tansetnewfigurepart1((actual_figure + figtabsize -1)%figtabsize);
168
tansetnewfigurepart2();
173
/********************************/
174
GtkWidget *mainwindow;
175
GtkWidget *widgetgrande; /* widget de la grande drawarea */
176
GtkWidget *widgetpetite; /* widget de la petite drawarea */
177
GtkStatusbar *widgetstat; /* widget de la statusbar */
178
GtkSpinButton *spinner=NULL;
180
gint statconid; /* context id de la statusbar */
181
GdkRectangle selbackrect; /* rectangle a redessiner pour effacer la piece selected */
183
GdkPixmap *pixmapgrande1=NULL,*pixmapgrande2;
184
GdkPixmap *pixmappetite=NULL;
185
GdkPixmap *pixmappiece1=NULL,*pixmappiece2=NULL,*pixmapfond=NULL;
187
GtkWidget *colselwin=NULL,*filselwin=NULL;
190
/* les polygones doivent etre clockwise */
191
tanpiecedef piecesdef[]={
192
{2.0/3,2.0/3, 4,{{1,0,6*HT},{1,0,0},{0,1,2*HT},{0,1,0}}, 3,{{0,0},{2,0},{0,2},{0,0}}},
193
{CL/3,CL/3, 2,{{CC,CC,5*HT},{CC,CC,3*HT},{0,0,0},{0,0,0}}, 3,{{0,0},{CL,0},{0,CL},{0,0}}},
194
{0.5,0.5, 2,{{0,0,0},{1,1,4*HT},{0,0,0},{0,0,0}}, 4,{{0,0},{1,0},{1,1},{0,1}}},
195
{CC/2,(CC+CL)/2,2,{{0,CC,1*HT},{CC,CL,5*HT},{0,0,0},{0,0,0}},4,{{0,CC},{CC,0},{CC,CL},{0,CC+CL}}},
196
{1.0/3,1.0/3, 1,{{0,0,0},{0,0,0},{0,0,0},{0,0,0}}, 3,{{0,0},{1,0},{0,1},{0,0}}}
199
tanfigure figuredebut={
200
0.125,1,TOUR/64,FALSE,
210
tanfigure *figtab=NULL;
211
int figtabsize; /* ==0 : pas de figure */
212
char *figfilename=NULL;
213
int figactualnr; /* nr de la figure dans le figtab (-1=figuredebut, -2=figpetite) */
215
tantinytri tinytabpe[TINYNBR],tinytabgr[TINYNBR];
216
tanfigure figgrande,figpetite;
217
int selectedgrande=FALSE;
218
int xact,yact,xoth,yoth,xold,yold;
219
int actiongrande=AN_none;
220
int selpossible=TRUE;
221
int rotact,rotnew,rotold;
223
int rotstepnbr=TOUR/32; /* nb. de pas de rotation affiches */
224
int initcbgr=FALSE,initcbpe=FALSE; /* init cb deja appellee ? */
230
GdkColor colortab[GCNBR];
231
GdkPixmap *dumtabpxpx[3],**tabpxpx=dumtabpxpx-PXSTART;
232
char *dumtabpxnam[3],**tabpxnam=dumtabpxnam-PXSTART;
234
gboolean helpoutset=FALSE;
235
gboolean helptanset=PIECENBR;
236
int accuracy; /* precision de reconaissance */
240
#define FLPNTMAX PIECENBR*(PNTNBRMAX+1)*2
241
static gboolean dumtabpxpixmode[3],*tabpxpixmode=dumtabpxpixmode-PXSTART; /* mode VOULU */
242
static gboolean tabcolalloc[GCNBR]; /* couleur allouee ? */
243
static gchar *userconf=NULL; /* nom complet du fichier de config local */
244
static tanflfig flfigpetite;
245
static tanfpnt fpntspetite[FLPNTMAX];
247
static double dxout,dyout,dxpetite,dypetite;
249
static double selposxnc,selposync; /* position de la piece actuelle non limitee */
252
/********************************/
253
/* change la valeur max du spinbutton (si il existe) */
254
void tanspinsetvalmax (int val){
258
adj = gtk_spin_button_get_adjustment(spinner);
259
adj->upper = (gfloat)val;
260
gtk_adjustment_changed(adj);
261
if (gtk_spin_button_get_value_as_int(spinner)){
262
gtk_spin_button_set_value(spinner, 0);
265
tansetnewfigurepart1(0);
266
tansetnewfigurepart2();
270
tansetnewfigurepart1(0);
271
tansetnewfigurepart2();
277
/********************************/
278
void tanallocname (char **pnt, char *name){
282
*pnt=(char *)g_malloc(strlen(name)+1);
289
/********************************/
290
/* maintien les pieces dans les limites */
291
void tanclampgrandefig (void){
293
tanpiecepos *piecepos;
297
dumzoom = 1.0/figgrande.zoom;
298
piecepos = figgrande.piecepos;
299
for (i = 0; i<PIECENBR; i++){
300
piecepos->posx = CLAMP(piecepos->posx, 0.0, dumzoom);
301
piecepos->posy = CLAMP(piecepos->posy, 0.0, dumzoom);
309
/********************************/
310
/* renvoi la direction d'un segment */
311
int tanangle (double dx, double dy){
314
ret = (int)(atan2(dy,dx)/PASTOUR);
315
ret = (ret+TOUR)%TOUR;
322
/********************************/
323
gboolean tantinytabcompare (tantinytri *tinys1, tantinytri *tinys2, int accuracy){
325
gboolean libre[TINYNBR];
327
double dist,mindist,mindistmax,xi,yi;
328
int drot,drotmax,roti;
334
drotmax = (int)(TOUR/64)+1;
338
drotmax = (int)(TOUR/32)+1;
342
drotmax = (int)(TOUR/64)+1;
345
/* drotmax=figpetite.drotmax; */
346
mindistmax=pow(figpetite.distmax*0.10*flaccur,2);
348
for (i=0; i<TINYNBR; i++)
351
for (i=0; i<TINYNBR; i++){
358
for (j=0; j<TINYNBR; j++){
360
dist=pow(xi-tinys2[j].posx,2)+pow(yi-tinys2[j].posy,2);
361
drot=ABS(roti-tinys2[j].rot);
364
if ( dist<mindist && drot<drotmax ){
371
if ( mindist>mindistmax )
380
/********************************/
381
void tansmall2tiny (tansmalltri *small, tantinytri *tiny1, tantinytri *tiny2){
383
double cosrot,sinrot;
387
cosrot=cos(rot*PASTOUR);
388
sinrot=sin(rot*PASTOUR);
390
tiny1->rot=(rot+HT*3)%TOUR;
391
tiny1->posx=small->posx+0.5*cosrot +0.16666666*sinrot;
392
tiny1->posy=small->posy+0.16666666*cosrot-0.5*sinrot;
394
tiny2->rot=(rot+HT*5)%TOUR;
395
tiny2->posx=small->posx+0.16666666*cosrot+0.5*sinrot;
396
tiny2->posy=small->posy+0.5*cosrot -0.16666666*sinrot;
401
/********************************/
402
void tanmaketinytabnotr (tanfigure *figure, tantinytri *tinys){
405
tansmalltri dusmall,*small=&dusmall;
406
tanpiecepos *piecepos;
407
tanpiecedef *piecedat;
408
double ly,lx2,cosrot,sinrot;
411
piecepos=figure->piecepos;
413
for (j=0; j<PIECENBR; j++){
415
piecedat=&piecesdef[piecepos->type];
417
cosrot=cos(rot*PASTOUR);
418
sinrot=sin(rot*PASTOUR);
420
for (i=0; i<piecedat->trinbr; i++){
421
lx2=piecedat->tri[i].posx-piecedat->handlex;
422
ly=piecedat->tri[i].posy-piecedat->handley;
423
rottri=piecedat->tri[i].rot;
425
if (piecepos->flipped){
427
rottri=TOUR+6*HT-rottri;
430
small->posx=piecepos->posx+lx2*cosrot+ly*sinrot;
431
small->posy=piecepos->posy+ly*cosrot-lx2*sinrot;
432
small->rot=(rottri+rot)%TOUR;
433
tansmall2tiny(small,tinys,tinys+1);
442
/********************************/
443
void tantranstinytab (tantinytri *tinys){
446
double moyx=0,moyy=0;
448
for (i=0; i<TINYNBR; i++){
457
for (i=0; i<TINYNBR; i++){
458
(--tinys)->posx-=moyx;
465
/********************************/
466
/* termine la rotation (lorsque le mouse button est relache) */
467
/* est appele par redrawgrande et on_buttonpress au cas ou le signal a ete masque par*/
468
/* l'appui sur un bouton */
469
void tanreleaseifrot (void){
470
if (actiongrande==AN_rot){
471
gdk_draw_line (widgetgrande->window,
473
xact,yact,invx2,invy2);
475
figgrande.piecepos[PIECENBR-1].rot=(rotnew+TOUR*5)%TOUR;
478
actiongrande = AN_none;
484
/********************************/
485
/* calcule une serie de GdkPoint correspondant au polygone de la piece */
486
/* + un point correspondand au centre de la piece */
487
int tanplacepiece (tanpiecepos *piecepos, GdkPoint *pnts, double zoom){
490
tanpiecedef *piecedat;
491
double lx,ly,lx2,cosrot,sinrot;
494
piecedat=&piecesdef[piecepos->type];
496
cosrot=cos(rot*PASTOUR);
497
sinrot=sin(rot*PASTOUR);
499
for(i=0; i<piecedat->pntnbr; i++){
500
lx2=piecedat->pnt[i].posx-piecedat->handlex;
501
ly=piecedat->pnt[i].posy-piecedat->handley;
502
if (piecepos->flipped)
504
lx=(piecepos->posx+lx2*cosrot+ly*sinrot)*zoom;
505
ly=(piecepos->posy+ly*cosrot-lx2*sinrot)*zoom;
506
pnts->x=(gint16)(lx+ARON);
507
pnts->y=(gint16)(ly+ARON);
511
pnts->x=(gint16)(piecepos->posx*zoom+ARON);
512
pnts->y=(gint16)(piecepos->posy*zoom+ARON);
514
return(piecedat->pntnbr);
519
/********************************/
520
/* calcule une serie de point en flottant correspondant au polygone de la piece */
521
/* pas de point central */
522
/* copie le premier points derriere le dernier */
523
/* le polygone retourne est clockwise (si la def l'est) */
524
int tanplacepiecefloat (tanpiecepos *piecepos, tanfpnt *fpnts, double zoom){
527
tanpiecedef *piecedat;
528
double lx,ly,lx2,cosrot,sinrot;
532
piecedat=&piecesdef[piecepos->type];
533
nbr=piecedat->pntnbr;
535
cosrot=cos(rot*PASTOUR);
536
sinrot=sin(rot*PASTOUR);
538
for(i=0; i<nbr; i++){
539
lx2=piecedat->pnt[i].posx-piecedat->handlex;
540
ly=piecedat->pnt[i].posy-piecedat->handley;
541
if (piecepos->flipped)
543
lx=(piecepos->posx+lx2*cosrot+ly*sinrot)*zoom;
544
ly=(piecepos->posy+ly*cosrot-lx2*sinrot)*zoom;
550
if (piecepos->flipped){
552
for (i = 0; i<nbr/2 ;i++){
554
fpnts[i] = fpnts[nbr-i-1];
555
fpnts[nbr-i-1] = dumfpnt;
566
/********************************/
567
/* calcule le carre de la distance et le deplacement entre un point et un segment */
568
/* renvoie 100000.0 si la projection sur la droite du point n'est pas sur le segment */
569
/* resultat : vecteur du segment au point */
570
double tandistcarsegpnt (tanfpnt *segment, tanfpnt *point, double *pdx, double *pdy){
573
double seglencar,scal,dum;
575
segdx=segment[1].posx-segment[0].posx;
576
segdy=segment[1].posy-segment[0].posy;
577
*pdx=point->posx-segment->posx;
578
*pdy=point->posy-segment->posy;
580
seglencar=segdx*segdx+segdy*segdy;
581
if ( (scal=(*pdx*segdx)+(*pdy*segdy))<0 || (dum=scal/seglencar)>1 )
587
return (*pdx*(*pdx)+*pdy*(*pdy));
592
/********************************/
593
double tandistcar (tanfpnt *pnt1, tanfpnt *pnt2){
597
dx=(pnt1->posx-pnt2->posx);
598
dy=(pnt1->posy-pnt2->posy);
599
return (dx*dx+dy*dy);
604
/********************************/
605
void tancolle (tanfigure *figure, double seuil){
607
tanpiecepos *piecepos;
608
tanfpnt pnts1[PNTNBRMAX+1],pnts2[PNTNBRMAX+1];
612
double dx,dy,dx2,dy2,dxtot,dytot;
615
piecepos=figure->piecepos;
617
for (i=0; i<PIECENBR-1; i++){
618
for (j=i+1; j<PIECENBR; j++) {
619
pntnbr1=tanplacepiecefloat(&piecepos[i],pnts1,1);
620
pntnbr2=tanplacepiecefloat(&piecepos[j],pnts2,1);
623
for (k=0; k<pntnbr1; k++){
624
for (l=0; l<pntnbr2; l++){
625
dx=pnts1[k+1].posx-pnts2[l].posx;
626
dy=pnts1[k+1].posy-pnts2[l].posy;
627
dx2=pnts1[k].posx-pnts2[l+1].posx;
628
dy2=pnts1[k].posy-pnts2[l+1].posy;
629
if ( (dx*dx+dy*dy)>seuil && (dx2*dx2+dy2*dy2)>seuil ){
630
if ( tandistcarsegpnt(&pnts1[k],&pnts2[l],&dx,&dy)<seuil/4 ){
635
if ( tandistcarsegpnt(&pnts2[l],&pnts1[k],&dx,&dy)<seuil/4 ){
644
piecepos[j].posx+=dxtot/nbrcommun;
645
piecepos[j].posy+=dytot/nbrcommun;
648
pntnbr2=tanplacepiecefloat(&piecepos[j],pnts2,1);
651
for (k=0; k<pntnbr1; k++){
652
for (l=0; l<pntnbr2; l++){
653
dx=(pnts1[k].posx-pnts2[l].posx);
654
dy=(pnts1[k].posy-pnts2[l].posy);
655
if ( (dx*dx+dy*dy)<seuil ){
661
dx=(pnts1[(k+1)*2]-pnts2[l*2]);
662
dy=(pnts1[(k+1)*2+1]-pnts2[l*2+1]);
663
dx2=(pnts1[k*2]-pnts2[(l+1)*2]);
664
dy2=(pnts1[k*2+1]-pnts2[(l+1)*2+1]);
665
if ( (dx*dx+dy*dy)>seuil && (dx2*dx2+dy2*dy2)>seuil ){
666
if ( tandistcarsegpnt(pnts1+k*2,pnts2+l*2,&dx,&dy)<seuil/100 ){
671
if ( tandistcarsegpnt(pnts2+l*2,pnts1+k*2,&dx,&dy)<seuil/100 ){
682
piecepos[j].posx+=dxtot/nbrcommun;
683
piecepos[j].posy+=dytot/nbrcommun;
690
/********************************/
691
GdkRectangle tandrawpiece (GtkWidget *widget,GdkPixmap *pixmap,
692
tanpiecepos *piecepos,
693
double zoom, tanremplis remplis){
695
GdkPoint pnt[PNTNBRMAX+1];
696
int i,pntnbr,ix,iy,ixmax=-20000,ixmin=20000,iymax=-20000,iymin=20000;
697
GdkRectangle update_rect;
701
pntnbr=tanplacepiece(piecepos,pnt,zoom);
703
for(i=0; i<pntnbr; i++){
718
update_rect.width=ixmax-ixmin+1;
719
update_rect.height=iymax-iymin+1;
723
gc=tabgc[GCPETITEHLP];
726
gc=tabgc[GCPIECENOR];
727
gdk_gc_set_ts_origin (gc,pnt[pntnbr].x,pnt[pntnbr].y);
731
gdk_gc_set_ts_origin (gc,pnt[pntnbr].x,pnt[pntnbr].y);
734
gc=widget->style->white_gc;
738
gdk_draw_polygon (pixmap,
744
if ( remplis==TAN_PIECENOR || remplis==TAN_PIECEHI ){
745
pnt[pntnbr]=pnt[0]; /* ecrase le point du centre */
746
for (i=0; i<pntnbr; i++){
747
rx=pnt[i+1].x-pnt[i].x;
748
ry=pnt[i].y-pnt[i+1].y;
749
gris=(ry+rx)*0.35355339/sqrt(rx*rx+ry*ry);
750
if (piecepos->flipped)
753
gdk_draw_line (pixmap,
754
tabgc[(int)(gris*(GRISNBR))],
755
pnt[i].x,pnt[i].y,pnt[i+1].x,pnt[i+1].y);
763
/********************************/
764
void tandrawfigure (GtkWidget *widget,GdkPixmap *pixmap,
765
tanfigure *figure,int exclue, tanremplis remplis){
769
tanpiecepos *piecepos;
771
zoom=widget->allocation.width*figure->zoom;
772
piecepos=figure->piecepos;
774
for (i=0; i<PIECENBR; i++){
776
tandrawpiece(widget,pixmap,piecepos,zoom,remplis);
782
/********************************/
783
/* affiche flfigpetite dans le pixmap */
784
void tandrawfloat (GdkPixmap *pixmap, gboolean isoutline){
786
tanflfig *flfig=&flfigpetite;
788
GdkPoint pnts[PIECENBR*(PNTNBRMAX+1)];
794
tanpolytype polytype;
798
zoom = widgetgrande->allocation.width*figgrande.zoom;
803
zoom = widgetpetite->allocation.width*figpetite.zoom;
808
flpiecenbr = flfig->flpiecenbr;
809
for (i = 0; i<flpiecenbr; i++){
810
figfpnts = flfig->flpieces[i].flpnts;
811
flpntnbr = flfig->flpieces[i].flpntnbr;
812
polytype = flfig->flpieces[i].polytype;
813
for (j = 0; j<flpntnbr; j++){
814
pnts[j].x = (gint16)(zoom*(figfpnts[j].posx-dx)+ARON);
815
pnts[j].y = (gint16)(zoom*(figfpnts[j].posy-dy)+ARON);
818
pnts[flpntnbr] = pnts[0];
819
gdk_draw_lines(pixmap, tabgc[GCPIECEHLP], pnts, flpntnbr+1);
822
gdk_draw_polygon(pixmap,
823
(polytype==TAN_POLYON) ? ( figpetite.reussi ? tabgc[GCPETITECHK] : tabgc[GCPETITEBG] ) : tabgc[GCPETITEFG],
824
TRUE, pnts, flpntnbr);
830
/********************************/
831
/* affiche le fond de la widgetgrande */
832
void tandrawbgndgr (GdkPixmap *pixmap){
835
gdk_draw_rectangle (pixmap,
839
widgetgrande->allocation.width,
840
widgetgrande->allocation.height);
842
if ( helpoutset && figtabsize )
843
tandrawfloat(pixmap, TRUE);
848
/********************************/
849
void taninitselect(int selected, gboolean force){
855
selected != PIECENBR-1 ||
858
tandrawbgndgr(pixmapgrande2);
860
tandrawfigure(widgetgrande,pixmapgrande2,&figgrande,
861
selected,TAN_PIECENOR);
865
selbackrect.width=widgetgrande->allocation.width;
866
selbackrect.height=widgetgrande->allocation.height;
868
dum=figgrande.piecepos[selected];
869
for (i=selected; i<PIECENBR-1; i++)
870
figgrande.piecepos[i]=figgrande.piecepos[i+1];
871
figgrande.piecepos[PIECENBR-1]=dum;
874
selposxnc = figgrande.piecepos[PIECENBR-1].posx;
875
selposync = figgrande.piecepos[PIECENBR-1].posy;
879
/********************************/
880
void tandrawselect(int dx, int dy, int drot){
881
tanpiecepos *selpiece;
886
selpiece=&(figgrande.piecepos[PIECENBR-1]);
887
zoom=widgetgrande->allocation.width*figgrande.zoom;
889
selposxnc += dx/zoom;
890
selposync += dy/zoom;
892
selpiece->posx = CLAMP(selposxnc, 0, 1.0/figgrande.zoom);
893
selpiece->posy = CLAMP(selposync, 0, 1.0/figgrande.zoom);
894
dumrot=selpiece->rot;
895
rotnew=selpiece->rot-=drot;
897
gdk_draw_pixmap(pixmapgrande1,
898
widgetgrande->style->fg_gc[GTK_WIDGET_STATE (widgetgrande)],
900
selbackrect.x,selbackrect.y,
901
selbackrect.x,selbackrect.y,
902
selbackrect.width,selbackrect.height);
904
selbk2=tandrawpiece(widgetgrande,pixmapgrande1,
909
gtk_widget_draw (widgetgrande, &selbackrect);
910
gtk_widget_draw (widgetgrande, &selbk2);
914
selpiece->rot=dumrot;
919
/********************************/
920
void tanredrawgrande (void){
922
GdkRectangle rect={0,0,0,0};
923
GtkWidget *widget=NULL;
929
taninitselect(PIECENBR-1, TRUE);
930
tandrawselect(0,0,0);
934
tandrawbgndgr(pixmapgrande1);
935
tandrawfigure(widget, pixmapgrande1, &figgrande, PIECENBR+1, TAN_PIECENOR);
936
rect.width=widget->allocation.width;
937
rect.height=widget->allocation.height;
938
gtk_widget_draw (widget, &rect);
944
/********************************/
945
void tanclearreussinr (int fignr){
947
if ( fignr>= 0 && fignr<figtabsize )
948
(figtab+fignr)->reussi = FALSE;
953
/********************************/
954
void tansetreussiactual (void){
956
figpetite.reussi = TRUE;
957
if ( figactualnr>= 0 && figactualnr<figtabsize )
958
(figtab+figactualnr)->reussi = TRUE;
963
/********************************/
964
void tanredrawpetite (void){
966
GdkRectangle rect={0,0,0,0};
969
/* in case we are called before widget configured */
973
wid = widgetpetite->allocation.width;
974
hei = widgetpetite->allocation.height;
976
gdk_draw_rectangle (pixmappetite,
977
figpetite.reussi ? tabgc[GCPETITECHK] : tabgc[GCPETITEBG],
984
tandrawfloat (pixmappetite, FALSE);
986
if (helptanset<PIECENBR)
987
tandrawpiece(widgetpetite,
989
&figpetite.piecepos[helptanset],
990
widgetpetite->allocation.width*figpetite.zoom,
993
/* tandrawfigure(widget, pixmappetite, &figpetite, PIECENBR+1, TAN_PETITEFG); */
997
gtk_widget_draw (widgetpetite, &rect);
1002
/********************************/
1003
void tanunselect (void){
1005
if (selectedgrande){
1006
selectedgrande=FALSE;
1012
/********************************/
1013
gdouble tanreadfloat(FILE *fhd, int *lres)
1020
*lres = fscanf(fhd, "%99s",buf);
1021
pouet=g_strtod(buf,NULL);
1029
/********************************/
1030
#define SPESC if (lres==1) lres = fscanf
1032
gboolean tanloadfigtab (char *name){
1038
tanfigure *newfigtab=NULL,*figs;
1043
if ( (hand = g_fopen(name, "r"))!=NULL &&
1044
fscanf(hand, "gTans v1.0 %d \n", &newfigtabsize)==1 &&
1045
(newfigtab = (tanfigure *)g_malloc(sizeof(tanfigure)*newfigtabsize))!=NULL ){
1049
for (i = 0; i<newfigtabsize; i++){
1050
*figs = figuredebut;
1051
figs->zoom = tanreadfloat(hand, &lres);
1052
figs->distmax = tanreadfloat(hand, &lres);
1053
SPESC(hand,"%d \n", &figs->drotmax);
1054
/*fscanf(hand,"%le %le %d \n",&figs->zoom,&figs->distmax,&figs->drotmax);*/
1055
for (j=0; j<PIECENBR; j++){
1056
SPESC(hand,"p %d", &figs->piecepos[j].type);
1057
SPESC(hand,"%d", &figs->piecepos[j].flipped);
1058
figs->piecepos[j].posx = tanreadfloat(hand, &lres);
1059
figs->piecepos[j].posy = tanreadfloat(hand, &lres);
1060
SPESC(hand,"%d \n", &figs->piecepos[j].rot);
1061
/*fscanf(hand,"%d %d %le %le %d \n",&figs->piecepos[j].type,&figs->piecepos[j].flipped,
1062
&figs->piecepos[j].posx,&figs->piecepos[j].posy,&figs->piecepos[j].rot);*/
1067
g_warning("Opening file %s fails",name);
1080
figtabsize=newfigtabsize;
1084
tansetnewfigurepart1(actual_figure);
1085
tansetnewfigurepart2();
1087
//tanspinsetvalmax(figtabsize-1);
1090
if (succes || figfilename==NULL)
1091
tanallocname(&figfilename, name);
1098
/********************************/
1099
/* charge un pixmap, si necessaire desalloue et/ou (re)alloue la couleur */
1100
gboolean tansetpixmapmode(GtkWidget *widget, char *aname, int gcnbr){
1108
pixmap=tabpxpx[gcnbr];
1109
pname=tabpxnam[gcnbr];
1112
if (tabcolalloc[gcnbr]){
1113
gdk_colormap_free_colors (gdk_colormap_get_system(), &colortab[gcnbr], 1);
1114
tabcolalloc[gcnbr] = FALSE;
1118
gdk_pixmap_unref(pixmap);
1121
if ( (pixmap=gdk_pixmap_create_from_xpm (widget->window, NULL, NULL, aname))!=NULL ){
1122
tanallocname(&pname,aname);
1123
gdk_gc_set_fill (gc, GDK_TILED);
1124
gdk_gc_set_tile (gc, pixmap);
1129
tanallocname(&pname,"LoadPixmapFailed");
1131
tabpxpx[gcnbr] = pixmap;
1132
tabpxnam[gcnbr] = pname;
1133
tabpxpixmode[gcnbr] = ret;
1136
tansetcolormode(&colortab[gcnbr],gcnbr);
1143
/********************************/
1144
/* passe en mode color, decharge le pixmap (mais pas le nom) */
1145
void tansetcolormode(GdkColor *acolor, int gcnbr){
1150
GdkColormap *syscmap;
1153
pcolor = &colortab[gcnbr];
1154
syscmap = gdk_colormap_get_system();
1156
if (tabcolalloc[gcnbr])
1157
gdk_colormap_free_colors (syscmap, pcolor, 1);
1159
if ( gcnbr>=PXSTART && gcnbr<PXSTART+PXNBR ){
1160
tabpxpixmode[gcnbr] = FALSE;
1161
if ( (pixmap = tabpxpx[gcnbr])!=NULL ){
1162
tabpxpx[gcnbr] = NULL;
1163
gdk_pixmap_unref(pixmap);
1167
pcolor->red = acolor->red;
1168
pcolor->green = acolor->green;
1169
pcolor->blue = acolor->blue;
1170
tabcolalloc[gcnbr] = gdk_colormap_alloc_color (syscmap, pcolor, FALSE, TRUE);
1171
gdk_gc_set_fill (gc, GDK_SOLID);
1172
gdk_gc_set_foreground (gc, pcolor);
1176
/********************************/
1177
/* config par defaut */
1178
void tansetdefconfig (void){
1181
guint backgroung_color_red = 0xe8<<8;
1182
guint backgroung_color_green = 0xe7<<8;
1183
guint backgroung_color_blue = 0xe2<<8;
1185
for (i = PXSTART; i<PXNBR+PXSTART; i++){
1186
tabpxpixmode[i] = FALSE;
1187
tanallocname(&tabpxnam[i], "NoConfigFile");
1190
colortab[GCPETITEFG].red = colortab[GCPETITEFG].green = colortab[GCPETITEFG].blue = 0;
1191
colortab[GCPETITEBG].red = backgroung_color_red;
1192
colortab[GCPETITEBG].green = backgroung_color_green;
1193
colortab[GCPETITEBG].blue = backgroung_color_blue;
1195
colortab[GCPIECENOR].red = colortab[GCPIECENOR].green = 32768;
1196
colortab[GCPIECENOR].blue = 50000;
1198
colortab[GCPIECEHI].red = colortab[GCPIECEHI].green = 40000;
1199
colortab[GCPIECEHI].blue = 65535;
1201
colortab[GCPIECEBG].red = backgroung_color_red;
1202
colortab[GCPIECEBG].green = backgroung_color_green;
1203
colortab[GCPIECEBG].blue = backgroung_color_blue;
1205
colortab[GCPIECEHLP].blue = colortab[GCPIECEHLP].green = 0;
1206
colortab[GCPIECEHLP].red = 65535;
1208
colortab[GCPETITECHK].blue = colortab[GCPETITECHK].red = 40000;
1209
colortab[GCPETITECHK].green = 60000;
1211
colortab[GCPETITEHLP].red = (colortab[GCPETITEFG].red+colortab[GCPETITEBG].red)/2;
1212
colortab[GCPETITEHLP].green = (colortab[GCPETITEFG].green+colortab[GCPETITEBG].green)/2;
1213
colortab[GCPETITEHLP].blue = (colortab[GCPETITEFG].blue+colortab[GCPETITEBG].blue)/2;
1216
GcomprisProperties *properties = gc_prop_get();
1217
gchar *deffigfile = g_strconcat(properties->package_data_dir,
1218
"/tangram/default.figures", NULL);
1220
tanallocname(&figfilename, deffigfile);
1225
rotstepnbr = TOUR/32;
1227
figgrande.zoom = 0.125;
1233
/********************************/
1234
/* supprime 2 points successifs identiques (en principe inutile) */
1235
gboolean tanremsame(tanflfig *flfig, tanpoly *polys, int *pntsuiv, tanfpnt *fpnts, double seuil){
1237
gboolean trouve, ret;
1242
polynbr = flfig->flpiecenbr;
1248
for (i = 0; i<polynbr && !trouve; i++){
1249
act = polys[i].firstpnt;
1250
for (k = 0; k<polys[i].pntnbr && !trouve; k++){
1251
suiv = pntsuiv[act];
1252
if ( tandistcar(&fpnts[act],&fpnts[suiv])<seuil ){
1253
pntsuiv[act] = pntsuiv[suiv];
1255
polys[i].firstpnt = act;
1256
trouve = ret = TRUE;
1257
printf ("j'en ai trouve un.\n");
1268
/* ajoute des point intermediaire */
1269
gboolean tanajoute(tanflfig *flfig,
1276
gboolean trouve, ret;
1283
polynbr = flfig->flpiecenbr;
1287
while ( trouve && flptnew<FLPNTMAX ){
1289
for (i = 0; i<polynbr && !trouve; i++){
1290
for (j = 0; j<polynbr && !trouve; j++){
1292
act1 = polys[i].firstpnt;
1293
segment[0] = fpnts[act1];
1294
for (k = 0; k<polys[i].pntnbr && !trouve; k++){
1295
suiv1 = pntsuiv[act1];
1296
segment[1] = fpnts[suiv1];
1297
act2 = polys[j].firstpnt;
1298
for (l = 0; l<polys[j].pntnbr && !trouve; l++){
1299
suiv2 = pntsuiv[act2];
1300
if ( tandistcar(&segment[0], &fpnts[act2])>seuil &&
1301
tandistcar(&segment[1], &fpnts[act2])>seuil &&
1302
tandistcarsegpnt(segment, &fpnts[act2], &dx, &dy)<seuil/4 ){
1303
fpnts[flptnew].posx = fpnts[act2].posx-dx;
1304
fpnts[flptnew].posy = fpnts[act2].posy-dy;
1305
pntsuiv[flptnew] = pntsuiv[act1];
1306
pntsuiv[act1] = flptnew;
1309
polys[i].firstpnt = act1;
1310
trouve = ret = TRUE;
1315
segment[0] = segment[1];
1322
flfig->flpiecenbr = polynbr;
1328
/* "tasse" les fpnt et recree la floatfig */
1329
/* copie les point de ref dans cop */
1330
/* en sortie les 2 sont identiques mais la floatfig pointe sur cop */
1331
int tantasse(tanflfig *flfig,
1341
for (i = 0; i<flfig->flpiecenbr; i++){
1342
pntnbr = polys[i].pntnbr;
1343
flfig->flpieces[i].flpntnbr = pntnbr;
1344
flfig->flpieces[i].flpnts = fpnts;
1345
flfig->flpieces[i].polytype = polys[i].polytype;
1346
act = polys[i].firstpnt;
1347
for (j = 0; j<pntnbr+1; j++){
1348
*fpnts++ = fpntsref[act];
1354
for (i = 0; i<flfig->flpiecenbr; i++){
1355
pntnbr = polys[i].pntnbr;
1356
polys[i].firstpnt = act;
1357
for (j = 0; j<pntnbr-1; j++)
1358
pntsuiv[act+j] = act+j+1;
1359
pntsuiv[act+j] = act;
1363
pntnbr = fpnts-fpntscop;
1364
for (i = 0; i<pntnbr; i++)
1365
*fpntsref++ = *fpntscop++;
1371
/* supprime les points intermediaires de segments alignes */
1372
gboolean tanalign(tanflfig *flfig, tanpoly *polys, int *pntsuiv, tanfpnt *fpnts){
1374
gboolean trouve, ret;
1381
polynbr = flfig->flpiecenbr;
1387
for (i = 0; i<polynbr && !trouve; i++){
1388
act = polys[i].firstpnt;
1389
suiva = pntsuiv[act];
1390
dumi = tanangle(fpnts[suiva].posx-fpnts[act].posx, fpnts[suiva].posy-fpnts[act].posy);
1391
diract = (int)((dumi+rotstepnbr/2)/rotstepnbr);
1392
for (k = 0; k<polys[i].pntnbr && !trouve; k++){
1393
suiva = pntsuiv[act];
1394
suivb = pntsuiv[suiva];
1395
dumi = tanangle(fpnts[suivb].posx-fpnts[suiva].posx, fpnts[suivb].posy-fpnts[suiva].posy);
1396
dirsuiv = (int)((dumi+rotstepnbr/2)/rotstepnbr);
1397
if ( diract==dirsuiv ){
1398
pntsuiv[act] = suivb;
1400
polys[i].firstpnt = act;
1401
trouve = ret = TRUE;
1413
/* supprime les segments consecutifs superposes */
1414
gboolean tanconseq(tanflfig *flfig, tanpoly *polys, int *pntsuiv, tanfpnt *fpnts, double seuil){
1416
gboolean trouve, ret;
1421
polynbr = flfig->flpiecenbr;
1427
for (i = 0; i<polynbr && !trouve; i++){
1428
act = polys[i].firstpnt;
1429
for (k = 0; k<polys[i].pntnbr && !trouve; k++){
1430
suiva = pntsuiv[act];
1431
suivb = pntsuiv[suiva];
1432
if ( tandistcar(&fpnts[act],&fpnts[suivb])<seuil ){
1433
pntsuiv[act] = pntsuiv[suivb];
1434
polys[i].pntnbr -= 2;
1435
polys[i].firstpnt = act;
1436
trouve = ret = TRUE;
1447
/* concatene les poly ayant 1 segment commun */
1448
gboolean tanconcat(tanflfig *flfig, tanpoly *polys, int *pntsuiv, tanfpnt *fpnts, double seuil){
1450
gboolean trouve, ret;
1455
polynbr = flfig->flpiecenbr;
1461
for (i = 0; i<polynbr-1 && !trouve; i++){
1462
for (j = i+1; j<polynbr && !trouve; j++){
1463
act1 = polys[i].firstpnt;
1464
for (k = 0; k<polys[i].pntnbr && !trouve; k++){
1465
suiv1 = pntsuiv[act1];
1466
act2 = polys[j].firstpnt;
1467
for (l = 0; l<polys[j].pntnbr && !trouve; l++){
1468
suiv2 = pntsuiv[act2];
1469
if ( tandistcar(&fpnts[act1],&fpnts[suiv2])<seuil &&
1470
tandistcar(&fpnts[suiv1],&fpnts[act2])<seuil ){
1471
pntsuiv[act1] = pntsuiv[suiv2];
1472
pntsuiv[act2] = pntsuiv[suiv1];
1473
polys[i].pntnbr += polys[j].pntnbr-2;
1474
polys[i].firstpnt = act1;
1475
for (m = j; m<polynbr-1; m++)
1476
polys[m] = polys[m+1];
1478
trouve = ret = TRUE;
1488
flfig->flpiecenbr = polynbr;
1494
/* detecte les poly "inclus" */
1495
/* probleme potentiel : pourrait ne pas detecter une inclusion
1496
car on n'ajoute pas de points pour les 'auto-corespondance' */
1497
gboolean taninclus(tanflfig *flfig, tanpoly *polys, int *pntsuiv, tanfpnt *fpnts, double seuil){
1499
gboolean trouve, ret;
1506
int dumpntposxmin = 0;
1508
polynbr = flfig->flpiecenbr;
1510
trouve = ret = FALSE;
1511
for (i = 0; i<polynbr && !trouve; i++){
1512
pntnbr = polys[i].pntnbr;
1514
/*pour etre sur de partir de l'exterieur*/
1515
act1 = polys[i].firstpnt;
1516
dumposxmin = 99999999.0;
1517
for (m=0; m<pntnbr; m++){
1518
if ( fpnts[act1].posx<dumposxmin ){
1519
dumposxmin = fpnts[act1].posx;
1520
dumpntposxmin = act1;
1522
act1 = pntsuiv[act1];
1524
act1 = dumpntposxmin;
1526
for (k = 0; k<pntnbr-2 && !trouve; k++){
1527
suiv1 = pntsuiv[act1];
1528
act2 = pntsuiv[suiv1];
1529
for (l = k+2; l<pntnbr && !trouve; l++){
1530
suiv2 = pntsuiv[act2];
1531
if ( tandistcar(&fpnts[act1],&fpnts[suiv2])<seuil &&
1532
tandistcar(&fpnts[suiv1],&fpnts[act2])<seuil ){
1534
pntsuiv[act1] = pntsuiv[suiv2];
1535
pntsuiv[act2] = pntsuiv[suiv1];
1538
for (n = i; n<polynbr-1; n++)
1539
polys[n] = polys[n+1];
1543
for (m = 0; polys[m].polytype==TAN_POLYBACK && m<polynbr; m++);
1545
/* printf("inclusion trouvee\n");*/
1547
for (n = polynbr+1; n>m+1; n--)
1548
polys[n] = polys[n-2];
1550
dumpoly.pntnbr -= l-k+1;
1551
dumpoly.firstpnt = act1;
1552
if (dumpoly.polytype!=TAN_POLYON)
1553
dumpoly.polytype = TAN_POLYBACK;
1555
dumpoly.polytype = TAN_POLYON;
1559
polys[m+1].pntnbr = l-k-1;
1560
polys[m+1].firstpnt = act2;
1561
polys[m+1].polytype = TAN_POLYON;
1565
trouve = ret = TRUE;
1576
flfig->flpiecenbr = polynbr;
1582
/* change de petite figure */
1583
/* pas d'acces gtk */
1584
void tansetnewfigurepart1(int nrfig){
1588
double xmin=10000,xmax=-10000,ymin=10000,ymax=-10000;
1589
tanpiecepos *piecepos;
1590
tanflfig *flfig=&flfigpetite;
1591
int flpiecenbr,flpntnbr;
1593
tanfpnt dumfpnts[FLPNTMAX];
1594
tanpoly polys[PIECENBR];
1595
int polypntact,polypntnbr;
1596
int pntsuivants[FLPNTMAX];
1597
double seuil=0.00000000001;
1600
if ( nrfig>=0 && figtabsize ){
1601
nrfig %= figtabsize;
1602
actual_figure = nrfig;
1603
figure = figtab+nrfig;
1606
figure = &figuredebut;
1608
figure = &figpetite;
1612
figactualnr = nrfig;
1614
helptanset=PIECENBR;
1616
tancolle(&figpetite,0.02);
1617
tanmaketinytabnotr(&figpetite,tinytabpe);
1618
tantranstinytab(tinytabpe);
1620
/* la floatfig et preparation de la concatenation */
1621
flfig->flpiecenbr = PIECENBR;
1622
flfig->figure = figure;
1625
for (i = 0; i<PIECENBR; i++){
1626
polypntnbr = piecesdef[figure->piecepos[i].type].pntnbr;
1627
polys[i].pntnbr = polypntnbr;
1628
polys[i].firstpnt = polypntact;
1629
polys[i].polytype = TAN_POLYNORMAL;
1631
for (j = 0; j<polypntnbr-1; j++)
1632
pntsuivants[polypntact+j] = polypntact+j+1;
1633
pntsuivants[polypntact+j] = polypntact;
1634
polypntact += polypntnbr+1;
1636
tanplacepiecefloat(&figure->piecepos[i], fpnts,1);
1637
fpnts += polypntnbr+1;
1640
tanconcat(flfig, polys, pntsuivants, dumfpnts, seuil);
1641
tanconseq(flfig, polys, pntsuivants, dumfpnts, seuil);
1643
pntnew = tantasse(flfig, polys, pntsuivants, dumfpnts, fpntspetite);
1644
tanajoute(flfig, polys, pntsuivants, dumfpnts, seuil, pntnew);
1645
tanconcat(flfig, polys, pntsuivants, dumfpnts, seuil);
1646
tanconseq(flfig, polys, pntsuivants, dumfpnts, seuil);
1647
if (taninclus(flfig, polys, pntsuivants, dumfpnts, seuil))
1648
taninclus(flfig, polys, pntsuivants, dumfpnts, seuil);
1649
tanalign(flfig, polys, pntsuivants, dumfpnts);
1650
tanremsame(flfig, polys, pntsuivants, dumfpnts, seuil);
1652
pntnew = tantasse(flfig, polys, pntsuivants, dumfpnts, fpntspetite);
1653
tanajoute(flfig, polys, pntsuivants, dumfpnts, seuil, pntnew);
1654
tanconcat(flfig, polys, pntsuivants, dumfpnts, seuil);
1655
tanconseq(flfig, polys, pntsuivants, dumfpnts, seuil);
1656
if (taninclus(flfig, polys, pntsuivants, dumfpnts, seuil))
1657
taninclus(flfig, polys, pntsuivants, dumfpnts, seuil);
1658
tanalign(flfig, polys, pntsuivants, dumfpnts);
1659
tanremsame(flfig, polys, pntsuivants, dumfpnts, seuil);
1661
tantasse(flfig, polys, pntsuivants, dumfpnts, fpntspetite);
1663
/* calcul du centrage */
1664
flpiecenbr = flfig->flpiecenbr;
1665
for (i = 0; i<flpiecenbr; i++){
1666
fpnts = flfig->flpieces[i].flpnts;
1667
flpntnbr = flfig->flpieces[i].flpntnbr;
1668
for (j = 0; j<flpntnbr; j++){
1669
if (fpnts[j].posx>xmax)
1671
if (fpnts[j].posy>ymax)
1673
if (fpnts[j].posx<xmin)
1675
if (fpnts[j].posy<ymin)
1680
figpetite.zoom = 1/(( (xmax-xmin)>(ymax-ymin) ? (xmax-xmin) : (ymax-ymin) )+0.25);
1681
dxpetite = 0.5*(xmax+xmin)-(0.5/figpetite.zoom);
1682
dypetite = 0.5*(ymax+ymin)-(0.5/figpetite.zoom);
1684
dxout = 0.5*(xmax+xmin)-(0.5/figgrande.zoom); /* cf tanrecentreout pour correction */
1685
dyout = 0.5*(ymax+ymin)-(0.5/figgrande.zoom);
1687
/* centrage des pieces petite */
1688
piecepos=figpetite.piecepos;
1689
for (i=0; i<PIECENBR; i++){
1690
piecepos->posx-=dxpetite;
1691
piecepos->posy-=dypetite;
1697
/********************************/
1698
/* corrige dxout et dyout pour les changement de zoom de figgrande */
1699
void tanrecentreout(double oldzoom, double newzoom){
1701
tanpiecepos *piecepos;
1705
correction = 0.5*(1/oldzoom-1/newzoom);
1707
dxout += correction;
1708
dyout += correction;
1710
piecepos = figgrande.piecepos;
1711
for (i = 0; i<PIECENBR; i++){
1712
piecepos->posx -= correction;
1713
piecepos->posy -= correction;
1721
/********************************/
1722
/* change de petite figure */
1723
void tansetnewfigurepart2(void){
1725
if (selectedgrande){
1729
else if (helpoutset){ /* pour eviter 2 appels successif a tanredrawgrande */
1741
/********************************/
1742
void spesavefig (void){
1746
tanfigure *fig=NULL; /*juste pour eviter un warning*/
1748
if ( (hand=g_fopen("pouet.fig", "w"))!=NULL){
1750
fprintf(hand, "gTans v1.0 %d \n",figtabsize);
1753
fprintf(hand,"%e %e %d \n",1.0,fig->distmax,fig->drotmax);
1754
for (j=0; j<PIECENBR; j++)
1755
fprintf(hand,"p %d %d %e %e %d \n",fig->piecepos[j].type,fig->piecepos[j].flipped,
1756
fig->piecepos[j].posx,fig->piecepos[j].posy,fig->piecepos[j].rot);
1763
tansetnewfigurepart1(-2);
1764
tansetnewfigurepart2();
1769
/********************************/
1770
void taninitstart(void){
1775
for (i = PXSTART; i<PXNBR+PXSTART; i++){
1780
for (i = 0; i<GCNBR; i++)
1781
tabcolalloc[i] = FALSE;
1784
figgrande = figuredebut;
1787
tansetnewfigurepart1(-1);
1791
tanclampgrandefig();
1794
boardRootItem = goo_canvas_group_new (goo_canvas_get_root_item(gcomprisBoard->canvas),
1798
create_mainwindow(boardRootItem);
1802
accurstr = "maccuracy1";
1805
accurstr = "maccuracy3";
1808
accurstr = "maccuracy2";
1811
if (rotstepnbr==TOUR/256)
1812
accurstr = "mrotcont";
1814
accurstr = "mrotstp";
1816
tanloadfigtab(figfilename);
1821
/********************************/
1824
GdkColormap *syscmap;
1826
syscmap = gdk_colormap_get_system();
1831
if (figfilename!=NULL)
1832
g_free(figfilename);
1837
if (pixmappetite!=NULL)
1838
gdk_pixmap_unref(pixmappetite);
1839
if (pixmapgrande1!=NULL)
1840
gdk_pixmap_unref(pixmapgrande1);
1841
if (pixmapgrande2!=NULL)
1842
gdk_pixmap_unref(pixmapgrande2);
1843
if (pixmappiece1!=NULL)
1844
gdk_pixmap_unref(pixmappiece1);
1845
if (pixmappiece2!=NULL)
1846
gdk_pixmap_unref(pixmappiece2);
1847
if (pixmapfond!=NULL)
1848
gdk_pixmap_unref(pixmapfond);
1850
for (i=PXSTART; i<PXSTART+PXNBR; i++){
1851
if (tabpxpx[i]!=NULL)
1852
gdk_pixmap_unref(tabpxpx[i]);
1853
if (tabpxnam[i]!=NULL)
1854
g_free(tabpxnam[i]);
1857
for (i = 0; i<GCNBR; i++){
1859
gdk_gc_unref(tabgc[i]);
1861
gdk_colormap_free_colors (syscmap, &colortab[i], 1);
1864
gdk_gc_unref(invertgc);
1870
/********************************/
1871
void taninitcbcommun(void){
1876
/********************************/
1877
void taninitcbgr(void){
1881
initcbgr = TRUE; /* pour ne pas initialiser 2 fois */
1883
for (i=PXSTART; i<PXSTART+PXNBR; i++){
1884
tabgc[i] = gdk_gc_new(widgetgrande->window);
1885
if (tabpxpixmode[i])
1886
tansetpixmapmode(widgetgrande,tabpxnam[i],i);
1888
tansetcolormode(&colortab[i],i);
1891
for (i=0; i<GRISNBR; i++){
1892
color = &colortab[i];
1893
color->red = color->green = color->blue = (gushort)(65535.0/(GRISNBR-1)*i);
1894
tabgc[i] = gdk_gc_new(widgetgrande->window);
1895
tansetcolormode(color,i);
1898
invertgc=gdk_gc_new(widgetgrande->window);
1899
gdk_gc_set_function(invertgc,GDK_INVERT);
1900
tabgc[GCPIECEHLP]=gdk_gc_new(widgetgrande->window);
1901
tansetcolormode(&colortab[GCPIECEHLP],GCPIECEHLP);
1902
/* les line attribute sont dans le callback */
1910
/********************************/
1911
void taninitcbpe(void){
1913
initcbpe=TRUE; /* pour ne pas initialiser 2 fois (c'est pas propre, mais bon) */
1915
tabgc[GCPETITEFG]=gdk_gc_new(widgetpetite->window);
1916
tansetcolormode(&colortab[GCPETITEFG],GCPETITEFG);
1918
tabgc[GCPETITEBG]=gdk_gc_new(widgetpetite->window);
1919
tansetcolormode(&colortab[GCPETITEBG],GCPETITEBG);
1921
tabgc[GCPETITEHLP]=gdk_gc_new(widgetpetite->window);
1922
tansetcolormode(&colortab[GCPETITEHLP],GCPETITEHLP);
1924
tabgc[GCPETITECHK]=gdk_gc_new(widgetpetite->window);
1925
tansetcolormode(&colortab[GCPETITECHK],GCPETITECHK);
1933
/********************************/
1934
/* determine si le point x,y est dans la piece */
1935
gboolean tanpntisinpiece(int x, int y, tanpiecepos *piecepos){
1939
GdkPoint pnt[PNTNBRMAX+2];
1942
nbrpnt=tanplacepiece(piecepos,pnt,widgetgrande->allocation.width*figgrande.zoom);
1946
if (piecepos->flipped){
1947
for (i=0; (i<nbrpnt && in); i++)
1948
if ( (x-pnt[i].x)*(pnt[i+1].y-pnt[i].y)-(y-pnt[i].y)*(pnt[i+1].x-pnt[i].x)<0 )
1952
for (i=0; (i<nbrpnt && in); i++)
1953
if ( (x-pnt[i].x)*(pnt[i+1].y-pnt[i].y)-(y-pnt[i].y)*(pnt[i+1].x-pnt[i].x)>0 )
1963
/********************************/
1964
/* determine dans quelle piece se trouve le point (-1=aucune) */
1965
int tanwichisselect(int x, int y){
1971
for (i=PIECENBR-1; i>=0 && !trouve; i--)
1972
trouve=tanpntisinpiece(x,y,figgrande.piecepos+i);