ForceQVGA without pixel doubling and QVGA icon!

Discussion in 'Code Samples & Tips' started by N1c0_ds, Dec 21, 2008.

  1. N1c0_ds

    N1c0_ds Active Member Licensed User

    So here's the problem: You want your items to show exactly the same way on VGA and QVGA screens but Force QVGA just stretches controls on VGA screens and make images pixelated. However drawing every control based on screen resolution is a waste of time and reduces the speed of your application:
    If [I](the screen is QVGA)[/I] then
    "Form1","Button1",5,5,100,25,"Click me")
    Else If (the screen is VGA) Then
    "Form1","Button1",10,10,200,50,"Click me")
    End If
    How can you double your control sizes without requiring "If Then Else" statements for everything you draw? Erel has already proposed a solution but it doesn't work when drawing stuff at runtime (AddButton, DrawImage, Drawstring...). Here's how I did it for Gecko after much thinking and some swearing:

    1-Get the screen resolution
    There are many ways to do this. It doesn't matter to know the exact resolution, since all you want to know is whether you will double controls size or not. If Form.Height is bigger than 400, it's VGA. You can also use the Display control from ControlsExDevice or the dzHW library to get more detailed information.

    Once this is done, you need to add the following code in your application:
    Sub Globals

    Sub App_Start
    'Do your stuff
    End Sub

    Sub SetControlSize
    If Form1.Height>400 Then
    2 '(yes, 2)
    End If
    End Sub
    2-Add compatibility to the controls you want to resize by changing from:

    If VGA=2, control sizes will be doubled. Otherwise, they'll stay the same size. It only requires a few extra lines and avoids the pixel doubling of ForceQVGA

    If you get the full screen size (and not form.height) to check if it's VGA, be careful! Some libraries will return the full screen size on the desktop version so go to Designer>(any form)>Tools>Screen size and type in a VGA resolution. The font sizes will still look small, but on the device they are the same size as with Force QVGA
    Last edited: Dec 21, 2008
  2. Cableguy

    Cableguy Expert Licensed User

    Not putting you down, but your solution is just about the same as EREL's proposal or mine, with the AutoAdjust module...
    It all works around a "Scale" factor, you just implemented it in a diferent way...
    But it is a nice way of thinking...And all solution can be merged into one, to rearrange both designer created as well as runtime created controls...
  3. N1c0_ds

    N1c0_ds Active Member Licensed User

    AutoAdjust? I had not seen this.

    My app has around 3 controls created at the beginning and between 50 and 100 controls and strings created at runtime so I really needed an efficient solution! By creating stuff at runtime I can show a "Loading..." screen early and resize them to fit the screen size right at the begining.

    Also, I could easily "turn off" VGA resizing by adding a VGAFonts variable and multiplying the fontsize property by it:

    If VGA=2 'If it's VGA and I want to force high resolution
     VGAFonts= 1/VGA 'Either 1 or 0.5
     VGA=1 'Display tiny controls
    End If

    9*VGAFont) 'Tiny fonts

    I love programming! :sign0060:
  4. Cableguy

    Cableguy Expert Licensed User

  5. N1c0_ds

    N1c0_ds Active Member Licensed User

    Great idea, but not good for my application. There is a top and bottom bar that is the same height on 240x240 and 320x320. Proportions would not work for this. ;)
  6. Erel

    Erel Administrator Staff Member Licensed User

    Thank you for sharing this :sign0188:
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice