Hi Paul,
I have modified your code thus:
c---------------------------------------------------------------
include <windows.ins>
common mode
external gr_func, tog_fn
mode = 1
i=winio@('%ww[no_border]&')
i=winio@('%ca[Box Selection]&')
i=winio@('%mn[E&xit,&Toggle]&','EXIT',tog_fn)
i=winio@('%ob&')
i=winio@('%^gr[white,box_selection,full_mouse_input]&',
+ 300,300,gr_func)
i=winio@('%cb')
end
c-----------------------------------------------------------
integer function gr_func()
gr_func=2
end
c-----------------------------------------------------------
integer function tog_fn()
include <windows.ins>
common mode
if (mode .eq. 3) then
mode = 0
else
mode = mode + 1
endif
call set_graphics_selection@ (mode)
tog_fn = 2
end
At the outset, because we have declared box_selection in the %gr format, a click-and-drag still draws the rectangle. ClearWin already knows how to sort out that an area selection has been made without testing for button press and release. To do so in Fortran code is re-inventing the wheel.
When one clicks the toggle menu I have arranged the program to step through the 4 possible options. With mode = 2, Clearwin also recognises that a rubberband line could be selected.
At this point, I stopped reading the manual, and experimented. This program is the result:
winapp
c---------------------------------------------------------------
include <windows.ins>
common mode
integer mstat
character*30 cstat
common/control/ mstat,cstat
external gr_func, tog_fn
mode = 1
i=winio@('%ww[no_border]&')
i=winio@('%ca[Box Selection]&')
i=winio@('%mn[E&xit,&Toggle]&','EXIT',tog_fn)
i=winio@('%ob&')
i=winio@('%^gr[white,box_selection,full_mouse_input]&',
+ 300,300,gr_func)
i=winio@('%cb&')
i=winio@('%ob[status]%20st%cb',cstat)
end
c-----------------------------------------------------------
integer function gr_func()
include <windows.ins>
integer mstat
character*30 cstat
common/control/ mstat,cstat
common mode
if (mode .eq. 0) then
gr_func=2
return
endif
call get_graphics_selected_area@(ix1,iy1,ix2,iy2)
write(cstat(1:30),'(4I7)') ix1,iy1,ix2,iy2
call window_update@(cstat)
gr_func=2
end
c-----------------------------------------------------------
integer function tog_fn()
include <windows.ins>
common mode
if (mode .eq. 3) then
mode = 0
else
mode = mode + 1
endif
call set_graphics_selection@ (mode)
tog_fn = 2
end
I had to put the mode=0 check into gr_func, otherwise the get... causes a program exit. With each mode change, the get_graphics_selected_area@ coords are all reported as -1. In mode=1 or 2, once a left-click has been done, a click-drag reports the start and finish coords, a left-click reports two pairs of identical coords, and a right-click is ignored. In mode=3, both left and right-clicks are ignored by get_graphics_selected_area@, and the -1's continue to be reported. The normal way of getting the coordinates for single clicks works.
Some further investigation looking for MOUSE_LEFT_CLICK and MOUSE_RIGHT_CLICK showed that MOUSE_RIGHT_CLICK is shown when the right mouse button is depressed, but every other callback gives a MOUSE_LEFT_CLICK message. The key seems to be in mode=1 and mode=2 to stop looking for MOUSE_LEFT_CLICK messages, but instead, to look for (ix1,iy1)=(ix2,iy2) as a way to find those single mouse clicks.
So, in answer to my original query, Clearwin doesn't require one to check for button_down and button_up. However, one still needs to have a way to discover that box selection is completed. I have discovered that this can be done because the coordinates reported by get_graphics_selected_area@ don't change.
I'll have to mull the implications of this over for some time!
Regards
Eddie