Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
61 andreas 1
/*
334 andreas 2
 * Copyright (C) 2021 to 2023 by Andreas Theofilu <andreas@theosys.at>
61 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
 
19
#include "tqemitqueue.h"
20
#include "terror.h"
21
 
22
TQManageQueue::~TQManageQueue()
23
{
24
    DECL_TRACER("TQManageQueue::~TQManageQueue()");
25
 
26
    TQEmitQueue *next, *p = mEmitQueue;
27
    next = nullptr;
28
 
29
    while (p)
30
    {
31
        next = p->next;
32
        delete p;
33
        p = next;
34
    }
35
}
36
 
262 andreas 37
#ifdef _OPAQUE_SKIA_
289 andreas 38
void TQManageQueue::addBackground(ulong handle, TBitmap& image, int width, int height, ulong color)
262 andreas 39
#else
289 andreas 40
void TQManageQueue::addBackground(ulong handle, TBitmap& image, int width, int height, ulong color, int opacity)
262 andreas 41
#endif
61 andreas 42
{
289 andreas 43
    DECL_TRACER("TQManageQueue::addBackground(ulong handle, TBitmap& image, int width, int height, ulong color [, int opacity])");
61 andreas 44
 
45
    TQEmitQueue *eq = addEntity(ET_BACKGROUND);
46
 
47
    if (!eq)
48
        return;
49
 
50
    eq->handle = handle;
289 andreas 51
    eq->bitmap = image;
61 andreas 52
    eq->width = width;
53
    eq->height = height;
54
    eq->color = color;
262 andreas 55
#ifndef _OPAQUE_SKIA_
56
    eq->opacity = opacity;
57
#endif
61 andreas 58
    removeDuplicates();
59
}
60
 
262 andreas 61
#ifdef _OPAQUE_SKIA_
289 andreas 62
bool TQManageQueue::getBackground(ulong* handle, TBitmap *image, int* width, int* height, ulong* color)
262 andreas 63
#else
289 andreas 64
bool TQManageQueue::getBackground(ulong* handle, TBitmap **image, int* width, int* height, ulong* color, int *opacity)
262 andreas 65
#endif
61 andreas 66
{
289 andreas 67
    DECL_TRACER("TQManageQueue::getBackground(ulong* handle, TBitmap **image, int* width, int* height, ulong* color [, int *opacity])");
61 andreas 68
 
69
    TQEmitQueue *eq = mEmitQueue;
70
 
71
    while(eq)
72
    {
73
        if (eq->etype == ET_BACKGROUND)
74
        {
75
            *handle = eq->handle;
289 andreas 76
            *image = eq->bitmap;
61 andreas 77
            *width = eq->width;
78
            *height = eq->height;
79
            *color = eq->color;
262 andreas 80
#ifndef _OPAQUE_SKIA_
81
            if (opacity)
82
                *opacity = eq->opacity;
83
#endif
61 andreas 84
            return true;
85
        }
86
 
87
        eq = eq->next;
88
    }
89
 
90
    return false;
91
}
92
 
298 andreas 93
void TQManageQueue::addButton(ulong handle, ulong parent, TBitmap& buffer, int left, int top, int width, int height, bool passthrough)
61 andreas 94
{
298 andreas 95
    DECL_TRACER("TQManageQueue::addButton(ulong handle, ulong parent, TBitmap& buffer, int left, int top, int width, int height, bool passthrough)");
61 andreas 96
 
97
    TQEmitQueue *eq = addEntity(ET_BUTTON);
98
 
99
    if (!eq)
100
        return;
101
 
102
    eq->handle = handle;
103
    eq->parent = parent;
289 andreas 104
    eq->bitmap = buffer;
61 andreas 105
    eq->left = left;
106
    eq->top = top;
107
    eq->width = width;
108
    eq->height = height;
298 andreas 109
    eq->view = passthrough;
61 andreas 110
    removeDuplicates();
111
}
112
 
289 andreas 113
void TQManageQueue::addViewButton(ulong handle, ulong parent, bool vertical, TBitmap& buffer, int left, int top, int width, int height, int space, TColor::COLOR_T fillColor)
279 andreas 114
{
289 andreas 115
    DECL_TRACER("TQManageQueue::addViewButton(ulong handle, ulong parent, TBitmap& buffer, int left, int top, int width, int height, int space, TColor::COLOR_T fillColor)");
279 andreas 116
 
117
    TQEmitQueue *eq = addEntity(ET_BUTTON);
118
 
119
    if (!eq)
120
        return;
121
 
122
    eq->handle = handle;
123
    eq->parent = parent;
289 andreas 124
    eq->bitmap = buffer;
279 andreas 125
    eq->left = left;
126
    eq->top = top;
127
    eq->width = width;
128
    eq->height = height;
129
    eq->view = true;
280 andreas 130
    eq->vertical = vertical;
289 andreas 131
    eq->amxColor = fillColor;
132
    eq->space = space;
279 andreas 133
    removeDuplicates();
134
}
135
 
298 andreas 136
bool TQManageQueue::getButton(ulong* handle, ulong* parent, TBitmap *buffer, int* left, int* top, int* width, int* height, bool *passthrough)
61 andreas 137
{
298 andreas 138
    DECL_TRACER("TQManageQueue::getButton(ulong* handle, ulong* parent, TBitmap **buffer, int* left, int* top, int* width, int* height, bool *passthrough)");
61 andreas 139
 
140
    TQEmitQueue *eq = mEmitQueue;
141
 
142
    while(eq)
143
    {
144
        if (eq->etype == ET_BUTTON)
145
        {
146
            *handle = eq->handle;
147
            *parent = eq->parent;
289 andreas 148
            *buffer = eq->bitmap;
61 andreas 149
            *left = eq->left;
150
            *top = eq->top;
151
            *width = eq->width;
152
            *height = eq->height;
298 andreas 153
            *passthrough = eq->view;
61 andreas 154
            return true;
155
        }
156
 
157
        eq = eq->next;
158
    }
159
 
160
    return false;
161
}
162
 
289 andreas 163
bool TQManageQueue::getViewButton(ulong *handle, ulong *parent, bool *vertical, TBitmap *buffer, int *left, int *top, int *width, int *height, int *space, TColor::COLOR_T *fillColor)
164
{
165
    DECL_TRACER("TQManageQueue::getViewButton(ulong *handle, ulong *parent, bool *vertical, TBitmap *buffer, int *left, int *top, int *width, int *height, TColor::COLOR_T *fillColor)");
166
 
167
    TQEmitQueue *eq = mEmitQueue;
168
 
169
    while(eq)
170
    {
171
        if (eq->etype == ET_BUTTON)
172
        {
173
            *handle = eq->handle;
174
            *parent = eq->parent;
175
            *buffer = eq->bitmap;
176
            *left = eq->left;
177
            *top = eq->top;
178
            *width = eq->width;
179
            *height = eq->height;
180
            *vertical = eq->vertical;
181
            *fillColor = eq->amxColor;
182
            *space = eq->space;
183
            return true;
184
        }
185
 
186
        eq = eq->next;
187
    }
188
 
189
    return false;
190
}
191
 
192 andreas 192
void TQManageQueue::addInText(ulong handle, Button::TButton* button, Button::BITMAP_t bm, int frame)
61 andreas 193
{
192 andreas 194
    DECL_TRACER("TQManageQueue::addInText(ulong handle, Button::TButton* button, Button::BITMAP_t bm, int frame)");
61 andreas 195
 
196
    TQEmitQueue *eq = addEntity(ET_INTEXT);
197
 
198
    if (!eq)
199
        return;
200
 
201
    eq->handle = handle;
202
    eq->button = button;
203
    eq->bm = bm;
192 andreas 204
    eq->frame = frame;
61 andreas 205
    removeDuplicates();
206
}
207
 
200 andreas 208
void TQManageQueue::addListBox(Button::TButton* button, Button::BITMAP_t bm, int frame)
209
{
210
    DECL_TRACER("TQManageQueue::addListBox(Button::TButton* button, Button::BITMAP_t bm, int frame)");
211
 
212
    TQEmitQueue *eq = addEntity(ET_LISTBOX);
213
 
214
    if (!eq)
215
        return;
216
 
217
    eq->handle = button->getHandle();
218
    eq->button = button;
219
    eq->bm = bm;
220
    eq->frame = frame;
221
    removeDuplicates();
222
}
223
 
192 andreas 224
bool TQManageQueue::getInText(ulong* handle, Button::TButton ** button, Button::BITMAP_t* bm, int *frame)
61 andreas 225
{
192 andreas 226
    DECL_TRACER("TQManageQueue::getInText(ulong* handle, Button::TButton ** button, Button::BITMAP_t* bm, int *frame)");
61 andreas 227
 
228
    TQEmitQueue *eq = mEmitQueue;
229
 
230
    while(eq)
231
    {
232
        if (eq->etype == ET_INTEXT)
233
        {
234
            *handle = eq->handle;
235
            *button = eq->button;
236
            *bm = eq->bm;
192 andreas 237
            *frame = eq->frame;
61 andreas 238
            return true;
239
        }
240
    }
241
 
242
    return false;
243
}
244
 
245
void TQManageQueue::addPage(ulong handle, int width, int height)
246
{
247
    DECL_TRACER("TQManageQueue::addPage(ulong handle, int width, int height)");
248
 
249
    TQEmitQueue *eq = addEntity(ET_PAGE);
250
 
251
    if (!eq)
252
        return;
253
 
254
    eq->handle = handle;
255
    eq->width = width;
256
    eq->height = height;
257
    removeDuplicates();
258
}
259
 
260
bool TQManageQueue::getPage(ulong* handle, int* width, int* height)
261
{
262
    DECL_TRACER("TQManageQueue::getPage(ulong* handle, int* width, int* height)");
263
 
264
    TQEmitQueue *eq = mEmitQueue;
265
 
266
    while(eq)
267
    {
268
        if (eq->etype == ET_PAGE)
269
        {
270
            *handle = eq->handle;
271
            *width = eq->width;
272
            *height = eq->height;
273
            return true;
274
        }
275
    }
276
 
277
    return false;
278
}
279
 
262 andreas 280
#ifdef _OPAQUE_SKIA_
217 andreas 281
void TQManageQueue::addSubPage(ulong handle, ulong parent, int left, int top, int width, int height, ANIMATION_t anim)
262 andreas 282
#else
283
void TQManageQueue::addSubPage(ulong handle, ulong parent, int left, int top, int width, int height, ANIMATION_t anim, int opacity)
284
#endif
61 andreas 285
{
217 andreas 286
    DECL_TRACER("TQManageQueue::addSubPage(ulong handle, ulong parent, int left, int top, int width, int height, ANIMATION_t anim)");
61 andreas 287
 
288
    TQEmitQueue *eq = addEntity(ET_SUBPAGE);
289
 
290
    if (!eq)
291
        return;
292
 
293
    eq->handle = handle;
217 andreas 294
    eq->parent = parent;
61 andreas 295
    eq->left = left;
296
    eq->top = top;
297
    eq->width = width;
298
    eq->height = height;
299
    eq->animate = anim;
262 andreas 300
#ifndef _OPAQUE_SKIA_
301
    eq->opacity = opacity;
302
#endif
61 andreas 303
    removeDuplicates();
304
}
305
 
262 andreas 306
#ifdef _OPAQUE_SKIA_
217 andreas 307
bool TQManageQueue::getSubPage(ulong* handle, ulong *parent, int* left, int* top, int* width, int* height, ANIMATION_t* anim)
262 andreas 308
#else
309
bool TQManageQueue::getSubPage(ulong* handle, ulong *parent, int* left, int* top, int* width, int* height, ANIMATION_t* anim, int *opacity)
310
#endif
61 andreas 311
{
217 andreas 312
    DECL_TRACER("TQManageQueue::getSubPage(ulong* handle, ulong *parent, int* left, int* top, int* width, int* height, ANIMATION_t* anim)");
61 andreas 313
 
314
    TQEmitQueue *eq = mEmitQueue;
315
 
316
    while(eq)
317
    {
318
        if (eq->etype == ET_SUBPAGE)
319
        {
320
            *handle = eq->handle;
217 andreas 321
            *parent = eq->parent;
61 andreas 322
            *left = eq->left;
323
            *top = eq->top;
324
            *width = eq->width;
325
            *height = eq->height;
326
            *anim = eq->animate;
262 andreas 327
#ifndef _OPAQUE_SKIA_
328
            if (opacity)
329
                *opacity = eq->opacity;
330
#endif
61 andreas 331
            return true;
332
        }
333
 
334
        eq = eq->next;
335
    }
336
 
337
    return false;
338
}
339
 
300 andreas 340
void TQManageQueue::addVideo(ulong handle, ulong parent, int left, int top, int width, int height, std::string url, std::string user, std::string pw)
61 andreas 341
{
300 andreas 342
    DECL_TRACER("TQManageQueue::addVideo(ulong handle, ulong parent, int left, int top, int width, int height, std::string url, std::string user, std::string pw)");
61 andreas 343
 
344
    TQEmitQueue *eq = addEntity(ET_VIDEO);
345
 
346
    if (!eq)
347
        return;
348
 
349
    eq->handle = handle;
350
    eq->parent = parent;
351
    eq->left = left;
352
    eq->top = top;
353
    eq->width = width;
354
    eq->height = height;
355
    eq->url = url;
356
    eq->user = user;
357
    eq->pw = pw;
358
    removeDuplicates();
359
}
360
 
361
bool TQManageQueue::getVideo(ulong* handle, ulong* parent, int* left, int* top, int* width, int* height, std::string* url, std::string* user, std::string* pw)
362
{
363
    DECL_TRACER("TQManageQueue::getVideo(ulong* handle, ulong* parent, int* left, int* top, int* width, int* height, std::string* url, std::string* user, std::string* pw)");
364
 
365
    TQEmitQueue *eq = mEmitQueue;
366
 
367
    while(eq)
368
    {
369
        if (eq->etype == ET_VIDEO)
370
        {
371
            *handle = eq->handle;
372
            *parent = eq->parent;
373
            *left = eq->left;
374
            *top = eq->top;
375
            *width = eq->width;
376
            *height = eq->height;
377
            *url = eq->url;
378
            *user = eq->user;
379
            *pw = eq->pw;
380
            return true;
381
        }
382
 
383
        eq = eq->next;
384
    }
385
 
386
    return false;
387
}
388
 
389
_EMIT_TYPE_t TQManageQueue::getNextType()
390
{
391
    DECL_TRACER("TQManageQueue::getNextType()");
392
 
393
    if (!mEmitQueue)
394
        return ET_NONE;
395
 
396
    return mEmitQueue->etype;
397
}
398
 
399
bool TQManageQueue::isDeleted()
400
{
401
    DECL_TRACER("TQManageQueue::isDeleted()");
402
 
403
    if (!mEmitQueue)
404
        return false;
405
 
406
    return mEmitQueue->isDropped();
407
}
408
 
409
/**
410
 * This deletes the first occurance of the \p handle in the queue.
411
 *
412
 * @param handle    The handle number.
413
 * @return If the \p handle was found in the queue TRUE is returned.
414
 */
