[cairo-commit] cairo-demo/gameoflife cgolwin.cpp,1.3,1.4 cgolwin.h,1.1,1.2 ctk.cpp,1.1,1.2 ctk.h,1.1,1.2 main.cpp,1.1,1.2
Andrew Chant
commit at pdx.freedesktop.org
Mon Nov 24 23:13:19 PST 2003
- Previous message: [cairo-commit] rcairo/src cairo.c,1.3,1.4 image.c,1.2,1.3 rbcairo.h,1.1,1.2 xlib.c,1.1,1.2
- Next message: [cairo-commit] libic ChangeLog,1.27,1.28 configure.in,1.14,1.15
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Committed by: chant
Update of /cvs/cairo/cairo-demo/gameoflife
In directory pdx:/tmp/cvs-serv23611
Modified Files:
cgolwin.cpp cgolwin.h ctk.cpp ctk.h main.cpp
Log Message:
Attempt to add circle drawing by first drawing to anotehr surface
then using surface_show.
view the problem with cgol -s. can't figure out scaling.
all relevant code in cgolwin.cpp function gameoflifeWin::render
Index: cgolwin.cpp
===================================================================
RCS file: /cvs/cairo/cairo-demo/gameoflife/cgolwin.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** cgolwin.cpp 25 Nov 2003 04:22:03 -0000 1.3
--- cgolwin.cpp 25 Nov 2003 07:13:17 -0000 1.4
***************
*** 31,35 ****
using std::cout;
! gameoflifeWin::gameoflifeWin(Ctkapp * app, int wi, int h, int r, int c)
:Ctkwin(app,wi,h)
{
--- 31,35 ----
using std::cout;
! gameoflifeWin::gameoflifeWin(Ctkapp * app, int wi, int h, int r, int c, bool s)
:Ctkwin(app,wi,h)
{
***************
*** 38,41 ****
--- 38,42 ----
width = wi;
height = h;
+ use_cairo_show_surface = s;
game = new gameoflife(rows, cols);
***************
*** 103,107 ****
{
cairo_default_matrix(cr);
! cairo_scale(cr, (double)width/(double)cols,(double)height/(double)rows); // I hope this goes the right way..
cairo_set_line_width(cr, 0.1); // set to one tenth of a unit... will that be row or col?
radius = 0.5; // so, the edges of circles in connecting cells should just touch.
--- 104,108 ----
{
cairo_default_matrix(cr);
! cairo_scale(cr, (double)width/(double)cols,(double)height/(double)rows);
cairo_set_line_width(cr, 0.1); // set to one tenth of a unit... will that be row or col?
radius = 0.5; // so, the edges of circles in connecting cells should just touch.
***************
*** 112,127 ****
XFillRectangle(dpy, grid, gc, 0, 0, width, height);
! /* needs work
! if (use_cairo_show_surface)
! {
! cellpix = XCreatePixmap(dpy, w, ceil(cellwidth),
! ceil(cellheight), DefaultDepth(dpy, DefaultScreen(dpy)));
surface = cairo_xlib_surface_create(dpy, cellpix,
DefaultVisual(dpy, DefaultScreen(dpy)),
! 0, DefaultColormap(dpy, DefaultScreen(dpy)));
if (surface == NULL)
exit(1); // no mem
}
! */
cairo_set_target_drawable(cr, dpy, grid);
--- 113,136 ----
XFillRectangle(dpy, grid, gc, 0, 0, width, height);
! if (use_cairo_show_surface) // Broken
! { //todo : fix mem leak here
! cairo_save(cr);
! cairo_default_matrix(cr);
! cairo_scale(cr,50,50);
! cellpix = XCreatePixmap(dpy, w, 50,
! 50, DefaultDepth(dpy, DefaultScreen(dpy)));
! XFillRectangle(dpy, cellpix, gc, 0, 0, 50, 50);
surface = cairo_xlib_surface_create(dpy, cellpix,
DefaultVisual(dpy, DefaultScreen(dpy)),
! CAIRO_FORMAT_RGB24, DefaultColormap(dpy, DefaultScreen(dpy)));
if (surface == NULL)
exit(1); // no mem
+ cairo_set_target_surface(cr, surface);
+ cairo_set_rgb_color(cr,0,0,0);
+ cairo_arc(cr, .5, .5, .5, 0, 2*M_PI);
+ cairo_fill(cr);
+ cairo_restore(cr);
}
!
cairo_set_target_drawable(cr, dpy, grid);
***************
*** 157,171 ****
if (i->dna & G1) green += .50;
if (i->dna & G2) green += .25;
! /* needs work...
if (use_cairo_show_surface)
{
! // .. ok , gen surface
! cairo_show_surface(cr, surface, cellwidth, cellheight);
}
else
! { */
! cairo_set_rgb_color(cr, red, green, blue);
! cairo_arc(cr, i->x + .5, i->y + .5, radius, 0, 2*M_PI);
! cairo_fill(cr);
}
cairo_set_rgb_color(cr, 0, 0, 0);
--- 166,182 ----
if (i->dna & G1) green += .50;
if (i->dna & G2) green += .25;
!
if (use_cairo_show_surface)
{
! //Note: broken
! cairo_move_to(cr, i->x, i->y);
! cairo_show_surface(cr, surface, 1, 1);
}
else
! {
! cairo_set_rgb_color(cr, red, green, blue);
! cairo_arc(cr, i->x + .5, i->y + .5, radius, 0, 2*M_PI);
! cairo_fill(cr);
! }
}
cairo_set_rgb_color(cr, 0, 0, 0);
Index: cgolwin.h
===================================================================
RCS file: /cvs/cairo/cairo-demo/gameoflife/cgolwin.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** cgolwin.h 25 Nov 2003 02:06:56 -0000 1.1
--- cgolwin.h 25 Nov 2003 07:13:17 -0000 1.2
***************
*** 27,31 ****
{
public:
! gameoflifeWin(Ctkapp *, int, int, int, int);
void event(XEvent *);
static void advanceTimer(void *);
--- 27,31 ----
{
public:
! gameoflifeWin(Ctkapp *, int, int, int, int, bool);
void event(XEvent *);
static void advanceTimer(void *);
***************
*** 40,43 ****
--- 40,45 ----
Pixmap grid, buffer, cellpix;
cairo * cr;
+ cairo_surface * surface;
+ bool use_cairo_show_surface;
int rows, cols, width, height;
double cellheight, cellwidth;
Index: ctk.cpp
===================================================================
RCS file: /cvs/cairo/cairo-demo/gameoflife/ctk.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** ctk.cpp 25 Nov 2003 02:06:56 -0000 1.1
--- ctk.cpp 25 Nov 2003 07:13:17 -0000 1.2
***************
*** 1,6 ****
/* ctk.cpp
* - implementation of ctk
! * 'crappy toolkit'
! * s/crappy/chant
* (c) 2003 Andrew Chant
* licensed under GPL
--- 1,5 ----
/* ctk.cpp
* - implementation of ctk
! * homebrew toolkit
* (c) 2003 Andrew Chant
* licensed under GPL
Index: ctk.h
===================================================================
RCS file: /cvs/cairo/cairo-demo/gameoflife/ctk.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** ctk.h 25 Nov 2003 02:06:56 -0000 1.1
--- ctk.h 25 Nov 2003 07:13:17 -0000 1.2
***************
*** 1,5 ****
/* ctk.h -
! * - description of 'crappy toolkit' classes
! * s/crappy/chant
* (c) 2003 Andrew Chant
* licensed under GPL
--- 1,4 ----
/* ctk.h -
! * - description of homebrew toolkit classes
* (c) 2003 Andrew Chant
* licensed under GPL
Index: main.cpp
===================================================================
RCS file: /cvs/cairo/cairo-demo/gameoflife/main.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** main.cpp 25 Nov 2003 02:06:56 -0000 1.1
--- main.cpp 25 Nov 2003 07:13:17 -0000 1.2
***************
*** 27,31 ****
void usage(char * name)
{
! std::cout << "Usage: " << name << " [-w width] [-h height] [-c columns] [-r rows]\n";
}
--- 27,31 ----
void usage(char * name)
{
! std::cout << "Usage: " << name << " [-w width] [-h height] [-c columns] [-r rows] [-s (use show surface)]\n";
}
***************
*** 38,41 ****
--- 38,42 ----
char action;
int traverse = 0;
+ bool s = false;
while (++traverse < argc)
***************
*** 79,82 ****
--- 80,86 ----
cols = atoi(argv[traverse]);
break;
+ case 's':
+ s = true;
+ break;
default:
usage(argv[0]);
***************
*** 88,92 ****
Ctkapp myapp;
! gameoflifeWin mywin(&myapp,width,height, rows, cols);
myapp.go();
return 0;
--- 92,96 ----
Ctkapp myapp;
! gameoflifeWin mywin(&myapp,width,height, rows, cols, s);
myapp.go();
return 0;
- Previous message: [cairo-commit] rcairo/src cairo.c,1.3,1.4 image.c,1.2,1.3 rbcairo.h,1.1,1.2 xlib.c,1.1,1.2
- Next message: [cairo-commit] libic ChangeLog,1.27,1.28 configure.in,1.14,1.15
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the cairo-commit
mailing list