Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 andreas 1
/*
15 andreas 2
 * Copyright (C) 2020, 2021 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
 
2 andreas 31
#include "treadxml.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"
2 andreas 38
 
8 andreas 39
#define ORD_ELEM_COUNT  5
40
 
21 andreas 41
extern bool prg_stopped;
42
 
8 andreas 43
class SkFont;
21 andreas 44
struct RESOURCE_T;
8 andreas 45
 
2 andreas 46
namespace Button
47
{
15 andreas 48
    typedef enum BUTTONTYPE
49
    {
50
        NONE,
51
        GENERAL,
52
        MULTISTATE_GENERAL,
53
        BARGRAPH,
54
        MULTISTATE_BARGRAPH,
55
        JOISTICK,
56
        TEXT_INPUT,
57
        COMPUTER_CONTROL,
58
        TAKE_NOTE,
59
        SUBPAGE_VIEW
60
    } BUTTONTYPE;
61
 
4 andreas 62
    typedef struct SYSBORDER_t
63
    {
8 andreas 64
        int id{0};
4 andreas 65
        char *name{nullptr};
66
        int number{0};
67
        char *style{nullptr};
68
        int width{0};
69
        int radius{0};
70
    }SYSBORDER_t;
71
 
15 andreas 72
    typedef struct SYSBUTTONS_t
73
    {
74
        int channel{0};             // Channel number
75
        BUTTONTYPE type{NONE};      // Type of button
76
        int states{0};              // Maximum number of states
77
        int ll{0};                  // Level low range
78
        int lh{0};                  // Level high range
79
    }SYSBUTTONS_t;
80
 
3 andreas 81
    typedef enum TEXT_ORIENTATION
82
    {
83
        ORI_ABSOLUT,
84
        ORI_TOP_LEFT,
85
        ORI_TOP_MIDDLE,
86
        ORI_TOP_RIGHT,
87
        ORI_CENTER_LEFT,
88
        ORI_CENTER_MIDDLE,		// default
89
        ORI_CENTER_RIGHT,
90
        ORI_BOTTOM_LEFT,
91
        ORI_BOTTOM_MIDDLE,
92
        ORI_BOTTOM_RIGHT
93
    } TEXT_ORIENTATION;
2 andreas 94
 
7 andreas 95
    typedef enum TEXT_EFFECT
96
    {
97
        EFFECT_NONE,
98
        EFFECT_OUTLINE_S,
99
        EFFECT_OUTLINE_M,
100
        EFFECT_OUTLINE_L,
101
        EFFECT_OUTLINE_X,
102
        EFFECT_GLOW_S,
103
        EFFECT_GLOW_M,
104
        EFFECT_GLOW_L,
105
        EFFECT_GLOW_X,
106
        EFFECT_SOFT_DROP_SHADOW_1,
107
        EFFECT_SOFT_DROP_SHADOW_2,
108
        EFFECT_SOFT_DROP_SHADOW_3,
109
        EFFECT_SOFT_DROP_SHADOW_4,
110
        EFFECT_SOFT_DROP_SHADOW_5,
111
        EFFECT_SOFT_DROP_SHADOW_6,
112
        EFFECT_SOFT_DROP_SHADOW_7,
113
        EFFECT_SOFT_DROP_SHADOW_8,
114
        EFFECT_MEDIUM_DROP_SHADOW_1,
115
        EFFECT_MEDIUM_DROP_SHADOW_2,
116
        EFFECT_MEDIUM_DROP_SHADOW_3,
117
        EFFECT_MEDIUM_DROP_SHADOW_4,
118
        EFFECT_MEDIUM_DROP_SHADOW_5,
119
        EFFECT_MEDIUM_DROP_SHADOW_6,
120
        EFFECT_MEDIUM_DROP_SHADOW_7,
121
        EFFECT_MEDIUM_DROP_SHADOW_8,
122
        EFFECT_HARD_DROP_SHADOW_1,
123
        EFFECT_HARD_DROP_SHADOW_2,
124
        EFFECT_HARD_DROP_SHADOW_3,
125
        EFFECT_HARD_DROP_SHADOW_4,
126
        EFFECT_HARD_DROP_SHADOW_5,
127
        EFFECT_HARD_DROP_SHADOW_6,
128
        EFFECT_HARD_DROP_SHADOW_7,
129
        EFFECT_HARD_DROP_SHADOW_8,
130
        EFFECT_SOFT_DROP_SHADOW_1_WITH_OUTLINE,
131
        EFFECT_SOFT_DROP_SHADOW_2_WITH_OUTLINE,
132
        EFFECT_SOFT_DROP_SHADOW_3_WITH_OUTLINE,
133
        EFFECT_SOFT_DROP_SHADOW_4_WITH_OUTLINE,
134
        EFFECT_SOFT_DROP_SHADOW_5_WITH_OUTLINE,
135
        EFFECT_SOFT_DROP_SHADOW_6_WITH_OUTLINE,
136
        EFFECT_SOFT_DROP_SHADOW_7_WITH_OUTLINE,
137
        EFFECT_SOFT_DROP_SHADOW_8_WITH_OUTLINE,
138
        EFFECT_MEDIUM_DROP_SHADOW_1_WITH_OUTLINE,
139
        EFFECT_MEDIUM_DROP_SHADOW_2_WITH_OUTLINE,
140
        EFFECT_MEDIUM_DROP_SHADOW_3_WITH_OUTLINE,
141
        EFFECT_MEDIUM_DROP_SHADOW_4_WITH_OUTLINE,
142
        EFFECT_MEDIUM_DROP_SHADOW_5_WITH_OUTLINE,
143
        EFFECT_MEDIUM_DROP_SHADOW_6_WITH_OUTLINE,
144
        EFFECT_MEDIUM_DROP_SHADOW_7_WITH_OUTLINE,
145
        EFFECT_MEDIUM_DROP_SHADOW_8_WITH_OUTLINE,
146
        EFFECT_HARD_DROP_SHADOW_1_WITH_OUTLINE,
147
        EFFECT_HARD_DROP_SHADOW_2_WITH_OUTLINE,
148
        EFFECT_HARD_DROP_SHADOW_3_WITH_OUTLINE,
149
        EFFECT_HARD_DROP_SHADOW_4_WITH_OUTLINE,
150
        EFFECT_HARD_DROP_SHADOW_5_WITH_OUTLINE,
151
        EFFECT_HARD_DROP_SHADOW_6_WITH_OUTLINE,
152
        EFFECT_HARD_DROP_SHADOW_7_WITH_OUTLINE,
153
        EFFECT_HARD_DROP_SHADOW_8_WITH_OUTLINE
154
    }TEXT_EFFECT;
155
 
8 andreas 156
    typedef enum DRAW_ORDER
157
    {
158
        ORD_ELEM_NONE,
159
        ORD_ELEM_FILL,
160
        ORD_ELEM_BITMAP,
161
        ORD_ELEM_ICON,
162
        ORD_ELEM_TEXT,
163
        ORD_ELEM_BORDER
164
    }DRAW_ORDER;
165
 
3 andreas 166
    typedef struct SR_T
167
    {
168
        int number{0};
6 andreas 169
        std::string _do;        // Order on how to show a multistate bargraph (010203...)
170
        std::string bs;         // Frame type (circle, ...)
171
        std::string mi;         // Chameleon image
172
        int mi_width{0};        // Width of image
173
        int mi_height{0};       // Height of image
174
        std::string cb;         // Border color
175
        std::string cf;         // Fill color
176
        std::string ct;         // Text Color
177
        std::string ec;         // Text effect color
178
        std::string bm;         // bitmap file name
179
        std::string sd;         // Sound file to play
180
        int bm_width{0};        // Width of image
181
        int bm_height{0};       // Height of image
182
        bool dynamic{false};    // TRUE = moving image
183
        int sb{0};              // Index to external graphics download
184
        int ii{0};              // Icon index number
10 andreas 185
        int ix{0};              // Icon X position
186
        int iy{0};              // Icon Y position
7 andreas 187
        int ji{5};              // Icon style / position like "jt", default 5 = center+middle
188
        int jb{5};              // Image position (center, left, ...), default 5 = center+middle
10 andreas 189
        int bx{0};              // Absolute image position x
190
        int by{0};              // Absolute image position y
191
        int fi{0};              // Font index
6 andreas 192
        std::string te;         // Text
193
        TEXT_ORIENTATION jt{ORI_CENTER_MIDDLE}; // Text orientation
194
        int tx{0};              // Text X position
195
        int ty{0};              // Text Y position
196
        int ww{0};              // line break when 1
197
        int et{0};              // Text effect (^TEF)
8 andreas 198
        int oo{-1};             // Over all opacity
3 andreas 199
    } SR_T;
2 andreas 200
 
3 andreas 201
    typedef enum FEEDBACK
202
    {
203
        FB_NONE,
204
        FB_CHANNEL,
6 andreas 205
        FB_INV_CHANNEL,     // inverted channel
3 andreas 206
        FB_ALWAYS_ON,
207
        FB_MOMENTARY,
208
        FB_BLINK
209
    } FEEDBACK;
2 andreas 210
 
3 andreas 211
    typedef struct PUSH_FUNC
212
    {
6 andreas 213
        std::string pfType; // command to execute when button was pushed
214
        std::string pfName; // Name of popup
3 andreas 215
    } PUSH_FUNC_T;
2 andreas 216
 
4 andreas 217
    typedef enum CENTER_CODE
218
    {
219
        SC_ICON = 0,
220
        SC_BITMAP,
221
        SC_TEXT
222
    }CENTER_CODE;
223
 
224
    typedef struct POSITION_t
225
    {
226
        int width{0};
227
        int height{0};
10 andreas 228
        int left{1};
229
        int top{1};
17 andreas 230
        bool overflow{false};
4 andreas 231
        bool valid{false};
232
    }POSITION_t;
233
 
21 andreas 234
    typedef struct THR_REFRESH_t
235
    {
236
        ulong handle{0};
237
        ulong parent{0};
238
        int bi{0};
239
        TImageRefresh *mImageRefresh{nullptr};
240
        THR_REFRESH_t *next{nullptr};
241
    }THR_REFRESH_t;
242
 
3 andreas 243
    class TButton
244
    {
245
        public:
246
            TButton();
247
            ~TButton();
2 andreas 248
 
14 andreas 249
            /**
250
             * The following function parses the parameters of a particular
251
             * button and creates a new button. This function is called either
252
             * from class TPage or TSubPage when a page or subpage is created.
253
             *
23 andreas 254
             * @param xml     A pointer to the XML reader
255
             * @param node    A pointer to the actual node in the XML tree.
14 andreas 256
             */
