Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

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