GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/userpalette.cpp Lines: 239 303 78.9 %
Date: 2018-09-20 Branches: 223 484 46.1 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2008  Douglas Boffey <[email protected]>
4
 *  Copyright (C) 2009  The Mana World Development Team
5
 *  Copyright (C) 2009-2010  The Mana Developers
6
 *  Copyright (C) 2011-2018  The ManaPlus Developers
7
 *
8
 *  This file is part of The ManaPlus Client.
9
 *
10
 *  This program is free software; you can redistribute it and/or modify
11
 *  it under the terms of the GNU General Public License as published by
12
 *  the Free Software Foundation; either version 2 of the License, or
13
 *  any later version.
14
 *
15
 *  This program is distributed in the hope that it will be useful,
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 *  GNU General Public License for more details.
19
 *
20
 *  You should have received a copy of the GNU General Public License
21
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 */
23
24
#include "gui/userpalette.h"
25
26
#include "configuration.h"
27
28
#include "utils/foreach.h"
29
#include "utils/gettext.h"
30
31
#include "debug.h"
32
33
UserPalette *userPalette = nullptr;
34
35
3
const std::string ColorTypeNames[CAST_SIZE(
36
    UserColorId::USER_COLOR_LAST)] =
37
{
38
    "",
39
    "ColorBeing",
40
    "ColorFriend",
41
    "ColorDisregarded",
42
    "ColorIgnored",
43
    "ColorErased",
44
    "ColorEnemy",
45
    "ColorPlayer",
46
    "ColorSelf",
47
    "ColorGM",
48
    "ColorNPC",
49
    "ColorMonster",
50
    "ColorPet",
51
    "ColorMercenary",
52
    "ColorHomunculus",
53
    "ColorSkillUnit",
54
    "ColorParty",
55
    "ColorGuild",
56
    "ColorTeam1",
57
    "ColorTeam2",
58
    "ColorTeam3",
59
    "",
60
    "ColorParticle",
61
    "ColorPickupInfo",
62
    "ColorExpInfo",
63
    "",
64
    "ColorPlayerHp",
65
    "ColorPlayerHp2",
66
    "ColorMonsterHp",
67
    "ColorMonsterHp2",
68
    "ColorHomunHp",
69
    "ColorHomunHp2",
70
    "ColorMercHp",
71
    "ColorMercHp2",
72
    "ColorElementalHp",
73
    "ColorElementalHp2",
74
    "",
75
    "ColorHitPlayerMonster",
76
    "ColorHitMonsterPlayer",
77
    "ColorHitPlayerPlayer",
78
    "ColorHitCritical",
79
    "ColorHitLocalPlayerMonster",
80
    "ColorHitLocalPlayerCritical",
81
    "ColorHitLocalPlayerMiss",
82
    "ColorMiss",
83
    "",
84
    "ColorPortalHighlight",
85
    "ColorCollisionHighlight",
86
    "ColorCollisionAirHighlight",
87
    "ColorCollisionWaterHighlight",
88
    "ColorCollisionMonsterHighlight",
89
    "ColorCollisionGroundtopHighlight",
90
    "ColorWalkableTileHighlight",
91
    "ColorNet",
92
    "",
93
    "ColorAttackRange",
94
    "ColorAttackRangeBorder",
95
    "ColorMonsterAttackRange",
96
    "ColorSkillAttackRange",
97
    "",
98
    "ColorFloorItemText",
99
    "ColorHomePlace",
100
    "ColorHomePlaceBorder",
101
    "ColorRoadPoint",
102
































129
};
103
104
std::string UserPalette::getConfigName(const std::string &typeName)
105
{
106
    std::string res("Color" + typeName);
107
    size_t pos = 5;
108
    for (size_t i = 0; i < typeName.length(); i++)
109
    {
110
        if (i == 0 || typeName[i] == '_')
111
        {
112
            if (i > 0)
113
                i++;
114
115
            res[pos] = typeName[i];
116
        }
117
        else
118
        {
119
           res[pos] = CAST_S8(tolower(typeName[i]));
120
        }
121
        pos ++;
122
    }
123
    res.erase(pos, res.length() - pos);
124
    return res;
125
}
126
127
158
UserPalette::UserPalette() :
128
    Palette(CAST_S32(UserColorId::USER_COLOR_LAST)),
129
316
    ListModel()
