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
































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

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

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


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

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

3
}