3 andreas 257
            void initialize(TReadXML *xml, mxml_node_t *node);
2 andreas 258
 
14 andreas 259
            /**
260
             * Returns the button index. This is a unique number inside a page
261
             * or subpage.
23 andreas 262
             *
263
             * @return return the button index number as defined in the
264
             * configuration file.
14 andreas 265
             */
3 andreas 266
            int getButtonIndex() { return bi; }
14 andreas 267
            /**
268
             * Returns the name of the button.
269
             */
3 andreas 270
            std::string& getButtonName() { return na; }
14 andreas 271
            /**
272
             * Returns the description of the button, if there is one.
273
             */
3 andreas 274
            std::string& getButtonDescription() { return bd; }
14 andreas 275
            /**
276
             * Returns the width of the button in pixels.
277
             */
3 andreas 278
            int getWidth() { return wt; }
14 andreas 279
            /**
280
             * Returns the height of the button in pixels.
281
             */
3 andreas 282
            int getHeight() { return ht; }
14 andreas 283
            /**
284
             * Returns the left position in pixels.
285
             */
3 andreas 286
            int getLeftPosition() { return lt; }
14 andreas 287
            /**
288
             * Returns the top position of the button in pixels.
289
             */
3 andreas 290
            int getTopPosition() { return tp; }
