Compare commits

..

1 Commits

Author SHA1 Message Date
Bryan Petty
af75c24d38 This commit was manufactured by cvs2svn to create tag 'wxGTK_2_1_13'.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/tags/wxGTK_2_1_13@5627 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2000-01-24 13:27:37 +00:00
1935 changed files with 293785 additions and 18115 deletions

35
.cvsignore Normal file
View File

@@ -0,0 +1,35 @@
system.list
bin
.gdb_history
Test
config.cache
configarg.cache
config.status
system.list
linux.system.cache
wx-config
config.log
linux-gnu.system.cache
*.dsp
*.dsw
*.plg
*.opt
*.aps
*.ncb
*.pro
*.opt
*.d
*.swp
*.swo
Release
Debug
ReleaseDLL
DebugDLL
robert
stamp-h.in
Makefile
configure
setup.h
stamp-h
libtool
aclocal.m4

242
BuildCVS.txt Normal file
View File

@@ -0,0 +1,242 @@
------------------------------------------------------------------------
How to build the sources from CVS
------------------------------------------------------------------------
I) Windows using plain makefiles
----------------------------------------
a) If using Microsoft Visual C++ 5.0 or 6.0
Ensure that the command-line compiler and tools (including
nmake) are installed and ready to run. Depending on your
installation there may be a batch file (named something like
VCVARS32.BAT) that needs to be run to set correct environment
varaibles and PATH entries.
Continue with item c) below.
b) If using the GNU MinGW32 or GNU CygWin32 compilers
You'll need the compiler itself which is available from
http://www.cygwin.com
When using MingW32 you'll need GNU make which is a part
of the CygWin32 toolchain and is also available as a stand
alone port without the infamous Cygwin.dll from
http://agnes.dida.physik.uni-essen.de/~janjaap/mingw32
The makefile has small problems with Cygwin<69>s tools
so it is recommended not to use these (but MingGW32
and its make.exe).
-> Set your path so that it includes the directory
where your compiler and tools reside
b-2) Using Mingw32 with gcc-2.95 and Anders Norlander's
Win32 headers
Using the newer gcc-2.95/Noralander header combination
will allow you to compile more of the MSW code, such
as OLE and Drag-n-Drop.
Instructions are similar to those for Regular Mingw32 except
->Get the compiler from
ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/mingw32/gcc-2.95/
->patch the gcc headers with info in wxWin\Mingw32-gcc295.patches.
PLEASE APPLY THESE PATCHES BY HAND! There are apparently a few
different versions of the headers floating around.
->Edit wx/src/makeg95.env and set the MINGW32 variable at the top of
the file to either 1 (you have Mingw32) or 0 (you have Cygwin32).
If using MINGW32, also set the MINGW32VERSION variable
appropriately.
c) Build instructions
-> Assumming that you installed the wxWindows sources
into c:\wxWin
-> Copy c:\wxWin\include\wx\msw\setup0.h
to c:\wxWin\include\wx\msw\setup.h
-> Edit c:\wxWin\include\wx\msw\setup.h so that
most features are enabled (i.e. defined to 1) with
#define wxUSE_ODBC 0
#define wxUSE_SOCKETS 0
#define wxUSE_HTML 1
#define wxUSE_THREADS 1
#define wxUSE_FS_INET 0
#define wxUSE_FS_ZIP 1
#define wxUSE_BUSYINFO 1
#define wxUSE_DYNLIB_CLASS 1
#define wxUSE_ZIPSTREAM 1
#define wxUSE_LIBJPEG 1
#define wxUSE_LIBPNG 1
and iostreams ares disabled with
#define wxUSE_STD_IOSTREAM 0
note: ODBC and SOCKETS can be 1 for gcc-2.95
-> type: cd c:\wxWin\src\msw
-> type: make -f makefile.g95 (if using GNU tools)
or type: make -f makefile.vc (if using MS VC++)
II) Unix ports
--------------
Building wxGTK or wxMotif completely without configure
won't ever work, but there is now a new makefile system
that works without libtool and automake, using only
configure to create what is needed.
In order to create configure, you need to have the
GNU autoconf package (version 2.13 or 2.14) installed
on your system and type run "autoconf" in the base
directory (or run the autogen.sh script in the same
directory, which just calls autoconf).
Set WXWIN environment variable to the base directory such
as ~/wxWindows (this is actually not really needed).
-> type: export WXWIN=~/wxWindows
-> type: md mybuild
-> type: cd mybuild
-> type: ../configure --with-motif
or type: ../configure --with-gtk
-> type: make
-> type: su <type root password>
-> type: make install
-> type: ldconfig
-> type: exit
Call configure with --disable-shared to create a static
library. Calling "make uninstall" will remove the installed
library and "make dist" will create a distribution (not
yet complete).
III) Windows using configure
----------------------------------------
Take a look at Unix->Windows cross compiling. With minor
modifications, this should work in Windows if you've got the cygnus
utilities (bash, GNU make, etc) and either mingw32 or cygwin32 installed.
See http://www.cygnus.com for these programs, or go straight to their
ftp server at ftp://sourceware.cygnus.com/pub/cygwin/.
Of course, you can also build the library using plain makefiles (see
section I).
V) MacOS
----------------------------------------
VI) OS/2
----------------------------------------
VII) Unix->Windows cross-compiling using configure
--------------------------------------------------
First you'll need a cross-compiler; linux glibc binaries of mingw32 and
cygwin32 (both based on egcs) can be found at
ftp://ftp.objsw.com/pub/crossgcc/linux-x-win32. Otherwise you can
compile one yourself. Check the relevant FAQs.
[ A Note about cygwin32 and mingw32: the main difference is that cygwin32
binaries are always linked against cygwin.dll. This dll encapsulates most
standard Unix C extensions, which is very handy if you're porting unix
software to windows. However, wxMSW doesn't need this, so mingw32 is
preferable if you write portable C(++). ]
You might want to build both Unix and Windows binaries in the same source
tree; to do this make subdirs for each e.g. unix and win32. If you've
already build wxWindows in the main dir, do a 'make distclean' there,
otherwise configure will get confused. (In any case, read the section 'Unix
using configure' and make sure you're able to build a native wxWindows
library; cross-compiling errors can be pretty obscure and you'll want to be
sure that your configure setup is basically sound.)
To cross compile the windows library, do
-> cd win32
(or whatever you called it)
Now run configure. There are two ways to do this
-> ../configure --host=i586-mingw32 --build=i586-linux --with-mingw \
--enable-dnd=no --without-odbc
where --build= should read whatever platform you're building on. Configure
will notice that build and host platforms differ, and automatically prepend
i586-mingw32- to gcc, ar, ld, etc (make sure they're in the PATH!).
The other way to run configure is by specifying the names of the binaries
yourself:
-> CC=i586-mingw32-gcc CXX=i586-mingw32-g++ RANLIB=i586-mingw32-ranlib \
DLLTOOL=i586-mingw32-dlltool LD=i586-mingw32-ld NM=i586-mingw32-nm \
../configure --host=i586-mingw32 --with-mingw --enable-dnd=no
(all assuming you're using mingw32)
Drag'n'drop is disabled because mingw32 lacks (AFAIK) OLE headers.
[ Update: some new mingw32 versions now have a new set of windows header
files, which apparently can handle ole. Untested at the moment ]
ODBC files don't compile as of 13.10.99 - may be this will be fixed by the
moment you're reading these lines.
Configure will conclude that shared libraries are out of the question and
opt for a static one. I haven't looked into DLL creation yet.
Type
-> make
and wait, wait, wait. Don't leave the room, because the minute you do there
will be a compile error :-)
NB: you risk to get quite a few warnings about "ANSI C++ forbids implicit
conversion from 'void *'" in all places where va_arg macro is used. This
is due to a bug in (some versions of) mingw32 headers which may be
corrected by editing the file
${install_prefix}/lib/gcc-lib/i586-mingw32/egcs-2.91.57/include/stdarg.h
(instead of egcs-2.91.57 you may have something different), searching for
the lines
/* Define __gnuc_va_list. */
#ifndef __GNUC_VA_LIST
#define __GNUC_VA_LIST
#if defined(__svr4__) || defined(_AIX) || defined(_M_UNIX) || defined(__NetBSD__)
typedef char *__gnuc_va_list;
#else
typedef void *__gnuc_va_list;
#endif
#endif
and adding "|| defined(_WIN32)" to the list of platforms on which
__gnuc_va_list is char *.
If this is successful, you end up with a libwx_msw.a in win32/lib. Now try
building the minimal sample:
-> cd samples/minimal
-> make
and run it with wine, for example (or copy to a Windows box)
-> wine minimal.exe
If all is well, do an install; from win32
-> make install
Native and cross-compiled installations can co-exist peacefully
(as long as their widget sets differ), except for wx-config. You might
want to rename the cross-compiled one to i586-mingw32-wx-config, or something.
Cross-compiling TODO:
---------------------
- resource compiling must be done manually for now (should/can we link the
default wx resources into libwx_msw.a?) [ No we can't; the linker won't
link it in... you have to supply an object file ]
- dynamic libraries
- static executables are HUGE -- there must be room for improvement.

3380
Makefile.in Normal file

File diff suppressed because it is too large Load Diff

131
Mingw32-gcc295.patches Normal file
View File

@@ -0,0 +1,131 @@
*** \gcc-inc\basetyps.h Sat Jul 31 16:48:36 1999
--- basetyps.h Fri Aug 06 11:14:36 1999
***************
*** 74,91 ****
--- 74,97 ----
STDMETHOD(Clone)(IENUM_THIS_(I) I**) PURE; \
}
#define DECLARE_ENUMERATOR(T) DECLARE_ENUMERATOR_(IEnum##T,T)
+ #ifndef GUID_DEFINED
+ #define GUID_DEFINED
typedef struct _GUID
{
unsigned long Data1;
unsigned short Data2;
unsigned short Data3;
unsigned char Data4[8];
} GUID;
+ #endif /* GUID_DEFINED */
typedef GUID *REFGUID;
typedef GUID *LPGUID;
+ #ifndef UUID_DEFINED
+ #define UUID_DEFINED
typedef GUID UUID;
+ #endif /* UUID_DEFINED */
typedef GUID IID;
typedef GUID CLSID;
typedef CLSID *LPCLSID;
typedef IID *LPIID;
*** \gcc-inc\oaidl.h Sat Jul 31 16:48:42 1999
--- oaidl.h Fri Aug 06 13:18:48 1999
***************
*** 39,44 ****
--- 39,53 ----
#define IMPLTYPEFLAG_FRESTRICTED 4
#define IMPLTYPEFLAG_FDEFAULTVTABLE 8
+ #define DISPID_UNKNOWN ( -1 )
+ #define DISPID_VALUE ( 0 )
+ #define DISPID_PROPERTYPUT ( -3 )
+ #define DISPID_NEWENUM ( -4 )
+ #define DISPID_EVALUATE ( -5 )
+ #define DISPID_CONSTRUCTOR ( -6 )
+ #define DISPID_DESTRUCTOR ( -7 )
+ #define DISPID_COLLECT ( -8 )
+
typedef interface ITypeLib *LPTYPELIB;
typedef interface ICreateTypeInfo *LPCREATETYPEINFO;
typedef interface ICreateTypeInfo2 *LPCREATETYPEINFO2;
***************
*** 49,54 ****
--- 58,73 ----
typedef interface IDispatch *LPDISPATCH;
typedef interface ICreateErrorInfo *LPCREATEERRORINFO;
+ extern "C" const IID IID_ITypeLib;
+ extern "C" const IID IID_ICreateTypeInfo;
+ extern "C" const IID IID_ICreateTypeInfo2;
+ extern "C" const IID IID_ICreateTypeLib;
+ extern "C" const IID IID_ICreateTypeLib2;
+ extern "C" const IID IID_ITypeInfo;
+ extern "C" const IID IID_IErrorInfo;
+ extern "C" const IID IID_IDispatch;
+ extern "C" const IID IID_ICreateErrorInfo;
+
typedef enum tagSYSKIND {
SYS_WIN16,SYS_WIN32,SYS_MAC
} SYSKIND;
***************
*** 375,382 ****
STDMETHOD_(ULONG,Release)(THIS) PURE;
STDMETHOD(GetTypeInfoCount)(THIS_ UINT*) PURE;
STDMETHOD(GetTypeInfo)(THIS_ UINT,LCID,LPTYPEINFO*) PURE;
! STDMETHOD(GetIDsOfNames)(THIS_ REFIID,LPOLESTR*,UINT,LCID,DISPID)
PURE;
! STDMETHOD(Invoked)(THIS_ DISPID,REFIID,LCID,WORD,DISPPARAMS*,VARIANT*,EXCEPINFO*,UINT*) PURE;
};
#ifdef __cplusplus
--- 394,401 ----
STDMETHOD_(ULONG,Release)(THIS) PURE;
STDMETHOD(GetTypeInfoCount)(THIS_ UINT*) PURE;
STDMETHOD(GetTypeInfo)(THIS_ UINT,LCID,LPTYPEINFO*) PURE;
! STDMETHOD(GetIDsOfNames)(THIS_ REFIID,LPOLESTR*,UINT,LCID,DISPID*)
PURE;
! STDMETHOD(Invoke)(THIS_ DISPID,REFIID,LCID,WORD,DISPPARAMS*,VARIANT*,EXCEPINFO*,UINT*) PURE;
};
#ifdef __cplusplus
*** \gcc-inc\objidl.h Sat Jul 31 16:48:42 1999
--- objidl.h Fri Aug 06 11:00:19 1999
***************
*** 627,633 ****
STDMETHOD(QueryGetData)(THIS_ FORMATETC*) PURE;
STDMETHOD(GetCanonicalFormatEtc)(THIS_ FORMATETC*,FORMATETC*) PURE;
STDMETHOD(SetData)(THIS_ FORMATETC*,STGMEDIUM*,BOOL) PURE;
! STDMETHOD(EnumFormatEtc)(THIS_ DWORD,IEnumFORMATETC*) PURE;
STDMETHOD(DAdvise)(THIS_ FORMATETC*,DWORD,IAdviseSink*,PDWORD) PURE;
STDMETHOD(DUnadvise)(THIS_ DWORD) PURE;
STDMETHOD(EnumDAdvise)(THIS_ IEnumSTATDATA**);
--- 627,633 ----
STDMETHOD(QueryGetData)(THIS_ FORMATETC*) PURE;
STDMETHOD(GetCanonicalFormatEtc)(THIS_ FORMATETC*,FORMATETC*) PURE;
STDMETHOD(SetData)(THIS_ FORMATETC*,STGMEDIUM*,BOOL) PURE;
! STDMETHOD(EnumFormatEtc)(THIS_ DWORD,IEnumFORMATETC**) PURE;
STDMETHOD(DAdvise)(THIS_ FORMATETC*,DWORD,IAdviseSink*,PDWORD) PURE;
STDMETHOD(DUnadvise)(THIS_ DWORD) PURE;
STDMETHOD(EnumDAdvise)(THIS_ IEnumSTATDATA**);
--- i386-mingw32\include\stdio.h Sun Aug 1 06:18:20 1999
+++ stdio.h Sun Nov 7 03:41:40 1999
@@ -203,9 +203,12 @@
int fprintf (FILE* filePrintTo, const char* szFormat, ...);
int printf (const char* szFormat, ...);
int sprintf (char* caBuffer, const char* szFormat, ...);
+int _snprintf (char* caBuffer, size_t n, const char* szFormat, ...);
int vfprintf (FILE* filePrintTo, const char* szFormat, va_list varg);
int vprintf (const char* szFormat, va_list varg);
int vsprintf (char* caBuffer, const char* szFormat, va_list varg);
+int _vsnprintf (char* caBuffer, size_t n, const char* szFormat,
+ va_list varg);
/* Wide character versions */
int fwprintf (FILE* filePrintTo, const wchar_t* wsFormat, ...);

2
autogen.sh Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/sh
autoconf

951
config.guess vendored Executable file
View File

@@ -0,0 +1,951 @@
#! /bin/sh
# Attempt to guess a canonical system name.
# Copyright (C) 1992, 93, 94, 95, 96, 97, 1998 Free Software Foundation, Inc.
#
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
# Written by Per Bothner <bothner@cygnus.com>.
# The master version of this file is at the FSF in /home/gd/gnu/lib.
#
# This script attempts to guess a canonical system name similar to
# config.sub. If it succeeds, it prints the system name on stdout, and
# exits with 0. Otherwise, it exits with 1.
#
# The plan is that this can be called by configure scripts if you
# don't specify an explicit system type (host/target name).
#
# Only a few systems have been added to this list; please add others
# (but try to keep the structure clean).
#
# This is needed to find uname on a Pyramid OSx when run in the BSD universe.
# (ghazi@noc.rutgers.edu 8/24/94.)
if (test -f /.attbin/uname) >/dev/null 2>&1 ; then
PATH=$PATH:/.attbin ; export PATH
fi
UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown
UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
trap 'rm -f dummy.c dummy.o dummy; exit 1' 1 2 15
# Note: order is significant - the case branches are not exclusive.
case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
alpha:OSF1:*:*)
if test $UNAME_RELEASE = "V4.0"; then
UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
fi
# A Vn.n version is a released version.
# A Tn.n version is a released field test version.
# A Xn.n version is an unreleased experimental baselevel.
# 1.2 uses "1.2" for uname -r.
cat <<EOF >dummy.s
.globl main
.ent main
main:
.frame \$30,0,\$26,0
.prologue 0
.long 0x47e03d80 # implver $0
lda \$2,259
.long 0x47e20c21 # amask $2,$1
srl \$1,8,\$2
sll \$2,2,\$2
sll \$0,3,\$0
addl \$1,\$0,\$0
addl \$2,\$0,\$0
ret \$31,(\$26),1
.end main
EOF
${CC-cc} dummy.s -o dummy 2>/dev/null
if test "$?" = 0 ; then
./dummy
case "$?" in
7)
UNAME_MACHINE="alpha"
;;
15)
UNAME_MACHINE="alphaev5"
;;
14)
UNAME_MACHINE="alphaev56"
;;
10)
UNAME_MACHINE="alphapca56"
;;
16)
UNAME_MACHINE="alphaev6"
;;
esac
fi
rm -f dummy.s dummy
echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[VTX]//' | tr [[A-Z]] [[a-z]]`
exit 0 ;;
21064:Windows_NT:50:3)
echo alpha-dec-winnt3.5
exit 0 ;;
Amiga*:UNIX_System_V:4.0:*)
echo m68k-cbm-sysv4
exit 0;;
amiga:NetBSD:*:*)
echo m68k-cbm-netbsd${UNAME_RELEASE}
exit 0 ;;
amiga:OpenBSD:*:*)
echo m68k-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
*:[Aa]miga[Oo][Ss]:*:*)
echo ${UNAME_MACHINE}-unknown-amigaos
exit 0 ;;
arc64:OpenBSD:*:*)
echo mips64el-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
arc:OpenBSD:*:*)
echo mipsel-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
hkmips:OpenBSD:*:*)
echo mips-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
pmax:OpenBSD:*:*)
echo mipsel-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
sgi:OpenBSD:*:*)
echo mips-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
wgrisc:OpenBSD:*:*)
echo mipsel-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
echo arm-acorn-riscix${UNAME_RELEASE}
exit 0;;
arm32:NetBSD:*:*)
echo arm-unknown-netbsd`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
exit 0 ;;
SR2?01:HI-UX/MPP:*:*)
echo hppa1.1-hitachi-hiuxmpp
exit 0;;
Pyramid*:OSx*:*:*|MIS*:OSx*:*:*|MIS*:SMP_DC-OSx*:*:*)
# akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE.
if test "`(/bin/universe) 2>/dev/null`" = att ; then
echo pyramid-pyramid-sysv3
else
echo pyramid-pyramid-bsd
fi
exit 0 ;;
NILE:*:*:dcosx)
echo pyramid-pyramid-svr4
exit 0 ;;
sun4H:SunOS:5.*:*)
echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
exit 0 ;;
sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*)
echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
exit 0 ;;
i86pc:SunOS:5.*:*)
echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
exit 0 ;;
sun4*:SunOS:6*:*)
# According to config.sub, this is the proper way to canonicalize
# SunOS6. Hard to guess exactly what SunOS6 will be like, but
# it's likely to be more like Solaris than SunOS4.
echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
exit 0 ;;
sun4*:SunOS:*:*)
case "`/usr/bin/arch -k`" in
Series*|S4*)
UNAME_RELEASE=`uname -v`
;;
esac
# Japanese Language versions have a version number like `4.1.3-JL'.
echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'`
exit 0 ;;
sun3*:SunOS:*:*)
echo m68k-sun-sunos${UNAME_RELEASE}
exit 0 ;;
sun*:*:4.2BSD:*)
UNAME_RELEASE=`(head -1 /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null`
test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3
case "`/bin/arch`" in
sun3)
echo m68k-sun-sunos${UNAME_RELEASE}
;;
sun4)
echo sparc-sun-sunos${UNAME_RELEASE}
;;
esac
exit 0 ;;
aushp:SunOS:*:*)
echo sparc-auspex-sunos${UNAME_RELEASE}
exit 0 ;;
atari*:NetBSD:*:*)
echo m68k-atari-netbsd${UNAME_RELEASE}
exit 0 ;;
atari*:OpenBSD:*:*)
echo m68k-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
sun3*:NetBSD:*:*)
echo m68k-sun-netbsd${UNAME_RELEASE}
exit 0 ;;
sun3*:OpenBSD:*:*)
echo m68k-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
mac68k:NetBSD:*:*)
echo m68k-apple-netbsd${UNAME_RELEASE}
exit 0 ;;
mac68k:OpenBSD:*:*)
echo m68k-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
mvme68k:OpenBSD:*:*)
echo m68k-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
mvme88k:OpenBSD:*:*)
echo m88k-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
powerpc:machten:*:*)
echo powerpc-apple-machten${UNAME_RELEASE}
exit 0 ;;
macppc:NetBSD:*:*)
echo powerpc-apple-netbsd${UNAME_RELEASE}
exit 0 ;;
RISC*:Mach:*:*)
echo mips-dec-mach_bsd4.3
exit 0 ;;
RISC*:ULTRIX:*:*)
echo mips-dec-ultrix${UNAME_RELEASE}
exit 0 ;;
VAX*:ULTRIX*:*:*)
echo vax-dec-ultrix${UNAME_RELEASE}
exit 0 ;;
2020:CLIX:*:*)
echo clipper-intergraph-clix${UNAME_RELEASE}
exit 0 ;;
mips:*:*:UMIPS | mips:*:*:RISCos)
sed 's/^ //' << EOF >dummy.c
int main (argc, argv) int argc; char **argv; {
#if defined (host_mips) && defined (MIPSEB)
#if defined (SYSTYPE_SYSV)
printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0);
#endif
#if defined (SYSTYPE_SVR4)
printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0);
#endif
#if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD)
printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0);
#endif
#endif
exit (-1);
}
EOF
${CC-cc} dummy.c -o dummy \
&& ./dummy `echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` \
&& rm dummy.c dummy && exit 0
rm -f dummy.c dummy
echo mips-mips-riscos${UNAME_RELEASE}
exit 0 ;;
Night_Hawk:Power_UNIX:*:*)
echo powerpc-harris-powerunix
exit 0 ;;
m88k:CX/UX:7*:*)
echo m88k-harris-cxux7
exit 0 ;;
m88k:*:4*:R4*)
echo m88k-motorola-sysv4
exit 0 ;;
m88k:*:3*:R3*)
echo m88k-motorola-sysv3
exit 0 ;;
AViiON:dgux:*:*)
# DG/UX returns AViiON for all architectures
UNAME_PROCESSOR=`/usr/bin/uname -p`
if [ $UNAME_PROCESSOR = mc88100 -o $UNAME_PROCESSOR = mc88110 ] ; then
if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx \
-o ${TARGET_BINARY_INTERFACE}x = x ] ; then
echo m88k-dg-dgux${UNAME_RELEASE}
else
echo m88k-dg-dguxbcs${UNAME_RELEASE}
fi
else echo i586-dg-dgux${UNAME_RELEASE}
fi
exit 0 ;;
M88*:DolphinOS:*:*) # DolphinOS (SVR3)
echo m88k-dolphin-sysv3
exit 0 ;;
M88*:*:R3*:*)
# Delta 88k system running SVR3
echo m88k-motorola-sysv3
exit 0 ;;
XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3)
echo m88k-tektronix-sysv3
exit 0 ;;
Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD)
echo m68k-tektronix-bsd
exit 0 ;;
*:IRIX*:*:*)
echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'`
exit 0 ;;
????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX.
echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id
exit 0 ;; # Note that: echo "'`uname -s`'" gives 'AIX '
i?86:AIX:*:*)
echo i386-ibm-aix
exit 0 ;;
*:AIX:2:3)
if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then
sed 's/^ //' << EOF >dummy.c
#include <sys/systemcfg.h>
main()
{
if (!__power_pc())
exit(1);
puts("powerpc-ibm-aix3.2.5");
exit(0);
}
EOF
${CC-cc} dummy.c -o dummy && ./dummy && rm dummy.c dummy && exit 0
rm -f dummy.c dummy
echo rs6000-ibm-aix3.2.5
elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
echo rs6000-ibm-aix3.2.4
else
echo rs6000-ibm-aix3.2
fi
exit 0 ;;
*:AIX:*:4)
IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | head -1 | awk '{ print $1 }'`
if /usr/sbin/lsattr -EHl ${IBM_CPU_ID} | grep POWER >/dev/null 2>&1; then
IBM_ARCH=rs6000
else
IBM_ARCH=powerpc
fi
if [ -x /usr/bin/oslevel ] ; then
IBM_REV=`/usr/bin/oslevel`
else
IBM_REV=4.${UNAME_RELEASE}
fi
echo ${IBM_ARCH}-ibm-aix${IBM_REV}
exit 0 ;;
*:AIX:*:*)
echo rs6000-ibm-aix
exit 0 ;;
ibmrt:4.4BSD:*|romp-ibm:BSD:*)
echo romp-ibm-bsd4.4
exit 0 ;;
ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC NetBSD and
echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to
exit 0 ;; # report: romp-ibm BSD 4.3
*:BOSX:*:*)
echo rs6000-bull-bosx
exit 0 ;;
DPX/2?00:B.O.S.:*:*)
echo m68k-bull-sysv3
exit 0 ;;
9000/[34]??:4.3bsd:1.*:*)
echo m68k-hp-bsd
exit 0 ;;
hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*)
echo m68k-hp-bsd4.4
exit 0 ;;
9000/[34678]??:HP-UX:*:*)
case "${UNAME_MACHINE}" in
9000/31? ) HP_ARCH=m68000 ;;
9000/[34]?? ) HP_ARCH=m68k ;;
9000/6?? | 9000/7?? | 9000/80[24] | 9000/8?[13679] | 9000/892 )
sed 's/^ //' << EOF >dummy.c
#include <stdlib.h>
#include <unistd.h>
int main ()
{
#if defined(_SC_KERNEL_BITS)
long bits = sysconf(_SC_KERNEL_BITS);
#endif
long cpu = sysconf (_SC_CPU_VERSION);
switch (cpu)
{
case CPU_PA_RISC1_0: puts ("hppa1.0"); break;
case CPU_PA_RISC1_1: puts ("hppa1.1"); break;
case CPU_PA_RISC2_0:
#if defined(_SC_KERNEL_BITS)
switch (bits)
{
case 64: puts ("hppa2.0w"); break;
case 32: puts ("hppa2.0n"); break;
default: puts ("hppa2.0"); break;
} break;
#else /* !defined(_SC_KERNEL_BITS) */
puts ("hppa2.0"); break;
#endif
default: puts ("hppa1.0"); break;
}
exit (0);
}
EOF
(${CC-cc} dummy.c -o dummy 2>/dev/null ) && HP_ARCH=`./dummy`
rm -f dummy.c dummy
esac
HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
echo ${HP_ARCH}-hp-hpux${HPUX_REV}
exit 0 ;;
3050*:HI-UX:*:*)
sed 's/^ //' << EOF >dummy.c
#include <unistd.h>
int
main ()
{
long cpu = sysconf (_SC_CPU_VERSION);
/* The order matters, because CPU_IS_HP_MC68K erroneously returns
true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct
results, however. */
if (CPU_IS_PA_RISC (cpu))
{
switch (cpu)
{
case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break;
case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break;
case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break;
default: puts ("hppa-hitachi-hiuxwe2"); break;
}
}
else if (CPU_IS_HP_MC68K (cpu))
puts ("m68k-hitachi-hiuxwe2");
else puts ("unknown-hitachi-hiuxwe2");
exit (0);
}
EOF
${CC-cc} dummy.c -o dummy && ./dummy && rm dummy.c dummy && exit 0
rm -f dummy.c dummy
echo unknown-hitachi-hiuxwe2
exit 0 ;;
9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* )
echo hppa1.1-hp-bsd
exit 0 ;;
9000/8??:4.3bsd:*:*)
echo hppa1.0-hp-bsd
exit 0 ;;
hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* )
echo hppa1.1-hp-osf
exit 0 ;;
hp8??:OSF1:*:*)
echo hppa1.0-hp-osf
exit 0 ;;
i?86:OSF1:*:*)
if [ -x /usr/sbin/sysversion ] ; then
echo ${UNAME_MACHINE}-unknown-osf1mk
else
echo ${UNAME_MACHINE}-unknown-osf1
fi
exit 0 ;;
parisc*:Lites*:*:*)
echo hppa1.1-hp-lites
exit 0 ;;
C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
echo c1-convex-bsd
exit 0 ;;
C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
if getsysinfo -f scalar_acc
then echo c32-convex-bsd
else echo c2-convex-bsd
fi
exit 0 ;;
C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
echo c34-convex-bsd
exit 0 ;;
C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
echo c38-convex-bsd
exit 0 ;;
C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
echo c4-convex-bsd
exit 0 ;;
CRAY*X-MP:*:*:*)
echo xmp-cray-unicos
exit 0 ;;
CRAY*Y-MP:*:*:*)
echo ymp-cray-unicos${UNAME_RELEASE}
exit 0 ;;
CRAY*[A-Z]90:*:*:*)
echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \
| sed -e 's/CRAY.*\([A-Z]90\)/\1/' \
-e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/
exit 0 ;;
CRAY*TS:*:*:*)
echo t90-cray-unicos${UNAME_RELEASE}
exit 0 ;;
CRAY-2:*:*:*)
echo cray2-cray-unicos
exit 0 ;;
F300:UNIX_System_V:*:*)
FUJITSU_SYS=`uname -p | tr [A-Z] [a-z] | sed -e 's/\///'`
FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
echo "f300-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
exit 0 ;;
F301:UNIX_System_V:*:*)
echo f301-fujitsu-uxpv`echo $UNAME_RELEASE | sed 's/ .*//'`
exit 0 ;;
hp3[0-9][05]:NetBSD:*:*)
echo m68k-hp-netbsd${UNAME_RELEASE}
exit 0 ;;
hp300:OpenBSD:*:*)
echo m68k-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
sparc*:BSD/OS:*:*)
echo sparc-unknown-bsdi${UNAME_RELEASE}
exit 0 ;;
i?86:BSD/386:*:* | *:BSD/OS:*:*)
echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}
exit 0 ;;
*:FreeBSD:*:*)
echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
exit 0 ;;
*:NetBSD:*:*)
echo ${UNAME_MACHINE}-unknown-netbsd`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
exit 0 ;;
*:OpenBSD:*:*)
echo ${UNAME_MACHINE}-unknown-openbsd`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
exit 0 ;;
i*:CYGWIN*:*)
echo ${UNAME_MACHINE}-pc-cygwin32
exit 0 ;;
i*:MINGW*:*)
echo ${UNAME_MACHINE}-pc-mingw32
exit 0 ;;
p*:CYGWIN*:*)
echo powerpcle-unknown-cygwin32
exit 0 ;;
prep*:SunOS:5.*:*)
echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
exit 0 ;;
*:GNU:*:*)
echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
exit 0 ;;
*:Linux:*:*)
# uname on the ARM produces all sorts of strangeness, and we need to
# filter it out.
case "$UNAME_MACHINE" in
arm* | sa110*) UNAME_MACHINE="arm" ;;
esac
# The BFD linker knows what the default object file format is, so
# first see if it will tell us.
ld_help_string=`ld --help 2>&1`
ld_supported_emulations=`echo $ld_help_string \
| sed -ne '/supported emulations:/!d
s/[ ][ ]*/ /g
s/.*supported emulations: *//
s/ .*//
p'`
case "$ld_supported_emulations" in
i?86linux) echo "${UNAME_MACHINE}-pc-linux-gnuaout" ; exit 0 ;;
i?86coff) echo "${UNAME_MACHINE}-pc-linux-gnucoff" ; exit 0 ;;
sparclinux) echo "${UNAME_MACHINE}-unknown-linux-gnuaout" ; exit 0 ;;
armlinux) echo "${UNAME_MACHINE}-unknown-linux-gnuaout" ; exit 0 ;;
m68klinux) echo "${UNAME_MACHINE}-unknown-linux-gnuaout" ; exit 0 ;;
elf32ppc) echo "powerpc-unknown-linux-gnu" ; exit 0 ;;
esac
if test "${UNAME_MACHINE}" = "alpha" ; then
sed 's/^ //' <<EOF >dummy.s
.globl main
.ent main
main:
.frame \$30,0,\$26,0
.prologue 0
.long 0x47e03d80 # implver $0
lda \$2,259
.long 0x47e20c21 # amask $2,$1
srl \$1,8,\$2
sll \$2,2,\$2
sll \$0,3,\$0
addl \$1,\$0,\$0
addl \$2,\$0,\$0
ret \$31,(\$26),1
.end main
EOF
LIBC=""
${CC-cc} dummy.s -o dummy 2>/dev/null
if test "$?" = 0 ; then
./dummy
case "$?" in
7)
UNAME_MACHINE="alpha"
;;
15)
UNAME_MACHINE="alphaev5"
;;
14)
UNAME_MACHINE="alphaev56"
;;
10)
UNAME_MACHINE="alphapca56"
;;
16)
UNAME_MACHINE="alphaev6"
;;
esac
objdump --private-headers dummy | \
grep ld.so.1 > /dev/null
if test "$?" = 0 ; then
LIBC="libc1"
fi
fi
rm -f dummy.s dummy
echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} ; exit 0
elif test "${UNAME_MACHINE}" = "mips" ; then
cat >dummy.c <<EOF
main(argc, argv)
int argc;
char *argv[];
{
#ifdef __MIPSEB__
printf ("%s-unknown-linux-gnu\n", argv[1]);
#endif
#ifdef __MIPSEL__
printf ("%sel-unknown-linux-gnu\n", argv[1]);
#endif
return 0;
}
EOF
${CC-cc} dummy.c -o dummy 2>/dev/null && ./dummy "${UNAME_MACHINE}" && rm dummy.c dummy && exit 0
rm -f dummy.c dummy
else
# Either a pre-BFD a.out linker (linux-gnuoldld)
# or one that does not give us useful --help.
# GCC wants to distinguish between linux-gnuoldld and linux-gnuaout.
# If ld does not provide *any* "supported emulations:"
# that means it is gnuoldld.
echo "$ld_help_string" | grep >/dev/null 2>&1 "supported emulations:"
test $? != 0 && echo "${UNAME_MACHINE}-pc-linux-gnuoldld" && exit 0
case "${UNAME_MACHINE}" in
i?86)
VENDOR=pc;
;;
*)
VENDOR=unknown;
;;
esac
# Determine whether the default compiler is a.out or elf
cat >dummy.c <<EOF
#include <features.h>
main(argc, argv)
int argc;
char *argv[];
{
#ifdef __ELF__
# ifdef __GLIBC__
# if __GLIBC__ >= 2
printf ("%s-${VENDOR}-linux-gnu\n", argv[1]);
# else
printf ("%s-${VENDOR}-linux-gnulibc1\n", argv[1]);
# endif
# else
printf ("%s-${VENDOR}-linux-gnulibc1\n", argv[1]);
# endif
#else
printf ("%s-${VENDOR}-linux-gnuaout\n", argv[1]);
#endif
return 0;
}
EOF
${CC-cc} dummy.c -o dummy 2>/dev/null && ./dummy "${UNAME_MACHINE}" && rm dummy.c dummy && exit 0
rm -f dummy.c dummy
fi ;;
# ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. earlier versions
# are messed up and put the nodename in both sysname and nodename.
i?86:DYNIX/ptx:4*:*)
echo i386-sequent-sysv4
exit 0 ;;
i?86:UNIX_SV:4.2MP:2.*)
# Unixware is an offshoot of SVR4, but it has its own version
# number series starting with 2...
# I am not positive that other SVR4 systems won't match this,
# I just have to hope. -- rms.
# Use sysv4.2uw... so that sysv4* matches it.
echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}
exit 0 ;;
i?86:*:4.*:* | i?86:SYSTEM_V:4.*:*)
if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
echo ${UNAME_MACHINE}-univel-sysv${UNAME_RELEASE}
else
echo ${UNAME_MACHINE}-pc-sysv${UNAME_RELEASE}
fi
exit 0 ;;
i?86:*:3.2:*)
if test -f /usr/options/cb.name; then
UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name`
echo ${UNAME_MACHINE}-pc-isc$UNAME_REL
elif /bin/uname -X 2>/dev/null >/dev/null ; then
UNAME_REL=`(/bin/uname -X|egrep Release|sed -e 's/.*= //')`
(/bin/uname -X|egrep i80486 >/dev/null) && UNAME_MACHINE=i486
(/bin/uname -X|egrep '^Machine.*Pentium' >/dev/null) \
&& UNAME_MACHINE=i586
echo ${UNAME_MACHINE}-pc-sco$UNAME_REL
else
echo ${UNAME_MACHINE}-pc-sysv32
fi
exit 0 ;;
i?86:UnixWare:*:*)
if /bin/uname -X 2>/dev/null >/dev/null ; then
(/bin/uname -X|egrep '^Machine.*Pentium' >/dev/null) \
&& UNAME_MACHINE=i586
fi
echo ${UNAME_MACHINE}-unixware-${UNAME_RELEASE}-${UNAME_VERSION}
exit 0 ;;
pc:*:*:*)
# uname -m prints for DJGPP always 'pc', but it prints nothing about
# the processor, so we play safe by assuming i386.
echo i386-pc-msdosdjgpp
exit 0 ;;
Intel:Mach:3*:*)
echo i386-pc-mach3
exit 0 ;;
paragon:*:*:*)
echo i860-intel-osf1
exit 0 ;;
i860:*:4.*:*) # i860-SVR4
if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then
echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4
else # Add other i860-SVR4 vendors below as they are discovered.
echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4
fi
exit 0 ;;
mini*:CTIX:SYS*5:*)
# "miniframe"
echo m68010-convergent-sysv
exit 0 ;;
M68*:*:R3V[567]*:*)
test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;;
3[34]??:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 4850:*:4.0:3.0)
OS_REL=''
test -r /etc/.relid \
&& OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
&& echo i486-ncr-sysv4.3${OS_REL} && exit 0
/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
&& echo i586-ncr-sysv4.3${OS_REL} && exit 0 ;;
3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*)
/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
&& echo i486-ncr-sysv4 && exit 0 ;;
m68*:LynxOS:2.*:*)
echo m68k-unknown-lynxos${UNAME_RELEASE}
exit 0 ;;
mc68030:UNIX_System_V:4.*:*)
echo m68k-atari-sysv4
exit 0 ;;
i?86:LynxOS:2.*:*)
echo i386-unknown-lynxos${UNAME_RELEASE}
exit 0 ;;
TSUNAMI:LynxOS:2.*:*)
echo sparc-unknown-lynxos${UNAME_RELEASE}
exit 0 ;;
rs6000:LynxOS:2.*:* | PowerPC:LynxOS:2.*:*)
echo rs6000-unknown-lynxos${UNAME_RELEASE}
exit 0 ;;
SM[BE]S:UNIX_SV:*:*)
echo mips-dde-sysv${UNAME_RELEASE}
exit 0 ;;
RM*:SINIX-*:*:*)
echo mips-sni-sysv4
exit 0 ;;
*:SINIX-*:*:*)
if uname -p 2>/dev/null >/dev/null ; then
UNAME_MACHINE=`(uname -p) 2>/dev/null`
echo ${UNAME_MACHINE}-sni-sysv4
else
echo ns32k-sni-sysv
fi
exit 0 ;;
PENTIUM:CPunix:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
# says <Richard.M.Bartel@ccMail.Census.GOV>
echo i586-unisys-sysv4
exit 0 ;;
*:UNIX_System_V:4*:FTX*)
# From Gerald Hewes <hewes@openmarket.com>.
# How about differentiating between stratus architectures? -djm
echo hppa1.1-stratus-sysv4
exit 0 ;;
*:*:*:FTX*)
# From seanf@swdc.stratus.com.
echo i860-stratus-sysv4
exit 0 ;;
mc68*:A/UX:*:*)
echo m68k-apple-aux${UNAME_RELEASE}
exit 0 ;;
news*:NEWS-OS:*:6*)
echo mips-sony-newsos6
exit 0 ;;
R3000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R4000:UNIX_SV:*:*)
if [ -d /usr/nec ]; then
echo mips-nec-sysv${UNAME_RELEASE}
else
echo mips-unknown-sysv${UNAME_RELEASE}
fi
exit 0 ;;
BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only.
echo powerpc-be-beos
exit 0 ;;
BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only.
echo powerpc-apple-beos
exit 0 ;;
BePC:BeOS:*:*) # BeOS running on Intel PC compatible.
echo i586-pc-beos
exit 0 ;;
esac
#echo '(No uname command or uname output not recognized.)' 1>&2
#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2
cat >dummy.c <<EOF
#ifdef _SEQUENT_
# include <sys/types.h>
# include <sys/utsname.h>
#endif
main ()
{
#if defined (sony)
#if defined (MIPSEB)
/* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed,
I don't know.... */
printf ("mips-sony-bsd\n"); exit (0);
#else
#include <sys/param.h>
printf ("m68k-sony-newsos%s\n",
#ifdef NEWSOS4
"4"
#else
""
#endif
); exit (0);
#endif
#endif
#if defined (__arm) && defined (__acorn) && defined (__unix)
printf ("arm-acorn-riscix"); exit (0);
#endif
#if defined (hp300) && !defined (hpux)
printf ("m68k-hp-bsd\n"); exit (0);
#endif
#if defined (NeXT)
#if !defined (__ARCHITECTURE__)
#define __ARCHITECTURE__ "m68k"
#endif
int version;
version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`;
printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version);
exit (0);
#endif
#if defined (MULTIMAX) || defined (n16)
#if defined (UMAXV)
printf ("ns32k-encore-sysv\n"); exit (0);
#else
#if defined (CMU)
printf ("ns32k-encore-mach\n"); exit (0);
#else
printf ("ns32k-encore-bsd\n"); exit (0);
#endif
#endif
#endif
#if defined (__386BSD__)
printf ("i386-pc-bsd\n"); exit (0);
#endif
#if defined (sequent)
#if defined (i386)
printf ("i386-sequent-dynix\n"); exit (0);
#endif
#if defined (ns32000)
printf ("ns32k-sequent-dynix\n"); exit (0);
#endif
#endif
#if defined (_SEQUENT_)
struct utsname un;
uname(&un);
if (strncmp(un.version, "V2", 2) == 0) {
printf ("i386-sequent-ptx2\n"); exit (0);
}
if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */
printf ("i386-sequent-ptx1\n"); exit (0);
}
printf ("i386-sequent-ptx\n"); exit (0);
#endif
#if defined (vax)
#if !defined (ultrix)
printf ("vax-dec-bsd\n"); exit (0);
#else
printf ("vax-dec-ultrix\n"); exit (0);
#endif
#endif
#if defined (alliant) && defined (i860)
printf ("i860-alliant-bsd\n"); exit (0);
#endif
exit (1);
}
EOF
${CC-cc} dummy.c -o dummy 2>/dev/null && ./dummy && rm dummy.c dummy && exit 0
rm -f dummy.c dummy
# Apollos put the system type in the environment.
test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit 0; }
# Convex versions that predate uname can use getsysinfo(1)
if [ -x /usr/convex/getsysinfo ]
then
case `getsysinfo -f cpu_type` in
c1*)
echo c1-convex-bsd
exit 0 ;;
c2*)
if getsysinfo -f scalar_acc
then echo c32-convex-bsd
else echo c2-convex-bsd
fi
exit 0 ;;
c34*)
echo c34-convex-bsd
exit 0 ;;
c38*)
echo c38-convex-bsd
exit 0 ;;
c4*)
echo c4-convex-bsd
exit 0 ;;
esac
fi
#echo '(Unable to guess system type)' 1>&2
exit 1