415
bool TQManageQueue::dropHandle(ulong handle)
416
{
417
    DECL_TRACER("TQManageQueue::dropHandle(ulong handle)");
418
 
419
    TQEmitQueue *prev, *next, *p = mEmitQueue;
420
    prev = next = nullptr;
421
 
422
    while (p)
423
    {
424
        next = p->next;
425
 
426
        if (p->handle == handle)
427
        {
428
            if (prev)
429
                prev->next = next;
430
 
431
            if (p == mEmitQueue)
432
                mEmitQueue = next;
433
 
434
            delete p;
435
            return true;
436
        }
437
 
438
        prev = p;
439
        p = p->next;
440
    }
441
 
442
    return false;
443
}
444
 
445
/**
446
 * This deletes the first occurance of the \p t in the queue.
447
 *
448
 * @param t     The type.
449
 * @return If \p t was found in the queue TRUE is returned.
450
 */
451
bool TQManageQueue::dropType(_EMIT_TYPE_t t)
452
{
453
    DECL_TRACER("TQManageQueue::dropType(_EMIT_TYPE_t t)");
454
 
455
    TQEmitQueue *prev, *next, *p = mEmitQueue;
456
    prev = next = nullptr;
457
 
458
    while (p)
459
    {
460
        next = p->next;
461
 
462
        if (p->etype == t)
463
        {
464
            if (prev)
465
                prev->next = next;
466
 
467
            if (p == mEmitQueue)
468
                mEmitQueue = next;
469
 
470
            delete p;
471
            return true;
472
        }
473
 
474
        prev = p;
475
        p = p->next;
476
    }
477
 
478
    return false;
479
}
480
 