130
{
131
474
    mColors[CAST_SIZE(UserColorId::BEING)] = ColorElem();
132
474
    mColors[CAST_SIZE(UserColorId::PC)] = ColorElem();
133
474
    mColors[CAST_SIZE(UserColorId::SELF)] = ColorElem();
134
474
    mColors[CAST_SIZE(UserColorId::GM)] = ColorElem();
135
474
    mColors[CAST_SIZE(UserColorId::NPC)] = ColorElem();
136
474
    mColors[CAST_SIZE(UserColorId::MONSTER)] = ColorElem();
137
138
632
    addLabel(UserColorId::LABEL_BEING,
139
        // TRANSLATORS: palette label
140
316
        _("Beings"));
141
632
    addColor(UserColorId::BEING,
142
        0xffffff,
143
        GradientType::STATIC,
144
        // TRANSLATORS: palette color
145
158
        _("Being"),
146
158
        GRADIENT_DELAY);
147
632
    addColor(UserColorId::FRIEND,
148
        0xb0ffb0,
149
        GradientType::STATIC,
150
        // TRANSLATORS: palette color
151
158
        _("Friend names"),
152
158
        GRADIENT_DELAY);
153
632
    addColor(UserColorId::DISREGARDED,
154
        0xa00000,
155
        GradientType::STATIC,
156
        // TRANSLATORS: palette color
157
158
        _("Disregarded names"),
158
158
        GRADIENT_DELAY);
159
632
    addColor(UserColorId::IGNORED,
160
        0xff0000,
161
        GradientType::STATIC,
162
        // TRANSLATORS: palette color
163
158
        _("Ignored names"),
164
158
        GRADIENT_DELAY);
165
632
    addColor(UserColorId::ERASED,
166
        0xff0000,
167
        GradientType::STATIC,
168
        // TRANSLATORS: palette color
169
158
        _("Erased names"),
170
158
        GRADIENT_DELAY);
171
632
    addColor(UserColorId::ENEMY,
172
        0xff4040,
173
        GradientType::STATIC,
174
        // TRANSLATORS: palette color
175
158
        _("Enemy"),
176
158
        GRADIENT_DELAY);
177
632
    addColor(UserColorId::PC,
178
        0xffffff,
179
        GradientType::STATIC,
180
        // TRANSLATORS: palette color
181
158
        _("Other players names"),
182
158
        GRADIENT_DELAY);
183
632
    addColor(UserColorId::SELF,
184
        0xff8040,
185
        GradientType::STATIC,
186
        // TRANSLATORS: palette color
187
158
        _("Own name"),
188
158
        GRADIENT_DELAY);
189
632
    addColor(UserColorId::GM,
190
        0x00ff00,
191
        GradientType::STATIC,
192
        // TRANSLATORS: palette color
193
158
        _("GM names"),
194
158
        GRADIENT_DELAY);
195
632
    addColor(UserColorId::NPC,
196
        0xc8c8ff,
197
        GradientType::STATIC,
198
        // TRANSLATORS: palette color
199
158
        _("NPCs"),
200
158
        GRADIENT_DELAY);
201
632
    addColor(UserColorId::MONSTER,
202
        0xff4040,
203
        GradientType::STATIC,
204
        // TRANSLATORS: palette color
205
158
        _("Monsters"),
206
158
        GRADIENT_DELAY);
207
632
    addColor(UserColorId::PET,
208
        0xffffff,
209
        GradientType::STATIC,
210
        // TRANSLATORS: palette color
211
158
        _("Pets"),
212
158
        GRADIENT_DELAY);
213
632
    addColor(UserColorId::MERCENARY,
214
        0xffffff,
215
        GradientType::STATIC,
216
        // TRANSLATORS: palette color
217
158
        _("Mercenary"),
218
158
        GRADIENT_DELAY);
219
632
    addColor(UserColorId::HOMUNCULUS,
220
        0xffffff,
221
        GradientType::STATIC,
222
        // TRANSLATORS: palette color
223
158
        _("Homunculus"),
224
158
        GRADIENT_DELAY);
225
632
    addColor(UserColorId::SKILLUNIT,
226
        0xffffff,
227
        GradientType::STATIC,
228
        // TRANSLATORS: palette color
229
158
        _("Skill unit"),
230
158
        GRADIENT_DELAY);
231
632
    addColor(UserColorId::PARTY,
232
        0xff00d8,
233
        GradientType::STATIC,
234
        // TRANSLATORS: palette color
235
158
        _("Party members"),
236
158
        GRADIENT_DELAY);
237
632
    addColor(UserColorId::GUILD,
238
        0xff00d8,
239
        GradientType::STATIC,
240
        // TRANSLATORS: palette color
241
158
        _("Guild members"),
242
158
        GRADIENT_DELAY);
243
    addColor(UserColorId::TEAM1,
244
        0x0000ff,
245
        GradientType::STATIC,
246
        // TRANSLATORS: palette color
247
316
        strprintf(_("Team %d"), 1),
248
158
        GRADIENT_DELAY);
249
    addColor(UserColorId::TEAM2,
250
        0x00a020,
251
        GradientType::STATIC,
252
        // TRANSLATORS: palette color
253
316
        strprintf(_("Team %d"), 2),
254
158
        GRADIENT_DELAY);
255
    addColor(UserColorId::TEAM3,
256
        0xffff20,
257
        GradientType::STATIC,
258
        // TRANSLATORS: palette color
259
316
        strprintf(_("Team %d"), 3),
260
158
        GRADIENT_DELAY);
261
632
    addLabel(UserColorId::LABEL_PARTICLES,
262
        // TRANSLATORS: palette label
263
316
        _("Particles"));
264
632
    addColor(UserColorId::PARTICLE,
265
        0xffffff,
266
        GradientType::STATIC,
267
        // TRANSLATORS: palette color
268
158
        _("Particle effects"),
269
158
        GRADIENT_DELAY);
270
632
    addColor(UserColorId::PICKUP_INFO,
271
        0x28dc28,
272
        GradientType::STATIC,
273
        // TRANSLATORS: palette color
274
158
        _("Pickup notification"),
275
158
        GRADIENT_DELAY);
276
632
    addColor(UserColorId::EXP_INFO,
277
        0xffff00,
278
        GradientType::STATIC,
279
        // TRANSLATORS: palette color
280
158
        _("Exp notification"),
281
158
        GRADIENT_DELAY);
282
632
    addLabel(UserColorId::LABEL_HP,
283
        // TRANSLATORS: palette label
284
316
        _("Hp bars"));
285
632
    addColor(UserColorId::PLAYER_HP,
286
        0x00ff00,
287
        GradientType::STATIC,
288
        // TRANSLATORS: palette color
289
316
        _("Player HP bar"), 50);
290
632
    addColor(UserColorId::PLAYER_HP2,
291
        0xff0000,
292
        GradientType::STATIC,
293
        // TRANSLATORS: palette color
294
158
        _("Player HP bar (second color)"),
295
158
        50);
296
632
    addColor(UserColorId::MONSTER_HP,
297
        0x00ff00,
298
        GradientType::STATIC,
299
        // TRANSLATORS: palette color
300
158
        _("Monster HP bar"),
301
158
        50);
302
632
    addColor(UserColorId::MONSTER_HP2,
303
        0xff0000,
304
        GradientType::STATIC,
305
        // TRANSLATORS: palette color
306
158
        _("Monster HP bar (second color)"),
307
158
        50);
308
632
    addColor(UserColorId::HOMUN_HP,
309
        0x00ff00,
310
        GradientType::STATIC,
311
        // TRANSLATORS: palette color
312
158
        _("Homunculus HP bar"),
313
158
        50);
314
632
    addColor(UserColorId::HOMUN_HP2,
315
        0xff0000,
316
        GradientType::STATIC,
317
        // TRANSLATORS: palette color
318
158
        _("Homunculus HP bar (second color)"),
319
158
        50);
320
632
    addColor(UserColorId::MERC_HP,
321
        0x00ff00,
322
        GradientType::STATIC,
323
        // TRANSLATORS: palette color
324
158
        _("Mercenary HP bar"),
325
158
        50);
326
632
    addColor(UserColorId::MERC_HP2,
327
        0xff0000,
328
        GradientType::STATIC,
329
        // TRANSLATORS: palette color
330
158
        _("Mercenary HP bar (second color)"),
331
158
        50);
332
333
632
    addColor(UserColorId::ELEMENTAL_HP,
334
        0x00ff00,
335
        GradientType::STATIC,
336
        // TRANSLATORS: palette color
337
158
        _("Elemental HP bar"),
338
158
        50);
339
632
    addColor(UserColorId::ELEMENTAL_HP2,
340
        0xff0000,
341
        GradientType::STATIC,
342
        // TRANSLATORS: palette color
343
158
        _("Elemental HP bar (second color)"),
344
158
        50);
345
632
    addLabel(UserColorId::LABEL_HITS,
346
        // TRANSLATORS: palette label
347
316
        _("Hits"));
348
632
    addColor(UserColorId::HIT_PLAYER_MONSTER,
349
        0x0064ff,
350
        GradientType::STATIC,
351
        // TRANSLATORS: palette color
352
158
        _("Player hits monster"),
353
158
        GRADIENT_DELAY);
354
632
    addColor(UserColorId::HIT_MONSTER_PLAYER,
355
        0xff3232,
356
        GradientType::STATIC,
357
        // TRANSLATORS: palette color
358
158
        _("Monster hits player"),
359
158
        GRADIENT_DELAY);
360
632
    addColor(UserColorId::HIT_PLAYER_PLAYER,
361
        0xff5050,
362
        GradientType::STATIC,
363
       // TRANSLATORS: palette color
364
158
       _("Other player hits local player"),
365
158
        GRADIENT_DELAY);
366
632
    addColor(UserColorId::HIT_CRITICAL,
367
        0xff0000,
368
        GradientType::RAINBOW,
369
        // TRANSLATORS: palette color
370
158
        _("Critical Hit"),
371
158
        GRADIENT_DELAY);
372
632
    addColor(UserColorId::HIT_LOCAL_PLAYER_MONSTER,
373
        0x00ff00,
374
        GradientType::STATIC,
375
        // TRANSLATORS: palette color
376
158
        _("Local player hits monster"),
377
158
        GRADIENT_DELAY);
378
632
    addColor(UserColorId::HIT_LOCAL_PLAYER_CRITICAL,
379
        0xff0000,
380
        GradientType::RAINBOW,
381
        // TRANSLATORS: palette color
382
158
        _("Local player critical hit"),
383
158
        GRADIENT_DELAY);
384
632
    addColor(UserColorId::HIT_LOCAL_PLAYER_MISS,
385
        0x00ffa6,
386
        GradientType::STATIC,
387
        // TRANSLATORS: palette color
388
158
        _("Local player miss"),
389
158
        GRADIENT_DELAY);
390
632
    addColor(UserColorId::MISS, 0xffff00,
391
        GradientType::STATIC,
392
        // TRANSLATORS: palette color
393
158
        _("Misses"),
394
158
        GRADIENT_DELAY);
395
632
    addLabel(UserColorId::LABEL_TILES,
396
        // TRANSLATORS: palette label
397
316
        _("Tiles"));
398
632
    addColor(UserColorId::PORTAL_HIGHLIGHT,
399
        0xC80000,
400
        GradientType::STATIC,
401
        // TRANSLATORS: palette color
402
158
        _("Portal highlight"),
403
158
        GRADIENT_DELAY);
404
632
    addColor(UserColorId::COLLISION_HIGHLIGHT,
405
        0x0000C8,
406
        GradientType::STATIC,
407
        // TRANSLATORS: palette color
408
158
        _("Default collision highlight"),
409
158
        64);
410
632
    addColor(UserColorId::AIR_COLLISION_HIGHLIGHT,
411
        0xe0e0ff,
412
        GradientType::STATIC,
413
        // TRANSLATORS: palette color
414
158
        _("Air collision highlight"),
415
158
        64);
416
632
    addColor(UserColorId::WATER_COLLISION_HIGHLIGHT,
417
        0x2050e0,
418
        GradientType::STATIC,
419
        // TRANSLATORS: palette color
420
158
        _("Water collision highlight"),
421
158
        64);
422
632
    addColor(UserColorId::MONSTER_COLLISION_HIGHLIGHT,
423
        0x2050e0,
424
        GradientType::STATIC,
425
        // TRANSLATORS: palette color
426
158
        _("Monster collision highlight"),
427
158
        64);
428
632
    addColor(UserColorId::GROUNDTOP_COLLISION_HIGHLIGHT,
429
        0xffff00,
430
        GradientType::STATIC,
431
        // TRANSLATORS: palette color
432
158
        _("Special ground collision highlight"),
433
158
        20);
434
632
    addColor(UserColorId::WALKABLE_HIGHLIGHT,
435
        0x00D000,
436
        GradientType::STATIC,
437
        // TRANSLATORS: palette color
438
158
        _("Walkable highlight"),
439
158
        255);
440
632
    addColor(UserColorId::NET,
441
        0x000000,
442
        GradientType::STATIC,
443
        // TRANSLATORS: palette color
444
316
        _("Tiles border"), 64);
445
632
    addLabel(UserColorId::LABEL_RANGES,
446
        // TRANSLATORS: palette label
447
316
        _("Ranges"));
448
632
    addColor(UserColorId::ATTACK_RANGE,
449
        0xffffff,
450
        GradientType::STATIC,
451
        // TRANSLATORS: palette color
452
158
        _("Local player attack range"),
453
158
        5);
454
632
    addColor(UserColorId::ATTACK_RANGE_BORDER,
455
        0x0,
456
        GradientType::STATIC,
457
        // TRANSLATORS: palette color
458
158
        _("Local player attack range border"),
459
158
        76);
460
632
    addColor(UserColorId::MONSTER_ATTACK_RANGE,
461
        0xff0000,
462
        GradientType::STATIC,
463
        // TRANSLATORS: palette color
464
158
        _("Monster attack range"),
465
158
        20);
466
632
    addColor(UserColorId::SKILL_ATTACK_RANGE,
467
        0x0,
468
        GradientType::STATIC,
469
        // TRANSLATORS: palette color
470
158
        _("Skill attack range border"),
471
158
        76);
472
632
    addLabel(UserColorId::LABEL_OTHER,
473
        // TRANSLATORS: palette label
474
316
        _("Other"));
475
632
    addColor(UserColorId::FLOOR_ITEM_TEXT,
476
        0xffffff,
477
        GradientType::STATIC,
478
        // TRANSLATORS: palette color
479
158
        _("Floor item amount color"),
480
158
        100);
481
632
    addColor(UserColorId::HOME_PLACE,
482
        0xffffff,
483
        GradientType::STATIC,
484
        // TRANSLATORS: palette color
485
158
        _("Home place"),
486
158
        20);
487
632
    addColor(UserColorId::HOME_PLACE_BORDER,
488
        0xffff00,
489
        GradientType::STATIC,
490
        // TRANSLATORS: palette color
491
158
        _("Home place border"),
492
158
        200);
493
632
    addColor(UserColorId::ROAD_POINT,
494
        0x000000,
495
        GradientType::STATIC,
496
        // TRANSLATORS: palette color
497
316
        _("Road point"), 100);
498
158
    commit(true);
499
158
}
500
501
632
UserPalette::~UserPalette()
502
{
503
11060
    FOR_EACH (Colors::const_iterator, col, mColors)
504
    {
505
10112
        if (col->grad == GradientType::LABEL)
506
            continue;
507
9006
        const std::string &configName = ColorTypeNames[col->type];
508
18012
        config.setValue(configName + "Gradient",
509
18012
            CAST_S32(col->committedGrad));
510
18012
        config.setValue(configName + "Delay", col->delay);
511
512

9322
        if (col->grad == GradientType::STATIC ||
513
316
            col->grad == GradientType::PULSE)
514
        {
515
            char buffer[20];
516
26070
            snprintf(buffer, sizeof(buffer), "0x%06x", col->getRGB());
517
8690
            buffer[19] = 0;
518
34760
            config.setValue(configName, std::string(buffer));
519
        }
520
    }
521
316
}
522
523
void UserPalette::setColor(const UserColorIdT type,
524
                           const int r,
525
                           const int g,
526
                           const int b)
