{"id":18485942,"url":"https://github.com/52inc/canvasscript","last_synced_at":"2025-10-31T14:30:30.943Z","repository":{"id":81905619,"uuid":"90642868","full_name":"52inc/CanvasScript","owner":"52inc","description":"A canvas rendering wrapper for Android's Canvas and Paint classes","archived":false,"fork":false,"pushed_at":"2017-05-31T14:30:39.000Z","size":240,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-12-25T14:29:51.046Z","etag":null,"topics":["android","android-canvas","custom-views","graphics","paint"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/52inc.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-05-08T15:19:18.000Z","updated_at":"2017-05-16T14:42:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"478cef0a-58d9-4cf9-808c-6c13a5ba2bfd","html_url":"https://github.com/52inc/CanvasScript","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/52inc%2FCanvasScript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/52inc%2FCanvasScript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/52inc%2FCanvasScript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/52inc%2FCanvasScript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/52inc","download_url":"https://codeload.github.com/52inc/CanvasScript/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239201656,"owners_count":19599079,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","android-canvas","custom-views","graphics","paint"],"created_at":"2024-11-06T12:47:15.235Z","updated_at":"2025-10-31T14:30:30.904Z","avatar_url":"https://github.com/52inc.png","language":"Java","readme":"# CanvasScript\nA canvas rendering wrapper for Android's Canvas and Paint classes\n\n[![Build Status](https://travis-ci.org/52inc/CanvasScript.svg?branch=master)](https://travis-ci.org/52inc/CanvasScript) [![Download](https://api.bintray.com/packages/52inc/CanvasScript/CanvasScript/images/download.svg) ](https://bintray.com/52inc/CanvasScript/CanvasScript/_latestVersion) \n\n## Include\n```groovy\ncompile 'com.52inc:canvasscript:1.0.2'\n```\n\n## How-to-Use\n\nThere are two ways to to utilize the wrapper.\n\n1. **Creating a new Bitmap to render to**\n\n```java\nCanvasScript.create(int width, int height)\nCanvasScript.create(int width, int height, Bitmap.Config config)\nCanvasScript.create(Bitmap bitmap);\n```\n\nThis will create a new script object initialized with new (or provided) bitmap where all subsequent drawing calls will be rendered to and returned.\n\n2. **Wrap an existing canvas**\n\n```java\nCanvasScript.wrap(Canvas canvas)\n```\n\nThis will return a script instance wrapped around an existing `Canvas` (i.e. if you are trying to use the script to render in a custom view object) where all drawing calls will be directed and rendered to.\n\n---\n\nOnce you have initialized your script object you can then start chaining drawing and paint calls that will be combined sequentially in the order they were called when you call the `.draw()` function. If you created your script using **Method #1** then it will return the provided/created `Bitmap` that was drawn upon. If you created your script using **Method #2** then it will return `null`. \n\n### Methods\nThere are basically **two** groups of methods: **Paint** methods, and **Canvas** Methods.\n\n#### Paint\n\nThese methods modify an internally tracked `Paint` object that can be implicitly provided for all the `Canvas` drawing calls so you don't have to keep track of creating and supplying your own (unless you want to).\n\n[`CanvasScript.java L155 - L359`](https://github.com/52inc/CanvasScript/blob/master/library/src/main/java/com/ftinc/canvasscript/CanvasScript.java#L155-L359)\n\nOne of these methods must be called to initialize the internal paint object before calling and implicity canvas method or else you will get an `IllegalStateException`\n\n#### Canvas\n\nThese methods are instructions for calls to the `Canvas` object to be rendered sequentially:\n\n\n[`CanvasScript.java L362 - L1480`](https://github.com/52inc/CanvasScript/blob/master/library/src/main/java/com/ftinc/canvasscript/CanvasScript.java#L362-L1480)\n\nThere is a version of every call to account for all possible drawing methods for their `Canvas` equivelents. There is also a duplicate call where you can supply your own `Paint` object for rendering instead of using the internally tracked one mentioned above.\n\n#### Special\n\nNow there are a few special methods in the API to give you some extra functionality and they are:\n\n```java\npublic CanvasScript custom(@NonNull CanvasParams customParameter)\n```\n\nThis call allows you to provide a custom `CanvasParams` object where you can define a custom set of `Canvas` drawing calls to the stack (i.e. If you wanted to create a parameter that auto magically sets up a PorterDuff Xfer call in one line)\n\n```java\npublic CanvasScript script(CanvasScript script)\npublic CanvasScript script(float dx, float dy, CanvasScript script)\n```\n\nThese calls allow you to chain multiple `CanvasScripts` together \n\n### Drawing\n\nOnce you have finished your chain of paint and canvas methods and are reading to render everything to the canvas/bitmap just call:\n\n```java\n@Nullable\npublic Bitmap draw()\n```\n\nIf you wrapped an existing `Canvas` object when you created your `CanvasScript` then this will return `null`, otherwise it will return the `Bitmap` that it created will all the subsequent drawing calls made to it.\n\n##### Special note about save/restore calls\n\nIf you make any `Canvas` save calls (i.e. `save()`, `saveLayer(...)`, etc) the CanvasScript will internally keep track of the returned integer (i.e. the save count) so when you later call `restore()` it will automatically restore to that saved count.\n\n### Example\n\n```java\nCanvasScript.wrap(canvas)\n        .saveLayer()\n        .bitmap(image, measuredWidth, measuredHeight)\n        .porterDuffXfer(PorterDuff.Mode.CLEAR)\n        .circle(measuredWidth/2f, measuredHeight/2f, measuredWidth/4f)\n        .paint(null)\n        .restore()\n        .color(color(R.color.colorAccent))\n        .alpha(0.5f)\n        .rect(0f, 0f, measuredWidth/2f, measuredHeight/2f)\n        .alpha(1f)\n        .color(Color.BLUE)\n        .roundedRect(measuredWidth/2f, measuredHeight/2f, measuredWidth.toFloat(), measuredHeight.toFloat(), 20f)\n        .color(Color.YELLOW)\n        .style(Paint.Style.STROKE)\n        .strokeWidth(10f)\n        .strokeCap(Paint.Cap.ROUND)\n        .arc(20f, 20f, measuredWidth.toFloat() - 40f, measuredHeight.toFloat() - 40f, -135f, 90f, false)\n        .draw()\n```\n\nThe result looks like this:\n\n\u003cimg src=\"art/example.png\" width=\"300px\"\u003e\u003c/img\u003e\n\n## Author\n**[r0adkll](https://github.com/r0adkll)** (Drew Heavner) @ **[52inc](https://github.com/52inc)**\n\n## License\n\n```\nCopyright © 2017 52inc\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F52inc%2Fcanvasscript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F52inc%2Fcanvasscript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F52inc%2Fcanvasscript/lists"}