00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023
00024
00025
00026 #include "Customization.h"
00027 #include "Canvas.h"
00028 #include "Device.h"
00029
00030 Canvas::Canvas()
00031 {
00032
00033
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
00045
00046 UInt32 supportedDepths;
00047 Boolean supportsColor;
00048 WinScreenMode(winScreenModeGetSupportedDepths, NULL, NULL, &supportedDepths, NULL);
00049 WinScreenMode(winScreenModeGetSupportsColor, NULL, NULL, NULL, &supportsColor);
00050
00051
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;
00063 }
00064
00065 if (!(mode & supportedDepths))
00066 {
00067 continue;
00068 }
00069
00070
00071
00072 colorMode = (mode & 0x80000000);
00073
00074
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
00087 Err error = WinScreenMode(winScreenModeSet, NULL, NULL, &selectedDepth, NULL);
00088 ErrNonFatalDisplayIf(error, "Unable to set screen mode");
00089
00090
00091 if (selectedDepth == 2)
00092 {
00093 if ((Device::supports31) && (!(Device::supports35)))
00094 {
00095 UInt16 value = 3 + (7 << 4) + (1 << 12);
00096 *((UInt16 *)0xFFFFFA32) = value;
00097 }
00098 }
00099
00100
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
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 }