⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 surface.h

📁 这是一款2d游戏引擎
💻 H
字号:
/*  $Id: surface.h,v 1.48 2004/01/02 15:42:43 mbn Exp $
**
**  ClanLib Game SDK
**  Copyright (C) 2003  The ClanLib Team
**  For a total list of contributers see the file CREDITS.
**
**  This library is free software; you can redistribute it and/or
**  modify it under the terms of the GNU Lesser General Public
**  License as published by the Free Software Foundation; either
**  version 2.1 of the License, or (at your option) any later version.
**
**  This library is distributed in the hope that it will be useful,
**  but WITHOUT ANY WARRANTY; without even the implied warranty of
**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
**  Lesser General Public License for more details.
**
**  You should have received a copy of the GNU Lesser General Public
**  License along with this library; if not, write to the Free Software
**  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
**
*/

//! clanDisplay="Display 2D"
//! header=display.h

#ifndef header_surface
#define header_surface

#if _MSC_VER > 1000
#pragma once
#endif

#ifdef _MSC_VER
#pragma warning( disable : 4786)
#endif

#include "blend_func.h"
#include "../Core/Math/origin.h"
#include "color.h"
#include <string>

#include "../Core/Resources/resource.h"

class CL_PixelBuffer;
class CL_GraphicContext;
class CL_Point;
class CL_Rect;
class CL_ResourceManager;
class CL_Sprite;
class CL_Surface_Generic;

//: Construct hardware accelerated (where available) 2D surface.
//- !group=Display/Display 2D!
//- !header=display.h!
// TODO: Add flip_vertical, flip_horizontal ?
class CL_Surface
{
//! Enums:
public:
	enum Hint
	{
		//: surface class will try to automatically determine what type it is
		hint_automatic,

		//: surface only contain opaque data (no transparency)
		hint_opaque,
		
		//: surface only has colorkey alpha (transparency)
		hint_colorkey,
		
		//: surface with full alpha support (translucency)
		hint_alpha
	};

//! Construction:
public:
	// TODO: Add some hint to specify 16 or 32 bit surface.
	// TODO: Add some hint to specify mipmapping or not.

	//: Constructs a surface.
	//param provider: Image that surface will use.
	//param delete_provider: If true, will delete provider after it has copied its image data.
	//param hint: Hints what sort of optimizations CL_Surface can perform to increase rendering performance.
	//param filename: Name of an image file to load image data from.
	CL_Surface();

	CL_Surface(
		CL_PixelBuffer *provider,
		bool delete_provider = false,
		Hint hint = hint_automatic);

	CL_Surface(
		const std::string &resource_id,
		CL_ResourceManager *manager);

	CL_Surface(const std::string &filename, Hint hint = hint_automatic);

	CL_Surface(const CL_Surface &copy);

	virtual ~CL_Surface();

//! Attributes:
public:
	//: Returns the width.
	int get_width() const;
	
	//: Returns the height.
	int get_height() const;
	
	//: Returns current angle in degrees.
	float get_angle() const;

	//: Returns scale for x and y.
	//- <p> 1.0f is normal scale, 2.0f is twice the size, etc. </p>
	void get_scale(float &x, float &y) const;

	//: Returns current alpha.
	//- <p> Alpha 0.0f is full transparency, and 1.0f is full visibility (solid). </p>
	float get_alpha() const;

	//: Returns current color.
	//- <p> Alpha 0.0f is full transparency, and 1.0f is full visibility (solid). </p>
	void get_color(float &red, float &green, float &blue, float &alpha) const;
	CL_Color get_color() const {float r,g,b,a; get_color(r,g,b,a); return CL_Color(int(r*255.0f),int(g*255.0f),int(b*255.0f),int(a*255.0f));}
	
	//: Returns blending functions.
	void get_blend_func(CL_BlendFunc &src, CL_BlendFunc &dest) const;

	//: Returns translation hotspot.
	void get_alignment(CL_Origin &origin, int &x, int &y) const;

	//: Returns rotation hotspot.
	void get_rotation_hotspot(CL_Origin &origin, int &x, int &y) const;
	
	//: Returns a pixelbuffer object for accessing surface data.
	CL_PixelBuffer get_pixeldata();
	
	//: Returns a graphic context object for rendering to this surface.
	CL_GraphicContext *get_gc();

	//: Resource owning this surface, if any.
	CL_Resource resource;

//! Operations:
public:
	//: Copy assignment operator.
	CL_Surface &operator =(const CL_Surface &copy);

	//: Return true if the CL_Sprite is valid and useable
	operator bool () const;

	//: Uploads pixel data to surface.
	//!param pos, x, y: Position on surface where pixel data should be put.
	//!param src_rect: Part of pixelbuffer that should be uploaded.
	//!param pixeldata: CL_PixelBuffer containing the image to be uploaded.
	void set_pixeldata(CL_PixelBuffer &pixeldata);
	
	void set_pixeldata(int x, int y, CL_PixelBuffer &pixeldata);
	
	void set_pixeldata(const CL_Point &pos, CL_PixelBuffer &pixeldata);
	
	void set_pixeldata(const CL_Point &pos, const CL_Rect &src_rect, CL_PixelBuffer &pixeldata);

	//: Draw surface on graphic context.
	//param x, y: Anchor position of where to render surface. Actual rendering position depends on the anchor and the alignment mode.
	//param gc: Graphic context on which to render upon. If null, will use CL_Display's current graphic context.
	//param dest: Rectangle to draw surface in.
	//param src: Rectangle specifying the sub section of a surface to render.
	void draw(
		int x = 0,
		int y = 0,
		CL_GraphicContext *context = 0);

	void draw(
		const CL_Rect &dest,
		CL_GraphicContext *context = 0);

	void draw(
		const CL_Rect &src,
		const CL_Rect &dest,
		CL_GraphicContext *context = 0);

	//: Set absolute rotation angle in degrees.
	void set_angle(float angle);

	//: Add angle in degrees to current angle.
	void rotate(float angle);

	//: Set scale for x and y directions individually.
	//- <p> 1.0f is normal scale, 2.0f is twice the size, etc. </p>
	void set_scale(float x, float y);

	//: Sets transparency.
	//- <p> Alpha 0.0f is full transparency, and 1.0f is full visibility (solid). </p>
	void set_alpha(float alpha);

	//: Sets the color.
	//- <p> Alpha 0.0f is full transparency, and 1.0f is full visibility (solid). </p>
	void set_color(float r, float g, float b, float a = 1.0f);
	void set_color(const CL_Color& c) {set_color(float(c.get_red())/255.0f,float(c.get_green())/255.0f,float(c.get_blue())/255.0f,float(c.get_alpha())/255.0f);}
	
	//: Sets blending functions.
	void set_blend_func(CL_BlendFunc src, CL_BlendFunc dest);

	//: Sets translation hotspot.
	void set_alignment(CL_Origin origin, int x = 0, int y = 0);

	//: Sets rotation hotspot.
	void set_rotation_hotspot(CL_Origin origin, int x = 0, int y = 0);

// Implementation:
protected:
	CL_Surface_Generic *impl;

	friend class CL_Sprite;
};

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -