<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Approximatrix Forums — Resizing Windows in AppGraphics]]></title>
		<link>https://forums.approximatrix.com/viewtopic.php?id=456</link>
		<atom:link href="https://forums.approximatrix.com/extern.php?action=feed&amp;tid=456&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Resizing Windows in AppGraphics.]]></description>
		<lastBuildDate>Mon, 27 Apr 2015 19:17:59 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Resizing Windows in AppGraphics]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=2037#p2037</link>
			<description><![CDATA[<p>Jeff,</p><p>Thank you for your quick response and suggestions.<br />I have not tried them as of yet, but will shortly.</p><p>Since you mentioned the issue with enablemenuitem, I should also mention that I found disablemenuitem to be unreliable.</p><p>Thanks again, I&#039;ll try your example.</p><p>Frank</p>]]></description>
			<author><![CDATA[null@example.com (drfrank)]]></author>
			<pubDate>Mon, 27 Apr 2015 19:17:59 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=2037#p2037</guid>
		</item>
		<item>
			<title><![CDATA[Re: Resizing Windows in AppGraphics]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=2035#p2035</link>
			<description><![CDATA[<p>As a quick update, the <em>addmenuitem</em> function works properly. There was an issue with <em>enablemenuitem</em> in the library that has since been fixed.</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Mon, 27 Apr 2015 15:56:18 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=2035#p2035</guid>
		</item>
		<item>
			<title><![CDATA[Re: Resizing Windows in AppGraphics]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=2032#p2032</link>
			<description><![CDATA[<p>Frank,</p><p>Regarding your first message, there does seem to be a current bug related to the file dialogs.&nbsp; There seems to be a problem creating the windows due to some thread interaction issues.&nbsp; &nbsp;I&#039;ll have a fix soon.</p><p>Regarding callbacks, AppGraphics basically runs on two threads.&nbsp; The first thread is your actual program, probably Fortran, that creates the window, etc.&nbsp; The second thread is a GUI thread that handles window updates and messages from the operating system in regards to the GUI.</p><p>Any callback functions will execute in the GUI thread.&nbsp; You&#039;ll notice that in most of the AppGraphics examples, a callback function usually does two things:</p><p>1. Set a flag<br />2. Release the idle state</p><p>All of the computation code in the examples is written in the Fortran thread.&nbsp; &nbsp;Basically, the design would be to initialize the window in the main Fortran thread and enter an idle state to wait for a command.&nbsp; &nbsp;When a user, for example, clicks a &quot;Run&quot; menu item, the callback associated with that menu item would set a flag, possibly something similar to &quot;start_run = .TRUE.&quot;, followed by a command to exit the idle state, <em>call stopidle()</em>.&nbsp; The main program would then take action after leaving the idle state based on flags that have been set.</p><p>When you actually start executing long-running code in your callback, it basically disallows the GUI thread from performing any Window updates.&nbsp; &nbsp;You would need to somehow get the main thread to perform the task you&#039;re requesting.</p><p>I&#039;ve rewritten your attached program with a few changes.&nbsp; Basically, menu items will now trigger a <em>task</em> variable to be set and release the idle state.&nbsp; Based on the value of <em>task</em>, the main program will take some action:</p><div class="codebox"><pre><code>!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
program resizing
use appgraphics
implicit none

    integer::myscreen
    integer::mybutton
    integer, volatile::task
    
    integer, parameter::task_quit=0
    integer, parameter::task_open=1
    integer, parameter::task_run=2
    
    integer::run_item

    !--------------Added-------------------------------------\/
    integer::root_menu, file_menu, item_temp
    !--------------------------------------------------------/\

    myscreen = initwindow(320, 240, closeflag=.TRUE.)
    mybutton = createbutton(270, 210, 40, 20, &quot;Close&quot;, handle_button)

    !--------------Added-------------------------------------\/
    root_menu = addmenu(&quot;&quot;, MENU_FOR_WINDOW)
    file_menu = addmenu(&quot;File&quot;, root_menu)

    item_temp = addmenuitem(&quot;Save Screenshot...&quot;, file_menu, savescreen)
    item_temp = addmenuitem(&quot;Open&quot;, file_menu, handle_open)
    run_item = addmenuitem(&quot;Run&quot;, file_menu, handle_run)
    item_temp = addmenuitem(&quot;Quit&quot;, file_menu, quitwndo)
    !--------------------------------------------------------/\

    call enableresize(handle_resize)

    task = -1

    do while(task .NE. task_quit)
        call draw_window()
        call loop()
        select case(task)
            case (task_open)
                call openfile()
            case (task_run)
                call longrun()
        end select
    end do

    call closewindow(myscreen)

    contains

    subroutine draw_window()
    use appgraphics
    implicit none
        integer::w,h

        integer::tw
        character(100)::info

        w = getmaxx()
        h = getmaxy()

        call setbuttonposition(mybutton, w-50, h-30, 40, 20)

        write(info, &#039;(A5,1X,I5,A1,I5)&#039;) &quot;Size:&quot;, w, &quot;x&quot;, h

        call setviewport(0, 0, w, 40, .FALSE.)
        call clearviewport()
        tw = textwidth(trim(info))
        call outtextxy( (w/2-tw/2), 5, trim(info))

    end subroutine draw_window

    subroutine handle_button()
    use appgraphics, only: stopidle
    implicit none
    
        task = task_quit
        call stopidle()

    end subroutine handle_button

    subroutine handle_resize()
    use appgraphics
    implicit none

        call stopidle()

    end subroutine handle_resize
    
    subroutine handle_open()
    use appgraphics
    implicit none

        task = task_open
        call stopidle()

    end subroutine handle_open

    !--------------Added-------------------------------------\/
    subroutine openfile()
        USE appgraphics, ONLY: dlgopenfile
        implicit none

        CHARACTER(255)  :: input_file_name

        !   Appgraphics function dlgopenfile (filename, maskdesc, mask, title)
        input_file_name= repeat(&#039; &#039;, 255)

        IF( dlgopenfile( &amp;
            input_file_name, &#039;Data&#039;, &#039;*.raw&#039;, &#039;Enter data file&#039;) ) THEN

            Print *, &quot;You&#039;ve selected &quot;//trim(input_file_name)
        ELSE
            Print *, &quot;No file was selected&quot;
        END IF

        input_file_name = TRIM(input_file_name)

    end subroutine openfile

    subroutine savescreen()
        use appgraphics, only: writeimagefile
        implicit none

        ! This call will open a file dialog since we haven&#039;t
        ! specified a filename
        call writeimagefile()

    end subroutine savescreen

    subroutine handle_run()
        use appgraphics, only: stopidle
        implicit none
    
        task = task_run
        call stopidle()
        
    end subroutine handle_run
    
    subroutine longrun()
        implicit none
        
        real::starttime, nowtime
        
            call enablemenuitem(run_item, .FALSE.)
        
            call cpu_time(starttime)
            nowtime = starttime
            do while(nowtime - starttime .LT. 5.0)
                call cpu_time(nowtime)
                Print  *, &quot;no&quot;
            end do
            
            call enablemenuitem(run_item, .TRUE.)
            
    end subroutine longrun

    subroutine quitwndo()
        use appgraphics, only: stopidle
        implicit none

        task = task_quit
        call stopidle()

    end subroutine quitwndo
    !--------------------------------------------------------/\
end program resizing</code></pre></div><p>Incidentally, calling <em>dlgopenfile</em> in this manner actually works, although it is a bug that it doesn&#039;t work in the manner you had been using it.&nbsp; &nbsp;You&#039;ll also note that I added a long-running process as an example that is executed in the <em>longrun</em> subroutine.&nbsp; This subroutine should disable <strong>all</strong> menu items, but right now it will only disable the &quot;Run&quot; item.&nbsp; In reality, though, there is yet another bug that is causing the identifiers returned by <em>addmenuitem</em> to be meaningless.&nbsp; I&#039;ll be looking into that problem too.</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Mon, 27 Apr 2015 15:08:47 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=2032#p2032</guid>
		</item>
		<item>
			<title><![CDATA[Re: Resizing Windows in AppGraphics]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=2030#p2030</link>
			<description><![CDATA[<p>Jeff,</p><p>A somewhat related issue is how to maintain an active instance of a window containing menus when selecting a sub-menu (e.g., &#039;Run&#039;) callback to run a related routine in another module requiring several loops.&nbsp; I only seem to succeed if I close the main window after selecting the added menu &#039;run&#039; option and then I must re-load the window when the active routine ends.&nbsp; <br />Is there a way to retain a visual instance of the main window on the screen while running other routines in the background such that the results of the background run to a subroutine can then be populated in the main window?</p><p>I&#039;ve also tried making the main window &#039;recursive&#039; but each time a callback subroutine is selected to run and returns to the main window, another instance of the main window appears.&nbsp; As a results of multiple runs, several main windows populate the screen.&nbsp; I have not found a way to remove the &#039;older&#039; instances of the main window after each run.&nbsp; Is there a way to close ALL windows but the active one?&nbsp; Closewindow seems to close everything.&nbsp; And Closegraph() doesn&#039;t appear to be recognized by Appgraphics.&nbsp; </p><p>It may be that I just don&#039;t fully understand the complete functionality of Appgraphics, or perhaps there are other commands that could be added to the package to make it more functional.</p><p>I must say that I fully appreciate the work you put into developing this graphic library and look forward to future developments.</p><p>Frank</p>]]></description>
			<author><![CDATA[null@example.com (drfrank)]]></author>
			<pubDate>Mon, 27 Apr 2015 12:34:49 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=2030#p2030</guid>
		</item>
		<item>
			<title><![CDATA[Re: Resizing Windows in AppGraphics]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=2029#p2029</link>
			<description><![CDATA[<p>Frank,</p><p>It could be a bug.&nbsp; I&#039;ll have a look tomorrow (I&#039;ve been away from my desk for most of last week).</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Sun, 26 Apr 2015 15:38:12 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=2029#p2029</guid>
		</item>
		<item>
			<title><![CDATA[Re: Resizing Windows in AppGraphics]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=2027#p2027</link>
			<description><![CDATA[<p>Hi Jeff,</p><p>I would like to add a file/open menu to main window of resize (just as an example of the potential use of the open file dialog).</p><p>I&#039;ve successfully added &#039;File/saveimage&#039;,&nbsp; &#039;File/open&#039;, and &#039;File/quit&#039; sub-menus to the window.</p><p>The File/saveimage and File/quit options work just fine, but the File/open dlgopenfile() option causes the system to &#039;hang-up&#039;.</p><p>Do you have any suggestions on the proper use and way to add a file open dlgopenfile() menu to a main window?</p><p>Below is the code of your resize program with my revisions labeled to add menu options.</p><p>I look forward to any suggestions you or others may have to resolve this issue.</p><p>Frank</p><p>!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />appprogram resizing<br />use appgraphics<br />implicit none</p><p>&nbsp; &nbsp; integer::myscreen<br />&nbsp; &nbsp; integer::mybutton<br />&nbsp; &nbsp; logical::quit</p><p>&nbsp; &nbsp; !--------------Added-------------------------------------\/<br />&nbsp; &nbsp; integer::root_menu, file_menu, item_temp<br />&nbsp; &nbsp; !--------------------------------------------------------/\</p><p>&nbsp; &nbsp; myscreen = initwindow(320, 240, closeflag=.TRUE.)<br />&nbsp; &nbsp; mybutton = createbutton(270, 210, 40, 20, &quot;Close&quot;, handle_button)</p><p>&nbsp; &nbsp; !--------------Added-------------------------------------\/<br />&nbsp; &nbsp; root_menu = addmenu(&quot;&quot;, MENU_FOR_WINDOW)<br />&nbsp; &nbsp; file_menu = addmenu(&quot;File&quot;, root_menu)</p><p>&nbsp; &nbsp; item_temp = addmenuitem(&quot;Save Screenshot...&quot;, file_menu, savescreen)<br />&nbsp; &nbsp; item_temp = addmenuitem(&quot;Open&quot;, file_menu, openfile)<br />&nbsp; &nbsp; item_temp = addmenuitem(&quot;Quit&quot;, file_menu, quitwndo)<br />&nbsp; &nbsp; !--------------------------------------------------------/\</p><p>&nbsp; &nbsp; quit = .FALSE.</p><p>&nbsp; &nbsp; call enableresize(handle_resize)</p><p>&nbsp; &nbsp; do while(.NOT. quit)<br />&nbsp; &nbsp; &nbsp; &nbsp; call draw_window()<br />&nbsp; &nbsp; &nbsp; &nbsp; call loop()<br />&nbsp; &nbsp; end do</p><p>&nbsp; &nbsp; call closewindow(myscreen)</p><p>&nbsp; &nbsp; contains</p><p>&nbsp; &nbsp; subroutine draw_window()<br />&nbsp; &nbsp; use appgraphics<br />&nbsp; &nbsp; implicit none<br />&nbsp; &nbsp; &nbsp; &nbsp; integer::w,h</p><p>&nbsp; &nbsp; &nbsp; &nbsp; integer::tw<br />&nbsp; &nbsp; &nbsp; &nbsp; character(100)::info</p><p>&nbsp; &nbsp; &nbsp; &nbsp; w = getmaxx()<br />&nbsp; &nbsp; &nbsp; &nbsp; h = getmaxy()</p><p>&nbsp; &nbsp; &nbsp; &nbsp; call setbuttonposition(mybutton, w-50, h-30, 40, 20)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; write(info, &#039;(A5,1X,I5,A1,I5)&#039;) &quot;Size:&quot;, w, &quot;x&quot;, h</p><p>&nbsp; &nbsp; &nbsp; &nbsp; call setviewport(0, 0, w, 40, .FALSE.)<br />&nbsp; &nbsp; &nbsp; &nbsp; call clearviewport()<br />&nbsp; &nbsp; &nbsp; &nbsp; tw = textwidth(trim(info))<br />&nbsp; &nbsp; &nbsp; &nbsp; call outtextxy( (w/2-tw/2), 5, trim(info))</p><p>&nbsp; &nbsp; end subroutine draw_window</p><p>&nbsp; &nbsp; subroutine handle_button()<br />&nbsp; &nbsp; use appgraphics, only: stopidle<br />&nbsp; &nbsp; implicit none</p><p>&nbsp; &nbsp; &nbsp; &nbsp; quit = .TRUE.<br />&nbsp; &nbsp; &nbsp; &nbsp; call stopidle()</p><p>&nbsp; &nbsp; end subroutine handle_button</p><p>&nbsp; &nbsp; subroutine handle_resize()<br />&nbsp; &nbsp; use appgraphics<br />&nbsp; &nbsp; implicit none</p><p>&nbsp; &nbsp; &nbsp; &nbsp; call stopidle()</p><p>&nbsp; &nbsp; end subroutine handle_resize</p><p>&nbsp; &nbsp; !--------------Added-------------------------------------\/<br />&nbsp; &nbsp; subroutine openfile()<br />&nbsp; &nbsp; &nbsp; &nbsp; USE appgraphics, ONLY: dlgopenfile<br />&nbsp; &nbsp; &nbsp; &nbsp; implicit none</p><p>&nbsp; &nbsp; &nbsp; &nbsp; CHARACTER(255)&nbsp; :: input_file_name</p><p>&nbsp; &nbsp; &nbsp; &nbsp; !&nbsp; &nbsp;Appgraphics function dlgopenfile (filename, maskdesc, mask, title)<br />&nbsp; &nbsp; &nbsp; &nbsp; input_file_name= repeat(&#039; &#039;, 255)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; IF( dlgopenfile( &amp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; input_file_name, &#039;Data&#039;, &#039;*.raw&#039;, &#039;Enter data file&#039;) ) THEN</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Print *, &quot;You&#039;ve selected &quot;//trim(input_file_name)<br />&nbsp; &nbsp; &nbsp; &nbsp; ELSE<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Print *, &quot;No file was selected&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; END IF</p><p>&nbsp; &nbsp; &nbsp; &nbsp; input_file_name = TRIM(input_file_name)</p><p>&nbsp; &nbsp; end subroutine openfile</p><p>&nbsp; &nbsp; subroutine savescreen()<br />&nbsp; &nbsp; &nbsp; &nbsp; use appgraphics, only: writeimagefile<br />&nbsp; &nbsp; &nbsp; &nbsp; implicit none</p><p>&nbsp; &nbsp; &nbsp; &nbsp; ! This call will open a file dialog since we haven&#039;t<br />&nbsp; &nbsp; &nbsp; &nbsp; ! specified a filename<br />&nbsp; &nbsp; &nbsp; &nbsp; call writeimagefile()</p><p>&nbsp; &nbsp; end subroutine savescreen</p><p>&nbsp; &nbsp; subroutine quitwndo()<br />&nbsp; &nbsp; &nbsp; &nbsp; use appgraphics, only: stopidle<br />&nbsp; &nbsp; &nbsp; &nbsp; implicit none</p><p>&nbsp; &nbsp; &nbsp; &nbsp; quit = .TRUE.<br />&nbsp; &nbsp; &nbsp; &nbsp; call stopidle()</p><p>&nbsp; &nbsp; end subroutine quitwndo<br />&nbsp; &nbsp; !--------------------------------------------------------/\<br />end program resizing<br />!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</p>]]></description>
			<author><![CDATA[null@example.com (drfrank)]]></author>
			<pubDate>Sat, 25 Apr 2015 15:39:17 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=2027#p2027</guid>
		</item>
		<item>
			<title><![CDATA[Resizing Windows in AppGraphics]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=2014#p2014</link>
			<description><![CDATA[<p>In case users were not aware, AppGraphics included with Simply Fortran 2.23 now supports resizing windows.&nbsp; We have a new tutorial available on how to implement resizing:</p><p><a href="https://approximatrix.wordpress.com/2015/04/03/creating-resizeable-windows-with-appgraphics/">https://approximatrix.wordpress.com/201 … pgraphics/</a></p><p>The tutorial should be enough to get users started on creating resizeable windows.</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Wed, 08 Apr 2015 11:33:34 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=2014#p2014</guid>
		</item>
	</channel>
</rss>
