@@ -35,64 +35,64 @@ class Tools {
35
35
{
36
36
app_info info;
37
37
be_app->GetAppInfo (&info);
38
-
38
+
39
39
BPath path = BPath (&info.ref );
40
40
path.GetParent (&path);
41
-
41
+
42
42
return path.Path ();
43
43
}
44
-
45
-
44
+
45
+
46
46
static BString
47
47
AppName (void )
48
48
{
49
49
app_info info;
50
50
be_app->GetAppInfo (&info);
51
-
51
+
52
52
BPath path = BPath (&info.ref );
53
53
path.GetParent (&path);
54
-
54
+
55
55
return path.Leaf ();
56
56
}
57
-
58
-
57
+
58
+
59
59
static BString
60
60
SettingsPath (void )
61
61
{
62
62
BPath path;
63
63
if (find_directory (B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
64
64
return " " ;
65
-
65
+
66
66
path.Append (AppName ().Capitalize ());
67
67
create_directory (path.Path (), 0755 );
68
-
68
+
69
69
BString str (path.Path ());
70
70
str.Append (" /" );
71
- return str;
71
+ return str;
72
72
}
73
-
74
-
73
+
74
+
75
75
static std::vector<BString>
76
76
Split (BString str, const char token, BString start = " " , BString stop = " " )
77
77
{
78
78
std::vector<BString> vec;
79
-
79
+
80
80
int n1 = 0 ;
81
81
int n2 = str.Length ();
82
-
82
+
83
83
if (start != " " )
84
84
n1 = str.FindFirst (start, 0 );
85
-
85
+
86
86
if (stop != " " )
87
87
n2 = str.FindFirst (stop, n1 + 1 );
88
-
88
+
89
89
if (n1 == B_ERROR || n2 == B_ERROR)
90
90
return vec;
91
-
91
+
92
92
n1 = n1 + start.Length ();
93
-
93
+
94
94
int n = n1;
95
-
95
+
96
96
for (; n < n2; ++n)
97
97
if (str[n] == token) {
98
98
if (n > 0 && str[n-1 ] != token) {
@@ -105,39 +105,39 @@ class Tools {
105
105
n1 = n + 1 ;
106
106
}
107
107
}
108
-
108
+
109
109
char temp[n - n1 + 1 ] ;
110
110
str.CopyInto (temp, n1, n - n1);
111
111
temp[n - n1] = ' \0 ' ;
112
112
vec.push_back (temp);
113
113
return vec;
114
114
}
115
-
116
-
115
+
116
+
117
117
static std::vector<BString>
118
118
Split (unsigned int length, BString str,
119
119
const char token, BString start, BString stop)
120
120
{
121
121
std::vector<BString> vec;
122
-
122
+
123
123
int n1 = 0 ;
124
124
int n2 = str.Length ();
125
-
125
+
126
126
if (start != " " )
127
127
n1 = str.FindFirst (start, 0 );
128
-
128
+
129
129
if (stop != " " )
130
130
n2 = str.FindFirst (stop, n1 + 1 );
131
-
131
+
132
132
if (n1 == B_ERROR || n2 == B_ERROR) {
133
133
vec.resize (length, " " );
134
134
return vec;
135
135
}
136
-
136
+
137
137
n1 = n1 + start.Length ();
138
-
138
+
139
139
int n = n1;
140
-
140
+
141
141
for (; n < n2; ++n)
142
142
if (str[n] == token) {
143
143
if (n > 0 && str[n-1 ] != token) {
@@ -147,60 +147,60 @@ class Tools {
147
147
vec.push_back (temp);
148
148
if (vec.size () == length)
149
149
return vec;
150
-
150
+
151
151
n1 = n + 1 ;
152
152
} else {
153
153
n1 = n + 1 ;
154
154
}
155
155
}
156
-
156
+
157
157
char temp[n - n1 + 1 ] ;
158
158
str.CopyInto (temp, n1, n - n1);
159
159
temp[n - n1] = ' \0 ' ;
160
160
vec.push_back (temp);
161
161
vec.resize (length, " " );
162
-
162
+
163
163
return vec;
164
164
}
165
-
166
-
165
+
166
+
167
167
static BString
168
168
Find (BString str, BString searchStr)
169
169
{
170
170
BString result = " " ;
171
-
171
+
172
172
if (str.Length () == 0 || searchStr.Length () == 0 )
173
173
return result;
174
-
174
+
175
175
int n1 = str.FindFirst (searchStr) + searchStr.Length ();
176
176
int n2 = str.FindFirst (" " , n1);
177
-
177
+
178
178
if (n2 == B_ERROR)
179
179
n2 = str.Length ();
180
-
180
+
181
181
str.CopyInto (result, n1, n2 - n1);
182
-
182
+
183
183
return result;
184
184
}
185
-
186
-
185
+
186
+
187
187
static BBitmap*
188
188
LoadBitmap (BString const & imageName, int size)
189
189
{
190
190
BResources* res = be_app->AppResources ();
191
-
191
+
192
192
if (res == nullptr )
193
193
return nullptr ;
194
-
194
+
195
195
size_t nbytes = 0 ;
196
196
color_space cspace = B_RGBA32;
197
-
197
+
198
198
const void * data = res->LoadResource (' HVIF' , imageName.String (), &nbytes);
199
-
199
+
200
200
// size--;
201
-
201
+
202
202
BBitmap* bitmap = new BBitmap (BRect (0 , 0 , size, size), cspace);
203
-
203
+
204
204
if (bitmap->InitCheck () != B_OK) {
205
205
delete bitmap;
206
206
bitmap = nullptr ;
@@ -209,12 +209,12 @@ class Tools {
209
209
delete bitmap;
210
210
bitmap = nullptr ;
211
211
}
212
-
212
+
213
213
res->RemoveResource (data);
214
214
return bitmap;
215
215
}
216
-
217
-
216
+
217
+
218
218
static void
219
219
ExportBitmap (BBitmap* bitmap,
220
220
BString const & path, int32 const & format = B_PNG_FORMAT)
@@ -225,64 +225,64 @@ class Tools {
225
225
roster->Translate (&stream, NULL , NULL , &imageFile, B_PNG_FORMAT);
226
226
BBitmap* bmp;
227
227
stream.DetachBitmap (&bmp);
228
-
228
+
229
229
}
230
-
230
+
231
231
232
232
static std::unique_ptr<BBitmap>
233
233
RescaleBitmap (std::unique_ptr<BBitmap> src, int32 width, int32 height)
234
234
{
235
235
if (src == nullptr || src->IsValid () == false )
236
236
throw " Tools::RescaleBitmap" ;
237
-
237
+
238
238
if (height <= 0 ) {
239
239
if (width <= 0 )
240
240
return src;
241
-
242
- height = (width * src->Bounds ().Height ()) / src->Bounds ().Width ();
241
+
242
+ height = (width * src->Bounds ().Height ()) / src->Bounds ().Width ();
243
243
} else if (width <= 0 ) {
244
244
if (height <= 0 )
245
245
return src;
246
-
246
+
247
247
width = (height * src->Bounds ().Width ()) / src->Bounds ().Height ();
248
248
}
249
-
249
+
250
250
BRect srcSize = src->Bounds ();
251
-
251
+
252
252
if (height < 0 ) {
253
253
float srcProp = srcSize.Height ()/srcSize.Width ();
254
254
height = (int32)(width * ceil (srcProp));
255
255
}
256
-
256
+
257
257
BBitmap* res = new BBitmap (BRect (0 , 0 , (float )width, (float )height),
258
258
src->ColorSpace ());
259
-
259
+
260
260
float dx = (srcSize.Width () + 1 )/(float )(width + 1 );
261
261
float dy = (srcSize.Height () + 1 )/(float )(height + 1 );
262
262
uint8 bpp = (uint8)(src->BytesPerRow ()/ceil (srcSize.Width ()));
263
-
263
+
264
264
int srcYOff = src->BytesPerRow ();
265
265
int dstYOff = res->BytesPerRow ();
266
-
266
+
267
267
void * dstData = res->Bits ();
268
268
void * srcData = src->Bits ();
269
-
269
+
270
270
for (int32 y = 0 ; y <= height; y++) {
271
271
void * dstRow = (void *)((uintptr_t )dstData + (uintptr_t )(y * dstYOff));
272
272
void * srcRow = (void *)((uintptr_t )srcData + ((uintptr_t )(y * dy) * srcYOff));
273
-
273
+
274
274
for (int32 x = 0 ; x <= width; x++)
275
275
memcpy ((void *)((uintptr_t )dstRow + (x * bpp)), (void *)((uintptr_t )srcRow
276
276
+ ((uintptr_t )(x * dx) * bpp)), bpp);
277
277
}
278
-
278
+
279
279
std::unique_ptr<BBitmap> bitmap (res);
280
- return move (bitmap);
281
- }
280
+ return bitmap;
281
+ }
282
+
282
283
283
-
284
284
private:
285
- Tools (void );
285
+ Tools (void );
286
286
};
287
287
288
288
#endif
0 commit comments