14 andreas 291
            /**
292
             * Returns the Z-order. This number marks the order the buttons
293
             * are drawed on the screen. Inside a page or subpage the buttons
294
             * are always sorted.
295
             */
3 andreas 296
            int getZOrder() { return zo; }
14 andreas 297
            /**
298
             * Returns the type of the button.
299
             */
300
            BUTTONTYPE getButtonType() { return type; }
15 andreas 301
 
302
            int getRangeLow() { return rl; }
303
            int getRangeHigh() { return rh; }
304
            int getStateCount() { return stateCount; }
14 andreas 305
            int getAddressPort() { return ap; }
306
            int getAddressChannel() { return ad; }
307
            int getChannelNumber() { return ch; }
308
            int getChannelPort() { return cp; }
309
            int getLevelPort() { return lp; }
310
            int getLevelValue() { return lv; }
311
            int getNumberInstances() { return (int)sr.size(); }
15 andreas 312
            int getActiveInstance() { return mActInstance; }
16 andreas 313
            ulong getHandle() { return mHandle; }
314
            void setEnable(bool en) { mEnabled = en; }
315
            bool isEnabled() { return mEnabled; }
26 andreas 316
            void setHandle(ulong handle) { mHandle = handle; };
4 andreas 317
            void setPalette(TPalette *pal) { mPalette = pal; }
