Page 1 of 2

Changing border type on string and text gadgets

Posted: Sun Jan 07, 2007 11:47 am
by Lewis
I need to draw text in rectangles and expected that one or both of the string or text gadgets would do the job. Alas, no -- they provide 3D borders only! :cry: Can an API (Windows) call change the border type of these gadgets and, if so, would anyone care to volunteer a code snippet?

Posted: Sun Jan 07, 2007 2:24 pm
by srod
I don't think it can, at least I've never come across it before.

If you have to 'roll your own' then it shouldn't be too hard. One way would be to place a borderless text gadget within some kind of container, e.g. an image gadget, and then draw your own border within the container etc. There's all sorts of possibilities.

Posted: Sun Jan 07, 2007 2:26 pm
by Trond
You can, but I don't rememer how exactly.

Posted: Sun Jan 07, 2007 2:30 pm
by srod
Ah yea, depends on what sort of changes Lewis is after? I envisaged dashed borders and the like.

Posted: Sun Jan 07, 2007 2:34 pm
by srod

Code: Select all

If OpenWindow(0, 0, 0, 270, 160, "TextGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
    TextGadget(1, 10, 100, 250, 20, "TextGadget Border")
    SetWindowLong_(GadgetID(1), #GWL_STYLE, GetWindowLong_(GadgetID(1), #GWL_STYLE) |#WS_BORDER) 
    SetWindowPos_(GadgetID(1), 0, 0, 0, 0, 0, #SWP_NOMOVE | #SWP_NOSIZE | #SWP_FRAMECHANGED) 
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
:?:

Posted: Sun Jan 07, 2007 4:19 pm
by Sparkie
And for the StringGadget...

Code: Select all

If OpenWindow(0, 0, 0, 270, 160, "StringGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0)) 
  StringGadget(2, 10, 130, 250, 20, "StringGadget Flat Border")
  SetWindowLong_(GadgetID(2), #GWL_EXSTYLE, GetWindowLong_(GadgetID(2), #GWL_EXSTYLE) &(~#WS_EX_CLIENTEDGE)) 
  SetWindowLong_(GadgetID(2), #GWL_STYLE, GetWindowLong_(GadgetID(2), #GWL_STYLE) | #WS_BORDER) 
  SetWindowPos_(GadgetID(2), 0, 0, 0, 0, 0, #SWP_NOMOVE | #SWP_NOSIZE | #SWP_FRAMECHANGED) 
  
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow 
EndIf 

Posted: Sun Jan 07, 2007 4:37 pm
by Lewis
Excellent! My thanks to srod and Sparkie for the code snippets. :D Now let us extend the problem a little.

Given, say, a square TextGadget (or StringGadget, Sparkie :) ) of an arbitrary size, we need to centre the text both horizontally and vertically. The horizontal positioning is a piece of cake: simply specify the #PB_Text_Center flag. Vertically we need to set the text's "leading" value, which requires a bit of arithmetic on the size of the square and text/font attributes, and then make another API call.

Any of you experts care to provide a code snippet for that one? :wink:

Posted: Sun Jan 07, 2007 4:42 pm
by srod

Posted: Sun Jan 07, 2007 4:44 pm
by Dr. Dri
You can also try this :

Code: Select all

If OpenWindow(0, 0, 0, 270, 160, "TextGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
    TextGadget(1, 10, 100, 250, 20, "TextGadget Border", #WS_BORDER)
    StringGadget(2, 10, 130, 250, 20, "StringGadget Flat Border", #WS_EX_STATICEDGE | #WS_BORDER)
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Dri

Posted: Sun Jan 07, 2007 9:44 pm
by Lewis
Dr. Dri wrote:You can also try this :

Code: Select all

If OpenWindow(0, 0, 0, 270, 160, "TextGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
    TextGadget(1, 10, 100, 250, 20, "TextGadget Border", #WS_BORDER)
    StringGadget(2, 10, 130, 250, 20, "StringGadget Flat Border", #WS_EX_STATICEDGE | #WS_BORDER)
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Dri
Right, we can drop the API call by using its flag directly in the gadget. Nice one, Dr. Dri! So why isn't this documented (in the PB gadget documentation), Fred?

Posted: Sun Jan 07, 2007 9:49 pm
by netmaestro
So why isn't this documented (in the PB gadget documentation), Fred?
Flags like this are Windows Only, and the PureBasic language is designed to be cross-platform. As a rule, you won't find any OS-specific flags or commands documented or really supported but many will nonetheless work. For example, this note can be found in the MessageRequester doc:
Note: In PureBasic you can also use many more constants of the WindowsAPI. But be aware, that these constants are not cross-platform compatible! An overview you will find in the MSDN Library at the function MessageBox.

Posted: Sun Jan 07, 2007 10:13 pm
by Lewis
That's not the same problem, srod. An EditGadget gives me arbitrary multiple lines, not an arbitrary height,. Anyway, I don't think it can be done because -- as I understand it -- it requires access to the font metrics, just like you have in 2D drawing. No, I think we've got just about all we can out of the PB text/string gadgets, they simply aren't designed to be manipulated beyond their basic functionality.

Posted: Sun Jan 07, 2007 10:17 pm
by srod
I must have misunderstood because the link shows how to vertically centre text within a multiline string gadget. You need to look towards the bottom of the post for the relevant examples!

I thought this is what you requested?

Oh well, never mind.

Posted: Sun Jan 07, 2007 10:22 pm
by Lewis
netmaestro wrote:
So why isn't this documented (in the PB gadget documentation), Fred?
Flags like this are Windows Only, and the PureBasic language is designed to be cross-platform. As a rule, you won't find any OS-specific flags or commands documented or really supported but many will nonetheless work. For example, this note can be found in the MessageRequester doc:
Note: In PureBasic you can also use many more constants of the WindowsAPI. But be aware, that these constants are not cross-platform compatible! An overview you will find in the MSDN Library at the function MessageBox.
That's a fair enough retort (and rebuke), netmaestro, point taken! :)

Posted: Sun Jan 07, 2007 10:30 pm
by netmaestro
I think you misunderstand, it's not a retort or a rebuke. Merely further information, cheerfully given in the spirit of helpfulness! Please accept it as such.