Skip to content

Commit b4ab46b

Browse files
togeuilianries
andauthored
(#14055) canvas_ity: add recipe
* canvas_ity: add recipe * fix homepage Co-authored-by: Uilian Ries <[email protected]> Co-authored-by: Uilian Ries <[email protected]>
1 parent d9f2391 commit b4ab46b

File tree

8 files changed

+185
-0
lines changed

8 files changed

+185
-0
lines changed

recipes/canvas_ity/all/conandata.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
sources:
2+
"1.00":
3+
url: "https://github.com/a-e-k/canvas_ity/archive/f32fbb37e2fe7c0fcaee6ebdc02d3e5385603fd5.tar.gz"
4+
sha256: "be0d9ef9a023ba732e403fe8c1ec9e1cd8f02c75777c09562067c9270612a3ed"

recipes/canvas_ity/all/conanfile.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from conan import ConanFile
2+
from conan.tools.files import get, copy, load, save
3+
from conan.tools.layout import basic_layout
4+
import os
5+
6+
7+
required_conan_version = ">=1.50.0"
8+
9+
10+
class CanvasItyConan(ConanFile):
11+
name = "canvas_ity"
12+
description = "A tiny, single-header <canvas>-like 2D rasterizer for C++"
13+
license = "ISC"
14+
url = "https://github.com/conan-io/conan-center-index"
15+
homepage = "https://github.com/a-e-k/canvas_ity"
16+
topics = ("rasterizer", "canvas", "2d", "header-only")
17+
settings = "os", "arch", "compiler", "build_type"
18+
no_copy_source = True
19+
20+
def layout(self):
21+
basic_layout(self, src_folder="src")
22+
23+
def package_id(self):
24+
self.info.clear()
25+
26+
def source(self):
27+
get(self, **self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True)
28+
29+
def build(self):
30+
pass
31+
32+
def package(self):
33+
filename = os.path.join(self.source_folder, "src", "canvas_ity.hpp")
34+
file_content = load(self, filename)
35+
license_end = "// ======== ABOUT ========"
36+
license_contents = file_content[:file_content.find(license_end)].replace("//", "")
37+
save(self, os.path.join(self.package_folder, "licenses", "LICENSE"), license_contents)
38+
39+
copy(
40+
self,
41+
pattern="*.hpp",
42+
dst=os.path.join(self.package_folder, "include"),
43+
src=os.path.join(self.source_folder, "src"),
44+
)
45+
46+
def package_info(self):
47+
self.cpp_info.bindirs = []
48+
self.cpp_info.libdirs = []
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cmake_minimum_required(VERSION 3.1)
2+
project(test_package LANGUAGES CXX)
3+
4+
find_package(canvas_ity REQUIRED CONFIG)
5+
6+
add_executable(${PROJECT_NAME} test_package.cpp)
7+
target_link_libraries(${PROJECT_NAME} PRIVATE canvas_ity::canvas_ity)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from conan import ConanFile
2+
from conan.tools.build import can_run
3+
from conan.tools.cmake import cmake_layout, CMake
4+
import os
5+
6+
7+
class TestPackageConan(ConanFile):
8+
settings = "os", "arch", "compiler", "build_type"
9+
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
10+
test_type = "explicit"
11+
12+
def layout(self):
13+
cmake_layout(self)
14+
15+
def requirements(self):
16+
self.requires(self.tested_reference_str)
17+
18+
def build(self):
19+
cmake = CMake(self)
20+
cmake.configure()
21+
cmake.build()
22+
23+
def test(self):
24+
if can_run(self):
25+
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
26+
self.run(bin_path, env="conanrun")
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#include <algorithm>
2+
#include <fstream>
3+
4+
#define CANVAS_ITY_IMPLEMENTATION
5+
#include "canvas_ity.hpp"
6+
7+
int main() {
8+
// Construct the canvas.
9+
static int const width = 256, height = 256;
10+
canvas_ity::canvas context( width, height );
11+
12+
// Build a star path.
13+
context.move_to( 128.0f, 28.0f ); context.line_to( 157.0f, 87.0f );
14+
context.line_to( 223.0f, 97.0f ); context.line_to( 175.0f, 143.0f );
15+
context.line_to( 186.0f, 208.0f ); context.line_to( 128.0f, 178.0f );
16+
context.line_to( 69.0f, 208.0f ); context.line_to( 80.0f, 143.0f );
17+
context.line_to( 32.0f, 97.0f ); context.line_to( 98.0f, 87.0f );
18+
context.close_path();
19+
20+
// Set up the drop shadow.
21+
context.set_shadow_blur( 8.0f );
22+
context.shadow_offset_y = 4.0f;
23+
context.set_shadow_color( 0.0f, 0.0f, 0.0f, 0.5f );
24+
25+
// Fill the star with yellow.
26+
context.set_color( canvas_ity::fill_style, 1.0f, 0.9f, 0.2f, 1.0f );
27+
context.fill();
28+
29+
// Draw the star with a thick red stroke and rounded points.
30+
context.line_join = canvas_ity::rounded;
31+
context.set_line_width( 12.0f );
32+
context.set_color( canvas_ity::stroke_style, 0.9f, 0.0f, 0.5f, 1.0f );
33+
context.stroke();
34+
35+
// Draw the star again with a dashed thinner orange stroke.
36+
float segments[] = { 21.0f, 9.0f, 1.0f, 9.0f, 7.0f, 9.0f, 1.0f, 9.0f };
37+
context.set_line_dash( segments, 8 );
38+
context.line_dash_offset = 10.0f;
39+
context.line_cap = canvas_ity::circle;
40+
context.set_line_width( 6.0f );
41+
context.set_color( canvas_ity::stroke_style, 0.95f, 0.65f, 0.15f, 1.0f );
42+
context.stroke();
43+
44+
// Turn off the drop shadow.
45+
context.set_shadow_color( 0.0f, 0.0f, 0.0f, 0.0f );
46+
47+
// Add a shine layer over the star.
48+
context.set_linear_gradient( canvas_ity::fill_style, 64.0f, 0.0f, 192.0f, 256.0f );
49+
context.add_color_stop( canvas_ity::fill_style, 0.30f, 1.0f, 1.0f, 1.0f, 0.0f );
50+
context.add_color_stop( canvas_ity::fill_style, 0.35f, 1.0f, 1.0f, 1.0f, 0.8f );
51+
context.add_color_stop( canvas_ity::fill_style, 0.45f, 1.0f, 1.0f, 1.0f, 0.8f );
52+
context.add_color_stop( canvas_ity::fill_style, 0.50f, 1.0f, 1.0f, 1.0f, 0.0f );
53+
54+
context.global_composite_operation = canvas_ity::source_atop;
55+
context.fill_rectangle( 0.0f, 0.0f, 256.0f, 256.0f );
56+
57+
// Fetch the rendered RGBA pixels from the entire canvas.
58+
unsigned char *image = new unsigned char[ height * width * 4 ];
59+
context.get_image_data( image, width, height, width * 4, 0, 0 );
60+
// Write them out to a TGA image file (TGA uses BGRA order).
61+
unsigned char header[] = { 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0,
62+
width & 255, width >> 8, height & 255, height >> 8, 32, 40 };
63+
for ( int pixel = 0; pixel < height * width; ++pixel )
64+
std::swap( image[ pixel * 4 + 0 ], image[ pixel * 4 + 2 ] );
65+
std::ofstream stream( "example.tga", std::ios::binary );
66+
stream.write( reinterpret_cast< char * >( header ), sizeof( header ) );
67+
stream.write( reinterpret_cast< char * >( image ), height * width * 4 );
68+
delete[] image;
69+
70+
return 0;
71+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cmake_minimum_required(VERSION 3.1)
2+
project(test_package)
3+
4+
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5+
conan_basic_setup(TARGETS)
6+
7+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
8+
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from conans import ConanFile, CMake
2+
from conan.tools.build import cross_building
3+
import os
4+
5+
6+
class TestPackageV1Conan(ConanFile):
7+
settings = "os", "arch", "compiler", "build_type"
8+
generators = "cmake", "cmake_find_package_multi"
9+
10+
def build(self):
11+
cmake = CMake(self)
12+
cmake.configure()
13+
cmake.build()
14+
15+
def test(self):
16+
if not cross_building(self):
17+
bin_path = os.path.join("bin", "test_package")
18+
self.run(bin_path, run_environment=True)

recipes/canvas_ity/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
versions:
2+
"1.00":
3+
folder: all

0 commit comments

Comments
 (0)