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