Weird... i am very new to PB, so may not understand too many things...
Code: Select all
;EnableExplicit
Enumeration
#Str_1
#Info_1
#Str_2
#Info_2
EndEnumeration
; WinAPI size detection:
Procedure.u GetTextPixData_1(id.l, size.a)
; Protected hDC.l, hFont.l, result.u, lpSize.???
hDC = GetDC_(GadgetID(id))
hFont = SendMessage_(GadgetID(id), #WM_GETFONT, 0, 0)
If hFont And hDC
SelectObject_(hDC, hFont)
EndIf
GetTextExtentPoint32_(hDC, GetGadgetText(id), Len(GetGadgetText(id)), lpSize.SIZE)
If size = 0
result = lpSize\cx
ElseIf size = 1
result = lpSize\cy
EndIf
ProcedureReturn result
EndProcedure
; PB size detection:
Procedure.u GetTextPixData_2(id.l, size.a)
Protected str$
If StartDrawing(WindowOutput(0))
str$ = GetGadgetText(id)
If size = 0
result = TextWidth(str$)
ElseIf size = 1
result = TextHeight(str$)
EndIf
StopDrawing()
EndIf
ProcedureReturn result
EndProcedure
If OpenWindow(0, 0, 0, 400, 400, "Text pixel size detection", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_TitleBar )
TextGadget(#Str_1, 8, 8, 192, 16, "0")
str$ = "Info 1: w = " + Str(GetTextPixData_1(#Str_1, 0)) + ", h = " + Str(GetTextPixData_1(#Str_1, 1)) + " px"
TextGadget(#Info_1, 208, 8, 192, 16, str$)
TextGadget(#Str_2, 8, 30, 192, 20, "0")
str$ = "Info 2: w = " + Str(GetTextPixData_2(#Str_2, 0)) + ", h = " + Str(GetTextPixData_2(#Str_2, 1)) + " px"
TextGadget(#Info_2, 208, 30, 192, 16, str$)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
First - when using WinAPI (Procedure #1) - size of "0" in my system and my windows default font (i'm not using aero/glass etc, and as close as possible to classic theme) takes 6x13 pixels. When using PB TextWidth/TextHeight - 8x16px.
So when i try to compose textgadgets i have big gaps between them and i need manually subtract some from width and height from what calculated. But it's crazy - if there will be another font or size.
What i'm doind wrong?
And another question - when i use EnableExplicit i can't compile because lpSize is undeclared and i don't know how to declare it because it's WinAPI parameter (no experience in WinAPI, but maybe it will be needed sometime somewhere)
UPD: i've found info about ProGUI extension/library, there are TextControlEx() procedure (compiled in dll...) and author make possible to use escape codes in text to colorise (make bold/italic/underline/strike through/link effects) it. Anyone know something about it? So there is a chance to make only one TextGadget, not 2-3 to "hide" not important part of text? And as i understand - text is at the transparent bg. Maybe he uses ImageGadget?..
And harder question - if i wish to do the same in ListViewGadget? At the end i need some sort of list with few columns, where line/cell can be colored in any color, partially colored (for example, 20% of the cell in one color, 40% in another, ant last 40% in another one), with or without mini-icon/pict, with possibility to click on line/column and do some work with this. It's impossible?