Populous: The Beginning Script 3  1.0.0
Documentation for Populous Script 3 engine
LbColour.h
Go to the documentation of this file.
1 #pragma once
2 //***************************************************************************
3 // Colour
4 //***************************************************************************
5 
6 #include <LbPal.h>
7 #include <TbPixelCaps.h>
8 
9 #include "Pop3Debug.h"
10 
11 // the global palette, used by the colour class
12 LB_API_VAR_IMPORT TbPalette _lbGlobalPalette;
13 
14 
16 // <t>>TbColour<<
18 LB_API_CLASS(TbColour)
19 {
20 public:
21  TbColour()
22  {
23  Index = Red = Green = Blue = Alpha = 0;
24  }
25 
26  // Constructors
27  TbColour(UBYTE Ind)
28  {
29  // Palette lookup
30  Index = Ind;
31  Red = _lbGlobalPalette.Entry[Index].Red;
32  Green = _lbGlobalPalette.Entry[Index].Green;
33  Blue = _lbGlobalPalette.Entry[Index].Blue;
34  Alpha = 0xff;
35  };
36 
37  TbColour(int Ind)
38  {
39  ASSERT(Ind >= 0);
40  ASSERT(Ind<256);
41 
42  // Palette lookup
43  Index = (UBYTE)Ind;
44  Red = _lbGlobalPalette.Entry[Index].Red;
45  Green = _lbGlobalPalette.Entry[Index].Green;
46  Blue = _lbGlobalPalette.Entry[Index].Blue;
47  Alpha = 0xff;
48  };
49 
50  TbColour(UBYTE r, UBYTE g, UBYTE b)
51  {
52  Set(r, g, b);
53  };
54 
55  TbColour(UBYTE r, UBYTE g, UBYTE b, UBYTE Pal) : Red(r), Green(g), Blue(b), Index(Pal), Alpha(0xff)
56  {
57  };
58 
59 
60  // Set the colour to an rgb value
61  inline void Set(UBYTE r, UBYTE g, UBYTE b, UBYTE a = 0xff);
62 
63  // Function to get the colour as a packed 32bit value
64  inline ULONG Get32bitValue() const;
65 
66  // Function to get the colour as a formatted - packed to the specifications in the pixel format mask
67  inline ULONG GetFormattedValue(const TbPixelCaps& pixcaps) const;
68  inline ULONG GetFormattedValue(const TbPixFormat& pixformat) const;
69 
70  // public data
71  union
72  {
73  ULONG Packed;
74 
75  struct
76  {
77  UBYTE Blue;
78  UBYTE Green;
79  UBYTE Red;
80  UBYTE Alpha;
81  };
82  };
83 
84  UBYTE Index;
85 };
86 
87 
88 // Set to an rgb value then do a palette lookup
89 inline void TbColour::Set(UBYTE r, UBYTE g, UBYTE b, UBYTE a)
90 {
91  Red = r;
92  Green = g;
93  Blue = b;
94  Alpha = a;
95 
96  // Find colour for index
97  Index = LbPalette_FindColour(&_lbGlobalPalette, r, g, b);
98 };
99 
100 // Gets a 32 bit value.
101 inline ULONG TbColour::Get32bitValue() const
102 {
103  ULONG RetVal = (Red << 16) | (Green << 8) | (Blue) | (Alpha << 24);
104  return RetVal;
105 };
106 
107 // Gets a formatted long according to the pixformat specified.
108 inline ULONG TbColour::GetFormattedValue(const TbPixelCaps& pixcaps) const
109 {
110  return ((((Packed) >> pixcaps.mRed.ShiftRight) << pixcaps.mRed.ShiftLeft) & pixcaps.mRed.Mask)
111  | ((((Packed) >> pixcaps.mGreen.ShiftRight) << pixcaps.mGreen.ShiftLeft) & pixcaps.mGreen.Mask)
112  | ((((Packed) >> pixcaps.mBlue.ShiftRight) << pixcaps.mBlue.ShiftLeft) & pixcaps.mBlue.Mask)
113  | ((((Packed) >> pixcaps.mAlpha.ShiftRight) << pixcaps.mAlpha.ShiftLeft) & pixcaps.mAlpha.Mask);
114 };
115 
116 // Gets a formatted long according to the pixformat specified.
117 inline ULONG TbColour::GetFormattedValue(const TbPixFormat& pixformat) const
118 {
119  TbPixelCaps pixcaps;
120  pixcaps.Set(pixformat);
121  return GetFormattedValue(pixcaps);
122 };
123 
124 
125 
LB_API_VAR_IMPORT TbPalette _lbGlobalPalette
Definition: LbColour.h:12
LB_API_CLASS(TbColour)
Definition: LbColour.h:18