| 1 |
/*************************************************************************** |
| 2 |
* Copyright (C) 2005-2019 by the FIFE team * |
| 3 |
* http://www.fifengine.net * |
| 4 |
* This file is part of FIFE. * |
| 5 |
* * |
| 6 |
* FIFE is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Lesser General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2.1 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * |
| 14 |
* Lesser General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Lesser General Public * |
| 17 |
* License along with this library; if not, write to the * |
| 18 |
* Free Software Foundation, Inc., * |
| 19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * |
| 20 |
***************************************************************************/ |
| 21 |
%module fife |
| 22 |
|
| 23 |
%{ |
| 24 |
#include "video/image.h" |
| 25 |
#include "video/cursor.h" |
| 26 |
#include "video/animation.h" |
| 27 |
#include "video/imagemanager.h" |
| 28 |
#include "video/animationmanager.h" |
| 29 |
#include "video/renderbackend.h" |
| 30 |
#include "video/devicecaps.h" |
| 31 |
#include "video/atlasbook.h" |
| 32 |
#include "video/color.h" |
| 33 |
#include "util/base/sharedptr.h" |
| 34 |
#include "util/base/exception.h" |
| 35 |
%} |
| 36 |
|
| 37 |
%include <attribute.i> |
| 38 |
|
| 39 |
%include "util/base/utilbase.i" |
| 40 |
%include "util/structures/utilstructures.i" |
| 41 |
%include "util/resource/resource.i" |
| 42 |
|
| 43 |
namespace FIFE { |
| 44 |
class ScreenMode; |
| 45 |
} |
| 46 |
|
| 47 |
namespace std { |
| 48 |
%template(ScreenModeVector) std::vector<FIFE::ScreenMode>; |
| 49 |
} |
| 50 |
|
| 51 |
%attribute(FIFE::Color, uint8_t, r, getR, setR); |
| 52 |
%attribute(FIFE::Color, uint8_t, g, getG, setG); |
| 53 |
%attribute(FIFE::Color, uint8_t, b, getB, setB); |
| 54 |
%attribute(FIFE::Color, uint8_t, a, getAlpha, setAlpha); |
| 55 |
|
| 56 |
namespace FIFE { |
| 57 |
class Point; |
| 58 |
class ResourceLocation; |
| 59 |
|
| 60 |
%apply uint8_t *OUTPUT { uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a }; |
| 61 |
|
| 62 |
class Image : public IResource { |
| 63 |
public: |
| 64 |
//void render(const Rect& rect, uint8_t alpha = 255, uint8_t const* rgb = 0); |
| 65 |
virtual ~Image(); |
| 66 |
SDL_Surface* getSurface(); |
| 67 |
uint32_t getWidth() const; |
| 68 |
uint32_t getHeight() const; |
| 69 |
Rect getArea() const; |
| 70 |
void setXShift(int32_t xshift); |
| 71 |
inline int32_t getXShift() const; |
| 72 |
void setYShift(int32_t yshift); |
| 73 |
inline int32_t getYShift() const; |
| 74 |
void getPixelRGBA(int32_t x, int32_t y, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a); |
| 75 |
void saveImage(const std::string& filename); |
| 76 |
|
| 77 |
virtual void useSharedImage(const FIFE::ImagePtr& shared, const Rect& region) = 0; |
| 78 |
virtual void forceLoadInternal() = 0; |
| 79 |
bool isSharedImage() const; |
| 80 |
const Rect& getSubImageRect() const; |
| 81 |
void copySubimage(uint32_t xoffset, uint32_t yoffset, const FIFE::ImagePtr& img); |
| 82 |
|
| 83 |
private: |
| 84 |
Image(SDL_Surface* surface); |
| 85 |
Image(const uint8_t* data, uint32_t width, uint32_t height); |
| 86 |
}; |
| 87 |
|
| 88 |
typedef SharedPtr<Image> ImagePtr; |
| 89 |
%template(SharedImagePointer) SharedPtr<Image>; |
| 90 |
|
| 91 |
class ImageManager : public IResourceManager { |
| 92 |
public: |
| 93 |
virtual ~ImageManager(); |
| 94 |
|
| 95 |
virtual size_t getMemoryUsed() const; |
| 96 |
virtual size_t getTotalResourcesCreated() const; |
| 97 |
virtual size_t getTotalResourcesLoaded() const; |
| 98 |
virtual size_t getTotalResources() const; |
| 99 |
|
| 100 |
virtual ImagePtr create(const std::string& name, IResourceLoader* loader = 0); |
| 101 |
virtual ImagePtr load(const std::string& name, IResourceLoader* loader = 0); |
| 102 |
virtual ImagePtr loadBlank(uint32_t width, uint32_t height); |
| 103 |
virtual ImagePtr add(Image* res); |
| 104 |
|
| 105 |
virtual bool exists(const std::string& name); |
| 106 |
virtual bool exists(ResourceHandle handle); |
| 107 |
|
| 108 |
virtual void reload(const std::string& name); |
| 109 |
virtual void reload(ResourceHandle handle); |
| 110 |
virtual void reloadAll(); |
| 111 |
virtual void loadUnreferenced(); |
| 112 |
|
| 113 |
virtual void free(const std::string& name); |
| 114 |
virtual void free(ResourceHandle handle); |
| 115 |
virtual void freeAll(); |
| 116 |
virtual void freeUnreferenced(); |
| 117 |
|
| 118 |
virtual void remove(ImagePtr& resource); |
| 119 |
virtual void remove(const std::string& name); |
| 120 |
virtual void remove(ResourceHandle handle); |
| 121 |
virtual void removeAll(); |
| 122 |
virtual void removeUnreferenced(); |
| 123 |
|
| 124 |
virtual ImagePtr get(const std::string& name); |
| 125 |
virtual ImagePtr get(ResourceHandle handle); |
| 126 |
|
| 127 |
virtual ResourceHandle getResourceHandle(const std::string& name); |
| 128 |
|
| 129 |
virtual void invalidate(const std::string& name); |
| 130 |
virtual void invalidate(ResourceHandle handle); |
| 131 |
virtual void invalidateAll(); |
| 132 |
}; |
| 133 |
|
| 134 |
class Animation: public IResource { |
| 135 |
public: |
| 136 |
~Animation(); |
| 137 |
void addFrame(ImagePtr image, uint32_t duration); |
| 138 |
int32_t getFrameIndex(uint32_t timestamp); |
| 139 |
ImagePtr getFrame(int32_t index); |
| 140 |
ImagePtr getFrameByTimestamp(uint32_t timestamp); |
| 141 |
int32_t getFrameDuration(int32_t index); |
| 142 |
uint32_t getFrameCount() const; |
| 143 |
void setActionFrame(int32_t num); |
| 144 |
int32_t getActionFrame(); |
| 145 |
void setDirection(uint32_t direction); |
| 146 |
uint32_t getDirection(); |
| 147 |
int32_t getDuration(); |
| 148 |
}; |
| 149 |
|
| 150 |
typedef SharedPtr<Animation> AnimationPtr; |
| 151 |
%template(SharedAnimationPointer) SharedPtr<Animation>; |
| 152 |
|
| 153 |
class AnimationManager : public IResourceManager { |
| 154 |
public: |
| 155 |
virtual ~AnimationManager(); |
| 156 |
|
| 157 |
virtual size_t getMemoryUsed() const; |
| 158 |
virtual size_t getTotalResourcesCreated() const; |
| 159 |
virtual size_t getTotalResourcesLoaded() const; |
| 160 |
virtual size_t getTotalResources() const; |
| 161 |
|
| 162 |
virtual AnimationPtr create(const std::string& name, IResourceLoader* loader = 0); |
| 163 |
virtual AnimationPtr add(Animation* res); |
| 164 |
|
| 165 |
virtual bool exists(const std::string& name); |
| 166 |
virtual bool exists(ResourceHandle handle); |
| 167 |
|
| 168 |
virtual void reload(const std::string& name); |
| 169 |
virtual void reload(ResourceHandle handle); |
| 170 |
virtual void reloadAll(); |
| 171 |
virtual void loadUnreferenced(); |
| 172 |
|
| 173 |
virtual void free(const std::string& name); |
| 174 |
virtual void free(ResourceHandle handle); |
| 175 |
virtual void freeAll(); |
| 176 |
virtual void freeUnreferenced(); |
| 177 |
|
| 178 |
virtual void remove(ImagePtr& resource); |
| 179 |
virtual void remove(const std::string& name); |
| 180 |
virtual void remove(ResourceHandle handle); |
| 181 |
virtual void removeAll(); |
| 182 |
virtual void removeUnreferenced(); |
| 183 |
|
| 184 |
virtual AnimationPtr get(const std::string& name); |
| 185 |
virtual AnimationPtr get(ResourceHandle handle); |
| 186 |
|
| 187 |
virtual AnimationPtr getPtr(const std::string& name); |
| 188 |
virtual AnimationPtr getPtr(ResourceHandle handle); |
| 189 |
|
| 190 |
virtual ResourceHandle getResourceHandle(const std::string& name); |
| 191 |
|
| 192 |
virtual void invalidate(const std::string& name); |
| 193 |
virtual void invalidate(ResourceHandle handle); |
| 194 |
virtual void invalidateAll(); |
| 195 |
}; |
| 196 |
|
| 197 |
enum TextureFiltering { |
| 198 |
TEXTURE_FILTER_NONE = 0, |
| 199 |
TEXTURE_FILTER_BILINEAR = 1, |
| 200 |
TEXTURE_FILTER_TRILINEAR = 2, |
| 201 |
TEXTURE_FILTER_ANISOTROPIC = 3 |
| 202 |
}; |
| 203 |
|
| 204 |
class RenderBackend { |
| 205 |
public: |
| 206 |
virtual ~RenderBackend(); |
| 207 |
virtual const std::string& getName() const = 0; |
| 208 |
|
| 209 |
void captureScreen(const std::string& filename); |
| 210 |
void captureScreen(const std::string& filename, uint32_t width, uint32_t height); |
| 211 |
const ScreenMode& getCurrentScreenMode() const; |
| 212 |
uint32_t getWidth() const; |
| 213 |
uint32_t getHeight() const; |
| 214 |
uint32_t getScreenWidth() const; |
| 215 |
uint32_t getScreenHeight() const; |
| 216 |
const Rect& getArea(); |
| 217 |
const Rect& getClipArea() const; |
| 218 |
void setAlphaOptimizerEnabled(bool enabled); |
| 219 |
bool isAlphaOptimizerEnabled(); |
| 220 |
void setImageCompressingEnabled(bool enabled); |
| 221 |
bool isImageCompressingEnabled() const; |
| 222 |
void setFramebufferEnabled(bool enabled); |
| 223 |
bool isFramebufferEnabled() const; |
| 224 |
void setNPOTEnabled(bool enabled); |
| 225 |
bool isNPOTEnabled() const; |
| 226 |
void setTextureFiltering(TextureFiltering filter); |
| 227 |
TextureFiltering getTextureFiltering() const; |
| 228 |
void setMipmappingEnabled(bool enabled); |
| 229 |
bool isMipmappingEnabled() const; |
| 230 |
void setMonochromeEnabled(bool enabled); |
| 231 |
bool isMonochromeEnabled() const; |
| 232 |
void setColorKeyEnabled(bool colorkeyenable); |
| 233 |
bool isColorKeyEnabled() const; |
| 234 |
void setColorKey(const SDL_Color& colorkey); |
| 235 |
const SDL_Color& getColorKey() const; |
| 236 |
const SDL_PixelFormat& getPixelFormat() const; |
| 237 |
void setBackgroundColor(uint8_t r, uint8_t g, uint8_t b); |
| 238 |
void resetBackgroundColor(); |
| 239 |
void setVSyncEnabled(bool vsync); |
| 240 |
bool isVSyncEnabled() const; |
| 241 |
void setFrameLimitEnabled(bool limited); |
| 242 |
bool isFrameLimitEnabled() const; |
| 243 |
void setFrameLimit(uint16_t framelimit); |
| 244 |
uint16_t getFrameLimit() const; |
| 245 |
}; |
| 246 |
|
| 247 |
enum MouseCursorType { |
| 248 |
CURSOR_NONE, |
| 249 |
CURSOR_NATIVE, |
| 250 |
CURSOR_IMAGE, |
| 251 |
CURSOR_ANIMATION |
| 252 |
}; |
| 253 |
|
| 254 |
enum NativeCursor { |
| 255 |
NC_ARROW = 1000000, |
| 256 |
NC_IBEAM, |
| 257 |
NC_WAIT, |
| 258 |
NC_CROSS, |
| 259 |
NC_WAITARROW, |
| 260 |
NC_RESIZENWSE, |
| 261 |
NC_RESIZENESW, |
| 262 |
NC_RESIZEWE, |
| 263 |
NC_RESIZENS, |
| 264 |
NC_RESIZEALL, |
| 265 |
NC_NO, |
| 266 |
NC_HAND |
| 267 |
}; |
| 268 |
|
| 269 |
%apply int32_t *OUTPUT { int32_t* x, int32_t* y }; |
| 270 |
|
| 271 |
class Cursor { |
| 272 |
public: |
| 273 |
virtual ~Cursor() {} |
| 274 |
virtual void draw(); |
| 275 |
void set(uint32_t cursor_id=0); |
| 276 |
void set(AnimationPtr anim); |
| 277 |
void set(ImagePtr image); |
| 278 |
void setDrag(AnimationPtr anim, int32_t drag_offset_x=0, int32_t drag_offset_y=0); |
| 279 |
void setDrag(ImagePtr image, int32_t drag_offset_x=0, int32_t drag_offset_y=0); |
| 280 |
void resetDrag(); |
| 281 |
MouseCursorType getType() const; |
| 282 |
uint32_t getId() const; |
| 283 |
ImagePtr getImage(); |
| 284 |
AnimationPtr getAnimation(); |
| 285 |
MouseCursorType getDragType() const; |
| 286 |
ImagePtr getDragImage(); |
| 287 |
AnimationPtr getDragAnimation(); |
| 288 |
uint32_t getX() const; |
| 289 |
uint32_t getY() const; |
| 290 |
void setPosition(uint32_t x, uint32_t y); |
| 291 |
void getPosition(int32_t* x, int32_t* y); |
| 292 |
void setNativeImageCursorEnabled(bool native_image_cursor_enabled); |
| 293 |
bool isNativeImageCursorEnabled() const; |
| 294 |
|
| 295 |
private: |
| 296 |
Cursor(); |
| 297 |
}; |
| 298 |
|
| 299 |
class ScreenMode { |
| 300 |
public: |
| 301 |
~ScreenMode(); |
| 302 |
|
| 303 |
uint16_t getWidth() const; |
| 304 |
uint16_t getHeight() const; |
| 305 |
uint16_t getBPP() const; |
| 306 |
uint16_t getRefreshRate() const; |
| 307 |
uint32_t getSDLFlags() const; |
| 308 |
bool isFullScreen(); |
| 309 |
bool isOpenGL(); |
| 310 |
bool isSDL() const; |
| 311 |
uint8_t getDisplay() const; |
| 312 |
const std::string& getRenderDriverName() const; |
| 313 |
|
| 314 |
static const uint32_t WINDOWED_OPENGL; |
| 315 |
static const uint32_t FULLSCREEN_OPENGL; |
| 316 |
static const uint32_t WINDOWED_SDL; |
| 317 |
static const uint32_t FULLSCREEN_SDL; |
| 318 |
}; |
| 319 |
|
| 320 |
class DeviceCaps { |
| 321 |
public: |
| 322 |
DeviceCaps(); |
| 323 |
~DeviceCaps(); |
| 324 |
|
| 325 |
void fillDeviceCaps(); |
| 326 |
std::vector<ScreenMode> getSupportedScreenModes() const; |
| 327 |
ScreenMode getNearestScreenMode(uint16_t width, uint16_t height, uint16_t bpp, const std::string& renderer, bool fs) const; |
| 328 |
ScreenMode getNearestScreenMode(uint16_t width, uint16_t height, uint16_t bpp, const std::string& renderer, bool fs, uint16_t refresh, uint8_t display = 0) const; |
| 329 |
std::string getVideoDriverName() const; |
| 330 |
std::vector<string> getAvailableVideoDrivers() const; |
| 331 |
std::string getRenderDriverName() const; |
| 332 |
void setRenderDriverName(const std::string& driver); |
| 333 |
std::vector<std::string> getAvailableRenderDrivers() const; |
| 334 |
|
| 335 |
uint8_t getDisplayCount() const; |
| 336 |
std::string getDisplayName(uint8_t display = 0) const; |
| 337 |
uint32_t getDesktopFormat(uint8_t display = 0) const; |
| 338 |
int32_t getDesktopRefreshRate(uint8_t display = 0) const; |
| 339 |
int32_t getDesktopWidth(uint8_t display = 0) const; |
| 340 |
int32_t getDesktopHeight(uint8_t display = 0) const; |
| 341 |
Rect getDisplayBounds(uint8_t display = 0) const; |
| 342 |
}; |
| 343 |
|
| 344 |
class AtlasBlock { |
| 345 |
public: |
| 346 |
uint32_t page; |
| 347 |
uint32_t left, right, top, bottom; |
| 348 |
|
| 349 |
AtlasBlock(const Rect& rect, uint32_t page); |
| 350 |
AtlasBlock(); |
| 351 |
|
| 352 |
void setTrivial(); |
| 353 |
bool isTrivial() const; |
| 354 |
|
| 355 |
uint32_t getWidth() const; |
| 356 |
uint32_t getHeight() const; |
| 357 |
|
| 358 |
AtlasBlock intersects(AtlasBlock const& rect) const; |
| 359 |
void merge(AtlasBlock const& rect); |
| 360 |
}; |
| 361 |
|
| 362 |
class AtlasBook { |
| 363 |
public: |
| 364 |
AtlasBook(uint32_t pageWidth, uint32_t pageHeight, uint32_t pixelSize = 4); |
| 365 |
|
| 366 |
AtlasBlock* getBlock(uint32_t width, uint32_t height); |
| 367 |
void shrink(bool pot); |
| 368 |
}; |
| 369 |
|
| 370 |
%extend AtlasBook { |
| 371 |
uint32_t getPageWidth(uint32_t index) { |
| 372 |
return $self->getPage(index).getWidth(); |
| 373 |
} |
| 374 |
uint32_t getPageHeight(uint32_t index) { |
| 375 |
return $self->getPage(index).getHeight(); |
| 376 |
} |
| 377 |
} |
| 378 |
|
| 379 |
class Color { |
| 380 |
public: |
| 381 |
Color(uint8_t r = 0, uint8_t g = 0, uint8_t b = 0, uint8_t alpha = 255); |
| 382 |
~Color(); |
| 383 |
|
| 384 |
void set(uint8_t r, uint8_t g, uint8_t b, uint8_t alpha); |
| 385 |
void setR(uint8_t r); |
| 386 |
void setG(uint8_t g); |
| 387 |
void setB(uint8_t b); |
| 388 |
void setAlpha(uint8_t alpha); |
| 389 |
|
| 390 |
uint8_t getR() const; |
| 391 |
uint8_t getG() const; |
| 392 |
uint8_t getB() const; |
| 393 |
uint8_t getAlpha() const; |
| 394 |
}; |
| 395 |
} |