Changing border type on string and text gadgets

Just starting out? Need help? Post your questions and find answers here.
User avatar
Lewis
User
User
Posts: 47
Joined: Fri Nov 25, 2005 1:12 pm

Changing border type on string and text gadgets

Post 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?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

You can, but I don't rememer how exactly.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Ah yea, depends on what sort of changes Lewis is after? I envisaged dashed borders and the like.
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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
:?:
I may look like a mule, but I'm not a complete ass.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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 
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
Lewis
User
User
Posts: 47
Joined: Fri Nov 25, 2005 1:12 pm

Post 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:
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

I may look like a mule, but I'm not a complete ass.
Dr. Dri
Enthusiast
Enthusiast
Posts: 243
Joined: Sat Aug 23, 2003 6:45 pm

Post 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
User avatar
Lewis
User
User
Posts: 47
Joined: Fri Nov 25, 2005 1:12 pm

Post 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?
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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.
BERESHEIT
User avatar
Lewis
User
User
Posts: 47
Joined: Fri Nov 25, 2005 1:12 pm

Post 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.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
User avatar
Lewis
User
User
Posts: 47
Joined: Fri Nov 25, 2005 1:12 pm

Post 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! :)
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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.
BERESHEIT
Post Reply