Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

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