[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] system( 'clear' ) for interfaces



Strider wrote:
>I'm kinda cheap when it comes to my menu-driven interfaces. I use tabs a
>lot for positioning where I should use printf(), although of course I can't
>do that in MacPerl anyway.

What do you mean, you can't? Last time I looked, Perl has printf() and I
don't recall it being broken in MacPerl.

[deletia]
>Is there or can there be a command, maybe implemented as system( 'clear' )
>(or MacPerl::Clear if you prefer), which clears a given window quickly?
>It'd be a tremendous asset. If anyone else has any other way around this
>problem, please let me know.


I tried a Codewarrior trick for clearing the SIOUX window (if you don't
know, it doesn't matter) of building an event and then firing it off.
MacPerl won't let me build an event. I get an error about assigning to a
subroutine when I try to assign to the members of ToolboxEvent:

# Can't modify subroutine entry in scalar assignment, near "} ;"

I am not sure if this trick would have worked anyway, since I don't know
exactly what DispatchEvent() will do. The docs I have are rather vague,
basically the Shuck entry. Here's the subroutine for those of you who are
interested:

use Mac::Events;
sub macperl_clear_scr
{
	my $event = new ToolboxEvent;
	$event->what = { return keyDown() } ;
	$event->modifiers = { return cmdKey() };
	$event->when = { return TickCount() };
	$event->message = { return 'a' };
	DispatchEvent($event);

	$event->modifiers = {return 0};
	$event->message = {return "\x7F"};
	$event->when = {return TickCount()};
	DispatchEvent($event);
}

I don't know if I could get the assignments to work with typeglobs or not,
but that was a first stab at it. If anyone wants to try it, please let me
know the results.

You can very easily clear a window if you build one yourself and use the
MacOS GUI features. You'd want to do an EraseRect() on your window's
grafport rect. Of course, you then have to do your screen drawing manually,
and to keep the rest of your code portable you have to write lots of if()
and else.

#I suppose you could try getting the current port like so:
	use Mac::Quickdraw;
	$port = GetPort();
#Then erase it:
	EraseRect($port->portRect());
#Then return to the top left corner:
	MoveTo(0, 0);
#Now, if you call print() it should print in the top left corner.

However, the above will only work if your output window is in front, and
even then I haven't tried it, but it might get you started in the right
direction.

+----------------------------+-----------------------------+
|     Jason Stephenson       |        panda@mis.net        |
+----------------------------+-----------------------------+
| There are no guarantees in life, the Tao or programming. |
|                      --Bruce Eckel                       |
+----------------------------------------------------------+

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch