Subversion Repositories tpanel

Rev

Rev 446 | Rev 479 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
446 andreas 1
/*
2
 * Copyright (C) 2020 to 2024 by Andreas Theofilu <andreas@theosys.at>
3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software Foundation,
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
17
 */
18
#ifndef __TBUTTON_H__
19
#define __TBUTTON_H__
20
 
21
#include <string>
22
#include <vector>
23
#include <map>
24
#include <functional>
25
#include <thread>
26
 
27
#include <include/core/SkImage.h>
28
#include <include/core/SkCanvas.h>
29
#include <include/core/SkBitmap.h>
30
 
31
#include "texpat++.h"
32
#include "tpalette.h"
33
#include "tcolor.h"
34
#include "tfont.h"
35
#include "tamxnet.h"
36
#include "ttimer.h"
37
#include "timagerefresh.h"
38
#include "tsystem.h"
39
#include "tintborder.h"
40
#include "tsystemdraw.h"
41
 
42
#define ORD_ELEM_COUNT  5
43
 
44
extern bool prg_stopped;
45
extern bool _restart_;
46
 
47
class SkFont;
48
class SkTextBlob;
49
class TBitmap;
50
class TButtonStates;
51
 
52
struct RESOURCE_T;
53
 
54
namespace Button
55
{
56
#   define STATE_BASE   0
57
#   define STATE_OFF    0
58
#   define STATE_ON     1
59
#   define STATE_1      0
60
#   define STATE_2      1
61
#   define STATE_3      2
62
#   define STATE_4      3
63
#   define STATE_5      4
64
#   define STATE_6      5
65
#   define STATE_7      6
66
#   define STATE_8      7
67
#   define STATE_ALL    -1
68
 
69
#   define HANDLE_UNDEF 0
70
 
71
    typedef struct SYSTEF_t         // Text effect names
72
    {
73
        int idx{0};
74
        std::string name;
75
    }SYSTEF_t;
76
 
77
    typedef enum TEXT_ORIENTATION
78
    {
79
        ORI_ABSOLUT,
80
        ORI_TOP_LEFT,
81
        ORI_TOP_MIDDLE,
82
        ORI_TOP_RIGHT,
83
        ORI_CENTER_LEFT,
84
        ORI_CENTER_MIDDLE,		// default
85
        ORI_CENTER_RIGHT,
86
        ORI_BOTTOM_LEFT,
87
        ORI_BOTTOM_MIDDLE,
88
        ORI_BOTTOM_RIGHT
89
    } TEXT_ORIENTATION;
90
 
91
    typedef enum TEXT_EFFECT
92
    {
93
        EFFECT_NONE,
94
        EFFECT_OUTLINE_S,
95
        EFFECT_OUTLINE_M,
96
        EFFECT_OUTLINE_L,
97
        EFFECT_OUTLINE_X,
98
        EFFECT_GLOW_S,
99
        EFFECT_GLOW_M,
100
        EFFECT_GLOW_L,
101
        EFFECT_GLOW_X,
102
        EFFECT_SOFT_DROP_SHADOW_1,
103
        EFFECT_SOFT_DROP_SHADOW_2,
104
        EFFECT_SOFT_DROP_SHADOW_3,
105
        EFFECT_SOFT_DROP_SHADOW_4,
106
        EFFECT_SOFT_DROP_SHADOW_5,
107
        EFFECT_SOFT_DROP_SHADOW_6,
108
        EFFECT_SOFT_DROP_SHADOW_7,
109
        EFFECT_SOFT_DROP_SHADOW_8,
110
        EFFECT_MEDIUM_DROP_SHADOW_1,
111
        EFFECT_MEDIUM_DROP_SHADOW_2,
112
        EFFECT_MEDIUM_DROP_SHADOW_3,
113
        EFFECT_MEDIUM_DROP_SHADOW_4,
114
        EFFECT_MEDIUM_DROP_SHADOW_5,
115
        EFFECT_MEDIUM_DROP_SHADOW_6,
116
        EFFECT_MEDIUM_DROP_SHADOW_7,
117
        EFFECT_MEDIUM_DROP_SHADOW_8,
118
        EFFECT_HARD_DROP_SHADOW_1,
119
        EFFECT_HARD_DROP_SHADOW_2,
120
        EFFECT_HARD_DROP_SHADOW_3,
121
        EFFECT_HARD_DROP_SHADOW_4,
122
        EFFECT_HARD_DROP_SHADOW_5,
123
        EFFECT_HARD_DROP_SHADOW_6,
124
        EFFECT_HARD_DROP_SHADOW_7,
125
        EFFECT_HARD_DROP_SHADOW_8,
126
        EFFECT_SOFT_DROP_SHADOW_1_WITH_OUTLINE,
127
        EFFECT_SOFT_DROP_SHADOW_2_WITH_OUTLINE,
128
        EFFECT_SOFT_DROP_SHADOW_3_WITH_OUTLINE,
129
        EFFECT_SOFT_DROP_SHADOW_4_WITH_OUTLINE,
130
        EFFECT_SOFT_DROP_SHADOW_5_WITH_OUTLINE,
131
        EFFECT_SOFT_DROP_SHADOW_6_WITH_OUTLINE,
132
        EFFECT_SOFT_DROP_SHADOW_7_WITH_OUTLINE,
133
        EFFECT_SOFT_DROP_SHADOW_8_WITH_OUTLINE,
134
        EFFECT_MEDIUM_DROP_SHADOW_1_WITH_OUTLINE,
135
        EFFECT_MEDIUM_DROP_SHADOW_2_WITH_OUTLINE,
136
        EFFECT_MEDIUM_DROP_SHADOW_3_WITH_OUTLINE,
137
        EFFECT_MEDIUM_DROP_SHADOW_4_WITH_OUTLINE,
138
        EFFECT_MEDIUM_DROP_SHADOW_5_WITH_OUTLINE,
139
        EFFECT_MEDIUM_DROP_SHADOW_6_WITH_OUTLINE,
140
        EFFECT_MEDIUM_DROP_SHADOW_7_WITH_OUTLINE,
141
        EFFECT_MEDIUM_DROP_SHADOW_8_WITH_OUTLINE,
142
        EFFECT_HARD_DROP_SHADOW_1_WITH_OUTLINE,
143
        EFFECT_HARD_DROP_SHADOW_2_WITH_OUTLINE,
144
        EFFECT_HARD_DROP_SHADOW_3_WITH_OUTLINE,
145
        EFFECT_HARD_DROP_SHADOW_4_WITH_OUTLINE,
146
        EFFECT_HARD_DROP_SHADOW_5_WITH_OUTLINE,
147
        EFFECT_HARD_DROP_SHADOW_6_WITH_OUTLINE,
148
        EFFECT_HARD_DROP_SHADOW_7_WITH_OUTLINE,
149
        EFFECT_HARD_DROP_SHADOW_8_WITH_OUTLINE
150
    }TEXT_EFFECT;
151
 
152
    typedef enum DRAW_ORDER
153
    {
154
        ORD_ELEM_NONE,
155
        ORD_ELEM_FILL,
156
        ORD_ELEM_BITMAP,
157
        ORD_ELEM_ICON,
158
        ORD_ELEM_TEXT,
159
        ORD_ELEM_BORDER
160
    }DRAW_ORDER;
161
 
162
    typedef enum FEEDBACK
163
    {
164
        FB_NONE,
165
        FB_CHANNEL,
166
        FB_INV_CHANNEL,     // inverted channel
167
        FB_ALWAYS_ON,
168
        FB_MOMENTARY,
169
        FB_BLINK
170
    } FEEDBACK;
171
 
172
    typedef enum PMIX
173
    {
174
        PMIX_MULTIPLY,
175
        PMIX_XOR,
176
        PMIX_SCREEN,
177
        PMIX_SRC,
178
        PMIX_DST,
179
        PMIX_SRCOVER,
180
        PMIX_SRCTOP,
181
        PMIX_DSTTOP,
182
        PMIX_PLUS
183
    }PMIX;
184
 
185
    typedef enum SUBVIEW_POSITION_t
186
    {
187
        SVP_CENTER,
188
        SVP_LEFT_TOP,
189
        SVP_RIGHT_BOTTOM
190
    }SUBVIEW_POSITION_t;
191
 
192
    typedef struct SR_T
193
    {
194
        int number{0};
195
        std::string _do;        // Order on how to show a multistate bargraph (010203...)
196
        std::string bs;         // Frame type (circle, ...)
197
        std::string mi;         // Chameleon image
198
        int mi_width{0};        // Width of image
199
        int mi_height{0};       // Height of image
200
        std::string cb;         // Border color
201
        std::string cf;         // Fill color
202
        std::string ct;         // Text Color
203
        std::string ec;         // Text effect color
204
        std::string bm;         // bitmap file name
462 andreas 205
        std::vector<std::string> bitmaps;   // G5 table of bitmaps
446 andreas 206
        std::string sd;         // Sound file to play
207
        int bm_width{0};        // Width of image
208
        int bm_height{0};       // Height of image
209
        bool dynamic{false};    // TRUE = moving image
210
        int sb{0};              // Index to external graphics download
211
        int ii{0};              // Icon index number
212
        int ix{0};              // Icon X position
213
        int iy{0};              // Icon Y position
214
        int ji{5};              // Icon style / position like "jt", default 5 = center+middle
215
        int jb{5};              // Image position (center, left, ...), default 5 = center+middle
216
        int bx{0};              // Absolute image position x
217
        int by{0};              // Absolute image position y
218
        int fi{0};              // Font index
219
        std::string te;         // Text
220
        TEXT_ORIENTATION jt{ORI_CENTER_MIDDLE}; // Text orientation
221
        int tx{0};              // Text X position
222
        int ty{0};              // Text Y position
462 andreas 223
        std::string ff;         // G5 font file name
224
        int fs{0};              // G5 font size
446 andreas 225
        int ww{0};              // line break when 1
226
        int et{0};              // Text effect (^TEF)
227
        int oo{-1};             // Over all opacity
228
        int md{0};              // Marquee type: 1 = scroll left, 2 = scroll right, 3 = ping pong, 4 = scroll up, 5 = scroll down
229
        int mr{0};              // Marquee enabled: 1 = enabled, 0 = disabled
230
        int ms{1};              // Marquee speed: Range: 1 to 10 (look for command ^MSP to see of how to set this)
231
    } SR_T;
232
 
233
    typedef struct EXTBUTTON_t
234
    {
235
        BUTTONTYPE type;
236
        int bi{0};              // button ID
237
        std::string na;         // name
238
        int lt{0};              // pixel from left
239
        int tp{0};              // pixel from top
240
        int wt{0};              // width
241
        int ht{0};              // height
242
        int zo{0};              // Z-Order
243
        std::string hs;         // bounding, ...
244
        std::string bs;         // Border style (circle, ...)
245
        FEEDBACK fb{FB_NONE};   // Feedback type (momentary, ...)
246
        int ap{1};              // Address port (default: 1)
247
        int ad{0};              // Address channel
248
        int lp{1};              // Level port (default: 1)
249
        int lv{0};              // Level code
250
        std::string dr;         // Level "horizontal" or "vertical"
251
        int lu{0};              // Animate time up (Bargraph)
252
        int ld{0};              // Animate time down (Bargraph)
253
        int rl{0};              // Range low
254
        int rh{0};              // Range high
255
        int rn{0};              // Bargraph: Range drag increment
256
        std::string sc;         // Color of slider (for bargraph)
257
        std::vector<SR_T> sr;
258
    }EXTBUTTON_t;
259
 
260
    typedef struct PUSH_FUNC
261
    {
262
        std::string pfType; // command to execute when button was pushed
263
        std::string pfName; // Name of popup
264
    } PUSH_FUNC_T;
265
 
266
    typedef enum CENTER_CODE
267
    {
268
        SC_ICON = 0,
269
        SC_BITMAP,
270
        SC_TEXT
271
    }CENTER_CODE;
272
 
273
    typedef struct POSITION_t
274
    {
275
        int width{0};
276
        int height{0};
277
        int left{1};
278
        int top{1};
279
        bool overflow{false};
280
        bool valid{false};
281
    }POSITION_t;
282
 
283
    typedef struct POINT_t
284
    {
285
        int x{0};
286
        int y{0};
287
    }POINT_t;
288
 
289
    typedef struct IMAGE_SIZE_t
290
    {
291
        int width{0};
292
        int height{0};
293
    }IMAGE_SIZE_t;
294
 
295
    typedef struct THR_REFRESH_t
296
    {
297
        ulong handle{0};
298
        ulong parent{0};
299
        int bi{0};
300
        TImageRefresh *mImageRefresh{nullptr};
301
        THR_REFRESH_t *next{nullptr};
302
    }THR_REFRESH_t;
303
 
304
    typedef struct BITMAP_t
305
    {
306
        unsigned char *buffer{nullptr};
307
        int left{0};
308
        int top{0};
309
        int width{0};
310
        int height{0};
311
        size_t rowBytes{0};
312
    }BITMAP_t;
313
 
314
    typedef struct BITMAP_CACHE
315
    {
316
        ulong handle{0};
317
        ulong parent{0};
318
        int left{0};
319
        int top{0};
320
        int width{0};
321
        int height{0};
322
        int bi{0};
323
        bool show{false};
324
        bool ready{false};
325
        SkBitmap bitmap;
326
    }BITMAP_CACHE;
327
 
328
#   define LIST_IMAGE_CELL     1
329
#   define LIST_TEXT_PRIMARY   2
330
#   define LIST_TEXT_SECONDARY 4
331
 
332
    typedef enum LIST_SORT
333
    {
334
        LIST_SORT_NONE,
335
        LIST_SORT_ASC,
336
        LIST_SORT_DESC,
337
        LIST_SORT_OVERRIDE
338
    }LIST_SORT;
339
 
340
    class TButton : public TSystem, public Border::TIntBorder
341
    {
342
        public:
343
            TButton();
344
            ~TButton();
345
 
346
            /**
347
             * The following function parses the parameters of a particular
348
             * button and creates a new button. This function is called either
349
             * from class TPage or TSubPage when a page or subpage is created.
350
             *
351
             * @param xml     A pointer to the XML reader
352
             * @param node    A pointer to the actual node in the XML tree.
353
             * @return On success the last index processed. On error
354
             * TExpat::npos is returned.
355
             */
356
            size_t initialize(Expat::TExpat *xml, size_t index);
357
 
358
            /**
359
             * Returns the button index. This is a unique number inside a page
360
             * or subpage.
361
             *
362
             * @return return the button index number as defined in the
363
             * configuration file.
364
             */
365
            int getButtonIndex() { return bi; }
366
            /**
367
             * Returns the name of the button.
368
             */
369
            std::string& getButtonName() { return na; }
370
            /**
371
             * Returns the description of the button, if there is one.
372
             */
373
            std::string& getButtonDescription() { return bd; }
374
            /**
375
             * Returns the width of the button in pixels.
376
             */
377
            int getWidth() { return wt; }
378
            /**
379
             * Returns the height of the button in pixels.
380
             */
381
            int getHeight() { return ht; }
382
            /**
383
             * Returns the left position in pixels.
384
             */
385
            int getLeftPosition() { return mPosLeft; }
386
            /**
387
             * Returns the top position of the button in pixels.
388
             */
389
            int getTopPosition() { return mPosTop; }
390
            /**
391
             * Returns the original left position.
392
             */
393
            int getLeftOriginPosition() { return lt; }
394
            /**
395
             * Returns the original top position.
396
             */
397
            int getTopOriginPosition() { return tp; }
398
            /**
399
             * Returns the Z-order. This number marks the order the buttons
400
             * are drawed on the screen. Inside a page or subpage the buttons
401
             * are always sorted.
402
             */
403
            int getZOrder() { return zo; }
404
            /**
405
             * Returns the type of the button.
406
             */
407
            BUTTONTYPE getButtonType() { return type; }
408
            /**
409
             * Set font file name and optional the size
410
             *
411
             * @param name  File name of the font
412
             * @param size  The size of the font in PT
413
             * @param inst  The instance of the button
414
             *
415
             * @return TRUE success
416
             */
417
            bool setFontFileName(const std::string& name, int size, int inst);
418
            /**
419
             * Set font name.
420
             *
421
             * @param name  The font name
422
             * @param inst  The instance of the button
423
             *
424
             * @return TRUE success
425
             */
426
            bool setFontName(const std::string& name, int inst);
427
 
428
            std::string& getName() { return na; }
429
            int getRangeLow() { return rl; }
430
            int getRangeHigh() { return rh; }
431
            int getLevelRangeUp() { return ru; }
432
            int getLevelRangeDown() { return rd; }
433
            int getStateCount() { return stateCount; }
434
            int getAddressPort() { return ap; }
435
            int getAddressChannel() { return ad; }
436
            int getChannelNumber() { return ch; }
437
            int getChannelPort() { return cp; }
438
            int getLevelPort() { return lp; }
439
            int getLevelChannel() { return lv; }
440
            bool isBargraphInverted() { return (ri != 0); }
441
            bool isJoystickAuxInverted() { return (ji != 0); }
442
            int getLevelValue();
443
            void setLevelValue(int level);
444
            int getLevelAxisX();
445
            int getLevelAxisY();
446
            uint32_t getButtonID() { return mButtonID; }
447
            std::string getButtonIDstr(uint32_t rid=0x1fffffff);
448
            std::string& getLevelFuction() { return lf; }
449
            std::string getText(int inst=0);
450
            std::string getTextColor(int inst=0);
451
            std::string getTextEffectColor(int inst=0);
452
            void setTextEffectColor(const std::string& ec, int inst=-1);
453
            bool setTextEffectColorOnly(const std::string& ec, int inst=-1);
454
            int getTextEffect(int inst=0);
455
            void setTextEffect(int et, int inst=-1);
456
            std::string getTextEffectName(int inst=0);
457
            void setTextEffectName(const std::string& name, int inst=-1);
458
            std::string getFillColor(int inst=0);
459
            std::string getBitmapName(int inst=0);
460
            bool isSingleLine() { return ( dt.compare("multiple") != 0); }
461
            bool isMultiLine() { return ( dt.compare("multiple") == 0); }
462
            int getTextMaxChars() { return mt; }
463
            void setTextMaxChars(int m) { mt = m; }
464
            bool getTextWordWrap(int inst=0);
465
            bool setTextWordWrap(bool ww, int inst=-1);
466
            void setMarqueeSpeed(int speed, int inst=-1);
467
            int getMarqueeSpeed(int inst=0);
468
            int getFontIndex(int inst=0);
469
            bool setFontIndex(int fi, int inst=-1);
470
            int getIconIndex(int inst=0);
471
            std::string getSound(int inst=0);
472
            void setSound(const std::string& sd, int inst=-1);
473
            bool getDynamic(int inst=0);
474
            void setDynamic(int d, int inst=-1);
475
            int getNumberInstances() { return (int)sr.size(); }
476
            int getActiveInstance() { return mActInstance; }
477
            ulong getHandle() { return mHandle; }
478
            ulong getParent() { return (mHandle & 0xffff0000); }
479
            void setActiveInstance(int inst);
480
            void setEnable(bool en) { mEnabled = en; }
481
            bool isEnabled() { return mEnabled; }
482
            void setHandle(ulong handle) { mHandle = handle; };
483
            void setPalette(TPalette *pal) { mPalette = pal; }
484
            void setParentWidth(int width) { mParentWidth = width; }
485
            void setParentHeight(int height) { mParentHeight = height; }
486
            void setParentSize(int width, int height) { mParentWidth = width; mParentHeight = height; }
487
            void setFonts(TFont *ft) { mFonts = ft; }
488
            void setGlobalOpacity(int oo) { if (oo >= 0 && oo <= 255) mGlobalOO = oo; }
489
            void setVisible(bool v) { visible = v; hd = (v ? 0 : 1); }
490
            bool isVisible() { return visible; }
491
            bool isSubViewVertical() { return on == "vert"; }
492
            bool haveListContent() { return _getListContent != nullptr; }
493
            bool haveListRow() { return _getListRow != nullptr; }
494
            int getSubViewID() { return st; }
495
            bool getSubViewScrollbar() { return (ba == 1 ? true : false); }
496
            int getSubViewScrollbarOffset() { return (ba > 0 ? bo : 0); }
497
            bool getWrapSubViewPages() { return (ws != 0 ? true : false); }
498
            bool isFocused() { return mHasFocus; }
499
            int getTextCursorPosition() { return mCursorPosition; }
500
            void setChanged(bool ch) { mChanged = ch; }
501
            SUBVIEW_POSITION_t getSubViewAnchor();
502
            std::function<std::vector<std::string>(ulong handle, int ap, int ta, int ti, int rows, int columns)> getCallbackListContent() { return _getListContent; }
503
            std::function<std::string(int ti, int row)> getCallbackListRow() { return _getListRow; }
504
            std::function<void (TButton *button)> getCallbackGlobalSettings() { return _getGlobalSettings; };
505
 
506
            /**
507
             * @brief setBitmap Sets a new bitmap to the button
508
             * If there was already a bitmap on this button and if this bitmap
509
             * is different from the one in \p file, then it is erased.
510
             * The new bitmap file name is set and it will be loaded and created.
511
             *
512
             * @param file      File name of a bitmap file.
513
             * @param instance  The instance where to put the new bitmap. If
514
             *                  this is 0, the bitmap is set on all instances.
515
             * @return TRUE if no errors occures, otherwise FALSE.
516
             */
517
            bool setBitmap(const std::string& file, int instance);
518
            /**
519
             * @brief setCameleon Sets a new cameleon bitmap to the button
520
             * If there was already a cameleon bitmap on this button and if this
521
             * cameleon bitmap is different from the one in \p file, then it is
522
             * erased. The new cameleon bitmap file name is set and it will be
523
             * loaded and created.
524
             *
525
             * @param file      File name of a cameleon bitmap file.
526
             * @param instance  The instance where to put the new bitmap. If
527
             *                  this is 0, the bitmap is set on all instances.
528
             * @return TRUE if no errors occures, otherwise FALSE.
529
             */
530
            bool setCameleon(const std::string& file, int instance);
531
            /**
532
             * @brief setOpacity Sets the opacity of this button
533
             *
534
             * @param op        The opacity in a reange of 0 to 255.
535
             * @param instance  The instance where to put the new bitmap. If
536
             *                  this is 0, the bitmap is set on all instances.
537
             * @return TRUE if no errors occures, otherwise FALSE.
538
             */
539
            bool setOpacity(int op, int instance);
540
            int getOpacity(int inst=0);
541
            int getListAp() { return ap; }
542
            int getListTa() { return ta; }
543
            int getListTi() { return ti; }
544
            int getListNumRows() { return tr; }
545
            int getListNumCols() { return tc; }
546
            int getSubViewSpace() { return sa; }
547
            std::string getBounding() { return hs; }
548
            bool setFont(int id, int instance);
549
            bool setFontOnly(int id, int instance);
550
            void setTop(int top);
551
            void setLeft(int left);
552
            void setLeftTop(int left, int top);
553
            void setRectangle(int left, int top, int right, int bottom);
554
            void getRectangle(int *left, int *top, int *height, int *width);
555
            void resetButton();
556
            void setResourceName(const std::string& name, int instance);
557
            int getBitmapJustification(int *x, int *y, int instance);
558
            void setBitmapJustification(int j, int x, int y, int instance);
559
            int getIconJustification(int *x, int *y, int instance);
560
            void setIconJustification(int j, int x, int y, int instance);
561
            int getTextJustification(int *x, int *y, int instance);
562
            void setTextJustification(int j, int x, int y, int instance);
563
            bool setTextJustificationOnly(int j, int x, int y, int instance);
564
            bool startAnimation(int start, int end, int time);
565
            /**
566
             * @brief registerSystemButton registers the button as a system button.
567
             *
568
             * If the button is a system button, than it has special functions.
569
             * The action of the button depends on the kind of system button.
570
             */
571
            void registerSystemButton();
572
            bool isSystemButton();
573
            void addPushFunction(std::string& func, std::string& page);
574
            void clearPushFunctions() { pushFunc.clear(); }
575
            void clearPushFunction(const std::string& action);
576
            void refresh();
577
            /**
578
             * Sets a particular instance of the button active. This implies
579
             * a redraw of the button in case the instance is different from
580
             * the one already visible.
581
             *
582
             * @param instance
583
             * The instance of the button to be activated.
584
             *
585
             * @return
586
             * On error returns FALSE.
587
             */
588
            bool setActive(int instance);
589
            /**
590
             * Sets an Icon on the button. This implies a redraw of the button
591
             * in case the instance is different from the one already visible.
592
             *
593
             * @param id
594
             * The id number of the icon.
595
             *
596
             * @param instance
597
             * The instance where the icon should be drawed
598
             *
599
             * @return On error returns FALSE.
600
             */
601
            bool setIcon(int id, int instance);
602
            /**
603
             * Sets an Icon on the button. This implies a redraw of the button
604
             * in case the instance is different from the one already visible.
605
             *
606
             * @param icon
607
             * The file name of the icon.
608
             *
609
             * @param instance
610
             * The instance where the icon should be drawed
611
             *
612
             * @return
613
             * On error returns FALSE.
614
             */
615
            bool setIcon(const std::string& icon, int instance);
616
            /**
617
             * Removes an icon from a button. This implies a redraw of the
618
             * button.
619
             *
620
             * @param instance
621
             * The instance number involved.
622
             *
623
             * @return
624
             * On error returns FALSE.
625
             */
626
            bool revokeIcon(int instance);
627
            /**
628
             * Set a string to a button.
629
             *
630
             * @param txt
631
             * The text to write on top of  a button.
632
             *
633
             * @param instance
634
             * The instance number involved.
635
             *
636
             * @return
637
             * On error returns FALSE.
638
             */
639
            bool setText(const std::string& txt, int instance);
640
            /**
641
             * Set a string to a button. This method does not trigger a new
642
             * drawing of the element.
643
             *
644
             * @param txt
645
             * The text to write on top of  a button.
646
             *
647
             * @param instance
648
             * The instance number involved.
649
             *
650
             * @return
651
             * On error returns FALSE.
652
             */
653
            bool setTextOnly(const std::string& txt, int instance);
654
            /**
655
             * @brief appendText    Append non-unicode text.
656
             * @param txt
657
             * The text to write on top of  a button.
658
             * @param instance
659
             * The instance number involved.
660
             * @return
661
             * On error returns FALSE.
662
             */
663
            bool appendText(const std::string& txt, int instance);
664
            /**
665
             * @brief setTextCursorPosition - Set curso position
666
             * If the button element is of type TEXT_INPUT, this method sets
667
             * the cursor position. This position comes usually from an input
668
             * line managed by the graphical surface.
669
             * If the \b newPos is less then 0 the curser is set in front of the
670
             * first character. If the value \b newPos is grater then the number
671
             * of characters then the curser is set after the last character.
672
             *
673
             * @param oldPos    The old position of the cursor
674
             * @param newPos    The new position of the cursor
675
             */
676
            void setTextCursorPosition(int oldPos, int newPos);
677
            /**
678
             * @brief setTextFocus - Focus of input line changed
679
             * If the button element is of type TEXT_INPUT, this signals the
680
             * state of the focus. If \b in is TRUE then the input line got
681
             * the focus. The ON state of the button is send. If there is
682
             * a keyboard present the line is then related to this keyboard.
683
             * If \b in is FALSE the input line lost the focus. The off state
684
             * is displayed and no more characters are received from a
685
             * keyboard.
686
             * If this input line is a system input line, the focus is ignored.
687
             * It then receives always the keystrokes from a keyboard.
688
             *
689
             * @param in    TRUE: Input line got focus, FALSE: input line
690
             *              lost focus.
691
             */
692
            void setTextFocus(bool in);
693
            /**
694
             * @brief setBorderColor Set the border color.
695
             * Set the border color to the specified color. Only if the
696
             * specified border color is not the same as the current color.
697
             * Note: Color can be assigned by color name (without spaces),
698
             * number or R,G,B value (RRGGBB or RRGGBBAA).
699
             * @param color     the color
700
             * @param instance
701
             * The instance number involved.
702
             * @return
703
             * On error returns FALSE.
704
             */
705
            bool setBorderColor(const std::string& color, int instance);
706
            /**
707
             * @brief retrieves the current border color.
708
             * Determines the current border color of the button and returns
709
             * the color as a string.
710
             * @param instance  The instance number of the button.
711
             * @return
712
             * If everything went well it returns the color string of the button
713
             * instance. On error an empty string is returned.
714
             */
715
            std::string getBorderColor(int instance);
716
            /**
717
             * @brief setFillColor Set the fill color.
718
             * Set the fill color to the specified color. Only if the
719
             * specified fill color is not the same as the current color.
720
             * Note: Color can be assigned by color name (without spaces),
721
             * number or R,G,B value (RRGGBB or RRGGBBAA).
722
             * @param color     the color
723
             * @param instance
724
             * The instance number involved.
725
             * @return
726
             * On error returns FALSE.
727
             */
728
            bool setFillColor(const std::string& color, int instance);
729
            /**
730
             * @brief setTextColor set the text color.
731
             * Set the text color to the specified color. Only if the
732
             * specified text color is not the same as the current color. It
733
             * redraws the button if the color changed.
734
             * Note: Color can be assigned by color name (without spaces),
735
             * number or R,G,B value (RRGGBB or RRGGBBAA).
736
             * @param color     the color
737
             * @param instance
738
             * The instance number involved.
739
             * @return
740
             * On error returns FALSE.
741
             */
742
            bool setTextColor(const std::string& color, int instance);
743
            /**
744
             * @brief setTextColorOnly set the text color only.
745
             * Set the text color to the specified color. Only if the
746
             * specified text color is not the same as the current color.
747
             * Note: Color can be assigned by color name (without spaces),
748
             * number or R,G,B value (RRGGBB or RRGGBBAA).
749
             * @param color     the color
750
             * @param instance
751
             * The instance number involved.
752
             * @return
753
             * On error returns FALSE.
754
             */
755
            bool setTextColorOnly(const std::string& color, int instance);
756
            /**
757
             * @brief setDrawOrder - Set the button draw order.
758
             * Determines what order each layer of the button is drawn.
759
             * @param order     the draw order
760
             * @param instance
761
             * The instance number involved.
762
             * @return
763
             * On error returns FALSE.
764
             */
765
            bool setDrawOrder(const std::string& order, int instance);
766
            /**
767
             * @brief setFeedback - Set the feedback type of the button.
768
             * ONLY works on General-type buttons.
769
             * @param fb    The feedback type
770
             * @return On error returns FALSE.
771
             */
772
            bool setFeedback(FEEDBACK feedback);
773
            /**
774
             * @brief setFeedback - Sets the feedback type.
775
             * This retrieves the feedback type of a button. Only if the button
776
             * is a general type one, a valid value is returned.
777
             *
778
             * @return The feedback type of a button.
779
             */
780
            FEEDBACK getFeedback();
781
            /**
782
             * Set a border to a specific border style associated with a border
783
             * value for those buttons with a defined address range.
784
             * @param style     The name of the border style
785
             * @param instance  -1 = style for all instances
786
             * > 0 means the style is valid only for this instance.
787
             */
788
            bool setBorderStyle(const std::string& style, int instance=-1);
789
            /**
790
             * Set a border to a specific border style associated with a border
791
             * value for those buttons with a defined address range.
792
             * @param style     The index number of the border style
793
             * @param instance  -1 = style for all instances
794
             * > 0 means the style is valid only for this instance.
795
             */
796
            bool setBorderStyle(int style, int instance=-1);
797
            /**
798
             * Retrieves the border style, if any, of the instance \p instance
799
             * and returns it.
800
             * @param instance  The instance from where the border style is
801
             *                  wanted. This value must be between 1 and the
802
             *                  number of available instances.
803
             * @return The border style if there is any or an empty string.
804
             */
805
            std::string getBorderStyle(int instance=-1);
806
            /**
807
             * Set the bargraph upper limit. Range = 1 to 65535.
808
             * @param limit the new limit
809
             * @return TRUE on success.
810
             */
811
            bool setBargraphUpperLimit(int limit);
812
            /**
813
             * Set the bargraph lower limit. Range = 1 to 65535.
814
             * @param limit the new limit
815
             * @return TRUE on success.
816
             */
817
            bool setBargraphLowerLimit(int limit);
818
            /**
819
             * Change the bargraph slider color or joystick cursor color.
820
             * A user can also assign the color by Name and R,G,B value
821
             * (RRGGBB or RRGGBBAA).
822
             * @param color     The color value.
823
             * @return TRUE on success.
824
             */
825
            bool setBargraphSliderColor(const std::string& color);
826
            /**
827
             * Set the name of the bargraph slider name or the joystick cursor
828
             * name.
829
             * @param name  The name of the slider/cursor.
830
             * @return TRUE on success.
831
             */
832
            bool setBargraphSliderName(const std::string& name);
833
            /**
834
             * Sets the input mask for the text area. This method has no
835
             * effect on any non input button.
836
             * @param mask  The mask.
837
             * @return If all mask letters are valid it returns TRUE.
838
             */
839
            bool setInputMask(const std::string& mask);
840
            /**
841
             * Returns the input mask of the button.
842
             * @rturn The input mask of the text area, if there is any. If
843
             * there is no input mask present, an empty string is returned.
844
             */
845
            std::string& getInputMask() { return im; }
846
            /**
847
             * Read the images, if any, from files and create an image. If there
848
             * are no files, draw the image as defined.
849
             *
850
             * @param force
851
             * This parameter forces the function to reload the image. This is
852
             * necessary if the image of the button was changed by a command.
853
             * This parameter is optional. Defaults to FALSE.
854
             *
855
             * @return
856
             * On error returns FALSE.
857
             */
858
            bool createButtons(bool force = false);
859
            /**
860
             * Register a callback function to display a ready image. This
861
             * function is used for nearly every kind of button or bargraph.
862
             * It is up to the surface to bring the buttons to screen.
863
             */
864
            void registerCallback(std::function<void (ulong handle, ulong parent, TBitmap buffer, int width, int height, int left, int top, bool passthrough, int marqtype, int marq)> displayButton)
865
            {
866
                _displayButton = displayButton;
867
            }
868
            /**
869
             * Register a callback function to display a video on a special
870
             * button. It is up to the surface to display a video. So the
871
             * callback passes only the size, position and the url together
872
             * with a user name and password, if there is one.
873
             */
874
            void regCallPlayVideo(std::function<void (ulong handle, ulong parent, int left, int top, int width, int height, const std::string& url, const std::string& user, const std::string& pw)> playVideo) { _playVideo = playVideo; };
875
            /**
876
             * Registers a callback function to get the content of a list.
877
             * This function is called to get from the parent the content of
878
             * a list.
879
             */
880
            void regCallListContent(std::function<std::vector<std::string>(ulong handle, int ap, int ta, int ti, int rows, int columns)> getListCtnt) { _getListContent = getListCtnt; }
881
            /**
882
             * Registers a callback function to get the global settings of the
883
             * global page/subpage.
884
             */
885
            void regCallGlobalSettings(std::function<void (TButton *button)> getGlobalSettings) { _getGlobalSettings = getGlobalSettings; };
886
            /**
887
             * Registers a callback function to get the content of a particular
888
             * row of the list. This function is called for each row detected
889
             * in a list. If a row contains more than one column then the
890
             * columns are separated by a "|" symbol.
891
             */
892
            void regCallListRow(std::function<std::string(int ti, int row)> getListRow) { _getListRow = getListRow; }
893
            /**
894
             * @brief Registers a callback which will be called on every button
895
             * press.
896
             * This is used for system buttons to catch the keyboard keys.
897
             *
898
             * @param buttonPress The function pointer.
899
             */
900
            void regCallButtonPress(std::function<void(int channel, uint handle, bool pressed)> buttonPress) { _buttonPress = buttonPress; }
901
            /**
902
             * Make a pixel array and call the callback function to display the
903
             * image. If there is no callback function registered, nothing
904
             * happens.
905
             * This method draws a general button. It is used for most
906
             * specialized buttons too.
907
             *
908
             * @param instance
909
             * Optional. The instance of the button to draw. If the base
910
             * instance should be drawn, the parameter can be omitted.
911
             *
912
             * @param show
913
             * Optional. By defualt TRUE. If set to FALSE, the button image is
914
             * not send to GUI. The image is available in the variable
915
             * "mLastImage" immediately after ending the method.
916
             *
917
             * @param subview
918
             * Optional. If this is set to true, an internal marker is set to
919
             * mark the button as part of a subview. If it is pressed, it calls
920
             * another function to show the changed state.
921
             *
922
             * @return
923
             * On error returns FALSE.
924
             */
925
            bool drawButton(int instance=0, bool show=true, bool subview=false);
926
            /**
927
             * Creates a pixel array and holds it for access through a callback
928
             * function which receives this class as a whole. The callback
929
             * function displays a keyboard and handles input to this text area.
930
             * The created image can be obtained by calling the function
931
             * getLastImage().
932
             *
933
             * @param instance
934
             * Optional. The instance of the button to draw. If the base
935
             * instance should be drawn, the parameter can be omitted.
936
             *
937
             * @param show
938
             * Optional. By defualt TRUE. If set to FALSE, the button image is
939
             * not send to GUI. The image is available in the variable
940
             * "mLastImage" immediately after ending the method.
941
             *
942
             * @return
943
             * On error returns FALSE.
944
             */
945
            bool drawTextArea(int instance=0);
946
            /**
947
             * Method to draw a multistate animated button. It creates a thread
948
             * with a timer and starts an animation by drawing every instance in
949
             * the defined order.
950
             *
951
             * @return
952
             * On error returns FALSE.
953
             */
954
            bool drawButtonMultistateAni();
955
            /**
956
             * Draws a normal bargraph with an ON and OFF state. Takes care
957
             * about cameleon images. If registered, it calls a callback
958
             * function to the GUI to display the ready image.
959
             *
960
             * @param instance
961
             * The instance of the bargraph to draw. This value must be in the
962
             * range of 0 to "stateCount".
963
             *
964
             * @param level
965
             * This is the level to show on the bargraph. It must be a value
966
             * the range of "rl" (range low) and "rh" (range high). A lower
967
             * value than "rl" is interpreted as "rl" and a value higher than
968
             * "rh" is interpreted as "rh".
969
             *
970
             * @param show
971
             * Optional. By default TRUE. If set to FALSE, the bargraph image is
972
             * not send to GUI. The image is available in the variable
973
             * "mLastImage" immediately after ending the method.
974
             *
975
             * @return
976
             * On error returns FALSE.
977
             */
978
            bool drawBargraph(int instance, int level, bool show=true);
979
            /**
980
             * @brief drawMultistateBargraph draws a bargraph comparable to a button.
981
             * This method draws a multistate bargraph. This is like many
982
             * buttons in one. But they behave like a bargraph. This means, that
983
             * it depends on the level how many buttons are ON and which are OFF.
984
             *
985
             * @param level The level. This defines how many buttons are at ON state.
986
             * @param show  If this is false, the button is invisible.
987
             * @return If everything went well, TRUE is returned. If an error
988
             * occurred it returns FALSE.
989
             */
990
            bool drawMultistateBargraph(int level, bool show=true);
991
            /**
992
             * @brief Invert bargraph/joystick
993
             * This method sets or unsets inverting bargraphs or the axis of a
994
             * joystick.
995
             *
996
             * @param invert    A value between 0 and 3. If it is a bargraph
997
             *                  any value > 0 means to invert the axis. For
998
             *                  joysticks the values mean:
999
             *                     0 = no invert
1000
             *                     1 = invert horizontal axis
1001
             *                     2 = invert vertical axis
1002
             *                     3 = invert both axis
1003
             */
1004
            void setBargraphInvert(int invert);
1005
            /**
1006
             * @brief Change ramp down time
1007
             *
1008
             * @param t     Time in 1/10 seconds
1009
             */
1010
            void setBargraphRampDownTime(int t);
1011
            /**
1012
             * @brief Change ramp up time
1013
             *
1014
             * @param t     Time in 1/10 seconds
1015
             */
1016
            void setBargraphRampUpTime(int t);
1017
            /**
1018
             * @brief Set the increment step factor
1019
             *
1020
             * @param inc   Step increment.
1021
             */
1022
            void setBargraphDragIncrement(int inc);
1023
            /**
1024
             * @brief Draws a joystick field.
1025
             * The method draws a rectangular field acting as a joystick. This
1026
             * means, that every touch of move is translated into coordinates
1027
             * who are send to the NetLinx.
1028
             * This works the same prinzyp as the bargraphs do, but with 2
1029
             * dimensions.
1030
             *
1031
             * @param x         The x coordinate to set the curser. If this is
1032
             *                  -1 the default position is used.
1033
             * @param y         The y coordinate to set the cursor. If this is
1034
             *                  -1 the default position is used.
1035
             * @return If everything went well, TRUE is returned.
1036
             */
1037
            bool drawJoystick(int x, int y);
1038
            /**
1039
             * Draws the curser of the joystick, if there is one. The method
1040
             * calculates the pixel position of the cursor out of the level
1041
             * values.
1042
             *
1043
             * @param bm        The bitmap where to draw the curser.
1044
             * @param x         The x coordinate to set the curser (X level).
1045
             * @param y         The y coordinate to set the cursor (Y level).
1046
             * @return If everything went well, TRUE is returned.
1047
             */
1048
            bool drawJoystickCursor(SkBitmap *bm, int x, int y);
1049
            /**
1050
             * Draws the background and the frame, if any, of the box. It takes
1051
             * the number of rows in account.
1052
             *
1053
             * @param show  Optional: If set to false the button will not be
1054
             * shown.
1055
             * @return If everything went well, TRUE is returned. If an error
1056
             * occurred it returns FALSE.
1057
             */
1058
            bool drawList(bool show=true);
1059
            /**
1060
             * Show the button with it's current state.
1061
             */
1062
            void show();
1063
            /**
1064
             * Hide the button. In case of an animated button, the animation is
1065
             * stopped.
1066
             *
1067
             * @param total
1068
             * Optional. When set to TRUE, a transparent button is displayed.
1069
             */
1070
            void hide(bool total=false);
1071
            /**
1072
             * This method sends the image together with all data to the GUI,
1073
             * where it will be shown. The variable mLastImage must not be
1074
             * empty for the method to succeed.
1075
             */
1076
            void showLastButton();
1077
            /**
1078
             * Handle a mouse click.
1079
             *
1080
             * @param x
1081
             * The x coordinate of the mouse press
1082
             *
1083
             * @param y
1084
             * The y coordinate of the mouse press
1085
             *
1086
             * @param pressed
1087
             * TRUE = Button was pressed, FALSE = Button was released.
1088
             *
1089
             * @return
1090
             * TRUE = Button was clickable and processed. FALSE = Button was not
1091
             * clickable.
1092
             */
1093
            bool doClick(int x, int y, bool pressed);
1094
            /**
1095
             * Creates a button but uses the informations in the structure
1096
             * instead of reading it from a file.
1097
             *
1098
             * @param bt    A structure containing all information to create a button.
1099
             * @return On success returns TRUE, else FALSE.
1100
             */
1101
            bool createSoftButton(const EXTBUTTON_t& bt);
1102
            /**
1103
             * Returns the image in mLastImage as a pixel array with the defined
1104
             * dimensions.
1105
             *
1106
             * @return A typedef IMAGE_t containing the ingredentials of the
1107
             * image. It contains a pointer with allocated memory holding the
1108
             * image. This buffer must NOT be freed!
1109
             */
1110
            BITMAP_t getLastImage();
1111
            /**
1112
             * Returns the image in mLastImage as a TBitmap with the defined
1113
             * dimensions.
1114
             *
1115
             * @return TBitmap class
1116
             */
1117
            TBitmap getLastBitmap();
1118
            /**
1119
             * Returns the fint the button uses.
1120
             * @return A structure containing the informations for the font
1121
             * to load.
1122
             */
1123
            FONT_T getFont();
1124
            /**
1125
             * Returns the style of the font.
1126
             * @return The font style.
1127
             */
1128
            FONT_STYLE getFontStyle();
1129
            /**
1130
             * Tests the button if it is clickable.
1131
             * @return TRUE if it is clickable, FALSE otherwise.
1132
             */
1133
            bool isClickable(int x = -1, int y = -1);
1134
            /**
1135
             * Returns the password character.
1136
             *
1137
             * @return An integer representing the password character. If there
1138
             * is no password character 0 is returned.
1139
             */
1140
            uint getPasswordChar() { return (pc.empty() ? 0 : pc[0]); }
1141
            /**
1142
             * Set the level of a bargraph or a multistate bargraph.
1143
             * The method checks the level whether it is inside the defined
1144
             * range or not.
1145
             *
1146
             * @param level     The new level value
1147
             */
1148
            void setBargraphLevel(int level);
1149
            /**
1150
             * @brief Move the level to the mouse position
1151
             * The method moves the level to the mouse position while the left
1152
             * button is pressed. The exact behavior depends on the settings for
1153
             * the bargraph.
1154
             *
1155
             * @param x     The x coordinate of the mouse
1156
             * @param y     The y coordinate of the mouse
1157
             */
1158
            void moveBargraphLevel(int x, int y);
1159
            /**
1160
             * @brief Send the levels of a joystick
1161
             * The method sends the level of the x and y axes of a joystick to
1162
             * the NetLinx.
1163
             */
1164
            void sendJoystickLevels();
1165
            /**
1166
             * @brief Send the level of the bargraph
1167
             * The method sends the level of the bargraph to the NetLinx.
1168
             */
1169
            void sendBargraphLevel();
1170
            /**
1171
             * @brief invalidate - Mark a button internal as hidden.
1172
             * This method does not call any surface methods and marks the
1173
             * the button only internal hidden. The graphic remains.
1174
             *
1175
             * @return TRUE on success.
1176
             */
1177
            bool invalidate();
1178
            /**
1179
             * Returns the draw order of the elements of a button.
1180
             *
1181
             * @param instance  The button instance. This value must be >= 0.
1182
             * @return The draw order as a string with a length of 10.
1183
             */
1184
            std::string& getDrawOrder(int instance);
1185
            /**
1186
             * Returns the rows of the list in case this button is a list.
1187
             * Otherwise an empty list is returned.
1188
             *
1189
             * @return A vector list containing the rows of the list.
1190
             */
1191
            std::vector<std::string>& getListContent() { return mListContent; }
1192
            /**
1193
             * @brief Listview Data Source
1194
             * This command sets the data source to drive the Listview entries.
1195
             * Note that this command only configures the data source it does
1196
             * not actually cause the data to be fetched. The ^LVR refresh
1197
             * command must be issued to load the data.
1198
             *
1199
             * @param source    A string containing the source for list data.
1200
             * This can be either a URL or the name of a dynamic resource data.
1201
             * @param configs   One or more configurations defining the layout
1202
             * of the source.
1203
             *
1204
             * @return If the source is valid it returns TRUE.
1205
             */
1206
            bool setListSource(const std::string &source, const std::vector<std::string>& configs);
1207
            /**
1208
             * Returns the set source for list data.
1209
             *
1210
             * @return A string containg the source or and empty string if no
1211
             * valid source was set.
1212
             */
1213
            std::string& getListSource() { return listSource; }
1214
            /**
1215
             * Sets a filter for the data of a listView.
1216
             *
1217
             * @param filter    A string used as a filter for the data.
1218
             *
1219
             * @return Returns true if the string was evaluated ok.
1220
             */
1221
            bool setListSourceFilter(const std::string& filter);
1222
            /**
1223
             * Returns the filter string for a listView data source.
1224
             *
1225
             * @return The filter string.
1226
             */
1227
            std::string& getListSourceFilter() { return listFilter; }
1228
            /**
1229
             * Sets the listView event number. A value of 0 turns off event
1230
             * reporting. Any other number activates the events. Currently are
1231
             * only refresh events are reported.
1232
             *
1233
             * @param num   The event number.
1234
             */
1235
            void setListViewEventNumber(int num) { listEvNum = num; }
1236
            /**
1237
             * Returns the event number of the listView. By default this number
1238
             * is 1401. But with the command ^LVE this number can be changed.
1239
             *
1240
             * @return The event number of the listView.
1241
             */
1242
            int getListViewEventNumber() { return listEvNum; };
1243
            void setListViewColumns(int cols);
1244
            int getListViewColumns() { return tc; }
1245
            void setListViewLayout(int layout);
1246
            int getListViewLayout() { return listLayout; }
1247
            void setListViewComponent(int comp);
1248
            int getListViewComponent() { return listComponent; }
1249
            void setListViewCellheight(int height, bool percent=false);
1250
            int getListViewCellheight() { return tj; }
1251
            void setListViewP1(int p1);
1252
            int getListViewP1() { return listViewP1; }
1253
            void setListViewP2(int p2);
1254
            int getListViewP2() { return listViewP2; }
1255
            void setListViewColumnFilter(bool filter) { listViewColFiler = filter; }
1256
            bool getListViewColumnFilter() { return listViewColFiler; }
1257
            void setListViewFilterHeight(int height, bool percent=false);
1258
            int getListViewFilterHeight() { return listViewColFilterHeight; }
1259
            void setListViewAlphaScroll(bool alpha) { listAlphaScroll = alpha; }
1260
            bool getListViewAlphaScroll() { return listAlphaScroll; }
1261
            void setListViewFieldMap(const std::map<std::string,std::string>& map) { listFieldMap = map; }
1262
            std::map<std::string,std::string>& getListViewFieldMap() { return listFieldMap; }
1263
            void listViewNavigate(const std::string& command, bool select=false);
1264
            void listViewRefresh(int interval, bool force=false);
1265
            void listViewSortData(const std::vector<std::string>& columns, LIST_SORT order, const std::string& override);
1266
            int getBorderSize(const std::string& name);
1267
            void setPassword(const std::string& pw) { mPassword = pw; }
1268
            void setUserName(const std::string& user);
1269
 
1270
        protected:
1271
            BUTTONTYPE getButtonType(const std::string& bt);
1272
            FEEDBACK getButtonFeedback(const std::string& fb);
1273
            SkBitmap drawImageButton(SkBitmap& imgRed, SkBitmap& imgMask, int width, int height, SkColor col1, SkColor col2);
1274
            SkBitmap combineImages(SkBitmap& base, SkBitmap& alpha, SkColor col);
1275
 
1276
            void funcTimer(const amx::ANET_BLINK& blink);
1277
            void funcNetwork(int state);
1278
            void funcResource(const RESOURCE_T *resource, const std::string& url, BITMAP_CACHE bc, int instance);
1279
#ifdef __ANDROID__
1280
            void funcBattery(int level, bool charging, int chargeType);
1281
#endif
1282
#if TARGET_OS_SIMULATOR || TARGET_OS_IOS
1283
            void funcBattery(int level, int state);
1284
#endif
1285
            void funcNetworkState(int level);
1286
 
1287
        private:
1288
            std::function<void (ulong handle, ulong parent, TBitmap buffer, int width, int height, int left, int top, bool passthrough, int marqtype, int marq)> _displayButton{nullptr};
1289
            std::function<void (ulong handle, ulong parent, int left, int top, int width, int height, const std::string& url, const std::string& user, const std::string& pw)> _playVideo{nullptr};
1290
            std::function<std::vector<std::string>(ulong handle, int ap, int ta, int ti, int rows, int columns)> _getListContent{nullptr};
1291
            std::function<std::string(int ti, int row)> _getListRow{nullptr};
1292
            std::function<void (TButton *button)> _getGlobalSettings{nullptr};
1293
            std::function<void (int channel, uint handle, bool pressed)> _buttonPress{nullptr};
1294
 
1295
            // Mutexes used in class
1296
            std::mutex mutex_button;
1297
            std::mutex mutex_click;
1298
            std::mutex mutex_text;
1299
            std::mutex mutex_bargraph;
1300
            std::mutex mutex_sysdraw;
1301
            std::mutex mutex_bmCache;
1302
 
1303
            std::string buttonTypeToString();
1304
            std::string buttonTypeToString(BUTTONTYPE t);
1305
            POSITION_t calcImagePosition(int width, int height, CENTER_CODE cc, int number, int line = 0);
1306
            IMAGE_SIZE_t calcImageSize(int imWidth, int imHeight, int instance, bool aspect=false);
1307
            void calcImageSizePercent(int imWidth, int imHeight, int btWidth, int btHeight, int btFrame, int *realX, int *realY);
1308
            SkColor baseColor(SkColor basePix, SkColor maskPix, SkColor col1, SkColor col2);
1309
            TEXT_EFFECT textEffect(const std::string& effect);
1310
            int numberLines(const std::string& str);
1311
            SkRect calcRect(int width, int height, int pen);
1312
            void runAnimation();    // Method started as thread for button animation
1313
            void runAnimationRange(int start, int end, ulong step);     // Method started as thread for a limited time
1314
            bool drawAlongOrder(SkBitmap *imgButton, int instance);
1315
 
1316
            void getDrawOrder(const std::string& sdo, DRAW_ORDER *order);
1317
            bool buttonFill(SkBitmap *bm, int instance);
1318
            bool buttonBitmap(SkBitmap *bm, int instance);
1319
            bool buttonDynamic(SkBitmap *bm, int instance, bool show, bool *state=nullptr);
1320
            bool buttonIcon(SkBitmap *bm, int instance);
1321
            bool buttonText(SkBitmap *bm, int instance);
1322
            bool buttonBorder(SkBitmap *bm, int instance, TSystemDraw::LINE_TYPE_t lnType=TSystemDraw::LT_OFF);
1323
            bool isPixelTransparent(int x, int y);
1324
            bool barLevel(SkBitmap *bm, int instance, int level);
1325
            bool makeElement(int instance=-1);
1326
            bool loadImage(SkBitmap *bm, SkBitmap& image, int instance);
1327
            void _TimerCallback(ulong counter);
1328
            void _imageRefresh(const std::string& url);
1329
            static THR_REFRESH_t *_addResource(TImageRefresh *refr, ulong handle, ulong parent, int bi);
1330
            static THR_REFRESH_t *_findResource(ulong handle, ulong parent, int bi);
1331
            int calcLineHeight(const std::string& text, SkFont& font);
1332
            bool textEffect(SkCanvas *canvas, sk_sp<SkTextBlob>& blob, SkScalar startX, SkScalar startY, int instance);
1333
            std::string getFormatString(TEXT_ORIENTATION to);
1334
            bool checkForSound();
1335
            bool scaleImage(SkBitmap *bm, double scaleWidth, double scaleHeight);
1336
            bool stretchImageWidth(SkBitmap *bm, int width);
1337
            bool stretchImageHeight(SkBitmap *bm, int height);
1338
            bool stretchImageWH(SkBitmap *bm, int width, int height);
1339
            SkBitmap colorImage(SkBitmap& base, SkBitmap& alpha, SkColor col, SkColor bg=0, bool useBG=false);
1340
            bool retrieveImage(const std::string& path, SkBitmap *image);
1341
            bool getBorderFragment(const std::string& path, const std::string& pathAlpha, SkBitmap *image, SkColor color);
1342
            SkBitmap drawSliderButton(const std::string& slider, SkColor col);
1343
            SkBitmap drawCursorButton(const std::string& cursor, SkColor col);
1344
            POINT_t getImagePosition(int width, int height);
1345
 
1346
            void addToBitmapCache(BITMAP_CACHE& bc);
1347
            BITMAP_CACHE& getBCentryByHandle(ulong handle, ulong parent);
1348
            BITMAP_CACHE& getBCentryByBI(int bIdx);
1349
            void removeBCentry(std::vector<BITMAP_CACHE>::iterator *elem);
1350
            void setReady(ulong handle);
1351
            void setInvalid(ulong handle);
1352
            void setBCBitmap(ulong handle, SkBitmap& bm);
1353
            void showBitmapCache();
1354
            uint32_t pixelMix(uint32_t s, uint32_t d, uint32_t a, PMIX mix);
1355
            bool isPassThrough();
1356
            SkColor& flipColorLevelsRB(SkColor& color);
1357
            void runBargraphMove(int distance, bool moveUp=false);
1358
            void threadBargraphMove(int distance, bool moveUp);
1359
            TButtonStates *getButtonState();
1360
 
1361
            BUTTONTYPE type;
1362
            int bi{0};              // button ID
1363
            std::string na;         // name
1364
            std::string bd;         // Description --> ignored
1365
            int lt{0};              // pixel from left
1366
            int tp{0};              // pixel from top
1367
            int wt{0};              // width
1368
            int ht{0};              // height
1369
            int zo{0};              // Z-Order
1370
            std::string hs;         // bounding, ...
1371
            std::string bs;         // Border style (circle, ...)
1372
            FEEDBACK fb{FB_NONE};   // Feedback type (momentary, ...)
1373
            int ap{1};              // Address port (default: 1)
1374
            int ad{0};              // Address channel
1375
            int ch{0};              // Channel number
1376
            int cp{1};              // Channel port (default: 1)
1377
            int lp{1};              // Level port (default: 1)
1378
            int lv{0};              // Level code
1379
            int ta{0};              // Listbox table channel
1380
            int ti{0};              // Listbox table index number of rows (all rows have this number in "cp")
1381
            int tr{0};              // Listbox number of rows
1382
            int tc{0};              // Listbox number of columns
1383
            int tj{0};              // Listbox row height
1384
            int tk{0};              // Listbox preferred row height
1385
            int of{0};              // Listbox list offset: 0=disabled/1=enabled
1386
            int tg{0};              // Listbox managed: 0=no/1=yes
1387
            int so{1};              // String output port
1388
            int co{1};              // Command port
1389
            std::vector<std::string> cm;         // Commands to send on each button hit
1390
            std::string dr;         // Level "horizontal" or "vertical"
1391
            int va{0};              // Level control value
1392
            int stateCount{0};      // State count with multistate buttons (number of states)
1393
            int rm{0};              // State count with multistate buttons?
1394
            int nu{2};              // Animate time up
1395
            int nd{2};              // Animate time down
1396
            int ar{0};              // Auto repeat (1 = true)
1397
            int ru{2};              // Animate time up (bargraph)
1398
            int rd{2};              // Animate time down (bargraph)
1399
            int lu{2};              // Animate time up (Bargraph)
1400
            int ld{2};              // Animate time down (Bargraph)
1401
            int rv{0};              // Level control repeat time
1402
            int rl{0};              // Range low
1403
            int rh{0};              // Range high
1404
            int ri{0};              // Bargraph inverted (0 = normal, 1 = inverted)
1405
            int ji{0};              // Joystick aux inverted (0 = normal, 1 = inverted)
1406
            int rn{0};              // Bargraph: Range drag increment
1407
            int ac_di{0};           // (guess) Direction of text: 0 = left to right (default); 1 = right to left
1408
            int hd{0};              // 1 = Hidden, 0 = Normal visible
1409
            int da{0};              // 1 = Disabled, 0 = Normal active
1410
            int pp{0};              // >0 = password protected; Range 1 to 4
1411
            std::string lf;         // Bargraph function: empty = display only, active, active centering, drag, drag centering
1412
            std::string sd;         // Name/Type of slider for a bargraph
1413
            std::string vt;         // Level control type (rel = relative, abs = absolute)
1414
            std::string cd;         // Name of cursor for a joystick
1415
            std::string sc;         // Color of slider (for bargraph)
1416
            std::string cc;         // Color of cursor (for joystick)
1417
            int mt{0};              // Length of text area (0 = 2000)
1418
            std::string dt;         // "multiple" textarea has multiple lines, else single line
1419
            std::string im;         // Input mask of a text area
1420
            int st{0};              // SubPageView: ID of subview list
1421
            int ws{0};              // SubPageView: Wrap subpages; 1 = YES
1422
            std::string on;         // SubPageView: direction: vert = vertical, if empty: horizontal which is default
1423
            int sa{0};              // SubPageView: Percent of space between items in list
1424
            int dy{0};              // SubPageView: Allow dynamic reordering; 1 = YES
1425
            int rs{0};              // SubPageView: Reset view on show; 1 = YES
1426
            int ba{0};              // SubPageView: 1 = Scrollbar is visible, 0 = No scrollbar visible
1427
            int bo{0};              // SubPageView: Scrollbar offset in pixels; Only valid if "ba" > 0
1428
            std::string we;         // SubPageView: Anchor position: Empty = Center, "l/t" = left/top, "r/b" = right/bottom
1429
            std::string pc;         // Password character for text area
1430
            std::string op;         // String the button send
1431
            bool visible{true};     // TRUE=Button is visible
1432
            std::vector<PUSH_FUNC_T> pushFunc;  // Push functions: This are executed on button press
1433
            std::vector<SR_T> sr;   // The elements the button consists of
1434
            // ListView settings (G5)
1435
            std::string listSource; // Defines the data source for a list.
1436
            int listEvNum{1401};       // ListView event number.
1437
            std::string listFilter; // ListView filter string.
1438
            int listComponent{0};   // ListView component
1439
            int listLayout{0};      // ListView layout.
1440
            std::map<std::string,std::string> listFieldMap; // Maps the fields from the source to the columns of the list
1441
//            LIST_SORT listSort{LIST_SORT_NONE}; // ListView sort algorithm
1442
            std::string listSortOverride;   // A SQL ORDER BY command like sort option. Only valid if listStort == LIST_SORT_OVERRIDE
1443
            std::string listSourceUser;   // The user name (optional)
1444
            std::string listSourcePass;   // The password (optional)
1445
            bool listSourceCsv{false};  // TRUE = Source of listView is in CSV data
1446
            bool listSourceHasHeader{false};    // TRUE = The listView data has a had line which must be ignored.
1447
            int listViewP1{0};      // ListView layout percentage 1
1448
            int listViewP2{0};      // ListView layout percentage 2
1449
            bool listViewColFiler{false};   // ListView column filter state (TRUE = on)
1450
            int listViewColFilterHeight{0}; // ListView column filter height
1451
            bool listAlphaScroll{false};    // ListView alpha scroll state (TRUE = scrollbar visible)
1452
 
1453
            TPalette *mPalette{nullptr}; // The color palette
1454
            // Image management
1455
            SkBitmap mLastImage;    // The last calculated image
1456
            ulong mHandle{0};       // internal used handle to identify button
1457
            uint32_t mButtonID{0};  // A CRC32 checksum identifying the button.
1458
            int mParentHeight{0};   // The height of the parent page / subpage
1459
            int mParentWidth{0};    // The width of the parent page / subpage
1460
            bool mEnabled{true};    // By default a button is enabled (TRUE); FALSE = Button disabled
1461
            TFont *mFonts{nullptr}; // The font table
1462
            int mGlobalOO{-1};      // Opacity of the whole subpage, if any
1463
            int mActInstance{0};    // Active instance
1464
            DRAW_ORDER mDOrder[ORD_ELEM_COUNT];  // The order to draw the elements of a button
1465
            std::thread mThrAni;    // Thread handle for animation
1466
            std::thread mThrRes;    // A resouce (download of a remote image/video) running in background
1467
            std::thread mThrSlider; // Thread to move a slider (bargraph)
1468
            std::atomic<bool> mAniRunning{false}; // TRUE = Animation is running
1469
            std::atomic<bool> mAniStop{false};  // If TRUE, the running animation will stop
1470
//            int mLastLevel{0};      // The last level value for a bargraph
1471
            int mBarStartLevel{0};  // The level when a drag bargraph started.
1472
            int mBarThreshold{0};   // The difference between start coordinate and actual coordinate (drag bargraph only)
1473
            bool mRunBargraphMove{false}; // TRUE = The thread to move the bargraph level should run.
1474
            bool mThreadRunMove{false}; // TRUE the thread to move the bargrapg slider is running.
1475
//            int mLastJoyX{0};       // The last x position of the joystick curser
1476
//            int mLastJoyY{0};       // The last y position of the joystick curser
1477
//            int mLastSendLevelX{0}; // This is the last level send from a bargraph or the X level of a joystick
1478
//            int mLastSendLevelY{0}; // This is the last Y level from a joystick
1479
            bool mSystemReg{false}; // TRUE = registered as system button
1480
            amx::ANET_BLINK mLastBlink; // This is used for the system clock buttons
1481
            TTimer *mTimer{nullptr};    // This is for buttons displaying the time or a date. It's a thread running in background.
1482
            static THR_REFRESH_t *mThrRefresh;  // If  we have a source to reread periodicaly, this starts a thread to do that.
1483
            ulong mAniRunTime{0};   // The time in milliseconds an animation should run. 0 = run forever.
1484
            BITMAP_CACHE mBCDummy;  // A dummy retuned in case no cache exists or the element was not found.
1485
            bool mChanged{true};    // TRUE=Something changed --> button must be redrawn
1486
            int mBorderWidth{0};    // If there is a border this is set to the pixels the border is using
1487
            std::vector<std::string> mListContent;  // The content of a list, if this button is one
1488
            bool mSubViewPart{false};   // TRUE = The button is part of a subview item.
1489
            int mCursorPosition{0}; // The cursor position if this is of type TEXT_INPUT
1490
            bool mHasFocus{false};  // If this is of type TEXT_INPUT this holds the focus state
1491
            std::string dummy;      // dummy string used to return an empty string.
1492
            std::string mPassword;  // Contains the last typed password (askPassword()).
1493
            std::string mUser;      // If this contains a user name contained in the User Password list, the user is asked for a password.
1494
            int mPosLeft{0};        // The actual left position of the button
1495
            int mPosTop{0};         // The actual top position of the button
1496
            int mWidthOrig{0};      // The original width
1497
            int mHeightOrig{0};     // The original height
1498
 
1499
    };
1500
 
1501
    typedef struct BUTTONS_T
1502
    {
1503
        TButton *button{nullptr};
1504
        BUTTONS_T *previous{nullptr};
1505
        BUTTONS_T *next{nullptr};
1506
    } BUTTONS_T;
1507
}
1508
 
1509
#endif