Page 2 of 2

Re: Updated v3.0:TextGadget Vl & Hl Centered Aligned

Posted: Sat Jul 10, 2010 9:22 pm
by Vera
@ RASHAD

works fine as before :)

Still there is one mischief within my implementation. The #PB_Text_Center parameter is somehow corrupted / deactivated by the gtk calls. As long as you have more than a few words you always get the wanted result as the texts on the lines are centered, although it is on the whole left aligned. But you'll only experience this when you use less words than a single line-width would take. I'll try to figure this out if I can or ask in a different thread.

As for the mischief with the fontsize I mentioned. It is only due to the windows & gadget dimensions. If you only have few text which can fit in, than bigger fontsizes are unproblematic - vice versa just encrease the outer dimensions. :wink:

greeting ~ Vera

Re: Updated v3.0:TextGadget Vl & Hl Centered Aligned

Posted: Mon Jul 12, 2010 7:52 pm
by Vera
Hi RASHAD,

while trying to hunt that center-prob I played around a bit and added a horizontal modulation. I like it (though it's far from being finished) and it removes the left- alignment in most cases.
Have a look - maybe it's good for a clue ;)

Code: Select all

Global Text$,FSize,x,y,GW,GH,FColor,BColor,count
Global Dim A$(0)
fs = 4  ; only relevant when testing the loop

Procedure TextGadgetEx(Gadget,x,y,GW,GH,FColor,BColor)
    StartDrawing(WindowOutput(0))
    DrawingFont(FontID(0))
    For i = 1 To count
         A$(i) =  StringField(Text$,i, " ")
    Next
    run = 0
    k = 1
    NLines = 1
;    xG = 35             ; to apply a bit left indention (absolut value: ok for WIN)
     xG = (GW/100)*(3+(FSize/2))    ; any percentage of GW is better -> gives better results on Linux
     GW2 = GW - 2*xG     ; to apply according right indention
;      xG = 0          ; just to use for quick toggling 
;      GW2 = GW        ; to the original values 
    While k <> count
       If run = 0
          TW = TW + TextWidth(A$(k))
       Else
          TW = TW + TextWidth(" "+A$(k))
       EndIf
       If TW < GW2      ; use applied gadget-width
          run = 1
          k = k + 1
       Else
          run = 0       
          TW = 0
          NLines = NLines + 1
       EndIf 
    Wend
    TH = TextHeight("W")
    StopDrawing()
    LH = NLines * TH
    Debug NLines
    Debug xG
    Debug GW2
    mLH = (GH - LH)/2
    UseGadgetList(0)
    result = ContainerGadget(#PB_Any, x, y,GW,GH,#PB_Container_Single)
    SetGadgetColor(result,#PB_Gadget_BackColor, $666600)   ;  BColor a different color shows the frame
    TextGadget(Gadget,xG,mLH-2,GW2,LH,Text$,#PB_Text_Center)     ; set applied gadget-width
    SetGadgetColor(Gadget,#PB_Gadget_FrontColor,FColor)
    SetGadgetColor(Gadget,#PB_Gadget_BackColor,BColor)   
    SetGadgetFont(Gadget,FontID(0))
   
;    CompilerIf #PB_Compiler_OS = #PB_OS_Linux
; ;     CompilerSelect #PB_Compiler_OS        ; CompilerSelect is obsolete if only one exception is needed
; ;       CompilerCase #PB_OS_Linux   
;         gtk_label_set_line_wrap_(GadgetID(Gadget),1)
;         gtk_widget_set_size_request_(GadgetID(Gadget), GW2, LH)     ;  set applied gadget-width
;         gtk_label_set_justify_(GadgetID(Gadget), #GTK_JUSTIFY_CENTER) 
; ;     CompilerEndSelect
;   CompilerEndIf
   
  CloseGadgetList()
EndProcedure

; While n <= 3      ; just for fun
;   n+1             ; trial to loop procedure with dif. fontsizes
; FSize = fs + 4    ; but doesn't work fully yet ;)
  
FSize = 18         ; comment out when testing the loop
LoadFont(0,"Georgia",FSize)
Text$ = "Test Vertical and Horizontal Centered Text in Multiline TextGadget For MyTrial and more"
count = CountString(Text$," ") + 2
ReDim A$(count)
OpenWindow(0,0,0,400,300,"Edit Control VCenter",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
TextGadgetEx(0,10,10,380,280,$0002FF,$00ccff)             ;#Gadget,x,y,Width,Height,FrontColor,BackColor

; fs = FSize
; Debug fs
; Delay(3000)
; Wend

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
With different font-sizes you do not only have to consider the textamount and needed lines by a given width, but also consider the presentation on account of the available gadgetdimension. I think it somehow has to be calculated twice. First what you already do and then check the positioning. This way you may also retain missfitting oversizes.

This is only loud thinking ~ I hope I don't disturb you ;)

greetings ~ Vera

Re: Updated v3.0:TextGadget Vl & Hl Centered Aligned

Posted: Mon Jul 12, 2010 8:50 pm
by RASHAD
Hi Vera
Tested with Win 7 and different font name and different font sizes
It looks fantastic (VG job)

Now what about Linux?

Re: Updated v3.0:TextGadget Vl & Hl Centered Aligned

Posted: Mon Jul 12, 2010 10:33 pm
by Vera
RASHAD wrote:It looks fantastic (VG job)
W :lol: W ~ more than I imagined in my wildest dreams
Now what about Linux?
To apply the according right indention it needs to be: GW2 = GW - 2*xG. Why it has to be 2*xG is strange to me, but I couldn't find out the reason.
For Linux GW2 is acceptable but GW - xG is much better for more sizes. The trouble is that it depends on small or big fonts. The truth is somewhere dynamically inbetween, that's why I mentioned the need of two calculation-loops.

But to conclude, I would change
gtk_widget_set_size_request_(GadgetID(Gadget), GW2, LH)
to
gtk_widget_set_size_request_(GadgetID(Gadget), GW2 + xG, LH)
until you might develope an entirely different formular.

cheers ~ Vera

Re: Updated v3.0:TextGadget Vl & Hl Centered Aligned

Posted: Tue Jul 13, 2010 7:13 am
by RASHAD
@Vera Hi
I deleted the last post I am afraid you get the impression that we should stop modifing and improving the code

Next is a work around for the presence of the ampersand(&) in the text
There is a bug even you can not use ReplaceString() without troubles

Code: Select all


Global Text$,FSize,x,y,GW,GH,FColor,BColor,count
Global Dim A$(0)
fs = 4  ; only relevant when testing the loop

Procedure TextGadgetEx(Gadget,x,y,GW,GH,FColor,BColor)    
    StartDrawing(WindowOutput(0))
    DrawingFont(FontID(0))
    For i = 1 To count
         A$(i) =  StringField(Text$,i, " ")
         If A$(i) = "&"
            A$(i) = "&&"
         EndIf
         Tex$ =Tex$ + " " + A$(i)
    Next
    Tex$ = LTrim(Tex$)
    run = 0
    k = 1
    NLines = 1
;    xG = 35             ; to apply a bit left indention (absolut value: ok for WIN)
     xG = (GW/100)*(3+(FSize/2))    ; any percentage of GW is better -> gives better results on Linux
     GW2 = GW - 2*xG     ; to apply according right indention
;      xG = 0          ; just to use for quick toggling 
;      GW2 = GW        ; to the original values 
    While k <> count
       If run = 0
          TW = TW + TextWidth(A$(k))
       Else
          TW = TW + TextWidth(" "+A$(k))
       EndIf
       If TW < GW2      ; use applied gadget-width
          run = 1
          k = k + 1
       Else
          run = 0       
          TW = 0
          NLines = NLines + 1
       EndIf 
    Wend
    TH = TextHeight("W")
    StopDrawing()
    LH = NLines * TH
    mLH = (GH - LH)/2
    UseGadgetList(0)
    result = ContainerGadget(#PB_Any, x, y,GW,GH,#PB_Container_Single)
    SetGadgetColor(result,#PB_Gadget_BackColor, $666600)        ;  BColor a different color shows the frame
    TextGadget(Gadget,xG,mLH-2,GW2,LH,Tex$,#PB_Text_Center)     ; set applied gadget-width
    SetGadgetColor(Gadget,#PB_Gadget_FrontColor,FColor)
    SetGadgetColor(Gadget,#PB_Gadget_BackColor,BColor)   
    SetGadgetFont(Gadget,FontID(0))
   
  CloseGadgetList()
EndProcedure

  
FSize = 20         ; comment out when testing the loop
LoadFont(0,"Arial",FSize)
Text$ = "Test Vertical and Horizontal Centered Text in Multiline TextGadget For MyTrial & Others and more"
count = CountString(Text$," ") + 2
ReDim A$(count)
OpenWindow(0,0,0,400,300,"Edit Control VCenter",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
TextGadgetEx(0,10,10,380,280,$0002FF,$00ccff)             ;#Gadget,x,y,Width,Height,FrontColor,BackColor

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow

Re: Updated v3.0:TextGadget Vl & Hl Centered Aligned

Posted: Tue Jul 13, 2010 11:04 am
by Vera
> I deleted the last post I am afraid you get the impression that we should stop modifing and improving the code

In a way - yes. It sounded like you're satisfied with the latest achivement at the moment and that would be ok. (only you might update (1.posting) or post the actual valid version for others not to search all single changes)

In case of adding special effects I thought it better to start them in a new thread - like 'Variations on a TextGadget'. (There you are free to introduce independent issues. Maybe keep it as idea for later)

As for the new issue with the ampersand(&) I didn't find any trouble. Within a textstring they are taken as ordinary characters and displayed properly. I'm also able to replace them or any other words if I use
Text$ = ReplaceString(Text$, "&", "&&",1)
before the counting starts
For i = 1 To count
A$(i) = StringField(Text$,i, " ")
Next

Still your work around works as well :)
Could you please specify the troubles you encountered and what you're aiming at with replacing of strings.

greetings ~ Vera

Re: Updated v3.0:TextGadget Vl & Hl Centered Aligned

Posted: Tue Jul 13, 2010 11:18 am
by RASHAD
@Vera
No I am not satisfied, I was trying to tell you what in my mind for adding colors and effects
But I was trying not to use API and stick with native commands and that will make the task
very difficult
@Vera we are parteners in this thread ,so behave like a partner and do not give a shet to what I am saying

If the String has only one & ,it will not show up(Win 7 x64)
Now test your way for ReplaceString() and look at the right of & (No space)

Re: Updated v3.0:TextGadget Vl & Hl Centered Aligned

Posted: Tue Jul 13, 2010 11:39 am
by Vera
RASHAD wrote:do not give a shet to what I am saying
Gasp! - :shock: - that's hard-core as I'm spending a lot of time to support what your aiming at.

By no means had I any intention to offend or disregard you.
There can only be a misunderstanding or a unhappy translation, as I'm no native english speaker myself.
I also take a lot of time before posting to assure that my writing is ok.

sorry - but I don't see what I did wrong

Vera

Re: Updated v3.0:TextGadget Vl & Hl Centered Aligned

Posted: Tue Jul 13, 2010 11:54 am
by RASHAD
@Vera
I am not native english speaker too (you never said any thing abused me and that is true)
So forget all of this and roll up your sleeves and get in

Re: Updated v3.0:TextGadget Vl & Hl Centered Aligned

Posted: Wed Jul 14, 2010 2:15 pm
by Vera
Hello Rashad,

I've found that ampersand mischief on WIN XP too, switching it to an underscore when used in textgadget. My replacestring works for XP and doesn't remove an existing rightsighted blank. But as you workaround works as well, just use it.

But for Unix this trouble doesn't exist and would result showing two ampersands. So when changing and renaming the text string for windows you only need to add a SetGadgetText(Gadget, Text$) with the unchanged string into the CompilerIf demand and your done.

greeting ~ Vera

Re: Updated v3.0:TextGadget Vl & Hl Centered Aligned

Posted: Thu Jul 15, 2010 5:45 pm
by RASHAD
Glad to hear that
@Vera I do not care much for the code as I do for your friendship
Thanks mate