Back to index

gcompris  8.2.2
gtans_callbacks.c
Go to the documentation of this file.
00001 
00002 /*
00003  * Copyright (C) 1999  Philippe Banwarth
00004  * email: bwt@altern.org
00005  * smail: Philippe Banwarth, 8 sente du milieu des Gaudins, 95150 Taverny, France.
00006  *
00007  * This program is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  */
00021 
00022 #ifdef HAVE_CONFIG_H
00023 #  include <config.h>
00024 #endif
00025 
00026 #include "gcompris/gcompris.h"
00027 
00028 #include <stdio.h>
00029 #include <stdlib.h>
00030 #include <string.h>
00031 #include <math.h>
00032 
00033 #include "gtans_callbacks.h"
00034 #include "gtans_interface.h"
00035 #include "gtans.h"
00036 #include "gtans_support.h"
00037 
00038 void colselinit (int col);
00039 void filselinit (int col);
00040 
00041 #define FIGGC 2848
00042 
00043 gboolean
00044 on_wdrawareagrande_expose_event        (GtkWidget       *widget,
00045                                         GdkEventExpose  *event,
00046                                         gpointer         user_data)
00047 {
00048   if (pixmapgrande1!=NULL)
00049     gdk_draw_pixmap(widget->window,
00050                   widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
00051                   pixmapgrande1,
00052                   event->area.x, event->area.y,
00053                   event->area.x, event->area.y,
00054                   event->area.width, event->area.height);
00055 
00056   return FALSE;
00057 }
00058 
00059 
00060 gboolean
00061 on_wdrawareagrande_configure_event     (GtkWidget       *widget,
00062                                         GdkEventConfigure *event,
00063                                         gpointer         user_data)
00064 {
00065   double izoom;
00066   tanpiecepos *piecepos;
00067   int i;
00068 
00069   widgetgrande=widget;
00070   if (!initcbgr)
00071     taninitcbgr();
00072 
00073   if (pixmapgrande1!=NULL){
00074     gdk_pixmap_unref(pixmapgrande1);
00075     gdk_pixmap_unref(pixmapgrande2);
00076   }
00077 
00078   pixmapgrande1 = gdk_pixmap_new(widget->window,
00079                              widget->allocation.width,
00080                              widget->allocation.height,
00081                              -1);
00082   pixmapgrande2 = gdk_pixmap_new(widget->window,
00083                              widget->allocation.width,
00084                              widget->allocation.height,
00085                              -1);
00086    
00087   if ( !editmode ){
00088     izoom=(widgetgrande->allocation.width*figgrande.zoom);
00089     piecepos=figgrande.piecepos;
00090     for (i=0; i<PIECENBR; i++){
00091       piecepos->posx=floor((piecepos->posx*izoom)+ARON)/izoom;
00092       piecepos->posy=floor((piecepos->posy*izoom)+ARON)/izoom;
00093       piecepos++;
00094     }
00095   }
00096 
00097   gdk_gc_set_line_attributes(tabgc[GCPIECEHLP],
00098                           widget->allocation.width>340 ? 2 : 1,
00099                           GDK_LINE_SOLID,
00100                           GDK_CAP_ROUND,
00101                           GDK_JOIN_ROUND);
00102 
00103   tanredrawgrande();
00104 
00105   return TRUE;
00106 }
00107 
00108 
00109 gboolean
00110 on_wdrawareagrande_button_press_event  (GtkWidget       *widget,
00111                                         GdkEventButton  *event,
00112                                         gpointer         user_data)
00113 {
00114   int x,y;
00115   int piece;
00116 
00117   if (!selpossible || event->type!=GDK_BUTTON_PRESS)     /* double-click ou deja trouve */
00118     return TRUE;
00119   
00120   if (actiongrande != AN_none)      /* le button release event a ete avale */
00121     tanreleaseifrot();
00122 
00123   x=event->x;
00124   y=event->y;
00125 
00126   if ( event->button!=3){
00127     if ( (piece=tanwichisselect(x,y))>=0 ){
00128       taninitselect(piece, FALSE);
00129       selectedgrande=TRUE;
00130       actiongrande=AN_move;
00131       xold=x;
00132       yold=y;
00133       tandrawselect(0,0,0);
00134     }
00135     else{
00136       if (selectedgrande){
00137        actiongrande=AN_rot;
00138        xact=(gint16)(ARON+figgrande.piecepos[PIECENBR-1].posx*
00139                     widgetgrande->allocation.width*figgrande.zoom);
00140        yact=(gint16)(ARON+figgrande.piecepos[PIECENBR-1].posy*
00141                     widgetgrande->allocation.width*figgrande.zoom);
00142        xoth=xold=x;
00143        yoth=yold=y;
00144        rotact=tanangle((double)(xact-x),(double)(y-yact));
00145        rotold=0;
00146        
00147        invx2=x;
00148        invy2=y;
00149        gdk_draw_line (widgetgrande->window,
00150                      invertgc,
00151                      xact,yact,invx2,invy2);
00152        
00153       }
00154     }
00155   }
00156   
00157   if (event->button==3 && selectedgrande==TRUE){
00158     if (figgrande.piecepos[PIECENBR-1].type==3)
00159       figgrande.piecepos[PIECENBR-1].flipped^=1;
00160     else
00161       figgrande.piecepos[PIECENBR-1].rot=(figgrande.piecepos[PIECENBR-1].rot+TOUR/2)%TOUR;
00162     tandrawselect(0,0,0);
00163   }
00164 
00165   return TRUE;
00166 }
00167 
00168 
00169 gboolean
00170 on_wdrawareagrande_button_release_event (GtkWidget       *widget,
00171                                         GdkEventButton  *event,
00172                                         gpointer         user_data)
00173 {
00174   tanreleaseifrot();
00175 
00176   /* actiongrande=AN_none; dans releaseifrot */
00177 
00178   if ( selpossible && figtabsize ){
00179     tanmaketinytabnotr(&figgrande,tinytabgr);
00180     tantranstinytab(tinytabgr);
00181     if (tantinytabcompare(tinytabgr, tinytabpe, accuracy)){
00182       tanunselect();
00183       selpossible=FALSE;
00184       tansetreussiactual();
00185       tanredrawpetite();
00186       /* hide widget because of gnomecanvaswidget on top of bonus image */
00187       gtk_widget_hide(widgetgrande);
00188       gtk_widget_hide(widgetpetite);
00189       gc_bonus_display( TRUE, BONUS_RANDOM);
00190     }
00191   }
00192 
00193   return TRUE;
00194 }
00195 
00196 
00197 gboolean
00198 on_wdrawareagrande_motion_notify_event (GtkWidget       *widget,
00199                                         GdkEventMotion  *event,
00200                                         gpointer         user_data)
00201 {
00202   int x,y;
00203   GdkModifierType state;
00204   int rot;
00205 
00206   if (event->is_hint)
00207     gdk_window_get_pointer (event->window, &x, &y, &state);
00208   else{
00209     x=event->x;
00210     y=event->y;
00211     state=event->state;
00212   }
00213 
00214   if (actiongrande==AN_move){
00215     tandrawselect(x-xold,y-yold,0);
00216     xold=x;
00217     yold=y;
00218   }
00219 
00220   if (actiongrande==AN_rot){
00221     gdk_draw_line (widgetgrande->window,
00222                  invertgc,
00223                  xact,yact,invx2,invy2);
00224 
00225     rot=(rotact-tanangle((double)(xact-x),(double)(y-yact))+rotstepnbr/2+TOUR*3)%TOUR;
00226     rot=(int)(rot/rotstepnbr)*rotstepnbr;
00227     if (rot!=rotold){
00228       rotold=rot;
00229       tandrawselect(0,0,rot);
00230     }
00231 
00232     invx2=x;
00233     invy2=y;
00234     gdk_draw_line (widgetgrande->window,
00235                  invertgc,
00236                  xact,yact,invx2,invy2);
00237 
00238   }
00239 
00240   return TRUE;
00241 }
00242 
00243 
00244 gboolean
00245 on_wdrawareapetite_configure_event     (GtkWidget       *widget,
00246                                         GdkEventConfigure *event,
00247                                         gpointer         user_data)
00248 {
00249   widgetpetite=widget;
00250   if (!initcbpe)
00251     taninitcbpe();
00252 
00253   if (pixmappetite!=NULL)
00254     gdk_pixmap_unref(pixmappetite);
00255   
00256   pixmappetite = gdk_pixmap_new(widget->window,
00257                             widget->allocation.width,
00258                             widget->allocation.height,
00259                             -1);
00260 
00261   tanredrawpetite();
00262 
00263   return TRUE;
00264 }
00265 
00266 
00267 gboolean
00268 on_wdrawareapetite_expose_event        (GtkWidget       *widget,
00269                                         GdkEventExpose  *event,
00270                                         gpointer         user_data)
00271 {
00272   if (pixmappetite!=NULL)
00273     gdk_draw_pixmap(widget->window,
00274                   widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
00275                   pixmappetite,
00276                   event->area.x, event->area.y,
00277                   event->area.x, event->area.y,
00278                   event->area.width, event->area.height);
00279 
00280   return FALSE;
00281 }
00282 
00283 
00284 gboolean
00285 on_arrow_clicked (GnomeCanvasItem *item, GdkEvent *event, gpointer user_data)
00286 {
00287   if ((event->type == GDK_BUTTON_PRESS)  
00288       && (event->button.button == 1)) {
00289     change_figure((gboolean) GPOINTER_TO_INT(user_data));
00290     return TRUE;
00291   }
00292   return FALSE;
00293   
00294 }
00295 
00296 
00297 gboolean
00298 on_show_clicked (GnomeCanvasItem *canvasitem,
00299                 GdkEvent *event,
00300                 gpointer user_data)
00301 {
00302   if ((event->type == GDK_BUTTON_PRESS)  
00303       && (event->button.button == 1)) {
00304   helptanset = (helptanset+1)%PIECENBR;
00305   tanredrawpetite();
00306   return TRUE;
00307   }
00308   return FALSE;
00309 }
00310 
00311 gboolean
00312 on_outline_clicked (GnomeCanvasItem *canvasitem,
00313                 GdkEvent *event,
00314                 gpointer user_data)
00315 {
00316   if ((event->type == GDK_BUTTON_PRESS)  
00317       && (event->button.button == 1)) {
00318     if(!helpoutset){
00319       helpoutset = TRUE;
00320       tanredrawgrande();
00321     }
00322     return TRUE;
00323   }
00324   return FALSE;
00325 }
00326 
00327 gboolean
00328 on_symetry_clicked (GnomeCanvasItem *canvasitem,
00329                 GdkEvent *event,
00330                 gpointer user_data)
00331 {
00332   if ((event->type == GDK_BUTTON_PRESS)  
00333       && (event->button.button == 1)) {
00334     if (selectedgrande==TRUE){
00335       if (figgrande.piecepos[PIECENBR-1].type==3)
00336        figgrande.piecepos[PIECENBR-1].flipped^=1;
00337       else
00338        figgrande.piecepos[PIECENBR-1].rot=(figgrande.piecepos[PIECENBR-1].rot+TOUR/2)%TOUR;
00339       tandrawselect(0,0,0);
00340       return TRUE;
00341     }
00342   }
00343   return FALSE;
00344 }
00345 
00346 gboolean
00347 on_rotation_clicked (GnomeCanvasItem *canvasitem,
00348                 GdkEvent *event,
00349                 gpointer user_data)
00350 {
00351   if ((event->type == GDK_BUTTON_PRESS)  
00352       && (event->button.button == 1)) {
00353     gint angle = 0;
00354 
00355     if (selectedgrande==TRUE){
00356       switch (GPOINTER_TO_INT(user_data)){
00357       case 0:
00358        angle = -rotstepnbr;
00359        break;
00360       case 1:
00361        angle = rotstepnbr;
00362        break;
00363       case 2:
00364        angle = -4*rotstepnbr;
00365        break;
00366       case 3:
00367        angle = 4*rotstepnbr;
00368        break;
00369       }
00370       figgrande.piecepos[PIECENBR-1].rot += angle;
00371 
00372       tandrawselect(0,0,0);
00373       return TRUE;
00374     }
00375   }
00376   return FALSE;
00377 }
00378