home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / CPP / VCW411.ZIP / MAINWIN.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-10  |  4.3 KB  |  144 lines

  1. // -[Keep_Heading]-
  2.  
  3.  
  4. // -[Copyright_Mesg]-
  5. // --------------------------------------------------------------- //
  6. // (c) Copyright 1993-1994. Step Ahead Software Pty Limited. All rights reserved.
  7. // Class Source Filename: MAINWIN.cpp
  8. // Description: 
  9. // Main window of graphics application.
  10. // --------------------------------------------------------------- //
  11.  
  12.  
  13. #include "MAINWIN.h"
  14.  
  15.  
  16. // -[Keep_cpp_Extras]-
  17. #include <stdlib.h>
  18. #include <string.h>
  19.  
  20. #include "square.h"
  21. #include "circle.h"
  22.  
  23.  
  24.  
  25. // -[Module_Function_Decs]-
  26.  
  27.  
  28. // -[Module_Data_Decs_Def]-
  29.  
  30. // This is added only for the purpose of demonstrating initialisation of auto
  31. // initialised variables.
  32. static Circle DummyCircle(30, 30, 20);
  33.  
  34. // This is added to demonstration auto intialised variables. It is not used
  35. // in the application.
  36. static int DummyInt= 7;
  37.  
  38.  
  39. // -[Global_Data_Defs]-
  40.  
  41.  
  42. // -[Static_Member_Data_Defs]-
  43.  
  44.  
  45. // -[Function_Defs]-
  46.  
  47. // Reponse to the left mouse button down window message. We use this to check
  48. // if a mouse click occured on a shape.
  49. void
  50. GraphicWindow::WMLButtonDown(RTMessage Msg)
  51. {
  52.     // Test which shape the mouse event occured in
  53.     for (int i = displays->lowerBound(); i <= displays->upperBound(); i++)
  54.     {
  55.         RShape TheShape = (RShape)(*displays)[i];
  56.         // if element is valid...
  57.         if ( TheShape != NOOBJECT )
  58.             if ( TheShape.isIn(MAKEPOINT(Msg.LParam)) )
  59.             {        
  60.                 if ( TheShape.isHome() )
  61.                     // Move the shape to a random place
  62.                     TheShape.MoveTo(HWindow, random(500), random(400));
  63.                 else
  64.                     // Move the shape back home
  65.                     TheShape.GoHome(HWindow);
  66.                 break;
  67.             }
  68.     }
  69. }
  70.  
  71. // Constructs the main window object by calling base class constructor - TWindow
  72. GraphicWindow::GraphicWindow(PTWindowsObject AParent, LPSTR ATitle)
  73. : TWindow(AParent, ATitle)
  74. {
  75.     // Draw something significant
  76.     displays = new Array(10, 0, 10);
  77.  
  78.     // Letter C
  79.     displays->add(*(new Circle(120, 100, 20)));
  80.     displays->add(*(new Circle(140, 100, 20)));
  81.     displays->add(*(new Circle(100, 120, 20)));
  82.     displays->add(*(new Circle(100, 140, 20)));
  83.     displays->add(*(new Circle(100, 160, 20)));
  84.     displays->add(*(new Circle(120, 180, 20)));
  85.     displays->add(*(new Circle(140, 180, 20)));
  86.     
  87.     // first + 
  88.     displays->add(*(new Square(200, 120, 20)));
  89.     displays->add(*(new Square(180, 140, 20)));
  90.  
  91.     PShape LittleSquare = new Square(205, 145, 10);
  92.     LittleSquare->SetColour(RGB(0, 0, 255));
  93.     displays->add(*LittleSquare);
  94.  
  95.     displays->add(*(new Square(220, 140, 20)));
  96.     displays->add(*(new Square(200, 160, 20)));
  97.                                          
  98.     // second +
  99.     displays->add(*(new Square(280, 120, 20)));
  100.     displays->add(*(new Square(260, 140, 20)));
  101.     displays->add(*(new Square(300, 140, 20)));
  102.     displays->add(*(new Square(280, 160, 20)));
  103.  
  104.     LittleSquare = new Square(285, 145, 10);
  105.     LittleSquare->SetColour(RGB(0, 0, 255));
  106.     displays->add(*LittleSquare);
  107. }
  108.  
  109. // Paints the shape objects on the screen.
  110. void
  111. GraphicWindow::Paint(HDC hDC, PAINTSTRUCT _FAR &)
  112. {
  113.     // Paint each item in the array
  114.     for (int i = displays->lowerBound(); i <= displays->upperBound(); i++)
  115.     {
  116.         // if element is valid...
  117.         RShape TheShape = (RShape)(*displays)[i];
  118.         if ( TheShape != NOOBJECT )
  119.             // ... show it
  120.             TheShape.Show(hDC);
  121.     }
  122.  
  123.     // Show instructions
  124.     static char Instr[] = "Click on shapes once to move them to a random position. "\
  125.             "Click on them again to move them back home. This application lets you see "\
  126.             "Encapsulation and Polymorphism in action. MainWindow::Paint iterates through the list of shapes telling each to paint itself. "\
  127.             "It is not concerned with how each object does this.\n"\
  128.             "View the project design by "\
  129.             "double clicking on the Step 3 icon in the Visual Classworks group and you will see "\
  130.             "Visual Classworks's ability to show the application from a "\
  131.             "higher level than the source code - making you more productive. Even though you operate "\
  132.             "at a higher level most of the time Visual Classworks provides many points at which you can "\
  133.             "quickly and easily delve down low into "\
  134.             "the source code when necessary. Even though you're using an high level tool you're "\
  135.             "never too far away from the action!";
  136.  
  137.     RECT TR = {20, 220, 620, 460};
  138.     int OldBkMode = SetBkMode(hDC, TRANSPARENT);
  139.     DrawText(hDC, Instr, strlen(Instr), &TR, DT_CENTER|DT_WORDBREAK);
  140.     SetBkMode(hDC, OldBkMode);
  141. }
  142.  
  143.  
  144. // -[Persistent]-