481
void TQManageQueue::markDrop(ulong handle)
482
{
483
    DECL_TRACER("TQManageQueue::markDrop(ulong handle)");
484
 
485
    TQEmitQueue *eq = mEmitQueue;
486
 
487
    while (eq)
488
    {
489
        if (eq->handle == handle)
490
        {
491
            eq->markDropped();
492
            return;
493
        }
494
 
495
        eq = eq->next;
496
    }
497
}
498
 
499
TQEmitQueue *TQManageQueue::addEntity(_EMIT_TYPE_t etype)
500
{
501
    DECL_TRACER("TQManageQueue::addEntity(_EMIT_TYPE_t etype)");
502
 
503
    TQEmitQueue *eq;
504
 
505
    try
506
    {
507
        eq = new TQEmitQueue;
508
        eq->etype = etype;
509
 
510
        if (!mEmitQueue)
511
            mEmitQueue = eq;
512
        else
513
        {
514
            TQEmitQueue *p = mEmitQueue;
515
 
516
            while(p->next)
517
                p = p->next;
518
 
519
            p->next = eq;
520
        }
521
    }
522
    catch (std::exception& e)
523
    {
524
        MSG_ERROR("Memory error: " << e.what());
525
        return nullptr;
526
    }
527
 
528
    return eq;
529
}
530
 
