grid

This is a discussion on grid within the Windows Programming forums, part of the Platform Specific Boards category; 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 ...

  1. #1
    Registered User xlnk's Avatar
    Join Date
    Mar 2002
    Posts
    186

    Question 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?
    the best things in life are simple.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,643
    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.
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  3. #3
    Registered User xlnk's Avatar
    Join Date
    Mar 2002
    Posts
    186
    What if I load a bitmap of a grid. Could I still make the individual boxes clickable and fillable?
    the best things in life are simple.

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    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))
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. More Windows Trouble
    By samGwilliam in forum Windows Programming
    Replies: 9
    Last Post: 04-12-2005, 10:02 AM
  2. Cleaning up a Grid of Memory
    By Epo in forum C++ Programming
    Replies: 9
    Last Post: 02-25-2005, 09:23 AM
  3. Find a word in a 2d grid
    By The_Kingpin in forum C++ Programming
    Replies: 2
    Last Post: 02-24-2005, 04:38 PM
  4. Constructive Feed Back (Java Program)
    By xddxogm3 in forum Tech Board
    Replies: 12
    Last Post: 10-10-2004, 03:41 AM
  5. I need help making a grid!
    By Unregistered in forum Windows Programming
    Replies: 2
    Last Post: 09-02-2002, 05:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21