home *** CD-ROM | disk | FTP | other *** search
- // -[Keep_Heading]-
-
-
- // -[Copyright_Mesg]-
- // --------------------------------------------------------------- //
- // (c) Copyright 1993-1994. Step Ahead Software Pty Limited. All rights reserved.
- // Class Source Filename: MAINWIN.cpp
- // Description:
- // Main window of graphics application.
- // --------------------------------------------------------------- //
-
-
- #include "MAINWIN.h"
-
-
- // -[Keep_cpp_Extras]-
- #include <stdlib.h>
- #include <string.h>
-
- #include "square.h"
- #include "circle.h"
-
-
-
- // -[Module_Function_Decs]-
-
-
- // -[Module_Data_Decs_Def]-
-
- // This is added only for the purpose of demonstrating initialisation of auto
- // initialised variables.
- static Circle DummyCircle(30, 30, 20);
-
- // This is added to demonstration auto intialised variables. It is not used
- // in the application.
- static int DummyInt= 7;
-
-
- // -[Global_Data_Defs]-
-
-
- // -[Static_Member_Data_Defs]-
-
-
- // -[Function_Defs]-
-
- // Reponse to the left mouse button down window message. We use this to check
- // if a mouse click occured on a shape.
- void
- GraphicWindow::WMLButtonDown(RTMessage Msg)
- {
- // Test which shape the mouse event occured in
- for (int i = displays->lowerBound(); i <= displays->upperBound(); i++)
- {
- RShape TheShape = (RShape)(*displays)[i];
- // if element is valid...
- if ( TheShape != NOOBJECT )
- if ( TheShape.isIn(MAKEPOINT(Msg.LParam)) )
- {
- if ( TheShape.isHome() )
- // Move the shape to a random place
- TheShape.MoveTo(HWindow, random(500), random(400));
- else
- // Move the shape back home
- TheShape.GoHome(HWindow);
- break;
- }
- }
- }
-
- // Constructs the main window object by calling base class constructor - TWindow
- GraphicWindow::GraphicWindow(PTWindowsObject AParent, LPSTR ATitle)
- : TWindow(AParent, ATitle)
- {
- // Draw something significant
- displays = new Array(10, 0, 10);
-
- // Letter C
- displays->add(*(new Circle(120, 100, 20)));
- displays->add(*(new Circle(140, 100, 20)));
- displays->add(*(new Circle(100, 120, 20)));
- displays->add(*(new Circle(100, 140, 20)));
- displays->add(*(new Circle(100, 160, 20)));
- displays->add(*(new Circle(120, 180, 20)));
- displays->add(*(new Circle(140, 180, 20)));
-
- // first +
- displays->add(*(new Square(200, 120, 20)));
- displays->add(*(new Square(180, 140, 20)));
-
- PShape LittleSquare = new Square(205, 145, 10);
- LittleSquare->SetColour(RGB(0, 0, 255));
- displays->add(*LittleSquare);
-
- displays->add(*(new Square(220, 140, 20)));
- displays->add(*(new Square(200, 160, 20)));
-
- // second +
- displays->add(*(new Square(280, 120, 20)));
- displays->add(*(new Square(260, 140, 20)));
- displays->add(*(new Square(300, 140, 20)));
- displays->add(*(new Square(280, 160, 20)));
-
- LittleSquare = new Square(285, 145, 10);
- LittleSquare->SetColour(RGB(0, 0, 255));
- displays->add(*LittleSquare);
- }
-
- // Paints the shape objects on the screen.
- void
- GraphicWindow::Paint(HDC hDC, PAINTSTRUCT _FAR &)
- {
- // Paint each item in the array
- for (int i = displays->lowerBound(); i <= displays->upperBound(); i++)
- {
- // if element is valid...
- RShape TheShape = (RShape)(*displays)[i];
- if ( TheShape != NOOBJECT )
- // ... show it
- TheShape.Show(hDC);
- }
-
- // Show instructions
- static char Instr[] = "Click on shapes once to move them to a random position. "\
- "Click on them again to move them back home. This application lets you see "\
- "Encapsulation and Polymorphism in action. MainWindow::Paint iterates through the list of shapes telling each to paint itself. "\
- "It is not concerned with how each object does this.\n"\
- "View the project design by "\
- "double clicking on the Step 3 icon in the Visual Classworks group and you will see "\
- "Visual Classworks's ability to show the application from a "\
- "higher level than the source code - making you more productive. Even though you operate "\
- "at a higher level most of the time Visual Classworks provides many points at which you can "\
- "quickly and easily delve down low into "\
- "the source code when necessary. Even though you're using an high level tool you're "\
- "never too far away from the action!";
-
- RECT TR = {20, 220, 620, 460};
- int OldBkMode = SetBkMode(hDC, TRANSPARENT);
- DrawText(hDC, Instr, strlen(Instr), &TR, DT_CENTER|DT_WORDBREAK);
- SetBkMode(hDC, OldBkMode);
- }
-
-
- // -[Persistent]-