summaryrefslogtreecommitdiff
path: root/data.c
blob: e4b35d7ee48460a02b43441cfe5d7428ddfe0c5d (plain)
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
/*
 * $Id: data.c,v 1.20 2004/06/22 16:48:03 lordjaxom Exp $
 */

#include "data.h"
#include "common.h"
#include "render.h"

cText2SkinItem::cText2SkinItem(void) {
	mItem    = itemUnknown;
	mDisplay = displayAlways;
	mBpp     = 4;
	mArc     = 0;
	mAlpha   = 0;
	mFont    = cFont::GetFont(fontOsd);
	mAlign   = taDefault;
	mBase    = baseRelative;
}

cText2SkinItem::~cText2SkinItem() {
}

bool cText2SkinItem::Parse(const char *Text) {
	const char *text = Text;
	const char *ptr = text;
	bool res = false;

	// check if this is an item
	if (ParseVar(ptr, "Item", &mItem) && mItem != itemUnknown) {
		ParseItem(ptr);

		if (mItem == itemSkin && (mName == "" || mVersion == ""))
			esyslog("ERROR: text2skin: Item=Skin is missing the name and/or version parameter(s)");
		else
			res = true;
	} else 
		esyslog("ERROR: text2skin: unknown item in skin");
	return res;
}

bool cText2SkinItem::ParseItem(const char *Text) {
	ParseVar(Text, "name",     mName);
	ParseVar(Text, "version",  mVersion);
	ParseVar(Text, "base",    &mBase);
	ParseVar(Text, "display", &mDisplay);
	ParseVar(Text, "x1",      &mPos1.x);
	ParseVar(Text, "y1",      &mPos1.y);
	ParseVar(Text, "x2",      &mPos2.x);
	ParseVar(Text, "y2",      &mPos2.y);
	ParseVar(Text, "bpp",     &mBpp);
	ParseVar(Text, "arc",     &mArc);
	ParseVar(Text, "alpha",   &mAlpha);
	ParseVar(Text, "fg",       mFg);
	ParseVar(Text, "bg",       mBg);
	ParseVar(Text, "font",    &mFont);
	ParseVar(Text, "path",     mPath);
	ParseVar(Text, "altpath",  mAltPath);
	ParseVar(Text, "text",     mText);
	ParseVar(Text, "type",     mType);
	ParseVar(Text, "format",   mFormat);
	ParseVar(Text, "align",   &mAlign);
	return true;
}

const POINT cText2SkinItem::Pos(void) const {
	return cText2SkinRender::Transform(mPos1);
}

const SIZE cText2SkinItem::Size(void) const {
	POINT p1 = cText2SkinRender::Transform(mPos1);
	POINT p2 = cText2SkinRender::Transform(mPos2);
	return SIZE(p2.x - p1.x + 1, p2.y - p1.y + 1);
}

// --- cText2SkinData ---------------------------------------------------------
	
cText2SkinData::cText2SkinData(const char *Skin): cText2SkinFile(Skin) {
	mCurrentSection = sectionSkin;
}

cText2SkinData::~cText2SkinData() {
	for (int i = 0; i < __SECTION_COUNT__; ++i) {
		for (int j = 0; j < (int)mSections[i].size(); ++j)
			delete mSections[i][j];
		mSections[i].clear();
	}
}

bool cText2SkinData::Parse(const char *Text) {
	int l = strlen(Text);
	bool result = false;
	if (l) {
		if (Text[0] == '#') // comment
			result = true;
		else if (Text[0] == '[' && Text[l - 1] == ']') { // section
			char *s;
			int i;
			asprintf(&s, "%.*s", l - 2, Text + 1);
			for (i = 0; i < __SECTION_COUNT__; ++i) {
				if (SectionNames[i] == s) {
					mCurrentSection = (eSkinSection)i;
					result = true;
					break;
				}
			}
			if (i == __SECTION_COUNT__)
				esyslog("ERROR: text2skin: Unknown section %s", s);
			free(s);
		} else {
			cText2SkinItem *item = new cText2SkinItem;
			if (item->Parse(Text)) {
				mSections[mCurrentSection].push_back(item);
				result = true;
			} else
				delete item;
		}
	}
	return result;
}

cText2SkinItem *cText2SkinData::Get(eSkinSection Section, eSkinItem Item) {
	vector<cText2SkinItem*>::iterator it = mSections[Section].begin();
	for (; it != mSections[Section].end(); ++it) {
		if ((*it)->Item() == Item)
			return (*it);
	}
	return NULL;
}