[PB5.62b1] The text doesn't appear centred

Just starting out? Need help? Post your questions and find answers here.
User avatar
marcoagpinto
Addict
Addict
Posts: 939
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

[PB5.62b1] The text doesn't appear centred

Post by marcoagpinto »

The text doesn't appear centred (old bug).

Code: Select all

Declare about_purebasic()

Enumeration
  #WINDOW_ABOUT_PUREBASIC
  #WINDOW_MAIN
  #IMAGE_WINDOW_ABOUT_PUREBASIC
  #IMAGE_WINDOW_ABOUT_PUREBASIC_2
  #EDITOR_WINDOW_ABOUT_PUREBASIC
  #BUTTON_WINDOW_ABOUT_PUREBASIC_OKAY
  
EndEnumeration

CreateImage(31,407,133)
CreateImage(32,130,130)

OpenWindow(#WINDOW_MAIN,0,0,300,300,"Linux")

about_purebasic()

End


  Procedure about_purebasic()
    
    If OpenWindow(#WINDOW_ABOUT_PUREBASIC,0,0,550+4+4+4+4,283,"About PureBasic",#PB_Window_WindowCentered,WindowID(#WINDOW_MAIN))=#False : MessageRequester("Error", "Can't open a window.",#PB_MessageRequester_Error) : EndIf
    DisableWindow(#WINDOW_MAIN,#True)
            
    
    ; Big logo 407x133 pixels
    ImageGadget(#IMAGE_WINDOW_ABOUT_PUREBASIC,10+2+2+4,10,407,130,ImageID(31))
    
    ; Z logo 130x130 pixels
    ImageGadget(#IMAGE_WINDOW_ABOUT_PUREBASIC_2,2+2+GadgetX(#IMAGE_WINDOW_ABOUT_PUREBASIC)+GadgetWidth(#IMAGE_WINDOW_ABOUT_PUREBASIC)+5,10,130,130,ImageID(32))
    
    
    ; Editor Gadget with PureBasic information
    EditorGadget(#EDITOR_WINDOW_ABOUT_PUREBASIC,10+2+2+4,GadgetY(#IMAGE_WINDOW_ABOUT_PUREBASIC)+GadgetHeight(#IMAGE_WINDOW_ABOUT_PUREBASIC)+5,407+130-3-2-1,100+10-10,#PB_Editor_ReadOnly|#PB_Text_Center)    
    t$=""
    t$+"Coded/Compiled using PureBasic "+current_version_purebasic$+" - "+current_release_date_purebasic$+#LF$
    t$+Chr(34)+"Feel the ..Pure.. Power"+Chr(34)+#LF$+#LF$
    t$+"© 1998-"+FormatDate("%yyyy", #PB_Compiler_Date)+" Fantaisie Software."+#LF$
    t$+"www.purebasic.com"
    SetGadgetText(#EDITOR_WINDOW_ABOUT_PUREBASIC,t$)
    
    ; OKAY button
    ButtonGadget(#BUTTON_WINDOW_ABOUT_PUREBASIC_OKAY,220+2+2+4,253,90,25,"OK")


    ; Wait for the user to press the OKAY button
    okay=#False
    Repeat
      event=WaitWindowEvent()
      
      ; Pressed the close window gadget (Ubuntu) OR <ENTER> or <ESC>
      If (event=#PB_Event_CloseWindow) Or (event=#PB_Event_Menu And EventMenu()=1003) Or (event=#PB_Event_Menu And EventMenu()=1000)
        okay=#True     
      EndIf      
      
            
      Select event 
        Case #PB_Event_Gadget       
          Select EventGadget()
              
           ; OKAY button   
           Case #BUTTON_WINDOW_ABOUT_PUREBASIC_OKAY
              okay=#True
                         
             
         EndSelect
      EndSelect

    Until okay=#True
    
    ; Close the About window and activate the main window
    DisableWindow(#WINDOW_MAIN,#False)
    CloseWindow(#WINDOW_ABOUT_PUREBASIC)
    
  EndProcedure
  
; IDE Options = PureBasic 5.62 beta 1 (Linux - x64)
; CursorPosition = 20
; FirstLine = 4
; Folding = -
; EnableXP
User avatar
Kukulkan
Addict
Addict
Posts: 1352
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: [PB5.62b1] The text doesn't appear centred

Post by Kukulkan »

Upon you remove #PB_MessageRequester_Error, the same is for PB 5.46 LTS (x64) on Linux KDE Neon. All left aligned.
Oma
Enthusiast
Enthusiast
Posts: 312
Joined: Thu Jun 26, 2014 9:17 am
Location: Germany

Re: [PB5.62b1] The text doesn't appear centred

Post by Oma »

Hi!
There is no flag #PB_Text_Center for the EditorGadget.
An API solution is here http://www.chabba.de/Linux/EditorGadget ... tionSet.pb.

Regards, Charly
PureBasic 5.4-5.7, Linux: (X/L/K)Ubuntus+Mint - Windows XP (32Bit)
PureBasic Linux-API-Library & Viewer: http://www.chabba.de
User avatar
marcoagpinto
Addict
Addict
Posts: 939
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: [PB5.62b1] The text doesn't appear centred

Post by marcoagpinto »

Oma wrote:Hi!
There is no flag #PB_Text_Center for the EditorGadget.
An API solution is here http://www.chabba.de/Linux/EditorGadget ... tionSet.pb.

Regards, Charly
But it works on Windows, why not in Linux?
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: [PB5.62b1] The text doesn't appear centred

Post by mk-soft »

Works only randomly on Windows. However, if an invalid use of the flag

Window is not Linux and Linux is not Mac
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: [PB5.62b1] The text doesn't appear centred

Post by Shardik »

marcoagpinto wrote:The text doesn't appear centred (old bug).
It's not a bug. It's simply not implemented in PB's EditorGadget to center the text.

To center the whole text in the EditorGadget in Windows you have to use the flag ES_CENTER when creating the EditorGadget. In Linux and MacOS you have to use the following API functions to center the whole text in an existing EditorGadget:

Code: Select all

  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Linux
      gtk_text_view_set_justification_(GadgetID(Editor), #GTK_JUSTIFY_CENTER)
    CompilerCase #PB_OS_MacOS
      CocoaMessage(0, GadgetID(Editor), "setAlignment:", #NSCenterTextAlignment)
  CompilerEndSelect
For your conveniance I have programmed the following example which displays a PureBasic about window with centered text in the EditorGadget on Linux, MacOS and Windows. I have tested it successfully on the following operating systems:

- Linux Mint 18.1 "Serena" x64 with PB 5.61 x64 in GTK2 und GTK3

Image


- MacOS 10.13.1 "High Sierra" with PB 5.61 x86 and x64
- MacOS 10.6.8 "Snow Leopard" with PB 5.61 x86
Image
- Windows 7 x64 SP1 with PB 5.61 x86 und x64

Image

Code: Select all

EnableExplicit

UsePNGImageDecoder()

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  ; ----- Only necessary for extracting PureBasic's 48x48 icon from
  ;       PureBasic.Exe

  ImportC ""
    SHGetImageList_(ImageType.I, ImageListID.I, *ImageList) As "SHGetImageList"
  EndImport

  DataSection
    IID_IImageList:
    Data.L $46EB5926
    Data.W $582E, $4017
    Data.B $9F, $DF, $E8, $99, $8D, $AA, $09, $50
  EndDataSection
CompilerEndIf

Procedure DisplayAboutWindow()
  Protected AboutWindow.I
  Protected Editor.I
  Protected EditorFlags.I
  Protected FontArialBold.I
  Protected FontSize.I
  Protected Height.I
  Protected PBLogo.I
  Protected PBIcon.I
  Protected PBVersion.S
  Protected Text.S
  Protected Width.I

  EditorFlags = #PB_Editor_ReadOnly | #PB_Editor_WordWrap
  PBVersion = Str(#PB_Compiler_Version)
  PBVersion = Left(PBVersion, Len(PBVersion) - 2) + "." + Right(PBVersion, 2)

  AboutWindow = OpenWindow(#PB_Any, 0, 0, 1, 1, "About PureBasic",
    #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_Invisible)

  ; ----- Load PureBasic's big logo with 381x68 pixels

  PBLogo = LoadImage(#PB_Any, #PB_Compiler_Home +
    "examples/3d/Data/PureBasicLogo.bmp")
  ImageGadget(#PB_Any, 10, 10, ImageWidth(PBLogo), ImageHeight(PBLogo),
    ImageID(PBLogo))
   
  ; ----- Load PureBasic's Z logo with 48x48 pixels

  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Linux
      PBIcon = LoadImage(#PB_Any, #PB_Compiler_Home + "logo.png") 
      FontSize = 13
    CompilerCase #PB_OS_MacOS
      PBIcon = LoadImage(#PB_Any, #PB_Compiler_Home + "logo.png") 
      FontSize = 16
    CompilerCase #PB_OS_Windows
      ; ----- In PB's Windows version the file logo.png is missing, so the
      ;       PureBasic icon has to be extracted from PureBasic.Exe

      Protected FileInfo.SHFILEINFO
      Protected IconHandle.I
      Protected ImageList.iImageList
      Protected Shell32.I

      SHGetFileInfo_(#PB_Compiler_Home + "PureBasic.Exe", -1, @FileInfo,
        SizeOf(SHFILEINFO), #SHGFI_SYSICONINDEX)
      Shell32 = OpenLibrary(#PB_Any, "Shell32.DLL")

      If Shell32
        If CallFunction(Shell32, "SHGetImageList", #SHIL_EXTRALARGE,
          ?IID_IImageList, @ImageList) = 0
          ImageList\GetIcon(FileInfo\iIcon, #ILD_TRANSPARENT, @IconHandle)
          PBIcon = CreateImage(#PB_Any, 48, 48, 32, #PB_Image_Transparent)

          If StartDrawing(ImageOutput(PBIcon))
            DrawImage(IconHandle, 0, 0, 48, 48)
            DestroyIcon_(IconHandle)
            StopDrawing()
          EndIf

          CloseLibrary(Shell32)
        EndIf
      EndIf

      FontSize = 13

      ; ----- Add Windows flag to center text in EditorGadget
      EditorFlags | #ES_CENTER
  CompilerEndSelect

  ImageGadget(#PB_Any, ImageWidth(PBLogo) + 20, 20, ImageWidth(PBIcon),
    ImageWidth(PBIcon), ImageID(PBIcon))
  Width = ImageWidth(PBLogo) + ImageWidth(PBIcon) + 20
  Editor = EditorGadget(#PB_Any, 10, ImageHeight(PBLogo) + 10, Width, 130,
    EditorFlags)
  Height = ImageHeight(PBLogo) + GadgetHeight(Editor)
  FontArialBold = LoadFont(#PB_Any, "Arial", FontSize, #PB_Font_Bold)

  If FontArialBold
    SetGadgetFont(Editor, FontID(FontArialBold))
  EndIf

  Text = #LF$ +
    "Coded/Compiled with PureBasic " + PBVersion + #LF$ +
    Chr(34) + "Feel the ..Pure.. Power" + Chr(34) + #LF$ + #LF$ +
    "© 1998-" + FormatDate("%yyyy", #PB_Compiler_Date) +
    " Fantaisie Software." + #LF$ +
    "www.purebasic.com"
  SetGadgetText(Editor, Text)

  ; ----- Center contents of EditorGadget

  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Linux
      gtk_text_view_set_justification_(GadgetID(Editor), #GTK_JUSTIFY_CENTER)
    CompilerCase #PB_OS_MacOS
      CocoaMessage(0, GadgetID(Editor), "setAlignment:", #NSCenterTextAlignment)
  CompilerEndSelect

  ; ----- Resize window to contain images and EditorGadget

  ExamineDesktops()
  ResizeWindow(AboutWindow, (DesktopWidth(0) - Width + 20) / 2,
    (DesktopHeight(0) - Height + 20) / 2, Width + 20, Height + 20)
  HideWindow(AboutWindow, #False)
  SetActiveGadget(-1)

  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
EndProcedure

DisplayAboutWindow()
Last edited by Shardik on Tue Jan 30, 2018 9:30 am, edited 1 time in total.
User avatar
marcoagpinto
Addict
Addict
Posts: 939
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: [PB5.62b1] The text doesn't appear centred

Post by marcoagpinto »

Thank you guys for all the help!
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: [PB5.62b1] The text doesn't appear centred

Post by walbus »

It look right and centered works not on gtk3

Code: Select all

If OpenWindow(0, 0, 0, 270, 160, "TextGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    TextGadget(0, 10,  10, 250, 20, "TextGadget Standard (Left)")
    TextGadget(1, 10,  70, 250, 20, "TextGadget Center", #PB_Text_Center)
    TextGadget(2, 10,  40, 250, 20, "TextGadget Right", #PB_Text_Right)
    TextGadget(3, 10, 100, 250, 20, "TextGadget Border", #PB_Text_Border)
    TextGadget(4, 10, 130, 250, 20, "TextGadget Center + Border", #PB_Text_Center | #PB_Text_Border)
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
As a Hint : DrawText_EX and DrawText_BF can handle this worry free on all OS :wink:
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: [PB5.62b1] The text doesn't appear centred

Post by Shardik »

walbus wrote:It look right and centered works not on gtk3
It's fixed in PB 5.46 and PB 5.62 final!

Did you test my example code from above which utilizes the EditorGadget (not the TextGadget as in your example). My example code works on Linux Mint 18.1 'Serena' with Cinnamon in PB 5.46, PB 5.61 and PB 5.62 final like a charm on both GTK2 and GTK3.
Post Reply