Przeglądaj źródła

We don't need anymore the loader folder nor the loader classes

Daniele Bartolini 13 lat temu
rodzic
commit
b7bff99d4f

+ 0 - 1
CMakeLists.txt

@@ -22,7 +22,6 @@ set (INCLUDES
 	${CMAKE_SOURCE_DIR}/src/os
 	${CMAKE_SOURCE_DIR}/src/os/linux
 	${CMAKE_SOURCE_DIR}/src/input
-	${CMAKE_SOURCE_DIR}/src/loaders
 	${CMAKE_SOURCE_DIR}/src/renderers
 	${CMAKE_SOURCE_DIR}/src/renderers/gl
 	${CMAKE_SOURCE_DIR}/src/renderers/gles

+ 0 - 9
src/CMakeLists.txt

@@ -40,7 +40,6 @@ set (HEADERS
 	Material.h
 	MeshChunk.h
 	Mesh.h
-	MeshLoader.h
 	MovableCamera.h
 	OcclusionQuery.h
 	Pixel.h
@@ -186,12 +185,6 @@ set (INPUT_HEADERS
 	input/Touch.h
 )
 
-set (LOADERS_SRC
-)
-
-set (LOADERS_HEADERS
-)
-
 set (GL_SRC
 	renderers/gl/GLIndexBuffer.cpp
 	renderers/gl/GLOcclusionQuery.cpp
@@ -271,8 +264,6 @@ set (SOURCES
 	${COMPRESSORS_HEADERS}
 	${INPUT_SRC}
 	${INPUT_HEADERS}
-	${LOADERS_SRC}
-	${LOADERS_HEADERS}
 
 	${OS_SRC}
 	${OS_HEADERS}

+ 0 - 4
src/Crown.h

@@ -87,7 +87,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Material.h"
 #include "Mesh.h"
 #include "MeshChunk.h"
-#include "MeshLoader.h"
 #include "MovableCamera.h"
 #include "OcclusionQuery.h"
 #include "Pixel.h"
@@ -100,9 +99,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 // Engine/Filesystem
 #include "Filesystem.h"
 
-// Engine/Loaders
-//#include "XWMLReader.h"
-
 // Engine/Input
 #include "EventDispatcher.h"
 #include "InputManager.h"

+ 0 - 51
src/MeshLoader.h

@@ -1,51 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "Types.h"
-
-namespace crown
-{
-
-class Mesh;
-
-class MeshLoader
-{
-
-public:
-
-	//! Constructor
-	MeshLoader() {}
-
-	//! Destructor
-	virtual ~MeshLoader() {}
-
-	//! Loads a mesh from a file
-	virtual Mesh* LoadFile(const char* name) = 0;
-};
-
-} // namespace crown
-

+ 0 - 289
src/loaders/BMPImageLoader.cpp

@@ -1,289 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include <cstdio>
-#include "Image.h"
-#include "Log.h"
-#include "Types.h"
-#include "Str.h"
-#include "BMPImageLoader.h"
-#include "Device.h"
-#include "Exceptions.h"
-#include "Filesystem.h"
-
-namespace crown
-{
-
-#pragma pack(2)
-
-struct BitmapInfoHeader
-{
-	uint32_t biSize;
-	int32_t  biWidth;
-	int32_t  biHeight;
-	uint16_t biPlanes;
-	uint16_t biBitCount;
-	uint32_t biCompression;
-	uint32_t biSizeImage;
-	int32_t  biXPelsPerMeter;
-	int32_t  biYPelsPerMeter;
-	uint32_t biClrUsed;
-	uint32_t biClrImportant;
-};
-
-struct BitmapFileHeader
-{
-	uint16_t bfType;
-	uint32_t bfSize;
-	uint16_t bfReserved1;
-	uint16_t bfReserved2;
-	uint32_t bfOffBits;
-};
-
-#pragma pack()
-
-BMPImageLoader::BMPImageLoader()
-{
-}
-
-BMPImageLoader::~BMPImageLoader()
-{
-}
-
-Image* BMPImageLoader::LoadFile(const char* relativePath)
-{
-	Image* image = NULL;
-	Stream* fileStream;
-
-	BitmapFileHeader bfh;
-	BitmapInfoHeader bih;
-	int32_t magicNumber = 0;
-	int32_t padSize = 0;
-	int32_t dataSize = 0;
-	uint8_t* data = NULL;
-	uint8_t* tmpdata = NULL;
-	//<fp = fopen(name, "rb");
-	fileStream = GetFilesystem()->OpenStream(relativePath, SOM_READ);
-
-	if (fileStream == NULL)
-	{
-		return NULL;
-	}
-
-	fileStream->read(&magicNumber, 2);
-
-	if (magicNumber != 19778)
-	{
-		Str msg = Str("BMPImageLoader::LoadFile: file '") + Str(relativePath) + Str("' is not a valid bitmap file.");
-		Log::E(msg.c_str());
-		//throw ArgumentException(msg.c_str());
-		return NULL;
-	}
-
-	fileStream->seek(0);
-	fileStream->read(&bfh, sizeof(BitmapFileHeader));
-	fileStream->read(&bih, sizeof(BitmapInfoHeader));
-
-	int32_t bpp = (bih.biBitCount/8);
-
-	if (bpp != 3 && bpp != 4)
-	{
-		Str msg = "BMPImageLoader::LoadFile: Only 24bit and 32bit bitmaps are supported.";
-		Log::E(msg.c_str());
-		//throw ArgumentException(msg.c_str());
-		throw (void*)NULL;
-	}
-
-	padSize = 0;
-
-	while (((bih.biWidth*3+padSize) % 4) != 0)
-	{
-		padSize++;
-	}
-
-	dataSize = bih.biWidth * bih.biHeight * 4;
-	data = new uint8_t[dataSize];
-
-	if (bpp == 3)
-	{
-		tmpdata = new uint8_t[bih.biWidth*3];
-
-		for (int32_t i=0; i<bih.biHeight ; i++)
-		{
-			fileStream->read(tmpdata, bih.biWidth*3);
-
-			int32_t offset = bih.biWidth * 4 * i;
-
-			for (int32_t j=0; j<bih.biWidth; j++)
-			{
-				data[offset++] = tmpdata[j*3+2];
-				data[offset++] = tmpdata[j*3+1];
-				data[offset++] = tmpdata[j*3+0];
-				data[offset++] = 255;
-			}
-
-			if (padSize)
-			{
-				fileStream->skip(padSize);
-			}
-		}
-
-		delete[] tmpdata;
-	}
-	else
-	{
-		for (int32_t i=0; i<bih.biHeight ; i++)
-		{
-			int32_t offset = bih.biWidth * 4 * i;
-
-			fileStream->read(&data[offset], bih.biWidth*4);
-
-			if (padSize)
-			{
-				fileStream->skip(padSize);
-			}
-		}
-	}
-
-	GetFilesystem()->Close(fileStream);
-
-	image = new Image(PF_RGBA_8, bih.biWidth, bih.biHeight, data);
-	return image;
-}
-
-void BMPImageLoader::SaveFile(const Image* image, const char* relativePath)
-{
-	FILE* fp = NULL;
-
-	try
-	{
-		BitmapFileHeader bfh;
-		BitmapInfoHeader bih;
-		int32_t padSize = 0;
-		int32_t imgDataSize = 0;
-		int32_t bmpDataSize;
-		const uint8_t* imgData = NULL;
-		uint8_t* bmpRow = NULL;
-
-		PixelFormat format = image->GetFormat();
-		if (format != PF_LA_8 && format != PF_RGB_8 && format != PF_RGBA_8)
-			throw 2;
-
-		fp = fopen(relativePath, "wb");
-
-		if (!fp)
-		{
-			throw 0;
-		}
-
-		while (( (image->GetWidth() * 3 + padSize) % 4) != 0) padSize++;;
-		bmpDataSize = (image->GetWidth() * 3 + padSize) * image->GetHeight();
-
-		bfh.bfType = 19778;
-		bfh.bfSize = sizeof(bfh) + sizeof(bih) + bmpDataSize;
-		bfh.bfOffBits = sizeof(bfh) + sizeof(bih);
-		bfh.bfReserved1 = 0;
-		bfh.bfReserved2 = 0;
-		//compila la bih
-		bih.biSize = sizeof(bih);
-		bih.biWidth = image->GetWidth();
-		bih.biHeight = image->GetHeight();
-		bih.biPlanes = 1;
-		bih.biBitCount = 24;
-		bih.biCompression = 0;
-		bih.biSizeImage = bmpDataSize;
-		bih.biXPelsPerMeter = bih.biYPelsPerMeter = 0; //2835;
-		bih.biClrUsed = 0;
-		bih.biClrImportant = 0;
-
-		fwrite(&bfh, sizeof(bfh), 1, fp);
-		fwrite(&bih, sizeof(bih), 1, fp);
-
-
-		int32_t bpp = image->GetBytesPerPixel();
-
-		imgData = image->GetBuffer();
-		imgDataSize = image->GetWidth() * image->GetHeight() * bpp;
-
-		bmpRow = new uint8_t[bih.biWidth*3];
-
-		for (int32_t i=0; i<bih.biHeight ; i++)
-		{
-			int32_t offset = bih.biWidth * bpp * i;
-
-			for (int32_t j=0; j<bih.biWidth; j++)
-			{
-				if (bpp == 2)
-				{
-					bmpRow[j*3+2] = imgData[offset];
-					bmpRow[j*3+1] = imgData[offset];
-					bmpRow[j*3+0] = imgData[offset];
-					offset += 2;
-				}
-				else
-				{
-					bmpRow[j*3+2] = imgData[offset++];
-					bmpRow[j*3+1] = imgData[offset++];
-					bmpRow[j*3+0] = imgData[offset++];
-					if (bpp == 4)
-						offset++;
-				}
-			}
-
-			if (fwrite(bmpRow, 1, bih.biWidth*3, fp) != (uint32_t)bih.biWidth*3)
-			{
-				throw 1;
-			}
-
-			if (padSize)
-			{
-				fseek(fp, padSize, SEEK_CUR);
-			}
-		}
-
-		delete[] bmpRow;
-	}
-	catch (int32_t err)
-	{
-		switch (err)
-		{
-			case 0:
-				Log::E("File %s can't be opened for writing", relativePath);
-				break;
-			case 1:
-				Log::E("Can't write to file.");
-				break;
-			case 2:
-				Log::E("Only PF_LA_8, PF_RGB_8 and PF_RGBA_8 image formats are supported.");
-				break;
-		}
-	}
-
-	if (fp)
-		fclose(fp);
-}
-
-} // namespace crown
-

+ 0 - 51
src/loaders/BMPImageLoader.h

@@ -1,51 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "Types.h"
-#include "ImageLoader.h"
-
-namespace crown
-{
-
-class Image;
-
-class BMPImageLoader : public ImageLoader
-{
-
-public:
-
-	BMPImageLoader();
-	~BMPImageLoader();
-
-	Image* LoadFile(const char* relativePath);
-	void SaveFile(const Image* img, const char* relativePath);
-
-private:
-};
-
-} // namespace crown
-

+ 0 - 241
src/loaders/TGAImageLoader.cpp

@@ -1,241 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "Image.h"
-#include "Log.h"
-#include "Types.h"
-#include "Str.h"
-#include "TGAImageLoader.h"
-#include "Filesystem.h"
-
-namespace crown
-{
-
-TGAImageLoader::TGAImageLoader()
-{
-}
-
-TGAImageLoader::~TGAImageLoader()
-{
-}
-
-Image* TGAImageLoader::LoadFile(const char* relativePath)
-{
-	Stream* fileStream;
-
-	fileStream = GetFilesystem()->OpenStream(relativePath, SOM_READ);
-
-	if (fileStream == NULL)
-	{
-		return NULL;
-	}
-
-	fileStream->read(&mTGAHeader, sizeof(mTGAHeader));
-	// Skip ID
-	fileStream->skip(mTGAHeader.id_length);
-
-	Image* image = NULL;
-
-	switch (mTGAHeader.image_type)
-	{
-		case 0:
-			Log::E("The file does not contain image data.");
-			return NULL;
-			break;
-		case 2:
-			image = LoadUncompressedData(fileStream);
-			break;
-		case 10:
-			image = LoadCompressedData(fileStream);
-			break;
-		default:
-			Log::E("Data type not supported.");
-			return NULL;
-			break;
-	}
-
-	GetFilesystem()->Close(fileStream);
-
-	return image;
-}
-
-Image* TGAImageLoader::LoadUncompressedData(Stream* fp)
-{
-	Image* image;
-	uint32_t channels = mTGAHeader.pixel_depth / 8;
-	uint64_t size = mTGAHeader.width * mTGAHeader.height;
-	uint8_t* data;
-	PixelFormat format = PF_RGB_8;
-
-	if (mTGAHeader.pixel_depth == 16)
-	{
-		data = new uint8_t[(uint32_t)(size * 3)];
-		int32_t j = 0;
-
-		for (uint64_t i = 0; i < size * channels; i++)
-		{
-			uint16_t pixel_data;
-			fp->read(&pixel_data, sizeof(pixel_data));
-			data[j] = (pixel_data & 0x7c) >> 10;
-			data[j+1] = (pixel_data & 0x3e) >> 5;
-			data[j+2] = (pixel_data & 0x1f);
-			j += 3;
-		}
-	}
-	else
-	{
-		data = new uint8_t[(uint32_t)(size * channels)];
-		fp->read(data, (size_t)(size * channels));
-		SwapRedBlue(data, size * channels, channels);
-	}
-
-	if (channels == 4)
-	{
-		format = PF_RGBA_8;
-	}
-
-	image = new Image(format, mTGAHeader.width, mTGAHeader.height, data);
-	return image;
-}
-
-Image* TGAImageLoader::LoadCompressedData(Stream* fp)
-{
-	Image* image;
-	uint32_t channels = mTGAHeader.pixel_depth/8;
-	uint8_t rle_id = 0;
-	uint32_t i = 0;
-	uint8_t* colors;
-	uint32_t colors_read = 0;
-	uint64_t size = mTGAHeader.width * mTGAHeader.height;
-	uint8_t* data = new uint8_t[(uint32_t)(size * channels)];
-	colors = new uint8_t[channels];
-	PixelFormat format = PF_RGB_8;
-
-	if (channels == 4)
-	{
-		format = PF_RGBA_8;
-	}
-
-	while (i < size)
-	{
-		fp->read(&rle_id, sizeof(uint8_t));
-
-		if (rle_id & 0x80)   // Se il bit più significativo è ad 1
-		{
-			rle_id -= 127;
-			fp->read(colors, channels);
-
-			while (rle_id)
-			{
-				data[colors_read] = colors[2];
-				data[colors_read+1] = colors[1];
-				data[colors_read+2] = colors[0];
-
-				if (channels == 4)
-				{
-					data[colors_read+3] = colors[3];
-				}
-
-				rle_id--;
-				colors_read += channels;
-				i++;
-			}
-		}
-		else     // Altrimenti leggi i colori normalmente
-		{
-			rle_id++;
-
-			while (rle_id)
-			{
-				fp->read(colors, channels);
-				data[colors_read] = colors[2];
-				data[colors_read+1] = colors[1];
-				data[colors_read+2] = colors[0];
-
-				if (channels == 4)
-				{
-					data[colors_read+3] = colors[3];
-				}
-
-				rle_id--;
-				colors_read += channels;
-				i++;
-			}
-		}
-	}
-
-	delete[] colors;
-	image = new Image(format, mTGAHeader.width, mTGAHeader.height, data);
-	return image;
-}
-
-void TGAImageLoader::SwapRedBlue(uint8_t* data, uint64_t size, uint32_t channels)
-{
-	for (uint64_t i = 0; i < size; i += channels)
-	{
-		data[i] ^= data[i+2];
-		data[i+2] ^= data[i];
-		data[i] ^= data[i+2];
-	}
-}
-
-void TGAImageLoader::SaveFile(const Image* image, const char* relativePath)
-{
-	if (image->GetFormat() != PF_RGB_8 || image->GetFormat() != PF_RGBA_8)
-	{
-		Log::E("TGAImageLoader::SaveFile: Only PF_RGB8 and PF_RGBA8 supported");
-		return;
-	}
-
-	TGAHeader_t header;
-
-	header.id_length			= 0;
-	header.color_map_type		= 0;
-	header.image_type			= 2; // Uncompressed RGB
-	header.c_map_spec[0]		= 0;
-	header.c_map_spec[1]		= 0;
-	header.c_map_spec[2]		= 0;
-	header.c_map_spec[3]		= 0;
-	header.c_map_spec[4]		= 0;
-	header.x_offset				= 0;
-	header.y_offset				= 0;
-	header.width				= image->GetWidth();
-	header.height				= image->GetHeight();
-	header.pixel_depth			= image->GetBitsPerPixel();
-	header.image_descriptor		= 0;
-
-	Stream* fileStream = GetFilesystem()->OpenStream(relativePath, SOM_WRITE);
-
-	if (fileStream)
-	{
-		fileStream->write(&header, sizeof(header));
-		fileStream->write(image->GetBuffer(), image->GetWidth() * image->GetHeight() * image->GetBytesPerPixel());
-
-		GetFilesystem()->Close(fileStream);
-	}
-}
-
-} // namespace crown
-

+ 0 - 73
src/loaders/TGAImageLoader.h

@@ -1,73 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "ImageLoader.h"
-#include "Types.h"
-
-namespace crown
-{
-
-class Image;
-class Stream;
-
-class TGAImageLoader : public ImageLoader
-{
-
-	struct TGAHeader_t
-	{
-
-		char id_length;        /* 00h  Size of Image ID field */
-		char color_map_type;   /* 01h  Color map type */
-		char image_type;       /* 02h  Image type code */
-		char c_map_spec[5];    /* 03h  Color map origin 05h Color map length 07h Depth of color map entries */
-		uint16_t x_offset;        /* 08h  X origin of image */
-		uint16_t y_offset;        /* 0Ah  Y origin of image */
-		uint16_t width;           /* 0Ch  Width of image */
-		uint16_t height;          /* 0Eh  Height of image */
-		char pixel_depth;      /* 10h  Image pixel size */
-		char image_descriptor; /* 11h  Image descriptor byte */
-	};
-
-public:
-
-	TGAImageLoader();
-	~TGAImageLoader();
-
-	Image* LoadFile(const char* relativePath);
-	void SaveFile(const Image* image, const char* relativePath);
-
-private:
-
-	Image* LoadUncompressedData(Stream* file);
-	Image* LoadCompressedData(Stream* file);
-	void SwapRedBlue(uint8_t* data, uint64_t size, uint32_t channels);
-
-	TGAHeader_t mTGAHeader;
-};
-
-} // namespace crown
-

+ 0 - 296
src/loaders/XWMLReader.cpp

@@ -1,296 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "XWMLReader.h"
-#include "Log.h"
-#include "Types.h"
-#include "Auto.h"
-#include "StackLayout.h"
-#include "ListView.h"
-#include "TextBox.h"
-#include "Bind.h"
-#include "WindowContext.h"
-#include "TreeView.h"
-#include "ImageWidget.h"
-
-namespace crown
-{
-
-XWMLReader::XWMLReader()
-{
-
-}
-XWMLReader::~XWMLReader()
-{
-
-}
-
-bool XWMLReader::ParseAction(const Str& actionStr, Str& actionName, List<Str>* arguments)
-{
-	//TODO: Should throw
-	if (arguments == NULL)
-		return false;
-
-	//The action is in the form {Action actionName(arg0, arg1, ... , argn)}
-
-	if (!actionStr.StartsWith("{Action ") || !actionStr.EndsWith("}"))
-		return false;
-
-	Str actionStatement = actionStr.GetSubstring(8, actionStr.GetLength() - 1);
-
-	arguments->Clear();
-	int32_t openParenthesisIndex = actionStatement.FindFirst('(');
-	if (openParenthesisIndex != -1)
-	{
-		if (actionStatement[actionStatement.GetLength() - 1] != ')')
-			return false;
-
-		actionName = actionStatement.GetSubstring(0, openParenthesisIndex);
-
-		actionStatement = actionStatement.GetSubstring(openParenthesisIndex + 1, actionStatement.GetLength() - 1);
-		List<Str> args;
-		//TODO: Use something more appropriate than a split to detect commas
-		actionStatement.Split(',', args);
-		
-		for(int32_t i=0; i<args.GetSize(); i++)
-		{
-			int32_t firstQuoteIndex = args[i].FindFirst('\'');
-
-			if (firstQuoteIndex != -1)
-			{
-				int32_t lastQuoteIndex = args[i].FindLast('\'');
-				//In this case, trimming is not necessary because apices wrap the item well
-				arguments->Append(args[i].GetSubstring(firstQuoteIndex + 1, lastQuoteIndex));
-			}
-			else
-			{
-				//Do a Trim to remove prefix and postfix spaces
-				arguments->Append(args[i].Trim());
-			}
-		}
-	}
-	else
-	{
-		actionName = actionStatement;
-	}
-
-	return true;
-}
-
-bool XWMLReader::ParseBind(const Str& bindStr, Str& bindPath, Str& source, Str& converter)
-{
-	//The bind is in the form {Bind bindName} or {Bind bindName,Source=Self}
-
-	if (!bindStr.StartsWith("{Bind ") || !bindStr.EndsWith("}"))
-		return false;
-
-	Str values = bindStr.GetSubstring(6, bindStr.GetLength() - 1);
-
-	List<Str> splits;
-	values.Split(',', splits);
-	
-	bindPath = splits[0];
-	for(int32_t i = 1; i < splits.GetSize(); i++)
-	{
-		List<Str> valueSplits;
-		splits[i].Split('=', valueSplits);
-		if (valueSplits.GetSize() != 2)
-		{
-			Log::E("Invalid format for Bind parameter '" + splits[i] + "'");
-			return false;
-		}
-
-		if (valueSplits[0] == "Source")
-		{
-			source = valueSplits[1];
-		}
-		else if (valueSplits[0] == "Converter")
-		{
-			converter = valueSplits[1];
-		}
-		else
-		{
-			Log::E("Unknown Bind parameter '" + valueSplits[0] + "'");
-			return false;
-		}
-	}
-
-	return true;
-}
-
-Window* XWMLReader::LoadFile(Str filePath, WindowsManager* windowsManager, WindowContext* context)
-{
-	XMLReader xml;
-	if (!xml.LoadFile(filePath))
-		return NULL;
-
-	//Verify that the root is a Window element
-	XMLNode* rootNode = xml.GetRootXMLNode();
-
-	Auto<Window> window = LoadWindow(rootNode, windowsManager);
-
-	//Initialize the context
-	if (context != NULL)
-	{
-		context->SetAssociatedWindow(window.GetPoint32_ter());
-	}
-
-	if (!LoadWidgetPropertiesAndChildren(rootNode, window.GetPoint32_ter()))
-		return NULL;
-
-	//window->ApplyBinds();
-
-	if (context != NULL)
-	{
-		context->OnLoad();
-	}
-
-	return window.GetPoint32_ter(true);
-}
-
-Window* XWMLReader::LoadWindow(XMLNode* node, WindowsManager* windowsManager)
-{
-	if (node->name != "Window")
-	{
-		Log::E("XWMLReader::LoadFile: The root element of a XWML file must be a Window.");
-		return NULL;
-	}
-
-	Window* window = new Window(windowsManager, 180, 150, "Window");
-	return window;
-}
-
-
-Widget* XWMLReader::LoadWidget(XMLNode* node, Widget* parent)
-{
-	Auto<Widget> widget = CreateWidgetByName(node->name, parent);
-
-	if (widget.IsNull())
-	{
-		Log::E("XWMLReader::LoadFile: Undefined widget type '" + node->name + "'");
-		return NULL;
-	}
-
-	if (!LoadWidgetPropertiesAndChildren(node, widget.GetPoint32_ter()))
-		return NULL;
-
-	return widget.GetPoint32_ter(true);
-}
-
-bool XWMLReader::LoadWidgetPropertiesAndChildren(XMLNode* node, Widget* widget)
-{
-	Dictionary<Str, Str>::Enumerator es = node->simpleAttributes.getBegin();
-	while (es.next())
-	{
-		Str bindSourcePath, source, converterName;
-		if (ParseBind(es.current().value, bindSourcePath, source, converterName))
-		{
-			Bind* bind;
-			Converter* converter = NULL;
-			if (converterName != "")
-			{
-				converter = widget->GetWindow()->GetWindowContext()->GetRegisteredConverter(converterName);
-				if (converter == NULL)
-				{
-					Log::E("Converter '" + converterName + "' is not registered in the Window Context");
-				}
-			}
-
-			if (source != "")
-			{
-				if (source == "Self")
-				{
-					bind = new Bind(widget, widget, bindSourcePath, es.current().key, converter);
-				}
-				else if (source == "Parent")
-				{
-					bind = new Bind(widget->GetParent(), widget, bindSourcePath, es.current().key, converter);
-				}
-				else if (source == "LogicalParent")
-				{
-					bind = new Bind(widget->GetLogicalParent(), widget, bindSourcePath, es.current().key, converter);
-				}
-				else if (source == "Widget")
-				{
-					List<Str> splits;
-					bindSourcePath.Split('.', splits);
-					if (splits.GetSize() != 2)
-					{
-						Log::E("Bind Path '" + bindSourcePath + "' is in an invalid format");
-					}
-					bind = new Bind(splits[0], widget, splits[1], es.current().key, converter);
-				}
-				else
-				{
-					Log::E("Bind Source '" + source + "' unrecognized");
-					continue;
-				}
-			}
-			else
-			{
-				bind = new Bind(widget, bindSourcePath, es.current().key, converter);
-			}
-			widget->AddBind(bind);
-		}
-		else
-			widget->SetPropertyValue(es.current().key, es.current().value);
-	}
-
-	Dictionary<Str, XMLNode*>::Enumerator ec = node->complexAttributes.getBegin();
-	while (ec.next())
-	{
-		widget->SetPropertyValue(ec.current().key, ec.current().value);
-	}
-
-	for(int32_t i=0; i<node->children.GetSize(); i++)
-		LoadWidget(node->children[i], widget->GetContentWidget());
-
-	return true;
-}
-
-Widget* XWMLReader::CreateWidgetByName(Str name, Widget* parent)
-{
-	if (name == "Widget")
-		return new Widget(parent);
-	if (name == "Button")
-		return new Button(parent);
-	if (name == "Label")
-		return new Label(parent);
-	if (name == "StackLayout")
-		return new StackLayout(parent);
-	if (name == "ListView")
-		return new ListView(parent);
-	if (name == "TextBox")
-		return new TextBox(parent);
-	if (name == "TreeView")
-		return new TreeView(parent);
-	if (name == "ImageWidget")
-		return new ImageWidget(parent);
-
-	return NULL;
-}
-
-} // namespace crown
-

+ 0 - 56
src/loaders/XWMLReader.h

@@ -1,56 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "Types.h"
-#include "WindowsManager.h"
-#include "XMLReader.h"
-
-namespace crown
-{
-
-class WindowContext;
-
-class XWMLReader
-{
-public:
-  XWMLReader();
-  ~XWMLReader();
-
-  Window* LoadFile(Str filePath, WindowsManager* windowsManager, WindowContext* context);
-	static bool ParseAction(const Str& actionStr, Str& actionName, List<Str>* arguments);
-	static bool ParseBind(const Str& bindStr, Str& bindPath, Str& source, Str& converter);
-
-	static bool LoadWidgetPropertiesAndChildren(XMLNode* node, Widget* widget);
-
-private:
-	static Widget* LoadWidget(XMLNode* node, Widget* parent);
-		static Window* LoadWindow(XMLNode* node, WindowsManager* windowsManager);
-	static Widget* CreateWidgetByName(Str name, Widget* parent);
-};
-
-} // namespace crown
-