Computer Science Canada

Scrollbox Class

Author:  Raknarg [ Wed Jan 25, 2012 1:02 pm ]
Post subject:  Scrollbox Class

I made another class for your games. This here is a scrollbox. Basically whenever you want text added into it, you call the procedure add_line with whatever text you want and it'll throw it in. You can also scroll through the text history at your leisure. Theres another function, clear_text, which you can use to clear all history. I'll include an example I made:
Turing:

import "ScrollBox.tu"

setscreen ("offscreenonly")

var key : array char of boolean
var text : string

var box : pointer to ScrollBox
new ScrollBox, box

ScrollBox (box).initialize (25, 100, 200, Font.New ("Arial:10"), black, darkgrey, white, 15, 8)

loop
    Input.KeyDown (key)
    if key (KEY_ENTER) then
        get text : *
        ScrollBox (box).add_line (text)
    elsif key (KEY_ESC) then
        ScrollBox (box).clear_text
    end if
    ScrollBox (box).scrollbox_change
    ScrollBox (box).draw
    View.UpdateArea (0, 0, maxx, maxy)
    delay (100)
    cls
    Input.Flush
end loop

Some notes:
-This program requires the button class i made, which can be found here: http://compsci.ca/v3/viewtopic.php?t=30797
-The initialization is as follows: left x coordinate, bottom y coordinate, right x coordinate, font, fill colour, border colour, font colour, font size (or size of each line), number of visible lines
-You must include scrollbox_change in your loop for the buttons to actually work.

If you have any questions or suggestions, go ahead

Author:  Velocity [ Wed Jan 25, 2012 4:38 pm ]
Post subject:  RE:Scrollbox Class

Nice work! I love it.
Thats new, i never knew that with turing you can import different files too, assuming they are made in turing.

Author:  Raknarg [ Wed Jan 25, 2012 5:20 pm ]
Post subject:  RE:Scrollbox Class

Yeah, it can import other modules and classes.

Author:  Raknarg [ Fri Feb 03, 2012 1:22 pm ]
Post subject:  RE:Scrollbox Class

as long as the word unit is on the top of the file, I should say

Author:  Raknarg [ Sat Aug 04, 2012 11:05 pm ]
Post subject:  Re: Scrollbox Class

interesting update, gave that scrollbox a slider. Scrollboxes love sliders. Slider can be seen here: http://compsci.ca/v3/viewtopic.php?p=263021

From my recent addition, the slider class which I added vertical and reverse direction. Normally small to big is left to right or bottom to top. Quick change.

Author:  Raknarg [ Sun Aug 12, 2012 7:38 pm ]
Post subject:  Re: Scrollbox Class

Update again, fixing add_line, just replace it with this:

Turing:

proc add_line (s : string)
        var str : string := s
        if Font.Width (str, font) < x2 - x1 - 23 then
            new text, upper (text) + 1
            if upper (text) > numlines then
                scrollbar -> maxValue += 1
            end if
            text (upper (text)) := str
            bottomline := upper (text)
        else
            for i : 1 .. length (str)
                if Font.Width (str (1 .. i), font) > x2 - x1 - 23 then
                    for decreasing j : i .. 1
                        if str (j) = " " then
                            new text, upper (text) + 1
                            if upper (text) > numlines then
                                scrollbar -> maxValue += 1
                            end if
                            text (upper (text)) := str (1 .. j - 1)
                            bottomline := upper (text)
                            add_line (str (j + 1 .. *))
                            return
                        end if
                    end for
                end if
            end for
            for i : 1 .. length (str)
                if Font.Width (str (1 .. i), font) > x2 - x1 - 23 then
                    new text, upper (text) + 1
                    if upper (text) > numlines then
                        scrollbar -> maxValue += 1
                    end if
                    text (upper (text)) := str (1 .. i - 1)
                    bottomline := upper (text)
                    add_line (str (i .. *))
                    return
                end if
            end for
        end if
    end add_line


: