Compare commits
34 Commits
ce28f0d350
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
90eec8d301 | ||
|
|
e9d1e5c47e | ||
| 31b2196976 | |||
|
|
bd586cda6a | ||
|
|
ae58a60be9 | ||
|
|
43b6d284dd | ||
| 1fb4b1c1e1 | |||
| af6b0c4d30 | |||
|
|
e054fc4fe7 | ||
|
|
e7dc799f54 | ||
|
|
5e883e2d27 | ||
|
|
09b84a2aa8 | ||
|
|
7bc94d3a96 | ||
|
|
f96d6066ee | ||
| 237bb02a8c | |||
|
|
562cbc12da | ||
|
|
ed9aca01e4 | ||
|
|
6c8ca19fbf | ||
| 00031d145e | |||
| b0930c9e02 | |||
| 858a1f2c1a | |||
| 22b6700768 | |||
| 143a33558d | |||
|
|
2d6746c99c | ||
|
|
64dd2d6e40 | ||
|
|
1d168f7be4 | ||
|
|
232b5c8f90 | ||
|
|
61f9f1eed0 | ||
|
|
2bdcbfae1f | ||
|
|
9b4248981e | ||
| 5890a2aaa7 | |||
|
|
ed49bc5f14 | ||
|
|
f593d762fb | ||
| 392d49a5b7 |
661
LICENSE
Normal file
661
LICENSE
Normal file
@@ -0,0 +1,661 @@
|
||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
8
icons/hicolor/scalable/actions/tool-brush-symbolic.svg
Normal file
8
icons/hicolor/scalable/actions/tool-brush-symbolic.svg
Normal file
@@ -0,0 +1,8 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 22 22">
|
||||
<defs>
|
||||
<style id="current-color-scheme" type="text/css">
|
||||
.ColorScheme-Text { color:#444444; } .ColorScheme-Highlight { color:#4285f4; } .ColorScheme-NeutralText { color:#ff9800; } .ColorScheme-PositiveText { color:#4caf50; } .ColorScheme-NegativeText { color:#f44336; }
|
||||
</style>
|
||||
</defs>
|
||||
<path style="fill:currentColor" class="ColorScheme-Text" d="M 14.574219 1.0058594 C 13.520146 0.87298937 10.770478 2.75775 8.0605469 5.46875 C 6.8520776 6.67795 5.8032796 7.8729 5 9 C 5.9414561 9.29995 6.7002076 10.0582 7 11 C 8.1266713 10.19649 9.3243336 9.1522594 10.533203 7.9433594 C 13.607725 4.8675594 15.546263 1.8205187 14.863281 1.1367188 C 14.793083 1.0660188 14.697306 1.0216494 14.574219 1.0058594 z M 4.5 10.330078 L 4.5 10.332031 C 1.0001889 11.270271 3.6248533 13.4865 1 15 C 4.4998111 15 6.25 13.248178 6.25 12.080078 C 6.25 11.497798 6.3093545 10.426978 4.5 10.330078 z" transform="translate(3 3)"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1005 B |
10
icons/hicolor/scalable/actions/tool-pencil-symbolic.svg
Normal file
10
icons/hicolor/scalable/actions/tool-pencil-symbolic.svg
Normal file
@@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" version="1.1">
|
||||
<defs>
|
||||
<style id="current-color-scheme" type="text/css">
|
||||
.ColorScheme-Text { color:#444444; } .ColorScheme-Highlight { color:#4285f4; } .ColorScheme-NeutralText { color:#ff9800; } .ColorScheme-PositiveText { color:#4caf50; } .ColorScheme-NegativeText { color:#f44336; }
|
||||
</style>
|
||||
</defs>
|
||||
<g transform="translate(3,3)">
|
||||
<path style="fill:currentColor" class="ColorScheme-Text" d="M 12.778,1.2222 C 12.778,1.2222 12.278,0.72224 11.778,1.2222 L 10,3 13,6 14.778,4.2222 C 15.278,3.7222 14.778,3.2222 14.778,3.2222 Z M 9,4 1,12 V 15 H 4 L 12,7 Z"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 646 B |
9
icons/hicolor/scalable/actions/tool-polygon-symbolic.svg
Normal file
9
icons/hicolor/scalable/actions/tool-polygon-symbolic.svg
Normal file
@@ -0,0 +1,9 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" version="1.1">
|
||||
<defs>
|
||||
<style id="current-color-scheme" type="text/css">
|
||||
.ColorScheme-Text { color:#444444; } .ColorScheme-Highlight { color:#4285f4; } .ColorScheme-NeutralText { color:#ff9800; } .ColorScheme-PositiveText { color:#4caf50; } .ColorScheme-NegativeText { color:#f44336; }
|
||||
</style>
|
||||
</defs>
|
||||
<path style="fill:currentColor" class="ColorScheme-Text" d="M 16.98,6.5 5.9551,7.502 5.5,8 v 10 l 0.8203,0.385 5.7481,-4.7912 5.7086,2.8532 0.719,-0.502 -1,-8.9997 z m -0.423,1.043 0.845,7.6 -5.1793,-2.5903 -0.543,0.0625 L 6.5,16.932 V 8.457 Z"/>
|
||||
<path style="fill:currentColor" class="ColorScheme-Text" d="m 14,13 a 2,2 0 0 1 -2,2 2,2 0 0 1 -2,-2 2,2 0 0 1 2,-2 2,2 0 0 1 2,2 z M 8,8 A 2,2 0 0 1 6,10 2,2 0 0 1 4,8 2,2 0 0 1 6,6 2,2 0 0 1 8,8 Z m 0,10 a 2,2 0 0 1 -2,2 2,2 0 0 1 -2,-2 2,2 0 0 1 2,-2 2,2 0 0 1 2,2 z m 12,-2 a 2,2 0 0 1 -2,2 2,2 0 0 1 -2,-2 2,2 0 0 1 2,-2 2,2 0 0 1 2,2 z M 19,7 a 2,2 0 0 1 -2,2 2,2 0 0 1 -2,-2 2,2 0 0 1 2,-2 2,2 0 0 1 2,2 z"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.0 KiB |
8
icons/hicolor/scalable/actions/tool-select-symbolic.svg
Normal file
8
icons/hicolor/scalable/actions/tool-select-symbolic.svg
Normal file
@@ -0,0 +1,8 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 22 22">
|
||||
<defs>
|
||||
<style id="current-color-scheme" type="text/css">
|
||||
.ColorScheme-Text { color:#444444; } .ColorScheme-Highlight { color:#4285f4; } .ColorScheme-NeutralText { color:#ff9800; } .ColorScheme-PositiveText { color:#4caf50; } .ColorScheme-NegativeText { color:#f44336; }
|
||||
</style>
|
||||
</defs>
|
||||
<path style="fill:currentColor" class="ColorScheme-Text" d="M 3.9960938 1 L 4.0117188 12.535156 L 6.3339844 10.255859 L 6.7714844 9.8242188 L 7.0097656 10.404297 L 8.9023438 15 L 10.363281 14.328125 L 8.3808594 9.7792969 L 8.1347656 9.2128906 L 8.7285156 9.15625 L 11.996094 8.8457031 L 3.9960938 1 z" transform="translate(3 3)"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 719 B |
12
meson.build
12
meson.build
@@ -10,14 +10,22 @@ project(
|
||||
],
|
||||
)
|
||||
|
||||
gtk = dependency('gtk4', required: true)
|
||||
epoxy = dependency('epoxy')
|
||||
c_args = meson.get_compiler('c').get_supported_arguments([
|
||||
'-Wno-unused-variable',
|
||||
'-Wno-unused-parameter',
|
||||
'-Wno-pedantic'
|
||||
])
|
||||
add_project_arguments(c_args, language: 'c')
|
||||
|
||||
gtk = dependency('gtk4', required: true, include_type: 'system')
|
||||
epoxy = dependency('epoxy', include_type: 'system')
|
||||
|
||||
src = files(
|
||||
'src/main.c',
|
||||
'src/core/matrix.c',
|
||||
'src/core/primitives.c',
|
||||
'src/core/raster.c',
|
||||
'src/core/modifier.c',
|
||||
'src/ui/uicontroller.c',
|
||||
'src/ui/vektorcanvas.c',
|
||||
'src/ui/widgets/colorwheel.c',
|
||||
|
||||
40
shaders/selection.frag.glsl
Normal file
40
shaders/selection.frag.glsl
Normal file
@@ -0,0 +1,40 @@
|
||||
#version 320 es
|
||||
precision mediump float;
|
||||
|
||||
in vec2 vPos;
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform float uTime;
|
||||
uniform float uScale;
|
||||
uniform vec4 uColor1;
|
||||
uniform vec4 uColor2;
|
||||
uniform vec2 uMin;
|
||||
uniform vec2 uMax;
|
||||
|
||||
void main()
|
||||
{
|
||||
float borderWidth = 0.008 / uScale;
|
||||
|
||||
|
||||
float distX = min(vPos.x - uMin.x, uMax.x - vPos.x);
|
||||
float distY = min(vPos.y - uMin.y, uMax.y - vPos.y);
|
||||
float dist = min(distX, distY);
|
||||
|
||||
if (dist > borderWidth)
|
||||
discard;
|
||||
|
||||
float dash_length = 0.025;
|
||||
float gap_length = 0.015;
|
||||
float total = dash_length + gap_length;
|
||||
|
||||
float speed = 0.3;
|
||||
|
||||
float distance_along = (vPos.x + vPos.y) * 20.0;
|
||||
|
||||
float t = mod( distance_along * total + uTime * speed, total);
|
||||
|
||||
if (t < dash_length)
|
||||
FragColor = uColor2;
|
||||
else
|
||||
FragColor = uColor1;
|
||||
}
|
||||
@@ -7,9 +7,11 @@ layout (location = 1) in vec4 aColor;
|
||||
uniform mat4 uProjection;
|
||||
|
||||
out vec4 vColor;
|
||||
out vec2 vPos;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = uProjection * vec4(aPos, 0.0, 1.0);
|
||||
vPos = aPos;
|
||||
vColor = aColor;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
#include "src/core/matrix.h"
|
||||
#include "src/core/modifier.h"
|
||||
#include "src/ui/uicontroller.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
#include "./applicationstate.h"
|
||||
#include "glib.h"
|
||||
#include "gtk/gtk.h"
|
||||
#include "gtk/gtkrevealer.h"
|
||||
#include "src/core/primitives.h"
|
||||
#include "src/core/raster.h"
|
||||
|
||||
#include "src/ui/vektorcanvas.h"
|
||||
#include "src/ui/widgets/colorwheel.h"
|
||||
#include "src/util/color.h"
|
||||
@@ -19,10 +24,14 @@ static void appstate_set_tool(GtkButton* button, gpointer user_data) {
|
||||
data->state->selectedTool = data->tool;
|
||||
|
||||
// setting tool makes the sub-tools menu to close
|
||||
gtk_revealer_set_reveal_child(data->revealer, FALSE);
|
||||
// (ADD NEW REVEALERS HERE)
|
||||
gtk_revealer_set_reveal_child(
|
||||
data->state->widgetState->workspaceRevealerShapes, FALSE);
|
||||
|
||||
// setting tool also resets selected shape
|
||||
data->state->selectedShape = NULL;
|
||||
// NOTE: isn't needed anymore, as you would
|
||||
// want to be able to select & edit existing shapes
|
||||
// data->state->selectedShape = NULL;
|
||||
}
|
||||
|
||||
static void appstate_reveal_subtools(GtkButton* button, gpointer user_data) {
|
||||
@@ -31,16 +40,43 @@ static void appstate_reveal_subtools(GtkButton* button, gpointer user_data) {
|
||||
gtk_revealer_set_reveal_child(revealer, !visible);
|
||||
}
|
||||
|
||||
static void appstate_on_color_change(VektorColorWheel* wheel, gpointer user_data) {
|
||||
static void appstate_on_color_change(VektorColorWheel* wheel,
|
||||
gpointer user_data) {
|
||||
VektorColor c = vektor_color_wheel_get_color(wheel);
|
||||
VektorAppState* appstate = (VektorAppState*)user_data;
|
||||
appstate->currentColor = c;
|
||||
|
||||
if (appstate->selectedShape != NULL) {
|
||||
appstate->selectedShape->style.stroke_color = c;
|
||||
appstate->selectedShape->base->style.stroke_color = c;
|
||||
}
|
||||
|
||||
gtk_gl_area_queue_render(GTK_GL_AREA(appstate->widgetState->workspaceCanvas));
|
||||
// set entry fields under the color selector
|
||||
char *str_r, *str_g, *str_b;
|
||||
str_r = g_strdup_printf("%d", c.r);
|
||||
str_g = g_strdup_printf("%d", c.g);
|
||||
str_b = g_strdup_printf("%d", c.b);
|
||||
gtk_editable_set_text(GTK_EDITABLE(appstate->widgetState->sidepanelEntryR),
|
||||
str_r);
|
||||
gtk_editable_set_text(GTK_EDITABLE(appstate->widgetState->sidepanelEntryG),
|
||||
str_g);
|
||||
gtk_editable_set_text(GTK_EDITABLE(appstate->widgetState->sidepanelEntryB),
|
||||
str_b);
|
||||
|
||||
vektor_canvas_geometry_changed(appstate->renderInfo);
|
||||
}
|
||||
|
||||
static void appstate_on_entry_update(GtkEntry* entry, gpointer user_data) {
|
||||
VektorWidgetState* widgetState = (VektorWidgetState*)user_data;
|
||||
unsigned char r = (unsigned char)atoi(
|
||||
gtk_editable_get_text(GTK_EDITABLE(widgetState->sidepanelEntryR)));
|
||||
unsigned char g = (unsigned char)atoi(
|
||||
gtk_editable_get_text(GTK_EDITABLE(widgetState->sidepanelEntryG)));
|
||||
unsigned char b = (unsigned char)atoi(
|
||||
gtk_editable_get_text(GTK_EDITABLE(widgetState->sidepanelEntryB)));
|
||||
|
||||
vektor_color_wheel_set_color(
|
||||
VEKTOR_COLOR_WHEEL(widgetState->workspaceColorPicker),
|
||||
(VektorColor){.r = r, .g = g, .b = b});
|
||||
}
|
||||
|
||||
static void canvas_onclick(GtkGestureClick* gesture, int n_press, double x,
|
||||
@@ -54,19 +90,22 @@ static void canvas_onclick(GtkGestureClick* gesture, int n_press, double x,
|
||||
int widget_w = gtk_widget_get_width(widget);
|
||||
int widget_h = gtk_widget_get_height(widget);
|
||||
|
||||
int canvas_w = state->canvas->width;
|
||||
int canvas_h = state->canvas->height;
|
||||
|
||||
V2 normalized_coords =
|
||||
(V2){(2 * (x / widget_w)) - 1, 1 - (2 * (y / widget_h))};
|
||||
|
||||
vektor_appstate_canvas_click(state, normalized_coords.x,
|
||||
normalized_coords.y);
|
||||
gtk_gl_area_queue_render(GTK_GL_AREA(widget));
|
||||
|
||||
// technically there are cases when a click would not result in change of
|
||||
// the geometry but this is more concise then writing it inside that
|
||||
// function a bunch of times and burder future click dispatches with
|
||||
// handling this signal
|
||||
vektor_canvas_geometry_changed(state->renderInfo);
|
||||
}
|
||||
|
||||
void vektor_appstate_canvas_click(VektorAppState* state, double x, double y) {
|
||||
V2 pos = (V2){x, y};
|
||||
V2 pos =
|
||||
m33_transform(m33_inverse(state->renderInfo->canvasMat), (V2){x, y});
|
||||
|
||||
begin_click_dispatch:
|
||||
if (state->selectedTool == VektorLineTool) {
|
||||
@@ -76,34 +115,210 @@ begin_click_dispatch:
|
||||
VektorPolyline* line = vektor_polyline_new();
|
||||
VektorPrimitive linePrimitive =
|
||||
(VektorPrimitive){.kind = VEKTOR_POLYLINE, .polyline = line};
|
||||
VektorStyle style =
|
||||
(VektorStyle){.stroke_color = state->currentColor,
|
||||
.stroke_width = 0.01};
|
||||
VektorShape shape = (VektorShape){
|
||||
.primitive = linePrimitive, .z_index = 0, .style = style};
|
||||
vektor_shapebuffer_add_shape(state->shapeBuffer, vektor_shape_new(linePrimitive, style, 0));
|
||||
VektorStyle style = (VektorStyle){
|
||||
.stroke_color = state->currentColor, .stroke_width = 0.01};
|
||||
|
||||
vektor_shapenodebuf_add(state->shapeBuffer,
|
||||
vektor_shapenode_new(vektor_shape_new(
|
||||
linePrimitive, style, 0)));
|
||||
|
||||
state->selectedShape =
|
||||
&(state->shapeBuffer->shapes[state->shapeBuffer->count - 1]);
|
||||
&(state->shapeBuffer->nodes[state->shapeBuffer->count - 1]);
|
||||
|
||||
} else if (state->selectedShape->primitive.kind != VEKTOR_POLYLINE) {
|
||||
} else if (state->selectedShape->base->primitive.kind !=
|
||||
VEKTOR_POLYLINE) {
|
||||
// selecting a tool resets the selection, so this condition
|
||||
// should not happen
|
||||
g_warning("Invalid selected primitive; polyline expected");
|
||||
state->selectedShape = NULL;
|
||||
vektor_appstate_deselect_shape(state);
|
||||
goto begin_click_dispatch; // retry
|
||||
}
|
||||
|
||||
vektor_polyline_add_point(state->selectedShape->primitive.polyline,
|
||||
vektor_polyline_add_point(state->selectedShape->base->primitive.polyline,
|
||||
pos);
|
||||
state->selectedShape->base->bbox =
|
||||
vektor_primitive_get_bbox(state->selectedShape->base->primitive);
|
||||
|
||||
vektor_shapes_update_bbox(state->shapeBuffer);
|
||||
// polyline's handle count is not fixed, so we have to add them manually
|
||||
vektor_shape_add_handle(state->selectedShape->base, pos);
|
||||
|
||||
} else if (state->selectedTool == VektorPolygonTool) {
|
||||
// create new polygon shape if none is selected
|
||||
if (state->selectedShape == NULL) {
|
||||
|
||||
for (size_t i = 0; i < state->shapeBuffer->count; i++) {
|
||||
g_print("<%f,%f>-<%f,%f>\n", state->shapeBuffer->shapes[i].bbox.min.x, state->shapeBuffer->shapes[i].bbox.min.y, state->shapeBuffer->shapes[i].bbox.max.x, state->shapeBuffer->shapes[i].bbox.max.y);
|
||||
VektorPolygon* polygon = vektor_polygon_new();
|
||||
VektorPrimitive polygonPrimitive =
|
||||
(VektorPrimitive){.kind = VEKTOR_POLYGON, .polygon = polygon};
|
||||
VektorStyle style = (VektorStyle){
|
||||
.stroke_color = state->currentColor, .stroke_width = 0.01};
|
||||
vektor_shapenodebuf_add(state->shapeBuffer,
|
||||
vektor_shapenode_new(vektor_shape_new(
|
||||
polygonPrimitive, style, 0)));
|
||||
|
||||
state->selectedShape =
|
||||
&(state->shapeBuffer->nodes[state->shapeBuffer->count - 1]);
|
||||
|
||||
} else if (state->selectedShape->base->primitive.kind !=
|
||||
VEKTOR_POLYGON) {
|
||||
g_warning("Invalid selected primitive; polygon expected");
|
||||
vektor_appstate_deselect_shape(state);
|
||||
goto begin_click_dispatch; // retry
|
||||
}
|
||||
|
||||
vektor_polygon_add_point(state->selectedShape->base->primitive.polygon,
|
||||
pos);
|
||||
state->selectedShape->base->bbox =
|
||||
vektor_primitive_get_bbox(state->selectedShape->base->primitive);
|
||||
|
||||
// polygon's handle count is not fixed, so we have to add them manually
|
||||
vektor_shape_add_handle(state->selectedShape->base, pos);
|
||||
|
||||
} else if (state->selectedTool == VektorCircleTool) {
|
||||
|
||||
VektorCircle* circle = vektor_circle_new();
|
||||
VektorPrimitive circlePrimitive =
|
||||
(VektorPrimitive){.kind = VEKTOR_CIRCLE, .circle = *circle};
|
||||
VektorStyle style = (VektorStyle){.stroke_color = state->currentColor,
|
||||
.stroke_width = 0.01};
|
||||
vektor_shapenodebuf_add(
|
||||
state->shapeBuffer,
|
||||
vektor_shapenode_new(vektor_shape_new(circlePrimitive, style, 0)));
|
||||
|
||||
state->selectedShape =
|
||||
&(state->shapeBuffer->nodes[state->shapeBuffer->count - 1]);
|
||||
|
||||
vektor_circle_free(circle);
|
||||
|
||||
vektor_circle_set_center(&state->selectedShape->base->primitive.circle,
|
||||
pos);
|
||||
vektor_circle_set_radius(&state->selectedShape->base->primitive.circle,
|
||||
0.1f);
|
||||
|
||||
state->selectedShape->base->bbox =
|
||||
vektor_primitive_get_bbox(state->selectedShape->base->primitive);
|
||||
|
||||
vektor_circle_create_handles(
|
||||
&state->selectedShape->base->primitive.circle,
|
||||
&state->selectedShape->base->handles,
|
||||
&state->selectedShape->base->handleCount);
|
||||
} else if (state->selectedTool == VektorRectangleTool) {
|
||||
|
||||
VektorRectangle* rect = vektor_rectangle_new();
|
||||
VektorPrimitive rectPrimitive =
|
||||
(VektorPrimitive){.kind = VEKTOR_RECTANGLE, .rectangle = *rect};
|
||||
VektorStyle style = (VektorStyle){.stroke_color = state->currentColor,
|
||||
.stroke_width = 0.01};
|
||||
vektor_shapenodebuf_add(
|
||||
state->shapeBuffer,
|
||||
vektor_shapenode_new(vektor_shape_new(rectPrimitive, style, 0)));
|
||||
|
||||
state->selectedShape =
|
||||
&(state->shapeBuffer->nodes[state->shapeBuffer->count - 1]);
|
||||
|
||||
vektor_rectangle_free(rect);
|
||||
|
||||
vektor_rectangle_set_start(
|
||||
&state->selectedShape->base->primitive.rectangle, pos);
|
||||
vektor_rectangle_set_end(
|
||||
&state->selectedShape->base->primitive.rectangle,
|
||||
vec2_add(pos, (V2){0.1f, 0.1f}));
|
||||
vektor_rectangle_create_handles(
|
||||
&state->selectedShape->base->primitive.rectangle,
|
||||
&state->selectedShape->base->handles,
|
||||
&state->selectedShape->base->handleCount);
|
||||
|
||||
state->selectedShape->base->bbox =
|
||||
vektor_primitive_get_bbox(state->selectedShape->base->primitive);
|
||||
|
||||
} else if (state->selectedTool == VektorSelectionTool) {
|
||||
for (size_t i = 0; i < state->shapeBuffer->count; i++) {
|
||||
VektorBBox bbox = vektor_primitive_get_bbox(
|
||||
state->shapeBuffer->nodes[i].base->primitive);
|
||||
|
||||
// expand the bbox a little so its not painful to
|
||||
// try to grab handles located on the border of said bbox
|
||||
bbox = vektor_bbox_expand(bbox, 0.02);
|
||||
|
||||
if (vektor_bbox_isinside(bbox, pos)) {
|
||||
state->selectedShape = &(state->shapeBuffer->nodes[i]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// was clicked outside any shapes - reset selection
|
||||
vektor_appstate_deselect_shape(state);
|
||||
}
|
||||
}
|
||||
|
||||
void vektor_appstate_canvas_drag_begin(GtkGestureDrag* gesture, gdouble x,
|
||||
gdouble y, gpointer user_data) {
|
||||
GtkWidget* widget =
|
||||
gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(gesture));
|
||||
|
||||
VektorAppState* state = (VektorAppState*)user_data;
|
||||
|
||||
int widget_w = gtk_widget_get_width(widget);
|
||||
int widget_h = gtk_widget_get_height(widget);
|
||||
|
||||
V2 position = (V2){(2 * (x / widget_w)) - 1, 1 - (2 * (y / widget_h))};
|
||||
position = m33_transform(m33_inverse(state->renderInfo->canvasMat),
|
||||
(V2){position.x, position.y});
|
||||
|
||||
if (state->selectedShape != NULL) {
|
||||
VektorShapeNode* selectedShape = state->selectedShape;
|
||||
|
||||
// get selected shape's handles and check
|
||||
// if we click any of them
|
||||
for (size_t i = 0; i < selectedShape->base->handleCount; i++) {
|
||||
VektorBBox bbox =
|
||||
vektor_shape_get_handle_bbox(selectedShape->base->handles[i]);
|
||||
if (vektor_bbox_isinside(bbox, position)) {
|
||||
// clicked inside handle
|
||||
state->heldHandleIndex = i;
|
||||
vektor_canvas_geometry_changed(state->renderInfo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void vektor_appstate_canvas_drag_update(GtkGestureDrag* gesture, gdouble x,
|
||||
gdouble y, gpointer user_data) {
|
||||
|
||||
// ---- setup normalized coordinates (boilerplate) ----
|
||||
gdouble start_x, start_y;
|
||||
gtk_gesture_drag_get_start_point(gesture, &start_x, &start_y);
|
||||
|
||||
GtkWidget* widget =
|
||||
gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(gesture));
|
||||
|
||||
VektorAppState* state = (VektorAppState*)user_data;
|
||||
|
||||
int widget_w = gtk_widget_get_width(widget);
|
||||
int widget_h = gtk_widget_get_height(widget);
|
||||
|
||||
V2 position = (V2){(2 * ((x + start_x) / widget_w)) - 1,
|
||||
1 - (2 * ((y + start_y) / widget_h))};
|
||||
position = m33_transform(m33_inverse(state->renderInfo->canvasMat),
|
||||
(V2){position.x, position.y});
|
||||
|
||||
// drag handle if selected
|
||||
if (state->selectedShape != NULL && state->heldHandleIndex != -1) {
|
||||
state->selectedShape->base->handles[state->heldHandleIndex] = position;
|
||||
vektor_shape_handles_updated(state->selectedShape->base,
|
||||
&state->heldHandleIndex);
|
||||
vektor_canvas_geometry_changed(state->renderInfo);
|
||||
}
|
||||
}
|
||||
|
||||
void vektor_appstate_canvas_drag_end(GtkGestureDrag* gesture, gdouble x,
|
||||
gdouble y, gpointer user_data) {
|
||||
|
||||
VektorAppState* state = (VektorAppState*)user_data;
|
||||
|
||||
// if we were dragging a handle
|
||||
if (state->selectedShape != NULL && state->heldHandleIndex != -1) {
|
||||
state->heldHandleIndex = -1; // ...then remove handle drag flag
|
||||
vektor_canvas_geometry_changed(state->renderInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,22 +328,63 @@ void vektor_appstate_new(VektorWidgetState* wstate, VektorAppState* stateOut) {
|
||||
data_linetool->tool = VektorLineTool;
|
||||
data_linetool->revealer = wstate->workspaceRevealerShapes;
|
||||
|
||||
button_tool_set_data* data_polygontool =
|
||||
malloc(sizeof(button_tool_set_data));
|
||||
data_polygontool->state = stateOut;
|
||||
data_polygontool->tool = VektorPolygonTool;
|
||||
data_polygontool->revealer = wstate->workspaceRevealerShapes;
|
||||
|
||||
button_tool_set_data* data_rectangletool =
|
||||
malloc(sizeof(button_tool_set_data));
|
||||
data_rectangletool->state = stateOut;
|
||||
data_rectangletool->tool = VektorRectangleTool;
|
||||
data_rectangletool->revealer = wstate->workspaceRevealerShapes;
|
||||
|
||||
button_tool_set_data* data_selecttool =
|
||||
malloc(sizeof(button_tool_set_data));
|
||||
data_selecttool->state = stateOut;
|
||||
data_selecttool->tool = VektorSelectionTool;
|
||||
|
||||
button_tool_set_data* data_circletool =
|
||||
malloc(sizeof(button_tool_set_data));
|
||||
data_circletool->state = stateOut;
|
||||
data_circletool->tool = VektorCircleTool;
|
||||
data_circletool->revealer = wstate->workspaceRevealerShapes;
|
||||
|
||||
// populate appstate
|
||||
stateOut->shapeBuffer = malloc(sizeof(VektorShapeBuffer));
|
||||
*stateOut->shapeBuffer = (VektorShapeBuffer){0};
|
||||
stateOut->startupTime = g_get_monotonic_time();
|
||||
stateOut->shapeBuffer = malloc(sizeof(VektorShapeNodeBuffer));
|
||||
*stateOut->shapeBuffer = (VektorShapeNodeBuffer){0};
|
||||
stateOut->canvas = malloc(sizeof(VektorCanvas));
|
||||
stateOut->widgetState = wstate;
|
||||
stateOut->currentColor = vektor_color_blank;
|
||||
stateOut->currentColor = vektor_color_solid(0, 0, 0);
|
||||
stateOut->selectedShape = NULL;
|
||||
vektor_canvas_init(wstate, stateOut->canvas, stateOut->shapeBuffer);
|
||||
stateOut->heldHandleIndex = -1;
|
||||
|
||||
VektorCanvasRenderInfo* renderInfo = malloc(sizeof(VektorCanvasRenderInfo));
|
||||
renderInfo->zoom = 1;
|
||||
renderInfo->panX = 0;
|
||||
renderInfo->panY = 0;
|
||||
renderInfo->rotation = 0;
|
||||
m33_to_gl4(m33_identity(), renderInfo->canvasTransform);
|
||||
renderInfo->selectedShape = &(stateOut->selectedShape);
|
||||
renderInfo->shapes = stateOut->shapeBuffer;
|
||||
renderInfo->startupTime = stateOut->startupTime;
|
||||
renderInfo->canvasMat = m33_identity();
|
||||
vektor_canvas_init(wstate, stateOut->canvas, renderInfo);
|
||||
stateOut->renderInfo = renderInfo;
|
||||
|
||||
// link all the buttons
|
||||
g_signal_connect(G_OBJECT(wstate->workspaceButtonLinetool), "clicked",
|
||||
G_CALLBACK(appstate_set_tool), data_linetool);
|
||||
g_signal_connect(G_OBJECT(wstate->workspaceButtonRecttool), "clicked",
|
||||
G_CALLBACK(appstate_set_tool), data_linetool);
|
||||
g_signal_connect(G_OBJECT(wstate->workspaceButtonCircletool), "clicked",
|
||||
g_signal_connect(G_OBJECT(wstate->workspaceButtonLineTool), "clicked",
|
||||
G_CALLBACK(appstate_set_tool), data_linetool);
|
||||
g_signal_connect(G_OBJECT(wstate->workspaceButtonRectTool), "clicked",
|
||||
G_CALLBACK(appstate_set_tool), data_rectangletool);
|
||||
g_signal_connect(G_OBJECT(wstate->workspaceButtonCircleTool), "clicked",
|
||||
G_CALLBACK(appstate_set_tool), data_circletool);
|
||||
g_signal_connect(G_OBJECT(wstate->workspaceButtonPolygonTool), "clicked",
|
||||
G_CALLBACK(appstate_set_tool), data_polygontool);
|
||||
g_signal_connect(G_OBJECT(wstate->workspaceButtonSelectionTool), "clicked",
|
||||
G_CALLBACK(appstate_set_tool), data_selecttool);
|
||||
|
||||
// hook subtool revealers to their master buttons
|
||||
g_signal_connect(G_OBJECT(wstate->workspaceButtonMasterShapes), "clicked",
|
||||
@@ -139,10 +395,38 @@ void vektor_appstate_new(VektorWidgetState* wstate, VektorAppState* stateOut) {
|
||||
g_signal_connect(G_OBJECT(wstate->workspaceColorPicker), "color-changed",
|
||||
G_CALLBACK(appstate_on_color_change), stateOut);
|
||||
|
||||
// hook rgb entries change
|
||||
g_signal_connect(G_OBJECT(wstate->sidepanelEntryR), "activate",
|
||||
G_CALLBACK(appstate_on_entry_update),
|
||||
stateOut->widgetState);
|
||||
g_signal_connect(G_OBJECT(wstate->sidepanelEntryG), "activate",
|
||||
G_CALLBACK(appstate_on_entry_update),
|
||||
stateOut->widgetState);
|
||||
g_signal_connect(G_OBJECT(wstate->sidepanelEntryB), "activate",
|
||||
G_CALLBACK(appstate_on_entry_update),
|
||||
stateOut->widgetState);
|
||||
|
||||
// Add click gesture to canvas
|
||||
GtkGesture* canvasClickGesture = gtk_gesture_click_new();
|
||||
g_signal_connect(G_OBJECT(canvasClickGesture), "pressed",
|
||||
G_CALLBACK(canvas_onclick), stateOut);
|
||||
gtk_widget_add_controller(GTK_WIDGET(wstate->workspaceCanvas),
|
||||
GTK_EVENT_CONTROLLER(canvasClickGesture));
|
||||
|
||||
// Add drag gesture to canvas
|
||||
GtkGesture* canvasDragGesture = gtk_gesture_drag_new();
|
||||
g_signal_connect(G_OBJECT(canvasDragGesture), "drag-update",
|
||||
G_CALLBACK(vektor_appstate_canvas_drag_update), stateOut);
|
||||
g_signal_connect(G_OBJECT(canvasDragGesture), "drag-begin",
|
||||
G_CALLBACK(vektor_appstate_canvas_drag_begin), stateOut);
|
||||
g_signal_connect(G_OBJECT(canvasDragGesture), "drag-end",
|
||||
G_CALLBACK(vektor_appstate_canvas_drag_end), stateOut);
|
||||
|
||||
gtk_widget_add_controller(GTK_WIDGET(wstate->workspaceCanvas),
|
||||
GTK_EVENT_CONTROLLER(canvasDragGesture));
|
||||
}
|
||||
|
||||
void vektor_appstate_deselect_shape(VektorAppState* state) {
|
||||
state->heldHandleIndex = -1;
|
||||
state->selectedShape = NULL;
|
||||
}
|
||||
@@ -4,26 +4,36 @@
|
||||
#include "../core/primitives.h"
|
||||
#include "../ui/uicontroller.h"
|
||||
#include "../ui/vektorcanvas.h"
|
||||
#include "src/core/raster.h"
|
||||
#include "src/core/modifier.h"
|
||||
|
||||
typedef enum VektorAppTool { VektorLineTool } VektorAppTool;
|
||||
typedef enum VektorAppTool {
|
||||
VektorSelectionTool,
|
||||
VektorLineTool,
|
||||
VektorPolygonTool,
|
||||
VektorRectangleTool,
|
||||
VektorCircleTool
|
||||
} VektorAppTool;
|
||||
|
||||
typedef struct VektorAppState {
|
||||
gint64 startupTime;
|
||||
|
||||
VektorWidgetState* widgetState;
|
||||
|
||||
VektorAppTool selectedTool;
|
||||
VektorShape* selectedShape;
|
||||
VektorShapeNode* selectedShape;
|
||||
int heldHandleIndex;
|
||||
|
||||
VektorColor currentColor;
|
||||
|
||||
// Logic space
|
||||
VektorShapeBuffer* shapeBuffer;
|
||||
VektorShapeNodeBuffer* shapeBuffer;
|
||||
// View space
|
||||
VektorCanvas* canvas;
|
||||
|
||||
VektorCanvasRenderInfo* renderInfo;
|
||||
} VektorAppState;
|
||||
|
||||
void vektor_appstate_new(VektorWidgetState* wstate, VektorAppState* stateOut);
|
||||
void vektor_appstate_canvas_click(VektorAppState* state, double x, double y);
|
||||
void vektor_appstate_deselect_shape(VektorAppState* state);
|
||||
|
||||
#endif
|
||||
@@ -87,3 +87,25 @@ V2 m33_transform(const M33 mat, const V2 v) {
|
||||
return (V2){mat.m[0][0] * v.x + mat.m[0][1] * v.y + mat.m[0][2],
|
||||
mat.m[1][0] * v.x + mat.m[1][1] * v.y + mat.m[1][2]};
|
||||
}
|
||||
|
||||
void m33_to_gl4(const M33 m, float out[16]) {
|
||||
out[0] = m.m[0][0];
|
||||
out[1] = m.m[1][0];
|
||||
out[2] = 0.0f;
|
||||
out[3] = 0.0f;
|
||||
|
||||
out[4] = m.m[0][1];
|
||||
out[5] = m.m[1][1];
|
||||
out[6] = 0.0f;
|
||||
out[7] = 0.0f;
|
||||
|
||||
out[8] = 0.0f;
|
||||
out[9] = 0.0f;
|
||||
out[10] = 1.0f;
|
||||
out[11] = 0.0f;
|
||||
|
||||
out[12] = m.m[0][2];
|
||||
out[13] = m.m[1][2];
|
||||
out[14] = 0.0f;
|
||||
out[15] = 1.0f;
|
||||
}
|
||||
@@ -22,4 +22,6 @@ M33 m33_inverse(const M33 m);
|
||||
|
||||
V2 m33_transform(const M33 mat, const V2 v);
|
||||
|
||||
void m33_to_gl4(const M33 m, float out[16]);
|
||||
|
||||
#endif // MATRIX_H_
|
||||
|
||||
83
src/core/modifier.c
Normal file
83
src/core/modifier.c
Normal file
@@ -0,0 +1,83 @@
|
||||
#include "modifier.h"
|
||||
#include <glib.h>
|
||||
|
||||
VektorShapeNode vektor_shapenode_new(VektorShape* shape) {
|
||||
VektorShapeNode node = (VektorShapeNode){
|
||||
.base = shape,
|
||||
.modifier_count = 0,
|
||||
.evaluated = shape,
|
||||
.base_dirty = true
|
||||
};
|
||||
return node;
|
||||
}
|
||||
|
||||
void vektor_shapenode_free(VektorShapeNode* shapeNode) {
|
||||
if(shapeNode->base == shapeNode->evaluated) {
|
||||
free(shapeNode->base); // avoid double free()
|
||||
} else {
|
||||
free(shapeNode->base);
|
||||
free(shapeNode->evaluated);
|
||||
}
|
||||
free(shapeNode->modifiers);
|
||||
}
|
||||
|
||||
VektorShape* vektor_shapenode_get_evaluated(VektorShapeNode* shapeNode) {
|
||||
return shapeNode->evaluated;
|
||||
}
|
||||
|
||||
VektorShape vektor_modifier_apply(VektorModifier* mod, VektorShape* input) {
|
||||
mod->cachedEvaluatedShape = mod->apply(mod, input);
|
||||
return mod->cachedEvaluatedShape;
|
||||
}
|
||||
|
||||
// lots of copies by value here, could be problematic
|
||||
void vektor_shapenode_update(VektorShapeNode* shapeNode) {
|
||||
// if the base is dirty, apply EVERY modifier
|
||||
if(shapeNode->base_dirty) {
|
||||
VektorShape* evaluated = shapeNode->base;
|
||||
for(size_t i = 0; i < shapeNode->modifier_count; i++) {
|
||||
*evaluated = vektor_modifier_apply(&shapeNode->modifiers[i], evaluated);
|
||||
shapeNode->modifiers[i].dirty = false;
|
||||
}
|
||||
shapeNode->evaluated = evaluated;
|
||||
shapeNode->base_dirty = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// if the base is not dirty, start applying modifiers upstream
|
||||
// starting from the first dirty
|
||||
bool encountered_dirty = false;
|
||||
|
||||
for(size_t i = 0; i < shapeNode->modifier_count; i++) {
|
||||
if(shapeNode->modifiers[i].dirty) { encountered_dirty = true; }
|
||||
if(encountered_dirty) {
|
||||
if(i == 0) {
|
||||
vektor_modifier_apply(&shapeNode->modifiers[i], shapeNode->base);
|
||||
} else {
|
||||
vektor_modifier_apply(&shapeNode->modifiers[i], &shapeNode->modifiers[i - 1].cachedEvaluatedShape);
|
||||
}
|
||||
shapeNode->modifiers[i].dirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (encountered_dirty) {
|
||||
*shapeNode->evaluated = shapeNode->modifiers[shapeNode->modifier_count - 1].cachedEvaluatedShape;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void vektor_shapenodebuf_add(VektorShapeNodeBuffer* buffer,
|
||||
VektorShapeNode node) {
|
||||
if (buffer->count >= buffer->capacity) {
|
||||
buffer->capacity = buffer->capacity ? buffer->capacity * 2 : 4;
|
||||
buffer->nodes =
|
||||
realloc(buffer->nodes, sizeof(VektorShapeNode) * buffer->capacity);
|
||||
}
|
||||
buffer->nodes[buffer->count++] = node;
|
||||
|
||||
if (buffer->count <= buffer->capacity / 4) {
|
||||
buffer->capacity /= 2;
|
||||
buffer->nodes =
|
||||
realloc(buffer->nodes, sizeof(VektorShapeNode) * buffer->capacity);
|
||||
}
|
||||
}
|
||||
53
src/core/modifier.h
Normal file
53
src/core/modifier.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#ifndef VKTR_MODIFIER_H
|
||||
#define VKTR_MODIFIER_H
|
||||
|
||||
#include "src/core/primitives.h"
|
||||
|
||||
typedef enum {
|
||||
VEKTOR_MODIFIER_IDENTITY,
|
||||
VEKTOR_MODIFIER_BEVEL
|
||||
} VektorModifierType;
|
||||
|
||||
typedef struct VektorModifier {
|
||||
VektorModifierType type;
|
||||
bool enabled;
|
||||
bool dirty;
|
||||
void* parameters;
|
||||
|
||||
VektorShape (*apply)(struct VektorModifier* mod, VektorShape* input);
|
||||
VektorShape cachedEvaluatedShape;
|
||||
|
||||
} VektorModifier;
|
||||
|
||||
typedef struct VektorShapeNode {
|
||||
VektorShape* base;
|
||||
VektorShape* evaluated;
|
||||
|
||||
VektorModifier* modifiers;
|
||||
size_t modifier_count;
|
||||
|
||||
bool base_dirty;
|
||||
} VektorShapeNode;
|
||||
|
||||
typedef struct VektorShapeNodeBuffer {
|
||||
VektorShapeNode* nodes;
|
||||
size_t count;
|
||||
size_t capacity;
|
||||
} VektorShapeNodeBuffer;
|
||||
|
||||
VektorShape vektor_modifier_apply(VektorModifier* mod, VektorShape* input);
|
||||
|
||||
VektorShapeNode vektor_shapenode_new(VektorShape* shape);
|
||||
void vektor_shapenode_free(VektorShapeNode* shapeNode);
|
||||
VektorShape* vektor_shapenode_get_evaluated(VektorShapeNode* shapeNode);
|
||||
void vektor_shapenode_update(VektorShapeNode* shapeNode);
|
||||
void vektor_shapenode_modifier_add(VektorShapeNode* shapeNode,
|
||||
VektorModifier* mod);
|
||||
void vektor_shapenode_modifier_remove(VektorShapeNode* shapeNode,
|
||||
VektorModifier* mod);
|
||||
void vektor_shapenode_free(VektorShapeNode* shapeNode);
|
||||
|
||||
void vektor_shapenodebuf_add(VektorShapeNodeBuffer* buffer,
|
||||
VektorShapeNode node);
|
||||
|
||||
#endif
|
||||
16
src/core/modifiers/m_identity.c
Normal file
16
src/core/modifiers/m_identity.c
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "../modifier.h"
|
||||
|
||||
static VektorShape vektor_m_identity_apply(VektorModifier* m, VektorShape* input) {
|
||||
return *input;
|
||||
}
|
||||
|
||||
VektorModifier vektor_m_identity_new() {
|
||||
return (VektorModifier) {
|
||||
.type = VEKTOR_MODIFIER_IDENTITY,
|
||||
.enabled = true,
|
||||
.dirty = true,
|
||||
.parameters = NULL,
|
||||
.apply = vektor_m_identity_apply
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
#include "primitives.h"
|
||||
#include "glib.h"
|
||||
#include "src/core/matrix.h"
|
||||
#include "src/core/vector.h"
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <stddef.h>
|
||||
|
||||
// ------ PER-PRIMITIVE METHODS ------
|
||||
|
||||
VektorPolyline* vektor_polyline_new(void) {
|
||||
VektorPolyline* pl = malloc(sizeof(VektorPolyline));
|
||||
pl->count = 0;
|
||||
@@ -17,6 +22,11 @@ void vektor_polyline_add_point(VektorPolyline* pl, V2 point) {
|
||||
pl->points = realloc(pl->points, sizeof(V2) * pl->capacity);
|
||||
}
|
||||
pl->points[pl->count++] = point;
|
||||
|
||||
if (pl->count <= pl->capacity / 4) {
|
||||
pl->capacity /= 2;
|
||||
pl->points = realloc(pl->points, sizeof(V2) * pl->capacity);
|
||||
}
|
||||
}
|
||||
|
||||
void vektor_polyline_free(VektorPolyline* pl) {
|
||||
@@ -40,6 +50,11 @@ void vektor_polygon_add_point(VektorPolygon* pg, V2 point) {
|
||||
pg->points = realloc(pg->points, sizeof(V2) * pg->capacity);
|
||||
}
|
||||
pg->points[pg->count++] = point;
|
||||
|
||||
if (pg->count <= pg->capacity / 4) {
|
||||
pg->capacity /= 2;
|
||||
pg->points = realloc(pg->points, sizeof(V2) * pg->capacity);
|
||||
}
|
||||
}
|
||||
|
||||
void vektor_polygon_free(VektorPolygon* pg) {
|
||||
@@ -49,6 +64,418 @@ void vektor_polygon_free(VektorPolygon* pg) {
|
||||
free(pg);
|
||||
}
|
||||
|
||||
VektorCircle* vektor_circle_new(void) {
|
||||
VektorCircle* circ = malloc(sizeof(VektorCircle));
|
||||
circ->center = (V2){0, 0};
|
||||
circ->radius = 0;
|
||||
return circ;
|
||||
}
|
||||
|
||||
void vektor_circle_set_center(VektorCircle* circle, V2 point) {
|
||||
circle->center = point;
|
||||
}
|
||||
|
||||
void vektor_circle_set_radius(VektorCircle* circle, double radius) {
|
||||
circle->radius = radius;
|
||||
}
|
||||
|
||||
void vektor_circle_free(VektorCircle* circle) { free(circle); }
|
||||
|
||||
VektorRectangle* vektor_rectangle_new(void) {
|
||||
VektorRectangle* rct = malloc(sizeof(VektorRectangle));
|
||||
rct->start = (V2){.x = 0, .y = 0};
|
||||
rct->end = (V2){.x = 0, .y = 0};
|
||||
return rct;
|
||||
}
|
||||
|
||||
void vektor_rectangle_set_end(VektorRectangle* rct, V2 point) {
|
||||
rct->end = point;
|
||||
}
|
||||
void vektor_rectangle_set_start(VektorRectangle* rct, V2 point) {
|
||||
rct->start = point;
|
||||
}
|
||||
|
||||
void vektor_rectangle_free(VektorRectangle* rct) { free(rct); }
|
||||
|
||||
VektorBBox vektor_polyline_get_bbox(VektorPrimitive prim) {
|
||||
V2 first = prim.polyline->points[0];
|
||||
|
||||
float min_x = first.x;
|
||||
float max_x = first.x;
|
||||
float min_y = first.y;
|
||||
float max_y = first.y;
|
||||
|
||||
for (size_t i = 1; i < prim.polygon->count; i++) {
|
||||
V2 p = prim.polygon->points[i];
|
||||
|
||||
min_x = fminf(min_x, p.x);
|
||||
min_y = fminf(min_y, p.y);
|
||||
|
||||
max_x = fmaxf(max_x, p.x);
|
||||
max_y = fmaxf(max_y, p.y);
|
||||
}
|
||||
|
||||
return (VektorBBox){(V2){min_x, min_y}, (V2){max_x, max_y}};
|
||||
}
|
||||
|
||||
VektorBBox vektor_polygon_get_bbox(VektorPrimitive prim) {
|
||||
V2 first = prim.polygon->points[0];
|
||||
|
||||
float min_x = first.x;
|
||||
float max_x = first.x;
|
||||
float min_y = first.y;
|
||||
float max_y = first.y;
|
||||
|
||||
for (size_t i = 1; i < prim.polygon->count; i++) {
|
||||
V2 p = prim.polygon->points[i];
|
||||
|
||||
min_x = fminf(min_x, p.x);
|
||||
min_y = fminf(min_y, p.y);
|
||||
|
||||
max_x = fmaxf(max_x, p.x);
|
||||
max_y = fmaxf(max_y, p.y);
|
||||
}
|
||||
|
||||
return (VektorBBox){(V2){min_x, min_y}, (V2){max_x, max_y}};
|
||||
}
|
||||
|
||||
VektorBBox vektor_rectangle_get_bbox(VektorPrimitive prim) {
|
||||
return (VektorBBox){prim.rectangle.start, prim.rectangle.end};
|
||||
}
|
||||
|
||||
VektorBBox vektor_circle_get_bbox(VektorPrimitive prim) {
|
||||
return (VektorBBox){
|
||||
vec2_sub(prim.circle.center, vec2_fromfloat(prim.circle.radius)),
|
||||
vec2_add(prim.circle.center, vec2_fromfloat(prim.circle.radius))};
|
||||
}
|
||||
|
||||
VektorBBox vektor_primitive_get_bbox(VektorPrimitive prim) {
|
||||
switch (prim.kind) {
|
||||
case VEKTOR_POLYLINE:
|
||||
return vektor_polyline_get_bbox(prim);
|
||||
break;
|
||||
|
||||
case VEKTOR_POLYGON:
|
||||
return vektor_polygon_get_bbox(prim);
|
||||
break;
|
||||
|
||||
case VEKTOR_RECTANGLE:
|
||||
return vektor_rectangle_get_bbox(prim);
|
||||
break;
|
||||
|
||||
case VEKTOR_CIRCLE:
|
||||
return vektor_circle_get_bbox(prim);
|
||||
break;
|
||||
|
||||
default:
|
||||
// TODO: fill in all primitives
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ------ PRIMITIVE HANDLES GENERATION ------
|
||||
|
||||
/* [n]: polyline vertices */
|
||||
void vektor_polyline_create_handles(VektorPolyline* polyline, V2** handleArr,
|
||||
size_t* count) {
|
||||
*count = 0;
|
||||
*handleArr = NULL;
|
||||
}
|
||||
|
||||
/* [n]: polygon vertices */
|
||||
void vektor_polygon_create_handles(VektorPolygon* polygon, V2** handleArr,
|
||||
size_t* count) {
|
||||
*count = 0;
|
||||
*handleArr = NULL;
|
||||
}
|
||||
|
||||
/* [0]: center; [1]: radius */
|
||||
void vektor_circle_create_handles(VektorCircle* circle, V2** handleArr,
|
||||
size_t* count) {
|
||||
*count = 2;
|
||||
*handleArr = (V2*)malloc(sizeof(V2) * (*count));
|
||||
(*handleArr)[0] = circle->center;
|
||||
(*handleArr)[1] = (V2){circle->radius + circle->center.x, circle->center.y};
|
||||
}
|
||||
|
||||
/* [0]: center; [1-4]: corners (l2r, t2b); */
|
||||
void vektor_rectangle_create_handles(VektorRectangle* rectangle, V2** handleArr,
|
||||
size_t* count) {
|
||||
*count = 5;
|
||||
free(*handleArr);
|
||||
*handleArr = (V2*)malloc(sizeof(V2) * (*count));
|
||||
|
||||
V2 halfdist = vec2_scale(vec2_sub(rectangle->end, rectangle->start), 0.5f);
|
||||
V2 center = vec2_add(rectangle->start, halfdist);
|
||||
|
||||
(*handleArr)[0] = center;
|
||||
(*handleArr)[1] = vec2_add(center, vec2_mul(halfdist, (V2){-1.0f, 1.0f}));
|
||||
(*handleArr)[2] = vec2_add(center, halfdist);
|
||||
(*handleArr)[3] = vec2_add(center, vec2_mul(halfdist, (V2){-1.0f, -1.0f}));
|
||||
(*handleArr)[4] = vec2_add(center, vec2_mul(halfdist, (V2){1.0f, -1.0f}));
|
||||
}
|
||||
|
||||
void vektor_shape_create_handles(VektorShape* shape) {
|
||||
switch (shape->primitive.kind) {
|
||||
case VEKTOR_POLYLINE:
|
||||
vektor_polyline_create_handles(shape->primitive.polyline,
|
||||
&shape->handles, &shape->handleCount);
|
||||
break;
|
||||
case VEKTOR_POLYGON:
|
||||
vektor_polygon_create_handles(shape->primitive.polygon, &shape->handles,
|
||||
&shape->handleCount);
|
||||
break;
|
||||
case VEKTOR_CIRCLE:
|
||||
vektor_circle_create_handles(&shape->primitive.circle, &shape->handles,
|
||||
&shape->handleCount);
|
||||
break;
|
||||
case VEKTOR_RECTANGLE:
|
||||
vektor_rectangle_create_handles(&shape->primitive.rectangle,
|
||||
&shape->handles, &shape->handleCount);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ------ AUXILIARY HANDLE METHODS ------
|
||||
|
||||
void vektor_shape_add_handle(VektorShape* shape, V2 handle) {
|
||||
// could be optimised with capacity property
|
||||
// but this function is only called when adding new
|
||||
// points to polyline and polygon, so it should
|
||||
// not be that much of an overhead
|
||||
shape->handles =
|
||||
realloc(shape->handles, sizeof(V2) * shape->handleCount + 1);
|
||||
shape->handles[shape->handleCount++] = handle;
|
||||
}
|
||||
|
||||
VektorBBox vektor_shape_get_handle_bbox(V2 handle) {
|
||||
return vektor_bbox_fromcenter(handle, 0.02);
|
||||
}
|
||||
|
||||
// ------ PRIMITIVE HANDLES UPDATING ------
|
||||
|
||||
void vektor_polyline_handles_updated(VektorPolyline* polyline, V2** handles,
|
||||
size_t* count, int* heldHandleIndex) {
|
||||
if (*count != polyline->count) {
|
||||
g_warning("handle count & point count mismatch in polyline");
|
||||
return;
|
||||
}
|
||||
for (size_t i = 0; i < *count; i++) {
|
||||
polyline->points[i] = (*handles)[i];
|
||||
}
|
||||
}
|
||||
|
||||
void vektor_polygon_handles_updated(VektorPolygon* polygon, V2** handles,
|
||||
size_t* count, int* heldHandleIndex) {
|
||||
if (*count != polygon->count) {
|
||||
g_warning("handle count & point count mismatch in polygon");
|
||||
return;
|
||||
}
|
||||
for (size_t i = 0; i < *count; i++) {
|
||||
polygon->points[i] = (*handles)[i];
|
||||
}
|
||||
}
|
||||
|
||||
void vektor_circle_handles_updated(VektorCircle* circle, V2** handles,
|
||||
size_t* count, int* heldHandleIndex) {
|
||||
if (*count != 2) {
|
||||
g_warning("unexpected circle handle count (%zu)", *count);
|
||||
return;
|
||||
}
|
||||
|
||||
if (*heldHandleIndex == 0) { // dragging center
|
||||
V2 translation = vec2_sub((*handles)[0], circle->center);
|
||||
circle->center = (*handles)[0];
|
||||
(*handles)[1] = vec2_add(translation, (*handles)[1]);
|
||||
} else {
|
||||
circle->radius = vec2_length(vec2_sub((*handles)[0], (*handles)[1]));
|
||||
}
|
||||
}
|
||||
|
||||
// this shi is big because it dynamically handles handle remapping when
|
||||
// rectangle enters an invalid state (end < start)
|
||||
// creating the illusion of an invertable rect, while also keeping it
|
||||
// valid at all times
|
||||
void vektor_rectangle_handles_updated(VektorRectangle* rectangle, V2** handles,
|
||||
size_t* count, int* heldHandleIndex) {
|
||||
if (*count != 5) {
|
||||
g_warning("unexpected rectangle handle count (%zu)", *count);
|
||||
return;
|
||||
}
|
||||
|
||||
V2 start = rectangle->start;
|
||||
V2 end = rectangle->end;
|
||||
|
||||
switch (*heldHandleIndex) {
|
||||
case 0: // center drag
|
||||
{
|
||||
V2 oldCenter = vec2_scale(vec2_add(start, end), 0.5f);
|
||||
V2 newCenter = (*handles)[0];
|
||||
|
||||
V2 translation = vec2_sub(newCenter, oldCenter);
|
||||
|
||||
start = vec2_add(start, translation);
|
||||
end = vec2_add(end, translation);
|
||||
break;
|
||||
}
|
||||
|
||||
case 1: // top-left
|
||||
start.x = (*handles)[1].x;
|
||||
end.y = (*handles)[1].y;
|
||||
break;
|
||||
|
||||
case 2: // top-right
|
||||
end.x = (*handles)[2].x;
|
||||
end.y = (*handles)[2].y;
|
||||
break;
|
||||
|
||||
case 3: // bottom-left
|
||||
start.x = (*handles)[3].x;
|
||||
start.y = (*handles)[3].y;
|
||||
break;
|
||||
|
||||
case 4: // bottom-right
|
||||
end.x = (*handles)[4].x;
|
||||
start.y = (*handles)[4].y;
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
// Store raw values before normalization
|
||||
float raw_min_x = start.x;
|
||||
float raw_max_x = end.x;
|
||||
float raw_min_y = start.y;
|
||||
float raw_max_y = end.y;
|
||||
|
||||
// Normalize rectangle
|
||||
float min_x = fminf(start.x, end.x);
|
||||
float max_x = fmaxf(start.x, end.x);
|
||||
float min_y = fminf(start.y, end.y);
|
||||
float max_y = fmaxf(start.y, end.y);
|
||||
|
||||
bool flipX = raw_min_x > raw_max_x;
|
||||
bool flipY = raw_min_y > raw_max_y;
|
||||
|
||||
// Remap handle if we crossed axes
|
||||
if (*heldHandleIndex != 0) {
|
||||
if (flipX) {
|
||||
switch (*heldHandleIndex) {
|
||||
case 1:
|
||||
*heldHandleIndex = 2;
|
||||
break;
|
||||
case 2:
|
||||
*heldHandleIndex = 1;
|
||||
break;
|
||||
case 3:
|
||||
*heldHandleIndex = 4;
|
||||
break;
|
||||
case 4:
|
||||
*heldHandleIndex = 3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (flipY) {
|
||||
switch (*heldHandleIndex) {
|
||||
case 1:
|
||||
*heldHandleIndex = 3;
|
||||
break;
|
||||
case 3:
|
||||
*heldHandleIndex = 1;
|
||||
break;
|
||||
case 2:
|
||||
*heldHandleIndex = 4;
|
||||
break;
|
||||
case 4:
|
||||
*heldHandleIndex = 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VektorRectangle properRect = {.start = {min_x, min_y},
|
||||
.end = {max_x, max_y}};
|
||||
|
||||
vektor_rectangle_set_start(rectangle, properRect.start);
|
||||
vektor_rectangle_set_end(rectangle, properRect.end);
|
||||
|
||||
// regenerate handle positions
|
||||
vektor_rectangle_create_handles(&properRect, handles, count);
|
||||
}
|
||||
|
||||
void vektor_shape_handles_updated(VektorShape* shape, int* heldHandleIndex) {
|
||||
switch (shape->primitive.kind) {
|
||||
case VEKTOR_POLYLINE:
|
||||
vektor_polyline_handles_updated(shape->primitive.polyline,
|
||||
&shape->handles, &shape->handleCount,
|
||||
heldHandleIndex);
|
||||
break;
|
||||
case VEKTOR_POLYGON:
|
||||
vektor_polygon_handles_updated(shape->primitive.polygon,
|
||||
&shape->handles, &shape->handleCount,
|
||||
heldHandleIndex);
|
||||
break;
|
||||
case VEKTOR_CIRCLE:
|
||||
vektor_circle_handles_updated(&shape->primitive.circle, &shape->handles,
|
||||
&shape->handleCount, heldHandleIndex);
|
||||
break;
|
||||
case VEKTOR_RECTANGLE:
|
||||
vektor_rectangle_handles_updated(&shape->primitive.rectangle,
|
||||
&shape->handles, &shape->handleCount,
|
||||
heldHandleIndex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ------ BBOX METHODS ------
|
||||
|
||||
bool vektor_bbox_isinside(VektorBBox bbox, V2 point) {
|
||||
return point.x >= bbox.min.x && point.y >= bbox.min.y &&
|
||||
point.x <= bbox.max.x && point.y <= bbox.max.y;
|
||||
}
|
||||
|
||||
VektorBBox vektor_bbox_fromcenter(V2 center, float dist) {
|
||||
V2 v2dist = vec2_fromfloat(dist);
|
||||
V2 min = vec2_sub(center, v2dist);
|
||||
V2 max = vec2_add(center, v2dist);
|
||||
return (VektorBBox){min, max};
|
||||
}
|
||||
|
||||
VektorBBox vektor_bbox_expand(VektorBBox bbox, float val) {
|
||||
return (VektorBBox){vec2_sub(bbox.min, vec2_fromfloat(val)),
|
||||
vec2_add(bbox.max, vec2_fromfloat(val))};
|
||||
}
|
||||
|
||||
// ------ SHAPE METHODS ------
|
||||
|
||||
VektorShape* vektor_shape_new(VektorPrimitive prim, VektorStyle style,
|
||||
int z_index) {
|
||||
VektorShape* shape = malloc(sizeof(VektorShape));
|
||||
*shape = (VektorShape){.primitive = prim,
|
||||
.style = style,
|
||||
.transform = m33_identity(),
|
||||
.z_index = z_index,
|
||||
.bbox = vektor_primitive_get_bbox(prim)};
|
||||
|
||||
/*
|
||||
create_handles() allocates new buffer for handles,
|
||||
and even if the local shape variable goes out of scope and deallocates,
|
||||
the passed value's pointer to an array of handles remains valid in the
|
||||
passed copy.
|
||||
*/
|
||||
vektor_shape_create_handles(shape);
|
||||
return shape;
|
||||
}
|
||||
|
||||
void vektor_shapes_update_bbox(VektorShapeBuffer* buffer) {
|
||||
for (size_t i = 0; i < buffer->count; i++) {
|
||||
buffer->shapes[i].bbox =
|
||||
vektor_primitive_get_bbox(buffer->shapes[i].primitive);
|
||||
}
|
||||
}
|
||||
|
||||
void vektor_shapebuffer_add_shape(VektorShapeBuffer* buffer,
|
||||
VektorShape shape) {
|
||||
if (buffer->count >= buffer->capacity) {
|
||||
@@ -57,57 +484,10 @@ void vektor_shapebuffer_add_shape(VektorShapeBuffer* buffer,
|
||||
realloc(buffer->shapes, sizeof(VektorShape) * buffer->capacity);
|
||||
}
|
||||
buffer->shapes[buffer->count++] = shape;
|
||||
}
|
||||
|
||||
VektorBBox polyline_mk_bbox(VektorPrimitive prim) {
|
||||
float min_x, max_x, min_y, max_y;
|
||||
for (size_t i = 0; i < prim.polyline->count; i++) {
|
||||
V2 p = prim.polyline->points[i];
|
||||
min_x = fminf(min_x, p.x);
|
||||
min_y = fminf(min_y, p.y);
|
||||
|
||||
max_x = fminf(max_x, p.x);
|
||||
max_y = fminf(max_y, p.y);
|
||||
}
|
||||
return (VektorBBox){(V2){min_x, min_y}, (V2){max_x, max_y}};
|
||||
}
|
||||
|
||||
VektorBBox polygon_mk_bbox(VektorPrimitive prim) {
|
||||
float min_x, max_x, min_y, max_y;
|
||||
for (size_t i = 0; i < prim.polygon->count; i++) {
|
||||
V2 p = prim.polygon->points[i];
|
||||
min_x = fminf(min_x, p.x);
|
||||
min_y = fminf(min_y, p.y);
|
||||
|
||||
max_x = fminf(max_x, p.x);
|
||||
max_y = fminf(max_y, p.y);
|
||||
}
|
||||
return (VektorBBox){(V2){min_x, min_y}, (V2){max_x, max_y}};
|
||||
}
|
||||
|
||||
VektorBBox vektor_mk_bbox(VektorPrimitive prim) {
|
||||
switch (prim.kind) {
|
||||
case VEKTOR_POLYLINE:
|
||||
return polyline_mk_bbox(prim);
|
||||
break;
|
||||
|
||||
case VEKTOR_POLYGON:
|
||||
return polygon_mk_bbox(prim);
|
||||
break;
|
||||
|
||||
default:
|
||||
// TODO: fill in all primitives
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
VektorShape vektor_shape_new(VektorPrimitive prim, VektorStyle style,
|
||||
int z_index) {
|
||||
return (VektorShape){.primitive = prim, .style = style, .z_index = z_index, .bbox=vektor_mk_bbox(prim)};
|
||||
}
|
||||
|
||||
void vektor_shapes_update_bbox(VektorShapeBuffer* buffer) {
|
||||
for (size_t i = 0; i < buffer->count; i++) {
|
||||
buffer->shapes[i].bbox = vektor_mk_bbox(buffer->shapes[i].primitive);
|
||||
if (buffer->count <= buffer->capacity / 4) {
|
||||
buffer->capacity /= 2;
|
||||
buffer->shapes =
|
||||
realloc(buffer->shapes, sizeof(VektorShape) * buffer->capacity);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef PRIMITIVES_H_
|
||||
#define PRIMITIVES_H_
|
||||
|
||||
#include "src/core/matrix.h"
|
||||
#include "src/util/color.h"
|
||||
#include "stddef.h"
|
||||
#include "stdlib.h"
|
||||
@@ -23,10 +24,16 @@ typedef struct {
|
||||
double radius;
|
||||
} VektorCircle;
|
||||
|
||||
typedef struct {
|
||||
V2 start;
|
||||
V2 end;
|
||||
} VektorRectangle;
|
||||
|
||||
typedef enum {
|
||||
VEKTOR_POLYLINE,
|
||||
VEKTOR_POLYGON,
|
||||
VEKTOR_CIRCLE
|
||||
VEKTOR_CIRCLE,
|
||||
VEKTOR_RECTANGLE
|
||||
} VektorPrimitiveKind;
|
||||
|
||||
typedef struct {
|
||||
@@ -35,17 +42,10 @@ typedef struct {
|
||||
VektorPolyline* polyline;
|
||||
VektorPolygon* polygon;
|
||||
VektorCircle circle;
|
||||
VektorRectangle rectangle;
|
||||
};
|
||||
} VektorPrimitive;
|
||||
|
||||
VektorPolyline* vektor_polyline_new(void);
|
||||
void vektor_polyline_add_point(VektorPolyline* pl, V2 point);
|
||||
void vektor_polyline_free(VektorPolyline* pl);
|
||||
|
||||
VektorPolygon* vektor_polygon_new(void);
|
||||
void vektor_polygon_add_point(VektorPolygon* pl, V2 point);
|
||||
void vektor_polygon_free(VektorPolygon* pl);
|
||||
|
||||
typedef struct {
|
||||
VektorColor stroke_color;
|
||||
float stroke_width;
|
||||
@@ -59,18 +59,70 @@ typedef struct {
|
||||
typedef struct {
|
||||
VektorStyle style;
|
||||
int z_index;
|
||||
M33 transform;
|
||||
VektorBBox bbox;
|
||||
VektorPrimitive primitive;
|
||||
|
||||
V2* handles;
|
||||
size_t handleCount;
|
||||
} VektorShape;
|
||||
|
||||
VektorBBox polyline_mk_bbox(VektorPrimitive prim);
|
||||
VektorBBox polygon_mk_bbox(VektorPrimitive prim);
|
||||
VektorPolyline* vektor_polyline_new(void);
|
||||
void vektor_polyline_add_point(VektorPolyline* pl, V2 point);
|
||||
void vektor_polyline_free(VektorPolyline* pl);
|
||||
|
||||
VektorBBox vektor_mk_bbox(VektorPrimitive prim);
|
||||
VektorPolygon* vektor_polygon_new(void);
|
||||
void vektor_polygon_add_point(VektorPolygon* pl, V2 point);
|
||||
void vektor_polygon_free(VektorPolygon* pl);
|
||||
|
||||
VektorShape vektor_shape_new(VektorPrimitive prim, VektorStyle style,
|
||||
VektorCircle* vektor_circle_new(void);
|
||||
void vektor_circle_set_center(VektorCircle* circle, V2 point);
|
||||
void vektor_circle_set_radius(VektorCircle* circle, double radius);
|
||||
void vektor_circle_free(VektorCircle* circle);
|
||||
|
||||
VektorRectangle* vektor_rectangle_new(void);
|
||||
void vektor_rectangle_set_end(VektorRectangle* rct, V2 point);
|
||||
void vektor_rectangle_set_start(VektorRectangle* rct, V2 point);
|
||||
void vektor_rectangle_free(VektorRectangle* rct);
|
||||
|
||||
VektorShape* vektor_shape_new(VektorPrimitive prim, VektorStyle style,
|
||||
int z_index);
|
||||
|
||||
VektorBBox vektor_polyline_get_bbox(VektorPrimitive prim);
|
||||
VektorBBox vektor_polygon_get_bbox(VektorPrimitive prim);
|
||||
VektorBBox vektor_circle_get_bbox(VektorPrimitive prim);
|
||||
VektorBBox vektor_rectangle_get_bbox(VektorPrimitive prim);
|
||||
|
||||
VektorBBox vektor_primitive_get_bbox(VektorPrimitive prim);
|
||||
bool vektor_bbox_isinside(VektorBBox bbox, V2 point);
|
||||
VektorBBox vektor_bbox_fromcenter(V2 center, float dist);
|
||||
VektorBBox vektor_bbox_expand(VektorBBox bbox, float val);
|
||||
|
||||
// shape handles
|
||||
void vektor_polyline_create_handles(VektorPolyline* polyline, V2** handleArr,
|
||||
size_t* count);
|
||||
void vektor_polygon_create_handles(VektorPolygon* polygon, V2** handleArr,
|
||||
size_t* count);
|
||||
void vektor_circle_create_handles(VektorCircle* circle, V2** handleArr,
|
||||
size_t* count);
|
||||
void vektor_rectangle_create_handles(VektorRectangle* rectangle, V2** handleArr,
|
||||
size_t* count);
|
||||
void vektor_shape_create_handles(VektorShape* shape);
|
||||
|
||||
void vektor_shape_add_handle(VektorShape* shape, V2 handle);
|
||||
VektorBBox vektor_shape_get_handle_bbox(V2 handle);
|
||||
|
||||
/* reconstructs the shape based on handles alone */
|
||||
void vektor_polyline_handles_updated(VektorPolyline* polyline, V2** handles,
|
||||
size_t* count, int* heldHandleIndex);
|
||||
void vektor_polygon_handles_updated(VektorPolygon* polygon, V2** handles,
|
||||
size_t* count, int* heldHandleIndex);
|
||||
void vektor_circle_handles_updated(VektorCircle* circle, V2** handles,
|
||||
size_t* count, int* heldHandleIndex);
|
||||
void vektor_rectangle_handles_updated(VektorRectangle* rectangle, V2** handles,
|
||||
size_t* count, int* heldHandleIndex);
|
||||
void vektor_shape_handles_updated(VektorShape* shape, int* heldHandleIndex);
|
||||
|
||||
typedef struct {
|
||||
VektorShape* shapes;
|
||||
size_t count;
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
#include "raster.h"
|
||||
#include "epoxy/gl.h"
|
||||
#include "glib.h"
|
||||
#include "primitives.h"
|
||||
#include "src/core/matrix.h"
|
||||
#include "src/core/modifier.h"
|
||||
#include "src/core/vector.h"
|
||||
#include "stddef.h"
|
||||
#include <math.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define PI 3.14159265358979323846
|
||||
|
||||
void vektor_edgebuffer_add_edge(EdgeBuffer* buffer, Edge edge) {
|
||||
if (buffer->count >= buffer->capacity) {
|
||||
buffer->capacity = buffer->capacity ? buffer->capacity * 2 : 4;
|
||||
@@ -12,39 +19,88 @@ void vektor_edgebuffer_add_edge(EdgeBuffer* buffer, Edge edge) {
|
||||
buffer->edges[buffer->count++] = edge;
|
||||
}
|
||||
|
||||
void vektor_polyline_flatten(EdgeBuffer* buffer, VektorPolyline* line,
|
||||
size_t j) {
|
||||
void vektor_polyline_tessellate(EdgeBuffer* buffer, VektorPolyline* line,
|
||||
size_t j, double scale) {
|
||||
for (size_t i = 0; i + 1 < line->count; i++) {
|
||||
vektor_edgebuffer_add_edge(
|
||||
buffer, (Edge){line->points[i], line->points[i + 1], 0, j});
|
||||
}
|
||||
}
|
||||
|
||||
void vektor_polygon_flatten(EdgeBuffer* buffer, VektorPolygon* pg, size_t j) {
|
||||
size_t n = pg->count;
|
||||
if (n < 3)
|
||||
void vektor_polygon_tessellate(EdgeBuffer* buffer, VektorPolygon* polygon,
|
||||
size_t j, double scale) {
|
||||
for (size_t i = 0; i + 1 < polygon->count; i++) {
|
||||
vektor_edgebuffer_add_edge(
|
||||
buffer, (Edge){polygon->points[i], polygon->points[i + 1], 0, j});
|
||||
}
|
||||
vektor_edgebuffer_add_edge(
|
||||
buffer,
|
||||
(Edge){polygon->points[polygon->count - 1], polygon->points[0], 0, j});
|
||||
}
|
||||
|
||||
void vektor_circle_tessellate(EdgeBuffer* buffer, VektorCircle* circle,
|
||||
size_t j, double scale) {
|
||||
double err = 0.0025;
|
||||
size_t res = PI * sqrt((scale * circle->radius) / (2 * err));
|
||||
for (size_t i = 0; i < res; i++) {
|
||||
double theta1 = (2 * PI * i) / res;
|
||||
double theta2 = (2 * PI * (i + 1)) / res;
|
||||
V2 p1 = (V2){circle->center.x + circle->radius * cos(theta1),
|
||||
circle->center.y + circle->radius * sin(theta1)};
|
||||
V2 p2 = (V2){circle->center.x + circle->radius * cos(theta2),
|
||||
circle->center.y + circle->radius * sin(theta2)};
|
||||
vektor_edgebuffer_add_edge(buffer, (Edge){p1, p2, 0, j});
|
||||
}
|
||||
}
|
||||
|
||||
void vektor_rectangle_tessellate(EdgeBuffer* buffer, VektorRectangle* rct,
|
||||
size_t j, double scale) {
|
||||
if (vec2_equals(rct->end, rct->start)) {
|
||||
return;
|
||||
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
V2 p1 = pg->points[i];
|
||||
V2 p2 = pg->points[(i + 1) % n];
|
||||
int winding = (p1.y < p2.y) ? +1 : -1;
|
||||
vektor_edgebuffer_add_edge(buffer, (Edge){p1, p2, winding, j});
|
||||
}
|
||||
}
|
||||
|
||||
void vektor_rasterize(VertexBuffer* vb, VektorShapeBuffer* shapes) {
|
||||
Edge top = (Edge){rct->start, (V2){rct->end.x, rct->start.y}, 0, j};
|
||||
Edge right = (Edge){(V2){rct->end.x, rct->start.y}, rct->end, 0, j};
|
||||
Edge bottom = (Edge){(V2){rct->start.x, rct->end.y}, rct->end, 0, j};
|
||||
Edge left = (Edge){rct->start, (V2){rct->start.x, rct->end.y}, 0, j};
|
||||
|
||||
vektor_edgebuffer_add_edge(buffer, top);
|
||||
vektor_edgebuffer_add_edge(buffer, right);
|
||||
vektor_edgebuffer_add_edge(buffer, bottom);
|
||||
vektor_edgebuffer_add_edge(buffer, left);
|
||||
}
|
||||
|
||||
void vektor_vb_rasterize(VertexBuffer* vb, VektorShapeNodeBuffer* nodebuf,
|
||||
double scale) {
|
||||
for (size_t i = 0; i < nodebuf->count; i++) {
|
||||
EdgeBuffer edges = {0};
|
||||
for (size_t i = 0; i < shapes->count; i++) {
|
||||
VektorPrimitive* p = &shapes->shapes[i].primitive;
|
||||
|
||||
vektor_shapenode_update(&nodebuf->nodes[i]);
|
||||
VektorShape* currentShape = vektor_shapenode_get_evaluated(&nodebuf->nodes[i]);
|
||||
|
||||
VektorPrimitive* p = ¤tShape->primitive;
|
||||
VektorStyle style = currentShape->style;
|
||||
M33 transform = currentShape->transform;
|
||||
|
||||
switch (p->kind) {
|
||||
case VEKTOR_POLYLINE:
|
||||
vektor_polyline_flatten(&edges, p->polyline, i);
|
||||
vektor_polyline_tessellate(&edges, p->polyline, i, scale);
|
||||
vektor_edges_to_triangles(vb, &edges, &transform, style, FALSE);
|
||||
break;
|
||||
|
||||
case VEKTOR_POLYGON:
|
||||
vektor_polygon_flatten(&edges, p->polygon, i);
|
||||
vektor_polygon_tessellate(&edges, p->polygon, i, scale);
|
||||
vektor_edges_to_triangles(vb, &edges, &transform, style, TRUE);
|
||||
break;
|
||||
|
||||
case VEKTOR_CIRCLE:
|
||||
vektor_circle_tessellate(&edges, &p->circle, i, scale);
|
||||
vektor_edges_to_triangles(vb, &edges, &transform, style, TRUE);
|
||||
break;
|
||||
|
||||
case VEKTOR_RECTANGLE:
|
||||
vektor_rectangle_tessellate(&edges, &p->rectangle, i, scale);
|
||||
vektor_edges_to_triangles(vb, &edges, &transform, style, TRUE);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -52,11 +108,10 @@ void vektor_rasterize(VertexBuffer* vb, VektorShapeBuffer* shapes) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
vektor_edges_to_triangles(vb, &edges, shapes);
|
||||
}
|
||||
|
||||
void vb_add_triangle(VertexBuffer* vb, V2 v0, V2 v1, V2 v2, VektorColor color) {
|
||||
void vektor_vb_add_triangle(VertexBuffer* vb, V2 v0, V2 v1, V2 v2,
|
||||
VektorColor color) {
|
||||
if (vb->count + 3 >= vb->capacity) {
|
||||
vb->capacity = vb->capacity ? vb->capacity * 2 : 8;
|
||||
vb->vertices = realloc(vb->vertices, sizeof(Vertex) * vb->capacity);
|
||||
@@ -64,35 +119,132 @@ void vb_add_triangle(VertexBuffer* vb, V2 v0, V2 v1, V2 v2, VektorColor color) {
|
||||
vb->vertices[vb->count++] = (Vertex){v0, color};
|
||||
vb->vertices[vb->count++] = (Vertex){v1, color};
|
||||
vb->vertices[vb->count++] = (Vertex){v2, color};
|
||||
|
||||
if (vb->count <= vb->capacity / 4) {
|
||||
vb->capacity /= 2;
|
||||
vb->vertices = realloc(vb->vertices, sizeof(Vertex) * vb->capacity);
|
||||
}
|
||||
}
|
||||
|
||||
void vektor_edge_to_triangles(VertexBuffer* vb, Edge e,
|
||||
VektorShapeBuffer* shape_buffer) {
|
||||
float dx = e.p2.x - e.p1.x;
|
||||
float dy = e.p2.y - e.p1.y;
|
||||
float len = sqrtf(dx * dx + dy * dy);
|
||||
if (len == 0)
|
||||
return;
|
||||
void vektor_vb_add_quad(VertexBuffer* vb, V2 a, V2 b, VektorColor color) {
|
||||
|
||||
float px =
|
||||
-dy / len * (shape_buffer->shapes[e.shape_id].style.stroke_width / 2);
|
||||
float py =
|
||||
dx / len * (shape_buffer->shapes[e.shape_id].style.stroke_width / 2);
|
||||
float minx = fminf(a.x, b.x);
|
||||
float maxx = fmaxf(a.x, b.x);
|
||||
float miny = fminf(a.y, b.y);
|
||||
float maxy = fmaxf(a.y, b.y);
|
||||
|
||||
V2 v0 = {e.p1.x + px, e.p1.y + py};
|
||||
V2 v1 = {e.p1.x - px, e.p1.y - py};
|
||||
V2 v2 = {e.p2.x + px, e.p2.y + py};
|
||||
V2 v3 = {e.p2.x - px, e.p2.y - py};
|
||||
V2 tl = {minx, miny};
|
||||
V2 bl = {minx, maxy};
|
||||
V2 br = {maxx, maxy};
|
||||
V2 tr = {maxx, miny};
|
||||
|
||||
vb_add_triangle(vb, v0, v1, v2,
|
||||
shape_buffer->shapes[e.shape_id].style.stroke_color);
|
||||
vb_add_triangle(vb, v2, v1, v3,
|
||||
shape_buffer->shapes[e.shape_id].style.stroke_color);
|
||||
vektor_vb_add_triangle(vb, tl, bl, br, color);
|
||||
vektor_vb_add_triangle(vb, tl, br, tr, color);
|
||||
}
|
||||
|
||||
Edge edge_transform(const Edge* e, const M33* t) {
|
||||
Edge out = *e;
|
||||
out.p1 = m33_transform(*t, e->p1);
|
||||
out.p2 = m33_transform(*t, e->p2);
|
||||
return out;
|
||||
}
|
||||
|
||||
V2 line_intersection(V2 p, V2 r, V2 q, V2 s) {
|
||||
float t = vec2_cross(vec2_sub(q, p), s) / vec2_cross(r, s);
|
||||
return vec2_add(p, vec2_scale(r, t));
|
||||
}
|
||||
|
||||
void vektor_edges_to_triangles(VertexBuffer* vb, EdgeBuffer* edges,
|
||||
VektorShapeBuffer* shape_buffer) {
|
||||
M33* transform, VektorStyle style, bool closed) {
|
||||
if (!edges || edges->count < 1)
|
||||
return;
|
||||
|
||||
float hw = style.stroke_width * 0.5f;
|
||||
|
||||
for (size_t i = 0; i < edges->count; i++) {
|
||||
vektor_edge_to_triangles(vb, edges->edges[i], shape_buffer);
|
||||
Edge e = edge_transform(&edges->edges[i], transform);
|
||||
|
||||
V2 d = vec2_normalize(vec2_sub(e.p2, e.p1));
|
||||
V2 n = vec2_perp(d);
|
||||
V2 off = vec2_scale(n, hw);
|
||||
|
||||
V2 v0 = vec2_add(e.p1, off);
|
||||
V2 v1 = vec2_sub(e.p1, off);
|
||||
V2 v2 = vec2_add(e.p2, off);
|
||||
V2 v3 = vec2_sub(e.p2, off);
|
||||
|
||||
vektor_vb_add_triangle(vb, v0, v1, v2, style.stroke_color);
|
||||
vektor_vb_add_triangle(vb, v2, v1, v3, style.stroke_color);
|
||||
}
|
||||
|
||||
size_t limit = closed ? edges->count : edges->count - 1;
|
||||
|
||||
for (size_t i = 0; i < limit; i++) {
|
||||
Edge e1 = edge_transform(&edges->edges[i], transform);
|
||||
Edge e2 =
|
||||
edge_transform(&edges->edges[(i + 1) % edges->count], transform);
|
||||
|
||||
V2 corner = e1.p2;
|
||||
|
||||
V2 d1 = vec2_normalize(vec2_sub(e1.p2, e1.p1));
|
||||
V2 d2 = vec2_normalize(vec2_sub(e2.p2, e2.p1));
|
||||
|
||||
V2 n1 = vec2_perp(d1);
|
||||
V2 n2 = vec2_perp(d2);
|
||||
|
||||
V2 off1 = vec2_scale(n1, hw);
|
||||
V2 off2 = vec2_scale(n2, hw);
|
||||
|
||||
V2 v10 = vec2_add(e1.p1, off1);
|
||||
V2 v11 = vec2_sub(e1.p1, off1);
|
||||
V2 v12 = vec2_add(e1.p2, off1);
|
||||
V2 v13 = vec2_sub(e1.p2, off1);
|
||||
|
||||
V2 v20 = vec2_add(e2.p1, off2);
|
||||
V2 v21 = vec2_sub(e2.p1, off2);
|
||||
V2 v22 = vec2_add(e2.p2, off2);
|
||||
V2 v23 = vec2_sub(e2.p2, off2);
|
||||
|
||||
V2 outer1 = vec2_add(corner, off1);
|
||||
V2 outer2 = vec2_add(corner, off2);
|
||||
|
||||
V2 inner1 = vec2_sub(corner, off1);
|
||||
V2 inner2 = vec2_sub(corner, off2);
|
||||
|
||||
float cos_theta = vec2_dot(d1, d2);
|
||||
float sin_half = sqrtf((1.0f - cos_theta) * 0.5f);
|
||||
float miter_len = hw / sin_half;
|
||||
|
||||
if (miter_len > 4.0 * hw || miter_len < 1.05 * hw) {
|
||||
vektor_vb_add_triangle(vb, outer1, corner, outer2,
|
||||
style.stroke_color);
|
||||
vektor_vb_add_triangle(vb, inner1, corner, inner2,
|
||||
style.stroke_color);
|
||||
continue;
|
||||
}
|
||||
|
||||
V2 outer_miter = line_intersection(vec2_add(corner, off1), d1,
|
||||
vec2_add(corner, off2), d2);
|
||||
|
||||
V2 inner_miter = line_intersection(vec2_sub(corner, off1), d1,
|
||||
vec2_sub(corner, off2), d2);
|
||||
|
||||
V2 mo = vec2_sub(outer_miter, corner);
|
||||
V2 mi = vec2_sub(inner_miter, corner);
|
||||
|
||||
V2 vo1 = line_intersection(corner, vec2_normalize(vec2_perp(mo)),
|
||||
vec2_add(corner, off1), d1);
|
||||
V2 vo2 = line_intersection(corner,
|
||||
vec2_negate(vec2_normalize(vec2_perp(mo))),
|
||||
vec2_add(corner, off2), d2);
|
||||
|
||||
V2 vi1 = line_intersection(corner, vec2_normalize(vec2_perp(mi)),
|
||||
vec2_sub(corner, off1), d1);
|
||||
V2 vi2 = line_intersection(corner,
|
||||
vec2_negate(vec2_normalize(vec2_perp(mi))),
|
||||
vec2_sub(corner, off2), d2);
|
||||
|
||||
vektor_vb_add_triangle(vb, vo1, outer_miter, vo2, style.stroke_color);
|
||||
vektor_vb_add_triangle(vb, vi1, inner_miter, vi2, style.stroke_color);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "primitives.h"
|
||||
|
||||
#include "../util/color.h"
|
||||
#include "src/core/modifier.h"
|
||||
#include "stddef.h"
|
||||
#include "vector.h"
|
||||
#include <stddef.h>
|
||||
@@ -23,8 +24,14 @@ typedef struct {
|
||||
|
||||
void vektor_edgebuffer_add_edge(EdgeBuffer* edges, Edge edge);
|
||||
|
||||
void vektor_polyline_flatten(EdgeBuffer* edges, VektorPolyline* line, size_t i);
|
||||
void vektor_polygon_flatten(EdgeBuffer* buffer, VektorPolygon* line, size_t i);
|
||||
void vektor_polyline_tessellate(EdgeBuffer* edges, VektorPolyline* line,
|
||||
size_t i, double scale);
|
||||
void vektor_polygon_tessellate(EdgeBuffer* buffer, VektorPolygon* polygon,
|
||||
size_t i, double scale);
|
||||
void vektor_circle_tessellate(EdgeBuffer* buffer, VektorCircle* circle,
|
||||
size_t i, double scale);
|
||||
void vektor_rectangle_tessellate(EdgeBuffer* buffer, VektorRectangle* rct,
|
||||
size_t i, double scale);
|
||||
|
||||
typedef struct {
|
||||
V2 coords;
|
||||
@@ -37,11 +44,15 @@ typedef struct {
|
||||
size_t capacity;
|
||||
} VertexBuffer;
|
||||
|
||||
void vb_add_triangle(VertexBuffer* vb, V2 v0, V2 v1, V2 v2, VektorColor color);
|
||||
void vektor_vb_add_triangle(VertexBuffer* vb, V2 v0, V2 v1, V2 v2,
|
||||
VektorColor color);
|
||||
void vektor_vb_add_quad(VertexBuffer* vb, V2 v0, V2 v1, VektorColor color);
|
||||
|
||||
void vektor_edge_to_triangles(VertexBuffer* vb, Edge e,
|
||||
VektorShapeBuffer* shape_buffer);
|
||||
VektorShapeNodeBuffer* node_buffer);
|
||||
void vektor_edges_to_triangles(VertexBuffer* vb, EdgeBuffer* edges,
|
||||
VektorShapeBuffer* shape_buffer);
|
||||
void vektor_rasterize(VertexBuffer* vb, VektorShapeBuffer* shapes);
|
||||
M33* transform, VektorStyle style, bool closed);
|
||||
void vektor_vb_rasterize(VertexBuffer* vb, VektorShapeNodeBuffer* shapes,
|
||||
double scale);
|
||||
|
||||
#endif // RASTER_H_
|
||||
|
||||
@@ -14,14 +14,24 @@ typedef struct {
|
||||
double z;
|
||||
} V3;
|
||||
|
||||
static inline V2 vec2_fromfloat(const float f) { return (V2){f, f}; }
|
||||
|
||||
static inline V3 vec2_vector(const V2 v) { return (V3){v.x, v.y, 0}; }
|
||||
|
||||
static inline V3 vec2_point(const V2 v) { return (V3){v.x, v.y, 1}; }
|
||||
|
||||
static inline V2 vec2_perp(const V2 v) { return (V2){-v.y, v.x}; }
|
||||
|
||||
static inline V2 vec2_negate(const V2 v) { return (V2){-v.x, -v.y}; }
|
||||
|
||||
static inline V2 vec2_add(const V2 v1, const V2 v2) {
|
||||
return (V2){v1.x + v2.x, v1.y + v2.y};
|
||||
}
|
||||
|
||||
static inline bool vec2_equals(const V2 v1, const V2 v2) {
|
||||
return (bool)(v1.x == v2.x && v1.y == v2.x);
|
||||
}
|
||||
|
||||
static inline V2 vec2_sub(const V2 v1, const V2 v2) {
|
||||
return (V2){v1.x - v2.x, v1.y - v2.y};
|
||||
}
|
||||
@@ -42,16 +52,16 @@ static inline double vec2_cross(const V2 a, const V2 b) {
|
||||
return a.x * b.y - a.y * b.x;
|
||||
}
|
||||
|
||||
static inline double vec2_norm(const V2 v) {
|
||||
static inline double vec2_length(const V2 v) {
|
||||
return sqrt(v.x * v.x + v.y * v.y);
|
||||
}
|
||||
|
||||
static inline double vec2_quadrance(const V2 v) {
|
||||
static inline double vec2_lengthsq(const V2 v) {
|
||||
return (v.x * v.x + v.y * v.y);
|
||||
}
|
||||
|
||||
static inline V2 vec2_normalize(const V2 v) {
|
||||
return vec2_scale(v, 1 / vec2_norm(v));
|
||||
return vec2_scale(v, 1 / vec2_length(v));
|
||||
}
|
||||
|
||||
#endif // VECTOR_H_
|
||||
|
||||
15
src/main.c
15
src/main.c
@@ -1,17 +1,17 @@
|
||||
#include "glib.h"
|
||||
#include "gtk/gtk.h"
|
||||
#include "src/application/applicationstate.h"
|
||||
#include "src/core/primitives.h"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
#include "./application/applicationstate.h"
|
||||
#include "./core/raster.h"
|
||||
#include "./ui/uicontroller.h"
|
||||
#include "./ui/vektorcanvas.h"
|
||||
#include "./util/color.h"
|
||||
|
||||
static void on_map(GtkWidget* window, gpointer user_data) {
|
||||
vektor_uictrl_map((VektorWidgetState*)user_data);
|
||||
static int update_callback(gpointer data) {
|
||||
VektorAppState* appstate = (VektorAppState*)data;
|
||||
gtk_gl_area_queue_render(
|
||||
GTK_GL_AREA(appstate->widgetState->workspaceCanvas));
|
||||
return G_SOURCE_CONTINUE;
|
||||
}
|
||||
|
||||
static void activate(GtkApplication* app, gpointer user_data) {
|
||||
@@ -22,8 +22,7 @@ static void activate(GtkApplication* app, gpointer user_data) {
|
||||
VektorAppState* app_state = (VektorAppState*)malloc(sizeof(VektorAppState));
|
||||
vektor_appstate_new(widget_state, app_state);
|
||||
|
||||
g_signal_connect(widget_state->window, "map", G_CALLBACK(on_map),
|
||||
widget_state);
|
||||
g_timeout_add(1, update_callback, app_state);
|
||||
|
||||
gtk_window_present(widget_state->window);
|
||||
}
|
||||
|
||||
@@ -31,16 +31,13 @@ void vektor_uictrl_init(GtkApplication* app, VektorWidgetState* stateOut) {
|
||||
GtkIconTheme* theme =
|
||||
gtk_icon_theme_get_for_display(gdk_display_get_default());
|
||||
|
||||
/*if (gtk_icon_theme_has_icon(theme, "vektor-circle-symbolic"))
|
||||
g_print("GTK sees it!\n");
|
||||
else
|
||||
g_print("Still invisible...\n");*/
|
||||
|
||||
// populate state
|
||||
stateOut->window =
|
||||
GTK_WINDOW(gtk_builder_get_object(builder, "main_window"));
|
||||
stateOut->workspacePaned =
|
||||
GTK_PANED(gtk_builder_get_object(builder, "workspace_paned"));
|
||||
stateOut->sidepanelPaned =
|
||||
GTK_PANED(gtk_builder_get_object(builder, "sidepanel"));
|
||||
stateOut->workspaceCanvas =
|
||||
GTK_GL_AREA(gtk_builder_get_object(builder, "workspace"));
|
||||
|
||||
@@ -48,23 +45,34 @@ void vektor_uictrl_init(GtkApplication* app, VektorWidgetState* stateOut) {
|
||||
GTK_BUTTON(gtk_builder_get_object(builder, "button_shapetools"));
|
||||
stateOut->workspaceRevealerShapes =
|
||||
GTK_REVEALER(gtk_builder_get_object(builder, "shape_revealer"));
|
||||
stateOut->workspaceButtonLinetool =
|
||||
stateOut->workspaceButtonLineTool =
|
||||
GTK_BUTTON(gtk_builder_get_object(builder, "button_linetool"));
|
||||
stateOut->workspaceButtonRecttool =
|
||||
stateOut->workspaceButtonRectTool =
|
||||
GTK_BUTTON(gtk_builder_get_object(builder, "button_rectangletool"));
|
||||
stateOut->workspaceButtonCircletool =
|
||||
stateOut->workspaceButtonCircleTool =
|
||||
GTK_BUTTON(gtk_builder_get_object(builder, "button_circletool"));
|
||||
stateOut->workspaceButtonPolygonTool =
|
||||
GTK_BUTTON(gtk_builder_get_object(builder, "button_polygontool"));
|
||||
stateOut->workspaceButtonSelectionTool =
|
||||
GTK_BUTTON(gtk_builder_get_object(builder, "button_selecttool"));
|
||||
stateOut->workspaceColorPicker =
|
||||
VEKTOR_COLOR_WHEEL(gtk_builder_get_object(builder, "color_picker"));
|
||||
|
||||
stateOut->sidepanelEntryR =
|
||||
GTK_ENTRY(gtk_builder_get_object(builder, "spin_color_r"));
|
||||
stateOut->sidepanelEntryG =
|
||||
GTK_ENTRY(gtk_builder_get_object(builder, "spin_color_g"));
|
||||
stateOut->sidepanelEntryB =
|
||||
GTK_ENTRY(gtk_builder_get_object(builder, "spin_color_b"));
|
||||
|
||||
// Set window properties
|
||||
gtk_window_set_application(stateOut->window, app);
|
||||
gtk_window_set_title(stateOut->window, "Vektor");
|
||||
gtk_window_set_default_size(stateOut->window, 800, 600);
|
||||
|
||||
// Set dimensions
|
||||
gtk_paned_set_position(stateOut->workspacePaned, 800 * .7);
|
||||
gtk_paned_set_position(stateOut->sidepanelPaned, 250);
|
||||
|
||||
g_object_unref(builder);
|
||||
}
|
||||
|
||||
void vektor_uictrl_map(VektorWidgetState* state) {
|
||||
gtk_paned_set_position(state->workspacePaned, 800 * .7);
|
||||
}
|
||||
|
||||
@@ -12,16 +12,23 @@ all the widgets used in internal logic of the program
|
||||
typedef struct VektorWidgetState {
|
||||
GtkWindow* window;
|
||||
GtkPaned* workspacePaned;
|
||||
GtkPaned* sidepanelPaned;
|
||||
GtkGLArea* workspaceCanvas;
|
||||
|
||||
GtkButton* workspaceButtonMasterShapes;
|
||||
GtkRevealer* workspaceRevealerShapes;
|
||||
GtkButton* workspaceButtonLinetool;
|
||||
GtkButton* workspaceButtonRecttool;
|
||||
GtkButton* workspaceButtonCircletool;
|
||||
GtkButton* workspaceButtonLineTool;
|
||||
GtkButton* workspaceButtonRectTool;
|
||||
GtkButton* workspaceButtonCircleTool;
|
||||
GtkButton* workspaceButtonPolygonTool;
|
||||
GtkButton* workspaceButtonSelectionTool;
|
||||
|
||||
VektorColorWheel* workspaceColorPicker;
|
||||
|
||||
GtkEntry* sidepanelEntryR;
|
||||
GtkEntry* sidepanelEntryG;
|
||||
GtkEntry* sidepanelEntryB;
|
||||
|
||||
// GtkWidget* Workspace
|
||||
} VektorWidgetState;
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
#include "epoxy/gl.h"
|
||||
#include "glib.h"
|
||||
#include "gtk/gtk.h"
|
||||
|
||||
#include "../core/raster.h"
|
||||
#include "src/core/matrix.h"
|
||||
#include "src/core/primitives.h"
|
||||
#include "src/util/color.h"
|
||||
#include "uicontroller.h"
|
||||
#include "vektorcanvas.h"
|
||||
#include <epoxy/gl_generated.h>
|
||||
@@ -27,9 +30,23 @@ char* read_file(const char* path) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static GLuint shader_program;
|
||||
static GLuint standard_shader_program;
|
||||
static GLuint selection_shader_program;
|
||||
|
||||
// shader uniforms
|
||||
static GLuint shader_standard_uProjMatrixLoc;
|
||||
|
||||
static GLuint shader_selection_uProjMatrixLoc;
|
||||
static GLuint shader_selection_uTimeLoc;
|
||||
static GLuint shader_selection_uScaleLoc;
|
||||
static GLuint shader_selection_uC1Loc;
|
||||
static GLuint shader_selection_uC2Loc;
|
||||
static GLuint shader_selection_uMinLoc;
|
||||
static GLuint shader_selection_uMaxLoc;
|
||||
|
||||
static GLuint vao;
|
||||
VertexBuffer vb;
|
||||
static size_t shape_vertex_count = 0;
|
||||
|
||||
static GLuint compile_shader(GLenum type, const char* src) {
|
||||
GLuint shader = glCreateShader(type);
|
||||
@@ -46,17 +63,11 @@ static GLuint compile_shader(GLenum type, const char* src) {
|
||||
return shader;
|
||||
}
|
||||
|
||||
static void init_shader(void) {
|
||||
char* vert_src = read_file("./shaders/triangle.vert.glsl");
|
||||
char* frag_src = read_file("./shaders/triangle.frag.glsl");
|
||||
static GLuint create_shader_program(char* frag, char* vert) {
|
||||
GLuint vertex = compile_shader(GL_VERTEX_SHADER, vert);
|
||||
GLuint fragment = compile_shader(GL_FRAGMENT_SHADER, frag);
|
||||
|
||||
if (!vert_src || !frag_src)
|
||||
g_error("Failed to load shader files");
|
||||
|
||||
GLuint vertex = compile_shader(GL_VERTEX_SHADER, vert_src);
|
||||
GLuint fragment = compile_shader(GL_FRAGMENT_SHADER, frag_src);
|
||||
|
||||
shader_program = glCreateProgram();
|
||||
GLuint shader_program = glCreateProgram();
|
||||
glAttachShader(shader_program, vertex);
|
||||
glAttachShader(shader_program, fragment);
|
||||
glLinkProgram(shader_program);
|
||||
@@ -71,6 +82,42 @@ static void init_shader(void) {
|
||||
|
||||
glDeleteShader(vertex);
|
||||
glDeleteShader(fragment);
|
||||
|
||||
return shader_program;
|
||||
}
|
||||
|
||||
static void init_shader(void) {
|
||||
char* vert_src = read_file("./shaders/triangle.vert.glsl");
|
||||
char* frag_src = read_file("./shaders/triangle.frag.glsl");
|
||||
char* selection_frag_src = read_file("./shaders/selection.frag.glsl");
|
||||
|
||||
if (!vert_src || !frag_src)
|
||||
g_error("Failed to load shader files");
|
||||
|
||||
standard_shader_program = create_shader_program(frag_src, vert_src);
|
||||
selection_shader_program =
|
||||
create_shader_program(selection_frag_src, vert_src);
|
||||
|
||||
shader_standard_uProjMatrixLoc =
|
||||
glGetUniformLocation(standard_shader_program, "uProjection");
|
||||
shader_selection_uProjMatrixLoc =
|
||||
glGetUniformLocation(selection_shader_program, "uProjection");
|
||||
shader_selection_uTimeLoc =
|
||||
glGetUniformLocation(selection_shader_program, "uTime");
|
||||
shader_selection_uScaleLoc =
|
||||
glGetUniformLocation(selection_shader_program, "uScale");
|
||||
shader_selection_uC1Loc =
|
||||
glGetUniformLocation(selection_shader_program, "uColor1");
|
||||
shader_selection_uC2Loc =
|
||||
glGetUniformLocation(selection_shader_program, "uColor2");
|
||||
|
||||
shader_selection_uMinLoc =
|
||||
glGetUniformLocation(selection_shader_program, "uMin");
|
||||
shader_selection_uMaxLoc =
|
||||
glGetUniformLocation(selection_shader_program, "uMax");
|
||||
|
||||
if (shader_selection_uMinLoc == -1 || shader_selection_uMaxLoc == -1)
|
||||
g_warning("Selection shader: uMin/uMax uniform not found in shader!");
|
||||
}
|
||||
|
||||
static void init_geometry(void) {
|
||||
@@ -92,19 +139,52 @@ static void init_geometry(void) {
|
||||
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
static gboolean render(GtkGLArea* area, GdkGLContext* context,
|
||||
VektorShapeBuffer* prims) {
|
||||
vektor_rasterize(&vb, prims);
|
||||
|
||||
void vektor_canvas_geometry_changed(VektorCanvasRenderInfo* renderInfo) {
|
||||
vb.count = 0;
|
||||
vektor_vb_rasterize(&vb, renderInfo->shapes, renderInfo->zoom);
|
||||
shape_vertex_count = vb.count;
|
||||
|
||||
if (renderInfo->selectedShape != NULL &&
|
||||
*(renderInfo->selectedShape) != NULL) {
|
||||
|
||||
VektorShapeNode* selectedShape = *renderInfo->selectedShape;
|
||||
|
||||
// create handle quads if a shape is selected
|
||||
for (size_t i = 0; i < selectedShape->base->handleCount; i++) {
|
||||
V2 handle = selectedShape->base->handles[i];
|
||||
VektorBBox handleBbox = vektor_shape_get_handle_bbox(handle);
|
||||
vektor_vb_add_quad(&vb, handleBbox.min, handleBbox.max,
|
||||
vektor_color_new(255, 255, 255, 255));
|
||||
}
|
||||
|
||||
shape_vertex_count = vb.count;
|
||||
|
||||
// create selection quad if a shape is selected
|
||||
VektorBBox bbox =
|
||||
vektor_primitive_get_bbox(selectedShape->base->primitive);
|
||||
// expand it a little so it is not inset
|
||||
bbox = vektor_bbox_expand(bbox, 0.03f);
|
||||
|
||||
vektor_vb_add_quad(&vb, bbox.min, bbox.max,
|
||||
vektor_color_new(255, 255, 255, 255));
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean render(GtkGLArea* a, GdkGLContext* ctx,
|
||||
VektorCanvasRenderInfo* renderInfo) {
|
||||
// vektor_canvas_geometry_changed(renderInfo);
|
||||
|
||||
glBufferData(GL_ARRAY_BUFFER, vb.count * sizeof(Vertex), vb.vertices,
|
||||
GL_STATIC_DRAW);
|
||||
|
||||
glUseProgram(shader_program);
|
||||
// PASS 1 - draw shape vertices
|
||||
glUseProgram(standard_shader_program);
|
||||
|
||||
GLuint uProjectionLoc = glGetUniformLocation(shader_program, "uProjection");
|
||||
float projectionMatrix[16] = {1, 0, 0, 0, 0, 1, 0, 0,
|
||||
0, 0, 1, 0, 0, 0, 0, 1};
|
||||
glUniformMatrix4fv(uProjectionLoc, 1, GL_FALSE, projectionMatrix);
|
||||
// float projectionMatrix[16] = {1, 0, 0, 0, 0, 1, 0, 0,
|
||||
// 0, 0, 1, 0, 0, 0, 0, 1};
|
||||
glUniformMatrix4fv(shader_standard_uProjMatrixLoc, 1, GL_FALSE,
|
||||
renderInfo->canvasTransform);
|
||||
|
||||
glBindVertexArray(vao);
|
||||
glDisable(GL_CULL_FACE);
|
||||
@@ -112,10 +192,34 @@ static gboolean render(GtkGLArea* area, GdkGLContext* context,
|
||||
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, vb.count);
|
||||
GLenum err = glGetError();
|
||||
//printf("OpenGL error: %x\n", err);
|
||||
// glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
||||
glDrawArrays(GL_TRIANGLES, 0, shape_vertex_count);
|
||||
|
||||
// PASS 2 - draw selection quads
|
||||
if (vb.count > shape_vertex_count) {
|
||||
// g_print("vdelta: %zu\n", vb.count - shape_vertex_count);
|
||||
float time =
|
||||
(g_get_monotonic_time() - renderInfo->startupTime) / 10000000.0f;
|
||||
|
||||
// re-fetch bbox (we know a shape is selected)
|
||||
VektorBBox bbox = vektor_primitive_get_bbox(
|
||||
(*(renderInfo->selectedShape))->base->primitive);
|
||||
bbox = vektor_bbox_expand(bbox, 0.03f);
|
||||
|
||||
glUseProgram(selection_shader_program);
|
||||
|
||||
glUniformMatrix4fv(shader_selection_uProjMatrixLoc, 1, GL_FALSE,
|
||||
renderInfo->canvasTransform);
|
||||
glUniform1f(shader_selection_uTimeLoc, time);
|
||||
glUniform1f(shader_selection_uScaleLoc, renderInfo->zoom);
|
||||
glUniform2f(shader_selection_uMinLoc, bbox.min.x, bbox.min.y);
|
||||
glUniform2f(shader_selection_uMaxLoc, bbox.max.x, bbox.max.y);
|
||||
glUniform4f(shader_selection_uC1Loc, 0, 0, 0, 0);
|
||||
glUniform4f(shader_selection_uC2Loc, 0.46, 0.46, 1, 1);
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, shape_vertex_count,
|
||||
vb.count - shape_vertex_count);
|
||||
}
|
||||
|
||||
glBindVertexArray(0);
|
||||
glUseProgram(0);
|
||||
|
||||
@@ -160,8 +264,110 @@ static void realize(GtkGLArea* area, gpointer user_data) {
|
||||
init_geometry();
|
||||
}
|
||||
|
||||
static void on_scroll(GtkEventControllerScroll* controller, double dx,
|
||||
double dy, gpointer user_data) {
|
||||
VektorCanvasRenderInfo* s = user_data;
|
||||
|
||||
GdkModifierType state = gtk_event_controller_get_current_event_state(
|
||||
GTK_EVENT_CONTROLLER(controller));
|
||||
|
||||
// if (state & GDK_CONTROL_MASK) {
|
||||
|
||||
if (dy < 0)
|
||||
s->zoom *= 1.1f;
|
||||
else if (dy > 0)
|
||||
s->zoom *= 0.9f;
|
||||
|
||||
M33 mat =
|
||||
m33_mul(m33_translate(s->panX, s->panY),
|
||||
m33_mul(m33_rotate(s->rotation), m33_scale(s->zoom, s->zoom)));
|
||||
|
||||
m33_to_gl4(mat, s->canvasTransform);
|
||||
s->canvasMat = mat;
|
||||
|
||||
GtkWidget* widget =
|
||||
gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(controller));
|
||||
|
||||
vektor_canvas_geometry_changed(s);
|
||||
|
||||
}
|
||||
|
||||
static void on_pan_begin(GtkGestureDrag* gesture, double start_x,
|
||||
double start_y, gpointer user_data) {
|
||||
VektorCanvasRenderInfo* s = user_data;
|
||||
|
||||
GdkModifierType state = gtk_event_controller_get_current_event_state(
|
||||
GTK_EVENT_CONTROLLER(gesture));
|
||||
|
||||
if (!(state & GDK_SHIFT_MASK)) {
|
||||
s->drag_start_x = s->panX;
|
||||
s->drag_start_y = s->panY;
|
||||
} else {
|
||||
double x, y;
|
||||
gtk_gesture_drag_get_start_point(gesture, &x, &y);
|
||||
|
||||
s->mouse_start_x = x;
|
||||
s->mouse_start_y = y;
|
||||
|
||||
double cx = VKTR_CANVAS_WIDTH * 0.5;
|
||||
double cy = VKTR_CANVAS_HEIGHT * 0.5;
|
||||
|
||||
double dx = x - cx;
|
||||
double dy = y - cy;
|
||||
|
||||
s->dragStartAngle = atan2(dy, dx);
|
||||
s->dragStartRotation = s->rotation;
|
||||
}
|
||||
}
|
||||
|
||||
static void on_pan_drag(GtkGestureDrag* gesture, double offset_x,
|
||||
double offset_y, gpointer user_data) {
|
||||
VektorCanvasRenderInfo* s = user_data;
|
||||
|
||||
GdkModifierType state = gtk_event_controller_get_current_event_state(
|
||||
GTK_EVENT_CONTROLLER(gesture));
|
||||
|
||||
if (!(state & GDK_SHIFT_MASK)) {
|
||||
s->panX = s->drag_start_x + offset_x / (80 * s->zoom);
|
||||
s->panY = s->drag_start_y - offset_y / (80 * s->zoom);
|
||||
|
||||
M33 mat = m33_mul(
|
||||
m33_translate(s->panX, s->panY),
|
||||
m33_mul(m33_rotate(s->rotation), m33_scale(s->zoom, s->zoom)));
|
||||
m33_to_gl4(mat, s->canvasTransform);
|
||||
s->canvasMat = mat;
|
||||
} else {
|
||||
double x, y;
|
||||
gtk_gesture_drag_get_offset(gesture, &x, &y);
|
||||
|
||||
double mx = s->mouse_start_x + x;
|
||||
double my = s->mouse_start_y + y;
|
||||
|
||||
double cx = VKTR_CANVAS_WIDTH * 0.5;
|
||||
double cy = VKTR_CANVAS_HEIGHT * 0.5;
|
||||
|
||||
double dx = mx - cx;
|
||||
double dy = my - cy;
|
||||
|
||||
double angle = -atan2(dy, dx);
|
||||
|
||||
s->rotation = s->dragStartRotation + (angle - s->dragStartAngle);
|
||||
|
||||
M33 mat = m33_mul(
|
||||
m33_translate(s->panX, s->panY),
|
||||
m33_mul(m33_rotate(s->rotation), m33_scale(s->zoom, s->zoom)));
|
||||
m33_to_gl4(mat, s->canvasTransform);
|
||||
s->canvasMat = mat;
|
||||
}
|
||||
GtkWidget* widget =
|
||||
gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(gesture));
|
||||
|
||||
//gtk_gl_area_queue_render(GTK_GL_AREA(widget));
|
||||
vektor_canvas_geometry_changed(s);
|
||||
}
|
||||
|
||||
void vektor_canvas_init(VektorWidgetState* state, VektorCanvas* canvasOut,
|
||||
VektorShapeBuffer* prims) {
|
||||
VektorCanvasRenderInfo* renderInfo) {
|
||||
canvasOut->canvasWidget = state->workspaceCanvas;
|
||||
canvasOut->width = VKTR_CANVAS_WIDTH;
|
||||
canvasOut->height = VKTR_CANVAS_HEIGHT;
|
||||
@@ -176,5 +382,21 @@ void vektor_canvas_init(VektorWidgetState* state, VektorCanvas* canvasOut,
|
||||
g_signal_connect(canvasOut->canvasWidget, "realize", G_CALLBACK(realize),
|
||||
NULL);
|
||||
g_signal_connect(canvasOut->canvasWidget, "render", G_CALLBACK(render),
|
||||
prims);
|
||||
renderInfo);
|
||||
|
||||
GtkEventController* scroll =
|
||||
gtk_event_controller_scroll_new(GTK_EVENT_CONTROLLER_SCROLL_VERTICAL);
|
||||
|
||||
gtk_widget_add_controller(GTK_WIDGET(canvasOut->canvasWidget), scroll);
|
||||
|
||||
g_signal_connect(scroll, "scroll", G_CALLBACK(on_scroll), renderInfo);
|
||||
|
||||
GtkGesture* pan = gtk_gesture_drag_new();
|
||||
gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(pan), GDK_BUTTON_MIDDLE);
|
||||
|
||||
gtk_widget_add_controller(GTK_WIDGET(canvasOut->canvasWidget),
|
||||
GTK_EVENT_CONTROLLER(pan));
|
||||
|
||||
g_signal_connect(pan, "drag-begin", G_CALLBACK(on_pan_begin), renderInfo);
|
||||
g_signal_connect(pan, "drag-update", G_CALLBACK(on_pan_drag), renderInfo);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
#include "../core/raster.h"
|
||||
#include "../util/color.h"
|
||||
#include "gtk/gtk.h"
|
||||
#include "src/core/matrix.h"
|
||||
#include "src/core/modifier.h"
|
||||
#include "src/core/primitives.h"
|
||||
#include "uicontroller.h"
|
||||
|
||||
typedef struct VektorCanvas {
|
||||
@@ -18,8 +21,31 @@ typedef struct VektorCanvas {
|
||||
int height;
|
||||
} VektorCanvas;
|
||||
|
||||
typedef struct VektorCanvasRenderInfo {
|
||||
gint64 startupTime;
|
||||
VektorShapeNodeBuffer* shapes;
|
||||
|
||||
// a pointer to appstate->selectedShape
|
||||
VektorShapeNode** selectedShape;
|
||||
float zoom;
|
||||
float panX;
|
||||
float panY;
|
||||
float rotation;
|
||||
|
||||
float dragStartRotation;
|
||||
double dragStartAngle;
|
||||
double drag_start_x;
|
||||
double drag_start_y;
|
||||
double mouse_start_x;
|
||||
double mouse_start_y;
|
||||
|
||||
M33 canvasMat;
|
||||
float canvasTransform[16];
|
||||
} VektorCanvasRenderInfo;
|
||||
|
||||
void vektor_canvas_init(VektorWidgetState* state, VektorCanvas* canvasOut,
|
||||
VektorShapeBuffer* shapes);
|
||||
VektorCanvasRenderInfo* renderInfo);
|
||||
void vektor_canvas_geometry_changed(VektorCanvasRenderInfo* renderInfo);
|
||||
// void vektor_canvas_update(VektorCanvas* canvas);
|
||||
// void vektor_canvas_fill(VektorCanvas* canvas, VektorColor color);
|
||||
// void vektor_canvas_drawfrom(VektorFramebuffer* fb, VektorCanvas* canvas);
|
||||
|
||||
@@ -21,31 +21,70 @@ struct _VektorColorWheel {
|
||||
|
||||
G_DEFINE_TYPE(VektorColorWheel, vektor_color_wheel, GTK_TYPE_DRAWING_AREA)
|
||||
|
||||
static gboolean point_in_triangle(
|
||||
double px, double py,
|
||||
double ax, double ay,
|
||||
double bx, double by,
|
||||
double cx, double cy,
|
||||
double* u, double* v, double* w)
|
||||
{
|
||||
double denom =
|
||||
(by - cy)*(ax - cx) +
|
||||
(cx - bx)*(ay - cy);
|
||||
static gboolean point_in_triangle(double px, double py, double ax, double ay,
|
||||
double bx, double by, double cx, double cy,
|
||||
double* u, double* v, double* w) {
|
||||
double denom = (by - cy) * (ax - cx) + (cx - bx) * (ay - cy);
|
||||
|
||||
*u =
|
||||
((by - cy)*(px - cx) +
|
||||
(cx - bx)*(py - cy)) / denom;
|
||||
*u = ((by - cy) * (px - cx) + (cx - bx) * (py - cy)) / denom;
|
||||
|
||||
*v =
|
||||
((cy - ay)*(px - cx) +
|
||||
(ax - cx)*(py - cy)) / denom;
|
||||
*v = ((cy - ay) * (px - cx) + (ax - cx) * (py - cy)) / denom;
|
||||
|
||||
*w = 1 - *u - *v;
|
||||
|
||||
return (*u >= 0 && *v >= 0 && *w >= 0);
|
||||
}
|
||||
|
||||
static void vektor_color_wheel_snapshot(GtkWidget* widget, GtkSnapshot* snapshot) {
|
||||
static void closest_point_on_segment(double px, double py, double ax, double ay,
|
||||
double bx, double by, double* rx,
|
||||
double* ry) {
|
||||
double abx = bx - ax;
|
||||
double aby = by - ay;
|
||||
|
||||
double apx = px - ax;
|
||||
double apy = py - ay;
|
||||
|
||||
double t = (apx * abx + apy * aby) / (abx * abx + aby * aby);
|
||||
|
||||
if (t < 0)
|
||||
t = 0;
|
||||
if (t > 1)
|
||||
t = 1;
|
||||
|
||||
*rx = ax + abx * t;
|
||||
*ry = ay + aby * t;
|
||||
}
|
||||
|
||||
static void closest_point_on_triangle(double px, double py, double ax,
|
||||
double ay, double bx, double by,
|
||||
double cx, double cy, double* rx,
|
||||
double* ry) {
|
||||
double p1x, p1y;
|
||||
double p2x, p2y;
|
||||
double p3x, p3y;
|
||||
|
||||
closest_point_on_segment(px, py, ax, ay, bx, by, &p1x, &p1y);
|
||||
closest_point_on_segment(px, py, bx, by, cx, cy, &p2x, &p2y);
|
||||
closest_point_on_segment(px, py, cx, cy, ax, ay, &p3x, &p3y);
|
||||
|
||||
double d1 = (px - p1x) * (px - p1x) + (py - p1y) * (py - p1y);
|
||||
double d2 = (px - p2x) * (px - p2x) + (py - p2y) * (py - p2y);
|
||||
double d3 = (px - p3x) * (px - p3x) + (py - p3y) * (py - p3y);
|
||||
|
||||
if (d1 <= d2 && d1 <= d3) {
|
||||
*rx = p1x;
|
||||
*ry = p1y;
|
||||
} else if (d2 <= d3) {
|
||||
*rx = p2x;
|
||||
*ry = p2y;
|
||||
} else {
|
||||
*rx = p3x;
|
||||
*ry = p3y;
|
||||
}
|
||||
}
|
||||
|
||||
static void vektor_color_wheel_snapshot(GtkWidget* widget,
|
||||
GtkSnapshot* snapshot) {
|
||||
VektorColorWheel* self = VEKTOR_COLOR_WHEEL(widget);
|
||||
|
||||
int width = gtk_widget_get_width(widget);
|
||||
@@ -108,16 +147,20 @@ static void vektor_color_wheel_snapshot(GtkWidget* widget, GtkSnapshot* snapshot
|
||||
|
||||
// White gradient: from pure hue (right) → white (bottom)
|
||||
cairo_pattern_t* white = cairo_pattern_create_linear(ax, ay, bx, by);
|
||||
cairo_pattern_add_color_stop_rgba(white, 0.0, 1,1,1, 0.0); // transparent at pure hue
|
||||
cairo_pattern_add_color_stop_rgba(white, 1.0, 1,1,1, 1.0); // opaque white at bottom
|
||||
cairo_pattern_add_color_stop_rgba(white, 0.0, 1, 1, 1,
|
||||
0.0); // transparent at pure hue
|
||||
cairo_pattern_add_color_stop_rgba(white, 1.0, 1, 1, 1,
|
||||
1.0); // opaque white at bottom
|
||||
cairo_set_source(cr, white);
|
||||
cairo_paint(cr);
|
||||
cairo_pattern_destroy(white);
|
||||
|
||||
// Black gradient: from pure hue (right) → black (top)
|
||||
cairo_pattern_t* black = cairo_pattern_create_linear(ax, ay, cx2, cy2);
|
||||
cairo_pattern_add_color_stop_rgba(black, 0.0, 0,0,0, 0.0); // transparent at pure hue
|
||||
cairo_pattern_add_color_stop_rgba(black, 1.0, 0,0,0, 1.0); // opaque black at top
|
||||
cairo_pattern_add_color_stop_rgba(black, 0.0, 0, 0, 0,
|
||||
0.0); // transparent at pure hue
|
||||
cairo_pattern_add_color_stop_rgba(black, 1.0, 0, 0, 0,
|
||||
1.0); // opaque black at top
|
||||
cairo_set_source(cr, black);
|
||||
cairo_paint(cr);
|
||||
cairo_pattern_destroy(black);
|
||||
@@ -147,7 +190,7 @@ static void vektor_color_wheel_snapshot(GtkWidget* widget, GtkSnapshot* snapshot
|
||||
cairo_arc(cr, px, py, 5, 0, 2 * M_PI);
|
||||
|
||||
float fr, fg, fb;
|
||||
vektor_colorout_wheel_get_color(self, &fr, &fg, &fb);
|
||||
vektor_color_wheel_get_colorout(self, &fr, &fg, &fb);
|
||||
cairo_set_source_rgb(cr, fr, fg, fb);
|
||||
cairo_fill_preserve(cr);
|
||||
cairo_set_source_rgb(cr, 0.1, 0.1, 0.1);
|
||||
@@ -160,15 +203,10 @@ static void vektor_color_wheel_snapshot(GtkWidget* widget, GtkSnapshot* snapshot
|
||||
|
||||
cairo_new_path(cr);
|
||||
|
||||
cairo_arc(cr,
|
||||
cx, cy,
|
||||
wheel_radius,
|
||||
selector_angle - selector_width,
|
||||
cairo_arc(cr, cx, cy, wheel_radius, selector_angle - selector_width,
|
||||
selector_angle + selector_width);
|
||||
|
||||
cairo_arc_negative(cr,
|
||||
cx, cy,
|
||||
inner_radius,
|
||||
cairo_arc_negative(cr, cx, cy, inner_radius,
|
||||
selector_angle + selector_width,
|
||||
selector_angle - selector_width);
|
||||
|
||||
@@ -180,7 +218,8 @@ static void vektor_color_wheel_snapshot(GtkWidget* widget, GtkSnapshot* snapshot
|
||||
cairo_destroy(cr);
|
||||
}
|
||||
|
||||
static void on_click(GtkGestureClick* gesture, int n_press, double x, double y, gpointer data) {
|
||||
static void on_click(GtkGestureClick* gesture, int n_press, double x, double y,
|
||||
gpointer data) {
|
||||
VektorColorWheel* wheel = VEKTOR_COLOR_WHEEL(data);
|
||||
GtkWidget* widget = GTK_WIDGET(wheel);
|
||||
|
||||
@@ -189,7 +228,6 @@ static void on_click(GtkGestureClick* gesture, int n_press, double x, double y,
|
||||
|
||||
double outer_radius = MIN(width, height) / 2.0;
|
||||
double wheel_radius = outer_radius * 0.95;
|
||||
double inner_radius = wheel_radius * 0.9;
|
||||
|
||||
double triangle_radius = wheel_radius * 0.75;
|
||||
|
||||
@@ -206,7 +244,21 @@ static void on_click(GtkGestureClick* gesture, int n_press, double x, double y,
|
||||
double cy2 = cy - 0.866 * triangle_radius;
|
||||
|
||||
double u, v, w;
|
||||
if(point_in_triangle(x,y, ax,ay, bx,by, cx2,cy2, &u,&v,&w)) {
|
||||
gboolean inside =
|
||||
point_in_triangle(x, y, ax, ay, bx, by, cx2, cy2, &u, &v, &w);
|
||||
|
||||
if (wheel->dragging_triangle) {
|
||||
|
||||
if (!inside) { // if outside triangle, snap to its edge
|
||||
double sx, sy;
|
||||
|
||||
closest_point_on_triangle(x, y, ax, ay, bx, by, cx2, cy2, &sx, &sy);
|
||||
|
||||
x = sx;
|
||||
y = sy;
|
||||
|
||||
point_in_triangle(x, y, ax, ay, bx, by, cx2, cy2, &u, &v, &w);
|
||||
}
|
||||
|
||||
double denom = u + v;
|
||||
if (denom > 0.0001) { // avoid div-by-zero at black vertex
|
||||
@@ -215,27 +267,25 @@ static void on_click(GtkGestureClick* gesture, int n_press, double x, double y,
|
||||
wheel->saturation = 0.0; // arbitrary, since S irrelevant at V=0
|
||||
}
|
||||
wheel->lightness = denom;
|
||||
g_signal_emit(wheel, signals[COLOR_CHANGED], 0);
|
||||
|
||||
} else {
|
||||
} else { // dragging wheel
|
||||
double dx = x - cx;
|
||||
double dy = y - cy;
|
||||
double dist = sqrt(dx*dx+dy*dy);
|
||||
|
||||
if(dist > inner_radius && dist < outer_radius) {
|
||||
|
||||
double angle = atan2(dy, dx);
|
||||
if(angle < 0) { angle += 2 * M_PI; }
|
||||
if (angle < 0) {
|
||||
angle += 2 * M_PI;
|
||||
}
|
||||
|
||||
wheel->hue = angle / (2 * M_PI);
|
||||
g_signal_emit(wheel, signals[COLOR_CHANGED], 0);
|
||||
}
|
||||
}
|
||||
|
||||
g_signal_emit(wheel, signals[COLOR_CHANGED], 0);
|
||||
gtk_widget_queue_draw(widget);
|
||||
}
|
||||
|
||||
static void on_drag(GtkGestureDrag* gesture, double offset_x, double offset_y, gpointer data) {
|
||||
static void on_drag(GtkGestureDrag* gesture, double offset_x, double offset_y,
|
||||
gpointer data) {
|
||||
double x, y;
|
||||
gtk_gesture_drag_get_start_point(gesture, &x, &y);
|
||||
|
||||
@@ -245,6 +295,40 @@ static void on_drag(GtkGestureDrag* gesture, double offset_x, double offset_y, g
|
||||
on_click(NULL, 0, x, y, data);
|
||||
}
|
||||
|
||||
static void on_drag_begin(GtkGestureDrag* gesture, gdouble start_x,
|
||||
gdouble start_y, gpointer user_data) {
|
||||
// set dragging_wheel or dragging_triangle which are used
|
||||
// to determine to where the cursor should snap to
|
||||
|
||||
VektorColorWheel* wheel = VEKTOR_COLOR_WHEEL(user_data);
|
||||
GtkWidget* widget = GTK_WIDGET(wheel);
|
||||
|
||||
int width = gtk_widget_get_width(widget);
|
||||
int height = gtk_widget_get_height(widget);
|
||||
|
||||
double cx = width / 2.0;
|
||||
double cy = height / 2.0;
|
||||
|
||||
double dx = start_x - cx;
|
||||
double dy = start_y - cy;
|
||||
double dist = sqrt(dx * dx + dy * dy);
|
||||
|
||||
double outer_radius = MIN(width, height) / 2.0;
|
||||
double wheel_radius = outer_radius * 0.95;
|
||||
double inner_radius = wheel_radius * 0.9;
|
||||
|
||||
if (dist > inner_radius) {
|
||||
wheel->dragging_wheel = TRUE;
|
||||
wheel->dragging_triangle = FALSE;
|
||||
} else if (dist < inner_radius) {
|
||||
wheel->dragging_wheel = FALSE;
|
||||
wheel->dragging_triangle = TRUE;
|
||||
} else {
|
||||
wheel->dragging_wheel = FALSE;
|
||||
wheel->dragging_triangle = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static void vektor_color_wheel_init(VektorColorWheel* self) {
|
||||
GtkGesture* click = gtk_gesture_click_new();
|
||||
gtk_widget_add_controller(GTK_WIDGET(self), GTK_EVENT_CONTROLLER(click));
|
||||
@@ -255,6 +339,7 @@ static void vektor_color_wheel_init(VektorColorWheel* self) {
|
||||
gtk_widget_add_controller(GTK_WIDGET(self), GTK_EVENT_CONTROLLER(drag));
|
||||
|
||||
g_signal_connect(drag, "drag-update", G_CALLBACK(on_drag), self);
|
||||
g_signal_connect(drag, "drag-begin", G_CALLBACK(on_drag_begin), self);
|
||||
}
|
||||
|
||||
static void vektor_color_wheel_class_init(VektorColorWheelClass* klass) {
|
||||
@@ -262,17 +347,8 @@ static void vektor_color_wheel_class_init(VektorColorWheelClass* klass) {
|
||||
widget_class->snapshot = vektor_color_wheel_snapshot;
|
||||
|
||||
signals[COLOR_CHANGED] =
|
||||
g_signal_new(
|
||||
"color-changed",
|
||||
G_TYPE_FROM_CLASS(klass),
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
G_TYPE_NONE,
|
||||
0
|
||||
);
|
||||
g_signal_new("color-changed", G_TYPE_FROM_CLASS(klass),
|
||||
G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL, G_TYPE_NONE, 0);
|
||||
}
|
||||
|
||||
GtkWidget* vektor_color_wheel_new(void) {
|
||||
@@ -281,21 +357,26 @@ GtkWidget* vektor_color_wheel_new(void) {
|
||||
|
||||
VektorColor vektor_color_wheel_get_color(VektorColorWheel* wheel) {
|
||||
float r, g, b;
|
||||
gtk_hsv_to_rgb(wheel->hue,
|
||||
wheel->saturation,
|
||||
wheel->lightness,
|
||||
&r, &g, &b);
|
||||
gtk_hsv_to_rgb(wheel->hue, wheel->saturation, wheel->lightness, &r, &g, &b);
|
||||
|
||||
return (VektorColor) {
|
||||
.r = (unsigned char)(r*255),
|
||||
return (VektorColor){.r = (unsigned char)(r * 255),
|
||||
.g = (unsigned char)(g * 255),
|
||||
.b = (unsigned char)(b*255)
|
||||
};
|
||||
.b = (unsigned char)(b * 255),
|
||||
.a = 255};
|
||||
}
|
||||
|
||||
void vektor_colorout_wheel_get_color(VektorColorWheel* wheel, float* r, float* g, float* b) {
|
||||
gtk_hsv_to_rgb(wheel->hue,
|
||||
wheel->saturation,
|
||||
wheel->lightness,
|
||||
r, g, b);
|
||||
void vektor_color_wheel_get_colorout(VektorColorWheel* wheel, float* r,
|
||||
float* g, float* b) {
|
||||
gtk_hsv_to_rgb(wheel->hue, wheel->saturation, wheel->lightness, r, g, b);
|
||||
}
|
||||
|
||||
void vektor_color_wheel_set_color(VektorColorWheel* wheel, VektorColor c) {
|
||||
float h, s, v;
|
||||
gtk_rgb_to_hsv(c.r / 255.0, c.g / 255.0, c.b / 255.0, &h, &s, &v);
|
||||
wheel->hue = (float)h;
|
||||
wheel->saturation = (float)s;
|
||||
wheel->lightness = (float)v;
|
||||
|
||||
gtk_widget_queue_draw(GTK_WIDGET(wheel));
|
||||
g_signal_emit(wheel, signals[COLOR_CHANGED], 0);
|
||||
}
|
||||
@@ -5,10 +5,13 @@
|
||||
#include "src/util/color.h"
|
||||
|
||||
#define VEKTOR_TYPE_COLOR_WHEEL vektor_color_wheel_get_type()
|
||||
G_DECLARE_FINAL_TYPE(VektorColorWheel, vektor_color_wheel, VEKTOR, COLOR_WHEEL, GtkDrawingArea)
|
||||
G_DECLARE_FINAL_TYPE(VektorColorWheel, vektor_color_wheel, VEKTOR, COLOR_WHEEL,
|
||||
GtkDrawingArea)
|
||||
|
||||
GtkWidget* vektor_color_wheel_new(void);
|
||||
VektorColor vektor_color_wheel_get_color(VektorColorWheel* wheel);
|
||||
void vektor_colorout_wheel_get_color(VektorColorWheel* wheel, float* r, float* g, float* b);
|
||||
void vektor_color_wheel_get_colorout(VektorColorWheel* wheel, float* r,
|
||||
float* g, float* b);
|
||||
void vektor_color_wheel_set_color(VektorColorWheel* wheel, VektorColor c);
|
||||
|
||||
#endif
|
||||
96
ui/main.ui
96
ui/main.ui
@@ -31,6 +31,29 @@
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<!--Another topbar for style control-->
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">horizontal</property>
|
||||
<property name="hexpand">true</property>
|
||||
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="icon-name">tool-pencil-symbolic</property>
|
||||
<property name="margin-start">10</property>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<object class="GtkEntry" id="thickness_entry">
|
||||
<property name="text">1</property>
|
||||
<property name="margin-start">10</property>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<!--Main area below-->
|
||||
<child>
|
||||
<object class="GtkPaned" id="workspace_paned">
|
||||
@@ -65,6 +88,14 @@
|
||||
|
||||
<!--Tool buttons-->
|
||||
|
||||
<!--Select tool-->
|
||||
<child>
|
||||
<object class="GtkButton" id="button_selecttool">
|
||||
<property name="icon-name">tool-select-symbolic</property>
|
||||
<property name="halign">start</property>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<!--Shape tool (row container)-->
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
@@ -101,6 +132,13 @@
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<!--Polygon tool-->
|
||||
<child>
|
||||
<object class="GtkButton" id="button_polygontool">
|
||||
<property name="icon-name">tool-polygon-symbolic</property>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<!--Circle tool-->
|
||||
<child>
|
||||
<object class="GtkButton" id="button_circletool">
|
||||
@@ -147,6 +185,10 @@
|
||||
<property name="margin-top">6</property>
|
||||
<property name="margin-bottom">6</property>
|
||||
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
|
||||
<child>
|
||||
<object class="VektorColorWheel" id="color_picker">
|
||||
<property name="hexpand">true</property>
|
||||
@@ -154,6 +196,60 @@
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">horizontal</property>
|
||||
<property name="halign">center</property>
|
||||
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="label">R</property>
|
||||
<property name="margin-start">6</property>
|
||||
<property name="margin-end">6</property>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<object class="GtkEntry" id="spin_color_r">
|
||||
<property name="text">0</property>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="label">G</property>
|
||||
<property name="margin-start">6</property>
|
||||
<property name="margin-end">6</property>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<object class="GtkEntry" id="spin_color_g">
|
||||
<property name="text">0</property>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="label">B</property>
|
||||
<property name="margin-start">6</property>
|
||||
<property name="margin-end">6</property>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<object class="GtkEntry" id="spin_color_b">
|
||||
<property name="text">0</property>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
</object>
|
||||
</child>
|
||||
|
||||
</object>
|
||||
|
||||
</child>
|
||||
|
||||
</object>
|
||||
</child>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user