From: Dr. Michael Weller (eowmob@exp-math.uni-essen.de)
Date: Thu 13 Jul 2000 - 19:37:22 IDT
On Thu, 13 Jul 2000, Sergio Masci wrote: > Could someone please answer Pradeep's query. I have no experience of > vga_waitevent, keyboard_update or keyboard_getstate (I use mouse_update Probably this is my turn, I wrote vga_waitevent(). > > From: Pradeep Tumati <ptumati@vt.edu> > > Subject: mouse - svgalib > > Message-id: <4.3.2.7.0.20000712231019.00b056a0@mail.vt.edu> > > Hello sir, > > here is a sample program. It combines all the raw text, vga mode and the > > mouse. Can you please tell me where should I put the vga_waitevent to make > > this work... > > int main( ) > > { > > int a,b ; > > char *ret; > > a=vga_init( ); > > if (a==0) > > { > > vga_setmode(4); > > vga_setmousesupport(1); # You should enable the mouse before the setmode.. It needs to know the # screen rez for wrapping (should not be a problem though). > > b=keyboard_init( ); # I'd also feel more comfortable to set the keyboard before the screen, # but it is ok this way around > > if (b==0) > > { Here you need to add the vga_waitevent(). However, it also means the structure of your program is completely changed to an even driven scheme. (at least it should be). W/o trying to compile/run this, my suggestion: int event; /* this buffer is static, BTW, you only need to call ret=keyboard_getstate() once: */ ret=keyboard_getstate( ); for (;;) { event = vga_waitevent(VGA_MOUSEEVENT | VGA_KEYEVENT, NULL, NULL, NULL, NULL); if (event & VGA_KEYEVENT) { if (ret[SCANCODE_ESCAPE]) { /* do something. Probably you want this: */ break; } if ... check for other keys. } if (event & VGA_MOUSEEVENT) { x = mouse_getx( ); y = mouse_gety( ); /* do some mouse pointer updating etc.. */ } } > > keyboard_update( ); > > ret=keyboard_getstate( ); > > while(!ret[SCANCODE_ESCAPE]) > > { > > ret=keyboard_getstate( ); > > x=mouse_getx( ); > > y= mouse_gety( ); > > /* I guess it is here, if it is so, what about the keyboard update event > > in the next line? You don't need to call the _update funcs.. waitevent does that already for you. However, calling them is no problem (except a waste of CPU time), as long as you choose the non-blocking variants. You COULD indeed add vga_waitevent(VGA_MOUSEEVENT | VGA_KEYEVENT, NULL...) here. It would work.. but in your philosophy a mouse_update would then be missing (but vga_waitevent does that anyway) and you would not use that vga_waitevent returns already what kind of even actually occured (so you'd waste a little bit of CPU time). Theoretically it would make more sense to add it in front of x=mouse_getx( );, BTW: Because you read the mouse coords only after they've changed. Not a problem though as this is only in the first loop. In that light, do { ....} while(!ret[SCANCODE_ESCAPE]) would be more sensible too. You only check for Escape key when a key was actually pressed (not before). The only benefit the vga_waitevent would have is your program would not use 100% cpu time. Note that vga_waitevent() may return 0 even in this simple setup if a signal was sent to your process. > > keyboard_update( ); > > } > > } > > } > > } I also invite you to study the eventtest.c demo program which is packed with svgalib. Hope this helps, Michael. -- Michael Weller: eowmob@exp-math.uni-essen.de, eowmob@ms.exp-math.uni-essen.de, or even mat42b@spi.power.uni-essen.de. If you encounter an eowmob account on any machine in the net, it's very likely it's me.
This archive was generated by hypermail 2.1.4 : Wed 21 Jan 2004 - 22:10:23 IST