531
/**
532
 * This is a kind of garbage collector. It scans the queue for duplicate
533
 * entries and removes the oldest ones. An entry is duplicate if it has the
534
 * same handle number and, to be sure, the same type.
535
 * This method makes sure, that the queue contains no more events than
536
 * necessary. This reduces the drawings on the surface and an object is drawn
537
 * only once after the application became active.
538
 */
539
void TQManageQueue::removeDuplicates()
540
{
541
    DECL_TRACER("TQManageQueue::removeDuplicates()");
542
 
543
    TQEmitQueue *prev, *eq = mEmitQueue;
544
    prev = nullptr;
545
    bool noInc = false;
546
 
547
    if (!eq)
548
        return;
549
 
550
    while(eq)
551
    {
552
        TQEmitQueue *p = mEmitQueue;
553
 
554
        while(p)
555
        {
556
            if (p == eq)
557
            {
558
                p = p->next;
559
                continue;
560
            }
561
 
562
            if (p->handle == eq->handle && p->etype == eq->etype)   // Remove the duplicate;
563
            {
564
                if (!prev)
565
                {
566
                    mEmitQueue = mEmitQueue->next;
567
                    delete eq;
568
                    eq = mEmitQueue;
569
                    noInc = true;
570
                }
571
                else
572
                {
573
                    prev->next = eq->next;
574
                    delete eq;
575
                    eq = prev;
576
                }
577
 
578
                break;
579
            }
580
 
581
            p = p->next;
582
        }
583
 
584
        if (noInc)
585
        {
586
            noInc = false;
587
            continue;
588
        }
589
 
590
        prev = eq;
591
        eq = eq->next;
592
    }
593
}