955
config.sub vendored Executable file
View File

@@ -0,0 +1,955 @@
#! /bin/sh
# Configuration validation subroutine script, version 1.1.
# Copyright (C) 1991, 92-97, 1998 Free Software Foundation, Inc.
# This file is (in principle) common to ALL GNU software.
# The presence of a machine in this file suggests that SOME GNU software
# can handle that machine. It does not imply ALL GNU software can.
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
# Configuration subroutine to validate and canonicalize a configuration type.
# Supply the specified configuration type as an argument.
# If it is invalid, we print an error message on stderr and exit with code 1.
# Otherwise, we print the canonical config type on stdout and succeed.
# This file is supposed to be the same for all GNU packages
# and recognize all the CPU types, system types and aliases
# that are meaningful with *any* GNU software.
# Each package is responsible for reporting which valid configurations
# it does not support. The user should be able to distinguish
# a failure to support a valid configuration from a meaningless
# configuration.
# The goal of this file is to map all the various variations of a given
# machine specification into a single specification in the form:
# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
# or in some cases, the newer four-part form:
# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
# It is wrong to echo any other type of specification.
if [ x$1 = x ]
then
echo Configuration name missing. 1>&2
echo "Usage: $0 CPU-MFR-OPSYS" 1>&2
echo "or $0 ALIAS" 1>&2
echo where ALIAS is a recognized configuration type. 1>&2
exit 1
fi
# First pass through any local machine types.
case $1 in
*local*)
echo $1
exit 0
;;
*)
;;
esac
# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any).
# Here we must recognize all the valid KERNEL-OS combinations.
maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
case $maybe_os in
linux-gnu*)
os=-$maybe_os
basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
;;
*)
basic_machine=`echo $1 | sed 's/-[^-]*$//'`
if [ $basic_machine != $1 ]
then os=`echo $1 | sed 's/.*-/-/'`
else os=; fi
;;
esac
### Let's recognize common machines as not being operating systems so
### that things like config.sub decstation-3100 work. We also
### recognize some manufacturers as not being operating systems, so we
### can provide default operating systems below.
case $os in
-sun*os*)
# Prevent following clause from handling this invalid input.
;;
-dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \
-att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \
-unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \
-convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
-c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
-harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
-apple)
os=
basic_machine=$1
;;
-hiux*)
os=-hiuxwe2
;;
-sco5)
os=sco3.2v5
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-sco4)
os=-sco3.2v4
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-sco3.2.[4-9]*)
os=`echo $os | sed -e 's/sco3.2./sco3.2v/'`
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-sco3.2v[4-9]*)
# Don't forget version if it is 3.2v4 or newer.
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-sco*)
os=-sco3.2v2
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-isc)
os=-isc2.2
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-clix*)
basic_machine=clipper-intergraph
;;
-isc*)
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-lynx*)
os=-lynxos
;;
-ptx*)
basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'`
;;
-windowsnt*)
os=`echo $os | sed -e 's/windowsnt/winnt/'`
;;
-psos*)
os=-psos
;;
esac
# Decode aliases for certain CPU-COMPANY combinations.
case $basic_machine in
# Recognize the basic CPU types without company name.
# Some are omitted here because they have special meanings below.
tahoe | i860 | m32r | m68k | m68000 | m88k | ns32k | arc | arm \
| arme[lb] | pyramid | mn10200 | mn10300 | tron | a29k \
| 580 | i960 | h8300 | hppa | hppa1.0 | hppa1.1 | hppa2.0 \
| alpha | alphaev5 | alphaev56 | we32k | ns16k | clipper \
| i370 | sh | powerpc | powerpcle | 1750a | dsp16xx | pdp11 \
| mips64 | mipsel | mips64el | mips64orion | mips64orionel \
| mipstx39 | mipstx39el \
| sparc | sparclet | sparclite | sparc64 | v850)
basic_machine=$basic_machine-unknown
;;
# We use `pc' rather than `unknown'
# because (1) that's what they normally are, and
# (2) the word "unknown" tends to confuse beginning users.
i[34567]86)
basic_machine=$basic_machine-pc
;;
# Object if more than one company name word.
*-*-*)
echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
exit 1
;;
# Recognize the basic CPU types with company name.
vax-* | tahoe-* | i[34567]86-* | i860-* | m32r-* | m68k-* | m68000-* \
| m88k-* | sparc-* | ns32k-* | fx80-* | arc-* | arm-* | c[123]* \
| mips-* | pyramid-* | tron-* | a29k-* | romp-* | rs6000-* \
| power-* | none-* | 580-* | cray2-* | h8300-* | i960-* \
| xmp-* | ymp-* | hppa-* | hppa1.0-* | hppa1.1-* | hppa2.0-* \
| alpha-* | alphaev5-* | alphaev56-* | we32k-* | cydra-* \
| ns16k-* | pn-* | np1-* | xps100-* | clipper-* | orion-* \
| sparclite-* | pdp11-* | sh-* | powerpc-* | powerpcle-* \
| sparc64-* | mips64-* | mipsel-* \
| mips64el-* | mips64orion-* | mips64orionel-* \
| mipstx39-* | mipstx39el-* \
| f301-*)
;;
# Recognize the various machine names and aliases which stand
# for a CPU type and a company and sometimes even an OS.
3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)
basic_machine=m68000-att
;;
3b*)
basic_machine=we32k-att
;;
alliant | fx80)
basic_machine=fx80-alliant
;;
altos | altos3068)
basic_machine=m68k-altos
;;
am29k)
basic_machine=a29k-none
os=-bsd
;;
amdahl)
basic_machine=580-amdahl
os=-sysv
;;
amiga | amiga-*)
basic_machine=m68k-cbm
;;
amigaos | amigados)
basic_machine=m68k-cbm
os=-amigaos
;;
amigaunix | amix)
basic_machine=m68k-cbm
os=-sysv4
;;
apollo68)
basic_machine=m68k-apollo
os=-sysv
;;
aux)
basic_machine=m68k-apple
os=-aux
;;
balance)
basic_machine=ns32k-sequent
os=-dynix
;;
convex-c1)
basic_machine=c1-convex
os=-bsd
;;
convex-c2)
basic_machine=c2-convex
os=-bsd
;;
convex-c32)
basic_machine=c32-convex
os=-bsd
;;
convex-c34)
basic_machine=c34-convex
os=-bsd
;;
convex-c38)
basic_machine=c38-convex
os=-bsd
;;
cray | ymp)
basic_machine=ymp-cray
os=-unicos
;;
cray2)
basic_machine=cray2-cray
os=-unicos
;;
[ctj]90-cray)
basic_machine=c90-cray
os=-unicos
;;
crds | unos)
basic_machine=m68k-crds
;;
da30 | da30-*)
basic_machine=m68k-da30
;;
decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn)
basic_machine=mips-dec
;;
delta | 3300 | motorola-3300 | motorola-delta \
| 3300-motorola | delta-motorola)
basic_machine=m68k-motorola
;;
delta88)
basic_machine=m88k-motorola
os=-sysv3
;;
dpx20 | dpx20-*)
basic_machine=rs6000-bull
os=-bosx
;;
dpx2* | dpx2*-bull)
basic_machine=m68k-bull
os=-sysv3
;;
ebmon29k)
basic_machine=a29k-amd
os=-ebmon
;;
elxsi)
basic_machine=elxsi-elxsi
os=-bsd
;;
encore | umax | mmax)
basic_machine=ns32k-encore
;;
fx2800)
basic_machine=i860-alliant
;;
genix)
basic_machine=ns32k-ns
;;
gmicro)
basic_machine=tron-gmicro
os=-sysv
;;
h3050r* | hiux*)
basic_machine=hppa1.1-hitachi
os=-hiuxwe2
;;
h8300hms)
basic_machine=h8300-hitachi
os=-hms
;;
harris)
basic_machine=m88k-harris
os=-sysv3
;;
hp300-*)
basic_machine=m68k-hp
;;
hp300bsd)
basic_machine=m68k-hp
os=-bsd
;;
hp300hpux)
basic_machine=m68k-hp
os=-hpux
;;
hp9k2[0-9][0-9] | hp9k31[0-9])
basic_machine=m68000-hp
;;
hp9k3[2-9][0-9])
basic_machine=m68k-hp
;;
hp9k7[0-9][0-9] | hp7[0-9][0-9] | hp9k8[0-9]7 | hp8[0-9]7)
basic_machine=hppa1.1-hp
;;
hp9k8[0-9][0-9] | hp8[0-9][0-9])
basic_machine=hppa1.0-hp
;;
hppa-next)
os=-nextstep3
;;
i370-ibm* | ibm*)
basic_machine=i370-ibm
os=-mvs
;;
# I'm not sure what "Sysv32" means. Should this be sysv3.2?
i[34567]86v32)
basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
os=-sysv32
;;
i[34567]86v4*)
basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
os=-sysv4
;;
i[34567]86v)
basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
os=-sysv
;;
i[34567]86sol2)
basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
os=-solaris2
;;
iris | iris4d)
basic_machine=mips-sgi
case $os in
-irix*)
;;
*)
os=-irix4
;;
esac
;;
isi68 | isi)
basic_machine=m68k-isi
os=-sysv
;;
m88k-omron*)
basic_machine=m88k-omron
;;
magnum | m3230)
basic_machine=mips-mips
os=-sysv
;;
merlin)
basic_machine=ns32k-utek
os=-sysv
;;
miniframe)
basic_machine=m68000-convergent
;;
mipsel*-linux*)
basic_machine=mipsel-unknown
os=-linux-gnu
;;
mips*-linux*)
basic_machine=mips-unknown
os=-linux-gnu
;;
mips3*-*)
basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`
;;
mips3*)
basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown
;;
ncr3000)
basic_machine=i486-ncr
os=-sysv4
;;
news | news700 | news800 | news900)
basic_machine=m68k-sony
os=-newsos
;;
news1000)
basic_machine=m68030-sony
os=-newsos
;;
news-3600 | risc-news)
basic_machine=mips-sony
os=-newsos
;;
next | m*-next )
basic_machine=m68k-next
case $os in
-nextstep* )
;;
-ns2*)
os=-nextstep2
;;
*)
os=-nextstep3
;;
esac
;;
nh3000)
basic_machine=m68k-harris
os=-cxux
;;
nh[45]000)
basic_machine=m88k-harris
os=-cxux
;;
nindy960)
basic_machine=i960-intel
os=-nindy
;;
np1)
basic_machine=np1-gould
;;
pa-hitachi)
basic_machine=hppa1.1-hitachi
os=-hiuxwe2
;;
paragon)
basic_machine=i860-intel
os=-osf
;;
pbd)
basic_machine=sparc-tti
;;
pbb)
basic_machine=m68k-tti
;;
pc532 | pc532-*)
basic_machine=ns32k-pc532
;;
pentium | p5 | k5 | nexen)
basic_machine=i586-pc
;;
pentiumpro | p6 | k6 | 6x86)
basic_machine=i686-pc
;;
pentiumii | pentium2)
basic_machine=i786-pc
;;
pentium-* | p5-* | k5-* | nexen-*)
basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
pentiumpro-* | p6-* | k6-* | 6x86-*)
basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
pentiumii-* | pentium2-*)
basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
pn)
basic_machine=pn-gould
;;
power) basic_machine=rs6000-ibm
;;
ppc) basic_machine=powerpc-unknown
;;
ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
ppcle | powerpclittle | ppc-le | powerpc-little)
basic_machine=powerpcle-unknown
;;
ppcle-* | powerpclittle-*)
basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
ps2)
basic_machine=i386-ibm
;;
rm[46]00)
basic_machine=mips-siemens
;;
rtpc | rtpc-*)
basic_machine=romp-ibm
;;
sequent)
basic_machine=i386-sequent
;;
sh)
basic_machine=sh-hitachi
os=-hms
;;
sps7)
basic_machine=m68k-bull
os=-sysv2
;;
spur)
basic_machine=spur-unknown
;;
sun2)
basic_machine=m68000-sun
;;
sun2os3)
basic_machine=m68000-sun
os=-sunos3
;;
sun2os4)
basic_machine=m68000-sun
os=-sunos4
;;
sun3os3)
basic_machine=m68k-sun
os=-sunos3
;;
sun3os4)
basic_machine=m68k-sun
os=-sunos4
;;
sun4os3)
basic_machine=sparc-sun
os=-sunos3
;;
sun4os4)
basic_machine=sparc-sun
os=-sunos4
;;
sun4sol2)
basic_machine=sparc-sun
os=-solaris2
;;
sun3 | sun3-*)
basic_machine=m68k-sun
;;
sun4)
basic_machine=sparc-sun
;;
sun386 | sun386i | roadrunner)
basic_machine=i386-sun
;;
symmetry)
basic_machine=i386-sequent
os=-dynix
;;
tx39)
basic_machine=mipstx39-unknown
;;
tx39el)
basic_machine=mipstx39el-unknown
;;
tower | tower-32)
basic_machine=m68k-ncr
;;
udi29k)
basic_machine=a29k-amd
os=-udi
;;
ultra3)
basic_machine=a29k-nyu
os=-sym1
;;
vaxv)
basic_machine=vax-dec
os=-sysv
;;
vms)
basic_machine=vax-dec
os=-vms
;;
vpp*|vx|vx-*)
basic_machine=f301-fujitsu
;;
vxworks960)
basic_machine=i960-wrs
os=-vxworks
;;
vxworks68)
basic_machine=m68k-wrs
os=-vxworks
;;
vxworks29k)
basic_machine=a29k-wrs
os=-vxworks
;;
xmp)
basic_machine=xmp-cray
os=-unicos
;;
xps | xps100)
basic_machine=xps100-honeywell
;;
none)
basic_machine=none-none
os=-none
;;
# Here we handle the default manufacturer of certain CPU types. It is in
# some cases the only manufacturer, in others, it is the most popular.
mips)
if [ x$os = x-linux-gnu ]; then
basic_machine=mips-unknown
else
basic_machine=mips-mips
fi
;;
romp)
basic_machine=romp-ibm
;;
rs6000)
basic_machine=rs6000-ibm
;;
vax)
basic_machine=vax-dec
;;
pdp11)
basic_machine=pdp11-dec
;;
we32k)
basic_machine=we32k-att
;;
sparc)
basic_machine=sparc-sun
;;
cydra)
basic_machine=cydra-cydrome
;;
orion)
basic_machine=orion-highlevel
;;
orion105)
basic_machine=clipper-highlevel
;;
*)
echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
exit 1
;;
esac
# Here we canonicalize certain aliases for manufacturers.
case $basic_machine in
*-digital*)
basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'`
;;
*-commodore*)
basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'`
;;
*)
;;
esac
# Decode manufacturer-specific aliases for certain operating systems.
if [ x"$os" != x"" ]
then
case $os in
# First match some system type aliases
# that might get confused with valid system types.
# -solaris* is a basic system type, with this one exception.
-solaris1 | -solaris1.*)
os=`echo $os | sed -e 's|solaris1|sunos4|'`
;;
-solaris)
os=-solaris2
;;
-svr4*)
os=-sysv4
;;
-unixware*)
os=-sysv4.2uw
;;
-gnu/linux*)
os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'`
;;
# First accept the basic system types.
# The portable systems comes first.
# Each alternative MUST END IN A *, to match a version number.
# -sysv* is not here because it comes later, after sysvr4.
-gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
| -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\
| -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \
| -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
| -aos* \
| -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
| -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
| -hiux* | -386bsd* | -netbsd* | -openbsd* | -freebsd* | -riscix* \
| -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* \
| -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
| -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
| -cygwin32* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
| -mingw32* | -linux-gnu* | -uxpv* | -beos*)
# Remember, each alternative MUST END IN *, to match a version number.
;;
-linux*)
os=`echo $os | sed -e 's|linux|linux-gnu|'`
;;
-sunos5*)
os=`echo $os | sed -e 's|sunos5|solaris2|'`
;;
-sunos6*)
os=`echo $os | sed -e 's|sunos6|solaris3|'`
;;
-osfrose*)
os=-osfrose
;;
-osf*)
os=-osf
;;
-utek*)
os=-bsd
;;
-dynix*)
os=-bsd
;;
-acis*)
os=-aos
;;
-ctix* | -uts*)
os=-sysv
;;
-ns2 )
os=-nextstep2
;;
# Preserve the version number of sinix5.
-sinix5.*)
os=`echo $os | sed -e 's|sinix|sysv|'`
;;
-sinix*)
os=-sysv4
;;
-triton*)
os=-sysv3
;;
-oss*)
os=-sysv3
;;
-svr4)
os=-sysv4
;;
-svr3)
os=-sysv3
;;
-sysvr4)
os=-sysv4
;;
# This must come after -sysvr4.
-sysv*)
;;
-xenix)
os=-xenix
;;
-none)
;;
*)
# Get rid of the `-' at the beginning of $os.
os=`echo $os | sed 's/[^-]*-//'`
echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2
exit 1
;;
esac
else
# Here we handle the default operating systems that come with various machines.
# The value should be what the vendor currently ships out the door with their
# machine or put another way, the most popular os provided with the machine.
# Note that if you're going to try to match "-MANUFACTURER" here (say,
# "-sun"), then you have to tell the case statement up towards the top
# that MANUFACTURER isn't an operating system. Otherwise, code above
# will signal an error saying that MANUFACTURER isn't an operating
# system, and we'll never get to this point.
case $basic_machine in
*-acorn)
os=-riscix1.2
;;
arm*-semi)
os=-aout
;;
pdp11-*)
os=-none
;;
*-dec | vax-*)
os=-ultrix4.2
;;
m68*-apollo)
os=-domain
;;
i386-sun)
os=-sunos4.0.2
;;
m68000-sun)
os=-sunos3
# This also exists in the configure program, but was not the
# default.
# os=-sunos4
;;
*-tti) # must be before sparc entry or we get the wrong os.
os=-sysv3
;;
sparc-* | *-sun)
os=-sunos4.1.1
;;
*-be)
os=-beos
;;
*-ibm)
os=-aix
;;
*-hp)
os=-hpux
;;
*-hitachi)
os=-hiux
;;
i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent)
os=-sysv
;;
*-cbm)
os=-amigaos
;;
*-dg)
os=-dgux
;;
*-dolphin)
os=-sysv3
;;
m68k-ccur)
os=-rtu
;;
m88k-omron*)
os=-luna
;;
*-next )
os=-nextstep
;;
*-sequent)
os=-ptx
;;
*-crds)
os=-unos
;;
*-ns)
os=-genix
;;
i370-*)
os=-mvs
;;
*-next)
os=-nextstep3
;;
*-gould)
os=-sysv
;;
*-highlevel)
os=-bsd
;;
*-encore)
os=-bsd
;;
*-sgi)
os=-irix
;;
*-siemens)
os=-sysv4
;;
*-masscomp)
os=-rtu
;;
f301-fujitsu)
os=-uxpv
;;
*)
os=-none
;;
esac
fi
# Here we handle the case where we know the os, and the CPU type, but not the
# manufacturer. We pick the logical manufacturer.
vendor=unknown
case $basic_machine in
*-unknown)
case $os in
-riscix*)
vendor=acorn
;;
-sunos*)
vendor=sun
;;
-aix*)
vendor=ibm
;;
-hpux*)
vendor=hp
;;
-hiux*)
vendor=hitachi
;;
-unos*)
vendor=crds
;;
-dgux*)
vendor=dg
;;
-luna*)
vendor=omron
;;
-genix*)
vendor=ns
;;
-mvs*)
vendor=ibm
;;
-ptx*)
vendor=sequent
;;
-vxsim* | -vxworks*)
vendor=wrs
;;
-aux*)
vendor=apple
;;
esac
basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"`
;;
esac
echo $basic_machine$os

13711
configure vendored Executable file

File diff suppressed because it is too large Load Diff

3397
configure.in Normal file

File diff suppressed because it is too large Load Diff

11
demos/Makefile.in Normal file
View File

@@ -0,0 +1,11 @@
#
# Makefile : Builds wxWindows demos for Unix.
#
DEMOS_SUBDIRS=bombs forty fractal life poem
all:
@for d in $(DEMOS_SUBDIRS); do (cd $$d && make); done
clean:
@for d in $(DEMOS_SUBDIRS); do (cd $$d && make clean); done

0
demos/bombs/.cvsignore Normal file
View File

21
demos/bombs/Makefile.in Normal file
View File

@@ -0,0 +1,21 @@
#
# File: Makefile.in
# Author: Julian Smart
# Created: 1998
# Updated:
# Copyright: (c) 1998 Julian Smart
#
# "%W% %G%"
#
# Makefile for bombs example (UNIX).
top_srcdir = @top_srcdir@
top_builddir = ../..
program_dir = demos/bombs
PROGRAM=bombs
OBJECTS = bombs.o bombs1.o game.o
include ../../src/makeprog.env

BIN
demos/bombs/bombs.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 654 B

252
demos/bombs/bombs.cpp Normal file
View File

