StringGadget Vertical?

Just starting out? Need help? Post your questions and find answers here.
User avatar
oryaaaaa
Enthusiast
Enthusiast
Posts: 791
Joined: Mon Jan 12, 2004 11:40 pm
Location: Okazaki, JAPAN

StringGadget Vertical?

Post by oryaaaaa »

Can you vertically specify with StringGadget?

Thanks
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Not that I'm aware of. You can certainly draw angled text as demonstrated with:

Code: Select all

If OpenWindow(0, 0, 0, 640, 400, #PB_Window_SystemMenu, "Angled text!")
  hdc = GetDC_(WindowID())
  SetBkMode_(hdc, #TRANSPARENT)
  hfont = CreateFont_(30,16, 2700,0,0,0,0,0,0,0,0,0,0,"ARIAL")
  SelectObject_(hdc, hfont)
  TextOut_(hdc, 310, 100,"Pure Basic", 10)
  DeleteObject_(hfont)
  ReleaseDC_(WindowID(), hdc)
  Repeat
    EventID.l = WaitWindowEvent()
  Until EventID = #PB_EventCloseWindow 
EndIf

End
It is entirely conceivable that you could use code similar to the above in conjunction with, say a subclassed text gadget, in which you take over the paint process and thus get the text gadget to display angled text etc. The problem (at least one of them :lol:) with the string gadget will be the caret.

Your best bet might be to create your own custom control.
I may look like a mule, but I'm not a complete ass.
User avatar
oryaaaaa
Enthusiast
Enthusiast
Posts: 791
Joined: Mon Jan 12, 2004 11:40 pm
Location: Okazaki, JAPAN

Post by oryaaaaa »

Sorry

Code: Select all

;                Up
;
;              Center
;
;               Down
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Isn't this simply a multi-line string gadget?
I may look like a mule, but I'm not a complete ass.
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

Yes?

Make a StringGadget that's small in width, huge in height and add these constants in the flags:

Code: Select all

#PB_String_MultiLine|#ES_AUTOVSCROLL
I tried to make one it isn't something special. just the #ES_AUTOVSCROLL is needed...

:roll: (Yes! Even I can help :wink: )
User avatar
oryaaaaa
Enthusiast
Enthusiast
Posts: 791
Joined: Mon Jan 12, 2004 11:40 pm
Location: Okazaki, JAPAN

Post by oryaaaaa »

no, sorry.

Question from person who started PB recently
It seems to want to decide the position of length.
is not possible to do in my knowledge.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

I think I understand; you wish to position the text vertically within a string gadget? I.e. sometimes place the text at the top, sometimes in the middle etc?

Unfortunately I do not think that there is a simple style-flag to achieve this. You can certainly set the left and right margins, but I haven't as yet come across a flag to set a vertical margin. I'll have a scan through MSDN in a minute.

I actually needed this myself a while ago, but everytime I repositioned the text within the gadget (through some custom drawing), the cursor would not follow! I ended up cheating.

Basically, create some kind of container gadget and paint it to look like the string gadget's background. Then simply position a borderless string gadget at the appropriate position within the container to make it look like a single edit control and that's it - job done!

If I've understood you correctly, and if I've time, I'll put together a small example for you later on.
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 »

How about something like this...

Code: Select all

; ************************************************
; Code:   Verticaly and Horizontaly centered text
;         in a multiline StringGadget
; Author: Sparkie
; Date:   December 20, 2005
; OS:     Windows only
; ************************************************

; ************************************************
; Procedure: Center text in Multiline StringGadget
; ************************************************
Procedure StringGadgetVCenter(gadNum)
  ;--> Get line count of StringGadget
  lineCount = SendMessage_(GadgetID(gadNum), #EM_GETLINECOUNT, 0, 0)
  myText$ = GetGadgetText(gadNum)
  ;--> Get width and height of text on one line
  hdc = GetDC_(GadgetID(gadNum))
  GetTextExtentPoint32_(hdc, myText$, Len(myText$), @textXY.SIZE)
  ReleaseDC_(GadgetID(gadNum), hdc)
  ;--> Set rect coordinates for StringGadget
  eRect.RECT
  eRect\left = 0
  eRect\top = (GadgetHeight(gadNum) - textXY\cy*lineCount) / 2
  eRect\right = GadgetWidth(gadNum) - (eRect\left * 2)
  eRect\bottom = eRect\top + textXY\cy*lineCount
  SendMessage_(GadgetID(gadNum), #EM_SETRECT, 0, eRect)
EndProcedure
; ************************************************
; Main Window 
; ************************************************
If OpenWindow(0, 0, 0, 300, 200, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "StringGadget Centered Text") And CreateGadgetList(WindowID(0))
  ;--> #ES_CENTER will not work with a singleline StringGadget on Win95/NT4
  StringGadget(0, 50, 10, 200, 80, "Vertical and Horizontal" + #CRLF$ + "Centered Text in" + #CRLF$ + "Multiline StringGadget", #PB_String_MultiLine | #ES_CENTER)
  StringGadgetVCenter(0)
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
End
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

wow Sparkie, some nice code.

cheers
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Bloody hell, I'd never have thought of doing that! So simple. :)

I guess you'd have to call it every time new lines were added or deleted etc.
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 »

Thanks guys. :)

@srod: Yes, as it stands it only accepts 3 lines of text. If I get time this weekend, I'll see if I can improve on it. Or better yet, maybe I'll just let you handle the rest of it. :grin:
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Now that sound like a challenge to me!

Here ya go...

***EDIT: It now scrolls correctly and accounts for any scrollbars! -Twit that I am!

Code: Select all

; ************************************************ 
; Code:   Verticaly and Horizontaly centered text 
;         in a multiline StringGadget 
; Author: Sparkie + srod! (But mostly Sparkie!)
; Date:   December 20, 2005 
; OS:     Windows only 
; ************************************************ 

; ************************************************ 
; Procedure: Center text in Multiline StringGadget 
; ************************************************ 
Procedure StringGadgetVCenter(gadNum) 
  ;--> Get line count of StringGadget 
  lineCount = SendMessage_(GadgetID(gadNum), #EM_GETLINECOUNT, 0, 0) 
  myText$ = GetGadgetText(gadNum) 
  ;--> Get width and height of text on one line 
  hdc = GetDC_(GadgetID(gadNum)) 
  GetTextExtentPoint32_(hdc, myText$, Len(myText$), @textXY.SIZE) 
  ReleaseDC_(GadgetID(gadNum), hdc) 
  eRect.RECT 
  ;--> Set rect coordinates for StringGadget 
  ;The following line is used to set the left and right boundaries and takes any scrollbars
  ;into account.
  getclientrect_(GadgetID(gadNum), eRect) 
  eRect\top = (GadgetHeight(gadNum) - textXY\cy*lineCount) / 2
  eRect\bottom = eRect\top + textXY\cy*lineCount 
;Check if the rectangle is too high.  
  if eRect\bottom<gadgetheight(gadNum) 
    SendMessage_(GadgetID(gadNum), #EM_SETRECT, 0, eRect) 
  endif
EndProcedure 


; ************************************************ 
; Main Window 
; ************************************************ 
If OpenWindow(0, 0, 0, 300, 200, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "StringGadget Centered Text") And CreateGadgetList(WindowID(0)) 
  ;--> #ES_CENTER will not work with a singleline StringGadget on Win95/NT4 
  StringGadget(0, 50, 10, 200, 80, "Vertical and Horizontal" + #CRLF$ + "Centered Text in" + #CRLF$ + "Multiline StringGadget", #PB_String_MultiLine | #ES_CENTER|#WS_VSCROLL|#ES_AUTOVSCROLL) 
  StringGadgetVCenter(0) 
  numlines = sendmessage_(gadgetid(0), #EM_GETLINECOUNT,0,0)
  
  Repeat
    eventid=waitwindowevent()
    if eventtype() = #PB_EventType_Change and eventgadgetid() = 0 and numlines<>sendmessage_(gadgetid(0), #EM_GETLINECOUNT,0,0)
      numlines = sendmessage_(gadgetid(0), #EM_GETLINECOUNT,0,0)
      StringGadgetVCenter(0) 

    endif  
  Until eventid = #PB_Event_CloseWindow 
EndIf 
End 
I may look like a mule, but I'm not a complete ass.
User avatar
oryaaaaa
Enthusiast
Enthusiast
Posts: 791
Joined: Mon Jan 12, 2004 11:40 pm
Location: Okazaki, JAPAN

Post by oryaaaaa »

Sparkie Thanks!
srod Thanks!

Very Nice code! PureBasic lovers increases! :D
akira takama
New User
New User
Posts: 1
Joined: Wed Dec 28, 2005 8:44 am

Post by akira takama »

The all of you that thank you very much.
I am a japanese PB user.
This next, please help it.

sorry for my bad english.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

* BUMP *

Just needed this and took me a while to find it as it seems like a rather rare request. While I tested this I noticed some flaws. First off, the code doesn't take the currently selected font into account wich makes the lines get splitted into 2 or more blocks. Second, if you made this fix you also need to add the 2 x 2 pixel border when calculating 'eRect\bottom' or it causes the same problem.

Here's my fixed version for future searches:

Code: Select all

Procedure StringGadgetVCenter(GadgetID)
	hwndEdit = GadgetID(GadgetID)
	
	LineCount = SendMessage_(hwndEdit,#EM_GETLINECOUNT, 0, 0)

	hdc = GetDC_(hwndEdit)
	SelectObject_(hdc,GetGadgetFont(0))
	GetTextExtentPoint32_(hdc,"ABC",3,fsz.SIZE)
	ReleaseDC_(hwndEdit,hdc)	
	
	GetClientRect_(hwndEdit,eRect.RECT)
	eRect\top = (GadgetHeight(GadgetID) - fsz\cy * LineCount) / 2
	eRect\bottom = eRect\top + (fsz\cy * LineCount) + 4
	
	If eRect\bottom < GadgetHeight(GadgetID)
		SendMessage_(hwndEdit,#EM_SETRECT,0,eRect)
	EndIf
EndProcedure

Text$ = "Vertical and Horizontal" + #CRLF$ + "Centered Text in" + #CRLF$ + "Multiline StringGadget"

OpenWindow(0,0,0,300,200,"Edit Control VCenter",#WS_SYSMENU | #WS_CAPTION | 1) 
CreateGadgetList(WindowID(0))
StringGadget(0,10,10,280,180,Text$,#ES_MULTILINE | #ES_CENTER )
SetGadgetFont(0,LoadFont(0,"Arial",12))
StringGadgetVCenter(0)

LinesNum = SendMessage_(GadgetID(0), #EM_GETLINECOUNT,0,0)

Repeat
	EventID = WaitWindowEvent()
	
	Select EventGadget() 
		Case 0
		If EventType() = #PB_EventType_Change And LinesNum <> SendMessage_(GadgetID(0),#EM_GETLINECOUNT,0,0)
		  LinesNum = SendMessage_(GadgetID(0),#EM_GETLINECOUNT,0,0)
		  
		  StringGadgetVCenter(0)
		EndIf
	EndSelect
Until EventID = #PB_Event_CloseWindow
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Post Reply