-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyDrawing.cpp
49 lines (40 loc) · 1.04 KB
/
MyDrawing.cpp
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
#include "MyDrawing.hpp"
#include <cairomm/context.h>
#include <giomm/resource.h>
#include <gdkmm/general.h> // set_source_pixbuf()
#include <glibmm/fileutils.h>
#include <iostream>
MyArea::MyArea()
{
}
MyArea::~MyArea()
{
}
void MyArea::set_gol(GameOfLife *agol){
gol = agol;
}
void MyArea::gol_evolve(int verbose){
gol->evolve(verbose);
}
bool MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
{
Gtk::Allocation allocation = get_allocation();
const int width = allocation.get_width();
const int height = allocation.get_height();
int asize = gol->get_square_size();
float fullsize = asize * 10.0;
set_size_request(fullsize, fullsize);
cr->scale(fullsize, fullsize);
cr->set_source_rgb (0, 0, 0);
for (int y = 0; y < asize; y++) {
for (int x = 0; x < asize; x++) {
if(gol->get_module(x, y)){
cr->rectangle ((1.0+x)/(1.0 + asize),
(1.0+y)/(1.0 + asize),
1.0/asize, 1.0/asize);
}
}
}
cr->fill ();
return true;
}