@@ -0,0 +1,252 @@
///////////////////////////////////////////////////////////////////////////////
// Name: bombs.cpp
// Purpose: Bombs game
// Author: P. Foggia 1996
// Modified by:
// Created: 1996
// RCS-ID: $Id$
// Copyright: (c) 1996 P. Foggia
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation
#endif
#include "wx/wxprec.h"
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif //precompiled headers
#include "bombs.h"
#include <time.h>
#include <stdlib.h>
#if defined(__WXGTK__) || defined(__WXMOTIF__)
#include "bombs.xpm"
#endif
IMPLEMENT_APP(AppClass)
// Called to initialize the program
bool AppClass::OnInit()
{
srand((unsigned)time(NULL));
// Initialize all the top-level window members to NULL.
BombsFrame = NULL;
level=IDM_EASY;
BombsFrame =
new BombsFrameClass(NULL, "wxBombs", wxPoint(155, 165), wxSize(300, 300), wxMINIMIZE_BOX | wxSYSTEM_MENU | wxCAPTION);
int xmax=BombsFrame->BombsCanvas->field_width*BombsFrame->BombsCanvas->x_cell*X_UNIT;
int ymax=BombsFrame->BombsCanvas->field_height*BombsFrame->BombsCanvas->y_cell*Y_UNIT;
BombsFrame->SetClientSize(xmax, ymax);
return TRUE;
}
BEGIN_EVENT_TABLE(BombsFrameClass, wxFrame)
EVT_MENU(IDM_EASY, BombsFrameClass::OnEasy)
EVT_MENU(IDM_MEDIUM, BombsFrameClass::OnMedium)
EVT_MENU(IDM_DIFFICULT, BombsFrameClass::OnDifficult)
EVT_MENU(IDM_EXIT, BombsFrameClass::OnExit)
EVT_MENU(IDM_ABOUT, BombsFrameClass::OnAbout)
EVT_MENU(IDM_RESTART, BombsFrameClass::OnRestart)
EVT_CLOSE(BombsFrameClass::OnCloseWindow)
END_EVENT_TABLE()
BombsFrameClass::BombsFrameClass(wxFrame *parent, const wxString& title, const wxPoint& pos, const wxSize& size, long style):
wxFrame(parent, -1, title, pos, size, style)
{
// Initialize child subwindow members.
BombsCanvas = NULL;
SetIcon(wxICON(bombs));
CreateStatusBar();
// Create a menu bar for the frame
wxMenuBar *menuBar1 = new wxMenuBar;
wxMenu *menu1 = new wxMenu;
menu1->Append(IDM_EXIT, "E&xit"); // , "Quit the program");
menu1->AppendSeparator();
menu1->Append(IDM_ABOUT, "&About..."); // , "Infos on wxBombs");
menuBar1->Append(menu1, "&File");
wxMenu *menu2 = new wxMenu;
menu2->Append(IDM_RESTART, "&Restart"); // , "Clear the play field");
menu2->AppendSeparator();
menu2->Append(IDM_EASY, "&Easy", wxEmptyString, TRUE); // "10x10 play field", TRUE);
menu2->Append(IDM_MEDIUM, "&Medium", wxEmptyString, TRUE); // "15x15 play field", TRUE);
menu2->Append(IDM_DIFFICULT, "&Difficult", wxEmptyString, TRUE); // "25x20 play field", TRUE);
menuBar1->Append(menu2, "&Game");
SetMenuBar(menuBar1);
menuBar=menuBar1;
menuBar->Check(wxGetApp().level, TRUE);
// Create child subwindows.
BombsCanvas = new BombsCanvasClass(this);
// Ensure the subwindows get resized o.k.
// OnSize(width, height);
// Centre frame on the screen.
Centre(wxBOTH);
// Show the frame.
Show(TRUE);
}
BombsFrameClass::~BombsFrameClass(void)
{
}
void BombsFrameClass::OnCloseWindow(wxCloseEvent& event)
{
this->Destroy();
}
void BombsFrameClass::OnExit(wxCommandEvent& event)
{
this->Destroy();
}
void BombsFrameClass::OnRestart(wxCommandEvent& event)
{
BombsCanvas->UpdateFieldSize();
int xmax=BombsCanvas->field_width*BombsCanvas->x_cell*X_UNIT;
int ymax=BombsCanvas->field_height*BombsCanvas->y_cell*Y_UNIT;
wxGetApp().BombsFrame->SetClientSize(xmax, ymax);
}
void BombsFrameClass::OnAbout(wxCommandEvent& event)
{
wxMessageBox("wxBombs (c) 1996 by P. Foggia\n<foggia@amalfi.dis.unina.it>", "About wxBombs");
}
void BombsFrameClass::OnEasy(wxCommandEvent& event)
{
menuBar->Check(wxGetApp().level, FALSE);
wxGetApp().level=IDM_EASY;
menuBar->Check(wxGetApp().level, TRUE);
}
void BombsFrameClass::OnMedium(wxCommandEvent& event)
{
menuBar->Check(wxGetApp().level, FALSE);
wxGetApp().level=IDM_MEDIUM;
menuBar->Check(wxGetApp().level, TRUE);
}
void BombsFrameClass::OnDifficult(wxCommandEvent& event)
{
menuBar->Check(wxGetApp().level, FALSE);
wxGetApp().level=IDM_DIFFICULT;
menuBar->Check(wxGetApp().level, TRUE);
}
BEGIN_EVENT_TABLE(BombsCanvasClass, wxWindow)
EVT_PAINT(BombsCanvasClass::OnPaint)
EVT_MOUSE_EVENTS(BombsCanvasClass::OnEvent)
END_EVENT_TABLE()
BombsCanvasClass::BombsCanvasClass(wxFrame *parent, const wxPoint& pos, const wxSize& size, long style):
wxWindow(parent, -1, pos, size, style)
{
int sx, sy;
wxClientDC dc(this);
wxFont font= BOMBS_FONT;
dc.SetFont(font);
long chw, chh;
char buf[]="M";
dc.GetTextExtent(buf, &chw, &chh);
dc.SetFont(wxNullFont);
dc.SetMapMode(wxMM_METRIC);
int xcm = dc.LogicalToDeviceX(10.0);
int ycm = dc.LogicalToDeviceY(10.0);
// To have a square cell, there must be :
// sx*ycm == sy*xcm
if (chw*ycm < chh*xcm)
{ sy=chh;
sx=chh*xcm/ycm;
}
else
{ sx=chw;
sy=chw*ycm/xcm;
}
x_cell = (sx+3+X_UNIT)/X_UNIT;
y_cell = (sy+3+Y_UNIT)/Y_UNIT;
dc.SetMapMode(wxMM_TEXT);
bmp=NULL;
UpdateFieldSize();
}
BombsCanvasClass::~BombsCanvasClass(void)
{
if (bmp)
delete bmp;
}
// Called when canvas needs to be repainted.
void BombsCanvasClass::OnPaint(wxPaintEvent& event)
{
wxPaintDC dc(this);
// Insert your drawing code here.
if (!bmp)
{ bmp=new wxBitmap(field_width*x_cell*X_UNIT+1,
field_height*y_cell*Y_UNIT+1);
if (bmp)
{ wxMemoryDC memDC;
memDC.SelectObject(* bmp);
DrawField(&memDC, 0, 0, field_width-1, field_height-1);
memDC.SelectObject(wxNullBitmap);
}
}
if (bmp)
{ wxMemoryDC memDC;
memDC.SelectObject(* bmp);
dc.Blit(0, 0, field_width*x_cell*X_UNIT+1,
field_height*y_cell*Y_UNIT+1,
&memDC, 0, 0, wxCOPY);
memDC.SelectObject(wxNullBitmap);
}
else
DrawField(& dc, 0, 0, field_width-1, field_height-1);
}
// Updates the field size depending on wxGetApp().level and
// redraws the canvas
void BombsCanvasClass::UpdateFieldSize()
{ field_width=20;
field_height=20;
switch(wxGetApp().level)
{ case IDM_EASY:
field_width=10;
field_height=10;
break;
case IDM_MEDIUM:
field_width=15;
field_height=15;
break;
case IDM_DIFFICULT:
field_width=25;
field_height=20;
break;
}
wxGetApp().Game.Init(field_width, field_height);
if (bmp)
delete bmp;
bmp=NULL;
wxWindow::Refresh();
}

14
demos/bombs/bombs.def Normal file
View File

@@ -0,0 +1,14 @@
; bombs
; Generated by wxBuilder
;
NAME bombsapp
DESCRIPTION 'A wxWindows application'
;
EXETYPE WINDOWS
STUB 'WINSTUB.EXE'
;
CODE PRELOAD MOVEABLE DISCARDABLE
DATA PRELOAD MOVEABLE MULTIPLE
;
HEAPSIZE 1024
STACKSIZE 8192

119
demos/bombs/bombs.h Normal file
View File

@@ -0,0 +1,119 @@
///////////////////////////////////////////////////////////////////////////////
// Name: bombs.h
// Purpose: Bombs game
// Author: P. Foggia 1996
// Modified by:
// Created: 1996
// RCS-ID: $Id$
// Copyright: (c) 1996 P. Foggia
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _INC_BOMBS_H
#define _INC_BOMBS_H
#include "game.h"
/*
* Forward declarations of all top-level window classes.
*/
class BombsFrameClass;
class AboutFrameClass;
/*
* Class representing the entire Application
*/
class AppClass: public wxApp
{
public:
BombsFrameClass *BombsFrame;
int level;
BombsGame Game;
bool OnInit();
};
DECLARE_APP(AppClass)
class BombsCanvasClass;
class BombsFrameClass: public wxFrame
{
private:
protected:
public:
// Subwindows for reference within the program.
BombsCanvasClass *BombsCanvas;
wxMenuBar *menuBar;
// Constructor and destructor
BombsFrameClass(wxFrame *parent, const wxString& title, const wxPoint& pos, const wxSize& size, long style);
~BombsFrameClass(void);
void OnCloseWindow(wxCloseEvent& event);
void OnExit(wxCommandEvent& event);
void OnRestart(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
void OnEasy(wxCommandEvent& event);
void OnMedium(wxCommandEvent& event);
void OnDifficult(wxCommandEvent& event);
DECLARE_EVENT_TABLE()
};
/* Menu identifiers
*/
// File
#define BOMBSFRAMECLASS_FILE 1
// E&xit
#define IDM_EXIT 2
// About...
#define IDM_ABOUT 3
// Game
#define BOMBSFRAMECLASS_GAME 4
// &Restart
#define IDM_RESTART 5
// &Easy
#define IDM_EASY 6
// &Medium
#define IDM_MEDIUM 7
// &Difficult
#define IDM_DIFFICULT 8
class BombsCanvasClass: public wxWindow
{
private:
protected:
public:
int field_width, field_height;
int x_cell, y_cell;
wxBitmap *bmp;
// Constructor and destructor
BombsCanvasClass(wxFrame *parent, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0);
~BombsCanvasClass(void);
void OnPaint(wxPaintEvent& event);
void DrawField(wxDC *, int xc1, int yc1, int xc2, int yc2);
void Refresh(int xc1, int yc1, int xc2, int yc2);
void OnEvent(wxMouseEvent& event);
void UpdateFieldSize();
DECLARE_EVENT_TABLE()
};
/* Menu identifiers
*/
/* The following sizes should probably be redefined */
/* dimensions of a scroll unit, in pixels */
#define X_UNIT 4
#define Y_UNIT 4
/* the dimensions of a cell, in scroll units are in
* BombsCanvasClass::x_cell and y_cell
*/
#define BOMBS_FONT wxFont(14, wxROMAN, wxNORMAL, wxNORMAL)
#endif /* mutual exclusion */

BIN
demos/bombs/bombs.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 B

3
demos/bombs/bombs.rc Normal file
View File

@@ -0,0 +1,3 @@
bombs ICON "bombs.ico"
#include "wx/msw/wx.rc"

44
demos/bombs/bombs.xpm Normal file
View File

@@ -0,0 +1,44 @@
/* XPM */
static char *bombs_xpm[] = {
/* columns rows colors chars-per-pixel */
"32 32 6 1",
" c Black",
". c Blue",
"X c #00bf00",
"o c Red",
"O c Yellow",
"+ c Gray100",
/* pixels */
" ",
" oooooo +++++++++++++++++++++++ ",
" oooooo +++++++++++++++++++++++ ",
" oooooo +++++++++++++++++++++++ ",
" oooooo +++++++++++++++++++++++ ",
" oooooo +++++++++++++++++++++++ ",
" oooooo +++++++++++++++++++++++ ",
" oooooo +++++++++++++++++++++++ ",
" ",
" ++++++ ++++++++++++++++++ .... ",
" ++++++ ++++++++++++++++++ .... ",
" ++++++ ++++++++++++++++++ .... ",
" ++++++ ++++++++++++++++++ .... ",
" ++++++ ++++++++++++++++++ .... ",
" ++++++ ++++++++++++++++++ ",
" ++++++ ++++++++++++++++++ ++++ ",
" ++++++ ++++++++++++++++++ ++++ ",
" ++++++ ++++++++++++++++++ ++++ ",
" ++++++ ++++++++++++++++++ ++++ ",
" ++++++ ++++++++++++++++++ ++++ ",
" ++++++ ++++++++++++++++++ ++++ ",
" ++++++ ++++++++++++++++++ ++++ ",
" ++++++ ++++++++++++++++++ ++++ ",
" ++++++ ++++++++++++++++++ ++++ ",
" ++++++ ++++ ",
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
" "
};

204
demos/bombs/bombs1.cpp Normal file
View File

@@ -0,0 +1,204 @@
///////////////////////////////////////////////////////////////////////////////
// Name: bombs1.cpp
// Purpose: Bombs game
// Author: P. Foggia 1996
// Modified by:
// Created: 1996
// RCS-ID: $Id$
// Copyright: (c) 1996 P. Foggia
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
/*
* implementation of the methods DrawField and OnEvent of the
* class BombsCanvas
*/
#ifdef __GNUG__
#pragma implementation
#endif
#include "wx/wxprec.h"
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif //precompiled headers
#include "bombs.h"
/*-------- BombCanvasClass::DrawField(dc, xc1, yc1, xc2, yc2) -------*/
/* Draws the field on the device context dc */
/* xc1,yc1 etc. are the (inclusive) limits of the area to be drawn, */
/* expressed in cells. */
/*---------------------------------------------------------------------*/
void BombsCanvasClass::DrawField(wxDC *dc, int xc1, int yc1, int xc2, int yc2)
{ int x,y,xmax,ymax;
char buf[2];
long chw, chh;
wxColour *wxBlack = wxTheColourDatabase->FindColour("BLACK");
wxColour *wxWhite = wxTheColourDatabase->FindColour("WHITE");
wxColour *wxRed = wxTheColourDatabase->FindColour("RED");
wxColour *wxBlue = wxTheColourDatabase->FindColour("BLUE");
wxColour *wxGrey = wxTheColourDatabase->FindColour("LIGHT GREY");
wxColour *wxGreen = wxTheColourDatabase->FindColour("GREEN");
wxPen *blackPen = wxThePenList->FindOrCreatePen(*wxBlack, 1, wxSOLID);
wxPen *redPen = wxThePenList->FindOrCreatePen(*wxRed, 1, wxSOLID);
wxPen *bluePen = wxThePenList->FindOrCreatePen(*wxBlue, 1, wxSOLID);
wxBrush *whiteBrush = wxTheBrushList->FindOrCreateBrush(*wxWhite, wxSOLID);
wxBrush *greyBrush = wxTheBrushList->FindOrCreateBrush(*wxGrey, wxSOLID);
wxBrush *redBrush = wxTheBrushList->FindOrCreateBrush(*wxRed, wxSOLID);
xmax=field_width*x_cell*X_UNIT;
ymax=field_height*y_cell*Y_UNIT;
dc->SetPen(* blackPen);
for(x=xc1; x<=xc2; x++)
dc->DrawLine(x*x_cell*X_UNIT, 0, x*x_cell*X_UNIT, ymax);
for(y=xc1; y<=yc2; y++)
dc->DrawLine(0, y*y_cell*Y_UNIT, xmax, y*y_cell*Y_UNIT);
wxFont font= BOMBS_FONT;
dc->SetFont(font);
buf[1]='\0';
for(x=xc1; x<=xc2; x++)
for(y=yc1; y<=yc2; y++)
{ if (wxGetApp().Game.IsMarked(x,y))
{ dc->SetPen(* blackPen);
dc->SetBrush(* greyBrush);
dc->DrawRectangle( x*x_cell*X_UNIT, y*y_cell*Y_UNIT,
x_cell*X_UNIT+1, y_cell*Y_UNIT+1);
*buf='M';
if (!wxGetApp().Game.IsHidden(x,y) && wxGetApp().Game.IsBomb(x,y))
dc->SetTextForeground(*wxBlue);
else
dc->SetTextForeground(*wxRed);
dc->SetTextBackground(*wxGrey);
dc->GetTextExtent(buf, &chw, &chh);
dc->DrawText( buf,
x*x_cell*X_UNIT + (x_cell*X_UNIT-chw)/2,
y*y_cell*Y_UNIT + (y_cell*Y_UNIT-chh)/2
);
if (!wxGetApp().Game.IsHidden(x,y) && wxGetApp().Game.IsBomb(x,y))
{ dc->SetPen(*redPen);
dc->DrawLine(x*x_cell*X_UNIT, y*y_cell*Y_UNIT,
(x+1)*x_cell*X_UNIT, (y+1)*y_cell*Y_UNIT);
dc->DrawLine(x*x_cell*X_UNIT, (y+1)*y_cell*Y_UNIT,
(x+1)*x_cell*X_UNIT, y*y_cell*Y_UNIT);
}
}
else if (wxGetApp().Game.IsHidden(x,y))
{ dc->SetPen(*blackPen);
dc->SetBrush(*greyBrush);
dc->DrawRectangle( x*x_cell*X_UNIT, y*y_cell*Y_UNIT,
x_cell*X_UNIT+1, y_cell*Y_UNIT+1);
}
else if (wxGetApp().Game.IsBomb(x,y))
{ dc->SetPen(* blackPen);
dc->SetBrush(* redBrush);
dc->DrawRectangle( x*x_cell*X_UNIT, y*y_cell*Y_UNIT,
x_cell*X_UNIT+1, y_cell*Y_UNIT+1);
*buf='B';
dc->SetTextForeground(* wxBlack);
dc->SetTextBackground(* wxRed);
dc->GetTextExtent(buf, &chw, &chh);
dc->DrawText( buf,
x*x_cell*X_UNIT + (x_cell*X_UNIT-chw)/2,
y*y_cell*Y_UNIT + (y_cell*Y_UNIT-chh)/2
);
if (wxGetApp().Game.IsExploded(x,y))
{ dc->SetPen(* bluePen);
dc->DrawLine(x*x_cell*X_UNIT, y*y_cell*Y_UNIT,
(x+1)*x_cell*X_UNIT, (y+1)*y_cell*Y_UNIT);
dc->DrawLine(x*x_cell*X_UNIT, (y+1)*y_cell*Y_UNIT,
(x+1)*x_cell*X_UNIT, y*y_cell*Y_UNIT);
}
}
else // Display a digit
{ dc->SetPen(* blackPen);
dc->SetBrush(* whiteBrush);
dc->DrawRectangle( x*x_cell*X_UNIT, y*y_cell*Y_UNIT,
x_cell*X_UNIT+1, y_cell*Y_UNIT+1);
*buf = (wxGetApp().Game.Get(x,y) & BG_MASK) + '0';
dc->GetTextExtent(buf, &chw, &chh);
switch(*buf)
{ case '0': dc->SetTextForeground(* wxGreen); break;
case '1': dc->SetTextForeground(* wxBlue); break;
default: dc->SetTextForeground(* wxBlack); break;
}
dc->SetTextBackground(* wxWhite);
dc->DrawText( buf,
x*x_cell*X_UNIT + (x_cell*X_UNIT-chw)/2,
y*y_cell*Y_UNIT + (y_cell*Y_UNIT-chh)/2
);
}
}
dc->SetFont(wxNullFont);
if (wxGetApp().BombsFrame)
{ char buf[80];
sprintf(buf, "%d bombs %d remaining cells",
wxGetApp().Game.GetBombs(), wxGetApp().Game.GetRemainingCells());
wxGetApp().BombsFrame->SetStatusText(buf, 0);
}
}
/*-------- BombCanvasClass::Refresh(xc1, yc1, xc2, yc2) -------------*/
/* Refreshes the field image */
/* xc1,yc1 etc. are the (inclusive) limits of the area to be drawn, */
/* expressed in cells. */
/*---------------------------------------------------------------------*/
void BombsCanvasClass::Refresh(int xc1, int yc1, int xc2, int yc2)
{
wxClientDC dc(this);
DrawField(& dc, xc1, yc1, xc2, yc2);
if (bmp)
{ wxMemoryDC memDC;
memDC.SelectObject(* bmp);
DrawField(&memDC, xc1, yc1, xc2, yc2);
memDC.SelectObject(wxNullBitmap);
}
}
// Called when the canvas receives a mouse event.
void BombsCanvasClass::OnEvent(wxMouseEvent& event)
{
wxCoord fx, fy;
event.GetPosition(&fx, &fy);
int x = fx/(x_cell*X_UNIT);
int y = fy/(y_cell*Y_UNIT);
if (x<field_width && y<field_height)
{ if ( (event.RightDown() || (event.LeftDown() && event.ShiftDown()))
&& (wxGetApp().Game.IsHidden(x,y)
|| wxGetApp().Game.GetRemainingCells()==0))
{ wxGetApp().Game.Mark(x,y);
Refresh(x, y, x, y);
return;
}
else if (event.LeftDown() && wxGetApp().Game.IsHidden(x,y)
&& !wxGetApp().Game.IsMarked(x,y))
{ wxGetApp().Game.Unhide(x,y);
Refresh(x, y, x, y);
if (wxGetApp().Game.IsBomb(x,y) || wxGetApp().Game.GetRemainingCells()==0)
{ wxBell();
if (!wxGetApp().Game.IsBomb(x,y))
{ wxMessageBox("Nice! You found all the bombs!", "wxWin Bombs",
wxOK|wxCENTRE, wxGetApp().BombsFrame);
}
else // x,y is a bomb
{ wxGetApp().Game.Explode(x, y);
}
for(x=0; x<field_width; x++)
for(y=0; y<field_height; y++)
wxGetApp().Game.Unhide(x,y);
Refresh(0, 0, field_width-1, field_height-1);
}
return;
}
}
}

32
demos/bombs/descrip.mms Normal file
View File

@@ -0,0 +1,32 @@
#*****************************************************************************
# *
# Make file for VMS *
# Author : J.Jansen (joukj@hrem.stm.tudelft.nl) *
# Date : 10 November 1999 *
# *
#*****************************************************************************
.first
define wx [--.include.wx]
.ifdef __WXMOTIF__
CXX_DEFINE = /define=(__WXMOTIF__=1)
.else
CXX_DEFINE =
.endif
.suffixes : .cpp
.cpp.obj :
cxx $(CXXFLAGS)$(CXX_DEFINE) $(MMS$TARGET_NAME).cpp
all :
$(MMS)$(MMSQUALIFIERS) game.exe
game.exe : game.obj bombs1.obj bombs.obj
.ifdef __WXMOTIF__
cxxlink game,bombs1,bombs,[--.lib]vms/opt
.endif
game.obj : game.cpp
bombs1.obj : bombs1.cpp
bombs.obj : bombs.cpp

105
demos/bombs/game.cpp Normal file
View File

@@ -0,0 +1,105 @@
///////////////////////////////////////////////////////////////////////////////
// Name: bombs1.cpp
// Purpose: Implementation of the class BombsGame
// Author: P. Foggia 1996
// Modified by:
// Created: 1996
// RCS-ID: $Id$
// Copyright: (c) 1996 P. Foggia
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation
#endif
#include "wx/wxprec.h"
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif //precompiled headers
#include "game.h"
#include <stdlib.h>
#include <limits.h>
#define PROB 0.2
#ifndef RAND_MAX
#define RAND_MAX INT_MAX
#endif
/*-------------------- BombsGame::~BombsGame() ---------------------*/
/*--------------------------------------------------------------------*/
BombsGame::~BombsGame()
{ if (field)
free(field);
}
/*------------------ int BombsGame::Init(width,height) -------------------*/
/* Initialize the play field. Returns 0 on failure */
/*--------------------------------------------------------------------------*/
int BombsGame::Init(int aWidth, int aHeight)
{ int x, y;
int xx, yy;
if (field)
free(field);
field=(short *)malloc(aWidth*aHeight*sizeof(short));
if (!field)
{ width=height=0;
return 0;
}
width=aWidth;
height=aHeight;
for(x=0; x<width; x++)
for(y=0; y<height; y++)
{ field[x+y*width] = ((float)rand()/RAND_MAX <PROB)?
BG_HIDDEN | BG_BOMB :
BG_HIDDEN;
}
bombs=0;
for(x=0; x<width; x++)
for(y=0; y<height; y++)
if (field[x+y*width] & BG_BOMB)
{ bombs++;
for(xx=x-1; xx<=x+1; xx++)
if (xx>=0 && xx<width)
for(yy=y-1; yy<=y+1; yy++)
if (yy>=0 && yy<height && (yy!=y || xx!=x))
field[xx+yy*width]++;
}
normal_cells=height*width-bombs;
return 1;
}
/*---------------------- BombsGame::Mark(x,y) -------------------------*/
/* Marks/unmarks a cell */
/*-----------------------------------------------------------------------*/
void BombsGame::Mark(int x, int y)
{
field[x+y*width] ^= BG_MARKED;
}
/*------------------- BombsGame::Unhide(x,y) ------------------------*/
/* Unhides a cell */
/*---------------------------------------------------------------------*/
void BombsGame::Unhide(int x, int y)
{ if (!IsHidden(x,y))
return;
field[x+y*width] &= ~BG_HIDDEN;
if (!IsBomb(x,y))
normal_cells--;
}
/*------------------- BombsGame::Explode(x,y) ------------------------*/
/* Makes a cell exploded */
/*----------------------------------------------------------------------*/
void BombsGame::Explode(int x, int y)
{
field[x+y*width] |= BG_EXPLODED;
}

42
demos/bombs/game.h Normal file
View File

@@ -0,0 +1,42 @@
//---------------------------------------------------------------
// game.h
// Definition of the class BombsGame, containing the data for a
// playfield
//---------------------------------------------------------------
#ifndef GAME_H
#define GAME_H
#define BG_HIDDEN 0x100
#define BG_BOMB 0x200
#define BG_MARKED 0x400
#define BG_EXPLODED 0x800
#define BG_MASK 0x0FF
#include <stddef.h>
class BombsGame
{ protected:
int width,height;
short *field;
int bombs,normal_cells;
public:
BombsGame() { width=height=0; field=NULL; };
~BombsGame();
int Init(int width, int height);
int GetWidth() { return width; };
int GetHeight() { return height; };
int Get(int x, int y) { return field[x+y*width]; };
void Mark(int x, int y);
void Unhide(int x, int y);
void Explode(int x, int y);
int IsHidden(int x, int y) { return Get(x,y) & BG_HIDDEN; };
int IsMarked(int x, int y) { return Get(x,y) & BG_MARKED; };
int IsBomb(int x, int y) { return Get(x,y) & BG_BOMB; };
int IsExploded(int x, int y) { return Get(x,y) & BG_EXPLODED; };
int GetBombs() { return bombs; };
int GetRemainingCells() { return normal_cells; };
};
#endif /* def GAME_H */

16
demos/bombs/makefile.b32 Normal file
View File

@@ -0,0 +1,16 @@
#
# File: makefile.b32
# Author: Julian Smart
# Created: 1999
# Updated:
# Copyright:
#
# Makefile : Builds sample for 32-bit BC++
WXDIR = $(WXWIN)
TARGET=bombs
OBJECTS = $(TARGET).obj bombs1.obj game.obj
!include $(WXDIR)\src\makeprog.b32

19
demos/bombs/makefile.bcc Normal file
View File

@@ -0,0 +1,19 @@
#
# File: makefile.bcc
# Author: Julian Smart
# Created: 1998
# Updated:
#
# Builds a BC++ 16-bit sample
!if "$(WXWIN)" == ""
!error You must define the WXWIN variable in autoexec.bat, e.g. WXWIN=c:\wx
!endif
WXDIR = $(WXWIN)
TARGET=bombs
OBJECTS=$(TARGET).obj bombs1.obj game.obj
!include $(WXDIR)\src\makeprog.bcc

17
demos/bombs/makefile.dos Normal file
View File

@@ -0,0 +1,17 @@
#
# File: makefile.dos
# Author: Julian Smart
# Created: 1998
# Updated:
#
# Makefile : Builds 16-bit sample, VC++ 1.5
# Use FINAL=1 argument to nmake to build final version with no debugging
# info
WXDIR = $(WXWIN)
TARGET=bombs
OBJECTS = $(TARGET).obj bombs1.obj game.obj
!include $(WXDIR)\src\makeprog.msc

16
demos/bombs/makefile.g95 Normal file
View File

@@ -0,0 +1,16 @@
#
# File: makefile.g95
# Author: Julian Smart
# Created: 1999
# Updated:
# Copyright: (c) Julian Smart, 1999
#
# Makefile for wxWindows sample (Cygwin/Mingw32).
WXDIR = ../..
TARGET=bombs
OBJECTS = $(TARGET).o bombs1.o game.o
include $(WXDIR)/src/makeprog.g95

35
demos/bombs/makefile.unx Normal file
View File

@@ -0,0 +1,35 @@
#
# File: Makefile for samples
# Author: Robert Roebling
# Created: 1999
# Updated:
# Copyright: (c) 1998 Robert Roebling
#
# This makefile requires a Unix version of wxWindows
# to be installed on your system. This is most often
# done typing "make install" when using the complete
# sources of wxWindows or by installing the two
# RPM packages wxGTK.XXX.rpm and wxGTK-devel.XXX.rpm
# under Linux.
#
CC = gcc
PROGRAM = bombs
OBJECTS = $(PROGRAM).o game.o bombs1.o
# implementation
.SUFFIXES: .o .cpp
.cpp.o :
$(CC) -c `wx-config --cflags` -o $@ $<
all: $(PROGRAM)
$(PROGRAM): $(OBJECTS)
$(CC) -o $(PROGRAM) $(OBJECTS) `wx-config --libs`
clean:
rm -f *.o $(PROGRAM)

18
demos/bombs/makefile.vc Normal file
View File

@@ -0,0 +1,18 @@
#
# File: makefile.vc
# Author: Julian Smart
# Created: 1999
# Updated:
# Copyright: (c) Julian Smart
#
# Makefile : Builds sample (VC++, WIN32)
# Use FINAL=1 argument to nmake to build final version with no debug info.
# Set WXDIR for your system
WXDIR = $(WXWIN)
PROGRAM=bombs
OBJECTS = $(PROGRAM).obj bombs1.obj game.obj
!include $(WXDIR)\src\makeprog.vc

15
demos/bombs/makefile.wat Normal file
View File

@@ -0,0 +1,15 @@
#
# Makefile for WATCOM
#
# Created by Julian Smart, January 1999
#
#
WXDIR = $(%WXWIN)
PROGRAM = bombs
OBJECTS = $(PROGRAM).obj bombs1.obj game.obj
!include $(WXDIR)\src\makeprog.wat

78
demos/bombs/readme.txt Normal file
View File

@@ -0,0 +1,78 @@
wxWin Bombs
by Pasquale Foggia
1. The aim of the program
wxWin Bombs is the wxWin implementation of the minesweeper game you find
under MSWindows 3.1+. Later the rules of the game will be explained for
the lucky ones of you that have never used Windows.
2. Installation
If you are reading this file, I suppose you have succesfully unpacked the
files in a directory of your hard disk :-). You should already have
installed wxWin on your system.
Now you have to modify makefile.bcc
(if a Windows user) or makefile.unx (if you use a real OS) setting the
proper values for the directories. Finally, you have to run:
make -f makefile.bcc
for Windows (nmake if you use a MicroSoft compiler), or:
make -f makefile.unx xview
for Unix+xview and
make -f makefile.unx motif
for Unix+motif
If you are lucky, you will find the bombs executable, ready to be run.
3. Test
Bombs has been tested under the following platforms:
PC + MSWindos 3.1 + wxWin 1.60 + Borland C 3.1
Sun SPARCstation 20 + SunOS + xview + wxWin 1.63 + gcc 2.3.3
and all seems to work fine.
4. The author
This program has been developed by Pasquale Foggia, a PhD student
in Computer Engineering at the "Federico II" University of Naples, Italy.
You can contacting him using the following address:
foggia@amalfi.dis.unina.it
5. Disclaimer
This program is freeware. You can do everything you want with it, including
copying and modifying, without the need of a permission from the author.
On the other hand, this program is provided AS IS, with NO KIND OF WARRANTY.
The author will be in NO CASE responsible for damages directly or indirectly
caused by this program. Use it AT YOUR OWN RISK, or don't use it at all.
6. The rules of the game
Your aim is to discover all the bombs in a mined field. If you click with
the left mouse button on a cell containing a bomb, your game ends.
Otherwise, the number of bombs in the 8 neighbour cells will be displayed.
When you have clicked all the cells without a bomb, you win.
You can also use the right button (or left button+shift) to mark a cell
you think hides a bomb, in order to not click it accidentally.
7. Concluding remarks
I hope someone of you will enjoy this program. However, I enjoyed writing
it (thanks to Julian Smart and all the other wxWin developers).
In the near future I plan to implement under wxWin the great 'empire'
(is there someone that still remember it?), IMHO one of the most addictive
strategy games. If someone is interested, please contact me by e-mail.
I beg you pardon for my approximative english.
Pasquale Foggia
foggia@amalfi.dis.unina.it
------
A note from Julian Smart: Many thanks to Pasquale for the contribution.
I've taken the liberty of making a few changes.
1) I've made the status line have a single field so that you
can see the 'cells remaining' message properly.
2) I've changed the title from "wxWin Bombs" (which, as a statement,
is an unfortunate reflection of the reality of earlier versions of
wxWindows :-)) to wxBombs.
3) Added SetClientData to resize the window on Restart; eliminated
scrollbars; made the frame unresizeable.
4) Added makefile.dos for VC++ 1.x, makefile.wat for Watcom C++.

1
demos/forty/.cvsignore Normal file
View File

@@ -0,0 +1 @@

21
demos/forty/Makefile.in Normal file
View File

@@ -0,0 +1,21 @@
#
# File: Makefile.in
# Author: Julian Smart
# Created: 1998
# Updated:
# Copyright: (c) 1998 Julian Smart
#
# "%W% %G%"
#
# Makefile for forty example (UNIX).
top_srcdir = @top_srcdir@
top_builddir = ../..
program_dir = demos/forty
PROGRAM=forty
OBJECTS=$(PROGRAM).o canvas.o card.o game.o pile.o playerdg.o scoredg.o scorefil.o
include ../../src/makeprog.env

253
demos/forty/canvas.cpp Normal file
View File