527
{
528
    Color &color = mColors[CAST_SIZE(type)].color;
529
    color.r = r;
530
    color.g = g;
531
    color.b = b;
532
}
533
534
void UserPalette::setGradient(const UserColorIdT type,
535
                              const GradientTypeT grad)
536
{
537
    ColorElem *const elem = &mColors[CAST_SIZE(type)];
538
539
    if (elem->grad != GradientType::STATIC && grad == GradientType::STATIC)
540
    {
541
        const size_t sz = mGradVector.size();
542
        for (size_t i = 0; i < sz; i++)
543
        {
544
            if (mGradVector[i] == elem)
545
            {
546
                mGradVector.erase(mGradVector.begin() + i);
547
                break;
548
            }
549
        }
550
    }
551
    else if (elem->grad == GradientType::STATIC &&
552
             grad != GradientType::STATIC)
553
    {
554
        mGradVector.push_back(elem);
555
    }
556
557
    if (elem->grad != grad)
558
        elem->grad = grad;
559
}
560
561
std::string UserPalette::getElementAt(int i)
562
{
563
    if (i < 0 || i >= getNumberOfElements())
564
        return "";
565
566
    return mColors[i].text;
567
}
568
569
158
void UserPalette::commit(const bool commitNonStatic)
570
{
571
10744
    FOR_EACH (Colors::iterator, i, mColors)
572
    {
573
10112
        i->committedGrad = i->grad;
574
10112
        i->committedDelay = i->delay;
575

10112
        if (commitNonStatic || i->grad == GradientType::STATIC)
576
10112
            i->committedColor = i->color;
577
        else if (i->grad == GradientType::PULSE)
578
            i->committedColor = i->testColor;
579
    }
580
158
}
581
582
void UserPalette::rollback()
583
{
584
    FOR_EACH (Colors::iterator, i, mColors)
585
    {
586
        if (i->grad != i->committedGrad)
587
            setGradient(static_cast<UserColorIdT>(i->type), i->committedGrad);
588
589
        const Color &committedColor = i->committedColor;
590
        setGradientDelay(static_cast<UserColorIdT>(i->type),
591
            i->committedDelay);
592
        setColor(static_cast<UserColorIdT>(i->type),
593
            committedColor.r,
594
            committedColor.g,
595
            committedColor.b);
596
597
        if (i->grad == GradientType::PULSE)
598
        {
599
            Color &testColor = i->testColor;
600
            testColor.r = committedColor.r;
601
            testColor.g = committedColor.g;
602
            testColor.b = committedColor.b;
603
        }
604
    }
605
}
606
607
int UserPalette::getColorTypeAt(const int i)
608
{
609
    if (i < 0 || i >= getNumberOfElements())
610
        return 0;
611
612
    return mColors[i].type;
613
}
614
615
9006
void UserPalette::addColor(const UserColorIdT type,
616
                           const unsigned rgb,
617
                           GradientTypeT grad,
618
                           const std::string &text,
619
                           int delay)
