Quick Links: Gideros Home | Download Gideros | Developer Guide
Simple Log Window Class
  • antixantix +1 -1 (+5 / -0 )
    Member
    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 :)") -- 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.

    LogWindow.lua
    5K
  • antixantix +1 -1
    Member
    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 :)
    LogWindow.zip
    4K
  • antixantix +1 -1
    Member
    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.
    LogWindow.zip
    4K
  • antixantix +1 -1 (+1 / -0 )
    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
    LogWindow.zip
    5K

    Likes: rolfpancake

  • n1cken1cke +1 -1 (+2 / -0 )
    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.
    Chat.zip
    58K
    Chat.jpg
    640 x 690 - 186K

    Likes: antix, rolfpancake

  • talistalis +1 -1 (+2 / -0 )
    Guru
    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

  • @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 +1 -1 (+2 / -0 )
    Member
    @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 ;)
    LogWindow.zip
    6K

    Likes: talis, rolfpancake

  • totebototebo +1 -1 (+1 / -0 )
    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.totebogames.com
  • antixantix +1 -1
    Member
    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 +1 -1 (+1 / -0 )
    Member
    Here is the latest version which fixes a small issue with fitWidth() and fitHeight() not functioning quite the way they should have.
    LogWindow.zip
    6K

    Likes: totebo

  • SinisterSoftSinisterSoft +1 -1 (+3 / -0 )
    Maintainer
    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

  • antixantix +1 -1 (+1 / -0 )
    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

  • keszegh +1 -1 (+2 / -0 )
    Member
    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

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Login with Facebook Sign In with Google Sign In with OpenID

In this Discussion

Top Posters