diff --git a/.codespellrc b/.codespellrc new file mode 100644 index 0000000..a41b93c --- /dev/null +++ b/.codespellrc @@ -0,0 +1,7 @@ +# See: https://github.com/codespell-project/codespell#using-a-config-file +[codespell] +# In the event of a false positive, add the problematic word, in all lowercase, to a comma-separated list here: +ignore-words-list = cleary,mis +check-filenames = +check-hidden = +skip = ./.git diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..fa738ec --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +# See: https://docs.github.com/en/github/administering-a-repository/configuration-options-for-dependency-updates#about-the-dependabotyml-file +version: 2 + +updates: + # Configure check for outdated GitHub Actions actions in workflows. + # See: https://docs.github.com/en/github/administering-a-repository/keeping-your-actions-up-to-date-with-dependabot + - package-ecosystem: github-actions + directory: / # Check the repository's workflows under /.github/workflows/ + schedule: + interval: daily + labels: + - "topic: infrastructure" diff --git a/.github/workflows/check-arduino.yml b/.github/workflows/check-arduino.yml new file mode 100644 index 0000000..e818685 --- /dev/null +++ b/.github/workflows/check-arduino.yml @@ -0,0 +1,28 @@ +name: Check Arduino + +# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows +on: + push: + pull_request: + schedule: + # Run every Tuesday at 8 AM UTC to catch breakage caused by new rules added to Arduino Lint. + - cron: "0 8 * * TUE" + workflow_dispatch: + repository_dispatch: + +jobs: + lint: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Arduino Lint + uses: arduino/arduino-lint-action@v2 + with: + compliance: specification + library-manager: update + # Always use this setting for official repositories. Remove for 3rd party projects. + official: true + project-type: library diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml new file mode 100644 index 0000000..d80f79f --- /dev/null +++ b/.github/workflows/compile-examples.yml @@ -0,0 +1,74 @@ +name: Compile Examples + +# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows +on: + push: + paths: + - ".github/workflows/compile-examples.yml" + - "library.properties" + - "examples/**" + - "src/**" + pull_request: + paths: + - ".github/workflows/compile-examples.yml" + - "library.properties" + - "examples/**" + - "src/**" + schedule: + # Run every Tuesday at 8 AM UTC to catch breakage caused by changes to external resources (libraries, platforms). + - cron: "0 8 * * TUE" + workflow_dispatch: + repository_dispatch: + +jobs: + build: + name: ${{ matrix.board.fqbn }} + runs-on: ubuntu-latest + + env: + SKETCHES_REPORTS_PATH: sketches-reports + + strategy: + fail-fast: false + + matrix: + board: + - fqbn: arduino:samd:arduino_zero_edbg + platforms: | + - name: arduino:samd + artifact-name-suffix: arduino-samd-arduino_zero_edbg + - fqbn: arduino:samd:mkrzero + platforms: | + - name: arduino:samd + artifact-name-suffix: arduino-samd-mkrzero + - fqbn: arduino:samd:nano_33_iot + platforms: | + - name: arduino:samd + artifact-name-suffix: arduino-samd-nano_33_iot + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Compile examples + uses: arduino/compile-sketches@v1 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + fqbn: ${{ matrix.board.fqbn }} + platforms: ${{ matrix.board.platforms }} + libraries: | + # Install the library from the local path. + - source-path: ./ + # Additional library dependencies can be listed here. + # See: https://github.com/arduino/compile-sketches#libraries + sketch-paths: | + - examples + enable-deltas-report: true + sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }} + + - name: Save sketches report as workflow artifact + uses: actions/upload-artifact@v4 + with: + if-no-files-found: error + name: sketches-report-${{ matrix.board.artifact-name-suffix }} + path: ${{ env.SKETCHES_REPORTS_PATH }} diff --git a/.github/workflows/report-size-deltas.yml b/.github/workflows/report-size-deltas.yml new file mode 100644 index 0000000..39e2a0a --- /dev/null +++ b/.github/workflows/report-size-deltas.yml @@ -0,0 +1,24 @@ +name: Report Size Deltas + +# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows +on: + push: + paths: + - ".github/workflows/report-size-deltas.yml" + schedule: + # Run at the minimum interval allowed by GitHub Actions. + # Note: GitHub Actions periodically has outages which result in workflow failures. + # In this event, the workflows will start passing again once the service recovers. + - cron: "*/5 * * * *" + workflow_dispatch: + repository_dispatch: + +jobs: + report: + runs-on: ubuntu-latest + steps: + - name: Comment size deltas reports to PRs + uses: arduino/report-size-deltas@v1 + with: + # Regex matching the names of the workflow artifacts created by the "Compile Examples" workflow + sketches-reports-source: ^sketches-report-.+ diff --git a/.github/workflows/spell-check.yml b/.github/workflows/spell-check.yml new file mode 100644 index 0000000..ef7d894 --- /dev/null +++ b/.github/workflows/spell-check.yml @@ -0,0 +1,22 @@ +name: Spell Check + +# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows +on: + push: + pull_request: + schedule: + # Run every Tuesday at 8 AM UTC to catch new misspelling detections resulting from dictionary updates. + - cron: "0 8 * * TUE" + workflow_dispatch: + repository_dispatch: + +jobs: + spellcheck: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Spell check + uses: codespell-project/actions-codespell@master diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml new file mode 100644 index 0000000..53a9f54 --- /dev/null +++ b/.github/workflows/sync-labels.yml @@ -0,0 +1,138 @@ +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/sync-labels.md +name: Sync Labels + +# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows +on: + push: + paths: + - ".github/workflows/sync-labels.ya?ml" + - ".github/label-configuration-files/*.ya?ml" + pull_request: + paths: + - ".github/workflows/sync-labels.ya?ml" + - ".github/label-configuration-files/*.ya?ml" + schedule: + # Run daily at 8 AM UTC to sync with changes to shared label configurations. + - cron: "0 8 * * *" + workflow_dispatch: + repository_dispatch: + +env: + CONFIGURATIONS_FOLDER: .github/label-configuration-files + CONFIGURATIONS_ARTIFACT: label-configuration-files + +jobs: + check: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Download JSON schema for labels configuration file + id: download-schema + uses: carlosperate/download-file-action@v2 + with: + file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/arduino-tooling-gh-label-configuration-schema.json + location: ${{ runner.temp }}/label-configuration-schema + + - name: Install JSON schema validator + run: | + sudo npm install \ + --global \ + ajv-cli \ + ajv-formats + + - name: Validate local labels configuration + run: | + # See: https://github.com/ajv-validator/ajv-cli#readme + ajv validate \ + --all-errors \ + -c ajv-formats \ + -s "${{ steps.download-schema.outputs.file-path }}" \ + -d "${{ env.CONFIGURATIONS_FOLDER }}/*.{yml,yaml}" + + download: + needs: check + runs-on: ubuntu-latest + + strategy: + matrix: + filename: + # Filenames of the shared configurations to apply to the repository in addition to the local configuration. + # https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/sync-labels + - universal.yml + + steps: + - name: Download + uses: carlosperate/download-file-action@v2 + with: + file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }} + + - name: Pass configuration files to next job via workflow artifact + uses: actions/upload-artifact@v4 + with: + path: | + *.yaml + *.yml + if-no-files-found: error + name: ${{ env.CONFIGURATIONS_ARTIFACT }} + + sync: + needs: download + runs-on: ubuntu-latest + + steps: + - name: Set environment variables + run: | + # See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable + echo "MERGED_CONFIGURATION_PATH=${{ runner.temp }}/labels.yml" >> "$GITHUB_ENV" + + - name: Determine whether to dry run + id: dry-run + if: > + github.event_name == 'pull_request' || + ( + ( + github.event_name == 'push' || + github.event_name == 'workflow_dispatch' + ) && + github.ref != format('refs/heads/{0}', github.event.repository.default_branch) + ) + run: | + # Use of this flag in the github-label-sync command will cause it to only check the validity of the + # configuration. + echo "::set-output name=flag::--dry-run" + + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Download configuration files artifact + uses: actions/download-artifact@v4 + with: + name: ${{ env.CONFIGURATIONS_ARTIFACT }} + path: ${{ env.CONFIGURATIONS_FOLDER }} + + - name: Remove unneeded artifact + uses: geekyeggo/delete-artifact@v5 + with: + name: ${{ env.CONFIGURATIONS_ARTIFACT }} + + - name: Merge label configuration files + run: | + # Merge all configuration files + shopt -s extglob + cat "${{ env.CONFIGURATIONS_FOLDER }}"/*.@(yml|yaml) > "${{ env.MERGED_CONFIGURATION_PATH }}" + + - name: Install github-label-sync + run: sudo npm install --global github-label-sync + + - name: Sync labels + env: + GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # See: https://github.com/Financial-Times/github-label-sync + github-label-sync \ + --labels "${{ env.MERGED_CONFIGURATION_PATH }}" \ + ${{ steps.dry-run.outputs.flag }} \ + ${{ github.repository }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a612ad9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. diff --git a/README.adoc b/README.adoc deleted file mode 100644 index 38c6684..0000000 --- a/README.adoc +++ /dev/null @@ -1,23 +0,0 @@ -= ArduinoGraphics Library for Arduino = - -Core graphics library for Arduino. Based on the Processing API. - -For more information about this library please visit us at https://www.arduino.cc/en/Reference/ArduinoGraphics - -== License == - -Copyright (c) 2019 Arduino SA. All rights reserved. - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 2.1 of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/README.md b/README.md new file mode 100644 index 0000000..b4f164f --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# ArduinoGraphics Library for Arduino + +![Check Arduino status](https://github.com/arduino-libraries/ArduinoGraphics/actions/workflows/check-arduino.yml/badge.svg) +![Compile Examples status](https://github.com/arduino-libraries/ArduinoGraphics/actions/workflows/compile-examples.yml/badge.svg) +![Spell Check status](https://github.com/arduino-libraries/ArduinoGraphics/actions/workflows/spell-check.yml/badge.svg) + +Core graphics library for Arduino. Based on the Processing API. + +📖 For more information about this library please read the documentation [here](./docs/) or visit us at [https://www.arduino.cc/en/Reference/ArduinoGraphics](https://www.arduino.cc/en/Reference/ArduinoGraphics) diff --git a/docs/api.md b/docs/api.md new file mode 100644 index 0000000..004b2b6 --- /dev/null +++ b/docs/api.md @@ -0,0 +1,806 @@ +# Arduino Graphics Library + +## Methods + +### `begin()` + +#### Description + +Initializes the graphics device. + +#### Syntax + +``` +YourScreen.begin() +``` + +#### Parameters + +None + +#### Returns + +1 for success, 0 on failure. + +#### Example + +``` +if (!YourScreen.begin()) { + Serial.println("Failed to initialize the display!"); + while (1); +} +``` + +### `end()` + +#### Description + +Stops the graphics device. + +#### Syntax + +``` +YourScreen.end() +``` + +#### Parameters + +None + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.end(); +``` + +### `width()` + +#### Description + +Returns the pixel width of the graphics device. + +#### Syntax + +``` +YourScreen.width() +``` + +#### Parameters + +None + +#### Returns + +Returns the pixel width of the graphics device. + +#### Example + +``` +int w = YourScreen.width(); +``` + +### `height()` + +#### Description + +Returns the pixel height of the graphics device. + +#### Syntax + +``` +YourScreen.height() +``` + +#### Parameters + +None + +#### Returns + +Returns the pixel height of the graphics device. + +#### Example + +``` +int h = YourScreen.height(); +``` + +### `beginDraw()` + +#### Description + +Begins a drawing operation. + +#### Syntax + +``` +YourScreen.beginDraw() +``` + +#### Parameters + +None + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginDraw(); +YourScreen.set(0, 0, 255, 0, 0); +YourScreen.endDraw(); +``` + +### `endDraw()` + +#### Description + +Ends a drawing operation, any drawing operations after beginDraw() is called will be displayed to the screen. + +#### Syntax + +``` +YourScreen.endDraw() +``` + +#### Parameters + +None + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginDraw(); +YourScreen.set(0, 0, 255, 0, 0); +YourScreen.endDraw(); +``` + +### `background()` + +#### Description + +Set the background color of drawing operations. Used when calling clear() or drawing text. + +#### Syntax + +``` +YourScreen.background(r, g, b) +YourScreen.background(color) +``` + +#### Parameters + +- r: red color value (0 - 255) +- g: green color value (0 - 255) +- b: blue color value (0 - 255) +- color: 24-bit RGB color, 0xrrggbb + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginDraw(); +YourScreen.background(255, 0, 0); +YourScreen.clear(); +YourScreen.endDraw(); +``` + +### `clear()` + +#### Description + +Clear the screen contents or a specific pixel, uses the background colour set in background(). + +#### Syntax + +``` +YourScreen.clear() +YourScreen.clear(x, y) +``` + +#### Parameters + +- x: x position of the pixel to clear +- y: y position of the pixel to clear + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginDraw(); +YourScreen.background(255, 0, 0); +YourScreen.clear(); +YourScreen.endDraw(); +``` + +### `fill()` + +#### Description + +Set the fill color of drawing operations. + +#### Syntax + +``` +YourScreen.fill(r, g, b) +YourScreen.fill(color) +``` + +#### Parameters + +- r: red color value (0 - 255) +- g: green color value (0 - 255) +- b: blue color value (0 - 255) +- color: 24-bit RGB color, 0xrrggbb + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginDraw(); +YourScreen.clear(); +YourScreen.noStroke(); +YourScreen.fill(255, 255, 0); +YourScreen.rect(0, 0, YourScreen.width(), YourScreen.height()); +YourScreen.endDraw(); +``` + +### `noFill()` + +#### Description + +Clears the fill color of drawing operations. + +#### Syntax + +``` +YourScreen.noFill() +``` + +#### Parameters + +None + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginDraw(); +YourScreen.clear(); +YourScreen.stroke(255, 0, 255); +YourScreen.noFill(); +YourScreen.rect(0, 0, YourScreen.width(), YourScreen.height()); +YourScreen.endDraw(); +``` + +### `stroke()` + +#### Description + +Set the stroke color of drawing operations. + +#### Syntax + +``` +YourScreen.stroke(r, g, b) +YourScreen.stroke(color) +``` + +#### Parameters + +- r: red color value (0 - 255) +- g: green color value (0 - 255) +- b: blue color value (0 - 255) +- color: 24-bit RGB color, 0xrrggbb + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginDraw(); +YourScreen.clear(); +YourScreen.stroke(255, 0, 255); +YourScreen.noFill(); +YourScreen.rect(0, 0, YourScreen.width(), YourScreen.height()); +YourScreen.endDraw(); +``` + +### `noStroke()` + +#### Description + +Clears the stroke color of drawing operations. + +#### Syntax + +``` +YourScreen.noStroke() +``` + +#### Parameters + +None + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginDraw(); +YourScreen.clear(); +YourScreen.noStroke(); +YourScreen.fill(255, 255, 0); +YourScreen.rect(0, 0, YourScreen.width(), YourScreen.height()); +YourScreen.endDraw(); +``` + +### `line()` + +#### Description + +Stroke a line, uses the stroke color set in stroke(). + +#### Syntax + +``` +YourScreen.line(x1, y1, x2, y2) +``` + +#### Parameters + +- x1: x position of the starting point of the line +- y1: y position of the starting point of the line +- x2: x position of the end point of the line +- y2: y position of the end point of the line + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginDraw(); +YourScreen.clear(); +YourScreen.stroke(0, 0, 255); +YourScreen.line(0, 0, YourScreen.width() - 1, YourScreen.height() - 1); +YourScreen.endDraw(); +``` + +### `point()` + +#### Description + +Stroke a point, uses the stroke color set in stroke(). + +#### Syntax + +``` +YourScreen.point(x, y) +``` + +#### Parameters + +x: x position of the point +y: y position of the point + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginDraw(); +YourScreen.clear(); +YourScreen.stroke(0, 255, 0); +YourScreen.point(1, 1); +YourScreen.endDraw(); +``` + +### `rect()` + +#### Description + +Stroke and fill a rectangle, uses the stroke color set in stroke() and the fill color set in fill(). + +#### Syntax + +``` +YourScreen.rect(x, y, width, height) +``` + +#### Parameters + +- x: x position of the rectangle +- y: y position of the rectangle +- width: width of the rectangle +- height: height of the rectangle + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginDraw(); +YourScreen.clear(); +YourScreen.noStroke(); +YourScreen.fill(255, 255, 0); +YourScreen.rect(0, 0, YourScreen.width(), YourScreen.height()); +YourScreen.endDraw(); +``` + +### `circle()` + +#### Description + +Stroke and fill a circle, uses the stroke color set in stroke() and the fill color set in fill(). + +#### Syntax + +``` +YourScreen.circle(x, y, diameter) +``` + +#### Parameters + +- x: x center position of the circle +- y: y center position of the circle +- diameter: diameter of the circle + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginDraw(); +YourScreen.clear(); +YourScreen.noStroke(); +YourScreen.fill(255, 255, 0); +YourScreen.circle(YourScreen.width()/2, YourScreen.height()/2, YourScreen.height()); +YourScreen.endDraw(); +``` + +### `ellipse()` + +#### Description + +Stroke and fill an ellipse, uses the stroke color set in stroke() and the fill color set in fill(). + +#### Syntax + +``` +YourScreen.ellipse(x, y, width, height) +``` + +#### Parameters + +- x: x center position of the ellipse +- y: y center position of the ellipse +- width: width of the ellipse +- height: height of the ellipse + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginDraw(); +YourScreen.clear(); +YourScreen.noStroke(); +YourScreen.fill(255, 255, 0); +YourScreen.ellipse(YourScreen.width()/2, YourScreen.height()/2, YourScreen.width(), YourScreen.height()); +YourScreen.endDraw(); +``` + +### `text()` + +#### Description + +Draw some text, uses the stroke color set in stroke() and the background color set in background(). + +#### Syntax + +``` +YourScreen.text(string) +YourScreen.text(string, x, y) +``` + +#### Parameters + +- string: string to draw +- x: x position for the start of the text +- y: y position for the start of the text + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginDraw(); +YourScreen.clear(); +YourScreen.stroke(255, 255, 255); +YourScreen.text("abc", 0, 1); +YourScreen.endDraw(); +``` + +### `textFont()` + +#### Description + +Sets the font used for text. The library current has the Font_4x6 and Font_5x7 built in. + +#### Syntax + +``` +YourScreen.textFont(font) +``` + +#### Parameters + +font: font to set + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginDraw(); +YourScreen.clear(); +YourScreen.stroke(255, 255, 255); +YourScreen.textFont(Font_5x7); +YourScreen.text("abc", 0, 1); +YourScreen.endDraw(); +``` + +### `textFontWidth()` + +#### Description + +Returns the width, in pixels, of the current font. + +#### Syntax + +``` +YourScreen.textFontWidth() + +``` + +#### Parameters + +None + +#### Returns + +Nothing + +#### Example + +``` +int w = YourScreen.textFontWidth(); +``` + +### `textFontHeight()` + +#### Description + +Returns the height, in pixels, of the current font. + +#### Syntax + +``` +YourScreen.textFontHeight() +``` + +#### Parameters + +None + +#### Returns + +Nothing + +#### Example + +``` +int h = YourScreen.textFontHeight(); +``` + +### `textSize()` + +#### Description + +Set a text scale factor + +#### Syntax + +``` +YourScreen.textSize(scale) +YourScreen.textSize(scaleX, scaleY) +``` + +#### Parameters + +scale: scale factor used for both x and y +scaleX: x scale factor +scaleY: y scale factor + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginDraw(); +YourScreen.clear(); +YourScreen.stroke(255, 255, 255); +YourScreen.textFont(Font_5x7); +YourScreen.textSize(5); +YourScreen.text("abc", 0, 1); +YourScreen.endDraw(); +``` + +### `set()` + +#### Description + +Set a pixel’s color value. + +#### Syntax + +``` +YourScreen.set(x, y, r, g, b) +YourScreen.set(x, y, color) +``` + +#### Parameters + +x: x position of the pixel +y: y position of the pixel +r: red color value (0 - 255) +g: green color value (0 - 255) +b: blue color value (0 - 255) +color: 24-bit RGB color, 0xrrggbb + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginDraw(); +YourScreen.point(1, 1, 0, 255, 0); +YourScreen.endDraw(); +``` + +### `beginText()` + +#### Description + +Start the process of displaying and optionally scrolling text. The Print interface can be used to set the text. + +#### Syntax + +``` +YourScreen.beginText() +YourScreen.beginText(x, y, r, g, b) +YourScreen.beginText(x, y, color) +``` + +#### Parameters + +x: x position of the text +y: y position of the text +r: red color value (0 - 255) +g: green color value (0 - 255) +b: blue color value (0 - 255) +color: 24-bit RGB color, 0xrrggbb + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginText(0, 0, 127, 0, 0); +YourScreen.print("Hi"); +YourScreen.endText(); +``` + +### `endText()` + +#### Description + +End the process of displaying and optionally scrolling text. + +#### Syntax + +``` +YourScreen.endText() +YourScreen.endText(scrollDirection) +``` + +#### Parameters + +scrollDirection: (optional) the direction to scroll, defaults to NO_SCROLL if not provided. Valid options are NO_SCROLL, SCROLL_LEFT, SCROLL_RIGHT, SCROLL_UP, SCROLL_DOWN + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginText(0, 0, 127, 0, 0); +YourScreen.print("Hi"); +YourScreen.endText(); +``` + +### `textScrollSpeed()` + +#### Description + +Sets the text scrolling speed, the speed controls the delay in milliseconds between scrolling each pixel. + +#### Syntax + +``` +YourScreen.textScrollSpeed(speed) +``` + +#### Parameters + +speed: scroll speed + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginText(0, 0, 127, 0, 0); +YourScreen.textScrollSpeed(500); +YourScreen.print("Hello There!"); +YourScreen.endText(true); +``` diff --git a/docs/readme.md b/docs/readme.md new file mode 100644 index 0000000..0dd9764 --- /dev/null +++ b/docs/readme.md @@ -0,0 +1,20 @@ +# Arduino Graphics Library + +This is a library that allows you to draw and write on screens with graphical primitives; it requires a specific hardware interface library to drive the screen you are using, therefore every screen type should have its own hardware specific library. + +To use this library + +``` +#include +``` + +To let you easily understand the usage of the graphics primitives, we are using a dummy screen object named YourScreen that should be substituted with the real one, Eg. MATRIX, OLED, TFT and so on. Refer to the hardware interfacing library of your screen to get more details. + +The style and syntax of this library is inspired by [Processing 3](https://processing.org/) and we believe that learning Processing is very helpful to develop complex applications that combine the versatility of Arduino driven hardware with the power of a pc based graphical interface. + +## How-to generate bitmaps from the fonts + +```bash +cd extras +./generate_font.py 5x7.bdf Font_5x7.c Font_5x7 +``` \ No newline at end of file diff --git a/examples/ASCIIDraw/ASCIIDraw.ino b/examples/ASCIIDraw/ASCIIDraw.ino new file mode 100644 index 0000000..dfb6bb3 --- /dev/null +++ b/examples/ASCIIDraw/ASCIIDraw.ino @@ -0,0 +1,109 @@ +/* + ASCIIDraw + + Use the ArduinoGraphics library to draw ASCII art on the Serial Monitor. + + This is intended primarily to allow testing of the library. + See the Arduino_MKRRGB library for a more useful demonstration of the ArduinoGraphics library. + + The circuit: + - Arduino board + + This example code is in the public domain. +*/ + +#include + +const byte fontSize = 3; +const byte canvasWidth = fontSize * (5 * 7) + 26; +const byte canvasHeight = fontSize * 7 + 20; + +class ASCIIDrawClass : public ArduinoGraphics { + public: + // can be used with an object of any class that inherits from the Print class + ASCIIDrawClass(Print &printObject = (Print &)Serial) : + ArduinoGraphics(canvasWidth, canvasHeight), + _printObject(&printObject) {} + + // this function is called by the ArduinoGraphics library's functions + virtual void set(int x, int y, uint8_t r, uint8_t g, uint8_t b) { + // the r parameter is (mis)used to set the character to draw with + _canvasBuffer[x][y] = r; + // cast unused parameters to void to fix "unused parameter" warning + (void)g; + (void)b; + } + + // display the drawing + void endDraw() { + ArduinoGraphics::endDraw(); + + for (byte row = 0; row < canvasHeight; row++) { + for (byte column = 0; column < canvasWidth; column++) { + // handle unset parts of buffer + if (_canvasBuffer[column][row] == 0) { + _canvasBuffer[column][row] = ' '; + } + _printObject->print(_canvasBuffer[column][row]); + } + _printObject->println(); + } + } + + private: + Print *_printObject; + char _canvasBuffer[canvasWidth][canvasHeight] = {{0}}; +}; + +ASCIIDrawClass ASCIIDraw; + +void setup() { + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + ASCIIDraw.beginDraw(); + + // configure the character used to fill the background. The second and third parameters are ignored + ASCIIDraw.background('+', 0, 0); + ASCIIDraw.clear(); + + // add the outer border + ASCIIDraw.stroke('-', 0, 0); + ASCIIDraw.fill('*', 0, 0); + const byte outerBorderThickness = 1; + ASCIIDraw.rect(outerBorderThickness, outerBorderThickness, canvasWidth - outerBorderThickness * 2, canvasHeight - outerBorderThickness * 2); + + // add the inner border + ASCIIDraw.stroke('+', 0, 0); + ASCIIDraw.fill('O', 0, 0); + const byte borderThickness = outerBorderThickness + 6; + ASCIIDraw.rect(borderThickness, borderThickness, canvasWidth - borderThickness * 2, canvasHeight - borderThickness * 2); + + // add the text + ASCIIDraw.background(' ', 0, 0); + ASCIIDraw.stroke('@', 0, 0); + const char text[] = "ARDUINO"; + ASCIIDraw.textFont(Font_5x7); + ASCIIDraw.textSize(fontSize); + const byte textWidth = strlen(text) * ASCIIDraw.textFontWidth(); + const byte textHeight = ASCIIDraw.textFontHeight(); + const byte textX = (canvasWidth - textWidth) / 2; + const byte textY = (canvasHeight - textHeight) / 2; + ASCIIDraw.text(text, textX, textY); + + // underline the text + ASCIIDraw.stroke('-', 0, 0); + ASCIIDraw.line(textX, textY + textHeight - 1, textX + textWidth - 1, textY + textHeight - 1); + + // add some accents to the underline + ASCIIDraw.stroke('+', 0, 0); + ASCIIDraw.point(textX + 4, textY + textHeight - 1); + ASCIIDraw.point(textX + textWidth - 1 - 4, textY + textHeight - 1); + + // print the drawing to the Serial Monitor + ASCIIDraw.endDraw(); +} + +void loop() {} diff --git a/extras/generate_font.py b/extras/generate_font.py index de786e5..48efb84 100755 --- a/extras/generate_font.py +++ b/extras/generate_font.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -# This file is part of the MKRRGBMatrix library. +# This file is part of the ArduinoGraphics library. # Copyright (c) 2018 Arduino SA. All rights reserved. # # This library is free software; you can redistribute it and/or @@ -60,22 +60,27 @@ out = open(output, "w") -print >> out, "#include \"Font.h\"" -print >> out -print >> out, "const struct Font %s = {" % ( name ) -print >> out, " %d," % ( fontWidth ) -print >> out, " %d," % ( fontHeight ) -print >> out, " (const uint8_t*[]){" +out.write("#include \"Font.h\"\n") +out.write("\n") +out.write("const struct Font %s = {" % ( name )) +out.write("\n") +out.write(" %d," % ( fontWidth )) +out.write("\n") +out.write(" %d," % ( fontHeight )) +out.write("\n") +out.write(" (const uint8_t*[]){\n") for c in range (0, 255): if None == fontCharacters[c]: - print >> out, " NULL," + out.write(" NULL,\n") else: - print >> out, " // %s" % (fontCharacterNames[c]) - print >> out, " (const uint8_t[]){" + out.write(" // %s" % (fontCharacterNames[c])) + out.write("\n") + out.write(" (const uint8_t[]){\n") for i in range(0, fontHeight): - print >> out, " 0b%s," % ('{0:08b}'.format(fontCharacters[c][i])) - print >> out, " }," -print >> out, " }" -print >> out, "};" + out.write(" 0b%s," % ('{0:08b}'.format(fontCharacters[c][i]))) + out.write("\n") + out.write(" },\n") +out.write(" }\n") +out.write("};\n") out.close() diff --git a/keywords.txt b/keywords.txt index 5c7d60b..ce07cc7 100644 --- a/keywords.txt +++ b/keywords.txt @@ -33,6 +33,8 @@ line KEYWORD2 point KEYWORD2 quad KEYWORD2 rect KEYWORD2 +circle KEYWORD2 +ellipse KEYWORD2 text KEYWORD2 textFont KEYWORD2 diff --git a/library.properties b/library.properties index 2494df5..a6a1080 100644 --- a/library.properties +++ b/library.properties @@ -1,10 +1,10 @@ name=ArduinoGraphics -version=1.0.0 +version=1.1.4 author=Arduino maintainer=Arduino sentence=Core graphics library for Arduino. paragraph=Based on the Processing API. category=Display url=http://github.com/arduino-libraries/ArduinoGraphics -architectures=samd +architectures=samd,renesas_uno includes=ArduinoGraphics.h diff --git a/src/ArduinoGraphics.cpp b/src/ArduinoGraphics.cpp index e80e4b3..2a62a3a 100644 --- a/src/ArduinoGraphics.cpp +++ b/src/ArduinoGraphics.cpp @@ -1,20 +1,6 @@ /* This file is part of the ArduinoGraphics library. - Copyright (c) 2019 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Copyright (c) 2025 Arduino SA. All rights reserved. */ #include "ArduinoGraphics.h" @@ -26,7 +12,9 @@ ArduinoGraphics::ArduinoGraphics(int width, int height) : _width(width), _height(height), - _font(NULL) + _font(NULL), + _textSizeX(1), + _textSizeY(1) { } @@ -59,6 +47,12 @@ int ArduinoGraphics::height() return _height; } +uint32_t ArduinoGraphics::background() +{ + uint32_t bg = (uint32_t)((uint32_t)(_backgroundR << 16) | (uint32_t)(_backgroundG << 8) | (uint32_t)(_backgroundB << 0)); + return bg; +} + void ArduinoGraphics::beginDraw() { } @@ -83,11 +77,16 @@ void ArduinoGraphics::clear() { for (int x = 0; x < _width; x++) { for (int y = 0; y < _height; y++) { - set(x, y, _backgroundR, _backgroundB, _backgroundG); + set(x, y, _backgroundR, _backgroundG, _backgroundB); } } } +void ArduinoGraphics::clear(int x, int y) +{ + set(x, y, _backgroundR, _backgroundB, _backgroundG); +} + void ArduinoGraphics::fill(uint8_t r, uint8_t g, uint8_t b) { _fill = true; @@ -124,6 +123,47 @@ void ArduinoGraphics::noStroke() _stroke = false; } +void ArduinoGraphics::circle(int x, int y, int diameter) +{ + ellipse(x, y, diameter, diameter); +} + +void ArduinoGraphics::ellipse(int x, int y, int width, int height) +{ + if (!_stroke && !_fill) { + return; + } + + int32_t a = width / 2; + int32_t b = height / 2; + int64_t a2 = a * a; + int64_t b2 = b * b; + int64_t i, j; + + if (_fill) { + for (j = -b; j <= b; j++) { + for (i = -a; i <= a; i++) { + if (i*i*b2 + j*j*a2 <= a2*b2) { + set(x + i, y + j, _fillR, _fillG, _fillB); + } + } + } + } + if (_stroke) { + int x_val, y_val; + for (i = -a; i <= a; i++) { + y_val = b * sqrt(1 - (double)i*i / a2); + set(x + i, y + y_val, _strokeR, _strokeG, _strokeB); + set(x + i, y - y_val, _strokeR, _strokeG, _strokeB); + } + for (j = -b; j <= b; j++) { + x_val = a * sqrt(1 - (double)j*j / b2); + set(x + x_val, y + j, _strokeR, _strokeG, _strokeB); + set(x - x_val, y + j, _strokeR, _strokeG, _strokeB); + } + } +} + void ArduinoGraphics::line(int x1, int y1, int x2, int y2) { if (!_stroke) { @@ -191,10 +231,10 @@ void ArduinoGraphics::text(const char* str, int x, int y) } while (*str) { - int c = *str++; + uint8_t const c = (uint8_t)*str++; if (c == '\n') { - y += _font->height; + y += _font->height * _textSizeY; } else if (c == '\r') { x = 0; } else if (c == 0xc2 || c == 0xc3) { @@ -207,10 +247,10 @@ void ArduinoGraphics::text(const char* str, int x, int y) } if (b) { - bitmap(b, x, y, _font->width, _font->height); + bitmap(b, x, y, _font->width, _font->height, _textSizeX, _textSizeY); } - x += _font->width; + x += _font->width * _textSizeX; } } } @@ -222,38 +262,51 @@ void ArduinoGraphics::textFont(const Font& which) int ArduinoGraphics::textFontWidth() const { - return (_font ? _font->width : 0); + return (_font ? _font->width * _textSizeX : 0); } int ArduinoGraphics::textFontHeight() const { - return (_font ? _font->height : 0); + return (_font ? _font->height* _textSizeY : 0); } -void ArduinoGraphics::bitmap(const uint8_t* data, int x, int y, int width, int height) +void ArduinoGraphics::textSize(uint8_t sx, uint8_t sy) { - if (!_stroke) { + _textSizeX = (sx > 0)? sx : 1; + _textSizeY = (sy > 0)? sy : 1; +} + + +void ArduinoGraphics::bitmap(const uint8_t* data, int x, int y, int w, int h, uint8_t scale_x, uint8_t scale_y) { + if (!_stroke || !scale_x || !scale_y) { return; } - if ((data == NULL) || ((x + width) < 0) || ((y + height) < 0) || (x > _width) || (y > height)) { + if ((data == nullptr) || ((x + (w * scale_x) < 0)) || ((y + (h * scale_y) < 0)) || (x > _width) || (y > _height)) { // offscreen return; } - for (int j = 0; j < height; j++) { + int xStart = x; + for (int j = 0; j < h; j++) { uint8_t b = data[j]; - - for (int i = 0; i < width; i++) { - if (b & (1 << (7 - i))) { - set(x + i, y + j, _strokeR, _strokeG, _strokeB); - } else { - set(x + i, y + j, _backgroundR, _backgroundG, _backgroundB); + for (uint8_t ys = 0; ys < scale_y; ys++) { + if (ys >= _height) return; + x = xStart; // reset for each row + for (int i = 0; i < w; i++) { + if (b & (1 << (7 - i))) { + for (uint8_t xs = 0; xs < scale_x; xs++) set(x++, y, _strokeR, _strokeG, _strokeB); + } else { + for (uint8_t xs = 0; xs < scale_x; xs++) set(x++, y, _backgroundR, _backgroundG, _backgroundB); + } + if (x >= _width) break; } + y++; } } } + void ArduinoGraphics::imageRGB(const Image& img, int x, int y, int width, int height) { const uint8_t* data = img.data(); @@ -298,7 +351,7 @@ void ArduinoGraphics::imageRGB16(const Image& img, int x, int y, int width, int for (int i = 0; i < width; i++) { uint16_t pixel = *data++; - set(x + i, y + j, (pixel >> 8), ((pixel >> 3) & 0xfc), (pixel << 3) & 0xf8); + set(x + i, y + j, ((pixel >> 8) & 0xf8), ((pixel >> 3) & 0xfc), (pixel << 3) & 0xf8); } data += (img.width() - width); @@ -312,7 +365,7 @@ void ArduinoGraphics::image(const Image& img, int x, int y) void ArduinoGraphics::image(const Image& img, int x, int y, int width, int height) { - if (!img || ((x + width) < 0) || ((y + height) < 0) || (x > _width) || (y > height)) { + if (!img || ((x + width) < 0) || ((y + height) < 0) || (x > _width) || (y > _height)) { // offscreen return; } @@ -381,15 +434,21 @@ void ArduinoGraphics::endText(int scrollDirection) uint8_t strokeG = _strokeG; uint8_t strokeB = _strokeB; - - stroke(_textR, _textG, _textB); - if (scrollDirection == SCROLL_LEFT) { - int scrollLength = _textBuffer.length() * textFontWidth() + _textX; + int scrollLength = _textBuffer.length() * textFontWidth() + _textX + 1; for (int i = 0; i < scrollLength; i++) { beginDraw(); - text(_textBuffer, _textX - i, _textY); + + int const text_x = _textX - i; + stroke(_textR, _textG, _textB); + text(_textBuffer, text_x, _textY); + + // clear previous position + const int clearX = text_x + _textBuffer.length() * _font->width; + stroke(_backgroundR, _backgroundG, _backgroundB); + line(clearX, _textY, clearX, _textY + _font->height - 1); + endDraw(); delay(_textScrollSpeed); @@ -399,17 +458,37 @@ void ArduinoGraphics::endText(int scrollDirection) for (int i = 0; i < scrollLength; i++) { beginDraw(); - text(_textBuffer, _textX - (scrollLength - i - 1), _textY); + + int const text_x = _textX - (scrollLength - i - 1); + stroke(_textR, _textG, _textB); + text(_textBuffer, text_x, _textY); + + // clear previous position + const int clearX = text_x - 1; + stroke(_backgroundR, _backgroundG, _backgroundB); + line(clearX, _textY, clearX, _textY + _font->height - 1); + + bitmap(_font->data[0x20], text_x - 1, _textY, 1, _font->height, _textSizeX, _textSizeY); + endDraw(); delay(_textScrollSpeed); } } else if (scrollDirection == SCROLL_UP) { - int scrollLength = textFontHeight() + _textY; + int scrollLength = textFontHeight() + _textY + 1; for (int i = 0; i < scrollLength; i++) { beginDraw(); - text(_textBuffer, _textX, _textY - i); + + int const text_y = _textY - i; + stroke(_textR, _textG, _textB); + text(_textBuffer, _textX, text_y); + + // clear previous position + const int clearY = text_y + _font->height; + stroke(_backgroundR, _backgroundG, _backgroundB); + line(_textX, clearY, _textX + (_font->width * _textBuffer.length()) - 1, clearY); + endDraw(); delay(_textScrollSpeed); @@ -419,13 +498,24 @@ void ArduinoGraphics::endText(int scrollDirection) for (int i = 0; i < scrollLength; i++) { beginDraw(); - text(_textBuffer, _textX, _textY - (scrollLength - i - 1)); + + int const text_y = _textY - (scrollLength - i - 1); + stroke(_textR, _textG, _textB); + text(_textBuffer, _textX, text_y); + + // clear previous position + const int clearY = text_y - 1; + stroke(_backgroundR, _backgroundG, _backgroundB); + line(_textX, clearY, _textX + (_font->width * _textBuffer.length()) - 1, clearY); + + bitmap(_font->data[0x20], _textX, text_y - 1, _font->width, 1, _textSizeX, _textSizeY); endDraw(); delay(_textScrollSpeed); } } else { beginDraw(); + stroke(_textR, _textG, _textB); text(_textBuffer, _textX, _textY); endDraw(); } diff --git a/src/ArduinoGraphics.h b/src/ArduinoGraphics.h index f5468b0..c409796 100644 --- a/src/ArduinoGraphics.h +++ b/src/ArduinoGraphics.h @@ -1,20 +1,6 @@ /* This file is part of the ArduinoGraphics library. - Copyright (c) 2019 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Copyright (c) 2025 Arduino SA. All rights reserved. */ #ifndef _ARDUINO_GRAPHICS_H @@ -43,6 +29,7 @@ class ArduinoGraphics : public Print { int width(); int height(); + uint32_t background(); virtual void beginDraw(); virtual void endDraw(); @@ -50,6 +37,7 @@ class ArduinoGraphics : public Print { void background(uint8_t r, uint8_t g, uint8_t b); void background(uint32_t color); void clear(); + void clear(int x, int y); void fill(uint8_t r, uint8_t g, uint8_t b); void fill(uint32_t color); void noFill(); @@ -58,7 +46,8 @@ class ArduinoGraphics : public Print { void noStroke(); //virtual void arc(int x, int y, int width, int height, int start, int stop); - //virtual void ellipse(int x, int y, int width, int height); + virtual void circle(int x, int y, int diameter); + virtual void ellipse(int x, int y, int width, int height); virtual void line(int x1, int y1, int x2, int y2); virtual void point(int x, int y); //virtual void quad(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4); @@ -68,6 +57,8 @@ class ArduinoGraphics : public Print { virtual void text(const char* str, int x = 0, int y = 0); virtual void text(const String& str, int x = 0, int y = 0) { text(str.c_str(), x, y); } virtual void textFont(const Font& which); + virtual void textSize(uint8_t s) {textSize(s, s);} + virtual void textSize(uint8_t sx, uint8_t sy); virtual int textFontWidth() const; virtual int textFontHeight() const; @@ -89,7 +80,8 @@ class ArduinoGraphics : public Print { virtual void textScrollSpeed(unsigned long speed = 150); protected: - virtual void bitmap(const uint8_t* data, int x, int y, int width, int height); + virtual void bitmap(const uint8_t* data, int x, int y, int w, int h, uint8_t scale_x = 1, + uint8_t scale_y = 1); virtual void imageRGB(const Image& img, int x, int y, int width, int height); virtual void imageRGB24(const Image& img, int x, int y, int width, int height); virtual void imageRGB16(const Image& img, int x, int y, int width, int height); @@ -112,6 +104,8 @@ class ArduinoGraphics : public Print { uint8_t _textR, _textG, _textB; int _textX; int _textY; + uint8_t _textSizeX; + uint8_t _textSizeY; unsigned long _textScrollSpeed; }; diff --git a/src/Font.h b/src/Font.h index f44f9b5..c1d7f46 100644 --- a/src/Font.h +++ b/src/Font.h @@ -1,20 +1,6 @@ /* This file is part of the ArduinoGraphics library. - Copyright (c) 2019 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Copyright (c) 2025 Arduino SA. All rights reserved. */ #ifndef _FONT_H diff --git a/src/Font_4x6.c b/src/Font_4x6.c index 257ef73..407527b 100644 --- a/src/Font_4x6.c +++ b/src/Font_4x6.c @@ -1,20 +1,6 @@ /* This file is part of the ArduinoGraphics library. - Copyright (c) 2019 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Copyright (c) 2025 Arduino SA. All rights reserved. */ #include "Font.h" diff --git a/src/Font_5x7.c b/src/Font_5x7.c index 3c9a31b..a4ee951 100644 --- a/src/Font_5x7.c +++ b/src/Font_5x7.c @@ -1,20 +1,6 @@ /* This file is part of the ArduinoGraphics library. - Copyright (c) 2019 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Copyright (c) 2025 Arduino SA. All rights reserved. */ #include "Font.h" diff --git a/src/HasIncludeArduinoGraphics.h b/src/HasIncludeArduinoGraphics.h new file mode 100644 index 0000000..cc27970 --- /dev/null +++ b/src/HasIncludeArduinoGraphics.h @@ -0,0 +1,4 @@ +/* +This file is intentionally left blank. +Do not remove this comment. +*/ \ No newline at end of file diff --git a/src/Image.cpp b/src/Image.cpp index e7ad1a2..a010491 100644 --- a/src/Image.cpp +++ b/src/Image.cpp @@ -1,20 +1,6 @@ /* This file is part of the ArduinoGraphics library. - Copyright (c) 2019 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Copyright (c) 2025 Arduino SA. All rights reserved. */ #include diff --git a/src/Image.h b/src/Image.h index 0483e8e..c8f478f 100644 --- a/src/Image.h +++ b/src/Image.h @@ -1,20 +1,6 @@ /* This file is part of the ArduinoGraphics library. - Copyright (c) 2019 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Copyright (c) 2025 Arduino SA. All rights reserved. */ #ifndef _IMAGE_H