Subversion Repositories tpanel

Rev

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