static int scale_drag_event(GooCanvasItem *w, GooCanvasItem *target, GdkEvent *event, ScaleItem *scale) { double x, y; double item_x, item_y; if(answer_string) // disable, waiting a answer return FALSE; switch(event->type) { case GDK_BUTTON_PRESS: gc_drag_offset_save(event); goo_canvas_item_raise(goo_canvas_item_get_parent(scale->item), NULL); goo_canvas_item_raise(scale->item, NULL); break; case GDK_MOTION_NOTIFY: gc_drag_item_move(event, NULL); break; case GDK_BUTTON_RELEASE: { int plate; item_x = event->button.x; item_y = event->button.y; goo_canvas_convert_from_item_space(goo_canvas_item_get_canvas(w), scale->item, &item_x, &item_y); x = item_x; y = item_y; goo_canvas_convert_to_item_space(goo_canvas_item_get_canvas(w), group_g, &x, &y); if( -ITEM_W < x && x < PLATE_W + ITEM_W && abs(y - PLATE_Y) < ITEM_H) plate = 1; else { x = item_x; y = item_y; goo_canvas_convert_to_item_space(goo_canvas_item_get_canvas(w), group_d, &x, &y); if( -ITEM_W < x && x < PLATE_W + ITEM_W && abs(y - PLATE_Y) < ITEM_H) plate = -1; else plate=0; } scale_item_move_to(scale, plate); } break; default: break; } return FALSE; }
/* ==================================== */ static gint item_event(GooCanvasItem *item, GooCanvasItem *target, GdkEvent *event, PieceItem *data) { double item_x, item_y; if(!gcomprisBoard) return FALSE; if(board_paused) return FALSE; if(data && !data->on_top) return FALSE; switch (event->type) { case GDK_ENTER_NOTIFY: g_object_set(item, "stroke-color", "white", "line-width", (double)3, NULL); break; case GDK_LEAVE_NOTIFY: g_object_set(item, "stroke-color", "black", "line-width", (double)1, NULL); break; case GDK_BUTTON_PRESS: switch(event->button.button) { case 1: gc_sound_play_ogg ("sounds/bleep.wav", NULL); gc_drag_offset_save(event); goo_canvas_item_raise(data->group, NULL); break; } break; case GDK_MOTION_NOTIFY: gc_drag_item_move(event, data->group); break; case GDK_BUTTON_RELEASE: { gint i; gint tmpi, tmpj; double tmpx, tmpy; PieceItem *piece_src; PieceItem *piece_dst; gint col = 0, line; item_x = event->button.x; item_y = event->button.y; goo_canvas_convert_from_item_space(goo_canvas_item_get_canvas(item), item, &item_x, &item_y); /* Search the column (x) where this item is ungrabbed */ for(i=0; i<=number_of_item_x; i++) if(position[i][0]->x < item_x && position[i+1][0]->x > item_x) col = i; /* Bad drop / Outside of column area */ /* Bad drop / On the same column */ if(col<0 || col > number_of_item_x || col == data->i) { gc_sound_play_ogg ("sounds/eraser2.wav", NULL); /* Return to the original position */ gc_item_absolute_move (data->group, data->x , data->y); return FALSE; } /* Now search the free line (y) */ line = number_of_item_y; for(i=number_of_item_y-1; i>=0; i--) if(position[col][i]->color == -1) line = i; /* Bad drop / Too many pieces here */ if(line >= number_of_item_y) { gc_sound_play_ogg ("sounds/eraser2.wav", NULL); /* Return to the original position */ gc_item_absolute_move (data->group, data->x , data->y); return FALSE; } /* Update ontop values for the piece under the grabbed one */ if(data->j>0) position[data->i][data->j-1]->on_top = TRUE; /* Update ontop values for the piece under the ungrabbed one */ if(line>0) position[col][line-1]->on_top = FALSE; /* Move the piece */ piece_dst = position[col][line]; piece_src = data; gc_item_absolute_move (data->group, piece_dst->x , piece_dst->y); gc_sound_play_ogg ("sounds/scroll.wav", NULL); /* Swap values in the pieces */ tmpx = data->x; tmpy = data->y; piece_src->x = piece_dst->x; piece_src->y = piece_dst->y; piece_dst->x = tmpx; piece_dst->y = tmpy; tmpi = data->i; tmpj = data->j; position[tmpi][tmpj]->i = piece_dst->i; position[tmpi][tmpj]->j = piece_dst->j; piece_dst->i = tmpi; piece_dst->j = tmpj; position[piece_src->i][piece_src->j] = piece_src; position[piece_dst->i][piece_dst->j] = piece_dst; // dump_solution(); if(is_completed()) { gamewon = TRUE; hanoi_destroy_all_items(); gc_bonus_display(gamewon, GC_BONUS_SMILEY); } } break; default: break; } return FALSE; }