ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

VectorRenderer.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "common/textconsole.h"
00024 #include "common/util.h"
00025 
00026 #include "graphics/VectorRenderer.h"
00027 
00028 #define VECTOR_RENDERER_FAST_TRIANGLES
00029 
00030 namespace Graphics {
00031 
00032 /********************************************************************
00033  * DRAWSTEP handling functions
00034  ********************************************************************/
00035 void VectorRenderer::drawStep(const Common::Rect &area, const Common::Rect &clip, const DrawStep &step, uint32 extra) {
00036 
00037     if (step.bgColor.set)
00038         setBgColor(step.bgColor.r, step.bgColor.g, step.bgColor.b);
00039 
00040     if (step.fgColor.set)
00041         setFgColor(step.fgColor.r, step.fgColor.g, step.fgColor.b);
00042 
00043     if (step.bevelColor.set)
00044         setBevelColor(step.bevelColor.r, step.bevelColor.g, step.bevelColor.b);
00045 
00046     if (step.gradColor1.set && step.gradColor2.set)
00047         setGradientColors(step.gradColor1.r, step.gradColor1.g, step.gradColor1.b,
00048             step.gradColor2.r, step.gradColor2.g, step.gradColor2.b);
00049 
00050     setShadowOffset(_disableShadows ? 0 : step.shadow);
00051     setBevel(step.bevel);
00052     setGradientFactor(step.factor);
00053     setStrokeWidth(step.stroke);
00054     setFillMode((FillMode)step.fillMode);
00055     setClippingRect(applyStepClippingRect(area, clip, step));
00056 
00057     _dynamicData = extra;
00058 
00059     (this->*(step.drawingCall))(area, step);
00060 }
00061 
00062 Common::Rect VectorRenderer::applyStepClippingRect(const Common::Rect &area, const Common::Rect &clip, const DrawStep &step) {
00063     if (step.clip == Common::Rect()) {
00064         return clip;
00065     }
00066 
00067     Common::Rect finalClip = clip;
00068     if (step.clip.left > 0) {
00069         finalClip.left = area.left + step.clip.left;
00070     } else if (step.clip.left < 0) {
00071         finalClip.left = area.right + step.clip.left;
00072     }
00073 
00074     if (step.clip.top > 0) {
00075         finalClip.top = area.top + step.clip.top;
00076     } else if (step.clip.top < 0) {
00077         finalClip.top = area.bottom + step.clip.top;
00078     }
00079 
00080     if (step.clip.right > 0) {
00081         finalClip.right = area.left + step.clip.right;
00082     } else if (step.clip.right < 0) {
00083         finalClip.right = area.right + step.clip.right;
00084     }
00085 
00086     if (step.clip.bottom > 0) {
00087         finalClip.bottom = area.top + step.clip.bottom;
00088     } else if (step.clip.bottom < 0) {
00089         finalClip.bottom = area.bottom + step.clip.bottom;
00090     }
00091 
00092     finalClip.clip(clip);
00093 
00094     return finalClip;
00095 }
00096 
00097 int VectorRenderer::stepGetRadius(const DrawStep &step, const Common::Rect &area) {
00098     int radius = 0;
00099 
00100     if (step.radius == 0xFF)
00101         radius = MIN(area.width(), area.height()) / 2;
00102     else
00103         radius = step.radius;
00104 
00105     if (step.scale != (1 << 16) && step.scale != 0)
00106         radius = (radius * step.scale) >> 16;
00107 
00108     return radius;
00109 }
00110 
00111 void VectorRenderer::stepGetPositions(const DrawStep &step, const Common::Rect &area, uint16 &in_x, uint16 &in_y, uint16 &in_w, uint16 &in_h) {
00112     if (!step.autoWidth) {
00113         in_w = step.w == -1 ? area.height() : step.w;
00114 
00115         switch (step.xAlign) {
00116         case Graphics::DrawStep::kVectorAlignManual:
00117             if (step.x >= 0)
00118                 in_x = area.left + step.x + step.padding.left;
00119             else
00120                 in_x = area.left + area.width() + step.x + step.padding.left; // value relative to the opposite corner.
00121             break;
00122 
00123         case Graphics::DrawStep::kVectorAlignCenter:
00124             in_x = area.left + (area.width() / 2) - (in_w / 2) + ((step.padding.left + step.padding.right ) / 2);
00125             break;
00126 
00127         case Graphics::DrawStep::kVectorAlignLeft:
00128             in_x = area.left  + step.padding.left;
00129             break;
00130 
00131         case Graphics::DrawStep::kVectorAlignRight:
00132             in_x = area.left + area.width() - in_w - step.padding.right;
00133             break;
00134 
00135         default:
00136             error("Vertical alignment in horizontal data");
00137         }
00138     } else {
00139         in_x = area.left + step.padding.left;
00140         in_w = area.width() - step.padding.left - step.padding.right;
00141     }
00142 
00143     if (!step.autoHeight) {
00144         in_h = step.h == -1 ? area.width() : step.h;
00145 
00146         switch (step.yAlign) {
00147         case Graphics::DrawStep::kVectorAlignManual:
00148             if (step.y >= 0)
00149                 in_y = area.top + step.y + step.padding.top;
00150             else
00151                 in_y = area.top + area.height() + step.y + step.padding.top; // relative
00152             break;
00153 
00154         case Graphics::DrawStep::kVectorAlignCenter:
00155             in_y = area.top + (area.height() / 2) - (in_h / 2) + ((step.padding.top + step.padding.bottom ) / 2);
00156             break;
00157 
00158         case Graphics::DrawStep::kVectorAlignTop:
00159             in_y = area.top + step.padding.top;
00160             break;
00161 
00162         case Graphics::DrawStep::kVectorAlignBottom:
00163             in_y = area.top + area.height() - in_h - step.padding.bottom;
00164             break;
00165 
00166         default:
00167             error("Horizontal alignment in vertical data");
00168         }
00169     } else {
00170         in_y = area.top + step.padding.top;
00171         in_h = area.height() - step.padding.top - step.padding.bottom;
00172     }
00173 
00174     if (step.scale != (1 << 16) && step.scale != 0) {
00175         in_x = (in_x * step.scale) >> 16;
00176         in_y = (in_y * step.scale) >> 16;
00177         in_w = (in_w * step.scale) >> 16;
00178         in_h = (in_h * step.scale) >> 16;
00179     }
00180 }
00181 
00182 } // End of namespace Graphics


Generated on Sat Aug 8 2020 05:01:24 for ResidualVM by doxygen 1.7.1
curved edge   curved edge