6 andreas 318
            void setParentWidth(int width) { mParentWidth = width; }
319
            void setParentHeight(int height) { mParentHeight = height; }
320
            void setParentSize(int width, int height) { mParentWidth = width; mParentHeight = height; }
7 andreas 321
            void setFonts(TFont *ft) { mFonts = ft; }
10 andreas 322
            void setGlobalOpacity(int oo) { if (oo >= 0 && oo <= 255) mGlobalOO = oo; }
14 andreas 323
            void setVisible(bool v) { visible = v; }
16 andreas 324
            bool setBitmap(const std::string& file, int instance);
325
            bool setOpacity(int op, int instance);
326
            bool setWorWrap(bool state, int instance);
327
            bool setFont(int id, int instance);
328
            void setTop(int top);
329
            void setLeft(int left);
330
            void setLeftTop(int left, int top);
21 andreas 331
            void setResourceName(const std::string& name, int instance);
15 andreas 332
            void addPushFunction(std::string& func, std::string& page);
333
            void registerSystemButton();
334
            bool isSystemButton();
16 andreas 335
            void clearPushFunctions() { pushFunc.clear(); }
336
            void clearPushFunction(const std::string& action);
337
            void refresh();
3 andreas 338
            /**
14 andreas 339
             * Sets a particular instance of the button active. This implies
340
             * a redraw of the button in case the instance is different from
341
             * the one already visible.
342
             *
343
             * @param instance
344
             * The instance of the button to be activated.
345
             *
346
             * @return
347
             * On error returns FALSE.
348
             */
349
            bool setActive(int instance);
350
            /**
351
             * Sets an Icon on the button. This implies a redraw of the button
352
             * in case the instance is different from the one already visible.
353
             *
354
             * @param id
355
             * The id number of the icon.
356
             *
357
             * @param instance
358
             * The instance where the icon should be drawed
359
             *
360
             * @return On error returns FALSE.
361
             */
362
            bool setIcon(int id, int instance);
363
            /**
364
             * Sets an Icon on the button. This implies a redraw of the button
365
             * in case the instance is different from the one already visible.
366
             *
367
             * @param icon
368
             * The file name of the icon.
369
             *
370
             * @param instance
371
             * The instance where the icon should be drawed
372
             *
373
             * @return
374
             * On error returns FALSE.
375
             */
376
            bool setIcon(const std::string& icon, int instance);
377
            /**
378
             * Removes an icon from a button. This implies a redraw of the
379
             * button.
380
             *
381
             * @param instance
382
             * The instance number involved.
383
             *
384
             * @return
385
             * On error returns FALSE.
386
             */
387
            bool revokeIcon(int instance);
388
            /**
389
             * Set a string to a button.
390
             *
391
             * @param txt
392
             * The text to write on top of  a button.
393
             *
394
             * @param instance
395
             * The instance number involved.
396
             *
397
             * @return
398
             * On error returns FALSE.
399
             */
400
            bool setText(const std::string& txt, int instance);
401
            /**
3 andreas 402
             * Read the images, if any, from files and create an image. If there
403
             * are no files, draw the image as defined.
14 andreas 404
             *
405
             * @return
406
             * On error returns FALSE.
3 andreas 407
             */
