Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 Use GDI32 functions in fixed scale forms

Note: You must be registered in order to post a reply.

Screensize:
UserName:
Password:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkInsert EmailInsert Image Insert CodeInsert QuoteInsert List Spell Checker
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

   Insert an File
Check here to include your profile signature.
Check here to subscribe to this topic.
    

T O P I C    R E V I E W
Sion Posted - Aug 09 2004 : 12:24:47 PM
Okay, the title may be a bit cryptic but it's hard to explain my question in a sentence that short.

I have a form where ScaleMode is vbUser. The scale could for instance be 100 wide and 100 heigh, with left and top set to 0.
In this form I would like to use some of the GDI32 functions such as "Polygon" and "Polyline" to paint on the form. But all the GDI32 functions are operating in pixels and dosn't take the custom form scale into account.
I've tried to convert the custom scale values of the polygon into pixel values with the following code:

  
Private Sub DrawPoly(poly() As Coord)  
    Dim ix As Integer
    'Converts custom scale to pixels  
    For ix = LBound(poly) To UBound(poly)  
      poly(ix).X = Me.ScaleLeft + (poly(ix).X - 5) * (((Me.Width / Screen.TwipsPerPixelX) / (Me.ScaleWidth - Me.ScaleLeft)))  
      poly(ix).Y = Me.ScaleTop + poly(ix).Y * (((Me.Height / Screen.TwipsPerPixelY) / (Me.ScaleHeight - Me.ScaleTop)))  
    Next ix  
  
    'Polygon function creates unfilled polygon on screen.  
    Polygon Me.hDC, poly(1), UBound(poly)  
End Sub
  


But it dosn't work very well. It's not very precise, and when the form is resized it becomes less and less precise. Isn't there a way (or prehabs a API call) to make a stable conversion from a custom scale to a pixel scale?

Thanks in advance
5   L A T E S T    R E P L I E S    (Newest First)
Eric Coleman Posted - Aug 18 2004 : 12:22:15 PM
That's a great tip! Thanks for sharing.
Sion Posted - Aug 18 2004 : 09:33:58 AM
I ran a bit low on clock cycles in my game, and found a lot of wasted cycles in this rutine. Instead of using the code as presented in my last post directly, it should be rearranged to be more efficiant.
  
    Dim XScale As Single, YScale As Single
    XScale = Object.ScaleX(1, vbUser, vbPixels)  
    YScale = Object.ScaleY(1, vbUser, vbPixels)  
  
    LOOP
        poly(ix).x = (poly(ix).x - Object.ScaleLeft) * XScale  
        poly(ix).y = (poly(ix).y - Object.ScaleTop) * YScale  
    END LOOP
  


Using the above approach I managed to reduce the cycle usage by ~40%. I ran both versions 2000 times on a polygon with 60 sides. First approach took ~2700ms and second approach took ~1650ms. That's 44,444.44 calculations per second compared to 72,727.27
Sion Posted - Aug 09 2004 : 2:03:45 PM
For completeness here is the same code Eric posted, but also taking Object.ScaleLeft and Object.ScaleTop into account.

  
  poly(ix).x = Object.ScaleX(poly(ix).x - Object.ScaleLeft, vbUser, vbPixels)  
  poly(ix).y = Object.ScaleY(poly(ix).y - Object.ScaleTop, vbUser, vbPixels)  
  
Sion Posted - Aug 09 2004 : 1:36:16 PM
And once again Eric Coleman comes to the rescue!™

So simple and elegant... Guess I couldn't see the forest for trees or however the saying goes.
However, when I first tried it it didn't work. I realized that it - for some reason - only works if the scale is reset each time the object is resized. But now it works! Yeah!
EDIT: I didn't think straight when I tried it out - the scale must always be reset in order for the custom scale to work. That's common pratice. I'd actually done that in the game I should use this for... Phew, must be the heat

Mr. Coleman is now officially my programming rolemodel.
Eric Coleman Posted - Aug 09 2004 : 1:06:47 PM
Use ScaleX and ScaleY.

poly(ix).X = Object.ScaleX(poly(ix).X, vbUser, vbPixels)
poly(ix).Y = Object.ScaleY(poly(ix).Y, vbUser, vbPixels)

Object can be the form, a picturebox, the printer, or a user control.

VBGamer © Go To Top Of Page
This page was generated in 0.11 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.