PageRenderTime 30ms CodeModel.GetById 22ms app.highlight 7ms RepoModel.GetById 0ms app.codeStats 0ms

/src/gui/C4GameMessage.h

https://bitbucket.org/randrian/openclonk2
C Header | 130 lines | 93 code | 16 blank | 21 comment | 0 complexity | fb888524b96e1c73e2fde4bdc3787ff3 MD5 | raw file
Possible License(s): WTFPL, 0BSD, LGPL-2.1, CC-BY-3.0
  1/*
  2 * OpenClonk, http://www.openclonk.org
  3 *
  4 * Copyright (c) 1998-2000  Matthes Bender
  5 * Copyright (c) 2001, 2005, 2008  Sven Eberhardt
  6 * Copyright (c) 2001  Michael K?ser
  7 * Copyright (c) 2004  G?nther Brammer
  8 * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de
  9 *
 10 * Portions might be copyrighted by other authors who have contributed
 11 * to OpenClonk.
 12 *
 13 * Permission to use, copy, modify, and/or distribute this software for any
 14 * purpose with or without fee is hereby granted, provided that the above
 15 * copyright notice and this permission notice appear in all copies.
 16 * See isc_license.txt for full license and disclaimer.
 17 *
 18 * "Clonk" is a registered trademark of Matthes Bender.
 19 * See clonk_trademark_license.txt for full license.
 20 */
 21
 22/* Text messages drawn inside the viewport */
 23
 24#ifndef INC_C4GameMessage
 25#define INC_C4GameMessage
 26
 27#include <C4Surface.h>
 28#include <C4Gui.h>
 29
 30const int32_t C4GM_MaxText = 256,
 31          C4GM_MinDelay = 20;
 32
 33const int32_t C4GM_Global				=  1,
 34              C4GM_GlobalPlayer =  2,
 35              C4GM_Target       =  3,
 36              C4GM_TargetPlayer =  4;
 37
 38const int32_t C4GM_NoBreak = 1<<0,
 39              C4GM_Bottom  = 1<<1, // message placed at bottom of screen
 40              C4GM_Multiple= 1<<2,
 41              C4GM_Top     = 1<<3,
 42              C4GM_Left    = 1<<4,
 43              C4GM_Right   = 1<<5,
 44              C4GM_HCenter = 1<<6,
 45              C4GM_VCenter = 1<<7,
 46              C4GM_DropSpeech = 1<<8, // cut any text after '$'
 47              C4GM_WidthRel = 1<<9,
 48              C4GM_XRel     = 1<<10,
 49              C4GM_YRel     = 1<<11;
 50
 51const int32_t C4GM_PositioningFlags = C4GM_Bottom | C4GM_Top | C4GM_Left | C4GM_Right | C4GM_HCenter | C4GM_VCenter;
 52
 53class C4GameMessage
 54	{
 55	friend class C4GameMessageList;
 56	public:
 57		void Draw(C4TargetFacet &cgo, int32_t iPlayer, float Zoom);
 58		C4GameMessage();
 59		~C4GameMessage();
 60	protected:
 61		int32_t X,Y,Wdt;
 62		int32_t Delay;
 63		DWORD ColorDw;
 64		int32_t Player;
 65		int32_t Type;
 66		C4Object *Target;
 67		StdCopyStrBuf Text;
 68		C4GameMessage *Next;
 69		C4ID DecoID; StdStrBuf PortraitDef;
 70		C4GUI::FrameDecoration *pFrameDeco;
 71    uint32_t dwFlags;
 72	protected:
 73		void Init(int32_t iType, const StdStrBuf & Text, C4Object *pTarget, int32_t iPlayer, int32_t iX, int32_t iY, uint32_t dwCol, C4ID idDecoID, const char *szPortraitDef, uint32_t dwFlags, int width);
 74		void Append(const char *szText, bool fNoDuplicates = false);
 75		bool Execute();
 76    const char *WordWrap(int32_t iMaxWidth);
 77		void UpdateDef(C4ID idUpdDef);
 78
 79	public:
 80		int32_t GetPositioningFlags() const { return dwFlags & C4GM_PositioningFlags; }
 81	};
 82
 83class C4GameMessageList
 84	{
 85	public:
 86		C4GameMessageList();
 87		~C4GameMessageList();
 88	protected:
 89		C4GameMessage *First;
 90	public:
 91		void Default();
 92		void Clear();
 93		void Execute();
 94		void Draw(C4TargetFacet &cgo, int32_t iPlayer, float Zoom);
 95		void ClearPlayers(int32_t iPlayer, int32_t dwPositioningFlags);
 96		void ClearPointers(C4Object *pObj);
 97		void UpdateDef(C4ID idUpdDef); // called after reloaddef
 98		bool New(int32_t iType, const StdStrBuf & Text, C4Object *pTarget, int32_t iPlayer, int32_t iX = -1, int32_t iY = -1, uint32_t dwClr = 0xffFFFFFF, C4ID idDecoID=C4ID_None, const char *szPortraitDef=NULL, uint32_t dwFlags=0u, int32_t width=0);
 99		bool New(int32_t iType, const char *szText, C4Object *pTarget, int32_t iPlayer, int32_t iX, int32_t iY, uint8_t bCol);
100		bool New(int32_t iType, const char *szText, C4Object *pTarget, int32_t iPlayer, int32_t iX, int32_t iY, uint32_t dwClr, C4ID idDecoID=C4ID_None, const char *szPortraitDef=NULL, uint32_t dwFlags=0u, int32_t width=0);
101		bool Append(int32_t iType, const char *szText, C4Object *pTarget, int32_t iPlayer, int32_t iX, int32_t iY, uint8_t bCol, bool fNoDuplicates = false);
102	};
103
104extern C4GameMessageList Messages;
105
106inline void GameMsgObject(const char *szText, C4Object *pTarget, int32_t iFCol=FWhite)
107	{
108	::Messages.New(C4GM_Target,szText,pTarget,NO_OWNER,0,0,(uint8_t) iFCol);
109	}
110
111inline void GameMsgObjectPlayer(const char *szText, C4Object *pTarget, int32_t iPlayer, int32_t iFCol=FWhite)
112	{
113	::Messages.New(C4GM_TargetPlayer,szText,pTarget,iPlayer,0,0,(uint8_t) iFCol);
114	}
115
116inline void GameMsgGlobal(const char *szText, int32_t iFCol=FWhite)
117	{
118	::Messages.New(C4GM_Global,szText,NULL,ANY_OWNER,0,0,(uint8_t) iFCol);
119	}
120
121inline void GameMsgPlayer(const char *szText, int32_t iPlayer, int32_t iFCol=FWhite)
122	{
123	::Messages.New(C4GM_GlobalPlayer,szText,NULL,iPlayer,0,0,(uint8_t) iFCol);
124	}
125
126inline void GameMsgObjectDw(const char *szText, C4Object *pTarget, uint32_t dwClr)
127	{
128	::Messages.New(C4GM_Target,szText,pTarget,NO_OWNER,0,0,dwClr);
129	}
130#endif