|
-
Jan 9th, 2009, 09:12 AM
#1
Thread Starter
Lively Member
-
Jan 9th, 2009, 02:03 PM
#2
Junior Member
Re: Help with my Grid class
I fixed some part of your code. Here is it... Please try it and let me know.
Thanks,
Code:
Public Sub FillBlock(ByVal X As Single, ByVal Y As Single)
Dim sinX As Single, sinY As Single
sinX = Fix(X / m_BlockWidth) + 1
sinY = Fix(Y / m_BlockHeight) + 1
bytFilled(CLng(sinX), CLng(sinY)) = 1
FillRect m_hDC, udtBlocks(CLng(sinX), CLng(sinY)), lonBrush
End Sub
-
Jan 9th, 2009, 11:29 PM
#3
Thread Starter
Lively Member
Re: Help with my Grid class
 Originally Posted by tfbasta
I fixed some part of your code. Here is it... Please try it and let me know.
Thanks,
Code:
Public Sub FillBlock(ByVal X As Single, ByVal Y As Single)
Dim sinX As Single, sinY As Single
sinX = Fix(X / m_BlockWidth) + 1
sinY = Fix(Y / m_BlockHeight) + 1
bytFilled(CLng(sinX), CLng(sinY)) = 1
FillRect m_hDC, udtBlocks(CLng(sinX), CLng(sinY)), lonBrush
End Sub
Thanks, tf. That fixed the accuracy problem.
Anyone have any ideas about why some blocks appear filled in when resizing?
I think the problem is in the ReDimFilled() sub, which is to redimension the byte array that keeps track of filled blocks, while preserving existingly filled in ones...
-
Jan 15th, 2009, 11:49 AM
#4
Junior Member
Re: Help with my Grid class
Replace your RedimFilled sub with the one below. This should solve your problem.
Code:
Private Sub ReDimFilled(ByVal OldX As Long, ByVal OldY As Long, ByVal NewX As Long, ByVal NewY As Long)
If NewX > 0 And NewY > 0 Then
Dim bytOld() As Byte
Dim lX As Long, lY As Long
bytOld() = bytFilled
ReDim bytFilled(1 To NewX, 1 To NewY) As Byte
For lX = LBound(bytFilled, 1) To UBound(bytFilled, 1)
For lY = LBound(bytFilled, 2) To UBound(bytFilled, 2)
If lX <= UBound(bytOld, 1) And lY <= UBound(bytOld, 2) Then
bytFilled(lX, lY) = bytOld(lX, lY)
Else
bytFilled(lX, lY) = 0
End If
Next
Next
End If
End Sub
Last edited by tfbasta; Jan 15th, 2009 at 11:55 AM.
-
Jan 15th, 2009, 05:48 PM
#5
Thread Starter
Lively Member
Re: Help with my Grid class
Sorry for taking so long to reply. Thanks tfbasta, everything works perfect now.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|