Debian Codegraph @

modules/lsp-ws-lib/src/test/mtest/display/surface.cpp

raw
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: 7 июл. 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", surface)
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 ws::ISurface *x = s->create(160, 100);
58 if (x != NULL)
59 {
60 lsp_finally {
61 x->destroy();
62 delete x;
63 };
64
65 x->begin();
66 c.set_rgba32(0x88cccc00);
67 x->wire_rect(c, SURFMASK_NO_CORNER, 0.0f, 0.0f, 0.0f, 160, 100, 25.0f);
68
69 c.set_rgba32(0x00ff0000);
70 x->fill_rect(c, SURFMASK_NO_CORNER, 0.0f, 0.0f, 0.0f, 10.0f, 10.0f);
71
72 c.set_rgba32(0x8800ccff);
73 x->fill_rect(c, SURFMASK_NONE, 0.0f, 0.0f, 0.0f, 80.0f, 100.0f);
74 c.set_rgb24(0xccff00);
75 x->line(c, 0.0f, 0.0f, 160.0f, 100.0f, 2.0f);
76 x->line(c, 0.0f, 100.0f, 160.0f, 0.0f, 2.0f);
77 c.set_rgb24(0x888888);
78 x->wire_rect(c, SURFMASK_NONE, 0.0f, 0.0f, 0.0f, 160, 100, 1.0f);
79 x->end();
80
81 s->draw(x, 0.0f, 0.0f, 2.0f, 2.0f, 0.0f);
82 s->draw(x, 320.0f, 0.0f, 1.0f, 1.0f, 0.0f);
83 s->draw(x, 320.0f, 100.0f, 1.0f, 1.0f, 0.5f);
84 s->draw_rotate(x, 320, 240, 1.0f, 1.0f, M_PI * 0.5f, 0.5f);
85 s->draw_rotate(x, 160, 240, 1.0f, 1.0f, M_PI / 6.0f, 0.5f);
86 s->draw(x, 320, 200, 1.5f, 1.5f, 0.0f);
87 }
88
89 s->end();
90
91 return STATUS_OK;
92 }
93
94 case ws::UIE_CLOSE:
95 {
96 pWnd->hide();
97 pWnd->display()->quit_main();
98 break;
99 }
100
101 default:
102 return IEventHandler::handle_event(ev);
103 }
104
105 return STATUS_OK;
106 }
107 };
108
109 MTEST_MAIN
110 {
111 ws::IDisplay *dpy = ws::create_display(0, NULL);
112 MTEST_ASSERT(dpy != NULL);
113 lsp_finally { ws::free_display(dpy); };
114
115 ws::IWindow *wnd = dpy->create_window();
116 MTEST_ASSERT(wnd != NULL);
117 lsp_finally {
118 wnd->destroy();
119 delete wnd;
120 };
121
122 MTEST_ASSERT(wnd->init() == STATUS_OK);
123 MTEST_ASSERT(wnd->set_caption("Test surface") == STATUS_OK);
124 MTEST_ASSERT(wnd->set_window_actions(ws::WA_MOVE | ws::WA_CLOSE) == STATUS_OK);
125 MTEST_ASSERT(wnd->resize(640, 400) == STATUS_OK);
126 MTEST_ASSERT(wnd->set_size_constraints(640, 400, 640, 400) == STATUS_OK);
127
128 Handler h(this, wnd);
129 wnd->set_handler(&h);
130
131 MTEST_ASSERT(wnd->show() == STATUS_OK);
132
133 MTEST_ASSERT(dpy->main() == STATUS_OK);
134 }
135
136 MTEST_END
137
138
139