This content is provided AS IS for archive purposes only. Content may be out of date with no guarantee of correctness.

Text - Elements - Hag GUI for Cobra - Static

Main Article

Text - Elements - Hag GUI for Cobra

Example of word-wrapped text and hyperlinks.

Text elements are individually styled blocks of text, supporting word-wrapping, \n line breaks, tooltips and hyperlinks.

Text elements expose the following read-only variables:

hText.x: Integer - Text x position
hText.y: Integer - Text y position
hText.w: Integer - Text width
hText.h: Integer - Text height
hText.enabled: Boolean - If text is enabled
hText.visible: Boolean - If text is visible
hText.href: String - Text hyperlink (default is an empty string)

For a ready-to-run example, see Example_Text or Example2D in the Examples download.


Program (icon:"hag\icons\window.ico")

   y: Integer
   frmMain: ^forms
   txtMain: ^hTexts
   txtLink1: ^hTexts
   txtLink2: ^hTexts
   txtLink3: ^hTexts
   btnClose: ^buttons         
   background: Element
   cursor_hand : Element
   cursor_text : Element
   tooltip : Element

Procedure UpdateMyCursor()
   lastMouse : Static Integer
   lastTip : Static String

hag_mouse of
           If lastMouse <> HAG_MOUSE_NORMAL then
               lastMouse = HAG_MOUSE_NORMAL

           If lastMouse <> HAG_MOUSE_HAND then
               lastMouse = HAG_MOUSE_HAND
           If lastMouse <> HAG_MOUSE_TEXT then
               lastMouse = HAG_MOUSE_TEXT


   { Tooltip }
   If hag_tooltip <> lastTip then
hag_tooltip <> "" then
       lastTip = hag_tooltip



   SetAppName("Text example")
   OpenScreen(320, 240, 32, FALSE, COB_SHOWBORDER+COB_SHOWCLOSE)
   background = CreateSprite(320,240)
   Cls(ToRGBA(235,233,237),background) ; Flip

   // Init GUI
   HagInit(320, 240, 1) // Start at sprite index 1 because of the background sprite    
   // Set up GUI Elements
   frmMain = CreateForm()
   txtMain = CreateText(frmMain, 20, 20, "This is an example of the Hag GUI using text elements.\n\nText elements automatically use text-wrapping and support /n linebreaks.\n\nAlso, hyperlinks!\n\n", 280)
   y = txtMain.y + txtMain.h // Get end of the Text block
   txtLink1 = CreateHyperlink(frmMain, 20, y, "Visit Google", "")
   txtLink2 = CreateHyperlink(frmMain, 20, y+20, "Visit TopHatStuff", "")
   txtLink3 = CreateHyperlink(frmMain, 20, y+40, "Hag GUI Documentation", "")
   btnClose = CreateButton(frmMain, 250, 200, 50, "Close")

   // Mouse
   tooltip = CreateSprite(320,20)
   cursor_hand = LoadSprite("img\cursor_hand.png")
   cursor_text = LoadSprite("img\cursor_text.png")
   While ExitRequested = FALSE
       If ButtonClicked(btnClose) then RequestExit
       If KeyHits(VK_ESCAPE) > 0 then RequestExit


Stay Subscribed

Follow me on twitter @golightlyb, subscribe to the RSS feed or get updates by e-mail.

You can also contact me directly - I make an effort to reply to every e-mail.