9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: andrey mirtchovski <aam396@mail.usask.ca>
To: 9fans@cse.psu.edu
Subject: [9fans] graphics
Date: Mon,  7 Aug 2000 12:30:40 -0600	[thread overview]
Message-ID: <Pine.LNX.4.10.10008071158460.3867-200000@neon.myriadgate.net> (raw)

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1794 bytes --]

hi,

i spent the weekend trying to learn more about the plan9 graphics model and
trying to write a simple program (started off with russ cox' click.c and
worked on top of it) and i must say i am quite impressed with the ease with
which programs are created, relative size, simplicity and speed...

included is a simple program that emulates one of the x-screensavers by
drawing random squares in the window it is started in... one can use it
mostly for speed-evaluation and/or to tell me if there is any problem with
terminals running in less-than-24 bit mode...


several questions popped up while i was implementing it:

	the 'eresized()' routine seems not to be called if the program is not
	waiting on any event. e.g. in one of my earlier implementations i lacked
	a call to ecanread/emouse/emenuhit in the main loop and as a side effect
	eresized was not called when the window was moved... it only started
	working after i added (any) of the abovementioned function calls.

	it is possible to force the machine to reboot if one mistakingly forgets
	to free the allocimagemix pointer after the recangle is drawn... this seems
	to be a big problem, because i've always assumed a runaway process that
	takes up the entire memory would just be terminated instead of causing
	the machine to reboot... or maybe plan9 does things in a different way?
	:)


well.. comments/flames are welcome :)


cheers: andrey


PS: obligatory screenshot of plan9 in 'working condition' is available from

	http://homepage.usask.ca/aam396/scrsht.gif

you can see my irc client running in the bottom left corner of the screen,
the language spoken is bulgarian (transliterated)...

the entire page is not operational though, i'm just using it for this
screenshot...
	

[-- Attachment #2: Type: TEXT/PLAIN, Size: 1931 bytes --]

/* draw random rectangles in the current window
* sort of like the xscreensaver we all know
* -- andrey
*/

/* based on russ cox' click.c */


#include <u.h>
#include <libc.h>
#include <draw.h>
#include <thread.h>
#include <event.h>

int minx, miny, maxx, maxy;

void
eresized(int new)
{
	Rectangle r;
	if(new && getwindow(display, Refnone) < 0)
		fprint(2,"can't reattach to window");
	r = screen->r;
	minx = r.min.x;
	miny = r.min.y;
	maxx = r.max.x;
	maxy = r.max.y;
	draw(screen, screen->r, display->white, nil, ZP);
}

void
main(int argc, char **argv)
{
	Mouse m;
	Image *img;
	Rectangle r;
	int i;
	int slp = 10;

	char *items[] = { "slower", "faster", "exit", nil };


	Menu menu;

	/* setup menus */
	menu.item = items;
	menu.gen = nil;

	srand(0);

	initdraw(0,0,"whoopty doo");
	eresized(0);
	einit(Emouse);


	for(;;){
		if(ecanmouse())	{
			m = emouse();
			if(m.buttons & 4) {
				switch(emenuhit(3, &m, &menu)) {
					case 0: 	slp += 10; break;
					case 1: 	if(slp) 
									slp -= 10;
								else 
									slp = 0; 
								break;
					case 2: 	exits("user abort");
					default: 	fprint(2, "impossible button\n");
				}
			}
		}
		
		/* draw a rectangle somewhere in the window */
		/* make sure rectangle does not overflow window */
		r.min.x = minx + nrand(maxx - minx);
		r.min.y = miny + nrand(maxy - miny);
		r.max.x = r.min.x + nrand(maxx - r.min.x);
		r.max.y = r.min.y + nrand(maxy - r.min.y);

		/* get a random color and random alpha for drawing */
		/*** probably not the best way of doing it ***/
		img = allocimagemix(display,nrand(256)<<24 | nrand(256) << 16 | nrand(256) <<8 | (256 - nrand(256)),nrand(256)<<24 | nrand(256) << 16 | nrand(256) <<8 | (256 - nrand(256)));

	 	draw(screen, r, img, nil, ZP);
		flushimage(display, 1);
		freeimage(img);
		/* slow down the drawing somehow */
		sleep(slp);
	}
}

             reply	other threads:[~2000-08-07 18:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-08-07 18:30 andrey mirtchovski [this message]
2000-08-07 19:11 Russ Cox
2012-08-06 17:42 ron minnich
2012-08-06 17:54 ` Charles Forsyth
2012-08-08  1:05   ` ron minnich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.10.10008071158460.3867-200000@neon.myriadgate.net \
    --to=aam396@mail.usask.ca \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).