home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / SCROLLER.PAK / SCROLLEX.CPP < prev   
Encoding:
C/C++ Source or Header  |  1997-05-06  |  2.4 KB  |  102 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1995, 1995 by Borland International, All Rights Reserved
  4. //----------------------------------------------------------------------------
  5. #include <owl/pch.h>
  6. #include <owl/applicat.h>
  7. #include <owl/framewin.h>
  8. #include <owl/scroller.h>
  9. #include <owl/dc.h>
  10.  
  11.  
  12. //
  13. // Each "unit" is the number of device units (pixels) to scroll if the
  14. // SB_LINEUP or SB_LINEDOWN message is received.
  15. //
  16. const int XUnits = 7;
  17. const int YUnits = 16;
  18.  
  19. //
  20. // A range is number of units available to scroll.
  21. //
  22. const int XRange = 80;
  23. const int YRange = 60;
  24.  
  25. //
  26. // Therefore, the size of the imaginary canvas is calculated as
  27. // follows:
  28. // The width is XUnits * XRange  =  7 * 80 = 560 pixels.
  29. // The height is YUnits * YRange = 16 * 60 = 960 pixels.
  30. //
  31. const int NumberOfRectangles = 49;
  32.  
  33.  
  34. //
  35. // class TScrollWindow
  36. // ~~~~~ ~~~~~~~~~~~~~
  37. class TScrollWindow : public TWindow {
  38.   public:
  39.     TScrollWindow(TWindow* parent = 0, const char* title = 0);
  40.     void Paint(TDC& dc, bool, TRect&);
  41. };
  42.  
  43. //
  44. // Constructor for a TScrollWindow, sets scroll styles and
  45. // constructs the Scroller object.
  46. //
  47. TScrollWindow::TScrollWindow(TWindow* parent, const char* title)
  48. :
  49.   TWindow(parent, title)
  50. {
  51.   Attr.Style |= WS_VSCROLL | WS_HSCROLL;
  52.   Scroller = new TScroller(this, XUnits, YUnits, XRange, YRange);
  53. }
  54.  
  55. //
  56. // Responds to an incoming "paint" message by redrawing boxes. Note
  57. // that the Scroller's BeginView method, which sets the viewport origin
  58. // relative to the present scroll position, has already been called.
  59. //
  60. void
  61. TScrollWindow::Paint(TDC& dc, bool, TRect&)
  62. {
  63.   const int offsetX = 10;
  64.   const int offsetY = 30;
  65.  
  66.   // Golden ratio is 8/5. Derived from geometry.
  67.   //
  68.   const int goldenRatioX = 8;
  69.   const int goldenRatioY = 5;
  70.  
  71.   // Draw the rectangles
  72.   //
  73.   for (int i = 0; i < NumberOfRectangles; i++) {
  74.     int x = offsetX + i * goldenRatioX;
  75.     int y = offsetY + i * goldenRatioY;
  76.     dc.Rectangle(x, y, 2 * x, 3 * y);
  77.   }
  78. }
  79.  
  80.  
  81. //
  82. // class TScrollApp
  83. //
  84. class TScrollApp : public TApplication {
  85.   public:
  86.     TScrollApp()
  87.     :
  88.       TApplication("ScrollApp")
  89.     {
  90.     }
  91.     void InitMainWindow()
  92.     {
  93.       SetMainWindow(new TFrameWindow(0, "Boxes", new TScrollWindow));
  94.     }
  95. };
  96.  
  97. int
  98. OwlMain(int /*argc*/, char* /*argv*/ [])
  99. {
  100.   return TScrollApp().Run();
  101. }
  102.