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
|
/*
Winamp Skin
Copyright (C) 2002 Ryan Cumming
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation.
For more information look at the file COPYRIGHT in this package
*/
#include <ksimpleconfig.h>
#include <tqbitmap.h>
#include <tqpainter.h>
#include <tqregexp.h>
#include "waSkinModel.h"
#include "waSkins.h"
#include "waRegion.h"
WaRegion *windowRegion = NULL;
// Hack around case-insensitivity in Winamp INI files by searching for common capitializations
// Needs to be replaced with an all-custom loader after 3.0
const char *pointListNames[] = {"PointList", "pointlist", "Pointlist", "pointList", "POINTLIST", 0};
const char *numPointsNames[] = {"NumPoints", "numpoints", "Numpoints", "numPoints", "NUMPOINTS", 0};
WaRegion::WaRegion(TQString filename) {
// Load the region file, which happens to be in KConfig format
KSimpleConfig regionFile(filename, true);
// Clear our variables by default
window_mask = 0;
shade_mask = 0;
// Make the new bitmaps, default window size
window_mask = new TQBitmap(WaSkinModel::instance()->getMapGeometry(_WA_MAPPING_MAIN).size(), true);
shade_mask = new TQBitmap(WaSkinModel::instance()->getMapGeometry(_WA_MAPPING_TITLE).size(), true);
// Load the normal window mask data
regionFile.setGroup("Normal");
TQValueList<int> num_points;
for (int x = 0;numPointsNames[x];x++) {
if (regionFile.hasKey(numPointsNames[x]))
num_points = parseList(regionFile.readEntry(numPointsNames[x]));
}
TQValueList<int> point_list;
for (int x = 0;pointListNames[x];x++) {
if (regionFile.hasKey(pointListNames[x]))
point_list = parseList(regionFile.readEntry(pointListNames[x]));
}
// Now build the mask
buildPixmap(num_points, point_list, window_mask);
// Load the windowshade mask data
regionFile.setGroup("WindowShade");
num_points = parseList(regionFile.readEntry("NumPoints"));
point_list = parseList(regionFile.readEntry("PointList"));
// Now build the mask
buildPixmap(num_points, point_list, shade_mask);
}
WaRegion::~WaRegion() {
delete window_mask;
delete shade_mask;
}
void WaRegion::buildPixmap(const TQValueList<int> &num_points_list, const TQValueList<int> &points_list, TQBitmap *dest) {
if (!num_points_list.count()) {
dest->fill(Qt::color1);
return;
}
TQValueList<int>::const_iterator points = points_list.begin();
TQPainter p(dest);
// Coordinates in REGION.TXT can go one pixel beyond the window size
TQBitmap bm(dest->width()+1,dest->height()+1,true);
TQPainter bmp(&bm);
bmp.setBrush(Qt::color1);
bmp.setPen(Qt::NoPen); // The polygon border itself should not be part of the visible window
// Go over each "region" in the file
for (TQValueList<int>::const_iterator num_points = num_points_list.begin();num_points != num_points_list.end();num_points++) {
// Make a new point array
TQPointArray point_array(*num_points);
// Populate it
for (int i = 0;i < *num_points;i++) {
int x = (*points++);
int y = (*points++);
point_array.setPoint(i, x, y);
}
// Now draw it as a filled polygon on the mask
bmp.drawPolygon(point_array);
}
p.drawPixmap(0,0,bm,0,0,dest->width(),dest->height());
}
// The winamp list format is absolutely insane, it will accept either
// commas or whitespace as the delimiter. This function deals with
// that.
TQValueList<int> WaRegion::parseList(const TQString &list) const {
TQValueList<int> temp_list;
if (list.isEmpty())
return temp_list;
TQStringList open=TQStringList::split(TQRegExp("[,\\s]+"), list);
for (TQStringList::Iterator i=open.begin(); i != open.end(); ++i)
temp_list.append((*i).toInt());
return temp_list;
}
|