| 1 |
/* |
| 2 |
* Copyright (C) 2025 Linux Studio Plugins Project <https://lsp-plug.in/> |
| 3 |
* (C) 2025 Vladimir Sadovnikov <[email protected]> |
| 4 |
* |
| 5 |
* This file is part of lsp-ws-lib |
| 6 |
* Created on: 12 июл. 2022 г. |
| 7 |
* |
| 8 |
* lsp-ws-lib is free software: you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU Lesser General Public License as published by |
| 10 |
* the Free Software Foundation, either version 3 of the License, or |
| 11 |
* any later version. |
| 12 |
* |
| 13 |
* lsp-ws-lib is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU Lesser General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Lesser General Public License |
| 19 |
* along with lsp-ws-lib. If not, see <https://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#include <lsp-plug.in/ws/factory.h> |
| 23 |
#include <lsp-plug.in/ws/IEventHandler.h> |
| 24 |
#include <lsp-plug.in/stdlib/math.h> |
| 25 |
#include <lsp-plug.in/test-fw/mtest.h> |
| 26 |
|
| 27 |
MTEST_BEGIN("ws.display", rtext) |
| 28 |
|
| 29 |
class Handler: public ws::IEventHandler |
| 30 |
{ |
| 31 |
private: |
| 32 |
test_type_t *pTest; |
| 33 |
ws::IWindow *pWnd; |
| 34 |
|
| 35 |
public: |
| 36 |
inline Handler(test_type_t *test, ws::IWindow *wnd) |
| 37 |
{ |
| 38 |
pTest = test; |
| 39 |
pWnd = wnd; |
| 40 |
} |
| 41 |
|
| 42 |
virtual status_t handle_event(const ws::event_t *ev) |
| 43 |
{ |
| 44 |
switch (ev->nType) |
| 45 |
{ |
| 46 |
case ws::UIE_REDRAW: |
| 47 |
{ |
| 48 |
Color c(1.0f, 1.0f, 1.0f); |
| 49 |
ws::ISurface *s = pWnd->get_surface(); |
| 50 |
if (s == NULL) |
| 51 |
return STATUS_OK; |
| 52 |
|
| 53 |
// Perform drawing |
| 54 |
s->begin(); |
| 55 |
s->clear(c); |
| 56 |
|
| 57 |
// Draw the text |
| 58 |
ws::Font f; |
| 59 |
f.set_name("arial"); |
| 60 |
f.set_underline(true); |
| 61 |
|
| 62 |
LSPString str; |
| 63 |
str.set_utf8("Text"); |
| 64 |
|
| 65 |
s->set_antialiasing(false); |
| 66 |
for (size_t y=0; y<3; ++y) |
| 67 |
for (size_t x=0; x<3; ++x) |
| 68 |
{ |
| 69 |
float xx = 100 + x*100; |
| 70 |
float yy = 100 + y*100; |
| 71 |
float dx = x - 1.0f; |
| 72 |
float dy = y - 1.0f; |
| 73 |
|
| 74 |
c.set_rgb24(0x000000); |
| 75 |
f.set_size(32); |
| 76 |
s->out_text_relative(f, c, xx, yy, dx, dy, &str); |
| 77 |
|
| 78 |
c.set_rgb24(0x00cc00); |
| 79 |
f.set_size(12); |
| 80 |
s->out_text_relative(f, c, xx, yy, -dx, -dy, "Текст"); |
| 81 |
|
| 82 |
c.set_rgb24(0x0000ff); |
| 83 |
s->line(c, xx - 48, yy, xx + 48, yy, 1.0f); |
| 84 |
s->line(c, xx, yy - 24, xx, yy + 24, 1.0f); |
| 85 |
|
| 86 |
c.set_rgb24(0xff0000); |
| 87 |
s->line(c, xx - 8, yy - 8, xx + 8, yy + 8, 1.0f); |
| 88 |
s->line(c, xx - 8, yy + 8, xx + 8, yy - 8, 1.0f); |
| 89 |
} |
| 90 |
|
| 91 |
s->end(); |
| 92 |
|
| 93 |
return STATUS_OK; |
| 94 |
} |
| 95 |
|
| 96 |
case ws::UIE_CLOSE: |
| 97 |
{ |
| 98 |
pWnd->hide(); |
| 99 |
pWnd->display()->quit_main(); |
| 100 |
break; |
| 101 |
} |
| 102 |
|
| 103 |
default: |
| 104 |
return IEventHandler::handle_event(ev); |
| 105 |
} |
| 106 |
|
| 107 |
return STATUS_OK; |
| 108 |
} |
| 109 |
}; |
| 110 |
|
| 111 |
MTEST_MAIN |
| 112 |
{ |
| 113 |
ws::IDisplay *dpy = ws::create_display(0, NULL); |
| 114 |
MTEST_ASSERT(dpy != NULL); |
| 115 |
lsp_finally { ws::free_display(dpy); }; |
| 116 |
|
| 117 |
ws::IWindow *wnd = dpy->create_window(); |
| 118 |
MTEST_ASSERT(wnd != NULL); |
| 119 |
lsp_finally { |
| 120 |
wnd->destroy(); |
| 121 |
delete wnd; |
| 122 |
}; |
| 123 |
|
| 124 |
MTEST_ASSERT(wnd->init() == STATUS_OK); |
| 125 |
MTEST_ASSERT(wnd->set_caption("Test relative text") == STATUS_OK); |
| 126 |
MTEST_ASSERT(wnd->set_window_actions(ws::WA_MOVE | ws::WA_CLOSE) == STATUS_OK); |
| 127 |
MTEST_ASSERT(wnd->resize(400, 400) == STATUS_OK); |
| 128 |
MTEST_ASSERT(wnd->set_size_constraints(400, 400, 400, 400) == STATUS_OK); |
| 129 |
|
| 130 |
Handler h(this, wnd); |
| 131 |
wnd->set_handler(&h); |
| 132 |
|
| 133 |
MTEST_ASSERT(wnd->show() == STATUS_OK); |
| 134 |
MTEST_ASSERT(dpy->main() == STATUS_OK); |
| 135 |
} |
| 136 |
|
| 137 |
MTEST_END |
| 138 |
|
| 139 |
|
| 140 |
|