@@ -0,0 +1,253 @@
/////////////////////////////////////////////////////////////////////////////
// Name: canvas.cpp
// Purpose: Forty Thieves patience game
// Author: Chris Breeze
// Modified by:
// Created: 21/07/97
// RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze
// Licence: wxWindows licence
//---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWindows 2.0
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation
#pragma interface
#endif
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include "forty.h"
#include "card.h"
#include "game.h"
#include "scorefil.h"
#include "playerdg.h"
#include "canvas.h"
BEGIN_EVENT_TABLE(FortyCanvas, wxScrolledWindow)
EVT_MOUSE_EVENTS(FortyCanvas::OnMouseEvent)
END_EVENT_TABLE()
FortyCanvas::FortyCanvas(wxWindow* parent, int x, int y, int w, int h) :
wxScrolledWindow(parent, -1, wxPoint(x, y), wxSize(w, h)),
m_helpingHand(TRUE),
m_rightBtnUndo(TRUE),
m_playerDialog(0),
m_leftBtnDown(FALSE)
{
#ifdef __WXGTK__
m_font = wxTheFontList->FindOrCreateFont(12, wxROMAN, wxNORMAL, wxNORMAL);
#else
m_font = wxTheFontList->FindOrCreateFont(10, wxSWISS, wxNORMAL, wxNORMAL);
#endif
SetBackgroundColour(FortyApp::BackgroundColour());
m_handCursor = new wxCursor(wxCURSOR_HAND);
m_arrowCursor = new wxCursor(wxCURSOR_ARROW);
wxString name = wxTheApp->GetAppName();
if (name.Length() <= 0) name = "forty";
m_scoreFile = new ScoreFile(name);
m_game = new Game(0, 0, 0);
m_game->Deal();
}
FortyCanvas::~FortyCanvas()
{
UpdateScores();
delete m_game;
delete m_scoreFile;
}
/*
Write the current player's score back to the score file
*/
void FortyCanvas::UpdateScores()
{
if (m_player.Length() > 0 && m_scoreFile && m_game)
{
m_scoreFile->WritePlayersScore(
m_player,
m_game->GetNumWins(),
m_game->GetNumGames(),
m_game->GetScore()
);
}
}
void FortyCanvas::OnDraw(wxDC& dc)
{
dc.SetFont(* m_font);
m_game->Redraw(dc);
// if player name not set (and selection dialog is not displayed)
// then ask the player for their name
if (m_player.Length() == 0 && !m_playerDialog)
{
m_playerDialog = new PlayerSelectionDialog(this, m_scoreFile);
m_playerDialog->ShowModal();
m_player = m_playerDialog->GetPlayersName();
if (m_player.Length() > 0)
{
// user entered a name - lookup their score
int wins, games, score;
m_scoreFile->ReadPlayersScore(m_player, wins, games, score);
m_game->NewPlayer(wins, games, score);
m_game->DisplayScore(dc);
m_playerDialog->Destroy();
m_playerDialog = 0;
Refresh();
}
else
{
// user cancelled the dialog - exit the app
((wxFrame*)GetParent())->Close(TRUE);
}
}
}
/*
Called when the main frame is closed
*/
bool FortyCanvas::OnCloseCanvas()
{
if (m_game->InPlay() &&
wxMessageBox("Are you sure you want to\nabandon the current game?",
"Warning", wxYES_NO | wxICON_QUESTION) == wxNO)
{
return FALSE;
}
return TRUE;
}
void FortyCanvas::OnMouseEvent(wxMouseEvent& event)
{
int mouseX = (int)event.GetX();
int mouseY = (int)event.GetY();
wxClientDC dc(this);
PrepareDC(dc);
dc.SetFont(* m_font);
if (event.LeftDClick())
{
if (m_leftBtnDown)
{
m_leftBtnDown = FALSE;
ReleaseMouse();
m_game->LButtonUp(dc, mouseX, mouseY);
}
m_game->LButtonDblClk(dc, mouseX, mouseY);
}
else if (event.LeftDown())
{
if (!m_leftBtnDown)
{
m_leftBtnDown = TRUE;
CaptureMouse();
m_game->LButtonDown(dc, mouseX, mouseY);
}
}
else if (event.LeftUp())
{
if (m_leftBtnDown)
{
m_leftBtnDown = FALSE;
ReleaseMouse();
m_game->LButtonUp(dc, mouseX, mouseY);
}
}
else if (event.RightDown() && !event.LeftIsDown())
{
// only allow right button undo if m_rightBtnUndo is TRUE
if (m_rightBtnUndo)
{
if (event.ControlDown() || event.ShiftDown())
{
m_game->Redo(dc);
}
else
{
m_game->Undo(dc);
}
}
}
else if (event.Dragging())
{
m_game->MouseMove(dc, mouseX, mouseY);
}
if (!event.LeftIsDown())
{
SetCursorStyle(mouseX, mouseY);
}
}
void FortyCanvas::SetCursorStyle(int x, int y)
{
if (m_game->HaveYouWon())
{
if (wxMessageBox("Do you wish to play again?",
"Well Done, You have won!", wxYES_NO | wxICON_QUESTION) == wxYES)
{
m_game->Deal();
wxClientDC dc(this);
PrepareDC(dc);
dc.SetFont(* m_font);
m_game->Redraw(dc);
}
else
{
// user cancelled the dialog - exit the app
((wxFrame*)GetParent())->Close(TRUE);
}
}
// Only set cursor to a hand if 'helping hand' is enabled and
// the card under the cursor can go somewhere
if (m_game->CanYouGo(x, y) && m_helpingHand)
{
SetCursor(* m_handCursor);
}
else
{
SetCursor(* m_arrowCursor);
}
}
void FortyCanvas::NewGame()
{
m_game->Deal();
Refresh();
}
void FortyCanvas::Undo()
{
wxClientDC dc(this);
PrepareDC(dc);
dc.SetFont(* m_font);
m_game->Undo(dc);
}
void FortyCanvas::Redo()
{
wxClientDC dc(this);
PrepareDC(dc);
dc.SetFont(* m_font);
m_game->Redo(dc);
}

56
demos/forty/canvas.h Normal file
View File

@@ -0,0 +1,56 @@
/////////////////////////////////////////////////////////////////////////////
// Name: canvas.h
// Purpose: Forty Thieves patience game
// Author: Chris Breeze
// Modified by:
// Created: 21/07/97
// RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze
// Licence: wxWindows licence
//---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWindows 2.0
/////////////////////////////////////////////////////////////////////////////
#ifndef _CANVAS_H_
#define _CANVAS_H_
class Card;
class Game;
class ScoreFile;
class PlayerSelectionDialog;
class FortyCanvas: public wxScrolledWindow
{
public:
FortyCanvas(wxWindow* parent, int x, int y, int w, int h);
virtual ~FortyCanvas();
virtual void OnDraw(wxDC& dc);
bool OnCloseCanvas();
void OnMouseEvent(wxMouseEvent& event);
void SetCursorStyle(int x, int y);
void NewGame();
void Undo();
void Redo();
ScoreFile* GetScoreFile() const { return m_scoreFile; }
void UpdateScores();
void EnableHelpingHand(bool enable) { m_helpingHand = enable; }
void EnableRightButtonUndo(bool enable) { m_rightBtnUndo = enable; }
DECLARE_EVENT_TABLE()
private:
wxFont* m_font;
Game* m_game;
ScoreFile* m_scoreFile;
wxCursor* m_arrowCursor;
wxCursor* m_handCursor;
bool m_helpingHand;
bool m_rightBtnUndo;
wxString m_player;
PlayerSelectionDialog* m_playerDialog;
bool m_leftBtnDown;
};
#endif

358
demos/forty/card.cpp Normal file
View File

@@ -0,0 +1,358 @@
/////////////////////////////////////////////////////////////////////////////
// Name: card.cpp
// Purpose: Forty Thieves patience game
// Author: Chris Breeze
// Modified by:
// Created: 21/07/97
// RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze
// Licence: wxWindows licence
//---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWindows 2.0
/////////////////////////////////////////////////////////////////////////////
//+-------------------------------------------------------------+
//| Description
//| A class for drawing playing cards.
//| Currently assumes that the card symbols have been
//| loaded into hbmap_symbols and the pictures for the
//| Jack, Queen and King have been loaded into
//| hbmap_pictures.
//+-------------------------------------------------------------+
#ifdef __GNUG__
#pragma implementation
#pragma interface
#endif
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "forty.h"
#include "card.h"
#if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__)
#include "pictures.xpm"
#include "symbols.xbm"
#endif
wxBitmap* Card::m_pictureBmap = 0;
wxBitmap* Card::m_symbolBmap = 0;
//+-------------------------------------------------------------+
//| Card::Card() |
//+-------------------------------------------------------------+
//| Description: |
//| Constructor for a playing card. |
//| Checks that the value is in the range 1..52 and then |
//| initialises the suit, colour, pipValue and wayUp. |
//+-------------------------------------------------------------+
Card::Card(int value, WayUp way_up) :
m_wayUp(way_up)
{
if (!m_symbolBmap)
{
#ifdef __WXMSW__
m_symbolBmap = new wxBitmap("CardSymbols", wxBITMAP_TYPE_BMP_RESOURCE);
#else
m_symbolBmap = new wxBitmap(Symbols_bits, Symbols_width, Symbols_height);
#endif
if (!m_symbolBmap->Ok())
{
::wxMessageBox("Failed to load bitmap CardSymbols", "Error");
}
}
if (!m_pictureBmap)
{
#ifdef __WXMSW__
m_pictureBmap = new wxBitmap("CardPictures", wxBITMAP_TYPE_BMP_RESOURCE);
#else
m_pictureBmap = new wxBitmap(Pictures);
#endif
if (!m_pictureBmap->Ok())
{
::wxMessageBox("Failed to load bitmap CardPictures", "Error");
}
}
if (value >= 1 && value <= PackSize)
{
switch ((value - 1) / 13)
{
case 0:
m_suit = clubs;
m_colour = black;
break;
case 1:
m_suit = diamonds;
m_colour = red;
break;
case 2:
m_suit = hearts;
m_colour = red;
break;
case 3:
m_suit = spades;
m_colour = black;
break;
}
m_pipValue = 1 + (value - 1) % 13;
m_status = TRUE;
}
else
{
m_status = FALSE;
}
} // Card::Card()
//+-------------------------------------------------------------+
//| Card::~Card() |
//+-------------------------------------------------------------+
//| Description: |
//| Destructor - nothing to do at present. |
//+-------------------------------------------------------------+
Card::~Card()
{
}
//+-------------------------------------------------------------+
//| Card::Erase() |
//+-------------------------------------------------------------+
//| Description: |
//| Erase the card at (x, y) by drawing a rectangle in the |
//| background colour. |
//+-------------------------------------------------------------+
void Card::Erase(wxDC& dc, int x, int y)
{
wxPen* pen = wxThePenList->FindOrCreatePen(
FortyApp::BackgroundColour(),
1,
wxSOLID
);
dc.SetPen(* pen);
dc.SetBrush(FortyApp::BackgroundBrush());
dc.DrawRectangle(x, y, CardWidth, CardHeight);
} // Card::Erase()
//+-------------------------------------------------------------+
//| Card::Draw() |
//+-------------------------------------------------------------+
//| Description: |
//| Draw the card at (x, y). |
//| If the card is facedown draw the back of the card. |
//| If the card is faceup draw the front of the card. |
//| Cards are not held in bitmaps, instead they are drawn |
//| from their constituent parts when required. |
//| hbmap_symbols contains large and small suit symbols and |
//| pip values. These are copied to the appropriate part of |
//| the card. Picture cards use the pictures defined in |
//| hbmap_pictures. Note that only one picture is defined |
//| for the Jack, Queen and King, unlike a real pack where |
//| each suit is different. |
//| |
//| WARNING: |
//| The locations of these symbols is 'hard-wired' into the |
//| code. Editing the bitmaps or the numbers below will |
//| result in the wrong symbols being displayed. |
//+-------------------------------------------------------------+
void Card::Draw(wxDC& dc, int x, int y)
{
wxBrush backgroundBrush( dc.GetBackground() );
dc.SetBrush(* wxWHITE_BRUSH);
dc.SetPen(* wxBLACK_PEN);
dc.DrawRoundedRectangle(x, y, CardWidth, CardHeight, 4);
if (m_wayUp == facedown)
{
dc.SetBackground(* wxRED_BRUSH);
dc.SetBackgroundMode(wxSOLID);
wxBrush* brush = wxTheBrushList->FindOrCreateBrush(
"BLACK", wxCROSSDIAG_HATCH
);
dc.SetBrush(* brush);
dc.DrawRoundedRectangle(
x + 4, y + 4,
CardWidth - 8, CardHeight - 8,
2
);
}
else
{
wxMemoryDC memoryDC;
memoryDC.SelectObject(* m_symbolBmap);
// dc.SetBackgroundMode(wxTRANSPARENT);
dc.SetTextBackground(*wxWHITE);
switch (m_suit)
{
case spades:
case clubs:
dc.SetTextForeground(*wxBLACK);
break;
case diamonds:
case hearts:
dc.SetTextForeground(*wxRED);
break;
}
// Draw the value
dc.Blit(x + 3, y + 3, 6, 7,
&memoryDC, 6 * (m_pipValue - 1), 36, wxCOPY);
dc.Blit(x + CardWidth - 9, y + CardHeight - 11, 6, 7,
&memoryDC, 6 * (m_pipValue - 1), 43, wxCOPY);
// Draw the pips
dc.Blit(x + 11, y + 3, 7, 7,
&memoryDC, 7 * m_suit, 0, wxCOPY);
dc.Blit(x + CardWidth - 17, y + CardHeight - 11, 7, 7,
&memoryDC, 7 * m_suit, 7, wxCOPY);
switch (m_pipValue)
{
case 1:
dc.Blit(x - 5 + CardWidth / 2, y - 5 + CardHeight / 2, 11, 11,
&memoryDC, 11 * m_suit, 14, wxCOPY);
break;
case 3:
dc.Blit(x - 5 + CardWidth / 2, y - 5 + CardHeight / 2, 11, 11,
&memoryDC, 11 * m_suit, 14, wxCOPY);
case 2:
dc.Blit(x - 5 + CardWidth / 2,
y - 5 + CardHeight / 4, 11, 11,
&memoryDC, 11 * m_suit, 14, wxCOPY);
dc.Blit(x - 5 + CardWidth / 2,
y - 5 + 3 * CardHeight / 4, 11, 11,
&memoryDC, 11 * m_suit, 25, wxCOPY);
break;
case 5:
dc.Blit(x - 5 + CardWidth / 2, y - 5 + CardHeight / 2, 11, 11,
&memoryDC, 11 * m_suit, 14, wxCOPY);
case 4:
dc.Blit(x - 5 + CardWidth / 4,
y - 5 + CardHeight / 4, 11, 11,
&memoryDC, 11 * m_suit, 14, wxCOPY);
dc.Blit(x - 5 + CardWidth / 4,
y - 5 + 3 * CardHeight / 4, 11, 11,
&memoryDC, 11 * m_suit, 25, wxCOPY);
dc.Blit(x - 5 + 3 * CardWidth / 4,
y - 5 + CardHeight / 4, 11, 11,
&memoryDC, 11 * m_suit, 14, wxCOPY);
dc.Blit(x - 5 + 3 * CardWidth / 4,
y - 5 + 3 * CardHeight / 4, 11, 11,
&memoryDC, 11 * m_suit, 25, wxCOPY);
break;
case 8:
dc.Blit(x - 5 + 5 * CardWidth / 10,
y - 5 + 5 * CardHeight / 8, 11, 11,
&memoryDC, 11 * m_suit, 25, wxCOPY);
case 7:
dc.Blit(x - 5 + 5 * CardWidth / 10,
y - 5 + 3 * CardHeight / 8, 11, 11,
&memoryDC, 11 * m_suit, 14, wxCOPY);
case 6:
dc.Blit(x - 5 + CardWidth / 4,
y - 5 + CardHeight / 4, 11, 11,
&memoryDC, 11 * m_suit, 14, wxCOPY);
dc.Blit(x - 5 + CardWidth / 4,
y - 5 + CardHeight / 2, 11, 11,
&memoryDC, 11 * m_suit, 14, wxCOPY);
dc.Blit(x - 5 + CardWidth / 4,
y - 5 + 3 * CardHeight / 4, 11, 11,
&memoryDC, 11 * m_suit, 25, wxCOPY);
dc.Blit(x - 5 + 3 * CardWidth / 4,
y - 5 + CardHeight / 4, 11, 11,
&memoryDC, 11 * m_suit, 14, wxCOPY);
dc.Blit(x - 5 + 3 * CardWidth / 4,
y - 5 + CardHeight / 2, 11, 11,
&memoryDC, 11 * m_suit, 14, wxCOPY);
dc.Blit(x - 5 + 3 * CardWidth / 4,
y - 5 + 3 * CardHeight / 4, 11, 11,
&memoryDC, 11 * m_suit, 25, wxCOPY);
break;
case 10:
dc.Blit(x - 5 + CardWidth / 2,
y - 5 + 2 * CardHeight / 3, 11, 11,
&memoryDC, 11 * m_suit, 25, wxCOPY);
case 9:
dc.Blit(x - 5 + CardWidth / 4,
y - 6 + CardHeight / 4, 11, 11,
&memoryDC, 11 * m_suit, 14, wxCOPY);
dc.Blit(x - 5 + CardWidth / 4,
y - 6 + 5 * CardHeight / 12, 11, 11,
&memoryDC, 11 * m_suit, 14, wxCOPY);
dc.Blit(x - 5 + CardWidth / 4,
y - 5 + 7 * CardHeight / 12, 11, 11,
&memoryDC, 11 * m_suit, 25, wxCOPY);
dc.Blit(x - 5 + CardWidth / 4,
y - 5 + 3 * CardHeight / 4, 11, 11,
&memoryDC, 11 * m_suit, 25, wxCOPY);
dc.Blit(x - 5 + 3 * CardWidth / 4,
y - 6 + CardHeight / 4, 11, 11,
&memoryDC, 11 * m_suit, 14, wxCOPY);
dc.Blit(x - 5 + 3 * CardWidth / 4,
y - 6 + 5 * CardHeight / 12, 11, 11,
&memoryDC, 11 * m_suit, 14, wxCOPY);
dc.Blit(x - 5 + 3 * CardWidth / 4,
y - 5 + 7 * CardHeight / 12, 11, 11,
&memoryDC, 11 * m_suit, 25, wxCOPY);
dc.Blit(x - 5 + 3 * CardWidth / 4,
y - 5 + 3 * CardHeight / 4, 11, 11,
&memoryDC, 11 * m_suit, 25, wxCOPY);
dc.Blit(x - 5 + CardWidth / 2,
y - 5 + CardHeight / 3, 11, 11,
&memoryDC, 11 * m_suit, 14, wxCOPY);
break;
case 11:
case 12:
case 13:
memoryDC.SelectObject(* m_pictureBmap);
dc.Blit(x + 5, y - 5 + CardHeight / 4, 40, 45,
&memoryDC, 40 * (m_pipValue - 11), 0, wxCOPY);
memoryDC.SelectObject(* m_symbolBmap);
dc.Blit(x + 32, y - 3 + CardHeight / 4, 11, 11,
&memoryDC, 11 * m_suit, 14, wxCOPY);
dc.Blit(x + 7, y + 27 + CardHeight / 4, 11, 11,
&memoryDC, 11 * m_suit, 25, wxCOPY);
break;
}
}
dc.SetBackground( backgroundBrush );
} // Card:Draw()
//+-------------------------------------------------------------+
//| Card::DrawNullCard() |
//+-------------------------------------------------------------+
//| Description: |
//| Draws the outline of a card at (x, y). |
//| Used to draw place holders for empty piles of cards. |
//+-------------------------------------------------------------+
void Card::DrawNullCard(wxDC& dc, int x, int y)
{
wxPen* pen = wxThePenList->FindOrCreatePen(FortyApp::TextColour(), 1, wxSOLID);
dc.SetBrush(FortyApp::BackgroundBrush());
dc.SetPen(*pen);
dc.DrawRoundedRectangle(x, y, CardWidth, CardHeight, 4);
} // Card::DrawNullCard()

65
demos/forty/card.h Normal file
View File

@@ -0,0 +1,65 @@
/////////////////////////////////////////////////////////////////////////////
// Name: card.h
// Purpose: Forty Thieves patience game
// Author: Chris Breeze
// Modified by:
// Created: 21/07/97
// RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze
// Licence: wxWindows licence
//---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWindows 2.0
/////////////////////////////////////////////////////////////////////////////
//+-------------------------------------------------------------+
//| Description: |
//| A class for drawing playing cards. |
//| InitCards() must be called before using the Card class, |
//| otherwise the card bitmaps will not be loaded. |
//| CloseCards() must be called before terminating the |
//| program so that the bitmaps are deleted and the memory |
//| given back to Windows. |
//+-------------------------------------------------------------+
#ifndef _CARD_H_
#define _CARD_H_
// Constants
const int PackSize = 52;
const int CardWidth = 50;
const int CardHeight = 70;
// Data types
enum Suit { clubs = 0, diamonds = 1, hearts = 2, spades = 3 };
enum SuitColour { red = 0, black = 1 };
enum WayUp { faceup, facedown };
//--------------------------------//
// A class defining a single card //
//--------------------------------//
class Card {
public:
Card(int value, WayUp way_up = facedown);
virtual ~Card();
void Draw(wxDC& pDC, int x, int y);
static void DrawNullCard(wxDC& pDC, int x, int y); // Draw card place-holder
void Erase(wxDC& pDC, int x, int y);
void TurnCard(WayUp way_up = faceup) { m_wayUp = way_up; }
WayUp GetWayUp() const { return m_wayUp; }
int GetPipValue() const { return m_pipValue; }
Suit GetSuit() const { return m_suit; }
SuitColour GetColour() const { return m_colour; }
private:
Suit m_suit;
int m_pipValue; // in the range 1 (Ace) to 13 (King)
SuitColour m_colour; // red or black
bool m_status;
WayUp m_wayUp;
static wxBitmap* m_symbolBmap;
static wxBitmap* m_pictureBmap;
};
#endif // _CARD_H_

BIN
demos/forty/cards.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 B

271
demos/forty/forty.cpp Normal file
View File

@@ -0,0 +1,271 @@
/////////////////////////////////////////////////////////////////////////////
// Name: forty.cpp
// Purpose: Forty Thieves patience game
// Author: Chris Breeze
// Modified by:
// Created: 21/07/97
// RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze
// Licence: wxWindows licence
//---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWindows 2.0
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation
#pragma interface
#endif
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include "canvas.h"
#include "forty.h"
#include "scoredg.h"
#ifdef wx_x
#include "cards.xbm"
#endif
class FortyFrame: public wxFrame
{
public:
FortyFrame(wxFrame* frame, char* title, int x, int y, int w, int h);
virtual ~FortyFrame();
void OnCloseWindow(wxCloseEvent& event);
// Menu callbacks
void NewGame(wxCommandEvent& event);
void Exit(wxCommandEvent& event);
void About(wxCommandEvent& event);
void Undo(wxCommandEvent& event);
void Redo(wxCommandEvent& event);
void Scores(wxCommandEvent& event);
void ToggleRightButtonUndo(wxCommandEvent& event);
void ToggleHelpingHand(wxCommandEvent& event);
DECLARE_EVENT_TABLE()
private:
enum MenuCommands { NEW_GAME = 10, SCORES, EXIT,
UNDO, REDO,
RIGHT_BUTTON_UNDO, HELPING_HAND,
ABOUT };
wxMenuBar* m_menuBar;
FortyCanvas* m_canvas;
};
BEGIN_EVENT_TABLE(FortyFrame, wxFrame)
EVT_MENU(NEW_GAME, FortyFrame::NewGame)
EVT_MENU(EXIT, FortyFrame::Exit)
EVT_MENU(ABOUT, FortyFrame::About)
EVT_MENU(UNDO, FortyFrame::Undo)
EVT_MENU(REDO, FortyFrame::Redo)
EVT_MENU(SCORES, FortyFrame::Scores)
EVT_MENU(RIGHT_BUTTON_UNDO, FortyFrame::ToggleRightButtonUndo)
EVT_MENU(HELPING_HAND, FortyFrame::ToggleHelpingHand)
EVT_CLOSE(FortyFrame::OnCloseWindow)
END_EVENT_TABLE()
// Create a new application object
IMPLEMENT_APP (FortyApp)
wxColour* FortyApp::m_backgroundColour = 0;
wxColour* FortyApp::m_textColour = 0;
wxBrush* FortyApp::m_backgroundBrush = 0;
bool FortyApp::OnInit()
{
FortyFrame* frame = new FortyFrame(
0,
"Forty Thieves",
-1, -1, 668, 510
);
// Show the frame
frame->Show(TRUE);
return TRUE;
}
const wxColour& FortyApp::BackgroundColour()
{
if (!m_backgroundColour)
{
m_backgroundColour = new wxColour(0, 128, 0);
}
return *m_backgroundColour;
}
const wxBrush& FortyApp::BackgroundBrush()
{
if (!m_backgroundBrush)
{
m_backgroundBrush = new wxBrush(BackgroundColour(), wxSOLID);
}
return *m_backgroundBrush;
}
const wxColour& FortyApp::TextColour()
{
if (!m_textColour)
{
m_textColour = new wxColour("BLACK");
}
return *m_textColour;
}
// My frame constructor
FortyFrame::FortyFrame(wxFrame* frame, char* title, int x, int y, int w, int h):
wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
{
#ifdef __WXMAC__
// we need this in order to allow the about menu relocation, since ABOUT is not the default id of the about menu
wxApp::s_macAboutMenuItemId = ABOUT ;
#endif
// set the icon
#ifdef __WXMSW__
SetIcon(wxIcon("CardsIcon"));
#else
#ifdef GTK_TBD
SetIcon(wxIcon(Cards_bits, Cards_width, Cards_height));
#endif
#endif
// Make a menu bar
wxMenu* gameMenu = new wxMenu;
gameMenu->Append(NEW_GAME, "&New", "Start a new game");
gameMenu->Append(SCORES, "&Scores...", "Displays scores");
gameMenu->Append(EXIT, "E&xit", "Exits Forty Thieves");
wxMenu* editMenu = new wxMenu;
editMenu->Append(UNDO, "&Undo", "Undo the last move");
editMenu->Append(REDO, "&Redo", "Redo a move that has been undone");
wxMenu* optionsMenu = new wxMenu;
optionsMenu->Append(RIGHT_BUTTON_UNDO,
"&Right button undo",
"Enables/disables right mouse button undo and redo",
TRUE
);
optionsMenu->Append(HELPING_HAND,
"&Helping hand",
"Enables/disables hand cursor when a card can be moved",
TRUE
);
optionsMenu->Check(HELPING_HAND, TRUE);
optionsMenu->Check(RIGHT_BUTTON_UNDO, TRUE);
wxMenu* helpMenu = new wxMenu;
helpMenu->Append(ABOUT, "&About", "Displays program version information");
m_menuBar = new wxMenuBar;
m_menuBar->Append(gameMenu, "&Game");
m_menuBar->Append(editMenu, "&Edit");
m_menuBar->Append(optionsMenu, "&Options");
m_menuBar->Append(helpMenu, "&Help");
SetMenuBar(m_menuBar);
m_canvas = new FortyCanvas(this, 0, 0, 400, 400);
wxLayoutConstraints* constr = new wxLayoutConstraints;
constr->left.SameAs(this, wxLeft);
constr->top.SameAs(this, wxTop);
constr->right.SameAs(this, wxRight);
constr->height.SameAs(this, wxHeight);
m_canvas->SetConstraints(constr);
CreateStatusBar();
}
FortyFrame::~FortyFrame()
{
}
void FortyFrame::OnCloseWindow(wxCloseEvent& event)
{
if (m_canvas->OnCloseCanvas() )
{
this->Destroy();
}
else
event.Veto();
}
void
FortyFrame::NewGame(wxCommandEvent&)
{
m_canvas->NewGame();
}
void
FortyFrame::Exit(wxCommandEvent&)
{
#ifdef __WXGTK__
// wxGTK doesn't call OnClose() so we do it here
// if (OnClose())
#endif
Close(TRUE);
}
void
FortyFrame::About(wxCommandEvent&)
{
wxMessageBox(
"Forty Thieves\n\n"
"A freeware program using the wxWindows\n"
"portable C++ GUI toolkit.\n"
"http://web.ukonline.co.uk/julian.smart/wxwin\n"
"http://www.freiburg.linux.de/~wxxt\n\n"
"Author: Chris Breeze (c) 1992-1998\n"
"email: chris.breeze@iname.com",
"About Forty Thieves",
wxOK, this
);
}
void
FortyFrame::Undo(wxCommandEvent&)
{
m_canvas->Undo();
}
void
FortyFrame::Redo(wxCommandEvent&)
{
m_canvas->Redo();
}
void
FortyFrame::Scores(wxCommandEvent&)
{
m_canvas->UpdateScores();
ScoreDialog scores(this, m_canvas->GetScoreFile());
scores.Display();
}
void
FortyFrame::ToggleRightButtonUndo(wxCommandEvent& event)
{
bool checked = m_menuBar->IsChecked(event.GetId());
m_canvas->EnableRightButtonUndo(checked);
}
void
FortyFrame::ToggleHelpingHand(wxCommandEvent& event)
{
bool checked = m_menuBar->IsChecked(event.GetId());
m_canvas->EnableHelpingHand(checked);
}

8
demos/forty/forty.def Normal file
View File

@@ -0,0 +1,8 @@
NAME Forty
DESCRIPTION 'Forty Thieves'
EXETYPE WINDOWS
STUB 'WINSTUB.EXE'
CODE PRELOAD MOVEABLE DISCARDABLE
DATA PRELOAD MOVEABLE MULTIPLE
HEAPSIZE 4048
STACKSIZE 16000

31
demos/forty/forty.h Normal file
View File

@@ -0,0 +1,31 @@
/////////////////////////////////////////////////////////////////////////////
// Name: forty.h
// Purpose: Forty Thieves patience game
// Author: Chris Breeze
// Modified by:
// Created: 21/07/97
// RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze
// Licence: wxWindows licence
//---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWindows 2.0
/////////////////////////////////////////////////////////////////////////////
#ifndef _FORTY_H_
#define _FORTY_H_
class FortyApp: public wxApp
{
public:
bool OnInit();
static const wxColour& BackgroundColour();
static const wxColour& TextColour();
static const wxBrush& BackgroundBrush();
private:
static wxColour* m_backgroundColour;
static wxColour* m_textColour;
static wxBrush* m_backgroundBrush;
};
#endif

6
demos/forty/forty.rc Normal file
View File

@@ -0,0 +1,6 @@
#include "wx/msw/wx.rc"
CardsIcon ICON "cards.ico"
CardPictures BITMAP "pictures.bmp"
CardSymbols BITMAP "symbols.bmp"

946
demos/forty/game.cpp Normal file
View File

