[Linux] Textcoloring in the EditorGadget

Share your advanced PureBasic knowledge/code with the community.
Christian
Enthusiast
Enthusiast
Posts: 154
Joined: Mon Dec 08, 2003 7:50 pm
Location: Germany

[Linux] Textcoloring in the EditorGadget

Post by Christian »

Hi!
Here is a little code showing how to color the text in an EditorGadget. Please don't ask how to color the whole background of the Gadget: I don't know it, either. Unfortunataly I didn't found something about this. Bur this is still a nice effect I think ... :)

Code: Select all

; Coded by Christian
; 
; Coloring an EditorGadget

Dim color.GdkColor(3)            ; Text Color
    color(0)\red = 65535
    color(0)\blue = 0
    color(0)\green = 0

    color(1)\red = 0
    color(1)\blue = 65535
    color(1)\green = 0

    color(2)\red = 0         :  color(3)\red = 0        ; Fore- and Background
    color(2)\blue = 0        :  color(3)\blue = 25000
    color(2)\green = 65535   :  color(3)\green = 0

; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;                       Programmcode
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

MWHnd.l = OpenWindow(0, 0, 0, 500, 500, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "Colored EditorGadget")
If MWHnd <> 0

   ; -- GadgetList
   If CreateGadgetList(MWHnd)
      edit.l = EditorGadget(0, 0, 0, 500, 500)

      gtk_text_insert_(edit.l, 0, color(0), 0, "Here is red text!"+Chr(10), -1)
      gtk_text_insert_(edit.l, 0, color(1), 0, "But perhaps you like blue a bit more?"+Chr(10), -1)
      gtk_text_insert_(edit.l, 0, color(2), color(3), "Or here green with a nice background?", -1)
   EndIf

EndIf

Repeat

  Select WaitWindowEvent()

    Case #PB_EventCloseWindow
         quit = 1

   EndSelect
Until quit = 1

End
es_91
Enthusiast
Enthusiast
Posts: 298
Joined: Thu Jan 27, 2011 12:00 pm
Location: DE

Re: [Linux] Textcoloring in the EditorGadget

Post by es_91 »

This is great, Christian, and exactly what I needed!

Perhaps, is there a similar solution somewhere to be found for the Mac? :)
:mrgreen:
Post Reply