Grid in window... - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Grid in window...

SephirothSephiroth Fayetteville, NC, USAPosts: 1,035Member
I am creating a nice level editor for my game now, and I need to draw a 50x50 square grid in four of my child windows. How could I do this considering the fact that the window size could change on a different users computer? My current formula is below, but it will NOT work!

RECT pr;
GetClientRect(GetDlgItem(pwnd, ID_DATAVIEW), &pr);

for(int loop = 1; loop < 51; loop++)
{
MoveToEx(screen, (pr.right / 50) * loop, 0, NULL);
LineTo(screen, (pr.right / 50) * loop, pr.bottom);
MoveToEx(screen, 0, (pr.bottom / 50) * loop, NULL);
LineTo(screen, pr.right, (pr.bottom / 50) * loop);
}

I thought that would work, but it doesn't. Any ideas? Thanks to any and all who help.


-[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red]

Comments

  • Sephiroth2Sephiroth2 Posts: 423Member
    : I am creating a nice level editor for my game now, and I need to draw a 50x50 square grid in four of my child windows. How could I do this considering the fact that the window size could change on a different users computer? My current formula is below, but it will NOT work!
    :
    : RECT pr;
    : GetClientRect(GetDlgItem(pwnd, ID_DATAVIEW), &pr);
    :
    : for(int loop = 1; loop < 51; loop++)
    : {
    : MoveToEx(screen, (pr.right / 50) * loop, 0, NULL);
    : LineTo(screen, (pr.right / 50) * loop, pr.bottom);
    : MoveToEx(screen, 0, (pr.bottom / 50) * loop, NULL);
    : LineTo(screen, pr.right, (pr.bottom / 50) * loop);
    : }
    :
    Your code is faulty because the order of the calculations is incorrect.
    Use pr.right*loop/50 or you'll have problem.



  • SephirothSephiroth Fayetteville, NC, USAPosts: 1,035Member
    OK, I'll try that when I get home. I'm playing with the T1 here at work now (=. The way I was thinking was this:

    Width of window / 50 pixels == Exact length of each grid
    Exact length of each grid * Loop == Where to draw line

    Never even thought about using a decimal answer since it will give me a more accurate position. Thanks for the help man!



    -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red]


  • SephirothSephiroth Fayetteville, NC, USAPosts: 1,035Member
    No go. The formula you gave me doesn't draw anything in the window :/. I have another idea, and I'll try it now. If you have any other ideas, lemme' know.



    -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red]


  • pingpongpingpong Posts: 937Member
    warning: not compiled

    #define ROWS 50
    #define COLS 50

    void DrawGrid(HDC hdc, const RECT* rect)
    {
    for(int x = 0; x < COLS; x++)
    {
    MoveToEx(hdc, x, 0, NULL);
    LineTo(hdc, x, rect->bottom);
    }
    for(int y = 0; y < ROWS; y++)
    {
    MoveToEx(hdc, 0, y, NULL);
    LineTo(hdc, rect->right, y, NULL);
    }
    }

    and some other not compiled code...
    void HitTest(int x, int y, const RECT* rect, int *row, int *col)
    {
    *col = MulDiv(x, COLS, rect->right);
    *row = MulDiv(y, ROWS, rect->bottom);
    }


    : I am creating a nice level editor for my game now, and I need to draw a 50x50 square grid in four of my child windows. How could I do this considering the fact that the window size could change on a different users computer? My current formula is below, but it will NOT work!
    :
    : RECT pr;
    : GetClientRect(GetDlgItem(pwnd, ID_DATAVIEW), &pr);
    :
    : for(int loop = 1; loop < 51; loop++)
    : {
    : MoveToEx(screen, (pr.right / 50) * loop, 0, NULL);
    : LineTo(screen, (pr.right / 50) * loop, pr.bottom);
    : MoveToEx(screen, 0, (pr.bottom / 50) * loop, NULL);
    : LineTo(screen, pr.right, (pr.bottom / 50) * loop);
    : }
    :
    : I thought that would work, but it doesn't. Any ideas? Thanks to any and all who help.
    :
    : -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red]
    :




  • ColdShineColdShine Posts: 597Member
    This is just a draft, it may work...[code]int stepX = / 50;
    int stepY = / 50;
    int x = stepX, y = stepY;
    for (int loop = 1; loop <= 50; ++loop, x += stepX, y += stepY)
    {
    MoveToEx(screen, 0, y, NULL);
    LineTo (screen, <width>, y);
    MoveToEx(screen, x, 0, NULL);
    LineTo (screen, x, ));
    }[/code]This should draw 49 parallel lines as you want to do. The resulting size, however, will be rounded up to a multiple of 50 (if want better, use floats).
    ________
    [size=1][b][grey]Cold[/grey][blue]Shine[/blue][/b][/size]


  • SephirothSephiroth Fayetteville, NC, USAPosts: 1,035Member
    Thanks, but I figured it out. Here's the basic run-down:

    RECT pr;

    for(int loop = (pr.right / 50); loop < pr.right; pr.right += (pr.right / 50))
    {
    MoveToEx(screen, loop, 0, NULL);
    LineTo(screen, loop, pr.bottom);
    MoveToEx(screen, 0, loop, NULL);
    LineTo(screen, pr.right, loop);
    }

    A bit more simple than I thought. Thanks for the help though, I got the idea from the examples you showed me. Thanks to all of ya'!



    -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red]


Sign In or Register to comment.