Skip to content

Commit

Permalink
Next installment. [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
skaller committed Nov 25, 2017
1 parent bc1b9a3 commit 5188f7f
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/tutorial/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'default'
html_theme = 'classic'

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand Down
Binary file added doc/tutorial/gui05.jpeg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
139 changes: 139 additions & 0 deletions doc/tutorial/gui05.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
Using a Window Manager
======================

A *window manager* is a component that automates
distribution of message such as mouse clicks and key
presses to one of several event handlers.

The initial windows
-------------------

First our usual setup:

.. code-block:: felix
include "gui/__init__";
open FlxGui;
println$ "Basic Window Controller Test";
FlxGui::init();
var font_name = dflt_sans_serif_font();
var font : font_t = get_font(font_name, 12);
var lineskip = get_lineskip font;
Now, we make two similar windows, at different locations
but different titles.

.. code-block:: felix
var w1 = create_resizable_window("Felix:gui_05_window_controller_01",100,100,400,400);
w1.add$ mk_drawable FlxGui::clear lightgrey;
w1.add$ mk_drawable FlxGui::write (100,100,font,black,"Basic Window Controller Test#1");
w1.show();
w1.update();
var w2 = create_resizable_window("WINDOW 2",400,100,400,400);
w2.add$ mk_drawable FlxGui::clear blue;
w2.add$ mk_drawable FlxGui::write (100,100,font,black,"Basic Window Controller Test#2");
w2.show();
w2.update();
The Event handler
-----------------

The same as before!

.. code-block:: felix
// make an event handler for our window
chip ehandler
(var w:window_t)
connector pins
pin input : %<event_t
{
// get a first event from the window manager
var e: event_t = read pins.input;
// while the event isn't a quit event ..
while e.window.event.SDL_WindowEventID != SDL_WINDOWEVENT_CLOSE do
// print a diagnostic
var s =
match e with
| WINDOWEVENT we =>
we.type.SDL_EventType.str + ": " + we.event.SDL_WindowEventID.str + " wid=" + we.windowID.str
| _ =>
e.type.SDL_EventType.str
;
var linepos = 100 + 4 * lineskip;
if s != "" do
println$ s;
var r = rect_t (100,linepos - 2*lineskip,300,4*lineskip);
w.add$ mk_drawable fill (r, green);
w.add$ mk_drawable FlxGui::write (100,linepos,font,black,"EVENT: "+ s);
w.update();
done
// get another event
e= read pins.input;
done
// we must have got a quit ..
println$ "++++++CLOSE EVENT";
}
The Window manager
------------------

.. image:: gui05.jpeg

Noe for the fun bit. First, our mainline creates a window manager
object:

.. code-block:: felix
begin
//create a window manager
var wm = window_manager();
Now, we create two window controllers.
There will be clients of the window manager.

.. code-block:: felix
// create a window controller for our window
var eh1 = ehandler w1;
var wc1 = window_controller (w1, eh1);
var eh2 = ehandler w2;
var wc2 = window_controller (w2, eh2);
Note that in this case the same event handler is bound
to two distinct windows, and then a window controller
is bound to them, as well as the window (again!)

Next, we simply add the window controller clients
to the window manager.

.. code-block:: felix
// attach controller to window manager
var wno1 = wm.add_window wc1;
println$ "Window number " + wno1.str;
var wno2 = wm.add_window wc2;
println$ "Window number " + wno2.str;
When we do this, we get back a window number, assigned by the
window manager, so we can refer to the windows in a way
the window manager understands (although we're not doing
that here).

Finally:

.. code-block:: felix
wm.run_with_timeout 10.0;
println$ "gui05 quitting";
end
we just run the window manager, in this case with a timeout
because its a demo.
2 changes: 1 addition & 1 deletion doc/tutorial/guiindex.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ Felix GUI
gui02
gui03
gui04

gui05
1 change: 1 addition & 0 deletions src/packages/time.fdoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ if PLAT_WIN32 do
else
inherit PosixTime;
done
rename fun sleep = Faio::sleep;
}

@h1 Posix RTC
Expand Down

0 comments on commit 5188f7f

Please sign in to comment.