mirror of
https://github.com/thorvg/thorvg.git
synced 2025-07-26 08:09:14 +00:00
91 lines
No EOL
3 KiB
C++
91 lines
No EOL
3 KiB
C++
/*
|
|
* Copyright (c) 2020 - 2025 the ThorVG project. All rights reserved.
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
* copies or substantial portions of the Software.
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
* SOFTWARE.
|
|
*/
|
|
|
|
#include "Example.h"
|
|
|
|
/************************************************************************/
|
|
/* ThorVG Drawing Contents */
|
|
/************************************************************************/
|
|
|
|
struct UserExample : tvgexam::Example
|
|
{
|
|
tvg::Shape* solid = nullptr;
|
|
uint32_t w, h;
|
|
|
|
void bbox(tvg::Canvas* canvas, tvg::Paint* paint)
|
|
{
|
|
//aabb
|
|
{
|
|
float x, y, w, h;
|
|
paint->bounds(&x, &y, &w, &h);
|
|
|
|
auto bound = tvg::Shape::gen();
|
|
bound->moveTo(x, y);
|
|
bound->lineTo(x + w, y);
|
|
bound->lineTo(x + w, y + h);
|
|
bound->lineTo(x, y + h);
|
|
bound->close();
|
|
bound->strokeWidth(2.0f);
|
|
bound->strokeFill(255, 0, 0, 255);
|
|
|
|
canvas->push(bound);
|
|
}
|
|
}
|
|
|
|
bool content(tvg::Canvas* canvas, uint32_t w, uint32_t h) override
|
|
{
|
|
//Shape (for BG)
|
|
auto bg = tvg::Shape::gen();
|
|
bg->appendRect(0, 0, w, h);
|
|
bg->fill(255, 255, 255);
|
|
canvas->push(bg);
|
|
|
|
solid = tvg::Shape::gen();
|
|
solid->moveTo(100, 100);
|
|
solid->lineTo(120, 100);
|
|
solid->lineTo(120, 120);
|
|
solid->close();
|
|
solid->fill(0, 0, 0, 255);
|
|
solid->strokeFill(0, 255, 255, 125);
|
|
solid->strokeWidth(5);
|
|
tvg::Matrix m = {3, 0, 450, 0, 3, 100, 0, 0, 1};
|
|
solid->transform(m);
|
|
canvas->push(solid);
|
|
|
|
bbox(canvas, solid);
|
|
|
|
this->w = w;
|
|
this->h = h;
|
|
|
|
return true;
|
|
}
|
|
};
|
|
|
|
|
|
/************************************************************************/
|
|
/* Entry Point */
|
|
/************************************************************************/
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
return tvgexam::main(new UserExample, argc, argv, false, 960, 960);
|
|
} |