Modif du gitignore
This commit is contained in:
parent
31b41f28f0
commit
8e40f17b75
32
.gitignore
vendored
32
.gitignore
vendored
@ -17,21 +17,21 @@
|
|||||||
mono_crash.*
|
mono_crash.*
|
||||||
|
|
||||||
# Build results
|
# Build results
|
||||||
#[Dd]ebug/
|
[Dd]ebug/
|
||||||
#[Dd]ebugPublic/
|
[Dd]ebugPublic/
|
||||||
#[Rr]elease/
|
[Rr]elease/
|
||||||
#[Rr]eleases/
|
[Rr]eleases/
|
||||||
#x64/
|
x64/
|
||||||
#x86/
|
x86/
|
||||||
#[Ww][Ii][Nn]32/
|
[Ww][Ii][Nn]32/
|
||||||
#[Aa][Rr][Mm]/
|
[Aa][Rr][Mm]/
|
||||||
#[Aa][Rr][Mm]64/
|
[Aa][Rr][Mm]64/
|
||||||
#bld/
|
bld/
|
||||||
#[Bb]in/
|
[Bb]in/
|
||||||
#[Oo]bj/
|
[Oo]bj/
|
||||||
#[Oo]ut/
|
[Oo]ut/
|
||||||
#[Ll]og/
|
[Ll]og/
|
||||||
#[Ll]ogs/
|
[Ll]ogs/
|
||||||
|
|
||||||
# Visual Studio 2015/2017 cache/options directory
|
# Visual Studio 2015/2017 cache/options directory
|
||||||
.vs/
|
.vs/
|
||||||
@ -367,7 +367,9 @@ FodyWeavers.xsd
|
|||||||
/SQCSim2021/Release
|
/SQCSim2021/Release
|
||||||
/SQCSim2021/media/chunks
|
/SQCSim2021/media/chunks
|
||||||
/x64/Release/SQCSim2021.exe
|
/x64/Release/SQCSim2021.exe
|
||||||
|
/x64/Debug/SQCSim2021.exe
|
||||||
/SQCSim2021/x64/Release/SQCSim2021.tlog
|
/SQCSim2021/x64/Release/SQCSim2021.tlog
|
||||||
/SQCSim2021/x64/Debug
|
/SQCSim2021/x64/Debug
|
||||||
/x64/Release/SQCSim2023.exe
|
/x64/Release/SQCSim2023.exe
|
||||||
/x64/Debug/SQCSim2023.exe
|
/x64/Debug/SQCSim2023.exe
|
||||||
|
/x64/Debug/SQCSim2021.pdb
|
||||||
|
@ -1,64 +0,0 @@
|
|||||||
SRCS = $(wildcard *.cpp)
|
|
||||||
OBJS = $(SRCS:.cpp=.o)
|
|
||||||
BINFILE = ./mcclone
|
|
||||||
CC = g++
|
|
||||||
|
|
||||||
COMPILER_FLAGS = -I/usr/X11R6/include -I/usr/local/include -I./external/noise/include -I./external/enet-1.3.1/include -finline-functions -std=c++11
|
|
||||||
LINKER_FLAGS = -lm -L/usr/X11R6/lib -L/usr/local/lib -lGL -lGLU -lpthread -lsfml-graphics -lsfml-window -lsfml-system -lsndfile -lopenal -lsfml-audio -lXrandr -lIL -lILU -lX11 -ldl -lGLEW
|
|
||||||
|
|
||||||
# Release:
|
|
||||||
#CFLAGS = -O3 -fomit-frame-pointer -ffast-math -w $(COMPILER_FLAGS)
|
|
||||||
#LFLAGS = $(LINKER_FLAGS)
|
|
||||||
|
|
||||||
# Debug:
|
|
||||||
CFLAGS = -g -W -Wall $(COMPILER_FLAGS) -Wno-write-strings -Wno-unused-parameter -Wno-switch -Wno-reorder -DDEBUGMODE -DDEBUG
|
|
||||||
LFLAGS = $(LINKER_FLAGS)
|
|
||||||
|
|
||||||
# Profiling:
|
|
||||||
#CFLAGS = -pg -W -Wall $(COMPILER_FLAGS) -Wno-write-strings
|
|
||||||
#LFLAGS = -pg $(LINKER_FLAGS)
|
|
||||||
|
|
||||||
all : $(BINFILE)
|
|
||||||
|
|
||||||
$(BINFILE) : $(OBJS)
|
|
||||||
@echo Linking to $(BINFILE)...
|
|
||||||
@$(CC) $(OBJS) -o $(BINFILE) $(LFLAGS)
|
|
||||||
|
|
||||||
%.o : %.cpp
|
|
||||||
@echo CC $@
|
|
||||||
@$(CC) $(CFLAGS) -c $< -o $@
|
|
||||||
|
|
||||||
%.o : %.cc
|
|
||||||
@echo CC $@
|
|
||||||
@$(CC) $(CFLAGS) -c $< -o $@
|
|
||||||
|
|
||||||
%.o : %.C
|
|
||||||
@echo CC $@
|
|
||||||
@$(CC) $(CFLAGS) -c $< -o $@
|
|
||||||
|
|
||||||
%.o : %.cxx
|
|
||||||
@echo CC $@
|
|
||||||
@$(CC) $(CFLAGS) -c $< -o $@
|
|
||||||
|
|
||||||
strip:
|
|
||||||
@strip $(BINFILE)
|
|
||||||
|
|
||||||
clean:
|
|
||||||
@rm -f Makefile.bak
|
|
||||||
@rm -f $(OBJS)
|
|
||||||
@rm -f gmon.out
|
|
||||||
@rm -f profiler_output.txt
|
|
||||||
@rm -f $(BINFILE)
|
|
||||||
|
|
||||||
depend:
|
|
||||||
@$(CC) -MM $(CFLAGS) $(SRCS) > Makefile.dep
|
|
||||||
@make -s clean
|
|
||||||
|
|
||||||
info:
|
|
||||||
@echo SRCS: $(SRCS)
|
|
||||||
@echo OBJS: $(OBJS)
|
|
||||||
@echo $(BINFILE)
|
|
||||||
|
|
||||||
|
|
||||||
include Makefile.dep
|
|
||||||
|
|
140
SQCSim2021/external/devil178/include/IL/config.h
vendored
140
SQCSim2021/external/devil178/include/IL/config.h
vendored
@ -1,140 +0,0 @@
|
|||||||
/* include/IL/config.h. Generated by configure. */
|
|
||||||
/* include/IL/config.h.in. Generated from configure.in by autoheader. */
|
|
||||||
#ifndef __CONFIG_H__
|
|
||||||
#define __CONFIG_H__
|
|
||||||
|
|
||||||
#define IL_USE_PRAGMA_LIBS
|
|
||||||
|
|
||||||
// Supported image formats (IL)
|
|
||||||
|
|
||||||
// #define IL_NO_BLP
|
|
||||||
// #define IL_NO_BMP
|
|
||||||
// #define IL_NO_CUT
|
|
||||||
// #define IL_NO_CHEAD
|
|
||||||
// #define IL_NO_DCX
|
|
||||||
// #define IL_NO_DDS
|
|
||||||
// #define IL_NO_DICOM
|
|
||||||
// #define IL_NO_DOOM
|
|
||||||
// #define IL_NO_EXR
|
|
||||||
// #define IL_NO_FITS
|
|
||||||
// #define IL_NO_FTX
|
|
||||||
// #define IL_NO_GIF
|
|
||||||
// #define IL_NO_HDR
|
|
||||||
// #define IL_NO_ICO
|
|
||||||
// #define IL_NO_ICNS
|
|
||||||
// #define IL_NO_IWI
|
|
||||||
// #define IL_NO_JP2
|
|
||||||
// #define IL_NO_JPG
|
|
||||||
// #define IL_NO_LCMS
|
|
||||||
// #define IL_NO_LIF
|
|
||||||
// #define IL_NO_MDL
|
|
||||||
// #define IL_NO_MNG
|
|
||||||
// #define IL_NO_PCD
|
|
||||||
// #define IL_NO_PCX
|
|
||||||
// #define IL_NO_PIC
|
|
||||||
// #define IL_NO_PIX
|
|
||||||
// #define IL_NO_PNG
|
|
||||||
// #define IL_NO_PNM
|
|
||||||
// #define IL_NO_PSD
|
|
||||||
// #define IL_NO_PSP
|
|
||||||
// #define IL_NO_PXR
|
|
||||||
// #define IL_NO_RAW
|
|
||||||
// #define IL_NO_ROT
|
|
||||||
// #define IL_NO_SGI
|
|
||||||
// #define IL_NO_SUN
|
|
||||||
// #define IL_NO_TGA
|
|
||||||
// #define IL_NO_TIF
|
|
||||||
// #define IL_NO_TPL
|
|
||||||
// #define IL_NO_WAL
|
|
||||||
// #define IL_NO_WDP
|
|
||||||
// #define IL_NO_XPM
|
|
||||||
#define IL_USE_JPEGLIB_UNMODIFIED 1
|
|
||||||
//#define IL_USE_DXTC_NVIDIA
|
|
||||||
#define IL_USE_DXTC_SQUISH
|
|
||||||
|
|
||||||
/* Supported api (ilut) */
|
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// sorry just
|
|
||||||
// cant get this one to work under windows
|
|
||||||
// have disabled for the now
|
|
||||||
//
|
|
||||||
// will look at it some more later
|
|
||||||
//
|
|
||||||
// Kriss
|
|
||||||
//
|
|
||||||
#undef ILUT_USE_ALLEGRO
|
|
||||||
|
|
||||||
#undef ILUT_USE_DIRECTX8
|
|
||||||
//#define ILUT_USE_DIRECTX9
|
|
||||||
//#define ILUT_USE_DIRECTX10
|
|
||||||
//#define ILUT_USE_OPENGL
|
|
||||||
//#define ILUT_USE_SDL
|
|
||||||
//#define ILUT_USE_WIN32
|
|
||||||
|
|
||||||
|
|
||||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
|
||||||
//#define HAVE_DLFCN_H 1
|
|
||||||
|
|
||||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
|
||||||
//#define HAVE_INTTYPES_H 1
|
|
||||||
|
|
||||||
/* Define to 1 if you have the <memory.h> header file. */
|
|
||||||
//#define HAVE_MEMORY_H 1
|
|
||||||
|
|
||||||
/* Define to 1 if you have the <stdint.h> header file. */
|
|
||||||
//#define HAVE_STDINT_H 1
|
|
||||||
|
|
||||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
|
||||||
//#define HAVE_STDLIB_H 1
|
|
||||||
|
|
||||||
/* Define to 1 if you have the <strings.h> header file. */
|
|
||||||
//#define HAVE_STRINGS_H 1
|
|
||||||
|
|
||||||
/* Define to 1 if you have the <string.h> header file. */
|
|
||||||
//#define HAVE_STRING_H 1
|
|
||||||
|
|
||||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
|
||||||
//#define HAVE_SYS_STAT_H 1
|
|
||||||
|
|
||||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
|
||||||
//#define HAVE_SYS_TYPES_H 1
|
|
||||||
|
|
||||||
/* Define to 1 if you have the <unistd.h> header file. */
|
|
||||||
//#define HAVE_UNISTD_H 1
|
|
||||||
|
|
||||||
/* Name of package */
|
|
||||||
#define IL_PACKAGE "DevIL"
|
|
||||||
|
|
||||||
/* Define to the address where bug reports for this package should be sent. */
|
|
||||||
#define PACKAGE_BUGREPORT ""
|
|
||||||
|
|
||||||
/* Define to the full name of this package. */
|
|
||||||
#define IL_PACKAGE_NAME ""
|
|
||||||
|
|
||||||
/* Define to the full name and version of this package. */
|
|
||||||
#define IL_PACKAGE_STRING ""
|
|
||||||
|
|
||||||
/* Define to the one symbol short name of this package. */
|
|
||||||
#define IL_PACKAGE_TARNAME ""
|
|
||||||
|
|
||||||
/* Define to the version of this package. */
|
|
||||||
#define IL_PACKAGE_VERSION ""
|
|
||||||
|
|
||||||
/* Define to 1 if you have the ANSI C header files. */
|
|
||||||
#define STDC_HEADERS 1
|
|
||||||
|
|
||||||
/* Version number of package */
|
|
||||||
//#define IL_VERSION "1.7.3"
|
|
||||||
|
|
||||||
/* Define to 1 if your processor stores words with the most significant byte
|
|
||||||
first (like Motorola and SPARC, unlike Intel and VAX). */
|
|
||||||
/* #undef WORDS_BIGENDIAN */
|
|
||||||
|
|
||||||
/* If using Mac OS X uncomment this line */
|
|
||||||
/* #include "macconfig.h" */
|
|
||||||
|
|
||||||
/* Define to 1 if the X Window System is missing or not being used. */
|
|
||||||
/* #undef X_DISPLAY_MISSING */
|
|
||||||
#endif /* __CONFIG_H__ */
|
|
@ -1,79 +0,0 @@
|
|||||||
#ifndef __CONFIG_H__
|
|
||||||
#define __CONFIG_H__
|
|
||||||
|
|
||||||
#define IL_USE_PRAGMA_LIBS // Links to only the libraries that are requested.
|
|
||||||
#define IL_INLINE_ASM 1 // Define if you can support at least some ASM
|
|
||||||
|
|
||||||
// Supported images formats (IL)
|
|
||||||
|
|
||||||
// #define IL_NO_BLP
|
|
||||||
// #define IL_NO_BMP
|
|
||||||
// #define IL_NO_CUT
|
|
||||||
// #define IL_NO_CHEAD
|
|
||||||
// #define IL_NO_DCX
|
|
||||||
// #define IL_NO_DDS
|
|
||||||
// #define IL_NO_DICOM
|
|
||||||
// #define IL_NO_DOOM
|
|
||||||
// #define IL_NO_EXR
|
|
||||||
// #define IL_NO_FITS
|
|
||||||
// #define IL_NO_FTX
|
|
||||||
// #define IL_NO_GIF
|
|
||||||
// #define IL_NO_HDR
|
|
||||||
// #define IL_NO_ICO
|
|
||||||
// #define IL_NO_ICNS
|
|
||||||
// #define IL_NO_IWI
|
|
||||||
// #define IL_NO_JP2
|
|
||||||
// #define IL_NO_JPG
|
|
||||||
// #define IL_NO_LCMS
|
|
||||||
// #define IL_NO_LIF
|
|
||||||
// #define IL_NO_MDL
|
|
||||||
// #define IL_NO_MNG
|
|
||||||
// #define IL_NO_PCD
|
|
||||||
// #define IL_NO_PCX
|
|
||||||
// #define IL_NO_PIC
|
|
||||||
// #define IL_NO_PIX
|
|
||||||
// #define IL_NO_PNG
|
|
||||||
// #define IL_NO_PNM
|
|
||||||
// #define IL_NO_PSD
|
|
||||||
// #define IL_NO_PSP
|
|
||||||
// #define IL_NO_PXR
|
|
||||||
// #define IL_NO_RAW
|
|
||||||
// #define IL_NO_ROT
|
|
||||||
// #define IL_NO_SGI
|
|
||||||
// #define IL_NO_SUN
|
|
||||||
// #define IL_NO_TGA
|
|
||||||
// #define IL_NO_TIF
|
|
||||||
// #define IL_NO_TPL
|
|
||||||
// #define IL_NO_WAL
|
|
||||||
// #define IL_NO_WDP
|
|
||||||
// #define IL_NO_XPM
|
|
||||||
|
|
||||||
#define IL_USE_JPEGLIB_UNMODIFIED 1
|
|
||||||
#define IL_USE_DXTC_NVIDIA
|
|
||||||
#define IL_USE_DXTC_SQUISH
|
|
||||||
|
|
||||||
//#define IL_NO_GAMES
|
|
||||||
|
|
||||||
/* Supported api (ilut) */
|
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// sorry just
|
|
||||||
// cant get this one to work under windows
|
|
||||||
// have disabled for the now
|
|
||||||
//
|
|
||||||
// will look at it some more later
|
|
||||||
//
|
|
||||||
// Kriss
|
|
||||||
//
|
|
||||||
#undef ILUT_USE_ALLEGRO
|
|
||||||
|
|
||||||
#undef ILUT_USE_DIRECTX8
|
|
||||||
#define ILUT_USE_DIRECTX9
|
|
||||||
#define ILUT_USE_DIRECTX10
|
|
||||||
#define ILUT_USE_OPENGL
|
|
||||||
#define ILUT_USE_SDL
|
|
||||||
#define ILUT_USE_WIN32
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* __CONFIG_H__ */
|
|
@ -1,161 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ImageLib Sources
|
|
||||||
// Copyright (C) 2000-2009 by Denton Woods
|
|
||||||
// Last modified: 01/06/2009
|
|
||||||
//
|
|
||||||
// Filename: IL/devil_internal_exports.h
|
|
||||||
//
|
|
||||||
// Description: Internal stuff for DevIL (IL, ILU and ILUT)
|
|
||||||
//
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#ifndef IL_EXPORTS_H
|
|
||||||
#define IL_EXPORTS_H
|
|
||||||
|
|
||||||
#include "IL/il.h"
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
#include <assert.h>
|
|
||||||
#else
|
|
||||||
#define assert(x)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//#ifndef NOINLINE
|
|
||||||
#ifndef INLINE
|
|
||||||
#if defined(__GNUC__)
|
|
||||||
#define INLINE extern inline
|
|
||||||
#elif defined(_MSC_VER) //@TODO: Get this working in MSVC++.
|
|
||||||
// http://www.greenend.org.uk/rjk/2003/03/inline.html
|
|
||||||
#define NOINLINE
|
|
||||||
//#define INLINE
|
|
||||||
/*#ifndef _WIN64 // Cannot use inline assembly in x64 target platform.
|
|
||||||
#define USE_WIN32_ASM
|
|
||||||
#endif//_WIN64*/
|
|
||||||
#define INLINE __inline
|
|
||||||
#else
|
|
||||||
#define INLINE inline
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
//#else
|
|
||||||
//#define INLINE
|
|
||||||
//#endif //NOINLINE
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define IL_MAX(a,b) (((a) > (b)) ? (a) : (b))
|
|
||||||
#define IL_MIN(a,b) (((a) < (b)) ? (a) : (b))
|
|
||||||
|
|
||||||
|
|
||||||
//! Basic Palette struct
|
|
||||||
typedef struct ILpal
|
|
||||||
{
|
|
||||||
ILubyte* Palette; //!< the image palette (if any)
|
|
||||||
ILuint PalSize; //!< size of the palette (in bytes)
|
|
||||||
ILenum PalType; //!< the palette types in il.h (0x0500 range)
|
|
||||||
} ILpal;
|
|
||||||
|
|
||||||
|
|
||||||
//! The Fundamental Image structure
|
|
||||||
/*! Every bit of information about an image is stored in this internal structure.*/
|
|
||||||
typedef struct ILimage
|
|
||||||
{
|
|
||||||
ILuint Width; //!< the image's width
|
|
||||||
ILuint Height; //!< the image's height
|
|
||||||
ILuint Depth; //!< the image's depth
|
|
||||||
ILubyte Bpp; //!< bytes per pixel (now number of channels)
|
|
||||||
ILubyte Bpc; //!< bytes per channel
|
|
||||||
ILuint Bps; //!< bytes per scanline (components for IL)
|
|
||||||
ILubyte* Data; //!< the image data
|
|
||||||
ILuint SizeOfData; //!< the total size of the data (in bytes)
|
|
||||||
ILuint SizeOfPlane; //!< SizeOfData in a 2d image, size of each plane slice in a 3d image (in bytes)
|
|
||||||
ILenum Format; //!< image format (in IL enum style)
|
|
||||||
ILenum Type; //!< image type (in IL enum style)
|
|
||||||
ILenum Origin; //!< origin of the image
|
|
||||||
ILpal Pal; //!< palette details
|
|
||||||
ILuint Duration; //!< length of the time to display this "frame"
|
|
||||||
ILenum CubeFlags; //!< cube map flags for sides present in chain
|
|
||||||
struct ILimage* Mipmaps; //!< mipmapped versions of this image terminated by a NULL - usu. NULL
|
|
||||||
struct ILimage* Next; //!< next image in the chain - usu. NULL
|
|
||||||
struct ILimage* Faces; //!< next cubemap face in the chain - usu. NULL
|
|
||||||
struct ILimage* Layers; //!< subsequent layers in the chain - usu. NULL
|
|
||||||
ILuint* AnimList; //!< animation list
|
|
||||||
ILuint AnimSize; //!< animation list size
|
|
||||||
void* Profile; //!< colour profile
|
|
||||||
ILuint ProfileSize; //!< colour profile size
|
|
||||||
ILuint OffX; //!< x-offset of the image
|
|
||||||
ILuint OffY; //!< y-offset of the image
|
|
||||||
ILubyte* DxtcData; //!< compressed data
|
|
||||||
ILenum DxtcFormat; //!< compressed data format
|
|
||||||
ILuint DxtcSize; //!< compressed data size
|
|
||||||
} ILimage;
|
|
||||||
|
|
||||||
|
|
||||||
// Memory functions
|
|
||||||
ILAPI void* ILAPIENTRY ialloc(const ILsizei Size);
|
|
||||||
ILAPI void ILAPIENTRY ifree(const void *Ptr);
|
|
||||||
ILAPI void* ILAPIENTRY icalloc(const ILsizei Size, const ILsizei Num);
|
|
||||||
#ifdef ALTIVEC_GCC
|
|
||||||
ILAPI void* ILAPIENTRY ivec_align_buffer(void *buffer, const ILuint size);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Internal library functions in IL
|
|
||||||
ILAPI ILimage* ILAPIENTRY ilGetCurImage(void);
|
|
||||||
ILAPI void ILAPIENTRY ilSetCurImage(ILimage *Image);
|
|
||||||
ILAPI void ILAPIENTRY ilSetError(ILenum Error);
|
|
||||||
ILAPI void ILAPIENTRY ilSetPal(ILpal *Pal);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Utility functions
|
|
||||||
//
|
|
||||||
ILAPI ILubyte ILAPIENTRY ilGetBppFormat(ILenum Format);
|
|
||||||
ILAPI ILenum ILAPIENTRY ilGetFormatBpp(ILubyte Bpp);
|
|
||||||
ILAPI ILubyte ILAPIENTRY ilGetBpcType(ILenum Type);
|
|
||||||
ILAPI ILenum ILAPIENTRY ilGetTypeBpc(ILubyte Bpc);
|
|
||||||
ILAPI ILubyte ILAPIENTRY ilGetBppPal(ILenum PalType);
|
|
||||||
ILAPI ILenum ILAPIENTRY ilGetPalBaseType(ILenum PalType);
|
|
||||||
ILAPI ILuint ILAPIENTRY ilNextPower2(ILuint Num);
|
|
||||||
ILAPI ILenum ILAPIENTRY ilTypeFromExt(ILconst_string FileName);
|
|
||||||
ILAPI void ILAPIENTRY ilReplaceCurImage(ILimage *Image);
|
|
||||||
ILAPI void ILAPIENTRY iMemSwap(ILubyte *, ILubyte *, const ILuint);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Image functions
|
|
||||||
//
|
|
||||||
ILAPI void ILAPIENTRY iBindImageTemp (void);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilClearImage_ (ILimage *Image);
|
|
||||||
ILAPI void ILAPIENTRY ilCloseImage (ILimage *Image);
|
|
||||||
ILAPI void ILAPIENTRY ilClosePal (ILpal *Palette);
|
|
||||||
ILAPI ILpal* ILAPIENTRY iCopyPal (void);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilCopyImageAttr (ILimage *Dest, ILimage *Src);
|
|
||||||
ILAPI ILimage* ILAPIENTRY ilCopyImage_ (ILimage *Src);
|
|
||||||
ILAPI void ILAPIENTRY ilGetClear (void *Colours, ILenum Format, ILenum Type);
|
|
||||||
ILAPI ILuint ILAPIENTRY ilGetCurName (void);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilIsValidPal (ILpal *Palette);
|
|
||||||
ILAPI ILimage* ILAPIENTRY ilNewImage (ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp, ILubyte Bpc);
|
|
||||||
ILAPI ILimage* ILAPIENTRY ilNewImageFull (ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp, ILenum Format, ILenum Type, void *Data);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilInitImage (ILimage *Image, ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp, ILenum Format, ILenum Type, void *Data);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilResizeImage (ILimage *Image, ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp, ILubyte Bpc);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilTexImage_ (ILimage *Image, ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp, ILenum Format, ILenum Type, void *Data);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilTexSubImage_ (ILimage *Image, void *Data);
|
|
||||||
ILAPI void* ILAPIENTRY ilConvertBuffer (ILuint SizeOfData, ILenum SrcFormat, ILenum DestFormat, ILenum SrcType, ILenum DestType, ILpal *SrcPal, void *Buffer);
|
|
||||||
ILAPI ILimage* ILAPIENTRY iConvertImage (ILimage *Image, ILenum DestFormat, ILenum DestType);
|
|
||||||
ILAPI ILpal* ILAPIENTRY iConvertPal (ILpal *Pal, ILenum DestFormat);
|
|
||||||
ILAPI ILubyte* ILAPIENTRY iGetFlipped (ILimage *Image);
|
|
||||||
ILAPI ILboolean ILAPIENTRY iMirror();
|
|
||||||
ILAPI void ILAPIENTRY iFlipBuffer(ILubyte *buff, ILuint depth, ILuint line_size, ILuint line_num);
|
|
||||||
ILubyte* iFlipNewBuffer(ILubyte *buff, ILuint depth, ILuint line_size, ILuint line_num);
|
|
||||||
ILAPI void ILAPIENTRY iGetIntegervImage(ILimage *Image, ILenum Mode, ILint *Param);
|
|
||||||
|
|
||||||
// Internal library functions in ILU
|
|
||||||
ILAPI ILimage* ILAPIENTRY iluRotate_(ILimage *Image, ILfloat Angle);
|
|
||||||
ILAPI ILimage* ILAPIENTRY iluRotate3D_(ILimage *Image, ILfloat x, ILfloat y, ILfloat z, ILfloat Angle);
|
|
||||||
ILAPI ILimage* ILAPIENTRY iluScale_(ILimage *Image, ILuint Width, ILuint Height, ILuint Depth);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif//IL_EXPORTS_H
|
|
644
SQCSim2021/external/devil178/include/IL/il.h
vendored
644
SQCSim2021/external/devil178/include/IL/il.h
vendored
@ -1,644 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ImageLib Sources
|
|
||||||
// Copyright (C) 2000-2009 by Denton Woods
|
|
||||||
// Last modified: 03/07/2009
|
|
||||||
//
|
|
||||||
// Filename: IL/il.h
|
|
||||||
//
|
|
||||||
// Description: The main include file for DevIL
|
|
||||||
//
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Doxygen comment
|
|
||||||
/*! \file il.h
|
|
||||||
The main include file for DevIL
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __il_h_
|
|
||||||
#ifndef __IL_H__
|
|
||||||
|
|
||||||
#define __il_h_
|
|
||||||
#define __IL_H__
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//this define controls if floats and doubles are clampled to [0..1]
|
|
||||||
//during conversion. It takes a little more time, but it is the correct
|
|
||||||
//way of doing this. If you are sure your floats are always valid,
|
|
||||||
//you can undefine this value...
|
|
||||||
#define CLAMP_HALF 1
|
|
||||||
#define CLAMP_FLOATS 1
|
|
||||||
#define CLAMP_DOUBLES 1
|
|
||||||
|
|
||||||
/*#ifdef _WIN32_WCE
|
|
||||||
#define IL_NO_EXR
|
|
||||||
#define IL_NO_GIF
|
|
||||||
#define IL_NO_JP2
|
|
||||||
#define IL_NO_JPG
|
|
||||||
#define IL_NO_MNG
|
|
||||||
#define IL_NO_PNG
|
|
||||||
#define IL_NO_TIF
|
|
||||||
#define IL_NO_LCMS
|
|
||||||
#endif //_WIN32_WCE
|
|
||||||
|
|
||||||
#ifdef DJGPP
|
|
||||||
#define IL_NO_EXR
|
|
||||||
#define IL_NO_GIF
|
|
||||||
#define IL_NO_JP2
|
|
||||||
#define IL_NO_JPG
|
|
||||||
#define IL_NO_MNG
|
|
||||||
#define IL_NO_PNG
|
|
||||||
#define IL_NO_TIF
|
|
||||||
#define IL_NO_LCMS
|
|
||||||
#endif //DJGPP*/
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#if (defined(IL_USE_PRAGMA_LIBS)) && (!defined(_IL_BUILD_LIBRARY))
|
|
||||||
#if defined(_MSC_VER) || defined(__BORLANDC__)
|
|
||||||
#pragma comment(lib, "DevIL.lib")
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef RESTRICT_KEYWORD
|
|
||||||
#define RESTRICT restrict
|
|
||||||
#define CONST_RESTRICT const restrict
|
|
||||||
#else
|
|
||||||
#define RESTRICT
|
|
||||||
#define CONST_RESTRICT const
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
typedef unsigned int ILenum;
|
|
||||||
typedef unsigned char ILboolean;
|
|
||||||
typedef unsigned int ILbitfield;
|
|
||||||
typedef signed char ILbyte;
|
|
||||||
typedef signed short ILshort;
|
|
||||||
typedef int ILint;
|
|
||||||
typedef size_t ILsizei;
|
|
||||||
typedef unsigned char ILubyte;
|
|
||||||
typedef unsigned short ILushort;
|
|
||||||
typedef unsigned int ILuint;
|
|
||||||
typedef float ILfloat;
|
|
||||||
typedef float ILclampf;
|
|
||||||
typedef double ILdouble;
|
|
||||||
typedef double ILclampd;
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
typedef __int64 ILint64;
|
|
||||||
typedef unsigned __int64 ILuint64;
|
|
||||||
#else
|
|
||||||
typedef long long int ILint64;
|
|
||||||
typedef long long unsigned int ILuint64;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#include <limits.h>
|
|
||||||
#ifdef _UNICODE
|
|
||||||
#ifndef _WIN32_WCE
|
|
||||||
#include <wchar.h>
|
|
||||||
#endif
|
|
||||||
//if we use a define instead of a typedef,
|
|
||||||
//ILconst_string works as intended
|
|
||||||
#define ILchar wchar_t
|
|
||||||
#define ILstring wchar_t*
|
|
||||||
#define ILconst_string wchar_t const *
|
|
||||||
#else
|
|
||||||
//if we use a define instead of a typedef,
|
|
||||||
//ILconst_string works as intended
|
|
||||||
#define ILchar char
|
|
||||||
#define ILstring char*
|
|
||||||
#define ILconst_string char const *
|
|
||||||
#endif //_UNICODE
|
|
||||||
|
|
||||||
#define IL_FALSE 0
|
|
||||||
#define IL_TRUE 1
|
|
||||||
|
|
||||||
// Matches OpenGL's right now.
|
|
||||||
//! Data formats \link Formats Formats\endlink
|
|
||||||
#define IL_COLOUR_INDEX 0x1900
|
|
||||||
#define IL_COLOR_INDEX 0x1900
|
|
||||||
#define IL_ALPHA 0x1906
|
|
||||||
#define IL_RGB 0x1907
|
|
||||||
#define IL_RGBA 0x1908
|
|
||||||
#define IL_BGR 0x80E0
|
|
||||||
#define IL_BGRA 0x80E1
|
|
||||||
#define IL_LUMINANCE 0x1909
|
|
||||||
#define IL_LUMINANCE_ALPHA 0x190A
|
|
||||||
|
|
||||||
//! Data types \link Types Types\endlink
|
|
||||||
#define IL_BYTE 0x1400
|
|
||||||
#define IL_UNSIGNED_BYTE 0x1401
|
|
||||||
#define IL_SHORT 0x1402
|
|
||||||
#define IL_UNSIGNED_SHORT 0x1403
|
|
||||||
#define IL_INT 0x1404
|
|
||||||
#define IL_UNSIGNED_INT 0x1405
|
|
||||||
#define IL_FLOAT 0x1406
|
|
||||||
#define IL_DOUBLE 0x140A
|
|
||||||
#define IL_HALF 0x140B
|
|
||||||
|
|
||||||
|
|
||||||
#define IL_MAX_BYTE SCHAR_MAX
|
|
||||||
#define IL_MAX_UNSIGNED_BYTE UCHAR_MAX
|
|
||||||
#define IL_MAX_SHORT SHRT_MAX
|
|
||||||
#define IL_MAX_UNSIGNED_SHORT USHRT_MAX
|
|
||||||
#define IL_MAX_INT INT_MAX
|
|
||||||
#define IL_MAX_UNSIGNED_INT UINT_MAX
|
|
||||||
|
|
||||||
#define IL_LIMIT(x,m,M) (x<m?m:(x>M?M:x))
|
|
||||||
#define IL_CLAMP(x) IL_LIMIT(x,0,1)
|
|
||||||
|
|
||||||
#define IL_VENDOR 0x1F00
|
|
||||||
#define IL_LOAD_EXT 0x1F01
|
|
||||||
#define IL_SAVE_EXT 0x1F02
|
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// IL-specific #define's
|
|
||||||
//
|
|
||||||
|
|
||||||
#define IL_VERSION_1_7_8 1
|
|
||||||
#define IL_VERSION 178
|
|
||||||
|
|
||||||
|
|
||||||
// Attribute Bits
|
|
||||||
#define IL_ORIGIN_BIT 0x00000001
|
|
||||||
#define IL_FILE_BIT 0x00000002
|
|
||||||
#define IL_PAL_BIT 0x00000004
|
|
||||||
#define IL_FORMAT_BIT 0x00000008
|
|
||||||
#define IL_TYPE_BIT 0x00000010
|
|
||||||
#define IL_COMPRESS_BIT 0x00000020
|
|
||||||
#define IL_LOADFAIL_BIT 0x00000040
|
|
||||||
#define IL_FORMAT_SPECIFIC_BIT 0x00000080
|
|
||||||
#define IL_ALL_ATTRIB_BITS 0x000FFFFF
|
|
||||||
|
|
||||||
|
|
||||||
// Palette types
|
|
||||||
#define IL_PAL_NONE 0x0400
|
|
||||||
#define IL_PAL_RGB24 0x0401
|
|
||||||
#define IL_PAL_RGB32 0x0402
|
|
||||||
#define IL_PAL_RGBA32 0x0403
|
|
||||||
#define IL_PAL_BGR24 0x0404
|
|
||||||
#define IL_PAL_BGR32 0x0405
|
|
||||||
#define IL_PAL_BGRA32 0x0406
|
|
||||||
|
|
||||||
|
|
||||||
// Image types
|
|
||||||
#define IL_TYPE_UNKNOWN 0x0000
|
|
||||||
#define IL_BMP 0x0420 //!< Microsoft Windows Bitmap - .bmp extension
|
|
||||||
#define IL_CUT 0x0421 //!< Dr. Halo - .cut extension
|
|
||||||
#define IL_DOOM 0x0422 //!< DooM walls - no specific extension
|
|
||||||
#define IL_DOOM_FLAT 0x0423 //!< DooM flats - no specific extension
|
|
||||||
#define IL_ICO 0x0424 //!< Microsoft Windows Icons and Cursors - .ico and .cur extensions
|
|
||||||
#define IL_JPG 0x0425 //!< JPEG - .jpg, .jpe and .jpeg extensions
|
|
||||||
#define IL_JFIF 0x0425 //!<
|
|
||||||
#define IL_ILBM 0x0426 //!< Amiga IFF (FORM ILBM) - .iff, .ilbm, .lbm extensions
|
|
||||||
#define IL_PCD 0x0427 //!< Kodak PhotoCD - .pcd extension
|
|
||||||
#define IL_PCX 0x0428 //!< ZSoft PCX - .pcx extension
|
|
||||||
#define IL_PIC 0x0429 //!< PIC - .pic extension
|
|
||||||
#define IL_PNG 0x042A //!< Portable Network Graphics - .png extension
|
|
||||||
#define IL_PNM 0x042B //!< Portable Any Map - .pbm, .pgm, .ppm and .pnm extensions
|
|
||||||
#define IL_SGI 0x042C //!< Silicon Graphics - .sgi, .bw, .rgb and .rgba extensions
|
|
||||||
#define IL_TGA 0x042D //!< TrueVision Targa File - .tga, .vda, .icb and .vst extensions
|
|
||||||
#define IL_TIF 0x042E //!< Tagged Image File Format - .tif and .tiff extensions
|
|
||||||
#define IL_CHEAD 0x042F //!< C-Style Header - .h extension
|
|
||||||
#define IL_RAW 0x0430 //!< Raw Image Data - any extension
|
|
||||||
#define IL_MDL 0x0431 //!< Half-Life Model Texture - .mdl extension
|
|
||||||
#define IL_WAL 0x0432 //!< Quake 2 Texture - .wal extension
|
|
||||||
#define IL_LIF 0x0434 //!< Homeworld Texture - .lif extension
|
|
||||||
#define IL_MNG 0x0435 //!< Multiple-image Network Graphics - .mng extension
|
|
||||||
#define IL_JNG 0x0435 //!<
|
|
||||||
#define IL_GIF 0x0436 //!< Graphics Interchange Format - .gif extension
|
|
||||||
#define IL_DDS 0x0437 //!< DirectDraw Surface - .dds extension
|
|
||||||
#define IL_DCX 0x0438 //!< ZSoft Multi-PCX - .dcx extension
|
|
||||||
#define IL_PSD 0x0439 //!< Adobe PhotoShop - .psd extension
|
|
||||||
#define IL_EXIF 0x043A //!<
|
|
||||||
#define IL_PSP 0x043B //!< PaintShop Pro - .psp extension
|
|
||||||
#define IL_PIX 0x043C //!< PIX - .pix extension
|
|
||||||
#define IL_PXR 0x043D //!< Pixar - .pxr extension
|
|
||||||
#define IL_XPM 0x043E //!< X Pixel Map - .xpm extension
|
|
||||||
#define IL_HDR 0x043F //!< Radiance High Dynamic Range - .hdr extension
|
|
||||||
#define IL_ICNS 0x0440 //!< Macintosh Icon - .icns extension
|
|
||||||
#define IL_JP2 0x0441 //!< Jpeg 2000 - .jp2 extension
|
|
||||||
#define IL_EXR 0x0442 //!< OpenEXR - .exr extension
|
|
||||||
#define IL_WDP 0x0443 //!< Microsoft HD Photo - .wdp and .hdp extension
|
|
||||||
#define IL_VTF 0x0444 //!< Valve Texture Format - .vtf extension
|
|
||||||
#define IL_WBMP 0x0445 //!< Wireless Bitmap - .wbmp extension
|
|
||||||
#define IL_SUN 0x0446 //!< Sun Raster - .sun, .ras, .rs, .im1, .im8, .im24 and .im32 extensions
|
|
||||||
#define IL_IFF 0x0447 //!< Interchange File Format - .iff extension
|
|
||||||
#define IL_TPL 0x0448 //!< Gamecube Texture - .tpl extension
|
|
||||||
#define IL_FITS 0x0449 //!< Flexible Image Transport System - .fit and .fits extensions
|
|
||||||
#define IL_DICOM 0x044A //!< Digital Imaging and Communications in Medicine (DICOM) - .dcm and .dicom extensions
|
|
||||||
#define IL_IWI 0x044B //!< Call of Duty Infinity Ward Image - .iwi extension
|
|
||||||
#define IL_BLP 0x044C //!< Blizzard Texture Format - .blp extension
|
|
||||||
#define IL_FTX 0x044D //!< Heavy Metal: FAKK2 Texture - .ftx extension
|
|
||||||
#define IL_ROT 0x044E //!< Homeworld 2 - Relic Texture - .rot extension
|
|
||||||
#define IL_TEXTURE 0x044F //!< Medieval II: Total War Texture - .texture extension
|
|
||||||
#define IL_DPX 0x0450 //!< Digital Picture Exchange - .dpx extension
|
|
||||||
#define IL_UTX 0x0451 //!< Unreal (and Unreal Tournament) Texture - .utx extension
|
|
||||||
#define IL_MP3 0x0452 //!< MPEG-1 Audio Layer 3 - .mp3 extension
|
|
||||||
|
|
||||||
|
|
||||||
#define IL_JASC_PAL 0x0475 //!< PaintShop Pro Palette
|
|
||||||
|
|
||||||
|
|
||||||
// Error Types
|
|
||||||
#define IL_NO_ERROR 0x0000
|
|
||||||
#define IL_INVALID_ENUM 0x0501
|
|
||||||
#define IL_OUT_OF_MEMORY 0x0502
|
|
||||||
#define IL_FORMAT_NOT_SUPPORTED 0x0503
|
|
||||||
#define IL_INTERNAL_ERROR 0x0504
|
|
||||||
#define IL_INVALID_VALUE 0x0505
|
|
||||||
#define IL_ILLEGAL_OPERATION 0x0506
|
|
||||||
#define IL_ILLEGAL_FILE_VALUE 0x0507
|
|
||||||
#define IL_INVALID_FILE_HEADER 0x0508
|
|
||||||
#define IL_INVALID_PARAM 0x0509
|
|
||||||
#define IL_COULD_NOT_OPEN_FILE 0x050A
|
|
||||||
#define IL_INVALID_EXTENSION 0x050B
|
|
||||||
#define IL_FILE_ALREADY_EXISTS 0x050C
|
|
||||||
#define IL_OUT_FORMAT_SAME 0x050D
|
|
||||||
#define IL_STACK_OVERFLOW 0x050E
|
|
||||||
#define IL_STACK_UNDERFLOW 0x050F
|
|
||||||
#define IL_INVALID_CONVERSION 0x0510
|
|
||||||
#define IL_BAD_DIMENSIONS 0x0511
|
|
||||||
#define IL_FILE_READ_ERROR 0x0512 // 05/12/2002: Addition by Sam.
|
|
||||||
#define IL_FILE_WRITE_ERROR 0x0512
|
|
||||||
|
|
||||||
#define IL_LIB_GIF_ERROR 0x05E1
|
|
||||||
#define IL_LIB_JPEG_ERROR 0x05E2
|
|
||||||
#define IL_LIB_PNG_ERROR 0x05E3
|
|
||||||
#define IL_LIB_TIFF_ERROR 0x05E4
|
|
||||||
#define IL_LIB_MNG_ERROR 0x05E5
|
|
||||||
#define IL_LIB_JP2_ERROR 0x05E6
|
|
||||||
#define IL_LIB_EXR_ERROR 0x05E7
|
|
||||||
#define IL_UNKNOWN_ERROR 0x05FF
|
|
||||||
|
|
||||||
|
|
||||||
// Origin Definitions
|
|
||||||
#define IL_ORIGIN_SET 0x0600
|
|
||||||
#define IL_ORIGIN_LOWER_LEFT 0x0601
|
|
||||||
#define IL_ORIGIN_UPPER_LEFT 0x0602
|
|
||||||
#define IL_ORIGIN_MODE 0x0603
|
|
||||||
|
|
||||||
|
|
||||||
// Format and Type Mode Definitions
|
|
||||||
#define IL_FORMAT_SET 0x0610
|
|
||||||
#define IL_FORMAT_MODE 0x0611
|
|
||||||
#define IL_TYPE_SET 0x0612
|
|
||||||
#define IL_TYPE_MODE 0x0613
|
|
||||||
|
|
||||||
|
|
||||||
// File definitions
|
|
||||||
#define IL_FILE_OVERWRITE 0x0620
|
|
||||||
#define IL_FILE_MODE 0x0621
|
|
||||||
|
|
||||||
|
|
||||||
// Palette definitions
|
|
||||||
#define IL_CONV_PAL 0x0630
|
|
||||||
|
|
||||||
|
|
||||||
// Load fail definitions
|
|
||||||
#define IL_DEFAULT_ON_FAIL 0x0632
|
|
||||||
|
|
||||||
|
|
||||||
// Key colour and alpha definitions
|
|
||||||
#define IL_USE_KEY_COLOUR 0x0635
|
|
||||||
#define IL_USE_KEY_COLOR 0x0635
|
|
||||||
#define IL_BLIT_BLEND 0x0636
|
|
||||||
|
|
||||||
|
|
||||||
// Interlace definitions
|
|
||||||
#define IL_SAVE_INTERLACED 0x0639
|
|
||||||
#define IL_INTERLACE_MODE 0x063A
|
|
||||||
|
|
||||||
|
|
||||||
// Quantization definitions
|
|
||||||
#define IL_QUANTIZATION_MODE 0x0640
|
|
||||||
#define IL_WU_QUANT 0x0641
|
|
||||||
#define IL_NEU_QUANT 0x0642
|
|
||||||
#define IL_NEU_QUANT_SAMPLE 0x0643
|
|
||||||
#define IL_MAX_QUANT_INDEXS 0x0644 //XIX : ILint : Maximum number of colors to reduce to, default of 256. and has a range of 2-256
|
|
||||||
#define IL_MAX_QUANT_INDICES 0x0644 // Redefined, since the above #define is misspelled
|
|
||||||
|
|
||||||
|
|
||||||
// Hints
|
|
||||||
#define IL_FASTEST 0x0660
|
|
||||||
#define IL_LESS_MEM 0x0661
|
|
||||||
#define IL_DONT_CARE 0x0662
|
|
||||||
#define IL_MEM_SPEED_HINT 0x0665
|
|
||||||
#define IL_USE_COMPRESSION 0x0666
|
|
||||||
#define IL_NO_COMPRESSION 0x0667
|
|
||||||
#define IL_COMPRESSION_HINT 0x0668
|
|
||||||
|
|
||||||
|
|
||||||
// Compression
|
|
||||||
#define IL_NVIDIA_COMPRESS 0x0670
|
|
||||||
#define IL_SQUISH_COMPRESS 0x0671
|
|
||||||
|
|
||||||
|
|
||||||
// Subimage types
|
|
||||||
#define IL_SUB_NEXT 0x0680
|
|
||||||
#define IL_SUB_MIPMAP 0x0681
|
|
||||||
#define IL_SUB_LAYER 0x0682
|
|
||||||
|
|
||||||
|
|
||||||
// Compression definitions
|
|
||||||
#define IL_COMPRESS_MODE 0x0700
|
|
||||||
#define IL_COMPRESS_NONE 0x0701
|
|
||||||
#define IL_COMPRESS_RLE 0x0702
|
|
||||||
#define IL_COMPRESS_LZO 0x0703
|
|
||||||
#define IL_COMPRESS_ZLIB 0x0704
|
|
||||||
|
|
||||||
|
|
||||||
// File format-specific values
|
|
||||||
#define IL_TGA_CREATE_STAMP 0x0710
|
|
||||||
#define IL_JPG_QUALITY 0x0711
|
|
||||||
#define IL_PNG_INTERLACE 0x0712
|
|
||||||
#define IL_TGA_RLE 0x0713
|
|
||||||
#define IL_BMP_RLE 0x0714
|
|
||||||
#define IL_SGI_RLE 0x0715
|
|
||||||
#define IL_TGA_ID_STRING 0x0717
|
|
||||||
#define IL_TGA_AUTHNAME_STRING 0x0718
|
|
||||||
#define IL_TGA_AUTHCOMMENT_STRING 0x0719
|
|
||||||
#define IL_PNG_AUTHNAME_STRING 0x071A
|
|
||||||
#define IL_PNG_TITLE_STRING 0x071B
|
|
||||||
#define IL_PNG_DESCRIPTION_STRING 0x071C
|
|
||||||
#define IL_TIF_DESCRIPTION_STRING 0x071D
|
|
||||||
#define IL_TIF_HOSTCOMPUTER_STRING 0x071E
|
|
||||||
#define IL_TIF_DOCUMENTNAME_STRING 0x071F
|
|
||||||
#define IL_TIF_AUTHNAME_STRING 0x0720
|
|
||||||
#define IL_JPG_SAVE_FORMAT 0x0721
|
|
||||||
#define IL_CHEAD_HEADER_STRING 0x0722
|
|
||||||
#define IL_PCD_PICNUM 0x0723
|
|
||||||
#define IL_PNG_ALPHA_INDEX 0x0724 //XIX : ILint : the color in the palette at this index value (0-255) is considered transparent, -1 for no trasparent color
|
|
||||||
#define IL_JPG_PROGRESSIVE 0x0725
|
|
||||||
#define IL_VTF_COMP 0x0726
|
|
||||||
|
|
||||||
|
|
||||||
// DXTC definitions
|
|
||||||
#define IL_DXTC_FORMAT 0x0705
|
|
||||||
#define IL_DXT1 0x0706
|
|
||||||
#define IL_DXT2 0x0707
|
|
||||||
#define IL_DXT3 0x0708
|
|
||||||
#define IL_DXT4 0x0709
|
|
||||||
#define IL_DXT5 0x070A
|
|
||||||
#define IL_DXT_NO_COMP 0x070B
|
|
||||||
#define IL_KEEP_DXTC_DATA 0x070C
|
|
||||||
#define IL_DXTC_DATA_FORMAT 0x070D
|
|
||||||
#define IL_3DC 0x070E
|
|
||||||
#define IL_RXGB 0x070F
|
|
||||||
#define IL_ATI1N 0x0710
|
|
||||||
#define IL_DXT1A 0x0711 // Normally the same as IL_DXT1, except for nVidia Texture Tools.
|
|
||||||
|
|
||||||
// Environment map definitions
|
|
||||||
#define IL_CUBEMAP_POSITIVEX 0x00000400
|
|
||||||
#define IL_CUBEMAP_NEGATIVEX 0x00000800
|
|
||||||
#define IL_CUBEMAP_POSITIVEY 0x00001000
|
|
||||||
#define IL_CUBEMAP_NEGATIVEY 0x00002000
|
|
||||||
#define IL_CUBEMAP_POSITIVEZ 0x00004000
|
|
||||||
#define IL_CUBEMAP_NEGATIVEZ 0x00008000
|
|
||||||
#define IL_SPHEREMAP 0x00010000
|
|
||||||
|
|
||||||
|
|
||||||
// Values
|
|
||||||
#define IL_VERSION_NUM 0x0DE2
|
|
||||||
#define IL_IMAGE_WIDTH 0x0DE4
|
|
||||||
#define IL_IMAGE_HEIGHT 0x0DE5
|
|
||||||
#define IL_IMAGE_DEPTH 0x0DE6
|
|
||||||
#define IL_IMAGE_SIZE_OF_DATA 0x0DE7
|
|
||||||
#define IL_IMAGE_BPP 0x0DE8
|
|
||||||
#define IL_IMAGE_BYTES_PER_PIXEL 0x0DE8
|
|
||||||
#define IL_IMAGE_BPP 0x0DE8
|
|
||||||
#define IL_IMAGE_BITS_PER_PIXEL 0x0DE9
|
|
||||||
#define IL_IMAGE_FORMAT 0x0DEA
|
|
||||||
#define IL_IMAGE_TYPE 0x0DEB
|
|
||||||
#define IL_PALETTE_TYPE 0x0DEC
|
|
||||||
#define IL_PALETTE_SIZE 0x0DED
|
|
||||||
#define IL_PALETTE_BPP 0x0DEE
|
|
||||||
#define IL_PALETTE_NUM_COLS 0x0DEF
|
|
||||||
#define IL_PALETTE_BASE_TYPE 0x0DF0
|
|
||||||
#define IL_NUM_FACES 0x0DE1
|
|
||||||
#define IL_NUM_IMAGES 0x0DF1
|
|
||||||
#define IL_NUM_MIPMAPS 0x0DF2
|
|
||||||
#define IL_NUM_LAYERS 0x0DF3
|
|
||||||
#define IL_ACTIVE_IMAGE 0x0DF4
|
|
||||||
#define IL_ACTIVE_MIPMAP 0x0DF5
|
|
||||||
#define IL_ACTIVE_LAYER 0x0DF6
|
|
||||||
#define IL_ACTIVE_FACE 0x0E00
|
|
||||||
#define IL_CUR_IMAGE 0x0DF7
|
|
||||||
#define IL_IMAGE_DURATION 0x0DF8
|
|
||||||
#define IL_IMAGE_PLANESIZE 0x0DF9
|
|
||||||
#define IL_IMAGE_BPC 0x0DFA
|
|
||||||
#define IL_IMAGE_OFFX 0x0DFB
|
|
||||||
#define IL_IMAGE_OFFY 0x0DFC
|
|
||||||
#define IL_IMAGE_CUBEFLAGS 0x0DFD
|
|
||||||
#define IL_IMAGE_ORIGIN 0x0DFE
|
|
||||||
#define IL_IMAGE_CHANNELS 0x0DFF
|
|
||||||
|
|
||||||
# if defined __GNUC__ && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0))
|
|
||||||
// __attribute__((deprecated)) is supported by GCC 3.1 and later.
|
|
||||||
# define DEPRECATED(D) D __attribute__((deprecated))
|
|
||||||
# elif defined _MSC_VER && _MSC_VER >= 1300
|
|
||||||
// __declspec(deprecated) is supported by MSVC 7.0 and later.
|
|
||||||
# define DEPRECATED(D) __declspec(deprecated) D
|
|
||||||
# else
|
|
||||||
# define DEPRECATED (D) D
|
|
||||||
# endif
|
|
||||||
|
|
||||||
//
|
|
||||||
// Section shamelessly modified from the glut header.
|
|
||||||
//
|
|
||||||
|
|
||||||
// This is from Win32's <windef.h>
|
|
||||||
#if (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED) || defined(__BORLANDC__) || defined(__LCC__)
|
|
||||||
#define ILAPIENTRY __stdcall
|
|
||||||
#define IL_PACKSTRUCT
|
|
||||||
//#elif defined(linux) || defined(MACOSX) || defined(__CYGWIN__) //fix bug 840364
|
|
||||||
#elif defined( __GNUC__ )
|
|
||||||
// this should work for any of the above commented platforms
|
|
||||||
// plus any platform using GCC
|
|
||||||
#ifdef __MINGW32__
|
|
||||||
#define ILAPIENTRY __stdcall
|
|
||||||
#else
|
|
||||||
#define ILAPIENTRY
|
|
||||||
#endif
|
|
||||||
#define IL_PACKSTRUCT __attribute__ ((packed))
|
|
||||||
#else
|
|
||||||
#define ILAPIENTRY
|
|
||||||
#define IL_PACKSTRUCT
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// This is from Win32's <wingdi.h> and <winnt.h>
|
|
||||||
#if defined(__LCC__)
|
|
||||||
#define ILAPI __stdcall
|
|
||||||
#elif defined(_WIN32) //changed 20031221 to fix bug 840421
|
|
||||||
#ifdef IL_STATIC_LIB
|
|
||||||
#define ILAPI
|
|
||||||
#else
|
|
||||||
#ifdef _IL_BUILD_LIBRARY
|
|
||||||
#define ILAPI __declspec(dllexport)
|
|
||||||
#else
|
|
||||||
#define ILAPI __declspec(dllimport)
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#elif __APPLE__
|
|
||||||
#define ILAPI extern
|
|
||||||
#else
|
|
||||||
#define ILAPI
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#define IL_SEEK_SET 0
|
|
||||||
#define IL_SEEK_CUR 1
|
|
||||||
#define IL_SEEK_END 2
|
|
||||||
#define IL_EOF -1
|
|
||||||
|
|
||||||
|
|
||||||
// Callback functions for file reading
|
|
||||||
typedef void* ILHANDLE;
|
|
||||||
typedef void (ILAPIENTRY *fCloseRProc)(ILHANDLE);
|
|
||||||
typedef ILboolean (ILAPIENTRY *fEofProc) (ILHANDLE);
|
|
||||||
typedef ILint (ILAPIENTRY *fGetcProc) (ILHANDLE);
|
|
||||||
typedef ILHANDLE (ILAPIENTRY *fOpenRProc) (ILconst_string);
|
|
||||||
typedef ILint (ILAPIENTRY *fReadProc) (void*, ILuint, ILuint, ILHANDLE);
|
|
||||||
typedef ILint (ILAPIENTRY *fSeekRProc) (ILHANDLE, ILint, ILint);
|
|
||||||
typedef ILint (ILAPIENTRY *fTellRProc) (ILHANDLE);
|
|
||||||
|
|
||||||
// Callback functions for file writing
|
|
||||||
typedef void (ILAPIENTRY *fCloseWProc)(ILHANDLE);
|
|
||||||
typedef ILHANDLE (ILAPIENTRY *fOpenWProc) (ILconst_string);
|
|
||||||
typedef ILint (ILAPIENTRY *fPutcProc) (ILubyte, ILHANDLE);
|
|
||||||
typedef ILint (ILAPIENTRY *fSeekWProc) (ILHANDLE, ILint, ILint);
|
|
||||||
typedef ILint (ILAPIENTRY *fTellWProc) (ILHANDLE);
|
|
||||||
typedef ILint (ILAPIENTRY *fWriteProc) (const void*, ILuint, ILuint, ILHANDLE);
|
|
||||||
|
|
||||||
// Callback functions for allocation and deallocation
|
|
||||||
typedef void* (ILAPIENTRY *mAlloc)(const ILsizei);
|
|
||||||
typedef void (ILAPIENTRY *mFree) (const void* CONST_RESTRICT);
|
|
||||||
|
|
||||||
// Registered format procedures
|
|
||||||
typedef ILenum (ILAPIENTRY *IL_LOADPROC)(ILconst_string);
|
|
||||||
typedef ILenum (ILAPIENTRY *IL_SAVEPROC)(ILconst_string);
|
|
||||||
|
|
||||||
|
|
||||||
// ImageLib Functions
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilActiveFace(ILuint Number);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilActiveImage(ILuint Number);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilActiveLayer(ILuint Number);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilActiveMipmap(ILuint Number);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilApplyPal(ILconst_string FileName);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilApplyProfile(ILstring InProfile, ILstring OutProfile);
|
|
||||||
ILAPI void ILAPIENTRY ilBindImage(ILuint Image);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilBlit(ILuint Source, ILint DestX, ILint DestY, ILint DestZ, ILuint SrcX, ILuint SrcY, ILuint SrcZ, ILuint Width, ILuint Height, ILuint Depth);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilClampNTSC(void);
|
|
||||||
ILAPI void ILAPIENTRY ilClearColour(ILclampf Red, ILclampf Green, ILclampf Blue, ILclampf Alpha);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilClearImage(void);
|
|
||||||
ILAPI ILuint ILAPIENTRY ilCloneCurImage(void);
|
|
||||||
ILAPI ILubyte* ILAPIENTRY ilCompressDXT(ILubyte *Data, ILuint Width, ILuint Height, ILuint Depth, ILenum DXTCFormat, ILuint *DXTCSize);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilCompressFunc(ILenum Mode);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilConvertImage(ILenum DestFormat, ILenum DestType);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilConvertPal(ILenum DestFormat);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilCopyImage(ILuint Src);
|
|
||||||
ILAPI ILuint ILAPIENTRY ilCopyPixels(ILuint XOff, ILuint YOff, ILuint ZOff, ILuint Width, ILuint Height, ILuint Depth, ILenum Format, ILenum Type, void *Data);
|
|
||||||
ILAPI ILuint ILAPIENTRY ilCreateSubImage(ILenum Type, ILuint Num);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilDefaultImage(void);
|
|
||||||
ILAPI void ILAPIENTRY ilDeleteImage(const ILuint Num);
|
|
||||||
ILAPI void ILAPIENTRY ilDeleteImages(ILsizei Num, const ILuint *Images);
|
|
||||||
ILAPI ILenum ILAPIENTRY ilDetermineType(ILconst_string FileName);
|
|
||||||
ILAPI ILenum ILAPIENTRY ilDetermineTypeF(ILHANDLE File);
|
|
||||||
ILAPI ILenum ILAPIENTRY ilDetermineTypeL(const void *Lump, ILuint Size);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilDisable(ILenum Mode);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilDxtcDataToImage(void);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilDxtcDataToSurface(void);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilEnable(ILenum Mode);
|
|
||||||
ILAPI void ILAPIENTRY ilFlipSurfaceDxtcData(void);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilFormatFunc(ILenum Mode);
|
|
||||||
ILAPI void ILAPIENTRY ilGenImages(ILsizei Num, ILuint *Images);
|
|
||||||
ILAPI ILuint ILAPIENTRY ilGenImage(void);
|
|
||||||
ILAPI ILubyte* ILAPIENTRY ilGetAlpha(ILenum Type);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilGetBoolean(ILenum Mode);
|
|
||||||
ILAPI void ILAPIENTRY ilGetBooleanv(ILenum Mode, ILboolean *Param);
|
|
||||||
ILAPI ILubyte* ILAPIENTRY ilGetData(void);
|
|
||||||
ILAPI ILuint ILAPIENTRY ilGetDXTCData(void *Buffer, ILuint BufferSize, ILenum DXTCFormat);
|
|
||||||
ILAPI ILenum ILAPIENTRY ilGetError(void);
|
|
||||||
ILAPI ILint ILAPIENTRY ilGetInteger(ILenum Mode);
|
|
||||||
ILAPI void ILAPIENTRY ilGetIntegerv(ILenum Mode, ILint *Param);
|
|
||||||
ILAPI ILuint ILAPIENTRY ilGetLumpPos(void);
|
|
||||||
ILAPI ILubyte* ILAPIENTRY ilGetPalette(void);
|
|
||||||
ILAPI ILconst_string ILAPIENTRY ilGetString(ILenum StringName);
|
|
||||||
ILAPI void ILAPIENTRY ilHint(ILenum Target, ILenum Mode);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilInvertSurfaceDxtcDataAlpha(void);
|
|
||||||
ILAPI void ILAPIENTRY ilInit(void);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilImageToDxtcData(ILenum Format);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilIsDisabled(ILenum Mode);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilIsEnabled(ILenum Mode);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilIsImage(ILuint Image);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilIsValid(ILenum Type, ILconst_string FileName);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilIsValidF(ILenum Type, ILHANDLE File);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilIsValidL(ILenum Type, void *Lump, ILuint Size);
|
|
||||||
ILAPI void ILAPIENTRY ilKeyColour(ILclampf Red, ILclampf Green, ILclampf Blue, ILclampf Alpha);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilLoad(ILenum Type, ILconst_string FileName);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilLoadF(ILenum Type, ILHANDLE File);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilLoadImage(ILconst_string FileName);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilLoadL(ILenum Type, const void *Lump, ILuint Size);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilLoadPal(ILconst_string FileName);
|
|
||||||
ILAPI void ILAPIENTRY ilModAlpha(ILdouble AlphaValue);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilOriginFunc(ILenum Mode);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilOverlayImage(ILuint Source, ILint XCoord, ILint YCoord, ILint ZCoord);
|
|
||||||
ILAPI void ILAPIENTRY ilPopAttrib(void);
|
|
||||||
ILAPI void ILAPIENTRY ilPushAttrib(ILuint Bits);
|
|
||||||
ILAPI void ILAPIENTRY ilRegisterFormat(ILenum Format);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilRegisterLoad(ILconst_string Ext, IL_LOADPROC Load);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilRegisterMipNum(ILuint Num);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilRegisterNumFaces(ILuint Num);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilRegisterNumImages(ILuint Num);
|
|
||||||
ILAPI void ILAPIENTRY ilRegisterOrigin(ILenum Origin);
|
|
||||||
ILAPI void ILAPIENTRY ilRegisterPal(void *Pal, ILuint Size, ILenum Type);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilRegisterSave(ILconst_string Ext, IL_SAVEPROC Save);
|
|
||||||
ILAPI void ILAPIENTRY ilRegisterType(ILenum Type);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilRemoveLoad(ILconst_string Ext);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilRemoveSave(ILconst_string Ext);
|
|
||||||
ILAPI void ILAPIENTRY ilResetMemory(void); // Deprecated
|
|
||||||
ILAPI void ILAPIENTRY ilResetRead(void);
|
|
||||||
ILAPI void ILAPIENTRY ilResetWrite(void);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilSave(ILenum Type, ILconst_string FileName);
|
|
||||||
ILAPI ILuint ILAPIENTRY ilSaveF(ILenum Type, ILHANDLE File);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilSaveImage(ILconst_string FileName);
|
|
||||||
ILAPI ILuint ILAPIENTRY ilSaveL(ILenum Type, void *Lump, ILuint Size);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilSavePal(ILconst_string FileName);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilSetAlpha(ILdouble AlphaValue);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilSetData(void *Data);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilSetDuration(ILuint Duration);
|
|
||||||
ILAPI void ILAPIENTRY ilSetInteger(ILenum Mode, ILint Param);
|
|
||||||
ILAPI void ILAPIENTRY ilSetMemory(mAlloc, mFree);
|
|
||||||
ILAPI void ILAPIENTRY ilSetPixels(ILint XOff, ILint YOff, ILint ZOff, ILuint Width, ILuint Height, ILuint Depth, ILenum Format, ILenum Type, void *Data);
|
|
||||||
ILAPI void ILAPIENTRY ilSetRead(fOpenRProc, fCloseRProc, fEofProc, fGetcProc, fReadProc, fSeekRProc, fTellRProc);
|
|
||||||
ILAPI void ILAPIENTRY ilSetString(ILenum Mode, const char *String);
|
|
||||||
ILAPI void ILAPIENTRY ilSetWrite(fOpenWProc, fCloseWProc, fPutcProc, fSeekWProc, fTellWProc, fWriteProc);
|
|
||||||
ILAPI void ILAPIENTRY ilShutDown(void);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilSurfaceToDxtcData(ILenum Format);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilTexImage(ILuint Width, ILuint Height, ILuint Depth, ILubyte NumChannels, ILenum Format, ILenum Type, void *Data);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilTexImageDxtc(ILint w, ILint h, ILint d, ILenum DxtFormat, const ILubyte* data);
|
|
||||||
ILAPI ILenum ILAPIENTRY ilTypeFromExt(ILconst_string FileName);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilTypeFunc(ILenum Mode);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilLoadData(ILconst_string FileName, ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilLoadDataF(ILHANDLE File, ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilLoadDataL(void *Lump, ILuint Size, ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilSaveData(ILconst_string FileName);
|
|
||||||
|
|
||||||
// For all those weirdos that spell "colour" without the 'u'.
|
|
||||||
#define ilClearColor ilClearColour
|
|
||||||
#define ilKeyColor ilKeyColour
|
|
||||||
|
|
||||||
#define imemclear(x,y) memset(x,0,y);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // __IL_H__
|
|
||||||
#endif // __il_h__
|
|
205
SQCSim2021/external/devil178/include/IL/il_wrap.h
vendored
205
SQCSim2021/external/devil178/include/IL/il_wrap.h
vendored
@ -1,205 +0,0 @@
|
|||||||
#ifndef WRAPPER_H
|
|
||||||
#define WRAPPER_H
|
|
||||||
|
|
||||||
/*#include <il/il.h>
|
|
||||||
#include <il/ilu.h>*/
|
|
||||||
#include <IL/ilut.h> // Probably only have to #include this one
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#ifndef _IL_WRAP_BUILD_LIB
|
|
||||||
#pragma comment(lib, "il_wrap.lib")
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class ilImage
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ilImage();
|
|
||||||
ilImage(char *);
|
|
||||||
ilImage(const ilImage &);
|
|
||||||
virtual ~ilImage();
|
|
||||||
|
|
||||||
ILboolean Load(char *);
|
|
||||||
ILboolean Load(char *, ILenum);
|
|
||||||
ILboolean Save(char *);
|
|
||||||
ILboolean Save(char *, ILenum);
|
|
||||||
|
|
||||||
|
|
||||||
// ImageLib functions
|
|
||||||
ILboolean ActiveImage(ILuint);
|
|
||||||
ILboolean ActiveLayer(ILuint);
|
|
||||||
ILboolean ActiveMipmap(ILuint);
|
|
||||||
ILboolean Clear(void);
|
|
||||||
ILvoid ClearColour(ILclampf, ILclampf, ILclampf, ILclampf);
|
|
||||||
ILboolean Convert(ILenum);
|
|
||||||
ILboolean Copy(ILuint);
|
|
||||||
ILboolean Default(void);
|
|
||||||
ILboolean Flip(void);
|
|
||||||
ILboolean SwapColours(void);
|
|
||||||
ILboolean Resize(ILuint, ILuint, ILuint);
|
|
||||||
ILboolean TexImage(ILuint, ILuint, ILuint, ILubyte, ILenum, ILenum, ILvoid*);
|
|
||||||
|
|
||||||
|
|
||||||
// Image handling
|
|
||||||
ILvoid Bind(void) const;
|
|
||||||
ILvoid Bind(ILuint);
|
|
||||||
ILvoid Close(void) { this->Delete(); }
|
|
||||||
ILvoid Delete(void);
|
|
||||||
ILvoid iGenBind();
|
|
||||||
ILenum PaletteAlphaIndex();
|
|
||||||
|
|
||||||
// Image characteristics
|
|
||||||
ILuint Width(void);
|
|
||||||
ILuint Height(void);
|
|
||||||
ILuint Depth(void);
|
|
||||||
ILubyte Bpp(void);
|
|
||||||
ILubyte Bitpp(void);
|
|
||||||
ILenum PaletteType(void);
|
|
||||||
ILenum Format(void);
|
|
||||||
ILenum Type(void);
|
|
||||||
ILuint NumImages(void);
|
|
||||||
ILuint NumMipmaps(void);
|
|
||||||
ILuint GetId(void) const;
|
|
||||||
ILenum GetOrigin(void);
|
|
||||||
ILubyte *GetData(void);
|
|
||||||
ILubyte *GetPalette(void);
|
|
||||||
|
|
||||||
|
|
||||||
// Rendering
|
|
||||||
ILuint BindImage(void);
|
|
||||||
ILuint BindImage(ILenum);
|
|
||||||
|
|
||||||
|
|
||||||
// Operators
|
|
||||||
ilImage& operator = (ILuint);
|
|
||||||
ilImage& operator = (const ilImage &);
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
|
||||||
ILuint Id;
|
|
||||||
|
|
||||||
private:
|
|
||||||
ILvoid iStartUp();
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class ilFilters
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static ILboolean Alienify(ilImage &);
|
|
||||||
static ILboolean BlurAvg(ilImage &, ILuint Iter);
|
|
||||||
static ILboolean BlurGaussian(ilImage &, ILuint Iter);
|
|
||||||
static ILboolean Contrast(ilImage &, ILfloat Contrast);
|
|
||||||
static ILboolean EdgeDetectE(ilImage &);
|
|
||||||
static ILboolean EdgeDetectP(ilImage &);
|
|
||||||
static ILboolean EdgeDetectS(ilImage &);
|
|
||||||
static ILboolean Emboss(ilImage &);
|
|
||||||
static ILboolean Gamma(ilImage &, ILfloat Gamma);
|
|
||||||
static ILboolean Negative(ilImage &);
|
|
||||||
static ILboolean Noisify(ilImage &, ILubyte Factor);
|
|
||||||
static ILboolean Pixelize(ilImage &, ILuint PixSize);
|
|
||||||
static ILboolean Saturate(ilImage &, ILfloat Saturation);
|
|
||||||
static ILboolean Saturate(ilImage &, ILfloat r, ILfloat g, ILfloat b, ILfloat Saturation);
|
|
||||||
static ILboolean ScaleColours(ilImage &, ILfloat r, ILfloat g, ILfloat b);
|
|
||||||
static ILboolean Sharpen(ilImage &, ILfloat Factor, ILuint Iter);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef ILUT_USE_OPENGL
|
|
||||||
class ilOgl
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static ILvoid Init(void);
|
|
||||||
static GLuint BindTex(ilImage &);
|
|
||||||
static ILboolean Upload(ilImage &, ILuint);
|
|
||||||
static GLuint Mipmap(ilImage &);
|
|
||||||
static ILboolean Screen(void);
|
|
||||||
static ILboolean Screenie(void);
|
|
||||||
};
|
|
||||||
#endif//ILUT_USE_OPENGL
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef ILUT_USE_ALLEGRO
|
|
||||||
class ilAlleg
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static ILvoid Init(void);
|
|
||||||
static BITMAP *Convert(ilImage &);
|
|
||||||
};
|
|
||||||
#endif//ILUT_USE_ALLEGRO
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef ILUT_USE_WIN32
|
|
||||||
class ilWin32
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static ILvoid Init(void);
|
|
||||||
static HBITMAP Convert(ilImage &);
|
|
||||||
static ILboolean GetClipboard(ilImage &);
|
|
||||||
static ILvoid GetInfo(ilImage &, BITMAPINFO *Info);
|
|
||||||
static ILubyte *GetPadData(ilImage &);
|
|
||||||
static HPALETTE GetPal(ilImage &);
|
|
||||||
static ILboolean GetResource(ilImage &, HINSTANCE hInst, ILint ID, char *ResourceType);
|
|
||||||
static ILboolean GetResource(ilImage &, HINSTANCE hInst, ILint ID, char *ResourceType, ILenum Type);
|
|
||||||
static ILboolean SetClipboard(ilImage &);
|
|
||||||
};
|
|
||||||
#endif//ILUT_USE_WIN32
|
|
||||||
|
|
||||||
|
|
||||||
class ilValidate
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static ILboolean Valid(ILenum, char *);
|
|
||||||
static ILboolean Valid(ILenum, FILE *);
|
|
||||||
static ILboolean Valid(ILenum, ILvoid *, ILuint);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class ilState
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static ILboolean Disable(ILenum);
|
|
||||||
static ILboolean Enable(ILenum);
|
|
||||||
static ILvoid Get(ILenum, ILboolean &);
|
|
||||||
static ILvoid Get(ILenum, ILint &);
|
|
||||||
static ILboolean GetBool(ILenum);
|
|
||||||
static ILint GetInt(ILenum);
|
|
||||||
static const char *GetString(ILenum);
|
|
||||||
static ILboolean IsDisabled(ILenum);
|
|
||||||
static ILboolean IsEnabled(ILenum);
|
|
||||||
static ILboolean Origin(ILenum);
|
|
||||||
static ILvoid Pop(void);
|
|
||||||
static ILvoid Push(ILuint);
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class ilError
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static ILvoid Check(ILvoid (*Callback)(const char*));
|
|
||||||
static ILvoid Check(ILvoid (*Callback)(ILenum));
|
|
||||||
static ILenum Get(void);
|
|
||||||
static const char *String(void);
|
|
||||||
static const char *String(ILenum);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif//WRAPPER_H
|
|
195
SQCSim2021/external/devil178/include/IL/ilu.h
vendored
195
SQCSim2021/external/devil178/include/IL/ilu.h
vendored
@ -1,195 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ImageLib Utility Sources
|
|
||||||
// Copyright (C) 2000-2009 by Denton Woods
|
|
||||||
// Last modified: 03/07/2009
|
|
||||||
//
|
|
||||||
// Filename: IL/ilu.h
|
|
||||||
//
|
|
||||||
// Description: The main include file for ILU
|
|
||||||
//
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Doxygen comment
|
|
||||||
/*! \file ilu.h
|
|
||||||
The main include file for ILU
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __ilu_h_
|
|
||||||
#ifndef __ILU_H__
|
|
||||||
|
|
||||||
#define __ilu_h_
|
|
||||||
#define __ILU_H__
|
|
||||||
|
|
||||||
#include <IL/il.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#if (defined(IL_USE_PRAGMA_LIBS)) && (!defined(_IL_BUILD_LIBRARY))
|
|
||||||
#if defined(_MSC_VER) || defined(__BORLANDC__)
|
|
||||||
#pragma comment(lib, "ILU.lib")
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#define ILU_VERSION_1_7_8 1
|
|
||||||
#define ILU_VERSION 178
|
|
||||||
|
|
||||||
|
|
||||||
#define ILU_FILTER 0x2600
|
|
||||||
#define ILU_NEAREST 0x2601
|
|
||||||
#define ILU_LINEAR 0x2602
|
|
||||||
#define ILU_BILINEAR 0x2603
|
|
||||||
#define ILU_SCALE_BOX 0x2604
|
|
||||||
#define ILU_SCALE_TRIANGLE 0x2605
|
|
||||||
#define ILU_SCALE_BELL 0x2606
|
|
||||||
#define ILU_SCALE_BSPLINE 0x2607
|
|
||||||
#define ILU_SCALE_LANCZOS3 0x2608
|
|
||||||
#define ILU_SCALE_MITCHELL 0x2609
|
|
||||||
|
|
||||||
|
|
||||||
// Error types
|
|
||||||
#define ILU_INVALID_ENUM 0x0501
|
|
||||||
#define ILU_OUT_OF_MEMORY 0x0502
|
|
||||||
#define ILU_INTERNAL_ERROR 0x0504
|
|
||||||
#define ILU_INVALID_VALUE 0x0505
|
|
||||||
#define ILU_ILLEGAL_OPERATION 0x0506
|
|
||||||
#define ILU_INVALID_PARAM 0x0509
|
|
||||||
|
|
||||||
|
|
||||||
// Values
|
|
||||||
#define ILU_PLACEMENT 0x0700
|
|
||||||
#define ILU_LOWER_LEFT 0x0701
|
|
||||||
#define ILU_LOWER_RIGHT 0x0702
|
|
||||||
#define ILU_UPPER_LEFT 0x0703
|
|
||||||
#define ILU_UPPER_RIGHT 0x0704
|
|
||||||
#define ILU_CENTER 0x0705
|
|
||||||
#define ILU_CONVOLUTION_MATRIX 0x0710
|
|
||||||
|
|
||||||
#define ILU_VERSION_NUM IL_VERSION_NUM
|
|
||||||
#define ILU_VENDOR IL_VENDOR
|
|
||||||
|
|
||||||
|
|
||||||
// Languages
|
|
||||||
#define ILU_ENGLISH 0x0800
|
|
||||||
#define ILU_ARABIC 0x0801
|
|
||||||
#define ILU_DUTCH 0x0802
|
|
||||||
#define ILU_JAPANESE 0x0803
|
|
||||||
#define ILU_SPANISH 0x0804
|
|
||||||
#define ILU_GERMAN 0x0805
|
|
||||||
#define ILU_FRENCH 0x0806
|
|
||||||
|
|
||||||
|
|
||||||
// Filters
|
|
||||||
/*
|
|
||||||
#define ILU_FILTER_BLUR 0x0803
|
|
||||||
#define ILU_FILTER_GAUSSIAN_3x3 0x0804
|
|
||||||
#define ILU_FILTER_GAUSSIAN_5X5 0x0805
|
|
||||||
#define ILU_FILTER_EMBOSS1 0x0807
|
|
||||||
#define ILU_FILTER_EMBOSS2 0x0808
|
|
||||||
#define ILU_FILTER_LAPLACIAN1 0x080A
|
|
||||||
#define ILU_FILTER_LAPLACIAN2 0x080B
|
|
||||||
#define ILU_FILTER_LAPLACIAN3 0x080C
|
|
||||||
#define ILU_FILTER_LAPLACIAN4 0x080D
|
|
||||||
#define ILU_FILTER_SHARPEN1 0x080E
|
|
||||||
#define ILU_FILTER_SHARPEN2 0x080F
|
|
||||||
#define ILU_FILTER_SHARPEN3 0x0810
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct ILinfo
|
|
||||||
{
|
|
||||||
ILuint Id; // the image's id
|
|
||||||
ILubyte *Data; // the image's data
|
|
||||||
ILuint Width; // the image's width
|
|
||||||
ILuint Height; // the image's height
|
|
||||||
ILuint Depth; // the image's depth
|
|
||||||
ILubyte Bpp; // bytes per pixel (not bits) of the image
|
|
||||||
ILuint SizeOfData; // the total size of the data (in bytes)
|
|
||||||
ILenum Format; // image format (in IL enum style)
|
|
||||||
ILenum Type; // image type (in IL enum style)
|
|
||||||
ILenum Origin; // origin of the image
|
|
||||||
ILubyte *Palette; // the image's palette
|
|
||||||
ILenum PalType; // palette type
|
|
||||||
ILuint PalSize; // palette size
|
|
||||||
ILenum CubeFlags; // flags for what cube map sides are present
|
|
||||||
ILuint NumNext; // number of images following
|
|
||||||
ILuint NumMips; // number of mipmaps
|
|
||||||
ILuint NumLayers; // number of layers
|
|
||||||
} ILinfo;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct ILpointf {
|
|
||||||
ILfloat x;
|
|
||||||
ILfloat y;
|
|
||||||
} ILpointf;
|
|
||||||
|
|
||||||
typedef struct ILpointi {
|
|
||||||
ILint x;
|
|
||||||
ILint y;
|
|
||||||
} ILpointi;
|
|
||||||
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluAlienify(void);
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluBlurAvg(ILuint Iter);
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluBlurGaussian(ILuint Iter);
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluBuildMipmaps(void);
|
|
||||||
ILAPI ILuint ILAPIENTRY iluColoursUsed(void);
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluCompareImage(ILuint Comp);
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluContrast(ILfloat Contrast);
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluCrop(ILuint XOff, ILuint YOff, ILuint ZOff, ILuint Width, ILuint Height, ILuint Depth);
|
|
||||||
ILAPI void ILAPIENTRY iluDeleteImage(ILuint Id); // Deprecated
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluEdgeDetectE(void);
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluEdgeDetectP(void);
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluEdgeDetectS(void);
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluEmboss(void);
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluEnlargeCanvas(ILuint Width, ILuint Height, ILuint Depth);
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluEnlargeImage(ILfloat XDim, ILfloat YDim, ILfloat ZDim);
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluEqualize(void);
|
|
||||||
ILAPI ILconst_string ILAPIENTRY iluErrorString(ILenum Error);
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluConvolution(ILint *matrix, ILint scale, ILint bias);
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluFlipImage(void);
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluGammaCorrect(ILfloat Gamma);
|
|
||||||
ILAPI ILuint ILAPIENTRY iluGenImage(void); // Deprecated
|
|
||||||
ILAPI void ILAPIENTRY iluGetImageInfo(ILinfo *Info);
|
|
||||||
ILAPI ILint ILAPIENTRY iluGetInteger(ILenum Mode);
|
|
||||||
ILAPI void ILAPIENTRY iluGetIntegerv(ILenum Mode, ILint *Param);
|
|
||||||
ILAPI ILstring ILAPIENTRY iluGetString(ILenum StringName);
|
|
||||||
ILAPI void ILAPIENTRY iluImageParameter(ILenum PName, ILenum Param);
|
|
||||||
ILAPI void ILAPIENTRY iluInit(void);
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluInvertAlpha(void);
|
|
||||||
ILAPI ILuint ILAPIENTRY iluLoadImage(ILconst_string FileName);
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluMirror(void);
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluNegative(void);
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluNoisify(ILclampf Tolerance);
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluPixelize(ILuint PixSize);
|
|
||||||
ILAPI void ILAPIENTRY iluRegionfv(ILpointf *Points, ILuint n);
|
|
||||||
ILAPI void ILAPIENTRY iluRegioniv(ILpointi *Points, ILuint n);
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluReplaceColour(ILubyte Red, ILubyte Green, ILubyte Blue, ILfloat Tolerance);
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluRotate(ILfloat Angle);
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluRotate3D(ILfloat x, ILfloat y, ILfloat z, ILfloat Angle);
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluSaturate1f(ILfloat Saturation);
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluSaturate4f(ILfloat r, ILfloat g, ILfloat b, ILfloat Saturation);
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluScale(ILuint Width, ILuint Height, ILuint Depth);
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluScaleAlpha(ILfloat scale);
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluScaleColours(ILfloat r, ILfloat g, ILfloat b);
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluSetLanguage(ILenum Language);
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluSharpen(ILfloat Factor, ILuint Iter);
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluSwapColours(void);
|
|
||||||
ILAPI ILboolean ILAPIENTRY iluWave(ILfloat Angle);
|
|
||||||
|
|
||||||
#define iluColorsUsed iluColoursUsed
|
|
||||||
#define iluSwapColors iluSwapColours
|
|
||||||
#define iluReplaceColor iluReplaceColour
|
|
||||||
#define iluScaleColor iluScaleColour
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // __ILU_H__
|
|
||||||
#endif // __ilu_h_
|
|
@ -1,25 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ImageLib Utility Sources
|
|
||||||
// Copyright (C) 2000-2002 by Denton Woods
|
|
||||||
// Last modified: 07/09/2002 <--Y2K Compliant! =]
|
|
||||||
//
|
|
||||||
// Filename: src-ILU/src/ilu_region.h
|
|
||||||
//
|
|
||||||
// Description: Creates an image region.
|
|
||||||
//
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#ifndef ILU_REGION_H
|
|
||||||
#define ILU_REGION_H
|
|
||||||
|
|
||||||
typedef struct Edge
|
|
||||||
{
|
|
||||||
ILint yUpper;
|
|
||||||
ILfloat xIntersect, dxPerScan;
|
|
||||||
struct Edge *next;
|
|
||||||
} Edge;
|
|
||||||
|
|
||||||
|
|
||||||
#endif//ILU_REGION_H
|
|
||||||
|
|
390
SQCSim2021/external/devil178/include/IL/ilut.h
vendored
390
SQCSim2021/external/devil178/include/IL/ilut.h
vendored
@ -1,390 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ImageLib Utility Toolkit Sources
|
|
||||||
// Copyright (C) 2000-2009 by Denton Woods
|
|
||||||
// Last modified: 03/07/2009
|
|
||||||
//
|
|
||||||
// Filename: IL/ilut.h
|
|
||||||
//
|
|
||||||
// Description: The main include file for ILUT
|
|
||||||
//
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Doxygen comment
|
|
||||||
/*! \file ilut.h
|
|
||||||
The main include file for ILUT
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __ilut_h_
|
|
||||||
#ifndef __ILUT_H__
|
|
||||||
|
|
||||||
#define __ilut_h_
|
|
||||||
#define __ILUT_H__
|
|
||||||
|
|
||||||
#include <IL/il.h>
|
|
||||||
#include <IL/ilu.h>
|
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// Defines
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#define ILUT_VERSION_1_7_8 1
|
|
||||||
#define ILUT_VERSION 178
|
|
||||||
|
|
||||||
|
|
||||||
// Attribute Bits
|
|
||||||
#define ILUT_OPENGL_BIT 0x00000001
|
|
||||||
#define ILUT_D3D_BIT 0x00000002
|
|
||||||
#define ILUT_ALL_ATTRIB_BITS 0x000FFFFF
|
|
||||||
|
|
||||||
|
|
||||||
// Error Types
|
|
||||||
#define ILUT_INVALID_ENUM 0x0501
|
|
||||||
#define ILUT_OUT_OF_MEMORY 0x0502
|
|
||||||
#define ILUT_INVALID_VALUE 0x0505
|
|
||||||
#define ILUT_ILLEGAL_OPERATION 0x0506
|
|
||||||
#define ILUT_INVALID_PARAM 0x0509
|
|
||||||
#define ILUT_COULD_NOT_OPEN_FILE 0x050A
|
|
||||||
#define ILUT_STACK_OVERFLOW 0x050E
|
|
||||||
#define ILUT_STACK_UNDERFLOW 0x050F
|
|
||||||
#define ILUT_BAD_DIMENSIONS 0x0511
|
|
||||||
#define ILUT_NOT_SUPPORTED 0x0550
|
|
||||||
|
|
||||||
|
|
||||||
// State Definitions
|
|
||||||
#define ILUT_PALETTE_MODE 0x0600
|
|
||||||
#define ILUT_OPENGL_CONV 0x0610
|
|
||||||
#define ILUT_D3D_MIPLEVELS 0x0620
|
|
||||||
#define ILUT_MAXTEX_WIDTH 0x0630
|
|
||||||
#define ILUT_MAXTEX_HEIGHT 0x0631
|
|
||||||
#define ILUT_MAXTEX_DEPTH 0x0632
|
|
||||||
#define ILUT_GL_USE_S3TC 0x0634
|
|
||||||
#define ILUT_D3D_USE_DXTC 0x0634
|
|
||||||
#define ILUT_GL_GEN_S3TC 0x0635
|
|
||||||
#define ILUT_D3D_GEN_DXTC 0x0635
|
|
||||||
#define ILUT_S3TC_FORMAT 0x0705
|
|
||||||
#define ILUT_DXTC_FORMAT 0x0705
|
|
||||||
#define ILUT_D3D_POOL 0x0706
|
|
||||||
#define ILUT_D3D_ALPHA_KEY_COLOR 0x0707
|
|
||||||
#define ILUT_D3D_ALPHA_KEY_COLOUR 0x0707
|
|
||||||
#define ILUT_FORCE_INTEGER_FORMAT 0x0636
|
|
||||||
|
|
||||||
//This new state does automatic texture target detection
|
|
||||||
//if enabled. Currently, only cubemap detection is supported.
|
|
||||||
//if the current image is no cubemap, the 2d texture is chosen.
|
|
||||||
#define ILUT_GL_AUTODETECT_TEXTURE_TARGET 0x0807
|
|
||||||
|
|
||||||
|
|
||||||
// Values
|
|
||||||
#define ILUT_VERSION_NUM IL_VERSION_NUM
|
|
||||||
#define ILUT_VENDOR IL_VENDOR
|
|
||||||
|
|
||||||
// The different rendering api's...more to be added later?
|
|
||||||
#define ILUT_OPENGL 0
|
|
||||||
#define ILUT_ALLEGRO 1
|
|
||||||
#define ILUT_WIN32 2
|
|
||||||
#define ILUT_DIRECT3D8 3
|
|
||||||
#define ILUT_DIRECT3D9 4
|
|
||||||
#define ILUT_X11 5
|
|
||||||
#define ILUT_DIRECT3D10 6
|
|
||||||
|
|
||||||
/*
|
|
||||||
// Includes specific config
|
|
||||||
#ifdef DJGPP
|
|
||||||
#define ILUT_USE_ALLEGRO
|
|
||||||
#elif _WIN32_WCE
|
|
||||||
#define ILUT_USE_WIN32
|
|
||||||
#elif _WIN32
|
|
||||||
//#ifdef __GNUC__ //__CYGWIN32__ (Cygwin seems to not define this with DevIL builds)
|
|
||||||
#define ILUT_USE_WIN32
|
|
||||||
#include "IL/config.h"
|
|
||||||
|
|
||||||
// Temporary fix for the SDL main() linker bug.
|
|
||||||
//#ifdef ILUT_USE_SDL
|
|
||||||
//#undef ILUT_USE_SDL
|
|
||||||
//#endif//ILUT_USE_SDL
|
|
||||||
|
|
||||||
//#else
|
|
||||||
// #define ILUT_USE_WIN32
|
|
||||||
// #define ILUT_USE_OPENGL
|
|
||||||
// #define ILUT_USE_SDL
|
|
||||||
// #define ILUT_USE_DIRECTX8
|
|
||||||
//#endif
|
|
||||||
#elif BEOS // Don't know the #define
|
|
||||||
#define ILUT_USE_BEOS
|
|
||||||
#define ILUT_USE_OPENGL
|
|
||||||
#elif MACOSX
|
|
||||||
#define ILUT_USE_OPENGL
|
|
||||||
#else
|
|
||||||
|
|
||||||
// We are surely using a *nix so the configure script
|
|
||||||
// may have written the configured config.h header
|
|
||||||
#include "IL/config.h"
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if (defined(_WIN32) || defined(_WIN64))
|
|
||||||
#if (defined(IL_USE_PRAGMA_LIBS)) && (!defined(_IL_BUILD_LIBRARY))
|
|
||||||
#if defined(_MSC_VER) || defined(__BORLANDC__)
|
|
||||||
#pragma comment(lib, "ILUT.lib")
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <IL/ilut_config.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//this should remain private and hidden
|
|
||||||
//#include "IL/config.h"
|
|
||||||
|
|
||||||
//////////////
|
|
||||||
// OpenGL
|
|
||||||
//////////////
|
|
||||||
|
|
||||||
#ifdef ILUT_USE_OPENGL
|
|
||||||
#if defined(_MSC_VER) || defined(_WIN32)
|
|
||||||
//#define WIN32_LEAN_AND_MEAN
|
|
||||||
#include <windows.h>
|
|
||||||
#endif//_MSC_VER
|
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
#include <OpenGL/gl.h>
|
|
||||||
#include <OpenGL/glu.h>
|
|
||||||
#else
|
|
||||||
#include <GL/gl.h>
|
|
||||||
#include <GL/glu.h>
|
|
||||||
#endif//__APPLE__
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef ILUT_USE_WIN32
|
|
||||||
//#define WIN32_LEAN_AND_MEAN
|
|
||||||
#ifdef _DEBUG
|
|
||||||
#define _CRTDBG_MAP_ALLOC
|
|
||||||
#include <stdlib.h>
|
|
||||||
#ifndef _WIN32_WCE
|
|
||||||
#include <crtdbg.h>
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#include <windows.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// If we can avoid including these in all cases thing tend to break less
|
|
||||||
// and we can keep all of them defined as available
|
|
||||||
//
|
|
||||||
// Kriss
|
|
||||||
//
|
|
||||||
|
|
||||||
// ImageLib Utility Toolkit's Allegro Functions
|
|
||||||
#ifdef ILUT_USE_ALLEGRO
|
|
||||||
// #include <allegro.h>
|
|
||||||
#endif//ILUT_USE_ALLEGRO
|
|
||||||
|
|
||||||
#ifdef ILUT_USE_SDL
|
|
||||||
// #include <SDL.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef ILUT_USE_DIRECTX8
|
|
||||||
#include <d3d8.h>
|
|
||||||
#endif//ILUT_USE_DIRECTX9
|
|
||||||
|
|
||||||
#ifdef ILUT_USE_DIRECTX9
|
|
||||||
#include <d3d9.h>
|
|
||||||
#endif//ILUT_USE_DIRECTX9
|
|
||||||
|
|
||||||
#ifdef ILUT_USE_DIRECTX10
|
|
||||||
#pragma warning(push)
|
|
||||||
#pragma warning(disable : 4201) // Disables 'nonstandard extension used : nameless struct/union' warning
|
|
||||||
#include <rpcsal.h>
|
|
||||||
#include <sal.h>
|
|
||||||
#include <d3d10.h>
|
|
||||||
#pragma warning(pop)
|
|
||||||
#endif//ILUT_USE_DIRECTX10
|
|
||||||
|
|
||||||
#ifdef ILUT_USE_X11
|
|
||||||
#include <X11/Xlib.h>
|
|
||||||
#include <X11/Xutil.h>
|
|
||||||
#ifdef ILUT_USE_XSHM
|
|
||||||
#include <sys/ipc.h>
|
|
||||||
#include <sys/shm.h>
|
|
||||||
#include <X11/extensions/XShm.h>
|
|
||||||
#endif//ILUT_USE_XSHM
|
|
||||||
#endif//ILUT_USE_X11
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// Functions
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// ImageLib Utility Toolkit Functions
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutDisable(ILenum Mode);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutEnable(ILenum Mode);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutGetBoolean(ILenum Mode);
|
|
||||||
ILAPI void ILAPIENTRY ilutGetBooleanv(ILenum Mode, ILboolean *Param);
|
|
||||||
ILAPI ILint ILAPIENTRY ilutGetInteger(ILenum Mode);
|
|
||||||
ILAPI void ILAPIENTRY ilutGetIntegerv(ILenum Mode, ILint *Param);
|
|
||||||
ILAPI ILstring ILAPIENTRY ilutGetString(ILenum StringName);
|
|
||||||
ILAPI void ILAPIENTRY ilutInit(void);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutIsDisabled(ILenum Mode);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutIsEnabled(ILenum Mode);
|
|
||||||
ILAPI void ILAPIENTRY ilutPopAttrib(void);
|
|
||||||
ILAPI void ILAPIENTRY ilutPushAttrib(ILuint Bits);
|
|
||||||
ILAPI void ILAPIENTRY ilutSetInteger(ILenum Mode, ILint Param);
|
|
||||||
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutRenderer(ILenum Renderer);
|
|
||||||
|
|
||||||
|
|
||||||
// ImageLib Utility Toolkit's OpenGL Functions
|
|
||||||
#ifdef ILUT_USE_OPENGL
|
|
||||||
ILAPI GLuint ILAPIENTRY ilutGLBindTexImage();
|
|
||||||
ILAPI GLuint ILAPIENTRY ilutGLBindMipmaps(void);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutGLBuildMipmaps(void);
|
|
||||||
ILAPI GLuint ILAPIENTRY ilutGLLoadImage(ILstring FileName);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutGLScreen(void);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutGLScreenie(void);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutGLSaveImage(ILstring FileName, GLuint TexID);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutGLSubTex2D(GLuint TexID, ILuint XOff, ILuint YOff);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutGLSubTex3D(GLuint TexID, ILuint XOff, ILuint YOff, ILuint ZOff);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutGLSetTex2D(GLuint TexID);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutGLSetTex3D(GLuint TexID);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutGLTexImage(GLuint Level);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutGLSubTex(GLuint TexID, ILuint XOff, ILuint YOff);
|
|
||||||
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutGLSetTex(GLuint TexID); // Deprecated - use ilutGLSetTex2D.
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutGLSubTex(GLuint TexID, ILuint XOff, ILuint YOff); // Use ilutGLSubTex2D.
|
|
||||||
#endif//ILUT_USE_OPENGL
|
|
||||||
|
|
||||||
|
|
||||||
// ImageLib Utility Toolkit's Allegro Functions
|
|
||||||
#ifdef ILUT_USE_ALLEGRO
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
#include <allegro.h>
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ILAPI BITMAP* ILAPIENTRY ilutAllegLoadImage(ILstring FileName);
|
|
||||||
ILAPI BITMAP* ILAPIENTRY ilutConvertToAlleg(PALETTE Pal);
|
|
||||||
#endif//ILUT_USE_ALLEGRO
|
|
||||||
|
|
||||||
|
|
||||||
// ImageLib Utility Toolkit's SDL Functions
|
|
||||||
#ifdef ILUT_USE_SDL
|
|
||||||
ILAPI struct SDL_Surface* ILAPIENTRY ilutConvertToSDLSurface(unsigned int flags);
|
|
||||||
ILAPI struct SDL_Surface* ILAPIENTRY ilutSDLSurfaceLoadImage(ILstring FileName);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutSDLSurfaceFromBitmap(struct SDL_Surface *Bitmap);
|
|
||||||
#endif//ILUT_USE_SDL
|
|
||||||
|
|
||||||
|
|
||||||
// ImageLib Utility Toolkit's BeOS Functions
|
|
||||||
#ifdef ILUT_USE_BEOS
|
|
||||||
ILAPI BBitmap ILAPIENTRY ilutConvertToBBitmap(void);
|
|
||||||
#endif//ILUT_USE_BEOS
|
|
||||||
|
|
||||||
|
|
||||||
// ImageLib Utility Toolkit's Win32 GDI Functions
|
|
||||||
#ifdef ILUT_USE_WIN32
|
|
||||||
ILAPI HBITMAP ILAPIENTRY ilutConvertToHBitmap(HDC hDC);
|
|
||||||
ILAPI HBITMAP ILAPIENTRY ilutConvertSliceToHBitmap(HDC hDC, ILuint slice);
|
|
||||||
ILAPI void ILAPIENTRY ilutFreePaddedData(ILubyte *Data);
|
|
||||||
ILAPI void ILAPIENTRY ilutGetBmpInfo(BITMAPINFO *Info);
|
|
||||||
ILAPI HPALETTE ILAPIENTRY ilutGetHPal(void);
|
|
||||||
ILAPI ILubyte* ILAPIENTRY ilutGetPaddedData(void);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutGetWinClipboard(void);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutLoadResource(HINSTANCE hInst, ILint ID, ILstring ResourceType, ILenum Type);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutSetHBitmap(HBITMAP Bitmap);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutSetHPal(HPALETTE Pal);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutSetWinClipboard(void);
|
|
||||||
ILAPI HBITMAP ILAPIENTRY ilutWinLoadImage(ILstring FileName, HDC hDC);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutWinLoadUrl(ILstring Url);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutWinPrint(ILuint XPos, ILuint YPos, ILuint Width, ILuint Height, HDC hDC);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutWinSaveImage(ILstring FileName, HBITMAP Bitmap);
|
|
||||||
#endif//ILUT_USE_WIN32
|
|
||||||
|
|
||||||
// ImageLib Utility Toolkit's DirectX 8 Functions
|
|
||||||
#ifdef ILUT_USE_DIRECTX8
|
|
||||||
// ILAPI void ILAPIENTRY ilutD3D8MipFunc(ILuint NumLevels);
|
|
||||||
ILAPI struct IDirect3DTexture8* ILAPIENTRY ilutD3D8Texture(struct IDirect3DDevice8 *Device);
|
|
||||||
ILAPI struct IDirect3DVolumeTexture8* ILAPIENTRY ilutD3D8VolumeTexture(struct IDirect3DDevice8 *Device);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutD3D8TexFromFile(struct IDirect3DDevice8 *Device, char *FileName, struct IDirect3DTexture8 **Texture);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutD3D8VolTexFromFile(struct IDirect3DDevice8 *Device, char *FileName, struct IDirect3DVolumeTexture8 **Texture);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutD3D8TexFromFileInMemory(struct IDirect3DDevice8 *Device, void *Lump, ILuint Size, struct IDirect3DTexture8 **Texture);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutD3D8VolTexFromFileInMemory(struct IDirect3DDevice8 *Device, void *Lump, ILuint Size, struct IDirect3DVolumeTexture8 **Texture);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutD3D8TexFromFileHandle(struct IDirect3DDevice8 *Device, ILHANDLE File, struct IDirect3DTexture8 **Texture);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutD3D8VolTexFromFileHandle(struct IDirect3DDevice8 *Device, ILHANDLE File, struct IDirect3DVolumeTexture8 **Texture);
|
|
||||||
// These two are not tested yet.
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutD3D8TexFromResource(struct IDirect3DDevice8 *Device, HMODULE SrcModule, char *SrcResource, struct IDirect3DTexture8 **Texture);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutD3D8VolTexFromResource(struct IDirect3DDevice8 *Device, HMODULE SrcModule, char *SrcResource, struct IDirect3DVolumeTexture8 **Texture);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutD3D8LoadSurface(struct IDirect3DDevice8 *Device, struct IDirect3DSurface8 *Surface);
|
|
||||||
#endif//ILUT_USE_DIRECTX8
|
|
||||||
|
|
||||||
#ifdef ILUT_USE_DIRECTX9
|
|
||||||
#pragma warning(push)
|
|
||||||
#pragma warning(disable : 4115) // Disables 'named type definition in parentheses' warning
|
|
||||||
// ILAPI void ILAPIENTRY ilutD3D9MipFunc(ILuint NumLevels);
|
|
||||||
ILAPI struct IDirect3DTexture9* ILAPIENTRY ilutD3D9Texture (struct IDirect3DDevice9* Device);
|
|
||||||
ILAPI struct IDirect3DVolumeTexture9* ILAPIENTRY ilutD3D9VolumeTexture (struct IDirect3DDevice9* Device);
|
|
||||||
ILAPI struct IDirect3DCubeTexture9* ILAPIENTRY ilutD3D9CubeTexture (struct IDirect3DDevice9* Device);
|
|
||||||
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutD3D9CubeTexFromFile(struct IDirect3DDevice9 *Device, ILconst_string FileName, struct IDirect3DCubeTexture9 **Texture);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutD3D9CubeTexFromFileInMemory(struct IDirect3DDevice9 *Device, void *Lump, ILuint Size, struct IDirect3DCubeTexture9 **Texture);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutD3D9CubeTexFromFileHandle(struct IDirect3DDevice9 *Device, ILHANDLE File, struct IDirect3DCubeTexture9 **Texture);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutD3D9CubeTexFromResource(struct IDirect3DDevice9 *Device, HMODULE SrcModule, ILconst_string SrcResource, struct IDirect3DCubeTexture9 **Texture);
|
|
||||||
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutD3D9TexFromFile(struct IDirect3DDevice9 *Device, ILconst_string FileName, struct IDirect3DTexture9 **Texture);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutD3D9VolTexFromFile(struct IDirect3DDevice9 *Device, ILconst_string FileName, struct IDirect3DVolumeTexture9 **Texture);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutD3D9TexFromFileInMemory(struct IDirect3DDevice9 *Device, void *Lump, ILuint Size, struct IDirect3DTexture9 **Texture);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutD3D9VolTexFromFileInMemory(struct IDirect3DDevice9 *Device, void *Lump, ILuint Size, struct IDirect3DVolumeTexture9 **Texture);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutD3D9TexFromFileHandle(struct IDirect3DDevice9 *Device, ILHANDLE File, struct IDirect3DTexture9 **Texture);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutD3D9VolTexFromFileHandle(struct IDirect3DDevice9 *Device, ILHANDLE File, struct IDirect3DVolumeTexture9 **Texture);
|
|
||||||
|
|
||||||
// These three are not tested yet.
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutD3D9TexFromResource(struct IDirect3DDevice9 *Device, HMODULE SrcModule, ILconst_string SrcResource, struct IDirect3DTexture9 **Texture);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutD3D9VolTexFromResource(struct IDirect3DDevice9 *Device, HMODULE SrcModule, ILconst_string SrcResource, struct IDirect3DVolumeTexture9 **Texture);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutD3D9LoadSurface(struct IDirect3DDevice9 *Device, struct IDirect3DSurface9 *Surface);
|
|
||||||
#pragma warning(pop)
|
|
||||||
#endif//ILUT_USE_DIRECTX9
|
|
||||||
|
|
||||||
#ifdef ILUT_USE_DIRECTX10
|
|
||||||
ILAPI ID3D10Texture2D* ILAPIENTRY ilutD3D10Texture(ID3D10Device *Device);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutD3D10TexFromFile(ID3D10Device *Device, ILconst_string FileName, ID3D10Texture2D **Texture);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutD3D10TexFromFileInMemory(ID3D10Device *Device, void *Lump, ILuint Size, ID3D10Texture2D **Texture);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutD3D10TexFromResource(ID3D10Device *Device, HMODULE SrcModule, ILconst_string SrcResource, ID3D10Texture2D **Texture);
|
|
||||||
ILAPI ILboolean ILAPIENTRY ilutD3D10TexFromFileHandle(ID3D10Device *Device, ILHANDLE File, ID3D10Texture2D **Texture);
|
|
||||||
#endif//ILUT_USE_DIRECTX10
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef ILUT_USE_X11
|
|
||||||
ILAPI XImage * ILAPIENTRY ilutXCreateImage( Display* );
|
|
||||||
ILAPI Pixmap ILAPIENTRY ilutXCreatePixmap( Display*,Drawable );
|
|
||||||
ILAPI XImage * ILAPIENTRY ilutXLoadImage( Display*,char* );
|
|
||||||
ILAPI Pixmap ILAPIENTRY ilutXLoadPixmap( Display*,Drawable,char* );
|
|
||||||
#ifdef ILUT_USE_XSHM
|
|
||||||
ILAPI XImage * ILAPIENTRY ilutXShmCreateImage( Display*,XShmSegmentInfo* );
|
|
||||||
ILAPI void ILAPIENTRY ilutXShmDestroyImage( Display*,XImage*,XShmSegmentInfo* );
|
|
||||||
ILAPI Pixmap ILAPIENTRY ilutXShmCreatePixmap( Display*,Drawable,XShmSegmentInfo* );
|
|
||||||
ILAPI void ILAPIENTRY ilutXShmFreePixmap( Display*,Pixmap,XShmSegmentInfo* );
|
|
||||||
ILAPI XImage * ILAPIENTRY ilutXShmLoadImage( Display*,char*,XShmSegmentInfo* );
|
|
||||||
ILAPI Pixmap ILAPIENTRY ilutXShmLoadPixmap( Display*,Drawable,char*,XShmSegmentInfo* );
|
|
||||||
#endif//ILUT_USE_XSHM
|
|
||||||
#endif//ILUT_USE_X11
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // __ILUT_H__
|
|
||||||
#endif // __ilut_h_
|
|
@ -1,26 +0,0 @@
|
|||||||
#ifndef __ILUT_CONFIG_H__
|
|
||||||
#define __ILUT_CONFIG_H__
|
|
||||||
|
|
||||||
#define IL_USE_PRAGMA_LIBS
|
|
||||||
|
|
||||||
// Supported APIs (ILUT)
|
|
||||||
|
|
||||||
//
|
|
||||||
// sorry just
|
|
||||||
// cant get this one to work under windows
|
|
||||||
// have disabled for the now
|
|
||||||
//
|
|
||||||
// will look at it some more later
|
|
||||||
//
|
|
||||||
// Kriss
|
|
||||||
//
|
|
||||||
#undef ILUT_USE_ALLEGRO
|
|
||||||
|
|
||||||
#undef ILUT_USE_DIRECTX8
|
|
||||||
//#define ILUT_USE_DIRECTX9
|
|
||||||
//#define ILUT_USE_DIRECTX10
|
|
||||||
#define ILUT_USE_OPENGL
|
|
||||||
//#define ILUT_USE_SDL
|
|
||||||
#define ILUT_USE_WIN32
|
|
||||||
|
|
||||||
#endif//__ILUT_CONFIG_H__
|
|
BIN
SQCSim2021/external/devil178/lib/DevIL.dll
vendored
BIN
SQCSim2021/external/devil178/lib/DevIL.dll
vendored
Binary file not shown.
BIN
SQCSim2021/external/devil178/lib/DevIL.lib
vendored
BIN
SQCSim2021/external/devil178/lib/DevIL.lib
vendored
Binary file not shown.
BIN
SQCSim2021/external/devil178/lib/ILU.dll
vendored
BIN
SQCSim2021/external/devil178/lib/ILU.dll
vendored
Binary file not shown.
BIN
SQCSim2021/external/devil178/lib/ILU.lib
vendored
BIN
SQCSim2021/external/devil178/lib/ILU.lib
vendored
Binary file not shown.
BIN
SQCSim2021/external/devil178/lib/ILUT.dll
vendored
BIN
SQCSim2021/external/devil178/lib/ILUT.dll
vendored
Binary file not shown.
BIN
SQCSim2021/external/devil178/lib/ILUT.lib
vendored
BIN
SQCSim2021/external/devil178/lib/ILUT.lib
vendored
Binary file not shown.
BIN
SQCSim2021/external/devil178/lib/unicode/DevIL.dll
vendored
BIN
SQCSim2021/external/devil178/lib/unicode/DevIL.dll
vendored
Binary file not shown.
BIN
SQCSim2021/external/devil178/lib/unicode/DevIL.lib
vendored
BIN
SQCSim2021/external/devil178/lib/unicode/DevIL.lib
vendored
Binary file not shown.
BIN
SQCSim2021/external/devil178/lib/unicode/ILU.dll
vendored
BIN
SQCSim2021/external/devil178/lib/unicode/ILU.dll
vendored
Binary file not shown.
BIN
SQCSim2021/external/devil178/lib/unicode/ILU.lib
vendored
BIN
SQCSim2021/external/devil178/lib/unicode/ILU.lib
vendored
Binary file not shown.
BIN
SQCSim2021/external/devil178/lib/unicode/ILUT.dll
vendored
BIN
SQCSim2021/external/devil178/lib/unicode/ILUT.dll
vendored
Binary file not shown.
BIN
SQCSim2021/external/devil178/lib/unicode/ILUT.lib
vendored
BIN
SQCSim2021/external/devil178/lib/unicode/ILUT.lib
vendored
Binary file not shown.
16126
SQCSim2021/external/glew170/include/GL/glew.h
vendored
16126
SQCSim2021/external/glew170/include/GL/glew.h
vendored
File diff suppressed because it is too large
Load Diff
1587
SQCSim2021/external/glew170/include/GL/glxew.h
vendored
1587
SQCSim2021/external/glew170/include/GL/glxew.h
vendored
File diff suppressed because it is too large
Load Diff
1363
SQCSim2021/external/glew170/include/GL/wglew.h
vendored
1363
SQCSim2021/external/glew170/include/GL/wglew.h
vendored
File diff suppressed because it is too large
Load Diff
BIN
SQCSim2021/external/glew170/lib/glew32.lib
vendored
BIN
SQCSim2021/external/glew170/lib/glew32.lib
vendored
Binary file not shown.
BIN
SQCSim2021/external/glew170/lib/glew32mx.lib
vendored
BIN
SQCSim2021/external/glew170/lib/glew32mx.lib
vendored
Binary file not shown.
BIN
SQCSim2021/external/glew170/lib/glew32mxs.lib
vendored
BIN
SQCSim2021/external/glew170/lib/glew32mxs.lib
vendored
Binary file not shown.
BIN
SQCSim2021/external/glew170/lib/glew32s.lib
vendored
BIN
SQCSim2021/external/glew170/lib/glew32s.lib
vendored
Binary file not shown.
@ -1,56 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_AUDIO_HPP
|
|
||||||
#define SFML_AUDIO_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#include <SFML/System.hpp>
|
|
||||||
#include <SFML/Audio/InputSoundFile.hpp>
|
|
||||||
#include <SFML/Audio/Listener.hpp>
|
|
||||||
#include <SFML/Audio/Music.hpp>
|
|
||||||
#include <SFML/Audio/OutputSoundFile.hpp>
|
|
||||||
#include <SFML/Audio/Sound.hpp>
|
|
||||||
#include <SFML/Audio/SoundBuffer.hpp>
|
|
||||||
#include <SFML/Audio/SoundBufferRecorder.hpp>
|
|
||||||
#include <SFML/Audio/SoundFileFactory.hpp>
|
|
||||||
#include <SFML/Audio/SoundFileReader.hpp>
|
|
||||||
#include <SFML/Audio/SoundFileWriter.hpp>
|
|
||||||
#include <SFML/Audio/SoundRecorder.hpp>
|
|
||||||
#include <SFML/Audio/SoundSource.hpp>
|
|
||||||
#include <SFML/Audio/SoundStream.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_AUDIO_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \defgroup audio Audio module
|
|
||||||
///
|
|
||||||
/// Sounds, streaming (musics or custom sources), recording,
|
|
||||||
/// spatialization.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,70 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_ALRESOURCE_HPP
|
|
||||||
#define SFML_ALRESOURCE_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Audio/Export.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Base class for classes that require an OpenAL context
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_AUDIO_API AlResource
|
|
||||||
{
|
|
||||||
protected:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
AlResource();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Destructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
~AlResource();
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_ALRESOURCE_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::AlResource
|
|
||||||
/// \ingroup audio
|
|
||||||
///
|
|
||||||
/// This class is for internal use only, it must be the base
|
|
||||||
/// of every class that requires a valid OpenAL context in
|
|
||||||
/// order to work.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,48 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_AUDIO_EXPORT_HPP
|
|
||||||
#define SFML_AUDIO_EXPORT_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Config.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Define portable import / export macros
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#if defined(SFML_AUDIO_EXPORTS)
|
|
||||||
|
|
||||||
#define SFML_AUDIO_API SFML_API_EXPORT
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
#define SFML_AUDIO_API SFML_API_IMPORT
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_AUDIO_EXPORT_HPP
|
|
@ -1,250 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_INPUTSOUNDFILE_HPP
|
|
||||||
#define SFML_INPUTSOUNDFILE_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Audio/Export.hpp>
|
|
||||||
#include <SFML/System/NonCopyable.hpp>
|
|
||||||
#include <SFML/System/Time.hpp>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
class InputStream;
|
|
||||||
class SoundFileReader;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Provide read access to sound files
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_AUDIO_API InputSoundFile : NonCopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
InputSoundFile();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Destructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
~InputSoundFile();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Open a sound file from the disk for reading
|
|
||||||
///
|
|
||||||
/// The supported audio formats are: WAV, OGG/Vorbis, FLAC.
|
|
||||||
///
|
|
||||||
/// \param filename Path of the sound file to load
|
|
||||||
///
|
|
||||||
/// \return True if the file was successfully opened
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool openFromFile(const std::string& filename);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Open a sound file in memory for reading
|
|
||||||
///
|
|
||||||
/// The supported audio formats are: WAV, OGG/Vorbis, FLAC.
|
|
||||||
///
|
|
||||||
/// \param data Pointer to the file data in memory
|
|
||||||
/// \param sizeInBytes Size of the data to load, in bytes
|
|
||||||
///
|
|
||||||
/// \return True if the file was successfully opened
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool openFromMemory(const void* data, std::size_t sizeInBytes);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Open a sound file from a custom stream for reading
|
|
||||||
///
|
|
||||||
/// The supported audio formats are: WAV, OGG/Vorbis, FLAC.
|
|
||||||
///
|
|
||||||
/// \param stream Source stream to read from
|
|
||||||
///
|
|
||||||
/// \return True if the file was successfully opened
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool openFromStream(InputStream& stream);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Open the sound file from the disk for writing
|
|
||||||
///
|
|
||||||
/// \param filename Path of the sound file to write
|
|
||||||
/// \param channelCount Number of channels in the sound
|
|
||||||
/// \param sampleRate Sample rate of the sound
|
|
||||||
///
|
|
||||||
/// \return True if the file was successfully opened
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool openForWriting(const std::string& filename, unsigned int channelCount, unsigned int sampleRate);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the total number of audio samples in the file
|
|
||||||
///
|
|
||||||
/// \return Number of samples
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Uint64 getSampleCount() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the number of channels used by the sound
|
|
||||||
///
|
|
||||||
/// \return Number of channels (1 = mono, 2 = stereo)
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
unsigned int getChannelCount() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the sample rate of the sound
|
|
||||||
///
|
|
||||||
/// \return Sample rate, in samples per second
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
unsigned int getSampleRate() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the total duration of the sound file
|
|
||||||
///
|
|
||||||
/// This function is provided for convenience, the duration is
|
|
||||||
/// deduced from the other sound file attributes.
|
|
||||||
///
|
|
||||||
/// \return Duration of the sound file
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Time getDuration() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Change the current read position to the given sample offset
|
|
||||||
///
|
|
||||||
/// This function takes a sample offset to provide maximum
|
|
||||||
/// precision. If you need to jump to a given time, use the
|
|
||||||
/// other overload.
|
|
||||||
///
|
|
||||||
/// If the given offset exceeds to total number of samples,
|
|
||||||
/// this function jumps to the end of the sound file.
|
|
||||||
///
|
|
||||||
/// \param sampleOffset Index of the sample to jump to, relative to the beginning
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void seek(Uint64 sampleOffset);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Change the current read position to the given time offset
|
|
||||||
///
|
|
||||||
/// Using a time offset is handy but imprecise. If you need an accurate
|
|
||||||
/// result, consider using the overload which takes a sample offset.
|
|
||||||
///
|
|
||||||
/// If the given time exceeds to total duration, this function jumps
|
|
||||||
/// to the end of the sound file.
|
|
||||||
///
|
|
||||||
/// \param timeOffset Time to jump to, relative to the beginning
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void seek(Time timeOffset);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Read audio samples from the open file
|
|
||||||
///
|
|
||||||
/// \param samples Pointer to the sample array to fill
|
|
||||||
/// \param maxCount Maximum number of samples to read
|
|
||||||
///
|
|
||||||
/// \return Number of samples actually read (may be less than \a maxCount)
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Uint64 read(Int16* samples, Uint64 maxCount);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Close the current file
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void close();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SoundFileReader* m_reader; ///< Reader that handles I/O on the file's format
|
|
||||||
InputStream* m_stream; ///< Input stream used to access the file's data
|
|
||||||
bool m_streamOwned; ///< Is the stream internal or external?
|
|
||||||
Uint64 m_sampleCount; ///< Total number of samples in the file
|
|
||||||
unsigned int m_channelCount; ///< Number of channels of the sound
|
|
||||||
unsigned int m_sampleRate; ///< Number of samples per second
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_INPUTSOUNDFILE_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::InputSoundFile
|
|
||||||
/// \ingroup audio
|
|
||||||
///
|
|
||||||
/// This class decodes audio samples from a sound file. It is
|
|
||||||
/// used internally by higher-level classes such as sf::SoundBuffer
|
|
||||||
/// and sf::Music, but can also be useful if you want to process
|
|
||||||
/// or analyze audio files without playing them, or if you want to
|
|
||||||
/// implement your own version of sf::Music with more specific
|
|
||||||
/// features.
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// // Open a sound file
|
|
||||||
/// sf::InputSoundFile file;
|
|
||||||
/// if (!file.openFromFile("music.ogg"))
|
|
||||||
/// /* error */;
|
|
||||||
///
|
|
||||||
/// // Print the sound attributes
|
|
||||||
/// std::cout << "duration: " << file.getDuration().asSeconds() << std::endl;
|
|
||||||
/// std::cout << "channels: " << file.getChannelCount() << std::endl;
|
|
||||||
/// std::cout << "sample rate: " << file.getSampleRate() << std::endl;
|
|
||||||
/// std::cout << "sample count: " << file.getSampleCount() << std::endl;
|
|
||||||
///
|
|
||||||
/// // Read and process batches of samples until the end of file is reached
|
|
||||||
/// sf::Int16 samples[1024];
|
|
||||||
/// sf::Uint64 count;
|
|
||||||
/// do
|
|
||||||
/// {
|
|
||||||
/// count = file.read(samples, 1024);
|
|
||||||
///
|
|
||||||
/// // process, analyze, play, convert, or whatever
|
|
||||||
/// // you want to do with the samples...
|
|
||||||
/// }
|
|
||||||
/// while (count > 0);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \see sf::SoundFileReader, sf::OutputSoundFile
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,234 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_LISTENER_HPP
|
|
||||||
#define SFML_LISTENER_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Audio/Export.hpp>
|
|
||||||
#include <SFML/System/Vector3.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief The audio listener is the point in the scene
|
|
||||||
/// from where all the sounds are heard
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_AUDIO_API Listener
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Change the global volume of all the sounds and musics
|
|
||||||
///
|
|
||||||
/// The volume is a number between 0 and 100; it is combined with
|
|
||||||
/// the individual volume of each sound / music.
|
|
||||||
/// The default value for the volume is 100 (maximum).
|
|
||||||
///
|
|
||||||
/// \param volume New global volume, in the range [0, 100]
|
|
||||||
///
|
|
||||||
/// \see getGlobalVolume
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static void setGlobalVolume(float volume);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the current value of the global volume
|
|
||||||
///
|
|
||||||
/// \return Current global volume, in the range [0, 100]
|
|
||||||
///
|
|
||||||
/// \see setGlobalVolume
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static float getGlobalVolume();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the position of the listener in the scene
|
|
||||||
///
|
|
||||||
/// The default listener's position is (0, 0, 0).
|
|
||||||
///
|
|
||||||
/// \param x X coordinate of the listener's position
|
|
||||||
/// \param y Y coordinate of the listener's position
|
|
||||||
/// \param z Z coordinate of the listener's position
|
|
||||||
///
|
|
||||||
/// \see getPosition, setDirection
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static void setPosition(float x, float y, float z);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the position of the listener in the scene
|
|
||||||
///
|
|
||||||
/// The default listener's position is (0, 0, 0).
|
|
||||||
///
|
|
||||||
/// \param position New listener's position
|
|
||||||
///
|
|
||||||
/// \see getPosition, setDirection
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static void setPosition(const Vector3f& position);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the current position of the listener in the scene
|
|
||||||
///
|
|
||||||
/// \return Listener's position
|
|
||||||
///
|
|
||||||
/// \see setPosition
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static Vector3f getPosition();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the forward vector of the listener in the scene
|
|
||||||
///
|
|
||||||
/// The direction (also called "at vector") is the vector
|
|
||||||
/// pointing forward from the listener's perspective. Together
|
|
||||||
/// with the up vector, it defines the 3D orientation of the
|
|
||||||
/// listener in the scene. The direction vector doesn't
|
|
||||||
/// have to be normalized.
|
|
||||||
/// The default listener's direction is (0, 0, -1).
|
|
||||||
///
|
|
||||||
/// \param x X coordinate of the listener's direction
|
|
||||||
/// \param y Y coordinate of the listener's direction
|
|
||||||
/// \param z Z coordinate of the listener's direction
|
|
||||||
///
|
|
||||||
/// \see getDirection, setUpVector, setPosition
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static void setDirection(float x, float y, float z);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the forward vector of the listener in the scene
|
|
||||||
///
|
|
||||||
/// The direction (also called "at vector") is the vector
|
|
||||||
/// pointing forward from the listener's perspective. Together
|
|
||||||
/// with the up vector, it defines the 3D orientation of the
|
|
||||||
/// listener in the scene. The direction vector doesn't
|
|
||||||
/// have to be normalized.
|
|
||||||
/// The default listener's direction is (0, 0, -1).
|
|
||||||
///
|
|
||||||
/// \param direction New listener's direction
|
|
||||||
///
|
|
||||||
/// \see getDirection, setUpVector, setPosition
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static void setDirection(const Vector3f& direction);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the current forward vector of the listener in the scene
|
|
||||||
///
|
|
||||||
/// \return Listener's forward vector (not normalized)
|
|
||||||
///
|
|
||||||
/// \see setDirection
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static Vector3f getDirection();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the upward vector of the listener in the scene
|
|
||||||
///
|
|
||||||
/// The up vector is the vector that points upward from the
|
|
||||||
/// listener's perspective. Together with the direction, it
|
|
||||||
/// defines the 3D orientation of the listener in the scene.
|
|
||||||
/// The up vector doesn't have to be normalized.
|
|
||||||
/// The default listener's up vector is (0, 1, 0). It is usually
|
|
||||||
/// not necessary to change it, especially in 2D scenarios.
|
|
||||||
///
|
|
||||||
/// \param x X coordinate of the listener's up vector
|
|
||||||
/// \param y Y coordinate of the listener's up vector
|
|
||||||
/// \param z Z coordinate of the listener's up vector
|
|
||||||
///
|
|
||||||
/// \see getUpVector, setDirection, setPosition
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static void setUpVector(float x, float y, float z);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the upward vector of the listener in the scene
|
|
||||||
///
|
|
||||||
/// The up vector is the vector that points upward from the
|
|
||||||
/// listener's perspective. Together with the direction, it
|
|
||||||
/// defines the 3D orientation of the listener in the scene.
|
|
||||||
/// The up vector doesn't have to be normalized.
|
|
||||||
/// The default listener's up vector is (0, 1, 0). It is usually
|
|
||||||
/// not necessary to change it, especially in 2D scenarios.
|
|
||||||
///
|
|
||||||
/// \param upVector New listener's up vector
|
|
||||||
///
|
|
||||||
/// \see getUpVector, setDirection, setPosition
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static void setUpVector(const Vector3f& upVector);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the current upward vector of the listener in the scene
|
|
||||||
///
|
|
||||||
/// \return Listener's upward vector (not normalized)
|
|
||||||
///
|
|
||||||
/// \see setUpVector
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static Vector3f getUpVector();
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_LISTENER_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::Listener
|
|
||||||
/// \ingroup audio
|
|
||||||
///
|
|
||||||
/// The audio listener defines the global properties of the
|
|
||||||
/// audio environment, it defines where and how sounds and musics
|
|
||||||
/// are heard. If sf::View is the eyes of the user, then sf::Listener
|
|
||||||
/// is his ears (by the way, they are often linked together --
|
|
||||||
/// same position, orientation, etc.).
|
|
||||||
///
|
|
||||||
/// sf::Listener is a simple interface, which allows to setup the
|
|
||||||
/// listener in the 3D audio environment (position, direction and
|
|
||||||
/// up vector), and to adjust the global volume.
|
|
||||||
///
|
|
||||||
/// Because the listener is unique in the scene, sf::Listener only
|
|
||||||
/// contains static functions and doesn't have to be instantiated.
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// // Move the listener to the position (1, 0, -5)
|
|
||||||
/// sf::Listener::setPosition(1, 0, -5);
|
|
||||||
///
|
|
||||||
/// // Make it face the right axis (1, 0, 0)
|
|
||||||
/// sf::Listener::setDirection(1, 0, 0);
|
|
||||||
///
|
|
||||||
/// // Reduce the global volume
|
|
||||||
/// sf::Listener::setGlobalVolume(50);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,229 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_MUSIC_HPP
|
|
||||||
#define SFML_MUSIC_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Audio/Export.hpp>
|
|
||||||
#include <SFML/Audio/SoundStream.hpp>
|
|
||||||
#include <SFML/Audio/InputSoundFile.hpp>
|
|
||||||
#include <SFML/System/Mutex.hpp>
|
|
||||||
#include <SFML/System/Time.hpp>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
class InputStream;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Streamed music played from an audio file
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_AUDIO_API Music : public SoundStream
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Music();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Destructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
~Music();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Open a music from an audio file
|
|
||||||
///
|
|
||||||
/// This function doesn't start playing the music (call play()
|
|
||||||
/// to do so).
|
|
||||||
/// See the documentation of sf::InputSoundFile for the list
|
|
||||||
/// of supported formats.
|
|
||||||
///
|
|
||||||
/// \warning Since the music is not loaded at once but rather
|
|
||||||
/// streamed continuously, the file must remain accessible until
|
|
||||||
/// the sf::Music object loads a new music or is destroyed.
|
|
||||||
///
|
|
||||||
/// \param filename Path of the music file to open
|
|
||||||
///
|
|
||||||
/// \return True if loading succeeded, false if it failed
|
|
||||||
///
|
|
||||||
/// \see openFromMemory, openFromStream
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool openFromFile(const std::string& filename);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Open a music from an audio file in memory
|
|
||||||
///
|
|
||||||
/// This function doesn't start playing the music (call play()
|
|
||||||
/// to do so).
|
|
||||||
/// See the documentation of sf::InputSoundFile for the list
|
|
||||||
/// of supported formats.
|
|
||||||
///
|
|
||||||
/// \warning Since the music is not loaded at once but rather streamed
|
|
||||||
/// continuously, the \a data buffer must remain accessible until
|
|
||||||
/// the sf::Music object loads a new music or is destroyed. That is,
|
|
||||||
/// you can't deallocate the buffer right after calling this function.
|
|
||||||
///
|
|
||||||
/// \param data Pointer to the file data in memory
|
|
||||||
/// \param sizeInBytes Size of the data to load, in bytes
|
|
||||||
///
|
|
||||||
/// \return True if loading succeeded, false if it failed
|
|
||||||
///
|
|
||||||
/// \see openFromFile, openFromStream
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool openFromMemory(const void* data, std::size_t sizeInBytes);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Open a music from an audio file in a custom stream
|
|
||||||
///
|
|
||||||
/// This function doesn't start playing the music (call play()
|
|
||||||
/// to do so).
|
|
||||||
/// See the documentation of sf::InputSoundFile for the list
|
|
||||||
/// of supported formats.
|
|
||||||
///
|
|
||||||
/// \warning Since the music is not loaded at once but rather
|
|
||||||
/// streamed continuously, the \a stream must remain accessible
|
|
||||||
/// until the sf::Music object loads a new music or is destroyed.
|
|
||||||
///
|
|
||||||
/// \param stream Source stream to read from
|
|
||||||
///
|
|
||||||
/// \return True if loading succeeded, false if it failed
|
|
||||||
///
|
|
||||||
/// \see openFromFile, openFromMemory
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool openFromStream(InputStream& stream);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the total duration of the music
|
|
||||||
///
|
|
||||||
/// \return Music duration
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Time getDuration() const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Request a new chunk of audio samples from the stream source
|
|
||||||
///
|
|
||||||
/// This function fills the chunk from the next samples
|
|
||||||
/// to read from the audio file.
|
|
||||||
///
|
|
||||||
/// \param data Chunk of data to fill
|
|
||||||
///
|
|
||||||
/// \return True to continue playback, false to stop
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual bool onGetData(Chunk& data);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Change the current playing position in the stream source
|
|
||||||
///
|
|
||||||
/// \param timeOffset New playing position, from the beginning of the music
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual void onSeek(Time timeOffset);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Initialize the internal state after loading a new music
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void initialize();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
InputSoundFile m_file; ///< The streamed music file
|
|
||||||
Time m_duration; ///< Music duration
|
|
||||||
std::vector<Int16> m_samples; ///< Temporary buffer of samples
|
|
||||||
Mutex m_mutex; ///< Mutex protecting the data
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_MUSIC_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::Music
|
|
||||||
/// \ingroup audio
|
|
||||||
///
|
|
||||||
/// Musics are sounds that are streamed rather than completely
|
|
||||||
/// loaded in memory. This is especially useful for compressed
|
|
||||||
/// musics that usually take hundreds of MB when they are
|
|
||||||
/// uncompressed: by streaming it instead of loading it entirely,
|
|
||||||
/// you avoid saturating the memory and have almost no loading delay.
|
|
||||||
/// This implies that the underlying resource (file, stream or
|
|
||||||
/// memory buffer) must remain valid for the lifetime of the
|
|
||||||
/// sf::Music object.
|
|
||||||
///
|
|
||||||
/// Apart from that, a sf::Music has almost the same features as
|
|
||||||
/// the sf::SoundBuffer / sf::Sound pair: you can play/pause/stop
|
|
||||||
/// it, request its parameters (channels, sample rate), change
|
|
||||||
/// the way it is played (pitch, volume, 3D position, ...), etc.
|
|
||||||
///
|
|
||||||
/// As a sound stream, a music is played in its own thread in order
|
|
||||||
/// not to block the rest of the program. This means that you can
|
|
||||||
/// leave the music alone after calling play(), it will manage itself
|
|
||||||
/// very well.
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// // Declare a new music
|
|
||||||
/// sf::Music music;
|
|
||||||
///
|
|
||||||
/// // Open it from an audio file
|
|
||||||
/// if (!music.openFromFile("music.ogg"))
|
|
||||||
/// {
|
|
||||||
/// // error...
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// // Change some parameters
|
|
||||||
/// music.setPosition(0, 1, 10); // change its 3D position
|
|
||||||
/// music.setPitch(2); // increase the pitch
|
|
||||||
/// music.setVolume(50); // reduce the volume
|
|
||||||
/// music.setLoop(true); // make it loop
|
|
||||||
///
|
|
||||||
/// // Play it
|
|
||||||
/// music.play();
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \see sf::Sound, sf::SoundStream
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,133 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_OUTPUTSOUNDFILE_HPP
|
|
||||||
#define SFML_OUTPUTSOUNDFILE_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Audio/Export.hpp>
|
|
||||||
#include <SFML/System/NonCopyable.hpp>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
class SoundFileWriter;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Provide write access to sound files
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_AUDIO_API OutputSoundFile : NonCopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
OutputSoundFile();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Destructor
|
|
||||||
///
|
|
||||||
/// Closes the file if it was still open.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
~OutputSoundFile();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Open the sound file from the disk for writing
|
|
||||||
///
|
|
||||||
/// The supported audio formats are: WAV, OGG/Vorbis, FLAC.
|
|
||||||
///
|
|
||||||
/// \param filename Path of the sound file to write
|
|
||||||
/// \param sampleRate Sample rate of the sound
|
|
||||||
/// \param channelCount Number of channels in the sound
|
|
||||||
///
|
|
||||||
/// \return True if the file was successfully opened
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool openFromFile(const std::string& filename, unsigned int sampleRate, unsigned int channelCount);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Write audio samples to the file
|
|
||||||
///
|
|
||||||
/// \param samples Pointer to the sample array to write
|
|
||||||
/// \param count Number of samples to write
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void write(const Int16* samples, Uint64 count);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Close the current file
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void close();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SoundFileWriter* m_writer; ///< Writer that handles I/O on the file's format
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_OUTPUTSOUNDFILE_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::OutputSoundFile
|
|
||||||
/// \ingroup audio
|
|
||||||
///
|
|
||||||
/// This class encodes audio samples to a sound file. It is
|
|
||||||
/// used internally by higher-level classes such as sf::SoundBuffer,
|
|
||||||
/// but can also be useful if you want to create audio files from
|
|
||||||
/// custom data sources, like generated audio samples.
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// // Create a sound file, ogg/vorbis format, 44100 Hz, stereo
|
|
||||||
/// sf::OutputSoundFile file;
|
|
||||||
/// if (!file.openFromFile("music.ogg", 44100, 2))
|
|
||||||
/// /* error */;
|
|
||||||
///
|
|
||||||
/// while (...)
|
|
||||||
/// {
|
|
||||||
/// // Read or generate audio samples from your custom source
|
|
||||||
/// std::vector<sf::Int16> samples = ...;
|
|
||||||
///
|
|
||||||
/// // Write them to the file
|
|
||||||
/// file.write(samples.data(), samples.size());
|
|
||||||
/// }
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \see sf::SoundFileWriter, sf::InputSoundFile
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,264 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_SOUND_HPP
|
|
||||||
#define SFML_SOUND_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Audio/Export.hpp>
|
|
||||||
#include <SFML/Audio/SoundSource.hpp>
|
|
||||||
#include <SFML/System/Time.hpp>
|
|
||||||
#include <cstdlib>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
class SoundBuffer;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Regular sound that can be played in the audio environment
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_AUDIO_API Sound : public SoundSource
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Sound();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Construct the sound with a buffer
|
|
||||||
///
|
|
||||||
/// \param buffer Sound buffer containing the audio data to play with the sound
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
explicit Sound(const SoundBuffer& buffer);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Copy constructor
|
|
||||||
///
|
|
||||||
/// \param copy Instance to copy
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Sound(const Sound& copy);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Destructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
~Sound();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Start or resume playing the sound
|
|
||||||
///
|
|
||||||
/// This function starts the stream if it was stopped, resumes
|
|
||||||
/// it if it was paused, and restarts it from beginning if it
|
|
||||||
/// was it already playing.
|
|
||||||
/// This function uses its own thread so that it doesn't block
|
|
||||||
/// the rest of the program while the sound is played.
|
|
||||||
///
|
|
||||||
/// \see pause, stop
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void play();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Pause the sound
|
|
||||||
///
|
|
||||||
/// This function pauses the sound if it was playing,
|
|
||||||
/// otherwise (sound already paused or stopped) it has no effect.
|
|
||||||
///
|
|
||||||
/// \see play, stop
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void pause();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief stop playing the sound
|
|
||||||
///
|
|
||||||
/// This function stops the sound if it was playing or paused,
|
|
||||||
/// and does nothing if it was already stopped.
|
|
||||||
/// It also resets the playing position (unlike pause()).
|
|
||||||
///
|
|
||||||
/// \see play, pause
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void stop();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the source buffer containing the audio data to play
|
|
||||||
///
|
|
||||||
/// It is important to note that the sound buffer is not copied,
|
|
||||||
/// thus the sf::SoundBuffer instance must remain alive as long
|
|
||||||
/// as it is attached to the sound.
|
|
||||||
///
|
|
||||||
/// \param buffer Sound buffer to attach to the sound
|
|
||||||
///
|
|
||||||
/// \see getBuffer
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setBuffer(const SoundBuffer& buffer);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set whether or not the sound should loop after reaching the end
|
|
||||||
///
|
|
||||||
/// If set, the sound will restart from beginning after
|
|
||||||
/// reaching the end and so on, until it is stopped or
|
|
||||||
/// setLoop(false) is called.
|
|
||||||
/// The default looping state for sound is false.
|
|
||||||
///
|
|
||||||
/// \param loop True to play in loop, false to play once
|
|
||||||
///
|
|
||||||
/// \see getLoop
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setLoop(bool loop);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Change the current playing position of the sound
|
|
||||||
///
|
|
||||||
/// The playing position can be changed when the sound is
|
|
||||||
/// either paused or playing. Changing the playing position
|
|
||||||
/// when the sound is stopped has no effect, since playing
|
|
||||||
/// the sound will reset its position.
|
|
||||||
///
|
|
||||||
/// \param timeOffset New playing position, from the beginning of the sound
|
|
||||||
///
|
|
||||||
/// \see getPlayingOffset
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setPlayingOffset(Time timeOffset);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the audio buffer attached to the sound
|
|
||||||
///
|
|
||||||
/// \return Sound buffer attached to the sound (can be NULL)
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const SoundBuffer* getBuffer() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Tell whether or not the sound is in loop mode
|
|
||||||
///
|
|
||||||
/// \return True if the sound is looping, false otherwise
|
|
||||||
///
|
|
||||||
/// \see setLoop
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool getLoop() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the current playing position of the sound
|
|
||||||
///
|
|
||||||
/// \return Current playing position, from the beginning of the sound
|
|
||||||
///
|
|
||||||
/// \see setPlayingOffset
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Time getPlayingOffset() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the current status of the sound (stopped, paused, playing)
|
|
||||||
///
|
|
||||||
/// \return Current status of the sound
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Status getStatus() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Overload of assignment operator
|
|
||||||
///
|
|
||||||
/// \param right Instance to assign
|
|
||||||
///
|
|
||||||
/// \return Reference to self
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Sound& operator =(const Sound& right);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Reset the internal buffer of the sound
|
|
||||||
///
|
|
||||||
/// This function is for internal use only, you don't have
|
|
||||||
/// to use it. It is called by the sf::SoundBuffer that
|
|
||||||
/// this sound uses, when it is destroyed in order to prevent
|
|
||||||
/// the sound from using a dead buffer.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void resetBuffer();
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const SoundBuffer* m_buffer; ///< Sound buffer bound to the source
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_SOUND_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::Sound
|
|
||||||
/// \ingroup audio
|
|
||||||
///
|
|
||||||
/// sf::Sound is the class to use to play sounds.
|
|
||||||
/// It provides:
|
|
||||||
/// \li Control (play, pause, stop)
|
|
||||||
/// \li Ability to modify output parameters in real-time (pitch, volume, ...)
|
|
||||||
/// \li 3D spatial features (position, attenuation, ...).
|
|
||||||
///
|
|
||||||
/// sf::Sound is perfect for playing short sounds that can
|
|
||||||
/// fit in memory and require no latency, like foot steps or
|
|
||||||
/// gun shots. For longer sounds, like background musics
|
|
||||||
/// or long speeches, rather see sf::Music (which is based
|
|
||||||
/// on streaming).
|
|
||||||
///
|
|
||||||
/// In order to work, a sound must be given a buffer of audio
|
|
||||||
/// data to play. Audio data (samples) is stored in sf::SoundBuffer,
|
|
||||||
/// and attached to a sound with the setBuffer() function.
|
|
||||||
/// The buffer object attached to a sound must remain alive
|
|
||||||
/// as long as the sound uses it. Note that multiple sounds
|
|
||||||
/// can use the same sound buffer at the same time.
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// sf::SoundBuffer buffer;
|
|
||||||
/// buffer.loadFromFile("sound.wav");
|
|
||||||
///
|
|
||||||
/// sf::Sound sound;
|
|
||||||
/// sound.setBuffer(buffer);
|
|
||||||
/// sound.play();
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \see sf::SoundBuffer, sf::Music
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,352 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_SOUNDBUFFER_HPP
|
|
||||||
#define SFML_SOUNDBUFFER_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Audio/Export.hpp>
|
|
||||||
#include <SFML/Audio/AlResource.hpp>
|
|
||||||
#include <SFML/System/Time.hpp>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include <set>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
class Sound;
|
|
||||||
class InputSoundFile;
|
|
||||||
class InputStream;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Storage for audio samples defining a sound
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_AUDIO_API SoundBuffer : AlResource
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SoundBuffer();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Copy constructor
|
|
||||||
///
|
|
||||||
/// \param copy Instance to copy
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SoundBuffer(const SoundBuffer& copy);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Destructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
~SoundBuffer();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Load the sound buffer from a file
|
|
||||||
///
|
|
||||||
/// See the documentation of sf::InputSoundFile for the list
|
|
||||||
/// of supported formats.
|
|
||||||
///
|
|
||||||
/// \param filename Path of the sound file to load
|
|
||||||
///
|
|
||||||
/// \return True if loading succeeded, false if it failed
|
|
||||||
///
|
|
||||||
/// \see loadFromMemory, loadFromStream, loadFromSamples, saveToFile
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool loadFromFile(const std::string& filename);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Load the sound buffer from a file in memory
|
|
||||||
///
|
|
||||||
/// See the documentation of sf::InputSoundFile for the list
|
|
||||||
/// of supported formats.
|
|
||||||
///
|
|
||||||
/// \param data Pointer to the file data in memory
|
|
||||||
/// \param sizeInBytes Size of the data to load, in bytes
|
|
||||||
///
|
|
||||||
/// \return True if loading succeeded, false if it failed
|
|
||||||
///
|
|
||||||
/// \see loadFromFile, loadFromStream, loadFromSamples
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool loadFromMemory(const void* data, std::size_t sizeInBytes);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Load the sound buffer from a custom stream
|
|
||||||
///
|
|
||||||
/// See the documentation of sf::InputSoundFile for the list
|
|
||||||
/// of supported formats.
|
|
||||||
///
|
|
||||||
/// \param stream Source stream to read from
|
|
||||||
///
|
|
||||||
/// \return True if loading succeeded, false if it failed
|
|
||||||
///
|
|
||||||
/// \see loadFromFile, loadFromMemory, loadFromSamples
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool loadFromStream(InputStream& stream);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Load the sound buffer from an array of audio samples
|
|
||||||
///
|
|
||||||
/// The assumed format of the audio samples is 16 bits signed integer
|
|
||||||
/// (sf::Int16).
|
|
||||||
///
|
|
||||||
/// \param samples Pointer to the array of samples in memory
|
|
||||||
/// \param sampleCount Number of samples in the array
|
|
||||||
/// \param channelCount Number of channels (1 = mono, 2 = stereo, ...)
|
|
||||||
/// \param sampleRate Sample rate (number of samples to play per second)
|
|
||||||
///
|
|
||||||
/// \return True if loading succeeded, false if it failed
|
|
||||||
///
|
|
||||||
/// \see loadFromFile, loadFromMemory, saveToFile
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool loadFromSamples(const Int16* samples, Uint64 sampleCount, unsigned int channelCount, unsigned int sampleRate);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Save the sound buffer to an audio file
|
|
||||||
///
|
|
||||||
/// See the documentation of sf::OutputSoundFile for the list
|
|
||||||
/// of supported formats.
|
|
||||||
///
|
|
||||||
/// \param filename Path of the sound file to write
|
|
||||||
///
|
|
||||||
/// \return True if saving succeeded, false if it failed
|
|
||||||
///
|
|
||||||
/// \see loadFromFile, loadFromMemory, loadFromSamples
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool saveToFile(const std::string& filename) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the array of audio samples stored in the buffer
|
|
||||||
///
|
|
||||||
/// The format of the returned samples is 16 bits signed integer
|
|
||||||
/// (sf::Int16). The total number of samples in this array
|
|
||||||
/// is given by the getSampleCount() function.
|
|
||||||
///
|
|
||||||
/// \return Read-only pointer to the array of sound samples
|
|
||||||
///
|
|
||||||
/// \see getSampleCount
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const Int16* getSamples() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the number of samples stored in the buffer
|
|
||||||
///
|
|
||||||
/// The array of samples can be accessed with the getSamples()
|
|
||||||
/// function.
|
|
||||||
///
|
|
||||||
/// \return Number of samples
|
|
||||||
///
|
|
||||||
/// \see getSamples
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Uint64 getSampleCount() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the sample rate of the sound
|
|
||||||
///
|
|
||||||
/// The sample rate is the number of samples played per second.
|
|
||||||
/// The higher, the better the quality (for example, 44100
|
|
||||||
/// samples/s is CD quality).
|
|
||||||
///
|
|
||||||
/// \return Sample rate (number of samples per second)
|
|
||||||
///
|
|
||||||
/// \see getChannelCount, getDuration
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
unsigned int getSampleRate() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the number of channels used by the sound
|
|
||||||
///
|
|
||||||
/// If the sound is mono then the number of channels will
|
|
||||||
/// be 1, 2 for stereo, etc.
|
|
||||||
///
|
|
||||||
/// \return Number of channels
|
|
||||||
///
|
|
||||||
/// \see getSampleRate, getDuration
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
unsigned int getChannelCount() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the total duration of the sound
|
|
||||||
///
|
|
||||||
/// \return Sound duration
|
|
||||||
///
|
|
||||||
/// \see getSampleRate, getChannelCount
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Time getDuration() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Overload of assignment operator
|
|
||||||
///
|
|
||||||
/// \param right Instance to assign
|
|
||||||
///
|
|
||||||
/// \return Reference to self
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SoundBuffer& operator =(const SoundBuffer& right);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
friend class Sound;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Initialize the internal state after loading a new sound
|
|
||||||
///
|
|
||||||
/// \param file Sound file providing access to the new loaded sound
|
|
||||||
///
|
|
||||||
/// \return True on successful initialization, false on failure
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool initialize(InputSoundFile& file);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Update the internal buffer with the cached audio samples
|
|
||||||
///
|
|
||||||
/// \param channelCount Number of channels
|
|
||||||
/// \param sampleRate Sample rate (number of samples per second)
|
|
||||||
///
|
|
||||||
/// \return True on success, false if any error happened
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool update(unsigned int channelCount, unsigned int sampleRate);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Add a sound to the list of sounds that use this buffer
|
|
||||||
///
|
|
||||||
/// \param sound Sound instance to attach
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void attachSound(Sound* sound) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Remove a sound from the list of sounds that use this buffer
|
|
||||||
///
|
|
||||||
/// \param sound Sound instance to detach
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void detachSound(Sound* sound) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Types
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
typedef std::set<Sound*> SoundList; ///< Set of unique sound instances
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
unsigned int m_buffer; ///< OpenAL buffer identifier
|
|
||||||
std::vector<Int16> m_samples; ///< Samples buffer
|
|
||||||
Time m_duration; ///< Sound duration
|
|
||||||
mutable SoundList m_sounds; ///< List of sounds that are using this buffer
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_SOUNDBUFFER_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::SoundBuffer
|
|
||||||
/// \ingroup audio
|
|
||||||
///
|
|
||||||
/// A sound buffer holds the data of a sound, which is
|
|
||||||
/// an array of audio samples. A sample is a 16 bits signed integer
|
|
||||||
/// that defines the amplitude of the sound at a given time.
|
|
||||||
/// The sound is then reconstituted by playing these samples at
|
|
||||||
/// a high rate (for example, 44100 samples per second is the
|
|
||||||
/// standard rate used for playing CDs). In short, audio samples
|
|
||||||
/// are like texture pixels, and a sf::SoundBuffer is similar to
|
|
||||||
/// a sf::Texture.
|
|
||||||
///
|
|
||||||
/// A sound buffer can be loaded from a file (see loadFromFile()
|
|
||||||
/// for the complete list of supported formats), from memory, from
|
|
||||||
/// a custom stream (see sf::InputStream) or directly from an array
|
|
||||||
/// of samples. It can also be saved back to a file.
|
|
||||||
///
|
|
||||||
/// Sound buffers alone are not very useful: they hold the audio data
|
|
||||||
/// but cannot be played. To do so, you need to use the sf::Sound class,
|
|
||||||
/// which provides functions to play/pause/stop the sound as well as
|
|
||||||
/// changing the way it is outputted (volume, pitch, 3D position, ...).
|
|
||||||
/// This separation allows more flexibility and better performances:
|
|
||||||
/// indeed a sf::SoundBuffer is a heavy resource, and any operation on it
|
|
||||||
/// is slow (often too slow for real-time applications). On the other
|
|
||||||
/// side, a sf::Sound is a lightweight object, which can use the audio data
|
|
||||||
/// of a sound buffer and change the way it is played without actually
|
|
||||||
/// modifying that data. Note that it is also possible to bind
|
|
||||||
/// several sf::Sound instances to the same sf::SoundBuffer.
|
|
||||||
///
|
|
||||||
/// It is important to note that the sf::Sound instance doesn't
|
|
||||||
/// copy the buffer that it uses, it only keeps a reference to it.
|
|
||||||
/// Thus, a sf::SoundBuffer must not be destructed while it is
|
|
||||||
/// used by a sf::Sound (i.e. never write a function that
|
|
||||||
/// uses a local sf::SoundBuffer instance for loading a sound).
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// // Declare a new sound buffer
|
|
||||||
/// sf::SoundBuffer buffer;
|
|
||||||
///
|
|
||||||
/// // Load it from a file
|
|
||||||
/// if (!buffer.loadFromFile("sound.wav"))
|
|
||||||
/// {
|
|
||||||
/// // error...
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// // Create a sound source and bind it to the buffer
|
|
||||||
/// sf::Sound sound1;
|
|
||||||
/// sound1.setBuffer(buffer);
|
|
||||||
///
|
|
||||||
/// // Play the sound
|
|
||||||
/// sound1.play();
|
|
||||||
///
|
|
||||||
/// // Create another sound source bound to the same buffer
|
|
||||||
/// sf::Sound sound2;
|
|
||||||
/// sound2.setBuffer(buffer);
|
|
||||||
///
|
|
||||||
/// // Play it with a higher pitch -- the first sound remains unchanged
|
|
||||||
/// sound2.setPitch(2);
|
|
||||||
/// sound2.play();
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \see sf::Sound, sf::SoundBufferRecorder
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,138 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_SOUNDBUFFERRECORDER_HPP
|
|
||||||
#define SFML_SOUNDBUFFERRECORDER_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Audio/Export.hpp>
|
|
||||||
#include <SFML/Audio/SoundBuffer.hpp>
|
|
||||||
#include <SFML/Audio/SoundRecorder.hpp>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Specialized SoundRecorder which stores the captured
|
|
||||||
/// audio data into a sound buffer
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_AUDIO_API SoundBufferRecorder : public SoundRecorder
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the sound buffer containing the captured audio data
|
|
||||||
///
|
|
||||||
/// The sound buffer is valid only after the capture has ended.
|
|
||||||
/// This function provides a read-only access to the internal
|
|
||||||
/// sound buffer, but it can be copied if you need to
|
|
||||||
/// make any modification to it.
|
|
||||||
///
|
|
||||||
/// \return Read-only access to the sound buffer
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const SoundBuffer& getBuffer() const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Start capturing audio data
|
|
||||||
///
|
|
||||||
/// \return True to start the capture, or false to abort it
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual bool onStart();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Process a new chunk of recorded samples
|
|
||||||
///
|
|
||||||
/// \param samples Pointer to the new chunk of recorded samples
|
|
||||||
/// \param sampleCount Number of samples pointed by \a samples
|
|
||||||
///
|
|
||||||
/// \return True to continue the capture, or false to stop it
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual bool onProcessSamples(const Int16* samples, std::size_t sampleCount);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Stop capturing audio data
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual void onStop();
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
std::vector<Int16> m_samples; ///< Temporary sample buffer to hold the recorded data
|
|
||||||
SoundBuffer m_buffer; ///< Sound buffer that will contain the recorded data
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
#endif // SFML_SOUNDBUFFERRECORDER_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::SoundBufferRecorder
|
|
||||||
/// \ingroup audio
|
|
||||||
///
|
|
||||||
/// sf::SoundBufferRecorder allows to access a recorded sound
|
|
||||||
/// through a sf::SoundBuffer, so that it can be played, saved
|
|
||||||
/// to a file, etc.
|
|
||||||
///
|
|
||||||
/// It has the same simple interface as its base class (start(), stop())
|
|
||||||
/// and adds a function to retrieve the recorded sound buffer
|
|
||||||
/// (getBuffer()).
|
|
||||||
///
|
|
||||||
/// As usual, don't forget to call the isAvailable() function
|
|
||||||
/// before using this class (see sf::SoundRecorder for more details
|
|
||||||
/// about this).
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// if (sf::SoundBufferRecorder::isAvailable())
|
|
||||||
/// {
|
|
||||||
/// // Record some audio data
|
|
||||||
/// sf::SoundBufferRecorder recorder;
|
|
||||||
/// recorder.start();
|
|
||||||
/// ...
|
|
||||||
/// recorder.stop();
|
|
||||||
///
|
|
||||||
/// // Get the buffer containing the captured audio data
|
|
||||||
/// const sf::SoundBuffer& buffer = recorder.getBuffer();
|
|
||||||
///
|
|
||||||
/// // Save it to a file (for example...)
|
|
||||||
/// buffer.saveToFile("my_record.ogg");
|
|
||||||
/// }
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \see sf::SoundRecorder
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,197 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_SOUNDFILEFACTORY_HPP
|
|
||||||
#define SFML_SOUNDFILEFACTORY_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Audio/Export.hpp>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
class InputStream;
|
|
||||||
class SoundFileReader;
|
|
||||||
class SoundFileWriter;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Manages and instantiates sound file readers and writers
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_AUDIO_API SoundFileFactory
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Register a new reader
|
|
||||||
///
|
|
||||||
/// \see unregisterReader
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
template <typename T>
|
|
||||||
static void registerReader();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Unregister a reader
|
|
||||||
///
|
|
||||||
/// \see registerReader
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
template <typename T>
|
|
||||||
static void unregisterReader();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Register a new writer
|
|
||||||
///
|
|
||||||
/// \see unregisterWriter
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
template <typename T>
|
|
||||||
static void registerWriter();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Unregister a writer
|
|
||||||
///
|
|
||||||
/// \see registerWriter
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
template <typename T>
|
|
||||||
static void unregisterWriter();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Instantiate the right reader for the given file on disk
|
|
||||||
///
|
|
||||||
/// It's up to the caller to release the returned reader
|
|
||||||
///
|
|
||||||
/// \param filename Path of the sound file
|
|
||||||
///
|
|
||||||
/// \return A new sound file reader that can read the given file, or null if no reader can handle it
|
|
||||||
///
|
|
||||||
/// \see createReaderFromMemory, createReaderFromStream
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static SoundFileReader* createReaderFromFilename(const std::string& filename);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Instantiate the right codec for the given file in memory
|
|
||||||
///
|
|
||||||
/// It's up to the caller to release the returned reader
|
|
||||||
///
|
|
||||||
/// \param data Pointer to the file data in memory
|
|
||||||
/// \param sizeInBytes Total size of the file data, in bytes
|
|
||||||
///
|
|
||||||
/// \return A new sound file codec that can read the given file, or null if no codec can handle it
|
|
||||||
///
|
|
||||||
/// \see createReaderFromFilename, createReaderFromStream
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static SoundFileReader* createReaderFromMemory(const void* data, std::size_t sizeInBytes);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Instantiate the right codec for the given file in stream
|
|
||||||
///
|
|
||||||
/// It's up to the caller to release the returned reader
|
|
||||||
///
|
|
||||||
/// \param stream Source stream to read from
|
|
||||||
///
|
|
||||||
/// \return A new sound file codec that can read the given file, or null if no codec can handle it
|
|
||||||
///
|
|
||||||
/// \see createReaderFromFilename, createReaderFromMemory
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static SoundFileReader* createReaderFromStream(InputStream& stream);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Instantiate the right writer for the given file on disk
|
|
||||||
///
|
|
||||||
/// It's up to the caller to release the returned writer
|
|
||||||
///
|
|
||||||
/// \param filename Path of the sound file
|
|
||||||
///
|
|
||||||
/// \return A new sound file writer that can write given file, or null if no writer can handle it
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static SoundFileWriter* createWriterFromFilename(const std::string& filename);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Types
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
struct ReaderFactory
|
|
||||||
{
|
|
||||||
bool (*check)(InputStream&);
|
|
||||||
SoundFileReader* (*create)();
|
|
||||||
};
|
|
||||||
typedef std::vector<ReaderFactory> ReaderFactoryArray;
|
|
||||||
|
|
||||||
struct WriterFactory
|
|
||||||
{
|
|
||||||
bool (*check)(const std::string&);
|
|
||||||
SoundFileWriter* (*create)();
|
|
||||||
};
|
|
||||||
typedef std::vector<WriterFactory> WriterFactoryArray;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Static member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static ReaderFactoryArray s_readers; ///< List of all registered readers
|
|
||||||
static WriterFactoryArray s_writers; ///< List of all registered writers
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
#include <SFML/Audio/SoundFileFactory.inl>
|
|
||||||
|
|
||||||
#endif // SFML_SOUNDFILEFACTORY_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::SoundFileFactory
|
|
||||||
/// \ingroup audio
|
|
||||||
///
|
|
||||||
/// This class is where all the sound file readers and writers are
|
|
||||||
/// registered. You should normally only need to use its registration
|
|
||||||
/// and unregistration functions; readers/writers creation and manipulation
|
|
||||||
/// are wrapped into the higher-level classes sf::InputSoundFile and
|
|
||||||
/// sf::OutputSoundFile.
|
|
||||||
///
|
|
||||||
/// To register a new reader (writer) use the sf::SoundFileFactory::registerReader
|
|
||||||
/// (registerWriter) static function. You don't have to call the unregisterReader
|
|
||||||
/// (unregisterWriter) function, unless you want to unregister a format before your
|
|
||||||
/// application ends (typically, when a plugin is unloaded).
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// sf::SoundFileFactory::registerReader<MySoundFileReader>();
|
|
||||||
/// sf::SoundFileFactory::registerWriter<MySoundFileWriter>();
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \see sf::InputSoundFile, sf::OutputSoundFile, sf::SoundFileReader, sf::SoundFileWriter
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,100 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
namespace priv
|
|
||||||
{
|
|
||||||
template <typename T> SoundFileReader* createReader() {return new T;}
|
|
||||||
template <typename T> SoundFileWriter* createWriter() {return new T;}
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
template <typename T>
|
|
||||||
void SoundFileFactory::registerReader()
|
|
||||||
{
|
|
||||||
// Make sure the same class won't be registered twice
|
|
||||||
unregisterReader<T>();
|
|
||||||
|
|
||||||
// Create a new factory with the functions provided by the class
|
|
||||||
ReaderFactory factory;
|
|
||||||
factory.check = &T::check;
|
|
||||||
factory.create = &priv::createReader<T>;
|
|
||||||
|
|
||||||
// Add it
|
|
||||||
s_readers.push_back(factory);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
template <typename T>
|
|
||||||
void SoundFileFactory::unregisterReader()
|
|
||||||
{
|
|
||||||
// Remove the instance(s) of the reader from the array of factories
|
|
||||||
for (ReaderFactoryArray::iterator it = s_readers.begin(); it != s_readers.end(); )
|
|
||||||
{
|
|
||||||
if (it->create == &priv::createReader<T>)
|
|
||||||
it = s_readers.erase(it);
|
|
||||||
else
|
|
||||||
++it;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
template <typename T>
|
|
||||||
void SoundFileFactory::registerWriter()
|
|
||||||
{
|
|
||||||
// Make sure the same class won't be registered twice
|
|
||||||
unregisterWriter<T>();
|
|
||||||
|
|
||||||
// Create a new factory with the functions provided by the class
|
|
||||||
WriterFactory factory;
|
|
||||||
factory.check = &T::check;
|
|
||||||
factory.create = &priv::createWriter<T>;
|
|
||||||
|
|
||||||
// Add it
|
|
||||||
s_writers.push_back(factory);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
template <typename T>
|
|
||||||
void SoundFileFactory::unregisterWriter()
|
|
||||||
{
|
|
||||||
// Remove the instance(s) of the writer from the array of factories
|
|
||||||
for (WriterFactoryArray::iterator it = s_writers.begin(); it != s_writers.end(); )
|
|
||||||
{
|
|
||||||
if (it->create == &priv::createWriter<T>)
|
|
||||||
it = s_writers.erase(it);
|
|
||||||
else
|
|
||||||
++it;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sf
|
|
@ -1,161 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_SOUNDFILEREADER_HPP
|
|
||||||
#define SFML_SOUNDFILEREADER_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Audio/Export.hpp>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
class InputStream;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Abstract base class for sound file decoding
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_AUDIO_API SoundFileReader
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Structure holding the audio properties of a sound file
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
struct Info
|
|
||||||
{
|
|
||||||
Uint64 sampleCount; ///< Total number of samples in the file
|
|
||||||
unsigned int channelCount; ///< Number of channels of the sound
|
|
||||||
unsigned int sampleRate; ///< Samples rate of the sound, in samples per second
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Virtual destructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual ~SoundFileReader() {}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Open a sound file for reading
|
|
||||||
///
|
|
||||||
/// The provided stream reference is valid as long as the
|
|
||||||
/// SoundFileReader is alive, so it is safe to use/store it
|
|
||||||
/// during the whole lifetime of the reader.
|
|
||||||
///
|
|
||||||
/// \param stream Source stream to read from
|
|
||||||
/// \param info Structure to fill with the properties of the loaded sound
|
|
||||||
///
|
|
||||||
/// \return True if the file was successfully opened
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual bool open(InputStream& stream, Info& info) = 0;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Change the current read position to the given sample offset
|
|
||||||
///
|
|
||||||
/// If the given offset exceeds to total number of samples,
|
|
||||||
/// this function must jump to the end of the file.
|
|
||||||
///
|
|
||||||
/// \param sampleOffset Index of the sample to jump to, relative to the beginning
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual void seek(Uint64 sampleOffset) = 0;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Read audio samples from the open file
|
|
||||||
///
|
|
||||||
/// \param samples Pointer to the sample array to fill
|
|
||||||
/// \param maxCount Maximum number of samples to read
|
|
||||||
///
|
|
||||||
/// \return Number of samples actually read (may be less than \a maxCount)
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual Uint64 read(Int16* samples, Uint64 maxCount) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_SOUNDFILEREADER_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::SoundFileReader
|
|
||||||
/// \ingroup audio
|
|
||||||
///
|
|
||||||
/// This class allows users to read audio file formats not natively
|
|
||||||
/// supported by SFML, and thus extend the set of supported readable
|
|
||||||
/// audio formats.
|
|
||||||
///
|
|
||||||
/// A valid sound file reader must override the open, seek and write functions,
|
|
||||||
/// as well as providing a static check function; the latter is used by
|
|
||||||
/// SFML to find a suitable writer for a given input file.
|
|
||||||
///
|
|
||||||
/// To register a new reader, use the sf::SoundFileFactory::registerReader
|
|
||||||
/// template function.
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// class MySoundFileReader : public sf::SoundFileReader
|
|
||||||
/// {
|
|
||||||
/// public:
|
|
||||||
///
|
|
||||||
/// static bool check(sf::InputStream& stream)
|
|
||||||
/// {
|
|
||||||
/// // typically, read the first few header bytes and check fields that identify the format
|
|
||||||
/// // return true if the reader can handle the format
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// virtual bool open(sf::InputStream& stream, Info& info)
|
|
||||||
/// {
|
|
||||||
/// // read the sound file header and fill the sound attributes
|
|
||||||
/// // (channel count, sample count and sample rate)
|
|
||||||
/// // return true on success
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// virtual void seek(sf::Uint64 sampleOffset)
|
|
||||||
/// {
|
|
||||||
/// // advance to the sampleOffset-th sample from the beginning of the sound
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// virtual sf::Uint64 read(sf::Int16* samples, sf::Uint64 maxCount)
|
|
||||||
/// {
|
|
||||||
/// // read up to 'maxCount' samples into the 'samples' array,
|
|
||||||
/// // convert them (for example from normalized float) if they are not stored
|
|
||||||
/// // as 16-bits signed integers in the file
|
|
||||||
/// // return the actual number of samples read
|
|
||||||
/// }
|
|
||||||
/// };
|
|
||||||
///
|
|
||||||
/// sf::SoundFileFactory::registerReader<MySoundFileReader>();
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \see sf::InputSoundFile, sf::SoundFileFactory, sf::SoundFileWriter
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,125 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_SOUNDFILEWRITER_HPP
|
|
||||||
#define SFML_SOUNDFILEWRITER_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Audio/Export.hpp>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Abstract base class for sound file encoding
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_AUDIO_API SoundFileWriter
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Virtual destructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual ~SoundFileWriter() {}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Open a sound file for writing
|
|
||||||
///
|
|
||||||
/// \param filename Path of the file to open
|
|
||||||
/// \param sampleRate Sample rate of the sound
|
|
||||||
/// \param channelCount Number of channels of the sound
|
|
||||||
///
|
|
||||||
/// \return True if the file was successfully opened
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual bool open(const std::string& filename, unsigned int sampleRate, unsigned int channelCount) = 0;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Write audio samples to the open file
|
|
||||||
///
|
|
||||||
/// \param samples Pointer to the sample array to write
|
|
||||||
/// \param count Number of samples to write
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual void write(const Int16* samples, Uint64 count) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_SOUNDFILEWRITER_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::SoundFileWriter
|
|
||||||
/// \ingroup audio
|
|
||||||
///
|
|
||||||
/// This class allows users to write audio file formats not natively
|
|
||||||
/// supported by SFML, and thus extend the set of supported writable
|
|
||||||
/// audio formats.
|
|
||||||
///
|
|
||||||
/// A valid sound file writer must override the open and write functions,
|
|
||||||
/// as well as providing a static check function; the latter is used by
|
|
||||||
/// SFML to find a suitable writer for a given filename.
|
|
||||||
///
|
|
||||||
/// To register a new writer, use the sf::SoundFileFactory::registerWriter
|
|
||||||
/// template function.
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// class MySoundFileWriter : public sf::SoundFileWriter
|
|
||||||
/// {
|
|
||||||
/// public:
|
|
||||||
///
|
|
||||||
/// static bool check(const std::string& filename)
|
|
||||||
/// {
|
|
||||||
/// // typically, check the extension
|
|
||||||
/// // return true if the writer can handle the format
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// virtual bool open(const std::string& filename, unsigned int sampleRate, unsigned int channelCount)
|
|
||||||
/// {
|
|
||||||
/// // open the file 'filename' for writing,
|
|
||||||
/// // write the given sample rate and channel count to the file header
|
|
||||||
/// // return true on success
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// virtual void write(const sf::Int16* samples, sf::Uint64 count)
|
|
||||||
/// {
|
|
||||||
/// // write 'count' samples stored at address 'samples',
|
|
||||||
/// // convert them (for example to normalized float) if the format requires it
|
|
||||||
/// }
|
|
||||||
/// };
|
|
||||||
///
|
|
||||||
/// sf::SoundFileFactory::registerWriter<MySoundFileWriter>();
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \see sf::OutputSoundFile, sf::SoundFileFactory, sf::SoundFileReader
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,364 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_SOUNDRECORDER_HPP
|
|
||||||
#define SFML_SOUNDRECORDER_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Audio/Export.hpp>
|
|
||||||
#include <SFML/Audio/AlResource.hpp>
|
|
||||||
#include <SFML/System/Thread.hpp>
|
|
||||||
#include <SFML/System/Time.hpp>
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Abstract base class for capturing sound data
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_AUDIO_API SoundRecorder : AlResource
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief destructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual ~SoundRecorder();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Start the capture
|
|
||||||
///
|
|
||||||
/// The \a sampleRate parameter defines the number of audio samples
|
|
||||||
/// captured per second. The higher, the better the quality
|
|
||||||
/// (for example, 44100 samples/sec is CD quality).
|
|
||||||
/// This function uses its own thread so that it doesn't block
|
|
||||||
/// the rest of the program while the capture runs.
|
|
||||||
/// Please note that only one capture can happen at the same time.
|
|
||||||
/// You can select which capture device will be used, by passing
|
|
||||||
/// the name to the setDevice() method. If none was selected
|
|
||||||
/// before, the default capture device will be used. You can get a
|
|
||||||
/// list of the names of all available capture devices by calling
|
|
||||||
/// getAvailableDevices().
|
|
||||||
///
|
|
||||||
/// \param sampleRate Desired capture rate, in number of samples per second
|
|
||||||
///
|
|
||||||
/// \return True, if start of capture was successful
|
|
||||||
///
|
|
||||||
/// \see stop, getAvailableDevices
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool start(unsigned int sampleRate = 44100);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Stop the capture
|
|
||||||
///
|
|
||||||
/// \see start
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void stop();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the sample rate
|
|
||||||
///
|
|
||||||
/// The sample rate defines the number of audio samples
|
|
||||||
/// captured per second. The higher, the better the quality
|
|
||||||
/// (for example, 44100 samples/sec is CD quality).
|
|
||||||
///
|
|
||||||
/// \return Sample rate, in samples per second
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
unsigned int getSampleRate() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get a list of the names of all available audio capture devices
|
|
||||||
///
|
|
||||||
/// This function returns a vector of strings, containing
|
|
||||||
/// the names of all available audio capture devices.
|
|
||||||
///
|
|
||||||
/// \return A vector of strings containing the names
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static std::vector<std::string> getAvailableDevices();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the name of the default audio capture device
|
|
||||||
///
|
|
||||||
/// This function returns the name of the default audio
|
|
||||||
/// capture device. If none is available, an empty string
|
|
||||||
/// is returned.
|
|
||||||
///
|
|
||||||
/// \return The name of the default audio capture device
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static std::string getDefaultDevice();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the audio capture device
|
|
||||||
///
|
|
||||||
/// This function sets the audio capture device to the device
|
|
||||||
/// with the given \a name. It can be called on the fly (i.e:
|
|
||||||
/// while recording). If you do so while recording and
|
|
||||||
/// opening the device fails, it stops the recording.
|
|
||||||
///
|
|
||||||
/// \param name The name of the audio capture device
|
|
||||||
///
|
|
||||||
/// \return True, if it was able to set the requested device
|
|
||||||
///
|
|
||||||
/// \see getAvailableDevices, getDefaultDevice
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool setDevice(const std::string& name);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the name of the current audio capture device
|
|
||||||
///
|
|
||||||
/// \return The name of the current audio capture device
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const std::string& getDevice() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Check if the system supports audio capture
|
|
||||||
///
|
|
||||||
/// This function should always be called before using
|
|
||||||
/// the audio capture features. If it returns false, then
|
|
||||||
/// any attempt to use sf::SoundRecorder or one of its derived
|
|
||||||
/// classes will fail.
|
|
||||||
///
|
|
||||||
/// \return True if audio capture is supported, false otherwise
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static bool isAvailable();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
/// This constructor is only meant to be called by derived classes.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SoundRecorder();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the processing interval
|
|
||||||
///
|
|
||||||
/// The processing interval controls the period
|
|
||||||
/// between calls to the onProcessSamples function. You may
|
|
||||||
/// want to use a small interval if you want to process the
|
|
||||||
/// recorded data in real time, for example.
|
|
||||||
///
|
|
||||||
/// Note: this is only a hint, the actual period may vary.
|
|
||||||
/// So don't rely on this parameter to implement precise timing.
|
|
||||||
///
|
|
||||||
/// The default processing interval is 100 ms.
|
|
||||||
///
|
|
||||||
/// \param interval Processing interval
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setProcessingInterval(Time interval);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Start capturing audio data
|
|
||||||
///
|
|
||||||
/// This virtual function may be overridden by a derived class
|
|
||||||
/// if something has to be done every time a new capture
|
|
||||||
/// starts. If not, this function can be ignored; the default
|
|
||||||
/// implementation does nothing.
|
|
||||||
///
|
|
||||||
/// \return True to start the capture, or false to abort it
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual bool onStart();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Process a new chunk of recorded samples
|
|
||||||
///
|
|
||||||
/// This virtual function is called every time a new chunk of
|
|
||||||
/// recorded data is available. The derived class can then do
|
|
||||||
/// whatever it wants with it (storing it, playing it, sending
|
|
||||||
/// it over the network, etc.).
|
|
||||||
///
|
|
||||||
/// \param samples Pointer to the new chunk of recorded samples
|
|
||||||
/// \param sampleCount Number of samples pointed by \a samples
|
|
||||||
///
|
|
||||||
/// \return True to continue the capture, or false to stop it
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual bool onProcessSamples(const Int16* samples, std::size_t sampleCount) = 0;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Stop capturing audio data
|
|
||||||
///
|
|
||||||
/// This virtual function may be overridden by a derived class
|
|
||||||
/// if something has to be done every time the capture
|
|
||||||
/// ends. If not, this function can be ignored; the default
|
|
||||||
/// implementation does nothing.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual void onStop();
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Function called as the entry point of the thread
|
|
||||||
///
|
|
||||||
/// This function starts the recording loop, and returns
|
|
||||||
/// only when the capture is stopped.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void record();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the new available audio samples and process them
|
|
||||||
///
|
|
||||||
/// This function is called continuously during the
|
|
||||||
/// capture loop. It retrieves the captured samples and
|
|
||||||
/// forwards them to the derived class.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void processCapturedSamples();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Clean up the recorder's internal resources
|
|
||||||
///
|
|
||||||
/// This function is called when the capture stops.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void cleanup();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Thread m_thread; ///< Thread running the background recording task
|
|
||||||
std::vector<Int16> m_samples; ///< Buffer to store captured samples
|
|
||||||
unsigned int m_sampleRate; ///< Sample rate
|
|
||||||
Time m_processingInterval; ///< Time period between calls to onProcessSamples
|
|
||||||
bool m_isCapturing; ///< Capturing state
|
|
||||||
std::string m_deviceName; ///< Name of the audio capture device
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_SOUNDRECORDER_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::SoundRecorder
|
|
||||||
/// \ingroup audio
|
|
||||||
///
|
|
||||||
/// sf::SoundBuffer provides a simple interface to access
|
|
||||||
/// the audio recording capabilities of the computer
|
|
||||||
/// (the microphone). As an abstract base class, it only cares
|
|
||||||
/// about capturing sound samples, the task of making something
|
|
||||||
/// useful with them is left to the derived class. Note that
|
|
||||||
/// SFML provides a built-in specialization for saving the
|
|
||||||
/// captured data to a sound buffer (see sf::SoundBufferRecorder).
|
|
||||||
///
|
|
||||||
/// A derived class has only one virtual function to override:
|
|
||||||
/// \li onProcessSamples provides the new chunks of audio samples while the capture happens
|
|
||||||
///
|
|
||||||
/// Moreover, two additional virtual functions can be overridden
|
|
||||||
/// as well if necessary:
|
|
||||||
/// \li onStart is called before the capture happens, to perform custom initializations
|
|
||||||
/// \li onStop is called after the capture ends, to perform custom cleanup
|
|
||||||
///
|
|
||||||
/// A derived class can also control the frequency of the onProcessSamples
|
|
||||||
/// calls, with the setProcessingInterval protected function. The default
|
|
||||||
/// interval is chosen so that recording thread doesn't consume too much
|
|
||||||
/// CPU, but it can be changed to a smaller value if you need to process
|
|
||||||
/// the recorded data in real time, for example.
|
|
||||||
///
|
|
||||||
/// The audio capture feature may not be supported or activated
|
|
||||||
/// on every platform, thus it is recommended to check its
|
|
||||||
/// availability with the isAvailable() function. If it returns
|
|
||||||
/// false, then any attempt to use an audio recorder will fail.
|
|
||||||
///
|
|
||||||
/// If you have multiple sound input devices connected to your
|
|
||||||
/// computer (for example: microphone, external soundcard, webcam mic, ...)
|
|
||||||
/// you can get a list of all available devices through the
|
|
||||||
/// getAvailableDevices() function. You can then select a device
|
|
||||||
/// by calling setDevice() with the appropriate device. Otherwise
|
|
||||||
/// the default capturing device will be used.
|
|
||||||
///
|
|
||||||
/// It is important to note that the audio capture happens in a
|
|
||||||
/// separate thread, so that it doesn't block the rest of the
|
|
||||||
/// program. In particular, the onProcessSamples virtual function
|
|
||||||
/// (but not onStart and not onStop) will be called
|
|
||||||
/// from this separate thread. It is important to keep this in
|
|
||||||
/// mind, because you may have to take care of synchronization
|
|
||||||
/// issues if you share data between threads.
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// class CustomRecorder : public sf::SoundRecorder
|
|
||||||
/// {
|
|
||||||
/// virtual bool onStart() // optional
|
|
||||||
/// {
|
|
||||||
/// // Initialize whatever has to be done before the capture starts
|
|
||||||
/// ...
|
|
||||||
///
|
|
||||||
/// // Return true to start playing
|
|
||||||
/// return true;
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// virtual bool onProcessSamples(const Int16* samples, std::size_t sampleCount)
|
|
||||||
/// {
|
|
||||||
/// // Do something with the new chunk of samples (store them, send them, ...)
|
|
||||||
/// ...
|
|
||||||
///
|
|
||||||
/// // Return true to continue playing
|
|
||||||
/// return true;
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// virtual void onStop() // optional
|
|
||||||
/// {
|
|
||||||
/// // Clean up whatever has to be done after the capture ends
|
|
||||||
/// ...
|
|
||||||
/// }
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// // Usage
|
|
||||||
/// if (CustomRecorder::isAvailable())
|
|
||||||
/// {
|
|
||||||
/// CustomRecorder recorder;
|
|
||||||
///
|
|
||||||
/// if (!recorder.start())
|
|
||||||
/// return -1;
|
|
||||||
///
|
|
||||||
/// ...
|
|
||||||
/// recorder.stop();
|
|
||||||
/// }
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \see sf::SoundBufferRecorder
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,287 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_SOUNDSOURCE_HPP
|
|
||||||
#define SFML_SOUNDSOURCE_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Audio/Export.hpp>
|
|
||||||
#include <SFML/Audio/AlResource.hpp>
|
|
||||||
#include <SFML/System/Vector3.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Base class defining a sound's properties
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_AUDIO_API SoundSource : AlResource
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Enumeration of the sound source states
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
enum Status
|
|
||||||
{
|
|
||||||
Stopped, ///< Sound is not playing
|
|
||||||
Paused, ///< Sound is paused
|
|
||||||
Playing ///< Sound is playing
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Copy constructor
|
|
||||||
///
|
|
||||||
/// \param copy Instance to copy
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SoundSource(const SoundSource& copy);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Destructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual ~SoundSource();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the pitch of the sound
|
|
||||||
///
|
|
||||||
/// The pitch represents the perceived fundamental frequency
|
|
||||||
/// of a sound; thus you can make a sound more acute or grave
|
|
||||||
/// by changing its pitch. A side effect of changing the pitch
|
|
||||||
/// is to modify the playing speed of the sound as well.
|
|
||||||
/// The default value for the pitch is 1.
|
|
||||||
///
|
|
||||||
/// \param pitch New pitch to apply to the sound
|
|
||||||
///
|
|
||||||
/// \see getPitch
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setPitch(float pitch);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the volume of the sound
|
|
||||||
///
|
|
||||||
/// The volume is a value between 0 (mute) and 100 (full volume).
|
|
||||||
/// The default value for the volume is 100.
|
|
||||||
///
|
|
||||||
/// \param volume Volume of the sound
|
|
||||||
///
|
|
||||||
/// \see getVolume
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setVolume(float volume);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the 3D position of the sound in the audio scene
|
|
||||||
///
|
|
||||||
/// Only sounds with one channel (mono sounds) can be
|
|
||||||
/// spatialized.
|
|
||||||
/// The default position of a sound is (0, 0, 0).
|
|
||||||
///
|
|
||||||
/// \param x X coordinate of the position of the sound in the scene
|
|
||||||
/// \param y Y coordinate of the position of the sound in the scene
|
|
||||||
/// \param z Z coordinate of the position of the sound in the scene
|
|
||||||
///
|
|
||||||
/// \see getPosition
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setPosition(float x, float y, float z);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the 3D position of the sound in the audio scene
|
|
||||||
///
|
|
||||||
/// Only sounds with one channel (mono sounds) can be
|
|
||||||
/// spatialized.
|
|
||||||
/// The default position of a sound is (0, 0, 0).
|
|
||||||
///
|
|
||||||
/// \param position Position of the sound in the scene
|
|
||||||
///
|
|
||||||
/// \see getPosition
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setPosition(const Vector3f& position);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Make the sound's position relative to the listener or absolute
|
|
||||||
///
|
|
||||||
/// Making a sound relative to the listener will ensure that it will always
|
|
||||||
/// be played the same way regardless of the position of the listener.
|
|
||||||
/// This can be useful for non-spatialized sounds, sounds that are
|
|
||||||
/// produced by the listener, or sounds attached to it.
|
|
||||||
/// The default value is false (position is absolute).
|
|
||||||
///
|
|
||||||
/// \param relative True to set the position relative, false to set it absolute
|
|
||||||
///
|
|
||||||
/// \see isRelativeToListener
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setRelativeToListener(bool relative);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the minimum distance of the sound
|
|
||||||
///
|
|
||||||
/// The "minimum distance" of a sound is the maximum
|
|
||||||
/// distance at which it is heard at its maximum volume. Further
|
|
||||||
/// than the minimum distance, it will start to fade out according
|
|
||||||
/// to its attenuation factor. A value of 0 ("inside the head
|
|
||||||
/// of the listener") is an invalid value and is forbidden.
|
|
||||||
/// The default value of the minimum distance is 1.
|
|
||||||
///
|
|
||||||
/// \param distance New minimum distance of the sound
|
|
||||||
///
|
|
||||||
/// \see getMinDistance, setAttenuation
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setMinDistance(float distance);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the attenuation factor of the sound
|
|
||||||
///
|
|
||||||
/// The attenuation is a multiplicative factor which makes
|
|
||||||
/// the sound more or less loud according to its distance
|
|
||||||
/// from the listener. An attenuation of 0 will produce a
|
|
||||||
/// non-attenuated sound, i.e. its volume will always be the same
|
|
||||||
/// whether it is heard from near or from far. On the other hand,
|
|
||||||
/// an attenuation value such as 100 will make the sound fade out
|
|
||||||
/// very quickly as it gets further from the listener.
|
|
||||||
/// The default value of the attenuation is 1.
|
|
||||||
///
|
|
||||||
/// \param attenuation New attenuation factor of the sound
|
|
||||||
///
|
|
||||||
/// \see getAttenuation, setMinDistance
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setAttenuation(float attenuation);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the pitch of the sound
|
|
||||||
///
|
|
||||||
/// \return Pitch of the sound
|
|
||||||
///
|
|
||||||
/// \see setPitch
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
float getPitch() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the volume of the sound
|
|
||||||
///
|
|
||||||
/// \return Volume of the sound, in the range [0, 100]
|
|
||||||
///
|
|
||||||
/// \see setVolume
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
float getVolume() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the 3D position of the sound in the audio scene
|
|
||||||
///
|
|
||||||
/// \return Position of the sound
|
|
||||||
///
|
|
||||||
/// \see setPosition
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Vector3f getPosition() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Tell whether the sound's position is relative to the
|
|
||||||
/// listener or is absolute
|
|
||||||
///
|
|
||||||
/// \return True if the position is relative, false if it's absolute
|
|
||||||
///
|
|
||||||
/// \see setRelativeToListener
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool isRelativeToListener() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the minimum distance of the sound
|
|
||||||
///
|
|
||||||
/// \return Minimum distance of the sound
|
|
||||||
///
|
|
||||||
/// \see setMinDistance, getAttenuation
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
float getMinDistance() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the attenuation factor of the sound
|
|
||||||
///
|
|
||||||
/// \return Attenuation factor of the sound
|
|
||||||
///
|
|
||||||
/// \see setAttenuation, getMinDistance
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
float getAttenuation() const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
/// This constructor is meant to be called by derived classes only.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SoundSource();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the current status of the sound (stopped, paused, playing)
|
|
||||||
///
|
|
||||||
/// \return Current status of the sound
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Status getStatus() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
unsigned int m_source; ///< OpenAL source identifier
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_SOUNDSOURCE_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::SoundSource
|
|
||||||
/// \ingroup audio
|
|
||||||
///
|
|
||||||
/// sf::SoundSource is not meant to be used directly, it
|
|
||||||
/// only serves as a common base for all audio objects
|
|
||||||
/// that can live in the audio environment.
|
|
||||||
///
|
|
||||||
/// It defines several properties for the sound: pitch,
|
|
||||||
/// volume, position, attenuation, etc. All of them can be
|
|
||||||
/// changed at any time with no impact on performances.
|
|
||||||
///
|
|
||||||
/// \see sf::Sound, sf::SoundStream
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,386 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_SOUNDSTREAM_HPP
|
|
||||||
#define SFML_SOUNDSTREAM_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Audio/Export.hpp>
|
|
||||||
#include <SFML/Audio/SoundSource.hpp>
|
|
||||||
#include <SFML/System/Thread.hpp>
|
|
||||||
#include <SFML/System/Time.hpp>
|
|
||||||
#include <SFML/System/Mutex.hpp>
|
|
||||||
#include <cstdlib>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Abstract base class for streamed audio sources
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_AUDIO_API SoundStream : public SoundSource
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Structure defining a chunk of audio data to stream
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
struct Chunk
|
|
||||||
{
|
|
||||||
const Int16* samples; ///< Pointer to the audio samples
|
|
||||||
std::size_t sampleCount; ///< Number of samples pointed by Samples
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Destructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual ~SoundStream();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Start or resume playing the audio stream
|
|
||||||
///
|
|
||||||
/// This function starts the stream if it was stopped, resumes
|
|
||||||
/// it if it was paused, and restarts it from the beginning if
|
|
||||||
/// it was already playing.
|
|
||||||
/// This function uses its own thread so that it doesn't block
|
|
||||||
/// the rest of the program while the stream is played.
|
|
||||||
///
|
|
||||||
/// \see pause, stop
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void play();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Pause the audio stream
|
|
||||||
///
|
|
||||||
/// This function pauses the stream if it was playing,
|
|
||||||
/// otherwise (stream already paused or stopped) it has no effect.
|
|
||||||
///
|
|
||||||
/// \see play, stop
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void pause();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Stop playing the audio stream
|
|
||||||
///
|
|
||||||
/// This function stops the stream if it was playing or paused,
|
|
||||||
/// and does nothing if it was already stopped.
|
|
||||||
/// It also resets the playing position (unlike pause()).
|
|
||||||
///
|
|
||||||
/// \see play, pause
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void stop();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Return the number of channels of the stream
|
|
||||||
///
|
|
||||||
/// 1 channel means a mono sound, 2 means stereo, etc.
|
|
||||||
///
|
|
||||||
/// \return Number of channels
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
unsigned int getChannelCount() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the stream sample rate of the stream
|
|
||||||
///
|
|
||||||
/// The sample rate is the number of audio samples played per
|
|
||||||
/// second. The higher, the better the quality.
|
|
||||||
///
|
|
||||||
/// \return Sample rate, in number of samples per second
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
unsigned int getSampleRate() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the current status of the stream (stopped, paused, playing)
|
|
||||||
///
|
|
||||||
/// \return Current status
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Status getStatus() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Change the current playing position of the stream
|
|
||||||
///
|
|
||||||
/// The playing position can be changed when the stream is
|
|
||||||
/// either paused or playing. Changing the playing position
|
|
||||||
/// when the stream is stopped has no effect, since playing
|
|
||||||
/// the stream would reset its position.
|
|
||||||
///
|
|
||||||
/// \param timeOffset New playing position, from the beginning of the stream
|
|
||||||
///
|
|
||||||
/// \see getPlayingOffset
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setPlayingOffset(Time timeOffset);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the current playing position of the stream
|
|
||||||
///
|
|
||||||
/// \return Current playing position, from the beginning of the stream
|
|
||||||
///
|
|
||||||
/// \see setPlayingOffset
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Time getPlayingOffset() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set whether or not the stream should loop after reaching the end
|
|
||||||
///
|
|
||||||
/// If set, the stream will restart from beginning after
|
|
||||||
/// reaching the end and so on, until it is stopped or
|
|
||||||
/// setLoop(false) is called.
|
|
||||||
/// The default looping state for streams is false.
|
|
||||||
///
|
|
||||||
/// \param loop True to play in loop, false to play once
|
|
||||||
///
|
|
||||||
/// \see getLoop
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setLoop(bool loop);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Tell whether or not the stream is in loop mode
|
|
||||||
///
|
|
||||||
/// \return True if the stream is looping, false otherwise
|
|
||||||
///
|
|
||||||
/// \see setLoop
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool getLoop() const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
/// This constructor is only meant to be called by derived classes.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SoundStream();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Define the audio stream parameters
|
|
||||||
///
|
|
||||||
/// This function must be called by derived classes as soon
|
|
||||||
/// as they know the audio settings of the stream to play.
|
|
||||||
/// Any attempt to manipulate the stream (play(), ...) before
|
|
||||||
/// calling this function will fail.
|
|
||||||
/// It can be called multiple times if the settings of the
|
|
||||||
/// audio stream change, but only when the stream is stopped.
|
|
||||||
///
|
|
||||||
/// \param channelCount Number of channels of the stream
|
|
||||||
/// \param sampleRate Sample rate, in samples per second
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void initialize(unsigned int channelCount, unsigned int sampleRate);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Request a new chunk of audio samples from the stream source
|
|
||||||
///
|
|
||||||
/// This function must be overridden by derived classes to provide
|
|
||||||
/// the audio samples to play. It is called continuously by the
|
|
||||||
/// streaming loop, in a separate thread.
|
|
||||||
/// The source can choose to stop the streaming loop at any time, by
|
|
||||||
/// returning false to the caller.
|
|
||||||
/// If you return true (i.e. continue streaming) it is important that
|
|
||||||
/// the returned array of samples is not empty; this would stop the stream
|
|
||||||
/// due to an internal limitation.
|
|
||||||
///
|
|
||||||
/// \param data Chunk of data to fill
|
|
||||||
///
|
|
||||||
/// \return True to continue playback, false to stop
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual bool onGetData(Chunk& data) = 0;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Change the current playing position in the stream source
|
|
||||||
///
|
|
||||||
/// This function must be overridden by derived classes to
|
|
||||||
/// allow random seeking into the stream source.
|
|
||||||
///
|
|
||||||
/// \param timeOffset New playing position, relative to the beginning of the stream
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual void onSeek(Time timeOffset) = 0;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Function called as the entry point of the thread
|
|
||||||
///
|
|
||||||
/// This function starts the streaming loop, and returns
|
|
||||||
/// only when the sound is stopped.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void streamData();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Fill a new buffer with audio samples, and append
|
|
||||||
/// it to the playing queue
|
|
||||||
///
|
|
||||||
/// This function is called as soon as a buffer has been fully
|
|
||||||
/// consumed; it fills it again and inserts it back into the
|
|
||||||
/// playing queue.
|
|
||||||
///
|
|
||||||
/// \param bufferNum Number of the buffer to fill (in [0, BufferCount])
|
|
||||||
///
|
|
||||||
/// \return True if the stream source has requested to stop, false otherwise
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool fillAndPushBuffer(unsigned int bufferNum);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Fill the audio buffers and put them all into the playing queue
|
|
||||||
///
|
|
||||||
/// This function is called when playing starts and the
|
|
||||||
/// playing queue is empty.
|
|
||||||
///
|
|
||||||
/// \return True if the derived class has requested to stop, false otherwise
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool fillQueue();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Clear all the audio buffers and empty the playing queue
|
|
||||||
///
|
|
||||||
/// This function is called when the stream is stopped.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void clearQueue();
|
|
||||||
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
BufferCount = 3 ///< Number of audio buffers used by the streaming loop
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Thread m_thread; ///< Thread running the background tasks
|
|
||||||
mutable Mutex m_threadMutex; ///< Thread mutex
|
|
||||||
Status m_threadStartState; ///< State the thread starts in (Playing, Paused, Stopped)
|
|
||||||
bool m_isStreaming; ///< Streaming state (true = playing, false = stopped)
|
|
||||||
unsigned int m_buffers[BufferCount]; ///< Sound buffers used to store temporary audio data
|
|
||||||
unsigned int m_channelCount; ///< Number of channels (1 = mono, 2 = stereo, ...)
|
|
||||||
unsigned int m_sampleRate; ///< Frequency (samples / second)
|
|
||||||
Uint32 m_format; ///< Format of the internal sound buffers
|
|
||||||
bool m_loop; ///< Loop flag (true to loop, false to play once)
|
|
||||||
Uint64 m_samplesProcessed; ///< Number of buffers processed since beginning of the stream
|
|
||||||
bool m_endBuffers[BufferCount]; ///< Each buffer is marked as "end buffer" or not, for proper duration calculation
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_SOUNDSTREAM_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::SoundStream
|
|
||||||
/// \ingroup audio
|
|
||||||
///
|
|
||||||
/// Unlike audio buffers (see sf::SoundBuffer), audio streams
|
|
||||||
/// are never completely loaded in memory. Instead, the audio
|
|
||||||
/// data is acquired continuously while the stream is playing.
|
|
||||||
/// This behavior allows to play a sound with no loading delay,
|
|
||||||
/// and keeps the memory consumption very low.
|
|
||||||
///
|
|
||||||
/// Sound sources that need to be streamed are usually big files
|
|
||||||
/// (compressed audio musics that would eat hundreds of MB in memory)
|
|
||||||
/// or files that would take a lot of time to be received
|
|
||||||
/// (sounds played over the network).
|
|
||||||
///
|
|
||||||
/// sf::SoundStream is a base class that doesn't care about the
|
|
||||||
/// stream source, which is left to the derived class. SFML provides
|
|
||||||
/// a built-in specialization for big files (see sf::Music).
|
|
||||||
/// No network stream source is provided, but you can write your own
|
|
||||||
/// by combining this class with the network module.
|
|
||||||
///
|
|
||||||
/// A derived class has to override two virtual functions:
|
|
||||||
/// \li onGetData fills a new chunk of audio data to be played
|
|
||||||
/// \li onSeek changes the current playing position in the source
|
|
||||||
///
|
|
||||||
/// It is important to note that each SoundStream is played in its
|
|
||||||
/// own separate thread, so that the streaming loop doesn't block the
|
|
||||||
/// rest of the program. In particular, the OnGetData and OnSeek
|
|
||||||
/// virtual functions may sometimes be called from this separate thread.
|
|
||||||
/// It is important to keep this in mind, because you may have to take
|
|
||||||
/// care of synchronization issues if you share data between threads.
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// class CustomStream : public sf::SoundStream
|
|
||||||
/// {
|
|
||||||
/// public:
|
|
||||||
///
|
|
||||||
/// bool open(const std::string& location)
|
|
||||||
/// {
|
|
||||||
/// // Open the source and get audio settings
|
|
||||||
/// ...
|
|
||||||
/// unsigned int channelCount = ...;
|
|
||||||
/// unsigned int sampleRate = ...;
|
|
||||||
///
|
|
||||||
/// // Initialize the stream -- important!
|
|
||||||
/// initialize(channelCount, sampleRate);
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// private:
|
|
||||||
///
|
|
||||||
/// virtual bool onGetData(Chunk& data)
|
|
||||||
/// {
|
|
||||||
/// // Fill the chunk with audio data from the stream source
|
|
||||||
/// // (note: must not be empty if you want to continue playing)
|
|
||||||
/// data.samples = ...;
|
|
||||||
/// data.sampleCount = ...;
|
|
||||||
///
|
|
||||||
/// // Return true to continue playing
|
|
||||||
/// return true;
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// virtual void onSeek(Uint32 timeOffset)
|
|
||||||
/// {
|
|
||||||
/// // Change the current position in the stream source
|
|
||||||
/// ...
|
|
||||||
/// }
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// // Usage
|
|
||||||
/// CustomStream stream;
|
|
||||||
/// stream.open("path/to/stream");
|
|
||||||
/// stream.play();
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \see sf::Music
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
193
SQCSim2021/external/sfml23/include/SFML/Config.hpp
vendored
193
SQCSim2021/external/sfml23/include/SFML/Config.hpp
vendored
@ -1,193 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_CONFIG_HPP
|
|
||||||
#define SFML_CONFIG_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Define the SFML version
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#define SFML_VERSION_MAJOR 2
|
|
||||||
#define SFML_VERSION_MINOR 3
|
|
||||||
#define SFML_VERSION_PATCH 2
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Identify the operating system
|
|
||||||
// see http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#if defined(_WIN32)
|
|
||||||
|
|
||||||
// Windows
|
|
||||||
#define SFML_SYSTEM_WINDOWS
|
|
||||||
#ifndef NOMINMAX
|
|
||||||
#define NOMINMAX
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#elif defined(__APPLE__) && defined(__MACH__)
|
|
||||||
|
|
||||||
// Apple platform, see which one it is
|
|
||||||
#include "TargetConditionals.h"
|
|
||||||
|
|
||||||
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
|
|
||||||
|
|
||||||
// iOS
|
|
||||||
#define SFML_SYSTEM_IOS
|
|
||||||
|
|
||||||
#elif TARGET_OS_MAC
|
|
||||||
|
|
||||||
// MacOS
|
|
||||||
#define SFML_SYSTEM_MACOS
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
// Unsupported Apple system
|
|
||||||
#error This Apple operating system is not supported by SFML library
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#elif defined(__unix__)
|
|
||||||
|
|
||||||
// UNIX system, see which one it is
|
|
||||||
#if defined(__ANDROID__)
|
|
||||||
|
|
||||||
// Android
|
|
||||||
#define SFML_SYSTEM_ANDROID
|
|
||||||
|
|
||||||
#elif defined(__linux__)
|
|
||||||
|
|
||||||
// Linux
|
|
||||||
#define SFML_SYSTEM_LINUX
|
|
||||||
|
|
||||||
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
|
||||||
|
|
||||||
// FreeBSD
|
|
||||||
#define SFML_SYSTEM_FREEBSD
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
// Unsupported UNIX system
|
|
||||||
#error This UNIX operating system is not supported by SFML library
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
// Unsupported system
|
|
||||||
#error This operating system is not supported by SFML library
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Define a portable debug macro
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#if !defined(NDEBUG)
|
|
||||||
|
|
||||||
#define SFML_DEBUG
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Define helpers to create portable import / export macros for each module
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#if !defined(SFML_STATIC)
|
|
||||||
|
|
||||||
#if defined(SFML_SYSTEM_WINDOWS)
|
|
||||||
|
|
||||||
// Windows compilers need specific (and different) keywords for export and import
|
|
||||||
#define SFML_API_EXPORT __declspec(dllexport)
|
|
||||||
#define SFML_API_IMPORT __declspec(dllimport)
|
|
||||||
|
|
||||||
// For Visual C++ compilers, we also need to turn off this annoying C4251 warning
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
|
|
||||||
#pragma warning(disable: 4251)
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#else // Linux, FreeBSD, Mac OS X
|
|
||||||
|
|
||||||
#if __GNUC__ >= 4
|
|
||||||
|
|
||||||
// GCC 4 has special keywords for showing/hidding symbols,
|
|
||||||
// the same keyword is used for both importing and exporting
|
|
||||||
#define SFML_API_EXPORT __attribute__ ((__visibility__ ("default")))
|
|
||||||
#define SFML_API_IMPORT __attribute__ ((__visibility__ ("default")))
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
// GCC < 4 has no mechanism to explicitely hide symbols, everything's exported
|
|
||||||
#define SFML_API_EXPORT
|
|
||||||
#define SFML_API_IMPORT
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
// Static build doesn't need import/export macros
|
|
||||||
#define SFML_API_EXPORT
|
|
||||||
#define SFML_API_IMPORT
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Define portable fixed-size types
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
// All "common" platforms use the same size for char, short and int
|
|
||||||
// (basically there are 3 types for 3 sizes, so no other match is possible),
|
|
||||||
// we can use them without doing any kind of check
|
|
||||||
|
|
||||||
// 8 bits integer types
|
|
||||||
typedef signed char Int8;
|
|
||||||
typedef unsigned char Uint8;
|
|
||||||
|
|
||||||
// 16 bits integer types
|
|
||||||
typedef signed short Int16;
|
|
||||||
typedef unsigned short Uint16;
|
|
||||||
|
|
||||||
// 32 bits integer types
|
|
||||||
typedef signed int Int32;
|
|
||||||
typedef unsigned int Uint32;
|
|
||||||
|
|
||||||
// 64 bits integer types
|
|
||||||
#if defined(_MSC_VER)
|
|
||||||
typedef signed __int64 Int64;
|
|
||||||
typedef unsigned __int64 Uint64;
|
|
||||||
#else
|
|
||||||
typedef signed long long Int64;
|
|
||||||
typedef unsigned long long Uint64;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_CONFIG_HPP
|
|
@ -1,67 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_GRAPHICS_HPP
|
|
||||||
#define SFML_GRAPHICS_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#include <SFML/Window.hpp>
|
|
||||||
#include <SFML/Graphics/BlendMode.hpp>
|
|
||||||
#include <SFML/Graphics/CircleShape.hpp>
|
|
||||||
#include <SFML/Graphics/Color.hpp>
|
|
||||||
#include <SFML/Graphics/ConvexShape.hpp>
|
|
||||||
#include <SFML/Graphics/Drawable.hpp>
|
|
||||||
#include <SFML/Graphics/Font.hpp>
|
|
||||||
#include <SFML/Graphics/Glyph.hpp>
|
|
||||||
#include <SFML/Graphics/Image.hpp>
|
|
||||||
#include <SFML/Graphics/PrimitiveType.hpp>
|
|
||||||
#include <SFML/Graphics/Rect.hpp>
|
|
||||||
#include <SFML/Graphics/RectangleShape.hpp>
|
|
||||||
#include <SFML/Graphics/RenderStates.hpp>
|
|
||||||
#include <SFML/Graphics/RenderTarget.hpp>
|
|
||||||
#include <SFML/Graphics/RenderTexture.hpp>
|
|
||||||
#include <SFML/Graphics/RenderWindow.hpp>
|
|
||||||
#include <SFML/Graphics/Shader.hpp>
|
|
||||||
#include <SFML/Graphics/Shape.hpp>
|
|
||||||
#include <SFML/Graphics/Sprite.hpp>
|
|
||||||
#include <SFML/Graphics/Text.hpp>
|
|
||||||
#include <SFML/Graphics/Texture.hpp>
|
|
||||||
#include <SFML/Graphics/Transform.hpp>
|
|
||||||
#include <SFML/Graphics/Transformable.hpp>
|
|
||||||
#include <SFML/Graphics/Vertex.hpp>
|
|
||||||
#include <SFML/Graphics/VertexArray.hpp>
|
|
||||||
#include <SFML/Graphics/View.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_GRAPHICS_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \defgroup graphics Graphics module
|
|
||||||
///
|
|
||||||
/// 2D graphics module: sprites, text, shapes, ...
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,214 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_BLENDMODE_HPP
|
|
||||||
#define SFML_BLENDMODE_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Graphics/Export.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Blending modes for drawing
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
struct SFML_GRAPHICS_API BlendMode
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////
|
|
||||||
/// \brief Enumeration of the blending factors
|
|
||||||
///
|
|
||||||
/// The factors are mapped directly to their OpenGL equivalents,
|
|
||||||
/// specified by glBlendFunc() or glBlendFuncSeparate().
|
|
||||||
////////////////////////////////////////////////////////
|
|
||||||
enum Factor
|
|
||||||
{
|
|
||||||
Zero, ///< (0, 0, 0, 0)
|
|
||||||
One, ///< (1, 1, 1, 1)
|
|
||||||
SrcColor, ///< (src.r, src.g, src.b, src.a)
|
|
||||||
OneMinusSrcColor, ///< (1, 1, 1, 1) - (src.r, src.g, src.b, src.a)
|
|
||||||
DstColor, ///< (dst.r, dst.g, dst.b, dst.a)
|
|
||||||
OneMinusDstColor, ///< (1, 1, 1, 1) - (dst.r, dst.g, dst.b, dst.a)
|
|
||||||
SrcAlpha, ///< (src.a, src.a, src.a, src.a)
|
|
||||||
OneMinusSrcAlpha, ///< (1, 1, 1, 1) - (src.a, src.a, src.a, src.a)
|
|
||||||
DstAlpha, ///< (dst.a, dst.a, dst.a, dst.a)
|
|
||||||
OneMinusDstAlpha ///< (1, 1, 1, 1) - (dst.a, dst.a, dst.a, dst.a)
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
|
||||||
/// \brief Enumeration of the blending equations
|
|
||||||
///
|
|
||||||
/// The equations are mapped directly to their OpenGL equivalents,
|
|
||||||
/// specified by glBlendEquation() or glBlendEquationSeparate().
|
|
||||||
////////////////////////////////////////////////////////
|
|
||||||
enum Equation
|
|
||||||
{
|
|
||||||
Add, ///< Pixel = Src * SrcFactor + Dst * DstFactor
|
|
||||||
Subtract ///< Pixel = Src * SrcFactor - Dst * DstFactor
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
/// Constructs a blending mode that does alpha blending.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
BlendMode();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Construct the blend mode given the factors and equation.
|
|
||||||
///
|
|
||||||
/// This constructor uses the same factors and equation for both
|
|
||||||
/// color and alpha components. It also defaults to the Add equation.
|
|
||||||
///
|
|
||||||
/// \param sourceFactor Specifies how to compute the source factor for the color and alpha channels.
|
|
||||||
/// \param destinationFactor Specifies how to compute the destination factor for the color and alpha channels.
|
|
||||||
/// \param blendEquation Specifies how to combine the source and destination colors and alpha.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
BlendMode(Factor sourceFactor, Factor destinationFactor, Equation blendEquation = Add);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Construct the blend mode given the factors and equation.
|
|
||||||
///
|
|
||||||
/// \param colorSourceFactor Specifies how to compute the source factor for the color channels.
|
|
||||||
/// \param colorDestinationFactor Specifies how to compute the destination factor for the color channels.
|
|
||||||
/// \param colorBlendEquation Specifies how to combine the source and destination colors.
|
|
||||||
/// \param alphaSourceFactor Specifies how to compute the source factor.
|
|
||||||
/// \param alphaDestinationFactor Specifies how to compute the destination factor.
|
|
||||||
/// \param alphaBlendEquation Specifies how to combine the source and destination alphas.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
BlendMode(Factor colorSourceFactor, Factor colorDestinationFactor,
|
|
||||||
Equation colorBlendEquation, Factor alphaSourceFactor,
|
|
||||||
Factor alphaDestinationFactor, Equation alphaBlendEquation);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member Data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Factor colorSrcFactor; ///< Source blending factor for the color channels
|
|
||||||
Factor colorDstFactor; ///< Destination blending factor for the color channels
|
|
||||||
Equation colorEquation; ///< Blending equation for the color channels
|
|
||||||
Factor alphaSrcFactor; ///< Source blending factor for the alpha channel
|
|
||||||
Factor alphaDstFactor; ///< Destination blending factor for the alpha channel
|
|
||||||
Equation alphaEquation; ///< Blending equation for the alpha channel
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \relates BlendMode
|
|
||||||
/// \brief Overload of the == operator
|
|
||||||
///
|
|
||||||
/// \param left Left operand
|
|
||||||
/// \param right Right operand
|
|
||||||
///
|
|
||||||
/// \return True if blending modes are equal, false if they are different
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SFML_GRAPHICS_API bool operator ==(const BlendMode& left, const BlendMode& right);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \relates BlendMode
|
|
||||||
/// \brief Overload of the != operator
|
|
||||||
///
|
|
||||||
/// \param left Left operand
|
|
||||||
/// \param right Right operand
|
|
||||||
///
|
|
||||||
/// \return True if blending modes are different, false if they are equal
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SFML_GRAPHICS_API bool operator !=(const BlendMode& left, const BlendMode& right);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Commonly used blending modes
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SFML_GRAPHICS_API extern const BlendMode BlendAlpha; ///< Blend source and dest according to dest alpha
|
|
||||||
SFML_GRAPHICS_API extern const BlendMode BlendAdd; ///< Add source to dest
|
|
||||||
SFML_GRAPHICS_API extern const BlendMode BlendMultiply; ///< Multiply source and dest
|
|
||||||
SFML_GRAPHICS_API extern const BlendMode BlendNone; ///< Overwrite dest with source
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_BLENDMODE_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::BlendMode
|
|
||||||
/// \ingroup graphics
|
|
||||||
///
|
|
||||||
/// sf::BlendMode is a class that represents a blend mode. A blend
|
|
||||||
/// mode determines how the colors of an object you draw are
|
|
||||||
/// mixed with the colors that are already in the buffer.
|
|
||||||
///
|
|
||||||
/// The class is composed of 6 components, each of which has its
|
|
||||||
/// own public member variable:
|
|
||||||
/// \li %Color Source Factor (@ref colorSrcFactor)
|
|
||||||
/// \li %Color Destination Factor (@ref colorDstFactor)
|
|
||||||
/// \li %Color Blend Equation (@ref colorEquation)
|
|
||||||
/// \li Alpha Source Factor (@ref alphaSrcFactor)
|
|
||||||
/// \li Alpha Destination Factor (@ref alphaDstFactor)
|
|
||||||
/// \li Alpha Blend Equation (@ref alphaEquation)
|
|
||||||
///
|
|
||||||
/// The source factor specifies how the pixel you are drawing contributes
|
|
||||||
/// to the final color. The destination factor specifies how the pixel
|
|
||||||
/// already drawn in the buffer contributes to the final color.
|
|
||||||
///
|
|
||||||
/// The color channels RGB (red, green, blue; simply referred to as
|
|
||||||
/// color) and A (alpha; the transparency) can be treated separately. This
|
|
||||||
/// separation can be useful for specific blend modes, but most often you
|
|
||||||
/// won't need it and will simply treat the color as a single unit.
|
|
||||||
///
|
|
||||||
/// The blend factors and equations correspond to their OpenGL equivalents.
|
|
||||||
/// In general, the color of the resulting pixel is calculated according
|
|
||||||
/// to the following formula (\a src is the color of the source pixel, \a dst
|
|
||||||
/// the color of the destination pixel, the other variables correspond to the
|
|
||||||
/// public members, with the equations being + or - operators):
|
|
||||||
/// \code
|
|
||||||
/// dst.rgb = colorSrcFactor * src.rgb (colorEquation) colorDstFactor * dst.rgb
|
|
||||||
/// dst.a = alphaSrcFactor * src.a (alphaEquation) alphaDstFactor * dst.a
|
|
||||||
/// \endcode
|
|
||||||
/// All factors and colors are represented as floating point numbers between
|
|
||||||
/// 0 and 1. Where necessary, the result is clamped to fit in that range.
|
|
||||||
///
|
|
||||||
/// The most common blending modes are defined as constants
|
|
||||||
/// in the sf namespace:
|
|
||||||
///
|
|
||||||
/// \code
|
|
||||||
/// sf::BlendMode alphaBlending = sf::BlendAlpha;
|
|
||||||
/// sf::BlendMode additiveBlending = sf::BlendAdd;
|
|
||||||
/// sf::BlendMode multiplicativeBlending = sf::BlendMultipy;
|
|
||||||
/// sf::BlendMode noBlending = sf::BlendNone;
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// In SFML, a blend mode can be specified every time you draw a sf::Drawable
|
|
||||||
/// object to a render target. It is part of the sf::RenderStates compound
|
|
||||||
/// that is passed to the member function sf::RenderTarget::draw().
|
|
||||||
///
|
|
||||||
/// \see sf::RenderStates, sf::RenderTarget
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,154 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_CIRCLESHAPE_HPP
|
|
||||||
#define SFML_CIRCLESHAPE_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Graphics/Export.hpp>
|
|
||||||
#include <SFML/Graphics/Shape.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Specialized shape representing a circle
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_GRAPHICS_API CircleShape : public Shape
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
/// \param radius Radius of the circle
|
|
||||||
/// \param pointCount Number of points composing the circle
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
explicit CircleShape(float radius = 0, std::size_t pointCount = 30);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the radius of the circle
|
|
||||||
///
|
|
||||||
/// \param radius New radius of the circle
|
|
||||||
///
|
|
||||||
/// \see getRadius
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setRadius(float radius);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the radius of the circle
|
|
||||||
///
|
|
||||||
/// \return Radius of the circle
|
|
||||||
///
|
|
||||||
/// \see setRadius
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
float getRadius() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the number of points of the circle
|
|
||||||
///
|
|
||||||
/// \param count New number of points of the circle
|
|
||||||
///
|
|
||||||
/// \see getPointCount
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setPointCount(std::size_t count);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the number of points of the circle
|
|
||||||
///
|
|
||||||
/// \return Number of points of the circle
|
|
||||||
///
|
|
||||||
/// \see setPointCount
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual std::size_t getPointCount() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get a point of the circle
|
|
||||||
///
|
|
||||||
/// The returned point is in local coordinates, that is,
|
|
||||||
/// the shape's transforms (position, rotation, scale) are
|
|
||||||
/// not taken into account.
|
|
||||||
/// The result is undefined if \a index is out of the valid range.
|
|
||||||
///
|
|
||||||
/// \param index Index of the point to get, in range [0 .. getPointCount() - 1]
|
|
||||||
///
|
|
||||||
/// \return index-th point of the shape
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual Vector2f getPoint(std::size_t index) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
float m_radius; ///< Radius of the circle
|
|
||||||
std::size_t m_pointCount; ///< Number of points composing the circle
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_CIRCLESHAPE_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::CircleShape
|
|
||||||
/// \ingroup graphics
|
|
||||||
///
|
|
||||||
/// This class inherits all the functions of sf::Transformable
|
|
||||||
/// (position, rotation, scale, bounds, ...) as well as the
|
|
||||||
/// functions of sf::Shape (outline, color, texture, ...).
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// sf::CircleShape circle;
|
|
||||||
/// circle.setRadius(150);
|
|
||||||
/// circle.setOutlineColor(sf::Color::Red);
|
|
||||||
/// circle.setOutlineThickness(5);
|
|
||||||
/// circle.setPosition(10, 20);
|
|
||||||
/// ...
|
|
||||||
/// window.draw(circle);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// Since the graphics card can't draw perfect circles, we have to
|
|
||||||
/// fake them with multiple triangles connected to each other. The
|
|
||||||
/// "points count" property of sf::CircleShape defines how many of these
|
|
||||||
/// triangles to use, and therefore defines the quality of the circle.
|
|
||||||
///
|
|
||||||
/// The number of points can also be used for another purpose; with
|
|
||||||
/// small numbers you can create any regular polygon shape:
|
|
||||||
/// equilateral triangle, square, pentagon, hexagon, ...
|
|
||||||
///
|
|
||||||
/// \see sf::Shape, sf::RectangleShape, sf::ConvexShape
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,275 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_COLOR_HPP
|
|
||||||
#define SFML_COLOR_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Graphics/Export.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Utility class for manipulating RGBA colors
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_GRAPHICS_API Color
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
/// Constructs an opaque black color. It is equivalent to
|
|
||||||
/// sf::Color(0, 0, 0, 255).
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Color();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Construct the color from its 4 RGBA components
|
|
||||||
///
|
|
||||||
/// \param red Red component (in the range [0, 255])
|
|
||||||
/// \param green Green component (in the range [0, 255])
|
|
||||||
/// \param blue Blue component (in the range [0, 255])
|
|
||||||
/// \param alpha Alpha (opacity) component (in the range [0, 255])
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Color(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha = 255);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Construct the color from 32-bit unsigned integer
|
|
||||||
///
|
|
||||||
/// \param color Number containing the RGBA components (in that order)
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
explicit Color(Uint32 color);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Retrieve the color as a 32-bit unsigned integer
|
|
||||||
///
|
|
||||||
/// \return Color represented as a 32-bit unsigned integer
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Uint32 toInteger() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Static member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static const Color Black; ///< Black predefined color
|
|
||||||
static const Color White; ///< White predefined color
|
|
||||||
static const Color Red; ///< Red predefined color
|
|
||||||
static const Color Green; ///< Green predefined color
|
|
||||||
static const Color Blue; ///< Blue predefined color
|
|
||||||
static const Color Yellow; ///< Yellow predefined color
|
|
||||||
static const Color Magenta; ///< Magenta predefined color
|
|
||||||
static const Color Cyan; ///< Cyan predefined color
|
|
||||||
static const Color Transparent; ///< Transparent (black) predefined color
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Uint8 r; ///< Red component
|
|
||||||
Uint8 g; ///< Green component
|
|
||||||
Uint8 b; ///< Blue component
|
|
||||||
Uint8 a; ///< Alpha (opacity) component
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \relates Color
|
|
||||||
/// \brief Overload of the == operator
|
|
||||||
///
|
|
||||||
/// This operator compares two colors and check if they are equal.
|
|
||||||
///
|
|
||||||
/// \param left Left operand
|
|
||||||
/// \param right Right operand
|
|
||||||
///
|
|
||||||
/// \return True if colors are equal, false if they are different
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SFML_GRAPHICS_API bool operator ==(const Color& left, const Color& right);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \relates Color
|
|
||||||
/// \brief Overload of the != operator
|
|
||||||
///
|
|
||||||
/// This operator compares two colors and check if they are different.
|
|
||||||
///
|
|
||||||
/// \param left Left operand
|
|
||||||
/// \param right Right operand
|
|
||||||
///
|
|
||||||
/// \return True if colors are different, false if they are equal
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SFML_GRAPHICS_API bool operator !=(const Color& left, const Color& right);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \relates Color
|
|
||||||
/// \brief Overload of the binary + operator
|
|
||||||
///
|
|
||||||
/// This operator returns the component-wise sum of two colors.
|
|
||||||
/// Components that exceed 255 are clamped to 255.
|
|
||||||
///
|
|
||||||
/// \param left Left operand
|
|
||||||
/// \param right Right operand
|
|
||||||
///
|
|
||||||
/// \return Result of \a left + \a right
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SFML_GRAPHICS_API Color operator +(const Color& left, const Color& right);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \relates Color
|
|
||||||
/// \brief Overload of the binary - operator
|
|
||||||
///
|
|
||||||
/// This operator returns the component-wise subtraction of two colors.
|
|
||||||
/// Components below 0 are clamped to 0.
|
|
||||||
///
|
|
||||||
/// \param left Left operand
|
|
||||||
/// \param right Right operand
|
|
||||||
///
|
|
||||||
/// \return Result of \a left - \a right
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SFML_GRAPHICS_API Color operator -(const Color& left, const Color& right);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \relates Color
|
|
||||||
/// \brief Overload of the binary * operator
|
|
||||||
///
|
|
||||||
/// This operator returns the component-wise multiplication
|
|
||||||
/// (also called "modulation") of two colors.
|
|
||||||
/// Components are then divided by 255 so that the result is
|
|
||||||
/// still in the range [0, 255].
|
|
||||||
///
|
|
||||||
/// \param left Left operand
|
|
||||||
/// \param right Right operand
|
|
||||||
///
|
|
||||||
/// \return Result of \a left * \a right
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SFML_GRAPHICS_API Color operator *(const Color& left, const Color& right);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \relates Color
|
|
||||||
/// \brief Overload of the binary += operator
|
|
||||||
///
|
|
||||||
/// This operator computes the component-wise sum of two colors,
|
|
||||||
/// and assigns the result to the left operand.
|
|
||||||
/// Components that exceed 255 are clamped to 255.
|
|
||||||
///
|
|
||||||
/// \param left Left operand
|
|
||||||
/// \param right Right operand
|
|
||||||
///
|
|
||||||
/// \return Reference to \a left
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SFML_GRAPHICS_API Color& operator +=(Color& left, const Color& right);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \relates Color
|
|
||||||
/// \brief Overload of the binary -= operator
|
|
||||||
///
|
|
||||||
/// This operator computes the component-wise subtraction of two colors,
|
|
||||||
/// and assigns the result to the left operand.
|
|
||||||
/// Components below 0 are clamped to 0.
|
|
||||||
///
|
|
||||||
/// \param left Left operand
|
|
||||||
/// \param right Right operand
|
|
||||||
///
|
|
||||||
/// \return Reference to \a left
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SFML_GRAPHICS_API Color& operator -=(Color& left, const Color& right);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \relates Color
|
|
||||||
/// \brief Overload of the binary *= operator
|
|
||||||
///
|
|
||||||
/// This operator returns the component-wise multiplication
|
|
||||||
/// (also called "modulation") of two colors, and assigns
|
|
||||||
/// the result to the left operand.
|
|
||||||
/// Components are then divided by 255 so that the result is
|
|
||||||
/// still in the range [0, 255].
|
|
||||||
///
|
|
||||||
/// \param left Left operand
|
|
||||||
/// \param right Right operand
|
|
||||||
///
|
|
||||||
/// \return Reference to \a left
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SFML_GRAPHICS_API Color& operator *=(Color& left, const Color& right);
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_COLOR_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::Color
|
|
||||||
/// \ingroup graphics
|
|
||||||
///
|
|
||||||
/// sf::Color is a simple color class composed of 4 components:
|
|
||||||
/// \li Red
|
|
||||||
/// \li Green
|
|
||||||
/// \li Blue
|
|
||||||
/// \li Alpha (opacity)
|
|
||||||
///
|
|
||||||
/// Each component is a public member, an unsigned integer in
|
|
||||||
/// the range [0, 255]. Thus, colors can be constructed and
|
|
||||||
/// manipulated very easily:
|
|
||||||
///
|
|
||||||
/// \code
|
|
||||||
/// sf::Color color(255, 0, 0); // red
|
|
||||||
/// color.r = 0; // make it black
|
|
||||||
/// color.b = 128; // make it dark blue
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// The fourth component of colors, named "alpha", represents
|
|
||||||
/// the opacity of the color. A color with an alpha value of
|
|
||||||
/// 255 will be fully opaque, while an alpha value of 0 will
|
|
||||||
/// make a color fully transparent, whatever the value of the
|
|
||||||
/// other components is.
|
|
||||||
///
|
|
||||||
/// The most common colors are already defined as static variables:
|
|
||||||
/// \code
|
|
||||||
/// sf::Color black = sf::Color::Black;
|
|
||||||
/// sf::Color white = sf::Color::White;
|
|
||||||
/// sf::Color red = sf::Color::Red;
|
|
||||||
/// sf::Color green = sf::Color::Green;
|
|
||||||
/// sf::Color blue = sf::Color::Blue;
|
|
||||||
/// sf::Color yellow = sf::Color::Yellow;
|
|
||||||
/// sf::Color magenta = sf::Color::Magenta;
|
|
||||||
/// sf::Color cyan = sf::Color::Cyan;
|
|
||||||
/// sf::Color transparent = sf::Color::Transparent;
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// Colors can also be added and modulated (multiplied) using the
|
|
||||||
/// overloaded operators + and *.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,153 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_CONVEXSHAPE_HPP
|
|
||||||
#define SFML_CONVEXSHAPE_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Graphics/Export.hpp>
|
|
||||||
#include <SFML/Graphics/Shape.hpp>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Specialized shape representing a convex polygon
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_GRAPHICS_API ConvexShape : public Shape
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
/// \param pointCount Number of points of the polygon
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
explicit ConvexShape(std::size_t pointCount = 0);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the number of points of the polygon
|
|
||||||
///
|
|
||||||
/// \a count must be greater than 2 to define a valid shape.
|
|
||||||
///
|
|
||||||
/// \param count New number of points of the polygon
|
|
||||||
///
|
|
||||||
/// \see getPointCount
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setPointCount(std::size_t count);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the number of points of the polygon
|
|
||||||
///
|
|
||||||
/// \return Number of points of the polygon
|
|
||||||
///
|
|
||||||
/// \see setPointCount
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual std::size_t getPointCount() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the position of a point
|
|
||||||
///
|
|
||||||
/// Don't forget that the polygon must remain convex, and
|
|
||||||
/// the points need to stay ordered!
|
|
||||||
/// setPointCount must be called first in order to set the total
|
|
||||||
/// number of points. The result is undefined if \a index is out
|
|
||||||
/// of the valid range.
|
|
||||||
///
|
|
||||||
/// \param index Index of the point to change, in range [0 .. getPointCount() - 1]
|
|
||||||
/// \param point New position of the point
|
|
||||||
///
|
|
||||||
/// \see getPoint
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setPoint(std::size_t index, const Vector2f& point);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the position of a point
|
|
||||||
///
|
|
||||||
/// The returned point is in local coordinates, that is,
|
|
||||||
/// the shape's transforms (position, rotation, scale) are
|
|
||||||
/// not taken into account.
|
|
||||||
/// The result is undefined if \a index is out of the valid range.
|
|
||||||
///
|
|
||||||
/// \param index Index of the point to get, in range [0 .. getPointCount() - 1]
|
|
||||||
///
|
|
||||||
/// \return Position of the index-th point of the polygon
|
|
||||||
///
|
|
||||||
/// \see setPoint
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual Vector2f getPoint(std::size_t index) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
std::vector<Vector2f> m_points; ///< Points composing the convex polygon
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_CONVEXSHAPE_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::ConvexShape
|
|
||||||
/// \ingroup graphics
|
|
||||||
///
|
|
||||||
/// This class inherits all the functions of sf::Transformable
|
|
||||||
/// (position, rotation, scale, bounds, ...) as well as the
|
|
||||||
/// functions of sf::Shape (outline, color, texture, ...).
|
|
||||||
///
|
|
||||||
/// It is important to keep in mind that a convex shape must
|
|
||||||
/// always be... convex, otherwise it may not be drawn correctly.
|
|
||||||
/// Moreover, the points must be defined in order; using a random
|
|
||||||
/// order would result in an incorrect shape.
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// sf::ConvexShape polygon;
|
|
||||||
/// polygon.setPointCount(3);
|
|
||||||
/// polygon.setPoint(0, sf::Vector2f(0, 0));
|
|
||||||
/// polygon.setPoint(1, sf::Vector2f(0, 10));
|
|
||||||
/// polygon.setPoint(2, sf::Vector2f(25, 5));
|
|
||||||
/// polygon.setOutlineColor(sf::Color::Red);
|
|
||||||
/// polygon.setOutlineThickness(5);
|
|
||||||
/// polygon.setPosition(10, 20);
|
|
||||||
/// ...
|
|
||||||
/// window.draw(polygon);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \see sf::Shape, sf::RectangleShape, sf::CircleShape
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,126 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_DRAWABLE_HPP
|
|
||||||
#define SFML_DRAWABLE_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Graphics/Export.hpp>
|
|
||||||
#include <SFML/Graphics/RenderStates.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
class RenderTarget;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Abstract base class for objects that can be drawn
|
|
||||||
/// to a render target
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_GRAPHICS_API Drawable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Virtual destructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual ~Drawable() {}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
friend class RenderTarget;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Draw the object to a render target
|
|
||||||
///
|
|
||||||
/// This is a pure virtual function that has to be implemented
|
|
||||||
/// by the derived class to define how the drawable should be
|
|
||||||
/// drawn.
|
|
||||||
///
|
|
||||||
/// \param target Render target to draw to
|
|
||||||
/// \param states Current render states
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual void draw(RenderTarget& target, RenderStates states) const = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_DRAWABLE_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::Drawable
|
|
||||||
/// \ingroup graphics
|
|
||||||
///
|
|
||||||
/// sf::Drawable is a very simple base class that allows objects
|
|
||||||
/// of derived classes to be drawn to a sf::RenderTarget.
|
|
||||||
///
|
|
||||||
/// All you have to do in your derived class is to override the
|
|
||||||
/// draw virtual function.
|
|
||||||
///
|
|
||||||
/// Note that inheriting from sf::Drawable is not mandatory,
|
|
||||||
/// but it allows this nice syntax "window.draw(object)" rather
|
|
||||||
/// than "object.draw(window)", which is more consistent with other
|
|
||||||
/// SFML classes.
|
|
||||||
///
|
|
||||||
/// Example:
|
|
||||||
/// \code
|
|
||||||
/// class MyDrawable : public sf::Drawable
|
|
||||||
/// {
|
|
||||||
/// public:
|
|
||||||
///
|
|
||||||
/// ...
|
|
||||||
///
|
|
||||||
/// private:
|
|
||||||
///
|
|
||||||
/// virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
|
|
||||||
/// {
|
|
||||||
/// // You can draw other high-level objects
|
|
||||||
/// target.draw(m_sprite, states);
|
|
||||||
///
|
|
||||||
/// // ... or use the low-level API
|
|
||||||
/// states.texture = &m_texture;
|
|
||||||
/// target.draw(m_vertices, states);
|
|
||||||
///
|
|
||||||
/// // ... or draw with OpenGL directly
|
|
||||||
/// glBegin(GL_QUADS);
|
|
||||||
/// ...
|
|
||||||
/// glEnd();
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// sf::Sprite m_sprite;
|
|
||||||
/// sf::Texture m_texture;
|
|
||||||
/// sf::VertexArray m_vertices;
|
|
||||||
/// };
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \see sf::RenderTarget
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,48 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_GRAPHICS_EXPORT_HPP
|
|
||||||
#define SFML_GRAPHICS_EXPORT_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Config.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Define portable import / export macros
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#if defined(SFML_GRAPHICS_EXPORTS)
|
|
||||||
|
|
||||||
#define SFML_GRAPHICS_API SFML_API_EXPORT
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
#define SFML_GRAPHICS_API SFML_API_IMPORT
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_GRAPHICS_EXPORT_HPP
|
|
@ -1,433 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_FONT_HPP
|
|
||||||
#define SFML_FONT_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Graphics/Export.hpp>
|
|
||||||
#include <SFML/Graphics/Glyph.hpp>
|
|
||||||
#include <SFML/Graphics/Texture.hpp>
|
|
||||||
#include <SFML/Graphics/Rect.hpp>
|
|
||||||
#include <SFML/System/Vector2.hpp>
|
|
||||||
#include <SFML/System/String.hpp>
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
class InputStream;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Class for loading and manipulating character fonts
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_GRAPHICS_API Font
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Holds various information about a font
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
struct Info
|
|
||||||
{
|
|
||||||
std::string family; ///< The font family
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
/// This constructor defines an empty font
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Font();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Copy constructor
|
|
||||||
///
|
|
||||||
/// \param copy Instance to copy
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Font(const Font& copy);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Destructor
|
|
||||||
///
|
|
||||||
/// Cleans up all the internal resources used by the font
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
~Font();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Load the font from a file
|
|
||||||
///
|
|
||||||
/// The supported font formats are: TrueType, Type 1, CFF,
|
|
||||||
/// OpenType, SFNT, X11 PCF, Windows FNT, BDF, PFR and Type 42.
|
|
||||||
/// Note that this function know nothing about the standard
|
|
||||||
/// fonts installed on the user's system, thus you can't
|
|
||||||
/// load them directly.
|
|
||||||
///
|
|
||||||
/// \warning SFML cannot preload all the font data in this
|
|
||||||
/// function, so the file has to remain accessible until
|
|
||||||
/// the sf::Font object loads a new font or is destroyed.
|
|
||||||
///
|
|
||||||
/// \param filename Path of the font file to load
|
|
||||||
///
|
|
||||||
/// \return True if loading succeeded, false if it failed
|
|
||||||
///
|
|
||||||
/// \see loadFromMemory, loadFromStream
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool loadFromFile(const std::string& filename);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Load the font from a file in memory
|
|
||||||
///
|
|
||||||
/// The supported font formats are: TrueType, Type 1, CFF,
|
|
||||||
/// OpenType, SFNT, X11 PCF, Windows FNT, BDF, PFR and Type 42.
|
|
||||||
///
|
|
||||||
/// \warning SFML cannot preload all the font data in this
|
|
||||||
/// function, so the buffer pointed by \a data has to remain
|
|
||||||
/// valid until the sf::Font object loads a new font or
|
|
||||||
/// is destroyed.
|
|
||||||
///
|
|
||||||
/// \param data Pointer to the file data in memory
|
|
||||||
/// \param sizeInBytes Size of the data to load, in bytes
|
|
||||||
///
|
|
||||||
/// \return True if loading succeeded, false if it failed
|
|
||||||
///
|
|
||||||
/// \see loadFromFile, loadFromStream
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool loadFromMemory(const void* data, std::size_t sizeInBytes);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Load the font from a custom stream
|
|
||||||
///
|
|
||||||
/// The supported font formats are: TrueType, Type 1, CFF,
|
|
||||||
/// OpenType, SFNT, X11 PCF, Windows FNT, BDF, PFR and Type 42.
|
|
||||||
/// Warning: SFML cannot preload all the font data in this
|
|
||||||
/// function, so the contents of \a stream have to remain
|
|
||||||
/// valid as long as the font is used.
|
|
||||||
///
|
|
||||||
/// \warning SFML cannot preload all the font data in this
|
|
||||||
/// function, so the stream has to remain accessible until
|
|
||||||
/// the sf::Font object loads a new font or is destroyed.
|
|
||||||
///
|
|
||||||
/// \param stream Source stream to read from
|
|
||||||
///
|
|
||||||
/// \return True if loading succeeded, false if it failed
|
|
||||||
///
|
|
||||||
/// \see loadFromFile, loadFromMemory
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool loadFromStream(InputStream& stream);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the font information
|
|
||||||
///
|
|
||||||
/// \return A structure that holds the font information
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const Info& getInfo() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Retrieve a glyph of the font
|
|
||||||
///
|
|
||||||
/// If the font is a bitmap font, not all character sizes
|
|
||||||
/// might be available. If the glyph is not available at the
|
|
||||||
/// requested size, an empty glyph is returned.
|
|
||||||
///
|
|
||||||
/// \param codePoint Unicode code point of the character to get
|
|
||||||
/// \param characterSize Reference character size
|
|
||||||
/// \param bold Retrieve the bold version or the regular one?
|
|
||||||
///
|
|
||||||
/// \return The glyph corresponding to \a codePoint and \a characterSize
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const Glyph& getGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the kerning offset of two glyphs
|
|
||||||
///
|
|
||||||
/// The kerning is an extra offset (negative) to apply between two
|
|
||||||
/// glyphs when rendering them, to make the pair look more "natural".
|
|
||||||
/// For example, the pair "AV" have a special kerning to make them
|
|
||||||
/// closer than other characters. Most of the glyphs pairs have a
|
|
||||||
/// kerning offset of zero, though.
|
|
||||||
///
|
|
||||||
/// \param first Unicode code point of the first character
|
|
||||||
/// \param second Unicode code point of the second character
|
|
||||||
/// \param characterSize Reference character size
|
|
||||||
///
|
|
||||||
/// \return Kerning value for \a first and \a second, in pixels
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
float getKerning(Uint32 first, Uint32 second, unsigned int characterSize) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the line spacing
|
|
||||||
///
|
|
||||||
/// Line spacing is the vertical offset to apply between two
|
|
||||||
/// consecutive lines of text.
|
|
||||||
///
|
|
||||||
/// \param characterSize Reference character size
|
|
||||||
///
|
|
||||||
/// \return Line spacing, in pixels
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
float getLineSpacing(unsigned int characterSize) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the position of the underline
|
|
||||||
///
|
|
||||||
/// Underline position is the vertical offset to apply between the
|
|
||||||
/// baseline and the underline.
|
|
||||||
///
|
|
||||||
/// \param characterSize Reference character size
|
|
||||||
///
|
|
||||||
/// \return Underline position, in pixels
|
|
||||||
///
|
|
||||||
/// \see getUnderlineThickness
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
float getUnderlinePosition(unsigned int characterSize) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the thickness of the underline
|
|
||||||
///
|
|
||||||
/// Underline thickness is the vertical size of the underline.
|
|
||||||
///
|
|
||||||
/// \param characterSize Reference character size
|
|
||||||
///
|
|
||||||
/// \return Underline thickness, in pixels
|
|
||||||
///
|
|
||||||
/// \see getUnderlinePosition
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
float getUnderlineThickness(unsigned int characterSize) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Retrieve the texture containing the loaded glyphs of a certain size
|
|
||||||
///
|
|
||||||
/// The contents of the returned texture changes as more glyphs
|
|
||||||
/// are requested, thus it is not very relevant. It is mainly
|
|
||||||
/// used internally by sf::Text.
|
|
||||||
///
|
|
||||||
/// \param characterSize Reference character size
|
|
||||||
///
|
|
||||||
/// \return Texture containing the glyphs of the requested size
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const Texture& getTexture(unsigned int characterSize) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Overload of assignment operator
|
|
||||||
///
|
|
||||||
/// \param right Instance to assign
|
|
||||||
///
|
|
||||||
/// \return Reference to self
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Font& operator =(const Font& right);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Structure defining a row of glyphs
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
struct Row
|
|
||||||
{
|
|
||||||
Row(unsigned int rowTop, unsigned int rowHeight) : width(0), top(rowTop), height(rowHeight) {}
|
|
||||||
|
|
||||||
unsigned int width; ///< Current width of the row
|
|
||||||
unsigned int top; ///< Y position of the row into the texture
|
|
||||||
unsigned int height; ///< Height of the row
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Types
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
typedef std::map<Uint32, Glyph> GlyphTable; ///< Table mapping a codepoint to its glyph
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Structure defining a page of glyphs
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
struct Page
|
|
||||||
{
|
|
||||||
Page();
|
|
||||||
|
|
||||||
GlyphTable glyphs; ///< Table mapping code points to their corresponding glyph
|
|
||||||
Texture texture; ///< Texture containing the pixels of the glyphs
|
|
||||||
unsigned int nextRow; ///< Y position of the next new row in the texture
|
|
||||||
std::vector<Row> rows; ///< List containing the position of all the existing rows
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Free all the internal resources
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void cleanup();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Load a new glyph and store it in the cache
|
|
||||||
///
|
|
||||||
/// \param codePoint Unicode code point of the character to load
|
|
||||||
/// \param characterSize Reference character size
|
|
||||||
/// \param bold Retrieve the bold version or the regular one?
|
|
||||||
///
|
|
||||||
/// \return The glyph corresponding to \a codePoint and \a characterSize
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Glyph loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Find a suitable rectangle within the texture for a glyph
|
|
||||||
///
|
|
||||||
/// \param page Page of glyphs to search in
|
|
||||||
/// \param width Width of the rectangle
|
|
||||||
/// \param height Height of the rectangle
|
|
||||||
///
|
|
||||||
/// \return Found rectangle within the texture
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
IntRect findGlyphRect(Page& page, unsigned int width, unsigned int height) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Make sure that the given size is the current one
|
|
||||||
///
|
|
||||||
/// \param characterSize Reference character size
|
|
||||||
///
|
|
||||||
/// \return True on success, false if any error happened
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool setCurrentSize(unsigned int characterSize) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Types
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
typedef std::map<unsigned int, Page> PageTable; ///< Table mapping a character size to its page (texture)
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void* m_library; ///< Pointer to the internal library interface (it is typeless to avoid exposing implementation details)
|
|
||||||
void* m_face; ///< Pointer to the internal font face (it is typeless to avoid exposing implementation details)
|
|
||||||
void* m_streamRec; ///< Pointer to the stream rec instance (it is typeless to avoid exposing implementation details)
|
|
||||||
int* m_refCount; ///< Reference counter used by implicit sharing
|
|
||||||
Info m_info; ///< Information about the font
|
|
||||||
mutable PageTable m_pages; ///< Table containing the glyphs pages by character size
|
|
||||||
mutable std::vector<Uint8> m_pixelBuffer; ///< Pixel buffer holding a glyph's pixels before being written to the texture
|
|
||||||
#ifdef SFML_SYSTEM_ANDROID
|
|
||||||
void* m_stream; ///< Asset file streamer (if loaded from file)
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_FONT_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::Font
|
|
||||||
/// \ingroup graphics
|
|
||||||
///
|
|
||||||
/// Fonts can be loaded from a file, from memory or from a custom
|
|
||||||
/// stream, and supports the most common types of fonts. See
|
|
||||||
/// the loadFromFile function for the complete list of supported formats.
|
|
||||||
///
|
|
||||||
/// Once it is loaded, a sf::Font instance provides three
|
|
||||||
/// types of information about the font:
|
|
||||||
/// \li Global metrics, such as the line spacing
|
|
||||||
/// \li Per-glyph metrics, such as bounding box or kerning
|
|
||||||
/// \li Pixel representation of glyphs
|
|
||||||
///
|
|
||||||
/// Fonts alone are not very useful: they hold the font data
|
|
||||||
/// but cannot make anything useful of it. To do so you need to
|
|
||||||
/// use the sf::Text class, which is able to properly output text
|
|
||||||
/// with several options such as character size, style, color,
|
|
||||||
/// position, rotation, etc.
|
|
||||||
/// This separation allows more flexibility and better performances:
|
|
||||||
/// indeed a sf::Font is a heavy resource, and any operation on it
|
|
||||||
/// is slow (often too slow for real-time applications). On the other
|
|
||||||
/// side, a sf::Text is a lightweight object which can combine the
|
|
||||||
/// glyphs data and metrics of a sf::Font to display any text on a
|
|
||||||
/// render target.
|
|
||||||
/// Note that it is also possible to bind several sf::Text instances
|
|
||||||
/// to the same sf::Font.
|
|
||||||
///
|
|
||||||
/// It is important to note that the sf::Text instance doesn't
|
|
||||||
/// copy the font that it uses, it only keeps a reference to it.
|
|
||||||
/// Thus, a sf::Font must not be destructed while it is
|
|
||||||
/// used by a sf::Text (i.e. never write a function that
|
|
||||||
/// uses a local sf::Font instance for creating a text).
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// // Declare a new font
|
|
||||||
/// sf::Font font;
|
|
||||||
///
|
|
||||||
/// // Load it from a file
|
|
||||||
/// if (!font.loadFromFile("arial.ttf"))
|
|
||||||
/// {
|
|
||||||
/// // error...
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// // Create a text which uses our font
|
|
||||||
/// sf::Text text1;
|
|
||||||
/// text1.setFont(font);
|
|
||||||
/// text1.setCharacterSize(30);
|
|
||||||
/// text1.setStyle(sf::Text::Regular);
|
|
||||||
///
|
|
||||||
/// // Create another text using the same font, but with different parameters
|
|
||||||
/// sf::Text text2;
|
|
||||||
/// text2.setFont(font);
|
|
||||||
/// text2.setCharacterSize(50);
|
|
||||||
/// text2.setStyle(sf::Text::Italic);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// Apart from loading font files, and passing them to instances
|
|
||||||
/// of sf::Text, you should normally not have to deal directly
|
|
||||||
/// with this class. However, it may be useful to access the
|
|
||||||
/// font metrics or rasterized glyphs for advanced usage.
|
|
||||||
///
|
|
||||||
/// Note that if the font is a bitmap font, it is not scalable,
|
|
||||||
/// thus not all requested sizes will be available to use. This
|
|
||||||
/// needs to be taken into consideration when using sf::Text.
|
|
||||||
/// If you need to display text of a certain size, make sure the
|
|
||||||
/// corresponding bitmap font that supports that size is used.
|
|
||||||
///
|
|
||||||
/// \see sf::Text
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,79 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_GLYPH_HPP
|
|
||||||
#define SFML_GLYPH_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Graphics/Export.hpp>
|
|
||||||
#include <SFML/Graphics/Rect.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Structure describing a glyph
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_GRAPHICS_API Glyph
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Glyph() : advance(0) {}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
float advance; ///< Offset to move horizontally to the next character
|
|
||||||
FloatRect bounds; ///< Bounding rectangle of the glyph, in coordinates relative to the baseline
|
|
||||||
IntRect textureRect; ///< Texture coordinates of the glyph inside the font's texture
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_GLYPH_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::Glyph
|
|
||||||
/// \ingroup graphics
|
|
||||||
///
|
|
||||||
/// A glyph is the visual representation of a character.
|
|
||||||
///
|
|
||||||
/// The sf::Glyph structure provides the information needed
|
|
||||||
/// to handle the glyph:
|
|
||||||
/// \li its coordinates in the font's texture
|
|
||||||
/// \li its bounding rectangle
|
|
||||||
/// \li the offset to apply to get the starting position of the next glyph
|
|
||||||
///
|
|
||||||
/// \see sf::Font
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,327 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_IMAGE_HPP
|
|
||||||
#define SFML_IMAGE_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Graphics/Export.hpp>
|
|
||||||
#include <SFML/Graphics/Color.hpp>
|
|
||||||
#include <SFML/Graphics/Rect.hpp>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
class InputStream;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Class for loading, manipulating and saving images
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_GRAPHICS_API Image
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
/// Creates an empty image.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Image();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Destructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
~Image();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Create the image and fill it with a unique color
|
|
||||||
///
|
|
||||||
/// \param width Width of the image
|
|
||||||
/// \param height Height of the image
|
|
||||||
/// \param color Fill color
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void create(unsigned int width, unsigned int height, const Color& color = Color(0, 0, 0));
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Create the image from an array of pixels
|
|
||||||
///
|
|
||||||
/// The \a pixel array is assumed to contain 32-bits RGBA pixels,
|
|
||||||
/// and have the given \a width and \a height. If not, this is
|
|
||||||
/// an undefined behavior.
|
|
||||||
/// If \a pixels is null, an empty image is created.
|
|
||||||
///
|
|
||||||
/// \param width Width of the image
|
|
||||||
/// \param height Height of the image
|
|
||||||
/// \param pixels Array of pixels to copy to the image
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void create(unsigned int width, unsigned int height, const Uint8* pixels);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Load the image from a file on disk
|
|
||||||
///
|
|
||||||
/// The supported image formats are bmp, png, tga, jpg, gif,
|
|
||||||
/// psd, hdr and pic. Some format options are not supported,
|
|
||||||
/// like progressive jpeg.
|
|
||||||
/// If this function fails, the image is left unchanged.
|
|
||||||
///
|
|
||||||
/// \param filename Path of the image file to load
|
|
||||||
///
|
|
||||||
/// \return True if loading was successful
|
|
||||||
///
|
|
||||||
/// \see loadFromMemory, loadFromStream, saveToFile
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool loadFromFile(const std::string& filename);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Load the image from a file in memory
|
|
||||||
///
|
|
||||||
/// The supported image formats are bmp, png, tga, jpg, gif,
|
|
||||||
/// psd, hdr and pic. Some format options are not supported,
|
|
||||||
/// like progressive jpeg.
|
|
||||||
/// If this function fails, the image is left unchanged.
|
|
||||||
///
|
|
||||||
/// \param data Pointer to the file data in memory
|
|
||||||
/// \param size Size of the data to load, in bytes
|
|
||||||
///
|
|
||||||
/// \return True if loading was successful
|
|
||||||
///
|
|
||||||
/// \see loadFromFile, loadFromStream
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool loadFromMemory(const void* data, std::size_t size);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Load the image from a custom stream
|
|
||||||
///
|
|
||||||
/// The supported image formats are bmp, png, tga, jpg, gif,
|
|
||||||
/// psd, hdr and pic. Some format options are not supported,
|
|
||||||
/// like progressive jpeg.
|
|
||||||
/// If this function fails, the image is left unchanged.
|
|
||||||
///
|
|
||||||
/// \param stream Source stream to read from
|
|
||||||
///
|
|
||||||
/// \return True if loading was successful
|
|
||||||
///
|
|
||||||
/// \see loadFromFile, loadFromMemory
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool loadFromStream(InputStream& stream);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Save the image to a file on disk
|
|
||||||
///
|
|
||||||
/// The format of the image is automatically deduced from
|
|
||||||
/// the extension. The supported image formats are bmp, png,
|
|
||||||
/// tga and jpg. The destination file is overwritten
|
|
||||||
/// if it already exists. This function fails if the image is empty.
|
|
||||||
///
|
|
||||||
/// \param filename Path of the file to save
|
|
||||||
///
|
|
||||||
/// \return True if saving was successful
|
|
||||||
///
|
|
||||||
/// \see create, loadFromFile, loadFromMemory
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool saveToFile(const std::string& filename) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Return the size (width and height) of the image
|
|
||||||
///
|
|
||||||
/// \return Size of the image, in pixels
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Vector2u getSize() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Create a transparency mask from a specified color-key
|
|
||||||
///
|
|
||||||
/// This function sets the alpha value of every pixel matching
|
|
||||||
/// the given color to \a alpha (0 by default), so that they
|
|
||||||
/// become transparent.
|
|
||||||
///
|
|
||||||
/// \param color Color to make transparent
|
|
||||||
/// \param alpha Alpha value to assign to transparent pixels
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void createMaskFromColor(const Color& color, Uint8 alpha = 0);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Copy pixels from another image onto this one
|
|
||||||
///
|
|
||||||
/// This function does a slow pixel copy and should not be
|
|
||||||
/// used intensively. It can be used to prepare a complex
|
|
||||||
/// static image from several others, but if you need this
|
|
||||||
/// kind of feature in real-time you'd better use sf::RenderTexture.
|
|
||||||
///
|
|
||||||
/// If \a sourceRect is empty, the whole image is copied.
|
|
||||||
/// If \a applyAlpha is set to true, the transparency of
|
|
||||||
/// source pixels is applied. If it is false, the pixels are
|
|
||||||
/// copied unchanged with their alpha value.
|
|
||||||
///
|
|
||||||
/// \param source Source image to copy
|
|
||||||
/// \param destX X coordinate of the destination position
|
|
||||||
/// \param destY Y coordinate of the destination position
|
|
||||||
/// \param sourceRect Sub-rectangle of the source image to copy
|
|
||||||
/// \param applyAlpha Should the copy take into account the source transparency?
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void copy(const Image& source, unsigned int destX, unsigned int destY, const IntRect& sourceRect = IntRect(0, 0, 0, 0), bool applyAlpha = false);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Change the color of a pixel
|
|
||||||
///
|
|
||||||
/// This function doesn't check the validity of the pixel
|
|
||||||
/// coordinates, using out-of-range values will result in
|
|
||||||
/// an undefined behavior.
|
|
||||||
///
|
|
||||||
/// \param x X coordinate of pixel to change
|
|
||||||
/// \param y Y coordinate of pixel to change
|
|
||||||
/// \param color New color of the pixel
|
|
||||||
///
|
|
||||||
/// \see getPixel
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setPixel(unsigned int x, unsigned int y, const Color& color);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the color of a pixel
|
|
||||||
///
|
|
||||||
/// This function doesn't check the validity of the pixel
|
|
||||||
/// coordinates, using out-of-range values will result in
|
|
||||||
/// an undefined behavior.
|
|
||||||
///
|
|
||||||
/// \param x X coordinate of pixel to get
|
|
||||||
/// \param y Y coordinate of pixel to get
|
|
||||||
///
|
|
||||||
/// \return Color of the pixel at coordinates (x, y)
|
|
||||||
///
|
|
||||||
/// \see setPixel
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Color getPixel(unsigned int x, unsigned int y) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get a read-only pointer to the array of pixels
|
|
||||||
///
|
|
||||||
/// The returned value points to an array of RGBA pixels made of
|
|
||||||
/// 8 bits integers components. The size of the array is
|
|
||||||
/// width * height * 4 (getSize().x * getSize().y * 4).
|
|
||||||
/// Warning: the returned pointer may become invalid if you
|
|
||||||
/// modify the image, so you should never store it for too long.
|
|
||||||
/// If the image is empty, a null pointer is returned.
|
|
||||||
///
|
|
||||||
/// \return Read-only pointer to the array of pixels
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const Uint8* getPixelsPtr() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Flip the image horizontally (left <-> right)
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void flipHorizontally();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Flip the image vertically (top <-> bottom)
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void flipVertically();
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Vector2u m_size; ///< Image size
|
|
||||||
std::vector<Uint8> m_pixels; ///< Pixels of the image
|
|
||||||
#ifdef SFML_SYSTEM_ANDROID
|
|
||||||
void* m_stream; ///< Asset file streamer (if loaded from file)
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_IMAGE_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::Image
|
|
||||||
/// \ingroup graphics
|
|
||||||
///
|
|
||||||
/// sf::Image is an abstraction to manipulate images
|
|
||||||
/// as bidimensional arrays of pixels. The class provides
|
|
||||||
/// functions to load, read, write and save pixels, as well
|
|
||||||
/// as many other useful functions.
|
|
||||||
///
|
|
||||||
/// sf::Image can handle a unique internal representation of
|
|
||||||
/// pixels, which is RGBA 32 bits. This means that a pixel
|
|
||||||
/// must be composed of 8 bits red, green, blue and alpha
|
|
||||||
/// channels -- just like a sf::Color.
|
|
||||||
/// All the functions that return an array of pixels follow
|
|
||||||
/// this rule, and all parameters that you pass to sf::Image
|
|
||||||
/// functions (such as loadFromMemory) must use this
|
|
||||||
/// representation as well.
|
|
||||||
///
|
|
||||||
/// A sf::Image can be copied, but it is a heavy resource and
|
|
||||||
/// if possible you should always use [const] references to
|
|
||||||
/// pass or return them to avoid useless copies.
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// // Load an image file from a file
|
|
||||||
/// sf::Image background;
|
|
||||||
/// if (!background.loadFromFile("background.jpg"))
|
|
||||||
/// return -1;
|
|
||||||
///
|
|
||||||
/// // Create a 20x20 image filled with black color
|
|
||||||
/// sf::Image image;
|
|
||||||
/// image.create(20, 20, sf::Color::Black);
|
|
||||||
///
|
|
||||||
/// // Copy image1 on image2 at position (10, 10)
|
|
||||||
/// image.copy(background, 10, 10);
|
|
||||||
///
|
|
||||||
/// // Make the top-left pixel transparent
|
|
||||||
/// sf::Color color = image.getPixel(0, 0);
|
|
||||||
/// color.a = 0;
|
|
||||||
/// image.setPixel(0, 0, color);
|
|
||||||
///
|
|
||||||
/// // Save the image to a file
|
|
||||||
/// if (!image.saveToFile("result.png"))
|
|
||||||
/// return -1;
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \see sf::Texture
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,53 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_PRIMITIVETYPE_HPP
|
|
||||||
#define SFML_PRIMITIVETYPE_HPP
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \ingroup graphics
|
|
||||||
/// \brief Types of primitives that a sf::VertexArray can render
|
|
||||||
///
|
|
||||||
/// Points and lines have no area, therefore their thickness
|
|
||||||
/// will always be 1 pixel, regardless the current transform
|
|
||||||
/// and view.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
enum PrimitiveType
|
|
||||||
{
|
|
||||||
Points, ///< List of individual points
|
|
||||||
Lines, ///< List of individual lines
|
|
||||||
LinesStrip, ///< List of connected lines, a point uses the previous point to form a line
|
|
||||||
Triangles, ///< List of individual triangles
|
|
||||||
TrianglesStrip, ///< List of connected triangles, a point uses the two previous points to form a triangle
|
|
||||||
TrianglesFan, ///< List of connected triangles, a point uses the common center and the previous point to form a triangle
|
|
||||||
Quads ///< List of individual quads (deprecated, don't work with OpenGL ES)
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_PRIMITIVETYPE_HPP
|
|
@ -1,248 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_RECT_HPP
|
|
||||||
#define SFML_RECT_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/System/Vector2.hpp>
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Utility class for manipulating 2D axis aligned rectangles
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
template <typename T>
|
|
||||||
class Rect
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
/// Creates an empty rectangle (it is equivalent to calling
|
|
||||||
/// Rect(0, 0, 0, 0)).
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Rect();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Construct the rectangle from its coordinates
|
|
||||||
///
|
|
||||||
/// Be careful, the last two parameters are the width
|
|
||||||
/// and height, not the right and bottom coordinates!
|
|
||||||
///
|
|
||||||
/// \param rectLeft Left coordinate of the rectangle
|
|
||||||
/// \param rectTop Top coordinate of the rectangle
|
|
||||||
/// \param rectWidth Width of the rectangle
|
|
||||||
/// \param rectHeight Height of the rectangle
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Rect(T rectLeft, T rectTop, T rectWidth, T rectHeight);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Construct the rectangle from position and size
|
|
||||||
///
|
|
||||||
/// Be careful, the last parameter is the size,
|
|
||||||
/// not the bottom-right corner!
|
|
||||||
///
|
|
||||||
/// \param position Position of the top-left corner of the rectangle
|
|
||||||
/// \param size Size of the rectangle
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Rect(const Vector2<T>& position, const Vector2<T>& size);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Construct the rectangle from another type of rectangle
|
|
||||||
///
|
|
||||||
/// This constructor doesn't replace the copy constructor,
|
|
||||||
/// it's called only when U != T.
|
|
||||||
/// A call to this constructor will fail to compile if U
|
|
||||||
/// is not convertible to T.
|
|
||||||
///
|
|
||||||
/// \param rectangle Rectangle to convert
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
template <typename U>
|
|
||||||
explicit Rect(const Rect<U>& rectangle);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Check if a point is inside the rectangle's area
|
|
||||||
///
|
|
||||||
/// \param x X coordinate of the point to test
|
|
||||||
/// \param y Y coordinate of the point to test
|
|
||||||
///
|
|
||||||
/// \return True if the point is inside, false otherwise
|
|
||||||
///
|
|
||||||
/// \see intersects
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool contains(T x, T y) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Check if a point is inside the rectangle's area
|
|
||||||
///
|
|
||||||
/// \param point Point to test
|
|
||||||
///
|
|
||||||
/// \return True if the point is inside, false otherwise
|
|
||||||
///
|
|
||||||
/// \see intersects
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool contains(const Vector2<T>& point) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Check the intersection between two rectangles
|
|
||||||
///
|
|
||||||
/// \param rectangle Rectangle to test
|
|
||||||
///
|
|
||||||
/// \return True if rectangles overlap, false otherwise
|
|
||||||
///
|
|
||||||
/// \see contains
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool intersects(const Rect<T>& rectangle) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Check the intersection between two rectangles
|
|
||||||
///
|
|
||||||
/// This overload returns the overlapped rectangle in the
|
|
||||||
/// \a intersection parameter.
|
|
||||||
///
|
|
||||||
/// \param rectangle Rectangle to test
|
|
||||||
/// \param intersection Rectangle to be filled with the intersection
|
|
||||||
///
|
|
||||||
/// \return True if rectangles overlap, false otherwise
|
|
||||||
///
|
|
||||||
/// \see contains
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool intersects(const Rect<T>& rectangle, Rect<T>& intersection) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
T left; ///< Left coordinate of the rectangle
|
|
||||||
T top; ///< Top coordinate of the rectangle
|
|
||||||
T width; ///< Width of the rectangle
|
|
||||||
T height; ///< Height of the rectangle
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \relates Rect
|
|
||||||
/// \brief Overload of binary operator ==
|
|
||||||
///
|
|
||||||
/// This operator compares strict equality between two rectangles.
|
|
||||||
///
|
|
||||||
/// \param left Left operand (a rectangle)
|
|
||||||
/// \param right Right operand (a rectangle)
|
|
||||||
///
|
|
||||||
/// \return True if \a left is equal to \a right
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
template <typename T>
|
|
||||||
bool operator ==(const Rect<T>& left, const Rect<T>& right);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \relates Rect
|
|
||||||
/// \brief Overload of binary operator !=
|
|
||||||
///
|
|
||||||
/// This operator compares strict difference between two rectangles.
|
|
||||||
///
|
|
||||||
/// \param left Left operand (a rectangle)
|
|
||||||
/// \param right Right operand (a rectangle)
|
|
||||||
///
|
|
||||||
/// \return True if \a left is not equal to \a right
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
template <typename T>
|
|
||||||
bool operator !=(const Rect<T>& left, const Rect<T>& right);
|
|
||||||
|
|
||||||
#include <SFML/Graphics/Rect.inl>
|
|
||||||
|
|
||||||
// Create typedefs for the most common types
|
|
||||||
typedef Rect<int> IntRect;
|
|
||||||
typedef Rect<float> FloatRect;
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_RECT_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::Rect
|
|
||||||
/// \ingroup graphics
|
|
||||||
///
|
|
||||||
/// A rectangle is defined by its top-left corner and its size.
|
|
||||||
/// It is a very simple class defined for convenience, so
|
|
||||||
/// its member variables (left, top, width and height) are public
|
|
||||||
/// and can be accessed directly, just like the vector classes
|
|
||||||
/// (Vector2 and Vector3).
|
|
||||||
///
|
|
||||||
/// To keep things simple, sf::Rect doesn't define
|
|
||||||
/// functions to emulate the properties that are not directly
|
|
||||||
/// members (such as right, bottom, center, etc.), it rather
|
|
||||||
/// only provides intersection functions.
|
|
||||||
///
|
|
||||||
/// sf::Rect uses the usual rules for its boundaries:
|
|
||||||
/// \li The left and top edges are included in the rectangle's area
|
|
||||||
/// \li The right (left + width) and bottom (top + height) edges are excluded from the rectangle's area
|
|
||||||
///
|
|
||||||
/// This means that sf::IntRect(0, 0, 1, 1) and sf::IntRect(1, 1, 1, 1)
|
|
||||||
/// don't intersect.
|
|
||||||
///
|
|
||||||
/// sf::Rect is a template and may be used with any numeric type, but
|
|
||||||
/// for simplicity the instantiations used by SFML are typedef'd:
|
|
||||||
/// \li sf::Rect<int> is sf::IntRect
|
|
||||||
/// \li sf::Rect<float> is sf::FloatRect
|
|
||||||
///
|
|
||||||
/// So that you don't have to care about the template syntax.
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// // Define a rectangle, located at (0, 0) with a size of 20x5
|
|
||||||
/// sf::IntRect r1(0, 0, 20, 5);
|
|
||||||
///
|
|
||||||
/// // Define another rectangle, located at (4, 2) with a size of 18x10
|
|
||||||
/// sf::Vector2i position(4, 2);
|
|
||||||
/// sf::Vector2i size(18, 10);
|
|
||||||
/// sf::IntRect r2(position, size);
|
|
||||||
///
|
|
||||||
/// // Test intersections with the point (3, 1)
|
|
||||||
/// bool b1 = r1.contains(3, 1); // true
|
|
||||||
/// bool b2 = r2.contains(3, 1); // false
|
|
||||||
///
|
|
||||||
/// // Test the intersection between r1 and r2
|
|
||||||
/// sf::IntRect result;
|
|
||||||
/// bool b3 = r1.intersects(r2, result); // true
|
|
||||||
/// // result == (4, 2, 16, 3)
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,159 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
template <typename T>
|
|
||||||
Rect<T>::Rect() :
|
|
||||||
left (0),
|
|
||||||
top (0),
|
|
||||||
width (0),
|
|
||||||
height(0)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
template <typename T>
|
|
||||||
Rect<T>::Rect(T rectLeft, T rectTop, T rectWidth, T rectHeight) :
|
|
||||||
left (rectLeft),
|
|
||||||
top (rectTop),
|
|
||||||
width (rectWidth),
|
|
||||||
height(rectHeight)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
template <typename T>
|
|
||||||
Rect<T>::Rect(const Vector2<T>& position, const Vector2<T>& size) :
|
|
||||||
left (position.x),
|
|
||||||
top (position.y),
|
|
||||||
width (size.x),
|
|
||||||
height(size.y)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
template <typename T>
|
|
||||||
template <typename U>
|
|
||||||
Rect<T>::Rect(const Rect<U>& rectangle) :
|
|
||||||
left (static_cast<T>(rectangle.left)),
|
|
||||||
top (static_cast<T>(rectangle.top)),
|
|
||||||
width (static_cast<T>(rectangle.width)),
|
|
||||||
height(static_cast<T>(rectangle.height))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
template <typename T>
|
|
||||||
bool Rect<T>::contains(T x, T y) const
|
|
||||||
{
|
|
||||||
// Rectangles with negative dimensions are allowed, so we must handle them correctly
|
|
||||||
|
|
||||||
// Compute the real min and max of the rectangle on both axes
|
|
||||||
T minX = std::min(left, static_cast<T>(left + width));
|
|
||||||
T maxX = std::max(left, static_cast<T>(left + width));
|
|
||||||
T minY = std::min(top, static_cast<T>(top + height));
|
|
||||||
T maxY = std::max(top, static_cast<T>(top + height));
|
|
||||||
|
|
||||||
return (x >= minX) && (x < maxX) && (y >= minY) && (y < maxY);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
template <typename T>
|
|
||||||
bool Rect<T>::contains(const Vector2<T>& point) const
|
|
||||||
{
|
|
||||||
return contains(point.x, point.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
template <typename T>
|
|
||||||
bool Rect<T>::intersects(const Rect<T>& rectangle) const
|
|
||||||
{
|
|
||||||
Rect<T> intersection;
|
|
||||||
return intersects(rectangle, intersection);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
template <typename T>
|
|
||||||
bool Rect<T>::intersects(const Rect<T>& rectangle, Rect<T>& intersection) const
|
|
||||||
{
|
|
||||||
// Rectangles with negative dimensions are allowed, so we must handle them correctly
|
|
||||||
|
|
||||||
// Compute the min and max of the first rectangle on both axes
|
|
||||||
T r1MinX = std::min(left, static_cast<T>(left + width));
|
|
||||||
T r1MaxX = std::max(left, static_cast<T>(left + width));
|
|
||||||
T r1MinY = std::min(top, static_cast<T>(top + height));
|
|
||||||
T r1MaxY = std::max(top, static_cast<T>(top + height));
|
|
||||||
|
|
||||||
// Compute the min and max of the second rectangle on both axes
|
|
||||||
T r2MinX = std::min(rectangle.left, static_cast<T>(rectangle.left + rectangle.width));
|
|
||||||
T r2MaxX = std::max(rectangle.left, static_cast<T>(rectangle.left + rectangle.width));
|
|
||||||
T r2MinY = std::min(rectangle.top, static_cast<T>(rectangle.top + rectangle.height));
|
|
||||||
T r2MaxY = std::max(rectangle.top, static_cast<T>(rectangle.top + rectangle.height));
|
|
||||||
|
|
||||||
// Compute the intersection boundaries
|
|
||||||
T interLeft = std::max(r1MinX, r2MinX);
|
|
||||||
T interTop = std::max(r1MinY, r2MinY);
|
|
||||||
T interRight = std::min(r1MaxX, r2MaxX);
|
|
||||||
T interBottom = std::min(r1MaxY, r2MaxY);
|
|
||||||
|
|
||||||
// If the intersection is valid (positive non zero area), then there is an intersection
|
|
||||||
if ((interLeft < interRight) && (interTop < interBottom))
|
|
||||||
{
|
|
||||||
intersection = Rect<T>(interLeft, interTop, interRight - interLeft, interBottom - interTop);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
intersection = Rect<T>(0, 0, 0, 0);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
template <typename T>
|
|
||||||
inline bool operator ==(const Rect<T>& left, const Rect<T>& right)
|
|
||||||
{
|
|
||||||
return (left.left == right.left) && (left.width == right.width) &&
|
|
||||||
(left.top == right.top) && (left.height == right.height);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
template <typename T>
|
|
||||||
inline bool operator !=(const Rect<T>& left, const Rect<T>& right)
|
|
||||||
{
|
|
||||||
return !(left == right);
|
|
||||||
}
|
|
@ -1,132 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_RECTANGLESHAPE_HPP
|
|
||||||
#define SFML_RECTANGLESHAPE_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Graphics/Export.hpp>
|
|
||||||
#include <SFML/Graphics/Shape.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Specialized shape representing a rectangle
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_GRAPHICS_API RectangleShape : public Shape
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
/// \param size Size of the rectangle
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
explicit RectangleShape(const Vector2f& size = Vector2f(0, 0));
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the size of the rectangle
|
|
||||||
///
|
|
||||||
/// \param size New size of the rectangle
|
|
||||||
///
|
|
||||||
/// \see getSize
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setSize(const Vector2f& size);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the size of the rectangle
|
|
||||||
///
|
|
||||||
/// \return Size of the rectangle
|
|
||||||
///
|
|
||||||
/// \see setSize
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const Vector2f& getSize() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the number of points defining the shape
|
|
||||||
///
|
|
||||||
/// \return Number of points of the shape. For rectangle
|
|
||||||
/// shapes, this number is always 4.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual std::size_t getPointCount() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get a point of the rectangle
|
|
||||||
///
|
|
||||||
/// The returned point is in local coordinates, that is,
|
|
||||||
/// the shape's transforms (position, rotation, scale) are
|
|
||||||
/// not taken into account.
|
|
||||||
/// The result is undefined if \a index is out of the valid range.
|
|
||||||
///
|
|
||||||
/// \param index Index of the point to get, in range [0 .. 3]
|
|
||||||
///
|
|
||||||
/// \return index-th point of the shape
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual Vector2f getPoint(std::size_t index) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Vector2f m_size; ///< Size of the rectangle
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_RECTANGLESHAPE_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::RectangleShape
|
|
||||||
/// \ingroup graphics
|
|
||||||
///
|
|
||||||
/// This class inherits all the functions of sf::Transformable
|
|
||||||
/// (position, rotation, scale, bounds, ...) as well as the
|
|
||||||
/// functions of sf::Shape (outline, color, texture, ...).
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// sf::RectangleShape rectangle;
|
|
||||||
/// rectangle.setSize(sf::Vector2f(100, 50));
|
|
||||||
/// rectangle.setOutlineColor(sf::Color::Red);
|
|
||||||
/// rectangle.setOutlineThickness(5);
|
|
||||||
/// rectangle.setPosition(10, 20);
|
|
||||||
/// ...
|
|
||||||
/// window.draw(rectangle);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \see sf::Shape, sf::CircleShape, sf::ConvexShape
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,174 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_RENDERSTATES_HPP
|
|
||||||
#define SFML_RENDERSTATES_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Graphics/Export.hpp>
|
|
||||||
#include <SFML/Graphics/BlendMode.hpp>
|
|
||||||
#include <SFML/Graphics/Transform.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
class Shader;
|
|
||||||
class Texture;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Define the states used for drawing to a RenderTarget
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_GRAPHICS_API RenderStates
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
/// Constructing a default set of render states is equivalent
|
|
||||||
/// to using sf::RenderStates::Default.
|
|
||||||
/// The default set defines:
|
|
||||||
/// \li the BlendAlpha blend mode
|
|
||||||
/// \li the identity transform
|
|
||||||
/// \li a null texture
|
|
||||||
/// \li a null shader
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
RenderStates();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Construct a default set of render states with a custom blend mode
|
|
||||||
///
|
|
||||||
/// \param theBlendMode Blend mode to use
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
RenderStates(const BlendMode& theBlendMode);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Construct a default set of render states with a custom transform
|
|
||||||
///
|
|
||||||
/// \param theTransform Transform to use
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
RenderStates(const Transform& theTransform);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Construct a default set of render states with a custom texture
|
|
||||||
///
|
|
||||||
/// \param theTexture Texture to use
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
RenderStates(const Texture* theTexture);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Construct a default set of render states with a custom shader
|
|
||||||
///
|
|
||||||
/// \param theShader Shader to use
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
RenderStates(const Shader* theShader);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Construct a set of render states with all its attributes
|
|
||||||
///
|
|
||||||
/// \param theBlendMode Blend mode to use
|
|
||||||
/// \param theTransform Transform to use
|
|
||||||
/// \param theTexture Texture to use
|
|
||||||
/// \param theShader Shader to use
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
RenderStates(const BlendMode& theBlendMode, const Transform& theTransform,
|
|
||||||
const Texture* theTexture, const Shader* theShader);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Static member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static const RenderStates Default; ///< Special instance holding the default render states
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
BlendMode blendMode; ///< Blending mode
|
|
||||||
Transform transform; ///< Transform
|
|
||||||
const Texture* texture; ///< Texture
|
|
||||||
const Shader* shader; ///< Shader
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_RENDERSTATES_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::RenderStates
|
|
||||||
/// \ingroup graphics
|
|
||||||
///
|
|
||||||
/// There are four global states that can be applied to
|
|
||||||
/// the drawn objects:
|
|
||||||
/// \li the blend mode: how pixels of the object are blended with the background
|
|
||||||
/// \li the transform: how the object is positioned/rotated/scaled
|
|
||||||
/// \li the texture: what image is mapped to the object
|
|
||||||
/// \li the shader: what custom effect is applied to the object
|
|
||||||
///
|
|
||||||
/// High-level objects such as sprites or text force some of
|
|
||||||
/// these states when they are drawn. For example, a sprite
|
|
||||||
/// will set its own texture, so that you don't have to care
|
|
||||||
/// about it when drawing the sprite.
|
|
||||||
///
|
|
||||||
/// The transform is a special case: sprites, texts and shapes
|
|
||||||
/// (and it's a good idea to do it with your own drawable classes
|
|
||||||
/// too) combine their transform with the one that is passed in the
|
|
||||||
/// RenderStates structure. So that you can use a "global" transform
|
|
||||||
/// on top of each object's transform.
|
|
||||||
///
|
|
||||||
/// Most objects, especially high-level drawables, can be drawn
|
|
||||||
/// directly without defining render states explicitly -- the
|
|
||||||
/// default set of states is ok in most cases.
|
|
||||||
/// \code
|
|
||||||
/// window.draw(sprite);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// If you want to use a single specific render state,
|
|
||||||
/// for example a shader, you can pass it directly to the Draw
|
|
||||||
/// function: sf::RenderStates has an implicit one-argument
|
|
||||||
/// constructor for each state.
|
|
||||||
/// \code
|
|
||||||
/// window.draw(sprite, shader);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// When you're inside the Draw function of a drawable
|
|
||||||
/// object (inherited from sf::Drawable), you can
|
|
||||||
/// either pass the render states unmodified, or change
|
|
||||||
/// some of them.
|
|
||||||
/// For example, a transformable object will combine the
|
|
||||||
/// current transform with its own transform. A sprite will
|
|
||||||
/// set its texture. Etc.
|
|
||||||
///
|
|
||||||
/// \see sf::RenderTarget, sf::Drawable
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,451 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_RENDERTARGET_HPP
|
|
||||||
#define SFML_RENDERTARGET_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Graphics/Export.hpp>
|
|
||||||
#include <SFML/Graphics/Color.hpp>
|
|
||||||
#include <SFML/Graphics/Rect.hpp>
|
|
||||||
#include <SFML/Graphics/View.hpp>
|
|
||||||
#include <SFML/Graphics/Transform.hpp>
|
|
||||||
#include <SFML/Graphics/BlendMode.hpp>
|
|
||||||
#include <SFML/Graphics/RenderStates.hpp>
|
|
||||||
#include <SFML/Graphics/PrimitiveType.hpp>
|
|
||||||
#include <SFML/Graphics/Vertex.hpp>
|
|
||||||
#include <SFML/System/NonCopyable.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
class Drawable;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Base class for all render targets (window, texture, ...)
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_GRAPHICS_API RenderTarget : NonCopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Destructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual ~RenderTarget();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Clear the entire target with a single color
|
|
||||||
///
|
|
||||||
/// This function is usually called once every frame,
|
|
||||||
/// to clear the previous contents of the target.
|
|
||||||
///
|
|
||||||
/// \param color Fill color to use to clear the render target
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void clear(const Color& color = Color(0, 0, 0, 255));
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Change the current active view
|
|
||||||
///
|
|
||||||
/// The view is like a 2D camera, it controls which part of
|
|
||||||
/// the 2D scene is visible, and how it is viewed in the
|
|
||||||
/// render target.
|
|
||||||
/// The new view will affect everything that is drawn, until
|
|
||||||
/// another view is set.
|
|
||||||
/// The render target keeps its own copy of the view object,
|
|
||||||
/// so it is not necessary to keep the original one alive
|
|
||||||
/// after calling this function.
|
|
||||||
/// To restore the original view of the target, you can pass
|
|
||||||
/// the result of getDefaultView() to this function.
|
|
||||||
///
|
|
||||||
/// \param view New view to use
|
|
||||||
///
|
|
||||||
/// \see getView, getDefaultView
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setView(const View& view);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the view currently in use in the render target
|
|
||||||
///
|
|
||||||
/// \return The view object that is currently used
|
|
||||||
///
|
|
||||||
/// \see setView, getDefaultView
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const View& getView() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the default view of the render target
|
|
||||||
///
|
|
||||||
/// The default view has the initial size of the render target,
|
|
||||||
/// and never changes after the target has been created.
|
|
||||||
///
|
|
||||||
/// \return The default view of the render target
|
|
||||||
///
|
|
||||||
/// \see setView, getView
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const View& getDefaultView() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the viewport of a view, applied to this render target
|
|
||||||
///
|
|
||||||
/// The viewport is defined in the view as a ratio, this function
|
|
||||||
/// simply applies this ratio to the current dimensions of the
|
|
||||||
/// render target to calculate the pixels rectangle that the viewport
|
|
||||||
/// actually covers in the target.
|
|
||||||
///
|
|
||||||
/// \param view The view for which we want to compute the viewport
|
|
||||||
///
|
|
||||||
/// \return Viewport rectangle, expressed in pixels
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
IntRect getViewport(const View& view) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Convert a point from target coordinates to world
|
|
||||||
/// coordinates, using the current view
|
|
||||||
///
|
|
||||||
/// This function is an overload of the mapPixelToCoords
|
|
||||||
/// function that implicitly uses the current view.
|
|
||||||
/// It is equivalent to:
|
|
||||||
/// \code
|
|
||||||
/// target.mapPixelToCoords(point, target.getView());
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \param point Pixel to convert
|
|
||||||
///
|
|
||||||
/// \return The converted point, in "world" coordinates
|
|
||||||
///
|
|
||||||
/// \see mapCoordsToPixel
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Vector2f mapPixelToCoords(const Vector2i& point) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Convert a point from target coordinates to world coordinates
|
|
||||||
///
|
|
||||||
/// This function finds the 2D position that matches the
|
|
||||||
/// given pixel of the render target. In other words, it does
|
|
||||||
/// the inverse of what the graphics card does, to find the
|
|
||||||
/// initial position of a rendered pixel.
|
|
||||||
///
|
|
||||||
/// Initially, both coordinate systems (world units and target pixels)
|
|
||||||
/// match perfectly. But if you define a custom view or resize your
|
|
||||||
/// render target, this assertion is not true anymore, i.e. a point
|
|
||||||
/// located at (10, 50) in your render target may map to the point
|
|
||||||
/// (150, 75) in your 2D world -- if the view is translated by (140, 25).
|
|
||||||
///
|
|
||||||
/// For render-windows, this function is typically used to find
|
|
||||||
/// which point (or object) is located below the mouse cursor.
|
|
||||||
///
|
|
||||||
/// This version uses a custom view for calculations, see the other
|
|
||||||
/// overload of the function if you want to use the current view of the
|
|
||||||
/// render target.
|
|
||||||
///
|
|
||||||
/// \param point Pixel to convert
|
|
||||||
/// \param view The view to use for converting the point
|
|
||||||
///
|
|
||||||
/// \return The converted point, in "world" units
|
|
||||||
///
|
|
||||||
/// \see mapCoordsToPixel
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Vector2f mapPixelToCoords(const Vector2i& point, const View& view) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Convert a point from world coordinates to target
|
|
||||||
/// coordinates, using the current view
|
|
||||||
///
|
|
||||||
/// This function is an overload of the mapCoordsToPixel
|
|
||||||
/// function that implicitly uses the current view.
|
|
||||||
/// It is equivalent to:
|
|
||||||
/// \code
|
|
||||||
/// target.mapCoordsToPixel(point, target.getView());
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \param point Point to convert
|
|
||||||
///
|
|
||||||
/// \return The converted point, in target coordinates (pixels)
|
|
||||||
///
|
|
||||||
/// \see mapPixelToCoords
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Vector2i mapCoordsToPixel(const Vector2f& point) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Convert a point from world coordinates to target coordinates
|
|
||||||
///
|
|
||||||
/// This function finds the pixel of the render target that matches
|
|
||||||
/// the given 2D point. In other words, it goes through the same process
|
|
||||||
/// as the graphics card, to compute the final position of a rendered point.
|
|
||||||
///
|
|
||||||
/// Initially, both coordinate systems (world units and target pixels)
|
|
||||||
/// match perfectly. But if you define a custom view or resize your
|
|
||||||
/// render target, this assertion is not true anymore, i.e. a point
|
|
||||||
/// located at (150, 75) in your 2D world may map to the pixel
|
|
||||||
/// (10, 50) of your render target -- if the view is translated by (140, 25).
|
|
||||||
///
|
|
||||||
/// This version uses a custom view for calculations, see the other
|
|
||||||
/// overload of the function if you want to use the current view of the
|
|
||||||
/// render target.
|
|
||||||
///
|
|
||||||
/// \param point Point to convert
|
|
||||||
/// \param view The view to use for converting the point
|
|
||||||
///
|
|
||||||
/// \return The converted point, in target coordinates (pixels)
|
|
||||||
///
|
|
||||||
/// \see mapPixelToCoords
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Vector2i mapCoordsToPixel(const Vector2f& point, const View& view) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Draw a drawable object to the render target
|
|
||||||
///
|
|
||||||
/// \param drawable Object to draw
|
|
||||||
/// \param states Render states to use for drawing
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void draw(const Drawable& drawable, const RenderStates& states = RenderStates::Default);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Draw primitives defined by an array of vertices
|
|
||||||
///
|
|
||||||
/// \param vertices Pointer to the vertices
|
|
||||||
/// \param vertexCount Number of vertices in the array
|
|
||||||
/// \param type Type of primitives to draw
|
|
||||||
/// \param states Render states to use for drawing
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void draw(const Vertex* vertices, std::size_t vertexCount,
|
|
||||||
PrimitiveType type, const RenderStates& states = RenderStates::Default);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Return the size of the rendering region of the target
|
|
||||||
///
|
|
||||||
/// \return Size in pixels
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual Vector2u getSize() const = 0;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Save the current OpenGL render states and matrices
|
|
||||||
///
|
|
||||||
/// This function can be used when you mix SFML drawing
|
|
||||||
/// and direct OpenGL rendering. Combined with popGLStates,
|
|
||||||
/// it ensures that:
|
|
||||||
/// \li SFML's internal states are not messed up by your OpenGL code
|
|
||||||
/// \li your OpenGL states are not modified by a call to a SFML function
|
|
||||||
///
|
|
||||||
/// More specifically, it must be used around code that
|
|
||||||
/// calls Draw functions. Example:
|
|
||||||
/// \code
|
|
||||||
/// // OpenGL code here...
|
|
||||||
/// window.pushGLStates();
|
|
||||||
/// window.draw(...);
|
|
||||||
/// window.draw(...);
|
|
||||||
/// window.popGLStates();
|
|
||||||
/// // OpenGL code here...
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// Note that this function is quite expensive: it saves all the
|
|
||||||
/// possible OpenGL states and matrices, even the ones you
|
|
||||||
/// don't care about. Therefore it should be used wisely.
|
|
||||||
/// It is provided for convenience, but the best results will
|
|
||||||
/// be achieved if you handle OpenGL states yourself (because
|
|
||||||
/// you know which states have really changed, and need to be
|
|
||||||
/// saved and restored). Take a look at the resetGLStates
|
|
||||||
/// function if you do so.
|
|
||||||
///
|
|
||||||
/// \see popGLStates
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void pushGLStates();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Restore the previously saved OpenGL render states and matrices
|
|
||||||
///
|
|
||||||
/// See the description of pushGLStates to get a detailed
|
|
||||||
/// description of these functions.
|
|
||||||
///
|
|
||||||
/// \see pushGLStates
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void popGLStates();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Reset the internal OpenGL states so that the target is ready for drawing
|
|
||||||
///
|
|
||||||
/// This function can be used when you mix SFML drawing
|
|
||||||
/// and direct OpenGL rendering, if you choose not to use
|
|
||||||
/// pushGLStates/popGLStates. It makes sure that all OpenGL
|
|
||||||
/// states needed by SFML are set, so that subsequent draw()
|
|
||||||
/// calls will work as expected.
|
|
||||||
///
|
|
||||||
/// Example:
|
|
||||||
/// \code
|
|
||||||
/// // OpenGL code here...
|
|
||||||
/// glPushAttrib(...);
|
|
||||||
/// window.resetGLStates();
|
|
||||||
/// window.draw(...);
|
|
||||||
/// window.draw(...);
|
|
||||||
/// glPopAttrib(...);
|
|
||||||
/// // OpenGL code here...
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void resetGLStates();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
RenderTarget();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Performs the common initialization step after creation
|
|
||||||
///
|
|
||||||
/// The derived classes must call this function after the
|
|
||||||
/// target is created and ready for drawing.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void initialize();
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Apply the current view
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void applyCurrentView();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Apply a new blending mode
|
|
||||||
///
|
|
||||||
/// \param mode Blending mode to apply
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void applyBlendMode(const BlendMode& mode);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Apply a new transform
|
|
||||||
///
|
|
||||||
/// \param transform Transform to apply
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void applyTransform(const Transform& transform);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Apply a new texture
|
|
||||||
///
|
|
||||||
/// \param texture Texture to apply
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void applyTexture(const Texture* texture);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Apply a new shader
|
|
||||||
///
|
|
||||||
/// \param shader Shader to apply
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void applyShader(const Shader* shader);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Activate the target for rendering
|
|
||||||
///
|
|
||||||
/// This function must be implemented by derived classes to make
|
|
||||||
/// their OpenGL context current; it is called by the base class
|
|
||||||
/// everytime it's going to use OpenGL calls.
|
|
||||||
///
|
|
||||||
/// \param active True to make the target active, false to deactivate it
|
|
||||||
///
|
|
||||||
/// \return True if the function succeeded
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual bool activate(bool active) = 0;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Render states cache
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
struct StatesCache
|
|
||||||
{
|
|
||||||
enum {VertexCacheSize = 4};
|
|
||||||
|
|
||||||
bool glStatesSet; ///< Are our internal GL states set yet?
|
|
||||||
bool viewChanged; ///< Has the current view changed since last draw?
|
|
||||||
BlendMode lastBlendMode; ///< Cached blending mode
|
|
||||||
Uint64 lastTextureId; ///< Cached texture
|
|
||||||
bool useVertexCache; ///< Did we previously use the vertex cache?
|
|
||||||
Vertex vertexCache[VertexCacheSize]; ///< Pre-transformed vertices cache
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
View m_defaultView; ///< Default view
|
|
||||||
View m_view; ///< Current view
|
|
||||||
StatesCache m_cache; ///< Render states cache
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_RENDERTARGET_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::RenderTarget
|
|
||||||
/// \ingroup graphics
|
|
||||||
///
|
|
||||||
/// sf::RenderTarget defines the common behavior of all the
|
|
||||||
/// 2D render targets usable in the graphics module. It makes
|
|
||||||
/// it possible to draw 2D entities like sprites, shapes, text
|
|
||||||
/// without using any OpenGL command directly.
|
|
||||||
///
|
|
||||||
/// A sf::RenderTarget is also able to use views (sf::View),
|
|
||||||
/// which are a kind of 2D cameras. With views you can globally
|
|
||||||
/// scroll, rotate or zoom everything that is drawn,
|
|
||||||
/// without having to transform every single entity. See the
|
|
||||||
/// documentation of sf::View for more details and sample pieces of
|
|
||||||
/// code about this class.
|
|
||||||
///
|
|
||||||
/// On top of that, render targets are still able to render direct
|
|
||||||
/// OpenGL stuff. It is even possible to mix together OpenGL calls
|
|
||||||
/// and regular SFML drawing commands. When doing so, make sure that
|
|
||||||
/// OpenGL states are not messed up by calling the
|
|
||||||
/// pushGLStates/popGLStates functions.
|
|
||||||
///
|
|
||||||
/// \see sf::RenderWindow, sf::RenderTexture, sf::View
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,280 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_RENDERTEXTURE_HPP
|
|
||||||
#define SFML_RENDERTEXTURE_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Graphics/Export.hpp>
|
|
||||||
#include <SFML/Graphics/Texture.hpp>
|
|
||||||
#include <SFML/Graphics/RenderTarget.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
namespace priv
|
|
||||||
{
|
|
||||||
class RenderTextureImpl;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Target for off-screen 2D rendering into a texture
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_GRAPHICS_API RenderTexture : public RenderTarget
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
/// Constructs an empty, invalid render-texture. You must
|
|
||||||
/// call create to have a valid render-texture.
|
|
||||||
///
|
|
||||||
/// \see create
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
RenderTexture();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Destructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual ~RenderTexture();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Create the render-texture
|
|
||||||
///
|
|
||||||
/// Before calling this function, the render-texture is in
|
|
||||||
/// an invalid state, thus it is mandatory to call it before
|
|
||||||
/// doing anything with the render-texture.
|
|
||||||
/// The last parameter, \a depthBuffer, is useful if you want
|
|
||||||
/// to use the render-texture for 3D OpenGL rendering that requires
|
|
||||||
/// a depth buffer. Otherwise it is unnecessary, and you should
|
|
||||||
/// leave this parameter to false (which is its default value).
|
|
||||||
///
|
|
||||||
/// \param width Width of the render-texture
|
|
||||||
/// \param height Height of the render-texture
|
|
||||||
/// \param depthBuffer Do you want this render-texture to have a depth buffer?
|
|
||||||
///
|
|
||||||
/// \return True if creation has been successful
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool create(unsigned int width, unsigned int height, bool depthBuffer = false);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Enable or disable texture smoothing
|
|
||||||
///
|
|
||||||
/// This function is similar to Texture::setSmooth.
|
|
||||||
/// This parameter is disabled by default.
|
|
||||||
///
|
|
||||||
/// \param smooth True to enable smoothing, false to disable it
|
|
||||||
///
|
|
||||||
/// \see isSmooth
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setSmooth(bool smooth);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Tell whether the smooth filtering is enabled or not
|
|
||||||
///
|
|
||||||
/// \return True if texture smoothing is enabled
|
|
||||||
///
|
|
||||||
/// \see setSmooth
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool isSmooth() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Enable or disable texture repeating
|
|
||||||
///
|
|
||||||
/// This function is similar to Texture::setRepeated.
|
|
||||||
/// This parameter is disabled by default.
|
|
||||||
///
|
|
||||||
/// \param repeated True to enable repeating, false to disable it
|
|
||||||
///
|
|
||||||
/// \see isRepeated
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setRepeated(bool repeated);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Tell whether the texture is repeated or not
|
|
||||||
///
|
|
||||||
/// \return True if texture is repeated
|
|
||||||
///
|
|
||||||
/// \see setRepeated
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool isRepeated() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Activate of deactivate the render-texture for rendering
|
|
||||||
///
|
|
||||||
/// This function makes the render-texture's context current for
|
|
||||||
/// future OpenGL rendering operations (so you shouldn't care
|
|
||||||
/// about it if you're not doing direct OpenGL stuff).
|
|
||||||
/// Only one context can be current in a thread, so if you
|
|
||||||
/// want to draw OpenGL geometry to another render target
|
|
||||||
/// (like a RenderWindow) don't forget to activate it again.
|
|
||||||
///
|
|
||||||
/// \param active True to activate, false to deactivate
|
|
||||||
///
|
|
||||||
/// \return True if operation was successful, false otherwise
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool setActive(bool active = true);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Update the contents of the target texture
|
|
||||||
///
|
|
||||||
/// This function updates the target texture with what
|
|
||||||
/// has been drawn so far. Like for windows, calling this
|
|
||||||
/// function is mandatory at the end of rendering. Not calling
|
|
||||||
/// it may leave the texture in an undefined state.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void display();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Return the size of the rendering region of the texture
|
|
||||||
///
|
|
||||||
/// The returned value is the size that you passed to
|
|
||||||
/// the create function.
|
|
||||||
///
|
|
||||||
/// \return Size in pixels
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual Vector2u getSize() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get a read-only reference to the target texture
|
|
||||||
///
|
|
||||||
/// After drawing to the render-texture and calling Display,
|
|
||||||
/// you can retrieve the updated texture using this function,
|
|
||||||
/// and draw it using a sprite (for example).
|
|
||||||
/// The internal sf::Texture of a render-texture is always the
|
|
||||||
/// same instance, so that it is possible to call this function
|
|
||||||
/// once and keep a reference to the texture even after it is
|
|
||||||
/// modified.
|
|
||||||
///
|
|
||||||
/// \return Const reference to the texture
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const Texture& getTexture() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Activate the target for rendering
|
|
||||||
///
|
|
||||||
/// This function is called by the base class
|
|
||||||
/// everytime it's going to use OpenGL calls.
|
|
||||||
///
|
|
||||||
/// \param active True to make the target active, false to deactivate it
|
|
||||||
///
|
|
||||||
/// \return True if the function succeeded
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual bool activate(bool active);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
priv::RenderTextureImpl* m_impl; ///< Platform/hardware specific implementation
|
|
||||||
Texture m_texture; ///< Target texture to draw on
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_RENDERTEXTURE_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::RenderTexture
|
|
||||||
/// \ingroup graphics
|
|
||||||
///
|
|
||||||
/// sf::RenderTexture is the little brother of sf::RenderWindow.
|
|
||||||
/// It implements the same 2D drawing and OpenGL-related functions
|
|
||||||
/// (see their base class sf::RenderTarget for more details),
|
|
||||||
/// the difference is that the result is stored in an off-screen
|
|
||||||
/// texture rather than being show in a window.
|
|
||||||
///
|
|
||||||
/// Rendering to a texture can be useful in a variety of situations:
|
|
||||||
/// \li precomputing a complex static texture (like a level's background from multiple tiles)
|
|
||||||
/// \li applying post-effects to the whole scene with shaders
|
|
||||||
/// \li creating a sprite from a 3D object rendered with OpenGL
|
|
||||||
/// \li etc.
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
///
|
|
||||||
/// \code
|
|
||||||
/// // Create a new render-window
|
|
||||||
/// sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
|
|
||||||
///
|
|
||||||
/// // Create a new render-texture
|
|
||||||
/// sf::RenderTexture texture;
|
|
||||||
/// if (!texture.create(500, 500))
|
|
||||||
/// return -1;
|
|
||||||
///
|
|
||||||
/// // The main loop
|
|
||||||
/// while (window.isOpen())
|
|
||||||
/// {
|
|
||||||
/// // Event processing
|
|
||||||
/// // ...
|
|
||||||
///
|
|
||||||
/// // Clear the whole texture with red color
|
|
||||||
/// texture.clear(sf::Color::Red);
|
|
||||||
///
|
|
||||||
/// // Draw stuff to the texture
|
|
||||||
/// texture.draw(sprite); // sprite is a sf::Sprite
|
|
||||||
/// texture.draw(shape); // shape is a sf::Shape
|
|
||||||
/// texture.draw(text); // text is a sf::Text
|
|
||||||
///
|
|
||||||
/// // We're done drawing to the texture
|
|
||||||
/// texture.display();
|
|
||||||
///
|
|
||||||
/// // Now we start rendering to the window, clear it first
|
|
||||||
/// window.clear();
|
|
||||||
///
|
|
||||||
/// // Draw the texture
|
|
||||||
/// sf::Sprite sprite(texture.getTexture());
|
|
||||||
/// window.draw(sprite);
|
|
||||||
///
|
|
||||||
/// // End the current frame and display its contents on screen
|
|
||||||
/// window.display();
|
|
||||||
/// }
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// Like sf::RenderWindow, sf::RenderTexture is still able to render direct
|
|
||||||
/// OpenGL stuff. It is even possible to mix together OpenGL calls
|
|
||||||
/// and regular SFML drawing commands. If you need a depth buffer for
|
|
||||||
/// 3D rendering, don't forget to request it when calling RenderTexture::create.
|
|
||||||
///
|
|
||||||
/// \see sf::RenderTarget, sf::RenderWindow, sf::View, sf::Texture
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,267 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_RENDERWINDOW_HPP
|
|
||||||
#define SFML_RENDERWINDOW_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Graphics/Export.hpp>
|
|
||||||
#include <SFML/Graphics/RenderTarget.hpp>
|
|
||||||
#include <SFML/Graphics/Image.hpp>
|
|
||||||
#include <SFML/Window/Window.hpp>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Window that can serve as a target for 2D drawing
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_GRAPHICS_API RenderWindow : public Window, public RenderTarget
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
/// This constructor doesn't actually create the window,
|
|
||||||
/// use the other constructors or call create() to do so.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
RenderWindow();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Construct a new window
|
|
||||||
///
|
|
||||||
/// This constructor creates the window with the size and pixel
|
|
||||||
/// depth defined in \a mode. An optional style can be passed to
|
|
||||||
/// customize the look and behavior of the window (borders,
|
|
||||||
/// title bar, resizable, closable, ...).
|
|
||||||
///
|
|
||||||
/// The fourth parameter is an optional structure specifying
|
|
||||||
/// advanced OpenGL context settings such as antialiasing,
|
|
||||||
/// depth-buffer bits, etc. You shouldn't care about these
|
|
||||||
/// parameters for a regular usage of the graphics module.
|
|
||||||
///
|
|
||||||
/// \param mode Video mode to use (defines the width, height and depth of the rendering area of the window)
|
|
||||||
/// \param title Title of the window
|
|
||||||
/// \param style %Window style, a bitwise OR combination of sf::Style enumerators
|
|
||||||
/// \param settings Additional settings for the underlying OpenGL context
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
RenderWindow(VideoMode mode, const String& title, Uint32 style = Style::Default, const ContextSettings& settings = ContextSettings());
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Construct the window from an existing control
|
|
||||||
///
|
|
||||||
/// Use this constructor if you want to create an SFML
|
|
||||||
/// rendering area into an already existing control.
|
|
||||||
///
|
|
||||||
/// The second parameter is an optional structure specifying
|
|
||||||
/// advanced OpenGL context settings such as antialiasing,
|
|
||||||
/// depth-buffer bits, etc. You shouldn't care about these
|
|
||||||
/// parameters for a regular usage of the graphics module.
|
|
||||||
///
|
|
||||||
/// \param handle Platform-specific handle of the control (\a HWND on
|
|
||||||
/// Windows, \a %Window on Linux/FreeBSD, \a NSWindow on OS X)
|
|
||||||
/// \param settings Additional settings for the underlying OpenGL context
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
explicit RenderWindow(WindowHandle handle, const ContextSettings& settings = ContextSettings());
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Destructor
|
|
||||||
///
|
|
||||||
/// Closes the window and frees all the resources attached to it.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual ~RenderWindow();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the size of the rendering region of the window
|
|
||||||
///
|
|
||||||
/// The size doesn't include the titlebar and borders
|
|
||||||
/// of the window.
|
|
||||||
///
|
|
||||||
/// \return Size in pixels
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual Vector2u getSize() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Copy the current contents of the window to an image
|
|
||||||
///
|
|
||||||
/// This is a slow operation, whose main purpose is to make
|
|
||||||
/// screenshots of the application. If you want to update an
|
|
||||||
/// image with the contents of the window and then use it for
|
|
||||||
/// drawing, you should rather use a sf::Texture and its
|
|
||||||
/// update(Window&) function.
|
|
||||||
/// You can also draw things directly to a texture with the
|
|
||||||
/// sf::RenderTexture class.
|
|
||||||
///
|
|
||||||
/// \return Image containing the captured contents
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Image capture() const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Function called after the window has been created
|
|
||||||
///
|
|
||||||
/// This function is called so that derived classes can
|
|
||||||
/// perform their own specific initialization as soon as
|
|
||||||
/// the window is created.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual void onCreate();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Function called after the window has been resized
|
|
||||||
///
|
|
||||||
/// This function is called so that derived classes can
|
|
||||||
/// perform custom actions when the size of the window changes.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual void onResize();
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Activate the target for rendering
|
|
||||||
///
|
|
||||||
/// \param active True to make the target active, false to deactivate it
|
|
||||||
///
|
|
||||||
/// \return True if the function succeeded
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual bool activate(bool active);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_RENDERWINDOW_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::RenderWindow
|
|
||||||
/// \ingroup graphics
|
|
||||||
///
|
|
||||||
/// sf::RenderWindow is the main class of the Graphics module.
|
|
||||||
/// It defines an OS window that can be painted using the other
|
|
||||||
/// classes of the graphics module.
|
|
||||||
///
|
|
||||||
/// sf::RenderWindow is derived from sf::Window, thus it inherits
|
|
||||||
/// all its features: events, window management, OpenGL rendering,
|
|
||||||
/// etc. See the documentation of sf::Window for a more complete
|
|
||||||
/// description of all these features, as well as code examples.
|
|
||||||
///
|
|
||||||
/// On top of that, sf::RenderWindow adds more features related to
|
|
||||||
/// 2D drawing with the graphics module (see its base class
|
|
||||||
/// sf::RenderTarget for more details).
|
|
||||||
/// Here is a typical rendering and event loop with a sf::RenderWindow:
|
|
||||||
///
|
|
||||||
/// \code
|
|
||||||
/// // Declare and create a new render-window
|
|
||||||
/// sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
|
|
||||||
///
|
|
||||||
/// // Limit the framerate to 60 frames per second (this step is optional)
|
|
||||||
/// window.setFramerateLimit(60);
|
|
||||||
///
|
|
||||||
/// // The main loop - ends as soon as the window is closed
|
|
||||||
/// while (window.isOpen())
|
|
||||||
/// {
|
|
||||||
/// // Event processing
|
|
||||||
/// sf::Event event;
|
|
||||||
/// while (window.pollEvent(event))
|
|
||||||
/// {
|
|
||||||
/// // Request for closing the window
|
|
||||||
/// if (event.type == sf::Event::Closed)
|
|
||||||
/// window.close();
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// // Clear the whole window before rendering a new frame
|
|
||||||
/// window.clear();
|
|
||||||
///
|
|
||||||
/// // Draw some graphical entities
|
|
||||||
/// window.draw(sprite);
|
|
||||||
/// window.draw(circle);
|
|
||||||
/// window.draw(text);
|
|
||||||
///
|
|
||||||
/// // End the current frame and display its contents on screen
|
|
||||||
/// window.display();
|
|
||||||
/// }
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// Like sf::Window, sf::RenderWindow is still able to render direct
|
|
||||||
/// OpenGL stuff. It is even possible to mix together OpenGL calls
|
|
||||||
/// and regular SFML drawing commands.
|
|
||||||
///
|
|
||||||
/// \code
|
|
||||||
/// // Create the render window
|
|
||||||
/// sf::RenderWindow window(sf::VideoMode(800, 600), "SFML OpenGL");
|
|
||||||
///
|
|
||||||
/// // Create a sprite and a text to display
|
|
||||||
/// sf::Sprite sprite;
|
|
||||||
/// sf::Text text;
|
|
||||||
/// ...
|
|
||||||
///
|
|
||||||
/// // Perform OpenGL initializations
|
|
||||||
/// glMatrixMode(GL_PROJECTION);
|
|
||||||
/// ...
|
|
||||||
///
|
|
||||||
/// // Start the rendering loop
|
|
||||||
/// while (window.isOpen())
|
|
||||||
/// {
|
|
||||||
/// // Process events
|
|
||||||
/// ...
|
|
||||||
///
|
|
||||||
/// // Draw a background sprite
|
|
||||||
/// window.pushGLStates();
|
|
||||||
/// window.draw(sprite);
|
|
||||||
/// window.popGLStates();
|
|
||||||
///
|
|
||||||
/// // Draw a 3D object using OpenGL
|
|
||||||
/// glBegin(GL_QUADS);
|
|
||||||
/// glVertex3f(...);
|
|
||||||
/// ...
|
|
||||||
/// glEnd();
|
|
||||||
///
|
|
||||||
/// // Draw text on top of the 3D object
|
|
||||||
/// window.pushGLStates();
|
|
||||||
/// window.draw(text);
|
|
||||||
/// window.popGLStates();
|
|
||||||
///
|
|
||||||
/// // Finally, display the rendered frame on screen
|
|
||||||
/// window.display();
|
|
||||||
/// }
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \see sf::Window, sf::RenderTarget, sf::RenderTexture, sf::View
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,659 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_SHADER_HPP
|
|
||||||
#define SFML_SHADER_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Graphics/Export.hpp>
|
|
||||||
#include <SFML/Graphics/Transform.hpp>
|
|
||||||
#include <SFML/Graphics/Color.hpp>
|
|
||||||
#include <SFML/Window/GlResource.hpp>
|
|
||||||
#include <SFML/System/NonCopyable.hpp>
|
|
||||||
#include <SFML/System/Vector2.hpp>
|
|
||||||
#include <SFML/System/Vector3.hpp>
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
class InputStream;
|
|
||||||
class Texture;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Shader class (vertex and fragment)
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_GRAPHICS_API Shader : GlResource, NonCopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Types of shaders
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
enum Type
|
|
||||||
{
|
|
||||||
Vertex, ///< Vertex shader
|
|
||||||
Fragment ///< Fragment (pixel) shader
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Special type that can be passed to setParameter,
|
|
||||||
/// and that represents the texture of the object being drawn
|
|
||||||
///
|
|
||||||
/// \see setParameter(const std::string&, CurrentTextureType)
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
struct CurrentTextureType {};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Represents the texture of the object being drawn
|
|
||||||
///
|
|
||||||
/// \see setParameter(const std::string&, CurrentTextureType)
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static CurrentTextureType CurrentTexture;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
/// This constructor creates an invalid shader.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Shader();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Destructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
~Shader();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Load either the vertex or fragment shader from a file
|
|
||||||
///
|
|
||||||
/// This function loads a single shader, either vertex or
|
|
||||||
/// fragment, identified by the second argument.
|
|
||||||
/// The source must be a text file containing a valid
|
|
||||||
/// shader in GLSL language. GLSL is a C-like language
|
|
||||||
/// dedicated to OpenGL shaders; you'll probably need to
|
|
||||||
/// read a good documentation for it before writing your
|
|
||||||
/// own shaders.
|
|
||||||
///
|
|
||||||
/// \param filename Path of the vertex or fragment shader file to load
|
|
||||||
/// \param type Type of shader (vertex or fragment)
|
|
||||||
///
|
|
||||||
/// \return True if loading succeeded, false if it failed
|
|
||||||
///
|
|
||||||
/// \see loadFromMemory, loadFromStream
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool loadFromFile(const std::string& filename, Type type);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Load both the vertex and fragment shaders from files
|
|
||||||
///
|
|
||||||
/// This function loads both the vertex and the fragment
|
|
||||||
/// shaders. If one of them fails to load, the shader is left
|
|
||||||
/// empty (the valid shader is unloaded).
|
|
||||||
/// The sources must be text files containing valid shaders
|
|
||||||
/// in GLSL language. GLSL is a C-like language dedicated to
|
|
||||||
/// OpenGL shaders; you'll probably need to read a good documentation
|
|
||||||
/// for it before writing your own shaders.
|
|
||||||
///
|
|
||||||
/// \param vertexShaderFilename Path of the vertex shader file to load
|
|
||||||
/// \param fragmentShaderFilename Path of the fragment shader file to load
|
|
||||||
///
|
|
||||||
/// \return True if loading succeeded, false if it failed
|
|
||||||
///
|
|
||||||
/// \see loadFromMemory, loadFromStream
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool loadFromFile(const std::string& vertexShaderFilename, const std::string& fragmentShaderFilename);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Load either the vertex or fragment shader from a source code in memory
|
|
||||||
///
|
|
||||||
/// This function loads a single shader, either vertex or
|
|
||||||
/// fragment, identified by the second argument.
|
|
||||||
/// The source code must be a valid shader in GLSL language.
|
|
||||||
/// GLSL is a C-like language dedicated to OpenGL shaders;
|
|
||||||
/// you'll probably need to read a good documentation for
|
|
||||||
/// it before writing your own shaders.
|
|
||||||
///
|
|
||||||
/// \param shader String containing the source code of the shader
|
|
||||||
/// \param type Type of shader (vertex or fragment)
|
|
||||||
///
|
|
||||||
/// \return True if loading succeeded, false if it failed
|
|
||||||
///
|
|
||||||
/// \see loadFromFile, loadFromStream
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool loadFromMemory(const std::string& shader, Type type);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Load both the vertex and fragment shaders from source codes in memory
|
|
||||||
///
|
|
||||||
/// This function loads both the vertex and the fragment
|
|
||||||
/// shaders. If one of them fails to load, the shader is left
|
|
||||||
/// empty (the valid shader is unloaded).
|
|
||||||
/// The sources must be valid shaders in GLSL language. GLSL is
|
|
||||||
/// a C-like language dedicated to OpenGL shaders; you'll
|
|
||||||
/// probably need to read a good documentation for it before
|
|
||||||
/// writing your own shaders.
|
|
||||||
///
|
|
||||||
/// \param vertexShader String containing the source code of the vertex shader
|
|
||||||
/// \param fragmentShader String containing the source code of the fragment shader
|
|
||||||
///
|
|
||||||
/// \return True if loading succeeded, false if it failed
|
|
||||||
///
|
|
||||||
/// \see loadFromFile, loadFromStream
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool loadFromMemory(const std::string& vertexShader, const std::string& fragmentShader);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Load either the vertex or fragment shader from a custom stream
|
|
||||||
///
|
|
||||||
/// This function loads a single shader, either vertex or
|
|
||||||
/// fragment, identified by the second argument.
|
|
||||||
/// The source code must be a valid shader in GLSL language.
|
|
||||||
/// GLSL is a C-like language dedicated to OpenGL shaders;
|
|
||||||
/// you'll probably need to read a good documentation for it
|
|
||||||
/// before writing your own shaders.
|
|
||||||
///
|
|
||||||
/// \param stream Source stream to read from
|
|
||||||
/// \param type Type of shader (vertex or fragment)
|
|
||||||
///
|
|
||||||
/// \return True if loading succeeded, false if it failed
|
|
||||||
///
|
|
||||||
/// \see loadFromFile, loadFromMemory
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool loadFromStream(InputStream& stream, Type type);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Load both the vertex and fragment shaders from custom streams
|
|
||||||
///
|
|
||||||
/// This function loads both the vertex and the fragment
|
|
||||||
/// shaders. If one of them fails to load, the shader is left
|
|
||||||
/// empty (the valid shader is unloaded).
|
|
||||||
/// The source codes must be valid shaders in GLSL language.
|
|
||||||
/// GLSL is a C-like language dedicated to OpenGL shaders;
|
|
||||||
/// you'll probably need to read a good documentation for
|
|
||||||
/// it before writing your own shaders.
|
|
||||||
///
|
|
||||||
/// \param vertexShaderStream Source stream to read the vertex shader from
|
|
||||||
/// \param fragmentShaderStream Source stream to read the fragment shader from
|
|
||||||
///
|
|
||||||
/// \return True if loading succeeded, false if it failed
|
|
||||||
///
|
|
||||||
/// \see loadFromFile, loadFromMemory
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool loadFromStream(InputStream& vertexShaderStream, InputStream& fragmentShaderStream);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Change a float parameter of the shader
|
|
||||||
///
|
|
||||||
/// \a name is the name of the variable to change in the shader.
|
|
||||||
/// The corresponding parameter in the shader must be a float
|
|
||||||
/// (float GLSL type).
|
|
||||||
///
|
|
||||||
/// Example:
|
|
||||||
/// \code
|
|
||||||
/// uniform float myparam; // this is the variable in the shader
|
|
||||||
/// \endcode
|
|
||||||
/// \code
|
|
||||||
/// shader.setParameter("myparam", 5.2f);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \param name Name of the parameter in the shader
|
|
||||||
/// \param x Value to assign
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setParameter(const std::string& name, float x);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Change a 2-components vector parameter of the shader
|
|
||||||
///
|
|
||||||
/// \a name is the name of the variable to change in the shader.
|
|
||||||
/// The corresponding parameter in the shader must be a 2x1 vector
|
|
||||||
/// (vec2 GLSL type).
|
|
||||||
///
|
|
||||||
/// Example:
|
|
||||||
/// \code
|
|
||||||
/// uniform vec2 myparam; // this is the variable in the shader
|
|
||||||
/// \endcode
|
|
||||||
/// \code
|
|
||||||
/// shader.setParameter("myparam", 5.2f, 6.0f);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \param name Name of the parameter in the shader
|
|
||||||
/// \param x First component of the value to assign
|
|
||||||
/// \param y Second component of the value to assign
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setParameter(const std::string& name, float x, float y);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Change a 3-components vector parameter of the shader
|
|
||||||
///
|
|
||||||
/// \a name is the name of the variable to change in the shader.
|
|
||||||
/// The corresponding parameter in the shader must be a 3x1 vector
|
|
||||||
/// (vec3 GLSL type).
|
|
||||||
///
|
|
||||||
/// Example:
|
|
||||||
/// \code
|
|
||||||
/// uniform vec3 myparam; // this is the variable in the shader
|
|
||||||
/// \endcode
|
|
||||||
/// \code
|
|
||||||
/// shader.setParameter("myparam", 5.2f, 6.0f, -8.1f);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \param name Name of the parameter in the shader
|
|
||||||
/// \param x First component of the value to assign
|
|
||||||
/// \param y Second component of the value to assign
|
|
||||||
/// \param z Third component of the value to assign
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setParameter(const std::string& name, float x, float y, float z);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Change a 4-components vector parameter of the shader
|
|
||||||
///
|
|
||||||
/// \a name is the name of the variable to change in the shader.
|
|
||||||
/// The corresponding parameter in the shader must be a 4x1 vector
|
|
||||||
/// (vec4 GLSL type).
|
|
||||||
///
|
|
||||||
/// Example:
|
|
||||||
/// \code
|
|
||||||
/// uniform vec4 myparam; // this is the variable in the shader
|
|
||||||
/// \endcode
|
|
||||||
/// \code
|
|
||||||
/// shader.setParameter("myparam", 5.2f, 6.0f, -8.1f, 0.4f);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \param name Name of the parameter in the shader
|
|
||||||
/// \param x First component of the value to assign
|
|
||||||
/// \param y Second component of the value to assign
|
|
||||||
/// \param z Third component of the value to assign
|
|
||||||
/// \param w Fourth component of the value to assign
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setParameter(const std::string& name, float x, float y, float z, float w);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Change a 2-components vector parameter of the shader
|
|
||||||
///
|
|
||||||
/// \a name is the name of the variable to change in the shader.
|
|
||||||
/// The corresponding parameter in the shader must be a 2x1 vector
|
|
||||||
/// (vec2 GLSL type).
|
|
||||||
///
|
|
||||||
/// Example:
|
|
||||||
/// \code
|
|
||||||
/// uniform vec2 myparam; // this is the variable in the shader
|
|
||||||
/// \endcode
|
|
||||||
/// \code
|
|
||||||
/// shader.setParameter("myparam", sf::Vector2f(5.2f, 6.0f));
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \param name Name of the parameter in the shader
|
|
||||||
/// \param vector Vector to assign
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setParameter(const std::string& name, const Vector2f& vector);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Change a 3-components vector parameter of the shader
|
|
||||||
///
|
|
||||||
/// \a name is the name of the variable to change in the shader.
|
|
||||||
/// The corresponding parameter in the shader must be a 3x1 vector
|
|
||||||
/// (vec3 GLSL type).
|
|
||||||
///
|
|
||||||
/// Example:
|
|
||||||
/// \code
|
|
||||||
/// uniform vec3 myparam; // this is the variable in the shader
|
|
||||||
/// \endcode
|
|
||||||
/// \code
|
|
||||||
/// shader.setParameter("myparam", sf::Vector3f(5.2f, 6.0f, -8.1f));
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \param name Name of the parameter in the shader
|
|
||||||
/// \param vector Vector to assign
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setParameter(const std::string& name, const Vector3f& vector);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Change a color parameter of the shader
|
|
||||||
///
|
|
||||||
/// \a name is the name of the variable to change in the shader.
|
|
||||||
/// The corresponding parameter in the shader must be a 4x1 vector
|
|
||||||
/// (vec4 GLSL type).
|
|
||||||
///
|
|
||||||
/// It is important to note that the components of the color are
|
|
||||||
/// normalized before being passed to the shader. Therefore,
|
|
||||||
/// they are converted from range [0 .. 255] to range [0 .. 1].
|
|
||||||
/// For example, a sf::Color(255, 125, 0, 255) will be transformed
|
|
||||||
/// to a vec4(1.0, 0.5, 0.0, 1.0) in the shader.
|
|
||||||
///
|
|
||||||
/// Example:
|
|
||||||
/// \code
|
|
||||||
/// uniform vec4 color; // this is the variable in the shader
|
|
||||||
/// \endcode
|
|
||||||
/// \code
|
|
||||||
/// shader.setParameter("color", sf::Color(255, 128, 0, 255));
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \param name Name of the parameter in the shader
|
|
||||||
/// \param color Color to assign
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setParameter(const std::string& name, const Color& color);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Change a matrix parameter of the shader
|
|
||||||
///
|
|
||||||
/// \a name is the name of the variable to change in the shader.
|
|
||||||
/// The corresponding parameter in the shader must be a 4x4 matrix
|
|
||||||
/// (mat4 GLSL type).
|
|
||||||
///
|
|
||||||
/// Example:
|
|
||||||
/// \code
|
|
||||||
/// uniform mat4 matrix; // this is the variable in the shader
|
|
||||||
/// \endcode
|
|
||||||
/// \code
|
|
||||||
/// sf::Transform transform;
|
|
||||||
/// transform.translate(5, 10);
|
|
||||||
/// shader.setParameter("matrix", transform);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \param name Name of the parameter in the shader
|
|
||||||
/// \param transform Transform to assign
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setParameter(const std::string& name, const Transform& transform);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Change a texture parameter of the shader
|
|
||||||
///
|
|
||||||
/// \a name is the name of the variable to change in the shader.
|
|
||||||
/// The corresponding parameter in the shader must be a 2D texture
|
|
||||||
/// (sampler2D GLSL type).
|
|
||||||
///
|
|
||||||
/// Example:
|
|
||||||
/// \code
|
|
||||||
/// uniform sampler2D the_texture; // this is the variable in the shader
|
|
||||||
/// \endcode
|
|
||||||
/// \code
|
|
||||||
/// sf::Texture texture;
|
|
||||||
/// ...
|
|
||||||
/// shader.setParameter("the_texture", texture);
|
|
||||||
/// \endcode
|
|
||||||
/// It is important to note that \a texture must remain alive as long
|
|
||||||
/// as the shader uses it, no copy is made internally.
|
|
||||||
///
|
|
||||||
/// To use the texture of the object being draw, which cannot be
|
|
||||||
/// known in advance, you can pass the special value
|
|
||||||
/// sf::Shader::CurrentTexture:
|
|
||||||
/// \code
|
|
||||||
/// shader.setParameter("the_texture", sf::Shader::CurrentTexture).
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \param name Name of the texture in the shader
|
|
||||||
/// \param texture Texture to assign
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setParameter(const std::string& name, const Texture& texture);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Change a texture parameter of the shader
|
|
||||||
///
|
|
||||||
/// This overload maps a shader texture variable to the
|
|
||||||
/// texture of the object being drawn, which cannot be
|
|
||||||
/// known in advance. The second argument must be
|
|
||||||
/// sf::Shader::CurrentTexture.
|
|
||||||
/// The corresponding parameter in the shader must be a 2D texture
|
|
||||||
/// (sampler2D GLSL type).
|
|
||||||
///
|
|
||||||
/// Example:
|
|
||||||
/// \code
|
|
||||||
/// uniform sampler2D current; // this is the variable in the shader
|
|
||||||
/// \endcode
|
|
||||||
/// \code
|
|
||||||
/// shader.setParameter("current", sf::Shader::CurrentTexture);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \param name Name of the texture in the shader
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setParameter(const std::string& name, CurrentTextureType);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the underlying OpenGL handle of the shader.
|
|
||||||
///
|
|
||||||
/// You shouldn't need to use this function, unless you have
|
|
||||||
/// very specific stuff to implement that SFML doesn't support,
|
|
||||||
/// or implement a temporary workaround until a bug is fixed.
|
|
||||||
///
|
|
||||||
/// \return OpenGL handle of the shader or 0 if not yet loaded
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
unsigned int getNativeHandle() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Bind a shader for rendering
|
|
||||||
///
|
|
||||||
/// This function is not part of the graphics API, it mustn't be
|
|
||||||
/// used when drawing SFML entities. It must be used only if you
|
|
||||||
/// mix sf::Shader with OpenGL code.
|
|
||||||
///
|
|
||||||
/// \code
|
|
||||||
/// sf::Shader s1, s2;
|
|
||||||
/// ...
|
|
||||||
/// sf::Shader::bind(&s1);
|
|
||||||
/// // draw OpenGL stuff that use s1...
|
|
||||||
/// sf::Shader::bind(&s2);
|
|
||||||
/// // draw OpenGL stuff that use s2...
|
|
||||||
/// sf::Shader::bind(NULL);
|
|
||||||
/// // draw OpenGL stuff that use no shader...
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \param shader Shader to bind, can be null to use no shader
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static void bind(const Shader* shader);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Tell whether or not the system supports shaders
|
|
||||||
///
|
|
||||||
/// This function should always be called before using
|
|
||||||
/// the shader features. If it returns false, then
|
|
||||||
/// any attempt to use sf::Shader will fail.
|
|
||||||
///
|
|
||||||
/// Note: The first call to this function, whether by your
|
|
||||||
/// code or SFML will result in a context switch.
|
|
||||||
///
|
|
||||||
/// \return True if shaders are supported, false otherwise
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static bool isAvailable();
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Compile the shader(s) and create the program
|
|
||||||
///
|
|
||||||
/// If one of the arguments is NULL, the corresponding shader
|
|
||||||
/// is not created.
|
|
||||||
///
|
|
||||||
/// \param vertexShaderCode Source code of the vertex shader
|
|
||||||
/// \param fragmentShaderCode Source code of the fragment shader
|
|
||||||
///
|
|
||||||
/// \return True on success, false if any error happened
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool compile(const char* vertexShaderCode, const char* fragmentShaderCode);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Bind all the textures used by the shader
|
|
||||||
///
|
|
||||||
/// This function each texture to a different unit, and
|
|
||||||
/// updates the corresponding variables in the shader accordingly.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void bindTextures() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the location ID of a shader parameter
|
|
||||||
///
|
|
||||||
/// \param name Name of the parameter to search
|
|
||||||
///
|
|
||||||
/// \return Location ID of the parameter, or -1 if not found
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
int getParamLocation(const std::string& name);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Types
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
typedef std::map<int, const Texture*> TextureTable;
|
|
||||||
typedef std::map<std::string, int> ParamTable;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
unsigned int m_shaderProgram; ///< OpenGL identifier for the program
|
|
||||||
int m_currentTexture; ///< Location of the current texture in the shader
|
|
||||||
TextureTable m_textures; ///< Texture variables in the shader, mapped to their location
|
|
||||||
ParamTable m_params; ///< Parameters location cache
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_SHADER_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::Shader
|
|
||||||
/// \ingroup graphics
|
|
||||||
///
|
|
||||||
/// Shaders are programs written using a specific language,
|
|
||||||
/// executed directly by the graphics card and allowing
|
|
||||||
/// to apply real-time operations to the rendered entities.
|
|
||||||
///
|
|
||||||
/// There are two kinds of shaders:
|
|
||||||
/// \li Vertex shaders, that process vertices
|
|
||||||
/// \li Fragment (pixel) shaders, that process pixels
|
|
||||||
///
|
|
||||||
/// A sf::Shader can be composed of either a vertex shader
|
|
||||||
/// alone, a fragment shader alone, or both combined
|
|
||||||
/// (see the variants of the load functions).
|
|
||||||
///
|
|
||||||
/// Shaders are written in GLSL, which is a C-like
|
|
||||||
/// language dedicated to OpenGL shaders. You'll probably
|
|
||||||
/// need to learn its basics before writing your own shaders
|
|
||||||
/// for SFML.
|
|
||||||
///
|
|
||||||
/// Like any C/C++ program, a shader has its own variables
|
|
||||||
/// that you can set from your C++ application. sf::Shader
|
|
||||||
/// handles 5 different types of variables:
|
|
||||||
/// \li floats
|
|
||||||
/// \li vectors (2, 3 or 4 components)
|
|
||||||
/// \li colors
|
|
||||||
/// \li textures
|
|
||||||
/// \li transforms (matrices)
|
|
||||||
///
|
|
||||||
/// The value of the variables can be changed at any time
|
|
||||||
/// with the various overloads of the setParameter function:
|
|
||||||
/// \code
|
|
||||||
/// shader.setParameter("offset", 2.f);
|
|
||||||
/// shader.setParameter("point", 0.5f, 0.8f, 0.3f);
|
|
||||||
/// shader.setParameter("color", sf::Color(128, 50, 255));
|
|
||||||
/// shader.setParameter("matrix", transform); // transform is a sf::Transform
|
|
||||||
/// shader.setParameter("overlay", texture); // texture is a sf::Texture
|
|
||||||
/// shader.setParameter("texture", sf::Shader::CurrentTexture);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// The special Shader::CurrentTexture argument maps the
|
|
||||||
/// given texture variable to the current texture of the
|
|
||||||
/// object being drawn (which cannot be known in advance).
|
|
||||||
///
|
|
||||||
/// To apply a shader to a drawable, you must pass it as an
|
|
||||||
/// additional parameter to the Draw function:
|
|
||||||
/// \code
|
|
||||||
/// window.draw(sprite, &shader);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// ... which is in fact just a shortcut for this:
|
|
||||||
/// \code
|
|
||||||
/// sf::RenderStates states;
|
|
||||||
/// states.shader = &shader;
|
|
||||||
/// window.draw(sprite, states);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// In the code above we pass a pointer to the shader, because it may
|
|
||||||
/// be null (which means "no shader").
|
|
||||||
///
|
|
||||||
/// Shaders can be used on any drawable, but some combinations are
|
|
||||||
/// not interesting. For example, using a vertex shader on a sf::Sprite
|
|
||||||
/// is limited because there are only 4 vertices, the sprite would
|
|
||||||
/// have to be subdivided in order to apply wave effects.
|
|
||||||
/// Another bad example is a fragment shader with sf::Text: the texture
|
|
||||||
/// of the text is not the actual text that you see on screen, it is
|
|
||||||
/// a big texture containing all the characters of the font in an
|
|
||||||
/// arbitrary order; thus, texture lookups on pixels other than the
|
|
||||||
/// current one may not give you the expected result.
|
|
||||||
///
|
|
||||||
/// Shaders can also be used to apply global post-effects to the
|
|
||||||
/// current contents of the target (like the old sf::PostFx class
|
|
||||||
/// in SFML 1). This can be done in two different ways:
|
|
||||||
/// \li draw everything to a sf::RenderTexture, then draw it to
|
|
||||||
/// the main target using the shader
|
|
||||||
/// \li draw everything directly to the main target, then use
|
|
||||||
/// sf::Texture::update(Window&) to copy its contents to a texture
|
|
||||||
/// and draw it to the main target using the shader
|
|
||||||
///
|
|
||||||
/// The first technique is more optimized because it doesn't involve
|
|
||||||
/// retrieving the target's pixels to system memory, but the
|
|
||||||
/// second one doesn't impact the rendering process and can be
|
|
||||||
/// easily inserted anywhere without impacting all the code.
|
|
||||||
///
|
|
||||||
/// Like sf::Texture that can be used as a raw OpenGL texture,
|
|
||||||
/// sf::Shader can also be used directly as a raw shader for
|
|
||||||
/// custom OpenGL geometry.
|
|
||||||
/// \code
|
|
||||||
/// sf::Shader::bind(&shader);
|
|
||||||
/// ... render OpenGL geometry ...
|
|
||||||
/// sf::Shader::bind(NULL);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,355 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_SHAPE_HPP
|
|
||||||
#define SFML_SHAPE_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Graphics/Export.hpp>
|
|
||||||
#include <SFML/Graphics/Drawable.hpp>
|
|
||||||
#include <SFML/Graphics/Transformable.hpp>
|
|
||||||
#include <SFML/Graphics/VertexArray.hpp>
|
|
||||||
#include <SFML/System/Vector2.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Base class for textured shapes with outline
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_GRAPHICS_API Shape : public Drawable, public Transformable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Virtual destructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual ~Shape();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Change the source texture of the shape
|
|
||||||
///
|
|
||||||
/// The \a texture argument refers to a texture that must
|
|
||||||
/// exist as long as the shape uses it. Indeed, the shape
|
|
||||||
/// doesn't store its own copy of the texture, but rather keeps
|
|
||||||
/// a pointer to the one that you passed to this function.
|
|
||||||
/// If the source texture is destroyed and the shape tries to
|
|
||||||
/// use it, the behavior is undefined.
|
|
||||||
/// \a texture can be NULL to disable texturing.
|
|
||||||
/// If \a resetRect is true, the TextureRect property of
|
|
||||||
/// the shape is automatically adjusted to the size of the new
|
|
||||||
/// texture. If it is false, the texture rect is left unchanged.
|
|
||||||
///
|
|
||||||
/// \param texture New texture
|
|
||||||
/// \param resetRect Should the texture rect be reset to the size of the new texture?
|
|
||||||
///
|
|
||||||
/// \see getTexture, setTextureRect
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setTexture(const Texture* texture, bool resetRect = false);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the sub-rectangle of the texture that the shape will display
|
|
||||||
///
|
|
||||||
/// The texture rect is useful when you don't want to display
|
|
||||||
/// the whole texture, but rather a part of it.
|
|
||||||
/// By default, the texture rect covers the entire texture.
|
|
||||||
///
|
|
||||||
/// \param rect Rectangle defining the region of the texture to display
|
|
||||||
///
|
|
||||||
/// \see getTextureRect, setTexture
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setTextureRect(const IntRect& rect);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the fill color of the shape
|
|
||||||
///
|
|
||||||
/// This color is modulated (multiplied) with the shape's
|
|
||||||
/// texture if any. It can be used to colorize the shape,
|
|
||||||
/// or change its global opacity.
|
|
||||||
/// You can use sf::Color::Transparent to make the inside of
|
|
||||||
/// the shape transparent, and have the outline alone.
|
|
||||||
/// By default, the shape's fill color is opaque white.
|
|
||||||
///
|
|
||||||
/// \param color New color of the shape
|
|
||||||
///
|
|
||||||
/// \see getFillColor, setOutlineColor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setFillColor(const Color& color);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the outline color of the shape
|
|
||||||
///
|
|
||||||
/// By default, the shape's outline color is opaque white.
|
|
||||||
///
|
|
||||||
/// \param color New outline color of the shape
|
|
||||||
///
|
|
||||||
/// \see getOutlineColor, setFillColor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setOutlineColor(const Color& color);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the thickness of the shape's outline
|
|
||||||
///
|
|
||||||
/// Note that negative values are allowed (so that the outline
|
|
||||||
/// expands towards the center of the shape), and using zero
|
|
||||||
/// disables the outline.
|
|
||||||
/// By default, the outline thickness is 0.
|
|
||||||
///
|
|
||||||
/// \param thickness New outline thickness
|
|
||||||
///
|
|
||||||
/// \see getOutlineThickness
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setOutlineThickness(float thickness);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the source texture of the shape
|
|
||||||
///
|
|
||||||
/// If the shape has no source texture, a NULL pointer is returned.
|
|
||||||
/// The returned pointer is const, which means that you can't
|
|
||||||
/// modify the texture when you retrieve it with this function.
|
|
||||||
///
|
|
||||||
/// \return Pointer to the shape's texture
|
|
||||||
///
|
|
||||||
/// \see setTexture
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const Texture* getTexture() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the sub-rectangle of the texture displayed by the shape
|
|
||||||
///
|
|
||||||
/// \return Texture rectangle of the shape
|
|
||||||
///
|
|
||||||
/// \see setTextureRect
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const IntRect& getTextureRect() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the fill color of the shape
|
|
||||||
///
|
|
||||||
/// \return Fill color of the shape
|
|
||||||
///
|
|
||||||
/// \see setFillColor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const Color& getFillColor() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the outline color of the shape
|
|
||||||
///
|
|
||||||
/// \return Outline color of the shape
|
|
||||||
///
|
|
||||||
/// \see setOutlineColor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const Color& getOutlineColor() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the outline thickness of the shape
|
|
||||||
///
|
|
||||||
/// \return Outline thickness of the shape
|
|
||||||
///
|
|
||||||
/// \see setOutlineThickness
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
float getOutlineThickness() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the total number of points of the shape
|
|
||||||
///
|
|
||||||
/// \return Number of points of the shape
|
|
||||||
///
|
|
||||||
/// \see getPoint
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual std::size_t getPointCount() const = 0;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get a point of the shape
|
|
||||||
///
|
|
||||||
/// The returned point is in local coordinates, that is,
|
|
||||||
/// the shape's transforms (position, rotation, scale) are
|
|
||||||
/// not taken into account.
|
|
||||||
/// The result is undefined if \a index is out of the valid range.
|
|
||||||
///
|
|
||||||
/// \param index Index of the point to get, in range [0 .. getPointCount() - 1]
|
|
||||||
///
|
|
||||||
/// \return index-th point of the shape
|
|
||||||
///
|
|
||||||
/// \see getPointCount
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual Vector2f getPoint(std::size_t index) const = 0;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the local bounding rectangle of the entity
|
|
||||||
///
|
|
||||||
/// The returned rectangle is in local coordinates, which means
|
|
||||||
/// that it ignores the transformations (translation, rotation,
|
|
||||||
/// scale, ...) that are applied to the entity.
|
|
||||||
/// In other words, this function returns the bounds of the
|
|
||||||
/// entity in the entity's coordinate system.
|
|
||||||
///
|
|
||||||
/// \return Local bounding rectangle of the entity
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
FloatRect getLocalBounds() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the global (non-minimal) bounding rectangle of the entity
|
|
||||||
///
|
|
||||||
/// The returned rectangle is in global coordinates, which means
|
|
||||||
/// that it takes into account the transformations (translation,
|
|
||||||
/// rotation, scale, ...) that are applied to the entity.
|
|
||||||
/// In other words, this function returns the bounds of the
|
|
||||||
/// shape in the global 2D world's coordinate system.
|
|
||||||
///
|
|
||||||
/// This function does not necessarily return the \a minimal
|
|
||||||
/// bounding rectangle. It merely ensures that the returned
|
|
||||||
/// rectangle covers all the vertices (but possibly more).
|
|
||||||
/// This allows for a fast approximation of the bounds as a
|
|
||||||
/// first check; you may want to use more precise checks
|
|
||||||
/// on top of that.
|
|
||||||
///
|
|
||||||
/// \return Global bounding rectangle of the entity
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
FloatRect getGlobalBounds() const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Shape();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Recompute the internal geometry of the shape
|
|
||||||
///
|
|
||||||
/// This function must be called by the derived class everytime
|
|
||||||
/// the shape's points change (i.e. the result of either
|
|
||||||
/// getPointCount or getPoint is different).
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void update();
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Draw the shape to a render target
|
|
||||||
///
|
|
||||||
/// \param target Render target to draw to
|
|
||||||
/// \param states Current render states
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual void draw(RenderTarget& target, RenderStates states) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Update the fill vertices' color
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void updateFillColors();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Update the fill vertices' texture coordinates
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void updateTexCoords();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Update the outline vertices' position
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void updateOutline();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Update the outline vertices' color
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void updateOutlineColors();
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const Texture* m_texture; ///< Texture of the shape
|
|
||||||
IntRect m_textureRect; ///< Rectangle defining the area of the source texture to display
|
|
||||||
Color m_fillColor; ///< Fill color
|
|
||||||
Color m_outlineColor; ///< Outline color
|
|
||||||
float m_outlineThickness; ///< Thickness of the shape's outline
|
|
||||||
VertexArray m_vertices; ///< Vertex array containing the fill geometry
|
|
||||||
VertexArray m_outlineVertices; ///< Vertex array containing the outline geometry
|
|
||||||
FloatRect m_insideBounds; ///< Bounding rectangle of the inside (fill)
|
|
||||||
FloatRect m_bounds; ///< Bounding rectangle of the whole shape (outline + fill)
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_SHAPE_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::Shape
|
|
||||||
/// \ingroup graphics
|
|
||||||
///
|
|
||||||
/// sf::Shape is a drawable class that allows to define and
|
|
||||||
/// display a custom convex shape on a render target.
|
|
||||||
/// It's only an abstract base, it needs to be specialized for
|
|
||||||
/// concrete types of shapes (circle, rectangle, convex polygon,
|
|
||||||
/// star, ...).
|
|
||||||
///
|
|
||||||
/// In addition to the attributes provided by the specialized
|
|
||||||
/// shape classes, a shape always has the following attributes:
|
|
||||||
/// \li a texture
|
|
||||||
/// \li a texture rectangle
|
|
||||||
/// \li a fill color
|
|
||||||
/// \li an outline color
|
|
||||||
/// \li an outline thickness
|
|
||||||
///
|
|
||||||
/// Each feature is optional, and can be disabled easily:
|
|
||||||
/// \li the texture can be null
|
|
||||||
/// \li the fill/outline colors can be sf::Color::Transparent
|
|
||||||
/// \li the outline thickness can be zero
|
|
||||||
///
|
|
||||||
/// You can write your own derived shape class, there are only
|
|
||||||
/// two virtual functions to override:
|
|
||||||
/// \li getPointCount must return the number of points of the shape
|
|
||||||
/// \li getPoint must return the points of the shape
|
|
||||||
///
|
|
||||||
/// \see sf::RectangleShape, sf::CircleShape, sf::ConvexShape, sf::Transformable
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,279 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_SPRITE_HPP
|
|
||||||
#define SFML_SPRITE_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Graphics/Export.hpp>
|
|
||||||
#include <SFML/Graphics/Drawable.hpp>
|
|
||||||
#include <SFML/Graphics/Transformable.hpp>
|
|
||||||
#include <SFML/Graphics/Vertex.hpp>
|
|
||||||
#include <SFML/Graphics/Rect.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
class Texture;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Drawable representation of a texture, with its
|
|
||||||
/// own transformations, color, etc.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_GRAPHICS_API Sprite : public Drawable, public Transformable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
/// Creates an empty sprite with no source texture.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Sprite();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Construct the sprite from a source texture
|
|
||||||
///
|
|
||||||
/// \param texture Source texture
|
|
||||||
///
|
|
||||||
/// \see setTexture
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
explicit Sprite(const Texture& texture);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Construct the sprite from a sub-rectangle of a source texture
|
|
||||||
///
|
|
||||||
/// \param texture Source texture
|
|
||||||
/// \param rectangle Sub-rectangle of the texture to assign to the sprite
|
|
||||||
///
|
|
||||||
/// \see setTexture, setTextureRect
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Sprite(const Texture& texture, const IntRect& rectangle);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Change the source texture of the sprite
|
|
||||||
///
|
|
||||||
/// The \a texture argument refers to a texture that must
|
|
||||||
/// exist as long as the sprite uses it. Indeed, the sprite
|
|
||||||
/// doesn't store its own copy of the texture, but rather keeps
|
|
||||||
/// a pointer to the one that you passed to this function.
|
|
||||||
/// If the source texture is destroyed and the sprite tries to
|
|
||||||
/// use it, the behavior is undefined.
|
|
||||||
/// If \a resetRect is true, the TextureRect property of
|
|
||||||
/// the sprite is automatically adjusted to the size of the new
|
|
||||||
/// texture. If it is false, the texture rect is left unchanged.
|
|
||||||
///
|
|
||||||
/// \param texture New texture
|
|
||||||
/// \param resetRect Should the texture rect be reset to the size of the new texture?
|
|
||||||
///
|
|
||||||
/// \see getTexture, setTextureRect
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setTexture(const Texture& texture, bool resetRect = false);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the sub-rectangle of the texture that the sprite will display
|
|
||||||
///
|
|
||||||
/// The texture rect is useful when you don't want to display
|
|
||||||
/// the whole texture, but rather a part of it.
|
|
||||||
/// By default, the texture rect covers the entire texture.
|
|
||||||
///
|
|
||||||
/// \param rectangle Rectangle defining the region of the texture to display
|
|
||||||
///
|
|
||||||
/// \see getTextureRect, setTexture
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setTextureRect(const IntRect& rectangle);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the global color of the sprite
|
|
||||||
///
|
|
||||||
/// This color is modulated (multiplied) with the sprite's
|
|
||||||
/// texture. It can be used to colorize the sprite, or change
|
|
||||||
/// its global opacity.
|
|
||||||
/// By default, the sprite's color is opaque white.
|
|
||||||
///
|
|
||||||
/// \param color New color of the sprite
|
|
||||||
///
|
|
||||||
/// \see getColor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setColor(const Color& color);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the source texture of the sprite
|
|
||||||
///
|
|
||||||
/// If the sprite has no source texture, a NULL pointer is returned.
|
|
||||||
/// The returned pointer is const, which means that you can't
|
|
||||||
/// modify the texture when you retrieve it with this function.
|
|
||||||
///
|
|
||||||
/// \return Pointer to the sprite's texture
|
|
||||||
///
|
|
||||||
/// \see setTexture
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const Texture* getTexture() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the sub-rectangle of the texture displayed by the sprite
|
|
||||||
///
|
|
||||||
/// \return Texture rectangle of the sprite
|
|
||||||
///
|
|
||||||
/// \see setTextureRect
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const IntRect& getTextureRect() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the global color of the sprite
|
|
||||||
///
|
|
||||||
/// \return Global color of the sprite
|
|
||||||
///
|
|
||||||
/// \see setColor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const Color& getColor() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the local bounding rectangle of the entity
|
|
||||||
///
|
|
||||||
/// The returned rectangle is in local coordinates, which means
|
|
||||||
/// that it ignores the transformations (translation, rotation,
|
|
||||||
/// scale, ...) that are applied to the entity.
|
|
||||||
/// In other words, this function returns the bounds of the
|
|
||||||
/// entity in the entity's coordinate system.
|
|
||||||
///
|
|
||||||
/// \return Local bounding rectangle of the entity
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
FloatRect getLocalBounds() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the global bounding rectangle of the entity
|
|
||||||
///
|
|
||||||
/// The returned rectangle is in global coordinates, which means
|
|
||||||
/// that it takes into account the transformations (translation,
|
|
||||||
/// rotation, scale, ...) that are applied to the entity.
|
|
||||||
/// In other words, this function returns the bounds of the
|
|
||||||
/// sprite in the global 2D world's coordinate system.
|
|
||||||
///
|
|
||||||
/// \return Global bounding rectangle of the entity
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
FloatRect getGlobalBounds() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Draw the sprite to a render target
|
|
||||||
///
|
|
||||||
/// \param target Render target to draw to
|
|
||||||
/// \param states Current render states
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual void draw(RenderTarget& target, RenderStates states) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Update the vertices' positions
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void updatePositions();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Update the vertices' texture coordinates
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void updateTexCoords();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Vertex m_vertices[4]; ///< Vertices defining the sprite's geometry
|
|
||||||
const Texture* m_texture; ///< Texture of the sprite
|
|
||||||
IntRect m_textureRect; ///< Rectangle defining the area of the source texture to display
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_SPRITE_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::Sprite
|
|
||||||
/// \ingroup graphics
|
|
||||||
///
|
|
||||||
/// sf::Sprite is a drawable class that allows to easily display
|
|
||||||
/// a texture (or a part of it) on a render target.
|
|
||||||
///
|
|
||||||
/// It inherits all the functions from sf::Transformable:
|
|
||||||
/// position, rotation, scale, origin. It also adds sprite-specific
|
|
||||||
/// properties such as the texture to use, the part of it to display,
|
|
||||||
/// and some convenience functions to change the overall color of the
|
|
||||||
/// sprite, or to get its bounding rectangle.
|
|
||||||
///
|
|
||||||
/// sf::Sprite works in combination with the sf::Texture class, which
|
|
||||||
/// loads and provides the pixel data of a given texture.
|
|
||||||
///
|
|
||||||
/// The separation of sf::Sprite and sf::Texture allows more flexibility
|
|
||||||
/// and better performances: indeed a sf::Texture is a heavy resource,
|
|
||||||
/// and any operation on it is slow (often too slow for real-time
|
|
||||||
/// applications). On the other side, a sf::Sprite is a lightweight
|
|
||||||
/// object which can use the pixel data of a sf::Texture and draw
|
|
||||||
/// it with its own transformation/color/blending attributes.
|
|
||||||
///
|
|
||||||
/// It is important to note that the sf::Sprite instance doesn't
|
|
||||||
/// copy the texture that it uses, it only keeps a reference to it.
|
|
||||||
/// Thus, a sf::Texture must not be destroyed while it is
|
|
||||||
/// used by a sf::Sprite (i.e. never write a function that
|
|
||||||
/// uses a local sf::Texture instance for creating a sprite).
|
|
||||||
///
|
|
||||||
/// See also the note on coordinates and undistorted rendering in sf::Transformable.
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// // Declare and load a texture
|
|
||||||
/// sf::Texture texture;
|
|
||||||
/// texture.loadFromFile("texture.png");
|
|
||||||
///
|
|
||||||
/// // Create a sprite
|
|
||||||
/// sf::Sprite sprite;
|
|
||||||
/// sprite.setTexture(texture);
|
|
||||||
/// sprite.setTextureRect(sf::IntRect(10, 10, 50, 30));
|
|
||||||
/// sprite.setColor(sf::Color(255, 255, 255, 200));
|
|
||||||
/// sprite.setPosition(100, 25);
|
|
||||||
///
|
|
||||||
/// // Draw it
|
|
||||||
/// window.draw(sprite);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \see sf::Texture, sf::Transformable
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,372 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_TEXT_HPP
|
|
||||||
#define SFML_TEXT_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Graphics/Export.hpp>
|
|
||||||
#include <SFML/Graphics/Drawable.hpp>
|
|
||||||
#include <SFML/Graphics/Transformable.hpp>
|
|
||||||
#include <SFML/Graphics/Font.hpp>
|
|
||||||
#include <SFML/Graphics/Rect.hpp>
|
|
||||||
#include <SFML/Graphics/VertexArray.hpp>
|
|
||||||
#include <SFML/System/String.hpp>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Graphical text that can be drawn to a render target
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_GRAPHICS_API Text : public Drawable, public Transformable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Enumeration of the string drawing styles
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
enum Style
|
|
||||||
{
|
|
||||||
Regular = 0, ///< Regular characters, no style
|
|
||||||
Bold = 1 << 0, ///< Bold characters
|
|
||||||
Italic = 1 << 1, ///< Italic characters
|
|
||||||
Underlined = 1 << 2, ///< Underlined characters
|
|
||||||
StrikeThrough = 1 << 3 ///< Strike through characters
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
/// Creates an empty text.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Text();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Construct the text from a string, font and size
|
|
||||||
///
|
|
||||||
/// Note that if the used font is a bitmap font, it is not
|
|
||||||
/// scalable, thus not all requested sizes will be available
|
|
||||||
/// to use. This needs to be taken into consideration when
|
|
||||||
/// setting the character size. If you need to display text
|
|
||||||
/// of a certain size, make sure the corresponding bitmap
|
|
||||||
/// font that supports that size is used.
|
|
||||||
///
|
|
||||||
/// \param string Text assigned to the string
|
|
||||||
/// \param font Font used to draw the string
|
|
||||||
/// \param characterSize Base size of characters, in pixels
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Text(const String& string, const Font& font, unsigned int characterSize = 30);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the text's string
|
|
||||||
///
|
|
||||||
/// The \a string argument is a sf::String, which can
|
|
||||||
/// automatically be constructed from standard string types.
|
|
||||||
/// So, the following calls are all valid:
|
|
||||||
/// \code
|
|
||||||
/// text.setString("hello");
|
|
||||||
/// text.setString(L"hello");
|
|
||||||
/// text.setString(std::string("hello"));
|
|
||||||
/// text.setString(std::wstring(L"hello"));
|
|
||||||
/// \endcode
|
|
||||||
/// A text's string is empty by default.
|
|
||||||
///
|
|
||||||
/// \param string New string
|
|
||||||
///
|
|
||||||
/// \see getString
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setString(const String& string);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the text's font
|
|
||||||
///
|
|
||||||
/// The \a font argument refers to a font that must
|
|
||||||
/// exist as long as the text uses it. Indeed, the text
|
|
||||||
/// doesn't store its own copy of the font, but rather keeps
|
|
||||||
/// a pointer to the one that you passed to this function.
|
|
||||||
/// If the font is destroyed and the text tries to
|
|
||||||
/// use it, the behavior is undefined.
|
|
||||||
///
|
|
||||||
/// \param font New font
|
|
||||||
///
|
|
||||||
/// \see getFont
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setFont(const Font& font);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the character size
|
|
||||||
///
|
|
||||||
/// The default size is 30.
|
|
||||||
///
|
|
||||||
/// Note that if the used font is a bitmap font, it is not
|
|
||||||
/// scalable, thus not all requested sizes will be available
|
|
||||||
/// to use. This needs to be taken into consideration when
|
|
||||||
/// setting the character size. If you need to display text
|
|
||||||
/// of a certain size, make sure the corresponding bitmap
|
|
||||||
/// font that supports that size is used.
|
|
||||||
///
|
|
||||||
/// \param size New character size, in pixels
|
|
||||||
///
|
|
||||||
/// \see getCharacterSize
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setCharacterSize(unsigned int size);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the text's style
|
|
||||||
///
|
|
||||||
/// You can pass a combination of one or more styles, for
|
|
||||||
/// example sf::Text::Bold | sf::Text::Italic.
|
|
||||||
/// The default style is sf::Text::Regular.
|
|
||||||
///
|
|
||||||
/// \param style New style
|
|
||||||
///
|
|
||||||
/// \see getStyle
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setStyle(Uint32 style);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the global color of the text
|
|
||||||
///
|
|
||||||
/// By default, the text's color is opaque white.
|
|
||||||
///
|
|
||||||
/// \param color New color of the text
|
|
||||||
///
|
|
||||||
/// \see getColor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setColor(const Color& color);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the text's string
|
|
||||||
///
|
|
||||||
/// The returned string is a sf::String, which can automatically
|
|
||||||
/// be converted to standard string types. So, the following
|
|
||||||
/// lines of code are all valid:
|
|
||||||
/// \code
|
|
||||||
/// sf::String s1 = text.getString();
|
|
||||||
/// std::string s2 = text.getString();
|
|
||||||
/// std::wstring s3 = text.getString();
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \return Text's string
|
|
||||||
///
|
|
||||||
/// \see setString
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const String& getString() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the text's font
|
|
||||||
///
|
|
||||||
/// If the text has no font attached, a NULL pointer is returned.
|
|
||||||
/// The returned pointer is const, which means that you
|
|
||||||
/// cannot modify the font when you get it from this function.
|
|
||||||
///
|
|
||||||
/// \return Pointer to the text's font
|
|
||||||
///
|
|
||||||
/// \see setFont
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const Font* getFont() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the character size
|
|
||||||
///
|
|
||||||
/// \return Size of the characters, in pixels
|
|
||||||
///
|
|
||||||
/// \see setCharacterSize
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
unsigned int getCharacterSize() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the text's style
|
|
||||||
///
|
|
||||||
/// \return Text's style
|
|
||||||
///
|
|
||||||
/// \see setStyle
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Uint32 getStyle() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the global color of the text
|
|
||||||
///
|
|
||||||
/// \return Global color of the text
|
|
||||||
///
|
|
||||||
/// \see setColor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const Color& getColor() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Return the position of the \a index-th character
|
|
||||||
///
|
|
||||||
/// This function computes the visual position of a character
|
|
||||||
/// from its index in the string. The returned position is
|
|
||||||
/// in global coordinates (translation, rotation, scale and
|
|
||||||
/// origin are applied).
|
|
||||||
/// If \a index is out of range, the position of the end of
|
|
||||||
/// the string is returned.
|
|
||||||
///
|
|
||||||
/// \param index Index of the character
|
|
||||||
///
|
|
||||||
/// \return Position of the character
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Vector2f findCharacterPos(std::size_t index) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the local bounding rectangle of the entity
|
|
||||||
///
|
|
||||||
/// The returned rectangle is in local coordinates, which means
|
|
||||||
/// that it ignores the transformations (translation, rotation,
|
|
||||||
/// scale, ...) that are applied to the entity.
|
|
||||||
/// In other words, this function returns the bounds of the
|
|
||||||
/// entity in the entity's coordinate system.
|
|
||||||
///
|
|
||||||
/// \return Local bounding rectangle of the entity
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
FloatRect getLocalBounds() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the global bounding rectangle of the entity
|
|
||||||
///
|
|
||||||
/// The returned rectangle is in global coordinates, which means
|
|
||||||
/// that it takes into account the transformations (translation,
|
|
||||||
/// rotation, scale, ...) that are applied to the entity.
|
|
||||||
/// In other words, this function returns the bounds of the
|
|
||||||
/// text in the global 2D world's coordinate system.
|
|
||||||
///
|
|
||||||
/// \return Global bounding rectangle of the entity
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
FloatRect getGlobalBounds() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Draw the text to a render target
|
|
||||||
///
|
|
||||||
/// \param target Render target to draw to
|
|
||||||
/// \param states Current render states
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual void draw(RenderTarget& target, RenderStates states) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Make sure the text's geometry is updated
|
|
||||||
///
|
|
||||||
/// All the attributes related to rendering are cached, such
|
|
||||||
/// that the geometry is only updated when necessary.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void ensureGeometryUpdate() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
String m_string; ///< String to display
|
|
||||||
const Font* m_font; ///< Font used to display the string
|
|
||||||
unsigned int m_characterSize; ///< Base size of characters, in pixels
|
|
||||||
Uint32 m_style; ///< Text style (see Style enum)
|
|
||||||
Color m_color; ///< Text color
|
|
||||||
mutable VertexArray m_vertices; ///< Vertex array containing the text's geometry
|
|
||||||
mutable FloatRect m_bounds; ///< Bounding rectangle of the text (in local coordinates)
|
|
||||||
mutable bool m_geometryNeedUpdate; ///< Does the geometry need to be recomputed?
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_TEXT_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::Text
|
|
||||||
/// \ingroup graphics
|
|
||||||
///
|
|
||||||
/// sf::Text is a drawable class that allows to easily display
|
|
||||||
/// some text with custom style and color on a render target.
|
|
||||||
///
|
|
||||||
/// It inherits all the functions from sf::Transformable:
|
|
||||||
/// position, rotation, scale, origin. It also adds text-specific
|
|
||||||
/// properties such as the font to use, the character size,
|
|
||||||
/// the font style (bold, italic, underlined, strike through), the
|
|
||||||
/// global color and the text to display of course.
|
|
||||||
/// It also provides convenience functions to calculate the
|
|
||||||
/// graphical size of the text, or to get the global position
|
|
||||||
/// of a given character.
|
|
||||||
///
|
|
||||||
/// sf::Text works in combination with the sf::Font class, which
|
|
||||||
/// loads and provides the glyphs (visual characters) of a given font.
|
|
||||||
///
|
|
||||||
/// The separation of sf::Font and sf::Text allows more flexibility
|
|
||||||
/// and better performances: indeed a sf::Font is a heavy resource,
|
|
||||||
/// and any operation on it is slow (often too slow for real-time
|
|
||||||
/// applications). On the other side, a sf::Text is a lightweight
|
|
||||||
/// object which can combine the glyphs data and metrics of a sf::Font
|
|
||||||
/// to display any text on a render target.
|
|
||||||
///
|
|
||||||
/// It is important to note that the sf::Text instance doesn't
|
|
||||||
/// copy the font that it uses, it only keeps a reference to it.
|
|
||||||
/// Thus, a sf::Font must not be destructed while it is
|
|
||||||
/// used by a sf::Text (i.e. never write a function that
|
|
||||||
/// uses a local sf::Font instance for creating a text).
|
|
||||||
///
|
|
||||||
/// See also the note on coordinates and undistorted rendering in sf::Transformable.
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// // Declare and load a font
|
|
||||||
/// sf::Font font;
|
|
||||||
/// font.loadFromFile("arial.ttf");
|
|
||||||
///
|
|
||||||
/// // Create a text
|
|
||||||
/// sf::Text text("hello", font);
|
|
||||||
/// text.setCharacterSize(30);
|
|
||||||
/// text.setStyle(sf::Text::Bold);
|
|
||||||
/// text.setColor(sf::Color::Red);
|
|
||||||
///
|
|
||||||
/// // Draw it
|
|
||||||
/// window.draw(text);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \see sf::Font, sf::Transformable
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,618 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_TEXTURE_HPP
|
|
||||||
#define SFML_TEXTURE_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Graphics/Export.hpp>
|
|
||||||
#include <SFML/Graphics/Image.hpp>
|
|
||||||
#include <SFML/Window/GlResource.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
class Window;
|
|
||||||
class RenderTarget;
|
|
||||||
class RenderTexture;
|
|
||||||
class InputStream;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Image living on the graphics card that can be used for drawing
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_GRAPHICS_API Texture : GlResource
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Types of texture coordinates that can be used for rendering
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
enum CoordinateType
|
|
||||||
{
|
|
||||||
Normalized, ///< Texture coordinates in range [0 .. 1]
|
|
||||||
Pixels ///< Texture coordinates in range [0 .. size]
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
/// Creates an empty texture.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Texture();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Copy constructor
|
|
||||||
///
|
|
||||||
/// \param copy instance to copy
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Texture(const Texture& copy);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Destructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
~Texture();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Create the texture
|
|
||||||
///
|
|
||||||
/// If this function fails, the texture is left unchanged.
|
|
||||||
///
|
|
||||||
/// \param width Width of the texture
|
|
||||||
/// \param height Height of the texture
|
|
||||||
///
|
|
||||||
/// \return True if creation was successful
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool create(unsigned int width, unsigned int height);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Load the texture from a file on disk
|
|
||||||
///
|
|
||||||
/// This function is a shortcut for the following code:
|
|
||||||
/// \code
|
|
||||||
/// sf::Image image;
|
|
||||||
/// image.loadFromFile(filename);
|
|
||||||
/// texture.loadFromImage(image, area);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// The \a area argument can be used to load only a sub-rectangle
|
|
||||||
/// of the whole image. If you want the entire image then leave
|
|
||||||
/// the default value (which is an empty IntRect).
|
|
||||||
/// If the \a area rectangle crosses the bounds of the image, it
|
|
||||||
/// is adjusted to fit the image size.
|
|
||||||
///
|
|
||||||
/// The maximum size for a texture depends on the graphics
|
|
||||||
/// driver and can be retrieved with the getMaximumSize function.
|
|
||||||
///
|
|
||||||
/// If this function fails, the texture is left unchanged.
|
|
||||||
///
|
|
||||||
/// \param filename Path of the image file to load
|
|
||||||
/// \param area Area of the image to load
|
|
||||||
///
|
|
||||||
/// \return True if loading was successful
|
|
||||||
///
|
|
||||||
/// \see loadFromMemory, loadFromStream, loadFromImage
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool loadFromFile(const std::string& filename, const IntRect& area = IntRect());
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Load the texture from a file in memory
|
|
||||||
///
|
|
||||||
/// This function is a shortcut for the following code:
|
|
||||||
/// \code
|
|
||||||
/// sf::Image image;
|
|
||||||
/// image.loadFromMemory(data, size);
|
|
||||||
/// texture.loadFromImage(image, area);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// The \a area argument can be used to load only a sub-rectangle
|
|
||||||
/// of the whole image. If you want the entire image then leave
|
|
||||||
/// the default value (which is an empty IntRect).
|
|
||||||
/// If the \a area rectangle crosses the bounds of the image, it
|
|
||||||
/// is adjusted to fit the image size.
|
|
||||||
///
|
|
||||||
/// The maximum size for a texture depends on the graphics
|
|
||||||
/// driver and can be retrieved with the getMaximumSize function.
|
|
||||||
///
|
|
||||||
/// If this function fails, the texture is left unchanged.
|
|
||||||
///
|
|
||||||
/// \param data Pointer to the file data in memory
|
|
||||||
/// \param size Size of the data to load, in bytes
|
|
||||||
/// \param area Area of the image to load
|
|
||||||
///
|
|
||||||
/// \return True if loading was successful
|
|
||||||
///
|
|
||||||
/// \see loadFromFile, loadFromStream, loadFromImage
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool loadFromMemory(const void* data, std::size_t size, const IntRect& area = IntRect());
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Load the texture from a custom stream
|
|
||||||
///
|
|
||||||
/// This function is a shortcut for the following code:
|
|
||||||
/// \code
|
|
||||||
/// sf::Image image;
|
|
||||||
/// image.loadFromStream(stream);
|
|
||||||
/// texture.loadFromImage(image, area);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// The \a area argument can be used to load only a sub-rectangle
|
|
||||||
/// of the whole image. If you want the entire image then leave
|
|
||||||
/// the default value (which is an empty IntRect).
|
|
||||||
/// If the \a area rectangle crosses the bounds of the image, it
|
|
||||||
/// is adjusted to fit the image size.
|
|
||||||
///
|
|
||||||
/// The maximum size for a texture depends on the graphics
|
|
||||||
/// driver and can be retrieved with the getMaximumSize function.
|
|
||||||
///
|
|
||||||
/// If this function fails, the texture is left unchanged.
|
|
||||||
///
|
|
||||||
/// \param stream Source stream to read from
|
|
||||||
/// \param area Area of the image to load
|
|
||||||
///
|
|
||||||
/// \return True if loading was successful
|
|
||||||
///
|
|
||||||
/// \see loadFromFile, loadFromMemory, loadFromImage
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool loadFromStream(InputStream& stream, const IntRect& area = IntRect());
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Load the texture from an image
|
|
||||||
///
|
|
||||||
/// The \a area argument can be used to load only a sub-rectangle
|
|
||||||
/// of the whole image. If you want the entire image then leave
|
|
||||||
/// the default value (which is an empty IntRect).
|
|
||||||
/// If the \a area rectangle crosses the bounds of the image, it
|
|
||||||
/// is adjusted to fit the image size.
|
|
||||||
///
|
|
||||||
/// The maximum size for a texture depends on the graphics
|
|
||||||
/// driver and can be retrieved with the getMaximumSize function.
|
|
||||||
///
|
|
||||||
/// If this function fails, the texture is left unchanged.
|
|
||||||
///
|
|
||||||
/// \param image Image to load into the texture
|
|
||||||
/// \param area Area of the image to load
|
|
||||||
///
|
|
||||||
/// \return True if loading was successful
|
|
||||||
///
|
|
||||||
/// \see loadFromFile, loadFromMemory
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool loadFromImage(const Image& image, const IntRect& area = IntRect());
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Return the size of the texture
|
|
||||||
///
|
|
||||||
/// \return Size in pixels
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Vector2u getSize() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Copy the texture pixels to an image
|
|
||||||
///
|
|
||||||
/// This function performs a slow operation that downloads
|
|
||||||
/// the texture's pixels from the graphics card and copies
|
|
||||||
/// them to a new image, potentially applying transformations
|
|
||||||
/// to pixels if necessary (texture may be padded or flipped).
|
|
||||||
///
|
|
||||||
/// \return Image containing the texture's pixels
|
|
||||||
///
|
|
||||||
/// \see loadFromImage
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Image copyToImage() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Update the whole texture from an array of pixels
|
|
||||||
///
|
|
||||||
/// The \a pixel array is assumed to have the same size as
|
|
||||||
/// the \a area rectangle, and to contain 32-bits RGBA pixels.
|
|
||||||
///
|
|
||||||
/// No additional check is performed on the size of the pixel
|
|
||||||
/// array, passing invalid arguments will lead to an undefined
|
|
||||||
/// behavior.
|
|
||||||
///
|
|
||||||
/// This function does nothing if \a pixels is null or if the
|
|
||||||
/// texture was not previously created.
|
|
||||||
///
|
|
||||||
/// \param pixels Array of pixels to copy to the texture
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void update(const Uint8* pixels);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Update a part of the texture from an array of pixels
|
|
||||||
///
|
|
||||||
/// The size of the \a pixel array must match the \a width and
|
|
||||||
/// \a height arguments, and it must contain 32-bits RGBA pixels.
|
|
||||||
///
|
|
||||||
/// No additional check is performed on the size of the pixel
|
|
||||||
/// array or the bounds of the area to update, passing invalid
|
|
||||||
/// arguments will lead to an undefined behavior.
|
|
||||||
///
|
|
||||||
/// This function does nothing if \a pixels is null or if the
|
|
||||||
/// texture was not previously created.
|
|
||||||
///
|
|
||||||
/// \param pixels Array of pixels to copy to the texture
|
|
||||||
/// \param width Width of the pixel region contained in \a pixels
|
|
||||||
/// \param height Height of the pixel region contained in \a pixels
|
|
||||||
/// \param x X offset in the texture where to copy the source pixels
|
|
||||||
/// \param y Y offset in the texture where to copy the source pixels
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void update(const Uint8* pixels, unsigned int width, unsigned int height, unsigned int x, unsigned int y);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Update the texture from an image
|
|
||||||
///
|
|
||||||
/// Although the source image can be smaller than the texture,
|
|
||||||
/// this function is usually used for updating the whole texture.
|
|
||||||
/// The other overload, which has (x, y) additional arguments,
|
|
||||||
/// is more convenient for updating a sub-area of the texture.
|
|
||||||
///
|
|
||||||
/// No additional check is performed on the size of the image,
|
|
||||||
/// passing an image bigger than the texture will lead to an
|
|
||||||
/// undefined behavior.
|
|
||||||
///
|
|
||||||
/// This function does nothing if the texture was not
|
|
||||||
/// previously created.
|
|
||||||
///
|
|
||||||
/// \param image Image to copy to the texture
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void update(const Image& image);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Update a part of the texture from an image
|
|
||||||
///
|
|
||||||
/// No additional check is performed on the size of the image,
|
|
||||||
/// passing an invalid combination of image size and offset
|
|
||||||
/// will lead to an undefined behavior.
|
|
||||||
///
|
|
||||||
/// This function does nothing if the texture was not
|
|
||||||
/// previously created.
|
|
||||||
///
|
|
||||||
/// \param image Image to copy to the texture
|
|
||||||
/// \param x X offset in the texture where to copy the source image
|
|
||||||
/// \param y Y offset in the texture where to copy the source image
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void update(const Image& image, unsigned int x, unsigned int y);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Update the texture from the contents of a window
|
|
||||||
///
|
|
||||||
/// Although the source window can be smaller than the texture,
|
|
||||||
/// this function is usually used for updating the whole texture.
|
|
||||||
/// The other overload, which has (x, y) additional arguments,
|
|
||||||
/// is more convenient for updating a sub-area of the texture.
|
|
||||||
///
|
|
||||||
/// No additional check is performed on the size of the window,
|
|
||||||
/// passing a window bigger than the texture will lead to an
|
|
||||||
/// undefined behavior.
|
|
||||||
///
|
|
||||||
/// This function does nothing if either the texture or the window
|
|
||||||
/// was not previously created.
|
|
||||||
///
|
|
||||||
/// \param window Window to copy to the texture
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void update(const Window& window);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Update a part of the texture from the contents of a window
|
|
||||||
///
|
|
||||||
/// No additional check is performed on the size of the window,
|
|
||||||
/// passing an invalid combination of window size and offset
|
|
||||||
/// will lead to an undefined behavior.
|
|
||||||
///
|
|
||||||
/// This function does nothing if either the texture or the window
|
|
||||||
/// was not previously created.
|
|
||||||
///
|
|
||||||
/// \param window Window to copy to the texture
|
|
||||||
/// \param x X offset in the texture where to copy the source window
|
|
||||||
/// \param y Y offset in the texture where to copy the source window
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void update(const Window& window, unsigned int x, unsigned int y);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Enable or disable the smooth filter
|
|
||||||
///
|
|
||||||
/// When the filter is activated, the texture appears smoother
|
|
||||||
/// so that pixels are less noticeable. However if you want
|
|
||||||
/// the texture to look exactly the same as its source file,
|
|
||||||
/// you should leave it disabled.
|
|
||||||
/// The smooth filter is disabled by default.
|
|
||||||
///
|
|
||||||
/// \param smooth True to enable smoothing, false to disable it
|
|
||||||
///
|
|
||||||
/// \see isSmooth
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setSmooth(bool smooth);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Tell whether the smooth filter is enabled or not
|
|
||||||
///
|
|
||||||
/// \return True if smoothing is enabled, false if it is disabled
|
|
||||||
///
|
|
||||||
/// \see setSmooth
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool isSmooth() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Enable or disable repeating
|
|
||||||
///
|
|
||||||
/// Repeating is involved when using texture coordinates
|
|
||||||
/// outside the texture rectangle [0, 0, width, height].
|
|
||||||
/// In this case, if repeat mode is enabled, the whole texture
|
|
||||||
/// will be repeated as many times as needed to reach the
|
|
||||||
/// coordinate (for example, if the X texture coordinate is
|
|
||||||
/// 3 * width, the texture will be repeated 3 times).
|
|
||||||
/// If repeat mode is disabled, the "extra space" will instead
|
|
||||||
/// be filled with border pixels.
|
|
||||||
/// Warning: on very old graphics cards, white pixels may appear
|
|
||||||
/// when the texture is repeated. With such cards, repeat mode
|
|
||||||
/// can be used reliably only if the texture has power-of-two
|
|
||||||
/// dimensions (such as 256x128).
|
|
||||||
/// Repeating is disabled by default.
|
|
||||||
///
|
|
||||||
/// \param repeated True to repeat the texture, false to disable repeating
|
|
||||||
///
|
|
||||||
/// \see isRepeated
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setRepeated(bool repeated);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Tell whether the texture is repeated or not
|
|
||||||
///
|
|
||||||
/// \return True if repeat mode is enabled, false if it is disabled
|
|
||||||
///
|
|
||||||
/// \see setRepeated
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool isRepeated() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Overload of assignment operator
|
|
||||||
///
|
|
||||||
/// \param right Instance to assign
|
|
||||||
///
|
|
||||||
/// \return Reference to self
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Texture& operator =(const Texture& right);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the underlying OpenGL handle of the texture.
|
|
||||||
///
|
|
||||||
/// You shouldn't need to use this function, unless you have
|
|
||||||
/// very specific stuff to implement that SFML doesn't support,
|
|
||||||
/// or implement a temporary workaround until a bug is fixed.
|
|
||||||
///
|
|
||||||
/// \return OpenGL handle of the texture or 0 if not yet created
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
unsigned int getNativeHandle() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Bind a texture for rendering
|
|
||||||
///
|
|
||||||
/// This function is not part of the graphics API, it mustn't be
|
|
||||||
/// used when drawing SFML entities. It must be used only if you
|
|
||||||
/// mix sf::Texture with OpenGL code.
|
|
||||||
///
|
|
||||||
/// \code
|
|
||||||
/// sf::Texture t1, t2;
|
|
||||||
/// ...
|
|
||||||
/// sf::Texture::bind(&t1);
|
|
||||||
/// // draw OpenGL stuff that use t1...
|
|
||||||
/// sf::Texture::bind(&t2);
|
|
||||||
/// // draw OpenGL stuff that use t2...
|
|
||||||
/// sf::Texture::bind(NULL);
|
|
||||||
/// // draw OpenGL stuff that use no texture...
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// The \a coordinateType argument controls how texture
|
|
||||||
/// coordinates will be interpreted. If Normalized (the default), they
|
|
||||||
/// must be in range [0 .. 1], which is the default way of handling
|
|
||||||
/// texture coordinates with OpenGL. If Pixels, they must be given
|
|
||||||
/// in pixels (range [0 .. size]). This mode is used internally by
|
|
||||||
/// the graphics classes of SFML, it makes the definition of texture
|
|
||||||
/// coordinates more intuitive for the high-level API, users don't need
|
|
||||||
/// to compute normalized values.
|
|
||||||
///
|
|
||||||
/// \param texture Pointer to the texture to bind, can be null to use no texture
|
|
||||||
/// \param coordinateType Type of texture coordinates to use
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static void bind(const Texture* texture, CoordinateType coordinateType = Normalized);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the maximum texture size allowed
|
|
||||||
///
|
|
||||||
/// This maximum size is defined by the graphics driver.
|
|
||||||
/// You can expect a value of 512 pixels for low-end graphics
|
|
||||||
/// card, and up to 8192 pixels or more for newer hardware.
|
|
||||||
///
|
|
||||||
/// Note: The first call to this function, whether by your
|
|
||||||
/// code or SFML will result in a context switch.
|
|
||||||
///
|
|
||||||
/// \return Maximum size allowed for textures, in pixels
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static unsigned int getMaximumSize();
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
friend class RenderTexture;
|
|
||||||
friend class RenderTarget;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get a valid image size according to hardware support
|
|
||||||
///
|
|
||||||
/// This function checks whether the graphics driver supports
|
|
||||||
/// non power of two sizes or not, and adjusts the size
|
|
||||||
/// accordingly.
|
|
||||||
/// The returned size is greater than or equal to the original size.
|
|
||||||
///
|
|
||||||
/// \param size size to convert
|
|
||||||
///
|
|
||||||
/// \return Valid nearest size (greater than or equal to specified size)
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static unsigned int getValidSize(unsigned int size);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Vector2u m_size; ///< Public texture size
|
|
||||||
Vector2u m_actualSize; ///< Actual texture size (can be greater than public size because of padding)
|
|
||||||
unsigned int m_texture; ///< Internal texture identifier
|
|
||||||
bool m_isSmooth; ///< Status of the smooth filter
|
|
||||||
bool m_isRepeated; ///< Is the texture in repeat mode?
|
|
||||||
mutable bool m_pixelsFlipped; ///< To work around the inconsistency in Y orientation
|
|
||||||
bool m_fboAttachment; ///< Is this texture owned by a framebuffer object?
|
|
||||||
Uint64 m_cacheId; ///< Unique number that identifies the texture to the render target's cache
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_TEXTURE_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::Texture
|
|
||||||
/// \ingroup graphics
|
|
||||||
///
|
|
||||||
/// sf::Texture stores pixels that can be drawn, with a sprite
|
|
||||||
/// for example. A texture lives in the graphics card memory,
|
|
||||||
/// therefore it is very fast to draw a texture to a render target,
|
|
||||||
/// or copy a render target to a texture (the graphics card can
|
|
||||||
/// access both directly).
|
|
||||||
///
|
|
||||||
/// Being stored in the graphics card memory has some drawbacks.
|
|
||||||
/// A texture cannot be manipulated as freely as a sf::Image,
|
|
||||||
/// you need to prepare the pixels first and then upload them
|
|
||||||
/// to the texture in a single operation (see Texture::update).
|
|
||||||
///
|
|
||||||
/// sf::Texture makes it easy to convert from/to sf::Image, but
|
|
||||||
/// keep in mind that these calls require transfers between
|
|
||||||
/// the graphics card and the central memory, therefore they are
|
|
||||||
/// slow operations.
|
|
||||||
///
|
|
||||||
/// A texture can be loaded from an image, but also directly
|
|
||||||
/// from a file/memory/stream. The necessary shortcuts are defined
|
|
||||||
/// so that you don't need an image first for the most common cases.
|
|
||||||
/// However, if you want to perform some modifications on the pixels
|
|
||||||
/// before creating the final texture, you can load your file to a
|
|
||||||
/// sf::Image, do whatever you need with the pixels, and then call
|
|
||||||
/// Texture::loadFromImage.
|
|
||||||
///
|
|
||||||
/// Since they live in the graphics card memory, the pixels of a texture
|
|
||||||
/// cannot be accessed without a slow copy first. And they cannot be
|
|
||||||
/// accessed individually. Therefore, if you need to read the texture's
|
|
||||||
/// pixels (like for pixel-perfect collisions), it is recommended to
|
|
||||||
/// store the collision information separately, for example in an array
|
|
||||||
/// of booleans.
|
|
||||||
///
|
|
||||||
/// Like sf::Image, sf::Texture can handle a unique internal
|
|
||||||
/// representation of pixels, which is RGBA 32 bits. This means
|
|
||||||
/// that a pixel must be composed of 8 bits red, green, blue and
|
|
||||||
/// alpha channels -- just like a sf::Color.
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// // This example shows the most common use of sf::Texture:
|
|
||||||
/// // drawing a sprite
|
|
||||||
///
|
|
||||||
/// // Load a texture from a file
|
|
||||||
/// sf::Texture texture;
|
|
||||||
/// if (!texture.loadFromFile("texture.png"))
|
|
||||||
/// return -1;
|
|
||||||
///
|
|
||||||
/// // Assign it to a sprite
|
|
||||||
/// sf::Sprite sprite;
|
|
||||||
/// sprite.setTexture(texture);
|
|
||||||
///
|
|
||||||
/// // Draw the textured sprite
|
|
||||||
/// window.draw(sprite);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \code
|
|
||||||
/// // This example shows another common use of sf::Texture:
|
|
||||||
/// // streaming real-time data, like video frames
|
|
||||||
///
|
|
||||||
/// // Create an empty texture
|
|
||||||
/// sf::Texture texture;
|
|
||||||
/// if (!texture.create(640, 480))
|
|
||||||
/// return -1;
|
|
||||||
///
|
|
||||||
/// // Create a sprite that will display the texture
|
|
||||||
/// sf::Sprite sprite(texture);
|
|
||||||
///
|
|
||||||
/// while (...) // the main loop
|
|
||||||
/// {
|
|
||||||
/// ...
|
|
||||||
///
|
|
||||||
/// // update the texture
|
|
||||||
/// sf::Uint8* pixels = ...; // get a fresh chunk of pixels (the next frame of a movie, for example)
|
|
||||||
/// texture.update(pixels);
|
|
||||||
///
|
|
||||||
/// // draw it
|
|
||||||
/// window.draw(sprite);
|
|
||||||
///
|
|
||||||
/// ...
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// Like sf::Shader that can be used as a raw OpenGL shader,
|
|
||||||
/// sf::Texture can also be used directly as a raw texture for
|
|
||||||
/// custom OpenGL geometry.
|
|
||||||
/// \code
|
|
||||||
/// sf::Texture::bind(&texture);
|
|
||||||
/// ... render OpenGL geometry ...
|
|
||||||
/// sf::Texture::bind(NULL);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \see sf::Sprite, sf::Image, sf::RenderTexture
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,450 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_TRANSFORM_HPP
|
|
||||||
#define SFML_TRANSFORM_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Graphics/Export.hpp>
|
|
||||||
#include <SFML/Graphics/Rect.hpp>
|
|
||||||
#include <SFML/System/Vector2.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Define a 3x3 transform matrix
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_GRAPHICS_API Transform
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
/// Creates an identity transform (a transform that does nothing).
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Transform();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Construct a transform from a 3x3 matrix
|
|
||||||
///
|
|
||||||
/// \param a00 Element (0, 0) of the matrix
|
|
||||||
/// \param a01 Element (0, 1) of the matrix
|
|
||||||
/// \param a02 Element (0, 2) of the matrix
|
|
||||||
/// \param a10 Element (1, 0) of the matrix
|
|
||||||
/// \param a11 Element (1, 1) of the matrix
|
|
||||||
/// \param a12 Element (1, 2) of the matrix
|
|
||||||
/// \param a20 Element (2, 0) of the matrix
|
|
||||||
/// \param a21 Element (2, 1) of the matrix
|
|
||||||
/// \param a22 Element (2, 2) of the matrix
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Transform(float a00, float a01, float a02,
|
|
||||||
float a10, float a11, float a12,
|
|
||||||
float a20, float a21, float a22);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Return the transform as a 4x4 matrix
|
|
||||||
///
|
|
||||||
/// This function returns a pointer to an array of 16 floats
|
|
||||||
/// containing the transform elements as a 4x4 matrix, which
|
|
||||||
/// is directly compatible with OpenGL functions.
|
|
||||||
///
|
|
||||||
/// \code
|
|
||||||
/// sf::Transform transform = ...;
|
|
||||||
/// glLoadMatrixf(transform.getMatrix());
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \return Pointer to a 4x4 matrix
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const float* getMatrix() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Return the inverse of the transform
|
|
||||||
///
|
|
||||||
/// If the inverse cannot be computed, an identity transform
|
|
||||||
/// is returned.
|
|
||||||
///
|
|
||||||
/// \return A new transform which is the inverse of self
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Transform getInverse() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Transform a 2D point
|
|
||||||
///
|
|
||||||
/// \param x X coordinate of the point to transform
|
|
||||||
/// \param y Y coordinate of the point to transform
|
|
||||||
///
|
|
||||||
/// \return Transformed point
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Vector2f transformPoint(float x, float y) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Transform a 2D point
|
|
||||||
///
|
|
||||||
/// \param point Point to transform
|
|
||||||
///
|
|
||||||
/// \return Transformed point
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Vector2f transformPoint(const Vector2f& point) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Transform a rectangle
|
|
||||||
///
|
|
||||||
/// Since SFML doesn't provide support for oriented rectangles,
|
|
||||||
/// the result of this function is always an axis-aligned
|
|
||||||
/// rectangle. Which means that if the transform contains a
|
|
||||||
/// rotation, the bounding rectangle of the transformed rectangle
|
|
||||||
/// is returned.
|
|
||||||
///
|
|
||||||
/// \param rectangle Rectangle to transform
|
|
||||||
///
|
|
||||||
/// \return Transformed rectangle
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
FloatRect transformRect(const FloatRect& rectangle) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Combine the current transform with another one
|
|
||||||
///
|
|
||||||
/// The result is a transform that is equivalent to applying
|
|
||||||
/// *this followed by \a transform. Mathematically, it is
|
|
||||||
/// equivalent to a matrix multiplication.
|
|
||||||
///
|
|
||||||
/// \param transform Transform to combine with this transform
|
|
||||||
///
|
|
||||||
/// \return Reference to *this
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Transform& combine(const Transform& transform);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Combine the current transform with a translation
|
|
||||||
///
|
|
||||||
/// This function returns a reference to *this, so that calls
|
|
||||||
/// can be chained.
|
|
||||||
/// \code
|
|
||||||
/// sf::Transform transform;
|
|
||||||
/// transform.translate(100, 200).rotate(45);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \param x Offset to apply on X axis
|
|
||||||
/// \param y Offset to apply on Y axis
|
|
||||||
///
|
|
||||||
/// \return Reference to *this
|
|
||||||
///
|
|
||||||
/// \see rotate, scale
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Transform& translate(float x, float y);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Combine the current transform with a translation
|
|
||||||
///
|
|
||||||
/// This function returns a reference to *this, so that calls
|
|
||||||
/// can be chained.
|
|
||||||
/// \code
|
|
||||||
/// sf::Transform transform;
|
|
||||||
/// transform.translate(sf::Vector2f(100, 200)).rotate(45);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \param offset Translation offset to apply
|
|
||||||
///
|
|
||||||
/// \return Reference to *this
|
|
||||||
///
|
|
||||||
/// \see rotate, scale
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Transform& translate(const Vector2f& offset);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Combine the current transform with a rotation
|
|
||||||
///
|
|
||||||
/// This function returns a reference to *this, so that calls
|
|
||||||
/// can be chained.
|
|
||||||
/// \code
|
|
||||||
/// sf::Transform transform;
|
|
||||||
/// transform.rotate(90).translate(50, 20);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \param angle Rotation angle, in degrees
|
|
||||||
///
|
|
||||||
/// \return Reference to *this
|
|
||||||
///
|
|
||||||
/// \see translate, scale
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Transform& rotate(float angle);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Combine the current transform with a rotation
|
|
||||||
///
|
|
||||||
/// The center of rotation is provided for convenience as a second
|
|
||||||
/// argument, so that you can build rotations around arbitrary points
|
|
||||||
/// more easily (and efficiently) than the usual
|
|
||||||
/// translate(-center).rotate(angle).translate(center).
|
|
||||||
///
|
|
||||||
/// This function returns a reference to *this, so that calls
|
|
||||||
/// can be chained.
|
|
||||||
/// \code
|
|
||||||
/// sf::Transform transform;
|
|
||||||
/// transform.rotate(90, 8, 3).translate(50, 20);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \param angle Rotation angle, in degrees
|
|
||||||
/// \param centerX X coordinate of the center of rotation
|
|
||||||
/// \param centerY Y coordinate of the center of rotation
|
|
||||||
///
|
|
||||||
/// \return Reference to *this
|
|
||||||
///
|
|
||||||
/// \see translate, scale
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Transform& rotate(float angle, float centerX, float centerY);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Combine the current transform with a rotation
|
|
||||||
///
|
|
||||||
/// The center of rotation is provided for convenience as a second
|
|
||||||
/// argument, so that you can build rotations around arbitrary points
|
|
||||||
/// more easily (and efficiently) than the usual
|
|
||||||
/// translate(-center).rotate(angle).translate(center).
|
|
||||||
///
|
|
||||||
/// This function returns a reference to *this, so that calls
|
|
||||||
/// can be chained.
|
|
||||||
/// \code
|
|
||||||
/// sf::Transform transform;
|
|
||||||
/// transform.rotate(90, sf::Vector2f(8, 3)).translate(sf::Vector2f(50, 20));
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \param angle Rotation angle, in degrees
|
|
||||||
/// \param center Center of rotation
|
|
||||||
///
|
|
||||||
/// \return Reference to *this
|
|
||||||
///
|
|
||||||
/// \see translate, scale
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Transform& rotate(float angle, const Vector2f& center);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Combine the current transform with a scaling
|
|
||||||
///
|
|
||||||
/// This function returns a reference to *this, so that calls
|
|
||||||
/// can be chained.
|
|
||||||
/// \code
|
|
||||||
/// sf::Transform transform;
|
|
||||||
/// transform.scale(2, 1).rotate(45);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \param scaleX Scaling factor on the X axis
|
|
||||||
/// \param scaleY Scaling factor on the Y axis
|
|
||||||
///
|
|
||||||
/// \return Reference to *this
|
|
||||||
///
|
|
||||||
/// \see translate, rotate
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Transform& scale(float scaleX, float scaleY);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Combine the current transform with a scaling
|
|
||||||
///
|
|
||||||
/// The center of scaling is provided for convenience as a second
|
|
||||||
/// argument, so that you can build scaling around arbitrary points
|
|
||||||
/// more easily (and efficiently) than the usual
|
|
||||||
/// translate(-center).scale(factors).translate(center).
|
|
||||||
///
|
|
||||||
/// This function returns a reference to *this, so that calls
|
|
||||||
/// can be chained.
|
|
||||||
/// \code
|
|
||||||
/// sf::Transform transform;
|
|
||||||
/// transform.scale(2, 1, 8, 3).rotate(45);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \param scaleX Scaling factor on X axis
|
|
||||||
/// \param scaleY Scaling factor on Y axis
|
|
||||||
/// \param centerX X coordinate of the center of scaling
|
|
||||||
/// \param centerY Y coordinate of the center of scaling
|
|
||||||
///
|
|
||||||
/// \return Reference to *this
|
|
||||||
///
|
|
||||||
/// \see translate, rotate
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Transform& scale(float scaleX, float scaleY, float centerX, float centerY);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Combine the current transform with a scaling
|
|
||||||
///
|
|
||||||
/// This function returns a reference to *this, so that calls
|
|
||||||
/// can be chained.
|
|
||||||
/// \code
|
|
||||||
/// sf::Transform transform;
|
|
||||||
/// transform.scale(sf::Vector2f(2, 1)).rotate(45);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \param factors Scaling factors
|
|
||||||
///
|
|
||||||
/// \return Reference to *this
|
|
||||||
///
|
|
||||||
/// \see translate, rotate
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Transform& scale(const Vector2f& factors);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Combine the current transform with a scaling
|
|
||||||
///
|
|
||||||
/// The center of scaling is provided for convenience as a second
|
|
||||||
/// argument, so that you can build scaling around arbitrary points
|
|
||||||
/// more easily (and efficiently) than the usual
|
|
||||||
/// translate(-center).scale(factors).translate(center).
|
|
||||||
///
|
|
||||||
/// This function returns a reference to *this, so that calls
|
|
||||||
/// can be chained.
|
|
||||||
/// \code
|
|
||||||
/// sf::Transform transform;
|
|
||||||
/// transform.scale(sf::Vector2f(2, 1), sf::Vector2f(8, 3)).rotate(45);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \param factors Scaling factors
|
|
||||||
/// \param center Center of scaling
|
|
||||||
///
|
|
||||||
/// \return Reference to *this
|
|
||||||
///
|
|
||||||
/// \see translate, rotate
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Transform& scale(const Vector2f& factors, const Vector2f& center);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Static member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static const Transform Identity; ///< The identity transform (does nothing)
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
float m_matrix[16]; ///< 4x4 matrix defining the transformation
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \relates sf::Transform
|
|
||||||
/// \brief Overload of binary operator * to combine two transforms
|
|
||||||
///
|
|
||||||
/// This call is equivalent to calling Transform(left).combine(right).
|
|
||||||
///
|
|
||||||
/// \param left Left operand (the first transform)
|
|
||||||
/// \param right Right operand (the second transform)
|
|
||||||
///
|
|
||||||
/// \return New combined transform
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SFML_GRAPHICS_API Transform operator *(const Transform& left, const Transform& right);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \relates sf::Transform
|
|
||||||
/// \brief Overload of binary operator *= to combine two transforms
|
|
||||||
///
|
|
||||||
/// This call is equivalent to calling left.combine(right).
|
|
||||||
///
|
|
||||||
/// \param left Left operand (the first transform)
|
|
||||||
/// \param right Right operand (the second transform)
|
|
||||||
///
|
|
||||||
/// \return The combined transform
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SFML_GRAPHICS_API Transform& operator *=(Transform& left, const Transform& right);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \relates sf::Transform
|
|
||||||
/// \brief Overload of binary operator * to transform a point
|
|
||||||
///
|
|
||||||
/// This call is equivalent to calling left.transformPoint(right).
|
|
||||||
///
|
|
||||||
/// \param left Left operand (the transform)
|
|
||||||
/// \param right Right operand (the point to transform)
|
|
||||||
///
|
|
||||||
/// \return New transformed point
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SFML_GRAPHICS_API Vector2f operator *(const Transform& left, const Vector2f& right);
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_TRANSFORM_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::Transform
|
|
||||||
/// \ingroup graphics
|
|
||||||
///
|
|
||||||
/// A sf::Transform specifies how to translate, rotate, scale,
|
|
||||||
/// shear, project, whatever things. In mathematical terms, it defines
|
|
||||||
/// how to transform a coordinate system into another.
|
|
||||||
///
|
|
||||||
/// For example, if you apply a rotation transform to a sprite, the
|
|
||||||
/// result will be a rotated sprite. And anything that is transformed
|
|
||||||
/// by this rotation transform will be rotated the same way, according
|
|
||||||
/// to its initial position.
|
|
||||||
///
|
|
||||||
/// Transforms are typically used for drawing. But they can also be
|
|
||||||
/// used for any computation that requires to transform points between
|
|
||||||
/// the local and global coordinate systems of an entity (like collision
|
|
||||||
/// detection).
|
|
||||||
///
|
|
||||||
/// Example:
|
|
||||||
/// \code
|
|
||||||
/// // define a translation transform
|
|
||||||
/// sf::Transform translation;
|
|
||||||
/// translation.translate(20, 50);
|
|
||||||
///
|
|
||||||
/// // define a rotation transform
|
|
||||||
/// sf::Transform rotation;
|
|
||||||
/// rotation.rotate(45);
|
|
||||||
///
|
|
||||||
/// // combine them
|
|
||||||
/// sf::Transform transform = translation * rotation;
|
|
||||||
///
|
|
||||||
/// // use the result to transform stuff...
|
|
||||||
/// sf::Vector2f point = transform.transformPoint(10, 20);
|
|
||||||
/// sf::FloatRect rect = transform.transformRect(sf::FloatRect(0, 0, 10, 100));
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \see sf::Transformable, sf::RenderStates
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,429 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_TRANSFORMABLE_HPP
|
|
||||||
#define SFML_TRANSFORMABLE_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Graphics/Export.hpp>
|
|
||||||
#include <SFML/Graphics/Transform.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Decomposed transform defined by a position, a rotation and a scale
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_GRAPHICS_API Transformable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Transformable();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Virtual destructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual ~Transformable();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief set the position of the object
|
|
||||||
///
|
|
||||||
/// This function completely overwrites the previous position.
|
|
||||||
/// See the move function to apply an offset based on the previous position instead.
|
|
||||||
/// The default position of a transformable object is (0, 0).
|
|
||||||
///
|
|
||||||
/// \param x X coordinate of the new position
|
|
||||||
/// \param y Y coordinate of the new position
|
|
||||||
///
|
|
||||||
/// \see move, getPosition
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setPosition(float x, float y);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief set the position of the object
|
|
||||||
///
|
|
||||||
/// This function completely overwrites the previous position.
|
|
||||||
/// See the move function to apply an offset based on the previous position instead.
|
|
||||||
/// The default position of a transformable object is (0, 0).
|
|
||||||
///
|
|
||||||
/// \param position New position
|
|
||||||
///
|
|
||||||
/// \see move, getPosition
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setPosition(const Vector2f& position);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief set the orientation of the object
|
|
||||||
///
|
|
||||||
/// This function completely overwrites the previous rotation.
|
|
||||||
/// See the rotate function to add an angle based on the previous rotation instead.
|
|
||||||
/// The default rotation of a transformable object is 0.
|
|
||||||
///
|
|
||||||
/// \param angle New rotation, in degrees
|
|
||||||
///
|
|
||||||
/// \see rotate, getRotation
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setRotation(float angle);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief set the scale factors of the object
|
|
||||||
///
|
|
||||||
/// This function completely overwrites the previous scale.
|
|
||||||
/// See the scale function to add a factor based on the previous scale instead.
|
|
||||||
/// The default scale of a transformable object is (1, 1).
|
|
||||||
///
|
|
||||||
/// \param factorX New horizontal scale factor
|
|
||||||
/// \param factorY New vertical scale factor
|
|
||||||
///
|
|
||||||
/// \see scale, getScale
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setScale(float factorX, float factorY);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief set the scale factors of the object
|
|
||||||
///
|
|
||||||
/// This function completely overwrites the previous scale.
|
|
||||||
/// See the scale function to add a factor based on the previous scale instead.
|
|
||||||
/// The default scale of a transformable object is (1, 1).
|
|
||||||
///
|
|
||||||
/// \param factors New scale factors
|
|
||||||
///
|
|
||||||
/// \see scale, getScale
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setScale(const Vector2f& factors);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief set the local origin of the object
|
|
||||||
///
|
|
||||||
/// The origin of an object defines the center point for
|
|
||||||
/// all transformations (position, scale, rotation).
|
|
||||||
/// The coordinates of this point must be relative to the
|
|
||||||
/// top-left corner of the object, and ignore all
|
|
||||||
/// transformations (position, scale, rotation).
|
|
||||||
/// The default origin of a transformable object is (0, 0).
|
|
||||||
///
|
|
||||||
/// \param x X coordinate of the new origin
|
|
||||||
/// \param y Y coordinate of the new origin
|
|
||||||
///
|
|
||||||
/// \see getOrigin
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setOrigin(float x, float y);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief set the local origin of the object
|
|
||||||
///
|
|
||||||
/// The origin of an object defines the center point for
|
|
||||||
/// all transformations (position, scale, rotation).
|
|
||||||
/// The coordinates of this point must be relative to the
|
|
||||||
/// top-left corner of the object, and ignore all
|
|
||||||
/// transformations (position, scale, rotation).
|
|
||||||
/// The default origin of a transformable object is (0, 0).
|
|
||||||
///
|
|
||||||
/// \param origin New origin
|
|
||||||
///
|
|
||||||
/// \see getOrigin
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setOrigin(const Vector2f& origin);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief get the position of the object
|
|
||||||
///
|
|
||||||
/// \return Current position
|
|
||||||
///
|
|
||||||
/// \see setPosition
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const Vector2f& getPosition() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief get the orientation of the object
|
|
||||||
///
|
|
||||||
/// The rotation is always in the range [0, 360].
|
|
||||||
///
|
|
||||||
/// \return Current rotation, in degrees
|
|
||||||
///
|
|
||||||
/// \see setRotation
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
float getRotation() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief get the current scale of the object
|
|
||||||
///
|
|
||||||
/// \return Current scale factors
|
|
||||||
///
|
|
||||||
/// \see setScale
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const Vector2f& getScale() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief get the local origin of the object
|
|
||||||
///
|
|
||||||
/// \return Current origin
|
|
||||||
///
|
|
||||||
/// \see setOrigin
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const Vector2f& getOrigin() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Move the object by a given offset
|
|
||||||
///
|
|
||||||
/// This function adds to the current position of the object,
|
|
||||||
/// unlike setPosition which overwrites it.
|
|
||||||
/// Thus, it is equivalent to the following code:
|
|
||||||
/// \code
|
|
||||||
/// sf::Vector2f pos = object.getPosition();
|
|
||||||
/// object.setPosition(pos.x + offsetX, pos.y + offsetY);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \param offsetX X offset
|
|
||||||
/// \param offsetY Y offset
|
|
||||||
///
|
|
||||||
/// \see setPosition
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void move(float offsetX, float offsetY);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Move the object by a given offset
|
|
||||||
///
|
|
||||||
/// This function adds to the current position of the object,
|
|
||||||
/// unlike setPosition which overwrites it.
|
|
||||||
/// Thus, it is equivalent to the following code:
|
|
||||||
/// \code
|
|
||||||
/// object.setPosition(object.getPosition() + offset);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \param offset Offset
|
|
||||||
///
|
|
||||||
/// \see setPosition
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void move(const Vector2f& offset);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Rotate the object
|
|
||||||
///
|
|
||||||
/// This function adds to the current rotation of the object,
|
|
||||||
/// unlike setRotation which overwrites it.
|
|
||||||
/// Thus, it is equivalent to the following code:
|
|
||||||
/// \code
|
|
||||||
/// object.setRotation(object.getRotation() + angle);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \param angle Angle of rotation, in degrees
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void rotate(float angle);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Scale the object
|
|
||||||
///
|
|
||||||
/// This function multiplies the current scale of the object,
|
|
||||||
/// unlike setScale which overwrites it.
|
|
||||||
/// Thus, it is equivalent to the following code:
|
|
||||||
/// \code
|
|
||||||
/// sf::Vector2f scale = object.getScale();
|
|
||||||
/// object.setScale(scale.x * factorX, scale.y * factorY);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \param factorX Horizontal scale factor
|
|
||||||
/// \param factorY Vertical scale factor
|
|
||||||
///
|
|
||||||
/// \see setScale
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void scale(float factorX, float factorY);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Scale the object
|
|
||||||
///
|
|
||||||
/// This function multiplies the current scale of the object,
|
|
||||||
/// unlike setScale which overwrites it.
|
|
||||||
/// Thus, it is equivalent to the following code:
|
|
||||||
/// \code
|
|
||||||
/// sf::Vector2f scale = object.getScale();
|
|
||||||
/// object.setScale(scale.x * factor.x, scale.y * factor.y);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \param factor Scale factors
|
|
||||||
///
|
|
||||||
/// \see setScale
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void scale(const Vector2f& factor);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief get the combined transform of the object
|
|
||||||
///
|
|
||||||
/// \return Transform combining the position/rotation/scale/origin of the object
|
|
||||||
///
|
|
||||||
/// \see getInverseTransform
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const Transform& getTransform() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief get the inverse of the combined transform of the object
|
|
||||||
///
|
|
||||||
/// \return Inverse of the combined transformations applied to the object
|
|
||||||
///
|
|
||||||
/// \see getTransform
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const Transform& getInverseTransform() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Vector2f m_origin; ///< Origin of translation/rotation/scaling of the object
|
|
||||||
Vector2f m_position; ///< Position of the object in the 2D world
|
|
||||||
float m_rotation; ///< Orientation of the object, in degrees
|
|
||||||
Vector2f m_scale; ///< Scale of the object
|
|
||||||
mutable Transform m_transform; ///< Combined transformation of the object
|
|
||||||
mutable bool m_transformNeedUpdate; ///< Does the transform need to be recomputed?
|
|
||||||
mutable Transform m_inverseTransform; ///< Combined transformation of the object
|
|
||||||
mutable bool m_inverseTransformNeedUpdate; ///< Does the transform need to be recomputed?
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_TRANSFORMABLE_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::Transformable
|
|
||||||
/// \ingroup graphics
|
|
||||||
///
|
|
||||||
/// This class is provided for convenience, on top of sf::Transform.
|
|
||||||
///
|
|
||||||
/// sf::Transform, as a low-level class, offers a great level of
|
|
||||||
/// flexibility but it is not always convenient to manage. Indeed,
|
|
||||||
/// one can easily combine any kind of operation, such as a translation
|
|
||||||
/// followed by a rotation followed by a scaling, but once the result
|
|
||||||
/// transform is built, there's no way to go backward and, let's say,
|
|
||||||
/// change only the rotation without modifying the translation and scaling.
|
|
||||||
/// The entire transform must be recomputed, which means that you
|
|
||||||
/// need to retrieve the initial translation and scale factors as
|
|
||||||
/// well, and combine them the same way you did before updating the
|
|
||||||
/// rotation. This is a tedious operation, and it requires to store
|
|
||||||
/// all the individual components of the final transform.
|
|
||||||
///
|
|
||||||
/// That's exactly what sf::Transformable was written for: it hides
|
|
||||||
/// these variables and the composed transform behind an easy to use
|
|
||||||
/// interface. You can set or get any of the individual components
|
|
||||||
/// without worrying about the others. It also provides the composed
|
|
||||||
/// transform (as a sf::Transform), and keeps it up-to-date.
|
|
||||||
///
|
|
||||||
/// In addition to the position, rotation and scale, sf::Transformable
|
|
||||||
/// provides an "origin" component, which represents the local origin
|
|
||||||
/// of the three other components. Let's take an example with a 10x10
|
|
||||||
/// pixels sprite. By default, the sprite is positioned/rotated/scaled
|
|
||||||
/// relatively to its top-left corner, because it is the local point
|
|
||||||
/// (0, 0). But if we change the origin to be (5, 5), the sprite will
|
|
||||||
/// be positioned/rotated/scaled around its center instead. And if
|
|
||||||
/// we set the origin to (10, 10), it will be transformed around its
|
|
||||||
/// bottom-right corner.
|
|
||||||
///
|
|
||||||
/// To keep the sf::Transformable class simple, there's only one
|
|
||||||
/// origin for all the components. You cannot position the sprite
|
|
||||||
/// relatively to its top-left corner while rotating it around its
|
|
||||||
/// center, for example. To do such things, use sf::Transform directly.
|
|
||||||
///
|
|
||||||
/// sf::Transformable can be used as a base class. It is often
|
|
||||||
/// combined with sf::Drawable -- that's what SFML's sprites,
|
|
||||||
/// texts and shapes do.
|
|
||||||
/// \code
|
|
||||||
/// class MyEntity : public sf::Transformable, public sf::Drawable
|
|
||||||
/// {
|
|
||||||
/// virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
|
|
||||||
/// {
|
|
||||||
/// states.transform *= getTransform();
|
|
||||||
/// target.draw(..., states);
|
|
||||||
/// }
|
|
||||||
/// };
|
|
||||||
///
|
|
||||||
/// MyEntity entity;
|
|
||||||
/// entity.setPosition(10, 20);
|
|
||||||
/// entity.setRotation(45);
|
|
||||||
/// window.draw(entity);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// It can also be used as a member, if you don't want to use
|
|
||||||
/// its API directly (because you don't need all its functions,
|
|
||||||
/// or you have different naming conventions for example).
|
|
||||||
/// \code
|
|
||||||
/// class MyEntity
|
|
||||||
/// {
|
|
||||||
/// public:
|
|
||||||
/// void SetPosition(const MyVector& v)
|
|
||||||
/// {
|
|
||||||
/// myTransform.setPosition(v.x(), v.y());
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// void Draw(sf::RenderTarget& target) const
|
|
||||||
/// {
|
|
||||||
/// target.draw(..., myTransform.getTransform());
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// private:
|
|
||||||
/// sf::Transformable myTransform;
|
|
||||||
/// };
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// A note on coordinates and undistorted rendering: \n
|
|
||||||
/// By default, SFML (or more exactly, OpenGL) may interpolate drawable objects
|
|
||||||
/// such as sprites or texts when rendering. While this allows transitions
|
|
||||||
/// like slow movements or rotations to appear smoothly, it can lead to
|
|
||||||
/// unwanted results in some cases, for example blurred or distorted objects.
|
|
||||||
/// In order to render a sf::Drawable object pixel-perfectly, make sure
|
|
||||||
/// the involved coordinates allow a 1:1 mapping of pixels in the window
|
|
||||||
/// to texels (pixels in the texture). More specifically, this means:
|
|
||||||
/// * The object's position, origin and scale have no fractional part
|
|
||||||
/// * The object's and the view's rotation are a multiple of 90 degrees
|
|
||||||
/// * The view's center and size have no fractional part
|
|
||||||
///
|
|
||||||
/// \see sf::Transform
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,148 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_VERTEX_HPP
|
|
||||||
#define SFML_VERTEX_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Graphics/Export.hpp>
|
|
||||||
#include <SFML/Graphics/Color.hpp>
|
|
||||||
#include <SFML/System/Vector2.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Define a point with color and texture coordinates
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_GRAPHICS_API Vertex
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Vertex();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Construct the vertex from its position
|
|
||||||
///
|
|
||||||
/// The vertex color is white and texture coordinates are (0, 0).
|
|
||||||
///
|
|
||||||
/// \param thePosition Vertex position
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Vertex(const Vector2f& thePosition);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Construct the vertex from its position and color
|
|
||||||
///
|
|
||||||
/// The texture coordinates are (0, 0).
|
|
||||||
///
|
|
||||||
/// \param thePosition Vertex position
|
|
||||||
/// \param theColor Vertex color
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Vertex(const Vector2f& thePosition, const Color& theColor);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Construct the vertex from its position and texture coordinates
|
|
||||||
///
|
|
||||||
/// The vertex color is white.
|
|
||||||
///
|
|
||||||
/// \param thePosition Vertex position
|
|
||||||
/// \param theTexCoords Vertex texture coordinates
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Vertex(const Vector2f& thePosition, const Vector2f& theTexCoords);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Construct the vertex from its position, color and texture coordinates
|
|
||||||
///
|
|
||||||
/// \param thePosition Vertex position
|
|
||||||
/// \param theColor Vertex color
|
|
||||||
/// \param theTexCoords Vertex texture coordinates
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Vertex(const Vector2f& thePosition, const Color& theColor, const Vector2f& theTexCoords);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Vector2f position; ///< 2D position of the vertex
|
|
||||||
Color color; ///< Color of the vertex
|
|
||||||
Vector2f texCoords; ///< Coordinates of the texture's pixel to map to the vertex
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_VERTEX_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::Vertex
|
|
||||||
/// \ingroup graphics
|
|
||||||
///
|
|
||||||
/// A vertex is an improved point. It has a position and other
|
|
||||||
/// extra attributes that will be used for drawing: in SFML,
|
|
||||||
/// vertices also have a color and a pair of texture coordinates.
|
|
||||||
///
|
|
||||||
/// The vertex is the building block of drawing. Everything which
|
|
||||||
/// is visible on screen is made of vertices. They are grouped
|
|
||||||
/// as 2D primitives (triangles, quads, ...), and these primitives
|
|
||||||
/// are grouped to create even more complex 2D entities such as
|
|
||||||
/// sprites, texts, etc.
|
|
||||||
///
|
|
||||||
/// If you use the graphical entities of SFML (sprite, text, shape)
|
|
||||||
/// you won't have to deal with vertices directly. But if you want
|
|
||||||
/// to define your own 2D entities, such as tiled maps or particle
|
|
||||||
/// systems, using vertices will allow you to get maximum performances.
|
|
||||||
///
|
|
||||||
/// Example:
|
|
||||||
/// \code
|
|
||||||
/// // define a 100x100 square, red, with a 10x10 texture mapped on it
|
|
||||||
/// sf::Vertex vertices[] =
|
|
||||||
/// {
|
|
||||||
/// sf::Vertex(sf::Vector2f( 0, 0), sf::Color::Red, sf::Vector2f( 0, 0)),
|
|
||||||
/// sf::Vertex(sf::Vector2f( 0, 100), sf::Color::Red, sf::Vector2f( 0, 10)),
|
|
||||||
/// sf::Vertex(sf::Vector2f(100, 100), sf::Color::Red, sf::Vector2f(10, 10)),
|
|
||||||
/// sf::Vertex(sf::Vector2f(100, 0), sf::Color::Red, sf::Vector2f(10, 0))
|
|
||||||
/// };
|
|
||||||
///
|
|
||||||
/// // draw it
|
|
||||||
/// window.draw(vertices, 4, sf::Quads);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// Note: although texture coordinates are supposed to be an integer
|
|
||||||
/// amount of pixels, their type is float because of some buggy graphics
|
|
||||||
/// drivers that are not able to process integer coordinates correctly.
|
|
||||||
///
|
|
||||||
/// \see sf::VertexArray
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,223 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_VERTEXARRAY_HPP
|
|
||||||
#define SFML_VERTEXARRAY_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Graphics/Export.hpp>
|
|
||||||
#include <SFML/Graphics/Vertex.hpp>
|
|
||||||
#include <SFML/Graphics/PrimitiveType.hpp>
|
|
||||||
#include <SFML/Graphics/Rect.hpp>
|
|
||||||
#include <SFML/Graphics/Drawable.hpp>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Define a set of one or more 2D primitives
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_GRAPHICS_API VertexArray : public Drawable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
/// Creates an empty vertex array.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
VertexArray();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Construct the vertex array with a type and an initial number of vertices
|
|
||||||
///
|
|
||||||
/// \param type Type of primitives
|
|
||||||
/// \param vertexCount Initial number of vertices in the array
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
explicit VertexArray(PrimitiveType type, std::size_t vertexCount = 0);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Return the vertex count
|
|
||||||
///
|
|
||||||
/// \return Number of vertices in the array
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
std::size_t getVertexCount() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get a read-write access to a vertex by its index
|
|
||||||
///
|
|
||||||
/// This function doesn't check \a index, it must be in range
|
|
||||||
/// [0, getVertexCount() - 1]. The behavior is undefined
|
|
||||||
/// otherwise.
|
|
||||||
///
|
|
||||||
/// \param index Index of the vertex to get
|
|
||||||
///
|
|
||||||
/// \return Reference to the index-th vertex
|
|
||||||
///
|
|
||||||
/// \see getVertexCount
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Vertex& operator [](std::size_t index);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get a read-only access to a vertex by its index
|
|
||||||
///
|
|
||||||
/// This function doesn't check \a index, it must be in range
|
|
||||||
/// [0, getVertexCount() - 1]. The behavior is undefined
|
|
||||||
/// otherwise.
|
|
||||||
///
|
|
||||||
/// \param index Index of the vertex to get
|
|
||||||
///
|
|
||||||
/// \return Const reference to the index-th vertex
|
|
||||||
///
|
|
||||||
/// \see getVertexCount
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const Vertex& operator [](std::size_t index) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Clear the vertex array
|
|
||||||
///
|
|
||||||
/// This function removes all the vertices from the array.
|
|
||||||
/// It doesn't deallocate the corresponding memory, so that
|
|
||||||
/// adding new vertices after clearing doesn't involve
|
|
||||||
/// reallocating all the memory.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void clear();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Resize the vertex array
|
|
||||||
///
|
|
||||||
/// If \a vertexCount is greater than the current size, the previous
|
|
||||||
/// vertices are kept and new (default-constructed) vertices are
|
|
||||||
/// added.
|
|
||||||
/// If \a vertexCount is less than the current size, existing vertices
|
|
||||||
/// are removed from the array.
|
|
||||||
///
|
|
||||||
/// \param vertexCount New size of the array (number of vertices)
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void resize(std::size_t vertexCount);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Add a vertex to the array
|
|
||||||
///
|
|
||||||
/// \param vertex Vertex to add
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void append(const Vertex& vertex);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the type of primitives to draw
|
|
||||||
///
|
|
||||||
/// This function defines how the vertices must be interpreted
|
|
||||||
/// when it's time to draw them:
|
|
||||||
/// \li As points
|
|
||||||
/// \li As lines
|
|
||||||
/// \li As triangles
|
|
||||||
/// \li As quads
|
|
||||||
/// The default primitive type is sf::Points.
|
|
||||||
///
|
|
||||||
/// \param type Type of primitive
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setPrimitiveType(PrimitiveType type);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the type of primitives drawn by the vertex array
|
|
||||||
///
|
|
||||||
/// \return Primitive type
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
PrimitiveType getPrimitiveType() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Compute the bounding rectangle of the vertex array
|
|
||||||
///
|
|
||||||
/// This function returns the minimal axis-aligned rectangle
|
|
||||||
/// that contains all the vertices of the array.
|
|
||||||
///
|
|
||||||
/// \return Bounding rectangle of the vertex array
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
FloatRect getBounds() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Draw the vertex array to a render target
|
|
||||||
///
|
|
||||||
/// \param target Render target to draw to
|
|
||||||
/// \param states Current render states
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual void draw(RenderTarget& target, RenderStates states) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
std::vector<Vertex> m_vertices; ///< Vertices contained in the array
|
|
||||||
PrimitiveType m_primitiveType; ///< Type of primitives to draw
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_VERTEXARRAY_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::VertexArray
|
|
||||||
/// \ingroup graphics
|
|
||||||
///
|
|
||||||
/// sf::VertexArray is a very simple wrapper around a dynamic
|
|
||||||
/// array of vertices and a primitives type.
|
|
||||||
///
|
|
||||||
/// It inherits sf::Drawable, but unlike other drawables it
|
|
||||||
/// is not transformable.
|
|
||||||
///
|
|
||||||
/// Example:
|
|
||||||
/// \code
|
|
||||||
/// sf::VertexArray lines(sf::LinesStrip, 4);
|
|
||||||
/// lines[0].position = sf::Vector2f(10, 0);
|
|
||||||
/// lines[1].position = sf::Vector2f(20, 0);
|
|
||||||
/// lines[2].position = sf::Vector2f(30, 5);
|
|
||||||
/// lines[3].position = sf::Vector2f(40, 2);
|
|
||||||
///
|
|
||||||
/// window.draw(lines);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \see sf::Vertex
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,343 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_VIEW_HPP
|
|
||||||
#define SFML_VIEW_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Graphics/Export.hpp>
|
|
||||||
#include <SFML/Graphics/Rect.hpp>
|
|
||||||
#include <SFML/Graphics/Transform.hpp>
|
|
||||||
#include <SFML/System/Vector2.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief 2D camera that defines what region is shown on screen
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_GRAPHICS_API View
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
/// This constructor creates a default view of (0, 0, 1000, 1000)
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
View();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Construct the view from a rectangle
|
|
||||||
///
|
|
||||||
/// \param rectangle Rectangle defining the zone to display
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
explicit View(const FloatRect& rectangle);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Construct the view from its center and size
|
|
||||||
///
|
|
||||||
/// \param center Center of the zone to display
|
|
||||||
/// \param size Size of zone to display
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
View(const Vector2f& center, const Vector2f& size);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the center of the view
|
|
||||||
///
|
|
||||||
/// \param x X coordinate of the new center
|
|
||||||
/// \param y Y coordinate of the new center
|
|
||||||
///
|
|
||||||
/// \see setSize, getCenter
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setCenter(float x, float y);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the center of the view
|
|
||||||
///
|
|
||||||
/// \param center New center
|
|
||||||
///
|
|
||||||
/// \see setSize, getCenter
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setCenter(const Vector2f& center);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the size of the view
|
|
||||||
///
|
|
||||||
/// \param width New width of the view
|
|
||||||
/// \param height New height of the view
|
|
||||||
///
|
|
||||||
/// \see setCenter, getCenter
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setSize(float width, float height);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the size of the view
|
|
||||||
///
|
|
||||||
/// \param size New size
|
|
||||||
///
|
|
||||||
/// \see setCenter, getCenter
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setSize(const Vector2f& size);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the orientation of the view
|
|
||||||
///
|
|
||||||
/// The default rotation of a view is 0 degree.
|
|
||||||
///
|
|
||||||
/// \param angle New angle, in degrees
|
|
||||||
///
|
|
||||||
/// \see getRotation
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setRotation(float angle);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the target viewport
|
|
||||||
///
|
|
||||||
/// The viewport is the rectangle into which the contents of the
|
|
||||||
/// view are displayed, expressed as a factor (between 0 and 1)
|
|
||||||
/// of the size of the RenderTarget to which the view is applied.
|
|
||||||
/// For example, a view which takes the left side of the target would
|
|
||||||
/// be defined with View.setViewport(sf::FloatRect(0, 0, 0.5, 1)).
|
|
||||||
/// By default, a view has a viewport which covers the entire target.
|
|
||||||
///
|
|
||||||
/// \param viewport New viewport rectangle
|
|
||||||
///
|
|
||||||
/// \see getViewport
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setViewport(const FloatRect& viewport);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Reset the view to the given rectangle
|
|
||||||
///
|
|
||||||
/// Note that this function resets the rotation angle to 0.
|
|
||||||
///
|
|
||||||
/// \param rectangle Rectangle defining the zone to display
|
|
||||||
///
|
|
||||||
/// \see setCenter, setSize, setRotation
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void reset(const FloatRect& rectangle);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the center of the view
|
|
||||||
///
|
|
||||||
/// \return Center of the view
|
|
||||||
///
|
|
||||||
/// \see getSize, setCenter
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const Vector2f& getCenter() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the size of the view
|
|
||||||
///
|
|
||||||
/// \return Size of the view
|
|
||||||
///
|
|
||||||
/// \see getCenter, setSize
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const Vector2f& getSize() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the current orientation of the view
|
|
||||||
///
|
|
||||||
/// \return Rotation angle of the view, in degrees
|
|
||||||
///
|
|
||||||
/// \see setRotation
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
float getRotation() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the target viewport rectangle of the view
|
|
||||||
///
|
|
||||||
/// \return Viewport rectangle, expressed as a factor of the target size
|
|
||||||
///
|
|
||||||
/// \see setViewport
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const FloatRect& getViewport() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Move the view relatively to its current position
|
|
||||||
///
|
|
||||||
/// \param offsetX X coordinate of the move offset
|
|
||||||
/// \param offsetY Y coordinate of the move offset
|
|
||||||
///
|
|
||||||
/// \see setCenter, rotate, zoom
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void move(float offsetX, float offsetY);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Move the view relatively to its current position
|
|
||||||
///
|
|
||||||
/// \param offset Move offset
|
|
||||||
///
|
|
||||||
/// \see setCenter, rotate, zoom
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void move(const Vector2f& offset);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Rotate the view relatively to its current orientation
|
|
||||||
///
|
|
||||||
/// \param angle Angle to rotate, in degrees
|
|
||||||
///
|
|
||||||
/// \see setRotation, move, zoom
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void rotate(float angle);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Resize the view rectangle relatively to its current size
|
|
||||||
///
|
|
||||||
/// Resizing the view simulates a zoom, as the zone displayed on
|
|
||||||
/// screen grows or shrinks.
|
|
||||||
/// \a factor is a multiplier:
|
|
||||||
/// \li 1 keeps the size unchanged
|
|
||||||
/// \li > 1 makes the view bigger (objects appear smaller)
|
|
||||||
/// \li < 1 makes the view smaller (objects appear bigger)
|
|
||||||
///
|
|
||||||
/// \param factor Zoom factor to apply
|
|
||||||
///
|
|
||||||
/// \see setSize, move, rotate
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void zoom(float factor);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the projection transform of the view
|
|
||||||
///
|
|
||||||
/// This function is meant for internal use only.
|
|
||||||
///
|
|
||||||
/// \return Projection transform defining the view
|
|
||||||
///
|
|
||||||
/// \see getInverseTransform
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const Transform& getTransform() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the inverse projection transform of the view
|
|
||||||
///
|
|
||||||
/// This function is meant for internal use only.
|
|
||||||
///
|
|
||||||
/// \return Inverse of the projection transform defining the view
|
|
||||||
///
|
|
||||||
/// \see getTransform
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const Transform& getInverseTransform() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Vector2f m_center; ///< Center of the view, in scene coordinates
|
|
||||||
Vector2f m_size; ///< Size of the view, in scene coordinates
|
|
||||||
float m_rotation; ///< Angle of rotation of the view rectangle, in degrees
|
|
||||||
FloatRect m_viewport; ///< Viewport rectangle, expressed as a factor of the render-target's size
|
|
||||||
mutable Transform m_transform; ///< Precomputed projection transform corresponding to the view
|
|
||||||
mutable Transform m_inverseTransform; ///< Precomputed inverse projection transform corresponding to the view
|
|
||||||
mutable bool m_transformUpdated; ///< Internal state telling if the transform needs to be updated
|
|
||||||
mutable bool m_invTransformUpdated; ///< Internal state telling if the inverse transform needs to be updated
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_VIEW_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::View
|
|
||||||
/// \ingroup graphics
|
|
||||||
///
|
|
||||||
/// sf::View defines a camera in the 2D scene. This is a
|
|
||||||
/// very powerful concept: you can scroll, rotate or zoom
|
|
||||||
/// the entire scene without altering the way that your
|
|
||||||
/// drawable objects are drawn.
|
|
||||||
///
|
|
||||||
/// A view is composed of a source rectangle, which defines
|
|
||||||
/// what part of the 2D scene is shown, and a target viewport,
|
|
||||||
/// which defines where the contents of the source rectangle
|
|
||||||
/// will be displayed on the render target (window or texture).
|
|
||||||
///
|
|
||||||
/// The viewport allows to map the scene to a custom part
|
|
||||||
/// of the render target, and can be used for split-screen
|
|
||||||
/// or for displaying a minimap, for example. If the source
|
|
||||||
/// rectangle has not the same size as the viewport, its
|
|
||||||
/// contents will be stretched to fit in.
|
|
||||||
///
|
|
||||||
/// To apply a view, you have to assign it to the render target.
|
|
||||||
/// Then, every objects drawn in this render target will be
|
|
||||||
/// affected by the view until you use another view.
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// sf::RenderWindow window;
|
|
||||||
/// sf::View view;
|
|
||||||
///
|
|
||||||
/// // Initialize the view to a rectangle located at (100, 100) and with a size of 400x200
|
|
||||||
/// view.reset(sf::FloatRect(100, 100, 400, 200));
|
|
||||||
///
|
|
||||||
/// // Rotate it by 45 degrees
|
|
||||||
/// view.rotate(45);
|
|
||||||
///
|
|
||||||
/// // Set its target viewport to be half of the window
|
|
||||||
/// view.setViewport(sf::FloatRect(0.f, 0.f, 0.5f, 1.f));
|
|
||||||
///
|
|
||||||
/// // Apply it
|
|
||||||
/// window.setView(view);
|
|
||||||
///
|
|
||||||
/// // Render stuff
|
|
||||||
/// window.draw(someSprite);
|
|
||||||
///
|
|
||||||
/// // Set the default view back
|
|
||||||
/// window.setView(window.getDefaultView());
|
|
||||||
///
|
|
||||||
/// // Render stuff not affected by the view
|
|
||||||
/// window.draw(someText);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// See also the note on coordinates and undistorted rendering in sf::Transformable.
|
|
||||||
///
|
|
||||||
/// \see sf::RenderWindow, sf::RenderTexture
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
43
SQCSim2021/external/sfml23/include/SFML/Main.hpp
vendored
43
SQCSim2021/external/sfml23/include/SFML/Main.hpp
vendored
@ -1,43 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_MAIN_HPP
|
|
||||||
#define SFML_MAIN_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Config.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
#if defined(SFML_SYSTEM_IOS)
|
|
||||||
|
|
||||||
// On iOS, we have no choice but to have our own main,
|
|
||||||
// so we need to rename the user one and call it later
|
|
||||||
#define main sfmlMain
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_MAIN_HPP
|
|
@ -1,53 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_NETWORK_HPP
|
|
||||||
#define SFML_NETWORK_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#include <SFML/System.hpp>
|
|
||||||
#include <SFML/Network/Ftp.hpp>
|
|
||||||
#include <SFML/Network/Http.hpp>
|
|
||||||
#include <SFML/Network/IpAddress.hpp>
|
|
||||||
#include <SFML/Network/Packet.hpp>
|
|
||||||
#include <SFML/Network/Socket.hpp>
|
|
||||||
#include <SFML/Network/SocketHandle.hpp>
|
|
||||||
#include <SFML/Network/SocketSelector.hpp>
|
|
||||||
#include <SFML/Network/TcpListener.hpp>
|
|
||||||
#include <SFML/Network/TcpSocket.hpp>
|
|
||||||
#include <SFML/Network/UdpSocket.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_NETWORK_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \defgroup network Network module
|
|
||||||
///
|
|
||||||
/// Socket-based communication, utilities and higher-level
|
|
||||||
/// network protocols (HTTP, FTP).
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,48 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_NETWORK_EXPORT_HPP
|
|
||||||
#define SFML_NETWORK_EXPORT_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Config.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Define portable import / export macros
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#if defined(SFML_NETWORK_EXPORTS)
|
|
||||||
|
|
||||||
#define SFML_NETWORK_API SFML_API_EXPORT
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
#define SFML_NETWORK_API SFML_API_IMPORT
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_NETWORK_EXPORT_HPP
|
|
@ -1,611 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_FTP_HPP
|
|
||||||
#define SFML_FTP_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Network/Export.hpp>
|
|
||||||
#include <SFML/Network/TcpSocket.hpp>
|
|
||||||
#include <SFML/System/NonCopyable.hpp>
|
|
||||||
#include <SFML/System/Time.hpp>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
class IpAddress;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief A FTP client
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_NETWORK_API Ftp : NonCopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Enumeration of transfer modes
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
enum TransferMode
|
|
||||||
{
|
|
||||||
Binary, ///< Binary mode (file is transfered as a sequence of bytes)
|
|
||||||
Ascii, ///< Text mode using ASCII encoding
|
|
||||||
Ebcdic ///< Text mode using EBCDIC encoding
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Define a FTP response
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_NETWORK_API Response
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Status codes possibly returned by a FTP response
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
enum Status
|
|
||||||
{
|
|
||||||
// 1xx: the requested action is being initiated,
|
|
||||||
// expect another reply before proceeding with a new command
|
|
||||||
RestartMarkerReply = 110, ///< Restart marker reply
|
|
||||||
ServiceReadySoon = 120, ///< Service ready in N minutes
|
|
||||||
DataConnectionAlreadyOpened = 125, ///< Data connection already opened, transfer starting
|
|
||||||
OpeningDataConnection = 150, ///< File status ok, about to open data connection
|
|
||||||
|
|
||||||
// 2xx: the requested action has been successfully completed
|
|
||||||
Ok = 200, ///< Command ok
|
|
||||||
PointlessCommand = 202, ///< Command not implemented
|
|
||||||
SystemStatus = 211, ///< System status, or system help reply
|
|
||||||
DirectoryStatus = 212, ///< Directory status
|
|
||||||
FileStatus = 213, ///< File status
|
|
||||||
HelpMessage = 214, ///< Help message
|
|
||||||
SystemType = 215, ///< NAME system type, where NAME is an official system name from the list in the Assigned Numbers document
|
|
||||||
ServiceReady = 220, ///< Service ready for new user
|
|
||||||
ClosingConnection = 221, ///< Service closing control connection
|
|
||||||
DataConnectionOpened = 225, ///< Data connection open, no transfer in progress
|
|
||||||
ClosingDataConnection = 226, ///< Closing data connection, requested file action successful
|
|
||||||
EnteringPassiveMode = 227, ///< Entering passive mode
|
|
||||||
LoggedIn = 230, ///< User logged in, proceed. Logged out if appropriate
|
|
||||||
FileActionOk = 250, ///< Requested file action ok
|
|
||||||
DirectoryOk = 257, ///< PATHNAME created
|
|
||||||
|
|
||||||
// 3xx: the command has been accepted, but the requested action
|
|
||||||
// is dormant, pending receipt of further information
|
|
||||||
NeedPassword = 331, ///< User name ok, need password
|
|
||||||
NeedAccountToLogIn = 332, ///< Need account for login
|
|
||||||
NeedInformation = 350, ///< Requested file action pending further information
|
|
||||||
|
|
||||||
// 4xx: the command was not accepted and the requested action did not take place,
|
|
||||||
// but the error condition is temporary and the action may be requested again
|
|
||||||
ServiceUnavailable = 421, ///< Service not available, closing control connection
|
|
||||||
DataConnectionUnavailable = 425, ///< Can't open data connection
|
|
||||||
TransferAborted = 426, ///< Connection closed, transfer aborted
|
|
||||||
FileActionAborted = 450, ///< Requested file action not taken
|
|
||||||
LocalError = 451, ///< Requested action aborted, local error in processing
|
|
||||||
InsufficientStorageSpace = 452, ///< Requested action not taken; insufficient storage space in system, file unavailable
|
|
||||||
|
|
||||||
// 5xx: the command was not accepted and
|
|
||||||
// the requested action did not take place
|
|
||||||
CommandUnknown = 500, ///< Syntax error, command unrecognized
|
|
||||||
ParametersUnknown = 501, ///< Syntax error in parameters or arguments
|
|
||||||
CommandNotImplemented = 502, ///< Command not implemented
|
|
||||||
BadCommandSequence = 503, ///< Bad sequence of commands
|
|
||||||
ParameterNotImplemented = 504, ///< Command not implemented for that parameter
|
|
||||||
NotLoggedIn = 530, ///< Not logged in
|
|
||||||
NeedAccountToStore = 532, ///< Need account for storing files
|
|
||||||
FileUnavailable = 550, ///< Requested action not taken, file unavailable
|
|
||||||
PageTypeUnknown = 551, ///< Requested action aborted, page type unknown
|
|
||||||
NotEnoughMemory = 552, ///< Requested file action aborted, exceeded storage allocation
|
|
||||||
FilenameNotAllowed = 553, ///< Requested action not taken, file name not allowed
|
|
||||||
|
|
||||||
// 10xx: SFML custom codes
|
|
||||||
InvalidResponse = 1000, ///< Not part of the FTP standard, generated by SFML when a received response cannot be parsed
|
|
||||||
ConnectionFailed = 1001, ///< Not part of the FTP standard, generated by SFML when the low-level socket connection with the server fails
|
|
||||||
ConnectionClosed = 1002, ///< Not part of the FTP standard, generated by SFML when the low-level socket connection is unexpectedly closed
|
|
||||||
InvalidFile = 1003 ///< Not part of the FTP standard, generated by SFML when a local file cannot be read or written
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
/// This constructor is used by the FTP client to build
|
|
||||||
/// the response.
|
|
||||||
///
|
|
||||||
/// \param code Response status code
|
|
||||||
/// \param message Response message
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
explicit Response(Status code = InvalidResponse, const std::string& message = "");
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Check if the status code means a success
|
|
||||||
///
|
|
||||||
/// This function is defined for convenience, it is
|
|
||||||
/// equivalent to testing if the status code is < 400.
|
|
||||||
///
|
|
||||||
/// \return True if the status is a success, false if it is a failure
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool isOk() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the status code of the response
|
|
||||||
///
|
|
||||||
/// \return Status code
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Status getStatus() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the full message contained in the response
|
|
||||||
///
|
|
||||||
/// \return The response message
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const std::string& getMessage() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Status m_status; ///< Status code returned from the server
|
|
||||||
std::string m_message; ///< Last message received from the server
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Specialization of FTP response returning a directory
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_NETWORK_API DirectoryResponse : public Response
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
/// \param response Source response
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
DirectoryResponse(const Response& response);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the directory returned in the response
|
|
||||||
///
|
|
||||||
/// \return Directory name
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const std::string& getDirectory() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
std::string m_directory; ///< Directory extracted from the response message
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Specialization of FTP response returning a
|
|
||||||
/// filename listing
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_NETWORK_API ListingResponse : public Response
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
/// \param response Source response
|
|
||||||
/// \param data Data containing the raw listing
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
ListingResponse(const Response& response, const std::string& data);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Return the array of directory/file names
|
|
||||||
///
|
|
||||||
/// \return Array containing the requested listing
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const std::vector<std::string>& getListing() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
std::vector<std::string> m_listing; ///< Directory/file names extracted from the data
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Destructor
|
|
||||||
///
|
|
||||||
/// Automatically closes the connection with the server if
|
|
||||||
/// it is still opened.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
~Ftp();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Connect to the specified FTP server
|
|
||||||
///
|
|
||||||
/// The port has a default value of 21, which is the standard
|
|
||||||
/// port used by the FTP protocol. You shouldn't use a different
|
|
||||||
/// value, unless you really know what you do.
|
|
||||||
/// This function tries to connect to the server so it may take
|
|
||||||
/// a while to complete, especially if the server is not
|
|
||||||
/// reachable. To avoid blocking your application for too long,
|
|
||||||
/// you can use a timeout. The default value, Time::Zero, means that the
|
|
||||||
/// system timeout will be used (which is usually pretty long).
|
|
||||||
///
|
|
||||||
/// \param server Name or address of the FTP server to connect to
|
|
||||||
/// \param port Port used for the connection
|
|
||||||
/// \param timeout Maximum time to wait
|
|
||||||
///
|
|
||||||
/// \return Server response to the request
|
|
||||||
///
|
|
||||||
/// \see disconnect
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Response connect(const IpAddress& server, unsigned short port = 21, Time timeout = Time::Zero);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Close the connection with the server
|
|
||||||
///
|
|
||||||
/// \return Server response to the request
|
|
||||||
///
|
|
||||||
/// \see connect
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Response disconnect();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Log in using an anonymous account
|
|
||||||
///
|
|
||||||
/// Logging in is mandatory after connecting to the server.
|
|
||||||
/// Users that are not logged in cannot perform any operation.
|
|
||||||
///
|
|
||||||
/// \return Server response to the request
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Response login();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Log in using a username and a password
|
|
||||||
///
|
|
||||||
/// Logging in is mandatory after connecting to the server.
|
|
||||||
/// Users that are not logged in cannot perform any operation.
|
|
||||||
///
|
|
||||||
/// \param name User name
|
|
||||||
/// \param password Password
|
|
||||||
///
|
|
||||||
/// \return Server response to the request
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Response login(const std::string& name, const std::string& password);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Send a null command to keep the connection alive
|
|
||||||
///
|
|
||||||
/// This command is useful because the server may close the
|
|
||||||
/// connection automatically if no command is sent.
|
|
||||||
///
|
|
||||||
/// \return Server response to the request
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Response keepAlive();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the current working directory
|
|
||||||
///
|
|
||||||
/// The working directory is the root path for subsequent
|
|
||||||
/// operations involving directories and/or filenames.
|
|
||||||
///
|
|
||||||
/// \return Server response to the request
|
|
||||||
///
|
|
||||||
/// \see getDirectoryListing, changeDirectory, parentDirectory
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
DirectoryResponse getWorkingDirectory();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the contents of the given directory
|
|
||||||
///
|
|
||||||
/// This function retrieves the sub-directories and files
|
|
||||||
/// contained in the given directory. It is not recursive.
|
|
||||||
/// The \a directory parameter is relative to the current
|
|
||||||
/// working directory.
|
|
||||||
///
|
|
||||||
/// \param directory Directory to list
|
|
||||||
///
|
|
||||||
/// \return Server response to the request
|
|
||||||
///
|
|
||||||
/// \see getWorkingDirectory, changeDirectory, parentDirectory
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
ListingResponse getDirectoryListing(const std::string& directory = "");
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Change the current working directory
|
|
||||||
///
|
|
||||||
/// The new directory must be relative to the current one.
|
|
||||||
///
|
|
||||||
/// \param directory New working directory
|
|
||||||
///
|
|
||||||
/// \return Server response to the request
|
|
||||||
///
|
|
||||||
/// \see getWorkingDirectory, getDirectoryListing, parentDirectory
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Response changeDirectory(const std::string& directory);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Go to the parent directory of the current one
|
|
||||||
///
|
|
||||||
/// \return Server response to the request
|
|
||||||
///
|
|
||||||
/// \see getWorkingDirectory, getDirectoryListing, changeDirectory
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Response parentDirectory();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Create a new directory
|
|
||||||
///
|
|
||||||
/// The new directory is created as a child of the current
|
|
||||||
/// working directory.
|
|
||||||
///
|
|
||||||
/// \param name Name of the directory to create
|
|
||||||
///
|
|
||||||
/// \return Server response to the request
|
|
||||||
///
|
|
||||||
/// \see deleteDirectory
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Response createDirectory(const std::string& name);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Remove an existing directory
|
|
||||||
///
|
|
||||||
/// The directory to remove must be relative to the
|
|
||||||
/// current working directory.
|
|
||||||
/// Use this function with caution, the directory will
|
|
||||||
/// be removed permanently!
|
|
||||||
///
|
|
||||||
/// \param name Name of the directory to remove
|
|
||||||
///
|
|
||||||
/// \return Server response to the request
|
|
||||||
///
|
|
||||||
/// \see createDirectory
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Response deleteDirectory(const std::string& name);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Rename an existing file
|
|
||||||
///
|
|
||||||
/// The filenames must be relative to the current working
|
|
||||||
/// directory.
|
|
||||||
///
|
|
||||||
/// \param file File to rename
|
|
||||||
/// \param newName New name of the file
|
|
||||||
///
|
|
||||||
/// \return Server response to the request
|
|
||||||
///
|
|
||||||
/// \see deleteFile
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Response renameFile(const std::string& file, const std::string& newName);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Remove an existing file
|
|
||||||
///
|
|
||||||
/// The file name must be relative to the current working
|
|
||||||
/// directory.
|
|
||||||
/// Use this function with caution, the file will be
|
|
||||||
/// removed permanently!
|
|
||||||
///
|
|
||||||
/// \param name File to remove
|
|
||||||
///
|
|
||||||
/// \return Server response to the request
|
|
||||||
///
|
|
||||||
/// \see renameFile
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Response deleteFile(const std::string& name);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Download a file from the server
|
|
||||||
///
|
|
||||||
/// The filename of the distant file is relative to the
|
|
||||||
/// current working directory of the server, and the local
|
|
||||||
/// destination path is relative to the current directory
|
|
||||||
/// of your application.
|
|
||||||
/// If a file with the same filename as the distant file
|
|
||||||
/// already exists in the local destination path, it will
|
|
||||||
/// be overwritten.
|
|
||||||
///
|
|
||||||
/// \param remoteFile Filename of the distant file to download
|
|
||||||
/// \param localPath The directory in which to put the file on the local computer
|
|
||||||
/// \param mode Transfer mode
|
|
||||||
///
|
|
||||||
/// \return Server response to the request
|
|
||||||
///
|
|
||||||
/// \see upload
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Response download(const std::string& remoteFile, const std::string& localPath, TransferMode mode = Binary);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Upload a file to the server
|
|
||||||
///
|
|
||||||
/// The name of the local file is relative to the current
|
|
||||||
/// working directory of your application, and the
|
|
||||||
/// remote path is relative to the current directory of the
|
|
||||||
/// FTP server.
|
|
||||||
///
|
|
||||||
/// \param localFile Path of the local file to upload
|
|
||||||
/// \param remotePath The directory in which to put the file on the server
|
|
||||||
/// \param mode Transfer mode
|
|
||||||
///
|
|
||||||
/// \return Server response to the request
|
|
||||||
///
|
|
||||||
/// \see download
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Response upload(const std::string& localFile, const std::string& remotePath, TransferMode mode = Binary);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Send a command to the FTP server
|
|
||||||
///
|
|
||||||
/// While the most often used commands are provided as member
|
|
||||||
/// functions in the sf::Ftp class, this method can be used
|
|
||||||
/// to send any FTP command to the server. If the command
|
|
||||||
/// requires one or more parameters, they can be specified
|
|
||||||
/// in \a parameter. If the server returns information, you
|
|
||||||
/// can extract it from the response using Response::getMessage().
|
|
||||||
///
|
|
||||||
/// \param command Command to send
|
|
||||||
/// \param parameter Command parameter
|
|
||||||
///
|
|
||||||
/// \return Server response to the request
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Response sendCommand(const std::string& command, const std::string& parameter = "");
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Receive a response from the server
|
|
||||||
///
|
|
||||||
/// This function must be called after each call to
|
|
||||||
/// sendCommand that expects a response.
|
|
||||||
///
|
|
||||||
/// \return Server response to the request
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Response getResponse();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Utility class for exchanging datas with the server
|
|
||||||
/// on the data channel
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class DataChannel;
|
|
||||||
|
|
||||||
friend class DataChannel;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
TcpSocket m_commandSocket; ///< Socket holding the control connection with the server
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_FTP_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::Ftp
|
|
||||||
/// \ingroup network
|
|
||||||
///
|
|
||||||
/// sf::Ftp is a very simple FTP client that allows you
|
|
||||||
/// to communicate with a FTP server. The FTP protocol allows
|
|
||||||
/// you to manipulate a remote file system (list files,
|
|
||||||
/// upload, download, create, remove, ...).
|
|
||||||
///
|
|
||||||
/// Using the FTP client consists of 4 parts:
|
|
||||||
/// \li Connecting to the FTP server
|
|
||||||
/// \li Logging in (either as a registered user or anonymously)
|
|
||||||
/// \li Sending commands to the server
|
|
||||||
/// \li Disconnecting (this part can be done implicitly by the destructor)
|
|
||||||
///
|
|
||||||
/// Every command returns a FTP response, which contains the
|
|
||||||
/// status code as well as a message from the server. Some
|
|
||||||
/// commands such as getWorkingDirectory() and getDirectoryListing()
|
|
||||||
/// return additional data, and use a class derived from
|
|
||||||
/// sf::Ftp::Response to provide this data. The most often used
|
|
||||||
/// commands are directly provided as member functions, but it is
|
|
||||||
/// also possible to use specific commands with the sendCommand() function.
|
|
||||||
///
|
|
||||||
/// Note that response statuses >= 1000 are not part of the FTP standard,
|
|
||||||
/// they are generated by SFML when an internal error occurs.
|
|
||||||
///
|
|
||||||
/// All commands, especially upload and download, may take some
|
|
||||||
/// time to complete. This is important to know if you don't want
|
|
||||||
/// to block your application while the server is completing
|
|
||||||
/// the task.
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// // Create a new FTP client
|
|
||||||
/// sf::Ftp ftp;
|
|
||||||
///
|
|
||||||
/// // Connect to the server
|
|
||||||
/// sf::Ftp::Response response = ftp.connect("ftp://ftp.myserver.com");
|
|
||||||
/// if (response.isOk())
|
|
||||||
/// std::cout << "Connected" << std::endl;
|
|
||||||
///
|
|
||||||
/// // Log in
|
|
||||||
/// response = ftp.login("laurent", "dF6Zm89D");
|
|
||||||
/// if (response.isOk())
|
|
||||||
/// std::cout << "Logged in" << std::endl;
|
|
||||||
///
|
|
||||||
/// // Print the working directory
|
|
||||||
/// sf::Ftp::DirectoryResponse directory = ftp.getWorkingDirectory();
|
|
||||||
/// if (directory.isOk())
|
|
||||||
/// std::cout << "Working directory: " << directory.getDirectory() << std::endl;
|
|
||||||
///
|
|
||||||
/// // Create a new directory
|
|
||||||
/// response = ftp.createDirectory("files");
|
|
||||||
/// if (response.isOk())
|
|
||||||
/// std::cout << "Created new directory" << std::endl;
|
|
||||||
///
|
|
||||||
/// // Upload a file to this new directory
|
|
||||||
/// response = ftp.upload("local-path/file.txt", "files", sf::Ftp::Ascii);
|
|
||||||
/// if (response.isOk())
|
|
||||||
/// std::cout << "File uploaded" << std::endl;
|
|
||||||
///
|
|
||||||
/// // Send specific commands (here: FEAT to list supported FTP features)
|
|
||||||
/// response = ftp.sendCommand("FEAT");
|
|
||||||
/// if (response.isOk())
|
|
||||||
/// std::cout << "Feature list:\n" << response.getMessage() << std::endl;
|
|
||||||
///
|
|
||||||
/// // Disconnect from the server (optional)
|
|
||||||
/// ftp.disconnect();
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,482 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_HTTP_HPP
|
|
||||||
#define SFML_HTTP_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Network/Export.hpp>
|
|
||||||
#include <SFML/Network/IpAddress.hpp>
|
|
||||||
#include <SFML/Network/TcpSocket.hpp>
|
|
||||||
#include <SFML/System/NonCopyable.hpp>
|
|
||||||
#include <SFML/System/Time.hpp>
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief A HTTP client
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_NETWORK_API Http : NonCopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Define a HTTP request
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_NETWORK_API Request
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Enumerate the available HTTP methods for a request
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
enum Method
|
|
||||||
{
|
|
||||||
Get, ///< Request in get mode, standard method to retrieve a page
|
|
||||||
Post, ///< Request in post mode, usually to send data to a page
|
|
||||||
Head, ///< Request a page's header only
|
|
||||||
Put, ///< Request in put mode, useful for a REST API
|
|
||||||
Delete ///< Request in delete mode, useful for a REST API
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
/// This constructor creates a GET request, with the root
|
|
||||||
/// URI ("/") and an empty body.
|
|
||||||
///
|
|
||||||
/// \param uri Target URI
|
|
||||||
/// \param method Method to use for the request
|
|
||||||
/// \param body Content of the request's body
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Request(const std::string& uri = "/", Method method = Get, const std::string& body = "");
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the value of a field
|
|
||||||
///
|
|
||||||
/// The field is created if it doesn't exist. The name of
|
|
||||||
/// the field is case-insensitive.
|
|
||||||
/// By default, a request doesn't contain any field (but the
|
|
||||||
/// mandatory fields are added later by the HTTP client when
|
|
||||||
/// sending the request).
|
|
||||||
///
|
|
||||||
/// \param field Name of the field to set
|
|
||||||
/// \param value Value of the field
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setField(const std::string& field, const std::string& value);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the request method
|
|
||||||
///
|
|
||||||
/// See the Method enumeration for a complete list of all
|
|
||||||
/// the availale methods.
|
|
||||||
/// The method is Http::Request::Get by default.
|
|
||||||
///
|
|
||||||
/// \param method Method to use for the request
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setMethod(Method method);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the requested URI
|
|
||||||
///
|
|
||||||
/// The URI is the resource (usually a web page or a file)
|
|
||||||
/// that you want to get or post.
|
|
||||||
/// The URI is "/" (the root page) by default.
|
|
||||||
///
|
|
||||||
/// \param uri URI to request, relative to the host
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setUri(const std::string& uri);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the HTTP version for the request
|
|
||||||
///
|
|
||||||
/// The HTTP version is 1.0 by default.
|
|
||||||
///
|
|
||||||
/// \param major Major HTTP version number
|
|
||||||
/// \param minor Minor HTTP version number
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setHttpVersion(unsigned int major, unsigned int minor);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the body of the request
|
|
||||||
///
|
|
||||||
/// The body of a request is optional and only makes sense
|
|
||||||
/// for POST requests. It is ignored for all other methods.
|
|
||||||
/// The body is empty by default.
|
|
||||||
///
|
|
||||||
/// \param body Content of the body
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setBody(const std::string& body);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
friend class Http;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Prepare the final request to send to the server
|
|
||||||
///
|
|
||||||
/// This is used internally by Http before sending the
|
|
||||||
/// request to the web server.
|
|
||||||
///
|
|
||||||
/// \return String containing the request, ready to be sent
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
std::string prepare() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Check if the request defines a field
|
|
||||||
///
|
|
||||||
/// This function uses case-insensitive comparisons.
|
|
||||||
///
|
|
||||||
/// \param field Name of the field to test
|
|
||||||
///
|
|
||||||
/// \return True if the field exists, false otherwise
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool hasField(const std::string& field) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Types
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
typedef std::map<std::string, std::string> FieldTable;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
FieldTable m_fields; ///< Fields of the header associated to their value
|
|
||||||
Method m_method; ///< Method to use for the request
|
|
||||||
std::string m_uri; ///< Target URI of the request
|
|
||||||
unsigned int m_majorVersion; ///< Major HTTP version
|
|
||||||
unsigned int m_minorVersion; ///< Minor HTTP version
|
|
||||||
std::string m_body; ///< Body of the request
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Define a HTTP response
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_NETWORK_API Response
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Enumerate all the valid status codes for a response
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
enum Status
|
|
||||||
{
|
|
||||||
// 2xx: success
|
|
||||||
Ok = 200, ///< Most common code returned when operation was successful
|
|
||||||
Created = 201, ///< The resource has successfully been created
|
|
||||||
Accepted = 202, ///< The request has been accepted, but will be processed later by the server
|
|
||||||
NoContent = 204, ///< The server didn't send any data in return
|
|
||||||
ResetContent = 205, ///< The server informs the client that it should clear the view (form) that caused the request to be sent
|
|
||||||
PartialContent = 206, ///< The server has sent a part of the resource, as a response to a partial GET request
|
|
||||||
|
|
||||||
// 3xx: redirection
|
|
||||||
MultipleChoices = 300, ///< The requested page can be accessed from several locations
|
|
||||||
MovedPermanently = 301, ///< The requested page has permanently moved to a new location
|
|
||||||
MovedTemporarily = 302, ///< The requested page has temporarily moved to a new location
|
|
||||||
NotModified = 304, ///< For conditional requests, means the requested page hasn't changed and doesn't need to be refreshed
|
|
||||||
|
|
||||||
// 4xx: client error
|
|
||||||
BadRequest = 400, ///< The server couldn't understand the request (syntax error)
|
|
||||||
Unauthorized = 401, ///< The requested page needs an authentication to be accessed
|
|
||||||
Forbidden = 403, ///< The requested page cannot be accessed at all, even with authentication
|
|
||||||
NotFound = 404, ///< The requested page doesn't exist
|
|
||||||
RangeNotSatisfiable = 407, ///< The server can't satisfy the partial GET request (with a "Range" header field)
|
|
||||||
|
|
||||||
// 5xx: server error
|
|
||||||
InternalServerError = 500, ///< The server encountered an unexpected error
|
|
||||||
NotImplemented = 501, ///< The server doesn't implement a requested feature
|
|
||||||
BadGateway = 502, ///< The gateway server has received an error from the source server
|
|
||||||
ServiceNotAvailable = 503, ///< The server is temporarily unavailable (overloaded, in maintenance, ...)
|
|
||||||
GatewayTimeout = 504, ///< The gateway server couldn't receive a response from the source server
|
|
||||||
VersionNotSupported = 505, ///< The server doesn't support the requested HTTP version
|
|
||||||
|
|
||||||
// 10xx: SFML custom codes
|
|
||||||
InvalidResponse = 1000, ///< Response is not a valid HTTP one
|
|
||||||
ConnectionFailed = 1001 ///< Connection with server failed
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
/// Constructs an empty response.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Response();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the value of a field
|
|
||||||
///
|
|
||||||
/// If the field \a field is not found in the response header,
|
|
||||||
/// the empty string is returned. This function uses
|
|
||||||
/// case-insensitive comparisons.
|
|
||||||
///
|
|
||||||
/// \param field Name of the field to get
|
|
||||||
///
|
|
||||||
/// \return Value of the field, or empty string if not found
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const std::string& getField(const std::string& field) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the response status code
|
|
||||||
///
|
|
||||||
/// The status code should be the first thing to be checked
|
|
||||||
/// after receiving a response, it defines whether it is a
|
|
||||||
/// success, a failure or anything else (see the Status
|
|
||||||
/// enumeration).
|
|
||||||
///
|
|
||||||
/// \return Status code of the response
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Status getStatus() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the major HTTP version number of the response
|
|
||||||
///
|
|
||||||
/// \return Major HTTP version number
|
|
||||||
///
|
|
||||||
/// \see getMinorHttpVersion
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
unsigned int getMajorHttpVersion() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the minor HTTP version number of the response
|
|
||||||
///
|
|
||||||
/// \return Minor HTTP version number
|
|
||||||
///
|
|
||||||
/// \see getMajorHttpVersion
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
unsigned int getMinorHttpVersion() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the body of the response
|
|
||||||
///
|
|
||||||
/// The body of a response may contain:
|
|
||||||
/// \li the requested page (for GET requests)
|
|
||||||
/// \li a response from the server (for POST requests)
|
|
||||||
/// \li nothing (for HEAD requests)
|
|
||||||
/// \li an error message (in case of an error)
|
|
||||||
///
|
|
||||||
/// \return The response body
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const std::string& getBody() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
friend class Http;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Construct the header from a response string
|
|
||||||
///
|
|
||||||
/// This function is used by Http to build the response
|
|
||||||
/// of a request.
|
|
||||||
///
|
|
||||||
/// \param data Content of the response to parse
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void parse(const std::string& data);
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Read values passed in the answer header
|
|
||||||
///
|
|
||||||
/// This function is used by Http to extract values passed
|
|
||||||
/// in the response.
|
|
||||||
///
|
|
||||||
/// \param in String stream containing the header values
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void parseFields(std::istream &in);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Types
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
typedef std::map<std::string, std::string> FieldTable;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
FieldTable m_fields; ///< Fields of the header
|
|
||||||
Status m_status; ///< Status code
|
|
||||||
unsigned int m_majorVersion; ///< Major HTTP version
|
|
||||||
unsigned int m_minorVersion; ///< Minor HTTP version
|
|
||||||
std::string m_body; ///< Body of the response
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Http();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Construct the HTTP client with the target host
|
|
||||||
///
|
|
||||||
/// This is equivalent to calling setHost(host, port).
|
|
||||||
/// The port has a default value of 0, which means that the
|
|
||||||
/// HTTP client will use the right port according to the
|
|
||||||
/// protocol used (80 for HTTP). You should leave it like
|
|
||||||
/// this unless you really need a port other than the
|
|
||||||
/// standard one, or use an unknown protocol.
|
|
||||||
///
|
|
||||||
/// \param host Web server to connect to
|
|
||||||
/// \param port Port to use for connection
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Http(const std::string& host, unsigned short port = 0);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the target host
|
|
||||||
///
|
|
||||||
/// This function just stores the host address and port, it
|
|
||||||
/// doesn't actually connect to it until you send a request.
|
|
||||||
/// The port has a default value of 0, which means that the
|
|
||||||
/// HTTP client will use the right port according to the
|
|
||||||
/// protocol used (80 for HTTP). You should leave it like
|
|
||||||
/// this unless you really need a port other than the
|
|
||||||
/// standard one, or use an unknown protocol.
|
|
||||||
///
|
|
||||||
/// \param host Web server to connect to
|
|
||||||
/// \param port Port to use for connection
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setHost(const std::string& host, unsigned short port = 0);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Send a HTTP request and return the server's response.
|
|
||||||
///
|
|
||||||
/// You must have a valid host before sending a request (see setHost).
|
|
||||||
/// Any missing mandatory header field in the request will be added
|
|
||||||
/// with an appropriate value.
|
|
||||||
/// Warning: this function waits for the server's response and may
|
|
||||||
/// not return instantly; use a thread if you don't want to block your
|
|
||||||
/// application, or use a timeout to limit the time to wait. A value
|
|
||||||
/// of Time::Zero means that the client will use the system default timeout
|
|
||||||
/// (which is usually pretty long).
|
|
||||||
///
|
|
||||||
/// \param request Request to send
|
|
||||||
/// \param timeout Maximum time to wait
|
|
||||||
///
|
|
||||||
/// \return Server's response
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Response sendRequest(const Request& request, Time timeout = Time::Zero);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
TcpSocket m_connection; ///< Connection to the host
|
|
||||||
IpAddress m_host; ///< Web host address
|
|
||||||
std::string m_hostName; ///< Web host name
|
|
||||||
unsigned short m_port; ///< Port used for connection with host
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_HTTP_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::Http
|
|
||||||
/// \ingroup network
|
|
||||||
///
|
|
||||||
/// sf::Http is a very simple HTTP client that allows you
|
|
||||||
/// to communicate with a web server. You can retrieve
|
|
||||||
/// web pages, send data to an interactive resource,
|
|
||||||
/// download a remote file, etc. The HTTPS protocol is
|
|
||||||
/// not supported.
|
|
||||||
///
|
|
||||||
/// The HTTP client is split into 3 classes:
|
|
||||||
/// \li sf::Http::Request
|
|
||||||
/// \li sf::Http::Response
|
|
||||||
/// \li sf::Http
|
|
||||||
///
|
|
||||||
/// sf::Http::Request builds the request that will be
|
|
||||||
/// sent to the server. A request is made of:
|
|
||||||
/// \li a method (what you want to do)
|
|
||||||
/// \li a target URI (usually the name of the web page or file)
|
|
||||||
/// \li one or more header fields (options that you can pass to the server)
|
|
||||||
/// \li an optional body (for POST requests)
|
|
||||||
///
|
|
||||||
/// sf::Http::Response parse the response from the web server
|
|
||||||
/// and provides getters to read them. The response contains:
|
|
||||||
/// \li a status code
|
|
||||||
/// \li header fields (that may be answers to the ones that you requested)
|
|
||||||
/// \li a body, which contains the contents of the requested resource
|
|
||||||
///
|
|
||||||
/// sf::Http provides a simple function, SendRequest, to send a
|
|
||||||
/// sf::Http::Request and return the corresponding sf::Http::Response
|
|
||||||
/// from the server.
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// // Create a new HTTP client
|
|
||||||
/// sf::Http http;
|
|
||||||
///
|
|
||||||
/// // We'll work on http://www.sfml-dev.org
|
|
||||||
/// http.setHost("http://www.sfml-dev.org");
|
|
||||||
///
|
|
||||||
/// // Prepare a request to get the 'features.php' page
|
|
||||||
/// sf::Http::Request request("features.php");
|
|
||||||
///
|
|
||||||
/// // Send the request
|
|
||||||
/// sf::Http::Response response = http.sendRequest(request);
|
|
||||||
///
|
|
||||||
/// // Check the status code and display the result
|
|
||||||
/// sf::Http::Response::Status status = response.getStatus();
|
|
||||||
/// if (status == sf::Http::Response::Ok)
|
|
||||||
/// {
|
|
||||||
/// std::cout << response.getBody() << std::endl;
|
|
||||||
/// }
|
|
||||||
/// else
|
|
||||||
/// {
|
|
||||||
/// std::cout << "Error " << status << std::endl;
|
|
||||||
/// }
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,316 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_IPADDRESS_HPP
|
|
||||||
#define SFML_IPADDRESS_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Network/Export.hpp>
|
|
||||||
#include <SFML/System/Time.hpp>
|
|
||||||
#include <istream>
|
|
||||||
#include <ostream>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Encapsulate an IPv4 network address
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_NETWORK_API IpAddress
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
/// This constructor creates an empty (invalid) address
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
IpAddress();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Construct the address from a string
|
|
||||||
///
|
|
||||||
/// Here \a address can be either a decimal address
|
|
||||||
/// (ex: "192.168.1.56") or a network name (ex: "localhost").
|
|
||||||
///
|
|
||||||
/// \param address IP address or network name
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
IpAddress(const std::string& address);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Construct the address from a string
|
|
||||||
///
|
|
||||||
/// Here \a address can be either a decimal address
|
|
||||||
/// (ex: "192.168.1.56") or a network name (ex: "localhost").
|
|
||||||
/// This is equivalent to the constructor taking a std::string
|
|
||||||
/// parameter, it is defined for convenience so that the
|
|
||||||
/// implicit conversions from literal strings to IpAddress work.
|
|
||||||
///
|
|
||||||
/// \param address IP address or network name
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
IpAddress(const char* address);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Construct the address from 4 bytes
|
|
||||||
///
|
|
||||||
/// Calling IpAddress(a, b, c, d) is equivalent to calling
|
|
||||||
/// IpAddress("a.b.c.d"), but safer as it doesn't have to
|
|
||||||
/// parse a string to get the address components.
|
|
||||||
///
|
|
||||||
/// \param byte0 First byte of the address
|
|
||||||
/// \param byte1 Second byte of the address
|
|
||||||
/// \param byte2 Third byte of the address
|
|
||||||
/// \param byte3 Fourth byte of the address
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
IpAddress(Uint8 byte0, Uint8 byte1, Uint8 byte2, Uint8 byte3);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Construct the address from a 32-bits integer
|
|
||||||
///
|
|
||||||
/// This constructor uses the internal representation of
|
|
||||||
/// the address directly. It should be used for optimization
|
|
||||||
/// purposes, and only if you got that representation from
|
|
||||||
/// IpAddress::ToInteger().
|
|
||||||
///
|
|
||||||
/// \param address 4 bytes of the address packed into a 32-bits integer
|
|
||||||
///
|
|
||||||
/// \see toInteger
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
explicit IpAddress(Uint32 address);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get a string representation of the address
|
|
||||||
///
|
|
||||||
/// The returned string is the decimal representation of the
|
|
||||||
/// IP address (like "192.168.1.56"), even if it was constructed
|
|
||||||
/// from a host name.
|
|
||||||
///
|
|
||||||
/// \return String representation of the address
|
|
||||||
///
|
|
||||||
/// \see toInteger
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
std::string toString() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get an integer representation of the address
|
|
||||||
///
|
|
||||||
/// The returned number is the internal representation of the
|
|
||||||
/// address, and should be used for optimization purposes only
|
|
||||||
/// (like sending the address through a socket).
|
|
||||||
/// The integer produced by this function can then be converted
|
|
||||||
/// back to a sf::IpAddress with the proper constructor.
|
|
||||||
///
|
|
||||||
/// \return 32-bits unsigned integer representation of the address
|
|
||||||
///
|
|
||||||
/// \see toString
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Uint32 toInteger() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the computer's local address
|
|
||||||
///
|
|
||||||
/// The local address is the address of the computer from the
|
|
||||||
/// LAN point of view, i.e. something like 192.168.1.56. It is
|
|
||||||
/// meaningful only for communications over the local network.
|
|
||||||
/// Unlike getPublicAddress, this function is fast and may be
|
|
||||||
/// used safely anywhere.
|
|
||||||
///
|
|
||||||
/// \return Local IP address of the computer
|
|
||||||
///
|
|
||||||
/// \see getPublicAddress
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static IpAddress getLocalAddress();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the computer's public address
|
|
||||||
///
|
|
||||||
/// The public address is the address of the computer from the
|
|
||||||
/// internet point of view, i.e. something like 89.54.1.169.
|
|
||||||
/// It is necessary for communications over the world wide web.
|
|
||||||
/// The only way to get a public address is to ask it to a
|
|
||||||
/// distant website; as a consequence, this function depends on
|
|
||||||
/// both your network connection and the server, and may be
|
|
||||||
/// very slow. You should use it as few as possible. Because
|
|
||||||
/// this function depends on the network connection and on a distant
|
|
||||||
/// server, you may use a time limit if you don't want your program
|
|
||||||
/// to be possibly stuck waiting in case there is a problem; this
|
|
||||||
/// limit is deactivated by default.
|
|
||||||
///
|
|
||||||
/// \param timeout Maximum time to wait
|
|
||||||
///
|
|
||||||
/// \return Public IP address of the computer
|
|
||||||
///
|
|
||||||
/// \see getLocalAddress
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static IpAddress getPublicAddress(Time timeout = Time::Zero);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Static member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static const IpAddress None; ///< Value representing an empty/invalid address
|
|
||||||
static const IpAddress LocalHost; ///< The "localhost" address (for connecting a computer to itself locally)
|
|
||||||
static const IpAddress Broadcast; ///< The "broadcast" address (for sending UDP messages to everyone on a local network)
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Uint32 m_address; ///< Address stored as an unsigned 32 bits integer
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Overload of == operator to compare two IP addresses
|
|
||||||
///
|
|
||||||
/// \param left Left operand (a IP address)
|
|
||||||
/// \param right Right operand (a IP address)
|
|
||||||
///
|
|
||||||
/// \return True if both addresses are equal
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SFML_NETWORK_API bool operator ==(const IpAddress& left, const IpAddress& right);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Overload of != operator to compare two IP addresses
|
|
||||||
///
|
|
||||||
/// \param left Left operand (a IP address)
|
|
||||||
/// \param right Right operand (a IP address)
|
|
||||||
///
|
|
||||||
/// \return True if both addresses are different
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SFML_NETWORK_API bool operator !=(const IpAddress& left, const IpAddress& right);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Overload of < operator to compare two IP addresses
|
|
||||||
///
|
|
||||||
/// \param left Left operand (a IP address)
|
|
||||||
/// \param right Right operand (a IP address)
|
|
||||||
///
|
|
||||||
/// \return True if \a left is lesser than \a right
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SFML_NETWORK_API bool operator <(const IpAddress& left, const IpAddress& right);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Overload of > operator to compare two IP addresses
|
|
||||||
///
|
|
||||||
/// \param left Left operand (a IP address)
|
|
||||||
/// \param right Right operand (a IP address)
|
|
||||||
///
|
|
||||||
/// \return True if \a left is greater than \a right
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SFML_NETWORK_API bool operator >(const IpAddress& left, const IpAddress& right);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Overload of <= operator to compare two IP addresses
|
|
||||||
///
|
|
||||||
/// \param left Left operand (a IP address)
|
|
||||||
/// \param right Right operand (a IP address)
|
|
||||||
///
|
|
||||||
/// \return True if \a left is lesser or equal than \a right
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SFML_NETWORK_API bool operator <=(const IpAddress& left, const IpAddress& right);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Overload of >= operator to compare two IP addresses
|
|
||||||
///
|
|
||||||
/// \param left Left operand (a IP address)
|
|
||||||
/// \param right Right operand (a IP address)
|
|
||||||
///
|
|
||||||
/// \return True if \a left is greater or equal than \a right
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SFML_NETWORK_API bool operator >=(const IpAddress& left, const IpAddress& right);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Overload of >> operator to extract an IP address from an input stream
|
|
||||||
///
|
|
||||||
/// \param stream Input stream
|
|
||||||
/// \param address IP address to extract
|
|
||||||
///
|
|
||||||
/// \return Reference to the input stream
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SFML_NETWORK_API std::istream& operator >>(std::istream& stream, IpAddress& address);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Overload of << operator to print an IP address to an output stream
|
|
||||||
///
|
|
||||||
/// \param stream Output stream
|
|
||||||
/// \param address IP address to print
|
|
||||||
///
|
|
||||||
/// \return Reference to the output stream
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SFML_NETWORK_API std::ostream& operator <<(std::ostream& stream, const IpAddress& address);
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_IPADDRESS_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::IpAddress
|
|
||||||
/// \ingroup network
|
|
||||||
///
|
|
||||||
/// sf::IpAddress is a utility class for manipulating network
|
|
||||||
/// addresses. It provides a set a implicit constructors and
|
|
||||||
/// conversion functions to easily build or transform an IP
|
|
||||||
/// address from/to various representations.
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// sf::IpAddress a0; // an invalid address
|
|
||||||
/// sf::IpAddress a1 = sf::IpAddress::None; // an invalid address (same as a0)
|
|
||||||
/// sf::IpAddress a2("127.0.0.1"); // the local host address
|
|
||||||
/// sf::IpAddress a3 = sf::IpAddress::Broadcast; // the broadcast address
|
|
||||||
/// sf::IpAddress a4(192, 168, 1, 56); // a local address
|
|
||||||
/// sf::IpAddress a5("my_computer"); // a local address created from a network name
|
|
||||||
/// sf::IpAddress a6("89.54.1.169"); // a distant address
|
|
||||||
/// sf::IpAddress a7("www.google.com"); // a distant address created from a network name
|
|
||||||
/// sf::IpAddress a8 = sf::IpAddress::getLocalAddress(); // my address on the local network
|
|
||||||
/// sf::IpAddress a9 = sf::IpAddress::getPublicAddress(); // my address on the internet
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// Note that sf::IpAddress currently doesn't support IPv6
|
|
||||||
/// nor other types of network addresses.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,412 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_PACKET_HPP
|
|
||||||
#define SFML_PACKET_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Network/Export.hpp>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
class String;
|
|
||||||
class TcpSocket;
|
|
||||||
class UdpSocket;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Utility class to build blocks of data to transfer
|
|
||||||
/// over the network
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_NETWORK_API Packet
|
|
||||||
{
|
|
||||||
// A bool-like type that cannot be converted to integer or pointer types
|
|
||||||
typedef bool (Packet::*BoolType)(std::size_t);
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
/// Creates an empty packet.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Packet();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Virtual destructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual ~Packet();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Append data to the end of the packet
|
|
||||||
///
|
|
||||||
/// \param data Pointer to the sequence of bytes to append
|
|
||||||
/// \param sizeInBytes Number of bytes to append
|
|
||||||
///
|
|
||||||
/// \see clear
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void append(const void* data, std::size_t sizeInBytes);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Clear the packet
|
|
||||||
///
|
|
||||||
/// After calling Clear, the packet is empty.
|
|
||||||
///
|
|
||||||
/// \see append
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void clear();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get a pointer to the data contained in the packet
|
|
||||||
///
|
|
||||||
/// Warning: the returned pointer may become invalid after
|
|
||||||
/// you append data to the packet, therefore it should never
|
|
||||||
/// be stored.
|
|
||||||
/// The return pointer is NULL if the packet is empty.
|
|
||||||
///
|
|
||||||
/// \return Pointer to the data
|
|
||||||
///
|
|
||||||
/// \see getDataSize
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const void* getData() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the size of the data contained in the packet
|
|
||||||
///
|
|
||||||
/// This function returns the number of bytes pointed to by
|
|
||||||
/// what getData returns.
|
|
||||||
///
|
|
||||||
/// \return Data size, in bytes
|
|
||||||
///
|
|
||||||
/// \see getData
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
std::size_t getDataSize() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Tell if the reading position has reached the
|
|
||||||
/// end of the packet
|
|
||||||
///
|
|
||||||
/// This function is useful to know if there is some data
|
|
||||||
/// left to be read, without actually reading it.
|
|
||||||
///
|
|
||||||
/// \return True if all data was read, false otherwise
|
|
||||||
///
|
|
||||||
/// \see operator bool
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool endOfPacket() const;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Test the validity of the packet, for reading
|
|
||||||
///
|
|
||||||
/// This operator allows to test the packet as a boolean
|
|
||||||
/// variable, to check if a reading operation was successful.
|
|
||||||
///
|
|
||||||
/// A packet will be in an invalid state if it has no more
|
|
||||||
/// data to read.
|
|
||||||
///
|
|
||||||
/// This behavior is the same as standard C++ streams.
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// float x;
|
|
||||||
/// packet >> x;
|
|
||||||
/// if (packet)
|
|
||||||
/// {
|
|
||||||
/// // ok, x was extracted successfully
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// // -- or --
|
|
||||||
///
|
|
||||||
/// float x;
|
|
||||||
/// if (packet >> x)
|
|
||||||
/// {
|
|
||||||
/// // ok, x was extracted successfully
|
|
||||||
/// }
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// Don't focus on the return type, it's equivalent to bool but
|
|
||||||
/// it disallows unwanted implicit conversions to integer or
|
|
||||||
/// pointer types.
|
|
||||||
///
|
|
||||||
/// \return True if last data extraction from packet was successful
|
|
||||||
///
|
|
||||||
/// \see endOfPacket
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
operator BoolType() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// Overloads of operator >> to read data from the packet
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Packet& operator >>(bool& data);
|
|
||||||
Packet& operator >>(Int8& data);
|
|
||||||
Packet& operator >>(Uint8& data);
|
|
||||||
Packet& operator >>(Int16& data);
|
|
||||||
Packet& operator >>(Uint16& data);
|
|
||||||
Packet& operator >>(Int32& data);
|
|
||||||
Packet& operator >>(Uint32& data);
|
|
||||||
Packet& operator >>(Int64& data);
|
|
||||||
Packet& operator >>(Uint64& data);
|
|
||||||
Packet& operator >>(float& data);
|
|
||||||
Packet& operator >>(double& data);
|
|
||||||
Packet& operator >>(char* data);
|
|
||||||
Packet& operator >>(std::string& data);
|
|
||||||
Packet& operator >>(wchar_t* data);
|
|
||||||
Packet& operator >>(std::wstring& data);
|
|
||||||
Packet& operator >>(String& data);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// Overloads of operator << to write data into the packet
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Packet& operator <<(bool data);
|
|
||||||
Packet& operator <<(Int8 data);
|
|
||||||
Packet& operator <<(Uint8 data);
|
|
||||||
Packet& operator <<(Int16 data);
|
|
||||||
Packet& operator <<(Uint16 data);
|
|
||||||
Packet& operator <<(Int32 data);
|
|
||||||
Packet& operator <<(Uint32 data);
|
|
||||||
Packet& operator <<(Int64 data);
|
|
||||||
Packet& operator <<(Uint64 data);
|
|
||||||
Packet& operator <<(float data);
|
|
||||||
Packet& operator <<(double data);
|
|
||||||
Packet& operator <<(const char* data);
|
|
||||||
Packet& operator <<(const std::string& data);
|
|
||||||
Packet& operator <<(const wchar_t* data);
|
|
||||||
Packet& operator <<(const std::wstring& data);
|
|
||||||
Packet& operator <<(const String& data);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
friend class TcpSocket;
|
|
||||||
friend class UdpSocket;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Called before the packet is sent over the network
|
|
||||||
///
|
|
||||||
/// This function can be defined by derived classes to
|
|
||||||
/// transform the data before it is sent; this can be
|
|
||||||
/// used for compression, encryption, etc.
|
|
||||||
/// The function must return a pointer to the modified data,
|
|
||||||
/// as well as the number of bytes pointed.
|
|
||||||
/// The default implementation provides the packet's data
|
|
||||||
/// without transforming it.
|
|
||||||
///
|
|
||||||
/// \param size Variable to fill with the size of data to send
|
|
||||||
///
|
|
||||||
/// \return Pointer to the array of bytes to send
|
|
||||||
///
|
|
||||||
/// \see onReceive
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual const void* onSend(std::size_t& size);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Called after the packet is received over the network
|
|
||||||
///
|
|
||||||
/// This function can be defined by derived classes to
|
|
||||||
/// transform the data after it is received; this can be
|
|
||||||
/// used for decompression, decryption, etc.
|
|
||||||
/// The function receives a pointer to the received data,
|
|
||||||
/// and must fill the packet with the transformed bytes.
|
|
||||||
/// The default implementation fills the packet directly
|
|
||||||
/// without transforming the data.
|
|
||||||
///
|
|
||||||
/// \param data Pointer to the received bytes
|
|
||||||
/// \param size Number of bytes
|
|
||||||
///
|
|
||||||
/// \see onSend
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual void onReceive(const void* data, std::size_t size);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// Disallow comparisons between packets
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool operator ==(const Packet& right) const;
|
|
||||||
bool operator !=(const Packet& right) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Check if the packet can extract a given number of bytes
|
|
||||||
///
|
|
||||||
/// This function updates accordingly the state of the packet.
|
|
||||||
///
|
|
||||||
/// \param size Size to check
|
|
||||||
///
|
|
||||||
/// \return True if \a size bytes can be read from the packet
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool checkSize(std::size_t size);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
std::vector<char> m_data; ///< Data stored in the packet
|
|
||||||
std::size_t m_readPos; ///< Current reading position in the packet
|
|
||||||
std::size_t m_sendPos; ///< Current send position in the packet (for handling partial sends)
|
|
||||||
bool m_isValid; ///< Reading state of the packet
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_PACKET_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::Packet
|
|
||||||
/// \ingroup network
|
|
||||||
///
|
|
||||||
/// Packets provide a safe and easy way to serialize data,
|
|
||||||
/// in order to send it over the network using sockets
|
|
||||||
/// (sf::TcpSocket, sf::UdpSocket).
|
|
||||||
///
|
|
||||||
/// Packets solve 2 fundamental problems that arise when
|
|
||||||
/// transferring data over the network:
|
|
||||||
/// \li data is interpreted correctly according to the endianness
|
|
||||||
/// \li the bounds of the packet are preserved (one send == one receive)
|
|
||||||
///
|
|
||||||
/// The sf::Packet class provides both input and output modes.
|
|
||||||
/// It is designed to follow the behavior of standard C++ streams,
|
|
||||||
/// using operators >> and << to extract and insert data.
|
|
||||||
///
|
|
||||||
/// It is recommended to use only fixed-size types (like sf::Int32, etc.),
|
|
||||||
/// to avoid possible differences between the sender and the receiver.
|
|
||||||
/// Indeed, the native C++ types may have different sizes on two platforms
|
|
||||||
/// and your data may be corrupted if that happens.
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// sf::Uint32 x = 24;
|
|
||||||
/// std::string s = "hello";
|
|
||||||
/// double d = 5.89;
|
|
||||||
///
|
|
||||||
/// // Group the variables to send into a packet
|
|
||||||
/// sf::Packet packet;
|
|
||||||
/// packet << x << s << d;
|
|
||||||
///
|
|
||||||
/// // Send it over the network (socket is a valid sf::TcpSocket)
|
|
||||||
/// socket.send(packet);
|
|
||||||
///
|
|
||||||
/// -----------------------------------------------------------------
|
|
||||||
///
|
|
||||||
/// // Receive the packet at the other end
|
|
||||||
/// sf::Packet packet;
|
|
||||||
/// socket.receive(packet);
|
|
||||||
///
|
|
||||||
/// // Extract the variables contained in the packet
|
|
||||||
/// sf::Uint32 x;
|
|
||||||
/// std::string s;
|
|
||||||
/// double d;
|
|
||||||
/// if (packet >> x >> s >> d)
|
|
||||||
/// {
|
|
||||||
/// // Data extracted successfully...
|
|
||||||
/// }
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// Packets have built-in operator >> and << overloads for
|
|
||||||
/// standard types:
|
|
||||||
/// \li bool
|
|
||||||
/// \li fixed-size integer types (sf::Int8/16/32, sf::Uint8/16/32)
|
|
||||||
/// \li floating point numbers (float, double)
|
|
||||||
/// \li string types (char*, wchar_t*, std::string, std::wstring, sf::String)
|
|
||||||
///
|
|
||||||
/// Like standard streams, it is also possible to define your own
|
|
||||||
/// overloads of operators >> and << in order to handle your
|
|
||||||
/// custom types.
|
|
||||||
///
|
|
||||||
/// \code
|
|
||||||
/// struct MyStruct
|
|
||||||
/// {
|
|
||||||
/// float number;
|
|
||||||
/// sf::Int8 integer;
|
|
||||||
/// std::string str;
|
|
||||||
/// };
|
|
||||||
///
|
|
||||||
/// sf::Packet& operator <<(sf::Packet& packet, const MyStruct& m)
|
|
||||||
/// {
|
|
||||||
/// return packet << m.number << m.integer << m.str;
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// sf::Packet& operator >>(sf::Packet& packet, MyStruct& m)
|
|
||||||
/// {
|
|
||||||
/// return packet >> m.number >> m.integer >> m.str;
|
|
||||||
/// }
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// Packets also provide an extra feature that allows to apply
|
|
||||||
/// custom transformations to the data before it is sent,
|
|
||||||
/// and after it is received. This is typically used to
|
|
||||||
/// handle automatic compression or encryption of the data.
|
|
||||||
/// This is achieved by inheriting from sf::Packet, and overriding
|
|
||||||
/// the onSend and onReceive functions.
|
|
||||||
///
|
|
||||||
/// Here is an example:
|
|
||||||
/// \code
|
|
||||||
/// class ZipPacket : public sf::Packet
|
|
||||||
/// {
|
|
||||||
/// virtual const void* onSend(std::size_t& size)
|
|
||||||
/// {
|
|
||||||
/// const void* srcData = getData();
|
|
||||||
/// std::size_t srcSize = getDataSize();
|
|
||||||
///
|
|
||||||
/// return MySuperZipFunction(srcData, srcSize, &size);
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// virtual void onReceive(const void* data, std::size_t size)
|
|
||||||
/// {
|
|
||||||
/// std::size_t dstSize;
|
|
||||||
/// const void* dstData = MySuperUnzipFunction(data, size, &dstSize);
|
|
||||||
///
|
|
||||||
/// append(dstData, dstSize);
|
|
||||||
/// }
|
|
||||||
/// };
|
|
||||||
///
|
|
||||||
/// // Use like regular packets:
|
|
||||||
/// ZipPacket packet;
|
|
||||||
/// packet << x << s << d;
|
|
||||||
/// ...
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \see sf::TcpSocket, sf::UdpSocket
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,219 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_SOCKET_HPP
|
|
||||||
#define SFML_SOCKET_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Network/Export.hpp>
|
|
||||||
#include <SFML/Network/SocketHandle.hpp>
|
|
||||||
#include <SFML/System/NonCopyable.hpp>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
class SocketSelector;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Base class for all the socket types
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_NETWORK_API Socket : NonCopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Status codes that may be returned by socket functions
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
enum Status
|
|
||||||
{
|
|
||||||
Done, ///< The socket has sent / received the data
|
|
||||||
NotReady, ///< The socket is not ready to send / receive data yet
|
|
||||||
Partial, ///< The socket sent a part of the data
|
|
||||||
Disconnected, ///< The TCP socket has been disconnected
|
|
||||||
Error ///< An unexpected error happened
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Some special values used by sockets
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
AnyPort = 0 ///< Special value that tells the system to pick any available port
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Destructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual ~Socket();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Set the blocking state of the socket
|
|
||||||
///
|
|
||||||
/// In blocking mode, calls will not return until they have
|
|
||||||
/// completed their task. For example, a call to Receive in
|
|
||||||
/// blocking mode won't return until some data was actually
|
|
||||||
/// received.
|
|
||||||
/// In non-blocking mode, calls will always return immediately,
|
|
||||||
/// using the return code to signal whether there was data
|
|
||||||
/// available or not.
|
|
||||||
/// By default, all sockets are blocking.
|
|
||||||
///
|
|
||||||
/// \param blocking True to set the socket as blocking, false for non-blocking
|
|
||||||
///
|
|
||||||
/// \see isBlocking
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void setBlocking(bool blocking);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Tell whether the socket is in blocking or non-blocking mode
|
|
||||||
///
|
|
||||||
/// \return True if the socket is blocking, false otherwise
|
|
||||||
///
|
|
||||||
/// \see setBlocking
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool isBlocking() const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Types of protocols that the socket can use
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
enum Type
|
|
||||||
{
|
|
||||||
Tcp, ///< TCP protocol
|
|
||||||
Udp ///< UDP protocol
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
/// This constructor can only be accessed by derived classes.
|
|
||||||
///
|
|
||||||
/// \param type Type of the socket (TCP or UDP)
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Socket(Type type);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Return the internal handle of the socket
|
|
||||||
///
|
|
||||||
/// The returned handle may be invalid if the socket
|
|
||||||
/// was not created yet (or already destroyed).
|
|
||||||
/// This function can only be accessed by derived classes.
|
|
||||||
///
|
|
||||||
/// \return The internal (OS-specific) handle of the socket
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SocketHandle getHandle() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Create the internal representation of the socket
|
|
||||||
///
|
|
||||||
/// This function can only be accessed by derived classes.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void create();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Create the internal representation of the socket
|
|
||||||
/// from a socket handle
|
|
||||||
///
|
|
||||||
/// This function can only be accessed by derived classes.
|
|
||||||
///
|
|
||||||
/// \param handle OS-specific handle of the socket to wrap
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void create(SocketHandle handle);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Close the socket gracefully
|
|
||||||
///
|
|
||||||
/// This function can only be accessed by derived classes.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void close();
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
friend class SocketSelector;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Type m_type; ///< Type of the socket (TCP or UDP)
|
|
||||||
SocketHandle m_socket; ///< Socket descriptor
|
|
||||||
bool m_isBlocking; ///< Current blocking mode of the socket
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_SOCKET_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::Socket
|
|
||||||
/// \ingroup network
|
|
||||||
///
|
|
||||||
/// This class mainly defines internal stuff to be used by
|
|
||||||
/// derived classes.
|
|
||||||
///
|
|
||||||
/// The only public features that it defines, and which
|
|
||||||
/// is therefore common to all the socket classes, is the
|
|
||||||
/// blocking state. All sockets can be set as blocking or
|
|
||||||
/// non-blocking.
|
|
||||||
///
|
|
||||||
/// In blocking mode, socket functions will hang until
|
|
||||||
/// the operation completes, which means that the entire
|
|
||||||
/// program (well, in fact the current thread if you use
|
|
||||||
/// multiple ones) will be stuck waiting for your socket
|
|
||||||
/// operation to complete.
|
|
||||||
///
|
|
||||||
/// In non-blocking mode, all the socket functions will
|
|
||||||
/// return immediately. If the socket is not ready to complete
|
|
||||||
/// the requested operation, the function simply returns
|
|
||||||
/// the proper status code (Socket::NotReady).
|
|
||||||
///
|
|
||||||
/// The default mode, which is blocking, is the one that is
|
|
||||||
/// generally used, in combination with threads or selectors.
|
|
||||||
/// The non-blocking mode is rather used in real-time
|
|
||||||
/// applications that run an endless loop that can poll
|
|
||||||
/// the socket often enough, and cannot afford blocking
|
|
||||||
/// this loop.
|
|
||||||
///
|
|
||||||
/// \see sf::TcpListener, sf::TcpSocket, sf::UdpSocket
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,57 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_SOCKETHANDLE_HPP
|
|
||||||
#define SFML_SOCKETHANDLE_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Config.hpp>
|
|
||||||
|
|
||||||
#if defined(SFML_SYSTEM_WINDOWS)
|
|
||||||
#include <basetsd.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Define the low-level socket handle type, specific to
|
|
||||||
// each platform
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#if defined(SFML_SYSTEM_WINDOWS)
|
|
||||||
|
|
||||||
typedef UINT_PTR SocketHandle;
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
typedef int SocketHandle;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_SOCKETHANDLE_HPP
|
|
@ -1,263 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_SOCKETSELECTOR_HPP
|
|
||||||
#define SFML_SOCKETSELECTOR_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Network/Export.hpp>
|
|
||||||
#include <SFML/System/Time.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
class Socket;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Multiplexer that allows to read from multiple sockets
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_NETWORK_API SocketSelector
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SocketSelector();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Copy constructor
|
|
||||||
///
|
|
||||||
/// \param copy Instance to copy
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SocketSelector(const SocketSelector& copy);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Destructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
~SocketSelector();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Add a new socket to the selector
|
|
||||||
///
|
|
||||||
/// This function keeps a weak reference to the socket,
|
|
||||||
/// so you have to make sure that the socket is not destroyed
|
|
||||||
/// while it is stored in the selector.
|
|
||||||
/// This function does nothing if the socket is not valid.
|
|
||||||
///
|
|
||||||
/// \param socket Reference to the socket to add
|
|
||||||
///
|
|
||||||
/// \see remove, clear
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void add(Socket& socket);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Remove a socket from the selector
|
|
||||||
///
|
|
||||||
/// This function doesn't destroy the socket, it simply
|
|
||||||
/// removes the reference that the selector has to it.
|
|
||||||
///
|
|
||||||
/// \param socket Reference to the socket to remove
|
|
||||||
///
|
|
||||||
/// \see add, clear
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void remove(Socket& socket);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Remove all the sockets stored in the selector
|
|
||||||
///
|
|
||||||
/// This function doesn't destroy any instance, it simply
|
|
||||||
/// removes all the references that the selector has to
|
|
||||||
/// external sockets.
|
|
||||||
///
|
|
||||||
/// \see add, remove
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void clear();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Wait until one or more sockets are ready to receive
|
|
||||||
///
|
|
||||||
/// This function returns as soon as at least one socket has
|
|
||||||
/// some data available to be received. To know which sockets are
|
|
||||||
/// ready, use the isReady function.
|
|
||||||
/// If you use a timeout and no socket is ready before the timeout
|
|
||||||
/// is over, the function returns false.
|
|
||||||
///
|
|
||||||
/// \param timeout Maximum time to wait, (use Time::Zero for infinity)
|
|
||||||
///
|
|
||||||
/// \return True if there are sockets ready, false otherwise
|
|
||||||
///
|
|
||||||
/// \see isReady
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool wait(Time timeout = Time::Zero);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Test a socket to know if it is ready to receive data
|
|
||||||
///
|
|
||||||
/// This function must be used after a call to Wait, to know
|
|
||||||
/// which sockets are ready to receive data. If a socket is
|
|
||||||
/// ready, a call to receive will never block because we know
|
|
||||||
/// that there is data available to read.
|
|
||||||
/// Note that if this function returns true for a TcpListener,
|
|
||||||
/// this means that it is ready to accept a new connection.
|
|
||||||
///
|
|
||||||
/// \param socket Socket to test
|
|
||||||
///
|
|
||||||
/// \return True if the socket is ready to read, false otherwise
|
|
||||||
///
|
|
||||||
/// \see isReady
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool isReady(Socket& socket) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Overload of assignment operator
|
|
||||||
///
|
|
||||||
/// \param right Instance to assign
|
|
||||||
///
|
|
||||||
/// \return Reference to self
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SocketSelector& operator =(const SocketSelector& right);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
struct SocketSelectorImpl;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SocketSelectorImpl* m_impl; ///< Opaque pointer to the implementation (which requires OS-specific types)
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_SOCKETSELECTOR_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::SocketSelector
|
|
||||||
/// \ingroup network
|
|
||||||
///
|
|
||||||
/// Socket selectors provide a way to wait until some data is
|
|
||||||
/// available on a set of sockets, instead of just one. This
|
|
||||||
/// is convenient when you have multiple sockets that may
|
|
||||||
/// possibly receive data, but you don't know which one will
|
|
||||||
/// be ready first. In particular, it avoids to use a thread
|
|
||||||
/// for each socket; with selectors, a single thread can handle
|
|
||||||
/// all the sockets.
|
|
||||||
///
|
|
||||||
/// All types of sockets can be used in a selector:
|
|
||||||
/// \li sf::TcpListener
|
|
||||||
/// \li sf::TcpSocket
|
|
||||||
/// \li sf::UdpSocket
|
|
||||||
///
|
|
||||||
/// A selector doesn't store its own copies of the sockets
|
|
||||||
/// (socket classes are not copyable anyway), it simply keeps
|
|
||||||
/// a reference to the original sockets that you pass to the
|
|
||||||
/// "add" function. Therefore, you can't use the selector as a
|
|
||||||
/// socket container, you must store them outside and make sure
|
|
||||||
/// that they are alive as long as they are used in the selector.
|
|
||||||
///
|
|
||||||
/// Using a selector is simple:
|
|
||||||
/// \li populate the selector with all the sockets that you want to observe
|
|
||||||
/// \li make it wait until there is data available on any of the sockets
|
|
||||||
/// \li test each socket to find out which ones are ready
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// // Create a socket to listen to new connections
|
|
||||||
/// sf::TcpListener listener;
|
|
||||||
/// listener.listen(55001);
|
|
||||||
///
|
|
||||||
/// // Create a list to store the future clients
|
|
||||||
/// std::list<sf::TcpSocket*> clients;
|
|
||||||
///
|
|
||||||
/// // Create a selector
|
|
||||||
/// sf::SocketSelector selector;
|
|
||||||
///
|
|
||||||
/// // Add the listener to the selector
|
|
||||||
/// selector.add(listener);
|
|
||||||
///
|
|
||||||
/// // Endless loop that waits for new connections
|
|
||||||
/// while (running)
|
|
||||||
/// {
|
|
||||||
/// // Make the selector wait for data on any socket
|
|
||||||
/// if (selector.wait())
|
|
||||||
/// {
|
|
||||||
/// // Test the listener
|
|
||||||
/// if (selector.isReady(listener))
|
|
||||||
/// {
|
|
||||||
/// // The listener is ready: there is a pending connection
|
|
||||||
/// sf::TcpSocket* client = new sf::TcpSocket;
|
|
||||||
/// if (listener.accept(*client) == sf::Socket::Done)
|
|
||||||
/// {
|
|
||||||
/// // Add the new client to the clients list
|
|
||||||
/// clients.push_back(client);
|
|
||||||
///
|
|
||||||
/// // Add the new client to the selector so that we will
|
|
||||||
/// // be notified when he sends something
|
|
||||||
/// selector.add(*client);
|
|
||||||
/// }
|
|
||||||
/// else
|
|
||||||
/// {
|
|
||||||
/// // Error, we won't get a new connection, delete the socket
|
|
||||||
/// delete client;
|
|
||||||
/// }
|
|
||||||
/// }
|
|
||||||
/// else
|
|
||||||
/// {
|
|
||||||
/// // The listener socket is not ready, test all other sockets (the clients)
|
|
||||||
/// for (std::list<sf::TcpSocket*>::iterator it = clients.begin(); it != clients.end(); ++it)
|
|
||||||
/// {
|
|
||||||
/// sf::TcpSocket& client = **it;
|
|
||||||
/// if (selector.isReady(client))
|
|
||||||
/// {
|
|
||||||
/// // The client has sent some data, we can receive it
|
|
||||||
/// sf::Packet packet;
|
|
||||||
/// if (client.receive(packet) == sf::Socket::Done)
|
|
||||||
/// {
|
|
||||||
/// ...
|
|
||||||
/// }
|
|
||||||
/// }
|
|
||||||
/// }
|
|
||||||
/// }
|
|
||||||
/// }
|
|
||||||
/// }
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \see sf::Socket
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,162 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_TCPLISTENER_HPP
|
|
||||||
#define SFML_TCPLISTENER_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Network/Export.hpp>
|
|
||||||
#include <SFML/Network/Socket.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
class TcpSocket;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Socket that listens to new TCP connections
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_NETWORK_API TcpListener : public Socket
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
TcpListener();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the port to which the socket is bound locally
|
|
||||||
///
|
|
||||||
/// If the socket is not listening to a port, this function
|
|
||||||
/// returns 0.
|
|
||||||
///
|
|
||||||
/// \return Port to which the socket is bound
|
|
||||||
///
|
|
||||||
/// \see listen
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
unsigned short getLocalPort() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Start listening for connections
|
|
||||||
///
|
|
||||||
/// This functions makes the socket listen to the specified
|
|
||||||
/// port, waiting for new connections.
|
|
||||||
/// If the socket was previously listening to another port,
|
|
||||||
/// it will be stopped first and bound to the new port.
|
|
||||||
///
|
|
||||||
/// \param port Port to listen for new connections
|
|
||||||
///
|
|
||||||
/// \return Status code
|
|
||||||
///
|
|
||||||
/// \see accept, close
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Status listen(unsigned short port);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Stop listening and close the socket
|
|
||||||
///
|
|
||||||
/// This function gracefully stops the listener. If the
|
|
||||||
/// socket is not listening, this function has no effect.
|
|
||||||
///
|
|
||||||
/// \see listen
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void close();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Accept a new connection
|
|
||||||
///
|
|
||||||
/// If the socket is in blocking mode, this function will
|
|
||||||
/// not return until a connection is actually received.
|
|
||||||
///
|
|
||||||
/// \param socket Socket that will hold the new connection
|
|
||||||
///
|
|
||||||
/// \return Status code
|
|
||||||
///
|
|
||||||
/// \see listen
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Status accept(TcpSocket& socket);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_TCPLISTENER_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::TcpListener
|
|
||||||
/// \ingroup network
|
|
||||||
///
|
|
||||||
/// A listener socket is a special type of socket that listens to
|
|
||||||
/// a given port and waits for connections on that port.
|
|
||||||
/// This is all it can do.
|
|
||||||
///
|
|
||||||
/// When a new connection is received, you must call accept and
|
|
||||||
/// the listener returns a new instance of sf::TcpSocket that
|
|
||||||
/// is properly initialized and can be used to communicate with
|
|
||||||
/// the new client.
|
|
||||||
///
|
|
||||||
/// Listener sockets are specific to the TCP protocol,
|
|
||||||
/// UDP sockets are connectionless and can therefore communicate
|
|
||||||
/// directly. As a consequence, a listener socket will always
|
|
||||||
/// return the new connections as sf::TcpSocket instances.
|
|
||||||
///
|
|
||||||
/// A listener is automatically closed on destruction, like all
|
|
||||||
/// other types of socket. However if you want to stop listening
|
|
||||||
/// before the socket is destroyed, you can call its close()
|
|
||||||
/// function.
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// // Create a listener socket and make it wait for new
|
|
||||||
/// // connections on port 55001
|
|
||||||
/// sf::TcpListener listener;
|
|
||||||
/// listener.listen(55001);
|
|
||||||
///
|
|
||||||
/// // Endless loop that waits for new connections
|
|
||||||
/// while (running)
|
|
||||||
/// {
|
|
||||||
/// sf::TcpSocket client;
|
|
||||||
/// if (listener.accept(client) == sf::Socket::Done)
|
|
||||||
/// {
|
|
||||||
/// // A new client just connected!
|
|
||||||
/// std::cout << "New connection received from " << client.getRemoteAddress() << std::endl;
|
|
||||||
/// doSomethingWith(client);
|
|
||||||
/// }
|
|
||||||
/// }
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \see sf::TcpSocket, sf::Socket
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,315 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_TCPSOCKET_HPP
|
|
||||||
#define SFML_TCPSOCKET_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Network/Export.hpp>
|
|
||||||
#include <SFML/Network/Socket.hpp>
|
|
||||||
#include <SFML/System/Time.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
class TcpListener;
|
|
||||||
class IpAddress;
|
|
||||||
class Packet;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Specialized socket using the TCP protocol
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_NETWORK_API TcpSocket : public Socket
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
TcpSocket();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the port to which the socket is bound locally
|
|
||||||
///
|
|
||||||
/// If the socket is not connected, this function returns 0.
|
|
||||||
///
|
|
||||||
/// \return Port to which the socket is bound
|
|
||||||
///
|
|
||||||
/// \see connect, getRemotePort
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
unsigned short getLocalPort() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the address of the connected peer
|
|
||||||
///
|
|
||||||
/// It the socket is not connected, this function returns
|
|
||||||
/// sf::IpAddress::None.
|
|
||||||
///
|
|
||||||
/// \return Address of the remote peer
|
|
||||||
///
|
|
||||||
/// \see getRemotePort
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
IpAddress getRemoteAddress() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the port of the connected peer to which
|
|
||||||
/// the socket is connected
|
|
||||||
///
|
|
||||||
/// If the socket is not connected, this function returns 0.
|
|
||||||
///
|
|
||||||
/// \return Remote port to which the socket is connected
|
|
||||||
///
|
|
||||||
/// \see getRemoteAddress
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
unsigned short getRemotePort() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Connect the socket to a remote peer
|
|
||||||
///
|
|
||||||
/// In blocking mode, this function may take a while, especially
|
|
||||||
/// if the remote peer is not reachable. The last parameter allows
|
|
||||||
/// you to stop trying to connect after a given timeout.
|
|
||||||
/// If the socket was previously connected, it is first disconnected.
|
|
||||||
///
|
|
||||||
/// \param remoteAddress Address of the remote peer
|
|
||||||
/// \param remotePort Port of the remote peer
|
|
||||||
/// \param timeout Optional maximum time to wait
|
|
||||||
///
|
|
||||||
/// \return Status code
|
|
||||||
///
|
|
||||||
/// \see disconnect
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Status connect(const IpAddress& remoteAddress, unsigned short remotePort, Time timeout = Time::Zero);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Disconnect the socket from its remote peer
|
|
||||||
///
|
|
||||||
/// This function gracefully closes the connection. If the
|
|
||||||
/// socket is not connected, this function has no effect.
|
|
||||||
///
|
|
||||||
/// \see connect
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void disconnect();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Send raw data to the remote peer
|
|
||||||
///
|
|
||||||
/// To be able to handle partial sends over non-blocking
|
|
||||||
/// sockets, use the send(const void*, std::size_t, std::size_t&)
|
|
||||||
/// overload instead.
|
|
||||||
/// This function will fail if the socket is not connected.
|
|
||||||
///
|
|
||||||
/// \param data Pointer to the sequence of bytes to send
|
|
||||||
/// \param size Number of bytes to send
|
|
||||||
///
|
|
||||||
/// \return Status code
|
|
||||||
///
|
|
||||||
/// \see receive
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Status send(const void* data, std::size_t size);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Send raw data to the remote peer
|
|
||||||
///
|
|
||||||
/// This function will fail if the socket is not connected.
|
|
||||||
///
|
|
||||||
/// \param data Pointer to the sequence of bytes to send
|
|
||||||
/// \param size Number of bytes to send
|
|
||||||
/// \param sent The number of bytes sent will be written here
|
|
||||||
///
|
|
||||||
/// \return Status code
|
|
||||||
///
|
|
||||||
/// \see receive
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Status send(const void* data, std::size_t size, std::size_t& sent);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Receive raw data from the remote peer
|
|
||||||
///
|
|
||||||
/// In blocking mode, this function will wait until some
|
|
||||||
/// bytes are actually received.
|
|
||||||
/// This function will fail if the socket is not connected.
|
|
||||||
///
|
|
||||||
/// \param data Pointer to the array to fill with the received bytes
|
|
||||||
/// \param size Maximum number of bytes that can be received
|
|
||||||
/// \param received This variable is filled with the actual number of bytes received
|
|
||||||
///
|
|
||||||
/// \return Status code
|
|
||||||
///
|
|
||||||
/// \see send
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Status receive(void* data, std::size_t size, std::size_t& received);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Send a formatted packet of data to the remote peer
|
|
||||||
///
|
|
||||||
/// In non-blocking mode, if this function returns sf::Socket::Partial,
|
|
||||||
/// you \em must retry sending the same unmodified packet before sending
|
|
||||||
/// anything else in order to guarantee the packet arrives at the remote
|
|
||||||
/// peer uncorrupted.
|
|
||||||
/// This function will fail if the socket is not connected.
|
|
||||||
///
|
|
||||||
/// \param packet Packet to send
|
|
||||||
///
|
|
||||||
/// \return Status code
|
|
||||||
///
|
|
||||||
/// \see receive
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Status send(Packet& packet);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Receive a formatted packet of data from the remote peer
|
|
||||||
///
|
|
||||||
/// In blocking mode, this function will wait until the whole packet
|
|
||||||
/// has been received.
|
|
||||||
/// This function will fail if the socket is not connected.
|
|
||||||
///
|
|
||||||
/// \param packet Packet to fill with the received data
|
|
||||||
///
|
|
||||||
/// \return Status code
|
|
||||||
///
|
|
||||||
/// \see send
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Status receive(Packet& packet);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
friend class TcpListener;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Structure holding the data of a pending packet
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
struct PendingPacket
|
|
||||||
{
|
|
||||||
PendingPacket();
|
|
||||||
|
|
||||||
Uint32 Size; ///< Data of packet size
|
|
||||||
std::size_t SizeReceived; ///< Number of size bytes received so far
|
|
||||||
std::vector<char> Data; ///< Data of the packet
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
PendingPacket m_pendingPacket; ///< Temporary data of the packet currently being received
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_TCPSOCKET_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::TcpSocket
|
|
||||||
/// \ingroup network
|
|
||||||
///
|
|
||||||
/// TCP is a connected protocol, which means that a TCP
|
|
||||||
/// socket can only communicate with the host it is connected
|
|
||||||
/// to. It can't send or receive anything if it is not connected.
|
|
||||||
///
|
|
||||||
/// The TCP protocol is reliable but adds a slight overhead.
|
|
||||||
/// It ensures that your data will always be received in order
|
|
||||||
/// and without errors (no data corrupted, lost or duplicated).
|
|
||||||
///
|
|
||||||
/// When a socket is connected to a remote host, you can
|
|
||||||
/// retrieve informations about this host with the
|
|
||||||
/// getRemoteAddress and getRemotePort functions. You can
|
|
||||||
/// also get the local port to which the socket is bound
|
|
||||||
/// (which is automatically chosen when the socket is connected),
|
|
||||||
/// with the getLocalPort function.
|
|
||||||
///
|
|
||||||
/// Sending and receiving data can use either the low-level
|
|
||||||
/// or the high-level functions. The low-level functions
|
|
||||||
/// process a raw sequence of bytes, and cannot ensure that
|
|
||||||
/// one call to Send will exactly match one call to Receive
|
|
||||||
/// at the other end of the socket.
|
|
||||||
///
|
|
||||||
/// The high-level interface uses packets (see sf::Packet),
|
|
||||||
/// which are easier to use and provide more safety regarding
|
|
||||||
/// the data that is exchanged. You can look at the sf::Packet
|
|
||||||
/// class to get more details about how they work.
|
|
||||||
///
|
|
||||||
/// The socket is automatically disconnected when it is destroyed,
|
|
||||||
/// but if you want to explicitly close the connection while
|
|
||||||
/// the socket instance is still alive, you can call disconnect.
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// // ----- The client -----
|
|
||||||
///
|
|
||||||
/// // Create a socket and connect it to 192.168.1.50 on port 55001
|
|
||||||
/// sf::TcpSocket socket;
|
|
||||||
/// socket.connect("192.168.1.50", 55001);
|
|
||||||
///
|
|
||||||
/// // Send a message to the connected host
|
|
||||||
/// std::string message = "Hi, I am a client";
|
|
||||||
/// socket.send(message.c_str(), message.size() + 1);
|
|
||||||
///
|
|
||||||
/// // Receive an answer from the server
|
|
||||||
/// char buffer[1024];
|
|
||||||
/// std::size_t received = 0;
|
|
||||||
/// socket.receive(buffer, sizeof(buffer), received);
|
|
||||||
/// std::cout << "The server said: " << buffer << std::endl;
|
|
||||||
///
|
|
||||||
/// // ----- The server -----
|
|
||||||
///
|
|
||||||
/// // Create a listener to wait for incoming connections on port 55001
|
|
||||||
/// sf::TcpListener listener;
|
|
||||||
/// listener.listen(55001);
|
|
||||||
///
|
|
||||||
/// // Wait for a connection
|
|
||||||
/// sf::TcpSocket socket;
|
|
||||||
/// listener.accept(socket);
|
|
||||||
/// std::cout << "New client connected: " << socket.getRemoteAddress() << std::endl;
|
|
||||||
///
|
|
||||||
/// // Receive a message from the client
|
|
||||||
/// char buffer[1024];
|
|
||||||
/// std::size_t received = 0;
|
|
||||||
/// socket.receive(buffer, sizeof(buffer), received);
|
|
||||||
/// std::cout << "The client said: " << buffer << std::endl;
|
|
||||||
///
|
|
||||||
/// // Send an answer
|
|
||||||
/// std::string message = "Welcome, client";
|
|
||||||
/// socket.send(message.c_str(), message.size() + 1);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \see sf::Socket, sf::UdpSocket, sf::Packet
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,283 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_UDPSOCKET_HPP
|
|
||||||
#define SFML_UDPSOCKET_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Network/Export.hpp>
|
|
||||||
#include <SFML/Network/Socket.hpp>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
class IpAddress;
|
|
||||||
class Packet;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Specialized socket using the UDP protocol
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_NETWORK_API UdpSocket : public Socket
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Constants
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
MaxDatagramSize = 65507 ///< The maximum number of bytes that can be sent in a single UDP datagram
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
UdpSocket();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the port to which the socket is bound locally
|
|
||||||
///
|
|
||||||
/// If the socket is not bound to a port, this function
|
|
||||||
/// returns 0.
|
|
||||||
///
|
|
||||||
/// \return Port to which the socket is bound
|
|
||||||
///
|
|
||||||
/// \see bind
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
unsigned short getLocalPort() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Bind the socket to a specific port
|
|
||||||
///
|
|
||||||
/// Binding the socket to a port is necessary for being
|
|
||||||
/// able to receive data on that port.
|
|
||||||
/// You can use the special value Socket::AnyPort to tell the
|
|
||||||
/// system to automatically pick an available port, and then
|
|
||||||
/// call getLocalPort to retrieve the chosen port.
|
|
||||||
///
|
|
||||||
/// \param port Port to bind the socket to
|
|
||||||
///
|
|
||||||
/// \return Status code
|
|
||||||
///
|
|
||||||
/// \see unbind, getLocalPort
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Status bind(unsigned short port);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Unbind the socket from the local port to which it is bound
|
|
||||||
///
|
|
||||||
/// The port that the socket was previously using is immediately
|
|
||||||
/// available after this function is called. If the
|
|
||||||
/// socket is not bound to a port, this function has no effect.
|
|
||||||
///
|
|
||||||
/// \see bind
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void unbind();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Send raw data to a remote peer
|
|
||||||
///
|
|
||||||
/// Make sure that \a size is not greater than
|
|
||||||
/// UdpSocket::MaxDatagramSize, otherwise this function will
|
|
||||||
/// fail and no data will be sent.
|
|
||||||
///
|
|
||||||
/// \param data Pointer to the sequence of bytes to send
|
|
||||||
/// \param size Number of bytes to send
|
|
||||||
/// \param remoteAddress Address of the receiver
|
|
||||||
/// \param remotePort Port of the receiver to send the data to
|
|
||||||
///
|
|
||||||
/// \return Status code
|
|
||||||
///
|
|
||||||
/// \see receive
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Status send(const void* data, std::size_t size, const IpAddress& remoteAddress, unsigned short remotePort);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Receive raw data from a remote peer
|
|
||||||
///
|
|
||||||
/// In blocking mode, this function will wait until some
|
|
||||||
/// bytes are actually received.
|
|
||||||
/// Be careful to use a buffer which is large enough for
|
|
||||||
/// the data that you intend to receive, if it is too small
|
|
||||||
/// then an error will be returned and *all* the data will
|
|
||||||
/// be lost.
|
|
||||||
///
|
|
||||||
/// \param data Pointer to the array to fill with the received bytes
|
|
||||||
/// \param size Maximum number of bytes that can be received
|
|
||||||
/// \param received This variable is filled with the actual number of bytes received
|
|
||||||
/// \param remoteAddress Address of the peer that sent the data
|
|
||||||
/// \param remotePort Port of the peer that sent the data
|
|
||||||
///
|
|
||||||
/// \return Status code
|
|
||||||
///
|
|
||||||
/// \see send
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Status receive(void* data, std::size_t size, std::size_t& received, IpAddress& remoteAddress, unsigned short& remotePort);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Send a formatted packet of data to a remote peer
|
|
||||||
///
|
|
||||||
/// Make sure that the packet size is not greater than
|
|
||||||
/// UdpSocket::MaxDatagramSize, otherwise this function will
|
|
||||||
/// fail and no data will be sent.
|
|
||||||
///
|
|
||||||
/// \param packet Packet to send
|
|
||||||
/// \param remoteAddress Address of the receiver
|
|
||||||
/// \param remotePort Port of the receiver to send the data to
|
|
||||||
///
|
|
||||||
/// \return Status code
|
|
||||||
///
|
|
||||||
/// \see receive
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Status send(Packet& packet, const IpAddress& remoteAddress, unsigned short remotePort);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Receive a formatted packet of data from a remote peer
|
|
||||||
///
|
|
||||||
/// In blocking mode, this function will wait until the whole packet
|
|
||||||
/// has been received.
|
|
||||||
///
|
|
||||||
/// \param packet Packet to fill with the received data
|
|
||||||
/// \param remoteAddress Address of the peer that sent the data
|
|
||||||
/// \param remotePort Port of the peer that sent the data
|
|
||||||
///
|
|
||||||
/// \return Status code
|
|
||||||
///
|
|
||||||
/// \see send
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Status receive(Packet& packet, IpAddress& remoteAddress, unsigned short& remotePort);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
std::vector<char> m_buffer; ///< Temporary buffer holding the received data in Receive(Packet)
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_UDPSOCKET_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::UdpSocket
|
|
||||||
/// \ingroup network
|
|
||||||
///
|
|
||||||
/// A UDP socket is a connectionless socket. Instead of
|
|
||||||
/// connecting once to a remote host, like TCP sockets,
|
|
||||||
/// it can send to and receive from any host at any time.
|
|
||||||
///
|
|
||||||
/// It is a datagram protocol: bounded blocks of data (datagrams)
|
|
||||||
/// are transfered over the network rather than a continuous
|
|
||||||
/// stream of data (TCP). Therefore, one call to send will always
|
|
||||||
/// match one call to receive (if the datagram is not lost),
|
|
||||||
/// with the same data that was sent.
|
|
||||||
///
|
|
||||||
/// The UDP protocol is lightweight but unreliable. Unreliable
|
|
||||||
/// means that datagrams may be duplicated, be lost or
|
|
||||||
/// arrive reordered. However, if a datagram arrives, its
|
|
||||||
/// data is guaranteed to be valid.
|
|
||||||
///
|
|
||||||
/// UDP is generally used for real-time communication
|
|
||||||
/// (audio or video streaming, real-time games, etc.) where
|
|
||||||
/// speed is crucial and lost data doesn't matter much.
|
|
||||||
///
|
|
||||||
/// Sending and receiving data can use either the low-level
|
|
||||||
/// or the high-level functions. The low-level functions
|
|
||||||
/// process a raw sequence of bytes, whereas the high-level
|
|
||||||
/// interface uses packets (see sf::Packet), which are easier
|
|
||||||
/// to use and provide more safety regarding the data that is
|
|
||||||
/// exchanged. You can look at the sf::Packet class to get
|
|
||||||
/// more details about how they work.
|
|
||||||
///
|
|
||||||
/// It is important to note that UdpSocket is unable to send
|
|
||||||
/// datagrams bigger than MaxDatagramSize. In this case, it
|
|
||||||
/// returns an error and doesn't send anything. This applies
|
|
||||||
/// to both raw data and packets. Indeed, even packets are
|
|
||||||
/// unable to split and recompose data, due to the unreliability
|
|
||||||
/// of the protocol (dropped, mixed or duplicated datagrams may
|
|
||||||
/// lead to a big mess when trying to recompose a packet).
|
|
||||||
///
|
|
||||||
/// If the socket is bound to a port, it is automatically
|
|
||||||
/// unbound from it when the socket is destroyed. However,
|
|
||||||
/// you can unbind the socket explicitly with the Unbind
|
|
||||||
/// function if necessary, to stop receiving messages or
|
|
||||||
/// make the port available for other sockets.
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// // ----- The client -----
|
|
||||||
///
|
|
||||||
/// // Create a socket and bind it to the port 55001
|
|
||||||
/// sf::UdpSocket socket;
|
|
||||||
/// socket.bind(55001);
|
|
||||||
///
|
|
||||||
/// // Send a message to 192.168.1.50 on port 55002
|
|
||||||
/// std::string message = "Hi, I am " + sf::IpAddress::getLocalAddress().toString();
|
|
||||||
/// socket.send(message.c_str(), message.size() + 1, "192.168.1.50", 55002);
|
|
||||||
///
|
|
||||||
/// // Receive an answer (most likely from 192.168.1.50, but could be anyone else)
|
|
||||||
/// char buffer[1024];
|
|
||||||
/// std::size_t received = 0;
|
|
||||||
/// sf::IpAddress sender;
|
|
||||||
/// unsigned short port;
|
|
||||||
/// socket.receive(buffer, sizeof(buffer), received, sender, port);
|
|
||||||
/// std::cout << sender.ToString() << " said: " << buffer << std::endl;
|
|
||||||
///
|
|
||||||
/// // ----- The server -----
|
|
||||||
///
|
|
||||||
/// // Create a socket and bind it to the port 55002
|
|
||||||
/// sf::UdpSocket socket;
|
|
||||||
/// socket.bind(55002);
|
|
||||||
///
|
|
||||||
/// // Receive a message from anyone
|
|
||||||
/// char buffer[1024];
|
|
||||||
/// std::size_t received = 0;
|
|
||||||
/// sf::IpAddress sender;
|
|
||||||
/// unsigned short port;
|
|
||||||
/// socket.receive(buffer, sizeof(buffer), received, sender, port);
|
|
||||||
/// std::cout << sender.ToString() << " said: " << buffer << std::endl;
|
|
||||||
///
|
|
||||||
/// // Send an answer
|
|
||||||
/// std::string message = "Welcome " + sender.toString();
|
|
||||||
/// socket.send(message.c_str(), message.size() + 1, sender, port);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \see sf::Socket, sf::TcpSocket, sf::Packet
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,74 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_OPENGL_HPP
|
|
||||||
#define SFML_OPENGL_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Config.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// This file just includes the OpenGL headers,
|
|
||||||
/// which have actually different paths on each system
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#if defined(SFML_SYSTEM_WINDOWS)
|
|
||||||
|
|
||||||
// The Visual C++ version of gl.h uses WINGDIAPI and APIENTRY but doesn't define them
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#include <windows.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <GL/gl.h>
|
|
||||||
|
|
||||||
#elif defined(SFML_SYSTEM_LINUX) || defined(SFML_SYSTEM_FREEBSD)
|
|
||||||
|
|
||||||
#if defined(SFML_OPENGL_ES)
|
|
||||||
#include <GLES/gl.h>
|
|
||||||
#include <GLES/glext.h>
|
|
||||||
#else
|
|
||||||
#include <GL/gl.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#elif defined(SFML_SYSTEM_MACOS)
|
|
||||||
|
|
||||||
#include <OpenGL/gl.h>
|
|
||||||
|
|
||||||
#elif defined (SFML_SYSTEM_IOS)
|
|
||||||
|
|
||||||
#include <OpenGLES/ES1/gl.h>
|
|
||||||
#include <OpenGLES/ES1/glext.h>
|
|
||||||
|
|
||||||
#elif defined (SFML_SYSTEM_ANDROID)
|
|
||||||
|
|
||||||
#include <GLES/gl.h>
|
|
||||||
#include <GLES/glext.h>
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_OPENGL_HPP
|
|
@ -1,60 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_SYSTEM_HPP
|
|
||||||
#define SFML_SYSTEM_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#include <SFML/Config.hpp>
|
|
||||||
#include <SFML/System/Clock.hpp>
|
|
||||||
#include <SFML/System/Err.hpp>
|
|
||||||
#include <SFML/System/FileInputStream.hpp>
|
|
||||||
#include <SFML/System/InputStream.hpp>
|
|
||||||
#include <SFML/System/Lock.hpp>
|
|
||||||
#include <SFML/System/MemoryInputStream.hpp>
|
|
||||||
#include <SFML/System/Mutex.hpp>
|
|
||||||
#include <SFML/System/NonCopyable.hpp>
|
|
||||||
#include <SFML/System/Sleep.hpp>
|
|
||||||
#include <SFML/System/String.hpp>
|
|
||||||
#include <SFML/System/Thread.hpp>
|
|
||||||
#include <SFML/System/ThreadLocal.hpp>
|
|
||||||
#include <SFML/System/ThreadLocalPtr.hpp>
|
|
||||||
#include <SFML/System/Time.hpp>
|
|
||||||
#include <SFML/System/Utf.hpp>
|
|
||||||
#include <SFML/System/Vector2.hpp>
|
|
||||||
#include <SFML/System/Vector3.hpp>
|
|
||||||
|
|
||||||
#endif // SFML_SYSTEM_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \defgroup system System module
|
|
||||||
///
|
|
||||||
/// Base module of SFML, defining various utilities. It provides
|
|
||||||
/// vector classes, Unicode strings and conversion functions,
|
|
||||||
/// threads and mutexes, timing classes.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,117 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_CLOCK_HPP
|
|
||||||
#define SFML_CLOCK_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/System/Export.hpp>
|
|
||||||
#include <SFML/System/Time.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Utility class that measures the elapsed time
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_SYSTEM_API Clock
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
/// The clock starts automatically after being constructed.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Clock();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the elapsed time
|
|
||||||
///
|
|
||||||
/// This function returns the time elapsed since the last call
|
|
||||||
/// to restart() (or the construction of the instance if restart()
|
|
||||||
/// has not been called).
|
|
||||||
///
|
|
||||||
/// \return Time elapsed
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Time getElapsedTime() const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Restart the clock
|
|
||||||
///
|
|
||||||
/// This function puts the time counter back to zero.
|
|
||||||
/// It also returns the time elapsed since the clock was started.
|
|
||||||
///
|
|
||||||
/// \return Time elapsed
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Time restart();
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Time m_startTime; ///< Time of last reset, in microseconds
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_CLOCK_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::Clock
|
|
||||||
/// \ingroup system
|
|
||||||
///
|
|
||||||
/// sf::Clock is a lightweight class for measuring time.
|
|
||||||
///
|
|
||||||
/// Its provides the most precise time that the underlying
|
|
||||||
/// OS can achieve (generally microseconds or nanoseconds).
|
|
||||||
/// It also ensures monotonicity, which means that the returned
|
|
||||||
/// time can never go backward, even if the system time is
|
|
||||||
/// changed.
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// sf::Clock clock;
|
|
||||||
/// ...
|
|
||||||
/// Time time1 = clock.getElapsedTime();
|
|
||||||
/// ...
|
|
||||||
/// Time time2 = clock.restart();
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// The sf::Time value returned by the clock can then be
|
|
||||||
/// converted to a number of seconds, milliseconds or even
|
|
||||||
/// microseconds.
|
|
||||||
///
|
|
||||||
/// \see sf::Time
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,80 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_ERR_HPP
|
|
||||||
#define SFML_ERR_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/System/Export.hpp>
|
|
||||||
#include <ostream>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Standard stream used by SFML to output warnings and errors
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SFML_SYSTEM_API std::ostream& err();
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_ERR_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \fn sf::err
|
|
||||||
/// \ingroup system
|
|
||||||
///
|
|
||||||
/// By default, sf::err() outputs to the same location as std::cerr,
|
|
||||||
/// (-> the stderr descriptor) which is the console if there's
|
|
||||||
/// one available.
|
|
||||||
///
|
|
||||||
/// It is a standard std::ostream instance, so it supports all the
|
|
||||||
/// insertion operations defined by the STL
|
|
||||||
/// (operator <<, manipulators, etc.).
|
|
||||||
///
|
|
||||||
/// sf::err() can be redirected to write to another output, independently
|
|
||||||
/// of std::cerr, by using the rdbuf() function provided by the
|
|
||||||
/// std::ostream class.
|
|
||||||
///
|
|
||||||
/// Example:
|
|
||||||
/// \code
|
|
||||||
/// // Redirect to a file
|
|
||||||
/// std::ofstream file("sfml-log.txt");
|
|
||||||
/// std::streambuf* previous = sf::err().rdbuf(file.rdbuf());
|
|
||||||
///
|
|
||||||
/// // Redirect to nothing
|
|
||||||
/// sf::err().rdbuf(NULL);
|
|
||||||
///
|
|
||||||
/// // Restore the original output
|
|
||||||
/// sf::err().rdbuf(previous);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// \return Reference to std::ostream representing the SFML error stream
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,48 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_SYSTEM_EXPORT_HPP
|
|
||||||
#define SFML_SYSTEM_EXPORT_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Config.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Define portable import / export macros
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#if defined(SFML_SYSTEM_EXPORTS)
|
|
||||||
|
|
||||||
#define SFML_SYSTEM_API SFML_API_EXPORT
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
#define SFML_SYSTEM_API SFML_API_IMPORT
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_SYSTEM_EXPORT_HPP
|
|
@ -1,169 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_FILEINPUTSTREAM_HPP
|
|
||||||
#define SFML_FILEINPUTSTREAM_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Config.hpp>
|
|
||||||
#include <SFML/System/Export.hpp>
|
|
||||||
#include <SFML/System/InputStream.hpp>
|
|
||||||
#include <SFML/System/NonCopyable.hpp>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#ifdef ANDROID
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
namespace priv
|
|
||||||
{
|
|
||||||
class SFML_SYSTEM_API ResourceStream;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Implementation of input stream based on a file
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_SYSTEM_API FileInputStream : public InputStream, NonCopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
FileInputStream();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default destructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual ~FileInputStream();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Open the stream from a file path
|
|
||||||
///
|
|
||||||
/// \param filename Name of the file to open
|
|
||||||
///
|
|
||||||
/// \return True on success, false on error
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool open(const std::string& filename);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Read data from the stream
|
|
||||||
///
|
|
||||||
/// After reading, the stream's reading position must be
|
|
||||||
/// advanced by the amount of bytes read.
|
|
||||||
///
|
|
||||||
/// \param data Buffer where to copy the read data
|
|
||||||
/// \param size Desired number of bytes to read
|
|
||||||
///
|
|
||||||
/// \return The number of bytes actually read, or -1 on error
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual Int64 read(void* data, Int64 size);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Change the current reading position
|
|
||||||
///
|
|
||||||
/// \param position The position to seek to, from the beginning
|
|
||||||
///
|
|
||||||
/// \return The position actually sought to, or -1 on error
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual Int64 seek(Int64 position);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the current reading position in the stream
|
|
||||||
///
|
|
||||||
/// \return The current position, or -1 on error.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual Int64 tell();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Return the size of the stream
|
|
||||||
///
|
|
||||||
/// \return The total number of bytes available in the stream, or -1 on error
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual Int64 getSize();
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#ifdef ANDROID
|
|
||||||
priv::ResourceStream* m_file;
|
|
||||||
#else
|
|
||||||
std::FILE* m_file; ///< stdio file stream
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_FILEINPUTSTREAM_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class FileInputStream
|
|
||||||
/// \ingroup system
|
|
||||||
///
|
|
||||||
/// This class is a specialization of InputStream that
|
|
||||||
/// reads from a file on disk.
|
|
||||||
///
|
|
||||||
/// It wraps a file in the common InputStream interface
|
|
||||||
/// and therefore allows to use generic classes or functions
|
|
||||||
/// that accept such a stream, with a file on disk as the data
|
|
||||||
/// source.
|
|
||||||
///
|
|
||||||
/// In addition to the virtual functions inherited from
|
|
||||||
/// InputStream, FileInputStream adds a function to
|
|
||||||
/// specify the file to open.
|
|
||||||
///
|
|
||||||
/// SFML resource classes can usually be loaded directly from
|
|
||||||
/// a filename, so this class shouldn't be useful to you unless
|
|
||||||
/// you create your own algorithms that operate on a InputStream.
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// void process(InputStream& stream);
|
|
||||||
///
|
|
||||||
/// FileStream stream;
|
|
||||||
/// if (stream.open("some_file.dat"))
|
|
||||||
/// process(stream);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// InputStream, MemoryStream
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,152 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_INPUTSTREAM_HPP
|
|
||||||
#define SFML_INPUTSTREAM_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Config.hpp>
|
|
||||||
#include <SFML/System/Export.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Abstract class for custom file input streams
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_SYSTEM_API InputStream
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Virtual destructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual ~InputStream() {}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Read data from the stream
|
|
||||||
///
|
|
||||||
/// After reading, the stream's reading position must be
|
|
||||||
/// advanced by the amount of bytes read.
|
|
||||||
///
|
|
||||||
/// \param data Buffer where to copy the read data
|
|
||||||
/// \param size Desired number of bytes to read
|
|
||||||
///
|
|
||||||
/// \return The number of bytes actually read, or -1 on error
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual Int64 read(void* data, Int64 size) = 0;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Change the current reading position
|
|
||||||
///
|
|
||||||
/// \param position The position to seek to, from the beginning
|
|
||||||
///
|
|
||||||
/// \return The position actually sought to, or -1 on error
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual Int64 seek(Int64 position) = 0;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the current reading position in the stream
|
|
||||||
///
|
|
||||||
/// \return The current position, or -1 on error.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual Int64 tell() = 0;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Return the size of the stream
|
|
||||||
///
|
|
||||||
/// \return The total number of bytes available in the stream, or -1 on error
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual Int64 getSize() = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_INPUTSTREAM_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::InputStream
|
|
||||||
/// \ingroup system
|
|
||||||
///
|
|
||||||
/// This class allows users to define their own file input sources
|
|
||||||
/// from which SFML can load resources.
|
|
||||||
///
|
|
||||||
/// SFML resource classes like sf::Texture and
|
|
||||||
/// sf::SoundBuffer provide loadFromFile and loadFromMemory functions,
|
|
||||||
/// which read data from conventional sources. However, if you
|
|
||||||
/// have data coming from a different source (over a network,
|
|
||||||
/// embedded, encrypted, compressed, etc) you can derive your
|
|
||||||
/// own class from sf::InputStream and load SFML resources with
|
|
||||||
/// their loadFromStream function.
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// // custom stream class that reads from inside a zip file
|
|
||||||
/// class ZipStream : public sf::InputStream
|
|
||||||
/// {
|
|
||||||
/// public:
|
|
||||||
///
|
|
||||||
/// ZipStream(std::string archive);
|
|
||||||
///
|
|
||||||
/// bool open(std::string filename);
|
|
||||||
///
|
|
||||||
/// Int64 read(void* data, Int64 size);
|
|
||||||
///
|
|
||||||
/// Int64 seek(Int64 position);
|
|
||||||
///
|
|
||||||
/// Int64 tell();
|
|
||||||
///
|
|
||||||
/// Int64 getSize();
|
|
||||||
///
|
|
||||||
/// private:
|
|
||||||
///
|
|
||||||
/// ...
|
|
||||||
/// };
|
|
||||||
///
|
|
||||||
/// // now you can load textures...
|
|
||||||
/// sf::Texture texture;
|
|
||||||
/// ZipStream stream("resources.zip");
|
|
||||||
/// stream.open("images/img.png");
|
|
||||||
/// texture.loadFromStream(stream);
|
|
||||||
///
|
|
||||||
/// // musics...
|
|
||||||
/// sf::Music music;
|
|
||||||
/// ZipStream stream("resources.zip");
|
|
||||||
/// stream.open("musics/msc.ogg");
|
|
||||||
/// music.openFromStream(stream);
|
|
||||||
///
|
|
||||||
/// // etc.
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,139 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_LOCK_HPP
|
|
||||||
#define SFML_LOCK_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/System/Export.hpp>
|
|
||||||
#include <SFML/System/NonCopyable.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
class Mutex;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Automatic wrapper for locking and unlocking mutexes
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_SYSTEM_API Lock : NonCopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Construct the lock with a target mutex
|
|
||||||
///
|
|
||||||
/// The mutex passed to sf::Lock is automatically locked.
|
|
||||||
///
|
|
||||||
/// \param mutex Mutex to lock
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
explicit Lock(Mutex& mutex);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Destructor
|
|
||||||
///
|
|
||||||
/// The destructor of sf::Lock automatically unlocks its mutex.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
~Lock();
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Mutex& m_mutex; ///< Mutex to lock / unlock
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_LOCK_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::Lock
|
|
||||||
/// \ingroup system
|
|
||||||
///
|
|
||||||
/// sf::Lock is a RAII wrapper for sf::Mutex. By unlocking
|
|
||||||
/// it in its destructor, it ensures that the mutex will
|
|
||||||
/// always be released when the current scope (most likely
|
|
||||||
/// a function) ends.
|
|
||||||
/// This is even more important when an exception or an early
|
|
||||||
/// return statement can interrupt the execution flow of the
|
|
||||||
/// function.
|
|
||||||
///
|
|
||||||
/// For maximum robustness, sf::Lock should always be used
|
|
||||||
/// to lock/unlock a mutex.
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// sf::Mutex mutex;
|
|
||||||
///
|
|
||||||
/// void function()
|
|
||||||
/// {
|
|
||||||
/// sf::Lock lock(mutex); // mutex is now locked
|
|
||||||
///
|
|
||||||
/// functionThatMayThrowAnException(); // mutex is unlocked if this function throws
|
|
||||||
///
|
|
||||||
/// if (someCondition)
|
|
||||||
/// return; // mutex is unlocked
|
|
||||||
///
|
|
||||||
/// } // mutex is unlocked
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// Because the mutex is not explicitly unlocked in the code,
|
|
||||||
/// it may remain locked longer than needed. If the region
|
|
||||||
/// of the code that needs to be protected by the mutex is
|
|
||||||
/// not the entire function, a good practice is to create a
|
|
||||||
/// smaller, inner scope so that the lock is limited to this
|
|
||||||
/// part of the code.
|
|
||||||
///
|
|
||||||
/// \code
|
|
||||||
/// sf::Mutex mutex;
|
|
||||||
///
|
|
||||||
/// void function()
|
|
||||||
/// {
|
|
||||||
/// {
|
|
||||||
/// sf::Lock lock(mutex);
|
|
||||||
/// codeThatRequiresProtection();
|
|
||||||
///
|
|
||||||
/// } // mutex is unlocked here
|
|
||||||
///
|
|
||||||
/// codeThatDoesntCareAboutTheMutex();
|
|
||||||
/// }
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// Having a mutex locked longer than required is a bad practice
|
|
||||||
/// which can lead to bad performances. Don't forget that when
|
|
||||||
/// a mutex is locked, other threads may be waiting doing nothing
|
|
||||||
/// until it is released.
|
|
||||||
///
|
|
||||||
/// \see sf::Mutex
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,148 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_MEMORYINPUTSTREAM_HPP
|
|
||||||
#define SFML_MEMORYINPUTSTREAM_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Config.hpp>
|
|
||||||
#include <SFML/System/InputStream.hpp>
|
|
||||||
#include <SFML/System/Export.hpp>
|
|
||||||
#include <cstdlib>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Implementation of input stream based on a memory chunk
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_SYSTEM_API MemoryInputStream : public InputStream
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
MemoryInputStream();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Open the stream from its data
|
|
||||||
///
|
|
||||||
/// \param data Pointer to the data in memory
|
|
||||||
/// \param sizeInBytes Size of the data, in bytes
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void open(const void* data, std::size_t sizeInBytes);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Read data from the stream
|
|
||||||
///
|
|
||||||
/// After reading, the stream's reading position must be
|
|
||||||
/// advanced by the amount of bytes read.
|
|
||||||
///
|
|
||||||
/// \param data Buffer where to copy the read data
|
|
||||||
/// \param size Desired number of bytes to read
|
|
||||||
///
|
|
||||||
/// \return The number of bytes actually read, or -1 on error
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual Int64 read(void* data, Int64 size);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Change the current reading position
|
|
||||||
///
|
|
||||||
/// \param position The position to seek to, from the beginning
|
|
||||||
///
|
|
||||||
/// \return The position actually sought to, or -1 on error
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual Int64 seek(Int64 position);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the current reading position in the stream
|
|
||||||
///
|
|
||||||
/// \return The current position, or -1 on error.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual Int64 tell();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Return the size of the stream
|
|
||||||
///
|
|
||||||
/// \return The total number of bytes available in the stream, or -1 on error
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
virtual Int64 getSize();
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const char* m_data; ///< Pointer to the data in memory
|
|
||||||
Int64 m_size; ///< Total size of the data
|
|
||||||
Int64 m_offset; ///< Current reading position
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_MEMORYINPUTSTREAM_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class MemoryeInputStream
|
|
||||||
/// \ingroup system
|
|
||||||
///
|
|
||||||
/// This class is a specialization of InputStream that
|
|
||||||
/// reads from data in memory.
|
|
||||||
///
|
|
||||||
/// It wraps a memory chunk in the common InputStream interface
|
|
||||||
/// and therefore allows to use generic classes or functions
|
|
||||||
/// that accept such a stream, with content already loaded in memory.
|
|
||||||
///
|
|
||||||
/// In addition to the virtual functions inherited from
|
|
||||||
/// InputStream, MemoryInputStream adds a function to
|
|
||||||
/// specify the pointer and size of the data in memory.
|
|
||||||
///
|
|
||||||
/// SFML resource classes can usually be loaded directly from
|
|
||||||
/// memory, so this class shouldn't be useful to you unless
|
|
||||||
/// you create your own algorithms that operate on a InputStream.
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// void process(InputStream& stream);
|
|
||||||
///
|
|
||||||
/// MemoryStream stream;
|
|
||||||
/// stream.open(thePtr, theSize);
|
|
||||||
/// process(stream);
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// InputStream, FileStream
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,148 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_MUTEX_HPP
|
|
||||||
#define SFML_MUTEX_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/System/Export.hpp>
|
|
||||||
#include <SFML/System/NonCopyable.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
namespace priv
|
|
||||||
{
|
|
||||||
class MutexImpl;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Blocks concurrent access to shared resources
|
|
||||||
/// from multiple threads
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_SYSTEM_API Mutex : NonCopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Mutex();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Destructor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
~Mutex();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Lock the mutex
|
|
||||||
///
|
|
||||||
/// If the mutex is already locked in another thread,
|
|
||||||
/// this call will block the execution until the mutex
|
|
||||||
/// is released.
|
|
||||||
///
|
|
||||||
/// \see unlock
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void lock();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Unlock the mutex
|
|
||||||
///
|
|
||||||
/// \see lock
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void unlock();
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
priv::MutexImpl* m_mutexImpl; ///< OS-specific implementation
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_MUTEX_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::Mutex
|
|
||||||
/// \ingroup system
|
|
||||||
///
|
|
||||||
/// Mutex stands for "MUTual EXclusion". A mutex is a
|
|
||||||
/// synchronization object, used when multiple threads are involved.
|
|
||||||
///
|
|
||||||
/// When you want to protect a part of the code from being accessed
|
|
||||||
/// simultaneously by multiple threads, you typically use a
|
|
||||||
/// mutex. When a thread is locked by a mutex, any other thread
|
|
||||||
/// trying to lock it will be blocked until the mutex is released
|
|
||||||
/// by the thread that locked it. This way, you can allow only
|
|
||||||
/// one thread at a time to access a critical region of your code.
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// Database database; // this is a critical resource that needs some protection
|
|
||||||
/// sf::Mutex mutex;
|
|
||||||
///
|
|
||||||
/// void thread1()
|
|
||||||
/// {
|
|
||||||
/// mutex.lock(); // this call will block the thread if the mutex is already locked by thread2
|
|
||||||
/// database.write(...);
|
|
||||||
/// mutex.unlock(); // if thread2 was waiting, it will now be unblocked
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// void thread2()
|
|
||||||
/// {
|
|
||||||
/// mutex.lock(); // this call will block the thread if the mutex is already locked by thread1
|
|
||||||
/// database.write(...);
|
|
||||||
/// mutex.unlock(); // if thread1 was waiting, it will now be unblocked
|
|
||||||
/// }
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// Be very careful with mutexes. A bad usage can lead to bad problems,
|
|
||||||
/// like deadlocks (two threads are waiting for each other and the
|
|
||||||
/// application is globally stuck).
|
|
||||||
///
|
|
||||||
/// To make the usage of mutexes more robust, particularly in
|
|
||||||
/// environments where exceptions can be thrown, you should
|
|
||||||
/// use the helper class sf::Lock to lock/unlock mutexes.
|
|
||||||
///
|
|
||||||
/// SFML mutexes are recursive, which means that you can lock
|
|
||||||
/// a mutex multiple times in the same thread without creating
|
|
||||||
/// a deadlock. In this case, the first call to lock() behaves
|
|
||||||
/// as usual, and the following ones have no effect.
|
|
||||||
/// However, you must call unlock() exactly as many times as you
|
|
||||||
/// called lock(). If you don't, the mutex won't be released.
|
|
||||||
///
|
|
||||||
/// \see sf::Lock
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
@ -1,119 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_NONCOPYABLE_HPP
|
|
||||||
#define SFML_NONCOPYABLE_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/System/Export.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Utility class that makes any derived
|
|
||||||
/// class non-copyable
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class SFML_SYSTEM_API NonCopyable
|
|
||||||
{
|
|
||||||
protected:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
/// Because this class has a copy constructor, the compiler
|
|
||||||
/// will not automatically generate the default constructor.
|
|
||||||
/// That's why we must define it explicitly.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
NonCopyable() {}
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Disabled copy constructor
|
|
||||||
///
|
|
||||||
/// By making the copy constructor private, the compiler will
|
|
||||||
/// trigger an error if anyone outside tries to use it.
|
|
||||||
/// To prevent NonCopyable or friend classes from using it,
|
|
||||||
/// we also give no definition, so that the linker will
|
|
||||||
/// produce an error if the first protection was inefficient.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
NonCopyable(const NonCopyable&);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Disabled assignment operator
|
|
||||||
///
|
|
||||||
/// By making the assignment operator private, the compiler will
|
|
||||||
/// trigger an error if anyone outside tries to use it.
|
|
||||||
/// To prevent NonCopyable or friend classes from using it,
|
|
||||||
/// we also give no definition, so that the linker will
|
|
||||||
/// produce an error if the first protection was inefficient.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
NonCopyable& operator =(const NonCopyable&);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_NONCOPYABLE_HPP
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \class sf::NonCopyable
|
|
||||||
/// \ingroup system
|
|
||||||
///
|
|
||||||
/// This class makes its instances non-copyable, by explicitly
|
|
||||||
/// disabling its copy constructor and its assignment operator.
|
|
||||||
///
|
|
||||||
/// To create a non-copyable class, simply inherit from
|
|
||||||
/// sf::NonCopyable.
|
|
||||||
///
|
|
||||||
/// The type of inheritance (public or private) doesn't matter,
|
|
||||||
/// the copy constructor and assignment operator are declared private
|
|
||||||
/// in sf::NonCopyable so they will end up being inaccessible in both
|
|
||||||
/// cases. Thus you can use a shorter syntax for inheriting from it
|
|
||||||
/// (see below).
|
|
||||||
///
|
|
||||||
/// Usage example:
|
|
||||||
/// \code
|
|
||||||
/// class MyNonCopyableClass : sf::NonCopyable
|
|
||||||
/// {
|
|
||||||
/// ...
|
|
||||||
/// };
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// Deciding whether the instances of a class can be copied
|
|
||||||
/// or not is a very important design choice. You are strongly
|
|
||||||
/// encouraged to think about it before writing a class,
|
|
||||||
/// and to use sf::NonCopyable when necessary to prevent
|
|
||||||
/// many potential future errors when using it. This is also
|
|
||||||
/// a very important indication to users of your class.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user