Lua Ti-nspire platform.window:invalidate() - lua

I've searched many places for what platform.window:Invalidate() exactly does to the drawing screen on the Ti-Nspire, but sadly no in-depth answers come up.
Some sources say that by calling it 'invalidates' the window, or calls on.paint function. I don't exactly understand this, including why arguments can be included in the Invalidate(blah,blah2,blah3,blah4); does this mean that the on.paint function is called and can only repaint the portion defined, as if the other area not included in the argument is permanent?

I just found here that the on.paint gets 'flagged to fire' upon calling platform.window:Invalidate().
The entire window can be forced to repaint with by calling the function with no arguments : platform.window:invalidate()
If arguments are given, it will only be able to paint onto the area of x, y, width, height. The area outside of this outline is unaffected.

Related

How draw a line in a window with wxWidget with erlang?

I try to draw a line in a window with wxWidget in Erlang. I tried:
wx:new(),
Frame = wxFrame:new(wx:null(), ?wxID_ANY, "Hello"),
wxDC:drawLine(50,50),
I get an error:
undefined function wxDC:drawLine/2
I read the documentation here, but I don't understand how to do this:
http://www.erlang.org/doc/man/wxDC.html#drawLine-3
X Windows programming isn't quite that simple, and I'm not quite sure how you are expecting to draw a line with parameters like [50, 50], that's at best a point, and a line needs 2 points, and wxDC:drawLine needs to know where to draw the line too, because you could have many frames.
You can create a frame like this, yes (used -1 instead of the macro because I'm using the shell here):
Wx = wx:new().
Frame = wxFrame:new(wx:null(), -1, "Hello").
Now the important bit, you can't just draw on the frame, you have to register a callback to handle REdrawing. This is because a frame can be covered up at any point by other windows, or because you minimise it, resize it, etc. In fact you don't necessarily need to handle a REdraw for all those cases, but you get the idea.
So, this is not the most efficient, because it performs a redraw regardless of the event, by responding to ANY paint event by drawing a line, but obviously that will do the job:
wxFrame:connect(Frame, paint, [{callback,
fun(_Evt, _Obj) ->
io:format("paint~n"),
DrawContext = wxPaintDC:new(Frame),
wxDC:drawLine(DrawContext, {50, 50}, {150,100}),
wxPaintDC:destroy(DrawContext)
end
}]).
I added the io:format in there so you can see that it is being called when you interact with the window, or some other window interacts with it, because without the io:format call it's a bit invisible in its effect, other than making sure there's always a line in your window.
I also used a draw context. I won't go into it here, I'm afraid it's just one of a load of things you need to learn about X Windows programming, but basically, just be aware for now, you need to have a draw context for your frame, and use that to actually draw with.
One last thing, you need to actually display the frame, if you want to see it, like this:
wxFrame:show(Frame).
Now you should see a window, with a line.
Michael's answer tells you how to do what you want to do, so let me address the confusion about the error
message.
In Erlang, functions that have the same name but different number of arguments are considered separate functions. The number of arguments is called the "arity", and is sometimes indicated as e.g. /2 after the function name.
Your code is calling wxDC:drawLine with two arguments, but you get an error saying that wxDC:drawLine/2 is undefined. In the documentation, you can see that the function you want is wxDC:drawLine/3, which takes three arguments (the first being the draw context, and the second and third being the points between which you want to draw a line).

Lua script for iOS getColors within range?

I am trying to capture the pixel color of a specific letter in a font within an iOS app. I'd then use that color in an if/then statement to determine the next action of my script. I'm finding no easy way to determine if the color/colors I'm finding are the right ones. Here's my current process: I start recording my inputs and continuously click around the letter. I end up with something like touchdown(123,456). I change that to alert(getColor(123,456)) and run, which produces a popup that tells me the color such as 3094841 (not sure why the colors are in numeric format, but they are). I do this for each touchdown line that is captured. The problem is, I don't know an easy way to determine which color is the small letter I'm trying to tap.
Is there a lua function that will capture and display a range of colors between 2 points? If there were, I could see the commonality of all of the colors within the 2 points and make at least an educated guess as to which is the color in the font. Or even more useful - is there a tool I can use to type in the color I'm getting back and have it display the corresponding color, so I can compare them. That'd be the easiest. Hope this makes sense. Any help would be awesome. In case it matters, I'm using Autotouch 8 on an iPhone 5.
TIA
I use this function often in my games.
I find the easiest way to get a color you want to execute every single time is to take a snap of the screen you're checking and then use the helper on getColor(x, y)
And you can use this to alert your color.
local color = getColor(x, y)
alert(color)
-- You can also use:
log(color)--this one keeps it in your log in case you can write it down immediately.
To use this in an if/then statement
function = namedfunction()
local color = getColor(x, y)
if color == YOURCOLOR then
else
end
end
namedfunction();
Note that I have the iPhone 5 iOS 8.3 and I have the most recent AutoTouch from Cydia. If you don't have the helper when you're scripting it might be worth it to check if Cydia offers a capatable version.
Edit: I am running version 3.5.3-8 of Autotouch.

Lua tables and screen coordinates. For every {x} at y do

I'm having a little curious sense of art in programming at the moment. And I want to script my Autotouch App on my iOS to generate Pixel Art inside of another app.
I was doing this previously by typing in code to tap at the screen at one coordinate, I did this 2000+ times and it got the job done. But there should be a better, smarter way to get it done.
My test image is going to be very symetrical to make things easy.
There is a code in the Lua app that I'm using to simply tap on the screen,
tap(x, y)
But I want to set this up like:
tap({xTable}, y)
But I'm not sure if that will "tap" at each x coordinate that I've listed for the y variable.
I want to paint a pixel at one very specific coordinate, and then step 5 pixels away and paint the next one, and repeat that until the end of the line.
Is this at all possible or am I reaching beyond the language capabilities?
Edit: for some reason my phone is not blocking code when I'm asking a question, if someone sees this and wants to edit, I would be grateful.
Is this at all possible or am I reaching beyond the language capabilities?
Not even close. I recommend you read Programming in Lua.
tap({xTable}, y)
But I'm not sure if that will "tap" at each x coordinate that I've listed for the y variable.
Why are you not sure? Did you not write it? If not, you can trivially write it yourself given tap:
function tapxs(xs, y)
for i,x in ipairs(xs) do
tap(x,y)
end
end
...
tapxs({10,20,30,40}, 10) -- tap at 10,10; 20,10; 30,10; etc.
I want to paint a pixel at one very specific coordinate, and then step 5 pixels away and paint the next one, and repeat that until the end of the line.
What is "the line"? Is it purely horizontal? You could write:
function tapHorizontally(startX, maxX, y, increment)
for x=startX,maxX,increment do
tap(x,y)
end
end
...
tapHorizontally(10,100,20,5) -- tap from 10,20 to 100,20 in 5 pixel increments
Of course, that's a bizarrely specific function. You'd typically write something that takes a starting x,y and ending x,y and draws between them, so you can support horizontal, vertical, diagonal lines all with the same function, but that requires more math.
The bottom line is: Lua is a full blown, powerful, high level programming language. It could be used to write the very app you're tapping on, or the app you're using to generate taps, so the limits are going to be your knowledge of programming/algorithms/math/etc.

XNA 4.0: How to remove text after drawn to screen?

Good day everyone.
I'm trying to draw the text "Pass Complete!" to screen with this code:
spriteBatch.DrawString(font, "PASS COMPLETE!", new Vector2(30, 130), Color.White);
Which does fire off the proper IF statement. However, how do I go about then removing that text from the screen? I'm really not sure at all where to go on from here and my instructor wants me to google the answer or find it in textbook. I have been all over my XNA textbook and I have found no outlet to removing that text.
Thanks for any and all help.
Update:
protected override void Draw(GameTime gameTime)
I have the IF statement included in here. Basically it checks collision with p_Receiver and if it the bool checks out, it draws the DrawString. Should I maybe be looking at this from a different angle?
Final:
I went ahead with the following as the answer and it's working better then before. :)
if (PassInfo == 3) {
(timer code)
(IF timer not "used up" then run the draw)
Working good for now.
I appreciate it.
I'm doing this by function that add text with some parameters into generic list. and then i update and draw items from that list. in pseudo code:
function addText(text,position,duration)
texts.add(new t(text,position,duration))
end function
function updateText()
for each t as text in texts.findall(where t.active)
t.duration -= 1
if t.duration < 0 then t.active = false
next
end function
function drawText()
for each t as text in texts.findall(where t.active)
//draw it
next
end function
so by this you can add unlimited number of texts on different position and duration on screen.
A lot of games redraw the entire window / screen each time through the draw cycle so there's a distinct chance that the solution to removing it is simply to stop drawing it.
i.e. have your if condition not draw the text when it is no longer required.
If, on the other hand, you've some more complex drawing logic that only draws portions of the window / screen that need updating then you'll need to include logic to redraw that part of the screen that contained the text once it is no longer needed.

What does mean a TRect with exchanged (left,top) and (right,bottom) points?

I'm reading a 3-d party Delphi sources and stuck with a line, where Rect is initialized with another Rect's coordinates, but swapped, like this:
r, rsrc: TRect;
...
r := Rect(rsrc.right + 1, rsrc.bottom + 1, rsrc.left, rsrc.top);
rsrc is filled with proper on-screen coordinates, so (left,top) is always less than (right,bottom).
What does this mean? I can't find any mentions of possible purpose for this in the Delphi documentation.
Strictly speaking, a TRect is only a a collection of four integers. The meaning of these numbers depends entirely on the context. Most often, they specify a rectangle.
That is, it does not make sense at all to expect the Delphi documentation to say anything about the current issue! It is like seeing a car making a U-turn on a small road and asking, "Why doesn't the car's manual explain why someone would make a U-turn on this particular road?"
It doesn't mean anything, just as SomeVarName := 7 doesn't mean anything on it's own. Look further down into the code and see what the r is supposed to be used for; Also look for how rsrc was obtained.
It might simply be that the coordinates for rsrc were obtained using some math and it was determined that the resulting rectangle is up side down, hence the code rotates the rectangle to be top-side-up.

Resources