@@ -0,0 +1,946 @@
/////////////////////////////////////////////////////////////////////////////
// Name: game.cpp
// Purpose: Forty Thieves patience game
// Author: Chris Breeze
// Modified by:
// Created: 21/07/97
// RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze
// Licence: wxWindows licence
//---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWindows 2.0
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation
#pragma interface
#endif
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
#include "forty.h"
#include "game.h"
Game::Game(int wins, int games, int score) :
m_inPlay(FALSE),
m_moveIndex(0),
m_redoIndex(0),
m_bmap(0),
m_bmapCard(0)
{
int i;
m_pack = new Pack(2, 2 + 4 * (CardHeight + 2));
srand(time(0));
for (i = 0; i < 5; i++) m_pack->Shuffle();
m_discard = new Discard(2, 2 + 5 * (CardHeight + 2));
for (i = 0; i < 8; i++)
{
m_foundations[i] = new Foundation(2 + (i / 4) * (CardWidth + 2),
2 + (i % 4) * (CardHeight + 2));
}
for (i = 0; i < 10; i++)
{
m_bases[i] = new Base(8 + (i + 2) * (CardWidth + 2), 2);
}
Deal();
m_srcPile = 0;
m_liftedCard = 0;
// copy the input parameters for future reference
m_numWins = wins;
m_numGames = games;
m_totalScore = score;
m_currentScore = 0;
}
// Make sure we delete all objects created by the game object
Game::~Game()
{
int i;
delete m_pack;
delete m_discard;
for (i = 0; i < 8; i++)
{
delete m_foundations[i];
}
for (i = 0; i < 10; i++)
{
delete m_bases[i];
}
delete m_bmap;
delete m_bmapCard;
}
/*
Set the score for a new player.
NB: call Deal() first if the new player is to start
a new game
*/
void Game::NewPlayer(int wins, int games, int score)
{
m_numWins = wins;
m_numGames = games;
m_totalScore = score;
m_currentScore = 0;
}
// Undo the last move
void Game::Undo(wxDC& dc)
{
if (m_moveIndex > 0)
{
m_moveIndex--;
Card* card = m_moves[m_moveIndex].dest->RemoveTopCard(dc);
m_moves[m_moveIndex].src->AddCard(dc, card);
DisplayScore(dc);
}
}
// Redo the last move
void Game::Redo(wxDC& dc)
{
if (m_moveIndex < m_redoIndex)
{
Card* card = m_moves[m_moveIndex].src->RemoveTopCard(dc);
if (m_moves[m_moveIndex].src == m_pack)
{
m_pack->Redraw(dc);
card->TurnCard(faceup);
}
m_moves[m_moveIndex].dest->AddCard(dc, card);
DisplayScore(dc);
m_moveIndex++;
}
}
void Game::DoMove(wxDC& dc, Pile* src, Pile* dest)
{
if (m_moveIndex < MaxMoves)
{
if (src == dest)
{
wxMessageBox("Game::DoMove() src == dest", "Debug message",
wxOK | wxICON_EXCLAMATION);
}
m_moves[m_moveIndex].src = src;
m_moves[m_moveIndex].dest = dest;
m_moveIndex++;
// when we do a move any moves in redo buffer are discarded
m_redoIndex = m_moveIndex;
}
else
{
wxMessageBox("Game::DoMove() Undo buffer full", "Debug message",
wxOK | wxICON_EXCLAMATION);
}
if (!m_inPlay)
{
m_inPlay = TRUE;
m_numGames++;
}
DisplayScore(dc);
}
void Game::DisplayScore(wxDC& dc)
{
wxColour bgColour = FortyApp::BackgroundColour();
wxPen* pen = wxThePenList->FindOrCreatePen(bgColour, 1, wxSOLID);
dc.SetTextBackground(bgColour);
dc.SetTextForeground(FortyApp::TextColour());
dc.SetBrush(FortyApp::BackgroundBrush());
dc.SetPen(* pen);
// count the number of cards in foundations
m_currentScore = 0;
for (int i = 0; i < 8; i++)
{
m_currentScore += m_foundations[i]->GetNumCards();
}
int x, y;
m_pack->GetTopCardPos(x, y);
x += 12 * CardWidth - 105;
int w, h;
{
long width, height;
dc.GetTextExtent("Average score:m_x", &width, &height);
w = width;
h = height;
}
dc.DrawRectangle(x + w, y, 20, 4 * h);
char str[80];
sprintf(str, "%d", m_currentScore);
dc.DrawText("Score:", x, y);
dc.DrawText(str, x + w, y);
y += h;
sprintf(str, "%d", m_numGames);
dc.DrawText("Games played:", x, y);
dc.DrawText(str, x + w, y);
y += h;
sprintf(str, "%d", m_numWins);
dc.DrawText("Games won:", x, y);
dc.DrawText(str, x + w, y);
y += h;
int average = 0;
if (m_numGames > 0)
{
average = (2 * (m_currentScore + m_totalScore) + m_numGames ) / (2 * m_numGames);
}
sprintf(str, "%d", average);
dc.DrawText("Average score:", x, y);
dc.DrawText(str, x + w, y);
}
// Shuffle the m_pack and deal the cards
void Game::Deal()
{
int i, j;
Card* card;
// Reset all the piles, the undo buffer and shuffle the m_pack
m_moveIndex = 0;
m_pack->ResetPile();
for (i = 0; i < 5; i++)
{
m_pack->Shuffle();
}
m_discard->ResetPile();
for (i = 0; i < 10; i++)
{
m_bases[i]->ResetPile();
}
for (i = 0; i < 8; i++)
{
m_foundations[i]->ResetPile();
}
// Deal the initial 40 cards onto the bases
for (i = 0; i < 10; i++)
{
for (j = 1; j <= 4; j++)
{
card = m_pack->RemoveTopCard();
card->TurnCard(faceup);
m_bases[i]->AddCard(card);
}
}
if (m_inPlay)
{
// player has started the game and then redealt
// and so we must add the score for this game to the total score
m_totalScore += m_currentScore;
}
m_currentScore = 0;
m_inPlay = FALSE;
}
// Redraw the m_pack, discard pile, the bases and the foundations
void Game::Redraw(wxDC& dc)
{
int i;
m_pack->Redraw(dc);
m_discard->Redraw(dc);
for (i = 0; i < 8; i++)
{
m_foundations[i]->Redraw(dc);
}
for (i = 0; i < 10; i++)
{
m_bases[i]->Redraw(dc);
}
DisplayScore(dc);
if (m_bmap == 0)
{
m_bmap = new wxBitmap(CardWidth, CardHeight);
m_bmapCard = new wxBitmap(CardWidth, CardHeight);
// Initialise the card bitmap to the background colour
wxMemoryDC memoryDC;
memoryDC.SelectObject(*m_bmapCard);
memoryDC.SetPen( *wxTRANSPARENT_PEN );
memoryDC.SetBrush(FortyApp::BackgroundBrush());
memoryDC.DrawRectangle(0, 0, CardWidth, CardHeight);
memoryDC.SelectObject(*m_bmap);
memoryDC.DrawRectangle(0, 0, CardWidth, CardHeight);
memoryDC.SelectObject(wxNullBitmap);
}
}
// Test to see if the point (x, y) is over the top card of one of the piles
// Returns pointer to the pile, or 0 if (x, y) is not over a pile
// or the pile is empty
Pile* Game::WhichPile(int x, int y)
{
if (m_pack->GetCard(x, y) &&
m_pack->GetCard(x, y) == m_pack->GetTopCard())
{
return m_pack;
}
if (m_discard->GetCard(x, y) &&
m_discard->GetCard(x, y) == m_discard->GetTopCard())
{
return m_discard;
}
int i;
for (i = 0; i < 8; i++)
{
if (m_foundations[i]->GetCard(x, y) &&
m_foundations[i]->GetCard(x, y) == m_foundations[i]->GetTopCard())
{
return m_foundations[i];
}
}
for (i = 0; i < 10; i++)
{
if (m_bases[i]->GetCard(x, y) &&
m_bases[i]->GetCard(x, y) == m_bases[i]->GetTopCard())
{
return m_bases[i];
}
}
return 0;
}
// Left button is pressed - if cursor is over the m_pack then deal a card
// otherwise if it is over a card pick it up ready to be dragged - see MouseMove()
bool Game::LButtonDown(wxDC& dc, int x, int y)
{
m_srcPile = WhichPile(x, y);
if (m_srcPile == m_pack)
{
Card* card = m_pack->RemoveTopCard();
if (card)
{
m_pack->Redraw(dc);
card->TurnCard(faceup);
m_discard->AddCard(dc, card);
DoMove(dc, m_pack, m_discard);
}
m_srcPile = 0;
}
else if (m_srcPile)
{
m_srcPile->GetTopCardPos(m_xPos, m_yPos);
m_xOffset = m_xPos - x;
m_yOffset = m_yPos - y;
// Copy the area under the card
// Initialise the card bitmap to the background colour
{
wxMemoryDC memoryDC;
memoryDC.SelectObject(*m_bmap);
m_liftedCard = m_srcPile->RemoveTopCard(memoryDC, m_xPos, m_yPos);
}
// Draw the card in card bitmap ready for blitting onto
// the screen
{
wxMemoryDC memoryDC;
memoryDC.SelectObject(*m_bmapCard);
m_liftedCard->Draw(memoryDC, 0, 0);
}
}
return m_srcPile != 0;
}
// Called when the left button is double clicked
// If a card is under the pointer and it can move elsewhere then move it.
// Move onto a foundation as first choice, a populated base as second and
// an empty base as third choice.
// NB Cards in the m_pack cannot be moved in this way - they aren't in play
// yet
void Game::LButtonDblClk(wxDC& dc, int x, int y)
{
Pile* pile = WhichPile(x, y);
if (!pile) return;
// Double click on m_pack is the same as left button down
if (pile == m_pack)
{
LButtonDown(dc, x, y);
}
else
{
Card* card = pile->GetTopCard();
if (card)
{
int i;
// if the card is an ace then try to place it next
// to an ace of the same suit
if (card->GetPipValue() == 1)
{
for(i = 0; i < 4; i++)
{
Card* m_topCard = m_foundations[i]->GetTopCard();
if ( m_topCard )
{
if (m_topCard->GetSuit() == card->GetSuit() &&
m_foundations[i + 4] != pile &&
m_foundations[i + 4]->GetTopCard() == 0)
{
pile->RemoveTopCard(dc);
m_foundations[i + 4]->AddCard(dc, card);
DoMove(dc, pile, m_foundations[i + 4]);
return;
}
}
}
}
// try to place the card on a foundation
for(i = 0; i < 8; i++)
{
if (m_foundations[i]->AcceptCard(card) && m_foundations[i] != pile)
{
pile->RemoveTopCard(dc);
m_foundations[i]->AddCard(dc, card);
DoMove(dc, pile, m_foundations[i]);
return;
}
}
// try to place the card on a populated base
for(i = 0; i < 10; i++)
{
if (m_bases[i]->AcceptCard(card) &&
m_bases[i] != pile &&
m_bases[i]->GetTopCard())
{
pile->RemoveTopCard(dc);
m_bases[i]->AddCard(dc, card);
DoMove(dc, pile, m_bases[i]);
return;
}
}
// try to place the card on any base
for(i = 0; i < 10; i++)
{
if (m_bases[i]->AcceptCard(card) && m_bases[i] != pile)
{
pile->RemoveTopCard(dc);
m_bases[i]->AddCard(dc, card);
DoMove(dc, pile, m_bases[i]);
return;
}
}
}
}
}
// Test to see whether the game has been won:
// i.e. m_pack, discard and bases are empty
bool Game::HaveYouWon()
{
if (m_pack->GetTopCard()) return FALSE;
if (m_discard->GetTopCard()) return FALSE;
for(int i = 0; i < 10; i++)
{
if (m_bases[i]->GetTopCard()) return FALSE;
}
m_numWins++;
m_totalScore += m_currentScore;
m_currentScore = 0;
return TRUE;
}
// See whether the card under the cursor can be moved somewhere else
// Returns TRUE if it can be moved, FALSE otherwise
bool Game::CanYouGo(int x, int y)
{
Pile* pile = WhichPile(x, y);
if (pile && pile != m_pack)
{
Card* card = pile->GetTopCard();
if (card)
{
int i;
for(i = 0; i < 8; i++)
{
if (m_foundations[i]->AcceptCard(card) && m_foundations[i] != pile)
{
return TRUE;
}
}
for(i = 0; i < 10; i++)
{
if (m_bases[i]->GetTopCard() &&
m_bases[i]->AcceptCard(card) &&
m_bases[i] != pile)
{
return TRUE;
}
}
}
}
return FALSE;
}
// Called when the left button is released after dragging a card
// Scan the piles to see if this card overlaps a pile and can be added
// to the pile. If the card overlaps more than one pile on which it can be placed
// then put it on the nearest pile.
void Game::LButtonUp(wxDC& dc, int x, int y)
{
if (m_srcPile)
{
// work out the position of the dragged card
x += m_xOffset;
y += m_yOffset;
Pile* nearestPile = 0;
int distance = (CardHeight + CardWidth) * (CardHeight + CardWidth);
// find the nearest pile which will accept the card
int i;
for (i = 0; i < 8; i++)
{
if (DropCard(x, y, m_foundations[i], m_liftedCard))
{
if (m_foundations[i]->CalcDistance(x, y) < distance)
{
nearestPile = m_foundations[i];
distance = nearestPile->CalcDistance(x, y);
}
}
}
for (i = 0; i < 10; i++)
{
if (DropCard(x, y, m_bases[i], m_liftedCard))
{
if (m_bases[i]->CalcDistance(x, y) < distance)
{
nearestPile = m_bases[i];
distance = nearestPile->CalcDistance(x, y);
}
}
}
// Restore the area under the card
wxMemoryDC memoryDC;
memoryDC.SelectObject(*m_bmap);
dc.Blit(m_xPos, m_yPos, CardWidth, CardHeight,
&memoryDC, 0, 0, wxCOPY);
// Draw the card in its new position
if (nearestPile)
{
// Add to new pile
nearestPile->AddCard(dc, m_liftedCard);
if (nearestPile != m_srcPile)
{
DoMove(dc, m_srcPile, nearestPile);
}
}
else
{
// Return card to src pile
m_srcPile->AddCard(dc, m_liftedCard);
}
m_srcPile = 0;
m_liftedCard = 0;
}
}
bool Game::DropCard(int x, int y, Pile* pile, Card* card)
{
bool retval = FALSE;
if (pile->Overlap(x, y))
{
if (pile->AcceptCard(card))
{
retval = TRUE;
}
}
return retval;
}
void Game::MouseMove(wxDC& dc, int mx, int my)
{
if (m_liftedCard)
{
wxMemoryDC memoryDC;
memoryDC.SelectObject(*m_bmap);
int dx = mx + m_xOffset - m_xPos;
int dy = my + m_yOffset - m_yPos;
if (abs(dx) >= CardWidth || abs(dy) >= CardHeight)
{
// Restore the area under the card
dc.Blit(m_xPos, m_yPos, CardWidth, CardHeight,
&memoryDC, 0, 0, wxCOPY);
// Copy the area under the card in the new position
memoryDC.Blit(0, 0, CardWidth, CardHeight,
&dc, m_xPos + dx, m_yPos + dy, wxCOPY);
}
else if (dx >= 0)
{
// dx >= 0
dc.Blit(m_xPos, m_yPos, dx, CardHeight, &memoryDC, 0, 0, wxCOPY);
if (dy >= 0)
{
// dy >= 0
dc.Blit(m_xPos + dx, m_yPos, CardWidth - dx, dy, &memoryDC, dx, 0, wxCOPY);
memoryDC.Blit(0, 0, CardWidth - dx, CardHeight - dy,
&memoryDC, dx, dy, wxCOPY);
memoryDC.Blit(0, CardHeight - dy, CardWidth - dx, dy,
&dc, m_xPos + dx, m_yPos + CardHeight, wxCOPY);
}
else
{
// dy < 0
dc.Blit(m_xPos + dx, m_yPos + dy + CardHeight, CardWidth - dx, -dy,
&memoryDC, dx, CardHeight + dy, wxCOPY);
memoryDC.Blit(0, -dy, CardWidth - dx, CardHeight + dy,
&memoryDC, dx, 0, wxCOPY);
memoryDC.Blit(0, 0, CardWidth - dx, -dy,
&dc, m_xPos + dx, m_yPos + dy, wxCOPY);
}
memoryDC.Blit(CardWidth - dx, 0, dx, CardHeight,
&dc, m_xPos + CardWidth, m_yPos + dy, wxCOPY);
}
else
{
// dx < 0
dc.Blit(m_xPos + CardWidth + dx, m_yPos, -dx, CardHeight,
&memoryDC, CardWidth + dx, 0, wxCOPY);
if (dy >= 0)
{
dc.Blit(m_xPos, m_yPos, CardWidth + dx, dy, &memoryDC, 0, 0, wxCOPY);
memoryDC.Blit(-dx, 0, CardWidth + dx, CardHeight - dy,
&memoryDC, 0, dy, wxCOPY);
memoryDC.Blit(-dx, CardHeight - dy, CardWidth + dx, dy,
&dc, m_xPos, m_yPos + CardHeight, wxCOPY);
}
else
{
// dy < 0
dc.Blit(m_xPos, m_yPos + CardHeight + dy, CardWidth + dx, -dy,
&memoryDC, 0, CardHeight + dy, wxCOPY);
memoryDC.Blit(-dx, -dy, CardWidth + dx, CardHeight + dy,
&memoryDC, 0, 0, wxCOPY);
memoryDC.Blit(-dx, 0, CardWidth + dx, -dy,
&dc, m_xPos, m_yPos + dy, wxCOPY);
}
memoryDC.Blit(0, 0, -dx, CardHeight,
&dc, m_xPos + dx, m_yPos + dy, wxCOPY);
}
m_xPos += dx;
m_yPos += dy;
// draw the card in its new position
memoryDC.SelectObject(*m_bmapCard);
dc.Blit(m_xPos, m_yPos, CardWidth, CardHeight,
&memoryDC, 0, 0, wxCOPY);
}
}
//----------------------------------------------//
// The Pack class: holds the two decks of cards //
//----------------------------------------------//
Pack::Pack(int x, int y) : Pile(x, y, 0, 0)
{
for (m_topCard = 0; m_topCard < NumCards; m_topCard++)
{
m_cards[m_topCard] = new Card(1 + m_topCard / 2, facedown);
}
m_topCard = NumCards - 1;
}
void Pack::Shuffle()
{
Card* temp[NumCards];
int i;
// Don't try to shuffle an empty m_pack!
if (m_topCard < 0) return;
// Copy the cards into a temporary array. Start by clearing
// the array and then copy the card into a random position.
// If the position is occupied then find the next lower position.
for (i = 0; i <= m_topCard; i++)
{
temp[i] = 0;
}
for (i = 0; i <= m_topCard; i++)
{
int pos = rand() % (m_topCard + 1);
while (temp[pos])
{
pos--;
if (pos < 0) pos = m_topCard;
}
m_cards[i]->TurnCard(facedown);
temp[pos] = m_cards[i];
m_cards[i] = 0;
}
// Copy each card back into the m_pack in a random
// position. If position is occupied then find nearest
// unoccupied position after the random position.
for (i = 0; i <= m_topCard; i++)
{
int pos = rand() % (m_topCard + 1);
while (m_cards[pos])
{
pos++;
if (pos > m_topCard) pos = 0;
}
m_cards[pos] = temp[i];
}
}
void Pack::Redraw(wxDC& dc)
{
Pile::Redraw(dc);
char str[10];
sprintf(str, "%d ", m_topCard + 1);
dc.SetBackgroundMode( wxSOLID );
dc.SetTextBackground(FortyApp::BackgroundColour());
dc.SetTextForeground(FortyApp::TextColour());
dc.DrawText(str, m_x + CardWidth + 5, m_y + CardHeight / 2);
}
void Pack::AddCard(Card* card)
{
if (card == m_cards[m_topCard + 1])
{
m_topCard++;
}
else
{
wxMessageBox("Pack::AddCard() Undo error", "Forty Thieves: Warning",
wxOK | wxICON_EXCLAMATION);
}
card->TurnCard(facedown);
}
Pack::~Pack()
{
for (m_topCard = 0; m_topCard < NumCards; m_topCard++)
{
delete m_cards[m_topCard];
}
};
//------------------------------------------------------//
// The Base class: holds the initial pile of four cards //
//------------------------------------------------------//
Base::Base(int x, int y) : Pile(x, y, 0, 12)
{
m_topCard = -1;
}
bool Base::AcceptCard(Card* card)
{
bool retval = FALSE;
if (m_topCard >= 0)
{
if (m_cards[m_topCard]->GetSuit() == card->GetSuit() &&
m_cards[m_topCard]->GetPipValue() - 1 == card->GetPipValue())
{
retval = TRUE;
}
}
else
{
// pile is empty - ACCEPT
retval = TRUE;
}
return retval;
}
Base::~Base()
{
// nothing special at the moment
};
//----------------------------------------------------------------//
// The Foundation class: holds the cards built up from the ace... //
//----------------------------------------------------------------//
Foundation::Foundation(int x, int y) : Pile(x, y, 0, 0)
{
m_topCard = -1;
}
bool Foundation::AcceptCard(Card* card)
{
bool retval = FALSE;
if (m_topCard >= 0)
{
if (m_cards[m_topCard]->GetSuit() == card->GetSuit() &&
m_cards[m_topCard]->GetPipValue() + 1 == card->GetPipValue())
{
retval = TRUE;
}
}
else if (card->GetPipValue() == 1)
{
// It's an ace and the pile is empty - ACCEPT
retval = TRUE;
}
return retval;
}
Foundation::~Foundation()
{
// nothing special at the moment
};
//----------------------------------------------------//
// The Discard class: holds cards dealt from the m_pack //
//----------------------------------------------------//
Discard::Discard(int x, int y) : Pile(x, y, 19, 0)
{
m_topCard = -1;
}
void Discard::Redraw(wxDC& dc)
{
if (m_topCard >= 0)
{
if (m_dx == 0 && m_dy == 0)
{
m_cards[m_topCard]->Draw(dc, m_x, m_y);
}
else
{
int x = m_x;
int y = m_y;
for (int i = 0; i <= m_topCard; i++)
{
m_cards[i]->Draw(dc, x, y);
x += m_dx;
y += m_dy;
if (i == 31)
{
x = m_x;
y = m_y + CardHeight / 3;
}
}
}
}
else
{
Card::DrawNullCard(dc, m_x, m_y);
}
}
void Discard::GetTopCardPos(int& x, int& y)
{
if (m_topCard < 0)
{
x = m_x;
y = m_y;
}
else if (m_topCard > 31)
{
x = m_x + m_dx * (m_topCard - 32);
y = m_y + CardHeight / 3;
}
else
{
x = m_x + m_dx * m_topCard;
y = m_y;
}
}
Card* Discard::RemoveTopCard(wxDC& dc, int m_xOffset, int m_yOffset)
{
Card* card;
if (m_topCard <= 31)
{
card = Pile::RemoveTopCard(dc, m_xOffset, m_yOffset);
}
else
{
int topX, topY, x, y;
GetTopCardPos(topX, topY);
card = Pile::RemoveTopCard();
card->Erase(dc, topX - m_xOffset, topY - m_yOffset);
GetTopCardPos(x, y);
dc.SetClippingRegion(topX - m_xOffset, topY - m_yOffset,
CardWidth, CardHeight);
for (int i = m_topCard - 31; i <= m_topCard - 31 + CardWidth / m_dx; i++)
{
m_cards[i]->Draw(dc, m_x - m_xOffset + i * m_dx, m_y - m_yOffset);
}
if (m_topCard > 31)
{
m_cards[m_topCard]->Draw(dc, topX - m_xOffset - m_dx, topY - m_yOffset);
}
dc.DestroyClippingRegion();
}
return card;
}
Discard::~Discard()
{
// nothing special at the moment
};

135
demos/forty/game.h Normal file
View File

@@ -0,0 +1,135 @@
/////////////////////////////////////////////////////////////////////////////
// Name: game.h
// Purpose: Forty Thieves patience game
// Author: Chris Breeze
// Modified by:
// Created: 21/07/97
// RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze
// Licence: wxWindows licence
//---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWindows 2.0
/////////////////////////////////////////////////////////////////////////////
#ifndef _GAME_H_
#define _GAME_H_
#include "card.h"
#include "pile.h"
const int MaxMoves = 800;
//---------------------------------------//
// A class which holds the pack of cards //
//---------------------------------------//
class Pack : public Pile {
public:
Pack(int x, int y);
~Pack();
void Redraw(wxDC& dc);
void ResetPile() { m_topCard = NumCards - 1; }
void Shuffle();
void AddCard(Card* card); // Add card
void AddCard(wxDC& dc, Card* card) { AddCard(card); Redraw(dc); }
};
//----------------------------------------------------------//
// A class which holds a base i.e. the initial 10 x 4 cards //
//----------------------------------------------------------//
class Base : public Pile {
public:
Base(int x, int y);
~Base();
bool AcceptCard(Card* card);
};
//----------------------------------------------------//
// A class which holds a foundation i.e. Ace, 2, 3... //
//----------------------------------------------------//
class Foundation : public Pile {
public:
Foundation(int x, int y);
~Foundation();
bool AcceptCard(Card* card);
};
//--------------------------------------//
// A class which holds the discard pile //
//--------------------------------------//
class Discard : public Pile {
public:
Discard(int x, int y);
~Discard();
void Redraw(wxDC& dc);
void GetTopCardPos(int& x, int& y);
Card* RemoveTopCard(wxDC& dc, int m_xOffset, int m_yOffset);
};
class Game {
public:
Game(int wins, int games, int score);
virtual ~Game();
void NewPlayer(int wins, int games, int score);
void Deal(); // Shuffle and deal a new game
bool CanYouGo(int x, int y); // can card under (x,y) go somewhere?
bool HaveYouWon(); // have you won the game?
void Undo(wxDC& dc); // Undo the last go
void Redo(wxDC& dc); // Redo the last go
void Redraw(wxDC& dc);
void DisplayScore(wxDC& dc);
bool LButtonDown(wxDC& dc, int mx, int my); //
void LButtonUp(wxDC& dc, int mx, int my);
void LButtonDblClk(wxDC& dc, int mx, int my);
void MouseMove(wxDC& dc, int mx, int my);
int GetNumWins() const { return m_numWins; }
int GetNumGames() const { return m_numGames; }
int GetScore() const { return m_currentScore + m_totalScore; }
bool InPlay() const { return m_inPlay; }
private:
bool DropCard(int x, int y, Pile* pile, Card* card);
// can the card at (x, y) be dropped on the pile?
Pile* WhichPile(int x, int y); // which pile is (x, y) over?
void DoMove(wxDC& dc, Pile* src, Pile* dest);
bool m_inPlay; // flag indicating that the game has started
// undo buffer
struct {
Pile* src;
Pile* dest;
} m_moves[MaxMoves];
int m_moveIndex; // current position in undo/redo buffer
int m_redoIndex; // max move index available for redo
// the various piles of cards
Pack* m_pack;
Discard* m_discard;
Base* m_bases[10];
Foundation* m_foundations[8];
// variables to do with dragging cards
Pile* m_srcPile;
Card* m_liftedCard;
int m_xPos, m_yPos; // current coords of card being dragged
int m_xOffset, m_yOffset; // card/mouse offset when dragging a card
wxBitmap* m_bmap;
wxBitmap* m_bmapCard;
// variables to do with scoring
int m_numGames;
int m_numWins;
int m_totalScore;
int m_currentScore;
};
#endif // _GAME_H_

BIN
demos/forty/make_cw.mcp Normal file

Binary file not shown.

16
demos/forty/makefile.b32 Normal file
View File

@@ -0,0 +1,16 @@
#
# File: makefile.b32
# Author: Julian Smart
# Created: 1999
# Updated:
# Copyright:
#
# Makefile : Builds sample for 32-bit BC++
WXDIR = $(WXWIN)
TARGET=forty
OBJECTS = $(TARGET).obj canvas.obj card.obj game.obj pile.obj playerdg.obj scoredg.obj scorefil.obj
!include $(WXDIR)\src\makeprog.b32

19
demos/forty/makefile.bcc Normal file
View File

@@ -0,0 +1,19 @@
#
# File: makefile.bcc
# Author: Julian Smart
# Created: 1998
# Updated:
#
# Builds a BC++ 16-bit sample
!if "$(WXWIN)" == ""
!error You must define the WXWIN variable in autoexec.bat, e.g. WXWIN=c:\wx
!endif
WXDIR = $(WXWIN)
TARGET=forty
OBJECTS=$(TARGET).obj canvas.obj card.obj game.obj pile.obj playerdg.obj scoredg.obj scorefil.obj
!include $(WXDIR)\src\makeprog.bcc

17
demos/forty/makefile.dos Normal file
View File

@@ -0,0 +1,17 @@
#
# File: makefile.dos
# Author: Julian Smart
# Created: 1998
# Updated:
#
# Makefile : Builds 16-bit sample, VC++ 1.5
# Use FINAL=1 argument to nmake to build final version with no debugging
# info
WXDIR = $(WXWIN)
TARGET=forty
OBJECTS = $(TARGET).obj canvas.obj card.obj game.obj pile.obj playerdg.obj scoredg.obj scorefil.obj
!include $(WXDIR)\src\makeprog.msc

16
demos/forty/makefile.g95 Normal file
View File

@@ -0,0 +1,16 @@
#
# File: makefile.g95
# Author: Julian Smart
# Created: 1999
# Updated:
# Copyright: (c) Julian Smart, 1999
#
# Makefile for wxWindows sample (Cygwin/Mingw32).
WXDIR = ../..
TARGET=forty
OBJECTS = $(TARGET).o canvas.o card.o game.o pile.o playerdg.o scoredg.o scorefil.o
include $(WXDIR)/src/makeprog.g95

35
demos/forty/makefile.unx Normal file
View File

@@ -0,0 +1,35 @@
#
# File: Makefile for samples
# Author: Robert Roebling
# Created: 1999
# Updated:
# Copyright: (c) 1998 Robert Roebling
#
# This makefile requires a Unix version of wxWindows
# to be installed on your system. This is most often
# done typing "make install" when using the complete
# sources of wxWindows or by installing the two
# RPM packages wxGTK.XXX.rpm and wxGTK-devel.XXX.rpm
# under Linux.
#
CC = g++
PROGRAM = forty
OBJECTS = $(PROGRAM).o canvas.o card.o game.o pile.o playerdg.o scoredg.o scorefil.o
# implementation
.SUFFIXES: .o .cpp
.cpp.o :
$(CC) -c `wx-config --cflags` -o $@ $<
all: $(PROGRAM)
$(PROGRAM): $(OBJECTS)
$(CC) -o $(PROGRAM) $(OBJECTS) `wx-config --libs`
clean:
rm -f *.o $(PROGRAM)

18
demos/forty/makefile.vc Normal file
View File

@@ -0,0 +1,18 @@
#
# File: makefile.vc
# Author: Julian Smart
# Created: 1999
# Updated:
# Copyright: (c) Julian Smart
#
# Makefile : Builds sample (VC++, WIN32)
# Use FINAL=1 argument to nmake to build final version with no debug info.
# Set WXDIR for your system
WXDIR = $(WXWIN)
PROGRAM=forty
OBJECTS = $(PROGRAM).obj card.obj canvas.obj game.obj pile.obj playerdg.obj scoredg.obj scorefil.obj
!include $(WXDIR)\src\makeprog.vc

15
demos/forty/makefile.wat Normal file
View File

@@ -0,0 +1,15 @@
#
# Makefile for WATCOM
#
# Created by Julian Smart, January 1999
#
#
WXDIR = $(%WXWIN)
PROGRAM = forty
OBJECTS = $(PROGRAM).obj canvas.obj card.obj game.obj pile.obj playerdg.obj scoredg.obj scorefil.obj
!include $(WXDIR)\src\makeprog.wat

BIN
demos/forty/pictures.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

60
demos/forty/pictures.xpm Normal file
View File

@@ -0,0 +1,60 @@
/* XPM */
static char *Pictures[] = {
/* width height num_colors chars_per_pixel */
" 120 45 8 1",
/* colors */
". c #000000",
"# c #c0c0c0",
"a c #808080",
"b c #ff0000",
"c c #ffff00",
"d c #0000ff",
"e c #00ffff",
"f c #ffffff",
/* pixels */
"........................................................................................................................",
".fff.fffffff.bb.bb.bb.b.fffffffffffffff..fffffffffff..f..bbc.cc..ffffffffffffff..fff.ffffff.bbccccbcccccbb.ffffffffffff.",
".ff.c.fffffff.bbbbbbbb.ffffffffffffffff..fff.ffffff..f.ff.bbc..c.ffffffffffffff..ff.a.ffffff.bbccbbbcccbb.fffffffffffff.",
".f.cbc.fffffff........fffffffffffffffff..ff.b.fffff.f.ffff.bb..c..fffffffffffff..f.#af.ffffff.bbbbbbbbbb.ffffffffffffff.",
".f.cbc.ffffff.fff.c.c.fffffffffffffffff..ff.b.fffff..f.ff.f.bbc.c.fffffffffffff..f.#af.ffffff............ffffffffffffff.",
".ff.c.fffffff.f..f.c.c.ffffffffffffffff..fff.ffffff.f..ff..f.bb..ffffffffffffff..f.#af.ffffff.a..f.fff.f.ffffffffffffff.",
".f.cbc.ffffff.f.ff.c.c.ffffffffffffffff..ff.c.fffff.fff.ffff..b.fffffffffffffff..f.#af.ffffff.a.f..fff..f.fffffffffffff.",
".f.cbc.fffff.fffff.c.c.ffffffffffffffff..ff.c.fffff.fff.ffff....fffffffffffffff..f.#af.ffffff.a.ffff.ffff.fffffffffffff.",
".ff.c.fffff.ffffff.c.c.ffffffffffffffff..ff.c.fffff.fff..fff.b..fffffffffffffff..f.#af.ffffff.a.fffff.fff.fffffffffffff.",
".f.cbc.ffff..###ff.c.c.ffffffffffffffff..ff.c.fffff.ffffffff..b.fffffffffffffff..f.#af.ffffff.a.ffff..fff.fffffffffffff.",
".f.cbc.ffffff...ff.c.c.ffffffffffffffff..fff.ffffff.ffbbbbff.f...ffffffffffffff..f.#af.fff..f.a..ffffffff.fffffffffffff.",
".ff....ffffff.ffff.c.c.ffffffffffffffff..ff....fffff.ffffff.f.f...fffffffffffff..f.#af.fff....a...f....f..fffffffffffff.",
".f.ffff.fffff.fffff.c.c.fffffffffffffff..f.ffff.ffff..ffff.f.f.f..fffffffffffff..f.#af.ffff.aaa.a..f.f.f...ffffffffffff.",
".f....ff.f.................ffffffffffff..f....ff.f.................ffffffffffff..f.#af.fff...................ffffffffff.",
".ff.fff....eddddddddddddddd.....fffffff..f.fffff...ffffffffff.cdbb......fffffff..f.#af.....c.cc..bbbbbb..c......fffffff.",
".ff....bbbd.dbcbbbbbbbbbcbdedbbb....fff..f....f.bc.fdddddddf.cdbb.d..f.....ffff..f.#af..cbbcc.cc..bbbb..c......b....fff.",
"...bbbb...deedbbcbbcbbcbbbd.dbb.bbbb.....f.fff.fbbc.fffffff.cdbb.d..f..dd.c..ff..........cbbcc.cc......c.....bbbdfff....",
".bb....c.ccdeedbbbcccbbbbdedbb.bbb..cc...ff...c.fbbc.fdddf.cdbb.d..f..dd.cccd.f...ffff...dcbbcc.cc....cc...ddbbbdfddddf.",
"...cc.c....bd.dbcbbcbbcbbd.db.bb..cbc.b..ff.dccc.bbc.ffff.cdbb.dd..ff...cdcdfd.........f.dcbbacc.cccccc..fdcbdbbdffddff.",
"..c....bbbbbdeddddddddddddedbb..cccc.bb..f..fdcdc.bbc.ff.cdbb.dddd..ff.cccdffdc...ffff.f.dcbbcacc.c...c.fdccccdbdffddff.",
"...bb.bb....bbbbbbbbbbbbbbbb..ccbbc.bb....ffdfdccc.bbc..cdbb..........cccdfdfbc........f.dcbbccacc.ccb.fdddbdbdbddffffd.",
".bbb.b..ccc.d.d.d.d.dd.d.d.d.cccbb.bb.b..cbdfffdccc.fdfdfdfdfdfdfdfd.cccdfffbbc...ffff.f.dcbbacca.bcdcc.caddddcddff..ff.",
".bb.bb.ccbcd.d.d.d.ff.d.d.d.dcbcc.bb.bb..cbbddddcdc.dbdbdbdbdbdbdbdb.cdcddddbbc.........ddcddaacc.cdddc.ccaddcdd........",
".b.bb.bbccc.d.d.d.dd.d.d.d.d.ccc.bb.bbb..cbbfffdccc.fdfdfdfdfdfdfdfd.cccdfffdbc..ff..ffddcddddaac.ccdcb.accbbcd.f.ffff..",
"..bb.cbbcc..bbbbbbbbbbbbbbbb....b..bb....cbfdfdccc..........bbdc..cbb.cccdfdff...dffffddcdbdbddaac.bcc.ccacbbcd.f.......",
".bb.cccc..bbdeddddddddddddedbbbbb....c...cdffdccc.ff..dddd.bbdc.ff.cbb.cdcdff.f..ffddffdbdccccdfa.c...c.ccabbcd.f.ffff..",
".b.cbc..bb.bd.dbbcbbcbbcbd.db....c.cc.....dfdcdc...ff..dd.bbdc.ffff.cbb.cccd.ff..ffddffdbbdbcdff..cccccc.ccbbcd.f.......",
"..cc..bbb.bbdedbbbbcccbbbdeedcc.c....bb..f.dccc.dd..f..d.bbdc.fdddf.cbbf.c...ff..fddddfdbbbddf...cc....cc.cbbcd...ffff..",
"....bbbb.bbd.dbbbcbbcbbcbbdeed...bbbb....ff..c.dd..f..d.bbdc.fffffff.cbbf.fff.f.....fffdbbb......c......cc.cbbc.........",
".fff....bbbdedbcbbbbbbbbbcbd.dbbb....ff..ffff.....f..d.bbdc.fdddddddf.cb.f....f..fff....bb......c..bbbb..cc.cbbc..fa#.f.",
".fffffff.....ddddddddddddddde....fff.ff..fffffff......bbdc.ffffffffff...fffff.f..fffffff.......c..bbbbbb..cc......fa#.f.",
".ffffffffffff.................f.ff....f..ffffffffffff.................f.ff....f..ffffffffff...................fff.fa#.f.",
".fffffffffffffff.c.c.fffff.fffff.ffff.f..fffffffffffff..f.f.f.ffff..ffff.ffff.f..ffffffffffff...f.f.f..a.aaa.ffff.fa#.f.",
".ffffffffffffffff.c.c.ffff.ffffff....ff..fffffffffffff...f.f.ffffff.fffff....ff..fffffffffffff..f....f...a....fff.fa#.f.",
".ffffffffffffffff.c.c.ff...ffffff.cbc.f..ffffffffffffff...f.ffbbbbff.ffffff.fff..fffffffffffff.ffffffff..a.f..fff.fa#.f.",
".ffffffffffffffff.c.c.ff###..ffff.cbc.f..fffffffffffffff.b..ffffffff.fffff.c.ff..fffffffffffff.fff..ffff.a.ffffff.fa#.f.",
".ffffffffffffffff.c.c.ffffff.fffff.c.ff..fffffffffffffff..b.fff..fff.fffff.c.ff..fffffffffffff.fff.fffff.a.ffffff.fa#.f.",
".ffffffffffffffff.c.c.fffff.fffff.cbc.f..fffffffffffffff....ffff.fff.fffff.c.ff..fffffffffffff.ffff.ffff.a.ffffff.fa#.f.",
".ffffffffffffffff.c.c.ff.f.ffffff.cbc.f..fffffffffffffff.b..ffff.fff.fffff.c.ff..fffffffffffff.f..fff..f.a.ffffff.fa#.f.",
".ffffffffffffffff.c.c.f..f.fffffff.c.ff..ffffffffffffff..bb.f..ff..f.ffffff.fff..ffffffffffffff.f.fff.ff.a.ffffff.fa#.f.",
".fffffffffffffffff.c.c.fff.ffffff.cbc.f..fffffffffffff.c.cbb.f.ff.f..fffff.b.ff..ffffffffffffff............ffffff.fa#.f.",
".fffffffffffffffff........fffffff.cbc.f..fffffffffffff..c..bb.ffff.f.fffff.b.ff..ffffffffffffff.bbbbbbbbbb.ffffff.fa#.f.",
".ffffffffffffffff.bbbbbbbb.fffffff.c.ff..ffffffffffffff.c..cbb.ff.f..ffffff.fff..fffffffffffff.bbcccbbbccbb.ffffff.a.ff.",
".fffffffffffffff.b.bb.bb.bb.fffffff.fff..ffffffffffffff..cc.cbb..f..fffffffffff..ffffffffffff.bbcccccbccccbb.ffffff.fff.",
"........................................................................................................................"
};

