Re: David Cuny's GUI
- Posted by David Cuny <dcuny at DSS.CA.GOV> Nov 10, 1997
- 771 views
------ =_NextPart_000_01BCEDCF.05F840A0 Hi, Mike. As you've noticed, you can't just show the dialog and exit, because the user may want to press the Cancel button while the action is taking place. So you've got to be able to do something like: display the dialog while true do do a little cpu intensive work if finished then exit end if process the keyboard an mouse if dialog is cancelled then exit end if update the dialog end while close the dialog So you are sort of multitasking - doing a slice of work, then giving up the cpu to the dialog. Here's the main dialog loop, in DIALOG.E: global procedure run_dialog() -- generic dialog run routine -- display the objects show_dialog() -- loop forever while get_dialog(EXIT_STATE) = MORE do edit_dialog() -- process keys end while end procedure There are two problems to solve: 1. Adding the CPU intensive code. 2. Updating the dialog. The first problem lies in edit_dialog(), also DIALOG.E. The code that waits for a key or mouse event is: keyPressed = watch_keys() -- wait for a key Problem is, it really does /wait/ for a key/mouse event before continuing. What you really want to have happen is for watch_keys to return a null key (-1) if nothing has happened. My solution would be to set up a flag in watch_keys() that would tell the routine NOT to wait. The function is found in KEYS.E: -- new variable, placed at the top of the file global integer WAIT_FOR_KEY WAIT_FOR_KEY = 1 < SNIP > global function watch_keys() < SNIP > keyPress = 0 while keyPress = 0 do < SNIP > -- new code, placed at bottom of while loop -- exits loop if WAIT_FOR_KEY is false if not WAIT_FOR_KEY then -- dummy value keyPress = -1 end if end while return keyPress end function OK, now we can tell wait_keys() not to really wait for a key. Now we need to rewrite run_dialog to check for keys AND run that cpu intensive code: global procedure run_special_dialog() -- special dialog routine atom percent -- display the objects show_dialog() -- don't wait for a key from the user WAIT_FOR_KEY = 0 -- loop forever while get_dialog(EXIT_STATE) = MORE do -- do a slice of work, return amoount of work left percent = cpu_intensive() -- finished? assume 1 = 100% if percent = 1 then -- set flag to exit loop set_dialog( EXIT_STATE, DONE ) end if -- update the status on the dialog -- obviously, this code is incomplete position( col, row ) put_colors( OF_DIALOG, sprinf( ... ) -- check for a key/mouse event edit_dialog() -- process keys end while -- turn key wait back on WAIT_FOR_KEY = 1 end procedure Notice that the dialog isn't being redrawn each time - only the status information. This avoids a flickering dialog box on the screen. Does this help? -- David Cuny ------ =_NextPart_000_01BCEDCF.05F840A0