├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── _meta.lua ├── canvas.lua ├── editor.lua ├── icons ├── LICENSE-2.0.txt ├── center.png ├── circle.png ├── circlefill.png ├── close.png ├── dither.png ├── eraser.png ├── eyedropper.png ├── fill.png ├── fillall.png ├── filldiag.png ├── grid.png ├── line.png ├── load.png ├── menu.png ├── minus.png ├── new.png ├── pan.png ├── pencil.png ├── plus.png ├── rectangle.png ├── rectanglefill.png ├── refresh.png ├── resize.png ├── save.png └── view.png ├── item.lua ├── main.lua ├── rect.lua ├── screenshots ├── gridsize.png ├── old.png └── space.png └── submenu.lua /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .VSCodeCounter -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published 637 | by the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pixelart.koplugin 2 | 3 | ![GitHub repo size](https://img.shields.io/github/repo-size/morefoxbeans/pixelart.koplugin?style=for-the-badge) 4 | ![Lines of code](https://img.shields.io/tokei/lines/github/morefoxbeans/pixelart.koplugin?style=for-the-badge) 5 | ![GitHub commit activity](https://img.shields.io/github/commit-activity/m/morefoxbeans/pixelart.koplugin?style=for-the-badge) 6 | ![GitHub all releases](https://img.shields.io/github/downloads/morefoxbeans/pixelart.koplugin/total?style=for-the-badge) 7 | 8 | A WIP pixel art editor plugin for KOReader! I've only tested this on my personal reader so it please create an issue if something doesn't work. 9 | 10 | ## How to install 11 | 12 | Download the source code of the [latest release](https://github.com/MoreFoxBeans/pixelart.koplugin/releases), then extract that. Rename the folder "pixelart.koplugin-vX.X.X" to just "pixelart.koplugin". Now move that folder into the KOReader plugins directory, (it varies per device but for Kobo readers it's "~/.adds/koreader/plugins"). Restart KOReader and you're done! 13 | 14 | ## Where do I find it? 15 | 16 | It should be located in the "More tools" section of the plugins section of the KOReader menu. If you can't find it, make sure you have restarted KOReader before creating an issue. 17 | 18 | ## Tools 19 | 20 | - Menu 21 | - Change image size 22 | - Change grid size 23 | - New image 24 | - Save image 25 | - Open image 26 | - Quit 27 | - Pencil 28 | - Eraser 29 | - Picker 30 | - Line 31 | - Rectangle 32 | - Circle 33 | - Fill 34 | - Fill 8 directions 35 | - Fill 4 directions 36 | - Replace all colors 37 | - Pan 38 | - View 39 | - Zoom out 40 | - Zoom in 41 | - Fit to screen 42 | - Toggle grid 43 | - Refresh screen 44 | - Brush size 45 | - Lots of them! 46 | - Brush color 47 | - Colors (note that some may look similar on older devices) 48 | - Enable/disable shape fill 49 | 50 | ## Screenshots 51 | 52 | ![](screenshots/space.png) 53 | 54 | ![](screenshots/gridsize.png) 55 | -------------------------------------------------------------------------------- /_meta.lua: -------------------------------------------------------------------------------- 1 | local _ = require("gettext") 2 | return { 3 | name = "pixelart", 4 | fullname = _("Pixel Art"), 5 | description = _([[A simple pixel art editor.]]), 6 | } -------------------------------------------------------------------------------- /canvas.lua: -------------------------------------------------------------------------------- 1 | local Blitbuffer = require("ffi/blitbuffer") 2 | local Device = require("device") 3 | local Geom = require("ui/geometry") 4 | local GestureRange = require("ui/gesturerange") 5 | local InputContainer = require("ui/widget/container/inputcontainer") 6 | local RenderImage = require("ui/renderimage") 7 | local UIManager = require("ui/uimanager") 8 | 9 | -- Get the value at v% between a and b 10 | local function lerp(a, b, v) return (b - a) * v + a end 11 | 12 | -- Calculate the distance between two points 13 | local function dist(x1, y1, x2, y2) 14 | return math.sqrt(math.pow(math.abs(x2 - x1), 2) + math.pow(math.abs(y2 - y1), 2)) 15 | end 16 | 17 | -- Draw a line using linear interpolation [SLOW BUT EASY] 18 | local function paintLine(bb, x1, y1, x2, y2, c, s) 19 | for i = 0, 1, 1 / dist(x1, y1, x2, y2) do 20 | local lx = math.floor(lerp(x1, x2, i) + 0.5) 21 | local ly = math.floor(lerp(y1, y2, i) + 0.5) 22 | 23 | if lx >= 0 and ly >= 0 and lx < bb:getWidth() and ly < bb:getHeight() then 24 | if s == 1 then 25 | bb:setPixel(lx, ly, Blitbuffer.Color8(c)) 26 | else 27 | bb:paintCircle(lx, ly, math.floor(s / 2), Blitbuffer.Color8(c)) 28 | end 29 | end 30 | end 31 | end 32 | 33 | -- Paint a rectangle in any quadrant 34 | local function paintRect(bb, x1, y1, x2, y2, c, s) 35 | if s then 36 | if x2 >= x1 and y2 >= y1 then 37 | bb:paintBorder(x1, y1, x2 - x1 + 1, y2 - y1 + 1, s, Blitbuffer.Color8(c)) 38 | elseif x2 >= x1 and y2 < y1 then 39 | bb:paintBorder(x1, y2, x2 - x1 + 1, y1 - y2 + 1, s, Blitbuffer.Color8(c)) 40 | elseif x2 < x1 and y2 >= y1 then 41 | bb:paintBorder(x2, y1, x1 - x2 + 1, y2 - y1 + 1, s, Blitbuffer.Color8(c)) 42 | elseif x2 < x1 and y2 < y1 then 43 | bb:paintBorder(x2, y2, x1 - x2 + 1, y1 - y2 + 1, s, Blitbuffer.Color8(c)) 44 | end 45 | else 46 | if x2 >= x1 and y2 >= y1 then 47 | bb:paintRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1, Blitbuffer.Color8(c)) 48 | elseif x2 >= x1 and y2 < y1 then 49 | bb:paintRect(x1, y2, x2 - x1 + 1, y1 - y2 + 1, Blitbuffer.Color8(c)) 50 | elseif x2 < x1 and y2 >= y1 then 51 | bb:paintRect(x2, y1, x1 - x2 + 1, y2 - y1 + 1, Blitbuffer.Color8(c)) 52 | elseif x2 < x1 and y2 < y1 then 53 | bb:paintRect(x2, y2, x1 - x2 + 1, y1 - y2 + 1, Blitbuffer.Color8(c)) 54 | end 55 | end 56 | end 57 | 58 | -- Flood/bucket fill at a point 59 | local function floodFill(bb, x, y, c, diag) 60 | local cur = bb:getPixel(x, y).a 61 | if cur == c then return end 62 | fill(bb, x, y, c, cur, diag) 63 | end 64 | 65 | function fill(bb, x, y, c, cur, diag) 66 | if x < 0 or y < 0 or x > bb:getWidth() - 1 or y > bb:getHeight() - 1 or bb:getPixel(x, y).a ~= cur then return end 67 | 68 | bb:setPixel(x, y, Blitbuffer.Color8(c)) 69 | fill(bb, x, y - 1, c, cur, diag) 70 | fill(bb, x, y + 1, c, cur, diag) 71 | fill(bb, x - 1, y, c, cur, diag) 72 | fill(bb, x + 1, y, c, cur, diag) 73 | 74 | if diag then 75 | fill(bb, x - 1, y - 1, c, cur, diag) 76 | fill(bb, x + 1, y + 1, c, cur, diag) 77 | fill(bb, x - 1, y + 1, c, cur, diag) 78 | fill(bb, x + 1, y - 1, c, cur, diag) 79 | end 80 | end 81 | 82 | local Canvas = InputContainer:new{ 83 | width = nil, 84 | height = nil, 85 | dark = nil, 86 | show_parent = nil, 87 | 88 | image_w = 64, 89 | image_h = 64, 90 | zoom = 40, 91 | grid = true, 92 | grid_w = 8, 93 | grid_h = 8, 94 | pattern = false, 95 | view_x = 0, 96 | view_y = 0, 97 | 98 | _touch_ix = nil, -- Initial touch point 99 | _touch_iy = nil, 100 | _touch_px = nil, -- Previous touch point 101 | _touch_py = nil, 102 | _touch_x = nil, -- Current touch point 103 | _touch_y = nil, 104 | 105 | _view_ix = nil, -- Initial view pos for pan tool 106 | _view_iy = nil, 107 | 108 | _image = nil, 109 | _preview = nil, 110 | _disp_preview = false, 111 | _bb = nil, 112 | } 113 | 114 | function Canvas:init() 115 | self.dimen = Geom:new{ 116 | x = 0, y = 0, 117 | w = self.width or self.show_parent.dimen.w, 118 | h = self.height or self.show_parent.dimen.h, 119 | } 120 | 121 | self.drag_callback = function () self:doDrag() end 122 | 123 | self.ges_events = { 124 | TouchCanvas = { 125 | GestureRange:new{ 126 | ges = "touch", 127 | range = function () return self.dimen end, 128 | }, 129 | }, 130 | } 131 | 132 | self:createCanvas(self.image_w, self.image_h) 133 | self:center() 134 | end 135 | 136 | -- Create a new canvas + free old + update! 137 | function Canvas:createCanvas(w, h) 138 | self.image_w = w 139 | self.image_h = h 140 | 141 | if self._image then self._image:free() end 142 | self._image = Blitbuffer.new(self.image_w, self.image_h, Blitbuffer.TYPE_BB8) 143 | self._image:fill(Blitbuffer.COLOR_WHITE) 144 | 145 | if self._preview then self._preview:free() end 146 | self._preview = Blitbuffer.new(self.image_w, self.image_h, Blitbuffer.TYPE_BB8) 147 | 148 | self:_update() 149 | end 150 | 151 | -- Resize the canvas anchored to (0, 0) 152 | function Canvas:resizeCanvas(nw, nh) 153 | local ow, oh = self.image_w, self.image_h 154 | local old = Blitbuffer.new(ow, oh, Blitbuffer.TYPE_BB8) 155 | old:blitFrom(self._image, 0, 0, 0, 0, ow, oh) 156 | self:createCanvas(nw, nh) 157 | self._image:blitFrom(old, 0, 0, 0, 0, ow, oh) 158 | old:free() 159 | old = nil 160 | 161 | self:_update("flashui") 162 | end 163 | 164 | -- Probably don't need this but it cools cool ig 165 | function Canvas:getCanvasSize() return { w = self.image_w, h = self.image_h } end 166 | 167 | -- Auto zoom/pos the canvas to fit screen 168 | function Canvas:center() 169 | if self.dimen.w / self.dimen.h <= self.image_w / self.image_h then 170 | self.zoom = math.floor(self.dimen.w / self.image_w) 171 | else 172 | self.zoom = math.floor(self.dimen.h / self.image_h) 173 | end 174 | 175 | self.view_x = math.floor((self.dimen.w - self.image_w * self.zoom) / 2) 176 | self.view_y = math.floor((self.dimen.h - self.image_h * self.zoom) / 2) 177 | 178 | self:_update("flashui") 179 | end 180 | 181 | function Canvas:setZoom(z) self.zoom = z self:_update() end 182 | function Canvas:getZoom() return self.zoom end 183 | function Canvas:zoomIn() self:setZoom(math.min(math.ceil(self.zoom * 1.5), 200)) end 184 | function Canvas:zoomOut() self:setZoom(math.max(math.floor(self.zoom / 1.5), 1)) end 185 | 186 | function Canvas:setGrid(g) self.grid = g self:_update() end 187 | function Canvas:getGrid() return self.grid end 188 | function Canvas:resizeGrid(nw, nh) self.grid_w, self.grid_h = nw, nh self:_update() end 189 | function Canvas:getGridSize() return { w = self.grid_w, h = self.grid_h } end 190 | 191 | -- Refresh the canvas using canvas coords, not screen coords 192 | function Canvas:_refresh(x, y, w, h, type) 193 | if x and y and w and h then 194 | UIManager:setDirty(self.show_parent, function () 195 | return (type or "ui"), Geom:new{ 196 | x = x * self.zoom + self.dimen.x + self.view_x, 197 | y = y * self.zoom + self.dimen.y + self.view_y, 198 | w = w * self.zoom, 199 | h = h * self.zoom, 200 | } 201 | end) 202 | else 203 | UIManager:setDirty(self.show_parent, function () 204 | return (x or type or "ui"), self.dimen 205 | end) 206 | end 207 | end 208 | 209 | -- If canvas changed, redraw and refresh 210 | function Canvas:_update(x, y, w, h, type) 211 | if self._bb then 212 | self._bb:free() 213 | self._bb = nil 214 | 215 | self:_refresh(x, y, w, h, type) 216 | end 217 | end 218 | 219 | function Canvas:paintTo(bb, x, y) 220 | self.dimen = Geom:new{ 221 | x = x, y = y, 222 | w = self.dimen.w, 223 | h = self.dimen.h 224 | } 225 | 226 | if not self._bb then 227 | self._bb = Blitbuffer.new(self.dimen.w, self.dimen.h, bb:getType()) 228 | self._bb:fill(Blitbuffer.Color8(self.dark and 0x33 or 0x99)) 229 | self._bb:paintRect(self.view_x, self.view_y, self.image_w * self.zoom, self.image_h * self.zoom, Blitbuffer.Color8(0x77)) 230 | 231 | -- Get draw pixel size (make smaller pixels instead of drawing lines for grid for faster painting 232 | local z = self.zoom - ((self.grid and self.zoom > 4) and 1 or 0) 233 | 234 | -- If preview image (line, rect, circle), then use that one 235 | local img = self._disp_preview and self._preview or self._image 236 | 237 | for iy = 0, self.image_h - 1 do 238 | for ix = 0, self.image_w - 1 do 239 | local vx = ix * self.zoom + self.view_x 240 | local vy = iy * self.zoom + self.view_y 241 | 242 | -- Bigger grid lines every few pixels 243 | local zw = self.grid_w == 1 and z or (z == self.zoom and self.zoom or (z - (ix % self.grid_w == self.grid_w - 1 and 1 or 0))) 244 | local zh = self.grid_h == 1 and z or (z == self.zoom and self.zoom or (z - (iy % self.grid_h == self.grid_h - 1 and 1 or 0))) 245 | 246 | if self.pattern then -- Hidden feature? 247 | for pix = -1, 1 do 248 | for piy = -1, 1 do 249 | self._bb:paintRect(vx + (self.image_w * self.zoom) * pix, vy + (self.image_h * self.zoom) * piy, (pix == 0 and piy == 0) and zw or self.zoom, (pix == 0 and piy == 0) and zh or self.zoom, img:getPixel(ix, iy)) 250 | end 251 | end 252 | else 253 | self._bb:paintRect(vx, vy, zw, zh, img:getPixel(ix, iy)) 254 | end 255 | end 256 | end 257 | 258 | -- Looks cool, mostly for if self.pattern 259 | self._bb:paintBorder(self.view_x - 4, self.view_y - 4, self.image_w * self.zoom + 8, self.image_h * self.zoom + 8, 4, Blitbuffer.Color8(0x66), 8) 260 | end 261 | 262 | bb:blitFrom(self._bb, x, y, 0, 0, self.dimen.w, self.dimen.h) 263 | end 264 | 265 | -- Convert screen coords to pixel coords 266 | function Canvas:tx(v) return math.floor((v - self.dimen.x - self.view_x) / self.zoom) end 267 | function Canvas:ty(v) return math.floor((v - self.dimen.y - self.view_y) / self.zoom) end 268 | 269 | -- When canvas first touched 270 | function Canvas:onTouchCanvas(arg, ges) 271 | if not(ges.pos.x >= 108 and ges.pos.y >= self.show_parent.submenu_y.width and ges.pos.x < 108 + self.show_parent.submenu:getSize().w and ges.pos.y < self.show_parent.submenu_y.width + 108) and ges.pos.x >= self.dimen.x + self.view_x and ges.pos.y >= self.dimen.y + self.view_y and ges.pos.x < self.dimen.x + self.view_x + self.image_w * self.zoom and ges.pos.y < self.dimen.y + self.view_y + self.image_h * self.zoom then -- Check if touching canvas and not touching submenu 272 | local tool = self.show_parent.tool -- alias 273 | local x, y = self:tx(ges.pos.x), self:ty(ges.pos.y) 274 | 275 | if tool == "picker" then 276 | self.show_parent.color = self._image:getPixel(x, y).a 277 | 278 | UIManager:setDirty(self.show_parent, function () 279 | return "ui", self.show_parent.dimen 280 | end) 281 | elseif tool == "fill" or tool == "filldiag" or tool == "fillall" then 282 | if tool == "fill" then 283 | floodFill(self._image, x, y, self.show_parent.color, false) 284 | elseif tool == "filldiag" then 285 | floodFill(self._image, x, y, self.show_parent.color, true) 286 | elseif tool == "fillall" then 287 | local fillcur = self._image:getPixel(x, y).a 288 | 289 | for hyi = 0, self.image_h - 1 do 290 | for wxi = 0, self.image_w - 1 do 291 | if self._image:getPixel(wxi, hyi).a == fillcur then 292 | self._image:setPixel(wxi, hyi, Blitbuffer.Color8(self.show_parent.color)) 293 | end 294 | end 295 | end 296 | end 297 | 298 | self:_update() 299 | 300 | UIManager:setDirty(self.show_parent, function () 301 | return "ui", self.show_parent.dimen 302 | end) 303 | else 304 | if tool == "line" or tool == "circle" or tool == "rect" then 305 | self._touch_ix = x -- Store initial coords 306 | self._touch_iy = y 307 | 308 | self._disp_preview = true 309 | end 310 | 311 | if tool == "pan" then 312 | self._touch_ix = ges.pos.x -- Store initial screen coords 313 | self._touch_iy = ges.pos.y 314 | 315 | self._view_ix = self.view_x -- Store initial view coords 316 | self._view_iy = self.view_y 317 | end 318 | 319 | self._touch_x = nil 320 | self._touch_y = nil 321 | 322 | self:doDrag() 323 | end 324 | 325 | return true 326 | end 327 | end 328 | 329 | function Canvas:dragLine() 330 | local ix, iy = self._touch_ix, self._touch_iy 331 | local px, py = self._touch_px, self._touch_py 332 | local x, y = self._touch_x, self._touch_y 333 | 334 | local nx, xx, ny, xy = math.min(ix, px, x), math.max(ix, px, x), math.min(iy, py, y), math.max(iy, py, y) -- Get full boundaries to refresh 335 | 336 | self._preview:blitFrom(self._image, 0, 0, 0, 0, self.image_w, self.image_h) 337 | paintLine(self._preview, ix, iy, x, y, self.show_parent.color, self.show_parent.size) 338 | 339 | local s = self.show_parent.size 340 | self:_update(nx - math.floor(s / 2), ny - math.floor(s / 2), xx - nx + s + 1, xy - ny + s + 1) 341 | end 342 | 343 | function Canvas:releaseLine() 344 | local ix, iy = self._touch_ix, self._touch_iy 345 | local px, py = self._touch_px, self._touch_py 346 | local x, y = self._touch_x, self._touch_y 347 | 348 | local nx, xx, ny, xy = math.min(ix, px, x), math.max(ix, px, x), math.min(iy, py, y), math.max(iy, py, y) -- Get full boundaries to refresh 349 | 350 | paintLine(self._image, ix, iy, x, y, self.show_parent.color, self.show_parent.size) 351 | 352 | self._disp_preview = false 353 | 354 | local s = self.show_parent.size 355 | self:_update(nx - math.floor(s / 2), ny - math.floor(s / 2), xx - nx + s + 1, xy - ny + s + 1) 356 | end 357 | 358 | function Canvas:dragRect() 359 | local ix, iy = self._touch_ix, self._touch_iy 360 | local px, py = self._touch_px, self._touch_py 361 | local x, y = self._touch_x, self._touch_y 362 | 363 | local nx, xx, ny, xy = math.min(ix, px, x), math.max(ix, px, x), math.min(iy, py, y), math.max(iy, py, y) -- Get full boundaries to refresh 364 | 365 | self._preview:blitFrom(self._image, 0, 0, 0, 0, self.image_w, self.image_h) 366 | 367 | paintRect(self._preview, ix, iy, x, y, self.show_parent.color, not self.show_parent.fill and self.show_parent.size or nil) 368 | 369 | self:_update(nx, ny, xx - nx + 1, xy - ny + 1) 370 | end 371 | 372 | function Canvas:releaseRect() 373 | local ix, iy = self._touch_ix, self._touch_iy 374 | local px, py = self._touch_px, self._touch_py 375 | local x, y = self._touch_x, self._touch_y 376 | 377 | local nx, xx, ny, xy = math.min(ix, px, x), math.max(ix, px, x), math.min(iy, py, y), math.max(iy, py, y) -- Get full boundaries to refresh 378 | 379 | paintRect(self._image, ix, iy, x, y, self.show_parent.color, not self.show_parent.fill and self.show_parent.size or nil) 380 | 381 | self._disp_preview = false 382 | 383 | self:_update(nx, ny, xx - nx + 1, xy - ny + 1) 384 | end 385 | 386 | function Canvas:dragCircle() 387 | local ix, iy = self._touch_ix, self._touch_iy 388 | local px, py = self._touch_px, self._touch_py 389 | local x, y = self._touch_x, self._touch_y 390 | 391 | local s = math.floor(dist(ix, iy, x, y)) 392 | local ms = math.max(math.floor(dist(ix, iy, px, py)), s) 393 | 394 | self._preview:blitFrom(self._image, 0, 0, 0, 0, self.image_w, self.image_h) 395 | 396 | self._preview:paintCircle(ix, iy, s, Blitbuffer.Color8(self.show_parent.color), not self.show_parent.fill and self.show_parent.size or nil) 397 | 398 | self:_update(ix - ms, iy - ms, ms * 2 + 1, ms * 2 + 1) 399 | end 400 | 401 | function Canvas:releaseCircle() 402 | local ix, iy = self._touch_ix, self._touch_iy 403 | local px, py = self._touch_px, self._touch_py 404 | local x, y = self._touch_x, self._touch_y 405 | 406 | local s = math.floor(dist(ix, iy, x, y)) 407 | local ms = math.max(math.floor(dist(ix, iy, px, py)), s) 408 | 409 | self._image:paintCircle(ix, iy, s, Blitbuffer.Color8(self.show_parent.color), not self.show_parent.fill and self.show_parent.size or nil) 410 | 411 | self._disp_preview = false 412 | 413 | self:_update(ix - ms, iy - ms, ms * 2 + 1, ms * 2 + 1) 414 | end 415 | 416 | function Canvas:dragPencil() 417 | local px, py = self._touch_px, self._touch_py 418 | local x, y = self._touch_x, self._touch_y 419 | 420 | for i = 0, 1, 1 / dist(px, py, x, y) do -- Interpolate (pixels between touch coords for smooth lines) 421 | local lx = math.floor(lerp(px, x, i)) 422 | local ly = math.floor(lerp(py, y, i)) 423 | 424 | if self.show_parent.size == 1 then 425 | if lx >= 0 and ly >= 0 and lx < self.image_w and ly < self.image_h then 426 | self._image:setPixel(lx, ly, self.show_parent.tool == "pencil" and Blitbuffer.Color8(self.show_parent.color) or Blitbuffer.COLOR_WHITE) 427 | end 428 | else 429 | self._image:paintCircle(lx, ly, math.floor(self.show_parent.size / 2), self.show_parent.tool == "pencil" and Blitbuffer.Color8(self.show_parent.color) or Blitbuffer.COLOR_WHITE) 430 | end 431 | end 432 | 433 | local nx, xx, ny, xy = math.min(px, x), math.max(px, x), math.min(py, y), math.max(py, y) -- Get full boundaries to refresh 434 | local s = self.show_parent.size 435 | self:_update(nx - math.floor(s / 2), ny - math.floor(s / 2), xx - nx + s + 1, xy - ny + s + 1) 436 | end 437 | 438 | function Canvas:dragPan() 439 | local ix, iy = self._touch_ix, self._touch_iy 440 | local x, y = Device.input:getCurrentMtSlotData("x"), Device.input:getCurrentMtSlotData("y") 441 | 442 | self.view_x = self._view_ix + x - ix 443 | self.view_y = self._view_iy + y - iy 444 | 445 | self:_update() 446 | end 447 | 448 | function Canvas:releasePan() 449 | self:_refresh("flashui") 450 | end 451 | 452 | function Canvas:doDrag() 453 | self._touch_px = self._touch_x 454 | self._touch_py = self._touch_y 455 | self._touch_x = self:tx(Device.input:getCurrentMtSlotData("x")) 456 | self._touch_y = self:ty(Device.input:getCurrentMtSlotData("y")) 457 | self._touch_px = self._touch_px or self._touch_x 458 | self._touch_py = self._touch_py or self._touch_y 459 | 460 | local tool = self.show_parent.tool 461 | 462 | if tool == "pencil" or tool == "eraser" then self:dragPencil() 463 | elseif tool == "line" then self:dragLine() 464 | elseif tool == "rect" then self:dragRect() 465 | elseif tool == "circle" then self:dragCircle() 466 | elseif tool == "pan" then self:dragPan() 467 | end 468 | 469 | if Device.input:getCurrentMtSlotData("id") ~= -1 then 470 | UIManager:scheduleIn(tool == "pan" and 0.3 or 0.1, self.drag_callback) 471 | else 472 | if tool == "line" then self:releaseLine() 473 | elseif tool == "rect" then self:releaseRect() 474 | elseif tool == "circle" then self:releaseCircle() 475 | elseif tool == "pan" then self:releasePan() 476 | end 477 | end 478 | end 479 | 480 | -- Clear the canvas + center 481 | function Canvas:newImage() 482 | self._image:fill(Blitbuffer.COLOR_WHITE) 483 | self:center() 484 | self:_update() 485 | end 486 | 487 | -- Export canvas to PNG 488 | function Canvas:saveImage(file) 489 | local bgr = Device:hasBGRFrameBuffer() and true or false 490 | self._image:writePNG(file, bgr) 491 | end 492 | 493 | -- Load canvas from image 494 | function Canvas:loadImage(file) 495 | local load = RenderImage:renderImageFile(file, false, self.image_w, self.image_h) 496 | self._image:blitFrom(load, 0, 0) 497 | load:free() 498 | self:center() 499 | self:_update() 500 | end 501 | 502 | function Canvas:free() 503 | if self._image then self._image:free() end 504 | if self._preview then self._preview:free() end 505 | if self._bb then self._bb:free() end 506 | self._image = nil 507 | self._preview = nil 508 | self._bb = nil 509 | end 510 | 511 | return Canvas -------------------------------------------------------------------------------- /editor.lua: -------------------------------------------------------------------------------- 1 | local Blitbuffer = require("ffi/blitbuffer") 2 | local Canvas = require("canvas") 3 | local ConfirmBox = require("ui/widget/confirmbox") 4 | local DataStorage = require("datastorage") 5 | local Device = require("device") 6 | local Event = require("ui/event") 7 | local FrameContainer = require("ui/widget/container/framecontainer") 8 | local Geom = require("ui/geometry") 9 | local GestureRange = require("ui/gesturerange") 10 | local HorizontalGroup = require("ui/widget/horizontalgroup") 11 | local HorizontalSpan = require("ui/widget/horizontalspan") 12 | local InputContainer = require("ui/widget/container/inputcontainer") 13 | local InputDialog = require("ui/widget/inputdialog") 14 | local Item = require("item") 15 | local OverlapGroup = require("ui/widget/overlapgroup") 16 | local PathChooser = require("ui/widget/pathchooser") 17 | local Rect = require("rect") 18 | local Screen = Device.screen 19 | local SubMenu = require("submenu") 20 | local UIManager = require("ui/uimanager") 21 | local VerticalGroup = require("ui/widget/verticalgroup") 22 | local VerticalSpan = require("ui/widget/verticalspan") 23 | local WidgetContainer = require("ui/widget/container/widgetcontainer") 24 | local ffiutil = require("ffi/util") 25 | 26 | local dark = false -- hidden dark mode? might make an official feature 27 | 28 | local colors = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF } 29 | local sizes = { 1, 2, 3, 4, 5, 6, 8, 10, 20 } 30 | 31 | --[[ Sidebar buttons (try adding one!) 32 | icon (load icon from plugins/pixelart.koplugin/icons) 33 | text (ugly text, use only as a placeholder) 34 | tool (select this tool when tapped) 35 | menu (open this menu when tapped) 36 | callback (run this when tapped) 37 | dim (draw grey border if true) 38 | background (set the button background) 39 | size (draw a black circle this size) 40 | seperator (add a gap after this button) 41 | ]] 42 | local button_info = { 43 | { 44 | icon = "menu", 45 | menu = "menu", 46 | seperator = true, 47 | }, 48 | { 49 | icon = "pencil", 50 | tool = "pencil", 51 | }, 52 | { 53 | icon = "eraser", 54 | tool = "eraser", 55 | }, 56 | { 57 | icon = "eyedropper", 58 | tool = "picker", 59 | }, 60 | { 61 | icon = "line", 62 | tool = "line", 63 | }, 64 | { 65 | icon = function (self) return self.fill and "rectanglefill" or "rectangle" end, 66 | tool = "rect", 67 | }, 68 | { 69 | icon = function (self) return self.fill and "circlefill" or "circle" end, 70 | tool = "circle", 71 | }, 72 | { 73 | icon = function (self) return self.fill_tool end, 74 | menu = "fill", 75 | callback = function (self) if self.tool == self.fill_tool then self:updateMenu("fill") else self.tool = self.fill_tool end end, 76 | dim = function (self) return self.tool == "fill" or self.tool == "filldiag" or self.tool == "fillall" end, 77 | }, 78 | { 79 | icon = "pan", 80 | tool = "pan", 81 | seperator = true, 82 | }, 83 | { 84 | icon = "view", 85 | menu = "view", 86 | }, 87 | { 88 | icon = "grid", 89 | callback = function (self) self.canvas:setGrid(not self.canvas:getGrid()) end, 90 | dim = function (self) return self.canvas:getGrid() end, 91 | }, 92 | { 93 | icon = "refresh", 94 | callback = function (self) self:refresh() end, 95 | seperator = true, 96 | }, 97 | { 98 | menu = "sizes", 99 | size = function (self) return self.size end, 100 | }, 101 | { 102 | menu = "colors", 103 | background = function (self) return Blitbuffer.Color8(self.color) end, 104 | }, 105 | } 106 | 107 | -- Submenus (ibid.) 108 | local menu_buttons = { 109 | ["colors"] = { 110 | { 111 | icon = "fill", 112 | callback = function (self) self.fill = not self.fill end, 113 | dim = function (self) return self.fill end, 114 | }, 115 | }, 116 | ["sizes"] = {}, 117 | ["menu"] = { 118 | { 119 | icon = "resize", 120 | callback = function (self) self:resizeCanvas() end, 121 | }, 122 | { 123 | icon = "grid", 124 | callback = function (self) self:resizeGrid() end, 125 | }, 126 | { 127 | icon = "new", 128 | callback = function (self) self:newImage() end, 129 | }, 130 | { 131 | icon = "save", 132 | callback = function (self) self:saveImage() end, 133 | }, 134 | { 135 | icon = "load", 136 | callback = function (self) self:loadImage() end, 137 | }, 138 | { 139 | icon = "close", 140 | callback = function (self) self:quit() end, 141 | }, 142 | }, 143 | ["fill"] = { 144 | { 145 | icon = "fill", 146 | callback = function (self) self.tool = "fill" self.fill_tool = "fill" self:updateMenu("none") end, 147 | dim = function (self) return self.tool == "fill" end, 148 | }, 149 | { 150 | icon = "filldiag", 151 | callback = function (self) self.tool = "filldiag" self.fill_tool = "filldiag" self:updateMenu("none") end, 152 | dim = function (self) return self.tool == "filldiag" end, 153 | }, 154 | { 155 | icon = "fillall", 156 | callback = function (self) self.tool = "fillall" self.fill_tool = "fillall" self:updateMenu("none") end, 157 | dim = function (self) return self.tool == "fillall" end, 158 | }, 159 | }, 160 | ["view"] = { 161 | { 162 | icon = "minus", 163 | callback = function (self) self.canvas:zoomOut() end, 164 | }, 165 | { 166 | icon = "plus", 167 | callback = function (self) self.canvas:zoomIn() end, 168 | }, 169 | { 170 | icon = "center", 171 | callback = function (self) self.canvas:center() end, 172 | }, 173 | }, 174 | } 175 | 176 | local button_size = 108 -- self-explanatory 177 | local sep_size = (Screen:getHeight() - #button_info * button_size) / 3 -- Even space btwn button groups 178 | 179 | -- Add color options 180 | for i = 1, #colors do 181 | table.insert(menu_buttons["colors"], #menu_buttons["colors"], { 182 | callback = function (self) self.color = colors[i] end, 183 | dim = function (self) return self.color == colors[i] end, 184 | background = Blitbuffer.Color8(colors[i]), 185 | width = button_size / 1.75, 186 | }) 187 | end 188 | 189 | -- Add size options 190 | for i = 1, #sizes do 191 | table.insert(menu_buttons["sizes"], { 192 | callback = function (self) self.size = sizes[i] end, 193 | dim = function (self) return self.size == sizes[i] end, 194 | size = sizes[i], 195 | }) 196 | end 197 | 198 | local night = false 199 | 200 | local function setNight(night) 201 | if not(G_reader_settings:nilOrFalse("night_mode")) ~= night then 202 | UIManager:broadcastEvent(Event:new("ToggleNightMode")) 203 | end 204 | end 205 | 206 | local Editor = InputContainer:new{ 207 | title = "Pixel Art", 208 | covers_fullscreen = true, 209 | 210 | tool = "pencil", 211 | color = 0x00, 212 | size = 1, 213 | fill = false, 214 | fill_tool = "fill", 215 | 216 | top = "colors", 217 | last_path = ffiutil.realpath(DataStorage:getDataDir()), 218 | } 219 | 220 | function Editor:init() 221 | self.dimen = Geom:new{ 222 | w = Screen:getWidth(), 223 | h = Screen:getHeight(), 224 | } 225 | 226 | self.canvas = Canvas:new{ 227 | width = self.dimen.w - button_size, 228 | height = self.dimen.h, 229 | show_parent = self, 230 | dark = dark, 231 | 232 | image_w = 64, 233 | image_h = 64, 234 | } 235 | 236 | self.buttons = VerticalGroup:new{ show_parent = self, } 237 | self:addButtons() 238 | 239 | local content = HorizontalGroup:new{ 240 | show_parent = self, 241 | align = "top", 242 | self.buttons, 243 | Rect:new{ width = 4, height = self.dimen.h, background = Blitbuffer.Color8(dark and 0x55 or 0xBB) }, 244 | self.canvas, 245 | } 246 | 247 | self.submenu = SubMenu:new{ dark = dark, show_parent = self, } 248 | self:updateMenu(self.menu) 249 | 250 | self.submenu_y = VerticalSpan:new{ width = 0 } 251 | 252 | self.submenu_overlay = VerticalGroup:new{ 253 | show_parent = self, 254 | self.submenu_y, 255 | self.submenu, 256 | } 257 | 258 | local overlay = OverlapGroup:new{ 259 | dimen = Geom:new{ 260 | w = self.dimen.w, 261 | h = self.dimen.h, 262 | }, 263 | show_parent = self, 264 | content, 265 | HorizontalGroup:new{ 266 | show_parent = self, 267 | HorizontalSpan:new{ width = button_size }, 268 | self.submenu_overlay, 269 | }, 270 | } 271 | 272 | self[1] = FrameContainer:new{ 273 | width = self.dimen.w, 274 | height = self.dimen.h, 275 | padding = 0, 276 | margin = 0, 277 | bordersize = 0, 278 | background = dark and Blitbuffer.COLOR_BLACK or Blitbuffer.COLOR_WHITE, 279 | overlay, 280 | } 281 | 282 | -- turn to day mode 283 | night = not(G_reader_settings:nilOrFalse("night_mode")) 284 | setNight(false) 285 | 286 | self:refresh() 287 | end 288 | 289 | -- Generate callback and dim for menu and tool values 290 | function Editor:getCallback(item) 291 | local callback, dim 292 | 293 | if item.menu then 294 | callback = function (self) self:updateMenu(item.menu) end 295 | dim = function (self) return self.menu == item.menu end 296 | elseif item.tool then 297 | callback = function (self) self.tool = item.tool end 298 | dim = function (self) return self.tool == item.tool end 299 | else 300 | callback = item.callback 301 | dim = item.dim 302 | end 303 | 304 | return { callback = item.callback or callback, dim = item.dim or dim } 305 | end 306 | 307 | -- Add buttons to left bar 308 | function Editor:addButtons() 309 | self.buttons:clear() 310 | 311 | local y = 0 312 | 313 | for i = 1, #button_info do 314 | local f = self:getCallback(button_info[i]) 315 | 316 | local item = Item:new{ 317 | text = button_info[i].name, 318 | icon = button_info[i].icon, 319 | callback = f.callback, 320 | dim = f.dim, 321 | width = button_info[i].width or button_size, 322 | height = button_info[i].height or button_size, 323 | background = button_info[i].background, 324 | size = button_info[i].size, 325 | menu = button_info[i].menu, 326 | dark = dark, 327 | show_parent = self, 328 | } 329 | 330 | table.insert(self.buttons, item) 331 | 332 | -- Tell the submenu what its parent is 333 | if button_info[i].menu then 334 | menu_buttons[button_info[i].menu].index = i 335 | end 336 | 337 | -- Y pos for submenu 338 | button_info[i].y = y 339 | 340 | y = y + (button_info[i].height or button_size) 341 | 342 | if button_info[i].seperator then 343 | table.insert(self.buttons, VerticalSpan:new{ width = sep_size }) 344 | y = y + sep_size 345 | end 346 | end 347 | end 348 | 349 | -- Update submenu 350 | function Editor:updateMenu(page) 351 | if self.menu == page then 352 | page = "none" 353 | end 354 | 355 | local p = menu_buttons[page] 356 | 357 | if p then 358 | self.menu = page 359 | self.submenu:clear() 360 | 361 | self.submenu_y.width = button_info[p.index].y 362 | self.submenu_overlay:resetLayout() 363 | 364 | for i = 1, #p do 365 | local f = self:getCallback(p[i]) 366 | 367 | table.insert(self.submenu, Item:new{ 368 | text = p[i].name, 369 | icon = p[i].icon, 370 | callback = f.callback, 371 | dim = f.dim, 372 | width = p[i].width or button_size, 373 | height = p[i].height or button_size, 374 | background = p[i].background, 375 | size = p[i].size, 376 | index = p.index, 377 | dark = dark, 378 | show_parent = self, 379 | }) 380 | 381 | if p[i].seperator then 382 | table.insert(self.submenu, HorizontalSpan:new{ width = sep_size }) 383 | end 384 | end 385 | elseif page == "none" then 386 | self.menu = "none" 387 | self.submenu:clear() 388 | end 389 | 390 | UIManager:setDirty(self, function() 391 | return "ui", self.dimen 392 | end) 393 | end 394 | 395 | function Editor:newImage() 396 | UIManager:show(ConfirmBox:new{ 397 | text = "Are you sure you would like to clear your drawing?", 398 | ok_text = "Clear", 399 | cancel_text = "Keep", 400 | ok_callback = function() self:updateMenu("none") self.canvas:newImage() end, 401 | }) 402 | end 403 | 404 | function Editor:saveImage() 405 | local chooser = PathChooser:new{ 406 | title = "Which folder?", 407 | path = self.last_path, 408 | select_directory = true, 409 | select_file = false, 410 | onConfirm = function(dir_path) 411 | local file_input 412 | file_input = InputDialog:new{ 413 | title = "Enter name", 414 | input = "", 415 | buttons = {{ 416 | { 417 | text = "Cancel", 418 | callback = function() UIManager:close(file_input) end, 419 | }, 420 | { 421 | text = "Save", 422 | callback = function() 423 | local file_path = file_input:getInputText() 424 | local fp = (dir_path == "/" and "/" or dir_path .. "/") .. file_path .. ".png" 425 | UIManager:close(file_input) 426 | self.last_path = fp:match("(.*)/") 427 | if self.last_path == "" then self.last_path = "/" end 428 | self.canvas:saveImage(fp) 429 | self:updateMenu("none") 430 | end, 431 | }, 432 | }}, 433 | } 434 | 435 | UIManager:show(file_input) 436 | file_input:onShowKeyboard() 437 | end, 438 | } 439 | 440 | UIManager:show(chooser) 441 | end 442 | 443 | function Editor:loadImage() 444 | local chooser = PathChooser:new{ 445 | title = "Which image?", 446 | path = self.last_path, 447 | select_file = true, 448 | select_directory = false, 449 | detailed_file_info = true, 450 | file_filter = function (path) 451 | local itype = string.lower(string.match(path, ".+%.([^.]+)") or "") 452 | 453 | return itype == "svg" or itype == "png" or itype == "jpg" or itype == "jpeg" or itype == "gif" or itype == "tiff" or itype == "tif" 454 | end, 455 | onConfirm = function (file_path) 456 | self.canvas:loadImage(file_path) 457 | self:updateMenu("none") 458 | end, 459 | } 460 | 461 | UIManager:show(chooser) 462 | end 463 | 464 | function Editor:resizeCanvas() 465 | local width, height, nw, nh 466 | 467 | width = InputDialog:new{ 468 | title = "Enter image width", 469 | input = tostring(self.canvas:getCanvasSize().w), 470 | buttons = {{ 471 | { 472 | text = "Cancel", 473 | callback = function() UIManager:close(width) end, 474 | }, 475 | { 476 | text = "Next", 477 | callback = function() 478 | nw = tonumber(width:getInputText()) 479 | 480 | if nw then 481 | UIManager:close(width) 482 | UIManager:show(height) 483 | height:onShowKeyboard() 484 | end 485 | end, 486 | }, 487 | }}, 488 | } 489 | 490 | height = InputDialog:new{ 491 | title = "Enter image height", 492 | input = tostring(self.canvas:getCanvasSize().h), 493 | buttons = {{ 494 | { 495 | text = "Cancel", 496 | callback = function() UIManager:close(height) end, 497 | }, 498 | { 499 | text = "Resize", 500 | callback = function() 501 | nh = tonumber(height:getInputText()) 502 | 503 | if nh then 504 | UIManager:close(height) 505 | self.canvas:resizeCanvas(nw, nh) 506 | self:updateMenu("none") 507 | end 508 | end, 509 | }, 510 | }}, 511 | } 512 | 513 | UIManager:show(width) 514 | width:onShowKeyboard() 515 | end 516 | 517 | -- Change the big grid size 518 | function Editor:resizeGrid() 519 | local width, height, nw, nh 520 | 521 | width = InputDialog:new{ 522 | title = "Enter grid width", 523 | input = tostring(self.canvas:getGridSize().w), 524 | buttons = {{ 525 | { 526 | text = "Cancel", 527 | callback = function() UIManager:close(width) end, 528 | }, 529 | { 530 | text = "Next", 531 | callback = function() 532 | nw = tonumber(width:getInputText()) 533 | 534 | if nw then 535 | UIManager:close(width) 536 | UIManager:show(height) 537 | height:onShowKeyboard() 538 | end 539 | end, 540 | }, 541 | }}, 542 | } 543 | 544 | height = InputDialog:new{ 545 | title = "Enter grid height", 546 | input = tostring(self.canvas:getGridSize().h), 547 | buttons = {{ 548 | { 549 | text = "Cancel", 550 | callback = function() UIManager:close(height) end, 551 | }, 552 | { 553 | text = "Resize", 554 | callback = function() 555 | nh = tonumber(height:getInputText()) 556 | 557 | if nh then 558 | UIManager:close(height) 559 | self.canvas:resizeGrid(nw, nh) 560 | self:updateMenu("none") 561 | end 562 | end, 563 | }, 564 | }}, 565 | } 566 | 567 | UIManager:show(width) 568 | width:onShowKeyboard() 569 | end 570 | 571 | function Editor:refresh() 572 | setNight(false) 573 | UIManager:setDirty(self, function() 574 | return "flashui", self.dimen 575 | end) 576 | end 577 | 578 | function Editor:quit() 579 | UIManager:show(ConfirmBox:new{ 580 | text = "Are you sure you would like to quit?", 581 | ok_text = "Quit", 582 | cancel_text = "Stay", 583 | ok_callback = function() self:onClose() end, 584 | }) 585 | end 586 | 587 | function Editor:onClose() 588 | self.canvas:free() -- ayyyyy being responsible with memoryyyyyy 589 | UIManager:close(self) 590 | 591 | setNight(night) 592 | 593 | self:refresh() 594 | 595 | return true 596 | end 597 | 598 | return Editor -------------------------------------------------------------------------------- /icons/LICENSE-2.0.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /icons/center.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MoreFoxBeans/pixelart.koplugin/407e711f963a58c93482d4c69e8e6de12c98263d/icons/center.png -------------------------------------------------------------------------------- /icons/circle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MoreFoxBeans/pixelart.koplugin/407e711f963a58c93482d4c69e8e6de12c98263d/icons/circle.png -------------------------------------------------------------------------------- /icons/circlefill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MoreFoxBeans/pixelart.koplugin/407e711f963a58c93482d4c69e8e6de12c98263d/icons/circlefill.png -------------------------------------------------------------------------------- /icons/close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MoreFoxBeans/pixelart.koplugin/407e711f963a58c93482d4c69e8e6de12c98263d/icons/close.png -------------------------------------------------------------------------------- /icons/dither.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MoreFoxBeans/pixelart.koplugin/407e711f963a58c93482d4c69e8e6de12c98263d/icons/dither.png -------------------------------------------------------------------------------- /icons/eraser.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MoreFoxBeans/pixelart.koplugin/407e711f963a58c93482d4c69e8e6de12c98263d/icons/eraser.png -------------------------------------------------------------------------------- /icons/eyedropper.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MoreFoxBeans/pixelart.koplugin/407e711f963a58c93482d4c69e8e6de12c98263d/icons/eyedropper.png -------------------------------------------------------------------------------- /icons/fill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MoreFoxBeans/pixelart.koplugin/407e711f963a58c93482d4c69e8e6de12c98263d/icons/fill.png -------------------------------------------------------------------------------- /icons/fillall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MoreFoxBeans/pixelart.koplugin/407e711f963a58c93482d4c69e8e6de12c98263d/icons/fillall.png -------------------------------------------------------------------------------- /icons/filldiag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MoreFoxBeans/pixelart.koplugin/407e711f963a58c93482d4c69e8e6de12c98263d/icons/filldiag.png -------------------------------------------------------------------------------- /icons/grid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MoreFoxBeans/pixelart.koplugin/407e711f963a58c93482d4c69e8e6de12c98263d/icons/grid.png -------------------------------------------------------------------------------- /icons/line.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MoreFoxBeans/pixelart.koplugin/407e711f963a58c93482d4c69e8e6de12c98263d/icons/line.png -------------------------------------------------------------------------------- /icons/load.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MoreFoxBeans/pixelart.koplugin/407e711f963a58c93482d4c69e8e6de12c98263d/icons/load.png -------------------------------------------------------------------------------- /icons/menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MoreFoxBeans/pixelart.koplugin/407e711f963a58c93482d4c69e8e6de12c98263d/icons/menu.png -------------------------------------------------------------------------------- /icons/minus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MoreFoxBeans/pixelart.koplugin/407e711f963a58c93482d4c69e8e6de12c98263d/icons/minus.png -------------------------------------------------------------------------------- /icons/new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MoreFoxBeans/pixelart.koplugin/407e711f963a58c93482d4c69e8e6de12c98263d/icons/new.png -------------------------------------------------------------------------------- /icons/pan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MoreFoxBeans/pixelart.koplugin/407e711f963a58c93482d4c69e8e6de12c98263d/icons/pan.png -------------------------------------------------------------------------------- /icons/pencil.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MoreFoxBeans/pixelart.koplugin/407e711f963a58c93482d4c69e8e6de12c98263d/icons/pencil.png -------------------------------------------------------------------------------- /icons/plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MoreFoxBeans/pixelart.koplugin/407e711f963a58c93482d4c69e8e6de12c98263d/icons/plus.png -------------------------------------------------------------------------------- /icons/rectangle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MoreFoxBeans/pixelart.koplugin/407e711f963a58c93482d4c69e8e6de12c98263d/icons/rectangle.png -------------------------------------------------------------------------------- /icons/rectanglefill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MoreFoxBeans/pixelart.koplugin/407e711f963a58c93482d4c69e8e6de12c98263d/icons/rectanglefill.png -------------------------------------------------------------------------------- /icons/refresh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MoreFoxBeans/pixelart.koplugin/407e711f963a58c93482d4c69e8e6de12c98263d/icons/refresh.png -------------------------------------------------------------------------------- /icons/resize.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MoreFoxBeans/pixelart.koplugin/407e711f963a58c93482d4c69e8e6de12c98263d/icons/resize.png -------------------------------------------------------------------------------- /icons/save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MoreFoxBeans/pixelart.koplugin/407e711f963a58c93482d4c69e8e6de12c98263d/icons/save.png -------------------------------------------------------------------------------- /icons/view.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MoreFoxBeans/pixelart.koplugin/407e711f963a58c93482d4c69e8e6de12c98263d/icons/view.png -------------------------------------------------------------------------------- /item.lua: -------------------------------------------------------------------------------- 1 | local Blitbuffer = require("ffi/blitbuffer") 2 | local CenterContainer = require("ui/widget/container/centercontainer") 3 | local Device = require("device") 4 | local Font = require("ui/font") 5 | local FrameContainer = require("ui/widget/container/framecontainer") 6 | local Geom = require("ui/geometry") 7 | local GestureRange = require("ui/gesturerange") 8 | local ImageWidget = require("ui/widget/imagewidget") 9 | local InputContainer = require("ui/widget/container/inputcontainer") 10 | local Screen = Device.screen 11 | local TextWidget = require("ui/widget/textwidget") 12 | local UIManager = require("ui/uimanager") 13 | local Widget = require("ui/widget/widget") 14 | 15 | local Item = InputContainer:new{ 16 | text = nil, 17 | icon = nil, 18 | callback = function () end, 19 | dim = function () return false end, 20 | width = nil, 21 | height = nil, 22 | background = nil, 23 | size = nil, 24 | dark = nil, 25 | show_parent = nil, 26 | } 27 | 28 | function Item:init() 29 | self.dimen = Geom:new{ 30 | w = self.width, 31 | h = self.height, 32 | } 33 | 34 | self.ges_events = { 35 | TapButton = { 36 | GestureRange:new{ 37 | ges = "tap", 38 | range = function () return self.dimen end, 39 | }, 40 | }, 41 | } 42 | 43 | if self.icon then 44 | self.content = ImageWidget:new{ 45 | file = "plugins/pixelart.koplugin/icons/" .. (type(self.icon) == "function" and self.icon(self.show_parent) or self.icon) .. ".png", 46 | width = 72, 47 | height = 72, 48 | alpha = true, 49 | show_parent = self.show_parent, 50 | } 51 | else 52 | self.content = TextWidget:new{ 53 | text = self.text or "", 54 | face = Font:getFace("infofont", 24), 55 | show_parent = self.show_parent, 56 | } 57 | end 58 | 59 | self[1] = FrameContainer:new{ 60 | width = self.dimen.w, 61 | height = self.dimen.h, 62 | padding = 0, 63 | margin = 0, 64 | bordersize = 0, 65 | background = (self.background and type(self.background) ~= "function") and (self.dark and self.background:invert() or self.background) or Blitbuffer.COLOR_WHITE, 66 | show_parent = self.show_parent, 67 | CenterContainer:new{ 68 | dimen = Geom:new{ 69 | w = self.dimen.w, 70 | h = self.dimen.h, 71 | }, 72 | show_parent = self.show_parent, 73 | self.content, 74 | }, 75 | } 76 | end 77 | 78 | function Item:paintTo(bb, x, y) 79 | if type(self.background) == "function" then -- background needs updating 80 | self[1].background = self.background(self.show_parent) 81 | if self.dark then self[1].background = self[1].background:invert() end 82 | end 83 | 84 | if type(self.icon) == "function" and ("plugins/pixelart.koplugin/icons/" .. self.icon(self.show_parent) .. ".png") ~= self.content.file then -- icon needs updating 85 | self.content:free() 86 | self.content = ImageWidget:new{ 87 | file = "plugins/pixelart.koplugin/icons/" .. self.icon(self.show_parent) .. ".png", 88 | width = 72, 89 | height = 72, 90 | alpha = true, 91 | show_parent = self.show_parent, 92 | } 93 | self[1][1][1] = self.content 94 | end 95 | 96 | InputContainer.paintTo(self, bb, x, y) -- paint image/text 97 | 98 | if self.size then -- draw size circle 99 | bb:paintCircle(x + self.dimen.w / 2, y + self.dimen.h / 2, (type(self.size) == "function" and self.size(self.show_parent) or self.size) * 2, Blitbuffer.COLOR_BLACK) 100 | end 101 | 102 | if self.icon or self.size then -- lower contrast for more modern design 103 | bb:dimRect(x, y, self.dimen.w, self.dimen.h, 0.2) 104 | end 105 | 106 | if self[1].background ~= Blitbuffer.COLOR_WHITE then -- make bg have rounded edges 107 | bb:paintBorder(x, y, self.dimen.w, self.dimen.h, 12, Blitbuffer.COLOR_WHITE) 108 | bb:paintBorder(x + 4, y + 4, self.dimen.w - 8, self.dimen.h - 8, 8, Blitbuffer.COLOR_WHITE, 20) 109 | end 110 | 111 | if self.menu then -- menu arrow thingy! 112 | for i = 0, 16 do 113 | bb:paintRect(x + 16 - i + self.dimen.w - 16, y + i + self.dimen.h - 16, i, 1, Blitbuffer.Color8(0xFF * 0.2)) 114 | end 115 | end 116 | 117 | if self.dark then -- hidden dark mode 118 | bb:invertRect(x, y, self.dimen.w, self.dimen.h) 119 | end 120 | 121 | if self.dim(self.show_parent) then -- outline if selected 122 | bb:paintBorder(x + 8, y + 8, self.dimen.w - 16, self.dimen.h - 16, 4, Blitbuffer.Color8(self.dark and 0x55 or 0xBB), 16) 123 | end 124 | end 125 | 126 | function Item:onTapButton() 127 | self.callback(self.show_parent) 128 | 129 | UIManager:setDirty(self.show_parent, function () 130 | return "ui", self.show_parent.dimen 131 | end) 132 | 133 | return true 134 | end 135 | 136 | return Item -------------------------------------------------------------------------------- /main.lua: -------------------------------------------------------------------------------- 1 | local Device = require("device") 2 | 3 | if not Device:isTouchDevice() then 4 | return { disabled = true } 5 | end 6 | 7 | local Editor = require("editor") 8 | local UIManager = require("ui/uimanager") 9 | local WidgetContainer = require("ui/widget/container/widgetcontainer") 10 | 11 | local PixelArt = WidgetContainer:new{ 12 | name = "pixelart", 13 | is_doc_only = false, 14 | } 15 | 16 | function PixelArt:init() 17 | self.ui.menu:registerToMainMenu(self) 18 | end 19 | 20 | function PixelArt:addToMainMenu(menu_items) 21 | menu_items.pixelart = { 22 | text = "Pixel Art", 23 | sorting_hint = "more_tools", 24 | keep_menu_open = true, 25 | callback = function() self:onOpen() end, 26 | } 27 | end 28 | 29 | function PixelArt:onOpen() 30 | UIManager:show(Editor:new{}) 31 | end 32 | 33 | return PixelArt -------------------------------------------------------------------------------- /rect.lua: -------------------------------------------------------------------------------- 1 | local Blitbuffer = require("ffi/blitbuffer") 2 | local FrameContainer = require("ui/widget/container/framecontainer") 3 | local Geom = require("ui/geometry") 4 | local Widget = require("ui/widget/widget") 5 | 6 | -- reserve 2d space w/ bg 7 | local Rect = FrameContainer:new{ 8 | width = 0, 9 | height = 0, 10 | background = Blitbuffer.Color8(0xFF), 11 | bordersize = 0, 12 | padding = 0, 13 | Widget:new{ dimen = Geom:new{ w = 0, h = 0 } }, 14 | } 15 | 16 | function Rect:init() 17 | self[1].dimen.w = self.width 18 | self[1].dimen.h = self.height 19 | end 20 | 21 | return Rect -------------------------------------------------------------------------------- /screenshots/gridsize.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MoreFoxBeans/pixelart.koplugin/407e711f963a58c93482d4c69e8e6de12c98263d/screenshots/gridsize.png -------------------------------------------------------------------------------- /screenshots/old.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MoreFoxBeans/pixelart.koplugin/407e711f963a58c93482d4c69e8e6de12c98263d/screenshots/old.png -------------------------------------------------------------------------------- /screenshots/space.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MoreFoxBeans/pixelart.koplugin/407e711f963a58c93482d4c69e8e6de12c98263d/screenshots/space.png -------------------------------------------------------------------------------- /submenu.lua: -------------------------------------------------------------------------------- 1 | local Blitbuffer = require("ffi/blitbuffer") 2 | local HorizontalGroup = require("ui/widget/horizontalgroup") 3 | 4 | local SubMenu = HorizontalGroup:new{ 5 | dark = nil, 6 | show_parent = nil, 7 | } 8 | 9 | -- Paint a single rounded corner (partly stolen from Blitbuffer paintRoundedCorner code) 10 | function paintCorner(image, off_x, off_y, w, h, bw, r, c, i) 11 | if 2 * r > h or 2 * r > w or r == 0 then return end 12 | 13 | r = math.min(r, h, w) 14 | bw = math.min(bw, r) 15 | 16 | local x = 0 17 | local y = r 18 | local delta = 5/4 - r 19 | 20 | local r2 = r - bw 21 | local x2 = 0 22 | local y2 = r2 23 | local delta2 = 5/4 - r 24 | 25 | while x < y do 26 | x = x + 1 27 | 28 | if delta > 0 then 29 | y = y - 1 30 | delta = delta + 2 * x - 2 * y + 2 31 | else 32 | delta = delta + 2 * x + 1 33 | end 34 | 35 | if x2 > y2 then 36 | y2 = y2 + 1 37 | x2 = x2 + 1 38 | else 39 | x2 = x2 + 1 40 | if delta2 > 0 then 41 | y2 = y2 - 1 42 | delta2 = delta2 + 2 * x2 - 2 * y2 + 2 43 | else 44 | delta2 = delta2 + 2 * x2 + 1 45 | end 46 | end 47 | 48 | for tmp_y = y, y2 + 1, -1 do 49 | if i == 4 then 50 | image:setPixelClamped((w - r) + off_x + x - 1, (h - r) + off_y + tmp_y - 1, c) 51 | image:setPixelClamped((w - r) + off_x + tmp_y - 1, (h - r) + off_y + x - 1, c) 52 | end 53 | 54 | if i == 2 then 55 | image:setPixelClamped((w - r) + off_x + tmp_y - 1, r + off_y - x, c) 56 | image:setPixelClamped((w - r) + off_x + x - 1, r + off_y - tmp_y, c) 57 | end 58 | 59 | if i == 1 then 60 | image:setPixelClamped(r + off_x - x, r + off_y - tmp_y, c) 61 | image:setPixelClamped(r + off_x - tmp_y, r + off_y - x, c) 62 | end 63 | 64 | if i == 3 then 65 | image:setPixelClamped(r + off_x - tmp_y, (h - r) + off_y + x - 1, c) 66 | image:setPixelClamped(r + off_x - x, (h - r) + off_y + tmp_y - 1, c) 67 | end 68 | end 69 | end 70 | end 71 | 72 | function SubMenu:paintTo(bb, x, y) 73 | HorizontalGroup.paintTo(self, bb, x, y) 74 | 75 | if self:getSize().w ~= 0 then 76 | local b = self.dark and Blitbuffer.COLOR_BLACK or Blitbuffer.COLOR_WHITE -- background 77 | local o = self.dark and Blitbuffer.Color8(0x55) or Blitbuffer.Color8(0xBB) -- outline 78 | 79 | bb:paintRect(x, y - 16, 4, self:getSize().h + 32, b) -- cover up sidebar outline 80 | 81 | bb:paintRect(x + 16, y - 4, self:getSize().w - 28, 4, o) -- top border 82 | bb:paintRect(x + 16, y + self:getSize().h, self:getSize().w - 28, 4, o) -- bottom border 83 | 84 | -- top inside corner 85 | paintCorner(bb, x, y - 32 + 6, 32, 32, 4, 16, b, 3) 86 | paintCorner(bb, x, y - 32 + 3, 32, 32, 4, 16, b, 3) 87 | paintCorner(bb, x, y - 32, 32, 32, 4, 16, o, 3) 88 | 89 | -- bottom insie corner 90 | paintCorner(bb, x, y + self:getSize().h - 6, 32, 32, 4, 16, b, 1) 91 | paintCorner(bb, x, y + self:getSize().h - 3, 32, 32, 4, 16, b, 1) 92 | paintCorner(bb, x, y + self:getSize().h, 32, 32, 4, 16, o, 1) 93 | 94 | -- right outside corners 95 | paintCorner(bb, x, y - 4, self:getSize().w + 4, self:getSize().h + 8, 4, 16, o, 2) 96 | bb:paintRect(x + self:getSize().w, y + 12, 4, self:getSize().h - 24, o) 97 | paintCorner(bb, x, y - 4, self:getSize().w + 4, self:getSize().h + 8, 4, 16, o, 4) 98 | end 99 | end 100 | 101 | return SubMenu --------------------------------------------------------------------------------