gamearea.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* $Id: gamearea.c,v 1.16 2001/04/29 22:07:44 kilobug Exp $ */
  2. #include "client.h"
  3. #define ZOOM_ALPHA 40.0
  4. #define ZOOM_BETA 0.4
  5. #define ZOOM_GAMMA 1.5
  6. void gamearea_refresh(GtkWidget *w, conf_t *conf)
  7. {
  8. gdk_draw_rgb_32_image(w->window,
  9. w->style->fg_gc[GTK_STATE_NORMAL],
  10. 0, 0, MAP_SIZE, MAP_SIZE,
  11. GDK_RGB_DITHER_NORMAL,
  12. gen_bigmap(conf, TRUE),
  13. MAP_SIZE * 4);
  14. }
  15. static gint gamearea_expose_event(GtkWidget *w, GdkEventExpose *e,
  16. conf_t *conf)
  17. {
  18. guint offs;
  19. offs = (e->area.x + e->area.y * MAP_SIZE) * 4;
  20. gdk_draw_rgb_32_image(w->window,
  21. w->style->fg_gc[GTK_WIDGET_STATE(w)],
  22. e->area.x, e->area.y,
  23. e->area.width, e->area.height,
  24. GDK_RGB_DITHER_NORMAL,
  25. gen_bigmap(conf, FALSE) + offs,
  26. MAP_SIZE * 4);
  27. return FALSE;
  28. }
  29. GtkWidget *create_game_area(conf_t *conf)
  30. {
  31. GtkWidget *frame, *vbox;
  32. frame = create_frame("Terrain de jeu");
  33. vbox = gtk_vbox_new(FALSE, 0);
  34. gtk_widget_show(vbox);
  35. gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0);
  36. conf->main = gtk_drawing_area_new();
  37. gtk_drawing_area_size(GTK_DRAWING_AREA(conf->main),
  38. MAP_SIZE, MAP_SIZE);
  39. gtk_signal_connect(GTK_OBJECT(conf->main), "expose_event",
  40. (GtkSignalFunc) gamearea_expose_event, conf);
  41. gtk_container_add(GTK_CONTAINER(frame), conf->main);
  42. gtk_widget_show(conf->main);
  43. return vbox;
  44. }
  45. void scroll_bigmap(conf_t *conf, float x, float y)
  46. {
  47. float sx, sy;
  48. float alpha;
  49. int xsize, ysize;
  50. if (conf->map == NULL)
  51. return;
  52. alpha = ZOOM_ALPHA / MAX(conf->map->sizex, conf->map->sizey);
  53. conf->big_zoom = alpha * exp(ZOOM_BETA * conf->log_big_zoom + ZOOM_GAMMA);
  54. conf->mini_center_x = x;
  55. conf->mini_center_y = y;
  56. xsize = conf->map->sizex * conf->big_zoom + 100;
  57. ysize = conf->map->sizey * conf->big_zoom + 100;
  58. sx = x * xsize / MINI_MAP_SIZE - MAP_SIZE / 2;
  59. sy = y * ysize / MINI_MAP_SIZE - MAP_SIZE / 2;
  60. conf->big_ofs_x = CLAMP((int) sx, -50, xsize - MAP_SIZE - 50);
  61. conf->big_ofs_y = CLAMP((int) sy, -50, ysize - MAP_SIZE - 50);
  62. minimap_refresh(conf->mini, conf);
  63. gamearea_refresh(conf->main, conf);
  64. }