File: cswstex.h

package info (click to toggle)
crystalspace 0.94-20020412-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 62,276 kB
  • ctags: 52,843
  • sloc: cpp: 274,783; ansic: 6,608; perl: 6,276; objc: 3,952; asm: 2,942; python: 2,354; php: 542; pascal: 530; sh: 430; makefile: 370; awk: 193
file content (132 lines) | stat: -rw-r--r-- 4,094 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
    Crystal Space Windowing System: Windowing System Texture class
    Copyright (C) 1998,1999 by Andrew Zabolotny <bit@eltech.ru>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 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
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the Free
    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifndef __CSWSTEX_H__
#define __CSWSTEX_H__

#include "csgfx/csimage.h"
#include "csutil/csvector.h"

struct iTextureHandle;
struct iTextureManager;

/**
 * Texture representation within the windowing system.
 * The application keeps an array of such objects, and they are registered
 * with the 3D and 2D drivers as soon as app->RegisterTextures() is called.
 */
class csWSTexture
{
  // Reference count
  int RefCount;
  // texture image
  iImage *Image;
  // Will be this texture used for 3D and/or for 2D operations?
  int Flags;
  // Red,Green and Blue components of key color
  uint8 tr, tg, tb;
  // texture has key color?
  bool HasKey;
  // Has transparent color changed?
  bool KeyChanged;
  // texture handle for the 3D/2D driver
  iTextureHandle *Handle;
  // texture name
  char *Name;
  // VFS file name
  char *FileName;

public:
  /// Create the 2D texture
  csWSTexture (const char *iName, iImage *Image, int iFlags);
  /// Destroy the texture object
  ~csWSTexture ();
  /// Set texture transparent color
  void SetKeyColor (int iR, int iG, int iB);
  /// Set whenever texture has transparent holes or not
  void SetKeyColor (bool iEnable);
  /// Get texture transparent color
  void GetKeyColor (int &oR, int &oG, int &oB)
  { oR = tr; oG = tg; oB = tb; }
  /// Query whenever texture has transparent areas
  bool HasKeyColor ()
  { return HasKey; }
  /// Register the texture with texture manager
  void Register (iTextureManager *iTexMan);
  /// Unregister the texture
  void Unregister ();
  /// Refresh the texture in video memory (do iTexMan->PrepareTexture ())
  void Refresh ();
  /// Define texture name
  void SetName (const char *iName);
  /// Get texture name
  const char *GetName ()
  { return Name; }
  /// CSWS uses its own reference counting system.
  iTextureHandle *GetHandle ()
  { return Handle; }
  /// Increment reference count to this texture
  void IncRef ()
  { RefCount++; }
  /// Delete a reference to this texture
  void DecRef ()
  { RefCount--; }
  /// Return reference count
  int GetRefCount () const
  { return RefCount; }
  /// Get texture file name
  const char *GetFileName () const
  { return FileName; }
  /// Set texture file name
  void SetFileName (const char *iFileName);
  /// Find nearest transparent color in image
  void FixKeyColor ();
  /// Tell texture that transparent color has already been fixed
  void DontFixKeyColor ()
  { KeyChanged = false; }
  /// Query texture width
  int GetWidth ();
  /// Query texture height
  int GetHeight ();
};

/// This class is a vector of csWSTexture's
class csWSTexVector : public csVector
{
public:
  /// Initialize the texture vector
  csWSTexVector ();
  /// Destroy the object
  virtual ~csWSTexVector ();
  /// Free a texture element
  virtual bool FreeItem (csSome Item);
  /// Compare texture with name; used in FindKey ()
  virtual int CompareKey (csSome Item, csConstSome Key, int Mode) const;
  /// Get texture by index
  csWSTexture *Get (int idx)
  { return (csWSTexture *)csVector::Get (idx); }
  /// Find a texture by name
  csWSTexture *FindTexture (const char *iName)
  {
    int idx = FindKey (iName);
    return idx >= 0 ? (csWSTexture *)Get (idx) : (csWSTexture*)NULL;
  }
};

#endif // __CSWSTEX_H__