305
demos/forty/pile.cpp Normal file
View File

@@ -0,0 +1,305 @@
/////////////////////////////////////////////////////////////////////////////
// Name: pile.cpp
// Purpose: Forty Thieves patience game
// Author: Chris Breeze
// Modified by:
// Created: 21/07/97
// RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze
// Licence: wxWindows licence
//---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWindows 2.0
/////////////////////////////////////////////////////////////////////////////
//+-------------------------------------------------------------+
//| Description: |
//| The base class for holding piles of playing cards. |
//+-------------------------------------------------------------+
#ifdef __GNUG__
#pragma implementation
#pragma interface
#endif
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#ifdef __GNUG__
#pragma implementation
#endif
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
#include "card.h"
#include "pile.h"
#include "wx/app.h"
//+-------------------------------------------------------------+
//| Pile::Pile() |
//+-------------------------------------------------------------+
//| Description: |
//| Initialise the pile to be empty of cards. |
//+-------------------------------------------------------------+
Pile::Pile(int x, int y, int dx, int dy)
{
m_x = x;
m_y = y;
m_dx = dx;
m_dy = dy;
for (m_topCard = 0; m_topCard < NumCards; m_topCard++)
{
m_cards[m_topCard] = 0;
}
m_topCard = -1; // i.e. empty
}
//+-------------------------------------------------------------+
//| Pile::Redraw() |
//+-------------------------------------------------------------+
//| Description: |
//| Redraw the pile on the screen. If the pile is empty |
//| just draw a NULL card as a place holder for the pile. |
//| Otherwise draw the pile from the bottom up, starting |
//| at the origin of the pile, shifting each subsequent |
//| card by the pile's x and y offsets. |
//+-------------------------------------------------------------+
void Pile::Redraw(wxDC& dc )
{
wxWindow *frame = wxTheApp->GetTopWindow();
wxWindow *canvas = (wxWindow *) NULL;
if (frame)
{
wxNode *node = frame->GetChildren().First();
if (node) canvas = (wxWindow*)node->Data();
}
if (m_topCard >= 0)
{
if (m_dx == 0 && m_dy == 0)
{
if ((canvas) && (canvas->IsExposed(m_x,m_y,60,200)))
m_cards[m_topCard]->Draw(dc, m_x, m_y);
}
else
{
int x = m_x;
int y = m_y;
for (int i = 0; i <= m_topCard; i++)
{
if ((canvas) && (canvas->IsExposed(x,y,60,200)))
m_cards[i]->Draw(dc, x, y);
x += m_dx;
y += m_dy;
}
}
}
else
{
if ((canvas) && (canvas->IsExposed(m_x,m_y,60,200)))
Card::DrawNullCard(dc, m_x, m_y);
}
}
//+-------------------------------------------------------------+
//| Pile::GetTopCard() |
//+-------------------------------------------------------------+
//| Description: |
//| Return a pointer to the top card in the pile or NULL |
//| if the pile is empty. |
//| NB: Gets a copy of the card without removing it from the |
//| pile. |
//+-------------------------------------------------------------+
Card* Pile::GetTopCard()
{
Card* card = 0;
if (m_topCard >= 0)
{
card = m_cards[m_topCard];
}
return card;
}
//+-------------------------------------------------------------+
//| Pile::RemoveTopCard() |
//+-------------------------------------------------------------+
//| Description: |
//| If the pile is not empty, remove the top card from the |
//| pile and return the pointer to the removed card. |
//| If the pile is empty return a NULL pointer. |
//+-------------------------------------------------------------+
Card* Pile::RemoveTopCard()
{
Card* card = 0;
if (m_topCard >= 0)
{
card = m_cards[m_topCard--];
}
return card;
}
//+-------------------------------------------------------------+
//| Pile::RemoveTopCard() |
//+-------------------------------------------------------------+
//| Description: |
//| As RemoveTopCard() but also redraw the top of the pile |
//| after the card has been removed. |
//| NB: the offset allows for the redrawn area to be in a |
//| bitmap ready for 'dragging' cards acrosss the screen. |
//+-------------------------------------------------------------+
Card* Pile::RemoveTopCard(wxDC& dc, int xOffset, int yOffset)
{
int topX, topY, x, y;
GetTopCardPos(topX, topY);
Card* card = RemoveTopCard();
if (card)
{
card->Erase(dc, topX - xOffset, topY - yOffset);
GetTopCardPos(x, y);
if (m_topCard < 0)
{
Card::DrawNullCard(dc, x - xOffset, y - yOffset);
}
else
{
m_cards[m_topCard]->Draw(dc, x - xOffset, y - yOffset);
}
}
return card;
}
void Pile::GetTopCardPos(int& x, int& y)
{
if (m_topCard < 0)
{
x = m_x;
y = m_y;
}
else
{
x = m_x + m_dx * m_topCard;
y = m_y + m_dy * m_topCard;
}
}
void Pile::AddCard(Card* card)
{
if (m_topCard < -1) m_topCard = -1;
m_cards[++m_topCard] = card;
}
void Pile::AddCard(wxDC& dc, Card* card)
{
AddCard(card);
int x, y;
GetTopCardPos(x, y);
card->Draw(dc, x, y);
}
// Can the card leave this pile.
// If it is a member of the pile then the answer is yes.
// Derived classes may override this behaviour to incorporate
// the rules of the game
bool Pile::CanCardLeave(Card* card)
{
for (int i = 0; i <= m_topCard; i++)
{
if (card == m_cards[i]) return TRUE;
}
return FALSE;
}
// Calculate how far x, y is from top card in the pile
// Returns the square of the distance
int Pile::CalcDistance(int x, int y)
{
int cx, cy;
GetTopCardPos(cx, cy);
return ((cx - x) * (cx - x) + (cy - y) * (cy - y));
}
// Return the card at x, y. Check the top card first, then
// work down the pile. If a card is found then return a pointer
// to the card, otherwise return NULL
Card* Pile::GetCard(int x, int y)
{
int cardX;
int cardY;
GetTopCardPos(cardX, cardY);
for (int i = m_topCard; i >= 0; i--)
{
if (x >= cardX && x <= cardX + CardWidth &&
y >= cardY && y <= cardY + CardHeight)
{
return m_cards[i];
}
cardX -= m_dx;
cardY -= m_dy;
}
return 0;
}
// Return the position of the given card. If it is not a member of this pile
// return the origin of the pile.
void Pile::GetCardPos(Card* card, int& x, int& y)
{
x = m_x;
y = m_y;
for (int i = 0; i <= m_topCard; i++)
{
if (card == m_cards[i])
{
return;
}
x += m_dx;
y += m_dy;
}
// card not found in pile, return origin of pile
x = m_x;
y = m_y;
}
bool Pile::Overlap(int x, int y)
{
int cardX;
int cardY;
GetTopCardPos(cardX, cardY);
if (x >= cardX - CardWidth && x <= cardX + CardWidth &&
y >= cardY - CardHeight && y <= cardY + CardHeight)
{
return TRUE;
}
return FALSE;
}
Pile::~Pile()
{
// nothing special at the moment
}

80
demos/forty/pile.h Normal file
View File

@@ -0,0 +1,80 @@
/////////////////////////////////////////////////////////////////////////////
// Name: pile.h
// Purpose: Forty Thieves patience game
// Author: Chris Breeze
// Modified by:
// Created: 21/07/97
// RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze
// Licence: wxWindows licence
//---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWindows 2.0
/////////////////////////////////////////////////////////////////////////////
//+-------------------------------------------------------------+
//| Description: |
//| The base class for holding piles of playing cards. |
//| This is the basic building block for card games. A pile |
//| has a position on the screen and an offset for each |
//| card placed on it e.g. a pack has no offset, but the |
//| discard pile may be fanned out across the screen. |
//| |
//| The pile knows how to draw itself, though this may be |
//| overridden if the default layout needs to be changed. |
//| One or more cards can be removed from the top of a pile, |
//| and single cards can be added to the top of a pile. |
//| Functions are provided which redraw the screen when |
//| cards are added or removed. |
//| |
//| Cards know which way up they are and how to draw |
//| themselves. Piles are lists of cards. Piles know which |
//| cards they contain and where they are to be drawn. |
//+-------------------------------------------------------------+
#ifndef _PILE_H_
#define _PILE_H_
#include "card.h"
const int NumCards = 2 * PackSize;
//----------------------------------------------------------------//
// A class defining a pile of cards with a position on the screen //
//----------------------------------------------------------------//
class Pile {
public:
Pile(int x, int y, int dx = 0, int dy = 0);
virtual ~Pile();
// General functions
virtual void ResetPile() { m_topCard = -1; }
virtual void Redraw(wxDC& pDC);
// Card query functions
virtual Card* GetCard(int x, int y); // Get pointer to card at x, y
Card* GetTopCard(); // Get pointer to top card
virtual void GetCardPos(Card* card, int& x, int& y);
// Get position of a card
virtual void GetTopCardPos(int& x, int& y);
// Get position of the top card
int GetNumCards() { return m_topCard + 1; } // Number of cards in pile
bool Overlap(int x, int y); // does card at x,y overlap the pile?
int CalcDistance(int x, int y); // calculates the square of the distance
// of a card at (x,y) from the top of the pile
// Functions removing one or more cards from the top of a pile
virtual bool CanCardLeave(Card* card);
Card* RemoveTopCard();
virtual Card* RemoveTopCard(wxDC& pDC, int xOffset = 0, int yOffset = 0);
// Functions to add a card to the top of a pile
virtual bool AcceptCard(Card*) { return FALSE; }
virtual void AddCard(Card* card); // Add card to top of pile
virtual void AddCard(wxDC& pDC, Card* card); // Add card + redraw it
protected:
int m_x, m_y; // Position of the pile on the screen
int m_dx, m_dy; // Offset when drawing the pile
Card* m_cards[NumCards]; // Array of cards in this pile
int m_topCard; // Array index of the top card
};
#endif // _PILE_H_

190
demos/forty/playerdg.cpp Normal file
View File

@@ -0,0 +1,190 @@
/////////////////////////////////////////////////////////////////////////////
// Name: playerdg.cpp
// Purpose: Forty Thieves patience game
// Author: Chris Breeze
// Modified by:
// Created: 21/07/97
// RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze
// Licence: wxWindows licence
//---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWindows 2.0
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation
#pragma interface
#endif
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include "scorefil.h"
#include "playerdg.h"
const int ID_LISTBOX = 101;
BEGIN_EVENT_TABLE(PlayerSelectionDialog, wxDialog)
EVT_SIZE(PlayerSelectionDialog::OnSize)
EVT_BUTTON(wxID_OK, PlayerSelectionDialog::ButtonCallback)
EVT_BUTTON(wxID_CANCEL, PlayerSelectionDialog::ButtonCallback)
EVT_LISTBOX(ID_LISTBOX, PlayerSelectionDialog::SelectCallback)
EVT_CLOSE(PlayerSelectionDialog::OnCloseWindow)
END_EVENT_TABLE()
PlayerSelectionDialog::PlayerSelectionDialog(
wxWindow* parent,
ScoreFile* file
) :
wxDialog(parent, -1, "Player Selection",
wxDefaultPosition, wxSize(320, 200),
wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE),
m_scoreFile(file)
{
// enable constraints
SetAutoLayout (TRUE);
wxStaticText* msg = new wxStaticText(this, -1, "Please select a name from the list");
wxListBox* list = new wxListBox(
this, ID_LISTBOX,
wxDefaultPosition, wxDefaultSize,
0, 0,
wxLB_SINGLE
);
wxArrayString players;
m_scoreFile->GetPlayerList(players);
for (unsigned int i = 0; i < players.Count(); i++)
{
list->Append(players[i]);
}
m_textField = new wxTextCtrl(this, -1, "", wxDefaultPosition, wxDefaultSize, 0);
m_OK = new wxButton(this, wxID_OK, "OK");
m_cancel = new wxButton(this, wxID_CANCEL, "Cancel");
wxLayoutConstraints* layout;
// Constrain the msg at the top of the window
layout = new wxLayoutConstraints;
layout->left.SameAs (this, wxLeft, 10);
layout->top.SameAs (this, wxTop, 10);
layout->height.AsIs();
layout->width.AsIs();
msg->SetConstraints(layout);
// Constrain the OK button
layout = new wxLayoutConstraints;
layout->left.SameAs (this, wxLeft, 10);
layout->bottom.SameAs (this, wxBottom, 10);
layout->height.AsIs();
layout->width.AsIs();
m_OK->SetConstraints(layout);
// Constrain the OK button
layout = new wxLayoutConstraints;
layout->left.RightOf (m_OK, 10);
layout->bottom.SameAs (this, wxBottom, 10);
layout->height.AsIs();
layout->width.AsIs();
m_cancel->SetConstraints(layout);
// Constrain the Name text entry field
layout = new wxLayoutConstraints;
layout->left.SameAs (this, wxLeft, 10);
layout->right.SameAs (this, wxRight, 10);
layout->bottom.SameAs (m_OK, wxTop, 10);
layout->height.AsIs();
m_textField->SetConstraints(layout);
// Constrain the list of players
layout = new wxLayoutConstraints;
layout->left.SameAs (this, wxLeft, 10);
layout->right.SameAs (this, wxRight, 10);
layout->top.Below (msg, 10);
layout->bottom.SameAs (m_textField, wxTop, 10);
list->SetConstraints(layout);
wxString prevPlayer = m_scoreFile->GetPreviousPlayer();
if (prevPlayer.Length() > 0)
{
list->SetStringSelection(prevPlayer);
m_textField->SetValue(prevPlayer);
}
Layout();
CentreOnParent();
}
PlayerSelectionDialog::~PlayerSelectionDialog()
{
}
void PlayerSelectionDialog::OnSize(wxSizeEvent& WXUNUSED(event))
{
Layout();
}
const wxString& PlayerSelectionDialog::GetPlayersName()
{
/*
m_player = "";
Show(TRUE);
*/
return m_player;
}
void PlayerSelectionDialog::OnCloseWindow(wxCloseEvent& event)
{
m_player = "";
EndModal(wxID_CANCEL);
}
void PlayerSelectionDialog::SelectCallback(wxCommandEvent& event)
{
if (event.GetEventType() == wxEVT_COMMAND_LISTBOX_SELECTED)
{
// if (event.IsSelection())
m_textField->SetValue(event.GetString());
}
}
void PlayerSelectionDialog::ButtonCallback(wxCommandEvent& event)
{
if (event.GetId() == wxID_OK)
{
wxString name = m_textField->GetValue();
if (!name.IsNull() && name.Length() > 0)
{
if (name.Contains('@'))
{
wxMessageBox("Names should not contain the '@' character", "Forty Thieves");
}
else
{
m_player = name;
EndModal(wxID_OK);
}
}
else
{
wxMessageBox("Please enter your name", "Forty Thieves");
}
}
else
{
m_player = "";
EndModal(wxID_CANCEL);
}
}

41
demos/forty/playerdg.h Normal file
View File

@@ -0,0 +1,41 @@
/////////////////////////////////////////////////////////////////////////////
// Name: playerdg.h
// Purpose: Forty Thieves patience game
// Author: Chris Breeze
// Modified by:
// Created: 21/07/97
// RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze
// Licence: wxWindows licence
//---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWindows 2.0
/////////////////////////////////////////////////////////////////////////////
#ifndef _PLAYERDG_H_
#define _PLAYERDG_H_
class PlayerSelectionDialog : public wxDialog
{
public:
PlayerSelectionDialog(wxWindow* parent, ScoreFile* file);
virtual ~PlayerSelectionDialog();
const wxString& GetPlayersName();
void ButtonCallback(wxCommandEvent& event);
void SelectCallback(wxCommandEvent& event);
void OnSize(wxSizeEvent& event);
DECLARE_EVENT_TABLE()
protected:
friend void SelectCallback(wxListBox&, wxCommandEvent&);
void OnCloseWindow(wxCloseEvent& event);
private:
ScoreFile* m_scoreFile;
wxString m_player;
wxButton* m_OK;
wxButton* m_cancel;
wxTextCtrl* m_textField;
};
#endif

86
demos/forty/readme.txt Normal file
View File

@@ -0,0 +1,86 @@
Forty Thieves is a patience game played with two full packs of
cards. At the start of the game forty cards are dealt on the
eight 'bases' along the top of the window. The object of the
game is to place all the cards onto the eight 'foundations'. The
foundations are built starting with the ace and adding cards of
the same suit up to the king. Cards are dealt from the pack and
placed on the discard pile. Cards may be moved from the discard
pile or one of the bases to a base or a foundation. Only one
card can be moved at a time. Cards can only be placed on a base
if the top card of the base is of the same suit and is one
higher in pip value or the base is empty e.g. the eight of
spades can only be placed on top of the nine of spades.
When the mouse cursor is over a card which can be moved it
changes to the 'hand' cursor. The card can then be moved by
double clicking the left button.
The mouse cursor also changes to a hand when a card is dragged
by placing the cursor over the card and holding down the left
button. This feature can be enabled and disabled by selecting
the 'Helping hand' option from the Edit menu.
The 'foundations' are the eight piles of cards down the left
side of the window. When the game starts these piles are empty.
The object of the game is to place all the cards on the
foundations. An ace can be placed on any empty foundation. Other
cards can only be placed on a foundation if the top card is of
the same suit and is one lower in pip value e.g. the three of
clubs can be placed on the four of clubs.
The 'bases' are the ten piles of cards along the top of the
window. At the start of the game four cards are dealt face up on
each of the bases. A card can be added to a base if the base is
empty or if the top card is of the same suit and is one higher
in pip value e.g. the queen of hearts can be placed on the king
of hearts The top card of a base can be moved onto another base
or a foundation.
Cards can be only moved one at a time. The top card of the pack
can be dealt onto discard pile by placing the mouse cursor over
the pack and pressing the left button. The number of cards
remaining is displayed to the right of the pack.
Cards can be moved from the discard pile or the bases either by
'double-clicking' or by dragging. If the left button is
double-clicked when the mouse cursor is over a card and it can
move to another pile, it will do so. This is a quick way of
moving cards when their destination is unambiguous.
A card can be dragged by placing the mouse cursor over the card
and holding down the left button. The card will follow the mouse
cursor until the left button is released. If the card is over a
pile on which it can be placed it will be added to that pile,
otherwise it will be returned to the pile from which it was
dragged.
One point is scored for every card that is placed on a
foundation. Since there are two packs of 52 cards the maximum
score is 104. A record is kept of the number of games played,
the number of games won, the current score and the average
score. This information is displayed at bottom right of the
window and is stored on disk between games. A game is deemed to
have started if the cards have been dealt and any card has been
moved. If the game is abandoned before it is finished (i.e. by
starting a new game or closing window) it counts as a lost game.
New players can be added by selecting the 'Player' option from
the Game menu. A summary of players' scores can be displayed by
selecting the 'Scores...' option from the Game menu.
All moves are recorded and can be undone. To undo a move select
the undo menu item from the Edit menu. A quicker way of undoing
is to press the right mouse button (it doesn't matter where the
mouse cursor is). Right button undo can be enabled and disabled
by selecting the 'Right button undo' option from the Edit menu.
Pressing the right mouse button with the control key pressed
re-does a previously undone move.
An empty base or two is very useful as it gives the opportunity
to unscramble other bases. Try not to build onto kings which
obscure valuable cards as it will be difficult to get to them
later. The undo facility is very useful for going back and using
'hindsight'.
Don't be put off if you can't win every game. I reckon winning 1
in 10 is pretty good (winning 1 in 3 is excellent).

192
demos/forty/scoredg.cpp Normal file
View File

@@ -0,0 +1,192 @@
/////////////////////////////////////////////////////////////////////////////
// Name: scoredg.cpp
// Purpose: Forty Thieves patience game
// Author: Chris Breeze
// Modified by:
// Created: 21/07/97
// RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze
// Licence: wxWindows licence
//---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWindows 2.0
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation
#pragma interface
#endif
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#if wxUSE_IOSTREAMH
#if defined(__WXMSW__) && !defined(__GNUWIN32__) && !defined(__MWERKS__)
#include <strstrea.h>
#else
#include <strstream.h>
#endif
#else
#include <strstream>
using namespace std;
#endif
#include "scorefil.h"
#include "scoredg.h"
class ScoreCanvas : public wxScrolledWindow
{
public:
ScoreCanvas(wxWindow* parent, ScoreFile* scoreFile);
virtual ~ScoreCanvas();
void OnDraw(wxDC& dc);
private:
wxFont* m_font;
wxString m_text;
};
ScoreCanvas::ScoreCanvas(wxWindow* parent, ScoreFile* scoreFile) :
wxScrolledWindow(parent)
{
#ifdef __WXGTK__
m_font = wxTheFontList->FindOrCreateFont(12, wxROMAN, wxNORMAL, wxNORMAL);
#else
m_font = wxTheFontList->FindOrCreateFont(10, wxSWISS, wxNORMAL, wxNORMAL);
#endif
wxArrayString players;
scoreFile->GetPlayerList( players);
ostrstream os;
os << "Player\tWins\tGames\tScore\n";
for (unsigned int i = 0; i < players.Count(); i++)
{
int wins, games, score;
scoreFile->ReadPlayersScore(players[i], wins, games, score);
int average = 0;
if (games > 0)
{
average = (2 * score + games) / (2 * games);
}
os << players[i] << '\t'
<< wins << '\t'
<< games << '\t'
<< average << '\n';
}
os << '\0';
char* str = os.str();
m_text = str;
delete str;
}
ScoreCanvas::~ScoreCanvas()
{
}
void ScoreCanvas::OnDraw(wxDC& dc)
{
dc.SetFont(* m_font);
const char* str = m_text;
unsigned int tab = 0;
unsigned int tabstops[] = { 5, 100, 150, 200 };
// get the line spacing for the current font
int lineSpacing;
{
long w, h;
dc.GetTextExtent("Testing", &w, &h);
lineSpacing = (int)h;
}
int y = 0;
while (*str)
{
char text[256];
char* dest = text;
while (*str && *str >= ' ') *dest++ = *str++;
*dest = '\0';
dc.DrawText(text, tabstops[tab], y);
if (*str == '\t')
{
if (tab < sizeof(tabstops) / sizeof(tabstops[0]) - 1)
{
tab++;
}
}
else if (*str == '\n')
{
tab = 0;
y += lineSpacing;
}
if (*str) str++;
}
}
BEGIN_EVENT_TABLE(ScoreDialog, wxDialog)
EVT_CLOSE(ScoreDialog::OnCloseWindow)
END_EVENT_TABLE()
ScoreDialog::ScoreDialog(
wxWindow* parent,
ScoreFile* file
) :
wxDialog(parent, -1, "Scores",
wxDefaultPosition, wxSize(310, 200),
wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE),
m_scoreFile(file)
{
// enable constraints
SetAutoLayout (TRUE);
ScoreCanvas* list = new ScoreCanvas(this, m_scoreFile);
m_OK = new wxButton(this, wxID_OK, "OK");
wxLayoutConstraints* layout;
// Constrain the OK button
layout = new wxLayoutConstraints;
layout->left.SameAs (this, wxLeft, 10);
layout->bottom.SameAs (this, wxBottom, 10);
layout->height.AsIs();
layout->width.AsIs();
m_OK->SetConstraints(layout);
// Constrain the list of players
layout = new wxLayoutConstraints;
layout->left.SameAs (this, wxLeft, 10);
layout->right.SameAs (this, wxRight, 10);
layout->top.SameAs (this, wxTop, 10);
layout->bottom.SameAs (m_OK, wxTop, 10);
list->SetConstraints(layout);
Layout();
}
ScoreDialog::~ScoreDialog()
{
}
void ScoreDialog::Display()
{
Show(TRUE);
}
void ScoreDialog::OnCloseWindow(wxCloseEvent& event)
{
EndModal(wxID_OK);
}

34
demos/forty/scoredg.h Normal file
View File

@@ -0,0 +1,34 @@
/////////////////////////////////////////////////////////////////////////////
// Name: scoredg.h
// Purpose: Forty Thieves patience game
// Author: Chris Breeze
// Modified by:
// Created: 21/07/97
// RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze
// Licence: wxWindows licence
//---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWindows 2.0
/////////////////////////////////////////////////////////////////////////////
#ifndef _SCOREDG_H_
#define _SCOREDG_H_
class ScoreDialog : public wxDialog
{
public:
ScoreDialog(wxWindow* parent, ScoreFile* file);
virtual ~ScoreDialog();
void Display();
protected:
void OnCloseWindow(wxCloseEvent& event);
private:
ScoreFile* m_scoreFile;
wxButton* m_OK;
DECLARE_EVENT_TABLE()
};
#endif

183
demos/forty/scorefil.cpp Normal file
View File

@@ -0,0 +1,183 @@
/////////////////////////////////////////////////////////////////////////////
// Name: scorefil.cpp
// Purpose: Forty Thieves patience game
// Author: Chris Breeze
// Modified by:
// Created: 21/07/97
// RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze
// Licence: wxWindows licence
//---------------------------------------------------------------------------
// Last modified: 14th May 1998 - ported to wxWindows 2.0
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation
#pragma interface
#endif
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#ifdef __WXGTK__
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#endif
#include "wx/textfile.h"
#include "wx/config.h"
#include "wx/fileconf.h"
#include "scorefil.h"
ScoreFile::ScoreFile(const char* appName)
{
#if 0
wxString filename;
m_configFilename << "/usr/local/share/" << appName << ".scores";
if (access(m_configFilename, F_OK) == 0)
{
if (access(m_configFilename, R_OK | W_OK) != 0)
{
// file is not r/w - use local file instead
m_configFilename = wxFileConfig::GetLocalFileName(appName);
}
}
else
{
int fd = creat(m_configFilename, 0666);
if (fd < 0)
{
// failed to create file - use local file instead
m_configFilename = wxFileConfig::GetLocalFileName(appName);
}
else
{
// ensure created file has rw-rw-rw permissions
close(fd);
}
}
#endif
m_config = new wxConfig(appName, "wxWindows", appName, "", wxCONFIG_USE_LOCAL_FILE); // only local
}
ScoreFile::~ScoreFile()
{
delete m_config;
#ifdef __WXGTK__
// ensure score file has rw-rw-rw permissions
// (wxFileConfig sets them to rw-------)
chmod(m_configFilename, 0666);
#endif
}
void ScoreFile::GetPlayerList( wxArrayString &list )
{
m_config->SetPath("/Players");
int length = m_config->GetNumberOfGroups();
if (length <= 0) return;
wxString player;
long index, i = 0;
if (m_config->GetFirstGroup(player, index))
{
list.Add( player );
i++;
while (m_config->GetNextGroup(player, index))
{
list.Add( player );
i++;
}
}
}
// Calculate an encrypted check number to prevent tampering with
// score file
long ScoreFile::CalcCheck(const char* name, int p1, int p2, int p3)
{
long check = 0;
while (*name)
{
check = (check << 1) ^ (long)*name++;
check = ((check >> 23) ^ check) & 0xFFFFFF;
}
check = (check << 1) ^ (long)p1;
check = ((check >> 23) ^ check) & 0xFFFFFF;
check = (check << 1) ^ (long)p2;
check = ((check >> 23) ^ check) & 0xFFFFFF;
check = (check << 1) ^ (long)p3;
check = ((check >> 23) ^ check) & 0xFFFFFF;
return check;
}
wxString ScoreFile::GetPreviousPlayer() const
{
wxString result;
m_config->SetPath("/General");
m_config->Read("LastPlayer", &result);
return result;
}
void ScoreFile::ReadPlayersScore(
const char* player,
int& wins,
int& games,
int& score)
{
long check = 0;
long myWins = 0, myGames = 0, myScore = 0;
games = wins = score = 0;
m_config->SetPath("/Players");
m_config->SetPath(player);
if (m_config->Read("Score", &myScore, 0L) &&
m_config->Read("Games", &myGames, 0L) &&
m_config->Read("Wins", &myWins, 0L) &&
m_config->Read("Check", &check, 0L))
{
if (check != CalcCheck(player, myGames, myWins, myScore))
{
wxMessageBox("Score file corrupted", "Warning",
wxOK | wxICON_EXCLAMATION);
}
else
{
games = myGames;
wins = myWins;
score = myScore;
}
}
WritePlayersScore(player, wins, games, score);
}
void ScoreFile::WritePlayersScore(const char* player, int wins, int games, int score)
{
if (player)
{
m_config->SetPath("/General");
m_config->Write("LastPlayer", wxString(player)); // Without wxString tmp, thinks it's bool in VC++
m_config->SetPath("/Players");
m_config->SetPath(player);
m_config->Write("Score", (long)score);
m_config->Write("Games", (long)games);
m_config->Write("Wins", (long)wins);
m_config->Write("Check", CalcCheck(player, games, wins, score));
}
}

37
demos/forty/scorefil.h Normal file
View File

