Silverfrost Forums

Welcome to our forums

Draw_rectangle@ with %gr smooth4 or smooth8 options

26 Nov 2018 12:11 #22855

Below is a link to a simple drawing program which behaves as expected, drawing lines, circles, rectangles etc.

http://www.tr5mx.co.uk/canvas2.f95

If the %gr options smooth4 or smooth8 are included, there is a problem when drawing a non-filled rectangle. The drawn element does not appear immediately, and will only appear after another element e.g. a line or circle is drawn.

Ken

26 Nov 2018 7:55 #22856

Ken

I think that the trick is probably to call set_graphics_selection@ as in the following sample which is similar to yours.

!FTN95$WINAPP
!------------------------------------------------------------------
    module gr7data
      character*32 cstat
    end module gr7data
!---------------------------------------------------------------
    program gr7
      use gr7data
      integer i,winio@,RGB@
      integer,external::gr_func
      cstat=' '
      i=winio@('%ww&')
      i=winio@('%ca[Box Selection]&')
      i=winio@('%mn[E&xit]&','EXIT') 
      i=winio@('%bg&',RGB@(240,240,240))
      i=winio@('%ob&')
      i=winio@('%^gr[colour=#f0f0f0,box_selection,smooth8]&',300,300,gr_func)
      i=winio@('%cb&')
      i=winio@('%ff %nl&')
      i=winio@('%ob[status]%20st%cb',cstat)
    end
!-----------------------------------------------------------
    integer function gr_func()
      use clrwin
      use gr7data
      integer x1,y1,x2,y2,nstat,a,b
      integer,parameter::MK_SHIFT=4,MK_CONTROL=8,RED=255
      call get_mouse_info@(x1,y1,nstat)
      write(cstat(1:30),'(3I7)') x1,y1,nstat
      call window_update@(cstat)
      if(clearwin_string@('CALLBACK_REASON') == 'MOUSE_LEFT_CLICK')then
        call set_line_width@(2)
        call get_graphics_selected_area@(x1,y1,x2,y2)
        call set_graphics_selection@(0)
        if(iand(nstat,MK_SHIFT)==MK_SHIFT) then
          call draw_rectangle@(x1,y1,x2,y2,RED)
        else if(iand(nstat,MK_CONTROL)==MK_CONTROL) then
          a=0.5*(x2-x1)
          b=0.5*(y2-y1)
          call draw_ellipse@(x1+a,y1+b,a,b,RED)
        else
          call draw_line_between@(x1,y1,x2,y2,RED)
        endif
        call set_graphics_selection@(1)
      endif
      gr_func=2
    end

!-----------------------------------------------------------
26 Nov 2018 2:19 #22857

Thanks Paul, I forgot about that example. Modified your example to demonstrate issue as below, and uncommenting the call to set_graphics_selection@ the problem goes away. 😄

Ken

     program gr7 
       integer i,winio@,RGB@ 
       integer,external::gr_func 
       i=winio@('%ww&') 
       i=winio@('%ca[Box Selection]&') 
       i=winio@('%mn[E&xit]&', 'EXIT') 
       i=winio@('%bg&', RGB@(240,240,240))  
       i=winio@('%^gr[colour=#f0f0f0,box_selection,smooth8]', 300, 300, gr_func)  
     end 
 !----------------------------------------------------------- 
     integer function gr_func() 
       use clrwin  
       integer x1, y1, x2, y2, nstat, a, b 
       integer, parameter :: RED=255  
       
       if (clearwin_string@('CALLBACK_REASON') == 'MOUSE_LEFT_CLICK') then 
         call set_line_width@(2) 
         call get_graphics_selected_area@(x1, y1, x2, y2)
         print *,x1,y1,x2,y2 
         call draw_rectangle@(x1,y1,x2,y2,RED)  
!         call set_graphics_selection@(1)
       endif       
       gr_func=2 
     end 
Please login to reply.