4 andreas 408
            bool createButtons();
409
            /**
410
             * Register a callback function to display a ready image.
411
             */
6 andreas 412
            void registerCallback(std::function<void (ulong handle, ulong parent, unsigned char *buffer, int width, int height, int pixline, int left, int top)> displayButton)
4 andreas 413
            {
414
                _displayButton = displayButton;
415
            }
7 andreas 416
            void registerCallbackFT(std::function<void (ulong handle, const std::string& text, const std::string& font, const std::string& family, int size, int x, int y, ulong color, ulong effectColor, FONT_STYLE style, TEXT_ORIENTATION ori, TEXT_EFFECT effect, bool ww)> setText)
417
            { _setText = setText; }
21 andreas 418
            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; };
7 andreas 419
 
4 andreas 420
            /**
421
             * Make a pixel array and call the callback function to display the
422
             * image. If there is no callback function registered, nothing
423
             * happens.
15 andreas 424
             * This method draws a general button. It is used for most
425
             * specialized buttons too.
14 andreas 426
             *
15 andreas 427
             * @param instance
428
             * Optional. The instance of the button to draw. If the base
429
             * instance should be drawn, the parameter can be omitted.
430
             *
431
             * @param show
432
             * Optional. By defualt TRUE. If set to FALSE, the button image is
433
             * not send to GUI. The image is available in the variable
434
             * "mLastImage" immediately after ending the method.
435
             *
14 andreas 436
             * @return
437
             * On error returns FALSE.
4 andreas 438
             */
15 andreas 439
            bool drawButton(int instance = 0, bool show=true);
6 andreas 440
            /**
15 andreas 441
             * Method to draw a multistate animated button. It creates a thread
442
             * with a timer and starts an animation by drawing every instance in
443
             * the defined order.
444
             *
445
             * @return
446
             * On error returns FALSE.
447
             */
448
            bool drawButtonMultistateAni();
449
            /**
450
             * Draws a normal bargraph with an ON and OFF state. Takes care
451
             * about cameleon images. If registered, it calls a callback
452
             * function to the GUI to display the ready image.
453
             *
454
             * @param instance
455
             * The instance of the bargraph to draw. This value must be in the
456
             * range of 0 to "stateCount".
457
             *
458
             * @param level
459
             * This is the level to show on the bargraph. It must be a value
460
             * the range of "rl" (range low) and "rh" (range high). A lower
461
             * value than "rl" is interpreted as "rl" and a value higher than
462
             * "rh" is interpreted as "rh".
463
             *
464
             * @param show
465
             * Optional. By default TRUE. If set to FALSE, the bargraph image is
466
             * not send to GUI. The image is available in the variable
467
             * "mLastImage" immediately after ending the method.
468
             *
469
             * @return
470
             * On error returns FALSE.
471
             */
472
            bool drawBargraph(int instance, int level, bool show=true);
473
            /**
6 andreas 474
             * Show the button with it's current state.
475
             */
476
            void show();
11 andreas 477
            /**
15 andreas 478
             * Hide the button. In case of an animated button, the animation is
479
             * stopped.
480
             *
481
             * @param total
482
             * Optional. When set to TRUE, a transparent button is displayed.
483
             */
484
            void hide(bool total=false);
485
            /**
486
             * This method sends the image together with all data to the GUI,
487
             * where it will be shown. The variable mLastImage must not be
488
             * empty for the method to succeed.
489
             */
490
            void showLastButton();
491
            /**
11 andreas 492
             * Handle a mouse click.
15 andreas 493
             *
494
             * @param pressed
495
             * TRUE = Button was pressed, FALSE = Button was released.
496
             *
497
             * @return
498
             * TRUE = Button was clickable and processed. FALSE = Button was not
499
             * clickable.
11 andreas 500
             */
15 andreas 501
            bool doClick(int x, int y, bool pressed);
3 andreas 502
 
503
        protected:
504
            BUTTONTYPE getButtonType(const std::string& bt);
505
            FEEDBACK getButtonFeedback(const std::string& fb);
10 andreas 506
            SkBitmap drawImageButton(SkBitmap& imgRed, SkBitmap& imgMask, int width, int height, SkColor col1, SkColor col2);
