summaryrefslogtreecommitdiffstats
path: root/draw.c
blob: 11840ee4f719a0a37f9ed635433e2badf57f3e6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "draw.h"
#include "level.h"
#include <gtk/gtk.h>
#include <cairo/cairo.h>


static double scale = 100.0;
static double xTranslate = 0.0, yTranslate = 0.0;

static void room2path(cairo_t *cr, ROOM *room) {
  int i;
  
  
  if(room->nVertices == 0) return;
  
  cairo_move_to(cr, room->vertices[0].x, room->vertices[0].y);
  
  for(i = 1; i < room->nVertices; i++)
    cairo_line_to(cr, room->vertices[i].x, room->vertices[i].y);
  
  cairo_close_path(cr);
}

gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, gpointer data) {
  VERTEX vertices[4] = {{-1,-1}, {-1,1}, {1,1}, {1,-1}};
  ROOM room = {sizeof(vertices)/sizeof(vertices[0]), vertices};
  LEVEL lvl = {1, &room};
  cairo_t *cr;
  int i;
  
  
  cr = gdk_cairo_create(widget->window);
  
  cairo_rectangle(cr, event->area.x, event->area.y, event->area.width, event->area.height);
  cairo_clip(cr);
  
  cairo_translate(cr, getImageWidth()/2-xTranslate, getImageHeight()/2-yTranslate);
  cairo_scale(cr, scale, scale);
  
  cairo_set_line_width(cr, 1.0/scale);
  
  for(i = 0; i < lvl.nRooms; i++)
    room2path(cr, &lvl.rooms[i]);
  
  cairo_set_source_rgba(cr, 0.0, 0.7, 1.0, 0.3);
  cairo_fill_preserve(cr);
  
  cairo_set_source_rgba(cr, 0.0, 0.7, 1.0, 0.7);
  cairo_stroke(cr);
  
  cairo_destroy (cr);
  
  return FALSE;
}

double getScale() {
  return scale;
}

void setScale(double s) {
  scale = s;
}

double getImageWidth() {
  return 5*scale;
}

double getImageHeight() {
  return 5*scale;
}

double getXTranslate() {
  return xTranslate;
}

void setXTranslate(double x) {
  xTranslate = x;
}

double getYTranslate() {
  return yTranslate;
}

void setYTranslate(double y) {
  yTranslate = y;
}