Giter Site home page Giter Site logo

kcanvas's Introduction

kcanvas

Yet another 2D API abstraction

Build status

What is it

kcanvas is easy to use C++ API for rendering 2D graphics. Its main purpose is to make 2D graphics programming easier and hide nasty details of platform specific graphics APIs. It's crossplatform and has native implementation for supported platforms (Direct2D on windows, Quartz on Mac OS X, Cairo on Linux). It's suitable for rendering 2D graphics such as user interfaces, data visualization, diagrams and other text and visual content. It's not intended to be used in interactive games, however simple 2D game could be rendered with kcanvas API.

This project is under development now, so not all of its features are implemented and
not all platforms are fully supported

Windows demo and examples binaries

What it does

kcanvas API is able to render 2D vector and raster graphics. You can stroke and fill different simple and complex shapes with many different styles, render text with different fonts available in your system. Here is sample image which shows what you can render with help of kcanvas API:
kcanvas demo image

Features

  • Commonly used predefined shapes (line, bezier, arc, rectangle, rounded rectangle, ellipse, poly lines and polygons)
  • Shapes of arbitrary complexity
  • Many different line stroke styles, line join styles
  • Several fill styles (solid, linear and radial gradients, bitmap)
  • Full alpha transparency support
  • Clipping to shapes and masking by grayscale images, mask fill with brush
  • Bitmap rendering (with alpha channel support)
  • Arbitrary transformation stack (via 3x2 matrix)
  • Text measurement and rendering (with simple layouts)

Ongoing development
The Roadmap wiki page contains some information about current project status and ongoing feature support and development plans.

How it works

In kcanvas API all of painting functions tied to kCanvas class. kCanvas object can't be instantiated directly, you need to use specific implementation to direct painting to specific device or kBitmap object. You can use kContextCanvas to paint into window and kBitmapCanvas to paint into kBitmap object.

Most of the properties for painting operation are taken from special resource objects, in general kcanvas API is stateless with few exceptions. Resource objects are immutable โ€“ once created their properties can't be changed. Some of resource objects can't be copied (kBitmap and kGradient) and always remains unique.

  • kStroke object holds properties for line style. It defines line pattern, line join style and line caps style.
  • kGradient object holds color gradient definition.
  • kPen object holds properties for stroke (outline painting) operations, it incapsulates kStroke and kBrush objects.
  • kBrush object holds properties for fill operations.
  • kFont object holds font properties for text painting (and measuring).
  • kPath object holds geometric shape data.
  • kBitmap object holds raster image data.

See reference wiki pages for full kcanvas API types and classes reference.
See guide wiki page for general kcanvas concepts and usage.

Under the hood kcanvas API uses one of existing platform specific APIs, such as Direct2D on Windows platform.

How to use

Having proper setup of your project for using kcanvas library (correct path to kcanvas include directory and kcanvas library linked into project) you only need to include kcanvas/canvas.h header in your source to get all kcanvas API stuff. To paint something you need to instantiate kContextCanvas object and issue painting commands.

Here is quick "Hello world" example:

// DeviceContext is platform dependent context descriptor,
// such as HDC or CGContextRef
kContextCanvas canvas(DeviceContext);

// create some resource objects for painting

// orange solid pen, 4 pixels wide
kPen pen(kColor(255, 127, 39), 4);
// yellow solid brush
kBrush brush(kColor(255, 201, 14));
// black solid brush
kBrush black(kColor::Black);
// font
kFont font("Tahoma", 50, kFontStyle::Bold);

// text to paint
const char *text = "Hello world!";

// measure text to find out rectangle which can include this text
kSize textsize = canvas.TextSize(text, -1, font);

// paint rectangle with outline
canvas.Rectangle(kRect(kPoint(10), textsize + 20), &pen, &brush);

// paint text
canvas.Text(kPoint(20, 20), text, -1, font, black);

Result:
kcanvas hello world

Please visit examples wiki page for additional information and usage examples.

How to build

Please visit guide wiki page for build instructions.

Copyright and licensing

kcanvas 2D Graphics Library

Copyright (C) 2015 โ€“ 2017, livingcreative (https://github.com/livingcreative)
All rights reserved.

Redistribution and use in source and/or binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • The name of the author may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.

License file

kcanvas's People

Contributors

livingcreative avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

kcanvas's Issues

header missing for win32

hi,
trying compile ion windows
on file canvastypes.h doesn't found header files
kcommon/c_util.h
kcommon/c_geometry.h

theirs files are not in the archive?
thanks,

General: prepare first alpha release

Prepare and release first fully working alpha version.

  1. Basic API should work and finished
  2. Direct2D implementation is enough for 1st alpha
  3. Examples should work
  4. Check all "must to know" info in readme and wiki
  5. Check builds for library and examples
  6. Add binaries and premade solutions for Windows build

Any new developments with KCanvas?

Any new developments with KCanvas? After so many years, there should be a more refined version, right? KCanvas is still very good code with certain applications.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.