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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#ifndef CURSORICONS_H
#define CURSORICONS_H
#include <map>
#include <set>
#include <string>
using std::string;
#include "System/float3.h"
class CMouseCursor;
class CCursorIcons
{
public:
CCursorIcons();
~CCursorIcons();
void Enable(bool);
inline void AddIcon(int cmd, const float3& pos);
inline void AddIconText(const string& text, const float3& pos);
inline void AddBuildIcon(int cmd, const float3& pos, int team, int facing);
void SetCustomType(int cmdID, const string& cursor);
void Draw();
void Clear();
protected:
void DrawCursors();
void DrawTexts();
void DrawBuilds();
const CMouseCursor* GetCursor(int cmd) const;
protected:
bool enabled;
struct Icon {
Icon(int c, const float3& p)
: cmd(c), pos(p) {}
bool operator<(const Icon& i) const
{
// render the WAIT type commands last
if (cmd > i.cmd) return true;
if (cmd < i.cmd) return false;
if (pos.x < i.pos.x) return true;
if (pos.x > i.pos.x) return false;
if (pos.y < i.pos.y) return true;
if (pos.y > i.pos.y) return false;
if (pos.z < i.pos.z) return true;
if (pos.z > i.pos.z) return false;
return false;
}
int cmd;
float3 pos;
};
struct IconText {
IconText(const string& t, const float3& p)
: text(t), pos(p) {}
bool operator<(const IconText& i) const
{
if (pos.x < i.pos.x) return true;
if (pos.x > i.pos.x) return false;
if (pos.y < i.pos.y) return true;
if (pos.y > i.pos.y) return false;
if (pos.z < i.pos.z) return true;
if (pos.z > i.pos.z) return false;
return (text < i.text);
}
string text;
float3 pos;
};
struct BuildIcon {
BuildIcon(int c, const float3& p, int t, int f)
: pos(p), cmd(c), team(t), facing(f) {}
bool operator<(const BuildIcon& i) const
{
if (cmd > i.cmd) return true;
if (cmd < i.cmd) return false;
if (pos.x < i.pos.x) return true;
if (pos.x > i.pos.x) return false;
if (pos.y < i.pos.y) return true;
if (pos.y > i.pos.y) return false;
if (pos.z < i.pos.z) return true;
if (pos.z > i.pos.z) return false;
if (team > i.team) return true;
if (team < i.team) return false;
if (facing > i.facing) return true;
if (facing < i.facing) return false;
return false;
}
float3 pos;
int cmd;
int team;
int facing;
};
// use a set to minimize the number of texture bindings,
// and to avoid overdraw from multiple units with the
// same command
std::set<Icon> icons;
std::set<IconText> texts;
std::set<BuildIcon> buildIcons;
std::map<int, string> customTypes;
};
inline void CCursorIcons::AddIcon(int cmd, const float3& pos)
{
if (enabled) {
Icon icon(cmd, pos);
icons.insert(icon);
}
}
inline void CCursorIcons::AddIconText(const string& text, const float3& pos)
{
if (enabled) {
IconText iconText(text, pos);
texts.insert(iconText);
}
}
inline void CCursorIcons::AddBuildIcon(int cmd, const float3& pos,
int team, int facing)
{
if (enabled) {
BuildIcon icon(cmd, pos, team, facing);
buildIcons.insert(icon);
}
}
extern CCursorIcons cursorIcons;
#endif /* CURSORICONS_H */
|