Quote:I noticed the use of private and final, I am guessing you are being more explicit here for easy reading purposes, or is there another reason
Your code will still run if you remove private and final identifiers.
I use final when I assume the variables will not change while running the program. So they are ... final.
I use private when I do not want a function to be called from outside the class. Again, you can just remove it, and it will still work. It's just a matter of readability in this case. You don't have to go start searching outside the class to see where the function is being used because the only place it
can be used, is inside the class.
Quote:I see you used the a draw function inside a class, I am guessing this is the best way to make a loop inside a class
I did not use
the draw function inside the class. I just used a function called draw. Because that's what it does. It draws the text engine. You still need to call the function from within processing's draw function. But you can rename the function to something else, and it will still work.
Quote:Also what is happening in this bit of code, is this recursive, I am really puzzeled. And what is max determining here, why do you want to know what the max value is between 0 and the size of excess lines (), perhaps trying to prevent a null pointer error
void draw()
{
draw(max(0, lineBuffer.size()-maxLines));
}
No, it's not a recursive call. It calls a function with the same name, but with a different parameter. I made a private draw function which starts the drawing at a specific index, so that it can be used in both the draw() and the scrollText() function. The max(number1, number2) determines the maximum of 0 and a number that might possibly be negative. This happens when the size of the buffer is smaller than the maximum number of lines which can be shown on the screen. In this case the textengine should start drawing from the start of the buffer (0) and not buffersize-maxlines.
Quote:What is happening here, especially the one with the arrow confuses me. I can only find get in the refrence in conjecture with pVectors, and I don't think we're working with those. I am guessing it gets the difference between the excess and the buffer size one at a time or something How does the % work in this
for(int i = start; i < start+nbLines ; i++)
{
String line = (String)lineBuffer.get(i%lineBuffer.size()); <==
text(line,leftMargin,((i-start)*fontSize)+fontSize);
}
All lines are being drawn from the startindex to startindex+nblines. This last index might very well be larger than the number of items in our linebuffer, so we need to wrap the index around back to the start of the buffer.
lineBuffer.get(index) : get the string at the specified index
i%lineBuffer.size() : wrap the index around
The a%b operation (a modulo b) gives you the remainder after dividing a by b. So if you divide 7 by 4, the remainder is 3.
So if your index reaches the size of the buffer it goes back to 0.
Quote:Again the draw(); function weirds me out. I suppose this is the bit that does the timing, I can't get around how though.
draw(scrollIndex);
if(lineBuffer.size() - scrollIndex > maxLines)
{
scrollIndex = (scrollIndex + 1)%lineBuffer.size();
}
Also linkedList() and removeFirst() (just removes the first item of an array maybe) seem to be things in the processing library you call, but I don't really know what they are, and I can't find them in the reference.
It used the private draw function as explained above.
Processing is built on top of java, so you can use stuff which is not in the processing reference, but which is in
java api:
LinkedListI recommend using the stuff documented in processing though. As the java api stuff is a little bit harder to use. However, there just isn't a decent alternative for the LinkedList (it's the most efficient way to remove the first item in a list, which is done a lot in this code). If I'm wrong, please someone correct me!
I hope it helps.