-
grid
I'm working on a cellular automata program. (Conway's Game of Life) for example.
Heres a java example: http://hensel.lifepatterns.net/
click on "Enjoy Life" to launch applet.
You can see theres a grid which is clickable.
How would i go about making a grid in win32? Just draw lines and specify xy coordinates for the boxes?
-
That's it. Make a pen, and use LineTo/MoveToEx to do the drawing:
Code:
for(x = startX; x < maxX; x += grid_spread){
MoveToEx(hdc, x, startY);
LineTo(hdc, x, maxY);
}
for(y = startY; y < maxY; y += grid_spread){
MoveToEx(hdc, startX, y);
LineTo(hdc, maxX, y);
}
Hope that helps.
-
What if I load a bitmap of a grid. Could I still make the individual boxes clickable and fillable?
-
I would use an array of RECT's.
Then use PtInRect() and a loop using the array index to work out where has been clicked.
FillRect() Rectangle() FrameRect() ect to draw them again with the loop.
If you use a bitmap then you will have to calculate a scale based on the screen size to image size.
Code:
for(i=0;i<ROWS;i++)
{
for(j=0;j<COLS;j++)
{
if(PtInRect(&(rBoardRect[i][j]),MousePoint))