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

Canvas.cpp

Go to the documentation of this file.
00001 /*********************************************************************************
00002  *
00003  * Razor! Engine - A modular C++ presentation engine
00004  *
00005  * $Id: Canvas.h,v 1.1.1.1 2000/12/09 09:28:39 christ Exp $
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 
00026 #include "Customization.h"
00027 #include "Canvas.h"
00028 #include "Device.h"
00029 
00030 Canvas::Canvas()
00031 {
00032     //
00033     // Determine size of display
00034     //
00035     WinGetDisplayExtent(&width, &height);
00036         
00037     displayBounds.topLeft.x = 0;
00038     displayBounds.topLeft.y = 0;
00039     displayBounds.extent.x = width;
00040     displayBounds.extent.y = height;
00041 
00042 
00043     //
00044     // Set proper color mode and bit-depth
00045     //
00046     UInt32 supportedDepths;
00047     Boolean supportsColor;
00048     WinScreenMode(winScreenModeGetSupportedDepths, NULL, NULL, &supportedDepths, NULL);     
00049     WinScreenMode(winScreenModeGetSupportsColor, NULL, NULL, NULL, &supportsColor); 
00050             
00051     // Iterate over all supported modes
00052     for (UInt16 i = 0; ; i++)
00053     {
00054         UInt32 mode = supportedCanvasModes[i];
00055         if (mode == 0)
00056         {
00057             Device::panic(sysErrParamErr, "Required screen mode not supported by device!");
00058         }       
00059 
00060         if ((mode & 0x80000000) && (!supportsColor))
00061         {
00062             continue;  // Color required, but device is only grayscale.
00063         }
00064 
00065         if (!(mode & supportedDepths))
00066         {
00067             continue;  // Required bit-depth not available
00068         }
00069 
00070         // All requirements of this mode are fulfilled :-)))
00071 
00072         colorMode = (mode & 0x80000000);
00073 
00074         // Determine selectedDepth
00075         selectedDepth = 1;
00076         for (UInt32 selector = 1; ; selector <<= 1, selectedDepth++)
00077         {
00078             if (mode & selector)
00079                 break;                      
00080         }
00081         
00082         break;
00083     }
00084 
00085 
00086     // Set selected screen mode 
00087     Err error = WinScreenMode(winScreenModeSet, NULL, NULL, &selectedDepth, NULL);
00088     ErrNonFatalDisplayIf(error, "Unable to set screen mode");
00089 
00090     // Ugly hack against broken grayscale palette in PalmOS 3.1. This is fixed in 3.1.1
00091     if (selectedDepth == 2)
00092     {
00093         if ((Device::supports31) && (!(Device::supports35)))
00094         {                   
00095             UInt16 value = 3 + (7 << 4) + (1 << 12);
00096             *((UInt16 *)0xFFFFFA32) = value;    // Poke default grayscale values directly into display controller
00097         }
00098     }
00099 
00100     // Enable special 4bpp color mode
00101     if ((selectedDepth == 4) && colorMode)
00102     {
00103         RGBColorType palette[] = {
00104                              {  0, 0xff, 0xff, 0xff },
00105                              {  1, 0x80, 0x80, 0x80 },
00106                              {  2, 0x80, 0x00, 0x00 },
00107                              {  3, 0x80, 0x80, 0x00 },
00108                              {  4, 0x00, 0x80, 0x00 },
00109                              {  5, 0x00, 0x80, 0x80 },
00110                              {  6, 0x00, 0x00, 0x80 },
00111                              {  7, 0x80, 0x00, 0x80 },
00112                              {  8, 0xff, 0x00, 0xff },
00113                              {  9, 0xc0, 0xc0, 0xc0 },
00114                              { 10, 0xff, 0x00, 0x00 },
00115                              { 11, 0xff, 0xff, 0x00 },
00116                              { 12, 0x00, 0xff, 0x00 },
00117                              { 13, 0x00, 0xff, 0xff },
00118                              { 14, 0x00, 0x00, 0xff },
00119                              { 15, 0x00, 0x00, 0x00 }
00120                            };
00121                            
00122         WinPalette(winPaletteSet,0,16,palette);
00123     }
00124 }
00125 
00126 
00127 Canvas::~Canvas() 
00128 {
00129     // Restore display color-depth to normal
00130     WinScreenMode(winScreenModeSetToDefaults, NULL, NULL, NULL, NULL);
00131 }
00132 
00133 
00134 void Canvas::uniteBounds(RectangleType *rect1Bound, RectangleType *rect2Bound, RectangleType *resultBound)
00135 {
00136     Coord rect1RightEdge = rect1Bound->topLeft.x + rect1Bound->extent.x;
00137     Coord rect2RightEdge = rect2Bound->topLeft.x + rect2Bound->extent.x;
00138 
00139     if (rect1Bound->topLeft.x < rect2Bound->topLeft.x)
00140         resultBound->topLeft.x = rect1Bound->topLeft.x;
00141     else
00142         resultBound->topLeft.x = rect2Bound->topLeft.x;
00143 
00144     if (rect1RightEdge > rect2RightEdge)
00145         resultBound->extent.x = rect1RightEdge - resultBound->topLeft.x;
00146     else
00147         resultBound->extent.x = rect2RightEdge - resultBound->topLeft.x;
00148 
00149 
00150     Coord rect1BottomEdge = rect1Bound->topLeft.y + rect1Bound->extent.y;
00151     Coord rect2BottomEdge = rect2Bound->topLeft.y + rect2Bound->extent.y;
00152 
00153     if (rect1Bound->topLeft.y < rect2Bound->topLeft.y)
00154         resultBound->topLeft.y = rect1Bound->topLeft.y;
00155     else
00156         resultBound->topLeft.y = rect2Bound->topLeft.y;
00157 
00158     if (rect1BottomEdge > rect2BottomEdge)
00159         resultBound->extent.y = rect1BottomEdge - resultBound->topLeft.y;
00160     else
00161         resultBound->extent.y = rect2BottomEdge - resultBound->topLeft.y;
00162 }

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