3 andreas 507
 
15 andreas 508
            void funcTimer(const amx::ANET_BLINK& blink);
509
            void funcNetwork(int state);
21 andreas 510
            void funcResource(const RESOURCE_T *resource, const std::string& url, SkBitmap* bm, int instance);
23 andreas 511
            void funcBattery();
15 andreas 512
 
3 andreas 513
        private:
514
            typedef struct IMAGE_t
515
            {
516
                int number{0};
6 andreas 517
                SkBitmap imageMi;
518
                SkBitmap imageBm;
3 andreas 519
 
520
                void clear()
521
                {
522
                    number = 0;
6 andreas 523
                    imageMi.reset();
3 andreas 524
                    imageBm.reset();
525
                }
526
            }IMAGE_t;
527
 
6 andreas 528
            std::function<void (ulong handle, ulong parent, unsigned char *buffer, int width, int height, int pixline, int left, int top)> _displayButton{nullptr};
7 andreas 529
            std::function<void (ulong handle, const std::string& text, const std::string& font, const std::string& family, int size, int x, int y, ulong color, ulong effectColor, FONT_STYLE style, TEXT_ORIENTATION ori, TEXT_EFFECT effect, bool ww)> _setText{nullptr};
21 andreas 530
            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};
6 andreas 531
 
4 andreas 532
            POSITION_t calcImagePosition(int width, int height, CENTER_CODE cc, int number);
533
            int getBorderSize(const std::string& name);
534
            void calcImageSizePercent(int imWidth, int imHeight, int btWidth, int btHeight, int btFrame, int *realX, int *realY);
10 andreas 535
            SkColor baseColor(SkColor basePix, SkColor maskPix, SkColor col1, SkColor col2);
7 andreas 536
            TEXT_EFFECT textEffect(const std::string& effect);
8 andreas 537
            int numberLines(const std::string& str);
538
            std::vector<std::string> splitLine(const std::string& str);
539
            std::vector<std::string> splitLine(const std::string& str, int width, int height, SkFont& font, SkPaint& paint);
540
            SkRect calcRect(int width, int height, int pen);
15 andreas 541
            void runAnimation();    // Method started as thread for button animation
3 andreas 542
 
8 andreas 543
            void getDrawOrder(const std::string& sdo, DRAW_ORDER *order);
544
            bool buttonFill(SkBitmap *bm, int instance);
545
            bool buttonBitmap(SkBitmap *bm, int instance);
21 andreas 546
            bool buttonDynamic(SkBitmap *bm, int instance);
8 andreas 547
            bool buttonIcon(SkBitmap *bm, int instance);
548
            bool buttonText(SkBitmap *bm, int instance);
549
            bool buttonBorder(SkBitmap *bm, int instance);
15 andreas 550
            bool isClickable();
551
            bool isPixelTransparent(int x, int y);
552
            bool barLevel(SkBitmap *bm, int instance, int level);
553
            bool makeElement(int instance=-1);
21 andreas 554
            bool loadImage(SkBitmap *bm, SkBitmap& image, int instance);
15 andreas 555
            void _TimerCallback(ulong counter);
21 andreas 556
            void _imageRefresh(const std::string& url);
23 andreas 557
            void _BatteryCallback(ulong counter);
21 andreas 558
            static THR_REFRESH_t *_addResource(TImageRefresh *refr, ulong handle, ulong parent, int bi);
559
            static THR_REFRESH_t *_findResource(ulong handle, ulong parent, int bi);
8 andreas 560
 
3 andreas 561
            BUTTONTYPE type;
562
            int bi{0};              // button ID
563
            std::string na;         // name
564
            std::string bd;         // Description --> ignored
565
            int lt{0};              // pixel from left
566
            int tp{0};              // pixel from top
567
            int wt{0};              // width
568
            int ht{0};              // height
569
            int zo{0};              // Z-Order
570
            std::string hs;         // bounding, ...
571
            std::string bs;         // Border style (circle, ...)
572
            FEEDBACK fb{FB_NONE};   // momentary, ...
14 andreas 573
            int ap{1};              // Address port (default: 1)
3 andreas 574
            int ad{0};              // Address channel