@@ -0,0 +1,37 @@
/////////////////////////////////////////////////////////////////////////////
// Name: scorefil.h
// Purpose: Forty Thieves patience game
// Author: Chris Breeze
// Modified by:
// Created: 21/07/97
// RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze
// Licence: wxWindows licence
//---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWindows 2.0
/////////////////////////////////////////////////////////////////////////////
#ifndef _SCOREFILE_H_
#define _SCOREFILE_H_
#include <wx/config.h>
class wxConfig;
class ScoreFile {
public:
ScoreFile(const char* appName);
virtual ~ScoreFile();
void GetPlayerList( wxArrayString &list );
wxString GetPreviousPlayer() const;
void ReadPlayersScore(const char* player, int& wins, int& games, int &score);
void WritePlayersScore(const char* player, int wins, int games, int score);
private:
long CalcCheck(const char* name, int p1, int p2, int p3);
wxString m_configFilename;
wxConfig* m_config;
};
#endif

BIN
demos/forty/symbols.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 662 B

37
demos/forty/symbols.xbm Normal file
View File

@@ -0,0 +1,37 @@
#define Symbols_width 79
#define Symbols_height 50
static char Symbols_bits[] = {
0x08,0x84,0x0d,0x01,0x00,0x00,0x00,0x00,0x00,0x80,0x1c,0xce,0x9f,0x03,0x00,
0x00,0x00,0x00,0x00,0x80,0x2a,0xdf,0xdf,0x07,0x00,0x00,0x00,0x00,0x00,0x80,
0xff,0xff,0xff,0x0f,0x00,0x00,0x00,0x00,0x00,0x80,0x2a,0x9f,0xcf,0x07,0x00,
0x00,0x00,0x00,0x00,0x80,0x08,0x0e,0x07,0x01,0x00,0x00,0x00,0x00,0x00,0x80,
0x1c,0x04,0x82,0x03,0x00,0x00,0x00,0x00,0x00,0x80,0x1c,0x04,0x82,0x03,0x00,
0x00,0x00,0x00,0x00,0x80,0x08,0x0e,0x07,0x01,0x00,0x00,0x00,0x00,0x00,0x80,
0x2a,0x9f,0xcf,0x07,0x00,0x00,0x00,0x00,0x00,0x80,0xff,0xff,0xff,0x0f,0x00,
0x00,0x00,0x00,0x00,0x80,0x2a,0xdf,0xdf,0x07,0x00,0x00,0x00,0x00,0x00,0x80,
0x1c,0xce,0x9f,0x03,0x00,0x00,0x00,0x00,0x00,0x80,0x08,0x84,0x0d,0x01,0x00,
0x00,0x00,0x00,0x00,0x80,0x70,0x00,0x01,0x63,0x40,0x00,0x00,0x00,0x00,0x80,
0xf8,0x80,0x83,0xf7,0xe0,0x00,0x00,0x00,0x00,0x80,0xf8,0x80,0xc3,0xff,0xf1,
0x01,0x00,0x00,0x00,0x80,0x70,0xc0,0xc7,0xff,0xf9,0x03,0x00,0x00,0x00,0x80,
0x26,0xe3,0xcf,0xff,0xfd,0x07,0x00,0x00,0x00,0x80,0xaf,0xf7,0xdf,0xff,0xff,
0x0f,0x00,0x00,0x00,0x80,0xff,0xe7,0x8f,0xff,0xfe,0x0f,0x00,0x00,0x00,0x80,
0xaf,0xc7,0x07,0x7f,0x5e,0x0f,0x00,0x00,0x00,0x80,0x26,0x83,0x03,0x3e,0x4c,
0x06,0x00,0x00,0x00,0x80,0x70,0x80,0x03,0x1c,0xe0,0x00,0x00,0x00,0x00,0x80,
0xfc,0x01,0x01,0x08,0xf8,0x03,0x00,0x00,0x00,0x80,0xfc,0x01,0x01,0x08,0xf8,
0x03,0x00,0x00,0x00,0x80,0x70,0x80,0x03,0x1c,0xe0,0x00,0x00,0x00,0x00,0x80,
0x26,0x83,0x03,0x3e,0x4c,0x06,0x00,0x00,0x00,0x80,0xaf,0xc7,0x07,0x7f,0x5e,
0x0f,0x00,0x00,0x00,0x80,0xff,0xe7,0x8f,0xff,0xfe,0x0f,0x00,0x00,0x00,0x80,
0xaf,0xf7,0xdf,0xff,0xff,0x0f,0x00,0x00,0x00,0x80,0x26,0xe3,0xcf,0xff,0xfd,
0x07,0x00,0x00,0x00,0x80,0x70,0xc0,0xc7,0xff,0xf9,0x03,0x00,0x00,0x00,0x80,
0xf8,0x80,0xc3,0xff,0xf1,0x01,0x00,0x00,0x00,0x80,0xf8,0x80,0x83,0xf7,0xe0,
0x00,0x00,0x00,0x00,0x80,0x70,0x00,0x01,0x63,0x40,0x00,0x00,0x00,0x00,0x80,
0x0c,0xe7,0x43,0x3e,0xe7,0x73,0x5c,0xe6,0x73,0xa2,0x92,0x08,0x61,0x82,0x00,
0x8a,0x62,0x09,0x89,0x92,0x21,0x88,0x50,0x9e,0x00,0x89,0x62,0x09,0x89,0x8a,
0x21,0xc6,0x49,0xa0,0x87,0x70,0x7c,0x09,0x89,0x86,0x3f,0x01,0xfa,0xa0,0x88,
0x88,0x60,0x09,0xa9,0x8a,0xa1,0x20,0x42,0xa2,0x88,0x88,0x50,0x29,0x49,0x92,
0xa1,0xcf,0x41,0x1c,0x87,0x70,0x48,0xc6,0xb0,0xa2,0xa1,0xcf,0x11,0x1c,0x87,
0x70,0x88,0x89,0x69,0xa2,0x21,0x28,0x12,0xa2,0x88,0x88,0x44,0x4a,0x92,0xa4,
0x3f,0x24,0xf8,0x82,0x88,0x88,0x42,0x4a,0xa8,0xa8,0x21,0xc3,0x91,0x82,0x8f,
0x70,0x5e,0x4a,0x88,0xb0,0xa1,0x80,0x50,0x3c,0x48,0x88,0x62,0x4a,0x88,0xa8,
0x92,0x48,0x30,0x20,0x28,0x88,0x62,0x4a,0x88,0xa4,0x0c,0xe7,0x13,0x3e,0xe7,
0x73,0x9c,0xe9,0x73,0xa2};

60
demos/forty/symbols.xpm Normal file
View File

@@ -0,0 +1,60 @@
/* XPM */
static char *symbols[] = {
/* width height num_colors chars_per_pixel */
" 79 50 3 1",
/* colors */
". c #ffffff",
"* c #ff0000",
"# c #000000",
/* pixels */
"...#......*....**.**....#......................................................",
"..###....***..*******..###.....................................................",
".#.#.#..*****.*******.#####....................................................",
"#######**************#######...................................................",
".#.#.#..*****..*****..#####....................................................",
"...#.....***....***.....#......................................................",
"..###.....*......*.....###.....................................................",
"..###.....*......*.....###.....................................................",
"...#.....***....***.....#......................................................",
".#.#.#..*****..*****..#####....................................................",
"#######**************#######...................................................",
".#.#.#..*****.*******.#####....................................................",
"..###....***..*******..###.....................................................",
"...#......*....**.**....#......................................................",
"....###.........*.......**...**.......#........................................",
"...#####.......***.....****.****.....###.......................................",
"...#####.......***....***********...#####......................................",
"....###.......*****...***********..#######.....................................",
".##..#..##...*******..***********.#########....................................",
"####.#.####.*********.***********###########...................................",
"###########..*******...*********.###########...................................",
"####.#.####...*****.....*******..####.#.####...................................",
".##..#..##.....***.......*****....##..#..##....................................",
"....###........***........***........###.......................................",
"..#######.......*..........*.......#######.....................................",
"..#######.......*..........*.......#######.....................................",
"....###........***........***........###.......................................",
".##..#..##.....***.......*****....##..#..##....................................",
"####.#.####...*****.....*******..####.#.####...................................",
"###########..*******...*********.###########...................................",
"####.#.####.*********.***********###########...................................",
".##..#..##...*******..***********.#########....................................",
"....###.......*****...***********..#######.....................................",
"...#####.......***....***********...#####......................................",
"...#####.......***.....****.****.....###.......................................",
"....###.........*.......**...**.......#........................................",
"..##....###..#####....#..#####..###..#####..###...###.#..##..#####..###..#...#.",
".#..#..#...#....#....##..#.....#.........#.#...#.#...##.#..#....#..#...#.#..#..",
"#....#.....#...#....#.#..####..#........#..#...#.#...##.#..#....#..#...#.#.#...",
"#....#...##...###..#..#......#.####....#....###...#####.#..#....#..#...#.##....",
"######..#........#.#####.....#.#...#...#...#...#.....##.#..#....#..#.#.#.#.#...",
"#....#.#.....#...#....#..#...#.#...#...#...#...#....#.#.#..#.#..#..#..#..#..#..",
"#....#.#####..###.....#...###...###....#....###....#..#..##...##....##.#.#...#.",
"#....#.#####..###...#.....###...###....#....###....#...##..#...##..#.##..#...#.",
"#....#.....#.#...#..#....#...#.#...#...#...#...#..#...#..#.#..#..#..#..#..#..#.",
"######....#..#.....#####.#.....#...#...#...#...#.#....#..#.#..#....#.#.#...#.#.",
"#....#..##....###...#..#.#.....#####...#....###..####.#..#.#..#....#...#....##.",
"#....#.#.......#....#.#...####.....#..#....#...#.#...##..#.#..#....#...#...#.#.",
".#..#..#...#..#.....##.......#.....#.#.....#...#.#...##..#.#..#....#...#..#..#.",
"..##....###..#####..#....#####..###..#####..###...###..##..#.#####..###..#...#."
};

1
demos/fractal/.cvsignore Normal file
View File

@@ -0,0 +1 @@

21
demos/fractal/Makefile.in Normal file
View File

@@ -0,0 +1,21 @@
#
# File: Makefile.in
# Author: Julian Smart
# Created: 1998
# Updated:
# Copyright: (c) 1998 Julian Smart
#
# "%W% %G%"
#
# Makefile for fractal example (UNIX).
top_srcdir = @top_srcdir@
top_builddir = ../..
program_dir = demos/fractal
PROGRAM=fractal
OBJECTS=$(PROGRAM).o
include ../../src/makeprog.env

251
demos/fractal/fractal.cpp Normal file
View File

@@ -0,0 +1,251 @@
///////////////////////////////////////////////////////////////////////////////
// Name: fractal.cpp
// Purpose: demo of wxConfig and related classes
// Author: Andrew Davison
// Modified by:
// Created: 05.04.94
// RCS-ID: $Id$
// Copyright: (c) 1994 Andrew Davison
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
/*
Date: Tue, 5 Apr 1994 12:01:18 +1000
From: Andrew Davison <andrewd@au.com.sfe>
To: wxwin-users@ed.aiai
Subject: Fractal mountains
Hi,
This is a quick port of a fractal mountain generator originally
done for MS-Windows. On a Sun the colours look a little washed
out and there is not as much snow or high mountains (maybe the
random number generators fault). The viewing plane is not
quite right as the original code used SetViewportOrg() which there
doesn't seem to be an equivalent of under wxWindows, and my quick
hack doesn't fix.
*/
#ifdef __GNUG__
#pragma implementation
#pragma interface
#endif
#include "wx/wxprec.h"
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif //precompiled headers
#include <stdlib.h>
#include <math.h>
#include <time.h>
#define Random(x) (rand() % x)
#define Randomize() (srand((unsigned int)time(NULL)))
static int detail = 9; // CHANGE THIS... 7,8,9 etc
static bool running = FALSE;
static wxMenuBar *menuBar = NULL;
// Define a new application type
class MyApp: public wxApp
{ public:
bool OnInit();
};
IMPLEMENT_APP(MyApp)
// Define a new frame type
class MyFrame: public wxFrame
{
public:
MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size);
void OnCloseWindow(wxCloseEvent& event);
void OnExit(wxCommandEvent& event);
DECLARE_EVENT_TABLE()
};
// Define a new canvas which can receive some events
class MyCanvas: public wxWindow
{
public:
MyCanvas(wxFrame *frame);
void Draw(wxDC& dc);
private:
void OnPaint(wxPaintEvent& event);
void Fractal(wxDC& dc, int X1, int Y1, int X2, int Y2, int Z1, int Z2, int Z3, int Z4, int Iteration, double Std, double Ratio);
wxPen SnowPen, MtnPen, GreenPen;
wxBrush WaterBrush;
int Sealevel;
DECLARE_EVENT_TABLE()
};
// `Main program' equivalent, creating windows and returning main app frame
bool MyApp::OnInit()
{
// Create the main frame window
MyFrame *frame = new MyFrame(NULL, "Fractal Mountains for wxWindows", wxPoint(-1, -1), wxSize(640, 480));
// Make a menubar
wxMenu *file_menu = new wxMenu;
file_menu->Append(wxID_EXIT, "E&xit");
menuBar = new wxMenuBar;
menuBar->Append(file_menu, "&File");
frame->SetMenuBar(menuBar);
int width, height;
frame->GetClientSize(&width, &height);
(void) new MyCanvas(frame);
// Show the frame
frame->Show(TRUE);
return TRUE;
}
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_CLOSE(MyFrame::OnCloseWindow)
EVT_MENU(wxID_EXIT, MyFrame::OnExit)
END_EVENT_TABLE()
// My frame constructor
MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size):
wxFrame(frame, -1, title, pos, size)
{
}
// Intercept menu commands
void MyFrame::OnExit(wxCommandEvent& event)
{
this->Destroy();
}
void MyFrame::OnCloseWindow(wxCloseEvent& event)
{
static bool destroyed = FALSE;
if (destroyed)
return;
this->Destroy();
destroyed = TRUE;
}
BEGIN_EVENT_TABLE(MyCanvas, wxWindow)
EVT_PAINT(MyCanvas::OnPaint)
END_EVENT_TABLE()
// Define a constructor for my canvas
MyCanvas::MyCanvas(wxFrame *frame):
wxWindow(frame, -1)
{
wxColour wxCol1(255,255,255);
SnowPen = wxPen(wxCol1, 2, wxSOLID);
wxColour wxCol2(128,0,0);
MtnPen = wxPen(wxCol2, 1, wxSOLID);
wxColour wxCol3(0,128,0);
GreenPen = wxPen(wxCol3, 1, wxSOLID);
wxColour wxCol4(0,0,128);
WaterBrush = wxBrush(wxCol4, wxSOLID);
}
void MyCanvas::OnPaint(wxPaintEvent& event)
{
wxPaintDC dc(this);
Draw(dc);
}
void MyCanvas::Draw(wxDC& dc)
{
if (running) return;
running = TRUE;
menuBar->EnableTop(0, FALSE);
Randomize();
int Left, Top, Right, Bottom;
GetClientSize(&Right, &Bottom);
Right *= 3; Right /= 4;
Bottom *= 3; Bottom /= 4;
Left = 0;
Top = Bottom/8;
wxPoint Water[4];
Water[0].x = Left; Water[0].y = Top;
Water[1].x = Right; Water[1].y = Top;
Water[2].x = Right+Bottom/2; Water[2].y = Bottom;
Water[3].x = Bottom/2; Water[3].y = Bottom;
dc.SetBrush(WaterBrush);
dc.DrawPolygon(4, Water);
double H = 0.75;
double Scale = Bottom;
double Ratio = 1.0 / pow(2.0, H);
double Std = Scale * Ratio;
Sealevel = Random(18) - 8;
Fractal(dc, Left, Top, Right, Bottom, 0, 0, 0, 0, detail, Std, Ratio);
menuBar->EnableTop(0, TRUE);
running = FALSE;
}
void MyCanvas::Fractal(wxDC& dc, int X1, int Y1, int X2, int Y2, int Z1, int Z2, int Z3, int Z4, int Iteration, double Std, double Ratio)
{
int Xmid = (X1 + X2) / 2;
int Ymid = (Y1 + Y2) / 2;
int Z23 = (Z2 + Z3) / 2;
int Z41 = (Z4 + Z1) / 2;
int Newz = (int)((Z1 + Z2 + Z3 + Z4) / 4 + (double)(Random(17) - 8) / 8.0 * Std);
if (--Iteration)
{
int Z12 = (Z1 + Z2) / 2;
int Z34 = (Z3 + Z4) / 2;
double Stdmid = Std * Ratio;
Fractal(dc, Xmid, Y1, X2, Ymid, Z12, Z2, Z23, Newz, Iteration, Stdmid, Ratio);
Fractal(dc, X1, Y1, Xmid, Ymid, Z1, Z12, Newz, Z41, Iteration, Stdmid, Ratio);
Fractal(dc, Xmid, Ymid, X2, Y2, Newz, Z23, Z3, Z34, Iteration, Stdmid, Ratio);
Fractal(dc, X1, Ymid, Xmid, Y2, Z41, Newz, Z34, Z4, Iteration, Stdmid, Ratio);
}
else
{
if (Newz <= Sealevel)
{
wxPoint P[4];
P[0].x = Y1 / 2 + X1; P[0].y = Y1 + Z1;
P[1].x = Y1 / 2 + X2; P[1].y = Y1 + Z2;
P[2].x = Y2 / 2 + X2; P[2].y = Y2 + Z3;
P[3].x = Y2 / 2 + X1; P[3].y = Y2 + Z4;
dc.SetPen(* wxBLACK_PEN);
dc.SetBrush(* wxBLACK_BRUSH);
dc.DrawPolygon(4, P);
if (Z1 >= -(60+Random(25)))
dc.SetPen(GreenPen);
else if (Z1 >= -(100+Random(25)))
dc.SetPen(MtnPen);
else
dc.SetPen(SnowPen);
dc.DrawLine(Ymid/2+X2, Ymid+Z23, Ymid/2+X1, Ymid+Z41);
}
}
}

View File

@@ -0,0 +1,9 @@
NAME Fractal
DESCRIPTION 'Fractal'
EXETYPE WINDOWS
STUB 'WINSTUB.EXE'
CODE PRELOAD MOVEABLE DISCARDABLE
DATA PRELOAD MOVEABLE MULTIPLE
HEAPSIZE 1024
STACKSIZE 16192

4
demos/fractal/fractal.rc Normal file
View File

@@ -0,0 +1,4 @@
wxSTD_FRAME ICON "mondrian.ico"
#include "wx/msw/wx.rc"

View File

@@ -0,0 +1,16 @@
#
# File: makefile.b32
# Author: Julian Smart
# Created: 1999
# Updated:
# Copyright:
#
# Makefile : Builds sample for 32-bit BC++
WXDIR = $(WXWIN)
TARGET=fractal
OBJECTS = $(TARGET).obj
!include $(WXDIR)\src\makeprog.b32

View File

@@ -0,0 +1,19 @@
#
# File: makefile.bcc
# Author: Julian Smart
# Created: 1998
# Updated:
#
# Builds a BC++ 16-bit sample
!if "$(WXWIN)" == ""
!error You must define the WXWIN variable in autoexec.bat, e.g. WXWIN=c:\wx
!endif
WXDIR = $(WXWIN)
TARGET=fractal
OBJECTS=$(TARGET).obj
!include $(WXDIR)\src\makeprog.bcc

View File

@@ -0,0 +1,17 @@
#
# File: makefile.dos
# Author: Julian Smart
# Created: 1998
# Updated:
#
# Makefile : Builds 16-bit sample, VC++ 1.5
# Use FINAL=1 argument to nmake to build final version with no debugging
# info
WXDIR = $(WXWIN)
TARGET=fractal
OBJECTS=$(TARGET).obj
!include $(WXDIR)\src\makeprog.msc

View File

@@ -0,0 +1,16 @@
#
# File: makefile.g95
# Author: Julian Smart
# Created: 1999
# Updated:
# Copyright: (c) Julian Smart, 1999
#
# Makefile for wxWindows sample (Cygwin/Mingw32).
WXDIR = ../..
TARGET=fractal
OBJECTS = $(TARGET).o
include $(WXDIR)/src/makeprog.g95

View File

@@ -0,0 +1,35 @@
#
# File: Makefile for samples
# Author: Robert Roebling
# Created: 1999
# Updated:
# Copyright: (c) 1998 Robert Roebling
#
# This makefile requires a Unix version of wxWindows
# to be installed on your system. This is most often
# done typing "make install" when using the complete
# sources of wxWindows or by installing the two
# RPM packages wxGTK.XXX.rpm and wxGTK-devel.XXX.rpm
# under Linux.
#
CC = gcc
PROGRAM = fractal
OBJECTS = $(PROGRAM).o
# implementation
.SUFFIXES: .o .cpp
.cpp.o :
$(CC) -c `wx-config --cflags` -o $@ $<
all: $(PROGRAM)
$(PROGRAM): $(OBJECTS)
$(CC) -o $(PROGRAM) $(OBJECTS) `wx-config --libs`
clean:
rm -f *.o $(PROGRAM)

18
demos/fractal/makefile.vc Normal file
View File

@@ -0,0 +1,18 @@
#
# File: makefile.vc
# Author: Julian Smart
# Created: 1999
# Updated:
# Copyright: (c) Julian Smart
#
# Makefile : Builds sample (VC++, WIN32)
# Use FINAL=1 argument to nmake to build final version with no debug info.
# Set WXDIR for your system
WXDIR = $(WXWIN)
PROGRAM=fractal
OBJECTS = $(PROGRAM).obj
!include $(WXDIR)\src\makeprog.vc

View File

@@ -0,0 +1,15 @@
#
# Makefile for WATCOM
#
# Created by Julian Smart, January 1999
#
#
WXDIR = $(%WXWIN)
PROGRAM = fractal
OBJECTS = $(PROGRAM).obj
!include $(WXDIR)\src\makeprog.wat

BIN
demos/fractal/mondrian.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 B

22
demos/life/Makefile.in Normal file
View File

@@ -0,0 +1,22 @@
#
# File: makefile.unx
# Author: Julian Smart
# Created: 1998
# Updated:
# Copyright: (c) 1998 Julian Smart
#
# "%W% %G%"
#
# Makefile for toolbar example (UNIX).
top_srcdir = @top_srcdir@
top_builddir = ../..
program_dir = demos/life
PROGRAM=life
OBJECTS=$(PROGRAM).o dialogs.o game.o
include ../../src/makeprog.env

BIN
demos/life/bitmaps/play.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 246 B

View File

