Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Simple Log Window Class — Gideros Forum

Simple Log Window Class

antixantix Member
edited January 2016 in Code snippets
Hi all. While getting noobhub (http://giderosmobile.com/forum/discussion/4293/noobhub-free-opensource-multiplayer-and-network-messaging-for-gideros-coronasdk#Item_45) to work as a chat system I made this little Log Window class to show what was going on. Maybe some of you may find some use for it :)

Examples..
local myLog = LogWindow.new({ -- log window using custom options
  x         = 25,
  y         = 25,
  width     = 400,
  lines     = 16,
  color     = 0x555566,
  alpha     = 0.75,
  font      = myFont,
  textColor = 0xeeddee,
  textAlpha  = 0.8,
})
 
myOtherLog = LogWindow.new() -- another log window using all default values
 
myLog:toFront() -- bring log window to front
 
myLog:append("here is some text <img class="emoji" src="https://forum.giderosmobile.com/resources/emoji/smile.png" title=":)" alt=":)" height="20" />") -- print some text to the log
 
myLog:clear() -- clear the log
 
myLog:append("this text is green", 0x55bb55) -- print some colored text to the log
 
myLog:append("This is line1|This is line2|This is line 3") -- print multiple lines to log
 
myOtherLog:show(false) -- hide the other log
Notes:
Any options you don't specify will be replaced by default values (see the source).
You can insert linebreaks with the "|" character in your strings.
There is no history, once it has scrolled off the screen, its gone.

lua
lua
LogWindow.lua
5K
+1 -1 (+5 / -0 )Share on Facebook

Comments

  • antixantix Member
    edited June 2016
    Here is an update to the LogWindow class. It is no longer a subclassed shape, instead it is just a sprite. Some code has been tidied up also, mostly the init() and shutDown() functions. Enjoy :)
    zip
    zip
    LogWindow.zip
    4K
  • antixantix Member
    edited June 2016
    Here is another updated LogWindow class. This update modifies the way text is processed. Instead of splitting into paragraphs and then processing those, Logwindow now splits straight into words and processes those only.
    zip
    zip
    LogWindow.zip
    4K
  • antixantix Member
    And finally here is the last version which includes the ability to scroll back through previous lines by dragging your finger up and down.

    One thing to point out with this version is that because it now buffers any text you append to it, you will need to clear it periodically so you don't run out of RAM on your device. You can use count() to determine how many lines are currently bufered and if you think it's too many then you can call clear() to clear the text area.

    Maybe I will add some inbuilt buffer management but for now it's functional.
    LogWindow.png
    376 x 700 - 10K
    zip
    zip
    LogWindow.zip
    5K

    Likes: rolfpancake

    +1 -1 (+1 / -0 )Share on Facebook
  • n1cken1cke Maintainer
    Ok, my turn to "hijack threads" :)
    This is my old Chat class and it's no longer supported because of my new GUI system. It also has some flows and it's code need to be rewritten a bit. Other than that it's worth a look.
    zip
    zip
    Chat.zip
    58K
    Chat.jpg
    640 x 690 - 186K

    Likes: antix, rolfpancake

    +1 -1 (+2 / -0 )Share on Facebook
  • talistalis Guru
    edited June 2016
    Chatwars started :D Ok of course it is a joke. I am feeling so much amazed that new people start to share their work with the community.
    @n1cke i am pointing out again, i cant wait to see your new Gui system and chat class also seems so much usefull.
    And @antix new history addition and ability to write in different colors are also perfect additions.

    I am sure both classes have already answered to lots of needs. As myself i will check both of them on Monday and will decide which one to use.
    Thanks again guys.

    Likes: antix, n1cke

    +1 -1 (+2 / -0 )Share on Facebook
  • rolfpancakerolfpancake Member
    edited June 2016
    @antix:
    Thanks for your logwindow class. I wanted to make it responsive. Is this the right way to do so?
    appwidth = application:getDeviceWidth()
    sfactor = 2
     
    local LogWin = LogWindow.new({x = 0, y = 0, width = appwidth/sfactor, lines = 24, scale = sfactor})
    It fits the screenwidth now. Is there a better way to do so?

    -- Edit:
    I want to add something:
    The common newline identifier is "\n" instead of "/n". Is there a reason to use "/"? (see http://lua-users.org/wiki/StringsTutorial for reference)
  • antixantix Member
    edited June 2016
    @rolfpancake, no your method is great. I've now implemented it. There are now 2 new options, fitWidth and fitHeight. Specifying both = true will fill the entire screen with text now.

    I also found a bug where something strange happened after scrolling an entire page. That's resolved. It's looking really good now, thanks @rolfpancake for the great ideas :)

    LogWindow also now only redraws the textlines once it has scrolled an entire line, before it redrew every pixel scrolled.

    Oh, I also changed the /n's to \n's ;)
    zip
    zip
    LogWindow.zip
    6K

    Likes: talis, rolfpancake

    +1 -1 (+2 / -0 )Share on Facebook
  • totebototebo Member
    Comment #1: This thread should now be called "Feature complete LogWindow"
    Comment #2: This is so good it makes me want to cry happy tears.

    It needs to live on Github with a spotlight on it, not hidden away in this forum thread. Or maybe included in the official Gideros repository.

    Likes: antix

    My Gideros games: www.totebo.com
    +1 -1 (+1 / -0 )Share on Facebook
  • antixantix Member
    edited June 2016
    I'm happy it made you cry (in a good way) :D

    There's still a few more little things I might add to it. Does anyone else have any ideas?
  • antixantix Member
    Here is the latest version which fixes a small issue with fitWidth() and fitHeight() not functioning quite the way they should have.
    zip
    zip
    LogWindow.zip
    6K

    Likes: totebo

    +1 -1 (+1 / -0 )Share on Facebook
  • SinisterSoftSinisterSoft Maintainer
    edited March 2017
    You can get rid of using the bit library in this file by deleting line 24 and change lines 293 to 295:
    local r = 1/255 * bit.band(bit.ror(color, 16), 255)
    local g = 1/255 * bit.band(bit.ror(color, 8), 255)
    local b = 1/255 * bit.band(color, 255)
     
    changed to...
     
    local r=1/255*((color>>16)&0xff)
    local g=1/255*((color>>8)&0xff)
    local b=1/255*(color&0xff)

    Likes: antix, keszegh, pie

    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
    +1 -1 (+3 / -0 )Share on Facebook
  • antixantix Member
    @SinisterSoft, nice. I have a bunch of other code that uses the same stuff. Ahh the joys of updating zillions of lua files :D

    Likes: SinisterSoft

    +1 -1 (+1 / -0 )Share on Facebook
  • keszeghkeszegh Member
    edited March 2017
    thanks @SinisterSoft, i had another solution for hexToRgb, yours seems more efficient, so i changed to that.
    btw i at least did not use bitops, here it is for comparison:
        local blue=hex%256
        local green=(hex-blue)/256 %256
        local red=(hex-blue-256*green)/256^2
        return red/255,green/255,blue/255
    +1 -1 (+2 / -0 )Share on Facebook
Sign In or Register to comment.