aboutsummaryrefslogtreecommitdiff
path: root/Src/Winamp/GammaManagerAPI.h
blob: b60b8d7a20206d92f2a7252a1895f6af5709f4f3 (plain) (blame)
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
#pragma once
#include <api/skin/colorthemes.h>
#include <api/service/svcs/svc_skinfilter.h>
#include <vector>
#include <api/skin/api_colorthemes.h>

class ColorThemeGroupI : public ColorThemeGroup
{
public:
  ColorThemeGroupI(const wchar_t *pname, int pred, int pgreen, int pblue, int pgray, int pboost) 
		: name(0), red(pred), green(pgreen), blue(pblue), make_grayscale(pgray), boost_levels(pboost) 
	{
		name = _wcsdup(pname);
	}
~ColorThemeGroupI()
{
	free(name);
}
		ColorThemeGroupI(ColorThemeGroup &copy_group)
		{
			name = _wcsdup(copy_group.getName());
			red = copy_group.getRed();
			green = copy_group.getGreen();
			blue = copy_group.getBlue();
			make_grayscale = copy_group.getGray();
			boost_levels = copy_group.getBoost();
		}
    const wchar_t *getName() { return name; }
    int getRed() { return red; }
    int getGreen() { return green; }
    int getBlue() { return blue; }
    int getGray() { return make_grayscale; }
    int getBoost() { return boost_levels; }
    void setName(const wchar_t *pname) { free(name); name = _wcsdup(pname); }
    void setRed(int r) { red = r; }
    void setGreen(int g) { green = g; }
    void setBlue(int b) { blue = b; }
    void setGray(int g) { make_grayscale = g; }
    void setBoost(int b) { boost_levels = b; }
                                                                                          
  protected:
    RECVS_DISPATCH;

  wchar_t *name;
  int red;
  int green;
  int blue;
  int make_grayscale;
  int boost_levels;
};

static bool IsKeyword(const wchar_t *a, const wchar_t *b)
{
	return (CompareStringW(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT), NORM_IGNORECASE, a, -1, b, -1) == CSTR_EQUAL);
        
}
class GammaSet
{
	public:
	GammaSet( const wchar_t *pname ) : name( 0 ), generalgroup( L"General", 0, 0, 0, 0, 0 )
	{
		name = _wcsdup( pname );
	}

	~GammaSet()
	{
		//gammagroups.deleteAll();
		for ( ColorThemeGroupI *obj : gammagroups )
			delete obj;

		gammagroups.clear();

		free( name );
	}

	int haveGroup( const wchar_t *grp )
	{
		if ( !grp )
			return 0;

		for ( ColorThemeGroupI *obj : gammagroups )
		{
			if ( IsKeyword( grp, obj->getName() ) )
				return 1;
		}

		return 0;
	}

	void SetName( const wchar_t *newname )
	{
		free( name );
		name = _wcsdup( newname );
	}
	wchar_t *name;
	std::vector<ColorThemeGroupI *> gammagroups;
	ColorThemeGroupI generalgroup;
};


class GammaManagerAPI : public api_colorthemes
{
public:
	static const char *getServiceName() { return "Color Themes API"; }
	static const GUID getServiceGuid() { return ColorThemesAPIGUID; }	
	GammaManagerAPI();

	void StartTransaction();
	void EndTransaction();

	/* Gamma Sets */
	size_t getNumGammaSets();
	const wchar_t *enumGammaSet(size_t n);
	void deleteGammaSet(const wchar_t *set);
	void deleteAllGammaSets();
	void resetGammaSet(const wchar_t *set);
	void renameGammaSet(const wchar_t *set, const wchar_t *newname);
	size_t newGammaSet(const wchar_t *set); // returns index of your new gamma group
	void updateGammaSet(const wchar_t *set);

	
	/* Gamma Groups */
	int getNumGammaGroups(const wchar_t *gammaset);
	const wchar_t *enumGammaGroup(const wchar_t *gammaset, int n);
	ColorThemeGroup *enumColorThemeGroup(int colorset, int colorgroup);
	ColorThemeGroup *getColorThemeGroup(const wchar_t *colorset, const wchar_t *colorgroup);
	int getGammaForGroup(const wchar_t *group, int *r, int *g, int *b, int *gray, int *boost);
	void addGammaGroup(const wchar_t *set, ColorThemeGroup *group);
	void addGammaGroup2(size_t gammaSetIndex, ColorThemeGroup *group);

	/* Active Gamma Set */
	const wchar_t *getGammaSet();
	void setGammaSet(const wchar_t *set);

	  protected:
    RECVS_DISPATCH;

private:
	void setGammaSetInternal(GammaSet *set);

	std::vector<GammaSet*> gammasets;
	GammaSet *curSetSel; // current color theme
	size_t inTransaction;
};