575
            int ch{0};              // Channel number
14 andreas 576
            int cp{1};              // Channel port (default: 1)
577
            int lp{1};              // Level port (default: 1)
3 andreas 578
            int lv{0};              // Level code
579
            std::string dr;         // Level "horizontal" or "vertical"
580
            int va{0};
581
            int stateCount{0};      // State count with multistate buttons
582
            int rm{0};              // State count with multistate buttons?
15 andreas 583
            int nu{2};              // Animate time up
584
            int nd{2};              // Animate time down
3 andreas 585
            int ar{0};              // Auto repeat (1 = true)
586
            int ru{0};              // Animate time up (bargraph)
587
            int rd{0};              // Animate time down (bargraph)
588
            int lu{0};              // Animate time up (Bargraph)
589
            int ld{0};              // Animate time down (Bargraph)
590
            int rv{0};
591
            int rl{0};              // Range low
592
            int rh{0};              // Range high
593
            int ri{0};              // Bargraph inverted (0 = normal, 1 = inverted)
594
            int rn{0};              // Bargraph: Range drag increment
595
            std::string _if;        // Bargraph function: empty = display only, active, active centering, drag, drag centering
596
            std::string sd;         // Name/Type of slider for a bargraph
597
            std::string sc;         // Color of slider (for bargraph)
598
            int mt{0};              // Length of text area (0 = 2000)
599
            std::string dt;         // "multiple" textarea has multiple lines, else single line
600
            std::string im;         // Input mask of a text area
601
            std::string op;         // String the button send
14 andreas 602
            bool visible{true};     // TRUE=Button is visible
3 andreas 603
            std::vector<PUSH_FUNC_T> pushFunc;  // Push functions: This are executed on button press
604
            std::vector<SR_T> sr;   // The elements the button consists of
7 andreas 605
            TPalette *mPalette{nullptr}; // The color palette
3 andreas 606
            // Image management
607
            std::map<int, IMAGE_t> mImages; // Contains the images in ready to use format, if there any
6 andreas 608
            SkBitmap mLastImage;    // The last calculated image
5 andreas 609
            ulong mHandle{0};       // internal used handle to identify button
7 andreas 610
            int mParentHeight{0};   // The height of the parent page / subpage
611
            int mParentWidth{0};    // The width of the parent page / subpage
16 andreas 612
            bool mEnabled{true};    // By default a button is enabled (TRUE); FALSE = Button disabled
7 andreas 613
            TFont *mFonts{nullptr}; // The font table
10 andreas 614
            int mGlobalOO{-1};      // Opacity of the whole subpage, if any
14 andreas 615
            int mActInstance{0};    // Active instance
8 andreas 616
            DRAW_ORDER mDOrder[ORD_ELEM_COUNT];  // The order to draw the elements of a button
15 andreas 617
            std::thread mThrAni;    // Thread handle for animation
21 andreas 618
            std::thread mThrRes;    // A resouce (download of a remote image/video) running in background
15 andreas 619
            static std::atomic<bool> mAniRunning; // TRUE = Animation is running
620
            int mLastLevel{0};      // The last level value for a bargraph
621
            bool mSystemReg{false}; // TRUE = registered as system button
622
            amx::ANET_BLINK mLastBlink; // This is used for the system clock buttons
21 andreas 623
            TTimer *mTimer{nullptr};    // This is for buttons displaying the time or a date. It's a thread running in background.
624
            static THR_REFRESH_t *mThrRefresh;  // If  we have a source to reread periodicaly, this starts a thread to do that.
625
            bool mResourceRead{false};  // TRUE if the resource should be read only once on startup and this is done.
23 andreas 626
            bool mBatteryTimerRunning{false};   // TRUE = the timer for a battery system button is running
627
            TTimer *mBatteryTimer{nullptr};     // In case the button is a battery system button, this initializes a timer thread.
3 andreas 628
    };
629
 
630
    typedef struct BUTTONS_T
631
    {
632
        TButton *button{nullptr};
633
        BUTTONS_T *previous{nullptr};
634
        BUTTONS_T *next{nullptr};
635
    } BUTTONS_T;
2 andreas 636
}
637
 
638
#endif