Code Monkey home page Code Monkey logo

cn1pisces's Introduction

#Codename One 2D Graphics Library (Pisces)

This is a port of the Pisces graphics library for use with Codename One applications. It provides a 2D drawing canvas that can be used for drawing arbitrary shapes and paths in Codename One.

##License

GPL with CLASSPATH exception

##Features

  1. Draw shapes (ovals, rectangles, lines, polygons, and arbitrary paths).
  2. Path drawing supports moveTo(), lineTo(), quadTo(), and cubicTo() methods. This is all of the primitive drawing operations that should be necessary for doing all/most 2D drawing.
  3. Affine Transforms
  4. Draw images
  5. Supports drawing strings, but this has not been tested yet and likely requires more work to port this over.
  6. Supports all platforms that Codename One runs on. Including (but not limited to) iOS, Android, Windows Phone, Blackberry, and J2ME.

##Installation

  1. Copy the CN1Pisces.cn1lib file into your project's lib directory.
  2. Refresh libs in your project. In Netbeans this can be done by right-clicking the project icon in the project explorer, and selecting "Refresh Libs"

##Basic Usage Example

This example creates a simple form that, when pressed, draws a red oval the width and height of the screen. Notice the general pattern where you use the pisces.Graphics class to perform your drawing, then use its getImage() method to obtain a Codename One Image of the graphics. This image can be displayed in a number of ways, but this example sets it as the icon of a label since that is (probably) the simplest way.


	public void startPisces() {
       
        if(current != null){
            current.show();
            return;                
        }
        Image img  = drawCircle(Display.getInstance().getDisplayWidth(), Display.getInstance().getDisplayHeight());
        final Label l = new Label(img);
        Form hi = new Form("Hi World"){



            @Override
            public void pointerPressed(int x, int y) {
                Image img = drawCircle(x, y);
                l.setIcon(img);

            }

        };
        hi.addComponent(new Label("Hi World"));
        hi.addComponent(l);
        hi.show();
        
    }
    
    Image drawCircle(int width, int height){
        Image out = null;
        ca.weblite.piscesGraphics g = new ca.weblite.piscesGraphics(width,height);
        try {
            
            g.setColor(ca.weblite.piscesColor.Red);
            g.setAntialiasing(true);

            g.drawOval(0, 0, width, height);

            out = g.toImage();
        } finally {
            g.dispose();
        }
        return out;
    } 

##Advanced Usage Example

The following example is from the original Pisces GAE port repository. There are minor differences between this example and one that will work in Codename One. For example, you would probably want to use the Graphics.toImage() method to obtain an image than the Graphics.toPNG() method (which is used in this example) because there is no need to waste cycles compressing the image when you are just displaying it to the screen.

Example Source Code

##Other Examples

Tests Directory for Pisces Graphics (Not CN1 Port)

##Fonts

Pisces has a flexible API that allows you to easily add your own fonts. Check out the CN1FontBox project for TTF font support.

##JavaDocs

Index Page

###Key Classes

  1. Graphics
  2. Path
  3. Surface

##Todo

Codename One will be including a 2D drawing API in a future version (scheduled in the first part of 2014) so I'm not sure it is worth putting much more work into this library. Some nice features that could probably be added without a tremendous amout of work:

  1. Better integration with the Codename One class library. E.g. Possibly creating a wrapper class that extends the Codename One Graphics class but includes support for more 2D drawing primitives.

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.