1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
/*
* CWindowObject.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "CWindowObject.h"
#include "../widgets/MiscWidgets.h"
#include "../widgets/Images.h"
#include "../widgets/TextControls.h"
#include "../gui/CGuiHandler.h"
#include "../gui/CursorHandler.h"
#include "../battle/BattleInterface.h"
#include "../battle/BattleInterfaceClasses.h"
#include "../windows/CMessage.h"
#include "../renderSDL/SDL_PixelAccess.h"
#include "../render/IImage.h"
#include "../render/IScreenHandler.h"
#include "../render/IRenderHandler.h"
#include "../render/Canvas.h"
#include "../render/CanvasImage.h"
#include "../CGameInfo.h"
#include "../CPlayerInterface.h"
#include "../../CCallback.h"
#include "../../lib/CConfigHandler.h"
#include "../../lib/texts/CGeneralTextHandler.h" //for Unicode related stuff
#include <SDL_surface.h>
CWindowObject::CWindowObject(int options_, const ImagePath & imageName, Point centerAt):
WindowBase(0, Point()),
options(options_),
background(createBg(imageName, options & PLAYER_COLORED))
{
if(!(options & NEEDS_ANIMATED_BACKGROUND)) //currently workaround for highscores (currently uses window as normal control, because otherwise videos are not played in background yet)
assert(parent == nullptr); //Safe to remove, but windows should not have parent
if (options & RCLICK_POPUP)
CCS->curh->hide();
if (background)
pos = background->center(centerAt);
else
center(centerAt);
if (!(options & SHADOW_DISABLED))
setShadow(true);
}
CWindowObject::CWindowObject(int options_, const ImagePath & imageName):
WindowBase(0, Point()),
options(options_),
background(createBg(imageName, options_ & PLAYER_COLORED))
{
if(!(options & NEEDS_ANIMATED_BACKGROUND)) //currently workaround for highscores (currently uses window as normal control, because otherwise videos are not played in background yet)
assert(parent == nullptr); //Safe to remove, but windows should not have parent
if(options & RCLICK_POPUP)
CCS->curh->hide();
if(background)
pos = background->center();
else
center(GH.screenDimensions() / 2);
if(!(options & SHADOW_DISABLED))
setShadow(true);
}
CWindowObject::~CWindowObject()
{
if(options & RCLICK_POPUP)
CCS->curh->show();
}
std::shared_ptr<CPicture> CWindowObject::createBg(const ImagePath & imageName, bool playerColored)
{
OBJECT_CONSTRUCTION;
if(imageName.empty())
return nullptr;
auto image = std::make_shared<CPicture>(imageName, Point(0,0), EImageBlitMode::OPAQUE);
if(playerColored)
image->setPlayerColor(LOCPLINT->playerID);
return image;
}
void CWindowObject::setBackground(const ImagePath & filename)
{
OBJECT_CONSTRUCTION;
background = createBg(filename, options & PLAYER_COLORED);
if(background)
pos = background->center(Point(pos.w/2 + pos.x, pos.h/2 + pos.y));
updateShadow();
}
void CWindowObject::updateShadow()
{
setShadow(false);
if (!(options & SHADOW_DISABLED))
setShadow(true);
}
void CWindowObject::setShadow(bool on)
{
//size of shadow
int size = 8;
if(on == !shadowParts.empty())
return;
shadowParts.clear();
//object too small to cast shadow
if(pos.h <= size || pos.w <= size)
return;
if(on)
{
//FIXME: do something with this points
Point shadowStart;
if (options & BORDERED)
shadowStart = Point(size - 14, size - 14);
else
shadowStart = Point(size, size);
Point shadowPos;
if (options & BORDERED)
shadowPos = Point(pos.w + 14, pos.h + 14);
else
shadowPos = Point(pos.w, pos.h);
Point fullsize;
if (options & BORDERED)
fullsize = Point(pos.w + 28, pos.h + 29);
else
fullsize = Point(pos.w, pos.h);
Point sizeCorner(size, size);
Point sizeRight(fullsize.x - size, size);
Point sizeBottom(size, fullsize.y - size);
//create base 8x8 piece of shadow
auto imageCorner = GH.renderHandler().createImage(sizeCorner, CanvasScalingPolicy::AUTO);
auto imageRight = GH.renderHandler().createImage(sizeRight, CanvasScalingPolicy::AUTO);
auto imageBottom = GH.renderHandler().createImage(sizeBottom, CanvasScalingPolicy::AUTO);
Canvas canvasCorner = imageCorner->getCanvas();
Canvas canvasRight = imageRight->getCanvas();
Canvas canvasBottom = imageBottom->getCanvas();
canvasCorner.drawColor(Rect(Point(0,0), sizeCorner), { 0, 0, 0, 128 });
canvasRight.drawColor(Rect(Point(0,0), sizeRight), { 0, 0, 0, 128 });
canvasBottom.drawColor(Rect(Point(0,0), sizeBottom), { 0, 0, 0, 128 });
canvasCorner.drawColor(Rect(Point(0,0), sizeCorner - Point(1,1)), { 0, 0, 0, 192 });
canvasRight.drawColor(Rect(Point(0,0), sizeRight - Point(0,1)), { 0, 0, 0, 192 });
canvasBottom.drawColor(Rect(Point(0,0), sizeBottom - Point(1,0)), { 0, 0, 0, 192 });
//generate "shadow" object with these 3 pieces in it
{
OBJECT_CONSTRUCTION;
shadowParts.push_back(std::make_shared<CPicture>( imageCorner, Point(shadowPos.x, shadowPos.y)));
shadowParts.push_back(std::make_shared<CPicture>( imageRight, Point(shadowStart.x, shadowPos.y)));
shadowParts.push_back(std::make_shared<CPicture>( imageBottom, Point(shadowPos.x, shadowStart.y)));
}
}
}
void CWindowObject::showAll(Canvas & to)
{
auto color = LOCPLINT ? LOCPLINT->playerID : PlayerColor(1);
if(settings["session"]["spectate"].Bool())
color = PlayerColor(1); // TODO: Spectator shouldn't need special code for UI colors
CIntObject::showAll(to);
if ((options & BORDERED) && (pos.dimensions() != GH.screenDimensions()))
CMessage::drawBorder(color, to, pos.w+28, pos.h+29, pos.x-14, pos.y-15);
}
bool CWindowObject::isPopupWindow() const
{
return options & RCLICK_POPUP;
}
|