620
{
621
    const unsigned maxType = sizeof(ColorTypeNames)
622
9006
        / sizeof(ColorTypeNames[0]);
623
624
9006
    if (CAST_U32(type) >= maxType)
625
        return;
626
627
9006
    const std::string &configName = ColorTypeNames[CAST_SIZE(type)];
628
    char buffer[20];
629
9006
    snprintf(buffer, sizeof(buffer), "0x%06x", rgb);
630
9006
    buffer[19] = 0;
631
632
    const std::string rgbString = config.getValue(
633
45030
        configName, std::string(buffer));
634
9006
    unsigned int rgbValue = 0;
635


27018
    if (rgbString.length() == 8 && rgbString[0] == '0' && rgbString[1] == 'x')
636
9006
        rgbValue = atox(rgbString);
637
    else
638
        rgbValue = atoi(rgbString.c_str());
639
9006
    const Color &trueCol = Color(rgbValue);
640
    grad = static_cast<GradientTypeT>(config.getValue(
641
18012
        configName + "Gradient",
642
9006
        CAST_S32(grad)));
643

18012
    delay = config.getValueInt(configName + "Delay", delay);
644
18012
    mColors[CAST_SIZE(type)].set(CAST_S32(type),
645
9006
        trueCol, grad, delay);
646
27018
    mColors[CAST_SIZE(type)].text = text;
647
648
9006
    if (grad != GradientType::STATIC)
649
948
        mGradVector.push_back(&mColors[CAST_SIZE(type)]);
650
}
651
652
1106
void UserPalette::addLabel(const UserColorIdT type,
653
                           const std::string &text)
654
{
655
    const unsigned maxType = sizeof(ColorTypeNames)
656
1106
        / sizeof(ColorTypeNames[0]);
657
658
1106
    if (CAST_U32(type) >= maxType)
659
        return;
660
661
662
3318
    mColors[CAST_SIZE(type)] = ColorElem();
663
    const std::string str(" \342\200\225\342\200\225\342\200\225"
664
4424
        "\342\200\225\342\200\225 ");
665
2212
    mColors[CAST_SIZE(type)].grad = GradientType::LABEL;
666
2212
    mColors[CAST_SIZE(type)].text =
667
6636
        std::string(str).append(text).append(str);
668
}
669
670
int UserPalette::getIdByChar(const signed char c, bool &valid) const
671
{
672
    const CharColors::const_iterator it = mCharColors.find(c);
673
    if (it != mCharColors.end())
674
    {
675
        valid = true;
676
        return (*it).second;
677
    }
678
679
    valid = false;
680
    return 0;
681

3
}