|
Post by Chris Iverson on Jul 20, 2020 18:11:27 GMT -5
|
|
|
Post by Gordon Rahman on Jul 21, 2020 7:00:40 GMT -5
Hi Carl, I like English, in Dutch I could not place the word dense. I can't show an example in LB5. LB5 misses the LB4 posxy. It has a new function x() and y(), but I don't have the explanation for the working of that function. I forgot to mention that LB5 has not yet been implemented with window styles like graphics_nsb_nf. So here is my example in LB4 (with the missing pixel I already posted in the LB4 section here) with posxy and no stylebits. Here "home" misses homeing far more. WindowWidth = 800 WindowHeight = 600
open "" for graphics_nf_nsb as #w #w "trapclose [quit]" #w "home" #w "posxy x y" print x,y wait
[quit] close #w end
WindowWidth = 800 WindowHeight = 600
stylebits #w,0,_WS_BORDER,0,0 open "" for graphics_nf_nsb as #w #w "trapclose [quit]" #w "home" #w "posxy x y" print x,y
wait
[quit] close #w end
and here is an other one
WindowWidth = 800 WindowHeight = 600
graphicbox #w.g, 0,0,800,600 open "" for window_popup as #w #w "trapclose [quit]" #w.g "home" #w.g "posxy x y" print x,y wait
[quit] close #w end
And here it shows that STYLEBITS only works on the graphicbox. WindowWidth = 805 WindowHeight = 605
stylebits #w.g, 0,_WS_BORDER,0,0 graphicbox #w.g, 0,0,800,600 open "" for window as #w #w "trapclose [quit]" #w.g "home" #w.g "posxy x y" print x,y wait
[quit] close #w end
Where can I find details about the use of x() and y() in LB5? Did I missed it? my question meant to be, can we have a better "home" in LB5 then the one in LB4. Not missing a single pixel? As I considered the windows in LB are of MS Windows origin, I accused MS windows of having problems with stylebits too. Gordon
|
|
|
Post by Gordon Rahman on Jul 21, 2020 7:58:42 GMT -5
Ok here is my LB5 version
WindowWidth = 800 WindowHeight = 600 open "posxy test" for graphics as #1 #1 trapclose("[quit]") #1 home() print #1 x() print #1 y()
wait
[quit] close #1 end
WindowWidth = 800 WindowHeight = 600
graphicbox #1.g, 0,0,800,600
open "posxy test" for graphics as #1 #1 trapclose("[quit]") #1.g home() print #1.g x() print #1.g y()
wait
[quit] close #1 end
|
|
|
Post by Chris Iverson on Jul 21, 2020 12:22:25 GMT -5
Hi Carl, I like English, in Dutch I could not place the word dense. I can't show an example in LB5. LB5 misses the LB4 posxy. It has a new function x() and y(), but I don't have the explanation for the working of that function. I forgot to mention that LB5 has not yet been implemented with window styles like graphics_nsb_nf. So here is my example in LB4 (with the missing pixel I already posted in the LB4 section here) with posxy and no stylebits. Here "home" misses homeing far more. It's not a problem with stylebits. You're misunderstanding what the "window" is. When you create a "window" of a specific size, that size is the OUTERMOST limits of the window. Any decoration for that window is placed INSIDE those limits. Every window has a concept of a "client area". This "client area" is the area inside of your window that's actually available to you. If you create a control that has a border, that border is taken away from the usable drawing area of the control. The client area does not include the border, so the client area is smaller. If you create a top-level window with a titlebar and full window sizing borders, all of that is taken away from your window's size, not added to it. If you create a regular, top-level window 800x600 in size, you don't get 800x600 of usable space; some of that space is taken up by the nonclient area. (That's why things seem to work if you use STYLEBITS to remove the border of a graphicbox control in a regular window; with the border removed, there is no non-client area for the graphicbox control, so the entire thing is client area.) The HOME command is working fine; is just getting the center of the actual usable space. Here's proof; every one of your examples modified to also print the client area size, as well as those size values divided by two(to show how LB calculates the "home") WindowWidth = 800 WindowHeight = 600
open "" for graphics_nf_nsb as #w #w "trapclose [quit]" #w "home" #w "posxy x y" print x,y
call PrintClientArea hwnd(#w) wait
[quit] close #w end
Sub PrintClientArea hndl struct PCArect, x as long, y as long, w as long, h as long
CallDLL #user32, "GetClientRect",_ hndl as ulong,_ PCArect as struct,_ ret as long
Print PCArect.w.struct;" - ";int(PCArect.w.struct / 2), PCArect.h.struct;" - ";int(PCArect.h.struct / 2) End Sub WindowWidth = 800 WindowHeight = 600
stylebits #w,0,_WS_BORDER,0,0 open "" for graphics_nf_nsb as #w #w "trapclose [quit]" #w "home" #w "posxy x y" print x,y call PrintClientArea hwnd(#w) wait
[quit] close #w end
Sub PrintClientArea hndl struct PCArect, x as long, y as long, w as long, h as long
CallDLL #user32, "GetClientRect",_ hndl as ulong,_ PCArect as struct,_ ret as long
Print PCArect.w.struct;" - ";int(PCArect.w.struct / 2), PCArect.h.struct;" - ";int(PCArect.h.struct / 2) End Sub
WindowWidth = 800 WindowHeight = 600
graphicbox #w.g, 0,0,800,600 open "" for window_popup as #w #w "trapclose [quit]" #w.g "home" #w.g "posxy x y" print x,y call PrintClientArea hwnd(#w.g) wait
[quit] close #w end
Sub PrintClientArea hndl struct PCArect, x as long, y as long, w as long, h as long
CallDLL #user32, "GetClientRect",_ hndl as ulong,_ PCArect as struct,_ ret as long
Print PCArect.w.struct;" - ";int(PCArect.w.struct / 2), PCArect.h.struct;" - ";int(PCArect.h.struct / 2) End Sub WindowWidth = 805 WindowHeight = 605
stylebits #w.g, 0,_WS_BORDER,0,0 graphicbox #w.g, 0,0,800,600 open "" for window as #w #w "trapclose [quit]" #w.g "home" #w.g "posxy x y" print x,y call PrintClientArea hwnd(#w.g) wait
[quit] close #w end
Sub PrintClientArea hndl struct PCArect, x as long, y as long, w as long, h as long
CallDLL #user32, "GetClientRect",_ hndl as ulong,_ PCArect as struct,_ ret as long
Print PCArect.w.struct;" - ";int(PCArect.w.struct / 2), PCArect.h.struct;" - ";int(PCArect.h.struct / 2) End Sub
Also, please note in your last example that you ONLY changed the WINDOW size, NOT the graphicbox size. The position of the HOME command wouldn't change; the graphicbox is still the same size! Here's an example with the graphicbox's size changed as well. WindowWidth = 805 WindowHeight = 605
stylebits #w.g, 0,_WS_BORDER,0,0 graphicbox #w.g, 0,0,805,605 open "" for window as #w #w "trapclose [quit]" #w.g "home" #w.g "posxy x y" print x,y call PrintClientArea hwnd(#w.g) wait
[quit] close #w end
Sub PrintClientArea hndl struct PCArect, x as long, y as long, w as long, h as long
CallDLL #user32, "GetClientRect",_ hndl as ulong,_ PCArect as struct,_ ret as long
Print PCArect.w.struct;" - ";int(PCArect.w.struct / 2), PCArect.h.struct;" - ";int(PCArect.h.struct / 2) End Sub
|
|
|
Post by Gordon Rahman on Jul 21, 2020 14:23:57 GMT -5
Thank you Chris, This makes sense to me. Now I even know why it only worked with window-popup with a graphicbox.
I also have an issue with the length and width of a screen. That's my next question ... (wish)
Gordon
|
|
|
Post by Gordon Rahman on Jul 21, 2020 15:15:37 GMT -5
How wide is my screen if I say: WindowWidth = 800 WindowHeight = 600
nomainwin
WindowWidth = 800 WindowHeight = 600 stylebits #w, 0,_WS_Border,0,0 open "hoekpunten scherm" for graphics_nsb_nf as #w #w "color red; size 2; down; place 0 0" #w "set" #w "place 792 0" #w "set" wait
I can see the red dot on the screen (Upperleft and Upperright). If the screen ends at 800 I'm losing 8 pixels on the right border?
Gordon
|
|
|
Post by Chris Iverson on Jul 21, 2020 18:15:43 GMT -5
According to the PrintClientArea function, yes. The resulting clientarea for the graphic "window" is 792 pixels wide.
Although I think this specific instance is the result of a bug in LB, or maybe just an oversight.
You're losing 8 pixels horizontally, so I did some digging, and I wasn't sure why.
When opening a regular window, you only lose six pixels to the window frame. So why eight?
Well, the extra two comes from the one-pixel border on the graphicbox.
But wait, the border was removed with stylebits!
Well, with graphic windows, no, it wasn't. If you take the handle from the graphicbox, and get the window styles tied to it, WS_BORDER is still active.
So why didn't it get removed?
Well, keep in mind what a graphic window is. It's just a regular window with a full-size graphicbox in it, with some behind-the-scenes trickery to make the window handle refer to the graphicbox instead.
This "trickery" causes the stylebits problem in that, BEFORE the window opens, the handle refers to the top-level window, so it's the top-level window you're modifying the style for.
After it opens, it refers to the graphicbox. There doesn't seem to be a way to remove the "border" on a graphicbox that's on a window of type graphics.
|
|
|
Post by Gordon Rahman on Jul 21, 2020 19:04:17 GMT -5
Thanks for this explanation. I have learned a lot in a few days now.
I'll prepare my next question tomorrow, it's late over here.
About why the screen starts at 0,0 and not 1,1.
Gordon
|
|
|
Post by Carl Gundel on Jul 22, 2020 9:26:00 GMT -5
Thanks for this explanation. I have learned a lot in a few days now. I'll prepare my next question tomorrow, it's late over here. About why the screen starts at 0,0 and not 1,1. I may adjust that, but to answer your question this version of Liberty BASIC is based on a cross platform library, and so there are going to be little things that don't line up with Microsoft Windows' way of doing things. In fact the version of Smalltalk this is based on is older than any version of Microsoft Windows, and that's no joke.
|
|
|
Post by Rod on Jul 22, 2020 10:25:49 GMT -5
I kinda know where Gordon is coming from. He wants to ask for a specific drawing area and get that area. So when we ask for a graphicbox of 800x600 we get 801 drawing pixels 0-800
Border or not, what size then does the Window need to be to contain and show all off that graphicbox?
As it stands Windows appears to keep moving the goal posts. Home used to get a useable definition of half the size of the client area and so allow the precise calculation of a window size But now we need to add more pixels for unknown reasons. Thought it was shadow but no.
Beginners usually specify a window of 800x600 and a graphicbox of 800x600. That habit will not go away anytime soon. But the graphicbox will not be in full view and box 800,600 won’t be seen and sprites won’t bounce off the edges either.
Sample code and tutorials are required.
|
|
|
Post by Chris Iverson on Jul 22, 2020 11:26:17 GMT -5
There's an API call that can be used to help with this, AdjustWindowRect.
You pass in a RECT that indicates exactly where you want your client area to be, and what size you want it to be, as well as the style of the window you're using and if the window has a menu(all of which affects the final size of the window).
When you get the RECT back, the window position and height have been adjusted to place a client area of the exact size requested in the exact area you requested, regardless of window decoration.
This also works on all versions of Windows, which is useful since various versions had different window titlebar and frame sizes.
Instead of using the absolute positioning, here's some sample code that uses an empty rect(window of size 0x0 at location 0,0) to get the size of the adjustments made to the window rect, and then does the size adjustment itself.
stylebits #dummy, 0, _WS_VISIBLE, 0, 0 open "dummy" for window as #dummy
hWnd = hwnd(#dummy) style = GetWindowStyle(hWnd) close #dummy
struct AWRect, x as long, y as long, w as long, h as long
bWindowHasMenu = 0 CallDLL #user32, "AdjustWindowRect",_ AWRect as struct,_ style as long,_ bWindowHasMenu as long,_ ret as long
adjWidth = AWRect.w.struct - AWRect.x.struct adjHeight = AWRect.h.struct - AWRect.y.struct
WindowWidth = 800 + adjWidth WindowHeight = 600 + adjHeight
open "test" for window as #w input a close #w end
Function GetWindowStyle(hWnd) CallDLL #user32, "GetWindowLongA",_ hWnd as ulong,_ _GWL_STYLE as long,_ GetWindowStyle as long End Function
|
|
cundo
Full Member
Muchas Gracias!!
Posts: 146
|
Post by cundo on Jul 22, 2020 11:44:38 GMT -5
What about having some variables to know the client working area?
|
|
|
Post by Carl Gundel on Jul 22, 2020 13:30:53 GMT -5
I kinda know where Gordon is coming from. He wants to ask for a specific drawing area and get that area. So when we ask for a graphicbox of 800x600 we get 801 drawing pixels 0-800 Border or not, what size then does the Window need to be to contain and show all off that graphicbox? As it stands Windows appears to keep moving the goal posts. Home used to get a useable definition of half the size of the client area and so allow the precise calculation of a window size But now we need to add more pixels for unknown reasons. Thought it was shadow but no. Beginners usually specify a window of 800x600 and a graphicbox of 800x600. That habit will not go away anytime soon. But the graphicbox will not be in full view and box 800,600 won’t be seen and sprites won’t bounce off the edges either. Sample code and tutorials are required. The actual client area dimensions of a window of a specified size are not guaranteed to be exactly the same depending on operating system or version of operating system, GUI theme, and other settings. On the other hand, specifying the size of graphicbox widget should produce the specified size I agree.
|
|
|
Post by Rod on Jul 22, 2020 15:03:31 GMT -5
I have been trying to use less API. Since 5 will need native. It comes down to allowing ample space for a graphic box in a window. For precision use a graphics window or a popup window. But we need to test that even they give the drawing area we expect. Windows!
|
|
|
Post by Gordon Rahman on Jul 23, 2020 17:14:22 GMT -5
I have been trying to use less API. Since 5 will need native. It comes down to allowing ample space for a graphic box in a window. For precision use a graphics window or a popup window. But we need to test that even they give the drawing area we expect. Windows! WindowWidth = 800 WindowHeight = 600
nomainwin
button #w.b "Quit",[quit],UL,360,560 stylebits #w, 0,_WS_border,0,0 stylebits #w.g, 0,_WS_border,0,0 'here you "win" 2 pixels 'and home is correct
graphicbox #w.g, 0,0,800,600 open "" for window_popup as #w
'#w.g "color blue; size 1; down; line -1 -1 798 598" '#w.g "color 128 128 64; size 1; down; line -1 598 798 -1"
#w.g "color blue; size 1; down; line 0 0 799 599" #w.g "color 128 128 64; size 1; down; line 0 599 799 0"
#w.g "color red; home; size 3; set" '#w.g "size 1"
wait
[quit] close #w end
I'll try to explain this at the Workshop. The window lenght = 1 less then I expected and 1 pixel is used for the border. Gordon
|
|