home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
yacl-012.zip
/
uidemo
/
animate
/
appwin.cxx
next >
Wrap
C/C++ Source or Header
|
1995-04-08
|
2KB
|
67 lines
#include "ui/dsplsurf.h"
#include "appwin.h"
#if defined(__GNUC__)
template class CL_Binding<AppWindow>;
#endif
typedef CL_Binding<AppWindow> Bind;
const short _BallDiameter = 20;
AppWindow::AppWindow()
: UI_CompositeVObject (NULL, NULL, FALSE, UI_Rectangle (10, 50, 250, 150)),
_timer (Bind (this, &AppWindow::_Draw))
{
Title () = "YACL Bouncing Ball";
_xInc = _yInc = 5;
}
AppWindow::~AppWindow ()
{
_timer.Stop ();
}
void AppWindow::Initialize ()
{
_bgColor = UI_Color (UIColor_White);
UI_DisplaySurface& sfc = CreateDisplaySurface ();
sfc.ClearDisplay ();
UI_Rectangle bgRect (1, 1, _BallDiameter+4, _BallDiameter+4);
_bgMap.CopyFrom (sfc, bgRect);
sfc.Pen().Color (UIColor_Black);
sfc.Brush().Color (UIColor_Red);
sfc.Brush().Pattern (UIBrush_Solid);
sfc.DrawEllipse (UI_Rectangle (3, 3, _BallDiameter, _BallDiameter),
UID_Outline | UID_Fill);
_ballMap.CopyFrom (sfc, bgRect);
_position = UI_Point (1, 1);
_timer.Start (25);
}
bool AppWindow::_Draw (CL_Object&, long)
{
UI_DisplaySurface& sfc = *DisplaySurface ();
sfc.DrawBitmap (_bgMap, _position);
_position += UI_Point (_xInc, _yInc);
long x = _position.XCoord(), y = _position.YCoord();
if (x < 0 || x > ClientArea().Width() - _BallDiameter)
_xInc = -_xInc;
if (y < 0 || y > ClientArea().Height() - _BallDiameter)
_yInc = -_yInc;
sfc.DrawBitmap (_ballMap, _position);
return TRUE;
}
bool AppWindow::Reconfigure (const UI_Rectangle&)
{
_position = UI_Point (1, 1);
UI_DisplaySurface* sfc = DisplaySurface ();
if (sfc)
sfc->ClearDisplay();
return TRUE;
}