Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members

Canvas.h

Go to the documentation of this file.
00001 /*********************************************************************************
00002  *
00003  * Razor! Engine - A modular C++ presentation engine
00004  *
00005  * $Id$
00006  *
00007  * Copyright (c) 2000 Tilo Christ. All Rights Reserved.
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  *
00014  * This library is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Lesser General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public
00020  * License along with this library; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022  *
00023  **********************************************************************************/
00024 
00025 #ifndef CANVAS_H
00026 #define CANVAS_H
00027 
00028 #include <PalmOS.h>
00029 
00030 
00031 /**
00032  * Canvas manages a canvas into which a user can paint.
00033  */
00034 class Canvas
00035 {
00036     public:
00037 
00038 ///@name Construction / Destruction
00039 //@{
00040     /**
00041      * Construct a new canvas.
00042      */
00043     Canvas()
00044     {
00045         WinGetDisplayExtent(&width, &height);
00046         
00047         displayBounds.topLeft.x = 0;
00048         displayBounds.topLeft.y = 0;
00049         displayBounds.extent.x = width;
00050         displayBounds.extent.y = height;
00051     }
00052 
00053 
00054     /**
00055      * Destroy the canvas.
00056      */
00057     virtual ~Canvas() {}
00058 //@}
00059 
00060 
00061 /// @name Output management
00062 //@{
00063     /**
00064      * Switch drawing window to the window into which the application shall paint.
00065      */
00066     virtual void beginDraw(WinLockInitType initMode) = 0;
00067     
00068     /**
00069      * Notify the canvas of the end of user paint operations.
00070      * 
00071      * @param bounds the area that was modified by the user draw operation
00072      */
00073     virtual void endDraw(RectangleType *bounds) = 0;
00074 
00075     /**
00076      * Display user painted graphics.
00077      */
00078     virtual void show() = 0;    
00079 //@}
00080 
00081 
00082 /// @name Physical Display management
00083 //@{
00084     /**
00085      * Get the width of the display
00086      */
00087     Coord getWidth() const
00088     {
00089         return width;
00090     }
00091 
00092     
00093     /**
00094      * Get the height of the display
00095      */
00096     Coord getHeight() const
00097     {
00098         return height;
00099     }
00100 //@}
00101 
00102 
00103 
00104 /// @name Utility operations
00105 //@{
00106     /**
00107      * Determine a rectangle that encompasses two other rectangles.
00108      *
00109      * @param rect1Bound the bounds of rectangle #1
00110      * @param rect2Bound the bounds of rectangle #2
00111      * @param resultBound the bounds of the encompassing rectangle.
00112               rect1Bound, or rect2Bound, and resultBound may safely point to the same RectangleType structure.
00113      */
00114     static void uniteBounds(RectangleType *rect1Bound, RectangleType *rect2Bound, RectangleType *resultBound)
00115     {
00116         Coord rect1RightEdge = rect1Bound->topLeft.x + rect1Bound->extent.x;
00117         Coord rect2RightEdge = rect2Bound->topLeft.x + rect2Bound->extent.x;
00118 
00119         if (rect1Bound->topLeft.x < rect2Bound->topLeft.x)
00120             resultBound->topLeft.x = rect1Bound->topLeft.x;
00121         else
00122             resultBound->topLeft.x = rect2Bound->topLeft.x;
00123 
00124         if (rect1RightEdge > rect2RightEdge)
00125             resultBound->extent.x = rect1RightEdge - resultBound->topLeft.x;
00126         else
00127             resultBound->extent.x = rect2RightEdge - resultBound->topLeft.x;
00128 
00129 
00130         Coord rect1BottomEdge = rect1Bound->topLeft.y + rect1Bound->extent.y;
00131         Coord rect2BottomEdge = rect2Bound->topLeft.y + rect2Bound->extent.y;
00132 
00133         if (rect1Bound->topLeft.y < rect2Bound->topLeft.y)
00134             resultBound->topLeft.y = rect1Bound->topLeft.y;
00135         else
00136             resultBound->topLeft.y = rect2Bound->topLeft.y;
00137 
00138         if (rect1BottomEdge > rect2BottomEdge)
00139             resultBound->extent.y = rect1BottomEdge - resultBound->topLeft.y;
00140         else
00141             resultBound->extent.y = rect2BottomEdge - resultBound->topLeft.y;
00142     }
00143 //@}
00144 
00145     protected:
00146     RectangleType displayBounds;
00147 
00148     private:
00149     Coord width;
00150     Coord height;
00151 };
00152 
00153 
00154 #endif

Razor! Engine Developer's Guide. Copyright © by Tilo Christ. All Rights Reserved. Last updated: 4 Nov 2000