Windows programming

Moderators: None (Apply to moderate this forum)
Number of threads: 3670
Number of posts: 9122

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Grid in window... Posted by Sephiroth on 5 Apr 2001 at 2:12 PM
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.

<br>-Sephiroth

Report
Re: Grid in window... Posted by Sephiroth2 on 6 Apr 2001 at 10:02 AM
: 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.



Report
Re: Grid in window... Posted by Sephiroth on 6 Apr 2001 at 12:19 PM
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!



-Sephiroth


Report
Re: Grid in window... Posted by Sephiroth on 6 Apr 2001 at 3:31 PM
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.



-Sephiroth


Report
Re: Grid in window... Posted by pingpong on 6 Apr 2001 at 9:49 PM
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.
:
: -Sephiroth
:




Report
Re: Grid in window... Posted by ColdShine on 7 Apr 2001 at 2:30 PM
This is just a draft, it may work...
int stepX = <width> / 50;
int stepY = <height> / 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, <height>));
}
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).
________
ColdShine


Report
Re: Grid in window... Posted by Sephiroth on 7 Apr 2001 at 7:13 PM
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'!



-Sephiroth





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.