Subversion Repositories tpanel

Rev

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