@@ -0,0 +1,24 @@
/* XPM */
static char *play_xpm[] = {
/* columns rows colors chars-per-pixel */
"16 16 2 1",
" c None",
". c Black",
/* pixels */
" ",
" ",
" ",
" . ",
" ... ",
" ..... ",
" ....... ",
" ......... ",
" ....... ",
" ..... ",
" ... ",
" . ",
" ",
" ",
" ",
" "
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 822 B

View File

@@ -0,0 +1,24 @@
/* XPM */
static char *reset_xpm[] = {
/* columns rows colors chars-per-pixel */
"16 16 2 1",
" c None",
". c Black",
/* pixels */
" ",
" ",
" ",
" .. .. ",
" ... ... ",
" ... ... ",
" ...... ",
" .... ",
" .... ",
" ...... ",
" ... ... ",
" ... ... ",
" .. .. ",
" ",
" ",
" "
};

BIN
demos/life/bitmaps/stop.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 246 B

View File

@@ -0,0 +1,24 @@
/* XPM */
static char *stop_xpm[] = {
/* columns rows colors chars-per-pixel */
"16 16 2 1",
" c None",
". c Black",
/* pixels */
" ",
" ",
" ",
" ........ ",
" ........ ",
" ........ ",
" ........ ",
" ........ ",
" ........ ",
" ........ ",
" ........ ",
" ........ ",
" ",
" ",
" ",
" "
};

212
demos/life/dialogs.cpp Normal file
View File

@@ -0,0 +1,212 @@
/////////////////////////////////////////////////////////////////////////////
// Name: dialogs.cpp
// Purpose: Life! dialogs
// Author: Guillermo Rodriguez Garcia, <guille@iies.es>
// Modified by:
// Created: Jan/2000
// RCS-ID: $Id$
// Copyright: (c) 2000, Guillermo Rodriguez Garcia
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ==========================================================================
// declarations
// ==========================================================================
// --------------------------------------------------------------------------
// headers
// --------------------------------------------------------------------------
#ifdef __GNUG__
#pragma implementation "dialogs.h"
#endif
// for compilers that support precompilation, includes "wx/wx.h"
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
// for all others, include the necessary headers
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include "wx/statline.h"
#include "wx/spinctrl.h"
#include "dialogs.h"
#include "life.h"
#include "game.h"
// --------------------------------------------------------------------------
// constants
// --------------------------------------------------------------------------
// IDs for the controls and the menu commands
enum
{
// listbox in samples dialog
ID_LISTBOX = 2001
};
// sample configurations
#include "samples.inc"
// --------------------------------------------------------------------------
// event tables and other macros for wxWindows
// --------------------------------------------------------------------------
// Event tables
BEGIN_EVENT_TABLE(LifeNewGameDialog, wxDialog)
EVT_BUTTON (wxID_OK, LifeNewGameDialog::OnOK)
END_EVENT_TABLE()
BEGIN_EVENT_TABLE(LifeSamplesDialog, wxDialog)
EVT_LISTBOX (ID_LISTBOX, LifeSamplesDialog::OnListBox)
END_EVENT_TABLE()
// ==========================================================================
// implementation
// ==========================================================================
// --------------------------------------------------------------------------
// LifeNewGameDialog
// --------------------------------------------------------------------------
LifeNewGameDialog::LifeNewGameDialog(wxWindow *parent, int *w, int *h)
: wxDialog(parent, -1,
_("New game"),
wxDefaultPosition,
wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxDIALOG_MODAL)
{
m_w = w;
m_h = h;
// spin ctrls
m_spinctrlw = new wxSpinCtrl( this, -1 );
m_spinctrlw->SetValue(*m_w);
m_spinctrlw->SetRange(LIFE_MIN, LIFE_MAX);
m_spinctrlh = new wxSpinCtrl( this, -1 );
m_spinctrlh->SetValue(*m_h);
m_spinctrlh->SetRange(LIFE_MIN, LIFE_MAX);
// component layout
wxBoxSizer *inputsizer1 = new wxBoxSizer( wxHORIZONTAL );
inputsizer1->Add( new wxStaticText(this, -1, _("Width")), 1, wxCENTRE | wxLEFT, 20);
inputsizer1->Add( m_spinctrlw, 2, wxCENTRE | wxLEFT | wxRIGHT, 20 );
wxBoxSizer *inputsizer2 = new wxBoxSizer( wxHORIZONTAL );
inputsizer2->Add( new wxStaticText(this, -1, _("Height")), 1, wxCENTRE | wxLEFT, 20);
inputsizer2->Add( m_spinctrlh, 2, wxCENTRE | wxLEFT | wxRIGHT, 20 );
wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
topsizer->Add( CreateTextSizer(_("Enter board dimensions")), 0, wxALL, 10 );
topsizer->Add( new wxStaticLine(this, -1), 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 10);
topsizer->Add( inputsizer1, 1, wxGROW | wxLEFT | wxRIGHT, 5 );
topsizer->Add( inputsizer2, 1, wxGROW | wxLEFT | wxRIGHT, 5 );
topsizer->Add( new wxStaticLine(this, -1), 0, wxGROW | wxLEFT | wxRIGHT | wxTOP, 10);
topsizer->Add( CreateButtonSizer(wxOK | wxCANCEL), 0, wxCENTRE | wxALL, 10);
// activate
SetSizer(topsizer);
SetAutoLayout(TRUE);
topsizer->SetSizeHints(this);
topsizer->Fit(this);
Centre(wxBOTH);
}
void LifeNewGameDialog::OnOK(wxCommandEvent& WXUNUSED(event))
{
*m_w = m_spinctrlw->GetValue();
*m_h = m_spinctrlh->GetValue();
EndModal(wxID_OK);
}
// --------------------------------------------------------------------------
// LifeSamplesDialog
// --------------------------------------------------------------------------
LifeSamplesDialog::LifeSamplesDialog(wxWindow *parent)
: wxDialog(parent, -1,
_("Sample games"),
wxDefaultPosition,
wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxDIALOG_MODAL)
{
m_value = 0;
// create and populate the list of available samples
m_list = new wxListBox( this, ID_LISTBOX,
wxDefaultPosition,
wxDefaultSize,
0, NULL,
wxLB_SINGLE | wxLB_NEEDED_SB | wxLB_HSCROLL );
for (unsigned i = 0; i < (sizeof(g_shapes) / sizeof(LifeShape)); i++)
m_list->Append(g_shapes[i].m_name);
// descriptions
wxStaticBox *statbox = new wxStaticBox( this, -1, _("Description"));
m_life = new Life( 16, 16 );
m_life->SetShape(g_shapes[0]);
m_canvas = new LifeCanvas( this, m_life, FALSE );
m_text = new wxTextCtrl( this, -1,
g_shapes[0].m_desc,
wxDefaultPosition,
wxSize(300, 60),
wxTE_MULTILINE | wxTE_READONLY);
// layout components
wxStaticBoxSizer *sizer1 = new wxStaticBoxSizer( statbox, wxVERTICAL );
sizer1->Add( m_canvas, 2, wxGROW | wxCENTRE | wxALL, 5);
sizer1->Add( m_text, 1, wxGROW | wxCENTRE | wxALL, 5 );
wxBoxSizer *sizer2 = new wxBoxSizer( wxHORIZONTAL );
sizer2->Add( m_list, 0, wxGROW | wxCENTRE | wxALL, 5 );
sizer2->Add( sizer1, 1, wxGROW | wxCENTRE | wxALL, 5 );
wxBoxSizer *sizer3 = new wxBoxSizer( wxVERTICAL );
sizer3->Add( CreateTextSizer(_("Select one configuration")), 0, wxALL, 10 );
sizer3->Add( new wxStaticLine(this, -1), 0, wxGROW | wxLEFT | wxRIGHT, 10 );
sizer3->Add( sizer2, 1, wxGROW | wxCENTRE | wxALL, 5 );
sizer3->Add( new wxStaticLine(this, -1), 0, wxGROW | wxLEFT | wxRIGHT, 10 );
sizer3->Add( CreateButtonSizer(wxOK | wxCANCEL), 0, wxCENTRE | wxALL, 10 );
// activate
SetSizer(sizer3);
SetAutoLayout(TRUE);
sizer3->SetSizeHints(this);
sizer3->Fit(this);
Centre(wxBOTH);
}
LifeSamplesDialog::~LifeSamplesDialog()
{
m_canvas->Destroy();
delete m_life;
}
int LifeSamplesDialog::GetValue()
{
return m_value;
}
void LifeSamplesDialog::OnListBox(wxCommandEvent& event)
{
if (event.GetSelection() != -1)
{
m_value = m_list->GetSelection();
m_text->SetValue(g_shapes[ event.GetSelection() ].m_desc);
m_life->SetShape(g_shapes[ event.GetSelection() ]);
m_canvas->DrawEverything(TRUE); // force redraw everything
m_canvas->Refresh(FALSE); // do not erase background
}
}

92
demos/life/dialogs.h Normal file
View File

@@ -0,0 +1,92 @@
/////////////////////////////////////////////////////////////////////////////
// Name: dialogs.h
// Purpose: Life! dialogs
// Author: Guillermo Rodriguez Garcia, <guille@iies.es>
// Modified by:
// Created: Jan/2000
// RCS-ID: $Id$
// Copyright: (c) 2000, Guillermo Rodriguez Garcia
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _LIFE_DIALOGS_H_
#define _LIFE_DIALOGS_H_
#ifdef __GNUG__
#pragma interface "dialogs.h"
#endif
// for compilers that support precompilation, includes "wx/wx.h"
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
// for all others, include the necessary headers
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include "wx/spinctrl.h"
#include "life.h"
#include "game.h"
// sample configurations
extern LifeShape g_shapes[];
// --------------------------------------------------------------------------
// LifeNewGameDialog
// --------------------------------------------------------------------------
class LifeNewGameDialog : public wxDialog
{
public:
// ctor
LifeNewGameDialog(wxWindow *parent, int *w, int *h);
// event handlers
void OnOK(wxCommandEvent& event);
private:
// any class wishing to process wxWindows events must use this macro
DECLARE_EVENT_TABLE();
int *m_w;
int *m_h;
wxSpinCtrl *m_spinctrlw;
wxSpinCtrl *m_spinctrlh;
};
// --------------------------------------------------------------------------
// LifeSamplesDialog
// --------------------------------------------------------------------------
class LifeSamplesDialog : public wxDialog
{
public:
// ctor and dtor
LifeSamplesDialog(wxWindow *parent);
~LifeSamplesDialog();
// members
int GetValue();
// event handlers
void OnListBox(wxCommandEvent &event);
private:
// any class wishing to process wxWindows events must use this macro
DECLARE_EVENT_TABLE();
int m_value;
wxListBox *m_list;
wxTextCtrl *m_text;
LifeCanvas *m_canvas;
Life *m_life;
};
#endif // _LIFE_DIALOGS_H_

226
demos/life/game.cpp Normal file
View File

@@ -0,0 +1,226 @@
/////////////////////////////////////////////////////////////////////////////
// Name: game.cpp
// Purpose: Life! game logic
// Author: Guillermo Rodriguez Garcia, <guille@iies.es>
// Modified by:
// Created: Jan/2000
// RCS-ID: $Id$
// Copyright: (c) 2000, Guillermo Rodriguez Garcia
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ==========================================================================
// declarations
// ==========================================================================
// --------------------------------------------------------------------------
// headers
// --------------------------------------------------------------------------
#ifdef __GNUG__
#pragma implementation "game.h"
#endif
// for compilers that support precompilation, includes "wx/wx.h"
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
// for all others, include the necessary headers
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include "game.h"
// ==========================================================================
// implementation
// ==========================================================================
// --------------------------------------------------------------------------
// Life
// --------------------------------------------------------------------------
/* Format of the cell: (32 bit integer)
*
* 0yyyyyyy yyyyyy0x xxxxxxxxx xxx000ff
*
* y = y coordinate (13 bits)
* x = x coordinate (13 bits)
* f = flags (2 bits)
*
* OK, there is a reason for this, I promise :-). But I won't explain
* it now; it will be more clear when I implement the optimized life
* algorithm for large universes.
*/
Life::Life(int width, int height)
{
m_wrap = TRUE;
Create(width, height);
}
Life::~Life()
{
Destroy();
}
void Life::Create(int width, int height)
{
wxASSERT(width > 0 && height > 0 && m_cells.IsEmpty());
m_width = width;
m_height = height;
// preallocate memory to speed up initialization
m_cells.Alloc(m_width * m_height);
m_changed.Alloc(1000);
// add all cells
for (int j = 0; j < m_height; j++)
for (int i = 0; i < m_width; i++)
m_cells.Add( MakeCell(i, j, FALSE) );
}
void Life::Destroy()
{
m_cells.Clear();
m_changed.Clear();
}
void Life::Clear()
{
// set all cells in the array to dead
for (int j = 0; j < m_height; j++)
for (int i = 0; i < m_width; i++)
m_cells[j * m_width + i] &= ~CELL_ALIVE;
}
Cell Life::MakeCell(int i, int j, bool alive) const
{
return (Cell)((j << 18) | (i << 5) | (alive? CELL_ALIVE : CELL_DEAD));
}
bool Life::IsAlive(int i, int j) const
{
wxASSERT(i >= 0 && j >= 0 && i < m_width && j < m_height);
return (m_cells[j * m_width + i] & CELL_ALIVE);
}
bool Life::IsAlive(Cell c) const { return (c & CELL_ALIVE); };
int Life::GetX(Cell c) const { return (c >> 5) & 0x1fff; };
int Life::GetY(Cell c) const { return (c >> 18); };
Cell Life::SetCell(int i, int j, bool alive)
{
wxASSERT(i >= 0 && j >= 0 && i < m_width && j < m_height);
Cell c = MakeCell(i, j, alive);
m_cells[j * m_width + i] = c;
return c;
}
void Life::SetShape(LifeShape& shape)
{
wxASSERT((m_width >= shape.m_width) && (m_height >= shape.m_height));
int i0 = (m_width - shape.m_width) / 2;
int j0 = (m_height - shape.m_height) / 2;
char *p = shape.m_data;
Clear();
for (int j = j0; j < j0 + shape.m_height; j++)
for (int i = i0; i < i0 + shape.m_width; i++)
SetCell(i, j, *(p++) == '*');
}
bool Life::NextTic()
{
int i, j;
m_changed.Empty();
/* 1st pass. Find and mark deaths and births for this generation.
*
* Rules:
* An organism with <= 1 neighbors will die due to isolation.
* An organism with >= 4 neighbors will die due to starvation.
* New organisms are born in cells with exactly 3 neighbors.
*/
for (j = 0; j < m_height; j++)
for (i = 0; i < m_width; i++)
{
int neighbors = GetNeighbors(i, j);
bool alive = IsAlive(i, j);
/* Set CELL_MARK if this cell must change, clear it
* otherwise. We cannot toggle the CELL_ALIVE bit yet
* because all deaths and births are simultaneous (it
* would affect neighbouring cells).
*/
if ((!alive && neighbors == 3) ||
(alive && (neighbors <= 1 || neighbors >= 4)))
{
m_cells[j * m_width + i] |= CELL_MARK;
m_changed.Add( MakeCell(i, j, !alive) );
}
else
m_cells[j * m_width + i] &= ~CELL_MARK;
}
/* 2nd pass. Stabilize.
*/
for (j = 0; j < m_height; j++)
for (i = 0; i < m_width; i++)
{
/* Toggle CELL_ALIVE for those cells marked in the
* previous pass. Do not clear the CELL_MARK bit yet;
* it is useful to know which cells have changed and
* thus must be updated in the screen.
*/
if (m_cells[j * m_width + i] & CELL_MARK)
m_cells[j * m_width + i] ^= CELL_ALIVE;
}
return (!m_changed.IsEmpty());
}
int Life::GetNeighbors(int x, int y) const
{
wxASSERT(x >= 0 && y >= 0 && x < m_width && y < m_height);
int neighbors = 0;
int i0 = (x)? (x - 1) : 0;
int j0 = (y)? (y - 1) : 0;
int i1 = (x < (m_width - 1))? (x + 1) : (m_width - 1);
int j1 = (y < (m_height - 1))? (y + 1) : (m_height - 1);
if (m_wrap && ( !x || !y || x == (m_width - 1) || y == (m_height - 1)))
{
// this is an outer cell and wraparound is on
for (int j = y - 1; j <= y + 1; j++)
for (int i = x - 1; i <= x + 1; i++)
if (IsAlive( ((i < 0)? (i + m_width ) : (i % m_width)),
((j < 0)? (j + m_height) : (j % m_height)) ))
neighbors++;
}
else
{
// this is an inner cell, or wraparound is off
for (int j = j0; j <= j1; j++)
for (int i = i0; i <= i1; i++)
if (IsAlive(i, j))
neighbors++;
}
// do not count ourselves
if (IsAlive(x, y)) neighbors--;
return neighbors;
}

129
demos/life/game.h Normal file
View File

@@ -0,0 +1,129 @@
/////////////////////////////////////////////////////////////////////////////
// Name: game.h
// Purpose: Life! game logic
// Author: Guillermo Rodriguez Garcia, <guille@iies.es>
// Modified by:
// Created: Jan/2000
// RCS-ID: $Id$
// Copyright: (c) 2000, Guillermo Rodriguez Garcia
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _LIFE_GAME_H_
#define _LIFE_GAME_H_
#ifdef __GNUG__
#pragma interface "game.h"
#endif
// for compilers that support precompilation, includes "wx/wx.h"
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
// for all others, include the necessary headers
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
// --------------------------------------------------------------------------
// constants
// --------------------------------------------------------------------------
// minimum and maximum table size, in each dimension
#define LIFE_MIN 20
#define LIFE_MAX 200
// --------------------------------------------------------------------------
// Cell and CellArray;
// --------------------------------------------------------------------------
typedef long Cell;
typedef wxArrayLong CellArray;
// --------------------------------------------------------------------------
// LifeShape
// --------------------------------------------------------------------------
class LifeShape
{
public:
LifeShape::LifeShape(wxString name,
wxString desc,
int width, int height, char *data,
int fieldWidth = 20, int fieldHeight = 20,
bool wrap = TRUE)
{
m_name = name;
m_desc = desc;
m_width = width;
m_height = height;
m_data = data;
m_fieldWidth = fieldWidth;
m_fieldHeight = fieldHeight;
m_wrap = wrap;
}
wxString m_name;
wxString m_desc;
int m_width;
int m_height;
char *m_data;
int m_fieldWidth;
int m_fieldHeight;
bool m_wrap;
};
// --------------------------------------------------------------------------
// Life
// --------------------------------------------------------------------------
class Life
{
public:
// ctor and dtor
Life(int width, int height);
~Life();
void Create(int width, int height);
void Destroy();
// game field
inline int GetWidth() const { return m_width; };
inline int GetHeight() const { return m_height; };
inline void SetBorderWrap(bool on) { m_wrap = on; };
// cells
bool IsAlive(int i, int j) const;
bool IsAlive(Cell c) const;
int GetX(Cell c) const;
int GetY(Cell c) const;
const CellArray* GetCells() const { return &m_cells; };
const CellArray* GetChangedCells() const { return &m_changed; };
// game logic
void Clear();
Cell SetCell(int i, int j, bool alive = TRUE);
void SetShape(LifeShape &shape);
bool NextTic();
private:
int GetNeighbors(int i, int j) const;
inline Cell MakeCell(int i, int j, bool alive) const;
enum CellFlags
{
CELL_DEAD = 0x0000, // is dead
CELL_ALIVE = 0x0001, // is alive
CELL_MARK = 0x0002, // will change / has changed
};
int m_width;
int m_height;
CellArray m_cells;
CellArray m_changed;
bool m_wrap;
};
#endif // _LIFE_GAME_H_

630
demos/life/life.cpp Normal file
View File

@@ -0,0 +1,630 @@
/////////////////////////////////////////////////////////////////////////////
// Name: life.cpp
// Purpose: The game of life, created by J. H. Conway
// Author: Guillermo Rodriguez Garcia, <guille@iies.es>
// Modified by:
// Created: Jan/2000
// RCS-ID: $Id$
// Copyright: (c) 2000, Guillermo Rodriguez Garcia
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ==========================================================================
// declarations
// ==========================================================================
// --------------------------------------------------------------------------
// headers
// --------------------------------------------------------------------------
#ifdef __GNUG__
#pragma implementation "life.h"
#endif
// for compilers that support precompilation, includes "wx/wx.h"
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
// for all others, include the necessary headers
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include "wx/statline.h"
#include "life.h"
#include "game.h"
#include "dialogs.h"
// --------------------------------------------------------------------------
// resources
// --------------------------------------------------------------------------
#if defined(__WXGTK__) || defined(__WXMOTIF__)
// the application icon
#include "mondrian.xpm"
// bitmap buttons for the toolbar
#include "bitmaps/reset.xpm"
#include "bitmaps/play.xpm"
#include "bitmaps/stop.xpm"
#endif
// --------------------------------------------------------------------------
// constants
// --------------------------------------------------------------------------
// IDs for the controls and the menu commands
enum
{
// menu items and toolbar buttons
ID_NEWGAME = 1001,
ID_SAMPLES,
ID_ABOUT,
ID_EXIT,
ID_CLEAR,
ID_START,
ID_STEP,
ID_STOP,
ID_WRAP,
// speed selection slider
ID_SLIDER
};
// --------------------------------------------------------------------------
// event tables and other macros for wxWindows
// --------------------------------------------------------------------------
// Event tables
BEGIN_EVENT_TABLE(LifeFrame, wxFrame)
EVT_MENU (ID_NEWGAME, LifeFrame::OnNewGame)
EVT_MENU (ID_SAMPLES, LifeFrame::OnSamples)
EVT_MENU (ID_ABOUT, LifeFrame::OnMenu)
EVT_MENU (ID_EXIT, LifeFrame::OnMenu)
EVT_MENU (ID_CLEAR, LifeFrame::OnMenu)
EVT_MENU (ID_START, LifeFrame::OnMenu)
EVT_MENU (ID_STEP, LifeFrame::OnMenu)
EVT_MENU (ID_STOP, LifeFrame::OnMenu)
EVT_MENU (ID_WRAP, LifeFrame::OnMenu)
EVT_COMMAND_SCROLL (ID_SLIDER, LifeFrame::OnSlider)
END_EVENT_TABLE()
BEGIN_EVENT_TABLE(LifeCanvas, wxScrolledWindow)
EVT_PAINT ( LifeCanvas::OnPaint)
EVT_SIZE ( LifeCanvas::OnSize)
EVT_MOUSE_EVENTS ( LifeCanvas::OnMouse)
END_EVENT_TABLE()
// Create a new application object
IMPLEMENT_APP(LifeApp)
// ==========================================================================
// implementation
// ==========================================================================
// some shortcuts
#define ADD_TOOL(a, b, c, d) \
toolBar->AddTool(a, b, wxNullBitmap, FALSE, -1, -1, (wxObject *)0, c, d)
#define GET_FRAME() \
((LifeFrame *) wxGetApp().GetTopWindow())
// --------------------------------------------------------------------------
// LifeApp
// --------------------------------------------------------------------------
// `Main program' equivalent: the program execution "starts" here
bool LifeApp::OnInit()
{
// create the main application window
LifeFrame *frame = new LifeFrame();
// show it and tell the application that it's our main window
frame->Show(TRUE);
SetTopWindow(frame);
// enter the main message loop and run the app
return TRUE;
}
// --------------------------------------------------------------------------
// LifeFrame
// --------------------------------------------------------------------------
// frame constructor
LifeFrame::LifeFrame() : wxFrame((wxFrame *)0, -1, _("Life!"), wxPoint(50, 50))
{
// frame icon
SetIcon(wxICON(mondrian));
// menu bar
wxMenu *menuFile = new wxMenu("", wxMENU_TEAROFF);
wxMenu *menuGame = new wxMenu("", wxMENU_TEAROFF);
menuFile->Append(ID_NEWGAME, _("New game..."), _("Start a new game"));
menuFile->Append(ID_SAMPLES, _("Sample game..."), _("Select a sample configuration"));
menuFile->AppendSeparator();
menuFile->Append(ID_ABOUT, _("&About...\tCtrl-A"), _("Show about dialog"));
menuFile->AppendSeparator();
menuFile->Append(ID_EXIT, _("E&xit\tAlt-X"), _("Quit this program"));
menuGame->Append(ID_CLEAR, _("&Clear\tCtrl-C"), _("Clear game field"));
menuGame->Append(ID_START, _("&Start\tCtrl-S"), _("Start"));
menuGame->Append(ID_STEP, _("&Next\tCtrl-N"), _("Single step"));
menuGame->Append(ID_STOP, _("S&top\tCtrl-T"), _("Stop"));
menuGame->Enable(ID_STOP, FALSE);
menuGame->AppendSeparator();
menuGame->Append(ID_WRAP, _("&Wraparound\tCtrl-W"), _("Wrap around borders"), TRUE);
menuGame->Check (ID_WRAP, TRUE);
wxMenuBar *menuBar = new wxMenuBar();
menuBar->Append(menuFile, _("&File"));
menuBar->Append(menuGame, _("&Game"));
SetMenuBar(menuBar);
// tool bar
wxBitmap tbBitmaps[3];
tbBitmaps[0] = wxBITMAP(reset);
tbBitmaps[1] = wxBITMAP(play);
tbBitmaps[2] = wxBITMAP(stop);
wxToolBar *toolBar = CreateToolBar();
toolBar->SetMargins(5, 5);
toolBar->SetToolBitmapSize(wxSize(16, 16));
ADD_TOOL(ID_CLEAR, tbBitmaps[0], _("Clear"), _("Clear game board"));
ADD_TOOL(ID_START, tbBitmaps[1], _("Start"), _("Start"));
ADD_TOOL(ID_STOP , tbBitmaps[2], _("Stop"), _("Stop"));
toolBar->EnableTool(ID_STOP, FALSE);
toolBar->Realize();
// status bar
CreateStatusBar(2);
SetStatusText(_("Welcome to Life!"));
// game
wxPanel *panel = new wxPanel(this, -1);
m_life = new Life(20, 20);
m_canvas = new LifeCanvas(panel, m_life);
m_timer = new LifeTimer();
m_interval = 500;
m_tics = 0;
m_text = new wxStaticText(panel, -1, "");
UpdateInfoText();
// slider
wxSlider *slider = new wxSlider(panel, ID_SLIDER,
5, 1, 10,
wxDefaultPosition,
wxSize(200, -1),
wxSL_HORIZONTAL | wxSL_AUTOTICKS);
// component layout
wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
sizer->Add(new wxStaticLine(panel, -1), 0, wxGROW | wxCENTRE);
sizer->Add(m_canvas, 1, wxGROW | wxCENTRE | wxALL, 5);
sizer->Add(new wxStaticLine(panel, -1), 0, wxGROW | wxCENTRE);
sizer->Add(m_text, 0, wxCENTRE | wxTOP, 5);
sizer->Add(slider, 0, wxCENTRE | wxALL, 5);
panel->SetSizer(sizer);
panel->SetAutoLayout(TRUE);
sizer->Fit(this);
sizer->SetSizeHints(this);
}
LifeFrame::~LifeFrame()
{
delete m_timer;
delete m_life;
}
void LifeFrame::UpdateInfoText()
{
wxString msg;
msg.Printf(_("Generation: %u, Interval: %u ms"), m_tics, m_interval);
m_text->SetLabel(msg);
}
// event handlers
void LifeFrame::OnMenu(wxCommandEvent& event)
{
switch (event.GetId())
{
case ID_START : OnStart(); break;
case ID_STEP : OnTimer(); break;
case ID_STOP : OnStop(); break;
case ID_WRAP :
{
bool checked = GetMenuBar()->GetMenu(1)->IsChecked(ID_WRAP);
m_life->SetBorderWrap(checked);
break;
}
case ID_CLEAR :
{
OnStop();
m_life->Clear();
m_canvas->DrawEverything(TRUE);
m_canvas->Refresh(FALSE);
m_tics = 0;
UpdateInfoText();
break;
}
case ID_ABOUT :
{
wxMessageBox(
_("This is the about dialog of the Life! sample.\n"
"(c) 2000 Guillermo Rodriguez Garcia"),
_("About Life!"),
wxOK | wxICON_INFORMATION,
this);
break;
}
case ID_EXIT :
{
// TRUE is to force the frame to close
Close(TRUE);
break;
}
}
}
void LifeFrame::OnNewGame(wxCommandEvent& WXUNUSED(event))
{
int w = m_life->GetWidth();
int h = m_life->GetHeight();
// stop if it was running
OnStop();
// dialog box
LifeNewGameDialog dialog(this, &w, &h);
// new game?
if (dialog.ShowModal() == wxID_OK)
{
// check dimensions
if (w >= LIFE_MIN && w <= LIFE_MAX &&
h >= LIFE_MIN && h <= LIFE_MAX)
{
// resize game field
m_life->Destroy();
m_life->Create(w, h);
// tell the canvas
m_canvas->Reset();
m_canvas->Refresh();
m_tics = 0;
UpdateInfoText();
}
else
{
wxString msg;
msg.Printf(_("Both dimensions must be within %u and %u.\n"),
LIFE_MIN, LIFE_MAX);
wxMessageBox(msg, _("Error!"), wxOK | wxICON_EXCLAMATION, this);
}
}
}
void LifeFrame::OnSamples(wxCommandEvent& WXUNUSED(event))
{
// stop if it was running
OnStop();
// dialog box
LifeSamplesDialog dialog(this);
// new game?
if (dialog.ShowModal() == wxID_OK)
{
int result = dialog.GetValue();
if (result == -1)
return;
int gw = g_shapes[result].m_fieldWidth;
int gh = g_shapes[result].m_fieldHeight;
int wrap = g_shapes[result].m_wrap;
// set wraparound (don't ask the user)
m_life->SetBorderWrap(wrap);
GetMenuBar()->GetMenu(1)->Check(ID_WRAP, wrap);
// need to resize the game field?
if (gw > m_life->GetWidth() || gh > m_life->GetHeight())
{
wxString s;
s.Printf(_("Your game field is too small for this configuration.\n"
"It is recommended to resize it to %u x %u. Proceed?\n"),
gw, gh);
if (wxMessageBox(s, _("Question"), wxYES_NO | wxICON_QUESTION, this) == wxYES)
{
m_life->Destroy();
m_life->Create(gw, gh);
}
}
// put the shape
m_life->SetShape(g_shapes[result]);
// tell the canvas about the change
m_canvas->Reset();
m_canvas->Refresh();
m_tics = 0;
UpdateInfoText();
}
}
void LifeFrame::OnStart()
{
if (!m_running)
{
GetToolBar()->EnableTool(ID_START, FALSE);
GetToolBar()->EnableTool(ID_STOP, TRUE);
GetMenuBar()->GetMenu(1)->Enable(ID_START, FALSE);
GetMenuBar()->GetMenu(1)->Enable(ID_STEP, FALSE);
GetMenuBar()->GetMenu(1)->Enable(ID_STOP, TRUE);
m_timer->Start(m_interval);
m_running = TRUE;
}
}
void LifeFrame::OnStop()
{
if (m_running)
{
GetToolBar()->EnableTool(ID_START, TRUE);
GetToolBar()->EnableTool(ID_STOP, FALSE);
GetMenuBar()->GetMenu(1)->Enable(ID_START, TRUE);
GetMenuBar()->GetMenu(1)->Enable(ID_STEP, TRUE);
GetMenuBar()->GetMenu(1)->Enable(ID_STOP, FALSE);
m_timer->Stop();
m_running = FALSE;
}
}
void LifeFrame::OnTimer()
{
if (m_life->NextTic())
m_tics++;
else
OnStop();
UpdateInfoText();
m_canvas->DrawEverything();
m_canvas->Refresh(FALSE);
}
void LifeFrame::OnSlider(wxScrollEvent& event)
{
m_interval = event.GetPosition() * 100;
// restart timer if running, to set the new interval
if (m_running)
{
m_timer->Stop();
m_timer->Start(m_interval);
}
UpdateInfoText();
}
// --------------------------------------------------------------------------
// LifeTimer
// --------------------------------------------------------------------------
void LifeTimer::Notify()
{
GET_FRAME()->OnTimer();
};
// --------------------------------------------------------------------------
// LifeCanvas
// --------------------------------------------------------------------------
// canvas constructor
LifeCanvas::LifeCanvas(wxWindow *parent, Life *life, bool interactive)
: wxScrolledWindow(parent, -1, wxPoint(0, 0), wxSize(100, 100))
{
m_life = life;
m_interactive = interactive;
m_cellsize = 8;
m_bmp = NULL;
Reset();
}
LifeCanvas::~LifeCanvas()
{
delete m_bmp;
}
void LifeCanvas::Reset()
{
if (m_bmp)
delete m_bmp;
m_status = MOUSE_NOACTION;
m_width = CellToCoord(m_life->GetWidth()) + 1;
m_height = CellToCoord(m_life->GetHeight()) + 1;
m_bmp = new wxBitmap(m_width, m_height);
wxCoord w = GetClientSize().GetX();
wxCoord h = GetClientSize().GetY();
m_xoffset = (w > m_width)? ((w - m_width) / 2) : 0;
m_yoffset = (h > m_height)? ((h - m_height) / 2) : 0;
// redraw everything
DrawEverything(TRUE);
SetScrollbars(10, 10, (m_width + 9) / 10, (m_height + 9) / 10);
}
void LifeCanvas::DrawEverything(bool force)
{
wxMemoryDC dc;
dc.SelectObject(*m_bmp);
dc.BeginDrawing();
// draw cells
const CellArray *cells =
force? m_life->GetCells() : m_life->GetChangedCells();
for (unsigned i = 0; i < cells->GetCount(); i++)
DrawCell(cells->Item(i), dc);
// bounding rectangle (always drawn - better than clipping region)
dc.SetPen(*wxBLACK_PEN);
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle(0, 0, m_width, m_height);
dc.EndDrawing();
dc.SelectObject(wxNullBitmap);
}
void LifeCanvas::DrawCell(Cell c)
{
wxMemoryDC dc;
dc.SelectObject(*m_bmp);
dc.BeginDrawing();
dc.SetClippingRegion(1, 1, m_width - 2, m_height - 2);
DrawCell(c, dc);
dc.EndDrawing();
dc.SelectObject(wxNullBitmap);
}
void LifeCanvas::DrawCell(Cell c, wxDC &dc)
{
if (m_life->IsAlive(c))
{
dc.SetPen(*wxBLACK_PEN);
dc.SetBrush(*wxBLACK_BRUSH);
dc.DrawRectangle(CellToCoord( m_life->GetX(c) ),
CellToCoord( m_life->GetY(c) ),
m_cellsize,
m_cellsize);
}
else
{
dc.SetPen(*wxLIGHT_GREY_PEN);
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle(CellToCoord( m_life->GetX(c) ),
CellToCoord( m_life->GetY(c) ),
m_cellsize,
m_cellsize);
dc.SetPen(*wxWHITE_PEN);
dc.SetBrush(*wxWHITE_BRUSH);
dc.DrawRectangle(CellToCoord( m_life->GetX(c) ) + 1,
CellToCoord( m_life->GetY(c) ) + 1,
m_cellsize - 1,
m_cellsize - 1);
}
}
// event handlers
void LifeCanvas::OnPaint(wxPaintEvent& event)
{
wxPaintDC dc(this);
wxMemoryDC memdc;
wxRegionIterator upd(GetUpdateRegion());
wxCoord x, y, w, h, xx, yy;
dc.BeginDrawing();
memdc.SelectObject(*m_bmp);
while(upd)
{
x = upd.GetX();
y = upd.GetY();
w = upd.GetW();
h = upd.GetH();
CalcUnscrolledPosition(x, y, &xx, &yy);
dc.Blit(x, y, w, h, &memdc, xx - m_xoffset, yy - m_yoffset);
upd++;
}
memdc.SelectObject(wxNullBitmap);
dc.EndDrawing();
}
void LifeCanvas::OnMouse(wxMouseEvent& event)
{
if (!m_interactive)
return;
int x, y, xx, yy, i, j;
// which cell are we pointing at?
x = event.GetX();
y = event.GetY();
CalcUnscrolledPosition(x, y, &xx, &yy);
i = CoordToCell( xx - m_xoffset );
j = CoordToCell( yy - m_yoffset );
// adjust x, y to point to the upper left corner of the cell
CalcScrolledPosition( CellToCoord(i) + m_xoffset,
CellToCoord(j) + m_yoffset,
&x, &y );
// set cursor shape and statusbar text
if (i < 0 || i >= m_life->GetWidth() ||
j < 0 || j >= m_life->GetHeight())
{
GET_FRAME()->SetStatusText(wxEmptyString, 1);
SetCursor(*wxSTANDARD_CURSOR);
}
else
{
wxString msg;
msg.Printf(_("Cell: (%u, %u)"), i, j);
GET_FRAME()->SetStatusText(msg, 1);
SetCursor(*wxCROSS_CURSOR);
}
// button pressed?
if (!event.LeftIsDown())
{
m_status = MOUSE_NOACTION;
}
else if (i >= 0 && i < m_life->GetWidth() &&
j >= 0 && j < m_life->GetHeight())
{
bool alive = m_life->IsAlive(i, j);
// if just pressed, update status
if (m_status == MOUSE_NOACTION)
m_status = (alive? MOUSE_ERASING : MOUSE_DRAWING);
// toggle cell and refresh if needed
if (((m_status == MOUSE_ERASING) && alive) ||
((m_status == MOUSE_DRAWING) && !alive))
{
wxRect rect(x, y, m_cellsize + 1, m_cellsize + 1);
DrawCell( m_life->SetCell(i, j, !alive) );
Refresh(FALSE, &rect);
}
}
}
void LifeCanvas::OnSize(wxSizeEvent& event)
{
wxCoord w = event.GetSize().GetX();
wxCoord h = event.GetSize().GetY();
m_xoffset = (w > m_width)? ((w - m_width) / 2) : 0;
m_yoffset = (h > m_height)? ((h - m_height) / 2) : 0;
// allow default processing
event.Skip();
}

7
demos/life/life.def Normal file
View File

@@ -0,0 +1,7 @@
NAME Life
DESCRIPTION 'Life! wxWindows application'
EXETYPE WINDOWS
CODE PRELOAD MOVEABLE DISCARDABLE
DATA PRELOAD MOVEABLE MULTIPLE
HEAPSIZE 4048
STACKSIZE 16000

136
demos/life/life.h Normal file
View File

@@ -0,0 +1,136 @@
/////////////////////////////////////////////////////////////////////////////
// Name: life.h
// Purpose: The game of life, created by J. H. Conway
// Author: Guillermo Rodriguez Garcia, <guille@iies.es>
// Modified by:
// Created: Jan/2000
// RCS-ID: $Id$
// Copyright: (c) 2000, Guillermo Rodriguez Garcia
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _LIFE_APP_H_
#define _LIFE_APP_H_
#ifdef __GNUG__
#pragma interface "life.h"
#endif
// for compilers that support precompilation, includes "wx/wx.h"
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
// for all others, include the necessary headers
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include "game.h"
// --------------------------------------------------------------------------
// LifeCanvas
// --------------------------------------------------------------------------
class LifeCanvas : public wxScrolledWindow
{
public:
// ctor and dtor
LifeCanvas(wxWindow* parent, Life* life, bool interactive = TRUE);
~LifeCanvas();
// member functions
void Reset();
void DrawEverything(bool force = FALSE);
void DrawCell(Cell c);
void DrawCell(Cell c, wxDC &dc);
inline int CellToCoord(int i) const { return (i * m_cellsize); };
inline int CoordToCell(int x) const { return ((x >= 0)? (x / m_cellsize) : -1); };
// event handlers
void OnPaint(wxPaintEvent& event);
void OnMouse(wxMouseEvent& event);
void OnSize(wxSizeEvent& event);
private:
// any class wishing to process wxWindows events must use this macro
DECLARE_EVENT_TABLE()
enum MouseStatus
{
MOUSE_NOACTION,
MOUSE_DRAWING,
MOUSE_ERASING
};
Life *m_life;
wxBitmap *m_bmp;
int m_height;
int m_width;
int m_cellsize;
wxCoord m_xoffset;
wxCoord m_yoffset;
MouseStatus m_status;
bool m_interactive;
};
// --------------------------------------------------------------------------
// LifeTimer
// --------------------------------------------------------------------------
// Life timer
class LifeTimer : public wxTimer
{
public:
void Notify();
};
// --------------------------------------------------------------------------
// LifeFrame
// --------------------------------------------------------------------------
class LifeFrame : public wxFrame
{
public:
// ctor and dtor
LifeFrame();
~LifeFrame();
// member functions
void UpdateInfoText();
// event handlers
void OnMenu(wxCommandEvent& event);
void OnNewGame(wxCommandEvent& event);
void OnSamples(wxCommandEvent& event);
void OnStart();
void OnStop();
void OnTimer();
void OnSlider(wxScrollEvent& event);
private:
// any class wishing to process wxWindows events must use this macro
DECLARE_EVENT_TABLE()
Life *m_life;
LifeTimer *m_timer;
LifeCanvas *m_canvas;
wxStaticText *m_text;
bool m_running;
long m_interval;
long m_tics;
};
// --------------------------------------------------------------------------
// LifeApp
// --------------------------------------------------------------------------
class LifeApp : public wxApp
{
public:
virtual bool OnInit();
};
#endif // _LIFE_APP_H_

6
demos/life/life.rc Normal file
View File

@@ -0,0 +1,6 @@
mondrian ICON "mondrian.ico"
#include "wx/msw/wx.rc"
reset BITMAP "bitmaps/reset.bmp"
play BITMAP "bitmaps/play.bmp"
stop BITMAP "bitmaps/stop.bmp"

16
demos/life/makefile.b32 Normal file
View File

@@ -0,0 +1,16 @@
#
# File: makefile.b32
# Author: Julian Smart
# Created: 1999
# Updated:
# Copyright:
#
# Makefile : Builds sample for 32-bit BC++
WXDIR = $(WXWIN)
TARGET=life
OBJECTS = $(TARGET).obj dialogs.obj game.obj
!include $(WXDIR)\src\makeprog.b32

19
demos/life/makefile.bcc Normal file
View File

@@ -0,0 +1,19 @@
#
# File: makefile.bcc
# Author: Julian Smart
# Created: 1998
# Updated:
#
# Builds a BC++ 16-bit sample
!if "$(WXWIN)" == ""
!error You must define the WXWIN variable in autoexec.bat, e.g. WXWIN=c:\wx
!endif
WXDIR = $(WXWIN)
TARGET=life
OBJECTS=$(TARGET).obj dialogs.obj game.obj
!include $(WXDIR)\src\makeprog.bcc

17
demos/life/makefile.dos Normal file
View File

@@ -0,0 +1,17 @@
#
# File: makefile.dos
# Author: Julian Smart
# Created: 1998
# Updated:
#
# Makefile : Builds 16-bit sample, VC++ 1.5
# Use FINAL=1 argument to nmake to build final version with no debugging
# info
WXDIR = $(WXWIN)
TARGET=life
OBJECTS = $(TARGET).obj dialogs.obj game.obj
!include $(WXDIR)\src\makeprog.msc

16
demos/life/makefile.g95 Normal file
View File

@@ -0,0 +1,16 @@
#
# File: makefile.g95
# Author: Julian Smart
# Created: 1999
# Updated:
# Copyright: (c) Julian Smart, 1999
#
# Makefile for wxWindows sample (Cygwin/Mingw32).
WXDIR = ../..
TARGET=life
OBJECTS = $(TARGET).o dialogs.o game.o
include $(WXDIR)/src/makeprog.g95

35
demos/life/makefile.unx Normal file
View File

@@ -0,0 +1,35 @@
#
# File: Makefile for samples
# Author: Robert Roebling
# Created: 1999
# Updated:
# Copyright: (c) 1998 Robert Roebling
#
# This makefile requires a Unix version of wxWindows
# to be installed on your system. This is most often
# done typing "make install" when using the complete
# sources of wxWindows or by installing the two
# RPM packages wxGTK.XXX.rpm and wxGTK-devel.XXX.rpm
# under Linux.
#
CC = gcc
PROGRAM = life
OBJECTS = $(PROGRAM).o dialogs.o game.o
# implementation
.SUFFIXES: .o .cpp
.cpp.o :
$(CC) -c `wx-config --cflags` -o $@ $<
all: $(PROGRAM)
$(PROGRAM): $(OBJECTS)
$(CC) -o $(PROGRAM) $(OBJECTS) `wx-config --libs`
clean:
rm -f *.o $(PROGRAM)

18
demos/life/makefile.vc Normal file
View File

@@ -0,0 +1,18 @@
#
# File: makefile.vc
# Author: Julian Smart
# Created: 1999
# Updated:
# Copyright: (c) Julian Smart
#
# Makefile : Builds sample (VC++, WIN32)
# Use FINAL=1 argument to nmake to build final version with no debug info.
# Set WXDIR for your system
WXDIR = $(WXWIN)
PROGRAM=life
OBJECTS = $(PROGRAM).obj dialogs.obj game.obj
!include $(WXDIR)\src\makeprog.vc

Some files were not shown because too many files have changed in this diff Show More