Author Topic: Bordersize and Titlebar Height  (Read 9824 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Bordersize and Titlebar Height
« on: January 31, 2019, 12:24:47 pm »
Looking over a few old programs on my drive, I came across one which gave me the border size and title bar height for my program, and I thought I'd share:

Code: QB64: [Select]
  1.     FUNCTION glutGet& (BYVAL what&)
  2.  
  3. _SCREENMOVE 200, 200 'We moved our screen to 200,200 so we know these values are correct
  4. BorderWidth = glutGet(506)
  5. TitleBarHeight = glutGet(507)
  6. ActualScreenX = glutGet(100)
  7. ActualScreenY = glutGet(101)
  8.  
  9. PRINT "Actual Top Left of screen is at ("; _SCREENX; ","; _SCREENY; ")"
  10. PRINT "The border is "; BorderWidth; "pixels"
  11. PRINT "And the title bar is"; TitleBarHeight; " pixels"
  12. PRINT "So your actual display starts at ("; ActualScreenX; ","; ActualScreenY; ")"

I'm guessing since this is a glut command, it should work cross-platform for all the Linux/Mac folks, but I won't swear to it.  I've only got a Win 10 PC available ATM to test things on, and it works as advertised for me...

I honestly have no idea where I got the 100, 101, 506, 507 values, or what they actually represent here -- all I know is they seem to work and give me the relevant information which I'd want back.

For folks who use _SCREENCLICK and _MOUSEMOVE and such (like Pete and Cobolt), this might help you guys calculate where your actual buttons are on a screen and make it easier to interact with them, so I thought I'd share, even though it's basically still a mystery to me what the heck those values represent.  :P
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Re: Bordersize and Titlebar Height
« Reply #1 on: February 01, 2019, 01:41:10 am »
I honestly have no idea where I got the 100, 101, 506, 507 values, or what they actually represent here -- all I know is they seem to work and give me the relevant information which I'd want back.

You probably got 100/101 out of qb64\internal\c\parts\core\src\freeglut_std.h and 506/507 out of freeglut_ext.h in the same folder, there's also a html documentation here qb64\internal\c\parts\core\download\freeglut-2.8.0\doc\freeglut_user_interface.html. Function glutGet and it's respective constants are frequently used by the SCREEN related functions in libqb.cpp

BTW - Steve, you've fixed the _SCREENMOVE _MIDDLE thing a while ago, maybe you can go in again and take the border size / title height into account, so that the actual display area would be centered rather than the entire window. By doing so, we would finally restore the same _SCREENMOVE _MIDDLE behavior as it was in the old SDL version (just in the sake of backward compatibility).
« Last Edit: February 01, 2019, 12:15:53 pm by RhoSigma »
My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Bordersize and Titlebar Height
« Reply #2 on: November 10, 2021, 08:10:54 pm »
Expanded these little routines to also give us the Taskbar Height and Width, as well as to toss my little ScreenMove routines in there which actually position the screen itself and not the title bar at the position you specify.

Code: QB64: [Select]
  1. TBH = TaskbarHeight: TBW = TaskbarWidth
  2. TH = TitleBarHeight: BW = BorderWidth
  3. If TBH = DH Then TBH = 0 'Users taskbar is configured vertical, not hortizonal.
  4. If TBW = DW Then TBW = 0
  5.  
  6.  
  7. Screen _NewImage(DW, DH, 32)
  8.  
  9.  
  10. Print "This screen is the size of your desktop, but it has some inherent issues."; _Width, _Height
  11. Print "Hit the <SPACE BAR> and watch as we position it in different manners:"
  12. Print "To start with, this is a _SCREENMOVE 0,0 call.  It places the TITLEBAR's top left corner at position 0,0."
  13. Print "If you notice, the bottom of the screen is now hidden as the titlebar has shifted us down below the max resolution our screen will display."
  14. ScreenMove 0, 0
  15. Print "Now, this is a Steve Approved(tm) ScreenMove method to move the screen itself to position 0,0."
  16. Print "Now, as you can tell (if your taskbar is set to hide itself), the program window now covers the screen perfectly."
  17. Print "The only problem with this method is that we are now hiding the title bar over the top of the screen!"
  18.  
  19.  
  20. Screen _NewImage(DW - TBW - 2 * BW, DH - TBH - TH - BW * 2, 32)
  21.  
  22.  
  23. Print "To fix these issues, we use the functions here to figure out EXACTLY what size our screen needs to be."
  24. Print "Title Bar Height = "; TH
  25. Print "Screen Border ="; BW; "on each side."
  26. Print "Task Bar Height ="; TBH
  27. Print "Task Bar Height ="; TBW
  28. Print "This is a screen perfectly sized to fit on your screen."; _Width, _Height
  29. Print "See how it fits your visible screen perfectly?"
  30. Print "Note: If you have transparent borders, or if your theme has them set to opaque, it may appear to be a gap around your screen.  That transparent gap IS the screen border.  Set it a solid color and you can see it."
  31. Print "Note2: You may have to move the program window manually, if your taskbar isn't at the bottom of your screen."
  32. Print "At this point, you should have your title bar up top.  You screen shouldn't cover, or be covered, by the task bar."
  33. Print "Everything should be visible and accessable for you."
  34. Print "To my way of thinking, THIS is the maximum resolution that your screen should run in with a program.  ;)"
  35.  
  36.  
  37.  
  38. Sub ScreenMove (x, y)
  39.     Do Until _Width <> 0 And _ScreenExists = -1: Loop
  40.     _ScreenMove x - BorderWidth, y - BorderWidth - TitleBarHeight
  41.  
  42. Sub ScreenMove_Middle
  43.     Do Until _Width <> 0 And _ScreenExists = -1: Loop
  44.     _ScreenMove (_DesktopWidth - _Width - BorderWidth) / 2 + 1, (_DesktopHeight - _Height - BorderWidth) / 2 - TitleBarHeight + 1
  45.  
  46. Function TaskbarHeight
  47.     Do Until _Width <> 0 And _ScreenExists = -1: Loop
  48.     $If WIN Then
  49.         $If TASKBARDEC = UNDEFINED Then
  50.             $Let TASKBARDEC = TRUE
  51.             Declare Library "taskbar"
  52.                 Function taskbar_height& ()
  53.                 Function taskbar_width& ()
  54.             End Declare
  55.         $End If
  56.         TaskbarHeight = taskbar_height&
  57.     $Else
  58.         TaskbarHeight = 0 'no function to get the value for Linux/Mac, so return 0 instead of an error
  59.     $End If
  60.  
  61. Function TaskbarWidth
  62.     Do Until _Width <> 0 And _ScreenExists = -1: Loop
  63.     $If WIN Then
  64.         $If TASKBARDEC = UNDEFINED Then
  65.             $Let TASKBARDEC = TRUE
  66.  
  67.             Declare Library "taskbar"
  68.             Function taskbar_height& ()
  69.             Function taskbar_width& ()
  70.             End Declare
  71.         $End If
  72.         TaskbarWidth = taskbar_width&
  73.     $Else
  74.         TaskbarWidth = 0 'no function to get the value for Linux/Mac, so return 0 instead of an error
  75.     $End If
  76.  
  77.  
  78. Function TitleBarHeight
  79.     Do Until _Width <> 0 And _ScreenExists = -1: Loop
  80.     $If BORDERDEC = UNDEFINED Then
  81.         $Let BORDERDEC = TRUE
  82.         Declare Library
  83.             Function glutGet& (ByVal what&)
  84.         End Declare
  85.     $End If
  86.     TitleBarHeight = glutGet(507)
  87.  
  88. Function BorderWidth
  89.     Do Until _Width <> 0 And _ScreenExists = -1: Loop
  90.     $If BORDERDEC = UNDEFINED Then
  91.         $Let BORDERDEC = TRUE
  92.         Declare Library
  93.         Function glutGet& (ByVal what&)
  94.         End Declare
  95.     $End If
  96.     BorderWidth = glutGet(506)

Note that you'll need the taskbar.h file in your qb64 folder for this to work on Windows to actually get the taskbar dimensions for you.  Linux/Mac users, you get a 0 for your sizes as I'm not a Linux/Mac user and don't know which library to use to get those dimensions for you.  If someone wants to add that, let me know and I'll be happy to add it into the code here, but I'm basically just a pure Windows guy anymore.  I don't have enough free time anymore to bother with looking up libraries for OSes which I'll never use or anything personally.  Sorry.  :P

And there's probably a way to do this without the header file for Windows users.  Only problem is, I'm lazy and got it working this way first and said, "Good enough for my needs!"  LOL.  ;D
« Last Edit: November 11, 2021, 11:16:00 am by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Bordersize and Titlebar Height
« Reply #3 on: November 11, 2021, 02:06:41 am »
Feedback image on how your screen centering worked:
https://www.qb64.org/forum/index.php?topic=4381.msg138084#msg138084

Looks like screen height & width is just right but not the locate to right of the taskbar I have on the left side.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Bordersize and Titlebar Height
« Reply #4 on: November 11, 2021, 02:48:46 am »
Feedback image on how your screen centering worked:
https://www.qb64.org/forum/index.php?topic=4381.msg138084#msg138084

Looks like screen height & width is just right but not the locate to right of the taskbar I have on the left side.

Print "Note2: You may have to move the program window manually, if your taskbar isn't at the bottom of your screen."
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Bordersize and Titlebar Height
« Reply #5 on: November 11, 2021, 10:59:12 am »
Very interesting. Works well here.  By the way, I was playing around with the glutget function in that, and for some reason when I run the function by itself the QB64 IDE won't do anything when I try to compile the code.  Like in below, nothing happens. What am I missing here?  Running the latest QB64 version 32-bit.

Code: QB64: [Select]
  1.     FUNCTION glutGet& (BYVAL what&)
  2.  
  3. PRINT glutGet(506)
  4.  
  5.  

- Dav

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Bordersize and Titlebar Height
« Reply #6 on: November 11, 2021, 11:03:45 am »
Very interesting. Works well here.  By the way, I was playing around with the glutget function in that, and for some reason when I run the function by itself the QB64 IDE won't do anything when I try to compile the code.  Like in below, nothing happens. What am I missing here?  Running the latest QB64 version 32-bit.

Code: QB64: [Select]
  1.     FUNCTION glutGet& (BYVAL what&)
  2.  
  3. PRINT glutGet(506)
  4.  
  5.  

- Dav

Try adding this in there before your PRINT statement:


    Do Until _Width <> 0 And _ScreenExists = -1: Loop

https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Bordersize and Titlebar Height
« Reply #7 on: November 11, 2021, 11:05:33 am »
Yes, now it compiles.  Thanks.  But why won't it compile without adding it?

EDIT: Oh, maybe it is compiling, but I just don't notice it because the screen never shows.  Looks like it's closing by itself.

- Dav
« Last Edit: November 11, 2021, 11:11:58 am by Dav »

Marked as best answer by SMcNeill on November 11, 2021, 06:15:12 am

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Bordersize and Titlebar Height
« Reply #8 on: November 11, 2021, 11:10:22 am »
Feedback image on how your screen centering worked:
https://www.qb64.org/forum/index.php?topic=4381.msg138084#msg138084

Looks like screen height & width is just right but not the locate to right of the taskbar I have on the left side.

@bplus:

Give this version a go.  I added in 4 more functions for you so you can get to know all you'd ever want to know about your taskbar:

Code: QB64: [Select]
  1. TBH = TaskbarHeight: TBW = TaskbarWidth
  2. TH = TitleBarHeight: BW = BorderWidth
  3. If TBH = DH Then TBH = 0 'Users taskbar is configured vertical, not hortizonal.
  4. If TBW = DW Then TBW = 0
  5.  
  6.  
  7. Screen _NewImage(DW, DH, 32)
  8.  
  9. Print "This screen is the size of your desktop, but it has some inherent issues."; _Width, _Height
  10. Print "Hit the <SPACE BAR> and watch as we position it in different manners:"
  11. Print "To start with, this is a _SCREENMOVE 0,0 call.  It places the TITLEBAR's top left corner at position 0,0."
  12. Print "If you notice, the bottom of the screen is now hidden as the titlebar has shifted us down below the max resolution our screen will display."
  13. ScreenMove 0, 0
  14. Print "Now, this is a Steve Approved(tm) ScreenMove method to move the screen itself to position 0,0."
  15. Print "Now, as you can tell (if your taskbar is set to hide itself), the program window now covers the screen perfectly."
  16. Print "The only problem with this method is that we are now hiding the title bar over the top of the screen!"
  17.  
  18.  
  19. Screen _NewImage(DW - TBW - 2 * BW, DH - TBH - TH - BW * 2, 32)
  20. If taskbar_top > 0 Then ScreenX = 0 Else ScreenX = TBH
  21. If taskbar_left > 0 Then Screeny = 0 Else Screeny = TBW
  22. ScreenMove ScreenX, Screeny
  23.  
  24. Print "To fix these issues, we use the functions here to figure out EXACTLY what size our screen needs to be."
  25. Print "Title Bar Height = "; TH
  26. Print "Screen Border ="; BW; "on each side."
  27. Print "Task Bar Height ="; TBH
  28. Print "Task Bar Width ="; TBW
  29. Print "Task Bar Top = "; taskbar_top
  30. Print "Task Bar Left = "; taskbar_left
  31. Print "Task Bar Bottom = "; taskbar_bottom
  32. Print "Task Bar Right = "; taskbar_right
  33. Print "This is a screen perfectly sized to fit on your screen."; _Width, _Height
  34. Print "See how it fits your visible screen perfectly?"
  35. Print "Note: If you have transparent borders, or if your theme has them set to opaque, it may appear to be a gap around your screen.  That transparent gap IS the screen border.  Set it a solid color and you can see it."
  36. Print "At this point, you should have your title bar up top.  You screen shouldn't cover, or be covered, by the task bar."
  37. Print "Everything should be visible and accessable for you."
  38. Print "To my way of thinking, THIS is the maximum resolution that your screen should run in with a program.  ;)"
  39.  
  40.  
  41. Sub ScreenMove (x, y)
  42.     Do Until _Width <> 0 And _ScreenExists = -1: Loop
  43.     _ScreenMove x - BorderWidth, y - BorderWidth - TitleBarHeight
  44.  
  45. Sub ScreenMove_Middle
  46.     Do Until _Width <> 0 And _ScreenExists = -1: Loop
  47.     _ScreenMove (_DesktopWidth - _Width - BorderWidth) / 2 + 1, (_DesktopHeight - _Height - BorderWidth) / 2 - TitleBarHeight + 1
  48.  
  49. Function TaskbarHeight
  50.     Do Until _Width <> 0 And _ScreenExists = -1: Loop
  51.     $If WIN Then
  52.         $If TASKBARDEC = UNDEFINED Then
  53.             $Let TASKBARDEC = TRUE
  54.             Declare Library "taskbar"
  55.                 Function taskbar_height& ()
  56.                 Function taskbar_width& ()
  57.                 Function taskbar_top& ()
  58.                 Function taskbar_left& ()
  59.                 Function taskbar_bottom& ()
  60.                 Function taskbar_right& ()
  61.             End Declare
  62.         $End If
  63.         TaskbarHeight = taskbar_height&
  64.     $Else
  65.         TaskbarHeight = 0 'no function to get the value for Linux/Mac, so return 0 instead of an error
  66.     $End If
  67.  
  68. Function TaskbarWidth
  69.     Do Until _Width <> 0 And _ScreenExists = -1: Loop
  70.     $If WIN Then
  71.         $If TASKBARDEC = UNDEFINED Then
  72.             $Let TASKBARDEC = TRUE
  73.  
  74.             Declare Library "taskbar"
  75.             Function taskbar_height& ()
  76.             Function taskbar_width& ()
  77.             Function taskbar_top& ()
  78.             Function taskbar_left& ()
  79.             Function taskbar_bottom& ()
  80.             Function taskbar_right& ()
  81.             End Declare
  82.         $End If
  83.         TaskbarWidth = taskbar_width&
  84.     $Else
  85.         TaskbarWidth = 0 'no function to get the value for Linux/Mac, so return 0 instead of an error
  86.     $End If
  87.  
  88.  
  89. Function TitleBarHeight
  90.     Do Until _Width <> 0 And _ScreenExists = -1: Loop
  91.     $If BORDERDEC = UNDEFINED Then
  92.         $Let BORDERDEC = TRUE
  93.         Declare Library
  94.             Function glutGet& (ByVal what&)
  95.         End Declare
  96.     $End If
  97.     TitleBarHeight = glutGet(507)
  98.  
  99. Function BorderWidth
  100.     Do Until _Width <> 0 And _ScreenExists = -1: Loop
  101.     $If BORDERDEC = UNDEFINED Then
  102.         $Let BORDERDEC = TRUE
  103.         Declare Library
  104.         Function glutGet& (ByVal what&)
  105.         End Declare
  106.     $End If
  107.     BorderWidth = glutGet(506)
  108.  

You can now find your taskbar_top, taskbar_left, taskbar_bottom, taskbar_right positions, and move accordingly to suit your screen.

Unfortunately, I can't actually test to see if this works.  The taskbar *DOES NOT* move from the bottom in the newest versions of Windows.  Win 11 has this to say about the taskbar:  https://www.microsoft.com/en-us/windows/windows-11-specifications#primaryR4

Taskbar is changed including:
  • People is no longer present on the Taskbar.
  • Some icons may no longer appear in the System Tray (systray) for upgraded devices including previous customizations.
  • Alignment to the bottom of the screen is the only location allowed.
  • Apps can no longer customize areas of the Taskbar.
* taskbar.h (Filesize: 1.11 KB, Downloads: 248)
« Last Edit: November 11, 2021, 11:22:37 am by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Bordersize and Titlebar Height
« Reply #9 on: November 11, 2021, 11:13:42 am »
Yes, now it compiles.  Thanks.  But why won't it compile without adding it?

- Dav

It's the same type of race conditions which we end up seeing with _SCREENMOVE and _TITLE sometimes.  You're trying to grab the information from the screen before it's fully initialized and registered to begin win. 

A delay before the call will fix it at start up, or I've found   "Do Until _Width <> 0 And _ScreenExists = -1: Loop" to be a good test for a delay for me, as well.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Bordersize and Titlebar Height
« Reply #10 on: November 11, 2021, 11:49:50 am »
Yes, that makes sense, and I see a delay is needed to get valid info, but I find it puzzling that the program appears to not even compile and start without it. Shouldn’t the program still try to run? Maybe a failed glutget call terminates programs instantly I’m wondering.

- Dav

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Bordersize and Titlebar Height
« Reply #11 on: November 11, 2021, 12:08:49 pm »
Yes, that makes sense, and I see a delay is needed to get valid info, but I find it puzzling that the program appears to not even compile and start without it. Shouldn’t the program still try to run? Maybe a failed glutget call terminates programs instantly I’m wondering.

- Dav

It compiles (look in the QB64 folder for an untitled.exe if you're curious about it).  The problem is it generates a seg fault as soon as you run it, crashing before it even finishes initializing properly.  The program is running and dying in the blink of a nanosecond -- probably faster than your monitors 60 FPS refresh rate.  You'll want a *really* fast display to catch the try-but-die flicker you're generating.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Bordersize and Titlebar Height
« Reply #12 on: November 11, 2021, 12:27:46 pm »
Hi @SMcNeill

The last screen is loading under the taskbar and down from top of screen. When I drag it to see entire screen it fits well.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Bordersize and Titlebar Height
« Reply #13 on: November 11, 2021, 01:18:38 pm »
Hi @SMcNeill

The last screen is loading under the taskbar and down from top of screen. When I drag it to see entire screen it fits well.

There's a glitch in my logic here then:

If taskbar_top > 0 Then ScreenX = 0 Else ScreenX = TBH
If taskbar_left > 0 Then Screeny = 0 Else Screeny = TBW

The above determines if we're in the top left corner, but it doesn't tell us horizontal or vertical. 

If taskbar_bottom = TBH Then 'bar is at top
    ScreenY = TBH
Else
    ScreenY = 0
END IF

If taskbar_right = TBW THEN 'bar is on left
   ScreenX = TBW
ELSE
    ScreenX = 0
END IF

Replace those two lines with the above and see if it corrects the logic.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Bordersize and Titlebar Height
« Reply #14 on: November 11, 2021, 01:33:05 pm »
The taskbar location are listed correctly left, top = 0,0 and right, bottom = 63, 768 (the screen height available to view), so if you  drew a rectangle with those dimensions you would have taskbar outlined.