Results 1 to 14 of 14

Thread: Draw it Symmetrically (Resolved)

  1. #1

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192

    Resolved Draw it Symmetrically (Resolved)

    I am drawing a trapezoid using regions... But the problem is that it isn't symmetrical.. What am I doing wrong?

    VB Code:
    1. Option Explicit
    2.  
    3. Private Type COORD
    4.  x As Long
    5.  y As Long
    6. End Type
    7.  
    8. Dim Region() As COORD
    9. Dim iXBorder As Long
    10. Dim iYBorder As Long
    11.  
    12. Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As Any, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
    13. Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
    14. Private Declare Function Polygon Lib "gdi32" (ByVal hdc As Long, lpPoint As Any, ByVal nCount As Long) As Long
    15. Private Declare Function GetStockObject Lib "gdi32" (ByVal nIndex As Long) As Long
    16. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    17.  
    18. Const ALTERNATE = 1 ' ALTERNATE and WINDING are
    19. Const WINDING = 2 ' constants for FillMode.
    20. Const BLACKBRUSH = 4 ' Constant for brush type.
    21.  
    22. Private Sub drawTrapezoid(x As Long, y As Long, Width As Long, Height As Long)
    23.  Width = Width - iXBorder
    24.  
    25.  ReDim Preserve Region(1 To 4)
    26.  Dim NumCoords As Long, hBrush As Long, hRgn As Long
    27.  
    28.  ' Number of vertices in polygon.
    29.  NumCoords = 4
    30.  
    31.  With Region(1)
    32.   .x = x + iXBorder
    33.   .y = y
    34.  End With
    35.  With Region(2)
    36.   .x = x
    37.   .y = y + Height
    38.  End With
    39.  With Region(3)
    40.   .x = x + iXBorder + Width
    41.   .y = y + Height
    42.  End With
    43.  With Region(4)
    44.   .x = x + Width
    45.   .y = y
    46.  End With
    47.  
    48.  hBrush = GetStockObject(BLACKBRUSH)
    49.  ' Creates region to fill with color.
    50.  hRgn = CreatePolygonRgn(Region(1), NumCoords, ALTERNATE)
    51.  ' If the creation of the region was successful then color.
    52.  If hRgn Then
    53.   Dim Ret As Long
    54.   Ret = SetWindowRgn(Me.hWnd, hRgn, True)
    55.  End If
    56.    
    57.  DeleteObject hRgn
    58. End Sub
    59.  
    60. Private Sub Form_Load()
    61.  iXBorder = 10
    62.  drawTrapezoid 40, 40, ScaleX(1995, vbTwips, vbPixels), ScaleX(285, vbTwips, vbPixels)
    63. End Sub

    Let me show what i mean:
    Attached Images Attached Images  
    Last edited by Tec-Nico; Oct 3rd, 2004 at 01:49 PM.
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  2. #2
    Addicted Member
    Join Date
    Jun 2004
    Location
    USA
    Posts
    172
    Its where you have the -0.5. I don't see anywhere that xBorder is equal to 1.

  3. #3

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192
    Thank you for your reply. I am sorry, I was desperate and so I was changing the code before posting it... Please copy it to a form and run it.. You will see the trapezoid that appears is not symmetric even when the points tell it should be.

    Also, iXBorder is set to 10 in FormLoad.
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    do you mean to have 2 ScaleX, not X and Y???

  5. #5
    Addicted Member
    Join Date
    Jun 2004
    Location
    USA
    Posts
    172
    VB Code:
    1. With Region(1)
    2.   .x = x + iXBorder
    3.   .y = y
    4.  End With
    5.  With Region(2)
    6.   .x = x
    7.   .y = y + Height
    8.  End With
    9.  With Region(3)
    10.   .x = x + Width
    11.   .y = y + Height
    12.  End With
    13.  With Region(4)
    14.   .x = (x + Width) - iXBorder
    15.   .y = y
    16.  End With

    works for me.

  6. #6
    Addicted Member
    Join Date
    Jun 2004
    Location
    USA
    Posts
    172
    Originally posted by dglienna
    do you mean to have 2 ScaleX, not X and Y???
    It really doesn't matter. Twips are the same per pixel x and y.

  7. #7
    Hyperactive Member Vishalgiri's Avatar
    Join Date
    Oct 2003
    Location
    India
    Posts
    345
    wow it is very nice custom type cord and arry of cord makes Region!! realy impressive
    Regards,
    Vishalgiri Goswami
    Gujarat, ( INDIA ).
    ---------------------

  8. #8

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192
    dglienna, I am using twips for all, that's why I make the conversions... xjake, I will try your code... It is strange because it gets symmetrical if you add a 1 to the last coordinate.
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  9. #9

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192
    Thanks, Vishalgiri... But the credit is for si_geek, I found a skelleton of the code that is like the one I am using and I just adapted it to my needs.

    I just added the coordinates for a trapezoid and the API for making the form have the shape of the region. And I also made it a call for drawing (I think I will generalize it later when I have time)
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  10. #10

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192
    xjake, your code has the same problem my original does... Let me show you:
    Attached Images Attached Images  
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  11. #11

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192
    This code works... But.. Why?

    (My old version):


    VB Code:
    1. With Region(1)
    2.   .x = x + iXBorder
    3.   .y = y
    4.  End With
    5.  With Region(2)
    6.   .x = x
    7.   .y = y + Height
    8.  End With
    9.  With Region(3)
    10.   .x = x + iXBorder + Width
    11.   .y = y + Height
    12.  End With
    13.  With Region(4)
    14.   .x = x + Width [B]+ 1[/B]
    15.   .y = y [B]+ 1[/B]
    16.  End With

    xjake's version
    VB Code:
    1. With Region(1)
    2.   .x = x + iXBorder
    3.   .y = y
    4.  End With
    5.  With Region(2)
    6.   .x = x
    7.   .y = y + Height
    8.  End With
    9.  With Region(3)
    10.   .x = x + Width
    11.   .y = y + Height
    12.  End With
    13.  With Region(4)
    14.   .x = (x + Width) - iXBorder [B]+ 1[/B]
    15.   .y = y [B]+ 1[/B]
    16.  End With
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  12. #12

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192
    No idea? This is about to be solved... I just want to know why I have to add 1 to both of the coordinates..
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  13. #13
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    Hmm, well, what comes to mind is: if the coordinates were exact same and you were trying to draw something of 1 x 1 pixel, nothing would appear because the size would be 0 x 0. So you have to add one to the coordinates so that the size would be 1 x 1.

    Does this make sense? I'm just about to go to sleep so the quality of the explanation is what it is...
    Last edited by Merri; Aug 27th, 2004 at 06:57 PM.

  14. #14

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192
    Thanks Merri, now it makes perfect sense to me.

    We need to add one more to delimitate it properly and thus be able to make regions that will be 1 x 1 pixels, if it wasn't like that we would have them of 0 x 0 instead.
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width