-
Notifications
You must be signed in to change notification settings - Fork 2k
canvas_ity: add recipe #14055
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
canvas_ity: add recipe #14055
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
sources: | ||
"1.00": | ||
url: "https://github.com/a-e-k/canvas_ity/archive/f32fbb37e2fe7c0fcaee6ebdc02d3e5385603fd5.tar.gz" | ||
sha256: "be0d9ef9a023ba732e403fe8c1ec9e1cd8f02c75777c09562067c9270612a3ed" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from conan import ConanFile | ||
from conan.tools.files import get, copy, load, save | ||
from conan.tools.layout import basic_layout | ||
import os | ||
|
||
|
||
required_conan_version = ">=1.50.0" | ||
|
||
|
||
class CanvasItyConan(ConanFile): | ||
name = "canvas_ity" | ||
description = "A tiny, single-header <canvas>-like 2D rasterizer for C++" | ||
license = "ISC" | ||
url = "https://github.com/conan-io/conan-center-index" | ||
homepage = "https://github.com/project/package" | ||
topics = ("rasterizer", "canvas", "2d", "header-only") | ||
settings = "os", "arch", "compiler", "build_type" | ||
no_copy_source = True | ||
|
||
def layout(self): | ||
basic_layout(self, src_folder="src") | ||
|
||
def package_id(self): | ||
self.info.clear() | ||
|
||
def source(self): | ||
get(self, **self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True) | ||
|
||
def build(self): | ||
pass | ||
|
||
def package(self): | ||
filename = os.path.join(self.source_folder, "src", "canvas_ity.hpp") | ||
file_content = load(self, filename) | ||
license_end = "// ======== ABOUT ========" | ||
license_contents = file_content[:file_content.find(license_end)].replace("//", "") | ||
save(self, os.path.join(self.package_folder, "licenses", "LICENSE"), license_contents) | ||
|
||
copy( | ||
self, | ||
pattern="*.hpp", | ||
dst=os.path.join(self.package_folder, "include"), | ||
src=os.path.join(self.source_folder, "src"), | ||
) | ||
|
||
def package_info(self): | ||
self.cpp_info.bindirs = [] | ||
self.cpp_info.libdirs = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
project(test_package LANGUAGES CXX) | ||
|
||
find_package(canvas_ity REQUIRED CONFIG) | ||
|
||
add_executable(${PROJECT_NAME} test_package.cpp) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE canvas_ity::canvas_ity) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from conan import ConanFile | ||
from conan.tools.build import can_run | ||
from conan.tools.cmake import cmake_layout, CMake | ||
import os | ||
|
||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "arch", "compiler", "build_type" | ||
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" | ||
test_type = "explicit" | ||
|
||
def layout(self): | ||
cmake_layout(self) | ||
|
||
def requirements(self): | ||
self.requires(self.tested_reference_str) | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def test(self): | ||
if can_run(self): | ||
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") | ||
self.run(bin_path, env="conanrun") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include <algorithm> | ||
#include <fstream> | ||
|
||
#define CANVAS_ITY_IMPLEMENTATION | ||
#include "canvas_ity.hpp" | ||
|
||
int main() { | ||
// Construct the canvas. | ||
static int const width = 256, height = 256; | ||
canvas_ity::canvas context( width, height ); | ||
|
||
// Build a star path. | ||
context.move_to( 128.0f, 28.0f ); context.line_to( 157.0f, 87.0f ); | ||
context.line_to( 223.0f, 97.0f ); context.line_to( 175.0f, 143.0f ); | ||
context.line_to( 186.0f, 208.0f ); context.line_to( 128.0f, 178.0f ); | ||
context.line_to( 69.0f, 208.0f ); context.line_to( 80.0f, 143.0f ); | ||
context.line_to( 32.0f, 97.0f ); context.line_to( 98.0f, 87.0f ); | ||
context.close_path(); | ||
|
||
// Set up the drop shadow. | ||
context.set_shadow_blur( 8.0f ); | ||
context.shadow_offset_y = 4.0f; | ||
context.set_shadow_color( 0.0f, 0.0f, 0.0f, 0.5f ); | ||
|
||
// Fill the star with yellow. | ||
context.set_color( canvas_ity::fill_style, 1.0f, 0.9f, 0.2f, 1.0f ); | ||
context.fill(); | ||
|
||
// Draw the star with a thick red stroke and rounded points. | ||
context.line_join = canvas_ity::rounded; | ||
context.set_line_width( 12.0f ); | ||
context.set_color( canvas_ity::stroke_style, 0.9f, 0.0f, 0.5f, 1.0f ); | ||
context.stroke(); | ||
|
||
// Draw the star again with a dashed thinner orange stroke. | ||
float segments[] = { 21.0f, 9.0f, 1.0f, 9.0f, 7.0f, 9.0f, 1.0f, 9.0f }; | ||
context.set_line_dash( segments, 8 ); | ||
context.line_dash_offset = 10.0f; | ||
context.line_cap = canvas_ity::circle; | ||
context.set_line_width( 6.0f ); | ||
context.set_color( canvas_ity::stroke_style, 0.95f, 0.65f, 0.15f, 1.0f ); | ||
context.stroke(); | ||
|
||
// Turn off the drop shadow. | ||
context.set_shadow_color( 0.0f, 0.0f, 0.0f, 0.0f ); | ||
|
||
// Add a shine layer over the star. | ||
context.set_linear_gradient( canvas_ity::fill_style, 64.0f, 0.0f, 192.0f, 256.0f ); | ||
context.add_color_stop( canvas_ity::fill_style, 0.30f, 1.0f, 1.0f, 1.0f, 0.0f ); | ||
context.add_color_stop( canvas_ity::fill_style, 0.35f, 1.0f, 1.0f, 1.0f, 0.8f ); | ||
context.add_color_stop( canvas_ity::fill_style, 0.45f, 1.0f, 1.0f, 1.0f, 0.8f ); | ||
context.add_color_stop( canvas_ity::fill_style, 0.50f, 1.0f, 1.0f, 1.0f, 0.0f ); | ||
|
||
context.global_composite_operation = canvas_ity::source_atop; | ||
context.fill_rectangle( 0.0f, 0.0f, 256.0f, 256.0f ); | ||
|
||
// Fetch the rendered RGBA pixels from the entire canvas. | ||
unsigned char *image = new unsigned char[ height * width * 4 ]; | ||
context.get_image_data( image, width, height, width * 4, 0, 0 ); | ||
// Write them out to a TGA image file (TGA uses BGRA order). | ||
unsigned char header[] = { 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
width & 255, width >> 8, height & 255, height >> 8, 32, 40 }; | ||
for ( int pixel = 0; pixel < height * width; ++pixel ) | ||
std::swap( image[ pixel * 4 + 0 ], image[ pixel * 4 + 2 ] ); | ||
std::ofstream stream( "example.tga", std::ios::binary ); | ||
stream.write( reinterpret_cast< char * >( header ), sizeof( header ) ); | ||
stream.write( reinterpret_cast< char * >( image ), height * width * 4 ); | ||
delete[] image; | ||
|
||
return 0; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
project(test_package) | ||
|
||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_basic_setup(TARGETS) | ||
|
||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/ | ||
${CMAKE_CURRENT_BINARY_DIR}/test_package/) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from conans import ConanFile, CMake | ||
from conan.tools.build import cross_building | ||
import os | ||
|
||
|
||
class TestPackageV1Conan(ConanFile): | ||
settings = "os", "arch", "compiler", "build_type" | ||
generators = "cmake", "cmake_find_package_multi" | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def test(self): | ||
if not cross_building(self): | ||
bin_path = os.path.join("bin", "test_package") | ||
self.run(bin_path, run_environment=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
versions: | ||
"1.00": | ||
folder: all |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.