File: cs_148.html

package info (click to toggle)
crystalspace 0.94-20020412-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 62,276 kB
  • ctags: 52,843
  • sloc: cpp: 274,783; ansic: 6,608; perl: 6,276; objc: 3,952; asm: 2,942; python: 2,354; php: 542; pascal: 530; sh: 430; makefile: 370; awk: 193
file content (157 lines) | stat: -rw-r--r-- 6,670 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Created by texi2html 1.64 -->
<!-- 
Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author)
            Karl Berry  <karl@freefriends.org>
            Olaf Bachmann <obachman@mathematik.uni-kl.de>
            and many others.
Maintained by: Olaf Bachmann <obachman@mathematik.uni-kl.de>
Send bugs and suggestions to <texi2html@mathematik.uni-kl.de>
 
-->
<HTML>
<HEAD>
<TITLE>Crystal Space: CSWS Tutorial</TITLE>

<META NAME="description" CONTENT="Crystal Space: CSWS Tutorial">
<META NAME="keywords" CONTENT="Crystal Space: CSWS Tutorial">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META NAME="Generator" CONTENT="texi2html 1.64">

</HEAD>

<BODY LANG="" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000">

<A NAME="SEC324"></A>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_147.html#SEC321"> &lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_149.html#SEC326"> &gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_142.html#SEC310"> &lt;&lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_143.html#SEC311"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_149.html#SEC326"> &gt;&gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="index.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_285.html#SEC711">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<HR SIZE=1>
<H3> 6.6.5 Quick Tutorial </H3>
<!--docid::SEC324::-->
<P>

In the following discussion I will try to explain how to build simple
applications using the Crystal Space Windowing System.  I hope you will
understand enough to start writing your own applications; I also hope you will
get a deeper knowledge of CSWS during your development (or lab) sessions.
In fact, I highly recommend perusing the CSWS header files (or
alternatively at the HTML documentation generated from the header files)
as they contain a lot of useful information which is not present here.
</P><P>

<A NAME="SEC325"></A>
<H4> A Simple Application </H4>
<!--docid::SEC325::-->
<P>

The simplest possible application should do the following:
</P><P>

<UL>
<LI>
Create and initialize a system driver object.
<LI>
Create and initialize an application object (`<SAMP>csApp</SAMP>') based on the
system driver.
<LI>
Run the application; meaning run the main event processing loop.
<LI>
Finish the application; that is, delete the object.
</UL>
<P>

Let's try:
</P><P>

<TABLE><tr><td>&nbsp;</td><td class=example><pre>#include "csws/csws.h"

int main(int argc, char const* const argv[])
{
  SysSystemDriver sys;
  if (!sys.Initialize(argc, argv, "/config/cswstest,cfg"))
    return -1;
  if (!sys.Open("Crystal Space Windowing System"))
    return -1;

  csApp app(&#38;sys);
  if (app.Initialize("/csws/csws.cfg"))
    app.Loop();
}
</pre></td></tr></table></P><P>

Pretty simple, eh?  So the result is simple as well.  We got a grey background,
a mouse and nothing more.  What the program does is:
</P><P>

<UL>
<LI>
First of all, it creates the system driver object.  You can provide a
configuration file which contains the list of all plugins to be loaded, in
addition to other things.  You can use the `<TT>cswstest.cfg</TT>' file as a
template.  You can also pass `<SAMP>NULL</SAMP>' as the file name, in which case you
will have to manually tell to the system driver which plug-ins to load (via the
<CODE>iSystem::RequestPlugin()</CODE> method).
<P>

<LI>
Second, it creates a `<SAMP>csApp</SAMP>' object called `<SAMP>app</SAMP>'.  To initialize the
application you pass a pointer to the system driver object.
<P>

<LI>
The next step is to call <CODE>csApp::Initialize()</CODE>.  You pass the name of the
CSWS configuration file (which is different from system configuration
file).  This configuration file tells CSWS which textures to use for
windowing system components; where on the textures the respective pictures are
placed; and other skin-dependent information.  You may want to override this
method to initialize your application here (after calling the parent's
<CODE>Initialize()</CODE>).  For instance, create a popup menu, insert it onto the
desktop, add some windows, check configuration files, etc.
<P>

<LI>
And finally we run the main application loop.  The event consuming loop does
the following.  While there are events in input queue it read an event and
passes it to <CODE>HandleEvent()</CODE>.  If there weren't any events in the loop,
it calls <CODE>Idle()</CODE> method to give some time slices to other running
applications (if <CODE>csSystemDriver::Sleep()</CODE> method is implemented
properly).  If some window needs redrawing, it is redrawn.  After this the
screen is updated and everything starts again from the beginning.
</UL>
<P>

If you observe, the above program does not delete the `<SAMP>SysSystemDriver</SAMP>'
or `<SAMP>csApp</SAMP>' objects. That's because they are automatic variables and not
pointers, so they are automatically deleted when they go out of scope.
<A NAME="csPhyziks"></A>
<HR SIZE=1>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_147.html#SEC321"> &lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_149.html#SEC326"> &gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_142.html#SEC310"> &lt;&lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_143.html#SEC311"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_149.html#SEC326"> &gt;&gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="index.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_285.html#SEC711">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<BR>  
<FONT SIZE="-1">
This document was generated

using <A HREF="http://www.mathematik.uni-kl.de/~obachman/Texi2html
"><I>texi2html</I></A>

</BODY>
</HTML>