<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Approximatrix Forums — Mouse event]]></title>
		<link>http://forums.approximatrix.com/viewtopic.php?id=612</link>
		<atom:link href="http://forums.approximatrix.com/extern.php?action=feed&amp;tid=612&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Mouse event.]]></description>
		<lastBuildDate>Tue, 21 Mar 2017 17:38:32 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Mouse event]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=2807#p2807</link>
			<description><![CDATA[<p>Thanks Jeff,<br />I forgot to mention that also&nbsp; mfinish =&nbsp; finish has to be after finish = .false. starting mouse_move.<br />A remove mouse handlers should be very helpful and I think also that too much active handlers might cause other problems<br />Klaus</p>]]></description>
			<author><![CDATA[null@example.com (Klaus Asmus)]]></author>
			<pubDate>Tue, 21 Mar 2017 17:38:32 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=2807#p2807</guid>
		</item>
		<item>
			<title><![CDATA[Re: Mouse event]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=2806#p2806</link>
			<description><![CDATA[<p>Klaus,</p><p>The next version of AppGraphics will include calls to remove mouse handlers.&nbsp; It&#039;s easy to do in C right now, but impossible using only the Fortran interface.&nbsp; They should have been present in the library.</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Tue, 21 Mar 2017 17:29:03 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=2806#p2806</guid>
		</item>
		<item>
			<title><![CDATA[Re: Mouse event]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=2805#p2805</link>
			<description><![CDATA[<p>Jeff, <br />The mouse_move procedure using module cross_sup are working in my application<br />with a small addition. I added directly after start of the handle callbacks <br />If (mfinish) return<br />to avoid doing unwanted things in the handlers<br />Next there are more mouse actions planned like a drag mouse which i hope to solve similar<br />Klaus</p>]]></description>
			<author><![CDATA[null@example.com (Klaus Asmus)]]></author>
			<pubDate>Tue, 21 Mar 2017 17:20:58 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=2805#p2805</guid>
		</item>
		<item>
			<title><![CDATA[Re: Mouse event]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=2790#p2790</link>
			<description><![CDATA[<p>Thanks Jeff for your investigation and explanation.<br />Now I understand what happens and i try first your module solution. <br />Klaus</p>]]></description>
			<author><![CDATA[null@example.com (Klaus Asmus)]]></author>
			<pubDate>Thu, 16 Mar 2017 21:33:31 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=2790#p2790</guid>
		</item>
		<item>
			<title><![CDATA[Re: Mouse event]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=2789#p2789</link>
			<description><![CDATA[<p>Klaus,</p><p>This was&nbsp; a tricky one!&nbsp; The reason you&#039;re getting the crash, I believe, is that your mouse handlers are still attempting to be called after the right-click leaves your monitoring loop.&nbsp; Normally, this behaivor isn&#039;t problematic, but your mouse handlers are &quot;contain&quot;ed routines rather than globally visible routines.&nbsp; When idling via &quot;loop()&quot; in <em>MOVE_CROSS</em>, the&nbsp; variables <em>x_cross</em>, <em>y_cross</em>, and <em>finish</em> are all defined and within scope.&nbsp; When you exit <em>MOVE_CROSS</em>, though, those variables cease to be defined.&nbsp; Furthermore, both <em>handle_click</em> and <em>handle_clickrb</em> are no longer valid, visible subroutines.</p><p>When you move outside of <em>MOVE_CROSS</em> back into <em>child_window_test</em>, the window will continue passing mouse events to the no-longer-visible <em>handle_click</em> and <em>handle_clickrb</em> subroutines that attempt to access nonexistent variables (since they only existed in <em>MOVE_CROSS</em>&#039;s scope).&nbsp; &nbsp;This behavior causes the crash.</p><p>One problem with AppGraphics right now is that the Fortran interface doesn&#039;t provide an easy way to disconnect mouse handlers.&nbsp; The process is easy in C, though.&nbsp; &nbsp;That call should be added to the Fortran interface.</p><p>One fix, though, is to make the mouse handlers and the variables they access more &quot;visible&quot; rather than &quot;contain&quot;ed within a subroutine.&nbsp; &nbsp;I did this using a module:</p><div class="codebox"><pre><code>module cross_sup

DOUBLE PRECISION::x_cross, y_cross
Logical mfinish

contains

SUBROUTINE MOVE_CROSS (finish)
USE AppGraphics
implicit none
Logical finish

    finish=.false. 

    Call registermousehandler (MOUSE_LB_DOWN, handle_click)
    Call registermousehandler (MOUSE_RB_DOWN, handle_clickrb)

    Call loop()
    
    call clearmouseclick(MOUSE_LB_DOWN)
    call clearmouseclick(MOUSE_RB_DOWN)
    
    finish = mfinish

    
End SUBROUTINE MOVE_CROSS


subroutine handle_click(x, y)
use appgraphics
implicit none
    integer::x,y
    logical::Clicked
    
    integer::x_offset=10, y_offset=10
    real::scale_x=1.0, scale_y=1.0, ywtot=1.0
    
    print *,&#039;move cross: handle click started for LB_down&#039;
    Clicked = ismouseclick (MOUSE_LB_DOWN)
    If(clicked) then
        call line (x-20,y,x+20,y)
        Call line (x,y-20,x,y+20)
        x_cross = dble(real(x -x_offset))/scale_x
        y_cross = ywtot-dble(real(y+y_offset))/scale_y
        Print*,&#039;move cross: handle click got ordinates by LB_down&#039;,x,y
         
        call clearmouseclick(MOUSE_LB_DOWN)
        
        
        
        Call stopidle ( )
    end if
end subroutine handle_click

subroutine handle_clickrb(x,y)
use appgraphics
implicit none
    integer::x,y
    logical::Clicked
    print *,&#039;move cross stops: handle click for RB_down&#039;,x,y
    Clicked = ismouseclick (MOUSE_RB_DOWN)
    If(clicked)then
        mFinish = .true.
        Call stopidle ( )
        return
        Print*,&#039;handle click move cross finished&#039; 
        call clearmouseclick(MOUSE_RB_DOWN)
    END If
end subroutine handle_clickrb

end module cross_sup</code></pre></div><p>Now if the mouse handlers are still triggered, they are still visible since they are module procedures and they access only module variables.&nbsp; I may have made a few additional variable declarations just to get things building and running, but I think you&#039;ll see what I did.</p><p>I will look into adding an &quot;unregister&quot; call for mouse events&nbsp; since you should be able to disconnect them.&nbsp; That would have avoided this whole issue.</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Thu, 16 Mar 2017 17:42:12 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=2789#p2789</guid>
		</item>
		<item>
			<title><![CDATA[Re: Mouse event]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=2788#p2788</link>
			<description><![CDATA[<p>Jeff, <br />Here more about this mouse matter:<br />“After return to the current window menu” means that a graphic window&nbsp; is available to show the mouse movements by a cross&nbsp; from where MOVE_CROSS is called. After the right mouse button is pressed the control returns to the existing graphic window.</p><p>See my simple test program written as a subroutine added to my dialog tests:</p><p>subroutine child_window_test<br />use appgraphics<br />logical finish<br /> DOUBLE PRECISION&nbsp; &nbsp;x_move, y_move<br />&nbsp; &nbsp; initW = getcurrentwindow()&nbsp; ! keep the main window in memory for return to it<br />&nbsp; &nbsp; dlg_screen = initwindow(1000, 1000, title = &quot;mouse test&quot;, closeflag = .false.)<br />&nbsp; &nbsp; call setcolor(Black)<br />&nbsp; &nbsp; Call setbkcolor(white)<br />&nbsp; &nbsp; Call settextstyle(MONOSPACE_FONT, horiz_dir,16)<br />&nbsp; &nbsp; Call clearviewport()</p><br /><p> Call setcolor(black)<br /> CALL OUTTEXTxy(1,1,&#039;Pick midpoint and press left button - right button: return&#039;)</p><p>Do while (.not. finish)<br />! 1-- Click a point on a part, define the coordinates of the point<br /> CALL MOVE_CROSS(x_move,y_move,finish)! Move the mouse to a point on the screen and press left button<br /> if (finish)then <br />&nbsp; &nbsp; Print*,&#039;the mouse function is finished&#039;<br />&nbsp; &nbsp; Else<br />&nbsp; &nbsp; Print*,&#039;Pick next point&#039;<br /> end if<br />end do<br />&nbsp; &nbsp; <br />call delay (1000)</p><p>end subroutine child_window_test</p><br /><br /><p>After &quot;finish&quot; (right button in Move_cross) a mouse button hit causes the crash.<br />By the way: I am still very happy with the use of SF and your fast reply on all the questions!<br />Regards Klaus</p>]]></description>
			<author><![CDATA[null@example.com (Klaus Asmus)]]></author>
			<pubDate>Tue, 14 Mar 2017 21:49:42 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=2788#p2788</guid>
		</item>
		<item>
			<title><![CDATA[Re: Mouse event]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=2787#p2787</link>
			<description><![CDATA[<p>Klaus,</p><p>I&#039;ll have to experiment with this problem a bit. Could you explain &quot;After return to the current window menu...&quot; a bit more?&nbsp; Are you saying after the routine returns, or after a separate window is closed, returning to a main window?</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Tue, 14 Mar 2017 20:49:38 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=2787#p2787</guid>
		</item>
		<item>
			<title><![CDATA[Mouse event]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=2786#p2786</link>
			<description><![CDATA[<p>Hi Jeff<br />A procedure to move a cross on screen (to draw a cross on the screen) causes a problem.<br />It&#039;s a short procedure as follows:<br />Starting with registering the mouse&nbsp; next is call loop the rest is done by the handle_click call back routines. There also&nbsp; stop idle is called so that clearmouseclick is executed. See below</p><p>What happens:<br /> After return to the current window menu every mouse click else where on the graphic screen results in a segmentation fault! Of course these mouse clicks without any target makes no sense but could happen.<br />Only after closing that current window and restarting it again this fault does not happen again.<br />I made a small test program with only the routine move cross and the same happened!</p><p>I understood that&nbsp; clearmouseclick clears the events. But my impression is that the mouse event is still (a bit) active until the current graphic window is closed too. The Windows controlled mouse is working but also a mouse click outside the Window menu gives the wrong response resulting in a crash.&nbsp; <br />What can I do to solve this problem? Do I have to run the mouse handling in a separate thread?<br />Regards, Klaus</p><p>SUBROUTINE MOVE_CROSS (x_cross, y_cross, finish)&nbsp; ! exit when finished<br /> USE AppGraphics<br /> Use W_ords_to_pixels<br /> Logical finish<br /> DOUBLE PRECISION&nbsp; &nbsp;x_cross, y_cross<br />&nbsp; &nbsp;finish=.false. <br />!&nbsp; &nbsp; __________________________________________________________________<br />&nbsp; &nbsp; Call registermousehandler (MOUSE_LB_DOWN, handle_click)<br />&nbsp; &nbsp; Call registermousehandler (MOUSE_RB_DOWN, handle_clickrb)</p><p> Call loop ! the corresponding world ordinates related to mouse x and y are defined in handleclick</p><p> call clearmouseclick(MOUSE_LB_DOWN)<br /> call clearmouseclick(MOUSE_RB_DOWN)<br /> contains</p><p>subroutine handle_click(x, y)<br />&nbsp; &nbsp; integer::x, y&nbsp; <br />&nbsp; &nbsp; logical Clicked<br /> print *,&#039;move cross: handle click started for LB_down&#039;<br /> Clicked = ismouseclick (MOUSE_LB_DOWN)<br /> If(clicked)then !&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x+y &gt; 0)then<br />&nbsp; &nbsp; call line (x-20,y,x+20,y)<br />&nbsp; &nbsp; Call line (x,y-20,x,y+20)<br />&nbsp; &nbsp; x_cross = dble(real(x -x_offset))/scale_x ;&nbsp; y_cross&nbsp; = ywtot- dble(real(y+y_offset))/scale_y<br />&nbsp; &nbsp; Print*,&#039;move cross: handle click got ordinates by LB_down&#039;,x,y<br />&nbsp; &nbsp; Call stopidle ( ) <br /> end if<br />end subroutine handle_click</p><p>subroutine handle_clickrb(x,y)<br />&nbsp; &nbsp; integer::x, y&nbsp; <br />&nbsp; &nbsp; logical Clicked<br /> print *,&#039;move cross stops: handle click for RB_down&#039;,x,y<br />&nbsp; &nbsp; Clicked = ismouseclick (MOUSE_RB_DOWN)<br /> If(clicked)then<br />&nbsp; &nbsp; Finish = .true.<br />&nbsp; &nbsp; &nbsp;Call stopidle ( );return<br />&nbsp; &nbsp; Print*,&#039;handle click move cross finished&#039; <br />end if<br />end subroutine handle_clickrb<br />End SUBROUTINE MOVE_CROSS</p>]]></description>
			<author><![CDATA[null@example.com (Klaus Asmus)]]></author>
			<pubDate>Mon, 13 Mar 2017 09:10:08 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=2786#p2786</guid>
		</item>
	</channel>
</rss>
