Repository: acaudwell/Gource Branch: master Commit: 70db547c6b8b Files: 115 Total size: 672.0 KB Directory structure: gitextract_8c62qvm7/ ├── .gitattributes ├── .github/ │ └── FUNDING.yml ├── .gitignore ├── .gitmodules ├── COPYING ├── ChangeLog ├── INSTALL ├── Makefile.am ├── README.md ├── THANKS ├── autogen.sh ├── cmd/ │ ├── gource │ └── gource.cmd ├── configure.ac ├── contrib/ │ └── svn-gource.py ├── data/ │ ├── bloom.tga │ ├── bloom_alpha.tga │ ├── fonts/ │ │ └── README │ ├── gource.1 │ ├── gource.style │ └── shaders/ │ ├── bloom.frag │ ├── bloom.vert │ ├── shadow.frag │ ├── shadow.vert │ ├── text.frag │ └── text.vert ├── dev/ │ ├── .gitignore │ ├── bin/ │ │ ├── build_tar.pl │ │ └── build_win64.pl │ └── nsis/ │ ├── disclaimer.txt │ └── welcome.xcf ├── gource.pro ├── m4/ │ ├── ax_boost_base.m4 │ ├── ax_boost_filesystem.m4 │ ├── ax_check_gl.m4 │ ├── ax_check_glu.m4 │ ├── ax_check_glut.m4 │ ├── ax_pthread.m4 │ ├── ax_restore_flags_with_prefix.m4 │ ├── ax_save_flags_with_prefix.m4 │ └── pkg.m4 ├── resources/ │ ├── file.xcf │ └── user.xcf ├── scripts/ │ └── gource-ps.pl ├── src/ │ ├── .gitignore │ ├── action.cpp │ ├── action.h │ ├── bloom.cpp │ ├── bloom.h │ ├── caption.cpp │ ├── caption.h │ ├── dirnode.cpp │ ├── dirnode.h │ ├── file.cpp │ ├── file.h │ ├── formats/ │ │ ├── apache.cpp │ │ ├── apache.h │ │ ├── bzr.cpp │ │ ├── bzr.h │ │ ├── commitlog.cpp │ │ ├── commitlog.h │ │ ├── custom.cpp │ │ ├── custom.h │ │ ├── cvs-exp.cpp │ │ ├── cvs-exp.h │ │ ├── cvs2cl.cpp │ │ ├── cvs2cl.h │ │ ├── git.cpp │ │ ├── git.h │ │ ├── gitraw.cpp │ │ ├── gitraw.h │ │ ├── hg.cpp │ │ ├── hg.h │ │ ├── svn.cpp │ │ └── svn.h │ ├── gource.cpp │ ├── gource.h │ ├── gource_settings.cpp │ ├── gource_settings.h │ ├── gource_shell.cpp │ ├── gource_shell.h │ ├── key.cpp │ ├── key.h │ ├── logmill.cpp │ ├── logmill.h │ ├── main.cpp │ ├── main.h │ ├── pawn.cpp │ ├── pawn.h │ ├── slider.cpp │ ├── slider.h │ ├── spline.cpp │ ├── spline.h │ ├── test/ │ │ ├── datetime_tests.cpp │ │ ├── main.cpp │ │ └── regex_tests.cpp │ ├── textbox.cpp │ ├── textbox.h │ ├── tinyxml/ │ │ ├── tinystr.cpp │ │ ├── tinystr.h │ │ ├── tinyxml.cpp │ │ ├── tinyxml.h │ │ ├── tinyxmlerror.cpp │ │ └── tinyxmlparser.cpp │ ├── user.cpp │ ├── user.h │ ├── zoomcamera.cpp │ └── zoomcamera.h └── tests/ ├── logs/ │ ├── custom-dir-delete.log │ ├── file-removal.log │ ├── file-to-dir.log │ ├── svn-dir-delete.log │ ├── utf8-caption.log │ └── utf8.log └── test.conf ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitattributes ================================================ *.cmd text eol=crlf ================================================ FILE: .github/FUNDING.yml ================================================ ko_fi: acaudwell ================================================ FILE: .gitignore ================================================ *.avi *.mpg *.mkv *.mp4 gource-*.png .objs /gource /gource.exe gource.pro.user debug.log Makefile Makefile.in *.dll *.dll.a logs/* /aclocal.m4 /autom4te.cache /configure /config.log /config.status /dev/win64 /build-aux *.swp *.d .deps .dirstamp ================================================ FILE: .gitmodules ================================================ [submodule "src/core"] path = src/core url = https://github.com/acaudwell/Core.git ================================================ FILE: COPYING ================================================ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is 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. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. 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. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. 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 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. Use with the GNU Affero General Public License. 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 Affero 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 special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU 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 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 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 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. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". 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 GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . ================================================ FILE: ChangeLog ================================================ 0.57: * Handle loading indexed colour images (sokripon). 0.56: * Added --author-time option (onlyJakob). * Fixed build with Boost 1.89.0 by no longer linking boost system. * Increased minimum required version of Boost to 1.69. * Request compatibility profile when creating OpenGL context. 0.55: * Fixed build with Boost 1.85.0 (cho-m). 0.54: * Added experimental support for Wayland (beroset). * Fixed building on Apple M1 by updating autoconf macros (Ckhardin). 0.53: * Added --high-dpi option. * Fixed various bugs with Retina displays on MacOS. * Fixed slider timestamp font not affected by --font-scale. * Fixed hovering over end of slider stopping time advancing. 0.52: * Support rendering at native resolution on Retina / Ultra HD displays. * Support ISO 8601 timestamp format. * Allow custom log and caption file timestamps to be strings. * Change regular expression library to PCRE2. * Fixed filenames not being affected by --font-scale (Carl Colena). * Fixed file key not being affected by --font-scale. * Added --file-idle-time-at-end option. * Added --fixed-user-size option. 0.51: * Fixed --font-file relative path handling. * Fixed a bug in resolving the repository root directory from a relative path. 0.50: * Right mouse button rotation now pivots around the camera. * Added --font-file option. * Added --enable-font-file option to configure. * Added --no-time-travel option (Lars Schmertmann). * Added --dir-name-position option (Lars Schmertmann). * Added --file-extension-fallback option (Lars Schmertmann). * Added --user-show-filter option (Victor Lopez). * Added --disable-input option (Joey Parrish). * Added --loop-delay-seconds option (Joey Parrish). * Added --font-scale option. * Added filename, dirname and user font size options (Carl Colena). * Added workaround for FFMpeg error parsing Gource PPM video output. * Fixed a bug in the Mercurial log parser that caused changes to be missed. * Fixed file removal being cancelled by an action with an earlier timestamp. * Fixed a bug in the log file format detection that could result in the wrong first entry being displayed for a custom log. * Fixed a bug where automatically cycling through a config with multiple repositories reset settings to their defaults. 0.49: * Fixed compatibility with GLM 0.9.9.0. 0.48: * Can now generate logs from git sub module directories. 0.47: * Fixed low mouse movement speed with some mice while repositioning camera. 0.46: * Added --screen option. 0.45: * Added --window-position XxY option. * Added --frameless option. * Added --file-show-filter REGEX option (swoogles). * Added --filename-time and filename-colour options (gh2k). * Improved handling of very low seconds-per-day values (malengrin). * Fixed crash when SVN log lacks author information (obarthel). * Additional git log command validation (cym13). * Allow lower case hex colours in custom logs (HSorensen). * Enabled STDOUT support with --output-stream '-' on Windows (circulosmeos). * Now requires SDL 2 to build (deprecated SDL 1.2 support removed). 0.44: * Fixed crash when taking a screenshot with an odd resolution. * Fixed type deduction compilation error with newer versions of GCC. * Documentation improvements. 0.43: * Updated boost autoconf macros to fix multi-arch detection. 0.42: * Fixed bzr log command when no start date was specified (chrisf). * Fixed hg log commit order when date range specified. * Fixed hg log command line on Windows. * Fixed parser bug in date range filtering code. 0.41: * Multi-monitor support using SDL 2.0 when available. * SDL 1.2 support is deprecated. * Full screen mode now uses desktop resolution by default. * Added --start-date, --stop-date 'YYYY-MM-DD hh:mm:ss' options. * Added --dir-name-depth option. * Changed --file-idle-time default value to 0. * Changed screenshot format to PNG. 0.40: * Added caption support. * Improved command line interoperability on Windows. * Fixed directory deletion short circuiting processing the rest of a commit. * Fixed issue loading non-ascii user image filenames on windows. * Ignore UTF-8 byte order mark at the start of lines in custom log files. * Fix to boost macros for Macs and non-GNU systems (mistydemeo). * Autotools improvements (flameeyes). 0.39: * Fixed blurry non power of 2 logos. * File colour changes now supported in custom logs (rmyorston). * Fixed building against Boost 1.50 (svenstaro). * Updated boost autoconf macros (flameeyes). * Autogen script (matthiaskrgr). 0.38: * New high quality sprites. * Fullscreen toggle with alt + enter. * Window is now resizable. -WIDTHxHEIGHT! creates a non-resizable window. * Lowered minimum zoom distance. * Use AM_CPPFLAGS in Makefile.am to allow passing custom CPPFLAGS. * Don't add files that match the path of a known directory. * Fixed divide by zero in text shader causing artifacts on some video cards. * Recursively search for repository directory when log-format not specified (thanks to Jörg Bachmann for original concept / prototype). * New dependency on Boost Filesystem. * Doubled the maximum zoom out distance. * Allow negative timestamps before 1970 in custom log (artzub). * Fix for UTF8-CPP checked.h compilation issue (vszakats). * Fixed bug causing missing characters in text. * Fixed --highlight-users option not using highlight-colour. * highlight-colour default changed to white. * Added --selection-colour option (applied to selected users and files). * Added --dir-colour option (applied to directories). 0.37: * Made SVN log GMT timestamp conversion fix portable. 0.36: * Fixed SVN log GMT timestamp conversion. * Fixed issue with sub-dirs of deleted dir not being removed in some cases. 0.35: * Added long file extension truncation handling to file key (--key). * Treat changes in Mercurial log files with the same time/user as one commit. * Fixed handling of spaces in directory names with Mercurial. * Fixed --font-colour option. 0.34: * Now using VBOs and shaders for faster rendering when OpenGL 2.0 is available. * Eliminated bloom colour banding artifacts (requires OpenGL 2.0). * New font rendering library derived from FTGL (FTGL no longer required). * Single pass font/shadow rendering (with lots of help from Chris Forbes). * Added --no-vsync option. * Fixed bug where tree is out of alignment with object positions in windowed mode due to using the wrong display dimensions internally. * Removed default max-files limit. 0.33: * Added --hide root option to not draw branches from the root directory. * Fixed log parsing of Bazaar merges and tagged commits. * --output-custom-log now skips unparsed log entries instead of exiting. 0.32: * Fixed behaviour of user camera tracking. 0.31: * Added --with-tinyxml option to configure (use the system TinyXML library). 0.30: * Fixed crash when SVN log entry contains no 'paths' element. * Handle directory deletion (happens in SVN logs). 0.29: * SVN built-in support. * cvs2cl log support (cvs-exp support is now deprecated). * Made camera behaviour when zooming and selecting objects more intuitive. * Improved interactive performance. * Added file extension key (--key or toggled with 'K'). * Added mouse-over tool tips. * Added --highlight-colour option. * Added --hash-seed option. The S key now randomizes colours. * Added --output-custom-log option. * Exposed --time-scale option (previously only available interactively). * Removed arbitrary 1024 maximum length limit for log lines. * Fixed two file colouring bugs (quoted files from git, period in file path). * Fix handling of avatars for UTF-8 usernames on MACOSX (Christian Köstlin). * Recover from video mode failing to set due to multi-sampling (Siddhesh Poyarekar). 0.28: * Bazaar support for merged commits (Nick Moffit). * C++ efficiency improvements (Oliver Smith). * Improved cvs-exp log compatibility. * Re-show name of user when adding a new action if user is idle. * Added --padding option to control camera view padding. * More accurate camera tracking (tracks the bounding boxes of objects). * Improved automatic rotation logic. 0.27: * Display time stops at the time of the last commit. * Users fade out when end reached rather than ending abruptly. * Position slider is now hidden by default if recording a video. * Automatic camera rotation for better use of screen space. * Support international keyboards (Peter Kjellerstedt). * C++ efficiency improvements (Jacob Metcalfe). * Fixed crash when reading from STDIN. * Fixed intermittent crash closing Gource when using --output-ppm-stream. * Added ini style config file support (see --load/save-config). * Added screenshot button (F12). Screenshots respect the alpha channel. * Added --transparent to make the background see-through (for screenshots). * Added --logo and --background-image options. * Added --dont-stop option for manual exiting when recording videos. * Added --stop-at-time option to stop Gource after a number of seconds. * Added --hide 'mouse' option. * Added --highlight-dirs option. * Added --file-extensions to show filename extensions only. * Added --user-filter REGEX option. * Allow --file-idle-time 0 (files will never expire). * Allow --start-position 'random' to set a random start position. * --log-command VCS replaces multiple --log-command-VCS options. * Replaced --disable-progress and --disable-bloom with arguments to --hide. 0.26a: * Updated to latest version of GL autoconf macros. 0.26: * Improved mouse dragging. * Holding right mouse button and moving the mouse rotates the view. * The middle mouse button now toggles the camera mode. * Username positions now scale correctly. * Simulation time no longer incremented while paused, counting towards file time lag. * M key now toggles mouse visibility. * Added --hide option to use instead of multiple --hide-ELEMENT options. 0.25: * Bazaar support (John Arbash Meinel). * Dragging the mouse on the background moves the camera. * Added --camera-mode option (track,overview). * Support DOS line endings in logs. * Improved compatibility of hg log command (Brendan Cully). * Fixed PPM exporter producing blank images on some video cards. * Fixed parsing of negative timezones from cvs-exp.pl logs. * Fixed various gdb and compiler warnings. 0.24: * PPM output speed improvements, including using a second thread (HighlandSun). * Now using standard autotools (Flameeyes). * Fixed --max-file-lag not working with some custom log files. * Gource will stop at the end of the log by default when recording a video. * Fixed STDIN stopping working after the first lot of records with tail -f. * Added proper exception handling. * Print errors to stderr. 0.23: * Hiding filenames no longer hides directory names. * Fixed --stop-on-idle option. * Added --stop-at-end option (more intuitive than --stop-position 1.0). 0.22: * Fixed Mercurial log order. 0.21b: * Fixed windows build. 0.21: * Some documentation fixes. 0.20: * Added bloom effect (turn off with --disable-bloom). * Added support for Mercurial (thanks to Justin Love for gource.style). * --start-position option now works in combination with --disable-progress. 0.19: * Use time_t instead of long for timestamps. 0.18: * Fixed camera movement while the simulation is paused. 0.17: * Show correct month for CVS logs. * Added time scaling (Bitshifter). 0.16: * Added --hide-dirnames option. * Added --user-scale option. * Added --date-format option (Pat Notz). * Fix bug when encountering long log lines. * Fixed incorrect parsing of trivial merges. * Fixed building issues on OSX. 0.15: * Added PPM output support for creating videos (Johannes Schindelin). * Added experimental Apache combined access log support (--log-format apache). * Added --stop-position and --stop-on-idle options (useful for making videos). * Added --max-file-lag option to limit how long after a commit file changes can take to appear. * Added --no-renames to the git log command as they don't display correctly. * Added --max-user-speed and --user-friction as options. * Now builds on OSX Leopard (with the required libaries installed). * Caught raw exception from replace_invalid(). * Added CXXFLAGS. You may want to override the default (eg CXXFLAGS=-O3 ./configure). 0.14: * Updated SVN instructions. 0.13: * Removed single quotes from log command (fixes running gource --git-log-command in back ticks) * Added SVN instructions. * Fixed manpage hyphens. 0.12: * Added --enable-ttf-font-dir=DIR option to configure (to specify the ttf-freefont directory). * UTF-8 support using UTF8-CPP (http://utfcpp.sourceforge.net/). * Changed the git log command (see --git-log-command) to require less work to parse. Log files generated with the previous git-log command used by gource should continue to work. * Allow --seconds-per-day value less than 1.0. * Added --git-branch command. * Added --loop command. * Added --crop command. 0.11: * Made N key skip to next entry. * Documented --user-image-dir flag. * temp file name now uses uid instead of time 0.1: * First release. ================================================ FILE: INSTALL ================================================ This file is to help you configure, build and install Gource for your system. Contents ======== 1. Dependencies 2. Building 3. Configure Options 1. Dependencies =============== Gource requires the following libraries to compile (package names may vary): SDL 2.0 (libsdl2-dev) SDL Image 2.0 (libsdl2-image-dev) PCRE2 (libpcre2-dev) Freetype 2 (libfreetype6-dev) GLEW (libglew-dev) GLM >= 0.9.3 (libglm-dev) Boost Filesystem >= 1.69 (libboost-filesystem-dev) PNG >= 1.2 (libpng-dev) Optional: TinyXML (libtinyxml-dev) SDL Image 2.0 needs to have been built with support PNG and JPEG images. 2. Building =========== Gource requires a GNU compatible C++ compiler that supports c++0x features such as 'auto' and the new 'for' loop syntax. GCC 4.6+ or Clang recommended. If you got the source directly from the Gource.git repository, you will first need to run autogen.sh which will generate the configure script and initialize and update the submodules. ./autogen.sh Generic build instructions for Linux/Mac OS: ./configure make make install Building on Windows: On Windows compile gource.pro with Qt Creator. A pre-built version for Windows is normally available from the homepage. Gource expects SDL to have been built with the NO_STDIO_REDIRECT flag. 3. Configure Options ==================== By default Gource will install some GNU FreeFont TTF Fonts on your system. If you already have these fonts, you can configure Gource to use them with: ./configure --enable-ttf-font-dir=/path/to/freefont/ You can also build Gource with a different font: ./configure --enable-font-file=/path/to/alternate/font.ttf The font file format must be supported by Free Type 2. Gource includes a copy of TinyXML. To build against the system version of the library use: ./configure --with-tinyxml ================================================ FILE: Makefile.am ================================================ ACLOCAL_AMFLAGS = -I m4 bin_PROGRAMS = gource gource_CXXFLAGS = -std=gnu++0x -Wall -Wno-sign-compare -Wno-reorder -Wno-unused-but-set-variable -Wno-unused-variable sources = \ src/action.cpp \ src/bloom.cpp \ src/caption.cpp \ src/core/conffile.cpp \ src/core/display.cpp \ src/core/frustum.cpp \ src/core/fxfont.cpp \ src/core/logger.cpp \ src/core/mousecursor.cpp \ src/core/plane.cpp \ src/core/ppm.cpp \ src/core/quadtree.cpp \ src/core/regex.cpp \ src/core/resource.cpp \ src/core/sdlapp.cpp \ src/core/seeklog.cpp \ src/core/settings.cpp \ src/core/shader.cpp \ src/core/shader_common.cpp \ src/core/stringhash.cpp \ src/core/texture.cpp \ src/core/png_writer.cpp \ src/core/timezone.cpp \ src/core/vbo.cpp \ src/core/vectors.cpp \ src/dirnode.cpp \ src/file.cpp \ src/formats/apache.cpp \ src/formats/bzr.cpp \ src/formats/commitlog.cpp \ src/formats/custom.cpp \ src/formats/cvs-exp.cpp \ src/formats/cvs2cl.cpp \ src/formats/git.cpp \ src/formats/gitraw.cpp \ src/formats/hg.cpp \ src/formats/svn.cpp \ src/gource.cpp \ src/gource_shell.cpp \ src/gource_settings.cpp \ src/key.cpp \ src/logmill.cpp \ src/pawn.cpp \ src/slider.cpp \ src/spline.cpp \ src/textbox.cpp \ src/user.cpp \ src/zoomcamera.cpp if USE_BUNDLED_TINYXML sources += \ src/tinyxml/tinyxmlerror.cpp \ src/tinyxml/tinystr.cpp \ src/tinyxml/tinyxml.cpp \ src/tinyxml/tinyxmlparser.cpp endif gource_SOURCES = src/main.cpp ${sources} AM_CPPFLAGS = -DSDLAPP_RESOURCE_DIR=\"$(pkgdatadir)\" dist_pkgdata_DATA = data/beam.png data/bloom.tga data/bloom_alpha.tga data/file.png data/user.png data/gource.style shadersdir = $(pkgdatadir)/shaders dist_shaders_DATA = data/shaders/shadow.vert data/shaders/shadow.frag data/shaders/bloom.vert data/shaders/bloom.frag data/shaders/text.vert data/shaders/text.frag install-data-hook: $(MKDIR_P) $(DESTDIR)$(mandir)/man1 gzip -cf9 $(srcdir)/data/gource.1 > $(DESTDIR)$(mandir)/man1/gource.1.gz uninstall-hook: rm -f $(DESTDIR)$(mandir)/man1/gource.1.gz if FONTFILE AM_CPPFLAGS += -DGOURCE_FONT_FILE=\"$(gourcefontfile)\" else if FONTDIR AM_CPPFLAGS += -DSDLAPP_FONT_DIR=\"$(gourcefontdir)\" else fontsdir = $(pkgdatadir)/fonts dist_fonts_DATA = data/fonts/README data/fonts/FreeSans.ttf endif endif check_PROGRAMS = gource_tests gource_tests_CPPFLAGS = -I src/test/ ${BOOST_CPPFLAGS} gource_tests_LDFLAGS = ${BOOST_LDFLAGS} gource_tests_LDADD = ${BOOST_UNIT_TEST_FRAMEWORK_LIB} gource_tests_SOURCES = \ src/test/main.cpp \ src/test/datetime_tests.cpp \ src/test/regex_tests.cpp \ ${sources} TESTS = gource_tests ================================================ FILE: README.md ================================================ Gource ====== https://gource.io Description =========== Gource is a visualization tool for source control repositories. The repository is displayed as a tree where the root of the repository is the centre, directories are branches and files are leaves. Contributors to the source code appear and disappear as they contribute to specific files and directories. Requirements ============ Gource's display is rendered using OpenGL and requires a 3D accelerated video card to run. Using Gource ============ ``` gource [options] [path] options: -h, --help Help ('-H' for extended help). -WIDTHxHEIGHT, --viewport WIDTHxHEIGHT Set the viewport size. If -f is also supplied, will attempt to set the video mode to this also. Add ! to make the window non-resizable. --screen SCREEN Set the number of the screen to display on. --high-dpi Request a high DPI display when creating the window. On some platforms such as MacOS, the window resolution is specified in points instead of pixels. The --high-dpi flag may be required to access some higher resolutions. E.g. requesting a high DPI 800x600 window may produce a window that is 1600x1200 pixels. --window-position XxY Initial window position on your desktop which may be made up of multiple monitors. This will override the screen setting so don't specify both. --frameless Frameless window. -f, --fullscreen Fullscreen. -w, --windowed Windowed. --transparent Make the background transparent. Only really useful for screenshots. --start-date "YYYY-MM-DD hh:mm:ss +tz" Start with the first entry after the supplied date and optional time. If a time zone offset isn't specified the local time zone is used. Example accepted formats: "2012-06-30" "2012-06-30 12:00" "2012-06-30 12:00:00 +12" --stop-date "YYYY-MM-DD hh:mm:ss +tz" Stop after the last entry prior to the supplied date and optional time. Uses the same format as --start-date. -p, --start-position POSITION Begin at some position in the log (between 0.0 and 1.0 or 'random'). --stop-position POSITION Stop (exit) at some position in the log (does not work with STDIN). -t, --stop-at-time SECONDS Stop (exit) after a specified number of seconds. --stop-at-end Stop (exit) at the end of the log / stream. --loop Loop back to the start of the log when the end is reached. --loop-delay-seconds Seconds to delay before looping. -a, --auto-skip-seconds SECONDS Skip to next entry if nothing happens for a number of seconds. -s, --seconds-per-day SECONDS Speed of simulation in seconds per day. --realtime Realtime playback speed. --no-time-travel Use the time of the last commit if the time of a commit is in the past. --author-time Use the timestamp of the author instead of the timestamp of the committer. -c, --time-scale SCALE Change simulation time scale. This affects the movement speed of user avatars. E.g. 0.5 for half speed, 2 for double speed. -i, --file-idle-time SECONDS Time in seconds files remain idle before they are removed or 0 for no limit. --file-idle-time-at-end SECONDS Time in seconds files remain idle at the end before they are removed. -e, --elasticity FLOAT Elasticity of nodes. -b, --background-colour FFFFFF Background colour in hex. --background-image IMAGE Set a background image. --logo IMAGE Logo to display in the foreground. --logo-offset XxY Offset position of the logo. --title TITLE Set a title. --font-file FILE Specify the font. Should work with most font file formats supported by FreeType, such as TTF and OTF, among others. --font-scale SCALE Scale the size of all fonts. --font-size SIZE Font size used by the date and title. --file-font-size SIZE Font size of filenames. --dir-font-size SIZE Font size of directory names --user-font-size SIZE Font size of user names. --font-colour FFFFFF Font colour used by the date and title in hex. --key Show file extension key. --date-format FORMAT Specify display date string (strftime format). --log-command VCS Show the VCS log command used by gource (git,svn,hg,bzr,cvs2cl). --log-format VCS Specify the log format (git,svn,hg,bzr,cvs2cl,custom). Required when reading from STDIN. --git-branch Get the git log of a branch other than the current one. --follow-user USER Have the camera automatically follow a particular user. --highlight-dirs Highlight the names of all directories. --highlight-user USER Highlight the names of a particular user. --highlight-users Highlight the names of all users. --highlight-colour FFFFFF Font colour for highlighted users in hex. --selection-colour FFFFFF Font colour for selected users and files. --filename-colour FFFFFF Font colour for filenames. --dir-colour FFFFFF Font colour for directories. --dir-name-depth DEPTH Draw names of directories down to a specific depth in the tree. --dir-name-position FLOAT Position along edge of the directory name (between 0.1 and 1.0, default is 0.5). --filename-time SECONDS Duration to keep filenames on screen (>= 2.0). --file-extensions Show filename extensions only. --file-extension-fallback Use filename as extension if the extension is missing or empty. --file-filter REGEX Filter out file paths matching the specified regular expression. --file-show-filter REGEX Show only file paths matching the specified regular expression. --user-filter REGEX Filter usernames matching the specified regular expression. --user-show-filter REGEX Show only usernames matching the specified regular expression. --user-image-dir DIRECTORY Directory containing .jpg or .png images of users (eg "Full Name.png") to use as avatars. --default-user-image IMAGE Path of .jpg or .png to use as the default user image. --fixed-user-size Forces the size of the user image to remain fixed throughout. --colour-images Colourize user images. --crop AXIS Crop view on an axis (vertical,horizontal). --padding FLOAT Camera view padding. --multi-sampling Enable multi-sampling. --no-vsync Disable vsync. --bloom-multiplier FLOAT Adjust the amount of bloom. --bloom-intensity FLOAT Adjust the intensity of the bloom. --max-files NUMBER Set the maximum number of files or 0 for no limit. Excess files will be discarded. --max-file-lag SECONDS Max time files of a commit can take to appear. Use -1 for no limit. --max-user-speed UNITS Max speed users can travel per second. --user-friction SECONDS Time users take to come to a halt. --user-scale SCALE Change scale of user avatars. --camera-mode MODE Camera mode (overview,track). --disable-auto-rotate Disable automatic camera rotation. --disable-input Disable keyboard and mouse input. --hide DISPLAY_ELEMENT Hide one or more display elements from the list below: bloom - bloom effect date - current date dirnames - names of directories files - file icons filenames - names of files mouse - mouse cursor progress - progress bar widget root - root directory of tree tree - animated tree structure users - user avatars usernames - names of users Separate multiple elements with commas (eg "mouse,progress") --hash-seed SEED Change the seed of hash function. --caption-file FILE Caption file (see Caption Log Format). --caption-size SIZE Caption size. --caption-colour FFFFFF Caption colour in hex. --caption-duration SECONDS Caption duration. --caption-offset X Caption horizontal offset (0 to centre captions). -o, --output-ppm-stream FILE Output a PPM image stream to a file ('-' for STDOUT). This will automatically hide the progress bar initially and enable 'stop-at-end' unless other behaviour is specified. -r, --output-framerate FPS Framerate of output (25,30,60). Used with --output-ppm-stream. --output-custom-log FILE Output a custom format log file ('-' for STDOUT). --load-config CONFIG_FILE Load a gource conf file. --save-config CONFIG_FILE Save a gource conf file with the current options. --path PATH path Either a supported version control directory, a pre-generated log file (see log commands or the custom log format), a Gource conf file or '-' to read STDIN. If path is omitted, gource will attempt to read a log from the current directory. ``` Git, Bazaar, Mercurial and SVN Examples: View the log of the repository in the current path: ``` gource ``` View the log of a project in the specified directory: ``` gource my-project-dir ``` For large projects, generating a log of the project history may take a long time. For centralized VCS like SVN, generating the log may also put load on the central VCS server. In these cases, you may like to save a copy of the log for later use. You can generate a log in the VCS specific log format using the --log-command VCS option: ``` cd my-svn-project `gource --log-command svn` > my-svn-project.log gource my-svn-project.log ``` You can also have Gource write a copy of the log file in its own format: ``` gource --output-custom-log my-project-custom.log ``` CVS Support: Use 'cvs2cl' to generate the log and then pass it to Gource: ``` cvs2cl --chrono --stdout --xml -g-q > my-cvs-project.log gource my-cvs-project.log ``` Custom Log Format: If you want to use Gource with something other than the supported systems, there is a pipe ('|') delimited custom log format: timestamp - An ISO 8601 or unix timestamp of when the update occurred. username - The name of the user who made the update. type - initial for the update type - (A)dded, (M)odified or (D)eleted. file - Path of the file updated. colour - A colour for the file in hex (FFFFFF) format. Optional. Caption Log Format: Gource can display captions along the timeline by specifying a caption file (using --caption-file) in the pipe ('|') delimited format below: timestamp - An ISO 8601 or A unix timestamp of when to display the caption. caption - The caption Recording Videos: See the guide on the homepage for examples of recording videos with Gource: https://github.com/acaudwell/Gource/wiki/Videos More Information: Visit the Gource homepage for guides and examples of using Gource with various version control systems: https://gource.io Interface: The time shown in the top left of the screen is set initially from the first log entry read and is incremented according to the simulation speed (--seconds-per-day). Pressing SPACE at any time will pause/resume the simulation. While paused you may use the mouse to inspect the detail of individual files and users. TAB cycles through selecting the current visible users. The camera mode, either tracking activity or showing the entire code tree, can be toggled using the Middle mouse button. You can drag the left mouse button to manually control the camera. The right mouse button rotates the view. Interactive keyboard commands: (V) Toggle camera mode (C) Displays Gource logo (K) Toggle file extension key (M) Toggle mouse visibility (N) Jump forward in time to next log entry (S) Randomize colours (D) Toggle directory name display mode (F) Toggle file name display mode (U) Toggle user name display mode (G) Toggle display of users (T) Toggle display of directory tree edges (R) Toggle display of root directory edges (<>) Adjust time scale / user avatar movement speed (+-) Adjust simulation speed (Keypad +-) Adjust camera zoom (TAB) Cycle through visible users (F12) Screenshot (Alt+Enter) Fullscreen toggle (ESC) Quit Copyright ========= Gource - software version control visualization Copyright (C) 2009 Andrew Caudwell This program is free software: you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ================================================ FILE: THANKS ================================================ Cheers to everyone at Catalyst IT for their support and encouragement. ================================================ FILE: autogen.sh ================================================ #! /bin/sh if (autoreconf -f -i) ; then echo "autoreconf ran successfully." echo "Initializing submodules..." if (git submodule init) ; then echo "Updating submodules..." if (git submodule update --init --recursive) ; then echo "Run './configure && make' to continue." else echo "Error: could not update submodules!" fi else echo "Error: could not initialize submodules!" fi else echo "Running autoreconf failed, please make sure you have autoconf installed." fi ================================================ FILE: cmd/gource ================================================ #!/bin/sh GOURCE_CMD_DIR=`dirname "$0"` "$GOURCE_CMD_DIR/../gource.exe" "$@" ================================================ FILE: cmd/gource.cmd ================================================ @echo off "%~dp0\..\gource.exe" %* ================================================ FILE: configure.ac ================================================ # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. AC_PREREQ(2.61) AC_INIT(Gource, 0.57, [acaudwell@gmail.com]) AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_SRCDIR([src/main.h]) AM_INIT_AUTOMAKE([dist-bzip2 foreign subdir-objects]) AC_CANONICAL_HOST # Checks for programs. AC_PROG_CXX AC_LANG(C++) AC_CHECK_FUNCS([timegm unsetenv]) #Disable X11 on Macs unless required AS_IF([test "$with_x" != yes], [ case "$host_os" in darwin*) with_x="no" LIBS="$LIBS -framework CoreFoundation" ;; esac ], []) #GL AX_CHECK_GL AX_CHECK_GLU CXXFLAGS="$CXXFLAGS $GL_CFLAGS $GLU_CFLAGS" CPPFLAGS="$CPPFLAGS $GL_CFLAGS $GLU_CFLAGS" LIBS="$LIBS $GL_LIBS $GLU_LIBS" PKG_CHECK_MODULES([FT2], [freetype2 >= 9.0.3]) PKG_CHECK_MODULES([PCRE2], [libpcre2-8]) PKG_CHECK_MODULES([GLEW], [glew]) PKG_CHECK_MODULES([SDL2], [sdl2 SDL2_image]); PKG_CHECK_MODULES([PNG], [libpng >= 1.2]) CPPFLAGS="${CPPFLAGS} ${FT2_CFLAGS} ${PCRE2_CFLAGS} ${GLEW_CFLAGS} ${SDL2_CFLAGS} ${PNG_CFLAGS}" LIBS="${LIBS} ${FT2_LIBS} ${PCRE2_LIBS} ${GLEW_LIBS} ${SDL2_LIBS} ${PNG_LIBS}" AC_CHECK_FUNCS([IMG_LoadPNG_RW], , AC_MSG_ERROR([SDL2_image with PNG support required. Please see INSTALL])) AC_CHECK_FUNCS([IMG_LoadJPG_RW], , AC_MSG_ERROR([SDL2_image with JPEG support required. Please see INSTALL])) #BOOST AX_BOOST_BASE([1.69], , AC_MSG_ERROR(Boost Filesystem >= 1.69 is required. Please see INSTALL)) AX_BOOST_FILESYSTEM CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" LIBS="$LIBS $BOOST_SYSTEM_LIB $BOOST_FILESYSTEM_LIB" AC_ARG_ENABLE(font-file,[AS_HELP_STRING([--enable-font-file=FILE],[override the default font])],[gourcefontfile="$enableval"],[gourcefontfile=""]) AM_CONDITIONAL([FONTFILE], [test "x$gourcefontfile" != "x"]) AC_SUBST(gourcefontfile) #see if ttf-font-dir option is enabled AC_ARG_ENABLE(ttf-font-dir,[AS_HELP_STRING([--enable-ttf-font-dir=DIR],[directory containing GNU FreeFont TTF fonts])],[gourcefontdir="$enableval"],[gourcefontdir=""]) AM_CONDITIONAL([FONTDIR], [test "x$gourcefontdir" != "x"]) AC_SUBST(gourcefontdir) #GLM AC_CHECK_HEADER([glm/glm.hpp],, AC_MSG_ERROR(GLM headers are required. Please see INSTALL)) #see if building against system TinyXML library use_tinyxml_system_library=no AC_ARG_WITH(tinyxml, AS_HELP_STRING([--with-tinyxml],[Use system installed TinyXML library]), use_tinyxml_system_library=$withval) if test "x$use_tinyxml_system_library" = "xyes"; then AC_CHECK_LIB([tinyxml],[main],[],[AC_MSG_ERROR(TinyXML library was requested but not found)],[])ac_cv_lib_tinyxml=ac_cv_lib_tinyxml_main fi AM_CONDITIONAL(USE_BUNDLED_TINYXML, test "x$use_tinyxml_system_library" != "xyes") AC_CONFIG_FILES([Makefile]) AC_OUTPUT ================================================ FILE: contrib/svn-gource.py ================================================ #!/usr/bin/python ## Copyright (c) 2009 Cameron Hart (cam@bitshifter.net.nz) ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions ## are met: ## 1. Redistributions of source code must retain the above copyright ## notice, this list of conditions and the following disclaimer. ## 2. Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## 3. The name of the author may not be used to endorse or promote products ## derived from this software without specific prior written permission. ## ## THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR ## IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES ## OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ## IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, ## INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT ## NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF ## THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import sys import time import getopt import re from xml.etree import ElementTree opt_filter_dirs = False _USAGE = """ svn-gource.py [--help] [--filter-dirs] The input file must be the output of the command svn log --verbose --xml. """ # regular expression for matching any file with an extension extn_prog = re.compile(".*/?[^/]+\.[^\.]+$") def reverse(data): """Returns the log entries in reverse.""" for index in range(len(data)-1, -1, -1): yield data[index] def processXmltree(xmltree): global opt_filter_dirs for logentry in reverse(xmltree.getiterator("logentry")): datetext = logentry.find("date").text # svn xml logs always use UTC timestamp = (time.mktime(time.strptime(datetext[:-8], "%Y-%m-%dT%H:%M:%S"))) # a bit of a hack to get it into local time again... #timestamp = timestamp - time.timezone #author might not exist try: author = logentry.find("author").text except: author = "" # output all affected files for pathentry in logentry.getiterator("path"): # apply directory filtering strategy if opt_filter_dirs and not re.match(extn_prog, pathentry.text): continue; # join output print( "|".join( ( "%d" % int(timestamp), "%s" % author.encode("utf-8"), "%s" % pathentry.get("action"), "%s" % pathentry.text.encode("utf-8"), "" ) ) ) def printUsage(message): sys.stderr.write(_USAGE) if message: sys.exit('\nFATAL ERROR: ' + message) else: sys.exit(1) def processArguments(): global opt_filter_dirs try: opts, filenames = getopt.getopt(sys.argv[1:], '', ['help', 'filter-dirs']) except getopt.GetoptError: printUsage('Invalid arguments.') for (opt, val) in opts: if opt == '--help': printUsage(None) elif opt == '--filter-dirs': opt_filter_dirs = True if not filenames: printUsage('No input file specified.') return filenames[0] if __name__ == "__main__": filename = processArguments() xmltree = ElementTree.parse(filename) processXmltree(xmltree) ================================================ FILE: data/fonts/README ================================================ -*-text-*- GNU FreeFont The GNU FreeFont project aims to provide a useful set of free scalable (i.e., OpenType) fonts covering as much as possible of the ISO 10646/Unicode UCS (Universal Character Set). Statement of Purpose -------------------- The practical reason for putting glyphs together in a single font face is to conveniently mix symbols and characters from different writing systems, without having to switch fonts. Coverage -------- FreeFont covers the following character sets * ISO 8859 parts 1-15 * CEN MES-3 European Unicode Subset http://www.evertype.com/standards/iso10646/pdf/cwa13873.pdf * IBM/Microsoft code pages 437, 850, 852, 1250, 1252 and more * Microsoft/Adobe Windows Glyph List 4 (WGL4) http://www.microsoft.com/typography/otspec/WGL4.htm * KOI8-R and KOI8-RU * DEC VT100 graphics symbols * International Phonetic Alphabet * Arabic, Hebrew, Armenian, Georgian, Ethiopian and Thai alphabets, including Arabic presentation forms A/B * mathematical symbols, including the whole TeX repertoire of symbols * APL symbols etc. Editing ------- The free outline font editor, George Williams's FontForge is used for editing the fonts. Design Issues ------------- Which font shapes should be made? Historical style terms like Renaissance or Baroque letterforms cannot be applied beyond Latin/Cyrillic/Greek scripts to any greater extent than Kufi or Nashki can be applied beyond Arabic script; "italic" is really only meaningful for Latin letters. However, most modern writing systems have typographic formulations for contrasting uniform and modulated character stroke widths, and have some history with "oblique", faces. Since the advent of the typewriter, most have developed a typographic style with uniform-width characters. Accordingly, the FreeFont family has one monospaced - FreeMono - and two proportional faces (one with uniform stroke - FreeSans - and one with modulated stroke - FreeSerif). To make text from different writing systems look good side-by-side, each FreeFont face is meant to contain characters of similar style and weight. Licensing --------- Free UCS scalable fonts is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. The fonts are distributed in the hope that they will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. As a special exception, if you create a document which uses this font, and embed this font or unaltered portions of this font into the document, this font does not by itself cause the resulting document to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the document might be covered by the GNU General Public License. If you modify this font, you may extend this exception to your version of the font, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. Files and their suffixes ------------------------ The files with .sfd (Spline Font Database) are in FontForge's native format. Please use these if you plan to modify the font files. TrueType fonts for immediate consumption are the files with the .ttf (TrueType Font) suffix. These are ready to use in Xwindows based systems using FreeType, on Mac OS, and on older Windows systems. OpenType fonts (with suffix .otf) are for use in Windows Vista. Note that although they can be installed on Linux, but many applications in Linux still don't support them. -------------------------------------------------------------------------- Primoz Peterlin, Steve White Free UCS scalable fonts: http://savannah.gnu.org/projects/freefont/ $Id: README,v 1.7 2009/01/13 08:43:23 Stevan_White Exp $ ================================================ FILE: data/gource.1 ================================================ .TH Gource 1 .SH NAME Gource - a software version control visualization .SH SYNOPSIS \fIgource\fR [options] [path] .SH DESCRIPTION \fIgource\fR is an OpenGL-based 3D visualisation tool for source control repositories. The repository is displayed as a tree where the root of the repository is the centre, directories are branches and files are leaves. Contributors to the source code appear and disappear as they contribute to specific files and directories. .SH REQUIREMENTS \fIgource\fR requires a OpenGL capable video card to run. .SH OPTIONS .TP 8 \fB\-h, \-\-help\fR Help ('\fB-H\fR' for extended help). .TP \fB\-WIDTHxHEIGHT, \-\-viewport WIDTHxHEIGHT\fR Set the viewport size. If \-f is also supplied, will attempt to set the video mode to this also. Add ! to make the window non-resizable. .TP \fB\-f\fR Fullscreen. .TP \fB\-\-screen SCREEN\fR Set the number of the screen to display on. .TP \fB\-\-high\-dpi\fR Request a high DPI display when creating the window. On some platforms such as MacOS, the window resolution is specified in points instead of pixels. The \-\-high-dpi flag may be required to access some higher resolutions. E.g. requesting a high DPI 800x600 window may produce a window that is 1600x1200 pixels. .TP \fB\-\-window\-position XxY\fR Initial window position on your desktop which may be made up of multiple monitors. This will override the screen setting so don't specify both. .TP \fB\-\-frameless\fR Frameless window. .TP \fB\-\-transparent\fR Make the background transparent. Only really useful for screenshots. .TP \fB\-\-start\-date "YYYY\-MM\-DD hh:mm:ss +tz"\fR Start with the first entry after the supplied date and optional time. If a time zone offset isn't specified the local time zone is used. Example accepted formats: "2012-06-30" "2012-06-30 12:00" "2012-06-30 12:00:00 +12" .TP \fB\-\-stop\-date "YYYY\-MM\-DD hh:mm:ss +tz"\fR Stop at the last entry prior to the supplied date and optional time. Uses the same format as \-\-start\-date. .TP \fB\-p, \-\-start\-position POSITION\fR Begin at some position in the log (between 0.0 and 1.0 or 'random'). .TP \fB\-\-stop\-position POSITION\fR Stop (exit) at some position in the log (does not work with STDIN). .TP \fB\-t, \-\-stop\-at\-time SECONDS\fR Stop (exit) after a specified number of seconds. .TP \fB\-\-stop\-at\-end\fR Stop (exit) at the end of the log / stream. .TP \fB\-\-loop\fR Loop back to the start of the log when the end is reached. .TP \fB\-\-loop\-delay\-seconds SECONDS\fR Seconds to delay before looping. .TP \fB\-a, \-\-auto\-skip\-seconds SECONDS\fR Automatically skip to next entry if nothing happens for a specified number of seconds. .TP \fB\-s, \-\-seconds\-per\-day SECONDS\fR Speed of simulation in seconds per day. .TP \fB\-\-realtime\fR Realtime playback speed. .TP \fB\-\-no\-time\-travel\fR Use the time of the last commit if the time of a commit is in the past. .TP \fB\-\-author\-time\fR Use the timestamp of the author instead of the timestamp of the committer. .TP \fB\-c, \-\-time\-scale SCALE\fR Change simulation time scale. This affects the movement speed of user avatars. E.g. 0.5 for half speed, 2 for double speed. .TP \fB\-i, \-\-file\-idle\-time SECONDS\fR Time in seconds files remain idle before they are removed or 0 for no limit. .TP \fB\-\-file\-idle\-time\-at\-end SECONDS\fR Time in seconds files remain idle at the end before they are removed. .TP \fB\-e, \-\-elasticity FLOAT\fR Elasticity of nodes. .TP \fB\-b, \-\-background-colour FFFFFF\fR Background colour in hex. .TP \fB\-\-background\-image IMAGE\fR Set a background image. .TP \fB\-\-title TITLE\fR Set a title .TP \fB\-\-font\-file FILE\fR Specify the font. Should work with most font file formats supported by FreeType, such as TTF and OTF, among others. .TP \fB\-\-font\-scale SCALE\fR Scale the size of all fonts. .TP \fB\-\-font\-size SIZE\fR Font size used by the date and title. .TP \fB\-\-file\-font\-size SIZE\fR Font size of filenames. .TP \fB\-\-dir\-font\-size SIZE\fR Font size of directory names. .TP \fB\-\-user\-font\-size SIZE\fR Font size of user names. .TP \fB\-\-font\-colour FFFFFF\fR Font colour used by the date and title in hex. .TP \fB\-\-key\fR Show file extension key. .TP \fB\-\-logo IMAGE\fR Logo to display in the foreground. .TP \fB\-\-logo\-offset XxY\fR Offset position of the logo. .TP \fB\-\-date\-format FORMAT\fR Specify display date string (strftime format). .TP \fB\-\-log\-command VCS\fR Show the log command used by gource (git,svn,hg,bzr,cvs2cl). .TP \fB\-\-log\-format VCS\fR Specify format of the log being read (git,svn,hg,bzr,cvs2cl,custom). Required when reading from STDIN. .TP \fB\-\-git\-branch\fR Get the git log of a branch other than the current one. .TP \fB\-\-follow\-user USER\fR Have the camera automatically follow a particular user. .TP \fB\-\-highlight\-dirs\fR Highlight the names of all directories. .TP \fB\-\-highlight\-user USER\fR Highlight the names of a particular user. .TP \fB\-\-highlight\-users\fR Highlight the names of all users. .TP \fB\-\-highlight\-colour FFFFFF\fR Font colour for highlighted users in hex. .TP \fB\-\-selection\-colour FFFFFF\fR Font colour for selected users and files. .TP \fB\-\-filename\-colour FFFFFF\fR Font colour for filenames. .TP \fB\-\-dir\-colour FFFFFF\fR Font colour for directories. .TP \fB\-\-dir\-name\-depth DEPTH\fR Draw names of directories down to a specific depth in the tree. .TP \fB\-\-dir\-name\-position FLOAT Position along edge of the directory name (between 0.1 and 1.0, default is 0.5). .TP \fB\-\-filename\-time SECONDS\fR Duration to keep filenames on screen (>= 2.0). .TP \fB\-\-file\-extensions\fR Show filename extensions only. .TP \fB\-\-file\-extension\-fallback\fR Use filename as extension if the extension is missing or empty. .TP \fB\-\-file\-filter REGEX\fR Filter out file paths matching the specified regular expression. .TP \fB\-\-file\-show\-filter REGEX\fR Show only file paths matching the specified regular expression. .TP \fB\-\-user\-filter REGEX\fR Filter usernames matching the specified regular expression. .TP \fB\-\-user\-show\-filter REGEX\fR Show only usernames matching the specified regular expression. .TP \fB\-\-user\-image\-dir DIRECTORY\fR Directory containing .jpg or .png images of users (eg "Full Name.png") to use as avatars. .TP \fB\-\-default\-user\-image IMAGE\fR Path of .jpg to use as the default user image. .TP \fB\-\-fixed\-user\-size\fR Forces the size of the user image to remain fixed throughout. .TP \fB\-\-colour\-images\fR Colourize user images. .TP \fB\-\-crop AXIS\fR Crop view on an axis (vertical,horizontal). .TP \fB\-\-padding FLOAT\fR Camera view padding. .TP \fB\-\-multi\-sampling\fR Enable multi-sampling. .TP \fB\-\-no\-vsync\fR Disable vsync. .TP \fB\-\-bloom\-multiplier FLOAT\fR Adjust the amount of bloom. .TP \fB\-\-bloom\-intensity FLOAT\fR Adjust the intensity of the bloom. .TP \fB\-\-max\-files NUMBER\fR Set the maximum number of files or 0 for no limit. Excess files will be discarded. .TP \fB\-\-max\-file\-lag SECONDS\fR Max time files of a commit can take to appear. Use \-1 for no limit. .TP \fB\-\-max\-user\-speed UNITS\fR Max speed users can travel per second. .TP \fB\-\-user\-friction SECONDS\fR Time users take to come to a halt. .TP \fB\-\-user\-scale SCALE\fR Change scale of user avatars. .TP \fB\-\-camera\-mode MODE\fR Camera mode (overview,track). .TP \fB\-\-disable\-auto\-rotate\fR Disable automatic camera rotation. .TP \fB\-\-disable\-input\fR Disable keyboard and mouse input. .TP \fB\-\-hide DISPLAY_ELEMENT\fR Hide one or more display elements from the list below: bloom \- bloom effect date \- current date dirnames \- names of directories files \- file icons filenames \- names of files mouse \- mouse cursor progress \- progress bar widget root \- root directory of the tree tree \- animated tree structure users \- user avatars usernames \- names of users Separate multiple elements with commas (eg "mouse,progress") .TP \fB\-\-hash\-seed SEED\fR Change the seed of hash function. .TP \fB\-\-caption-file FILE Caption file (see Caption Log Format). .TP \fB\-\-caption-size SIZE Caption size. .TP \fB\-\-caption-colour FFFFFF Caption colour in hex. .TP \fB\-\-caption-duration SECONDS Caption duration. .TP \fB\-\-caption-offset X Caption horizontal offset (0 to centre captions). .TP \fB\-o, \-\-output\-ppm\-stream FILE\fR Output a PPM image stream to a file ('\-' for STDOUT). This will automatically hide the progress bar initially and enable 'stop\-at\-end' unless other behaviour is specified. .TP \fB\-r, \-\-output\-framerate FPS\fR Framerate of output (25,30,60). Used with \-\-output\-ppm\-stream. .TP \fB\-\-output\-custom\-log FILE\fR Output a custom format log file ('\-' for STDOUT). .TP \fB\-\-load\-config CONFIG_FILE\fR Load a config file. .TP \fB\-\-save\-config CONFIG_FILE\fR Save a config file with the current options. .TP \fB\-\-path PATH\fR .TP \fBpath\fR Either a supported version control directory, a pre-generated log file (see log commands or the custom log format), a Gource conf file or '-' to read STDIN. If path is omitted, gource will attempt to read a log from the current directory. .SS Git, Bazaar, Mercurial and SVN Examples View the log of the repository in the current path: .ti 10 \fIgource\fR View the log of a project in the specified directory: .ti 10 \fIgource\fR my\-project\-dir For large projects, generating a log of the project history may take a long time. For centralized VCS like SVN, generating the log will put load on the central VCS server. In these cases, you may like to save a copy of the log for later use. You can generate a log in the VCS specific log format using the \-\-log\-command VCS option: .ti 10 cd my\-svn\-project .ti 10 \`\fIgource\fR \-\-log\-command svn\` > my\-svn\-project.log .ti 10 \fIgource\fR my\-svn\-project.log You can also have Gource write a copy of the log file in its own format: .ti 10 \fIgource\fR \-\-output\-custom\-log my\-project\-custom.log .SS CVS Support Use 'cvs2cl' to generate the log and then pass it to Gource: .ti 10 cvs2cl \-\-chrono \-\-stdout \-\-xml \-g\-q > my\-cvs\-project.log .ti 10 gource my\-cvs\-project.log .SS Custom Log Format If you want to use Gource with something other than the supported systems, there is a pipe ('|') delimited custom log format: .ti 10 timestamp - An ISO 8601 or unix timestamp of when the update occurred. .ti 10 username - The name of the user who made the update. .ti 10 type - Single character for the update type - (A)dded, (M)odified or (D)eleted. .ti 10 file - Path of the file updated. .ti 10 colour - A colour for the file in hex (FFFFFF) format. Optional. .SS Caption Log Format Gource can display captions along the timeline by specifying a caption file (using \-\-caption\-file) in the pipe ('|') delimited format below: .ti 10 timestamp - An ISO 8601 or unix timestamp of when to display the caption. .ti 10 caption - The caption .SS Recording Videos See the guide on the homepage for examples of recording videos with Gource: .ti 10 https://github.com/acaudwell/Gource/wiki/Videos .SS More Information Visit the Gource homepage for guides and examples of using Gource with various version control systems: .ti 10 http://gource.io .SH INTERFACE The time shown in the top left of the screen is set initially from the first log entry read and is incremented according to the simulation speed (\-\-seconds\-per\-day). Pressing SPACE at any time will pause/resume the simulation. While paused you may use the mouse to inspect the detail of individual files and users. TAB cycles through selecting the current visible users. The camera mode, either tracking activity or showing the entire code tree, can be toggled using the Middle mouse button. You can drag the left mouse button to manually control the camera. The right mouse button rotates the view. Interactive keyboard commands: .sp .ti 10 (V) Toggle camera mode .ti 10 (C) Displays Gource logo .ti 10 (K) Toggle file extension key .ti 10 (M) Toggle mouse visibility .ti 10 (N) Jump forward in time to next log entry .ti 10 (S) Randomize colours .ti 10 (D) Toggle directory name display mode .ti 10 (F) Toggle file name display mode .ti 10 (U) Toggle user name display mode .ti 10 (G) Toggle display of users .ti 10 (T) Toggle display of directory tree edges .ti 10 (R) Toggle display of root directory edges .ti 10 (<>) Adjust time scale / user avatar movement speed .ti 10 (+-) Adjust simulation speed .ti 10 (Keypad +-) Adjust camera zoom .ti 10 (TAB) Cycle through visible users .ti 10 (F12) Screenshot .ti 10 (Alt+Enter) Fullscreen toggle .ti 10 (ESC) Quit .SH AUTHOR .nf Written by Andrew Caudwell Project Homepage: http://gource.io .SH COPYRIGHT .nf Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . .fi .SH ACKNOWLEDGEMENTS .nf Catalyst IT (catalyst.net.nz) For supporting the development of Gource! .fi ================================================ FILE: data/gource.style ================================================ changeset = '{file_adds}{file_copies}{file_mods}{file_dels}' file_mod = "{date|hgdate}|{author|person}|M|{file_mod}\n" file_add = "{date|hgdate}|{author|person}|A|{file_add}\n" file_del = "{date|hgdate}|{author|person}|D|{file_del}\n" file_copy = "{date|hgdate}|{author|person}|A|{name}\n" ================================================ FILE: data/shaders/bloom.frag ================================================ varying vec3 pos; void main() { float r = fract(sin(dot(pos.xy ,vec2(11.3713,67.3219))) * 2351.3718); float offset = (0.5 - r) * gl_TexCoord[0].x * 0.045; float intensity = min(1.0, cos((length(pos*2.0)+offset)/gl_TexCoord[0].x)); float gradient = intensity * smoothstep(0.0, 2.0, intensity); gradient *= smoothstep(1.0,0.67+r*0.33, 1.0-intensity); gl_FragColor = gl_Color * gradient; } ================================================ FILE: data/shaders/bloom.vert ================================================ varying vec3 pos; void main() { pos = gl_Vertex.xyz - gl_MultiTexCoord0.yzw; gl_TexCoord[0] = gl_MultiTexCoord0; gl_FrontColor = gl_Color; gl_Position = ftransform(); } ================================================ FILE: data/shaders/shadow.frag ================================================ uniform sampler2D tex; uniform float shadow_strength; void main(void) { vec4 colour = texture2D(tex,gl_TexCoord[0].st); gl_FragColor = vec4(0.0, 0.0, 0.0, gl_Color.w * colour.w * shadow_strength); } ================================================ FILE: data/shaders/shadow.vert ================================================ void main(void) { gl_TexCoord[0] = gl_MultiTexCoord0; gl_FrontColor = gl_Color; gl_Position = ftransform(); } ================================================ FILE: data/shaders/text.frag ================================================ uniform sampler2D tex; uniform float shadow_strength; uniform float texel_size; void main(void) { float colour_alpha = texture2D(tex,gl_TexCoord[0].xy).w; float shadow_alpha = texture2D(tex,gl_TexCoord[0].xy - vec2(texel_size)).w * shadow_strength; float combined_alpha = 1.0 - (1.0-shadow_alpha)*(1.0-colour_alpha); if(combined_alpha > 0.0) colour_alpha /= combined_alpha; gl_FragColor = gl_Color * vec4(vec3(colour_alpha), combined_alpha); } ================================================ FILE: data/shaders/text.vert ================================================ void main(void) { gl_TexCoord[0] = gl_MultiTexCoord0; gl_FrontColor = gl_Color; gl_Position = ftransform(); } ================================================ FILE: dev/.gitignore ================================================ builds/ ================================================ FILE: dev/bin/build_tar.pl ================================================ #!/usr/bin/perl #copy stuff we want to go into the gource source tar ball use strict; use warnings; use FindBin; use File::Path; use File::Copy; use Date::Format; use Getopt::Long qw(GetOptions); use Cwd; sub gource_version { my $version = `cat $FindBin::Bin/../../src/gource_settings.h | grep GOURCE_VERSION`; $version =~ /"([^"]+)"/ or die("could not determine version\n"); $version = $1; return $version; } my $VERSION = gource_version(); my @exclusions = ( qr{^/autogen\.sh$}, qr{^/backup/}, qr{^/confs/}, qr{^/cmd/}, qr{^/resources/}, qr{^/tests/}, qr{^/scripts/}, qr{^/contrib/}, qr{^/config.status$}, qr{^/config.log$}, qr{^/gource$}, qr{^/dev/}, qr{^/logs/}, qr{/\.}, qr{Makefile$}, qr{\.o$}, qr{^/todo.txt$}, qr{^/build-stamp$}, qr{^/autom4te}, qr{^/src/core/README$}, qr{^/src/core/ui/}, qr{\.d$}, ); my @inclusions = ( qr{^/gource\.pro$}, qr{^/ChangeLog$}, qr{^/THANKS$}, qr{^/COPYING$}, qr{^/INSTALL$}, qr{^/README\.md$}, qr{/Makefile\.(?:am|in)$}, qr{^/aclocal\.m4$}, qr{^/m4/.+\.m4$}, qr{^/configure(?:\.ac)?$}, qr{^/src/.+\.(?:cpp|h|cc|hh)$}, qr{^/data/file\.png$}, qr{^/data/user\.png$}, qr{^/data/beam\.png$}, qr{^/data/bloom\.tga$}, qr{^/data/bloom_alpha\.tga$}, qr{^/data/cursor\.png$}, qr{^/data/fonts/FreeSans\.ttf$}, qr{^/data/gource\.1$}, qr{^/data/gource\.style$}, qr{^/data/fonts/README$}, qr{^/data/shaders/bloom\.(?:vert|frag)$}, qr{^/data/shaders/shadow\.(?:vert|frag)$}, qr{^/data/shaders/text\.(?:vert|frag)$}, qr{^/build-aux/(?:compile|config.(?:guess|sub)|depcomp|install-sh|missing|test-driver)$}, ); my $tmp_path = "/var/tmp/gource-$VERSION"; system("rm -r $tmp_path") if -d $tmp_path; mkpath($tmp_path) or die("failed to make temp folder $tmp_path"); chdir("$FindBin::Bin/../../"); my @files = `find .`; #check configure.ac has been updated unless(`cat configure.ac` =~ /AC_INIT\(Gource, $VERSION,/) { die("configure.ac does not mention current version number\n"); } #check ChangeLog has been updated unless(`cat ChangeLog` =~ /^$VERSION:/) { die("ChangeLog does not mention current version number\n"); } #if Makefile exists, do distclean if(-e 'Makefile') { if(system("make distclean") != 0) { die("make distclean failed: $!\n"); } } #reconfigure if(system("autoreconf -f -i -v") != 0) { die("autoreconf failed: $!\n"); } foreach my $file (@files) { $file =~ s/[\r\n]+//; $file =~ s/^\.//; (my $relfile = $file) =~ s{^/}{}; (my $dir = $file) =~ s{[^/]+$}{/}; next if $file =~ /^\s*$/; next if -d $relfile; next if grep { $file =~ $_ } @exclusions; unless(grep { $file =~ $_ } @inclusions) { warn "WARNING: nothing known about $file\n"; next; } mkpath("$tmp_path/$dir"); if(system("cp", "$relfile", "$tmp_path/$relfile") != 0) { die("error copying $file to $tmp_path/$relfile: $? $!\n"); } } my $current_dir = cwd; chdir("/var/tmp/"); my $archive = "gource-$VERSION.tar.gz"; if(system("tar -czf $archive gource-$VERSION") !=0) { die("failed to make archive $archive"); } unlink("$FindBin::Bin/../builds/$archive"); my $builds_dir = "$FindBin::Bin/../builds/"; system('mkdir', '-p', $builds_dir); unlink("$builds_dir/$archive") if -e "$builds_dir/$archive"; move("$archive", $builds_dir); system("rm -r $tmp_path"); print "Built $archive\n"; ================================================ FILE: dev/bin/build_win64.pl ================================================ #!/usr/bin/perl # windows archive + installer generator use strict; use warnings; use FindBin; use File::Copy; my $base_dir = "$FindBin::Bin/../.."; my $build_dir = "$base_dir/../build-gource-Msys2_64_bit-Release/release"; my $binaries_dir = "$base_dir/dev/win64"; my $builds_output_dir = "$base_dir/dev/builds"; my $makensis = "'C:\\Program Files (x86)\\NSIS\\makensis.exe'"; sub gource_version { my $version = `cat $base_dir/src/gource_settings.h | grep GOURCE_VERSION`; $version =~ /"([^"]+)"/ or die("could not determine version\n"); $version = $1; return $version; } sub doit { my $cmd = shift; if(system($cmd) != 0) { die("command '$cmd' failed: $!"); } } sub dosify { my($src, $dest) = @_; my $content = `cat $src`; $content =~ s/\r?\n/\r\n/g; open OUTPUT, ">$dest" or die("$!"); print OUTPUT $content; close OUTPUT; } my @dll_files; sub update_binaries { copy("$build_dir/gource.exe", "$binaries_dir/gource.exe") or die("failed to copy $build_dir/gource.exe: $!\n"); chdir($binaries_dir) or die("failed to change directory to $binaries_dir\n"); for my $existing_dll (glob("*.dll")) { unlink($existing_dll) or die("failed to remove existing dll $existing_dll: $!\n"); } my @dlls = `cygcheck ./gource.exe | grep msys`; for my $dll (@dlls) { $dll =~ s/^\s+//g; $dll =~ s/[\r\n]//g; my($name) = $dll =~ m{\\([^\\]+\.dll)$}; warn "adding $name\n"; copy($dll, "$binaries_dir/$name") or die "failed to copy $name: $!\n"; push @dll_files, $name; } } my $nsis_script = q[ !define MULTIUSER_MUI !define MULTIUSER_EXECUTIONLEVEL Highest !define MULTIUSER_INSTALLMODE_COMMANDLINE !define MULTIUSER_USE_PROGRAMFILES64 !define MULTIUSER_INSTALLMODE_DEFAULT_REGISTRY_KEY "Software\Gource" !define MULTIUSER_INSTALLMODE_INSTDIR_REGISTRY_KEY "Software\Gource" !define MULTIUSER_INSTALLMODE_DEFAULT_REGISTRY_VALUENAME "Install_Mode" !define MULTIUSER_INSTALLMODE_INSTDIR_REGISTRY_VALUENAME "Install_Dir" !define MULTIUSER_INSTALLMODE_INSTDIR "Gource" !include "x64.nsh" !include "MultiUser.nsh" !include "MUI2.nsh" !include "LogicLib.nsh" !include "SafeEnvVarUpdate.nsh" Name "Gource GOURCE_VERSION" OutFile "GOURCE_INSTALLER" !define MUI_WELCOMEFINISHPAGE_BITMAP "..\..\nsis\welcome.bmp" !define MUI_UNWELCOMEFINISHPAGE_BITMAP "..\..\nsis\welcome.bmp" !define MUI_COMPONENTSPAGE_NODESC !insertmacro MULTIUSER_PAGE_INSTALLMODE !insertmacro MUI_PAGE_WELCOME !define MUI_PAGE_HEADER_TEXT "Legal Disclaimer" !insertmacro MUI_PAGE_LICENSE "..\..\nsis\disclaimer.txt" !insertmacro MUI_PAGE_COMPONENTS !insertmacro MUI_PAGE_DIRECTORY !insertmacro MUI_PAGE_INSTFILES !insertmacro MUI_PAGE_FINISH !insertmacro MUI_LANGUAGE "English" Function .onInit ${IfNot} ${RunningX64} MessageBox MB_OK "This installer requires 64-bit Windows" Quit ${EndIf} !insertmacro MULTIUSER_INIT ReadRegStr $R0 SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\Gource" "UninstallString" StrCmp $R0 "" done MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \ "Gource appears to already be installed. $\n$\nClick OK to remove the previous version and continue the installation." \ IDOK uninst Abort uninst: ClearErrors ExecWait $R0 done: FunctionEnd Function un.onInit !insertmacro MULTIUSER_UNINIT FunctionEnd Section "Gource" SecGource SectionIn RO GOURCE_INSTALL_LIST writeUninstaller $INSTDIR\uninstall.exe WriteRegStr SHCTX "Software\Gource" ${MULTIUSER_INSTALLMODE_INSTDIR_REGISTRY_VALUENAME} "$INSTDIR" WriteRegStr SHCTX "Software\Gource" ${MULTIUSER_INSTALLMODE_DEFAULT_REGISTRY_VALUENAME} "$MultiUser.InstallMode" WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\Gource" "DisplayName" "Gource" WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\Gource" "DisplayVersion" "GOURCE_VERSION" WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\Gource" "Publisher" "acaudwell" WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\Gource" "UninstallString" '"$INSTDIR\uninstall.exe"' WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\Gource" "QuietUninstallString" '"$INSTDIR\uninstall.exe" /S' WriteRegDWORD SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\Gource" "NoModify" 1 WriteRegDWORD SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\Gource" "NoRepair" 1 SectionEnd Section "Add to PATH" SecAddtoPath ${If} $MultiUser.InstallMode == "AllUsers" ${EnvVarUpdate} $0 "PATH" "A" "HKLM" "$INSTDIR\cmd" ${ElseIf} $MultiUser.InstallMode == "CurrentUser" ${EnvVarUpdate} $0 "PATH" "A" "HKCU" "$INSTDIR\cmd" ${EndIf} SectionEnd Section "Uninstall" ${If} $MultiUser.InstallMode == "AllUsers" ${un.EnvVarUpdate} $0 "PATH" "R" "HKLM" "$INSTDIR\cmd" ${ElseIf} $MultiUser.InstallMode == "CurrentUser" ${un.EnvVarUpdate} $0 "PATH" "R" "HKCU" "$INSTDIR\cmd" ${EndIf} DeleteRegKey SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\Gource" DeleteRegKey SHCTX "Software\Gource" GOURCE_UNINSTALL_LIST GOURCE_UNINSTALL_DIRS Delete $INSTDIR\uninstall.exe RMDir "$INSTDIR" SectionEnd ]; my @gource_files = qw( data/beam.png data/file.png data/user.png data/bloom.tga data/bloom_alpha.tga data/gource.style data/fonts/FreeSans.ttf data/shaders/bloom.frag data/shaders/bloom.vert data/shaders/shadow.frag data/shaders/shadow.vert data/shaders/text.frag data/shaders/text.vert cmd/gource.cmd cmd/gource ); my @gource_txts = qw( README.md ChangeLog data/fonts/README COPYING THANKS ); my @bin_files = qw( gource.exe ); my @gource_dirs = qw( data data/fonts data/shaders cmd ); mkdir($binaries_dir) unless -d $binaries_dir; mkdir($builds_output_dir) unless -d $builds_output_dir; my $tmp_dir = "$builds_output_dir/gource-build.$$"; doit("rm $tmp_dir") if -d $tmp_dir; mkdir($tmp_dir); # create directories foreach my $dir (@gource_dirs) { mkdir("$tmp_dir/$dir"); } my @gource_bundle; update_binaries(); chdir("$base_dir") or die("chdir to $base_dir failed"); # copy binaries foreach my $file (@bin_files, @dll_files) { doit("cp $binaries_dir/$file $tmp_dir/$file"); push @gource_bundle, $file; } # copy general files foreach my $file (@gource_files) { doit("cp $file $tmp_dir/$file"); push @gource_bundle, $file; } # convert text files foreach my $file (@gource_txts) { (my $file_prefix = $file) =~ s/\..+$//; my $txt_file = "$file_prefix.txt"; dosify("$file", "$tmp_dir/$txt_file"); push @gource_bundle, $txt_file; } my $version = gource_version(); my $installer_name = "gource-${version}.win64-setup.exe"; my $archive_name = "gource-${version}.win64.zip"; my $install_list = ''; foreach my $dir ('', @gource_dirs) { my @dir_files = map { my $f = $_; $f =~ s{/}{\\}g; $f; } grep { my $d = /^(.+)\// ? $1 : ''; $d eq $dir } @gource_bundle; (my $output_dir = $dir) =~ s{/}{\\}g; $install_list .= "\n" . ' SetOutPath "$INSTDIR' . ( $dir ? "\\$output_dir" : "" ) . "\"\n\n"; foreach my $file (@dir_files) { $install_list .= ' File '.$file."\n"; } } my $uninstall_list = join("\n", map { my $f = $_; $f =~ s{/}{\\}g; ' Delete $INSTDIR\\'.$f } @gource_bundle); my $uninstall_dirs = join("\n", map { my $d = $_; $d =~ s{/}{\\}g; ' RMDir $INSTDIR\\'.$d } reverse @gource_dirs); $nsis_script =~ s/GOURCE_VERSION/$version/g; $nsis_script =~ s/GOURCE_INSTALLER/$installer_name/g; $nsis_script =~ s/GOURCE_INSTALL_LIST/$install_list/; $nsis_script =~ s/GOURCE_UNINSTALL_LIST/$uninstall_list/; $nsis_script =~ s/GOURCE_UNINSTALL_DIRS/$uninstall_dirs/; $nsis_script =~ s/\n/\r\n/g; chdir($tmp_dir) or die("failed to change directory to '$tmp_dir'\n"); # remove existing copies of the version installer if they exist unlink("../$installer_name") if -e "../$installer_name"; unlink("../$archive_name") if -e "../$archive_name"; my $output_file = "gource.nsi"; open my $NSIS_HANDLE, ">$output_file" or die("failed to open $output_file: $!"); print $NSIS_HANDLE $nsis_script; close $NSIS_HANDLE; # generate installer # assert we have the long string build of NSIS doit("$makensis -HDRINFO | grep -q NSIS_MAX_STRLEN=8192"); doit("$makensis $output_file"); doit("rm $output_file"); doit("mv $installer_name .."); # also create zip archive doit("zip -r $archive_name *"); doit("mv $archive_name .."); chdir("$tmp_dir/.."); doit("rm -rf $tmp_dir"); ================================================ FILE: dev/nsis/disclaimer.txt ================================================ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: gource.pro ================================================ # Note: this project file currently only implements building on Windows with Mingw-w64 # See the INSTALL file for building instructions TEMPLATE = app CONFIG += console CONFIG -= app_bundle CONFIG -= qt DEFINES -= UNICODE CONFIG += c++11 CONFIG += object_parallel_to_source gcc { QMAKE_CXXFLAGS_WARN_ON = -Wall -Wno-unused-variable -Wno-sign-compare -Wno-unused-parameter -Wno-reorder QMAKE_CXXFLAGS_DEBUG += -DASSERTS_ENABLED } mingw { QMAKE_CXXFLAGS += -Dmain=SDL_main QMAKE_LFLAGS += -mconsole INCLUDEPATH += C:\msys64\mingw64\include\SDL2 INCLUDEPATH += C:\msys64\mingw64\include\freetype2 LIBS += -lmingw32 -lSDL2main -lSDL2.dll LIBS += -lSDL2_image.dll -lfreetype.dll -lpcre2-8.dll -lpng.dll -lglew32.dll -lboost_system-mt -lboost_filesystem-mt -lopengl32 -lglu32 LIBS += -static-libgcc -static-libstdc++ LIBS += -lcomdlg32 } VPATH += ./src SOURCES += \ action.cpp \ bloom.cpp \ caption.cpp \ dirnode.cpp \ file.cpp \ gource.cpp \ gource_settings.cpp \ gource_shell.cpp \ key.cpp \ logmill.cpp \ main.cpp \ pawn.cpp \ slider.cpp \ spline.cpp \ textbox.cpp \ user.cpp \ zoomcamera.cpp \ formats/apache.cpp \ formats/bzr.cpp \ formats/commitlog.cpp \ formats/custom.cpp \ formats/cvs-exp.cpp \ formats/cvs2cl.cpp \ formats/git.cpp \ formats/gitraw.cpp \ formats/hg.cpp \ formats/svn.cpp \ tinyxml/tinystr.cpp \ tinyxml/tinyxml.cpp \ tinyxml/tinyxmlerror.cpp \ tinyxml/tinyxmlparser.cpp \ core/conffile.cpp \ core/display.cpp \ core/frustum.cpp \ core/fxfont.cpp \ core/logger.cpp \ core/mousecursor.cpp \ core/plane.cpp \ core/png_writer.cpp \ core/ppm.cpp \ core/quadtree.cpp \ core/regex.cpp \ core/resource.cpp \ core/sdlapp.cpp \ core/seeklog.cpp \ core/settings.cpp \ core/shader.cpp \ core/shader_common.cpp \ core/stringhash.cpp \ core/texture.cpp \ core/tga.cpp \ core/timezone.cpp \ core/vbo.cpp \ core/vectors.cpp HEADERS += \ action.h \ bloom.h \ caption.h \ dirnode.h \ file.h \ gource.h \ gource_settings.h \ gource_shell.h \ key.h \ logmill.h \ main.h \ pawn.h \ slider.h \ spline.h \ textbox.h \ user.h \ zoomcamera.h \ formats/apache.h \ formats/bzr.h \ formats/commitlog.h \ formats/custom.h \ formats/cvs-exp.h \ formats/cvs2cl.h \ formats/git.h \ formats/gitraw.h \ formats/hg.h \ formats/svn.h \ tinyxml/tinystr.h \ tinyxml/tinyxml.h \ core/bounds.h \ core/conffile.h \ core/display.h \ core/frustum.h \ core/fxfont.h \ core/gl.h \ core/logger.h \ core/mousecursor.h \ core/pi.h \ core/plane.h \ core/png_writer.h \ core/ppm.h \ core/quadtree.h \ core/regex.h \ core/resource.h \ core/sdlapp.h \ core/seeklog.h \ core/settings.h \ core/shader.h \ core/shader_common.h \ core/stringhash.h \ core/texture.h \ core/tga.h \ core/timezone.h \ core/vbo.h \ core/vectors.h DISTFILES += \ data/shaders/bloom.frag \ data/shaders/shadow.frag \ data/shaders/text.frag \ data/shaders/bloom.vert \ data/shaders/shadow.vert \ data/shaders/text.vert ================================================ FILE: m4/ax_boost_base.m4 ================================================ # =========================================================================== # https://www.gnu.org/software/autoconf-archive/ax_boost_base.html # =========================================================================== # # SYNOPSIS # # AX_BOOST_BASE([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) # # DESCRIPTION # # Test for the Boost C++ libraries of a particular version (or newer) # # If no path to the installed boost library is given the macro searches # under /usr, /usr/local, /opt, /opt/local and /opt/homebrew and evaluates # the $BOOST_ROOT environment variable. Further documentation is available # at . # # This macro calls: # # AC_SUBST(BOOST_CPPFLAGS) / AC_SUBST(BOOST_LDFLAGS) # # And sets: # # HAVE_BOOST # # LICENSE # # Copyright (c) 2008 Thomas Porschberg # Copyright (c) 2009 Peter Adolphs # # Copying and distribution of this file, with or without modification, are # permitted in any medium without royalty provided the copyright notice # and this notice are preserved. This file is offered as-is, without any # warranty. #serial 55 # example boost program (need to pass version) m4_define([_AX_BOOST_BASE_PROGRAM], [AC_LANG_PROGRAM([[ #include ]],[[ (void) ((void)sizeof(char[1 - 2*!!((BOOST_VERSION) < ($1))])); ]])]) AC_DEFUN([AX_BOOST_BASE], [ AC_ARG_WITH([boost], [AS_HELP_STRING([--with-boost@<:@=ARG@:>@], [use Boost library from a standard location (ARG=yes), from the specified location (ARG=), or disable it (ARG=no) @<:@ARG=yes@:>@ ])], [ AS_CASE([$withval], [no],[want_boost="no";_AX_BOOST_BASE_boost_path=""], [yes],[want_boost="yes";_AX_BOOST_BASE_boost_path=""], [want_boost="yes";_AX_BOOST_BASE_boost_path="$withval"]) ], [want_boost="yes"]) AC_ARG_WITH([boost-libdir], [AS_HELP_STRING([--with-boost-libdir=LIB_DIR], [Force given directory for boost libraries. Note that this will override library path detection, so use this parameter only if default library detection fails and you know exactly where your boost libraries are located.])], [ AS_IF([test -d "$withval"], [_AX_BOOST_BASE_boost_lib_path="$withval"], [AC_MSG_ERROR([--with-boost-libdir expected directory name])]) ], [_AX_BOOST_BASE_boost_lib_path=""]) BOOST_LDFLAGS="" BOOST_CPPFLAGS="" AS_IF([test "x$want_boost" = "xyes"], [_AX_BOOST_BASE_RUNDETECT([$1],[$2],[$3])]) AC_SUBST(BOOST_CPPFLAGS) AC_SUBST(BOOST_LDFLAGS) ]) # convert a version string in $2 to numeric and affect to polymorphic var $1 AC_DEFUN([_AX_BOOST_BASE_TONUMERICVERSION],[ AS_IF([test "x$2" = "x"],[_AX_BOOST_BASE_TONUMERICVERSION_req="1.20.0"],[_AX_BOOST_BASE_TONUMERICVERSION_req="$2"]) _AX_BOOST_BASE_TONUMERICVERSION_req_shorten=`expr $_AX_BOOST_BASE_TONUMERICVERSION_req : '\([[0-9]]*\.[[0-9]]*\)'` _AX_BOOST_BASE_TONUMERICVERSION_req_major=`expr $_AX_BOOST_BASE_TONUMERICVERSION_req : '\([[0-9]]*\)'` AS_IF([test "x$_AX_BOOST_BASE_TONUMERICVERSION_req_major" = "x"], [AC_MSG_ERROR([You should at least specify libboost major version])]) _AX_BOOST_BASE_TONUMERICVERSION_req_minor=`expr $_AX_BOOST_BASE_TONUMERICVERSION_req : '[[0-9]]*\.\([[0-9]]*\)'` AS_IF([test "x$_AX_BOOST_BASE_TONUMERICVERSION_req_minor" = "x"], [_AX_BOOST_BASE_TONUMERICVERSION_req_minor="0"]) _AX_BOOST_BASE_TONUMERICVERSION_req_sub_minor=`expr $_AX_BOOST_BASE_TONUMERICVERSION_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'` AS_IF([test "X$_AX_BOOST_BASE_TONUMERICVERSION_req_sub_minor" = "X"], [_AX_BOOST_BASE_TONUMERICVERSION_req_sub_minor="0"]) _AX_BOOST_BASE_TONUMERICVERSION_RET=`expr $_AX_BOOST_BASE_TONUMERICVERSION_req_major \* 100000 \+ $_AX_BOOST_BASE_TONUMERICVERSION_req_minor \* 100 \+ $_AX_BOOST_BASE_TONUMERICVERSION_req_sub_minor` AS_VAR_SET($1,$_AX_BOOST_BASE_TONUMERICVERSION_RET) ]) dnl Run the detection of boost should be run only if $want_boost AC_DEFUN([_AX_BOOST_BASE_RUNDETECT],[ _AX_BOOST_BASE_TONUMERICVERSION(WANT_BOOST_VERSION,[$1]) succeeded=no AC_REQUIRE([AC_CANONICAL_HOST]) dnl On 64-bit systems check for system libraries in both lib64 and lib. dnl The former is specified by FHS, but e.g. Debian does not adhere to dnl this (as it rises problems for generic multi-arch support). dnl The last entry in the list is chosen by default when no libraries dnl are found, e.g. when only header-only libraries are installed! AS_CASE([${host_cpu}], [x86_64],[libsubdirs="lib64 libx32 lib lib64"], [mips*64*],[libsubdirs="lib64 lib32 lib lib64"], [ppc64|powerpc64|s390x|sparc64|aarch64|ppc64le|powerpc64le|riscv64|e2k|loongarch64],[libsubdirs="lib64 lib lib64"], [libsubdirs="lib"] ) dnl allow for real multi-arch paths e.g. /usr/lib/x86_64-linux-gnu. Give dnl them priority over the other paths since, if libs are found there, they dnl are almost assuredly the ones desired. AS_CASE([${host_cpu}], [i?86],[multiarch_libsubdir="lib/i386-${host_os}"], [armv7l],[multiarch_libsubdir="lib/arm-${host_os}"], [multiarch_libsubdir="lib/${host_cpu}-${host_os}"] ) dnl first we check the system location for boost libraries dnl this location is chosen if boost libraries are installed with the --layout=system option dnl or if you install boost with RPM AS_IF([test "x$_AX_BOOST_BASE_boost_path" != "x"],[ AC_MSG_CHECKING([for boostlib >= $1 ($WANT_BOOST_VERSION) includes in "$_AX_BOOST_BASE_boost_path/include"]) AS_IF([test -d "$_AX_BOOST_BASE_boost_path/include" && test -r "$_AX_BOOST_BASE_boost_path/include"],[ AC_MSG_RESULT([yes]) BOOST_CPPFLAGS="-I$_AX_BOOST_BASE_boost_path/include" for _AX_BOOST_BASE_boost_path_tmp in $multiarch_libsubdir $libsubdirs; do AC_MSG_CHECKING([for boostlib >= $1 ($WANT_BOOST_VERSION) lib path in "$_AX_BOOST_BASE_boost_path/$_AX_BOOST_BASE_boost_path_tmp"]) AS_IF([test -d "$_AX_BOOST_BASE_boost_path/$_AX_BOOST_BASE_boost_path_tmp" && test -r "$_AX_BOOST_BASE_boost_path/$_AX_BOOST_BASE_boost_path_tmp" ],[ AC_MSG_RESULT([yes]) BOOST_LDFLAGS="-L$_AX_BOOST_BASE_boost_path/$_AX_BOOST_BASE_boost_path_tmp"; break; ], [AC_MSG_RESULT([no])]) done],[ AC_MSG_RESULT([no])]) ],[ if test X"$cross_compiling" = Xyes; then search_libsubdirs=$multiarch_libsubdir else search_libsubdirs="$multiarch_libsubdir $libsubdirs" fi for _AX_BOOST_BASE_boost_path_tmp in /usr /usr/local /opt /opt/local /opt/homebrew ; do if test -d "$_AX_BOOST_BASE_boost_path_tmp/include/boost" && test -r "$_AX_BOOST_BASE_boost_path_tmp/include/boost" ; then for libsubdir in $search_libsubdirs ; do if ls "$_AX_BOOST_BASE_boost_path_tmp/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi done BOOST_LDFLAGS="-L$_AX_BOOST_BASE_boost_path_tmp/$libsubdir" BOOST_CPPFLAGS="-I$_AX_BOOST_BASE_boost_path_tmp/include" break; fi done ]) dnl overwrite ld flags if we have required special directory with dnl --with-boost-libdir parameter AS_IF([test "x$_AX_BOOST_BASE_boost_lib_path" != "x"], [BOOST_LDFLAGS="-L$_AX_BOOST_BASE_boost_lib_path"]) AC_MSG_CHECKING([for boostlib >= $1 ($WANT_BOOST_VERSION)]) CPPFLAGS_SAVED="$CPPFLAGS" CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" export CPPFLAGS LDFLAGS_SAVED="$LDFLAGS" LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" export LDFLAGS AC_REQUIRE([AC_PROG_CXX]) AC_LANG_PUSH(C++) AC_COMPILE_IFELSE([_AX_BOOST_BASE_PROGRAM($WANT_BOOST_VERSION)],[ AC_MSG_RESULT(yes) succeeded=yes found_system=yes ],[ ]) AC_LANG_POP([C++]) dnl if we found no boost with system layout we search for boost libraries dnl built and installed without the --layout=system option or for a staged(not installed) version if test "x$succeeded" != "xyes" ; then CPPFLAGS="$CPPFLAGS_SAVED" LDFLAGS="$LDFLAGS_SAVED" BOOST_CPPFLAGS= if test -z "$_AX_BOOST_BASE_boost_lib_path" ; then BOOST_LDFLAGS= fi _version=0 if test -n "$_AX_BOOST_BASE_boost_path" ; then if test -d "$_AX_BOOST_BASE_boost_path" && test -r "$_AX_BOOST_BASE_boost_path"; then for i in `ls -d $_AX_BOOST_BASE_boost_path/include/boost-* 2>/dev/null`; do _version_tmp=`echo $i | sed "s#$_AX_BOOST_BASE_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'` V_CHECK=`expr $_version_tmp \> $_version` if test "x$V_CHECK" = "x1" ; then _version=$_version_tmp fi VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'` BOOST_CPPFLAGS="-I$_AX_BOOST_BASE_boost_path/include/boost-$VERSION_UNDERSCORE" done dnl if nothing found search for layout used in Windows distributions if test -z "$BOOST_CPPFLAGS"; then if test -d "$_AX_BOOST_BASE_boost_path/boost" && test -r "$_AX_BOOST_BASE_boost_path/boost"; then BOOST_CPPFLAGS="-I$_AX_BOOST_BASE_boost_path" fi fi dnl if we found something and BOOST_LDFLAGS was unset before dnl (because "$_AX_BOOST_BASE_boost_lib_path" = ""), set it here. if test -n "$BOOST_CPPFLAGS" && test -z "$BOOST_LDFLAGS"; then for libsubdir in $libsubdirs ; do if ls "$_AX_BOOST_BASE_boost_path/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi done BOOST_LDFLAGS="-L$_AX_BOOST_BASE_boost_path/$libsubdir" fi fi else if test "x$cross_compiling" != "xyes" ; then for _AX_BOOST_BASE_boost_path in /usr /usr/local /opt /opt/local /opt/homebrew ; do if test -d "$_AX_BOOST_BASE_boost_path" && test -r "$_AX_BOOST_BASE_boost_path" ; then for i in `ls -d $_AX_BOOST_BASE_boost_path/include/boost-* 2>/dev/null`; do _version_tmp=`echo $i | sed "s#$_AX_BOOST_BASE_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'` V_CHECK=`expr $_version_tmp \> $_version` if test "x$V_CHECK" = "x1" ; then _version=$_version_tmp best_path=$_AX_BOOST_BASE_boost_path fi done fi done VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'` BOOST_CPPFLAGS="-I$best_path/include/boost-$VERSION_UNDERSCORE" if test -z "$_AX_BOOST_BASE_boost_lib_path" ; then for libsubdir in $libsubdirs ; do if ls "$best_path/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi done BOOST_LDFLAGS="-L$best_path/$libsubdir" fi fi if test -n "$BOOST_ROOT" ; then for libsubdir in $libsubdirs ; do if ls "$BOOST_ROOT/stage/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi done if test -d "$BOOST_ROOT" && test -r "$BOOST_ROOT" && test -d "$BOOST_ROOT/stage/$libsubdir" && test -r "$BOOST_ROOT/stage/$libsubdir"; then version_dir=`expr //$BOOST_ROOT : '.*/\(.*\)'` stage_version=`echo $version_dir | sed 's/boost_//' | sed 's/_/./g'` stage_version_shorten=`expr $stage_version : '\([[0-9]]*\.[[0-9]]*\)'` V_CHECK=`expr $stage_version_shorten \>\= $_version` if test "x$V_CHECK" = "x1" && test -z "$_AX_BOOST_BASE_boost_lib_path" ; then AC_MSG_NOTICE(We will use a staged boost library from $BOOST_ROOT) BOOST_CPPFLAGS="-I$BOOST_ROOT" BOOST_LDFLAGS="-L$BOOST_ROOT/stage/$libsubdir" fi fi fi fi CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" export CPPFLAGS LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" export LDFLAGS AC_LANG_PUSH(C++) AC_COMPILE_IFELSE([_AX_BOOST_BASE_PROGRAM($WANT_BOOST_VERSION)],[ AC_MSG_RESULT(yes) succeeded=yes found_system=yes ],[ ]) AC_LANG_POP([C++]) fi if test "x$succeeded" != "xyes" ; then if test "x$_version" = "x0" ; then AC_MSG_NOTICE([[We could not detect the boost libraries (version $1 or higher). If you have a staged boost library (still not installed) please specify \$BOOST_ROOT in your environment and do not give a PATH to --with-boost option. If you are sure you have boost installed, then check your version number looking in . See http://randspringer.de/boost for more documentation.]]) else AC_MSG_NOTICE([Your boost libraries seems to old (version $_version).]) fi BOOST_LDFLAGS="" BOOST_CPPFLAGS="" # execute ACTION-IF-NOT-FOUND (if present): ifelse([$3], , :, [$3]) else AC_DEFINE(HAVE_BOOST,,[define if the Boost library is available]) # execute ACTION-IF-FOUND (if present): ifelse([$2], , :, [$2]) fi CPPFLAGS="$CPPFLAGS_SAVED" LDFLAGS="$LDFLAGS_SAVED" ]) ================================================ FILE: m4/ax_boost_filesystem.m4 ================================================ # =========================================================================== # https://www.gnu.org/software/autoconf-archive/ax_boost_filesystem.html # =========================================================================== # # SYNOPSIS # # AX_BOOST_FILESYSTEM # # DESCRIPTION # # Test for Filesystem library from the Boost C++ libraries. The macro # requires a preceding call to AX_BOOST_BASE. Further documentation is # available at . # # This macro calls: # # AC_SUBST(BOOST_FILESYSTEM_LIB) # # And sets: # # HAVE_BOOST_FILESYSTEM # # LICENSE # # Copyright (c) 2009 Thomas Porschberg # Copyright (c) 2009 Michael Tindal # Copyright (c) 2009 Roman Rybalko # # Copying and distribution of this file, with or without modification, are # permitted in any medium without royalty provided the copyright notice # and this notice are preserved. This file is offered as-is, without any # warranty. #serial 28 AC_DEFUN([AX_BOOST_FILESYSTEM], [ AC_ARG_WITH([boost-filesystem], AS_HELP_STRING([--with-boost-filesystem@<:@=special-lib@:>@], [use the Filesystem library from boost - it is possible to specify a certain library for the linker e.g. --with-boost-filesystem=boost_filesystem-gcc-mt ]), [ if test "$withval" = "no"; then want_boost="no" elif test "$withval" = "yes"; then want_boost="yes" ax_boost_user_filesystem_lib="" else want_boost="yes" ax_boost_user_filesystem_lib="$withval" fi ], [want_boost="yes"] ) if test "x$want_boost" = "xyes"; then AC_REQUIRE([AC_PROG_CC]) CPPFLAGS_SAVED="$CPPFLAGS" CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" export CPPFLAGS LDFLAGS_SAVED="$LDFLAGS" LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" export LDFLAGS LIBS_SAVED=$LIBS LIBS="$LIBS $BOOST_SYSTEM_LIB" export LIBS AC_CACHE_CHECK(whether the Boost::Filesystem library is available, ax_cv_boost_filesystem, [AC_LANG_PUSH([C++]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include ]], [[using namespace boost::filesystem; path my_path( "foo/bar/data.txt" ); return 0;]])], ax_cv_boost_filesystem=yes, ax_cv_boost_filesystem=no) AC_LANG_POP([C++]) ]) if test "x$ax_cv_boost_filesystem" = "xyes"; then AC_DEFINE(HAVE_BOOST_FILESYSTEM,,[define if the Boost::Filesystem library is available]) BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'` if test "x$ax_boost_user_filesystem_lib" = "x"; then for libextension in `ls -r $BOOSTLIBDIR/libboost_filesystem* 2>/dev/null | sed 's,.*/lib,,' | sed 's,\..*,,'` ; do ax_lib=${libextension} AC_CHECK_LIB($ax_lib, exit, [BOOST_FILESYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_FILESYSTEM_LIB) link_filesystem="yes"; break], [link_filesystem="no"]) done if test "x$link_filesystem" != "xyes"; then for libextension in `ls -r $BOOSTLIBDIR/boost_filesystem* 2>/dev/null | sed 's,.*/,,' | sed -e 's,\..*,,'` ; do ax_lib=${libextension} AC_CHECK_LIB($ax_lib, exit, [BOOST_FILESYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_FILESYSTEM_LIB) link_filesystem="yes"; break], [link_filesystem="no"]) done fi else for ax_lib in $ax_boost_user_filesystem_lib boost_filesystem-$ax_boost_user_filesystem_lib; do AC_CHECK_LIB($ax_lib, exit, [BOOST_FILESYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_FILESYSTEM_LIB) link_filesystem="yes"; break], [link_filesystem="no"]) done fi if test "x$ax_lib" = "x"; then AC_MSG_ERROR(Could not find a version of the Boost::Filesystem library!) fi if test "x$link_filesystem" != "xyes"; then AC_MSG_ERROR(Could not link against $ax_lib !) fi fi CPPFLAGS="$CPPFLAGS_SAVED" LDFLAGS="$LDFLAGS_SAVED" LIBS="$LIBS_SAVED" fi ]) ================================================ FILE: m4/ax_check_gl.m4 ================================================ # =========================================================================== # https://www.gnu.org/software/autoconf-archive/ax_check_gl.html # =========================================================================== # # SYNOPSIS # # AX_CHECK_GL([ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND]) # # DESCRIPTION # # Checks for an OpenGL implementation. If a valid OpenGL implementation is # found, this macro would set C preprocessor symbol HAVE_GL to 1. # # If either a valid OpenGL header or library was not found, by default the # configuration would exits on error. This behavior can be overwritten by # providing a custom "ACTION-IF-NOT-FOUND" hook. # # If the header, library was found, and been tested for compiling and # linking the configuration would export the required compiler flags to # "GL_CFLAGS" and "GL_LIBS". These two variables can also be overwritten # by user from the command line if they want to link against the library # they specified instead of having the configuration script to detect the # flags automatically. Note that having "GL_CFLAGS" or "GL_LIBS" set # doesn't mean it can compile or link with the flags, since it could be # overwritten by user. However the "HAVE_GL" symbol and "ACTION-IF-FOUND" # hook is always guaranteed to reflect a valid OpenGL implementation. # # If user didn't specify the "ACTION-IF-FOUND" hook, the configuration # would prepend "GL_CFLAGS" and "GL_LIBS" to "CFLAGS" and "LIBS", like # many other autoconf macros do. # # OpenGL is one of the libraries that has different header names on # different platforms. This macro does the header detection, and will # export the following symbol: "HAVE_GL_GL_H" for having "GL/gl.h" or # "HAVE_OPENGL_GL_H" for having "OpenGL/gl.h". To write a portable OpenGL # code, you should include OpenGL header like so: # # #if defined(HAVE_WINDOWS_H) && defined(_WIN32) # # include # #endif # #ifdef HAVE_GL_GL_H # # include # #elif defined(HAVE_OPENGL_GL_H) # # include # #else # # error no gl.h # #endif # # On the OSX platform, there's two possible OpenGL implementation. One is # the OpenGL that ships with OSX, the other comes with X11/XQuartz # (http://www.xquartz.org). To use the xquartz variant, user can use the # option --with-xquartz-gl[=path to xquartz root]. By default the # configuration will check "/opt/X11", which is the default X11 install # location on OSX. # # LICENSE # # Copyright (c) 2009 Braden McDaniel # Copyright (c) 2012 Bastien Roucaries # Copyright (c) 2016 Felix Chern # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; either version 2 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 General # Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program. If not, see . # # As a special exception, the respective Autoconf Macro's copyright owner # gives unlimited permission to copy, distribute and modify the configure # scripts that are the output of Autoconf when processing the Macro. You # need not follow the terms of the GNU General Public License when using # or distributing such scripts, even though portions of the text of the # Macro appear in them. The GNU General Public License (GPL) does govern # all other use of the material that constitutes the Autoconf Macro. # # This special exception to the GPL applies to versions of the Autoconf # Macro released by the Autoconf Archive. When you make and distribute a # modified version of the Autoconf Macro, you may extend this special # exception to the GPL to apply to your modified version as well. #serial 22 # example gl program m4_define([_AX_CHECK_GL_PROGRAM], [AC_LANG_PROGRAM([[ # if defined(HAVE_WINDOWS_H) && defined(_WIN32) # include # endif # ifdef HAVE_GL_GL_H # include # elif defined(HAVE_OPENGL_GL_H) # include # else # error no gl.h # endif ]],[[glBegin(0)]])]) dnl Default include : add windows.h dnl see http://www.opengl.org/wiki/Platform_specifics:_Windows dnl (acceded 20120801) AC_DEFUN([_AX_CHECK_GL_INCLUDES_DEFAULT],dnl [ AC_INCLUDES_DEFAULT [ # if defined(HAVE_WINDOWS_H) && defined(_WIN32) # include # endif ] ]) # _AX_CHECK_GL_SAVE_FLAGS(LIST-OF-FLAGS) # Use this macro before you modify the flags. # Restore the flags by _AX_CHECK_GL_RESTORE_FLAGS # # Example: _AX_CHECK_GL_SAVE_FLAGS([[CFLAGS],[LIBS]]) expands to # gl_saved_flag_cflags=$CFLAGS # gl_saved_flag_libs=$LIBS # CFLAGS="$GL_CFLAGS $CFLAGS" # LIBS="$GL_LIBS $LIBS" AC_DEFUN([_AX_CHECK_GL_SAVE_FLAGS], [ AX_SAVE_FLAGS_WITH_PREFIX([GL],[$1]) AC_LANG_PUSH([C]) ]) # _AX_CHECK_GL_RESTORE_FLAGS(LIST-OF-FLAGS) # Use this marcro to restore the flags you saved using # _AX_CHECK_GL_SAVE_FLAGS # # Example: _AX_CHECK_GL_RESTORE_FLAGS([[CFLAGS],[LIBS]]) expands to # CFLAGS="$gl_saved_flag_cflags" # LIBS="$gl_saved_flag_libs" AC_DEFUN([_AX_CHECK_GL_RESTORE_FLAGS], [ AX_RESTORE_FLAGS_WITH_PREFIX([GL],[$1]) AC_LANG_POP([C]) ]) # Check if the program compiles AC_DEFUN([_AX_CHECK_GL_COMPILE], [dnl _AX_CHECK_GL_SAVE_FLAGS([CFLAGS]) AC_COMPILE_IFELSE([_AX_CHECK_GL_PROGRAM], [ax_check_gl_compile_opengl="yes"], [ax_check_gl_compile_opengl="no"]) _AX_CHECK_GL_RESTORE_FLAGS([CFLAGS]) ]) # Compile the example program (cache) AC_DEFUN([_AX_CHECK_GL_COMPILE_CV], [dnl AC_CACHE_CHECK([for compiling a minimal OpenGL program],[ax_cv_check_gl_compile_opengl], [_AX_CHECK_GL_COMPILE() ax_cv_check_gl_compile_opengl="${ax_check_gl_compile_opengl}"]) ax_check_gl_compile_opengl="${ax_cv_check_gl_compile_opengl}" ]) # Link the example program AC_DEFUN([_AX_CHECK_GL_LINK], [dnl _AX_CHECK_GL_SAVE_FLAGS([[CFLAGS],[LIBS],[LDFLAGS]]) AC_LINK_IFELSE([_AX_CHECK_GL_PROGRAM], [ax_check_gl_link_opengl="yes"], [ax_check_gl_link_opengl="no"]) _AX_CHECK_GL_RESTORE_FLAGS([[CFLAGS],[LIBS],[LDFLAGS]]) ]) # Link the example program (cache) AC_DEFUN([_AX_CHECK_GL_LINK_CV], [dnl AC_CACHE_CHECK([for linking a minimal OpenGL program],[ax_cv_check_gl_link_opengl], [_AX_CHECK_GL_LINK() ax_cv_check_gl_link_opengl="${ax_check_gl_link_opengl}"]) ax_check_gl_link_opengl="${ax_cv_check_gl_link_opengl}" ]) # _AX_CHECK_GL_MANUAL_LIBS_GENERIC(LIBRARIES-TO-SEARCH) # Searches library provided in $1, and output the flag # $ax_check_gl_lib_opengl AC_DEFUN([_AX_CHECK_GL_MANUAL_LIBS_GENERIC], [ AS_IF([test -n "$GL_LIBS"],[], [ ax_check_gl_manual_libs_generic_extra_libs="$1" AS_IF([test "X$ax_check_gl_manual_libs_generic_extra_libs" = "X"], [AC_MSG_ERROR([AX_CHECK_GL_MANUAL_LIBS_GENERIC argument must no be empty])]) _AX_CHECK_GL_SAVE_FLAGS([CFLAGS]) AC_SEARCH_LIBS([glBegin],[$ax_check_gl_manual_libs_generic_extra_libs], [ ax_check_gl_lib_opengl="yes" break ]) AS_IF([test "X$ax_check_gl_lib_opengl"="Xyes"], [GL_LIBS="${ac_cv_search_glBegin}"]) _AX_CHECK_GL_RESTORE_FLAGS([CFLAGS]) ]) ]) # _WITH_XQUARTZ_GL # ---------------- # Provides an option in command line to specify the XQuartz installation # path on OSX, so that user can link to it instead of using the default # OSX OpenGL framework. (Mac OSX only) AC_DEFUN_ONCE([_WITH_XQUARTZ_GL],[ AC_ARG_WITH([xquartz-gl], [AS_HELP_STRING([--with-xquartz-gl@<:@=DIR@:>@], [On Mac OSX, use opengl provided by X11/XQuartz instead of the built-in framework. If enabled, the default location is @<:@DIR=/opt/X11@:>@. This option is default to false.])], [AS_IF([test "X$with_xquartz_gl"="Xyes"], [with_xquartz_gl="/opt/X11"])], [with_xquartz_gl=no]) AS_IF([test "X$with_xquartz_gl" != "Xno"], [AC_MSG_CHECKING([OSX X11 path]) AS_IF([test -e "$with_xquartz_gl"], [AC_MSG_RESULT(["$with_xquartz_gl"]) CFLAGS="-I$with_xquartz_gl/include $CFLAGS" LIBS="-L$with_xquartz_gl/lib $LIBS" ], [with_xquartz_gl=no AC_MSG_RESULT([no]) AC_MSG_WARN([--with-xquartz-gl was given, but test for X11 failed. Fallback to system framework]) ]) ]) ]) # OSX specific setup for OpenGL check AC_DEFUN([_AX_CHECK_DARWIN_GL], [ AC_REQUIRE([_WITH_XQUARTZ_GL]) AS_IF([test "x$with_xquartz_gl" != "xno"], [GL_LIBS="${GL_LIBS:--lGL}"], [GL_LIBS="${GL_LIBS:--framework OpenGL}"]) ]) # AX_CHECK_GL_LIB([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) # --------------------------------------------------------- # Checks OpenGL headers and library and provides hooks for success and failures. # When $1 is not set, this macro would modify CFLAGS and LIBS environment variables. # However, user can override this behavior by providing their own hooks. # The CFLAGS and LIBS flags required by OpenGL is always exported in # GL_CFLAGS and GL_LIBS environment variable. # # In other words, the default behavior of AX_CHECK_GL_LIB() is equivalent to # AX_CHECK_GL_LIB( # [CFLAGS="$GL_CFLAGS $CFLAGS" # LIBS="$GL_LIBS $LIBS"] # ) AC_DEFUN([AX_CHECK_GL], [AC_REQUIRE([AC_CANONICAL_HOST]) AC_REQUIRE([PKG_PROG_PKG_CONFIG]) AC_ARG_VAR([GL_CFLAGS],[C compiler flags for GL, overriding configure script defaults]) AC_ARG_VAR([GL_LIBS],[Linker flags for GL, overriding configure script defaults]) dnl --with-gl or not can be implemented outside of check-gl AS_CASE([${host}], [*-darwin*],[_AX_CHECK_DARWIN_GL], dnl some windows may support X11 opengl, and should be able to linked dnl by -lGL. However I have no machine to test it. [*-cygwin*|*-mingw*],[ _AX_CHECK_GL_MANUAL_LIBS_GENERIC([opengl32 GL gl]) AC_CHECK_HEADERS([windows.h]) ], [PKG_PROG_PKG_CONFIG PKG_CHECK_MODULES([GL],[gl], [], [_AX_CHECK_GL_MANUAL_LIBS_GENERIC([GL gl])]) ]) dnl host specific checks dnl this was cache _AX_CHECK_GL_SAVE_FLAGS([CFLAGS]) AC_CHECK_HEADERS([GL/gl.h OpenGL/gl.h], [ax_check_gl_have_headers="yes";break]) _AX_CHECK_GL_RESTORE_FLAGS([CFLAGS]) AS_IF([test "X$ax_check_gl_have_headers" = "Xyes"], [_AX_CHECK_GL_COMPILE_CV()], [no_gl=yes]) AS_IF([test "X$ax_check_gl_compile_opengl" = "Xyes"], [_AX_CHECK_GL_LINK_CV()], [no_gl=yes]) AS_IF([test "X$no_gl" = "X"], [AC_DEFINE([HAVE_GL], [1], [Defined if a valid OpenGL implementation is found.]) m4_ifval([$1], [$1], [CFLAGS="$GL_CFLAGS $CFLAGS" LIBS="$GL_LIBS $LIBS"]) ], [m4_ifval([$2], [$2], [AC_MSG_ERROR([Could not find a valid OpenGL implementation])]) ]) ]) ================================================ FILE: m4/ax_check_glu.m4 ================================================ # =========================================================================== # https://www.gnu.org/software/autoconf-archive/ax_check_glu.html # =========================================================================== # # SYNOPSIS # # AX_CHECK_GLU([ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND]) # # DESCRIPTION # # Checks for GLUT. If a valid GLU implementation is found, the configure # script would export the C preprocessor symbol "HAVE_GLU=1". # # If either a valid GLU header or library was not found, by default the # configure script would exit on error. This behavior can be overwritten # by providing a custom "ACTION-IF-NOT-FOUND" hook. # # If the header, library was found, and been tested for compiling and # linking the configuration would export the required compiler flags to # "GLU_CFLAGS" and "GLU_LIBS" environment variables. These two variables # can also be overwritten by defining the environment variables before # executing the configure program. If it was predefined, configure would # not try to overwrite it, but it would still perform the compile and link # test. Only when the tests succeeded does the configure script to export # "HAVE_GLU=1" and to run "ACTION-IF-FOUND" hook. # # If user didn't specify the "ACTION-IF-FOUND" hook, the configuration # would prepend "GLU_CFLAGS" and "GLU_LIBS" to "CFLAGS" and "LIBS", like # many other autoconf macros do. # # If the header "GL/glu.h" is found, "HAVE_GL_GLU_H" is defined. If the # header "OpenGL/glu.h" is found, HAVE_OPENGL_GLU_H is defined. # # You should use something like this in your headers: # # # if defined(HAVE_WINDOWS_H) && defined(_WIN32) # # include # # endif # # if defined(HAVE_GL_GLU_H) # # include # # elif defined(HAVE_OPENGL_GLU_H) # # include # # else # # error no glu.h # # endif # # On the OSX platform, you can use the option --with-xquartz-gl to use # X11/Xquartz GLU implementation instead of the system built in GLU # framework. # # Some implementations (in particular, some versions of Mac OS X) are # known to treat the GLU tesselator callback function type as "GLvoid # (*)(...)" rather than the standard "GLvoid (*)()". If the former # condition is detected, this macro defines "HAVE_VARARGS_GLU_TESSCB". # # LICENSE # # Copyright (c) 2009 Braden McDaniel # Copyright (c) 2013 Bastien Roucaries # Copyright (c) 2016 Felix Chern # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; either version 2 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 General # Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program. If not, see . # # As a special exception, the respective Autoconf Macro's copyright owner # gives unlimited permission to copy, distribute and modify the configure # scripts that are the output of Autoconf when processing the Macro. You # need not follow the terms of the GNU General Public License when using # or distributing such scripts, even though portions of the text of the # Macro appear in them. The GNU General Public License (GPL) does govern # all other use of the material that constitutes the Autoconf Macro. # # This special exception to the GPL applies to versions of the Autoconf # Macro released by the Autoconf Archive. When you make and distribute a # modified version of the Autoconf Macro, you may extend this special # exception to the GPL to apply to your modified version as well. #serial 23 # example program m4_define([_AX_CHECK_GLU_PROGRAM], [AC_LANG_PROGRAM([[ # if defined(HAVE_WINDOWS_H) && defined(_WIN32) # include # endif # ifdef HAVE_GL_GLU_H # include # elif defined(HAVE_OPENGL_GLU_H) # include # else # error no glu.h # endif ]],[[gluBeginCurve(0)]])]) dnl Default include : add windows.h dnl see http://www.opengl.org/wiki/Platform_specifics:_Windows dnl (acceded 20120801) AC_DEFUN([_AX_CHECK_GLU_INCLUDES_DEFAULT],dnl [ AC_INCLUDES_DEFAULT [ # if defined(HAVE_WINDOWS_H) && defined(_WIN32) # include # endif ] ]) # check tesselation callback function signature. m4_define([_AX_CHECK_GLU_VARARGS_TESSVB_PROGRAM], [AC_LANG_PROGRAM([[ # if defined(HAVE_WINDOWS_H) && defined(_WIN32) # include # endif # ifdef HAVE_GL_GLU_H # include # elif defined(HAVE_OPENGL_GLU_H) # include # else # error no glu.h # endif ]], [[GLvoid (*func)(...); gluTessCallback(0, 0, func)]]) ]) # _AX_CHECK_GLU_SAVE_FLAGS(LIST-OF-FLAGS,[LANG]) # ---------------------------------------------- # Save the flags to shell variables. # Example: _AX_CHECK_GLU_SAVE_FLAGS([[CFLAGS],[LIBS]]) expands to # AC_LANG_PUSH([C]) # glu_saved_flag_cflags=$CFLAGS # glu_saved_flag_libs=$LIBS # CFLAGS="$GLU_CFLAGS $CFLAGS" # LIBS="$GLU_LIBS $LIBS" # # Can optionally support other LANG by specifying $2 AC_DEFUN([_AX_CHECK_GLU_SAVE_FLAGS], [ m4_ifval([$2], [AC_LANG_PUSH([$2])], [AC_LANG_PUSH([C])]) AX_SAVE_FLAGS_WITH_PREFIX([GLU],[$1]) dnl defined in ax_check_gl ]) # _AX_CHECK_GLU_RESTORE_FLAGS(LIST-OF-FLAGS) # Use this marcro to restore the flags you saved using # _AX_CHECK_GLU_SAVE_FLAGS # # Example: _AX_CHECK_GLU_RESTORE_FLAGS([[CFLAGS],[LIBS]]) expands to # CFLAGS="$glu_saved_flag_cflags" # LIBS="$glu_saved_flag_libs" # AC_LANG_POP([C]) AC_DEFUN([_AX_CHECK_GLU_RESTORE_FLAGS], [ AX_RESTORE_FLAGS_WITH_PREFIX([GLU],[$1]) dnl defined in ax_check_gl m4_ifval([$2], [AC_LANG_POP([$2])], [AC_LANG_POP([C])]) ]) # Search headers and export $ax_check_glu_have_headers AC_DEFUN([_AX_CHECK_GLU_HEADERS], [ _AX_CHECK_GLU_SAVE_FLAGS([CFLAGS]) AC_CHECK_HEADERS([$1], [ax_check_glu_have_headers="yes";], [], [_AX_CHECK_GLU_INCLUDES_DEFAULT()]) _AX_CHECK_GLU_RESTORE_FLAGS([CFLAGS]) ]) # _AX_CHECK_GLU_SEARCH_LIBS(LIBS) # ------------------------------- # Search for a valid GLU lib from $1 and set # GLU_LIBS respectively AC_DEFUN([_AX_CHECK_GLU_SEARCH_LIBS], [ _AX_CHECK_GLU_SAVE_FLAGS([[CFLAGS],[LIBS]]) AC_SEARCH_LIBS([gluBeginCurve],[$1], [GLU_LIBS="${GLU_LIBS:-$ac_cv_search_gluBeginCurve}"]) _AX_CHECK_GLU_RESTORE_FLAGS([[CFLAGS],[LIBS]]) ]) # OSX specific GLU checks AC_DEFUN([_AX_CHECK_DARWIN_GLU], [ AC_REQUIRE([_WITH_XQUARTZ_GL]) AS_IF([test "x$with_xquartz_gl" != "xno"], [GLU_LIBS="${GLU_LIBS:--lGLU}"], [GLU_LIBS="${GLU_LIBS:--framework OpenGL}"]) ]) # AX_CHECK_GLU([ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND]) # ----------------------------------------------------- # Checks GLU and provides hooks for success and failures AC_DEFUN([AX_CHECK_GLU],[ AC_REQUIRE([AC_CANONICAL_HOST]) AC_REQUIRE([_WITH_XQUARTZ_GL]) AC_REQUIRE([PKG_PROG_PKG_CONFIG]) AC_ARG_VAR([GLU_CFLAGS],[C compiler flags for GLU, overriding system check]) AC_ARG_VAR([GLU_LIBS],[Linker flags for GLU, overriding system check]) dnl Setup GLU_CFLAGS and GLU_LIBS AS_CASE([${host}], [*-darwin*],[_AX_CHECK_DARWIN_GLU], [*-cygwin*],[_AX_CHECK_GLU_SEARCH_LIBS([GLU glu MesaGLU glu32]) AC_CHECK_HEADERS([windows.h])], # try first native [*-mingw*],[_AX_CHECK_GLU_SEARCH_LIBS([glu32 GLU glu MesaGLU]) AC_CHECK_HEADERS([windows.h])], [PKG_PROG_PKG_CONFIG PKG_CHECK_MODULES([GLU],[glu], [], [_AX_CHECK_GLU_SEARCH_LIBS([GLU glu MesaGLU])]) ]) AS_CASE([$host], [*-darwin*], [AS_IF([test "X$with_xquartz_gl" = "Xno"], [_AX_CHECK_GLU_HEADERS([OpenGL/glu.h])], [_AX_CHECK_GLU_HEADERS([GL/glu.h])] )], [_AX_CHECK_GLU_HEADERS([GL/glu.h])]) dnl compile test AS_IF([test "X$ax_check_glu_have_headers" = "Xyes"], [AC_CACHE_CHECK([for compiling a minimal OpenGL Utility (GLU) program], [ax_cv_check_glu_compile], [_AX_CHECK_GLU_SAVE_FLAGS([CFLAGS]) AC_COMPILE_IFELSE([_AX_CHECK_GLU_PROGRAM], [ax_cv_check_glu_compile="yes"], [ax_cv_check_glu_compile="no"]) _AX_CHECK_GLU_RESTORE_FLAGS([CFLAGS])]) ]) dnl link test AS_IF([test "X$ax_cv_check_glu_compile" = "Xyes"], [AC_CACHE_CHECK([for linking a minimal GLU program], [ax_cv_check_glu_link], [_AX_CHECK_GLU_SAVE_FLAGS([[CFLAGS],[LIBS]]) AC_LINK_IFELSE([_AX_CHECK_GLU_PROGRAM], [ax_cv_check_glu_link="yes"], [ax_cv_check_glu_link="no"]) _AX_CHECK_GLU_RESTORE_FLAGS([[CFLAGS],[LIBS]])]) ]) # # Some versions of Mac OS X include a broken interpretation of the GLU # tesselation callback function signature. AS_IF([test "X$ax_cv_check_glu_link" = "Xyes"], [AC_CACHE_CHECK([if GLU varargs tesselator is using non-standard form], [ax_cv_varargs_glu_tesscb], [_AX_CHECK_GLU_SAVE_FLAGS([CFLAGS],[C++]) AC_COMPILE_IFELSE([_AX_CHECK_GLU_VARARGS_TESSVB_PROGRAM], [ax_cv_varargs_glu_tesscb="yes"], [ax_cv_varargs_glu_tesscb="no"]) _AX_CHECK_GLU_RESTORE_FLAGS([CFLAGS],[C++])]) AS_IF([test "X$ax_cv_varargs_glu_tesscb" = "yes"], [AC_DEFINE([HAVE_VARARGS_GLU_TESSCB], [1], [Use nonstandard varargs form for the GLU tesselator callback])]) ]) dnl hook AS_IF([test "X$ax_cv_check_glu_link" = "Xyes"], [AC_DEFINE([HAVE_GLU],[1],[Defined if a valid GLU implementation is found.]) m4_ifval([$1], [$1], [CFLAGS="$GLU_CFLAGS $CFLAGS" LIBS="$GLU_LIBS $LIBS"])], [m4_ifval([$2], [$2], [AC_MSG_ERROR([Could not find a valid GLU implementation])]) ]) ]) ================================================ FILE: m4/ax_check_glut.m4 ================================================ # =========================================================================== # https://www.gnu.org/software/autoconf-archive/ax_check_glut.html # =========================================================================== # # SYNOPSIS # # AX_CHECK_GLUT([ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND]) # # DESCRIPTION # # Checks for GLUT. If a valid GLUT implementation is found, the configure # script would export the C preprocessor symbol "HAVE_GLUT=1". # # If either a valid GLUT header or library was not found, by default the # configure script would exit on error. This behavior can be overwritten # by providing a custom "ACTION-IF-NOT-FOUND" hook. # # If the header, library was found, and been tested for compiling and # linking the configuration would export the required compiler flags to # "GLUT_CFLAGS" and "GLUT_LIBS" environment variables. These two variables # can also be overwritten by defining the environment variables before # executing the configure program. If it was predefined, configure would # not try to overwrite it, but it would still perform the compile and link # test. Only when the tests succeeded does the configure script to export # "HAVE_GLUT=1" and to run "ACTION-IF-FOUND" hook. # # If user didn't specify the "ACTION-IF-FOUND" hook, the configuration # would prepend "GLUT_CFLAGS" and "GLUT_LIBS" to "CFLAGS" and "LIBS", like # many other autoconf macros do. # # If the header "GL/glut.h" is found, "HAVE_GL_GLUT_H" is defined. If the # header "GLUT/glut.h" is found, HAVE_GLUT_GLUT_H is defined. # # You should use something like this in your headers: # # # if HAVE_WINDOWS_H && defined(_WIN32) # # include # # endif # # if defined(HAVE_GL_GLUT_H) # # include # # elif defined(HAVE_GLUT_GLUT_H) # # include # # else # # error no glut.h # # endif # # On the OSX platform, you can use the option --with-xquartz-gl to use # X11/Xquartz GLUT implementation instead of the system built in GLUT # framework. # # LICENSE # # Copyright (c) 2009 Braden McDaniel # Copyright (c) 2013 Bastien Roucaries # Copyright (c) 2016 Felix Chern # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; either version 2 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 General # Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program. If not, see . # # As a special exception, the respective Autoconf Macro's copyright owner # gives unlimited permission to copy, distribute and modify the configure # scripts that are the output of Autoconf when processing the Macro. You # need not follow the terms of the GNU General Public License when using # or distributing such scripts, even though portions of the text of the # Macro appear in them. The GNU General Public License (GPL) does govern # all other use of the material that constitutes the Autoconf Macro. # # This special exception to the GPL applies to versions of the Autoconf # Macro released by the Autoconf Archive. When you make and distribute a # modified version of the Autoconf Macro, you may extend this special # exception to the GPL to apply to your modified version as well. #serial 17 AC_DEFUN([_AX_CHECK_GLUT_SAVE_FLAGS], [ AX_SAVE_FLAGS_WITH_PREFIX([GLUT],[$1]) dnl defined in ax_check_gl AC_LANG_PUSH([C]) ]) AC_DEFUN([_AX_CHECK_GLUT_RESTORE_FLAGS], [ AX_RESTORE_FLAGS_WITH_PREFIX([GLUT],[$1]) dnl defined in ax_check_gl AC_LANG_POP([C]) ]) dnl Default include : add windows.h dnl see http://www.opengl.org/wiki/Platform_specifics:_Windows dnl (acceded 20120801) AC_DEFUN([_AX_CHECK_GLUT_INCLUDES_DEFAULT],dnl [ AC_INCLUDES_DEFAULT [ # if defined(HAVE_WINDOWS_H) && defined(_WIN32) # include # endif ] ]) m4_define([_AX_CHECK_GLUT_PROGRAM], [AC_LANG_PROGRAM([[ # if HAVE_WINDOWS_H && defined(_WIN32) # include # endif # ifdef HAVE_GL_GLUT_H # include # elif defined(HAVE_GLUT_GLUT_H) # include # else # error no glut.h # endif]], [[glutMainLoop()]])]) # _AX_CHECK_GLUT_MANUAL_LIBS_GENERIC(LIST-OF-LIBS) # ------------------------------------------------ # Searches libraries provided in $1, and export variable # $ax_check_glut_lib_glut AC_DEFUN([_AX_CHECK_GLUT_MANUAL_LIBS_GENERIC], [ _AX_CHECK_GLUT_SAVE_FLAGS([[CFLAGS],[LIBS]]) AC_SEARCH_LIBS([glutMainLoop],[$1], [GLUT_LIBS="${GLUT_LIBS:-$ac_cv_search_glutMainLoop}"]) _AX_CHECK_GLUT_RESTORE_FLAGS([[CFLAGS],[LIBS]]) ]) # Wrapper macro to check GLUT header AC_DEFUN([_AX_CHECK_GLUT_HEADER],[ _AX_CHECK_GLUT_SAVE_FLAGS([CFLAGS]) AC_CHECK_HEADERS([$1], [ax_check_glut_have_headers=yes]) _AX_CHECK_GLUT_RESTORE_FLAGS([CFLAGS]) ]) # AX_CHECK_GLUT_LIB([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) # --------------------------------------------------------- # Checks GLUT headers and library and provides hooks for success and failures. AC_DEFUN([AX_CHECK_GLUT], [AC_REQUIRE([AC_CANONICAL_HOST]) AC_REQUIRE([_WITH_XQUARTZ_GL]) AC_ARG_VAR([GLUT_CFLAGS],[C compiler flags for GLUT, overriding configure script defaults]) AC_ARG_VAR([GLUT_LIBS],[Linker flags for GLUT, overriding configure script defaults]) AS_CASE([${host}], [*-darwin*],[AS_IF([test "x$with_xquartz_gl" != "xno"], [GLUT_LIBS="${GLUT_LIBS:--lGLUT}"], [GLUT_LIBS="${GLUT_LIBS:--framework GLUT}"])], [*-cygwin*|*-mingw*],[ _AX_CHECK_GLUT_MANUAL_LIBS_GENERIC([glut32 glut]) AC_CHECK_HEADERS([windows.h]) ], [_AX_CHECK_GLUT_MANUAL_LIBS_GENERIC([glut]) ]) dnl host specific checks dnl checks header AS_CASE([${host}], [*-darwin*],[AS_IF([test "x$with_xquartz_gl" = "xno"], [_AX_CHECK_GLUT_HEADER([GLUT/glut.h])], [_AX_CHECK_GLUT_HEADER([GL/glut.h])] )], [_AX_CHECK_GLUT_HEADER([GL/glut.h])]) dnl compile AS_IF([test "X$ax_check_glut_have_headers" = "Xyes"], [AC_CACHE_CHECK([for compiling a minimal GLUT program], [ax_cv_check_glut_compile], [_AX_CHECK_GLUT_SAVE_FLAGS([CFLAGS]) AC_COMPILE_IFELSE([_AX_CHECK_GLUT_PROGRAM], [ax_cv_check_glut_compile="yes"], [ax_cv_check_glut_compile="no"]) _AX_CHECK_GLUT_RESTORE_FLAGS([CFLAGS]) ]) ]) dnl link AS_IF([test "X$ax_cv_check_glut_compile" = "Xyes"], [AC_CACHE_CHECK([for linking a minimal GLUT program], [ax_cv_check_glut_link], [_AX_CHECK_GLUT_SAVE_FLAGS([[CFLAGS],[LIBS]]) AC_LINK_IFELSE([_AX_CHECK_GLUT_PROGRAM], [ax_cv_check_glut_link="yes"], [ax_cv_check_glut_link="no"]) _AX_CHECK_GLUT_RESTORE_FLAGS([[CFLAGS],[LIBS]]) ]) ]) dnl hook AS_IF([test "X$ax_cv_check_glut_link" = "Xyes"], [AC_DEFINE([HAVE_GLUT], [1], [Defined if a valid GLUT implementation is found]) m4_ifval([$1], [$1], [CFLAGS="$GLUT_CFLAGS $CFLAGS" LIBS="$GLUT_LIBS $LIBS"]) ], [m4_ifval([$2], [$2], [AC_MSG_ERROR([Could not find a valid GLUT implementation])] ) ]) ]) ================================================ FILE: m4/ax_pthread.m4 ================================================ # =========================================================================== # http://www.nongnu.org/autoconf-archive/ax_pthread.html # =========================================================================== # # SYNOPSIS # # AX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) # # DESCRIPTION # # This macro figures out how to build C programs using POSIX threads. It # sets the PTHREAD_LIBS output variable to the threads library and linker # flags, and the PTHREAD_CFLAGS output variable to any special C compiler # flags that are needed. (The user can also force certain compiler # flags/libs to be tested by setting these environment variables.) # # Also sets PTHREAD_CC to any special C compiler that is needed for # multi-threaded programs (defaults to the value of CC otherwise). (This # is necessary on AIX to use the special cc_r compiler alias.) # # NOTE: You are assumed to not only compile your program with these flags, # but also link it with them as well. e.g. you should link with # $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS # # If you are only building threads programs, you may wish to use these # variables in your default LIBS, CFLAGS, and CC: # # LIBS="$PTHREAD_LIBS $LIBS" # CFLAGS="$CFLAGS $PTHREAD_CFLAGS" # CC="$PTHREAD_CC" # # In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant # has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to that name # (e.g. PTHREAD_CREATE_UNDETACHED on AIX). # # ACTION-IF-FOUND is a list of shell commands to run if a threads library # is found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it # is not found. If ACTION-IF-FOUND is not specified, the default action # will define HAVE_PTHREAD. # # Please let the authors know if this macro fails on any platform, or if # you have any other suggestions or comments. This macro was based on work # by SGJ on autoconf scripts for FFTW (http://www.fftw.org/) (with help # from M. Frigo), as well as ac_pthread and hb_pthread macros posted by # Alejandro Forero Cuervo to the autoconf macro repository. We are also # grateful for the helpful feedback of numerous users. # # LICENSE # # Copyright (c) 2008 Steven G. Johnson # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU 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 General # Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program. If not, see . # # As a special exception, the respective Autoconf Macro's copyright owner # gives unlimited permission to copy, distribute and modify the configure # scripts that are the output of Autoconf when processing the Macro. You # need not follow the terms of the GNU General Public License when using # or distributing such scripts, even though portions of the text of the # Macro appear in them. The GNU General Public License (GPL) does govern # all other use of the material that constitutes the Autoconf Macro. # # This special exception to the GPL applies to versions of the Autoconf # Macro released by the Autoconf Archive. When you make and distribute a # modified version of the Autoconf Macro, you may extend this special # exception to the GPL to apply to your modified version as well. AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD]) AC_DEFUN([AX_PTHREAD], [ AC_REQUIRE([AC_CANONICAL_HOST]) AC_LANG_SAVE AC_LANG_C ax_pthread_ok=no # We used to check for pthread.h first, but this fails if pthread.h # requires special compiler flags (e.g. on True64 or Sequent). # It gets checked for in the link test anyway. # First of all, check if the user has set any of the PTHREAD_LIBS, # etcetera environment variables, and if threads linking works using # them: if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then save_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS $PTHREAD_CFLAGS" save_LIBS="$LIBS" LIBS="$PTHREAD_LIBS $LIBS" AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS]) AC_TRY_LINK_FUNC(pthread_join, ax_pthread_ok=yes) AC_MSG_RESULT($ax_pthread_ok) if test x"$ax_pthread_ok" = xno; then PTHREAD_LIBS="" PTHREAD_CFLAGS="" fi LIBS="$save_LIBS" CFLAGS="$save_CFLAGS" fi # We must check for the threads library under a number of different # names; the ordering is very important because some systems # (e.g. DEC) have both -lpthread and -lpthreads, where one of the # libraries is broken (non-POSIX). # Create a list of thread flags to try. Items starting with a "-" are # C compiler flags, and other items are library names, except for "none" # which indicates that we try without any flags at all, and "pthread-config" # which is a program returning the flags for the Pth emulation library. ax_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config" # The ordering *is* (sometimes) important. Some notes on the # individual items follow: # pthreads: AIX (must check this before -lpthread) # none: in case threads are in libc; should be tried before -Kthread and # other compiler flags to prevent continual compiler warnings # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h) # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread) # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads) # -pthreads: Solaris/gcc # -mthreads: Mingw32/gcc, Lynx/gcc # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it # doesn't hurt to check since this sometimes defines pthreads too; # also defines -D_REENTRANT) # ... -mt is also the pthreads flag for HP/aCC # pthread: Linux, etcetera # --thread-safe: KAI C++ # pthread-config: use pthread-config program (for GNU Pth library) case "${host_cpu}-${host_os}" in *solaris*) # On Solaris (at least, for some versions), libc contains stubbed # (non-functional) versions of the pthreads routines, so link-based # tests will erroneously succeed. (We need to link with -pthreads/-mt/ # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather # a function called by this macro, so we could check for that, but # who knows whether they'll stub that too in a future libc.) So, # we'll just look for -pthreads and -lpthread first: ax_pthread_flags="-pthreads pthread -mt -pthread $ax_pthread_flags" ;; esac if test x"$ax_pthread_ok" = xno; then for flag in $ax_pthread_flags; do case $flag in none) AC_MSG_CHECKING([whether pthreads work without any flags]) ;; -*) AC_MSG_CHECKING([whether pthreads work with $flag]) PTHREAD_CFLAGS="$flag" ;; pthread-config) AC_CHECK_PROG(ax_pthread_config, pthread-config, yes, no) if test x"$ax_pthread_config" = xno; then continue; fi PTHREAD_CFLAGS="`pthread-config --cflags`" PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`" ;; *) AC_MSG_CHECKING([for the pthreads library -l$flag]) PTHREAD_LIBS="-l$flag" ;; esac save_LIBS="$LIBS" save_CFLAGS="$CFLAGS" LIBS="$PTHREAD_LIBS $LIBS" CFLAGS="$CFLAGS $PTHREAD_CFLAGS" # Check for various functions. We must include pthread.h, # since some functions may be macros. (On the Sequent, we # need a special flag -Kthread to make this header compile.) # We check for pthread_join because it is in -lpthread on IRIX # while pthread_create is in libc. We check for pthread_attr_init # due to DEC craziness with -lpthreads. We check for # pthread_cleanup_push because it is one of the few pthread # functions on Solaris that doesn't have a non-functional libc stub. # We try pthread_create on general principles. AC_TRY_LINK([#include static void routine(void* a) {a=0;} static void* start_routine(void* a) {return a;}], [pthread_t th; pthread_attr_t attr; pthread_join(th, 0); pthread_attr_init(&attr); pthread_cleanup_push(routine, 0); pthread_create(&th,0,start_routine,0); pthread_cleanup_pop(0); ], [ax_pthread_ok=yes]) LIBS="$save_LIBS" CFLAGS="$save_CFLAGS" AC_MSG_RESULT($ax_pthread_ok) if test "x$ax_pthread_ok" = xyes; then break; fi PTHREAD_LIBS="" PTHREAD_CFLAGS="" done fi # Various other checks: if test "x$ax_pthread_ok" = xyes; then save_LIBS="$LIBS" LIBS="$PTHREAD_LIBS $LIBS" save_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS $PTHREAD_CFLAGS" # Detect AIX lossage: JOINABLE attribute is called UNDETACHED. AC_MSG_CHECKING([for joinable pthread attribute]) attr_name=unknown for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do AC_TRY_LINK([#include ], [int attr=$attr; return attr;], [attr_name=$attr; break]) done AC_MSG_RESULT($attr_name) if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name, [Define to necessary symbol if this constant uses a non-standard name on your system.]) fi AC_MSG_CHECKING([if more special flags are required for pthreads]) flag=no case "${host_cpu}-${host_os}" in *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";; *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";; esac AC_MSG_RESULT(${flag}) if test "x$flag" != xno; then PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS" fi LIBS="$save_LIBS" CFLAGS="$save_CFLAGS" # More AIX lossage: must compile with xlc_r or cc_r if test x"$GCC" != xyes; then AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC}) else PTHREAD_CC=$CC fi else PTHREAD_CC="$CC" fi AC_SUBST(PTHREAD_LIBS) AC_SUBST(PTHREAD_CFLAGS) AC_SUBST(PTHREAD_CC) # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: if test x"$ax_pthread_ok" = xyes; then ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1]) : else ax_pthread_ok=no $2 fi AC_LANG_RESTORE ])dnl AX_PTHREAD ================================================ FILE: m4/ax_restore_flags_with_prefix.m4 ================================================ # ================================================================================= # https://www.gnu.org/software/autoconf-archive/ax_restore_flags_with_prefix.html # ================================================================================= # # SYNOPSIS # # AX_RESTORE_FLAGS_WITH_PREFIX(PREFIX, LIST-OF-FLAGS) # # DESCRIPTION # # Restore the flags saved by AX_SAVE_FLAGS_WITH_PREFIX. # # Expansion example: AX_RESTORE_FLAGS_WITH_PREFIX([GL], [[CFLAGS],[LIBS]]) # expands to # # CFLAGS="$gl_saved_flag_cflags" # LIBS="$gl_saved_flag_libs" # # One common use case is to define a package specific wrapper macro around # this one, and also restore other variables if needed. For example: # # AC_DEFUN([_AX_CHECK_GL_RESTORE_FLAGS], [ # AX_RESTORE_FLAGS_WITH_PREFIX([GL],[$1]) # AC_LANG_POP([C]) # ]) # # # Restores CFLAGS, LIBS and language state # _AX_CHECK_GL_RESTORE_FLAGS([[CFLAGS],[LIBS]]) # # LICENSE # # Copyright (c) 2016 Felix Chern # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; either version 2 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 General # Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program. If not, see . # # As a special exception, the respective Autoconf Macro's copyright owner # gives unlimited permission to copy, distribute and modify the configure # scripts that are the output of Autoconf when processing the Macro. You # need not follow the terms of the GNU General Public License when using # or distributing such scripts, even though portions of the text of the # Macro appear in them. The GNU General Public License (GPL) does govern # all other use of the material that constitutes the Autoconf Macro. # # This special exception to the GPL applies to versions of the Autoconf # Macro released by the Autoconf Archive. When you make and distribute a # modified version of the Autoconf Macro, you may extend this special # exception to the GPL to apply to your modified version as well. #serial 3 AC_DEFUN([AX_RESTORE_FLAGS_WITH_PREFIX],[ m4_ifval([$2], [ m4_car($2)="$_ax_[]m4_tolower($1)_saved_flag_[]m4_tolower(m4_car($2))" $0($1, m4_cdr($2))]) ]) ================================================ FILE: m4/ax_save_flags_with_prefix.m4 ================================================ # ============================================================================== # https://www.gnu.org/software/autoconf-archive/ax_save_flags_with_prefix.html # ============================================================================== # # SYNOPSIS # # AX_SAVE_FLAGS_WITH_PREFIX(PREFIX, LIST-OF-FLAGS) # # DESCRIPTION # # For each flag in LIST-OF-FLAGS, it expands to lower-cased shell variable # with the prefix holding the flag original value. The saved variables # can be restored by AX_RESTORE_FLAGS_WITH_PREFIX # # As an example: AX_SAVE_FLAGS_WITH_PREFIX([GL], [[CFLAGS],[LIBS]]) # expands to # # gl_saved_flag_cflags="$CFLAGS" # gl_saved_flag_libs="$LIBS" # CFLAGS="$GL_CFLAGS $CFLAGS" # LIBS="$GL_LIBS $LIBS" # # One common use case is to define a package specific wrapper macro around # this one, and also setup other variables if needed. For example: # # AC_DEFUN([_AX_CHECK_GL_SAVE_FLAGS], [ # AX_SAVE_FLAGS_WITH_PREFIX([GL],[$1]) # AC_LANG_PUSH([C]) # ]) # # # pushes GL_CFLAGS and GL_LIBS to CFLAGS and LIBS # # also set the current language to test to C # _AX_CHECK_GL_SAVE_FLAGS([[CFLAGS],[LIBS]]) # # LICENSE # # Copyright (c) 2016 Felix Chern # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; either version 2 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 General # Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program. If not, see . # # As a special exception, the respective Autoconf Macro's copyright owner # gives unlimited permission to copy, distribute and modify the configure # scripts that are the output of Autoconf when processing the Macro. You # need not follow the terms of the GNU General Public License when using # or distributing such scripts, even though portions of the text of the # Macro appear in them. The GNU General Public License (GPL) does govern # all other use of the material that constitutes the Autoconf Macro. # # This special exception to the GPL applies to versions of the Autoconf # Macro released by the Autoconf Archive. When you make and distribute a # modified version of the Autoconf Macro, you may extend this special # exception to the GPL to apply to your modified version as well. #serial 3 AC_DEFUN([AX_SAVE_FLAGS_WITH_PREFIX],[ m4_ifval([$2], [ _ax_[]m4_tolower($1)_saved_flag_[]m4_tolower(m4_car($2))="$m4_car($2)" m4_car($2)="$$1_[]m4_car($2) $m4_car($2)" $0($1, m4_cdr($2)) ])]) ================================================ FILE: m4/pkg.m4 ================================================ # pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*- # # Copyright © 2004 Scott James Remnant . # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 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 # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. # PKG_PROG_PKG_CONFIG([MIN-VERSION]) # ---------------------------------- AC_DEFUN([PKG_PROG_PKG_CONFIG], [m4_pattern_forbid([^_?PKG_[A-Z_]+$]) m4_pattern_allow([^PKG_CONFIG(_PATH)?$]) AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])dnl if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then AC_PATH_TOOL([PKG_CONFIG], [pkg-config]) fi if test -n "$PKG_CONFIG"; then _pkg_min_version=m4_default([$1], [0.9.0]) AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version]) if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then AC_MSG_RESULT([yes]) else AC_MSG_RESULT([no]) PKG_CONFIG="" fi fi[]dnl ])# PKG_PROG_PKG_CONFIG # PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) # # Check to see whether a particular set of modules exists. Similar # to PKG_CHECK_MODULES(), but does not set variables or print errors. # # # Similar to PKG_CHECK_MODULES, make sure that the first instance of # this or PKG_CHECK_MODULES is called, or make sure to call # PKG_CHECK_EXISTS manually # -------------------------------------------------------------- AC_DEFUN([PKG_CHECK_EXISTS], [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl if test -n "$PKG_CONFIG" && \ AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then m4_ifval([$2], [$2], [:]) m4_ifvaln([$3], [else $3])dnl fi]) # _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES]) # --------------------------------------------- m4_define([_PKG_CONFIG], [if test -n "$PKG_CONFIG"; then if test -n "$$1"; then pkg_cv_[]$1="$$1" else PKG_CHECK_EXISTS([$3], [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`], [pkg_failed=yes]) fi else pkg_failed=untried fi[]dnl ])# _PKG_CONFIG # _PKG_SHORT_ERRORS_SUPPORTED # ----------------------------- AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED], [AC_REQUIRE([PKG_PROG_PKG_CONFIG]) if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then _pkg_short_errors_supported=yes else _pkg_short_errors_supported=no fi[]dnl ])# _PKG_SHORT_ERRORS_SUPPORTED # PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND], # [ACTION-IF-NOT-FOUND]) # # # Note that if there is a possibility the first call to # PKG_CHECK_MODULES might not happen, you should be sure to include an # explicit call to PKG_PROG_PKG_CONFIG in your configure.ac # # # -------------------------------------------------------------- AC_DEFUN([PKG_CHECK_MODULES], [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl pkg_failed=no AC_MSG_CHECKING([for $1]) _PKG_CONFIG([$1][_CFLAGS], [cflags], [$2]) _PKG_CONFIG([$1][_LIBS], [libs], [$2]) m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS and $1[]_LIBS to avoid the need to call pkg-config. See the pkg-config man page for more details.]) if test $pkg_failed = yes; then _PKG_SHORT_ERRORS_SUPPORTED if test $_pkg_short_errors_supported = yes; then $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --errors-to-stdout --print-errors "$2"` else $1[]_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "$2"` fi # Put the nasty error message in config.log where it belongs echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD ifelse([$4], , [AC_MSG_ERROR(dnl [Package requirements ($2) were not met: $$1_PKG_ERRORS Consider adjusting the PKG_CONFIG_PATH environment variable if you installed software in a non-standard prefix. _PKG_TEXT ])], [AC_MSG_RESULT([no]) $4]) elif test $pkg_failed = untried; then ifelse([$4], , [AC_MSG_FAILURE(dnl [The pkg-config script could not be found or is too old. Make sure it is in your PATH or set the PKG_CONFIG environment variable to the full path to pkg-config. _PKG_TEXT To get pkg-config, see .])], [$4]) else $1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS $1[]_LIBS=$pkg_cv_[]$1[]_LIBS AC_MSG_RESULT([yes]) ifelse([$3], , :, [$3]) fi[]dnl ])# PKG_CHECK_MODULES ================================================ FILE: scripts/gource-ps.pl ================================================ #!/usr/bin/perl #poll ps and convert changes into Gource format. #usage: # gource-ps.pl [[USER@]SERVER] | gource --log-format custom - # # (requires Gource 0.27 or later as needs working STDIN support) use strict; use warnings; use Getopt::Long qw(GetOptions); #use Data::Dumper; my %opt = (); if(!GetOptions(\%opt, 'debug|d')) { die("usage: gource-ps.pl [[USER\@]SERVER] | gource --log-format custom - ...\n"); } my $windows = $^O =~ /win32|msys/i; if($windows) { require Win32::Process::Info; Win32::Process::Info->import(); } my($server) = @ARGV; my $user = $ENV{USER}; if($server && $server =~ /(.+)\@(.+)/) { $user = $1; $server = $2; } die('remote ps via ssh unimplemented on Win32') if $windows && $server; $|=1; my %process; sub _proc_list { my $ps_command = 'ps axo pid,ppid,user,time,comm'; my @pslist = $server ? `ssh $user\@$server "$ps_command"` : `$ps_command`; if($?) { die("ps command failed: $!\n"); } shift @pslist; chomp(@pslist); my @stack; #build process tree foreach my $line (@pslist) { $line =~ s/^\s+//; my ($pid, $ppid, $username, $time, @command) = split(/\s+/, $line); my $command = join(' ', @command) || ''; $command =~ s{^.+/}{}g; my $proc; if($proc = $process{$pid}) { $proc->{status} = ($proc->{'time'} ne $time) ? 'M' : ''; } else { $proc = { pid => $pid, ppid => $ppid, username => $username, command => $command, 'time' => $time, status => 'A', }; $process{$pid} = $proc; } #warn Dumper($process{$pid}); } } sub _win32_proc_list { my $pi = Win32::Process::Info->new (); foreach my $winproc ($pi->GetProcInfo) { # use Data::Dumper; # print Dumper($proc); my $pid = $winproc->{ProcessId}; my $ppid = $winproc->{ParentProcessId}; my $command = $winproc->{Description}; my $username = $winproc->{Owner} || 'System'; my $time = $winproc->{UserModeTime}; $username =~ s/^.+\\//; $command =~ s/\.exe$//i; next unless $command && $pid && $username; my $proc; if($proc = $process{$pid}) { $proc->{status} = ($proc->{'time'} ne $time) ? 'M' : ''; } else { $proc = { pid => $pid, ppid => $ppid, username => $username, command => $command, 'time' => $time, status => 'A', }; $process{$pid} = $proc; } } } sub _make_command_path { my $proc = shift; my @path; my $node = $proc; while($node) { push @path, $node->{pid} . '.' . $node->{command}; $node = $node->{ppid} ? $process{$node->{ppid}} : 0; } return join('/', reverse @path); } while(1) { my @proclist = $windows ? _win32_proc_list : _proc_list; my @filter_pids; #filter ps / gource processes and parent processes owned by this user foreach my $pid (sort {$a <=> $b} keys %process) { my $proc = $process{$pid}; next unless $proc; # delete ps process and parents of if($proc->{command} eq 'ps' && $proc->{username} eq $user || $proc->{command} eq 'gource') { while($proc) { push @filter_pids, $proc->{pid}; $proc = $proc->{ppid} ? $process{$proc->{ppid}} : undef; } } } delete $process{$_} for @filter_pids; my @expired_pids; my $current_time = time; foreach my $pid (sort {$a <=> $b} keys %process) { my $proc = $process{$pid}; if($proc->{status}) { my $output_line = join('|', $current_time, $proc->{username}, $proc->{status}, _make_command_path($proc)). "\n"; print $output_line; print STDERR $output_line if $opt{debug}; } #delete if not seen next time if($proc->{status} eq 'D') { push @expired_pids, $pid; } else { $proc->{status} = 'D'; } } #remove expired pids delete $process{$_} for @expired_pids; sleep(1); } ================================================ FILE: src/.gitignore ================================================ *.o ================================================ FILE: src/action.cpp ================================================ /* Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "action.h" RAction::RAction(RUser* source, RFile* target, time_t timestamp, float t, const vec3& colour) : colour(colour), source(source), target(target), timestamp(timestamp), t(t), progress(0.0f), rate(0.5f) { } void RAction::apply() { target->touch(timestamp, colour); } void RAction::logic(float dt) { if(progress >= 1.0) return; if(progress == 0.0) { apply(); } float action_rate = std::min(10.0f, rate * std::max(1.0f, ((float)source->getPendingActionCount()))); progress = std::min(progress + action_rate * dt, 1.0f); } void RAction::drawToVBO(quadbuf& buffer) const { if(isFinished()) return; vec2 src = source->getPos(); vec2 dest = target->getAbsolutePos(); //TODO: could use glm::perp vec2 n = normalise(dest - src); vec2 perp = vec2(-n.y, n.x); vec2 offset = perp * target->getSize() * 0.5f; vec2 offset_src = offset * 0.3f; float alpha = 1.0 - progress; float alpha2 = alpha * 0.1; vec4 col1 = vec4(colour, alpha); vec4 col2 = vec4(colour, alpha2); quadbuf_vertex v1(src - offset_src, col2, vec2(0.0f, 0.0f)); quadbuf_vertex v2(src + offset_src, col2, vec2(0.0f, 1.0f)); quadbuf_vertex v3(dest + offset, col1, vec2(1.0f, 1.0f)); quadbuf_vertex v4(dest - offset, col1, vec2(1.0f, 0.0f)); buffer.add(0, v1, v2, v3, v4); } void RAction::draw(float dt) { if(isFinished()) return; vec2 src = source->getPos(); vec2 dest = target->getAbsolutePos(); vec2 n = normalise(dest - src); vec2 perp = vec2(-n.y, n.x); vec2 offset = perp * target->getSize() * 0.5f; vec2 offset_src = offset * 0.3f; float alpha = 1.0 - progress; float alpha2 = alpha * 0.1; vec4 col1 = vec4(colour, alpha); vec4 col2 = vec4(colour, alpha2); glBegin(GL_QUADS); glColor4fv(glm::value_ptr(col2)); glTexCoord2f(0.0,0.0); glVertex2f(src.x - offset_src.x, src.y - offset_src.y); glTexCoord2f(0.0,1.0); glVertex2f(src.x + offset_src.x, src.y + offset_src.y); glColor4fv(glm::value_ptr(col1)); glTexCoord2f(1.0,1.0); glVertex2f(dest.x + offset.x, dest.y + offset.y); glTexCoord2f(1.0,0.0); glVertex2f(dest.x - offset.x, dest.y - offset.y); glEnd(); } CreateAction::CreateAction(RUser* source, RFile* target, time_t timestamp, float t) : RAction(source, target, timestamp, t, vec3(0.0f, 1.0f, 0.0f)) { } RemoveAction::RemoveAction(RUser* source, RFile* target, time_t timestamp, float t) : RAction(source, target, timestamp, t, vec3(1.0f, 0.0f, 0.0f)) { } void RemoveAction::logic(float dt) { float old_progress = progress; RAction::logic(dt); if(old_progress < 1.0 && progress >= 1.0) { target->remove(timestamp); } } ModifyAction::ModifyAction(RUser* source, RFile* target, time_t timestamp, float t, const vec3& modify_colour) : RAction(source, target, timestamp, t, vec3(1.0f, 0.7f, 0.3f)), modify_colour(modify_colour) { } void ModifyAction::apply() { RAction::apply(); target->setFileColour(modify_colour); } ================================================ FILE: src/action.h ================================================ /* Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef RACTION_H #define RACTION_H #include "user.h" #include "file.h" class RUser; class RFile; class RAction { protected: vec3 colour; virtual void apply(); public: RUser* source; RFile* target; time_t timestamp; float t; float progress; float rate; RAction(RUser* source, RFile* target, time_t timestamp, float t, const vec3& colour); virtual ~RAction() {}; inline bool isFinished() const { return (progress >= 1.0); }; virtual void logic(float dt); void drawToVBO(quadbuf& buffer) const ; void draw(float dt); }; class CreateAction : public RAction { public: CreateAction(RUser* source, RFile* target, time_t timestamp, float t); }; class RemoveAction : public RAction { public: RemoveAction(RUser* source, RFile* target, time_t timestamp, float t); void logic(float dt); }; class ModifyAction : public RAction { protected: vec3 modify_colour; public: ModifyAction(RUser* source, RFile* target, time_t timestamp, float t, const vec3& modify_colour); void apply(); }; #endif ================================================ FILE: src/bloom.cpp ================================================ /* Copyright (C) 2011 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "bloom.h" //bloombuf bloombuf::bloombuf(int data_size) : data_size(data_size) { bufferid = 0; buffer_size = 0; vertex_count = 0; data = data_size > 0 ? new bloom_vertex[data_size] : 0; //fprintf(stderr, "size of bloom_vertex = %d\n", sizeof(bloom_vertex)); } bloombuf::~bloombuf() { if(bufferid !=0) glDeleteBuffers(1, &bufferid); if(data != 0) delete[] data; } void bloombuf::resize(int new_size) { bloom_vertex* _data = data; data = new bloom_vertex[new_size]; for(int i=0;i data_size) { resize(vertex_count*2); } data[i] = v1; data[i+1] = v2; data[i+2] = v3; data[i+3] = v4; } void bloombuf::update() { if(vertex_count==0) return; //note possibly better to have a queue and cycle them here if(bufferid==0) { glGenBuffers(1, &bufferid); } glBindBuffer(GL_ARRAY_BUFFER, bufferid); //recreate buffer if less than the vertex_count if(buffer_size < vertex_count) { buffer_size = data_size; glBufferData(GL_ARRAY_BUFFER, buffer_size*sizeof(bloom_vertex), &(data[0].pos.x), GL_DYNAMIC_DRAW); } else { glBufferSubData(GL_ARRAY_BUFFER, 0, vertex_count*sizeof(bloom_vertex), &(data[0].pos.x)); } glBindBuffer(GL_ARRAY_BUFFER, 0); } void bloombuf::draw() { if(vertex_count==0 || bufferid==0) return; glBindBuffer(GL_ARRAY_BUFFER, bufferid); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glVertexPointer(2, GL_FLOAT, sizeof(bloom_vertex), 0); glColorPointer(4, GL_FLOAT, sizeof(bloom_vertex), (GLvoid*)8); // offset pos (2x4 bytes) glTexCoordPointer(4, GL_FLOAT, sizeof(bloom_vertex), (GLvoid*)24); // offset pos + colour (2x4 + 4x4 bytes) glDrawArrays(GL_QUADS, 0, vertex_count); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, 0); } ================================================ FILE: src/bloom.h ================================================ /* Copyright (C) 2011 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef GOURCE_BLOOM_VBO_H #define GOURCE_BLOOM_VBO_H #include #include "core/display.h" #include "core/vectors.h" #include "core/logger.h" //note this should be 64 bytes class bloom_vertex { public: bloom_vertex() {}; bloom_vertex(const vec2& pos, const vec4& colour, const vec4& texcoord) : pos(pos), colour(colour), texcoord(texcoord) {}; vec2 pos; vec4 colour; vec4 texcoord; char padding[24]; }; class bloombuf { bloom_vertex* data; int data_size; GLuint bufferid; int buffer_size; int vertex_count; void resize(int new_size); public: bloombuf(int data_size = 0); ~bloombuf(); void unload(); void reset(); size_t vertices(); size_t capacity(); void add(GLuint textureid, const vec2& pos, const vec2& dims, const vec4& colour, const vec4& texcoord); void update(); void draw(); }; #endif ================================================ FILE: src/caption.cpp ================================================ /* Copyright (C) 2010 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "caption.h" RCaption::RCaption(const std::string& caption, time_t timestamp, const FXFont& font) { this->caption = caption; this->timestamp = timestamp; this->font = font; alpha = 0.0; elapsed = 0.0; colour = gGourceSettings.caption_colour; } void RCaption::setPos(const vec2& pos) { this->pos = pos; } const vec2& RCaption::getPos() const { return pos; } const std::string& RCaption::getCaption() const { return caption; } bool RCaption::isFinished() const { return elapsed >= gGourceSettings.caption_duration; } void RCaption::logic(float dt) { float fade_in = glm::min(2.0f, gGourceSettings.caption_duration / 3.0f); elapsed += dt; alpha = glm::min(1.0f, glm::min(elapsed,glm::max(0.0f,gGourceSettings.caption_duration-elapsed)) / fade_in); } void RCaption::draw() { font.setColour(vec4(colour.x, colour.y, colour.z, alpha)); font.draw(pos.x, pos.y, caption); } ================================================ FILE: src/caption.h ================================================ /* Copyright (C) 2010 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef RCAPTION_H #define RCAPTION_H #include "core/display.h" #include "core/fxfont.h" #include "gource_settings.h" class RCaption { float alpha; float elapsed; vec2 pos; vec3 colour; FXFont font; std::string caption; public: time_t timestamp; RCaption(const std::string& caption, time_t timestamp, const FXFont& font); void setPos(const vec2& pos); const vec2& getPos() const; const std::string& getCaption() const; bool isFinished() const; void logic(float dt); void draw(); }; #endif ================================================ FILE: src/dirnode.cpp ================================================ /* Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "dirnode.h" float gGourceMinDirSize = 15.0; float gGourceForceGravity = 10.0; float gGourceDirPadding = 1.5; bool gGourceNodeDebug = false; bool gGourceGravity = true; //debugging int gGourceDirNodeInnerLoops = 0; int gGourceFileInnerLoops = 0; std::map gGourceDirMap; RDirNode::RDirNode(RDirNode* parent, const std::string & abspath) { changePath(abspath); parent = 0; setParent(parent); accel = spos = prev_accel = vel = vec2(0.0f); //NOTE: parent is always being set to 0 so this never gets called ... //figure out starting position if(parent !=0) { vec2 parentPos = parent->getPos(); vec2 offset; pos = parentPos; } else { pos = vec2(0.0f, 0.0f); } float padded_file_radius = gGourceFileDiameter * 0.5; file_area = padded_file_radius * padded_file_radius * PI; visible_count = 0; visible = false; position_initialized = false; since_node_visible = 0.0; since_last_file_change = 0.0; since_last_node_change = 0.0; calcRadius(); calcColour(); } void RDirNode::changePath(const std::string & abspath) { //fix up path gGourceDirMap.erase(this->abspath); this->abspath = abspath; if(abspath.empty() || abspath[abspath.size()-1] != '/') { this->abspath += std::string("/"); } //debugLog("new dirnode %s\n", abspath.c_str()); gGourceDirMap[this->abspath] = this; } RDirNode::~RDirNode() { for(std::list::iterator it = children.begin(); it != children.end(); it++) { delete (*it); } gGourceDirMap.erase(abspath); } int RDirNode::getTokenOffset() const{ return path_token_offset; } void RDirNode::fileUpdated(bool userInitiated) { calcRadius(); since_last_file_change = 0.0; nodeUpdated(userInitiated); } void RDirNode::nodeUpdated(bool userInitiated) { if(userInitiated) since_last_node_change = 0.0; calcRadius(); updateFilePositions(); if(visible && noDirs() && noFiles()) visible = false; if(parent !=0) parent->nodeUpdated(true); } void RDirNode::rotate(float s, float c) { pos = rotate_vec2(pos, s, c); spos = rotate_vec2(spos, s, c); for(std::list::iterator it = children.begin(); it != children.end(); it++) { RDirNode* child = (*it); child->rotate(s, c); } } void RDirNode::rotate(float s, float c, const vec2& centre) { pos = rotate_vec2(pos - centre, s, c) + centre; spos = rotate_vec2(spos - centre, s, c) + centre; for(std::list::iterator it = children.begin(); it != children.end(); it++) { RDirNode* child = (*it); child->rotate(s, c, centre); } } void RDirNode::setPos(const vec2 & pos) { this->pos = pos; } //returns true if supplied path prefixes the nodes path bool RDirNode::prefixedBy(const std::string & path) const { if(path.empty()) return false; if(path[path.size()-1] != '/') return abspath.find(path + std::string("/")) == 0; else return abspath.find(path) == 0; } const std::string & RDirNode::getPath() const{ return abspath; } RDirNode* RDirNode::getParent() const{ return parent; } bool RDirNode::isDir(const std::string& path) const { if(prefixedBy(path)) return true; if(path.find(abspath) != 0) return false; for(std::list::const_iterator it = children.begin(); it != children.end(); it++) { if((*it)->isDir(path)) return true; } return false; } //finds directories closest to the root directory prefixed by path (eg foo/ may match just foo/ or could also match foo/bar1, foo/bar2, ... if foo/ doesn't exist). void RDirNode::findDirs(const std::string& path, std::list& dirs) { if(prefixedBy(path)) { dirs.push_back(this); return; } for(std::list::const_iterator it = children.begin(); it != children.end(); it++) { (*it)->findDirs(path, dirs); } } void RDirNode::getFilesRecursive(std::list& files) const { //add this dirs files files.insert(files.begin(), this->files.begin(), this->files.end()); for(std::list::const_iterator it = children.begin(); it != children.end(); it++) { (*it)->getFilesRecursive(files); } } int RDirNode::getDepth() const{ return depth; } void RDirNode::adjustPath() { //update display path int parent_token_offset = 0; path_token_offset = abspath.size(); if(parent != 0) { parent_token_offset = parent->getTokenOffset(); //debugLog("abspath.substr arguments: %d %d %s size = %d\n", parent_token_offset, abspath.size()-parent_token_offset-1, abspath.c_str(), abspath.size()); path_token = abspath.substr(parent_token_offset, abspath.size()-parent_token_offset-1); path_token_offset = abspath.size(); //debugLog("new token %s\n", path_token.c_str()); } } void RDirNode::setParent(RDirNode* parent) { if(parent != 0 && this->parent == parent) return; this->parent = parent; adjustPath(); adjustDepth(); } void RDirNode::adjustDepth() { if(parent == 0) { depth = 1; } else { depth = parent->getDepth() + 1; } for(RDirNode* child : children) { child->adjustDepth(); } } void RDirNode::addNode(RDirNode* node) { // does this node prefix any other nodes, if so, add them to it std::vector matches; std::string path = node->getPath(); //debugLog("adding node %s to %s\n", path.c_str(), abspath.c_str()); for(std::list::iterator it = children.begin(); it != children.end(); ) { RDirNode* child = (*it); if(child->prefixedBy(path)) { it = children.erase(it); node->addNode(child); } else { it++; } } // add to this node children.push_back(node); node->setParent(this); //debugLog("added node %s to %s\n", node->getPath().c_str(), getPath().c_str()); nodeUpdated(false); } RDirNode* RDirNode::getRoot() { if(parent==0) return this; return parent->getRoot(); } // note - you still need to delete the file yourself bool RDirNode::removeFile(RFile* f) { //doesnt match this path at all if(f->path.find(abspath) != 0) { return false; } //is this dir - add to this node if(f->path.compare(abspath) == 0) { for(std::list::iterator it = files.begin(); it != files.end(); it++) { if((*it)==f) { files.erase(it); if(!f->isHidden()) visible_count--; fileUpdated(false); return true; } } return false; } //does this belong to one of the children ? for(std::list::iterator it = children.begin(); it != children.end(); it++) { RDirNode* node = (*it); bool removed = node->removeFile(f); if(removed) { //fprintf(stderr, "%s file removed from a child. child file count=%d, dir count =%d\n", getPath().c_str(), node->fileCount(), node->dirCount()); //node->printFiles(); //node is now empty, reap! if(node->noFiles() && node->noDirs()) { children.erase(it); //fprintf(stderr, "deleting node %s from %s\n", node->getPath().c_str(), getPath().c_str()); delete node; nodeUpdated(false); } return true; } } return false; } void RDirNode::printFiles() { for(std::list::iterator it = files.begin(); it != files.end(); it++) { RFile* file = (*it); fprintf(stderr, "%s: %s %s\n", getPath().c_str(), file->fullpath.c_str() , file->isHidden() ? "hidden " : ""); } } void RDirNode::addVisible() { visible_count++; visible = true; } bool RDirNode::isVisible() { if(visible) return true; for(std::list::const_iterator it = children.begin(); it != children.end(); it++) { if((*it)->isVisible()) { visible = true; return true; } } return false; } int RDirNode::visibleFileCount() const{ return visible_count; } int RDirNode::fileCount() const{ return files.size(); } bool RDirNode::noFiles() const{ return files.empty(); } std::string RDirNode::commonPathPrefix(const std::string & str) const{ size_t c = 0; int slash = -1; while(cpath.find(abspath) != 0) { if(parent != 0) return false; //if this is the root node (ie no parent), we fork it //if we encounter a file with a non matching path to the //current root path. the calling process then checks if //the root now has a parent node, and changes the pointer. RDirNode* newparent; std::string common = commonPathPrefix(f->path); if(common.size()==0) common = "/"; newparent = new RDirNode(0, common); newparent->addNode(this); return newparent->addFile(f); } //simply change path of node and add this to it if( parent==0 && abspath == "/" && f->path.compare(abspath) != 0 && noFiles() && noDirs()) { debugLog("modifying root path to %s", f->path.c_str()); changePath(f->path); } //is this dir - add to this node if(f->path.compare(abspath) == 0) { //debugLog("addFile %s to %s\n", f->fullpath.c_str(), abspath.c_str()); files.push_back(f); if(!f->isHidden()) visible_count++; f->setDir(this); fileUpdated(false); return true; } bool added = false; //does this belong to one of the children ? for(std::list::iterator it = children.begin(); it != children.end(); it++) { RDirNode* child = (*it); added = child->addFile(f); if(added) break; } if(added && parent != 0) return true; //do we have a file in this directory thats fullpath is a prefix of this file, if so //that file is actually a directory - the file should be removed, and a directory with that path added //if this is the root node we do this regardless of if the file was added to a child node for(std::list::const_iterator it = files.begin(); it != files.end(); it++) { RFile* file = (*it); if(f->path.find(file->fullpath) == 0) { //fprintf(stderr, "removing %s as is actually the directory of %s\n", file->fullpath.c_str(), f->fullpath.c_str()); file->remove(); break; } } if(added) return true; //add new child, add it to that //if commonpath is longer than abspath, add intermediate node, else just add at the files path RDirNode* node = new RDirNode(this, f->path); node->addFile(f); addNode(node); // do we have dir nodes, with a common path element greater than abspath, // if so create another node, and move those nodes there std::string commonpath; vec2 commonPos; for(std::list::iterator it = children.begin(); it != children.end(); it++) { RDirNode* child = (*it); std::string common = child->commonPathPrefix(f->path); if(common.size() > abspath.size() && common != f->path) { commonpath = common; commonPos = child->getPos(); break; } } // redistribute to new common node if(commonpath.size() > abspath.size()) { //debugLog("common path %s\n", commonpath.c_str()); RDirNode* cnode = new RDirNode(this, commonpath); cnode->setPos(commonPos); for(std::list::iterator it = children.begin(); it != children.end();) { RDirNode* child = (*it); if(child->prefixedBy(commonpath)) { //debugLog("this path = %s, commonpath = %s, path = %s\n", abspath.c_str(), commonpath.c_str(), child->getPath().c_str()); it = children.erase(it); cnode->addNode(child); continue; } it++; } addNode(cnode); } return true; } float RDirNode::getParentRadius() const{ return parent_radius; } float RDirNode::getRadius() const{ return dir_radius; } float RDirNode::getRadiusSqrt() const{ return dir_radius_sqrt; } vec3 RDirNode::averageFileColour() const{ vec3 av; int count = 0; for(std::list::const_iterator it = files.begin(); it != files.end(); it++) { RFile* file = (*it); if(file->isHidden()) continue; av += file->getColour(); count++; } if(count>0) av *= (1.0f/(float)count); count = 0; for(std::list::const_iterator it = children.begin(); it != children.end();it++) { RDirNode* child = (*it); av += child->averageFileColour(); count++; } if(count>0) av *= (1.0f/(float)count); return av; } const vec4 & RDirNode::getColour() const{ return col; } void RDirNode::calcColour() { // make branch brighter if recently accessed float brightness = std::max(0.6f, 1.0f - std::min(1.0f, since_last_node_change / 3.0f)); col = vec4(brightness, brightness, brightness, 1.0); int fcount = 0; for(std::list::iterator it = files.begin(); it != files.end(); it++) { RFile* file = (*it); if(file->isHidden()) continue;; vec3 filecol = file->getColour() * brightness; float a = file->getAlpha(); col += vec4(filecol.x, filecol.y, filecol.z, a); fcount++; } this->col /= (float) fcount + 1.0; } float RDirNode::getArea() const{ return dir_area; } void RDirNode::calcRadius() { float total_file_area = file_area * visible_count; dir_area = total_file_area; //float parent_circ = 0.0; for(std::list::iterator it = children.begin(); it != children.end(); it++) { RDirNode* node = (*it); dir_area += node->getArea(); // parent_circ += node->getRadiusSqrt(); } this->dir_radius = std::max(1.0f, (float)sqrt(dir_area)) * gGourceDirPadding; //this->dir_radius_sqrt = sqrt(dir_radius); //dir_radius_sqrt is not used // this->parent_radius = std::max(1.0, parent_circ / PI); this->parent_radius = std::max(1.0f, (float) sqrt(total_file_area) * gGourceDirPadding); } float RDirNode::distanceToParent() const{ float posd = glm::length(parent->getPos() - pos); float distance = posd - (dir_radius + parent->getParentRadius()); return distance; } void RDirNode::applyForceDir(RDirNode* node) { if(node == this) return; vec2 dir = node->getPos() - pos; float posd2 = glm::length2(dir); float myradius = getRadius(); float your_radius = node->getRadius(); float sumradius = (myradius + your_radius); float distance2 = posd2 - sumradius*sumradius; if(distance2>0.0) return; float posd = sqrt(posd2); float distance = posd - myradius - your_radius; //resolve overlap if(posd < 0.00001) { accel += normalise(vec2( (rand() % 100) - 50, (rand() % 100) - 50)); return; } accel += distance * normalise(dir); } const vec2 & RDirNode::getPos() const{ return pos; } bool RDirNode::isParent(RDirNode* node) const { if(node==parent) return true; if(parent==0) return false; return parent->isParent(node); } bool RDirNode::empty() const{ return (visible_count==0 && noDirs()) ? true : false; } void RDirNode::applyForces(QuadTree & quadtree) { //child nodes for(std::list::iterator it = children.begin(); it != children.end(); it++) { RDirNode* node = (*it); node->applyForces(quadtree); } if(parent == 0) return; DirForceFunctor dff(this); quadtree.visitItemsInBounds(quadItemBounds, dff); gGourceDirNodeInnerLoops += dff.getLoopCount(); //always call on parent no matter how far away applyForceDir(parent); //pull towards parent float parent_dist = distanceToParent(); // * dirs should attract to sit on the radius of the parent dir ie: // should attract to distance_to_parent * normal_to_parent accel += gGourceForceGravity * parent_dist * normalise(parent->getPos() - pos); // * dirs should be pushed along the parent_parent to parent normal by a force smaller than the parent radius force RDirNode* pparent = parent->getParent(); if(pparent != 0) { vec2 parent_edge = (parent->getPos() - pparent->getPos()); vec2 parent_edge_normal = normalise(parent_edge); vec2 dest = (parent->getPos() + (parent->getRadius() + getRadius()) * parent_edge_normal) - pos; accel += dest; } // * dirs should repulse from other dirs of this parent const std::list & siblings = parent->getChildren(); if(!siblings.empty()) { vec2 sib_accel; int visible = 1; for(std::list::const_iterator it = siblings.begin(); it != siblings.end(); it++) { RDirNode* node = (*it); if(node == this) continue; if(!node->isVisible()) continue; visible++; sib_accel -= normalise(node->getPos() - pos); } //parent circumfrence divided by the number of visible child nodes if(visible>1) { float slice_size = (parent->getRadius() * PI) / (float) (visible+1); sib_accel *= slice_size; accel += sib_accel; } } } void RDirNode::debug(int indent) const{ std::string indentstr; while(indentstr.size() < indent) indentstr += " "; debugLog("%s%s", indentstr.c_str(), abspath.c_str()); for(std::list::const_iterator it = children.begin(); it != children.end(); it++) { RDirNode* node = (*it); node->debug(indent+1); } } int RDirNode::totalFileCount() const{ int total = visibleFileCount(); for(std::list::const_iterator it = children.begin(); it != children.end(); it++) { RDirNode* node = (*it); total += node->visibleFileCount(); } return total; } int RDirNode::totalDirCount() const{ int total = 1; for(std::list::const_iterator it = children.begin(); it != children.end(); it++) { RDirNode* node = (*it); total += node->totalDirCount(); } return total; } int RDirNode::dirCount() const{ return children.size(); } bool RDirNode::noDirs() const{ return children.empty(); } const std::list & RDirNode::getChildren() const{ return children; } void RDirNode::updateSplinePoint(float dt) { if(parent == 0) return; //update the spline point vec2 td = (parent->getPos() - pos) * 0.5f; vec2 mid = pos + td;// - td.perpendicular() * pos.normal();// * 10.0; vec2 delta = (mid - spos); //dont let spos get more than half the length of the distance behind if(glm::length2(delta) > glm::length2(td)) { spos += normalise(delta) * (glm::length(delta) - glm::length(td)); } spos += delta * std::min(1.0f, dt * 2.0f); } void RDirNode::setInitialPosition() { RDirNode* parentP = parent->getParent(); pos = parent->getPos(); //offset position by some pseudo-randomness if(parentP != 0) { //pos += ((parent->getPos() - parentP->getPos()).normal() * 2.0 + vec2Hash(abspath)).normal(); pos += normalise(normalise(parent->getPos() - parentP->getPos()) * 2.0f + vec2Hash(abspath)); } else { pos += vec2Hash(abspath); } //the spline point spos = pos - (parent->getPos() - pos) * 0.5f; position_initialized=true; } void RDirNode::move(float dt) { //the root node is the centre of the world if(parent == 0) { return; } //initial position if(!empty() && !position_initialized) { setInitialPosition(); } pos += accel * dt; if(gGourceSettings.elasticity>0.0) { vec2 diff = (accel - prev_accel); float m = dt * gGourceSettings.elasticity; vec2 accel3 = prev_accel * (1.0f-m) + diff * m; pos += accel3; prev_accel = accel3; } //accel = accel * std::max(0.0f, (1.0f - dt*10.0f)); accel = vec2(0.0, 0.0); } const vec2 & RDirNode::getNodeNormal() const{ return node_normal; } vec2 RDirNode::calcFileDest(int max_files, int file_no) { float arc = 1.0/(float)max_files; float frac = arc * 0.5 + arc * file_no; vec2 dest = vec2(sinf(frac*PI*2.0), cosf(frac*PI*2.0)); return dest; } void RDirNode::updateFilePositions() { int max_files = 1; int diameter = 1; int file_no = 0; float d = 0.0; int files_left = visible_count; for(std::list::iterator it = files.begin(); it!=files.end(); it++) { RFile* f = *it; if(f->isHidden()) { f->setDest(vec2(0.0,0.0)); f->setDistance(0.0f); continue; } vec2 dest = calcFileDest(max_files, file_no); f->setDest(dest); f->setDistance(d); files_left--; file_no++; if(file_no>=max_files) { diameter++; d += gGourceFileDiameter; max_files = (int) std::max(1.0, diameter*PI); if(files_leftgetProjectedPos(), parent->getColour(), projected_pos, col, projected_spos); } for(std::list::iterator it = children.begin(); it != children.end(); it++) { RDirNode* child = *it; child->calcEdges(); } } void RDirNode::logic(float dt) { //move move(dt); updateSplinePoint(dt); //update node normal if(parent != 0) { node_normal = normalise(pos - parent->getPos()); } //update files for(std::list::iterator it = files.begin(); it!=files.end(); it++) { RFile* f = *it; f->logic(dt); } //update child nodes for(std::list::iterator it = children.begin(); it != children.end(); it++) { RDirNode* node = (*it); node->logic(dt); } //update colour calcColour(); //update tickers if(visible) since_node_visible += dt; since_last_file_change += dt; since_last_node_change += dt; } void RDirNode::drawDirName(FXFont& dirfont) const{ if(parent==0) return; if(gGourceSettings.hide_dirnames) return; if(gGourceSettings.dir_name_depth > 0 && gGourceSettings.dir_name_depth < (depth-1)) return; if(!gGourceSettings.highlight_dirs && since_last_node_change > 5.0) return; float alpha = gGourceSettings.highlight_dirs ? 1.0 : std::max(0.0f, 5.0f - since_last_node_change) / 5.0f; vec2 label_pos = spline.getLabelPos(); dirfont.setAlpha(alpha); dirfont.draw(label_pos.x, label_pos.y, path_token); } void RDirNode::calcScreenPos(GLint* viewport, GLdouble* modelview, GLdouble* projection) { static GLdouble screen_x, screen_y, screen_z; gluProject( pos.x, pos.y, 0.0f, modelview, projection, viewport, &screen_x, &screen_y, &screen_z); screen_y = (float)viewport[3] - screen_y; projected_pos.x = screen_x; projected_pos.y = screen_y; gluProject( spos.x, spos.y, 0.0f, modelview, projection, viewport, &screen_x, &screen_y, &screen_z); screen_y = (float)viewport[3] - screen_y; projected_spos.x = screen_x; projected_spos.y = screen_y; static vec2 selected_offset(5.5f, -2.0f); static vec2 unselected_offset(5.5f, -1.0f); if(!gGourceSettings.hide_filenames) { //first pass - calculate positions of names for(std::list::const_iterator it = files.begin(); it!=files.end(); it++) { RFile* f = *it; f->calcScreenPos(viewport, modelview, projection); } } for(std::list::const_iterator it = children.begin(); it != children.end(); it++) { RDirNode* node = (*it); node->calcScreenPos(viewport, modelview, projection); } } void RDirNode::drawNames(FXFont& dirfont) { if(!gGourceSettings.hide_dirnames && isVisible()) { drawDirName(dirfont); } if(!gGourceSettings.hide_filenames) { if(!(gGourceSettings.hide_filenames || gGourceSettings.hide_files) && in_frustum) { for(std::list::const_iterator it = files.begin(); it!=files.end(); it++) { RFile* f = *it; if(!f->isSelected()) f->drawName(); } } } for(std::list::const_iterator it = children.begin(); it != children.end(); it++) { RDirNode* node = (*it); node->drawNames(dirfont); } } void RDirNode::checkFrustum(const Frustum& frustum) { in_frustum = frustum.intersects(quadItemBounds); for(std::list::const_iterator it = children.begin(); it != children.end(); it++) { RDirNode* node = (*it); node->checkFrustum(frustum); } } void RDirNode::drawShadows(float dt) const{ if(in_frustum) { glPushMatrix(); glTranslatef(pos.x, pos.y, 0.0); //draw files for(std::list::const_iterator it = files.begin(); it!=files.end(); it++) { RFile* f = *it; if(f->isHidden()) continue; f->drawShadow(dt); } glPopMatrix(); } for(std::list::const_iterator it = children.begin(); it != children.end(); it++) { RDirNode* node = (*it); node->drawShadows(dt); } } void RDirNode::updateFilesVBO(quadbuf& buffer, float dt) const{ if(in_frustum) { for(std::list::const_iterator it = files.begin(); it!=files.end(); it++) { RFile* f = *it; if(f->isHidden()) continue; vec3 col = f->getColour(); float alpha = f->getAlpha(); buffer.add(f->graphic->textureid, f->getAbsolutePos() - f->dims*0.5f, f->dims, vec4(col.x, col.y, col.z, alpha)); } } for(std::list::const_iterator it = children.begin(); it != children.end(); it++) { RDirNode* node = (*it); node->updateFilesVBO(buffer,dt); } } void RDirNode::updateBloomVBO(bloombuf& buffer, float dt) { if(in_frustum && isVisible()) { float bloom_radius = dir_radius * 2.0 * gGourceSettings.bloom_multiplier; float bloom_diameter = bloom_radius * 2.0; vec4 bloom_col = col * gGourceSettings.bloom_intensity; vec4 bloom_texcoords(bloom_radius, pos.x, pos.y, 0.0f); vec2 bloom_dims(bloom_diameter, bloom_diameter); buffer.add(0, pos - bloom_dims*0.5f,bloom_dims, vec4(bloom_col.x, bloom_col.y, bloom_col.z, 1.0f), bloom_texcoords); } for(std::list::const_iterator it = children.begin(); it != children.end(); it++) { RDirNode* node = (*it); node->updateBloomVBO(buffer,dt); } } void RDirNode::drawFiles(float dt) const{ if(in_frustum) { glPushMatrix(); glTranslatef(pos.x, pos.y, 0.0); //draw files for(std::list::const_iterator it = files.begin(); it!=files.end(); it++) { RFile* f = *it; if(f->isHidden()) continue; f->draw(dt); } glPopMatrix(); } for(std::list::const_iterator it = children.begin(); it != children.end(); it++) { RDirNode* node = (*it); node->drawFiles(dt); } } const vec2 & RDirNode::getSPos() const{ return projected_spos; } const vec2 & RDirNode::getProjectedPos() const{ return projected_pos; } void RDirNode::updateEdgeVBO(quadbuf& buffer) const { if(parent!=0 && (!gGourceSettings.hide_root || parent->parent !=0)) spline.drawToVBO(buffer); for(std::list::const_iterator it = children.begin(); it != children.end(); it++) { RDirNode* child = (*it); if(child->isVisible()) { child->updateEdgeVBO(buffer); } } } void RDirNode::drawEdgeShadows() const{ if(parent!=0 && (!gGourceSettings.hide_root || parent->parent !=0)) spline.drawShadow(); for(std::list::const_iterator it = children.begin(); it != children.end(); it++) { RDirNode* child = (*it); //draw edge - assumes calcEdges() called before hand so spline will exist if(child->isVisible()) { child->drawEdgeShadows(); } } } void RDirNode::drawEdges() const{ if(parent!=0 && (!gGourceSettings.hide_root || parent->parent !=0)) spline.draw(); for(std::list::const_iterator it = children.begin(); it != children.end(); it++) { RDirNode* child = (*it); //draw edge - assumes calcEdges() called before hand so spline will exist if(child->isVisible()) { child->drawEdges(); } } } void RDirNode::drawBloom(float dt){ if(in_frustum && isVisible()) { float bloom_radius = dir_radius * 2.0 * gGourceSettings.bloom_multiplier; vec4 bloom_col = col * gGourceSettings.bloom_intensity; glColor4f(bloom_col.x, bloom_col.y, bloom_col.z, 1.0); glPushMatrix(); glTranslatef(pos.x, pos.y, 0.0); glBegin(GL_QUADS); glTexCoord2f(1.0f, 1.0f); glVertex2f(bloom_radius,bloom_radius); glTexCoord2f(1.0f, 0.0f); glVertex2f(bloom_radius,-bloom_radius); glTexCoord2f(0.0f, 0.0f); glVertex2f(-bloom_radius,-bloom_radius); glTexCoord2f(0.0f, 1.0f); glVertex2f(-bloom_radius,bloom_radius); glEnd(); glPopMatrix(); } for(std::list::const_iterator it = children.begin(); it != children.end(); it++) { RDirNode* node = (*it); node->drawBloom(dt); } } void RDirNode::updateQuadItemBounds() { float radius = getRadius(); vec2 radoffset(radius, radius); //set bounds quadItemBounds.set(pos - radoffset, pos + radoffset); } ================================================ FILE: src/dirnode.h ================================================ /* Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef RDIRNODE_H #define RDIRNODE_H #include "core/sdlapp.h" #include "core/bounds.h" #include "core/quadtree.h" #include "core/pi.h" #include "core/vbo.h" #include "gource_settings.h" #include "spline.h" #include "file.h" #include "bloom.h" #include #include class RFile; class RDirNode : public QuadItem { std::string abspath; std::string path_token; int path_token_offset; RDirNode* parent; std::list children; std::list files; SplineEdge spline; vec4 col; vec2 spos; vec2 projected_pos; vec2 projected_spos; vec2 pos; vec2 vel; vec2 accel, prev_accel; float dir_area; bool visible; bool in_frustum; bool position_initialized; float since_node_visible; float since_last_file_change; float since_last_node_change; float file_area; float dir_radius; float dir_radius_sqrt; float parent_radius; int depth; int visible_count; vec3 screenpos; vec2 node_normal; void calcRadius(); void calcColour(); std::string commonPathPrefix(const std::string& str) const; void changePath(const std::string & abspath); void setInitialPosition(); void drawEdge(RDirNode* child) const; void updateSplinePoint(float dt); void move(float dt); vec2 calcFileDest(int layer_no, int file_no); void updateFilePositions(); void adjustDepth(); void adjustPath(); void drawDirName(FXFont& dirfont) const; public: RDirNode(RDirNode* parent, const std::string & abspath); ~RDirNode(); void printFiles(); bool empty() const; bool isAnchor(RDirNode* node) const; RDirNode* getRoot(); void fileUpdated(bool userInitiated); void nodeUpdated(bool userInitiated); void addVisible(); bool isVisible(); float getArea() const; int totalDirCount() const; int totalFileCount() const; int getTokenOffset() const; int dirCount() const; int fileCount() const; int visibleFileCount() const; bool noDirs() const; bool noFiles() const; bool prefixedBy(const std::string & path) const; const std::string & getPath() const; const vec2 & getNodeNormal() const; bool isParent(RDirNode* node) const; bool addFile(RFile* f); bool removeFile(RFile* f); int getDepth() const; const std::list & getChildren() const; void updateQuadItemBounds(); float getParentRadius() const; float getRadius() const; float getRadiusSqrt() const; const std::list* getFiles() const { return &files; }; void getFilesRecursive(std::list& files) const; vec3 averageFileColour() const; const vec4 & getColour() const; RDirNode* getParent() const; bool isDir(const std::string& path) const; void findDirs(const std::string& path, std::list& dirs); const vec2 & getPos() const; void calcEdges(); const vec2 & getProjectedPos() const; const vec2 & getSPos() const; void setPos(const vec2 & pos); void rotate(float s, float c); void rotate(float s, float c, const vec2& centre); void setParent(RDirNode* parent); float distanceToParent() const; void addNode(RDirNode* node); void debug(int indent=0) const; void applyForceDir(RDirNode* dir); void applyForces(QuadTree &quadtree); void logic(float dt); void updateEdgeVBO(quadbuf& buffer) const; void drawEdges() const; void drawEdgeShadows() const; void checkFrustum(const Frustum & frustum); void updateFilesVBO(quadbuf& buffer, float dt) const; void updateBloomVBO(bloombuf& buffer, float dt); void drawShadows(float dt) const; void drawFiles(float dt) const; void drawBloom(float dt); void drawNames(FXFont& dirfont); void calcScreenPos(GLint* viewport, GLdouble* modelview, GLdouble* projection); void nodeCount() const; }; class DirForceFunctor : public VisitFunctor{ private: RDirNode * this_dir; std::set seen; size_t loopCount; public: DirForceFunctor(RDirNode * dir) : this_dir(dir), seen(), loopCount(0){} int getLoopCount() const{ return loopCount; } void operator()(QuadItem * item){ std::set::iterator seentest; RDirNode* d = (RDirNode*) (item); if(d==this_dir) return; if(d==this_dir->getParent()) return; if(d->getParent() == this_dir) return; if(this_dir->isParent(d)) return; if(d->isParent(this_dir)) return; if(d->node_count != 1) { if((seentest = seen.find(d)) != seen.end()) return; seen.insert(d); } this_dir->applyForceDir(d); loopCount++; } }; extern int gGourceDirNodeInnerLoops; extern int gGourceFileInnerLoops; extern float gGourcePointSize; extern bool gGourceNodeDebug; extern bool gGourceGravity; extern float gGourceForceGravity; extern std::map gGourceDirMap; #endif ================================================ FILE: src/file.cpp ================================================ /* Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "file.h" float gGourceFileDiameter = 8.0; std::vector gGourceRemovedFiles; FXFont file_selected_font; FXFont file_font; RFile::RFile(const std::string & name, const vec3 & colour, const vec2 & pos, int tagid) : Pawn(name,pos,tagid) { hidden = true; size = gGourceFileDiameter * 1.05; radius = size * 0.5; setGraphic(gGourceSettings.file_graphic); speed = 5.0; nametime = gGourceSettings.filename_time; name_interval = nametime; namecol = vec3(1.0, 1.0, 1.0); file_colour = colour; last_action = 0.0f; fade_start = -1.0f; removed_timestamp = 0; expired = false; forced_removal = false; removing = false; shadow = true; distance = 0; setFilename(name); if(!file_selected_font.initialized()) { file_selected_font = fontmanager.grab(gGourceSettings.font_file, 18); file_selected_font.dropShadow(true); file_selected_font.roundCoordinates(false); file_selected_font.setColour(vec4(gGourceSettings.selection_colour, 1.0f)); } if(!file_font.initialized()) { file_font = fontmanager.grab(gGourceSettings.font_file, gGourceSettings.scaled_filename_font_size); file_font.dropShadow(true); file_font.roundCoordinates(false); file_font.setColour(vec4(gGourceSettings.filename_colour, 1.0f)); } setSelected(false); dir = 0; } RFile::~RFile() { } void RFile::remove(time_t removed_timestamp) { last_action = elapsed; fade_start = elapsed; removing = true; this->removed_timestamp = removed_timestamp; } void RFile::remove() { forced_removal = true; remove(0); } void RFile::setDir(RDirNode* dir) { this->dir = dir; } RDirNode* RFile::getDir() const{ return dir; } vec2 RFile::getAbsolutePos() const{ return pos + dir->getPos(); } bool RFile::overlaps(const vec2& pos) const { vec2 abs_pos = getAbsolutePos(); float halfsize_x = size * 0.5f; vec2 halfsize ( halfsize_x, halfsize_x * graphic_ratio ); Bounds2D file_bounds(abs_pos - halfsize, abs_pos + halfsize); return file_bounds.contains(pos); } void RFile::setFilename(const std::string& abs_file_path) { fullpath = abs_file_path; size_t pos = fullpath.rfind('/'); if(pos != std::string::npos) { path = name.substr(0,pos+1); name = name.substr(pos+1, std::string::npos); } else { path = std::string(""); name = abs_file_path; } //trim name to just extension size_t dotsep = name.rfind("."); if(dotsep != std::string::npos && dotsep != name.size()-1) { ext = name.substr(dotsep+1); } else if(gGourceSettings.file_extension_fallback) { ext = name; } } void RFile::colourize() { file_colour = ext.size() ? colourHash(ext) : vec3(1.0f, 1.0f, 1.0f); } const vec3& RFile::getNameColour() const{ return selected ? gGourceSettings.selection_colour : namecol; } void RFile::setFileColour(const vec3 & colour) { file_colour = colour; } const vec3 & RFile::getFileColour() const{ return file_colour; } vec3 RFile::getColour() const{ if(selected) return vec3(1.0f); float lc = elapsed - last_action; if(lc<1.0f) { return touch_colour * (1.0f-lc) + file_colour * lc; } return file_colour; } float RFile::getAlpha() const{ float alpha = Pawn::getAlpha(); //user fades out if not doing anything if(fade_start > 0.0f) { alpha = 1.0 - glm::clamp(elapsed - fade_start, 0.0f, 1.0f); } return alpha; } void RFile::logic(float dt) { Pawn::logic(dt); vec2 dest_pos = dest; /* if(dir->getParent() != 0 && dir->noDirs()) { vec2 dirnorm = dir->getNodeNormal(); dest_pos = dirnorm + dest; }*/ dest_pos = dest_pos * distance; accel = dest_pos - pos; // apply accel vec2 accel2 = accel * speed * dt; if(glm::length2(accel2) > glm::length2(accel)) { accel2 = accel; } pos += accel2; //files have no momentum accel = vec2(0.0f, 0.0f); if(fade_start < 0.0f && gGourceSettings.file_idle_time > 0.0f && (elapsed - last_action) > gGourceSettings.file_idle_time) { fade_start = elapsed; } // has completely faded out if(fade_start > 0.0f && !expired && (elapsed - fade_start) >= 1.0) { expired = true; bool found = false; for(std::vector::iterator it = gGourceRemovedFiles.begin(); it != gGourceRemovedFiles.end(); it++) { if((*it) == this) { found = true; break; } } if(!found) { gGourceRemovedFiles.push_back(this); //fprintf(stderr, "expiring %s\n", fullpath.c_str()); } } if(isHidden() && !forced_removal) elapsed = 0.0; } void RFile::touch(time_t touched_timestamp, const vec3 & colour) { if(forced_removal || (removing && touched_timestamp < removed_timestamp)) return; //fprintf(stderr, "touch %s\n", fullpath.c_str()); fade_start = -1.0f; removing = false; removed_timestamp = 0; last_action = elapsed; touch_colour = colour; //un expire file if touched after being removed if(expired) { for(std::vector::iterator it = gGourceRemovedFiles.begin(); it != gGourceRemovedFiles.end(); it++) { if((*it) == this) { gGourceRemovedFiles.erase(it); break; } } expired=false; } showName(); setHidden(false); dir->fileUpdated(true); } void RFile::setHidden(bool hidden) { if(this->hidden==true && hidden==false && dir !=0) { dir->addVisible(); } Pawn::setHidden(hidden); } void RFile::calcScreenPos(GLint* viewport, GLdouble* modelview, GLdouble* projection) { static GLdouble screen_x, screen_y, screen_z; vec2 text_pos = getAbsolutePos(); text_pos.x += 5.5f; if(selected) text_pos.y -= 2.0f; else text_pos.y -= 1.0f; gluProject( text_pos.x, text_pos.y, 0.0f, modelview, projection, viewport, &screen_x, &screen_y, &screen_z); screen_y = (float)viewport[3] - screen_y; screenpos.x = screen_x; screenpos.y = screen_y; } void RFile::drawNameText(float alpha) { if(!selected && alpha <= 0.01) return; float name_alpha = selected ? 1.0 : alpha; if(selected) { file_selected_font.draw(screenpos.x, screenpos.y, name); } else { file_font.setAlpha(name_alpha); file_font.draw(screenpos.x, screenpos.y, gGourceSettings.file_extensions ? ext : name); } } void RFile::draw(float dt) { Pawn::draw(dt); glLoadName(0); } ================================================ FILE: src/file.h ================================================ /* Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef RFILE_H #define RFILE_H #include "pawn.h" #include "dirnode.h" #include "core/stringhash.h" class RDirNode; class RFile : public Pawn { vec3 file_colour; vec3 touch_colour; RDirNode* dir; time_t removed_timestamp; bool forced_removal; bool expired; bool removing; float fade_start; float last_action; float radius; vec2 dest; float distance; // FXLabel* label; //GLuint namelist; void setFilename(const std::string& abs_file_path); const vec3& getNameColour() const; void drawNameText(float alpha); public: std::string path; std::string fullpath; std::string ext; RFile(const std::string & name, const vec3 & colour, const vec2 & pos, int tagid); ~RFile(); bool overlaps(const vec2& pos) const; void setFileColour(const vec3 & colour); const vec3 & getFileColour() const; vec3 getColour() const; void colourize(); float getAlpha() const; void touch(time_t touch_timestamp, const vec3& colour); void setHidden(bool hidden); void setDest(const vec2 & dest){ this->dest = dest; } void setDistance(float distance){ this->distance = distance; } void calcScreenPos(GLint* viewport, GLdouble* modelview, GLdouble* projection); void logic(float dt); void draw(float dt); void remove(time_t removed_timestamp); void remove(); vec2 getAbsolutePos() const; RDirNode* getDir() const; void setDir(RDirNode* dir); }; extern float gGourceFileDiameter; extern std::vector gGourceRemovedFiles; #endif ================================================ FILE: src/formats/apache.cpp ================================================ /* Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "apache.h" #include const char* months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug" , "Sep", "Oct", "Nov", "Dec" }; Regex apache_entry_start("^(?:[^ ]+ )?([^ ]+) +[^ ]+ +([^ ]+) +\\[(.*?)\\] +(.*)$"); Regex apache_entry_date("(\\d+)/([A-Za-z]+)/(\\d+):(\\d+):(\\d+):(\\d+) ([+-])(\\d+)"); Regex apache_entry_request("\"([^ ]+) +([^ ]+) +([^ ]+)\" +([^ ]+) +([^\\s+]+)(.*)"); Regex apache_entry_agent(" +\"([^\"]+)\" +\"([^\"]+)\" +\"([^\"]+)\""); Regex apache_hostname_parts("([^.]+)(?:\\.([^.]+))?(?:\\.([^.]+))?(?:\\.([^.]+))?(?:\\.([^.]+))?(?:\\.([^.]+))?(?:\\.([^.]+))?(?:\\.([^.]+))?$"); ApacheCombinedLog::ApacheCombinedLog(const std::string& logfile) : RCommitLog(logfile) { } //parse apache access.log entry into components bool ApacheCombinedLog::parseCommit(RCommit& commit) { std::string line; std::vector matches; if(!logf->getNextLine(line)) return false; apache_entry_start.match(line, &matches); if(matches.size()!=4) { return 0; } //get details commit.username = matches[0]; std::string request_str = matches[3]; std::string datestr = matches[2]; apache_entry_date.match(datestr, &matches); if(matches.size()!=8) { return 0; } //parse timestamp int day = atoi(matches[0].c_str()); int year = atoi(matches[2].c_str()); int hour = atoi(matches[3].c_str()); int minute = atoi(matches[4].c_str()); int second = atoi(matches[5].c_str()); int month=0; for(int i=0;i<12;i++) { if(matches[1] == months[i]) { month=i; break; } } struct tm time_str; time_str.tm_year = year - 1900; time_str.tm_mon = month; time_str.tm_mday = day; time_str.tm_hour = hour; time_str.tm_min = minute; time_str.tm_sec = second; time_str.tm_isdst = -1; commit.timestamp = mktime(&time_str); matches.clear(); apache_entry_request.match(request_str, &matches); if(matches.size() < 5) { return false; } std::string rtype = matches[0]; std::string file = matches[1]; std::string proto = matches[2]; int code = atoi(matches[3].c_str()); int bytes = atol(matches[4].c_str()); //remove args from url size_t argpos = file.rfind("?"); if(argpos != std::string::npos) { file = file.substr(0,argpos); } if(file.size()==0) file = "/"; //name index pages if(file[file.size()-1] == '/') { file += "index.html"; } std::string action = "A"; commit.addFile(file, action); std::string refer; std::string agent; if(matches.size() > 5) { std::string agentstr = matches[5]; matches.clear(); apache_entry_agent.match(agentstr, &matches); if(matches.size()>1) { refer = matches[0]; agent = matches[1]; } } return true; } ================================================ FILE: src/formats/apache.h ================================================ /* Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef GOURCE_APACHE_H #define GOURCE_APACHE_H #include #include "commitlog.h" class ApacheCombinedLog : public RCommitLog { protected: bool parseCommit(RCommit& commit); BaseLog* generateLog(const std::string& dir); public: ApacheCombinedLog(const std::string& logfile); }; #endif ================================================ FILE: src/formats/bzr.cpp ================================================ /* Copyright (C) 2010 John Arbash Meinel This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "bzr.h" #include "../gource_settings.h" #include Regex bzr_commit_regex("^ *([\\d.]+) (.+)\t(\\d{4})-(\\d+)-(\\d+)(?: \\{[^}]+})?(?: \\[merge\\])?$"); Regex bzr_file_regex("^ *([AMDR]) (.*[^/])$"); // parse Bazaar log entries (using the gource.style template) std::string BazaarLog::logCommand() { std::string start = (!gGourceSettings.start_date.empty()) ? "date:"+gGourceSettings.start_date : "1"; std::string stop = (!gGourceSettings.stop_date.empty()) ? "date:"+gGourceSettings.stop_date : "-1"; std::string range = str(boost::format("%s..%s") % start % stop); std::string log_command = str(boost::format("bzr log --verbose -r %s --short -n0 --forward") % range); return log_command; } BazaarLog::BazaarLog(const std::string& logfile) : RCommitLog(logfile) { log_command = logCommand(); //can generate log from directory if(!logf && is_dir) { logf = generateLog(logfile); if(logf) { success = true; seekable = true; } } } BaseLog* BazaarLog::generateLog(const std::string& dir) { //does directory have a .bzr ? std::string bzrdir = dir + std::string("/.bzr"); struct stat dirinfo; int stat_rc = stat(bzrdir.c_str(), &dirinfo); if(stat_rc!=0 || !(dirinfo.st_mode & S_IFDIR)) { return 0; } std::string command = getLogCommand(); // do we have this client installed requireExecutable("bzr"); createTempLog(); if(temp_file.size()==0) return 0; char cmd_buff[2048]; snprintf(cmd_buff, 2048, "%s %s > %s", command.c_str(), dir.c_str(), temp_file.c_str()); int command_rc = systemCommand(cmd_buff); if(command_rc != 0) { return 0; } BaseLog* seeklog = new SeekLog(temp_file); return seeklog; } bool BazaarLog::parseCommit(RCommit& commit) { std::string line; std::vector entries; int year, month, day; if(!logf->getNextLine(line)) return false; if (!bzr_commit_regex.match(line, &entries)) { //debugLog("regex failed\n"); return false; } commit.username = entries[1]; year = atoi(entries[2].c_str()); month = atoi(entries[3].c_str()); day = atoi(entries[4].c_str()); struct tm time_str; time_str.tm_year = year - 1900; time_str.tm_mon = month - 1; time_str.tm_mday = day; time_str.tm_hour = 0; time_str.tm_min = 0; time_str.tm_sec = 0; time_str.tm_isdst = -1; commit.timestamp = mktime(&time_str); while(logf->getNextLine(line) && line.size()) { if (!bzr_file_regex.match(line, &entries)) continue; commit.addFile(entries[1], entries[0]); } return true; } ================================================ FILE: src/formats/bzr.h ================================================ /* Copyright (C) 2010 John Arbash Meinel This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef BAZAARLOG_H #define BAZAARLOG_H #include "commitlog.h" class BazaarLog : public RCommitLog { protected: bool parseCommit(RCommit& commit); BaseLog* generateLog(const std::string& dir); public: BazaarLog(const std::string& logfile); static std::string logCommand(); }; #endif ================================================ FILE: src/formats/commitlog.cpp ================================================ /* Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "commitlog.h" #include "../gource_settings.h" #include "../core/sdlapp.h" #include "../core/utf8/utf8.h" std::string RCommitLog::filter_utf8(const std::string& str) { std::string filtered; try { utf8::replace_invalid(str.begin(), str.end(), back_inserter(filtered), '?'); } catch(...) { filtered = "???"; } return filtered; } //RCommitLog RCommitLog::RCommitLog(const std::string& logfile, int firstChar) { logf = 0; seekable = false; success = false; is_dir = false; buffered = false; if(logfile == "-") { //check first char if(checkFirstChar(firstChar, std::cin)) { logf = new StreamLog(); is_dir = false; seekable = false; success = true; } return; } struct stat fileinfo; int rc = stat(logfile.c_str(), &fileinfo); if(rc==0) { is_dir = (fileinfo.st_mode & S_IFDIR) ? true : false; if(!is_dir) { //check first char std::ifstream testf(logfile.c_str()); bool firstOK = checkFirstChar(firstChar, testf); testf.close(); if(firstOK) { logf = new SeekLog(logfile); seekable = true; success = true; } } } } RCommitLog::~RCommitLog() { if(logf!=0) delete logf; if(!temp_file.empty()) { remove(temp_file.c_str()); } } int RCommitLog::systemCommand(const std::string& command) { int rc = system(command.c_str()); return rc; } // TODO: implement check for 'nix OSs void RCommitLog::requireExecutable(const std::string& exename) { #ifdef _WIN32 TCHAR exePath[MAX_PATH]; DWORD result = SearchPath(0, exename.c_str(), ".exe", MAX_PATH, exePath, 0); if(result) return; throw SDLAppException("unable to find %s.exe", exename.c_str()); #endif } //check firstChar of stream is as expected. if no firstChar defined just returns true. bool RCommitLog::checkFirstChar(int firstChar, std::istream& stream) { //cant check this if(firstChar == -1) return true; int c = stream.peek(); if(firstChar == c) return true; return false; } bool RCommitLog::checkFormat() { if(!success) return false; //read a commit to see if the log is in the correct format if(nextCommit(lastCommit, false)) { if(seekable) { //if the log is seekable, go back to the start ((SeekLog*)logf)->seekTo(0.0); lastline.clear(); } else { //otherwise set the buffered flag as we have bufferd one commit buffered = true; } return true; } return false; } std::string RCommitLog::getLogCommand() { return log_command; } bool RCommitLog::isSeekable() { return seekable; } bool RCommitLog::getCommitAt(float percent, RCommit& commit) { if(!seekable) return false; SeekLog* seeklog = ((SeekLog*)logf); //save settings long currpointer = seeklog->getPointer(); std::string currlastline = lastline; seekTo(percent); bool success = findNextCommit(commit,500); //restore settings seeklog->setPointer(currpointer); lastline = currlastline; return success; } bool RCommitLog::getNextLine(std::string& line) { if(!lastline.empty()) { line = lastline; lastline.clear(); return true; } return logf->getNextLine(line); } void RCommitLog::seekTo(float percent) { if(!seekable) return; lastline.clear(); ((SeekLog*)logf)->seekTo(percent); } float RCommitLog::getPercent() { if(seekable) return ((SeekLog*)logf)->getPercent(); return 0.0; } bool RCommitLog::findNextCommit(RCommit& commit, int attempts) { for(int i=0;iisFinished()) return true; return false; } bool RCommitLog::hasBufferedCommit() { return buffered; } //create temp file bool RCommitLog::createTempLog() { return createTempFile(temp_file); } bool RCommitLog::createTempFile(std::string& temp_file) { std::string tempdir; #ifdef _WIN32 DWORD tmplen = GetTempPath(0, 0); if(tmplen == 0) return false; std::vector temp(tmplen+1); tmplen = GetTempPath(static_cast(temp.size()), &temp[0]); if(tmplen == 0 || tmplen >= temp.size()) return false; tempdir = std::string(temp.begin(), temp.begin() + static_cast(tmplen)); tempdir += "\\"; #else tempdir = "/tmp/"; #endif char tmplate[1024]; snprintf(tmplate, 1024, "%sgource-XXXXXX", tempdir.c_str()); #ifdef _WIN32 if(mktemp(tmplate) == NULL) return false; #else if(mkstemp(tmplate) < 0) return false; #endif temp_file = std::string(tmplate); return true; } // RCommitFile RCommitFile::RCommitFile(const std::string& filename, const std::string& action, vec3 colour) { this->filename = RCommitLog::filter_utf8(filename); //prepend a root slash if(this->filename[0] != '/') { this->filename.insert(0, 1, '/'); } this->action = action; this->colour = colour; } RCommit::RCommit() { timestamp = 0; } vec3 RCommit::fileColour(const std::string& filename) { size_t slash = filename.rfind('/'); size_t dot = filename.rfind('.'); if(dot != std::string::npos && dot+1::iterator ri = gGourceSettings.file_filters.begin(); ri != gGourceSettings.file_filters.end(); ri++) { Regex* r = *ri; if(r->match(filename)) { return; } } } // Only allow files that have been whitelisted if(!gGourceSettings.file_show_filters.empty()) { for(std::vector::iterator ri = gGourceSettings.file_show_filters.begin(); ri != gGourceSettings.file_show_filters.end(); ri++) { Regex* r = *ri; if(!r->match(filename)) { return; } } } files.push_back(RCommitFile(filename, action, colour)); } void RCommit::postprocess() { username = RCommitLog::filter_utf8(username); } bool RCommit::isValid() { //check user against filters, if found, discard commit if(!gGourceSettings.user_filters.empty()) { for(std::vector::iterator ri = gGourceSettings.user_filters.begin(); ri != gGourceSettings.user_filters.end(); ri++) { Regex* r = *ri; if(r->match(username)) { return false; } } } // Only allow users that have been whitelisted if(!gGourceSettings.user_show_filters.empty()) { for(std::vector::iterator ri = gGourceSettings.user_show_filters.begin(); ri != gGourceSettings.user_show_filters.end(); ri++) { Regex* r = *ri; if(!r->match(username)) { return false; } } } return !files.empty(); } void RCommit::debug() { debugLog("files:\n"); for(std::list::iterator it = files.begin(); it != files.end(); it++) { RCommitFile f = *it; debugLog("%s %s\n", f.action.c_str(), f.filename.c_str()); } } ================================================ FILE: src/formats/commitlog.h ================================================ /* Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef RCOMMIT_LOG_H #define RCOMMIT_LOG_H #include "../core/seeklog.h" #include "../core/display.h" #include "../core/regex.h" #include "../core/stringhash.h" #include #include #include #include "sys/stat.h" class RCommitFile { public: std::string filename; std::string action; vec3 colour; RCommitFile(const std::string& filename, const std::string& action, vec3 colour); }; class RCommit { vec3 fileColour(const std::string& filename); public: time_t timestamp; std::string username; std::list files; void postprocess(); bool isValid(); void addFile(const std::string& filename, const std::string& action); void addFile(const std::string& filename, const std::string& action, const vec3& colour); RCommit(); void debug(); virtual bool parse(BaseLog* logf) { return false; }; }; class RCommitLog { protected: BaseLog* logf; std::string temp_file; std::string log_command; std::string lastline; bool is_dir; bool success; bool seekable; RCommit lastCommit; bool buffered; bool checkFirstChar(int firstChar, std::istream& stream); bool createTempLog(); static bool createTempFile(std::string& temp_file); bool getNextLine(std::string& line); virtual bool parseCommit(RCommit& commit) { return false; }; public: RCommitLog(const std::string& logfile, int firstChar = -1); virtual ~RCommitLog(); static std::string filter_utf8(const std::string& str); void seekTo(float percent); bool checkFormat(); std::string getLogCommand(); static int systemCommand(const std::string& command); void requireExecutable(const std::string& exename); void bufferCommit(RCommit& commit); bool getCommitAt(float percent, RCommit& commit); bool findNextCommit(RCommit& commit, int attempts); bool nextCommit(RCommit& commit, bool validate = true); bool hasBufferedCommit(); bool isFinished(); bool isSeekable(); float getPercent(); }; #endif ================================================ FILE: src/formats/custom.cpp ================================================ /* Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "custom.h" #include "../gource_settings.h" Regex custom_regex("^(?:\\xEF\\xBB\\xBF)?([^|]+)\\|([^|]*)\\|([ADM]?)\\|([^|]+)(?:\\|#?([a-fA-F0-9]{6}))?"); CustomLog::CustomLog(const std::string& logfile) : RCommitLog(logfile) { } vec3 CustomLog::parseColour(const std::string& cstr) { vec3 colour; int r,g,b; if(sscanf(cstr.c_str(), "%02x%02x%02x", &r, &g, &b) == 3) { colour = vec3( r, g, b ); colour /= 255.0f; } return colour; } // parse modified cvs format log entries bool CustomLog::parseCommit(RCommit& commit) { while(parseCommitEntry(commit)); return !commit.files.empty(); } bool CustomLog::parseCommitEntry(RCommit& commit) { std::string line; std::vector entries; if(!getNextLine(line)) return false; //custom line if(!custom_regex.match(line, &entries)) return false; time_t timestamp; // Allow timestamp to be a string if(entries[0].size() > 1 && entries[0].find("-", 1) != std::string::npos) { if(!SDLAppSettings::parseDateTime(entries[0], timestamp)) return false; } else { timestamp = (time_t) atoll(entries[0].c_str()); if(!timestamp && entries[0] != "0") return false; } std::string username = (entries[1].size()>0) ? entries[1] : "Unknown"; std::string action = (entries[2].size()>0) ? entries[2] : "A"; //if this file is for the same person and timestamp //we add to the commit, else we save the lastline //and return false if(commit.files.empty()) { commit.timestamp = timestamp; commit.username = username; } else { if(commit.timestamp != timestamp || commit.username != username) { lastline = line; return false; } } bool has_colour = false; vec3 colour; if(entries.size()>=5 && entries[4].size()>0) { has_colour = true; colour = parseColour(entries[4]); } if(has_colour) { commit.addFile(entries[3], action, colour); } else { commit.addFile(entries[3], action); } return true; } ================================================ FILE: src/formats/custom.h ================================================ /* Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef CUSTOMLOG_H #define CUSTOMLOG_H #include "commitlog.h" class CustomLog : public RCommitLog { protected: bool parseCommit(RCommit& commit); bool parseCommitEntry(RCommit& commit); vec3 parseColour(const std::string& cstr); public: CustomLog(const std::string& logfile); }; #endif ================================================ FILE: src/formats/cvs-exp.cpp ================================================ /* Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "cvs-exp.h" Regex cvsexp_commitno_regex("^([0-9]{6}):"); Regex cvsexp_branch_regex("^BRANCH \\[(.+)\\]$"); Regex cvsexp_date_regex("^\\(date: ([0-9]{4})[-/]([0-9]{2})[-/]([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})(?: [+-][0-9]{4})?;(.+)$"); Regex cvsexp_detail_regex("author: ([^;]+); state: ([^;]+);(.+)$"); //Regex cvsexp_lines_regex("lines: \\+([0-9]+) -([0-9]+)"); Regex cvsexp_entry_regex("\\| (.+),v:([0-9.]+),?"); Regex cvsexp_end_regex("^(=+)$"); std::string CVSEXPCommitLog::logCommand() { std::string log_command = "cvs-exp.pl -notree"; return log_command; } CVSEXPCommitLog::CVSEXPCommitLog(const std::string& logfile) : RCommitLog(logfile) { } // parse modified cvs format log entries bool CVSEXPCommitLog::parseCommit(RCommit& commit) { std::string line; std::vector entries; if(!logf->getNextLine(line)) return false; //skip empty line if there is one if(line.size() == 0) { if(!logf->getNextLine(line)) return false; } //read commit no if(!cvsexp_commitno_regex.match(line, &entries)) return false; //int commitno = atoi(entries[0].c_str()); //debugLog("commitno matched\n"); if(!logf->getNextLine(line)) return false; //should be a branch if(cvsexp_branch_regex.match(line, &entries)) { //read next blank line if(!logf->getNextLine(line)) return false; if(line.size()) return false; if(!logf->getNextLine(line)) return false; } //parse date if(!cvsexp_date_regex.match(line, &entries)) return false; //debugLog("date matched\n"); struct tm time_str; time_str.tm_year = atoi(entries[0].c_str()) - 1900; time_str.tm_mon = atoi(entries[1].c_str()) - 1; time_str.tm_mday = atoi(entries[2].c_str()); time_str.tm_hour = atoi(entries[3].c_str()); time_str.tm_min = atoi(entries[4].c_str()); time_str.tm_sec = atoi(entries[5].c_str()); time_str.tm_isdst = -1; commit.timestamp = mktime(&time_str); //parse author,state std::string rest = entries[6]; if(!cvsexp_detail_regex.match(rest, &entries)) return false; //debugLog("author/state matched\n"); commit.username = entries[0]; std::string commit_state = entries[1]; /* not used //if rest is not ')' parse lines rest = entries[2]; // need to parse lines if(rest.size() > 2) { if(!cvsexp_lines_regex.match(rest, &entries)) return false; } */ if(!logf->getNextLine(line)) return false; std::string commit_action = (commit_state == "dead") ? "D" : "M"; while(cvsexp_entry_regex.match(line, &entries)) { //ignore files in Attic - previously deleted file if(entries[0].find("/Attic/") == std::string::npos) { commit.addFile(entries[0], commit_action); } if(!logf->getNextLine(line)) return false; } //read blank line if(!logf->getNextLine(line)) return false; //std::string message; //read commit message while(logf->getNextLine(line) && line.size()) { //if(message.size()) message += std::string("\n"); //message += line; } //read until end of commit or eof while(logf->getNextLine(line)) { if(cvsexp_end_regex.match(line,&entries)) { //debugLog("read end of commit %s\n", entries[0].c_str()); break; } } return true; } ================================================ FILE: src/formats/cvs-exp.h ================================================ /* Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef CVSLOG_EXP_H #define CVSLOG_EXP_H #include "commitlog.h" class CVSEXPCommitLog : public RCommitLog { protected: bool parseCommit(RCommit& commit); public: CVSEXPCommitLog(const std::string& logfile); static std::string logCommand(); }; #endif ================================================ FILE: src/formats/cvs2cl.cpp ================================================ /* Copyright (C) 2010 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "cvs2cl.h" #include "../gource_settings.h" #ifdef HAVE_LIBTINYXML #include #else #include "../tinyxml/tinyxml.h" #endif Regex cvs2cl_xml_tag("^<\\??xml"); Regex cvs2cl_logentry_start("^"); Regex cvs2cl_logentry_timestamp("(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})Z"); std::string CVS2CLCommitLog::logCommand() { std::string log_command = "cvs2cl --chrono --stdout --xml -g-q"; return log_command; } CVS2CLCommitLog::CVS2CLCommitLog(const std::string& logfile) : RCommitLog(logfile, '<') { } bool CVS2CLCommitLog::parseCommit(RCommit& commit) { //fprintf(stderr,"parsing cvs2cl log\n"); std::string line; if(!getNextLine(line)) return false; //start of log entry if(!cvs2cl_logentry_start.match(line)) { //is this the start of the document if(!cvs2cl_xml_tag.match(line)) return false; //fprintf(stderr,"found xml tag\n"); //if so find the first logentry tag bool found_logentry = false; while(getNextLine(line)) { if(cvs2cl_logentry_start.match(line)) { found_logentry = true; break; } } if(!found_logentry) return false; } //fprintf(stderr,"found logentry\n"); logentry.clear(); logentry.append(line); logentry.append("\n"); //fprintf(stderr,"found opening tag\n"); bool endfound = false; while(getNextLine(line)) { logentry.append(line); logentry.append("\n"); if(cvs2cl_logentry_end.match(line)) { //fprintf(stderr,"found closing tag\n"); endfound=true; break; } } //incomplete commit if(!endfound) return false; //fprintf(stderr,"read logentry\n"); TiXmlDocument doc; if(!doc.Parse(logentry.c_str())) return false; //fprintf(stderr,"try to parse logentry: %s\n", logentry.c_str()); TiXmlElement* leE = doc.FirstChildElement( "entry" ); std::vector entries; if(!leE) return false; //parse date TiXmlElement* dateE = leE->FirstChildElement( "isoDate" ); if(!dateE) return false; std::string timestamp_str(dateE->GetText()); if(!cvs2cl_logentry_timestamp.match(timestamp_str, &entries)) return false; struct tm time_str; time_str.tm_year = atoi(entries[0].c_str()) - 1900; time_str.tm_mon = atoi(entries[1].c_str()) - 1; time_str.tm_mday = atoi(entries[2].c_str()); time_str.tm_hour = atoi(entries[3].c_str()); time_str.tm_min = atoi(entries[4].c_str()); time_str.tm_sec = atoi(entries[5].c_str()); time_str.tm_isdst = -1; commit.timestamp = mktime(&time_str); //parse author TiXmlElement* authorE = leE->FirstChildElement("author"); if(authorE != 0) { std::string author(authorE->GetText()); if(author.empty()) author = "Unknown"; commit.username = author; } //parse changes for(TiXmlElement* fileE = leE->FirstChildElement("file"); fileE != 0; fileE = fileE->NextSiblingElement()) { TiXmlElement* state = fileE->FirstChildElement("cvsstate"); TiXmlElement* name = fileE->FirstChildElement("name"); //check for state if(name == 0 || state == 0) continue; std::string status = strcmp(state->GetText(), "dead") == 0 ? "D" : "M"; std::string file(name->GetText()); if(file.empty()) continue; commit.addFile(file, status); } //fprintf(stderr,"parsed logentry\n"); //read files return true; } ================================================ FILE: src/formats/cvs2cl.h ================================================ /* Copyright (C) 2010 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef CVS2CL_H #define CVS2CL_H #include "commitlog.h" class CVS2CLCommitLog : public RCommitLog { protected: bool parseCommit(RCommit& commit); std::string logentry; public: CVS2CLCommitLog(const std::string& logfile); static std::string logCommand(); }; #endif ================================================ FILE: src/formats/git.cpp ================================================ /* Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "git.h" #include "../gource_settings.h" #ifndef _MSC_VER #include #endif // parse git log entries //git-log command notes: // - no single quotes on WIN32 as system call treats them differently // - 'user:' prefix allows us to quickly tell if the log is the wrong format // and try a different format (eg cvs-exp) int git_version_major = 0; int git_version_minor = 0; int git_version_patch = 0; Regex git_version_regex("([0-9]+)(?:\\.([0-9]+))?(?:\\.([0-9]+))?"); void GitCommitLog::readGitVersion() { if(git_version_major != 0) return; std::string temp_file; if(!createTempFile(temp_file)) { return; } char cmd_buff[2048]; int result = snprintf(cmd_buff, sizeof(cmd_buff), "git --version > %s", temp_file.c_str()); if(result < 0 || result >= sizeof(cmd_buff)) { remove(temp_file.c_str()); return; } int command_rc = systemCommand(cmd_buff); if(command_rc != 0) { remove(temp_file.c_str()); return; } std::ifstream in(temp_file.c_str()); if(!in.is_open()) { remove(temp_file.c_str()); return; } std::string version_str; std::getline(in, version_str); in.close(); remove(temp_file.c_str()); std::vector entries; if(!git_version_regex.match(version_str, &entries)) return; git_version_major = atoi(entries[0].c_str()); if(entries.size() > 1) { git_version_minor = atoi(entries[1].c_str()); } if(entries.size() > 2) { git_version_patch = atoi(entries[2].c_str()); } } std::string GitCommitLog::logCommand() { std::string log_command = "git log " "--reverse --raw --encoding=UTF-8 " "--no-renames"; readGitVersion(); // Add --no-show-signature either // if git version couldn't be determined or if version // is at least 2.10 if( git_version_major == 0 || git_version_major > 2 || (git_version_major == 2 && git_version_minor >= 10)) { log_command += " --no-show-signature"; } if(gGourceSettings.author_time) { log_command += " --pretty=format:user:%aN%n%at"; } else { log_command += " --pretty=format:user:%aN%n%ct"; } if(!gGourceSettings.start_date.empty()) { log_command += " --since "; log_command += gGourceSettings.start_date; } if(!gGourceSettings.stop_date.empty()) { log_command += " --until "; log_command += gGourceSettings.stop_date; } if(!gGourceSettings.git_branch.empty()) { log_command += " "; log_command += gGourceSettings.git_branch; } return log_command; } GitCommitLog::GitCommitLog(const std::string& logfile) : RCommitLog(logfile, 'u') { log_command = logCommand(); //can generate log from directory if(!logf && is_dir) { logf = generateLog(logfile); if(logf) { success = true; seekable = true; } } } BaseLog* GitCommitLog::generateLog(const std::string& dir) { //get working directory char cwd_buff[1024]; if(getcwd(cwd_buff, 1024) != cwd_buff) { return 0; } //does directory have a .git ? std::string gitdir = dir + std::string("/.git"); struct stat dirinfo; int stat_rc = stat(gitdir.c_str(), &dirinfo); if(stat_rc!=0 || !(dirinfo.st_mode & S_IFDIR || dirinfo.st_mode & S_IFREG)) { return 0; } // do we have this client installed requireExecutable("git"); std::string command = getLogCommand(); //create temp file createTempLog(); if(temp_file.size()==0) return 0; if(chdir(dir.c_str()) != 0) { return 0; } char cmd_buff[2048]; int written = snprintf(cmd_buff, 2048, "%s > %s", command.c_str(), temp_file.c_str()); if(written < 0 || written >= 2048) { return 0; } int command_rc = systemCommand(cmd_buff); //change back to original directory chdir(cwd_buff); if(command_rc != 0) { return 0; } BaseLog* seeklog = new SeekLog(temp_file); return seeklog; } // parse modified git format log entries bool GitCommitLog::parseCommit(RCommit& commit) { std::string line; commit.username = ""; while(logf->getNextLine(line) && line.size()) { if(line.find("user:") == 0) { //username follows user prefix commit.username = line.substr(5); if(!logf->getNextLine(line)) return false; commit.timestamp = atol(line.c_str()); //this isnt a commit we are parsing, abort if(commit.timestamp == 0) return false; continue; } //should see username before files if(commit.username.empty()) return false; size_t tab = line.find('\t'); //incorrect log format if(tab == std::string::npos || tab == 0 || tab == line.size()-1) continue; std::string status = line.substr(tab - 1, 1); std::string file = line.substr(tab + 1); if(file.empty()) continue; //check for and remove double quotes if(file.find('"') == 0 && file.rfind('"') == file.size()-1) { if(file.size()<=2) continue; file = file.substr(1,file.size()-2); } commit.addFile(file, status); } //check we at least got a username if(commit.username.empty()) return false; return true; } ================================================ FILE: src/formats/git.h ================================================ /* Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef GITLOG_H #define GITLOG_H #include "commitlog.h" class GitCommitLog : public RCommitLog { protected: bool parseCommit(RCommit& commit); BaseLog* generateLog(const std::string& dir); static void readGitVersion(); public: GitCommitLog(const std::string& logfile); static std::string logCommand(); }; #endif ================================================ FILE: src/formats/gitraw.cpp ================================================ /* Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "gitraw.h" Regex git_raw_commit("^commit ([0-9a-z]+)"); Regex git_raw_tree("^tree ([0-9a-z]+)"); Regex git_raw_parent("^parent ([0-9a-z]+)"); Regex git_raw_author("^author (.+) <([^@>]+)@?([^>]*)> (\\d+) ([-+]\\d+)"); Regex git_raw_committer("^committer (.+) <([^@>]+)@?([^>]*)> (\\d+) ([-+]\\d+)"); Regex git_raw_file("^:[0-9]+ [0-9]+ [0-9a-z]+\\.* ([0-9a-z]+)\\.* ([A-Z])[ \\t]+(.+)"); // parse git log entries // NOTE: this format is deprecated and exists // to allow existing log files produced in this format to work std::string gGourceGitRawLogCommand = "git log --reverse --raw --pretty=raw"; GitRawCommitLog::GitRawCommitLog(const std::string& logfile) : RCommitLog(logfile, 'c') { log_command = gGourceGitRawLogCommand; } bool GitRawCommitLog::parseCommit(RCommit& commit) { std::string line; std::vector entries; //read commit ref/ branch if(!logf->getNextLine(line)) return false; //commit if(!git_raw_commit.match(line, &entries)) return false; if(!logf->getNextLine(line)) return false; //tree if(!git_raw_tree.match(line, &entries)) return false; if(!logf->getNextLine(line)) return false; //0 or more parents while(git_raw_parent.match(line, &entries)) { if(!logf->getNextLine(line)) return false; } //author - used for display name if(!git_raw_author.match(line, &entries)) return false; commit.username = entries[0]; if(!logf->getNextLine(line)) return false; //committer - used for time (most likely chronological) if(!git_raw_committer.match(line, &entries)) return false; commit.timestamp = atol(entries[3].c_str()); //blank line before message if(!logf->getNextLine(line)) return false; //read commit message while(logf->getNextLine(line) && line.size()) { } //read files while(logf->getNextLine(line) && line.size()) { //debugLog("file??? %s\n", line.c_str()); if(git_raw_file.match(line, &entries)) { commit.addFile(entries[2], entries[1]); } } // commit.debug(); return true; } ================================================ FILE: src/formats/gitraw.h ================================================ /* Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef GITLOG_RAW_H #define GITLOG_RAW_H #include "commitlog.h" #include extern std::string gGourceGitRawLogCommand; class GitRawCommitLog : public RCommitLog { protected: bool parseCommit(RCommit& commit); public: GitRawCommitLog(const std::string& logfile); }; #endif ================================================ FILE: src/formats/hg.cpp ================================================ /* Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "hg.h" #include "../core/sdlapp.h" #include "../gource_settings.h" #include Regex hg_regex("^([0-9]+) -?[0-9]+\\|([^|]+)\\|([ADM]?)\\|(.+)$"); std::string MercurialLog::logCommand() { // parse Mercurial log entries (using the gource.style template) std::string gource_style_path = gSDLAppResourceDir + std::string("gource.style"); std::string range = // date range (!gGourceSettings.start_date.empty() && !gGourceSettings.stop_date.empty()) ? str(boost::format("--date '%s to %s'") % gGourceSettings.start_date % gGourceSettings.stop_date) // start date only : (!gGourceSettings.start_date.empty()) ? str(boost::format("--date '>%s'") % gGourceSettings.start_date) // stop date only : (!gGourceSettings.stop_date.empty()) ? str(boost::format("--date '<%s'") % gGourceSettings.stop_date) // default : ""; std::string log_command = str(boost::format("hg log %s -r 0:tip --style '%s'") % range % gource_style_path); #ifdef _WIN32 std::replace(log_command.begin(), log_command.end(), '\'', '"'); #endif return log_command; } MercurialLog::MercurialLog(const std::string& logfile) : RCommitLog(logfile) { log_command = logCommand(); //can generate log from directory if(!logf && is_dir) { logf = generateLog(logfile); if(logf) { success = true; seekable = true; } } } BaseLog* MercurialLog::generateLog(const std::string& dir) { //does directory have a .hg ? std::string hgdir = dir + std::string("/.hg"); struct stat dirinfo; int stat_rc = stat(hgdir.c_str(), &dirinfo); if(stat_rc!=0 || !(dirinfo.st_mode & S_IFDIR)) { return 0; } // do we have this client installed requireExecutable("hg"); std::string command = getLogCommand(); createTempLog(); if(temp_file.size()==0) return 0; char cmd_buff[2048]; snprintf(cmd_buff, 2048, "%s -R \"%s\" > %s", command.c_str(), dir.c_str(), temp_file.c_str()); int command_rc = systemCommand(cmd_buff); if(command_rc != 0) { return 0; } BaseLog* seeklog = new SeekLog(temp_file); return seeklog; } bool MercurialLog::parseCommit(RCommit& commit) { while(parseCommitEntry(commit)); return !commit.files.empty(); } bool MercurialLog::parseCommitEntry(RCommit& commit) { std::string line; std::vector entries; if(!getNextLine(line)) return false; //custom line if(!hg_regex.match(line, &entries)) return false; time_t timestamp = atol(entries[0].c_str()); std::string username = entries[1]; //if this file is for the same person and timestamp //we add to the commit, else we save the lastline //and return false if(commit.files.empty()) { commit.timestamp = timestamp; commit.username = username; } else { if(commit.timestamp != timestamp || commit.username != username) { lastline = line; return false; } } std::string action = "A"; if(!entries[2].empty()) { action = entries[2]; } commit.addFile(entries[3], action); //commit.debug(); return true; } ================================================ FILE: src/formats/hg.h ================================================ /* Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef MERCURIALLOG_H #define MERCURIALLOG_H #include "commitlog.h" class MercurialLog : public RCommitLog { protected: bool parseCommit(RCommit& commit); bool parseCommitEntry(RCommit& commit); BaseLog* generateLog(const std::string& dir); public: MercurialLog(const std::string& logfile); static std::string logCommand(); }; #endif ================================================ FILE: src/formats/svn.cpp ================================================ /* Copyright (C) 2010 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "svn.h" #include "../gource_settings.h" #include #ifdef HAVE_LIBTINYXML #include #else #include "../tinyxml/tinyxml.h" #endif Regex svn_xml_tag("^<\\??xml"); Regex svn_logentry_start("^"); Regex svn_logentry_timestamp("(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})"); std::string SVNCommitLog::logCommand() { std::string start = (!gGourceSettings.start_date.empty()) ? str(boost::format("{%s}") % gGourceSettings.start_date) : "1"; std::string stop = (!gGourceSettings.stop_date.empty()) ? str(boost::format("{%s}") % gGourceSettings.stop_date) : "HEAD"; std::string range = str(boost::format("%s:%s") % start % stop); std::string log_command = str(boost::format("svn log -r %s --xml --verbose --quiet") % range); return log_command; } SVNCommitLog::SVNCommitLog(const std::string& logfile) : RCommitLog(logfile, '<') { log_command = logCommand(); //can generate log from directory if(!logf && is_dir) { logf = generateLog(logfile); if(logf) { success = true; seekable = true; } } logentry.reserve(1024); } BaseLog* SVNCommitLog::generateLog(const std::string& dir) { //get working directory char cwd_buff[1024]; if(getcwd(cwd_buff, 1024) != cwd_buff) { return 0; } //does directory have a .svn ? std::string gitdir = dir + std::string("/.svn"); struct stat dirinfo; int stat_rc = stat(gitdir.c_str(), &dirinfo); if(stat_rc!=0 || !(dirinfo.st_mode & S_IFDIR)) { return 0; } // do we have this client installed requireExecutable("svn"); std::string command = getLogCommand(); //create temp file createTempLog(); if(temp_file.size()==0) return 0; if(chdir(dir.c_str()) != 0) { return 0; } char cmd_buff[2048]; snprintf(cmd_buff, 2048, "%s > %s", command.c_str(), temp_file.c_str()); int command_rc = systemCommand(cmd_buff); chdir(cwd_buff); if(command_rc != 0) { return 0; } BaseLog* seeklog = new SeekLog(temp_file); return seeklog; } #ifndef HAVE_TIMEGM std::string system_tz; bool system_tz_init = false; time_t __timegm_hack(struct tm* tm) { if(!system_tz_init) { char* current_tz_env = getenv("TZ"); if(current_tz_env != 0) { system_tz = std::string("TZ=") + current_tz_env; } system_tz_init = true; } putenv((char*)"TZ=UTC"); tzset(); time_t timestamp = mktime(tm); if(!system_tz.empty()) { putenv((char*)system_tz.c_str()); } else { #ifdef HAVE_UNSETENV unsetenv("TZ"); #else putenv((char*)"TZ="); #endif } tzset(); return timestamp; } #endif bool SVNCommitLog::parseCommit(RCommit& commit) { //fprintf(stderr,"parsing svn log\n"); std::string line; if(!getNextLine(line)) return false; //start of log entry if(!svn_logentry_start.match(line)) { //is this the start of the document if(!svn_xml_tag.match(line)) return false; //fprintf(stderr,"found xml tag\n"); //if so find the first logentry tag bool found_logentry = false; while(getNextLine(line)) { if(svn_logentry_start.match(line)) { found_logentry = true; break; } } if(!found_logentry) return false; } //fprintf(stderr,"found logentry\n"); logentry.clear(); logentry.append(line); logentry.append("\n"); //fprintf(stderr,"found opening tag\n"); bool endfound = false; while(getNextLine(line)) { logentry.append(line); logentry.append("\n"); if(svn_logentry_end.match(line)) { //fprintf(stderr,"found closing tag\n"); endfound=true; break; } } //incomplete commit if(!endfound) return false; //fprintf(stderr,"read logentry\n"); TiXmlDocument doc; if(!doc.Parse(logentry.c_str())) return false; //fprintf(stderr,"try to parse logentry: %s\n", logentry.c_str()); TiXmlElement* leE = doc.FirstChildElement( "logentry" ); std::vector entries; if(!leE) return false; //parse date TiXmlElement* dateE = leE->FirstChildElement( "date" ); if(!dateE) return false; std::string timestamp_str(dateE->GetText()); if(!svn_logentry_timestamp.match(timestamp_str, &entries)) return false; struct tm time_str; time_str.tm_year = atoi(entries[0].c_str()) - 1900; time_str.tm_mon = atoi(entries[1].c_str()) - 1; time_str.tm_mday = atoi(entries[2].c_str()); time_str.tm_hour = atoi(entries[3].c_str()); time_str.tm_min = atoi(entries[4].c_str()); time_str.tm_sec = atoi(entries[5].c_str()); time_str.tm_isdst = -1; #ifdef HAVE_TIMEGM commit.timestamp = timegm(&time_str); #else commit.timestamp = __timegm_hack(&time_str); #endif //parse author TiXmlElement* authorE = leE->FirstChildElement("author"); if(authorE != 0) { // GetText() may return NULL, causing author instantiation to crash. std::string author; if(authorE->GetText()) author = authorE->GetText(); if(author.empty()) author = "Unknown"; commit.username = author; } TiXmlElement* pathsE = leE->FirstChildElement( "paths" ); //log entries sometimes dont have any paths if(!pathsE) return true; //parse changes for(TiXmlElement* pathE = pathsE->FirstChildElement("path"); pathE != 0; pathE = pathE->NextSiblingElement()) { //parse path const char* kind = pathE->Attribute("kind"); const char* action = pathE->Attribute("action"); //check for action if(action == 0) continue; bool is_dir = false; //if has the 'kind' attribute (old versions of svn dont have this), check if it is a dir if(kind != 0 && strcmp(kind,"dir") == 0) { //accept only deletes for directories if(strcmp(action, "D") != 0) continue; is_dir = true; } std::string file(pathE->GetText()); std::string status(action); if(file.empty()) continue; if(status.empty()) continue; //append trailing slash if is directory if(is_dir && file[file.size()-1] != '/') { file = file + std::string("/"); } commit.addFile(file, status); } //fprintf(stderr,"parsed logentry\n"); //read files return true; } ================================================ FILE: src/formats/svn.h ================================================ /* Copyright (C) 2010 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef SVNLOG_H #define SVNLOG_H #include "commitlog.h" #include extern std::string gGourceSVNLogCommand; class SVNCommitLog : public RCommitLog { protected: bool parseCommit(RCommit& commit); BaseLog* generateLog(const std::string& dir); std::string logentry; public: SVNCommitLog(const std::string& logfile); static std::string logCommand(); }; #endif ================================================ FILE: src/gource.cpp ================================================ /* Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "gource.h" #include "core/png_writer.h" bool gGourceDrawBackground = true; bool gGourceQuadTreeDebug = false; int gGourceMaxQuadTreeDepth = 6; int gGourceUserInnerLoops = 0; Gource::Gource(FrameExporter* exporter) { this->logfile = gGourceSettings.path; commitlog = 0; //disable OpenGL 2.0 functions if not supported if(!GLEW_VERSION_2_0) gGourceSettings.ffp = true; if(!gGourceSettings.file_graphic) { gGourceSettings.file_graphic = texturemanager.grab("file.png", true, GL_CLAMP_TO_EDGE); } if(gGourceSettings.default_font_scale) { if(display.viewport_dpi_ratio.x > 1.0f) { gGourceSettings.font_scale = display.viewport_dpi_ratio.x; } else { int threshold = 1600; gGourceSettings.font_scale = (float) (1 + glm::max(0, display.height / threshold)); } debugLog("setting font scale for resolution %d x %d to %.2f", display.width, display.height, gGourceSettings.font_scale); gGourceSettings.setScaledFontSizes(); } fontlarge = fontmanager.grab(gGourceSettings.font_file, 42 * gGourceSettings.font_scale); fontlarge.dropShadow(true); fontlarge.roundCoordinates(true); fontmedium = fontmanager.grab(gGourceSettings.font_file, gGourceSettings.scaled_font_size); fontmedium.dropShadow(true); fontmedium.roundCoordinates(false); fontcaption = fontmanager.grab(gGourceSettings.font_file, gGourceSettings.caption_size); fontcaption.dropShadow(true); fontcaption.roundCoordinates(false); fontcaption.alignTop(false); font = fontmanager.grab(gGourceSettings.font_file, 14 * gGourceSettings.font_scale); font.dropShadow(true); font.roundCoordinates(true); fontdirname = fontmanager.grab(gGourceSettings.font_file, gGourceSettings.scaled_dirname_font_size); fontdirname.dropShadow(true); fontdirname.roundCoordinates(true); slider.init(); //only use bloom with alpha channel if transparent due to artifacts on some video cards std::string bloom_tga = gGourceSettings.transparent ? "bloom_alpha.tga" : "bloom.tga"; bloomtex = texturemanager.grab(bloom_tga); beamtex = texturemanager.grab("beam.png"); usertex = texturemanager.grab("user.png", true, GL_CLAMP_TO_EDGE); shadow_shader = text_shader = bloom_shader = 0; if(!gGourceSettings.ffp) { shadow_shader = shadermanager.grab("shadow"); bloom_shader = shadermanager.grab("bloom"); text_shader = shadermanager.grab("text"); } //calculate once GLint max_texture_size; glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size); font_texel_size = 1.0f / (float) std::min( 512, max_texture_size ); logotex = 0; backgroundtex = 0; //load logo if(gGourceSettings.logo.size() > 0) { bool mipmap_logo = !(GLEW_ARB_texture_non_power_of_two || GLEW_VERSION_2_0); logotex = texturemanager.grabFile(gGourceSettings.logo, mipmap_logo); } //load background image if(gGourceSettings.background_image.size() > 0) { backgroundtex = texturemanager.grabFile(gGourceSettings.background_image); } stop_position_reached=false; reloaded = false; paused = false; first_read = true; grab_mouse = false; mousemoved = false; mousedragged = false; mouseclicked = false; take_screenshot = false; if(gGourceSettings.hide_mouse) { cursor.showCursor(false); } splash = -1.0; debug = false; trace_debug = false; frameExporter = 0; dirNodeTree = 0; userTree = 0; selectedFile = 0; hoverFile = 0; selectedUser = 0; hoverUser = 0; date_x_offset = 0; starting_z = -300.0f; textbox = TextBox(fontmanager.grab(gGourceSettings.font_file, 18 * gGourceSettings.font_scale)); textbox.setBrightness(0.5f); textbox.show(); file_key = FileKey(1.0f); camera = ZoomCamera(vec3(0,0, starting_z), vec3(0.0, 0.0, 0.0), gGourceSettings.camera_zoom_default, gGourceSettings.camera_zoom_max); camera.setPadding(gGourceSettings.padding); setCameraMode(gGourceSettings.camera_mode); root = 0; //min physics rate 60fps (ie maximum allowed delta 1.0/60) max_tick_rate = 1.0 / 60.0; runtime = 0.0f; frameskip = 0; framecount = 0; reset(); logmill = new RLogMill(logfile); if(exporter!=0) setFrameExporter(exporter, gGourceSettings.output_framerate); //if recording a video or in demo mode, or multiple repos, the slider is initially hidden if(exporter==0 && gGourceSettings.repo_count==1) slider.show(); } void Gource::writeCustomLog(const std::string& logfile, const std::string& output_file) { RLogMill logmill(logfile); RCommitLog* commitlog = logmill.getLog(); // TODO: exception handling if(!commitlog) { std::string error = logmill.getError(); if(!error.empty()) SDLAppQuit(error); return; } RCommit commit; FILE* fh = stdout; if(output_file != "-") { fh = fopen(output_file.c_str(), "w"); if(!fh) return; } while(!commitlog->isFinished()) { RCommit commit; if(!commitlog->nextCommit(commit)) { if(!commitlog->isSeekable()) { break; } continue; } for(std::list::iterator it = commit.files.begin(); it != commit.files.end(); it++) { RCommitFile& cf = *it; fprintf(fh, "%lld|%s|%s|%s\n", (long long int) commit.timestamp, commit.username.c_str(), cf.action.c_str(), cf.filename.c_str()); } commit.files.clear(); } if(output_file != "-") fclose(fh); } Gource::~Gource() { reset(); if(logmill!=0) delete logmill; if(root!=0) delete root; //reset settings gGourceSettings.setGourceDefaults(); } void Gource::init() { } void Gource::unload() { file_vbo.unload(); user_vbo.unload(); edge_vbo.unload(); action_vbo.unload(); bloom_vbo.unload(); } void Gource::reload() { reloaded = true; } void Gource::quit() { } void Gource::update(float t, float dt) { float scaled_dt = std::min(dt, max_tick_rate); //if exporting a video use a fixed tick rate rather than time based if(frameExporter != 0) { scaled_dt = max_tick_rate; } //apply time scaling scaled_dt *= gGourceSettings.time_scale; //have to manage runtime internally as we're messing with dt if(!paused) runtime += scaled_dt; if(gGourceSettings.stop_at_time > 0.0 && runtime >= gGourceSettings.stop_at_time) stop_position_reached = true; logic_time = SDL_GetTicks(); logic(runtime, scaled_dt); logic_time = SDL_GetTicks() - logic_time; draw(runtime, scaled_dt); //extract frames based on frameskip setting if frameExporter defined if(frameExporter != 0 && commitlog && !gGourceSettings.shutdown) { if(framecount % (frameskip+1) == 0) { frameExporter->dump(); } } if(!gGourceSettings.hide_mouse) { //note: cursor uses real dt cursor.logic(dt); cursor.draw(); } framecount++; } //peek at the date under the mouse pointer on the slider std::string Gource::dateAtPosition(float percent) { RCommit commit; std::string date; if(percent<1.0 && commitlog->getCommitAt(percent, commit)) { //display date char datestr[256]; // TODO: memory leak ?? struct tm* timeinfo = localtime ( &(commit.timestamp) ); strftime(datestr, 256, "%A, %d %B, %Y", timeinfo); date = std::string(datestr); } return date; } void Gource::grabMouse(bool grab_mouse) { this->grab_mouse = grab_mouse; #if SDL_VERSION_ATLEAST(2,0,0) if(grab_mouse) { if(!SDL_GetRelativeMouseMode()) { // NOTE: SDL_SetWindowGrab needed as well to work around this bug: // http://bugzilla.libsdl.org/show_bug.cgi?id=1967 SDL_SetWindowGrab(display.sdl_window, SDL_TRUE); SDL_SetRelativeMouseMode(SDL_TRUE); } } else { if(SDL_GetRelativeMouseMode()) { SDL_SetWindowGrab(display.sdl_window, SDL_FALSE); SDL_SetRelativeMouseMode(SDL_FALSE); SDL_WarpMouseInWindow(display.sdl_window, mousepos.x, mousepos.y); } } #endif #if not SDL_VERSION_ATLEAST(2,0,0) if(!grab_mouse) { // restore old mouse position SDL_WarpMouse(mousepos.x, mousepos.y); } #endif cursor.showCursor(!grab_mouse); } void Gource::mouseMove(SDL_MouseMotionEvent *e) { if(commitlog==0) return; if(gGourceSettings.disable_input) return; if(gGourceSettings.hide_mouse) return; // debugLog("mouse move %d, %d (change %d, %d)", e->x, e->y, e->xrel, e->yrel); if(grab_mouse) { #if not SDL_VERSION_ATLEAST(2,0,0) int warp_x = display.width/2; int warp_y = display.height/2; //this is an even we generated by warping the mouse below if(e->x == warp_x && e->y == warp_y) return; SDL_WarpMouse(warp_x, warp_y); #endif } bool rightmouse = cursor.rightButtonPressed(); //move camera in direction the user dragged the mouse if(mousedragged || rightmouse) { vec2 mag( e->xrel, e->yrel ); //if right mouse button is held while dragging, rotate tree instead of //moving camera if(rightmouse) { manual_rotate = true; if(fabs(mag.x) > fabs(mag.y)) { rotate_angle = std::min(1.0f, (float) fabs(mag.x) / 10.0f) * 5.0f * DEGREES_TO_RADIANS; if(mag.x < 0.0f) rotate_angle = -rotate_angle; } else { rotate_angle = std::min(1.0f, (float) fabs(mag.y) / 10.0f) * 5.0f * DEGREES_TO_RADIANS; if(mag.y < 0.0f) rotate_angle = -rotate_angle; } return; } cursor_move += mag; return; } if(grab_mouse) return; mousepos = vec2(e->x, e->y); mousemoved=true; cursor.updatePos(mousepos); float pos; if(!gGourceSettings.hide_progress && slider.mouseOver(mousepos, &pos)) { std::string date = dateAtPosition(pos); slider.setCaption(date); } } void Gource::zoom(bool zoomin) { manual_zoom = true; float zoom_multi = 1.1; float distance = -camera.getDest().z; if(zoomin) { distance /= zoom_multi; if(distance < gGourceSettings.camera_zoom_min) distance = gGourceSettings.camera_zoom_min; } else { distance *= zoom_multi; if(distance > gGourceSettings.camera_zoom_max) distance = gGourceSettings.camera_zoom_max; } camera.setDistance(distance); } #if SDL_VERSION_ATLEAST(2,0,0) void Gource::mouseWheel(SDL_MouseWheelEvent *e) { if(gGourceSettings.disable_input) return; if(e->y > 0) { zoom(true); } if(e->y < 0) { zoom(false); } } #endif void Gource::mouseClick(SDL_MouseButtonEvent *e) { if(commitlog==0) return; if(gGourceSettings.disable_input) return; if(gGourceSettings.hide_mouse) return; //mouse click should stop the cursor being idle cursor.updatePos(mousepos); if(e->type == SDL_MOUSEBUTTONUP) { if(e->button == SDL_BUTTON_LEFT) { //stop dragging mouse, return the mouse to where //the user started dragging. mousedragged=false; } if(e->button == SDL_BUTTON_LEFT || e->button == SDL_BUTTON_RIGHT) { if(!cursor.buttonPressed()) { grabMouse(false); } } } if(e->type != SDL_MOUSEBUTTONDOWN) return; #if not SDL_VERSION_ATLEAST(2,0,0) //wheel up if(e->button == SDL_BUTTON_WHEELUP) { zoom(true); return; } //wheel down if(e->button == SDL_BUTTON_WHEELDOWN) { zoom(false); return; } #endif if(e->button == SDL_BUTTON_MIDDLE) { toggleCameraMode(); return; } if(e->button == SDL_BUTTON_RIGHT) { grabMouse(true); return; } if(e->button == SDL_BUTTON_LEFT) { //mousepos = vec2(e->x, e->y); mouseclicked=true; if(canSeek()) { float position; if(slider.click(mousepos, &position)) { seekTo(position); } } } } void Gource::showSplash() { splash = 15.0; } void Gource::setFrameExporter(FrameExporter* exporter, int video_framerate) { int gource_framerate = video_framerate; this->framecount = 0; this->frameskip = 0; //calculate appropriate tick rate for video frame rate while(gource_framerate<60) { gource_framerate += video_framerate; this->frameskip++; } this->max_tick_rate = 1.0f / ((float) gource_framerate); this->frameExporter = exporter; } void Gource::setCameraMode(const std::string& mode) { setCameraMode(mode == "track"); } void Gource::setCameraMode(bool track_users) { manual_rotate = false; manual_zoom = false; this->track_users = track_users; if(selectedUser!=0) camera.lockOn(track_users); manual_camera = false; gGourceSettings.camera_mode = track_users ? "track" : "overview"; } void Gource::toggleCameraMode() { setCameraMode(!track_users); } //trace click of mouse on background void Gource::selectBackground() { //is the left mouse button down? if(!cursor.leftButtonPressed()) return; selectUser(0); manual_camera = true; mousedragged=true; grabMouse(true); } //select a user, deselect current file/user void Gource::selectUser(RUser* user) { //already selected do nothing if(user!=0 && selectedUser==user) return; if(selectedFile != 0) { selectedFile->setSelected(false); selectedFile = 0; } // deselect current user if(selectedUser != 0) { selectedUser->setSelected(false); selectedUser = 0; } //if no user return if(user == 0) { camera.lockOn(false); return; } selectedUser = user; //select user, lock on camera selectedUser->setSelected(true); if(track_users) camera.lockOn(true); } //select a file, deselect current file/user void Gource::selectFile(RFile* file) { //already selected do nothing if(file!=0 && selectedFile==file) return; if(selectedUser != 0) { selectedUser->setSelected(false); selectedUser = 0; } // deselect current file if(selectedFile != 0) { selectedFile->setSelected(false); selectedFile = 0; } //if no file return if(file == 0) { return; } selectedFile = file; //select user, lock on camera selectedFile->setSelected(true); } void Gource::selectNextUser() { //debugLog("selectNextUser()\n"); int currTagId = -1; if(selectedUser != 0) { currTagId = selectedUser->getTagID(); } RUser* newSelectedUser = 0; // find next user after this user for(std::map::iterator it = tagusermap.begin(); it != tagusermap.end(); it++) { RUser* user = it->second; if(!user->isInactive() && user->getTagID() > currTagId && user->getAlpha() >= 1.0) { newSelectedUser = user; break; } } // just get first user if(newSelectedUser == 0) { for(std::map::iterator it = tagusermap.begin(); it != tagusermap.end(); it++) { RUser* user = it->second; if(!user->isInactive() && user->getAlpha() >= 1.0) { newSelectedUser = user; break; } } } selectUser(newSelectedUser); } void Gource::keyPress(SDL_KeyboardEvent *e) { if (gGourceSettings.disable_input) return; if (e->type == SDL_KEYUP) return; if (e->type == SDL_KEYDOWN) { #if SDL_VERSION_ATLEAST(2,0,0) bool key_escape = e->keysym.sym == SDLK_ESCAPE; bool key_tab = e->keysym.sym == SDLK_TAB; bool key_space = e->keysym.sym == SDLK_SPACE; bool key_plus = e->keysym.sym == SDLK_PLUS; bool key_equals = e->keysym.sym == SDLK_EQUALS; bool key_minus = e->keysym.sym == SDLK_MINUS; bool key_leftbracket = e->keysym.sym == SDLK_LEFTBRACKET; bool key_rightbracket = e->keysym.sym == SDLK_RIGHTBRACKET; bool key_comma = e->keysym.sym == SDLK_COMMA; bool key_period = e->keysym.sym == SDLK_PERIOD; bool key_slash = e->keysym.sym == SDLK_SLASH; #else bool key_escape = e->keysym.unicode == SDLK_ESCAPE; bool key_tab = e->keysym.unicode == SDLK_TAB; bool key_space = e->keysym.unicode == SDLK_SPACE; bool key_plus = e->keysym.unicode == SDLK_PLUS; bool key_equals = e->keysym.unicode == SDLK_EQUALS; bool key_minus = e->keysym.unicode == SDLK_MINUS; bool key_leftbracket = e->keysym.unicode == SDLK_LEFTBRACKET; bool key_rightbracket = e->keysym.unicode == SDLK_RIGHTBRACKET; bool key_comma = e->keysym.unicode == SDLK_COMMA; bool key_period = e->keysym.unicode == SDLK_PERIOD; bool key_slash = e->keysym.unicode == SDLK_SLASH; #endif if (key_escape) { quit(); } if(commitlog==0) return; if(e->keysym.sym == SDLK_F12) { take_screenshot = true; } if (e->keysym.sym == SDLK_q) { debug = !debug; } if (e->keysym.sym == SDLK_w) { trace_debug = !trace_debug; } if (e->keysym.sym == SDLK_m) { //toggle mouse visibility unless mouse clicked/pressed/dragged if(!(mousedragged || mouseclicked || cursor.leftButtonPressed() )) { if(!cursor.isHidden()) { cursor.showCursor(false); gGourceSettings.hide_mouse = true; } else { cursor.showCursor(true); gGourceSettings.hide_mouse = false; } } } if (e->keysym.sym == SDLK_n) { idle_time = gGourceSettings.auto_skip_seconds; } if (e->keysym.sym == SDLK_y) { gGourceQuadTreeDebug = !gGourceQuadTreeDebug; } if (e->keysym.sym == SDLK_t) { gGourceSettings.hide_tree = !gGourceSettings.hide_tree; } if (e->keysym.sym == SDLK_g) { gGourceSettings.hide_users = !gGourceSettings.hide_users; } if (e->keysym.sym == SDLK_u) { if(gGourceSettings.hide_usernames && !gGourceSettings.highlight_all_users) { gGourceSettings.hide_usernames = false; gGourceSettings.highlight_all_users = true; } else if (gGourceSettings.highlight_all_users && !gGourceSettings.hide_usernames) { gGourceSettings.hide_usernames = false; gGourceSettings.highlight_all_users = false; } else { gGourceSettings.hide_usernames = true; gGourceSettings.highlight_all_users = false; } } if (e->keysym.sym == SDLK_d) { if(gGourceSettings.hide_dirnames && !gGourceSettings.highlight_dirs) { gGourceSettings.hide_dirnames = false; gGourceSettings.highlight_dirs = true; } else if(gGourceSettings.highlight_dirs && !gGourceSettings.hide_dirnames) { gGourceSettings.hide_dirnames = false; gGourceSettings.highlight_dirs = false; } else { gGourceSettings.hide_dirnames = true; gGourceSettings.highlight_dirs = false; } } if (e->keysym.sym == SDLK_f) { if(gGourceSettings.hide_filenames && !gGourceSettings.file_extensions) { gGourceSettings.hide_filenames = false; } else if(!gGourceSettings.hide_filenames && gGourceSettings.file_extensions) { gGourceSettings.file_extensions = false; gGourceSettings.hide_filenames = true; } else { gGourceSettings.file_extensions = true; gGourceSettings.hide_filenames = false; } } if (e->keysym.sym == SDLK_r) { gGourceSettings.hide_root = !gGourceSettings.hide_root; } if (e->keysym.sym == SDLK_k) { gGourceSettings.show_key = !gGourceSettings.show_key; } if(e->keysym.sym == SDLK_c) { splash = 15.0f; } if (e->keysym.sym == SDLK_v) { toggleCameraMode(); } if (e->keysym.sym == SDLK_p) { if(GLEW_VERSION_2_0 && bloom_shader != 0) { gGourceSettings.ffp = !gGourceSettings.ffp; } } if (e->keysym.sym == SDLK_z) { gGourceGravity = !gGourceGravity; } if (e->keysym.sym == SDLK_s) { recolour=true; } if(key_tab) { selectNextUser(); } if (key_space) { paused = !paused; } if (key_equals || key_plus) { if(gGourceSettings.days_per_second>=1.0) { gGourceSettings.days_per_second = std::min(30.0f, floorf(gGourceSettings.days_per_second) + 1.0f); } else { gGourceSettings.days_per_second = std::min(1.0f, gGourceSettings.days_per_second * 2.0f); } } if (key_minus) { if(gGourceSettings.days_per_second>1.0) { gGourceSettings.days_per_second = std::max(0.0f, floorf(gGourceSettings.days_per_second) - 1.0f); } else { gGourceSettings.days_per_second = std::max(0.0f, gGourceSettings.days_per_second * 0.5f); } } if(e->keysym.sym == SDLK_KP_MINUS) { zoom(true); } if(e->keysym.sym == SDLK_KP_PLUS) { zoom(false); } if(key_leftbracket) { gGourceForceGravity /= 1.1; } if(key_rightbracket) { gGourceForceGravity *= 1.1; } if(key_period) { if(gGourceSettings.time_scale>=1.0) { gGourceSettings.time_scale = std::min(4.0f, floorf(gGourceSettings.time_scale) + 1.0f); } else { gGourceSettings.time_scale = std::min(1.0f, gGourceSettings.time_scale * 2.0f); } } if(key_comma) { if(gGourceSettings.time_scale>1.0) { gGourceSettings.time_scale = std::max(0.0f, floorf(gGourceSettings.time_scale) - 1.0f); } else { gGourceSettings.time_scale = std::max(0.25f, gGourceSettings.time_scale * 0.5f); } } if(key_slash) { gGourceSettings.time_scale = 1.0f; } } } void Gource::reset() { camera.reset(); user_bounds.reset(); active_user_bounds.reset(); dir_bounds.reset(); commitqueue.clear(); tagusermap.clear(); gGourceRemovedFiles.clear(); if(userTree!=0) delete userTree; if(dirNodeTree!=0) delete dirNodeTree; recolour = false; userTree = 0; dirNodeTree = 0; selectedFile = 0; hoverFile = 0; use_selection_bounds = false; selection_bounds.reset(); manual_rotate = false; manual_zoom = false; rotation_remaining_angle = 0.0f; message_timer = 0.0f; cursor_move = vec2(0.0f, 0.0f); selectedUser = 0; hoverUser = 0; manual_camera = false; grab_mouse = false; mouseclicked=false; mousemoved=false; mousedragged = false; commitqueue_max_size = 100; rotate_angle = 0.0f; if(root!=0) delete root; root = new RDirNode(0, "/"); //delete users for(std::map::iterator it = users.begin(); it != users.end(); it++) { delete it->second; } users.clear(); //delete for(std::map::iterator it = files.begin(); it != files.end(); it++) { delete it->second; } for(std::list::iterator it = captions.begin(); it!=captions.end();it++) { delete (*it); } for(std::list::iterator it = active_captions.begin(); it!=active_captions.end();it++) { delete (*it); } files.clear(); captions.clear(); active_captions.clear(); last_percent = 0.0; file_key.clear(); idle_time=0; currtime=0; lasttime=0; subseconds=0.0; tag_seq = 1; commit_seq = 1; } void Gource::deleteFile(RFile* file) { //debugLog("removing file %s\n", file->fullpath.c_str()); root->removeFile(file); if(hoverFile == file) { hoverFile = 0; } if(selectedFile == file) { selectFile(0); } //remove from any users with actions against this file - wrong way around? meh for(std::map::iterator it = users.begin(); it!=users.end(); it++) { RUser* user = it->second; user->fileRemoved(file); } files.erase(file->fullpath); file_key.dec(file); //debugLog("removed file %s\n", file->fullpath.c_str()); delete file; } RFile* Gource::addFile(const RCommitFile& cf) { //if we already have max files in circulation //we cant add any more if(gGourceSettings.max_files > 0 && files.size() >= gGourceSettings.max_files) return 0; //see if this is a directory std::string file_as_dir = cf.filename; if(file_as_dir[file_as_dir.size()-1] != '/') file_as_dir.append("/"); if(root->isDir(file_as_dir)) return 0; int tagid = tag_seq++; RFile* file = new RFile(cf.filename, cf.colour, vec2(0.0,0.0), tagid); files[cf.filename] = file; root->addFile(file); file_key.inc(file); while(root->getParent() != 0) { debugLog("parent changed to %s", root->getPath().c_str()); root = root->getParent(); } return file; } RUser* Gource::addUser(const std::string& username) { vec2 pos; if(dir_bounds.area() > 0) { pos = dir_bounds.centre(); } else { pos = vec2(0,0); } int tagid = tag_seq++; RUser* user = new RUser(username, pos, tagid); users[username] = user; tagusermap[tagid] = user; //debugLog("added user %s, tagid = %d\n", username.c_str(), tagid); return user; } void Gource::deleteUser(RUser* user) { if(hoverUser == user) { hoverUser = 0; } if(selectedUser == user) { selectUser(0); } users.erase(user->getName()); tagusermap.erase(user->getTagID()); //debugLog("deleted user %s, tagid = %d\n", user->getName().c_str(), user->getTagID()); delete user; } bool Gource::canSeek() { if(gGourceSettings.hide_progress || commitlog == 0 || !commitlog->isSeekable()) return false; return true; } void Gource::seekTo(float percent) { //debugLog("seekTo(%.2f)\n", percent); if(commitlog == 0 || !commitlog->isSeekable()) return; // end pause if(paused) paused = false; reset(); commitlog->seekTo(percent); } Regex caption_regex("^(?:\\xEF\\xBB\\xBF)?([^|]+)\\|(.+)$"); void Gource::loadCaptions() { if(!gGourceSettings.caption_file.size()) return; std::ifstream cf(gGourceSettings.caption_file.c_str()); if(!cf.is_open()) return; std::string line; std::vector matches; time_t last_timestamp = 0; while(std::getline(cf, line)) { ConfFile::trim(line); if(!caption_regex.match(line, &matches)) continue; time_t timestamp; // Allow timestamp to be a string if(matches[0].size() > 1 && matches[0].find("-", 1) != std::string::npos) { if(!SDLAppSettings::parseDateTime(matches[0], timestamp)) continue; } else { timestamp = (time_t) atoll(matches[0].c_str()); if(!timestamp && matches[0] != "0") continue; } std::string caption = RCommitLog::filter_utf8(matches[1]); //ignore older captions if(timestamp < currtime) continue; //ignore out of order captions if(timestamp < last_timestamp) continue; last_timestamp = timestamp; //fprintf(stderr, "%d %s\n", timestamp, matches[1].c_str()); captions.push_back(new RCaption(caption, timestamp, fontcaption)); } //fprintf(stderr, "loaded %d captions\n", captions.size()); } void Gource::readLog() { if(stop_position_reached) return; //debugLog("readLog()\n"); // read commits until either we are ahead of currtime while((commitlog->hasBufferedCommit() || !commitlog->isFinished()) && (commitqueue.empty() || (commitqueue.back().timestamp <= currtime && commitqueue.size() < commitqueue_max_size)) ) { RCommit commit; if(!commitlog->nextCommit(commit)) { if(!commitlog->isSeekable()) { break; } continue; } if(gGourceSettings.stop_timestamp != 0 && commit.timestamp > gGourceSettings.stop_timestamp) { stop_position_reached = true; break; } commitqueue.push_back(commit); } if(first_read && commitqueue.empty()) { throw SDLAppException("no commits found"); } first_read = false; if(!commitlog->isFinished() && commitlog->isSeekable()) { last_percent = commitlog->getPercent(); slider.setPercent(last_percent); } bool is_finished = commitlog->isFinished(); if( // end reached (gGourceSettings.stop_at_end && is_finished) // stop position reached || (gGourceSettings.stop_position > 0.0 && commitlog->isSeekable() && (is_finished || last_percent >= gGourceSettings.stop_position)) ) { stop_position_reached = true; } if((is_finished || stop_position_reached) && gGourceSettings.file_idle_time_at_end > 0.0f) { gGourceSettings.file_idle_time = gGourceSettings.file_idle_time_at_end; } // useful to figure out where we have crashes //debugLog("current date: %s\n", displaydate.c_str()); } void Gource::processCommit(const RCommit& commit, float t) { //find files of this commit or create it for(std::list::const_iterator it = commit.files.begin(); it != commit.files.end(); it++) { const RCommitFile& cf = *it; RFile* file = 0; //is this a directory (ends in slash) //deleting a directory - find directory: then for each file, remove each file if(!cf.filename.empty() && cf.filename[cf.filename.size()-1] == '/') { //ignore unless it is a delete: we cannot 'add' or 'modify' a directory //as its not a physical entity in Gource, only files are. if(cf.action != "D") continue; std::list dirs; root->findDirs(cf.filename, dirs); for(std::list::iterator it = dirs.begin(); it != dirs.end(); it++) { RDirNode* dir = (*it); //fprintf(stderr, "deleting everything under %s because of %s\n", dir->getPath().c_str(), cf.filename.c_str()); //foreach dir files std::list dir_files; dir->getFilesRecursive(dir_files); for(std::list::iterator it = dir_files.begin(); it != dir_files.end(); it++) { RFile* file = *it; addFileAction(commit, cf, file, t); } } continue; } std::map::iterator seen_file = files.find(cf.filename); if(seen_file != files.end()) file = seen_file->second; if(file == 0) { file = addFile(cf); if(!file) continue; } addFileAction(commit, cf, file, t); } } void Gource::addFileAction(const RCommit& commit, const RCommitFile& cf, RFile* file, float t) { //create user if havent yet. do it here to ensure at least one of there files //was added (incase we hit gGourceSettings.max_files) //find user of this commit or create them RUser* user = 0; //see if user already exists std::map::iterator seen_user = users.find(commit.username); if(seen_user != users.end()) user = seen_user->second; if(user == 0) { user = addUser(commit.username); if(gGourceSettings.highlight_all_users) user->setHighlighted(true); else { // set the highlighted flag if name matches a highlighted user for(std::vector::iterator hi = gGourceSettings.highlight_users.begin(); hi != gGourceSettings.highlight_users.end(); hi++) { std::string highlight = *hi; if(!highlight.empty() && user->getName() == highlight) { user->setHighlighted(true); break; } } } } //create action RAction* userAction = 0; commit_seq++; if(cf.action == "D") { userAction = new RemoveAction(user, file, commit.timestamp, t); } else { if(cf.action == "A") { userAction = new CreateAction(user, file, commit.timestamp, t); } else { userAction = new ModifyAction(user, file, commit.timestamp, t, cf.colour); } } user->addAction(userAction); } void Gource::interactUsers() { // update quad tree Bounds2D quadtreebounds = user_bounds; quadtreebounds.min -= vec2(1.0f, 1.0f); quadtreebounds.max += vec2(1.0f, 1.0f); update_user_tree_time = SDL_GetTicks(); if(userTree != 0) delete userTree; int max_depth = 1; //dont use deep quad tree initially when all the nodes are in one place if(dir_bounds.area() > 10000.0) { max_depth = gGourceMaxQuadTreeDepth; } userTree = new QuadTree(quadtreebounds, max_depth, 1); for(std::map::iterator it = users.begin(); it!=users.end(); it++) { RUser* user = it->second; userTree->addItem(user); } //move users - interact with other users and files for(std::map::iterator ait = users.begin(); ait!=users.end(); ait++) { RUser* a = ait->second; UserForceFunctor uff(a); userTree->visitItemsInBounds(a->quadItemBounds, uff); gGourceUserInnerLoops += uff.getLoopCount(); a->applyForceToActions(); } update_user_tree_time = SDL_GetTicks() - update_user_tree_time; } void Gource::updateBounds() { user_bounds.reset(); active_user_bounds.reset(); for(std::map::iterator it = users.begin(); it!=users.end(); it++) { RUser* user = it->second; user->updateQuadItemBounds(); user_bounds.update(user->quadItemBounds); if(!user->isIdle()) { active_user_bounds.update(user->quadItemBounds); } } dir_bounds.reset(); for(std::map::iterator it = gGourceDirMap.begin(); it!=gGourceDirMap.end(); it++) { RDirNode* node = it->second; if(node->isVisible()) { node->updateQuadItemBounds(); dir_bounds.update(node->quadItemBounds); } } } void Gource::updateUsers(float t, float dt) { std::vector inactiveUsers; size_t idle_users = 0; // move users for(std::map::iterator it = users.begin(); it!=users.end(); it++) { RUser* u = it->second; u->logic(t, dt); //deselect user if fading out from inactivity if(u->isFading() && selectedUser == u) { selectUser(0); } if(u->isInactive()) { inactiveUsers.push_back(u); } if(u->isIdle()) { idle_users++; } else { //if nothing is selected, and this user is active and this user is the specified user to follow, select them if(selectedUser == 0 && selectedFile == 0) { for(std::vector::iterator ui = gGourceSettings.follow_users.begin(); ui != gGourceSettings.follow_users.end(); ui++) { std::string follow = *ui; if(follow.size() && u->getName() == follow) { selectUser(u); } } } } } if(users.empty() && stop_position_reached) { appFinished = true; } //nothing is moving so increment idle if(idle_users==users.size()) { idle_time += dt; } else { idle_time = 0; } // delete inactive users for(std::vector::iterator it = inactiveUsers.begin(); it != inactiveUsers.end(); it++) { deleteUser(*it); } } void Gource::interactDirs() { // update quad tree Bounds2D quadtreebounds = dir_bounds; quadtreebounds.min -= vec2(1.0f, 1.0f); quadtreebounds.max += vec2(1.0f, 1.0f); update_dir_tree_time = SDL_GetTicks(); if(dirNodeTree !=0) delete dirNodeTree; int max_depth = 1; //dont use deep quad tree initially when all the nodes are in one place if(dir_bounds.area() > 10000.0) { max_depth = gGourceMaxQuadTreeDepth; } dirNodeTree = new QuadTree(quadtreebounds, max_depth, 1); //apply forces with other directories for(std::map::iterator it = gGourceDirMap.begin(); it!=gGourceDirMap.end(); it++) { RDirNode* node = it->second; if(!node->empty()) { dirNodeTree->addItem(node); } } update_dir_tree_time = SDL_GetTicks() - update_dir_tree_time; } void Gource::updateDirs(float dt) { root->applyForces(*dirNodeTree); root->logic(dt); } void Gource::updateTime(time_t display_time) { if(display_time == 0) { displaydate = ""; return; } //display date char datestr[256]; struct tm* timeinfo = localtime ( &display_time ); strftime(datestr, 256, gGourceSettings.date_format.c_str(), timeinfo); displaydate = datestr; //avoid wobbling by only moving font if change is sufficient int date_offset = (int) fontmedium.getWidth(displaydate) * 0.5; if(abs(date_x_offset - date_offset) > 5) date_x_offset = date_offset; } void Gource::updateCamera(float dt) { //camera tracking bool auto_rotate = !manual_rotate && !gGourceSettings.disable_auto_rotate; if(manual_camera) { if(glm::length2(cursor_move) > 0.0f) { float cam_rate = ( -camera.getPos().z ) / ( 5000.0f ); vec3 cam_pos = camera.getPos(); vec2 cursor_delta = cursor_move * cam_rate * 10.0f; cam_pos.x += cursor_delta.x; cam_pos.y += cursor_delta.y; camera.setPos(cam_pos, true); camera.stop(); auto_rotate = false; cursor_move = vec2(0.0f, 0.0f); } } else { Bounds2D cambounds; if(track_users && (selectedFile !=0 || selectedUser !=0)) { Bounds2D focusbounds; if(selectedUser !=0) focusbounds.update(selectedUser->getPos()); if(selectedFile !=0) focusbounds.update(selectedFile->getAbsolutePos()); cambounds = focusbounds; } else { if(track_users && idle_time==0) cambounds = active_user_bounds; else cambounds = dir_bounds; } camera.adjust(cambounds, !manual_zoom); } camera.logic(dt); //automatically rotate camera if(auto_rotate) { if(rotation_remaining_angle > 0.0f) { //rotation through 90 degrees, speed peaks at half way float angle_rate = std::max(dt, (float) (1.0f - fabs((rotation_remaining_angle / 90.0f) - 0.5) * 2.0f)) * dt; rotate_angle = std::min(rotation_remaining_angle, 90.0f * angle_rate); rotation_remaining_angle -= rotate_angle; rotate_angle *= DEGREES_TO_RADIANS; } else if(!cursor.rightButtonPressed() && dir_bounds.area() > 10000.0f) { float aspect_ratio = display.width / (float) display.height; float bounds_ratio = (aspect_ratio > 1.0f) ? dir_bounds.width() / dir_bounds.height() : dir_bounds.height() / dir_bounds.width(); if(bounds_ratio < 0.67f) { rotation_remaining_angle = 90.0f; } } } else { rotation_remaining_angle = 0.0f; } } //change the string hashing seed and recolour files and users void Gource::changeColours() { gStringHashSeed = (rand() % 10000) + 1; for(std::map::iterator it = users.begin(); it != users.end(); it++) { it->second->colourize(); } for(std::map::iterator it = files.begin(); it != files.end(); it++) { it->second->colourize(); } file_key.colourize(); } void Gource::logic(float t, float dt) { if(gGourceSettings.shutdown && logmill->isFinished()) { appFinished=true; return; } if(message_timer>0.0f) message_timer -= dt; if(splash>0.0f) splash -= dt; //init log file if(commitlog == 0) { if(!logmill->isFinished()) return; commitlog = logmill->getLog(); std::string error = logmill->getError(); if(!commitlog) { if(!error.empty()) { throw SDLAppException(error); } else { if(frameExporter!=0) frameExporter->stop(); SDL_Quit(); SDLAppException exception(""); exception.setShowHelp(true); throw exception; } } if(gGourceSettings.start_position>0.0) { seekTo(gGourceSettings.start_position); } } file_key.logic(dt); slider.logic(dt); bool right = false; bool left = false; bool up = false; bool down = false; #if SDL_VERSION_ATLEAST(2,0,0) const Uint8 *keystate = SDL_GetKeyboardState(0); right = keystate[SDL_SCANCODE_RIGHT]; left = keystate[SDL_SCANCODE_LEFT]; up = keystate[SDL_SCANCODE_UP]; down = keystate[SDL_SCANCODE_DOWN]; #else Uint8 *keystate = SDL_GetKeyState(0); right = keystate[SDLK_RIGHT]; left = keystate[SDLK_LEFT]; up = keystate[SDLK_UP]; down = keystate[SDLK_DOWN]; #endif if(right) { cursor_move.x = 10.0; manual_camera = true; } if(left) { cursor_move.x = -10.0; manual_camera = true; } if(up) { cursor_move.y = -10.0; manual_camera = true; } if(down) { cursor_move.y = 10.0; manual_camera = true; } //apply rotation if(rotate_angle != 0.0f) { float s = sinf(rotate_angle); float c = cosf(rotate_angle); if(manual_rotate) { // rotate around camera position if manual vec2 centre = vec2(camera.getPos()); root->rotate(s, c, centre); for(std::map::iterator it = users.begin(); it!=users.end(); it++) { RUser* user = it->second; vec2 rotated_user_pos = rotate_vec2(user->getPos() - centre, s, c) + centre; user->setPos(rotated_user_pos); } } else { root->rotate(s, c); for(std::map::iterator it = users.begin(); it!=users.end(); it++) { RUser* user = it->second; vec2 rotated_user_pos = rotate_vec2(user->getPos(), s, c); user->setPos(rotated_user_pos); } } rotate_angle = 0.0f; } if(recolour) { changeColours(); recolour = false; } //still want to update camera while paused if(paused) { updateBounds(); interactUsers(); interactDirs(); updateCamera(dt); return; } // get more entries if(commitqueue.empty()) { readLog(); } //loop in attempt to find commits if(gGourceSettings.loop && commitqueue.empty() && commitlog->isSeekable()) { if(idle_time >= gGourceSettings.loop_delay_seconds) { first_read=true; seekTo(0.0); readLog(); } } if(currtime==0 && !commitqueue.empty()) { currtime = lasttime = commitqueue[0].timestamp; subseconds = 0.0; loadCaptions(); } //set current time float time_inc = (dt * 86400.0 * gGourceSettings.days_per_second); int seconds = (int) time_inc; subseconds += time_inc - ((float) seconds); if(subseconds >= 1.0) { currtime += (int) subseconds; subseconds -= (int) subseconds; } currtime += seconds; // delete files for(std::vector::iterator it = gGourceRemovedFiles.begin(); it != gGourceRemovedFiles.end(); it++) { deleteFile(*it); } gGourceRemovedFiles.clear(); //add commits up until the current time while(!commitqueue.empty()) { RCommit commit = commitqueue.front(); //auto skip ahead, unless stop_position_reached if(gGourceSettings.auto_skip_seconds>=0.0 && idle_time >= gGourceSettings.auto_skip_seconds && !stop_position_reached) { currtime = lasttime = commit.timestamp; idle_time = 0.0; } if(commit.timestamp > currtime) break; processCommit(commit, t); if(gGourceSettings.no_time_travel) { if(commit.timestamp > lasttime) { lasttime = commit.timestamp; } } else { // allow for non linear time lines if(lasttime > commit.timestamp) { currtime = commit.timestamp; } lasttime = commit.timestamp; } subseconds = 0.0; commitqueue.pop_front(); } slider.resize(); float caption_height = fontcaption.getMaxHeight(); float caption_start_y = canSeek() ? slider.getBounds().min.y - 35.0f : display.height - fontmedium.getMaxHeight() - 20.0f; if(!gGourceSettings.title.empty()) { caption_start_y = glm::min( caption_start_y, display.height - 20.0f - fontmedium.getMaxHeight() ); } caption_start_y = glm::floor(caption_start_y); if(reloaded) { // reposition active captions float y = caption_start_y; for(RCaption* cap : active_captions) { int caption_offset_x = gGourceSettings.caption_offset; // centre if(caption_offset_x == 0) { caption_offset_x = (display.width / 2) - (fontcaption.getWidth(cap->getCaption()) / 2); } else if(caption_offset_x < 0) { caption_offset_x = display.width + caption_offset_x - fontcaption.getWidth(cap->getCaption()); } cap->setPos(vec2(caption_offset_x, y)); y -= caption_height; } reloaded = false; } while(captions.size() > 0) { RCaption* caption = captions.front(); if(caption->timestamp > currtime) break; float y = caption_start_y; while(1) { bool found = false; for(RCaption* cap : active_captions) { if(cap->getPos().y == y) { found = true; break; } } if(!found) break; y -= caption_height; } int caption_offset_x = gGourceSettings.caption_offset; // centre if(caption_offset_x == 0) { caption_offset_x = (display.width / 2) - (fontcaption.getWidth(caption->getCaption()) / 2); } else if(caption_offset_x < 0) { caption_offset_x = display.width + caption_offset_x - fontcaption.getWidth(caption->getCaption()); } caption->setPos(vec2(caption_offset_x, y)); captions.pop_front(); active_captions.push_back(caption); } for(std::list::iterator it = active_captions.begin(); it!=active_captions.end();) { RCaption* caption = *it; caption->logic(dt); if(caption->isFinished()) { it = active_captions.erase(it); delete caption; continue; } it++; } //reset loop counters gGourceUserInnerLoops = 0; gGourceDirNodeInnerLoops = 0; gGourceFileInnerLoops = 0; updateBounds(); interactUsers(); updateUsers(t, dt); interactDirs(); updateDirs(dt); updateCamera(dt); updateTime(!commitqueue.empty() ? currtime : lasttime); } void Gource::mousetrace(float dt) { vec3 cam_pos = camera.getPos(); vec2 projected_mouse = vec2( -(mousepos.x * 2.0f - ((float)display.width)) / ((float)display.height), (1.0f - (2.0f * mousepos.y) / ((float)display.height))) * cam_pos.z; projected_mouse.x += cam_pos.x; projected_mouse.y += cam_pos.y; //find user/file under mouse RFile* fileSelection = 0; RUser* userSelection = 0; if(!gGourceSettings.hide_users) { std::set userset; userTree->getItemsAt(userset, projected_mouse); for(std::set::iterator it = userset.begin(); it != userset.end(); it++) { RUser* user = (RUser*) *it; if(!user->isFading() && user->quadItemBounds.contains(projected_mouse)) { userSelection = user; break; } } } if(!userSelection && !gGourceSettings.hide_files) { std::set dirset; dirNodeTree->getItemsAt(dirset, projected_mouse); for(std::set::iterator it = dirset.begin(); it != dirset.end(); it++) { RDirNode* dir = (RDirNode*) *it; const std::list* files = dir->getFiles(); for(std::list::const_iterator fi = files->begin(); fi != files->end(); fi++) { RFile* file = *fi; if(!file->isHidden() && file->overlaps(projected_mouse)) { fileSelection = file; break; } } } } // is over a file if(fileSelection != 0) { // un hover a user if(hoverUser != 0) { hoverUser->setMouseOver(false); hoverUser = 0; } if(fileSelection != hoverFile) { //deselect previous selection if(hoverFile !=0) hoverFile->setMouseOver(false); //select new fileSelection->setMouseOver(true); hoverFile = fileSelection; } // is over a user } else if(userSelection != 0) { // un hover a file if(hoverFile != 0) { hoverFile->setMouseOver(false); hoverFile = 0; } if(userSelection != hoverUser) { //deselect previous selection if(hoverUser !=0) hoverUser->setMouseOver(false); //select new userSelection->setMouseOver(true); hoverUser = userSelection; } } else { if(hoverFile!=0) hoverFile->setMouseOver(false); if(hoverUser!=0) hoverUser->setMouseOver(false); hoverFile=0; hoverUser=0; } if(mouseclicked) { if(hoverUser!=0) { camera.lockOn(false); selectUser(hoverUser); } else if(hoverFile!=0) { camera.lockOn(false); selectFile(hoverFile); } else { selectBackground(); } } //fprintf(stderr, "end trace\n"); } void Gource::loadingScreen() { if(!gGourceDrawBackground) return; display.mode2D(); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glEnable(GL_TEXTURE_2D); glColor4f(1.0, 1.0, 1.0, 1.0); const char* progress = ""; switch(int(runtime*3.0f)%4) { case 0: progress = ""; break; case 1: progress = "."; break; case 2: progress = ".."; break; case 3: progress = "..."; break; } const char* action = !gGourceSettings.shutdown ? "Reading Log" : "Aborting"; int width = font.getWidth(action); font.setColour(vec4(1.0f)); font.print(display.width/2 - width/2, display.height/2 - 10, "%s%s", action, progress); } void Gource::drawBackground(float dt) { if(!gGourceDrawBackground) return; display.setClearColour(vec4(gGourceSettings.background_colour, gGourceSettings.transparent ? 0.0f : 1.0f)); display.clear(); if(backgroundtex!=0) { glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glEnable(GL_TEXTURE_2D); glColor4f(1.0, 1.0, 1.0, 1.0); glBindTexture(GL_TEXTURE_2D, backgroundtex->textureid); glPushMatrix(); glTranslatef(display.width/2 - backgroundtex->w/2, display.height/2 - backgroundtex->h/2, 0.0f); glBegin(GL_QUADS); glTexCoord2f(0.0f,0.0f); glVertex2i(0, 0); glTexCoord2f(1.0f,0.0f); glVertex2i(backgroundtex->w, 0); glTexCoord2f(1.0f,1.0f); glVertex2i(backgroundtex->w, backgroundtex->h); glTexCoord2f(0.0f,1.0f); glVertex2i(0, backgroundtex->h); glEnd(); glPopMatrix(); } } void Gource::drawScene(float dt) { //draw edges draw_edges_time = SDL_GetTicks(); updateAndDrawEdges(); draw_edges_time = SDL_GetTicks() - draw_edges_time; //draw file shadows draw_shadows_time = SDL_GetTicks(); drawFileShadows(dt); draw_shadows_time = SDL_GetTicks() - draw_shadows_time; //draw actions draw_actions_time = SDL_GetTicks(); drawActions(dt); draw_actions_time = SDL_GetTicks() - draw_actions_time; //draw files draw_files_time = SDL_GetTicks(); drawFiles(dt); draw_files_time = SDL_GetTicks() - draw_files_time; //draw users draw_users_time = SDL_GetTicks(); drawUserShadows(dt); drawUsers(dt); draw_users_time = SDL_GetTicks() - draw_users_time; //draw bloom draw_bloom_time = SDL_GetTicks(); drawBloom(dt); draw_bloom_time = SDL_GetTicks() - draw_bloom_time; } void Gource::updateAndDrawEdges() { root->calcEdges(); if(gGourceSettings.hide_tree) return; //switch to 2d glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0, display.width, display.height, 0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glEnable(GL_BLEND); glEnable(GL_TEXTURE_2D); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBindTexture(GL_TEXTURE_2D, beamtex->textureid); if(!gGourceSettings.ffp) { edge_vbo.reset(); root->updateEdgeVBO(edge_vbo); edge_vbo.update(); shadow_shader->setSampler2D("tex", 0); shadow_shader->setFloat("shadow_strength", 0.5); shadow_shader->use(); vec2 shadow_offset = vec2(2.0, 2.0); glPushMatrix(); glTranslatef(shadow_offset.x, shadow_offset.y, 0.0f); edge_vbo.draw(); glPopMatrix(); glUseProgramObjectARB(0); edge_vbo.draw(); } else { root->drawEdgeShadows(); root->drawEdges(); } //switch back glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); } void Gource::drawActions(float dt) { if(gGourceSettings.hide_users) return; glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, beamtex->textureid); glEnable(GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if(!gGourceSettings.ffp) { action_vbo.draw(); } else { //draw actions for(std::map::iterator it = users.begin(); it!=users.end(); it++) { it->second->drawActions(dt); } } } void Gource::drawBloom(float dt) { if(gGourceSettings.hide_bloom) return; glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc (GL_ONE, GL_ONE); if(!gGourceSettings.ffp) { bloom_shader->use(); bloom_vbo.draw(); glUseProgramObjectARB(0); } else { //draw 'gourceian blur' around dirnodes glBindTexture(GL_TEXTURE_2D, bloomtex->textureid); root->drawBloom(dt); } } void Gource::setMessage(const char* str, ...) { char msgbuff[1024]; va_list vl; va_start(vl, str); vsnprintf(msgbuff, 1024, str, vl); va_end(vl); message = std::string(msgbuff); message_timer = 5.0; } void Gource::screenshot() { //get next free recording name char pngname[256]; struct stat finfo; int pngno = 1; while(pngno < 10000) { snprintf(pngname, 256, "gource-%04d.png", pngno); if(stat(pngname, &finfo) != 0) break; pngno++; } //write png std::string filename(pngname); PNGWriter png(gGourceSettings.transparent ? 4 : 3); png.screenshot(filename); setMessage("Wrote screenshot %s", pngname); } void Gource::updateVBOs(float dt) { if(gGourceSettings.ffp) return; if(!gGourceSettings.hide_users) { user_vbo.reset(); action_vbo.reset(); //use a separate vbo for each user texture for(std::map::iterator it = users.begin(); it!=users.end(); it++) { RUser* user = it->second; float alpha = user->getAlpha(); vec3 col = user->getColour(); vec2 scaled_dims = user->dims; if(gGourceSettings.fixed_user_size) scaled_dims *= (-camera.getPos().z / -starting_z); user_vbo.add(user->graphic->textureid, user->getPos() - scaled_dims*0.5f, scaled_dims, vec4(col.x, col.y, col.z, alpha)); //draw actions user->updateActionsVBO(action_vbo); } user_vbo.update(); action_vbo.update(); } if(!gGourceSettings.hide_bloom) { bloom_vbo.reset(); root->updateBloomVBO(bloom_vbo, dt); bloom_vbo.update(); } if(!gGourceSettings.hide_files) { file_vbo.reset(); root->updateFilesVBO(file_vbo, dt); file_vbo.update(); } } void Gource::drawFileShadows(float dt) { if(gGourceSettings.hide_files) return; glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if(!gGourceSettings.ffp) { shadow_shader->setSampler2D("tex", 0); shadow_shader->setFloat("shadow_strength", 0.5); shadow_shader->use(); glBindTexture(GL_TEXTURE_2D, gGourceSettings.file_graphic->textureid); glPushMatrix(); glTranslatef(2.0f, 2.0f, 0.0f); file_vbo.draw(); glPopMatrix(); glUseProgramObjectARB(0); } else { root->drawShadows(dt); } } void Gource::drawUserShadows(float dt) { if(gGourceSettings.hide_users) return; glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if(!gGourceSettings.ffp) { shadow_shader->setSampler2D("tex", 0); shadow_shader->setFloat("shadow_strength", 0.5); shadow_shader->use(); vec2 shadow_offset = vec2(2.0, 2.0) * gGourceSettings.user_scale; glPushMatrix(); glTranslatef(shadow_offset.x, shadow_offset.y, 0.0f); user_vbo.draw(); glPopMatrix(); glUseProgramObjectARB(0); } else { for(std::map::iterator it = users.begin(); it!=users.end(); it++) { it->second->drawShadow(dt); } } } void Gource::drawFiles(float dt) { if(gGourceSettings.hide_files) return; if(trace_debug) { glDisable(GL_TEXTURE_2D); } else { glEnable(GL_TEXTURE_2D); } glEnable(GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if(!gGourceSettings.ffp) { glBindTexture(GL_TEXTURE_2D, gGourceSettings.file_graphic->textureid); file_vbo.draw(); } else { root->drawFiles(dt); } } void Gource::drawUsers(float dt) { if(gGourceSettings.hide_users) return; if(trace_debug) { glDisable(GL_TEXTURE_2D); } else { glEnable(GL_TEXTURE_2D); } glEnable(GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if(!gGourceSettings.ffp) { user_vbo.draw(); } else { for(std::map::iterator it = users.begin(); it!=users.end(); it++) { it->second->draw(dt); } } } void Gource::draw(float t, float dt) { display.mode2D(); drawBackground(dt); if(!commitlog) { loadingScreen(); return; } Frustum frustum(camera.getPos(), camera.getTarget(), camera.getUp(), camera.getFOV(), camera.getZNear(), camera.getZFar()); trace_time = SDL_GetTicks(); if(!gGourceSettings.hide_mouse && cursor.isVisible()) { mousetrace(dt); } else { if(hoverUser) { hoverUser->setMouseOver(false); hoverUser = 0; } if(hoverFile) { hoverFile->setMouseOver(false); hoverFile = 0; } } trace_time = SDL_GetTicks() - trace_time; glMatrixMode(GL_PROJECTION); glLoadIdentity(); camera.focus(); //check visibility root->checkFrustum(frustum); screen_project_time = SDL_GetTicks(); GLint viewport[4]; GLdouble modelview[16]; GLdouble projection[16]; glGetIntegerv( GL_VIEWPORT, viewport ); glGetDoublev( GL_MODELVIEW_MATRIX, modelview ); glGetDoublev( GL_PROJECTION_MATRIX, projection ); root->calcScreenPos(viewport, modelview, projection); for(std::map::iterator it = users.begin(); it!=users.end(); it++) { it->second->calcScreenPos(viewport, modelview, projection); } //need to calc screen pos of selected file if hiding other //file names if(selectedFile!=0 && gGourceSettings.hide_filenames) { selectedFile->calcScreenPos(viewport, modelview, projection); } screen_project_time = SDL_GetTicks() - screen_project_time; //update file and user vbos update_vbos_time = SDL_GetTicks(); updateVBOs(dt); update_vbos_time = SDL_GetTicks() - update_vbos_time; //draw scene draw_scene_time = SDL_GetTicks(); drawScene(dt); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glEnable(GL_TEXTURE_2D); draw_scene_time = SDL_GetTicks() - draw_scene_time; glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); text_time = text_update_time = SDL_GetTicks(); //switch to 2D, preserve current state display.push2D(); if(!gGourceSettings.ffp) { fontmanager.startBuffer(); } fontdirname.roundCoordinates(false); fontdirname.setColour(vec4(gGourceSettings.dir_colour, 1.0f)); root->drawNames(fontdirname); if(!(gGourceSettings.hide_usernames || gGourceSettings.hide_users)) { for(std::map::iterator it = users.begin(); it!=users.end(); it++) { RUser* user = it->second; if(!user->isSelected()) { user->drawName(); } } } text_update_time = SDL_GetTicks() - text_update_time; text_vbo_commit_time = 0; text_vbo_draw_time = 0; if(!gGourceSettings.ffp) { text_vbo_commit_time = SDL_GetTicks(); fontmanager.commitBuffer(); text_vbo_commit_time = SDL_GetTicks() - text_vbo_commit_time; text_vbo_draw_time = SDL_GetTicks(); text_shader->setSampler2D("tex", 0); text_shader->setFloat("shadow_strength", 0.7); text_shader->setFloat("texel_size", font_texel_size); text_shader->use(); fontmanager.drawBuffer(); glUseProgramObjectARB(0); text_vbo_draw_time = SDL_GetTicks() - text_vbo_draw_time; } //draw selected item names again so they are over the top if(selectedUser !=0) selectedUser->drawName(); if(selectedFile !=0) { selectedFile->drawName(); } //switch back display.pop2D(); text_time = SDL_GetTicks() - text_time; if(debug) { glDisable(GL_TEXTURE_2D); glLineWidth(2.0); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); track_users ? active_user_bounds.draw() : dir_bounds.draw(); } if(gGourceQuadTreeDebug) { glDisable(GL_TEXTURE_2D); glLineWidth(1.0); glColor4f(0.0f, 1.0f, 0.0f, 1.0f); dirNodeTree->outline(); glColor4f(0.0f, 1.0f, 1.0f, 1.0f); userTree->outline(); glColor4f(0.0f, 1.0f, 0.5f, 1.0f); userTree->outlineItems(); } glColor4f(1.0f, 1.0f, 1.0f, 1.0f); display.mode2D(); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glEnable(GL_TEXTURE_2D); vec3 campos = camera.getPos(); if(logotex!=0) { glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glEnable(GL_TEXTURE_2D); glColor4f(1.0, 1.0, 1.0, 1.0); glBindTexture(GL_TEXTURE_2D, logotex->textureid); vec2 logopos = vec2(display.width, display.height) - vec2(logotex->w, logotex->h) - gGourceSettings.logo_offset; glPushMatrix(); glTranslatef(logopos.x, logopos.y, 0.0); glBegin(GL_QUADS); glTexCoord2f(0.0f,0.0f); glVertex2i(0, 0); glTexCoord2f(1.0f,0.0f); glVertex2i(logotex->w, 0); glTexCoord2f(1.0f,1.0f); glVertex2i(logotex->w, logotex->h); glTexCoord2f(0.0f,1.0f); glVertex2i(0, logotex->h); glEnd(); glPopMatrix(); } font.roundCoordinates(true); if(splash>0.0f) { int logowidth = fontlarge.getWidth("Gource"); int logoheight = 100 * gGourceSettings.font_scale; int cwidth = font.getWidth("Software Version Control Visualization"); int awidth = font.getWidth("(C) 2009 Andrew Caudwell"); vec2 corner(display.width/2 - logowidth/2 - 30.0f * gGourceSettings.font_scale, display.height/2 - 40 * gGourceSettings.font_scale); glDisable(GL_TEXTURE_2D); glColor4f(0.0f, 0.5f, 1.0f, splash * 0.015f); glBegin(GL_QUADS); glVertex2f(0.0f, corner.y); glVertex2f(0.0f, corner.y + logoheight); glVertex2f(display.width, corner.y + logoheight); glVertex2f(display.width, corner.y); glEnd(); glEnable(GL_TEXTURE_2D); fontlarge.setColour(vec4(1.0f)); fontlarge.draw(display.width/2 - logowidth/2,display.height/2 - 30 * gGourceSettings.font_scale, "Gource"); font.setColour(vec4(1.0f)); font.draw(display.width/2 - cwidth/2,display.height/2 + 10 * gGourceSettings.font_scale, "Software Version Control Visualization"); font.draw(display.width/2 - awidth/2,display.height/2 + 30 * gGourceSettings.font_scale, "(C) 2009 Andrew Caudwell"); } // text using the specified font goes here fontmedium.setColour(vec4(gGourceSettings.font_colour, 1.0f)); if(!gGourceSettings.hide_date) { fontmedium.draw(display.width/2 - date_x_offset, 20, displaydate); } if(!gGourceSettings.title.empty()) { fontmedium.alignTop(false); fontmedium.draw(10, display.height - 10, gGourceSettings.title); fontmedium.alignTop(true); } for(std::list::iterator it = active_captions.begin(); it!=active_captions.end(); it++) { RCaption* caption = *it; caption->draw(); } //file key file_key.draw(); file_key.setShow(gGourceSettings.show_key); //slider if(canSeek()) { slider.draw(dt); } //text box if(hoverFile && hoverFile != selectedFile) { std::string display_path = hoverFile->path; display_path.erase(0,1); textbox.setText(hoverFile->getName()); if(display_path.size()) textbox.addLine(display_path); textbox.setColour(hoverFile->getColour()); textbox.setPos(mousepos, true); textbox.draw(); } else if(hoverUser && hoverUser != selectedUser) { textbox.setText(hoverUser->getName()); textbox.setColour(hoverUser->getColour()); textbox.setPos(mousepos, true); textbox.draw(); } //debug info if(debug) { font.setColour(vec4(1.0f)); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glEnable(GL_TEXTURE_2D); font.print(1,20, "FPS: %.2f", fps); font.print(1,40,"Days Per Second: %.2f", gGourceSettings.days_per_second); font.print(1,60,"Commit Queue: %d", commitqueue.size()); font.print(1,80,"Users: %d", users.size()); font.print(1,100,"Files: %d", files.size()); font.print(1,120,"Dirs: %d", gGourceDirMap.size()); font.print(1,140,"Log Position: %.4f", commitlog->getPercent()); font.print(1,160,"Camera: (%.2f, %.2f, %.2f)", campos.x, campos.y, campos.z); font.print(1,180,"Gravity: %.2f", gGourceForceGravity); font.print(1,200,"Update Tree: %u ms", update_dir_tree_time); font.print(1,220,"Update VBOs: %u ms", update_vbos_time); font.print(1,240,"Projection: %u ms", screen_project_time); font.print(1,260,"Draw Scene: %u ms", draw_scene_time); font.print(1,280," - Edges: %u ms", draw_edges_time); font.print(1,300," - Shadows: %u ms", draw_shadows_time); font.print(1,320," - Actions: %u ms", draw_actions_time); font.print(1,340," - Files: %u ms", draw_files_time); font.print(1,360," - Users: %u ms", draw_users_time); font.print(1,380," - Bloom: %u ms", draw_bloom_time); font.print(1,400,"Text: %u ms", text_time); font.print(1,420,"- Update: %u ms", text_update_time); font.print(1,440,"- VBO Commit: %u ms", text_vbo_commit_time); font.print(1,460,"- VBO Draw: %u ms", text_vbo_draw_time); font.print(1,480,"Mouse Trace: %u ms", trace_time); font.print(1,500,"Logic Time: %u ms", logic_time); font.print(1,520,"File Inner Loops: %d", gGourceFileInnerLoops); font.print(1,540,"User Inner Loops: %d", gGourceUserInnerLoops); font.print(1,560,"Dir Inner Loops: %d (QTree items = %d, nodes = %d, max node depth = %d)", gGourceDirNodeInnerLoops, dirNodeTree->item_count, dirNodeTree->node_count, dirNodeTree->max_node_depth); font.print(1,580,"Dir Bounds Ratio: %.2f, %.5f", dir_bounds.width() / dir_bounds.height(), rotation_remaining_angle); font.print(1,600,"String Hash Seed: %d", gStringHashSeed); if(!gGourceSettings.ffp) { font.print(1,620,"Text VBO: %d/%d vertices, %d texture changes", fontmanager.font_vbo.vertices(), fontmanager.font_vbo.capacity(), fontmanager.font_vbo.texture_changes()); font.print(1,640,"File VBO: %d/%d vertices, %d texture changes", file_vbo.vertices(), file_vbo.capacity(), file_vbo.texture_changes()); font.print(1,660,"User VBO: %d/%d vertices, %d texture changes", user_vbo.vertices(), user_vbo.capacity(), user_vbo.texture_changes()); font.print(1,680,"Action VBO: %d/%d vertices", action_vbo.vertices(), action_vbo.capacity()); font.print(1,700,"Bloom VBO: %d/%d vertices", bloom_vbo.vertices(), bloom_vbo.capacity()); font.print(1,720,"Edge VBO: %d/%d vertices", edge_vbo.vertices(), edge_vbo.capacity()); } if(selectedUser != 0) { } if(selectedFile != 0) { font.print(1,740,"%s: %d files (%d visible)", selectedFile->getDir()->getPath().c_str(), selectedFile->getDir()->fileCount(), selectedFile->getDir()->visibleFileCount()); } } mousemoved=false; mouseclicked=false; if(take_screenshot) { screenshot(); take_screenshot = false; } if(message_timer > 0.0f) { font.setColour(vec4(1.0f)); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glEnable(GL_TEXTURE_2D); font.draw(1, 3, message); } } ================================================ FILE: src/gource.h ================================================ /* Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef GOURCE_H #define GOURCE_H #include #include #include #include "core/display.h" #include "core/shader.h" #include "core/sdlapp.h" #include "core/fxfont.h" #include "core/bounds.h" #include "core/seeklog.h" #include "core/frustum.h" #include "core/regex.h" #include "core/ppm.h" #include "core/mousecursor.h" #include "gource_settings.h" #include "logmill.h" #include "core/vbo.h" #include "bloom.h" #include "slider.h" #include "textbox.h" #include "action.h" #include "caption.h" #include "file.h" #include "user.h" #include "dirnode.h" #include "zoomcamera.h" #include "key.h" class Gource : public SDLApp { std::string logfile; FrameExporter* frameExporter; RLogMill* logmill; RCommitLog* commitlog; PositionSlider slider; ZoomCamera camera; FileKey file_key; bool debug, trace_debug; bool manual_zoom; bool manual_rotate; bool manual_camera; float rotation_remaining_angle; MouseCursor cursor; bool grab_mouse; bool mousemoved; bool mouseclicked; bool mousedragged; vec2 cursor_move; bool recolour; bool use_selection_bounds; Bounds2D selection_bounds; float rotate_angle; vec2 mousepos; float last_percent; bool stop_position_reached; int tag_seq, commit_seq; GLint mouse_hits; RFile* hoverFile; RFile* selectedFile; RUser* hoverUser; RUser* selectedUser; quadbuf file_vbo; quadbuf user_vbo; quadbuf edge_vbo; quadbuf action_vbo; bloombuf bloom_vbo; GLuint selectionDepth; RDirNode* root; std::string displaydate; int date_x_offset; TextureResource* bloomtex; TextureResource* beamtex; TextureResource* logotex; TextureResource* backgroundtex; TextureResource* usertex; Shader* shadow_shader; Shader* text_shader; Shader* bloom_shader; float font_texel_size; TextBox textbox; FXFont font, fontlarge, fontmedium, fontcaption, fontdirname; bool first_read; bool paused; bool reloaded; bool take_screenshot; float max_tick_rate; int frameskip; int framecount; time_t currtime; time_t lasttime; float runtime; float subseconds; float splash; float idle_time; Uint32 screen_project_time; Uint32 draw_edges_time; Uint32 draw_shadows_time; Uint32 draw_actions_time; Uint32 draw_files_time; Uint32 draw_users_time; Uint32 draw_bloom_time; Uint32 update_vbos_time; Uint32 update_dir_tree_time; Uint32 update_user_tree_time; Uint32 draw_scene_time; Uint32 logic_time; Uint32 trace_time; Uint32 text_time; Uint32 text_update_time; Uint32 text_vbo_commit_time; Uint32 text_vbo_draw_time; bool track_users; Bounds2D dir_bounds; Bounds2D user_bounds; Bounds2D active_user_bounds; int commitqueue_max_size; float starting_z; std::deque commitqueue; std::map users; std::map files; std::map tagusermap; std::list captions; std::list active_captions; QuadTree* dirNodeTree; QuadTree* userTree; std::string message; float message_timer; void setMessage(const char* str, ...); void reset(); RUser* addUser(const std::string& username); RFile* addFile(const RCommitFile& cf); void deleteUser(RUser* user); void deleteFile(RFile* file); void selectBackground(); void selectUser(RUser* user); void selectFile(RFile* file); void selectNextUser(); void loadCaptions(); void readLog(); void logReadingError(const std::string& error); void processCommit(const RCommit& commit, float t); void addFileAction(const RCommit& commit, const RCommitFile& cf, RFile* file, float t); std::string dateAtPosition(float percent); void toggleCameraMode(); void updateCamera(float dt); void updateUsers(float t, float dt); void updateDirs(float dt); void interactUsers(); void interactDirs(); void updateBounds(); void updateTime(time_t display_time); void mousetrace(float dt); bool canSeek(); void seekTo(float percent); void zoom(bool zoomin); void loadingScreen(); void drawBackground(float dt); void drawScene(float dt); void updateVBOs(float dt); void updateAndDrawEdges(); void drawFileShadows(float dt); void drawUserShadows(float dt); void drawActions(float dt); void drawFiles(float dt); void drawUsers(float dt); void drawBloom(float dt); void screenshot(); void changeColours(); void grabMouse(bool grab_mouse); public: Gource(FrameExporter* frameExporter = 0); ~Gource(); static void writeCustomLog(const std::string& logfile, const std::string& output_file); void setCameraMode(const std::string& mode); void setCameraMode(bool track_users); void setFrameExporter(FrameExporter* exporter, int video_framerate); void showSplash(); bool isBusy(); void logic(float t, float dt); void draw(float t, float dt); void init(); void unload(); void reload(); void quit(); void update(float t, float dt); void keyPress(SDL_KeyboardEvent *e); void mouseMove(SDL_MouseMotionEvent *e); void mouseClick(SDL_MouseButtonEvent *e); #if SDL_VERSION_ATLEAST(2,0,0) void mouseWheel(SDL_MouseWheelEvent *e); #endif }; #endif ================================================ FILE: src/gource_settings.cpp ================================================ /* Copyright (C) 2010 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "gource_settings.h" #include "core/sdlapp.h" #include #include #include #include "core/utf8/utf8.h" #include #include "formats/hg.h" #include "formats/git.h" #include "formats/bzr.h" #include "formats/cvs-exp.h" #include "formats/cvs2cl.h" #include "formats/svn.h" #ifndef GOURCE_FONT_FILE #define GOURCE_FONT_FILE "FreeSans.ttf" #endif GourceSettings gGourceSettings; //display help message void GourceSettings::help(bool extended_help) { #ifdef _WIN32 //resize window to fit help message SDLApp::resizeConsole(1040); SDLApp::showConsole(true); #endif printf("Gource v%s\n", GOURCE_VERSION); printf("Usage: gource [options] [path]\n"); printf("\nOptions:\n"); printf(" -h, --help Help\n\n"); printf(" -WIDTHxHEIGHT, --viewport Set viewport size\n"); printf(" -f, --fullscreen Fullscreen\n"); printf(" --screen SCREEN Screen number\n"); printf(" --multi-sampling Enable multi-sampling\n"); #ifndef _WIN32 printf(" --high-dpi Request a high DPI display\n"); #endif printf(" --no-vsync Disable vsync\n\n"); printf(" --start-date 'YYYY-MM-DD hh:mm:ss +tz' Start at a date and optional time\n"); printf(" --stop-date 'YYYY-MM-DD hh:mm:ss +tz' Stop at a date and optional time\n\n"); printf(" -p, --start-position POSITION Start at some position (0.0-1.0 or 'random')\n"); printf(" --stop-position POSITION Stop at some position\n"); printf(" -t, --stop-at-time SECONDS Stop after a specified number of seconds\n"); printf(" --stop-at-end Stop at end of the log\n"); printf(" --dont-stop Keep running after the end of the log\n"); printf(" --loop Loop at the end of the log\n\n"); printf(" -a, --auto-skip-seconds SECONDS Auto skip to next entry if nothing happens\n"); printf(" for a number of seconds (default: 3)\n"); printf(" --disable-auto-skip Disable auto skip\n"); printf(" -s, --seconds-per-day SECONDS Speed in seconds per day (default: 10)\n"); printf(" --realtime Realtime playback speed\n"); printf(" --no-time-travel Use the time of the last commit if the\n"); printf(" time of a commit is in the past\n"); printf(" --author-time Use the timestamp of the author instead of\n"); printf(" the timestamp of the committer\n"); printf(" -c, --time-scale SCALE Change simulation time scale (default: 1.0)\n"); printf(" -e, --elasticity FLOAT Elasticity of nodes (default: 0.0)\n\n"); printf(" --key Show file extension key\n\n"); printf(" --user-image-dir DIRECTORY Dir containing images to use as avatars\n"); printf(" --default-user-image IMAGE Default user image file\n"); printf(" --fixed-user-size Use a fixed size throughout\n"); printf(" --colour-images Colourize user images\n\n"); printf(" -i, --file-idle-time SECONDS Time files remain idle (default: 0)\n"); printf(" --file-idle-time-at-end SECONDS Time files remain idle at end (default: 0)\n\n"); printf(" --max-files NUMBER Max number of files or 0 for no limit\n"); printf(" --max-file-lag SECONDS Max time files of a commit can take to appear\n\n"); printf(" --log-command VCS Show the VCS log command (git,svn,hg,bzr,cvs2cl)\n"); printf(" --log-format VCS Specify the log format (git,svn,hg,bzr,cvs2cl,custom)\n\n"); printf(" --load-config CONF_FILE Load a config file\n"); printf(" --save-config CONF_FILE Save a config file with the current options\n\n"); printf(" -o, --output-ppm-stream FILE Output PPM stream to a file ('-' for STDOUT)\n"); printf(" -r, --output-framerate FPS Framerate of output (25,30,60)\n\n"); if(extended_help) { printf("Extended Options:\n\n"); printf(" --window-position XxY Initial window position\n"); printf(" --frameless Frameless window\n\n"); printf(" --output-custom-log FILE Output a custom format log file ('-' for STDOUT).\n\n"); printf(" -b, --background-colour FFFFFF Background colour in hex\n"); printf(" --background-image IMAGE Set a background image\n\n"); printf(" --bloom-multiplier Adjust the amount of bloom (default: 1.0)\n"); printf(" --bloom-intensity Adjust the intensity of the bloom (default: 0.75)\n\n"); printf(" --camera-mode MODE Camera mode (overview,track)\n"); printf(" --crop AXIS Crop view on an axis (vertical,horizontal)\n"); printf(" --padding FLOAT Camera view padding (default: 1.1)\n\n"); printf(" --disable-auto-rotate Disable automatic camera rotation\n\n"); printf(" --disable-input Disable keyboard and mouse input\n\n"); printf(" --date-format FORMAT Specify display date string (strftime format)\n\n"); printf(" --font-file FILE Specify the font\n"); printf(" --font-scale SCALE Scale the size of all fonts\n"); printf(" --font-size SIZE Font size used by date and title\n"); printf(" --file-font-size SIZE Font size for filenames\n"); printf(" --dir-font-size SIZE Font size for directory names\n"); printf(" --user-font-size SIZE Font size for user names\n"); printf(" --font-colour FFFFFF Font colour used by date and title in hex\n\n"); printf(" --file-extensions Show filename extensions only\n"); printf(" --file-extension-fallback Use filename as extension if the extension\n"); printf(" is missing or empty\n\n"); printf(" --git-branch Get the git log of a particular branch\n\n"); printf(" --hide DISPLAY_ELEMENT bloom,date,dirnames,files,filenames,mouse,progress,\n"); printf(" root,tree,users,usernames\n\n"); printf(" --logo IMAGE Logo to display in the foreground\n"); printf(" --logo-offset XxY Offset position of the logo\n\n"); printf(" --loop-delay-seconds SECONDS Seconds to delay before looping (default: 3)\n\n"); printf(" --title TITLE Set a title\n\n"); printf(" --transparent Make the background transparent\n\n"); printf(" --user-filter REGEX Ignore usernames matching this regex\n"); printf(" --user-show-filter REGEX Show only usernames matching this regex\n\n"); printf(" --file-filter REGEX Ignore file paths matching this regex\n"); printf(" --file-show-filter REGEX Show only file paths matching this regex\n\n"); printf(" --user-friction SECONDS Change the rate users slow down (default: 0.67)\n"); printf(" --user-scale SCALE Change scale of users (default: 1.0)\n"); printf(" --max-user-speed UNITS Speed users can travel per second (default: 500)\n\n"); printf(" --follow-user USER Camera will automatically follow this user\n"); printf(" --highlight-dirs Highlight the names of all directories\n"); printf(" --highlight-user USER Highlight the names of a particular user\n"); printf(" --highlight-users Highlight the names of all users\n\n"); printf(" --highlight-colour Font colour for highlighted users in hex.\n"); printf(" --selection-colour Font colour for selected users and files.\n"); printf(" --filename-colour Font colour for filenames.\n"); printf(" --dir-colour Font colour for directories.\n\n"); printf(" --dir-name-depth DEPTH Draw names of directories down to a specific depth.\n"); printf(" --dir-name-position FLOAT Position along edge of the directory name\n"); printf(" (between 0.0 and 1.0, default is 0.5).\n\n"); printf(" --filename-time SECONDS Duration to keep filenames on screen (default: 4.0)\n\n"); printf(" --caption-file FILE Caption file\n"); printf(" --caption-size SIZE Caption font size\n"); printf(" --caption-colour FFFFFF Caption colour in hex\n"); printf(" --caption-duration SECONDS Caption duration (default: 10.0)\n"); printf(" --caption-offset X Caption horizontal offset\n\n"); printf(" --hash-seed SEED Change the seed of hash function.\n\n"); printf(" --path PATH\n\n"); } printf("PATH may be a supported version control directory, a log file, a gource config\n"); printf("file, or '-' to read STDIN. If omitted, gource will attempt to generate a log\n"); printf("from the current directory.\n\n"); if(!extended_help) { printf("To see the full command line options use '-H'\n\n"); } #ifdef _WIN32 if(!SDLApp::existing_console) { printf("Press Enter\n"); getchar(); } #endif exit(0); } GourceSettings::GourceSettings() { repo_count = 0; file_graphic = 0; log_level = LOG_LEVEL_OFF; shutdown = false; setGourceDefaults(); default_section_name = "gource"; //translate args arg_aliases["p"] = "start-position"; arg_aliases["a"] = "auto-skip-seconds"; arg_aliases["s"] = "seconds-per-day"; arg_aliases["t"] = "stop-at-time"; arg_aliases["i"] = "file-idle-time"; arg_aliases["e"] = "elasticity"; arg_aliases["h"] = "help"; arg_aliases["?"] = "help"; arg_aliases["H"] = "extended-help"; arg_aliases["b"] = "background-colour"; arg_aliases["c"] = "time-scale"; arg_aliases["background"] = "background-colour"; arg_aliases["disable-bloom"] = "hide-bloom"; arg_aliases["disable-progress"] = "hide-progress"; arg_aliases["highlight-all-users"] = "highlight-users"; //command line only options conf_sections["help"] = "command-line"; conf_sections["extended-help"] = "command-line"; conf_sections["log-command"] = "command-line"; conf_sections["git-log-command"] = "command-line"; conf_sections["cvs-exp-command"] = "command-line"; conf_sections["cvs2cl-command"] = "command-line"; conf_sections["hg-log-command"] = "command-line"; conf_sections["bzr-log-command"] = "command-line"; conf_sections["svn-log-command"] = "command-line"; conf_sections["load-config"] = "command-line"; conf_sections["save-config"] = "command-line"; conf_sections["output-custom-log"] = "command-line"; conf_sections["log-level"] = "command-line"; //boolean args arg_types["help"] = "bool"; arg_types["extended-help"] = "bool"; arg_types["stop-on-idle"] = "bool"; arg_types["stop-at-end"] = "bool"; arg_types["dont-stop"] = "bool"; arg_types["loop"] = "bool"; arg_types["realtime"] = "bool"; arg_types["no-time-travel"] = "bool"; arg_types["colour-images"] = "bool"; arg_types["hide-date"] = "bool"; arg_types["hide-files"] = "bool"; arg_types["hide-users"] = "bool"; arg_types["hide-tree"] = "bool"; arg_types["hide-usernames"] = "bool"; arg_types["hide-filenames"] = "bool"; arg_types["hide-dirnames"] = "bool"; arg_types["hide-progress"] = "bool"; arg_types["hide-bloom"] = "bool"; arg_types["hide-mouse"] = "bool"; arg_types["hide-root"] = "bool"; arg_types["highlight-users"] = "bool"; arg_types["highlight-dirs"] = "bool"; arg_types["file-extensions"] = "bool"; arg_types["file-extension-fallback"] = "bool"; arg_types["fixed-user-size"] = "bool"; arg_types["author-time"] = "bool"; arg_types["key"] = "bool"; arg_types["ffp"] = "bool"; arg_types["disable-auto-rotate"] = "bool"; arg_types["disable-auto-skip"] = "bool"; arg_types["disable-input"] = "bool"; arg_types["git-log-command"]= "bool"; arg_types["cvs-exp-command"]= "bool"; arg_types["cvs2cl-command"] = "bool"; arg_types["svn-log-command"]= "bool"; arg_types["hg-log-command"] = "bool"; arg_types["bzr-log-command"]= "bool"; arg_types["bloom-intensity"] = "float"; arg_types["bloom-multiplier"] = "float"; arg_types["elasticity"] = "float"; arg_types["seconds-per-day"] = "float"; arg_types["auto-skip-seconds"] = "float"; arg_types["stop-at-time"] = "float"; arg_types["max-user-speed"] = "float"; arg_types["user-friction"] = "float"; arg_types["padding"] = "float"; arg_types["time-scale"] = "float"; arg_types["dir-name-position"] = "float"; arg_types["loop-delay-seconds"] = "float"; arg_types["max-files"] = "int"; arg_types["font-size"] = "int"; arg_types["font-scale"] = "float"; arg_types["file-font-size"] = "int"; arg_types["dir-font-size"] = "int"; arg_types["user-font-size"] = "int"; arg_types["hash-seed"] = "int"; arg_types["user-filter"] = "multi-value"; arg_types["user-show-filter"] = "multi-value"; arg_types["file-filter"] = "multi-value"; arg_types["file-show-filter"] = "multi-value"; arg_types["follow-user"] = "multi-value"; arg_types["highlight-user"] = "multi-value"; arg_types["log-level"] = "string"; arg_types["background-image"] = "string"; arg_types["logo"] = "string"; arg_types["logo-offset"] = "string"; arg_types["log-command"] = "string"; arg_types["load-config"] = "string"; arg_types["save-config"] = "string"; arg_types["output-custom-log"] = "string"; arg_types["path"] = "string"; arg_types["log-command"] = "string"; arg_types["background-colour"] = "string"; arg_types["file-idle-time"] = "string"; arg_types["file-idle-time-at-end"] = "string"; arg_types["user-image-dir"] = "string"; arg_types["default-user-image"] = "string"; arg_types["date-format"] = "string"; arg_types["log-format"] = "string"; arg_types["git-branch"] = "string"; arg_types["start-position"] = "string"; arg_types["start-date"] = "string"; arg_types["stop-date"] = "string"; arg_types["stop-position"] = "string"; arg_types["crop"] = "string"; arg_types["hide"] = "string"; arg_types["max-file-lag"] = "string"; arg_types["user-scale"] = "string"; arg_types["camera-mode"] = "string"; arg_types["title"] = "string"; arg_types["font-file"] = "string"; arg_types["font-colour"] = "string"; arg_types["highlight-colour"] = "string"; arg_types["selection-colour"] = "string"; arg_types["dir-colour"] = "string"; arg_types["caption-file"] = "string"; arg_types["caption-size"] = "int"; arg_types["caption-duration"] = "float"; arg_types["caption-colour"] = "string"; arg_types["caption-offset"] = "int"; arg_types["filename-colour"] = "string"; arg_types["filename-time"] = "float"; arg_types["dir-name-depth"] = "int"; } void GourceSettings::setGourceDefaults() { path = "."; default_path = true; ffp = false; hide_date = false; hide_users = false; hide_tree = false; hide_files = false; hide_usernames = false; hide_filenames = false; hide_dirnames = false; hide_progress = false; hide_bloom = false; hide_mouse = false; hide_root = false; start_timestamp = 0; start_date = ""; stop_timestamp = 0; stop_date = ""; start_position = 0.0f; stop_position = 0.0f; stop_at_time = -1.0f; stop_on_idle = false; stop_at_end = false; dont_stop = false; no_time_travel = false; fixed_user_size = false; author_time = false; show_key = false; disable_auto_rotate = false; disable_input = false; auto_skip_seconds = 3.0f; days_per_second = 0.1f; // TODO: check this is right file_idle_time = 0.0f; file_idle_time_at_end = 0.0f; time_scale = 1.0f; loop = false; loop_delay_seconds = 3.0f; logo = ""; logo_offset = vec2(20.0f,20.0f); colour_user_images = false; default_user_image = ""; user_image_dir = ""; user_image_map.clear(); camera_zoom_min = 50.0f; camera_zoom_default = 100.0f; camera_zoom_max = 10000.0f; camera_mode = "overview"; padding = 1.1f; crop_vertical = false; crop_horizontal = false; bloom_multiplier = 1.0f; bloom_intensity = 0.75f; background_colour = vec3(0.1f, 0.1f, 0.1f); background_image = ""; title = ""; font_scale = 1.0f; default_font_scale = true; font_file = GOURCE_FONT_FILE; font_size = 16; filename_font_size = 14; dirname_font_size = 14; user_font_size = 14; dir_colour = vec3(1.0f); font_colour = vec3(1.0f); highlight_colour = vec3(1.0f); selection_colour = vec3(1.0, 1.0, 0.3f); dir_name_depth = 0; dir_name_position = 0.5f; elasticity = 0.0f; git_branch = ""; log_format = ""; date_format = "%A, %d %B, %Y %X"; max_files = 0; max_user_speed = 500.0f; max_file_lag = 5.0f; user_idle_time = 3.0f; user_friction = 1.0f; user_scale = 1.0f; follow_users.clear(); highlight_users.clear(); highlight_all_users = false; highlight_dirs = false; caption_file = ""; caption_duration = 10.0f; caption_size = 16; caption_offset = 0; caption_colour = vec3(1.0f, 1.0f, 1.0f); filename_colour = vec3(1.0f, 1.0f, 1.0f); filename_time = 4.0f; gStringHashSeed = 31; //delete file filters for(std::vector::iterator it = file_filters.begin(); it != file_filters.end(); it++) { delete (*it); } file_filters.clear(); //delete file whitelists for(std::vector::iterator it = file_show_filters.begin(); it != file_show_filters.end(); it++) { delete (*it); } file_show_filters.clear(); file_extensions = false; file_extension_fallback = false; //delete user filters for(std::vector::iterator it = user_filters.begin(); it != user_filters.end(); it++) { delete (*it); } user_filters.clear(); //delete user whitelist for(std::vector::iterator it = user_show_filters.begin(); it != user_show_filters.end(); it++) { delete (*it); } user_show_filters.clear(); setScaledFontSizes(); } void GourceSettings::setScaledFontSizes() { scaled_font_size = glm::clamp((int)(font_size * font_scale), 1, 100); scaled_user_font_size = glm::clamp((int)(user_font_size * font_scale), 1, 100); scaled_dirname_font_size = glm::clamp((int)(dirname_font_size * font_scale), 1, 100); scaled_filename_font_size = glm::clamp((int)(filename_font_size * font_scale), 1, 100); } void GourceSettings::commandLineOption(const std::string& name, const std::string& value) { if(name == "help") { help(); } if(name == "extended-help") { help(true); } if(name == "load-config" && value.size() > 0) { load_config = value; return; } if(name == "save-config" && value.size() > 0) { save_config = value; return; } std::string log_command; if(name == "log-command") { log_command = value; } if(name == "git-log-command" || log_command == "git") { SDLAppInfo(GitCommitLog::logCommand()); } if(name == "cvs-exp-command" || log_command == "cvs-exp") { SDLAppInfo(CVSEXPCommitLog::logCommand()); } if(log_command == "cvs") { throw ConfFileException("please use either 'cvs2cl' or 'cvs-exp'", "", 0); } if(name == "cvs2cl-command" || log_command == "cvs2cl") { SDLAppInfo(CVS2CLCommitLog::logCommand()); } if(name == "svn-log-command" || log_command == "svn") { SDLAppInfo(SVNCommitLog::logCommand()); } if(name == "hg-log-command" || log_command == "hg") { SDLAppInfo(MercurialLog::logCommand()); } if(name == "bzr-log-command" || log_command == "bzr") { SDLAppInfo(BazaarLog::logCommand()); } if(name == "output-custom-log" && value.size() > 0) { output_custom_filename = value; return; } if(name == "log-level") { if(value == "warn") { log_level = LOG_LEVEL_WARN; } else if(value == "debug") { log_level = LOG_LEVEL_DEBUG; } else if(value == "info") { log_level = LOG_LEVEL_INFO; } else if(value == "error") { log_level = LOG_LEVEL_ERROR; } else if(value == "pedantic") { log_level = LOG_LEVEL_PEDANTIC; } return; } std::string invalid_error = std::string("invalid ") + name + std::string(" value"); throw ConfFileException(invalid_error, "", 0); } #ifdef __APPLE__ #include #endif void GourceSettings::importGourceSettings(ConfFile& conffile, ConfSection* gource_settings) { setGourceDefaults(); if(gource_settings == 0) gource_settings = conffile.getSection(default_section_name); if(gource_settings == 0) { gource_settings = conffile.addSection("gource"); } ConfEntry* entry = 0; //hide flags std::vector hide_fields; if((entry = gource_settings->getEntry("hide")) != 0) { if(!entry->hasValue()) conffile.missingValueException(entry); std::string hide_string = entry->getString(); size_t sep; while((sep = hide_string.find(",")) != std::string::npos) { if(sep == 0 && hide_string.size()==1) break; if(sep == 0) { hide_string = hide_string.substr(sep+1, hide_string.size()-1); continue; } std::string hide_field = hide_string.substr(0, sep); hide_fields.push_back(hide_field); hide_string = hide_string.substr(sep+1, hide_string.size()-1); } if(hide_string.size() > 0 && hide_string != ",") hide_fields.push_back(hide_string); //validate field list for(std::vector::iterator it = hide_fields.begin(); it != hide_fields.end(); it++) { std::string hide_field = (*it); if( hide_field != "date" && hide_field != "users" && hide_field != "tree" && hide_field != "files" && hide_field != "usernames" && hide_field != "filenames" && hide_field != "dirnames" && hide_field != "bloom" && hide_field != "progress" && hide_field != "mouse" && hide_field != "root") { std::string unknown_hide_option = std::string("unknown option hide ") + hide_field; conffile.entryException(entry, unknown_hide_option); } } } //check hide booleans for(std::map::iterator it = arg_types.begin(); it != arg_types.end(); it++) { if(it->first.find("hide-") == 0 && it->second == "bool") { if(gource_settings->getBool(it->first)) { std::string hide_field = it->first.substr(5, it->first.size()-5); hide_fields.push_back(hide_field); } } } if(hide_fields.size()>0) { for(std::vector::iterator it = hide_fields.begin(); it != hide_fields.end(); it++) { std::string hidestr = (*it); if(hidestr == "date") hide_date = true; else if(hidestr == "users") hide_users = true; else if(hidestr == "tree") hide_tree = true; else if(hidestr == "files") hide_files = true; else if(hidestr == "usernames") hide_usernames = true; else if(hidestr == "filenames") hide_filenames = true; else if(hidestr == "dirnames") hide_dirnames = true; else if(hidestr == "bloom") hide_bloom = true; else if(hidestr == "progress") hide_progress = true; else if(hidestr == "root") hide_root = true; else if(hidestr == "mouse") { hide_mouse = true; hide_progress = true; } } } if((entry = gource_settings->getEntry("date-format")) != 0) { if(!entry->hasValue()) conffile.missingValueException(entry); date_format = entry->getString(); } if(gource_settings->getBool("disable-auto-rotate")) { disable_auto_rotate=true; } if(gource_settings->getBool("disable-auto-skip")) { auto_skip_seconds = -1.0; } if(gource_settings->getBool("disable-input")) { disable_input=true; } if(gource_settings->getBool("loop")) { loop = true; } if((entry = gource_settings->getEntry("loop-delay-seconds")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify loop-delay-seconds (float)"); loop_delay_seconds = entry->getFloat(); if(loop_delay_seconds<=0.0f) { conffile.invalidValueException(entry); } } if((entry = gource_settings->getEntry("git-branch")) != 0) { if(!entry->hasValue()) conffile.missingValueException(entry); Regex branch_regex("^(?!-)[/\\w.,;_=+{}\\[\\]-]+$"); std::string branch = entry->getString(); if(branch_regex.match(branch)) { git_branch = branch; } else { conffile.invalidValueException(entry); } } if(gource_settings->getBool("colour-images")) { colour_user_images = true; } if((entry = gource_settings->getEntry("crop")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify crop (vertical,horizontal)"); std::string crop = entry->getString(); if(crop == "vertical") { crop_vertical = true; } else if (crop == "horizontal") { crop_horizontal = true; } else { conffile.invalidValueException(entry); } } if((entry = gource_settings->getEntry("log-format")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify log-format (format)"); log_format = entry->getString(); if(log_format == "cvs") { conffile.entryException(entry, "please use either 'cvs2cl' or 'cvs-exp'"); } if( log_format != "git" && log_format != "cvs-exp" && log_format != "cvs2cl" && log_format != "svn" && log_format != "custom" && log_format != "hg" && log_format != "bzr" && log_format != "apache") { conffile.invalidValueException(entry); } } if((entry = gource_settings->getEntry("default-user-image")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify default-user-image (image path)"); default_user_image = entry->getString(); } if((entry = gource_settings->getEntry("user-image-dir")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify user-image-dir (directory)"); user_image_dir = entry->getString(); //append slash if(user_image_dir[user_image_dir.size()-1] != '/') { user_image_dir += std::string("/"); } user_image_map.clear(); boost::filesystem::path image_dir_path(user_image_dir); if(!is_directory(image_dir_path)) { conffile.entryException(entry, "specified user-image-dir is not a directory"); } std::vector image_dir_files; try { copy(boost::filesystem::directory_iterator(image_dir_path), boost::filesystem::directory_iterator(), back_inserter(image_dir_files)); } catch(const boost::filesystem::filesystem_error& exception) { conffile.entryException(entry, "error reading specified user-image-dir"); } for(boost::filesystem::path& p : image_dir_files) { std::string dirfile; #ifdef _WIN32 std::wstring dirfile_16 = p.filename().wstring(); utf8::utf16to8(dirfile_16.begin(), dirfile_16.end(), back_inserter(dirfile)); #else dirfile = p.filename().string(); #endif std::string file_ext = p.extension().string(); boost::algorithm::to_lower(file_ext); if(file_ext != ".jpg" && file_ext != ".jpeg" && file_ext != ".png") continue; std::string image_path = gGourceSettings.user_image_dir + dirfile; std::string name = dirfile.substr(0,dirfile.size() - file_ext.size()); #ifdef __APPLE__ CFMutableStringRef help = CFStringCreateMutable(kCFAllocatorDefault, 0); CFStringAppendCString(help, name.c_str(), kCFStringEncodingUTF8); CFStringNormalize(help, kCFStringNormalizationFormC); char data[4096]; CFStringGetCString(help, data, sizeof(data), kCFStringEncodingUTF8); name = data; #endif debugLog("%s => %s", name.c_str(), image_path.c_str()); user_image_map[name] = image_path; } } if((entry = gource_settings->getEntry("caption-file")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify caption file (filename)"); caption_file = entry->getString(); if(!boost::filesystem::exists(caption_file)) { conffile.entryException(entry, "caption file not found"); } } if((entry = gource_settings->getEntry("caption-duration")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify caption duration (seconds)"); caption_duration = entry->getFloat(); if(caption_duration <= 0.0f) { conffile.invalidValueException(entry); } } if((entry = gource_settings->getEntry("caption-size")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify caption size"); caption_size = entry->getInt(); if(caption_size<1 || caption_size>100) { conffile.invalidValueException(entry); } } if((entry = gource_settings->getEntry("caption-offset")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify caption offset"); caption_offset = entry->getInt(); } if((entry = gource_settings->getEntry("caption-colour")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify caption colour (FFFFFF)"); int r,g,b; std::string colstring = entry->getString(); if(entry->isVec3()) { caption_colour = entry->getVec3(); } else if(colstring.size()==6 && sscanf(colstring.c_str(), "%02x%02x%02x", &r, &g, &b) == 3) { caption_colour = vec3(r,g,b); caption_colour /= 255.0f; } else { conffile.invalidValueException(entry); } } if((entry = gource_settings->getEntry("filename-colour")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify filename colour (FFFFFF)"); int r,g,b; std::string colstring = entry->getString(); if(entry->isVec3()) { filename_colour = entry->getVec3(); } else if(colstring.size()==6 && sscanf(colstring.c_str(), "%02x%02x%02x", &r, &g, &b) == 3) { filename_colour = vec3(r,g,b); filename_colour /= 255.0f; } else { conffile.invalidValueException(entry); } } if((entry = gource_settings->getEntry("filename-time")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify duration to keep files on screen (float)"); filename_time = entry->getFloat(); if(filename_time<2.0f) { conffile.entryException(entry, "filename-time must be >= 2.0"); } } if((entry = gource_settings->getEntry("bloom-intensity")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify bloom-intensity (float)"); bloom_intensity = entry->getFloat(); if(bloom_intensity<=0.0f) { conffile.invalidValueException(entry); } } if((entry = gource_settings->getEntry("bloom-multiplier")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify bloom-multiplier (float)"); bloom_multiplier = entry->getFloat(); if(bloom_multiplier<=0.0f) { conffile.invalidValueException(entry); } } if((entry = gource_settings->getEntry("elasticity")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify elasticity (float)"); elasticity = entry->getFloat(); if(elasticity<=0.0f) { conffile.invalidValueException(entry); } } if((entry = gource_settings->getEntry("font-file")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify font file"); font_file = entry->getString(); boost::filesystem::path font_file_path(font_file); if(!boost::filesystem::exists(font_file_path)) { conffile.invalidValueException(entry); } font_file = boost::filesystem::canonical(font_file_path).string(); if(font_file.empty()) { conffile.invalidValueException(entry); } } if((entry = gource_settings->getEntry("font-size")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify font size"); font_size = entry->getInt(); if(font_size<1 || font_size>100) { conffile.invalidValueException(entry); } } if((entry = gource_settings->getEntry("file-font-size")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify font size"); filename_font_size = entry->getInt(); if(filename_font_size<1 || filename_font_size>100) { conffile.invalidValueException(entry); } } if((entry = gource_settings->getEntry("dir-font-size")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify font size"); dirname_font_size = entry->getInt(); if(dirname_font_size<1 || dirname_font_size>100) { conffile.invalidValueException(entry); } } if((entry = gource_settings->getEntry("user-font-size")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify font size"); user_font_size = entry->getInt(); if(user_font_size<1 || user_font_size>100) { conffile.invalidValueException(entry); } } if((entry = gource_settings->getEntry("font-scale")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify font scale"); font_scale = entry->getFloat(); default_font_scale = false; if(font_scale<0.0f || font_scale>10.0f) { conffile.invalidValueException(entry); } setScaledFontSizes(); } if((entry = gource_settings->getEntry("hash-seed")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify hash seed (integer)"); gStringHashSeed = entry->getInt(); } if((entry = gource_settings->getEntry("font-colour")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify font colour (FFFFFF)"); int r,g,b; std::string colstring = entry->getString(); if(entry->isVec3()) { font_colour = entry->getVec3(); } else if(colstring.size()==6 && sscanf(colstring.c_str(), "%02x%02x%02x", &r, &g, &b) == 3) { font_colour = vec3(r,g,b); font_colour /= 255.0f; } else { conffile.invalidValueException(entry); } } if((entry = gource_settings->getEntry("background-colour")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify background colour (FFFFFF)"); int r,g,b; std::string colstring = entry->getString(); if(entry->isVec3()) { background_colour = entry->getVec3(); } else if(colstring.size()==6 && sscanf(colstring.c_str(), "%02x%02x%02x", &r, &g, &b) == 3) { background_colour = vec3(r,g,b); background_colour /= 255.0f; } else { conffile.invalidValueException(entry); } } if((entry = gource_settings->getEntry("highlight-colour")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify highlight colour (FFFFFF)"); int r,g,b; std::string colstring = entry->getString(); if(entry->isVec3()) { highlight_colour = entry->getVec3(); } else if(colstring.size()==6 && sscanf(colstring.c_str(), "%02x%02x%02x", &r, &g, &b) == 3) { highlight_colour = vec3(r,g,b); highlight_colour /= 255.0f; } else { conffile.invalidValueException(entry); } } if((entry = gource_settings->getEntry("selection-colour")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify selection colour (FFFFFF)"); int r,g,b; std::string colstring = entry->getString(); if(entry->isVec3()) { selection_colour = entry->getVec3(); } else if(colstring.size()==6 && sscanf(colstring.c_str(), "%02x%02x%02x", &r, &g, &b) == 3) { selection_colour = vec3(r,g,b); selection_colour /= 255.0f; } else { conffile.invalidValueException(entry); } } if((entry = gource_settings->getEntry("dir-colour")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify dir colour (FFFFFF)"); int r,g,b; std::string colstring = entry->getString(); if(entry->isVec3()) { dir_colour = entry->getVec3(); } else if(colstring.size()==6 && sscanf(colstring.c_str(), "%02x%02x%02x", &r, &g, &b) == 3) { dir_colour = vec3(r,g,b); dir_colour /= 255.0f; } else { conffile.invalidValueException(entry); } } if((entry = gource_settings->getEntry("background-image")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify background image (image path)"); background_image = entry->getString(); } if((entry = gource_settings->getEntry("title")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify title"); title = entry->getString(); } if((entry = gource_settings->getEntry("logo")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify logo (image path)"); logo = entry->getString(); } if((entry = gource_settings->getEntry("logo-offset")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify logo-offset (XxY)"); std::string logo_offset_str = entry->getString(); int posx = 0; int posy = 0; if(parseRectangle(logo_offset_str, posx, posy)) { logo_offset = vec2(posx, posy); } else { conffile.invalidValueException(entry); } } if((entry = gource_settings->getEntry("seconds-per-day")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify seconds-per-day (seconds)"); float seconds_per_day = entry->getFloat(); if(seconds_per_day<=0.0f) { conffile.invalidValueException(entry); } // convert seconds-per-day to days-per-second days_per_second = 1.0 / seconds_per_day; } if((entry = gource_settings->getEntry("auto-skip-seconds")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify auto-skip-seconds (seconds)"); auto_skip_seconds = entry->getFloat(); if(auto_skip_seconds <= 0.0) { conffile.invalidValueException(entry); } } if((entry = gource_settings->getEntry("file-idle-time")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify file-idle-time (seconds)"); std::string file_idle_str = entry->getString(); file_idle_time = (float) atoi(file_idle_str.c_str()); if(file_idle_time<0.0f || (file_idle_time == 0.0f && file_idle_str[0] != '0') ) { conffile.invalidValueException(entry); } } if((entry = gource_settings->getEntry("file-idle-time-at-end")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify file-idle-time-at-end (seconds)"); std::string file_idle_at_end_str = entry->getString(); file_idle_time_at_end = (float) atoi(file_idle_at_end_str.c_str()); if(file_idle_time_at_end<0.0f || (file_idle_time_at_end == 0.0f && file_idle_at_end_str[0] != '0') ) { conffile.invalidValueException(entry); } } if((entry = gource_settings->getEntry("user-idle-time")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify user-idle-time (seconds)"); user_idle_time = entry->getFloat(); if(user_idle_time < 0.0f) { conffile.invalidValueException(entry); } } if((entry = gource_settings->getEntry("time-scale")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify time-scale (scale)"); time_scale = entry->getFloat(); if(time_scale <= 0.0f || time_scale > 4.0f) { conffile.entryException(entry, "time-scale outside of range 0.0 - 4.0"); } } if((entry = gource_settings->getEntry("start-date")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify start-date (YYYY-MM-DD hh:mm:ss)"); std::string start_date_string = entry->getString(); if(parseDateTime(start_date_string, start_timestamp)) { char datestr[256]; strftime(datestr, 256, "%Y-%m-%d", localtime ( &start_timestamp )); start_date = datestr; } else { conffile.invalidValueException(entry); } } if((entry = gource_settings->getEntry("stop-date")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify stop-date (YYYY-MM-DD hh:mm:ss)"); std::string end_date_string = entry->getString(); if(parseDateTime(end_date_string, stop_timestamp)) { struct tm * timeinfo; timeinfo = localtime ( &stop_timestamp ); time_t stop_timestamp_rounded = stop_timestamp; if(timeinfo->tm_hour > 0 || timeinfo->tm_min > 0 || timeinfo->tm_sec > 0) { stop_timestamp_rounded += 60*60*24; } char datestr[256]; strftime(datestr, 256, "%Y-%m-%d", localtime ( &stop_timestamp_rounded )); stop_date = datestr; } else { conffile.invalidValueException(entry); } } if((entry = gource_settings->getEntry("start-position")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify start-position (float,random)"); if(entry->getString() == "random") { srand(time(0)); start_position = (rand() % 1000) / 1000.0f; } else { start_position = entry->getFloat(); if(start_position<=0.0 || start_position>=1.0) { conffile.entryException(entry, "start-position outside of range 0.0 - 1.0 (non-inclusive)"); } } } if((entry = gource_settings->getEntry("stop-position")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify stop-position (float)"); stop_position = entry->getFloat(); if(stop_position<=0.0 || stop_position>1.0) { conffile.entryException(entry, "stop-position outside of range 0.0 - 1.0 (inclusive)"); } } if((entry = gource_settings->getEntry("stop-at-time")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify stop-at-time (seconds)"); stop_at_time = entry->getFloat(); if(stop_at_time <= 0.0) { conffile.invalidValueException(entry); } } if(gource_settings->getBool("key")) { show_key = true; } if(gource_settings->getBool("ffp")) { ffp = true; } if(gource_settings->getBool("realtime")) { days_per_second = 1.0 / 86400.0; } if(gource_settings->getBool("no-time-travel")) { no_time_travel = true; } if(gource_settings->getBool("dont-stop")) { dont_stop = true; } if(gource_settings->getBool("stop-at-end")) { stop_at_end = true; } //NOTE: this no longer does anything if(gource_settings->getBool("stop-on-idle")) { stop_on_idle = true; } if(gource_settings->getBool("fixed-user-size")) { fixed_user_size = true; } if(gource_settings->getBool("author-time")) { author_time = true; } if((entry = gource_settings->getEntry("max-files")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify max-files (number)"); max_files = entry->getInt(); if( max_files<0 || (max_files == 0 && entry->getString() != "0") ) { conffile.invalidValueException(entry); } } if((entry = gource_settings->getEntry("max-file-lag")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify max-file-lag (seconds)"); max_file_lag = entry->getFloat(); if(max_file_lag==0.0) { conffile.invalidValueException(entry); } } if((entry = gource_settings->getEntry("user-friction")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify user-friction (seconds)"); user_friction = entry->getFloat(); if(user_friction<=0.0) { conffile.invalidValueException(entry); } user_friction = 1.0 / user_friction; } if((entry = gource_settings->getEntry("user-scale")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify user-scale (scale)"); user_scale = entry->getFloat(); if(user_scale<=0.0 || user_scale>100.0) { conffile.invalidValueException(entry); } } if((entry = gource_settings->getEntry("max-user-speed")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify max-user-speed (units)"); max_user_speed = entry->getFloat(); if(max_user_speed<=0) { conffile.invalidValueException(entry); } } if( gource_settings->getBool("highlight-users") || gource_settings->getBool("highlight-all-users")) { highlight_all_users = true; } if(gource_settings->getBool("highlight-dirs")) { highlight_dirs = true; } if((entry = gource_settings->getEntry("camera-mode")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify camera-mode (overview,track)"); camera_mode = entry->getString(); if(camera_mode != "overview" && camera_mode != "track") { conffile.invalidValueException(entry); } } if((entry = gource_settings->getEntry("padding")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify padding (float)"); padding = entry->getFloat(); if(padding <= 0.0f || padding >= 2.0f) { conffile.invalidValueException(entry); } } // multi-value entries if((entry = gource_settings->getEntry("highlight-user")) != 0) { ConfEntryList* highlight_user_entries = gource_settings->getEntries("highlight-user"); for(ConfEntryList::iterator it = highlight_user_entries->begin(); it != highlight_user_entries->end(); it++) { entry = *it; if(!entry->hasValue()) conffile.entryException(entry, "specify highlight-user (user)"); highlight_users.push_back(entry->getString()); } } if((entry = gource_settings->getEntry("follow-user")) != 0) { ConfEntryList* follow_user_entries = gource_settings->getEntries("follow-user"); for(ConfEntryList::iterator it = follow_user_entries->begin(); it != follow_user_entries->end(); it++) { entry = *it; if(!entry->hasValue()) conffile.entryException(entry, "specify follow-user (user)"); follow_users.push_back(entry->getString()); } } if(gource_settings->getBool("file-extensions")) { file_extensions=true; } if(gource_settings->getBool("file-extension-fallback")) { file_extension_fallback=true; } if((entry = gource_settings->getEntry("file-filter")) != 0) { ConfEntryList* filters = gource_settings->getEntries("file-filter"); for(ConfEntryList::iterator it = filters->begin(); it != filters->end(); it++) { entry = *it; if(!entry->hasValue()) conffile.entryException(entry, "specify file-filter (regex)"); std::string filter_string = entry->getString(); Regex* r = new Regex(filter_string, 1); if(!r->isValid()) { delete r; conffile.entryException(entry, "invalid file-filter regular expression"); } file_filters.push_back(r); } } if((entry = gource_settings->getEntry("file-show-filter")) != 0) { ConfEntryList* filters = gource_settings->getEntries("file-show-filter"); for(ConfEntryList::iterator it = filters->begin(); it != filters->end(); it++) { entry = *it; if(!entry->hasValue()) conffile.entryException(entry, "specify file-show-filter (regex)"); std::string filter_string = entry->getString(); Regex* r = new Regex(filter_string, 1); if(!r->isValid()) { delete r; conffile.entryException(entry, "invalid file-show-filter regular expression"); } file_show_filters.push_back(r); } } if((entry = gource_settings->getEntry("user-filter")) != 0) { ConfEntryList* filters = gource_settings->getEntries("user-filter"); for(ConfEntryList::iterator it = filters->begin(); it != filters->end(); it++) { entry = *it; if(!entry->hasValue()) conffile.entryException(entry, "specify user-filter (regex)"); std::string filter_string = entry->getString(); Regex* r = new Regex(filter_string, 1); if(!r->isValid()) { delete r; conffile.entryException(entry, "invalid user-filter regular expression"); } user_filters.push_back(r); } } if((entry = gource_settings->getEntry("user-show-filter")) != 0) { ConfEntryList* filters = gource_settings->getEntries("user-show-filter"); for(ConfEntryList::iterator it = filters->begin(); it != filters->end(); it++) { entry = *it; if(!entry->hasValue()) conffile.entryException(entry, "specify user-show-filter (regex)"); std::string filter_string = entry->getString(); Regex* r = new Regex(filter_string, 1); if(!r->isValid()) { delete r; conffile.entryException(entry, "invalid user-show-filter regular expression"); } user_show_filters.push_back(r); } } if((entry = gource_settings->getEntry("dir-name-depth")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify dir-name-depth (depth)"); dir_name_depth = entry->getInt(); if(dir_name_depth <= 0) { conffile.invalidValueException(entry); } } if((entry = gource_settings->getEntry("dir-name-position")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify dir-name-position (float)"); dir_name_position = entry->getFloat(); if(dir_name_position < 0.1f || dir_name_position > 1.0f) { conffile.entryException(entry, "dir-name-position outside of range 0.1 - 1.0 (inclusive)"); } } //validate path if(gource_settings->hasValue("path")) { path = gource_settings->getString("path"); default_path = false; } if(path == "-") { if(log_format.size() == 0) { throw ConfFileException("log-format required when reading from STDIN", "", 0); } #ifdef _WIN32 DWORD available_bytes; HANDLE stdin_handle = GetStdHandle(STD_INPUT_HANDLE); while(PeekNamedPipe(stdin_handle, 0, 0, 0, &available_bytes, 0) && available_bytes==0 && !std::cin.fail()) { SDL_Delay(100); } #else while(std::cin.peek() == EOF && !std::cin.fail()) SDL_Delay(100); #endif std::cin.clear(); } else if(!path.empty() && path != ".") { //remove trailing slash if(path[path.size()-1] == '\\' || path[path.size()-1] == '/') { path.resize(path.size()-1); } // check path exists if(!boost::filesystem::exists(path)) { throw ConfFileException(str(boost::format("'%s' does not appear to be a valid file or directory") % path), "", 0); } } } ================================================ FILE: src/gource_settings.h ================================================ /* Copyright (C) 2010 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef GOURCE_SETTINGS_H #define GOURCE_SETTINGS_H #define GOURCE_VERSION "0.57" #include "core/texture.h" #include "core/settings.h" #include "core/regex.h" class GourceSettings : public SDLAppSettings { protected: void commandLineOption(const std::string& name, const std::string& value); public: int repo_count; bool hide_date; bool hide_users; bool hide_tree; bool hide_files; bool hide_usernames; bool hide_filenames; bool hide_dirnames; bool hide_progress; bool hide_bloom; bool hide_mouse; bool hide_root; bool disable_auto_rotate; bool disable_input; bool show_key; std::string load_config; std::string save_config; std::string path; bool default_path; std::string logo; vec2 logo_offset; std::string start_date; std::string stop_date; time_t start_timestamp; time_t stop_timestamp; float start_position; float stop_position; float stop_at_time; bool shutdown; bool stop_on_idle; bool stop_at_end; bool dont_stop; bool no_time_travel; bool fixed_user_size; bool author_time; float auto_skip_seconds; float days_per_second; float file_idle_time; float file_idle_time_at_end; float loop_delay_seconds; bool loop; bool ffp; bool colour_user_images; std::string default_user_image; std::string user_image_dir; std::map user_image_map; float camera_zoom_min; float camera_zoom_max; float camera_zoom_default; std::string camera_mode; float padding; bool crop_vertical; bool crop_horizontal; float bloom_multiplier; float bloom_intensity; vec3 background_colour; std::string background_image; std::string title; std::string font_file; int font_size; int filename_font_size; int dirname_font_size; int user_font_size; vec3 font_colour; float font_scale; bool default_font_scale; int scaled_font_size; int scaled_filename_font_size; int scaled_dirname_font_size; int scaled_user_font_size; float elasticity; std::string git_branch; std::string log_format; std::string date_format; int max_files; float max_user_speed; float max_file_lag; float user_idle_time; float user_friction; float user_scale; float time_scale; bool highlight_dirs; bool highlight_all_users; vec3 dir_colour; vec3 highlight_colour; vec3 selection_colour; int dir_name_depth; float dir_name_position; std::vector highlight_users; std::vector follow_users; std::vector file_filters; std::vector file_show_filters; std::vector user_filters; std::vector user_show_filters; bool file_extensions; bool file_extension_fallback; std::string caption_file; vec3 caption_colour; float caption_duration; int caption_size; int caption_offset; vec3 filename_colour; float filename_time; std::string output_custom_filename; TextureResource* file_graphic; int log_level; GourceSettings(); void setGourceDefaults(); void setScaledFontSizes(); void importGourceSettings(ConfFile& conf, ConfSection* gource_settings = 0); void help(bool extended_help=false); }; extern GourceSettings gGourceSettings; #endif ================================================ FILE: src/gource_shell.cpp ================================================ /* Copyright (C) 2010 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "gource_shell.h" GourceShell* gGourceShell = 0; // GourceShell GourceShell::GourceShell(ConfFile* conf, FrameExporter* exporter) { this->conf = conf; this->exporter = exporter; min_delta_msec = 16; next = false; gource = 0; gource_settings = conf->getSections("gource")->begin(); gGourceSettings.repo_count = conf->countSection("gource"); toggle_delay = 0.0; transition_texture = 0; transition_interval = 0.0f; if(GLEW_ARB_texture_non_power_of_two || GLEW_VERSION_2_0) { transition_texture = texturemanager.create(display.width, display.height, false, GL_CLAMP_TO_EDGE, GL_RGBA); } } GourceShell::~GourceShell() { if(gource!=0) delete gource; if(transition_texture!=0) texturemanager.release(transition_texture); } void GourceShell::toggleFullscreen() { if(exporter != 0) return; texturemanager.unload(); shadermanager.unload(); fontmanager.unload(); if(gource!=0) gource->unload(); //recreate gl context display.toggleFullscreen(); texturemanager.reload(); shadermanager.reload(); fontmanager.reload(); if(gource!=0) gource->reload(); } void GourceShell::toggleWindowFrame() { #if SDL_VERSION_ATLEAST(2,0,0) if(toggle_delay > 0.0) return; if(display.isFullscreen()) return; if(exporter != 0) return; texturemanager.unload(); shadermanager.unload(); fontmanager.unload(); if(gource!=0) gource->unload(); display.toggleFrameless(); texturemanager.reload(); shadermanager.reload(); fontmanager.reload(); if(gource!=0) gource->reload(); toggle_delay = 0.25f; #endif } void GourceShell::resize(int width, int height) { texturemanager.unload(); shadermanager.unload(); fontmanager.unload(); if(gource!=0) gource->unload(); //recreate gl context display.resize(width, height); texturemanager.reload(); shadermanager.reload(); fontmanager.reload(); if(gource!=0) gource->reload(); } void GourceShell::reload() { texturemanager.unload(); shadermanager.unload(); fontmanager.unload(); if(gource!=0) gource->unload(); texturemanager.reload(); shadermanager.reload(true); fontmanager.reload(); if(gource!=0) gource->reload(); } void GourceShell::keyPress(SDL_KeyboardEvent *e) { bool repeat = false; #if SDL_VERSION_ATLEAST(2,0,0) repeat = (e->repeat > 0); #endif //Quit demo if the user presses ESC if (e->type == SDL_KEYDOWN && !repeat) { #if SDL_VERSION_ATLEAST(2,0,0) bool key_escape = e->keysym.sym == SDLK_ESCAPE; bool key_return = e->keysym.sym == SDLK_RETURN; #else bool key_escape = e->keysym.unicode == SDLK_ESCAPE; bool key_return = e->keysym.unicode == SDLK_RETURN; #endif if (key_escape) { quit(); } if(gGourceSettings.disable_input) { // disable keyboard input other than the escape key return; } if (e->keysym.sym == SDLK_F5) { reload(); } if (e->keysym.sym == SDLK_F11) { toggleWindowFrame(); } if(key_return) { #if SDL_VERSION_ATLEAST(2,0,0) const Uint8* keystate = SDL_GetKeyboardState(NULL); if(keystate[SDL_SCANCODE_RALT] || keystate[SDL_SCANCODE_LALT]) { #else Uint8* keystate = SDL_GetKeyState(NULL); if(keystate[SDLK_RALT] || keystate[SDLK_LALT]) { #endif toggleFullscreen(); } else { if(gGourceSettings.repo_count>1) next = true; } } } if(gource!=0) gource->keyPress(e); } void GourceShell::mouseMove(SDL_MouseMotionEvent *e) { if(gource!=0) gource->mouseMove(e); } #if SDL_VERSION_ATLEAST(2,0,0) void GourceShell::mouseWheel(SDL_MouseWheelEvent *e) { if(gource!=0) gource->mouseWheel(e); } #endif void GourceShell::mouseClick(SDL_MouseButtonEvent *e) { if(gource!=0) gource->mouseClick(e); } void GourceShell::quit() { if(gource!=0) gource->quit(); gGourceSettings.shutdown=true; } Gource* GourceShell::getNext() { if(gource != 0) { transition_interval = 1.0f; delete gource; gource = 0; } if(gGourceSettings.shutdown || gource_settings == conf->getSections("gource")->end()) { // done return 0; } gGourceSettings.importGourceSettings(*conf, *gource_settings); //recording a video kind of implies you want this, unless: // -- dont stop requested // -- loop requested // -- reading from STDIN if(exporter!=0 && !(gGourceSettings.dont_stop || gGourceSettings.loop || gGourceSettings.path == "-")) gGourceSettings.stop_at_end = true; //multiple repo special settings if(gGourceSettings.repo_count > 1) { //set a stop condition if(gGourceSettings.stop_at_time <= 0.0f && gGourceSettings.stop_position <= 0.0f) { gGourceSettings.stop_at_time = 60.0f; } } gource_settings++; //loop unless only 1 repo if(gource_settings == conf->getSections("gource")->end()) { if(gGourceSettings.repo_count>1 && exporter==0) { gource_settings = conf->getSections("gource")->begin(); } } // replace gource gource = new Gource(exporter); next = false; return gource; } void GourceShell::blendLastFrame(float dt) { if(transition_texture==0 || transition_interval <= 0.0f) return; display.mode2D(); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glEnable(GL_TEXTURE_2D); transition_texture->bind(); glColor4f(1.0, 1.0, 1.0, transition_interval); glBegin(GL_QUADS); glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, 0.0); glTexCoord2f(1.0, 1.0f); glVertex2f(display.width, 0.0); glTexCoord2f(1.0, 0.0f); glVertex2f(display.width, display.height); glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, display.height); glEnd(); transition_interval -= dt; } void GourceShell::update(float t, float dt) { if(gource == 0 || gource->isFinished()) { if(!getNext()) appFinished=true; return; } gource->fps = this->fps; gource->update(t, dt); if(toggle_delay > 0.0) toggle_delay -= dt; //copy last frame if( (next|| gource->isFinished()) && transition_texture!=0) { glEnable(GL_TEXTURE_2D); transition_texture->bind(); glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, display.width, display.height, 0); } else { //blend last frame of previous scene blendLastFrame(dt); } if(next) { delete gource; gource = 0; transition_interval = 1.0f; next = false; } } ================================================ FILE: src/gource_shell.h ================================================ /* Copyright (C) 2010 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef GOURCE_SHELL_H #define GOURCE_SHELL_H #include "core/display.h" #include "core/sdlapp.h" #include "gource.h" class GourceShell : public SDLApp { Gource* gource; bool next; TextureResource* transition_texture; float transition_interval; float toggle_delay; FrameExporter* exporter; ConfFile* conf; ConfSectionList::iterator gource_settings; Gource* getNext(); void blendLastFrame(float dt); public: GourceShell(ConfFile* conf, FrameExporter* exporter); ~GourceShell(); void update(float t, float dt); void resize(int width, int height); void reload(); void toggleFullscreen(); void toggleWindowFrame(); void quit(); void keyPress(SDL_KeyboardEvent *e); void mouseMove(SDL_MouseMotionEvent *e); void mouseClick(SDL_MouseButtonEvent *e); #if SDL_VERSION_ATLEAST(2,0,0) void mouseWheel(SDL_MouseWheelEvent *e); #endif }; #endif extern GourceShell* gGourceShell; ================================================ FILE: src/key.cpp ================================================ #include "key.h" // File Key Entry // a string for the file ext and a colour FileKeyEntry::FileKeyEntry(const FXFont& font, const std::string& ext, const vec3& colour) { this->ext = ext; this->colour = colour; this->pos_y = -1.0f; this->font = font; this->font.dropShadow(false); shadow = vec2(3.0, 3.0); width = 90.0f * gGourceSettings.font_scale; height = gGourceSettings.scaled_font_size + 4.0f; left_margin = gGourceSettings.scaled_font_size + 4.0f; count = 0; brightness = 1.0f; alpha = 0.0f; move_elapsed = 1.0f; src_y = -1.0f; dest_y = -1.0f; show = true; display_ext = ext; bool truncated = false; while(font.getWidth(display_ext) > width - 15.0f * gGourceSettings.font_scale) { display_ext.resize(display_ext.size()-1); truncated = true; } if(truncated) { display_ext += std::string("..."); } } const vec3& FileKeyEntry::getColour() const { return colour; } const std::string& FileKeyEntry::getExt() const { return ext; } void FileKeyEntry::setShow(bool show) { this->show = show; } bool FileKeyEntry::isFinished() const { return (count<=0 && alpha <= 0.0f); } void FileKeyEntry::colourize() { colour = ext.empty() ? vec3(1.0f, 1.0f, 1.0f) : colourHash(ext); } void FileKeyEntry::inc() { count++; } void FileKeyEntry::dec() { count--; } int FileKeyEntry::getCount() const { return count; } void FileKeyEntry::setCount(int count) { this->count = count; } void FileKeyEntry::setDestY(float dest_y) { if(dest_y == this->dest_y) return; this->dest_y = dest_y; src_y = pos_y; move_elapsed = 0.0f; } void FileKeyEntry::logic(float dt) { if(count<=0 || !show) { alpha = std::max(0.0f, alpha - dt); } else if(alpha < 1.0f) { alpha = std::min(1.0f, alpha + dt); } //move towards dest if(pos_y != dest_y) { //initialize pos from dest if new if(pos_y < 0.0f) pos_y = dest_y; else { move_elapsed += dt; if(move_elapsed >= 1.0f) pos_y = dest_y; else pos_y = src_y + (dest_y - src_y) * move_elapsed; } } pos = vec2(alpha * left_margin, pos_y); } void FileKeyEntry::draw() { if(isFinished()) return; //label.draw(); glDisable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(0.0f, 0.0f, 0.0f, alpha * 0.333f); glPushMatrix(); glTranslatef(shadow.x, shadow.y, 0.0f); glBegin(GL_QUADS); glVertex2f(pos.x, pos.y); glVertex2f(pos.x, pos.y + height); glVertex2f(pos.x+width, pos.y + height); glVertex2f(pos.x+width, pos.y); glEnd(); glPopMatrix(); glBegin(GL_QUADS); glColor4f(colour.x * 0.5f, colour.y * 0.5f, colour.z * 0.5f, alpha); glVertex2f(pos.x, pos.y); glVertex2f(pos.x, pos.y + height); glColor4f(colour.x, colour.y, colour.z, alpha); glVertex2f(pos.x + width, pos.y + height); glVertex2f(pos.x + width, pos.y); glEnd(); glEnable(GL_TEXTURE_2D); font.setColour(vec4(1.0f, 1.0f, 1.0f, alpha)); font.dropShadow(false); font.draw((int)pos.x+2, (int)pos.y+3, display_ext.c_str()); font.dropShadow(true); font.print((int)pos.x+width+4, (int)pos.y+3, "%d", count); } // Key //maintain a key of all the current file types, updated periodically. //new entries slide in and out / fade in fade out FileKey::FileKey() { } FileKey::FileKey(float update_interval) { this->update_interval = update_interval; interval_remaining = 1.0f; font = fontmanager.grab(gGourceSettings.font_file, gGourceSettings.scaled_font_size); font.dropShadow(false); font.roundCoordinates(false); show = true; } FileKey::~FileKey() { active_keys.clear(); for(std::map::iterator it = keymap.begin(); it != keymap.end(); it++) { FileKeyEntry* entry = it->second; delete entry; } keymap.clear(); } void FileKey::setShow(bool show) { this->show = show; for(std::vector::iterator it = active_keys.begin(); it != active_keys.end(); it++) { FileKeyEntry* entry = *it; entry->setShow(show); } interval_remaining = 0.0f; } void FileKey::colourize() { for(std::vector::iterator it = active_keys.begin(); it != active_keys.end(); it++) { FileKeyEntry* entry = *it; entry->colourize(); } } void FileKey::clear() { for(std::vector::iterator it = active_keys.begin(); it != active_keys.end(); it++) { FileKeyEntry* entry = *it; entry->setCount(0); } interval_remaining = 0.0f; } void FileKey::inc(RFile* file) { FileKeyEntry* entry = 0; std::map::iterator result = keymap.find(file->ext); if(result != keymap.end()) { entry = result->second; } else { entry = new FileKeyEntry(font, file->ext, file->getFileColour()); keymap[file->ext] = entry; } entry->inc(); } //decrement count of extension. if drops to zero, mark it for removal void FileKey::dec(RFile* file) { std::map::iterator result = keymap.find(file->ext); if(result == keymap.end()) return; FileKeyEntry* entry = result->second; entry->dec(); } bool file_key_entry_sort (const FileKeyEntry* a, const FileKeyEntry* b) { //sort by count if(a->getCount() != b->getCount()) return (a->getCount() > b->getCount()); //then by name (tie breaker) return a->getExt().compare(b->getExt()) < 0; } void FileKey::logic(float dt) { interval_remaining -= dt; //recalculate active_keys if(interval_remaining <= 0.0f) { if(show) { active_keys.clear(); std::vector finished_keys; for(std::map::iterator it = keymap.begin(); it != keymap.end(); it++) { FileKeyEntry* entry = it->second; if(!entry->isFinished()) { active_keys.push_back(entry); } else { finished_keys.push_back(entry); } } //sort std::sort(active_keys.begin(), active_keys.end(), file_key_entry_sort); //limit to entries we can put onto the screen int max_visible_entries = std::max(0, (int)((display.height - 150.0f) / 20.0f)); if (active_keys.size() > max_visible_entries) { active_keys.resize(max_visible_entries); } //set position float offset_y = gGourceSettings.scaled_font_size + 6.0f; float key_y = offset_y; for(std::vector::iterator it = active_keys.begin(); it != active_keys.end(); it++) { FileKeyEntry* entry = *it; if(entry->getCount()>0) { entry->setDestY(key_y); } key_y += offset_y; } //remove and delete finished entries for(std::vector::iterator it = finished_keys.begin(); it != finished_keys.end(); it++) { FileKeyEntry* entry = *it; keymap.erase(entry->getExt()); delete entry; } } interval_remaining = update_interval; } for(std::vector::iterator it = active_keys.begin(); it != active_keys.end(); it++) { FileKeyEntry* entry = *it; entry->logic(dt); } } void FileKey::draw() { for(std::vector::iterator it = active_keys.begin(); it != active_keys.end(); it++) { FileKeyEntry* entry = *it; entry->draw(); } } ================================================ FILE: src/key.h ================================================ /* Copyright (C) 2010 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef FILE_KEY_H #define FILE_KEY_H #include "core/display.h" #include "core/vectors.h" #include "core/fxfont.h" #include "file.h" #include #include class FileKeyEntry { FXFont font; vec3 colour; std::string ext; std::string display_ext; float alpha; float brightness; int count; float pos_y; float src_y; float dest_y; float move_elapsed; float left_margin; float width; float height; vec2 pos; vec2 shadow; bool show; public: FileKeyEntry(const FXFont& font, const std::string& ext, const vec3& colour); const vec3& getColour() const; const std::string& getExt() const; void setDestY(float dest_y); void colourize(); void inc(); void dec(); void setShow(bool show); int getCount() const; void setCount(int count); bool isNew() const; bool isFinished() const; void logic(float dt); void draw(); }; class FileKey { std::vector active_keys; std::map keymap; FXFont font; float update_interval; float interval_remaining; bool show; public: FileKey(); ~FileKey(); FileKey(float update_interval); void setShow(bool show); void clear(); void colourize(); void inc(RFile* file); void dec(RFile* file); void logic(float dt); void draw(); }; #endif ================================================ FILE: src/logmill.cpp ================================================ /* Copyright (C) 2012 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "logmill.h" #include "gource_settings.h" #include "formats/git.h" #include "formats/gitraw.h" #include "formats/custom.h" #include "formats/hg.h" #include "formats/bzr.h" #include "formats/svn.h" #include "formats/apache.h" #include "formats/cvs-exp.h" #include "formats/cvs2cl.h" #include extern "C" { static int logmill_thread(void *lmill) { RLogMill *logmill = static_cast (lmill); logmill->run(); return 0; } }; RLogMill::RLogMill(const std::string& logfile) : logfile(logfile) { logmill_thread_state = LOGMILL_STATE_STARTUP; clog = 0; #if SDL_VERSION_ATLEAST(2,0,0) thread = SDL_CreateThread( logmill_thread, "logmill", this ); #else thread = SDL_CreateThread( logmill_thread, this ); #endif } RLogMill::~RLogMill() { abort(); if(clog) delete clog; } void RLogMill::run() { logmill_thread_state = LOGMILL_STATE_FETCHING; #if defined(HAVE_PTHREAD) && !defined(_WIN32) sigset_t mask; sigemptyset(&mask); // unblock SIGINT so user can cancel // NOTE: assumes SDL is using pthreads sigaddset(&mask, SIGINT); pthread_sigmask(SIG_UNBLOCK, &mask, 0); #endif std::string log_format = gGourceSettings.log_format; try { clog = fetchLog(log_format); // find first commit after start_timestamp if specified if(clog != 0 && gGourceSettings.start_timestamp != 0) { RCommit commit; while(!gGourceSettings.shutdown && !clog->isFinished()) { if(clog->nextCommit(commit) && commit.timestamp >= gGourceSettings.start_timestamp) { clog->bufferCommit(commit); break; } } } } catch(SeekLogException& exception) { error = "unable to read log file"; } catch(SDLAppException& exception) { error = exception.what(); } if(!clog && error.empty()) { if(boost::filesystem::is_directory(logfile)) { if(!log_format.empty()) { if(gGourceSettings.start_timestamp || gGourceSettings.stop_timestamp) { error = "failed to generate log file for the specified time period"; } else { error = "failed to generate log file"; } #ifdef _WIN32 // no error - should trigger help message } else if(gGourceSettings.default_path && boost::filesystem::exists("./gource.exe")) { error = ""; #endif } else { error = "directory not supported"; } } else { error = "unsupported log format (you may need to regenerate your log file)"; } } logmill_thread_state = clog ? LOGMILL_STATE_SUCCESS : LOGMILL_STATE_FAILURE; } void RLogMill::abort() { if(!thread) return; // TODO: make abort nicer by notifying the log process // we want to shutdown SDL_WaitThread(thread, 0); thread = 0; } bool RLogMill::isFinished() { return logmill_thread_state > LOGMILL_STATE_FETCHING; } int RLogMill::getStatus() { return logmill_thread_state; } std::string RLogMill::getError() { return error; } RCommitLog* RLogMill::getLog() { if(thread != 0) { SDL_WaitThread(thread, 0); thread = 0; } return clog; } bool RLogMill::findRepository(boost::filesystem::path& dir, std::string& log_format) { dir = canonical(dir); //fprintf(stderr, "find repository from initial path: %s\n", dir.string().c_str()); while(is_directory(dir)) { if(is_directory(dir / ".git") || is_regular_file(dir / ".git")) log_format = "git"; else if(is_directory(dir / ".hg")) log_format = "hg"; else if(is_directory(dir / ".bzr")) log_format = "bzr"; else if(is_directory(dir / ".svn")) log_format = "svn"; if(!log_format.empty()) { //fprintf(stderr, "found '%s' repository at: %s\n", log_format.c_str(), dir.string().c_str()); return true; } if(!dir.has_parent_path()) return false; dir = dir.parent_path(); } return false; } RCommitLog* RLogMill::fetchLog(std::string& log_format) { RCommitLog* clog = 0; //if the log format is not specified and 'logfile' is a directory, recursively look for a version control repository. //this method allows for something strange like someone who having an svn repository inside a git repository //(in which case it would pick the svn directory as it would encounter that first) if(log_format.empty() && logfile != "-") { try { boost::filesystem::path repo_path(logfile); if(is_directory(repo_path)) { if(findRepository(repo_path, log_format)) { logfile = repo_path.string(); } } } catch(boost::filesystem::filesystem_error& error) { } } //we've been told what format to use if(log_format.size() > 0) { debugLog("log-format = %s", log_format.c_str()); if(log_format == "git") { clog = new GitCommitLog(logfile); if(clog->checkFormat()) return clog; delete clog; clog = new GitRawCommitLog(logfile); if(clog->checkFormat()) return clog; delete clog; } if(log_format == "hg") { clog = new MercurialLog(logfile); if(clog->checkFormat()) return clog; delete clog; } if(log_format == "bzr") { clog = new BazaarLog(logfile); if(clog->checkFormat()) return clog; delete clog; } if(log_format == "cvs") { clog = new CVSEXPCommitLog(logfile); if(clog->checkFormat()) return clog; delete clog; } if(log_format == "custom") { clog = new CustomLog(logfile); if(clog->checkFormat()) return clog; delete clog; } if(log_format == "apache") { clog = new ApacheCombinedLog(logfile); if(clog->checkFormat()) return clog; delete clog; } if(log_format == "svn") { clog = new SVNCommitLog(logfile); if(clog->checkFormat()) return clog; delete clog; } if(log_format == "cvs2cl") { clog = new CVS2CLCommitLog(logfile); if(clog->checkFormat()) return clog; delete clog; } return 0; } // try different formats until one works //git debugLog("trying git..."); clog = new GitCommitLog(logfile); if(clog->checkFormat()) return clog; delete clog; //mercurial debugLog("trying mercurial..."); clog = new MercurialLog(logfile); if(clog->checkFormat()) return clog; delete clog; //bzr debugLog("trying bzr..."); clog = new BazaarLog(logfile); if(clog->checkFormat()) return clog; delete clog; //git raw debugLog("trying git raw..."); clog = new GitRawCommitLog(logfile); if(clog->checkFormat()) return clog; delete clog; //cvs exp debugLog("trying cvs-exp..."); clog = new CVSEXPCommitLog(logfile); if(clog->checkFormat()) return clog; delete clog; //svn debugLog("trying svn..."); clog = new SVNCommitLog(logfile); if(clog->checkFormat()) return clog; delete clog; //cvs2cl debugLog("trying cvs2cl..."); clog = new CVS2CLCommitLog(logfile); if(clog->checkFormat()) return clog; delete clog; //custom debugLog("trying custom..."); clog = new CustomLog(logfile); if(clog->checkFormat()) return clog; delete clog; //apache debugLog("trying apache combined..."); clog = new ApacheCombinedLog(logfile); if(clog->checkFormat()) return clog; delete clog; return 0; } ================================================ FILE: src/logmill.h ================================================ /* Copyright (C) 2012 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef LOGMILL_H #define LOGMILL_H #include #include "SDL_thread.h" #include "core/sdlapp.h" #include "core/display.h" #include "formats/commitlog.h" #if defined(HAVE_PTHREAD) && !defined(_WIN32) #include #endif enum { LOGMILL_STATE_STARTUP, LOGMILL_STATE_FETCHING, LOGMILL_STATE_SUCCESS, LOGMILL_STATE_FAILURE }; class RLogMill { SDL_Thread* thread; SDL_mutex* mutex; SDL_cond* cond; int logmill_thread_state; std::string logfile; RCommitLog* clog; std::string error; bool findRepository(boost::filesystem::path& dir, std::string& log_format); RCommitLog* fetchLog(std::string& log_format); public: RLogMill(const std::string& logfile); ~RLogMill(); void run(); void abort(); std::string getError(); int getStatus(); bool isFinished(); RCommitLog* getLog(); }; #endif ================================================ FILE: src/main.cpp ================================================ /* Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "main.h" int main(int argc, char *argv[]) { std::string exepath; #ifndef _WIN32 if(argc > 0) { exepath = std::string(argv[0]); } #endif SDLAppInit("Gource", "gource", exepath); #ifdef _WIN32 SDLApp::initConsole(); #endif ConfFile conf; std::vector files; //convert args to a conf file //read the conf file //apply the conf file to settings try { gGourceSettings.parseArgs(argc, argv, conf, &files); if(gGourceSettings.load_config.empty() && !files.empty()) { //see if file looks like a config file for(std::vector::iterator fit = files.begin(); fit != files.end(); fit++) { std::string file = *fit; int file_length = file.size(); if( (file.rfind(".conf") == (file_length-5) && file_length > 5) || (file.rfind(".cfg") == (file_length-4) && file_length > 4) || (file.rfind(".ini") == (file_length-4) && file_length > 4) ) { bool is_conf=true; try { ConfFile conftest; conftest.load(file); } catch(ConfFileException& exception) { is_conf = false; } if(is_conf) { gGourceSettings.load_config = file; files.erase(fit); break; } } } } //set log level Logger::getDefault()->setLevel(gGourceSettings.log_level); #ifdef _WIN32 // hide console if not needed if(gGourceSettings.log_level == LOG_LEVEL_OFF && !SDLApp::existing_console) { SDLApp::showConsole(false); } #endif //load config if(!gGourceSettings.load_config.empty()) { conf.clear(); conf.load(gGourceSettings.load_config); //apply args to loaded conf file gGourceSettings.parseArgs(argc, argv, conf); } //set path if(!files.empty()) { std::string path = files[files.size()-1]; ConfSectionList* sectionlist = conf.getSections("gource"); if(sectionlist!=0) { for(ConfSectionList::iterator sit = sectionlist->begin(); sit != sectionlist->end(); sit++) { (*sit)->setEntry("path", path); } } else { conf.setEntry("gource", "path", path); } } //apply the config / see if its valid gGourceSettings.importDisplaySettings(conf); gGourceSettings.importGourceSettings(conf); //save config if(!gGourceSettings.save_config.empty()) { conf.save(gGourceSettings.save_config); exit(0); } //write custom log file if(!gGourceSettings.output_custom_filename.empty() && !gGourceSettings.path.empty()) { Gource::writeCustomLog(gGourceSettings.path, gGourceSettings.output_custom_filename); exit(0); } } catch(ConfFileException& exception) { SDLAppQuit(exception.what()); } //enable frameless display.enableFrameless(gGourceSettings.frameless); // this causes corruption on some video drivers if(gGourceSettings.multisample) { display.multiSample(4); } //background needs alpha channel if(gGourceSettings.transparent) { display.enableAlpha(true); } //enable vsync display.enableVsync(gGourceSettings.vsync); //allow resizing window if we are not recording if(gGourceSettings.resizable && gGourceSettings.output_ppm_filename.empty()) { display.enableResize(true); } // Change OS High DPI display behaviour // On Windows this behaves differently, it seems safe to always enable it bool high_dpi = true; #ifndef _WIN32 // Requesting High DPI on MacOS may cause the pixel resolution to be doubled. // If a resolution has been specified this may not be appropriate // E.g. if you are recording a video at a specific resolution // Can override by supplying --high-dpi option. if(gGourceSettings.viewport_specified && !gGourceSettings.high_dpi) { high_dpi = false; } #endif display.enableHighDPIAwareness(high_dpi); try { display.init("Gource", gGourceSettings.display_width, gGourceSettings.display_height, gGourceSettings.fullscreen, gGourceSettings.screen); #if SDL_VERSION_ATLEAST(2,0,0) if(!display.isFullscreen() && gGourceSettings.window_x >= 0 && gGourceSettings.window_y >= 0) { SDL_SetWindowPosition(display.sdl_window, gGourceSettings.window_x, gGourceSettings.window_y); } SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0"); #endif } catch(SDLInitException& exception) { char errormsg[1024]; snprintf(errormsg, 1024, "SDL initialization failed - %s", exception.what()); SDLAppQuit(errormsg); } //init frame exporter FrameExporter* exporter = 0; if(gGourceSettings.output_ppm_filename.size() > 0) { try { exporter = new PPMExporter(gGourceSettings.output_ppm_filename); } catch(PPMExporterException& exception) { char errormsg[1024]; snprintf(errormsg, 1024, "could not write to '%s'", exception.what()); SDLAppQuit(errormsg); } } if(display.multiSamplingEnabled()) { glEnable(GL_MULTISAMPLE_ARB); } GourceShell* gourcesh = 0; try { gourcesh = gGourceShell = new GourceShell(&conf, exporter); gourcesh->run(); } catch(ResourceException& exception) { char errormsg[1024]; snprintf(errormsg, 1024, "failed to load resource '%s'", exception.what()); SDLAppQuit(errormsg); } catch(SDLAppException& exception) { if(exception.showHelp()) { gGourceSettings.help(); } else { SDLAppQuit(exception.what()); } } gGourceShell = 0; if(gourcesh != 0) delete gourcesh; if(exporter != 0) delete exporter; //free resources display.quit(); return 0; } ================================================ FILE: src/main.h ================================================ /* Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef GOURCE_MAIN_H #define GOURCE_MAIN_H #include "gource_shell.h" #include "gource.h" #endif ================================================ FILE: src/pawn.cpp ================================================ /* Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "pawn.h" float gGourceShadowStrength = 0.5; Pawn::Pawn(const std::string& name, vec2 pos, int tagid) { this->name = name; this->pos = pos; this->tagid = tagid; this->hidden = false; this->speed = 1.0; selected = false; mouseover = false; shadow = false; namewidth = 0; this->shadowOffset = vec2(2.0, 2.0); this->elapsed = 0.0; this->fadetime = 1.0; this->nametime = 5.0; this->name_interval = 0.0; this->namecol = vec3(1.0, 1.0, 1.0); this->graphic = 0; this->graphic_ratio = 1.0; size = 0.0f; } float Pawn::getSize() { return size; } void Pawn::setPos(vec2 pos) { this->pos = pos; } int Pawn::getTagID() { return tagid; } void Pawn::showName() { if(name_interval <= 0.0) name_interval = nametime; } void Pawn::updateQuadItemBounds() { float halfsize_x = size * 0.5f; vec2 halfsize ( halfsize_x, halfsize_x * graphic_ratio ); //set bounds quadItemBounds.set(pos - halfsize, pos + halfsize); } void Pawn::logic(float dt) { elapsed += dt; if(!isHidden()) { if(name_interval>0.0) name_interval -= dt; } } void Pawn::setGraphic(TextureResource* graphic) { if(graphic) { graphic_ratio = graphic->h / (float) graphic->w; } else { graphic_ratio = 1.0f; } this->graphic = graphic; this->dims = vec2(size, size*graphic_ratio); } void Pawn::setMouseOver(bool over) { //showName(); this->mouseover = over; } void Pawn::setSelected(bool selected) { this->selected = selected; } const vec3& Pawn::getNameColour() const { return namecol; } void Pawn::calcScreenPos(const vec2& offset) { screenpos = display.project(vec3(pos.x+offset.x, pos.y+offset.y, 0.0f)); } bool Pawn::nameVisible() const { return ((!selected && name_interval < 0.0) || isHidden()) ? false : true; } void Pawn::drawName() { if(!nameVisible()) return; float done = nametime - name_interval; if(done < 1.0) { drawNameText(done); } else if(done > 1.0 && done < nametime - 1.0) { drawNameText(1.0); } else { drawNameText((nametime - done)); } } void Pawn::drawShadow(float dt) { if(isHidden() || !shadow) return; float halfsize = size * 0.5f; vec2 offsetpos = pos - vec2(halfsize, halfsize*graphic_ratio) + shadowOffset; float alpha = getAlpha(); glBindTexture(GL_TEXTURE_2D, graphic->textureid); glColor4f(0.0, 0.0, 0.0, alpha * gGourceShadowStrength); glPushMatrix(); glTranslatef(offsetpos.x, offsetpos.y, 0.0f); glBegin(GL_QUADS); glTexCoord2f(0.0f,0.0f); glVertex2f(0.0f, 0.0f); glTexCoord2f(1.0f,0.0f); glVertex2f(size, 0.0f); glTexCoord2f(1.0f,1.0f); glVertex2f(size, size*graphic_ratio); glTexCoord2f(0.0f,1.0f); glVertex2f(0.0f, size*graphic_ratio); glEnd(); glPopMatrix(); } void Pawn::draw(float dt) { if(hidden) return; float halfsize = size * 0.5f; vec2 offsetpos = pos - vec2(halfsize, halfsize*graphic_ratio); float alpha = getAlpha(); vec3 col = getColour(); glBindTexture(GL_TEXTURE_2D, graphic->textureid); glPushMatrix(); glTranslatef(offsetpos.x, offsetpos.y, 0.0f); glColor4f(col.x, col.y, col.z, alpha); glBegin(GL_QUADS); glTexCoord2f(0.0f,0.0f); glVertex2f(0.0f, 0.0f); glTexCoord2f(1.0f,0.0f); glVertex2f(size, 0.0f); glTexCoord2f(1.0f,1.0f); glVertex2f(size, size*graphic_ratio); glTexCoord2f(0.0f,1.0f); glVertex2f(0.0f, size*graphic_ratio); glEnd(); glPopMatrix(); } ================================================ FILE: src/pawn.h ================================================ /* Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef PAWN_H #define PAWN_H #include #include "gource_settings.h" #include "core/display.h" #include "core/fxfont.h" #include "core/vectors.h" #include "core/quadtree.h" class Pawn : public QuadItem { protected: vec2 pos; vec2 shadowOffset; std::string name; float namewidth; vec2 accel; float speed; float elapsed; float fadetime; float nametime; float name_interval; vec3 namecol; bool shadow; bool hidden; int tagid; FXFont font; bool mouseover; virtual bool nameVisible() const; virtual void drawNameText(float alpha) {}; virtual const vec3& getNameColour() const; protected: bool selected; public: float size; float graphic_ratio; TextureResource* graphic; vec3 screenpos; vec2 dims; Pawn(const std::string& name, vec2 pos, int tagid); const vec2 & getPos() const { return pos; } void setPos(vec2 pos); void calcScreenPos(const vec2& offset); void updateQuadItemBounds(); void showName(); void setMouseOver(bool over); float getSize(); int getTagID(); const std::string& getName() const { return name; } virtual void setSelected(bool selected); bool isSelected() { return selected; }; void setHidden(bool hidden){ this->hidden = hidden; } bool isHidden() const { return hidden; } virtual float getAlpha() const{ return std::min(elapsed/fadetime, 1.0f); } virtual vec3 getColour() const { return vec3(1.0, 1.0, 1.0); } void setGraphic(TextureResource* graphic); void logic(float dt); void draw(float dt); void drawShadow(float dt); void drawName(); }; extern float gGourceShadowStrength; #endif ================================================ FILE: src/slider.cpp ================================================ /* Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "slider.h" #include "gource_settings.h" // PositionSlider PositionSlider::PositionSlider(float percent) { this->percent = percent; } void PositionSlider::init() { font = fontmanager.grab(gGourceSettings.font_file, 16 * gGourceSettings.font_scale); font.dropShadow(true); slidercol = vec3(1.0, 1.0, 1.0); mouseover = -1.0; mouseover_elapsed = 1.0; fade_time = 1.0; alpha = 0.0; capwidth = 0.0f; resize(); } const Bounds2D& PositionSlider::getBounds() const { return bounds; } void PositionSlider::resize() { int gap = 35; bounds.reset(); bounds.update(vec2(gap, display.height - gap*2)); bounds.update(vec2(display.width - gap, display.height - gap)); } void PositionSlider::setColour(vec3 col) { slidercol = col; } void PositionSlider::show() { mouseover_elapsed = 0.0; } bool PositionSlider::mouseOver(vec2 pos, float* percent_ptr) { if(bounds.contains(pos)) { mouseover_elapsed = 0; mouseover = pos.x; if(percent_ptr != 0) { *percent_ptr = (float) (pos.x - bounds.min.x) / (bounds.max.x - bounds.min.x); } return true; } mouseover = -1.0; return false; } bool PositionSlider::click(vec2 pos, float* percent_ptr) { if(mouseOver(pos, &percent)) { if(percent_ptr != 0) { *percent_ptr = percent; } return true; } return false; } void PositionSlider::setCaption(const std::string& caption) { capwidth = 0.0; this->caption = caption; if(caption.size()) { capwidth = font.getWidth(caption.c_str()); } } void PositionSlider::setPercent(float percent) { this->percent = percent; } void PositionSlider::logic(float dt) { if(mouseover < 0.0 && mouseover_elapsed < fade_time) mouseover_elapsed += dt; if(mouseover_elapsed < fade_time && alpha < 1.0) { alpha = std::min(1.0f, alpha+dt); } else if(mouseover_elapsed >= fade_time && alpha > 0.0) { alpha = std::max(0.0f, alpha-dt); } } void PositionSlider::drawSlider(float pos_x) const { glLineWidth(2.0f); bounds.draw(); glLineWidth(2.0f); glBegin(GL_LINES); glVertex2f(pos_x, bounds.min.y); glVertex2f(pos_x, bounds.max.y); glEnd(); } void PositionSlider::draw(float dt) { glDisable(GL_TEXTURE_2D); float pos_x = bounds.min.x + (bounds.max.x - bounds.min.x) * percent; glColor4f(0.0f, 0.0f, 0.0f, 0.7*alpha); glPushMatrix(); glTranslatef(2.0, 2.0, 0.0); drawSlider(pos_x); glPopMatrix(); glColor4f(slidercol.x, slidercol.y, slidercol.z, alpha); drawSlider(pos_x); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glEnable(GL_TEXTURE_2D); glColor4f(1.0, 1.0, 1.0, 1.0); if(caption.size() && mouseover >= 0.0) { int height_offset = 25 * gGourceSettings.font_scale; font.draw(std::min((double)display.width - capwidth - 1.0, std::max(1.0, mouseover - (capwidth/2.0))), bounds.min.y - height_offset, caption); } } ================================================ FILE: src/slider.h ================================================ /* Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef POS_SLIDER_H #define POS_SLIDER_H #include "core/logger.h" #include "core/bounds.h" #include "core/fxfont.h" class PositionSlider { FXFont font; Bounds2D bounds; float percent; float mouseover; float mouseover_elapsed; float fade_time; float alpha; vec3 slidercol; float capwidth; std::string caption; void drawSlider(float position) const; public: PositionSlider(float percent = 0.0f); void init(); void setColour(vec3 col); void setCaption(const std::string& cap); void setPercent(float percent); void resize(); void show(); const Bounds2D& getBounds() const; bool mouseOver(vec2 pos, float* percent_ptr); bool click(vec2 pos, float* percent_ptr); void logic(float dt); void draw(float dt); }; #endif ================================================ FILE: src/spline.cpp ================================================ /* Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "spline.h" SplineEdge::SplineEdge() { } void SplineEdge::update(const vec2& pos1, const vec4& col1, const vec2& pos2, const vec4& col2, const vec2& spos) { vec2 pt_last; vec4 col_last; vec2 mid = (pos1 - pos2) * 0.5f; vec2 to = vec2(pos1 - spos); //TODO: not sure this makes any sense //float dp = std::min(1.0f, to.normal().dot(mid.normal())); float dp = std::min(1.0f, glm::dot(normalise(to), normalise(mid)) ); float ang = acos(dp) / PI; int edge_detail = std::min(10, (int) (ang * 100.0)); if(edge_detail<1) edge_detail = 1; spline_point.clear(); spline_colour.clear(); spline_point.reserve(edge_detail+1); spline_colour.reserve(edge_detail+1); //calculate positions for(int i=0; i <= edge_detail; i++) { float t = (float)i/edge_detail; float tt = 1.0f-t; vec2 p0 = pos1 * t + spos * tt; vec2 p1 = spos * t + pos2 * tt; vec2 pt = p0 * t + p1 * tt; vec4 coln = col1 * t + col2 * tt; spline_point.push_back(pt); spline_colour.push_back(coln); } const float pos = gGourceSettings.dir_name_position; const float s_quota = 0.5f - glm::abs(pos - 0.5f); const float p_quota = 1.0f - s_quota; label_pos = pos1 * (p_quota * (1.0f - pos)) + pos2 * (p_quota * pos) + spos * s_quota; } const vec2& SplineEdge::getLabelPos() const { return label_pos; } void SplineEdge::drawToVBO(quadbuf& buffer) const { int edges_count = spline_point.size() - 1; for(int i=0; i < edges_count; i++) { //vec2 perp = (spline_point[i] - spline_point[i+1]).perpendicular().normal() * 2.5f; vec2 perp = (spline_point[i] - spline_point[i+1]); perp = normalise(vec2(-perp.y, perp.x)) * 2.5f; quadbuf_vertex v1(spline_point[i] + perp, spline_colour[i], vec2(1.0f, 0.0f)); quadbuf_vertex v2(spline_point[i] - perp, spline_colour[i], vec2(0.0f, 0.0f)); quadbuf_vertex v3(spline_point[i+1] - perp, spline_colour[i+1], vec2(0.0f, 0.0f)); quadbuf_vertex v4(spline_point[i+1] + perp, spline_colour[i+1], vec2(1.0f, 0.0f)); buffer.add(0, v1, v2, v3, v4); } } void SplineEdge::drawBeam(const vec2 & pos1, const vec4 & col1, const vec2 & pos2, const vec4 & col2, float radius, bool first) const{ //vec2 perp = (pos1 - pos2).perpendicular().normal() * radius; vec2 perp = (pos1 - pos2); perp = normalise(vec2(-perp.y, perp.x)) * radius; // src point if(first) { glColor4fv(glm::value_ptr(col1)); glTexCoord2f(1.0,0.0); glVertex2f(pos1.x + perp.x, pos1.y + perp.y); glTexCoord2f(0.0,0.0); glVertex2f(pos1.x - perp.x, pos1.y - perp.y); } // dest point glColor4fv(glm::value_ptr(col2)); glTexCoord2f(1.0,0.0); glVertex2f(pos2.x + perp.x, pos2.y + perp.y); glTexCoord2f(0.0,0.0); glVertex2f(pos2.x - perp.x, pos2.y - perp.y); } void SplineEdge::drawShadow() const{ int edges_count = spline_point.size() - 1; vec2 offset(2.0, 2.0); glBegin(GL_QUAD_STRIP); for(int i=0;i. */ #ifndef SPLINE_EDGE_H #define SPLINE_EDGE_H #include "core/display.h" #include "core/vectors.h" #include "core/pi.h" #include "pawn.h" #include class SplineEdge { std::vector spline_point; std::vector spline_colour; vec2 label_pos; void drawBeam(const vec2 & pos1, const vec4 & col1, const vec2 & pos2, const vec4 & col2, float radius, bool first) const; public: SplineEdge(); const vec2& getLabelPos() const; void update(const vec2& pos1, const vec4& col1, const vec2& pos2, const vec4& col2, const vec2& spos); void drawToVBO(quadbuf& buffer) const; void drawShadow() const; void draw() const; }; #endif ================================================ FILE: src/test/datetime_tests.cpp ================================================ /* Copyright (C) 2021 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "../main.h" #include "../gource_settings.h" #include #include BOOST_AUTO_TEST_CASE( parse_date_time_tests ) { time_t timestamp; BOOST_CHECK_EQUAL(putenv((char*)"TZ=UTC"), 0); BOOST_CHECK(SDLAppSettings::parseDateTime("2021-11-01", timestamp)); BOOST_CHECK_EQUAL(timestamp, 1635724800); BOOST_CHECK_EQUAL(putenv((char*)"TZ=Pacific/Auckland"), 0); BOOST_CHECK(SDLAppSettings::parseDateTime("2021-11-01", timestamp)); BOOST_CHECK_EQUAL(timestamp, 1635678000); BOOST_CHECK(SDLAppSettings::parseDateTime("2021-11-01Z", timestamp)); BOOST_CHECK_EQUAL(timestamp, 1635724800); BOOST_CHECK(SDLAppSettings::parseDateTime("2021-11-01+0", timestamp)); BOOST_CHECK_EQUAL(timestamp, 1635724800); BOOST_CHECK(SDLAppSettings::parseDateTime("2021-11-01+13", timestamp)); BOOST_CHECK_EQUAL(timestamp, 1635678000); BOOST_CHECK(SDLAppSettings::parseDateTime("2021-11-01 +13", timestamp)); BOOST_CHECK_EQUAL(timestamp, 1635678000); BOOST_CHECK(SDLAppSettings::parseDateTime("2021-11-01+5:30", timestamp)); BOOST_CHECK_EQUAL(timestamp, 1635705000); BOOST_CHECK(SDLAppSettings::parseDateTime("2021-11-01 12:01", timestamp)); BOOST_CHECK_EQUAL(timestamp, 1635721260); BOOST_CHECK(SDLAppSettings::parseDateTime("2021-11-01 12:01Z", timestamp)); BOOST_CHECK_EQUAL(timestamp, 1635768060); BOOST_CHECK(SDLAppSettings::parseDateTime("2021-11-01 12:01+0", timestamp)); BOOST_CHECK_EQUAL(timestamp, 1635768060); BOOST_CHECK(SDLAppSettings::parseDateTime("2021-11-01 12:01+13", timestamp)); BOOST_CHECK_EQUAL(timestamp, 1635721260); BOOST_CHECK(SDLAppSettings::parseDateTime("2021-11-01 12:01 +13", timestamp)); BOOST_CHECK_EQUAL(timestamp, 1635721260); BOOST_CHECK(SDLAppSettings::parseDateTime("2021-11-01 12:01+5:30", timestamp)); BOOST_CHECK_EQUAL(timestamp, 1635748260); BOOST_CHECK(SDLAppSettings::parseDateTime("2021-11-01 12:01:59", timestamp)); BOOST_CHECK_EQUAL(timestamp, 1635721319); BOOST_CHECK(SDLAppSettings::parseDateTime("2021-11-01T12:01:59.123", timestamp)); BOOST_CHECK_EQUAL(timestamp, 1635721319); BOOST_CHECK(SDLAppSettings::parseDateTime("2021-11-01 12:01:59Z", timestamp)); BOOST_CHECK_EQUAL(timestamp, 1635768119); BOOST_CHECK(SDLAppSettings::parseDateTime("2021-11-01 12:01:59+0", timestamp)); BOOST_CHECK_EQUAL(timestamp, 1635768119); BOOST_CHECK(SDLAppSettings::parseDateTime("2021-11-01 12:01:59+13", timestamp)); BOOST_CHECK_EQUAL(timestamp, 1635721319); BOOST_CHECK(SDLAppSettings::parseDateTime("2021-11-01 12:01:59 +13", timestamp)); BOOST_CHECK_EQUAL(timestamp, 1635721319); BOOST_CHECK(SDLAppSettings::parseDateTime("2021-11-01 12:01:59+5:30", timestamp)); BOOST_CHECK_EQUAL(timestamp, 1635748319); BOOST_CHECK(SDLAppSettings::parseDateTime("2021-11-01T12:01:59", timestamp)); BOOST_CHECK_EQUAL(timestamp, 1635721319); BOOST_CHECK(SDLAppSettings::parseDateTime("2021-11-01T12:01:59.123", timestamp)); BOOST_CHECK_EQUAL(timestamp, 1635721319); BOOST_CHECK(SDLAppSettings::parseDateTime("2021-11-01T12:01:59Z", timestamp)); BOOST_CHECK_EQUAL(timestamp, 1635768119); BOOST_CHECK(SDLAppSettings::parseDateTime("2021-11-01T12:01:59+0", timestamp)); BOOST_CHECK_EQUAL(timestamp, 1635768119); BOOST_CHECK(SDLAppSettings::parseDateTime("2021-11-01T12:01:59+13", timestamp)); BOOST_CHECK_EQUAL(timestamp, 1635721319); BOOST_CHECK(SDLAppSettings::parseDateTime("2021-11-01T12:01:59+13", timestamp)); BOOST_CHECK_EQUAL(timestamp, 1635721319); BOOST_CHECK(SDLAppSettings::parseDateTime("2021-11-01T12:01:59+5:30", timestamp)); BOOST_CHECK_EQUAL(timestamp, 1635748319); BOOST_CHECK(SDLAppSettings::parseDateTime("2021-11-01T12:01:59.123+5:30", timestamp)); BOOST_CHECK_EQUAL(timestamp, 1635748319); } ================================================ FILE: src/test/main.cpp ================================================ #define BOOST_TEST_MODULE Gource Test Suite #include ================================================ FILE: src/test/regex_tests.cpp ================================================ /* Copyright (C) 2021 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "../core/regex.h" #include #include BOOST_AUTO_TEST_CASE( regex_tests ) { Regex regex("^[A-Z]+$"); BOOST_CHECK(regex.isValid()); BOOST_CHECK(regex.match("ABC")); BOOST_CHECK(regex.match("abc") == false); BOOST_CHECK(regex.match("ABC123") == false); Regex regex_copy = Regex("^[A-Z]+$"); BOOST_CHECK(regex_copy.isValid()); BOOST_CHECK(regex_copy.match("ABC")); BOOST_CHECK_THROW(Regex("^[A-Z+$"), RegexCompilationException); Regex test_regex("^[A-Z+$", true); BOOST_CHECK(test_regex.isValid() == false); std::vector matches; Regex capture_regex("([0-9]+)"); BOOST_CHECK(capture_regex.match("ABC123", &matches)); BOOST_CHECK_EQUAL(matches.size(), 1); BOOST_CHECK_EQUAL(matches[0], "123"); } ================================================ FILE: src/textbox.cpp ================================================ /* Copyright (C) 2010 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "textbox.h" TextBox::TextBox() { } TextBox::TextBox(const FXFont& font) { this->font = font; shadow = vec2(3.0f, 3.0f); colour = vec3(0.7f, 0.7f, 0.7f); corner = vec2(0.0f,0.0f); alpha = 1.0f; brightness = 1.0f; max_width_chars = 1024; rect_width = 0; rect_height = 0; visible = false; } void TextBox::hide() { visible = false; } void TextBox::show() { visible = true; } void TextBox::setBrightness(float brightness) { this->brightness = brightness; } void TextBox::setColour(const vec3& colour) { this->colour = colour; } void TextBox::setAlpha(float alpha) { this->alpha = alpha; } void TextBox::clear() { content.clear(); rect_width = 0; rect_height = 2; } void TextBox::addLine(std::string str) { if(max_width_chars> 0 && str.size() > max_width_chars) { str = str.substr(0, max_width_chars); } int width = font.getWidth(str) + 6; if(width > rect_width) rect_width = width; rect_height += (font.getFontSize()+4); content.push_back(str); } void TextBox::setText(const std::string& str) { clear(); addLine(str); } void TextBox::setText(const std::vector& content) { clear(); for(std::vector::const_iterator it = content.begin(); it != content.end(); it++) { addLine(*it); } } void TextBox::setPos(const vec2& pos, bool adjust) { corner = pos; if(!adjust) return; int fontheight = font.getFontSize() + 4; corner.y -= rect_height; if((corner.x + rect_width) > display.width) { if((corner.x - rect_width - fontheight )>0) { corner.x -= rect_width; } else { corner.x = display.width - rect_width; } } if(corner.y < 0) corner.y += rect_height + fontheight; if(corner.y +rect_height > display.height) corner.y -= rect_height; } void TextBox::draw() const { if(!visible) return; glDisable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(0.0f, 0.0f, 0.0f, alpha * 0.333f); glPushMatrix(); glTranslatef(shadow.x, shadow.y, 0.0f); glBegin(GL_QUADS); glVertex2f(corner.x, corner.y); glVertex2f(corner.x, corner.y + rect_height); glVertex2f(corner.x+rect_width, corner.y + rect_height); glVertex2f(corner.x+rect_width, corner.y); glEnd(); glPopMatrix(); glColor4f(colour.x * brightness, colour.y * brightness, colour.z * brightness, alpha); glBegin(GL_QUADS); glVertex2f(corner.x, corner.y); glVertex2f(corner.x, corner.y + rect_height); glVertex2f(corner.x+rect_width, corner.y + rect_height); glVertex2f(corner.x+rect_width, corner.y); glEnd(); glEnable(GL_TEXTURE_2D); glColor4f(1.0f, 1.0f, 1.0f, alpha); int yinc = 3; std::vector::const_iterator it; for(it = content.begin(); it != content.end(); it++) { font.draw((int)corner.x+2, (int)corner.y+yinc, (*it).c_str()); yinc += font.getFontSize() + 4; } } ================================================ FILE: src/textbox.h ================================================ /* Copyright (C) 2010 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef TEXT_BOX_H #define TEXT_BOX_H #include #include #include "core/display.h" #include "core/vectors.h" #include "core/fxfont.h" class TextBox { std::vector content; vec3 colour; float alpha; float brightness; vec2 corner; vec2 shadow; FXFont font; int max_width_chars; int rect_width; int rect_height; bool visible; public: TextBox(); TextBox(const FXFont& font); void hide(); void show(); void clear(); void setPos(const vec2& pos, bool adjust = false); void setColour(const vec3& colour); void setAlpha(float alpha); void setBrightness(float brightness); void addLine(std::string str); void setText(const std::string& str); void setText(const std::vector& content); void draw() const; }; #endif ================================================ FILE: src/tinyxml/tinystr.cpp ================================================ /* www.sourceforge.net/projects/tinyxml This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef TIXML_USE_STL #include "tinystr.h" // Error value for find primitive const TiXmlString::size_type TiXmlString::npos = static_cast< TiXmlString::size_type >(-1); // Null rep. TiXmlString::Rep TiXmlString::nullrep_ = { 0, 0, { '\0' } }; void TiXmlString::reserve (size_type cap) { if (cap > capacity()) { TiXmlString tmp; tmp.init(length(), cap); memcpy(tmp.start(), data(), length()); swap(tmp); } } TiXmlString& TiXmlString::assign(const char* str, size_type len) { size_type cap = capacity(); if (len > cap || cap > 3*(len + 8)) { TiXmlString tmp; tmp.init(len); memcpy(tmp.start(), str, len); swap(tmp); } else { memmove(start(), str, len); set_size(len); } return *this; } TiXmlString& TiXmlString::append(const char* str, size_type len) { size_type newsize = length() + len; if (newsize > capacity()) { reserve (newsize + capacity()); } memmove(finish(), str, len); set_size(newsize); return *this; } TiXmlString operator + (const TiXmlString & a, const TiXmlString & b) { TiXmlString tmp; tmp.reserve(a.length() + b.length()); tmp += a; tmp += b; return tmp; } TiXmlString operator + (const TiXmlString & a, const char* b) { TiXmlString tmp; TiXmlString::size_type b_len = static_cast( strlen(b) ); tmp.reserve(a.length() + b_len); tmp += a; tmp.append(b, b_len); return tmp; } TiXmlString operator + (const char* a, const TiXmlString & b) { TiXmlString tmp; TiXmlString::size_type a_len = static_cast( strlen(a) ); tmp.reserve(a_len + b.length()); tmp.append(a, a_len); tmp += b; return tmp; } #endif // TIXML_USE_STL ================================================ FILE: src/tinyxml/tinystr.h ================================================ /* www.sourceforge.net/projects/tinyxml This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef TIXML_USE_STL #ifndef TIXML_STRING_INCLUDED #define TIXML_STRING_INCLUDED #include #include /* The support for explicit isn't that universal, and it isn't really required - it is used to check that the TiXmlString class isn't incorrectly used. Be nice to old compilers and macro it here: */ #if defined(_MSC_VER) && (_MSC_VER >= 1200 ) // Microsoft visual studio, version 6 and higher. #define TIXML_EXPLICIT explicit #elif defined(__GNUC__) && (__GNUC__ >= 3 ) // GCC version 3 and higher.s #define TIXML_EXPLICIT explicit #else #define TIXML_EXPLICIT #endif /* TiXmlString is an emulation of a subset of the std::string template. Its purpose is to allow compiling TinyXML on compilers with no or poor STL support. Only the member functions relevant to the TinyXML project have been implemented. The buffer allocation is made by a simplistic power of 2 like mechanism : if we increase a string and there's no more room, we allocate a buffer twice as big as we need. */ class TiXmlString { public : // The size type used typedef size_t size_type; // Error value for find primitive static const size_type npos; // = -1; // TiXmlString empty constructor TiXmlString () : rep_(&nullrep_) { } // TiXmlString copy constructor TiXmlString ( const TiXmlString & copy) : rep_(0) { init(copy.length()); memcpy(start(), copy.data(), length()); } // TiXmlString constructor, based on a string TIXML_EXPLICIT TiXmlString ( const char * copy) : rep_(0) { init( static_cast( strlen(copy) )); memcpy(start(), copy, length()); } // TiXmlString constructor, based on a string TIXML_EXPLICIT TiXmlString ( const char * str, size_type len) : rep_(0) { init(len); memcpy(start(), str, len); } // TiXmlString destructor ~TiXmlString () { quit(); } TiXmlString& operator = (const char * copy) { return assign( copy, (size_type)strlen(copy)); } TiXmlString& operator = (const TiXmlString & copy) { return assign(copy.start(), copy.length()); } // += operator. Maps to append TiXmlString& operator += (const char * suffix) { return append(suffix, static_cast( strlen(suffix) )); } // += operator. Maps to append TiXmlString& operator += (char single) { return append(&single, 1); } // += operator. Maps to append TiXmlString& operator += (const TiXmlString & suffix) { return append(suffix.data(), suffix.length()); } // Convert a TiXmlString into a null-terminated char * const char * c_str () const { return rep_->str; } // Convert a TiXmlString into a char * (need not be null terminated). const char * data () const { return rep_->str; } // Return the length of a TiXmlString size_type length () const { return rep_->size; } // Alias for length() size_type size () const { return rep_->size; } // Checks if a TiXmlString is empty bool empty () const { return rep_->size == 0; } // Return capacity of string size_type capacity () const { return rep_->capacity; } // single char extraction const char& at (size_type index) const { assert( index < length() ); return rep_->str[ index ]; } // [] operator char& operator [] (size_type index) const { assert( index < length() ); return rep_->str[ index ]; } // find a char in a string. Return TiXmlString::npos if not found size_type find (char lookup) const { return find(lookup, 0); } // find a char in a string from an offset. Return TiXmlString::npos if not found size_type find (char tofind, size_type offset) const { if (offset >= length()) return npos; for (const char* p = c_str() + offset; *p != '\0'; ++p) { if (*p == tofind) return static_cast< size_type >( p - c_str() ); } return npos; } void clear () { //Lee: //The original was just too strange, though correct: // TiXmlString().swap(*this); //Instead use the quit & re-init: quit(); init(0,0); } /* Function to reserve a big amount of data when we know we'll need it. Be aware that this function DOES NOT clear the content of the TiXmlString if any exists. */ void reserve (size_type cap); TiXmlString& assign (const char* str, size_type len); TiXmlString& append (const char* str, size_type len); void swap (TiXmlString& other) { Rep* r = rep_; rep_ = other.rep_; other.rep_ = r; } private: void init(size_type sz) { init(sz, sz); } void set_size(size_type sz) { rep_->str[ rep_->size = sz ] = '\0'; } char* start() const { return rep_->str; } char* finish() const { return rep_->str + rep_->size; } struct Rep { size_type size, capacity; char str[1]; }; void init(size_type sz, size_type cap) { if (cap) { // Lee: the original form: // rep_ = static_cast(operator new(sizeof(Rep) + cap)); // doesn't work in some cases of new being overloaded. Switching // to the normal allocation, although use an 'int' for systems // that are overly picky about structure alignment. const size_type bytesNeeded = sizeof(Rep) + cap; const size_type intsNeeded = ( bytesNeeded + sizeof(int) - 1 ) / sizeof( int ); rep_ = reinterpret_cast( new int[ intsNeeded ] ); rep_->str[ rep_->size = sz ] = '\0'; rep_->capacity = cap; } else { rep_ = &nullrep_; } } void quit() { if (rep_ != &nullrep_) { // The rep_ is really an array of ints. (see the allocator, above). // Cast it back before delete, so the compiler won't incorrectly call destructors. delete [] ( reinterpret_cast( rep_ ) ); } } Rep * rep_; static Rep nullrep_; } ; inline bool operator == (const TiXmlString & a, const TiXmlString & b) { return ( a.length() == b.length() ) // optimization on some platforms && ( strcmp(a.c_str(), b.c_str()) == 0 ); // actual compare } inline bool operator < (const TiXmlString & a, const TiXmlString & b) { return strcmp(a.c_str(), b.c_str()) < 0; } inline bool operator != (const TiXmlString & a, const TiXmlString & b) { return !(a == b); } inline bool operator > (const TiXmlString & a, const TiXmlString & b) { return b < a; } inline bool operator <= (const TiXmlString & a, const TiXmlString & b) { return !(b < a); } inline bool operator >= (const TiXmlString & a, const TiXmlString & b) { return !(a < b); } inline bool operator == (const TiXmlString & a, const char* b) { return strcmp(a.c_str(), b) == 0; } inline bool operator == (const char* a, const TiXmlString & b) { return b == a; } inline bool operator != (const TiXmlString & a, const char* b) { return !(a == b); } inline bool operator != (const char* a, const TiXmlString & b) { return !(b == a); } TiXmlString operator + (const TiXmlString & a, const TiXmlString & b); TiXmlString operator + (const TiXmlString & a, const char* b); TiXmlString operator + (const char* a, const TiXmlString & b); /* TiXmlOutStream is an emulation of std::ostream. It is based on TiXmlString. Only the operators that we need for TinyXML have been developed. */ class TiXmlOutStream : public TiXmlString { public : // TiXmlOutStream << operator. TiXmlOutStream & operator << (const TiXmlString & in) { *this += in; return *this; } // TiXmlOutStream << operator. TiXmlOutStream & operator << (const char * in) { *this += in; return *this; } } ; #endif // TIXML_STRING_INCLUDED #endif // TIXML_USE_STL ================================================ FILE: src/tinyxml/tinyxml.cpp ================================================ /* www.sourceforge.net/projects/tinyxml Original code by Lee Thomason (www.grinninglizard.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include #ifdef TIXML_USE_STL #include #include #endif #include "tinyxml.h" FILE* TiXmlFOpen( const char* filename, const char* mode ); bool TiXmlBase::condenseWhiteSpace = true; // Microsoft compiler security FILE* TiXmlFOpen( const char* filename, const char* mode ) { #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) FILE* fp = 0; errno_t err = fopen_s( &fp, filename, mode ); if ( !err && fp ) return fp; return 0; #else return fopen( filename, mode ); #endif } void TiXmlBase::EncodeString( const TIXML_STRING& str, TIXML_STRING* outString ) { int i=0; while( i<(int)str.length() ) { unsigned char c = (unsigned char) str[i]; if ( c == '&' && i < ( (int)str.length() - 2 ) && str[i+1] == '#' && str[i+2] == 'x' ) { // Hexadecimal character reference. // Pass through unchanged. // © -- copyright symbol, for example. // // The -1 is a bug fix from Rob Laveaux. It keeps // an overflow from happening if there is no ';'. // There are actually 2 ways to exit this loop - // while fails (error case) and break (semicolon found). // However, there is no mechanism (currently) for // this function to return an error. while ( i<(int)str.length()-1 ) { outString->append( str.c_str() + i, 1 ); ++i; if ( str[i] == ';' ) break; } } else if ( c == '&' ) { outString->append( entity[0].str, entity[0].strLength ); ++i; } else if ( c == '<' ) { outString->append( entity[1].str, entity[1].strLength ); ++i; } else if ( c == '>' ) { outString->append( entity[2].str, entity[2].strLength ); ++i; } else if ( c == '\"' ) { outString->append( entity[3].str, entity[3].strLength ); ++i; } else if ( c == '\'' ) { outString->append( entity[4].str, entity[4].strLength ); ++i; } else if ( c < 32 ) { // Easy pass at non-alpha/numeric/symbol // Below 32 is symbolic. char buf[ 32 ]; #if defined(TIXML_SNPRINTF) TIXML_SNPRINTF( buf, sizeof(buf), "&#x%02X;", (unsigned) ( c & 0xff ) ); #else sprintf( buf, "&#x%02X;", (unsigned) ( c & 0xff ) ); #endif //*ME: warning C4267: convert 'size_t' to 'int' //*ME: Int-Cast to make compiler happy ... outString->append( buf, (int)strlen( buf ) ); ++i; } else { //char realc = (char) c; //outString->append( &realc, 1 ); *outString += (char) c; // somewhat more efficient function call. ++i; } } } TiXmlNode::TiXmlNode( NodeType _type ) : TiXmlBase() { parent = 0; type = _type; firstChild = 0; lastChild = 0; prev = 0; next = 0; } TiXmlNode::~TiXmlNode() { TiXmlNode* node = firstChild; TiXmlNode* temp = 0; while ( node ) { temp = node; node = node->next; delete temp; } } void TiXmlNode::CopyTo( TiXmlNode* target ) const { target->SetValue (value.c_str() ); target->userData = userData; target->location = location; } void TiXmlNode::Clear() { TiXmlNode* node = firstChild; TiXmlNode* temp = 0; while ( node ) { temp = node; node = node->next; delete temp; } firstChild = 0; lastChild = 0; } TiXmlNode* TiXmlNode::LinkEndChild( TiXmlNode* node ) { assert( node->parent == 0 || node->parent == this ); assert( node->GetDocument() == 0 || node->GetDocument() == this->GetDocument() ); if ( node->Type() == TiXmlNode::TINYXML_DOCUMENT ) { delete node; if ( GetDocument() ) GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); return 0; } node->parent = this; node->prev = lastChild; node->next = 0; if ( lastChild ) lastChild->next = node; else firstChild = node; // it was an empty list. lastChild = node; return node; } TiXmlNode* TiXmlNode::InsertEndChild( const TiXmlNode& addThis ) { if ( addThis.Type() == TiXmlNode::TINYXML_DOCUMENT ) { if ( GetDocument() ) GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); return 0; } TiXmlNode* node = addThis.Clone(); if ( !node ) return 0; return LinkEndChild( node ); } TiXmlNode* TiXmlNode::InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis ) { if ( !beforeThis || beforeThis->parent != this ) { return 0; } if ( addThis.Type() == TiXmlNode::TINYXML_DOCUMENT ) { if ( GetDocument() ) GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); return 0; } TiXmlNode* node = addThis.Clone(); if ( !node ) return 0; node->parent = this; node->next = beforeThis; node->prev = beforeThis->prev; if ( beforeThis->prev ) { beforeThis->prev->next = node; } else { assert( firstChild == beforeThis ); firstChild = node; } beforeThis->prev = node; return node; } TiXmlNode* TiXmlNode::InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis ) { if ( !afterThis || afterThis->parent != this ) { return 0; } if ( addThis.Type() == TiXmlNode::TINYXML_DOCUMENT ) { if ( GetDocument() ) GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); return 0; } TiXmlNode* node = addThis.Clone(); if ( !node ) return 0; node->parent = this; node->prev = afterThis; node->next = afterThis->next; if ( afterThis->next ) { afterThis->next->prev = node; } else { assert( lastChild == afterThis ); lastChild = node; } afterThis->next = node; return node; } TiXmlNode* TiXmlNode::ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis ) { if ( !replaceThis ) return 0; if ( replaceThis->parent != this ) return 0; if ( withThis.ToDocument() ) { // A document can never be a child. Thanks to Noam. TiXmlDocument* document = GetDocument(); if ( document ) document->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); return 0; } TiXmlNode* node = withThis.Clone(); if ( !node ) return 0; node->next = replaceThis->next; node->prev = replaceThis->prev; if ( replaceThis->next ) replaceThis->next->prev = node; else lastChild = node; if ( replaceThis->prev ) replaceThis->prev->next = node; else firstChild = node; delete replaceThis; node->parent = this; return node; } bool TiXmlNode::RemoveChild( TiXmlNode* removeThis ) { if ( !removeThis ) { return false; } if ( removeThis->parent != this ) { assert( 0 ); return false; } if ( removeThis->next ) removeThis->next->prev = removeThis->prev; else lastChild = removeThis->prev; if ( removeThis->prev ) removeThis->prev->next = removeThis->next; else firstChild = removeThis->next; delete removeThis; return true; } const TiXmlNode* TiXmlNode::FirstChild( const char * _value ) const { const TiXmlNode* node; for ( node = firstChild; node; node = node->next ) { if ( strcmp( node->Value(), _value ) == 0 ) return node; } return 0; } const TiXmlNode* TiXmlNode::LastChild( const char * _value ) const { const TiXmlNode* node; for ( node = lastChild; node; node = node->prev ) { if ( strcmp( node->Value(), _value ) == 0 ) return node; } return 0; } const TiXmlNode* TiXmlNode::IterateChildren( const TiXmlNode* previous ) const { if ( !previous ) { return FirstChild(); } else { assert( previous->parent == this ); return previous->NextSibling(); } } const TiXmlNode* TiXmlNode::IterateChildren( const char * val, const TiXmlNode* previous ) const { if ( !previous ) { return FirstChild( val ); } else { assert( previous->parent == this ); return previous->NextSibling( val ); } } const TiXmlNode* TiXmlNode::NextSibling( const char * _value ) const { const TiXmlNode* node; for ( node = next; node; node = node->next ) { if ( strcmp( node->Value(), _value ) == 0 ) return node; } return 0; } const TiXmlNode* TiXmlNode::PreviousSibling( const char * _value ) const { const TiXmlNode* node; for ( node = prev; node; node = node->prev ) { if ( strcmp( node->Value(), _value ) == 0 ) return node; } return 0; } void TiXmlElement::RemoveAttribute( const char * name ) { #ifdef TIXML_USE_STL TIXML_STRING str( name ); TiXmlAttribute* node = attributeSet.Find( str ); #else TiXmlAttribute* node = attributeSet.Find( name ); #endif if ( node ) { attributeSet.Remove( node ); delete node; } } const TiXmlElement* TiXmlNode::FirstChildElement() const { const TiXmlNode* node; for ( node = FirstChild(); node; node = node->NextSibling() ) { if ( node->ToElement() ) return node->ToElement(); } return 0; } const TiXmlElement* TiXmlNode::FirstChildElement( const char * _value ) const { const TiXmlNode* node; for ( node = FirstChild( _value ); node; node = node->NextSibling( _value ) ) { if ( node->ToElement() ) return node->ToElement(); } return 0; } const TiXmlElement* TiXmlNode::NextSiblingElement() const { const TiXmlNode* node; for ( node = NextSibling(); node; node = node->NextSibling() ) { if ( node->ToElement() ) return node->ToElement(); } return 0; } const TiXmlElement* TiXmlNode::NextSiblingElement( const char * _value ) const { const TiXmlNode* node; for ( node = NextSibling( _value ); node; node = node->NextSibling( _value ) ) { if ( node->ToElement() ) return node->ToElement(); } return 0; } const TiXmlDocument* TiXmlNode::GetDocument() const { const TiXmlNode* node; for( node = this; node; node = node->parent ) { if ( node->ToDocument() ) return node->ToDocument(); } return 0; } TiXmlElement::TiXmlElement (const char * _value) : TiXmlNode( TiXmlNode::TINYXML_ELEMENT ) { firstChild = lastChild = 0; value = _value; } #ifdef TIXML_USE_STL TiXmlElement::TiXmlElement( const std::string& _value ) : TiXmlNode( TiXmlNode::TINYXML_ELEMENT ) { firstChild = lastChild = 0; value = _value; } #endif TiXmlElement::TiXmlElement( const TiXmlElement& copy) : TiXmlNode( TiXmlNode::TINYXML_ELEMENT ) { firstChild = lastChild = 0; copy.CopyTo( this ); } TiXmlElement& TiXmlElement::operator=( const TiXmlElement& base ) { ClearThis(); base.CopyTo( this ); return *this; } TiXmlElement::~TiXmlElement() { ClearThis(); } void TiXmlElement::ClearThis() { Clear(); while( attributeSet.First() ) { TiXmlAttribute* node = attributeSet.First(); attributeSet.Remove( node ); delete node; } } const char* TiXmlElement::Attribute( const char* name ) const { const TiXmlAttribute* node = attributeSet.Find( name ); if ( node ) return node->Value(); return 0; } #ifdef TIXML_USE_STL const std::string* TiXmlElement::Attribute( const std::string& name ) const { const TiXmlAttribute* attrib = attributeSet.Find( name ); if ( attrib ) return &attrib->ValueStr(); return 0; } #endif const char* TiXmlElement::Attribute( const char* name, int* i ) const { const TiXmlAttribute* attrib = attributeSet.Find( name ); const char* result = 0; if ( attrib ) { result = attrib->Value(); if ( i ) { attrib->QueryIntValue( i ); } } return result; } #ifdef TIXML_USE_STL const std::string* TiXmlElement::Attribute( const std::string& name, int* i ) const { const TiXmlAttribute* attrib = attributeSet.Find( name ); const std::string* result = 0; if ( attrib ) { result = &attrib->ValueStr(); if ( i ) { attrib->QueryIntValue( i ); } } return result; } #endif const char* TiXmlElement::Attribute( const char* name, double* d ) const { const TiXmlAttribute* attrib = attributeSet.Find( name ); const char* result = 0; if ( attrib ) { result = attrib->Value(); if ( d ) { attrib->QueryDoubleValue( d ); } } return result; } #ifdef TIXML_USE_STL const std::string* TiXmlElement::Attribute( const std::string& name, double* d ) const { const TiXmlAttribute* attrib = attributeSet.Find( name ); const std::string* result = 0; if ( attrib ) { result = &attrib->ValueStr(); if ( d ) { attrib->QueryDoubleValue( d ); } } return result; } #endif int TiXmlElement::QueryIntAttribute( const char* name, int* ival ) const { const TiXmlAttribute* attrib = attributeSet.Find( name ); if ( !attrib ) return TIXML_NO_ATTRIBUTE; return attrib->QueryIntValue( ival ); } int TiXmlElement::QueryUnsignedAttribute( const char* name, unsigned* value ) const { const TiXmlAttribute* node = attributeSet.Find( name ); if ( !node ) return TIXML_NO_ATTRIBUTE; int ival = 0; int result = node->QueryIntValue( &ival ); *value = (unsigned)ival; return result; } int TiXmlElement::QueryBoolAttribute( const char* name, bool* bval ) const { const TiXmlAttribute* node = attributeSet.Find( name ); if ( !node ) return TIXML_NO_ATTRIBUTE; int result = TIXML_WRONG_TYPE; if ( StringEqual( node->Value(), "true", true, TIXML_ENCODING_UNKNOWN ) || StringEqual( node->Value(), "yes", true, TIXML_ENCODING_UNKNOWN ) || StringEqual( node->Value(), "1", true, TIXML_ENCODING_UNKNOWN ) ) { *bval = true; result = TIXML_SUCCESS; } else if ( StringEqual( node->Value(), "false", true, TIXML_ENCODING_UNKNOWN ) || StringEqual( node->Value(), "no", true, TIXML_ENCODING_UNKNOWN ) || StringEqual( node->Value(), "0", true, TIXML_ENCODING_UNKNOWN ) ) { *bval = false; result = TIXML_SUCCESS; } return result; } #ifdef TIXML_USE_STL int TiXmlElement::QueryIntAttribute( const std::string& name, int* ival ) const { const TiXmlAttribute* attrib = attributeSet.Find( name ); if ( !attrib ) return TIXML_NO_ATTRIBUTE; return attrib->QueryIntValue( ival ); } #endif int TiXmlElement::QueryDoubleAttribute( const char* name, double* dval ) const { const TiXmlAttribute* attrib = attributeSet.Find( name ); if ( !attrib ) return TIXML_NO_ATTRIBUTE; return attrib->QueryDoubleValue( dval ); } #ifdef TIXML_USE_STL int TiXmlElement::QueryDoubleAttribute( const std::string& name, double* dval ) const { const TiXmlAttribute* attrib = attributeSet.Find( name ); if ( !attrib ) return TIXML_NO_ATTRIBUTE; return attrib->QueryDoubleValue( dval ); } #endif void TiXmlElement::SetAttribute( const char * name, int val ) { TiXmlAttribute* attrib = attributeSet.FindOrCreate( name ); if ( attrib ) { attrib->SetIntValue( val ); } } #ifdef TIXML_USE_STL void TiXmlElement::SetAttribute( const std::string& name, int val ) { TiXmlAttribute* attrib = attributeSet.FindOrCreate( name ); if ( attrib ) { attrib->SetIntValue( val ); } } #endif void TiXmlElement::SetDoubleAttribute( const char * name, double val ) { TiXmlAttribute* attrib = attributeSet.FindOrCreate( name ); if ( attrib ) { attrib->SetDoubleValue( val ); } } #ifdef TIXML_USE_STL void TiXmlElement::SetDoubleAttribute( const std::string& name, double val ) { TiXmlAttribute* attrib = attributeSet.FindOrCreate( name ); if ( attrib ) { attrib->SetDoubleValue( val ); } } #endif void TiXmlElement::SetAttribute( const char * cname, const char * cvalue ) { TiXmlAttribute* attrib = attributeSet.FindOrCreate( cname ); if ( attrib ) { attrib->SetValue( cvalue ); } } #ifdef TIXML_USE_STL void TiXmlElement::SetAttribute( const std::string& _name, const std::string& _value ) { TiXmlAttribute* attrib = attributeSet.FindOrCreate( _name ); if ( attrib ) { attrib->SetValue( _value ); } } #endif void TiXmlElement::Print( FILE* cfile, int depth ) const { int i; assert( cfile ); for ( i=0; iNext() ) { fprintf( cfile, " " ); attrib->Print( cfile, depth ); } // There are 3 different formatting approaches: // 1) An element without children is printed as a node // 2) An element with only a text child is printed as text // 3) An element with children is printed on multiple lines. TiXmlNode* node; if ( !firstChild ) { fprintf( cfile, " />" ); } else if ( firstChild == lastChild && firstChild->ToText() ) { fprintf( cfile, ">" ); firstChild->Print( cfile, depth + 1 ); fprintf( cfile, "", value.c_str() ); } else { fprintf( cfile, ">" ); for ( node = firstChild; node; node=node->NextSibling() ) { if ( !node->ToText() ) { fprintf( cfile, "\n" ); } node->Print( cfile, depth+1 ); } fprintf( cfile, "\n" ); for( i=0; i", value.c_str() ); } } void TiXmlElement::CopyTo( TiXmlElement* target ) const { // superclass: TiXmlNode::CopyTo( target ); // Element class: // Clone the attributes, then clone the children. const TiXmlAttribute* attribute = 0; for( attribute = attributeSet.First(); attribute; attribute = attribute->Next() ) { target->SetAttribute( attribute->Name(), attribute->Value() ); } TiXmlNode* node = 0; for ( node = firstChild; node; node = node->NextSibling() ) { target->LinkEndChild( node->Clone() ); } } bool TiXmlElement::Accept( TiXmlVisitor* visitor ) const { if ( visitor->VisitEnter( *this, attributeSet.First() ) ) { for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() ) { if ( !node->Accept( visitor ) ) break; } } return visitor->VisitExit( *this ); } TiXmlNode* TiXmlElement::Clone() const { TiXmlElement* clone = new TiXmlElement( Value() ); if ( !clone ) return 0; CopyTo( clone ); return clone; } const char* TiXmlElement::GetText() const { const TiXmlNode* child = this->FirstChild(); if ( child ) { const TiXmlText* childText = child->ToText(); if ( childText ) { return childText->Value(); } } return 0; } TiXmlDocument::TiXmlDocument() : TiXmlNode( TiXmlNode::TINYXML_DOCUMENT ) { tabsize = 4; useMicrosoftBOM = false; ClearError(); } TiXmlDocument::TiXmlDocument( const char * documentName ) : TiXmlNode( TiXmlNode::TINYXML_DOCUMENT ) { tabsize = 4; useMicrosoftBOM = false; value = documentName; ClearError(); } #ifdef TIXML_USE_STL TiXmlDocument::TiXmlDocument( const std::string& documentName ) : TiXmlNode( TiXmlNode::TINYXML_DOCUMENT ) { tabsize = 4; useMicrosoftBOM = false; value = documentName; ClearError(); } #endif TiXmlDocument::TiXmlDocument( const TiXmlDocument& copy ) : TiXmlNode( TiXmlNode::TINYXML_DOCUMENT ) { copy.CopyTo( this ); } TiXmlDocument& TiXmlDocument::operator=( const TiXmlDocument& copy ) { Clear(); copy.CopyTo( this ); return *this; } bool TiXmlDocument::LoadFile( TiXmlEncoding encoding ) { return LoadFile( Value(), encoding ); } bool TiXmlDocument::SaveFile() const { return SaveFile( Value() ); } bool TiXmlDocument::LoadFile( const char* _filename, TiXmlEncoding encoding ) { TIXML_STRING filename( _filename ); value = filename; // reading in binary mode so that tinyxml can normalize the EOL FILE* file = TiXmlFOpen( value.c_str (), "rb" ); if ( file ) { bool result = LoadFile( file, encoding ); fclose( file ); return result; } else { SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); return false; } } bool TiXmlDocument::LoadFile( FILE* file, TiXmlEncoding encoding ) { if ( !file ) { SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); return false; } // Delete the existing data: Clear(); location.Clear(); // Get the file size, so we can pre-allocate the string. HUGE speed impact. long length = 0; fseek( file, 0, SEEK_END ); length = ftell( file ); fseek( file, 0, SEEK_SET ); // Strange case, but good to handle up front. if ( length <= 0 ) { SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); return false; } // Subtle bug here. TinyXml did use fgets. But from the XML spec: // 2.11 End-of-Line Handling // // // ...the XML processor MUST behave as if it normalized all line breaks in external // parsed entities (including the document entity) on input, before parsing, by translating // both the two-character sequence #xD #xA and any #xD that is not followed by #xA to // a single #xA character. // // // It is not clear fgets does that, and certainly isn't clear it works cross platform. // Generally, you expect fgets to translate from the convention of the OS to the c/unix // convention, and not work generally. /* while( fgets( buf, sizeof(buf), file ) ) { data += buf; } */ char* buf = new char[ length+1 ]; buf[0] = 0; if ( fread( buf, length, 1, file ) != 1 ) { delete [] buf; SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); return false; } // Process the buffer in place to normalize new lines. (See comment above.) // Copies from the 'p' to 'q' pointer, where p can advance faster if // a newline-carriage return is hit. // // Wikipedia: // Systems based on ASCII or a compatible character set use either LF (Line feed, '\n', 0x0A, 10 in decimal) or // CR (Carriage return, '\r', 0x0D, 13 in decimal) individually, or CR followed by LF (CR+LF, 0x0D 0x0A)... // * LF: Multics, Unix and Unix-like systems (GNU/Linux, AIX, Xenix, Mac OS X, FreeBSD, etc.), BeOS, Amiga, RISC OS, and others // * CR+LF: DEC RT-11 and most other early non-Unix, non-IBM OSes, CP/M, MP/M, DOS, OS/2, Microsoft Windows, Symbian OS // * CR: Commodore 8-bit machines, Apple II family, Mac OS up to version 9 and OS-9 const char* p = buf; // the read head char* q = buf; // the write head const char CR = 0x0d; const char LF = 0x0a; buf[length] = 0; while( *p ) { assert( p < (buf+length) ); assert( q <= (buf+length) ); assert( q <= p ); if ( *p == CR ) { *q++ = LF; p++; if ( *p == LF ) { // check for CR+LF (and skip LF) p++; } } else { *q++ = *p++; } } assert( q <= (buf+length) ); *q = 0; Parse( buf, 0, encoding ); delete [] buf; return !Error(); } bool TiXmlDocument::SaveFile( const char * filename ) const { // The old c stuff lives on... FILE* fp = TiXmlFOpen( filename, "w" ); if ( fp ) { bool result = SaveFile( fp ); fclose( fp ); return result; } return false; } bool TiXmlDocument::SaveFile( FILE* fp ) const { if ( useMicrosoftBOM ) { const unsigned char TIXML_UTF_LEAD_0 = 0xefU; const unsigned char TIXML_UTF_LEAD_1 = 0xbbU; const unsigned char TIXML_UTF_LEAD_2 = 0xbfU; fputc( TIXML_UTF_LEAD_0, fp ); fputc( TIXML_UTF_LEAD_1, fp ); fputc( TIXML_UTF_LEAD_2, fp ); } Print( fp, 0 ); return (ferror(fp) == 0); } void TiXmlDocument::CopyTo( TiXmlDocument* target ) const { TiXmlNode::CopyTo( target ); target->error = error; target->errorId = errorId; target->errorDesc = errorDesc; target->tabsize = tabsize; target->errorLocation = errorLocation; target->useMicrosoftBOM = useMicrosoftBOM; TiXmlNode* node = 0; for ( node = firstChild; node; node = node->NextSibling() ) { target->LinkEndChild( node->Clone() ); } } TiXmlNode* TiXmlDocument::Clone() const { TiXmlDocument* clone = new TiXmlDocument(); if ( !clone ) return 0; CopyTo( clone ); return clone; } void TiXmlDocument::Print( FILE* cfile, int depth ) const { assert( cfile ); for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() ) { node->Print( cfile, depth ); fprintf( cfile, "\n" ); } } bool TiXmlDocument::Accept( TiXmlVisitor* visitor ) const { if ( visitor->VisitEnter( *this ) ) { for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() ) { if ( !node->Accept( visitor ) ) break; } } return visitor->VisitExit( *this ); } const TiXmlAttribute* TiXmlAttribute::Next() const { // We are using knowledge of the sentinel. The sentinel // have a value or name. if ( next->value.empty() && next->name.empty() ) return 0; return next; } /* TiXmlAttribute* TiXmlAttribute::Next() { // We are using knowledge of the sentinel. The sentinel // have a value or name. if ( next->value.empty() && next->name.empty() ) return 0; return next; } */ const TiXmlAttribute* TiXmlAttribute::Previous() const { // We are using knowledge of the sentinel. The sentinel // have a value or name. if ( prev->value.empty() && prev->name.empty() ) return 0; return prev; } /* TiXmlAttribute* TiXmlAttribute::Previous() { // We are using knowledge of the sentinel. The sentinel // have a value or name. if ( prev->value.empty() && prev->name.empty() ) return 0; return prev; } */ void TiXmlAttribute::Print( FILE* cfile, int /*depth*/, TIXML_STRING* str ) const { TIXML_STRING n, v; EncodeString( name, &n ); EncodeString( value, &v ); if (value.find ('\"') == TIXML_STRING::npos) { if ( cfile ) { fprintf (cfile, "%s=\"%s\"", n.c_str(), v.c_str() ); } if ( str ) { (*str) += n; (*str) += "=\""; (*str) += v; (*str) += "\""; } } else { if ( cfile ) { fprintf (cfile, "%s='%s'", n.c_str(), v.c_str() ); } if ( str ) { (*str) += n; (*str) += "='"; (*str) += v; (*str) += "'"; } } } int TiXmlAttribute::QueryIntValue( int* ival ) const { if ( TIXML_SSCANF( value.c_str(), "%d", ival ) == 1 ) return TIXML_SUCCESS; return TIXML_WRONG_TYPE; } int TiXmlAttribute::QueryDoubleValue( double* dval ) const { if ( TIXML_SSCANF( value.c_str(), "%lf", dval ) == 1 ) return TIXML_SUCCESS; return TIXML_WRONG_TYPE; } void TiXmlAttribute::SetIntValue( int _value ) { char buf [64]; #if defined(TIXML_SNPRINTF) TIXML_SNPRINTF(buf, sizeof(buf), "%d", _value); #else sprintf (buf, "%d", _value); #endif SetValue (buf); } void TiXmlAttribute::SetDoubleValue( double _value ) { char buf [256]; #if defined(TIXML_SNPRINTF) TIXML_SNPRINTF( buf, sizeof(buf), "%g", _value); #else sprintf (buf, "%g", _value); #endif SetValue (buf); } int TiXmlAttribute::IntValue() const { return atoi (value.c_str ()); } double TiXmlAttribute::DoubleValue() const { return atof (value.c_str ()); } TiXmlComment::TiXmlComment( const TiXmlComment& copy ) : TiXmlNode( TiXmlNode::TINYXML_COMMENT ) { copy.CopyTo( this ); } TiXmlComment& TiXmlComment::operator=( const TiXmlComment& base ) { Clear(); base.CopyTo( this ); return *this; } void TiXmlComment::Print( FILE* cfile, int depth ) const { assert( cfile ); for ( int i=0; i", value.c_str() ); } void TiXmlComment::CopyTo( TiXmlComment* target ) const { TiXmlNode::CopyTo( target ); } bool TiXmlComment::Accept( TiXmlVisitor* visitor ) const { return visitor->Visit( *this ); } TiXmlNode* TiXmlComment::Clone() const { TiXmlComment* clone = new TiXmlComment(); if ( !clone ) return 0; CopyTo( clone ); return clone; } void TiXmlText::Print( FILE* cfile, int depth ) const { assert( cfile ); if ( cdata ) { int i; fprintf( cfile, "\n" ); for ( i=0; i\n", value.c_str() ); // unformatted output } else { TIXML_STRING buffer; EncodeString( value, &buffer ); fprintf( cfile, "%s", buffer.c_str() ); } } void TiXmlText::CopyTo( TiXmlText* target ) const { TiXmlNode::CopyTo( target ); target->cdata = cdata; } bool TiXmlText::Accept( TiXmlVisitor* visitor ) const { return visitor->Visit( *this ); } TiXmlNode* TiXmlText::Clone() const { TiXmlText* clone = 0; clone = new TiXmlText( "" ); if ( !clone ) return 0; CopyTo( clone ); return clone; } TiXmlDeclaration::TiXmlDeclaration( const char * _version, const char * _encoding, const char * _standalone ) : TiXmlNode( TiXmlNode::TINYXML_DECLARATION ) { version = _version; encoding = _encoding; standalone = _standalone; } #ifdef TIXML_USE_STL TiXmlDeclaration::TiXmlDeclaration( const std::string& _version, const std::string& _encoding, const std::string& _standalone ) : TiXmlNode( TiXmlNode::TINYXML_DECLARATION ) { version = _version; encoding = _encoding; standalone = _standalone; } #endif TiXmlDeclaration::TiXmlDeclaration( const TiXmlDeclaration& copy ) : TiXmlNode( TiXmlNode::TINYXML_DECLARATION ) { copy.CopyTo( this ); } TiXmlDeclaration& TiXmlDeclaration::operator=( const TiXmlDeclaration& copy ) { Clear(); copy.CopyTo( this ); return *this; } void TiXmlDeclaration::Print( FILE* cfile, int /*depth*/, TIXML_STRING* str ) const { if ( cfile ) fprintf( cfile, "" ); if ( str ) (*str) += "?>"; } void TiXmlDeclaration::CopyTo( TiXmlDeclaration* target ) const { TiXmlNode::CopyTo( target ); target->version = version; target->encoding = encoding; target->standalone = standalone; } bool TiXmlDeclaration::Accept( TiXmlVisitor* visitor ) const { return visitor->Visit( *this ); } TiXmlNode* TiXmlDeclaration::Clone() const { TiXmlDeclaration* clone = new TiXmlDeclaration(); if ( !clone ) return 0; CopyTo( clone ); return clone; } void TiXmlUnknown::Print( FILE* cfile, int depth ) const { for ( int i=0; i", value.c_str() ); } void TiXmlUnknown::CopyTo( TiXmlUnknown* target ) const { TiXmlNode::CopyTo( target ); } bool TiXmlUnknown::Accept( TiXmlVisitor* visitor ) const { return visitor->Visit( *this ); } TiXmlNode* TiXmlUnknown::Clone() const { TiXmlUnknown* clone = new TiXmlUnknown(); if ( !clone ) return 0; CopyTo( clone ); return clone; } TiXmlAttributeSet::TiXmlAttributeSet() { sentinel.next = &sentinel; sentinel.prev = &sentinel; } TiXmlAttributeSet::~TiXmlAttributeSet() { assert( sentinel.next == &sentinel ); assert( sentinel.prev == &sentinel ); } void TiXmlAttributeSet::Add( TiXmlAttribute* addMe ) { #ifdef TIXML_USE_STL assert( !Find( TIXML_STRING( addMe->Name() ) ) ); // Shouldn't be multiply adding to the set. #else assert( !Find( addMe->Name() ) ); // Shouldn't be multiply adding to the set. #endif addMe->next = &sentinel; addMe->prev = sentinel.prev; sentinel.prev->next = addMe; sentinel.prev = addMe; } void TiXmlAttributeSet::Remove( TiXmlAttribute* removeMe ) { TiXmlAttribute* node; for( node = sentinel.next; node != &sentinel; node = node->next ) { if ( node == removeMe ) { node->prev->next = node->next; node->next->prev = node->prev; node->next = 0; node->prev = 0; return; } } assert( 0 ); // we tried to remove a non-linked attribute. } #ifdef TIXML_USE_STL TiXmlAttribute* TiXmlAttributeSet::Find( const std::string& name ) const { for( TiXmlAttribute* node = sentinel.next; node != &sentinel; node = node->next ) { if ( node->name == name ) return node; } return 0; } TiXmlAttribute* TiXmlAttributeSet::FindOrCreate( const std::string& _name ) { TiXmlAttribute* attrib = Find( _name ); if ( !attrib ) { attrib = new TiXmlAttribute(); Add( attrib ); attrib->SetName( _name ); } return attrib; } #endif TiXmlAttribute* TiXmlAttributeSet::Find( const char* name ) const { for( TiXmlAttribute* node = sentinel.next; node != &sentinel; node = node->next ) { if ( strcmp( node->name.c_str(), name ) == 0 ) return node; } return 0; } TiXmlAttribute* TiXmlAttributeSet::FindOrCreate( const char* _name ) { TiXmlAttribute* attrib = Find( _name ); if ( !attrib ) { attrib = new TiXmlAttribute(); Add( attrib ); attrib->SetName( _name ); } return attrib; } #ifdef TIXML_USE_STL std::istream& operator>> (std::istream & in, TiXmlNode & base) { TIXML_STRING tag; tag.reserve( 8 * 1000 ); base.StreamIn( &in, &tag ); base.Parse( tag.c_str(), 0, TIXML_DEFAULT_ENCODING ); return in; } #endif #ifdef TIXML_USE_STL std::ostream& operator<< (std::ostream & out, const TiXmlNode & base) { TiXmlPrinter printer; printer.SetStreamPrinting(); base.Accept( &printer ); out << printer.Str(); return out; } std::string& operator<< (std::string& out, const TiXmlNode& base ) { TiXmlPrinter printer; printer.SetStreamPrinting(); base.Accept( &printer ); out.append( printer.Str() ); return out; } #endif TiXmlHandle TiXmlHandle::FirstChild() const { if ( node ) { TiXmlNode* child = node->FirstChild(); if ( child ) return TiXmlHandle( child ); } return TiXmlHandle( 0 ); } TiXmlHandle TiXmlHandle::FirstChild( const char * value ) const { if ( node ) { TiXmlNode* child = node->FirstChild( value ); if ( child ) return TiXmlHandle( child ); } return TiXmlHandle( 0 ); } TiXmlHandle TiXmlHandle::FirstChildElement() const { if ( node ) { TiXmlElement* child = node->FirstChildElement(); if ( child ) return TiXmlHandle( child ); } return TiXmlHandle( 0 ); } TiXmlHandle TiXmlHandle::FirstChildElement( const char * value ) const { if ( node ) { TiXmlElement* child = node->FirstChildElement( value ); if ( child ) return TiXmlHandle( child ); } return TiXmlHandle( 0 ); } TiXmlHandle TiXmlHandle::Child( int count ) const { if ( node ) { int i; TiXmlNode* child = node->FirstChild(); for ( i=0; child && iNextSibling(), ++i ) { // nothing } if ( child ) return TiXmlHandle( child ); } return TiXmlHandle( 0 ); } TiXmlHandle TiXmlHandle::Child( const char* value, int count ) const { if ( node ) { int i; TiXmlNode* child = node->FirstChild( value ); for ( i=0; child && iNextSibling( value ), ++i ) { // nothing } if ( child ) return TiXmlHandle( child ); } return TiXmlHandle( 0 ); } TiXmlHandle TiXmlHandle::ChildElement( int count ) const { if ( node ) { int i; TiXmlElement* child = node->FirstChildElement(); for ( i=0; child && iNextSiblingElement(), ++i ) { // nothing } if ( child ) return TiXmlHandle( child ); } return TiXmlHandle( 0 ); } TiXmlHandle TiXmlHandle::ChildElement( const char* value, int count ) const { if ( node ) { int i; TiXmlElement* child = node->FirstChildElement( value ); for ( i=0; child && iNextSiblingElement( value ), ++i ) { // nothing } if ( child ) return TiXmlHandle( child ); } return TiXmlHandle( 0 ); } bool TiXmlPrinter::VisitEnter( const TiXmlDocument& ) { return true; } bool TiXmlPrinter::VisitExit( const TiXmlDocument& ) { return true; } bool TiXmlPrinter::VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute ) { DoIndent(); buffer += "<"; buffer += element.Value(); for( const TiXmlAttribute* attrib = firstAttribute; attrib; attrib = attrib->Next() ) { buffer += " "; attrib->Print( 0, 0, &buffer ); } if ( !element.FirstChild() ) { buffer += " />"; DoLineBreak(); } else { buffer += ">"; if ( element.FirstChild()->ToText() && element.LastChild() == element.FirstChild() && element.FirstChild()->ToText()->CDATA() == false ) { simpleTextPrint = true; // no DoLineBreak()! } else { DoLineBreak(); } } ++depth; return true; } bool TiXmlPrinter::VisitExit( const TiXmlElement& element ) { --depth; if ( !element.FirstChild() ) { // nothing. } else { if ( simpleTextPrint ) { simpleTextPrint = false; } else { DoIndent(); } buffer += ""; DoLineBreak(); } return true; } bool TiXmlPrinter::Visit( const TiXmlText& text ) { if ( text.CDATA() ) { DoIndent(); buffer += ""; DoLineBreak(); } else if ( simpleTextPrint ) { TIXML_STRING str; TiXmlBase::EncodeString( text.ValueTStr(), &str ); buffer += str; } else { DoIndent(); TIXML_STRING str; TiXmlBase::EncodeString( text.ValueTStr(), &str ); buffer += str; DoLineBreak(); } return true; } bool TiXmlPrinter::Visit( const TiXmlDeclaration& declaration ) { DoIndent(); declaration.Print( 0, 0, &buffer ); DoLineBreak(); return true; } bool TiXmlPrinter::Visit( const TiXmlComment& comment ) { DoIndent(); buffer += ""; DoLineBreak(); return true; } bool TiXmlPrinter::Visit( const TiXmlUnknown& unknown ) { DoIndent(); buffer += "<"; buffer += unknown.Value(); buffer += ">"; DoLineBreak(); return true; } ================================================ FILE: src/tinyxml/tinyxml.h ================================================ /* www.sourceforge.net/projects/tinyxml Original code by Lee Thomason (www.grinninglizard.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef TINYXML_INCLUDED #define TINYXML_INCLUDED #ifdef _MSC_VER #pragma warning( push ) #pragma warning( disable : 4530 ) #pragma warning( disable : 4786 ) #endif #include #include #include #include #include // Help out windows: #if defined( _DEBUG ) && !defined( DEBUG ) #define DEBUG #endif #ifdef TIXML_USE_STL #include #include #include #define TIXML_STRING std::string #else #include "tinystr.h" #define TIXML_STRING TiXmlString #endif // Deprecated library function hell. Compilers want to use the // new safe versions. This probably doesn't fully address the problem, // but it gets closer. There are too many compilers for me to fully // test. If you get compilation troubles, undefine TIXML_SAFE #define TIXML_SAFE #ifdef TIXML_SAFE #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) // Microsoft visual studio, version 2005 and higher. #define TIXML_SNPRINTF _snprintf_s #define TIXML_SSCANF sscanf_s #elif defined(_MSC_VER) && (_MSC_VER >= 1200 ) // Microsoft visual studio, version 6 and higher. //#pragma message( "Using _sn* functions." ) #define TIXML_SNPRINTF _snprintf #define TIXML_SSCANF sscanf #elif defined(__GNUC__) && (__GNUC__ >= 3 ) // GCC version 3 and higher.s //#warning( "Using sn* functions." ) #define TIXML_SNPRINTF snprintf #define TIXML_SSCANF sscanf #else #define TIXML_SNPRINTF snprintf #define TIXML_SSCANF sscanf #endif #endif class TiXmlDocument; class TiXmlElement; class TiXmlComment; class TiXmlUnknown; class TiXmlAttribute; class TiXmlText; class TiXmlDeclaration; class TiXmlParsingData; const int TIXML_MAJOR_VERSION = 2; const int TIXML_MINOR_VERSION = 6; const int TIXML_PATCH_VERSION = 2; /* Internal structure for tracking location of items in the XML file. */ struct TiXmlCursor { TiXmlCursor() { Clear(); } void Clear() { row = col = -1; } int row; // 0 based. int col; // 0 based. }; /** Implements the interface to the "Visitor pattern" (see the Accept() method.) If you call the Accept() method, it requires being passed a TiXmlVisitor class to handle callbacks. For nodes that contain other nodes (Document, Element) you will get called with a VisitEnter/VisitExit pair. Nodes that are always leaves are simply called with Visit(). If you return 'true' from a Visit method, recursive parsing will continue. If you return false, no children of this node or its sibilings will be Visited. All flavors of Visit methods have a default implementation that returns 'true' (continue visiting). You need to only override methods that are interesting to you. Generally Accept() is called on the TiXmlDocument, although all nodes suppert Visiting. You should never change the document from a callback. @sa TiXmlNode::Accept() */ class TiXmlVisitor { public: virtual ~TiXmlVisitor() {} /// Visit a document. virtual bool VisitEnter( const TiXmlDocument& /*doc*/ ) { return true; } /// Visit a document. virtual bool VisitExit( const TiXmlDocument& /*doc*/ ) { return true; } /// Visit an element. virtual bool VisitEnter( const TiXmlElement& /*element*/, const TiXmlAttribute* /*firstAttribute*/ ) { return true; } /// Visit an element. virtual bool VisitExit( const TiXmlElement& /*element*/ ) { return true; } /// Visit a declaration virtual bool Visit( const TiXmlDeclaration& /*declaration*/ ) { return true; } /// Visit a text node virtual bool Visit( const TiXmlText& /*text*/ ) { return true; } /// Visit a comment node virtual bool Visit( const TiXmlComment& /*comment*/ ) { return true; } /// Visit an unknown node virtual bool Visit( const TiXmlUnknown& /*unknown*/ ) { return true; } }; // Only used by Attribute::Query functions enum { TIXML_SUCCESS, TIXML_NO_ATTRIBUTE, TIXML_WRONG_TYPE }; // Used by the parsing routines. enum TiXmlEncoding { TIXML_ENCODING_UNKNOWN, TIXML_ENCODING_UTF8, TIXML_ENCODING_LEGACY }; const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN; /** TiXmlBase is a base class for every class in TinyXml. It does little except to establish that TinyXml classes can be printed and provide some utility functions. In XML, the document and elements can contain other elements and other types of nodes. @verbatim A Document can contain: Element (container or leaf) Comment (leaf) Unknown (leaf) Declaration( leaf ) An Element can contain: Element (container or leaf) Text (leaf) Attributes (not on tree) Comment (leaf) Unknown (leaf) A Declaration contains: Attributes (not on tree) @endverbatim */ class TiXmlBase { friend class TiXmlNode; friend class TiXmlElement; friend class TiXmlDocument; public: TiXmlBase() : userData(0) {} virtual ~TiXmlBase() {} /** All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL mode, std::string in STL mode.) Either or both cfile and str can be null. This is a formatted print, and will insert tabs and newlines. (For an unformatted stream, use the << operator.) */ virtual void Print( FILE* cfile, int depth ) const = 0; /** The world does not agree on whether white space should be kept or not. In order to make everyone happy, these global, static functions are provided to set whether or not TinyXml will condense all white space into a single space or not. The default is to condense. Note changing this value is not thread safe. */ static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; } /// Return the current white space setting. static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; } /** Return the position, in the original source file, of this node or attribute. The row and column are 1-based. (That is the first row and first column is 1,1). If the returns values are 0 or less, then the parser does not have a row and column value. Generally, the row and column value will be set when the TiXmlDocument::Load(), TiXmlDocument::LoadFile(), or any TiXmlNode::Parse() is called. It will NOT be set when the DOM was created from operator>>. The values reflect the initial load. Once the DOM is modified programmatically (by adding or changing nodes and attributes) the new values will NOT update to reflect changes in the document. There is a minor performance cost to computing the row and column. Computation can be disabled if TiXmlDocument::SetTabSize() is called with 0 as the value. @sa TiXmlDocument::SetTabSize() */ int Row() const { return location.row + 1; } int Column() const { return location.col + 1; } ///< See Row() void SetUserData( void* user ) { userData = user; } ///< Set a pointer to arbitrary user data. void* GetUserData() { return userData; } ///< Get a pointer to arbitrary user data. const void* GetUserData() const { return userData; } ///< Get a pointer to arbitrary user data. // Table that returns, for a given lead byte, the total number of bytes // in the UTF-8 sequence. static const int utf8ByteTable[256]; virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding /*= TIXML_ENCODING_UNKNOWN */ ) = 0; /** Expands entities in a string. Note this should not contain the tag's '<', '>', etc, or they will be transformed into entities! */ static void EncodeString( const TIXML_STRING& str, TIXML_STRING* out ); enum { TIXML_NO_ERROR = 0, TIXML_ERROR, TIXML_ERROR_OPENING_FILE, TIXML_ERROR_PARSING_ELEMENT, TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME, TIXML_ERROR_READING_ELEMENT_VALUE, TIXML_ERROR_READING_ATTRIBUTES, TIXML_ERROR_PARSING_EMPTY, TIXML_ERROR_READING_END_TAG, TIXML_ERROR_PARSING_UNKNOWN, TIXML_ERROR_PARSING_COMMENT, TIXML_ERROR_PARSING_DECLARATION, TIXML_ERROR_DOCUMENT_EMPTY, TIXML_ERROR_EMBEDDED_NULL, TIXML_ERROR_PARSING_CDATA, TIXML_ERROR_DOCUMENT_TOP_ONLY, TIXML_ERROR_STRING_COUNT }; protected: static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding ); inline static bool IsWhiteSpace( char c ) { return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' ); } inline static bool IsWhiteSpace( int c ) { if ( c < 256 ) return IsWhiteSpace( (char) c ); return false; // Again, only truly correct for English/Latin...but usually works. } #ifdef TIXML_USE_STL static bool StreamWhiteSpace( std::istream * in, TIXML_STRING * tag ); static bool StreamTo( std::istream * in, int character, TIXML_STRING * tag ); #endif /* Reads an XML name into the string provided. Returns a pointer just past the last character of the name, or 0 if the function has an error. */ static const char* ReadName( const char* p, TIXML_STRING* name, TiXmlEncoding encoding ); /* Reads text. Returns a pointer past the given end tag. Wickedly complex options, but it keeps the (sensitive) code in one place. */ static const char* ReadText( const char* in, // where to start TIXML_STRING* text, // the string read bool ignoreWhiteSpace, // whether to keep the white space const char* endTag, // what ends this text bool ignoreCase, // whether to ignore case in the end tag TiXmlEncoding encoding ); // the current encoding // If an entity has been found, transform it into a character. static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding ); // Get a character, while interpreting entities. // The length can be from 0 to 4 bytes. inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding ) { assert( p ); if ( encoding == TIXML_ENCODING_UTF8 ) { *length = utf8ByteTable[ *((const unsigned char*)p) ]; assert( *length >= 0 && *length < 5 ); } else { *length = 1; } if ( *length == 1 ) { if ( *p == '&' ) return GetEntity( p, _value, length, encoding ); *_value = *p; return p+1; } else if ( *length ) { //strncpy( _value, p, *length ); // lots of compilers don't like this function (unsafe), // and the null terminator isn't needed for( int i=0; p[i] && i<*length; ++i ) { _value[i] = p[i]; } return p + (*length); } else { // Not valid text. return 0; } } // Return true if the next characters in the stream are any of the endTag sequences. // Ignore case only works for english, and should only be relied on when comparing // to English words: StringEqual( p, "version", true ) is fine. static bool StringEqual( const char* p, const char* endTag, bool ignoreCase, TiXmlEncoding encoding ); static const char* errorString[ TIXML_ERROR_STRING_COUNT ]; TiXmlCursor location; /// Field containing a generic user pointer void* userData; // None of these methods are reliable for any language except English. // Good for approximation, not great for accuracy. static int IsAlpha( unsigned char anyByte, TiXmlEncoding encoding ); static int IsAlphaNum( unsigned char anyByte, TiXmlEncoding encoding ); inline static int ToLower( int v, TiXmlEncoding encoding ) { if ( encoding == TIXML_ENCODING_UTF8 ) { if ( v < 128 ) return tolower( v ); return v; } else { return tolower( v ); } } static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length ); private: TiXmlBase( const TiXmlBase& ); // not implemented. void operator=( const TiXmlBase& base ); // not allowed. struct Entity { const char* str; unsigned int strLength; char chr; }; enum { NUM_ENTITY = 5, MAX_ENTITY_LENGTH = 6 }; static Entity entity[ NUM_ENTITY ]; static bool condenseWhiteSpace; }; /** The parent class for everything in the Document Object Model. (Except for attributes). Nodes have siblings, a parent, and children. A node can be in a document, or stand on its own. The type of a TiXmlNode can be queried, and it can be cast to its more defined type. */ class TiXmlNode : public TiXmlBase { friend class TiXmlDocument; friend class TiXmlElement; public: #ifdef TIXML_USE_STL /** An input stream operator, for every class. Tolerant of newlines and formatting, but doesn't expect them. */ friend std::istream& operator >> (std::istream& in, TiXmlNode& base); /** An output stream operator, for every class. Note that this outputs without any newlines or formatting, as opposed to Print(), which includes tabs and new lines. The operator<< and operator>> are not completely symmetric. Writing a node to a stream is very well defined. You'll get a nice stream of output, without any extra whitespace or newlines. But reading is not as well defined. (As it always is.) If you create a TiXmlElement (for example) and read that from an input stream, the text needs to define an element or junk will result. This is true of all input streams, but it's worth keeping in mind. A TiXmlDocument will read nodes until it reads a root element, and all the children of that root element. */ friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base); /// Appends the XML node or attribute to a std::string. friend std::string& operator<< (std::string& out, const TiXmlNode& base ); #endif /** The types of XML nodes supported by TinyXml. (All the unsupported types are picked up by UNKNOWN.) */ enum NodeType { TINYXML_DOCUMENT, TINYXML_ELEMENT, TINYXML_COMMENT, TINYXML_UNKNOWN, TINYXML_TEXT, TINYXML_DECLARATION, TINYXML_TYPECOUNT }; virtual ~TiXmlNode(); /** The meaning of 'value' changes for the specific type of TiXmlNode. @verbatim Document: filename of the xml file Element: name of the element Comment: the comment text Unknown: the tag contents Text: the text string @endverbatim The subclasses will wrap this function. */ const char *Value() const { return value.c_str (); } #ifdef TIXML_USE_STL /** Return Value() as a std::string. If you only use STL, this is more efficient than calling Value(). Only available in STL mode. */ const std::string& ValueStr() const { return value; } #endif const TIXML_STRING& ValueTStr() const { return value; } /** Changes the value of the node. Defined as: @verbatim Document: filename of the xml file Element: name of the element Comment: the comment text Unknown: the tag contents Text: the text string @endverbatim */ void SetValue(const char * _value) { value = _value;} #ifdef TIXML_USE_STL /// STL std::string form. void SetValue( const std::string& _value ) { value = _value; } #endif /// Delete all the children of this node. Does not affect 'this'. void Clear(); /// One step up the DOM. TiXmlNode* Parent() { return parent; } const TiXmlNode* Parent() const { return parent; } const TiXmlNode* FirstChild() const { return firstChild; } ///< The first child of this node. Will be null if there are no children. TiXmlNode* FirstChild() { return firstChild; } const TiXmlNode* FirstChild( const char * value ) const; ///< The first child of this node with the matching 'value'. Will be null if none found. /// The first child of this node with the matching 'value'. Will be null if none found. TiXmlNode* FirstChild( const char * _value ) { // Call through to the const version - safe since nothing is changed. Exiting syntax: cast this to a const (always safe) // call the method, cast the return back to non-const. return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->FirstChild( _value )); } const TiXmlNode* LastChild() const { return lastChild; } /// The last child of this node. Will be null if there are no children. TiXmlNode* LastChild() { return lastChild; } const TiXmlNode* LastChild( const char * value ) const; /// The last child of this node matching 'value'. Will be null if there are no children. TiXmlNode* LastChild( const char * _value ) { return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->LastChild( _value )); } #ifdef TIXML_USE_STL const TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); } ///< STL std::string form. TiXmlNode* FirstChild( const std::string& _value ) { return FirstChild (_value.c_str ()); } ///< STL std::string form. const TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); } ///< STL std::string form. TiXmlNode* LastChild( const std::string& _value ) { return LastChild (_value.c_str ()); } ///< STL std::string form. #endif /** An alternate way to walk the children of a node. One way to iterate over nodes is: @verbatim for( child = parent->FirstChild(); child; child = child->NextSibling() ) @endverbatim IterateChildren does the same thing with the syntax: @verbatim child = 0; while( child = parent->IterateChildren( child ) ) @endverbatim IterateChildren takes the previous child as input and finds the next one. If the previous child is null, it returns the first. IterateChildren will return null when done. */ const TiXmlNode* IterateChildren( const TiXmlNode* previous ) const; TiXmlNode* IterateChildren( const TiXmlNode* previous ) { return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( previous ) ); } /// This flavor of IterateChildren searches for children with a particular 'value' const TiXmlNode* IterateChildren( const char * value, const TiXmlNode* previous ) const; TiXmlNode* IterateChildren( const char * _value, const TiXmlNode* previous ) { return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( _value, previous ) ); } #ifdef TIXML_USE_STL const TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) const { return IterateChildren (_value.c_str (), previous); } ///< STL std::string form. TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) { return IterateChildren (_value.c_str (), previous); } ///< STL std::string form. #endif /** Add a new node related to this. Adds a child past the LastChild. Returns a pointer to the new object or NULL if an error occured. */ TiXmlNode* InsertEndChild( const TiXmlNode& addThis ); /** Add a new node related to this. Adds a child past the LastChild. NOTE: the node to be added is passed by pointer, and will be henceforth owned (and deleted) by tinyXml. This method is efficient and avoids an extra copy, but should be used with care as it uses a different memory model than the other insert functions. @sa InsertEndChild */ TiXmlNode* LinkEndChild( TiXmlNode* addThis ); /** Add a new node related to this. Adds a child before the specified child. Returns a pointer to the new object or NULL if an error occured. */ TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis ); /** Add a new node related to this. Adds a child after the specified child. Returns a pointer to the new object or NULL if an error occured. */ TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis ); /** Replace a child of this node. Returns a pointer to the new object or NULL if an error occured. */ TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis ); /// Delete a child of this node. bool RemoveChild( TiXmlNode* removeThis ); /// Navigate to a sibling node. const TiXmlNode* PreviousSibling() const { return prev; } TiXmlNode* PreviousSibling() { return prev; } /// Navigate to a sibling node. const TiXmlNode* PreviousSibling( const char * ) const; TiXmlNode* PreviousSibling( const char *_prev ) { return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->PreviousSibling( _prev ) ); } #ifdef TIXML_USE_STL const TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); } ///< STL std::string form. TiXmlNode* PreviousSibling( const std::string& _value ) { return PreviousSibling (_value.c_str ()); } ///< STL std::string form. const TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); } ///< STL std::string form. TiXmlNode* NextSibling( const std::string& _value) { return NextSibling (_value.c_str ()); } ///< STL std::string form. #endif /// Navigate to a sibling node. const TiXmlNode* NextSibling() const { return next; } TiXmlNode* NextSibling() { return next; } /// Navigate to a sibling node with the given 'value'. const TiXmlNode* NextSibling( const char * ) const; TiXmlNode* NextSibling( const char* _next ) { return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->NextSibling( _next ) ); } /** Convenience function to get through elements. Calls NextSibling and ToElement. Will skip all non-Element nodes. Returns 0 if there is not another element. */ const TiXmlElement* NextSiblingElement() const; TiXmlElement* NextSiblingElement() { return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement() ); } /** Convenience function to get through elements. Calls NextSibling and ToElement. Will skip all non-Element nodes. Returns 0 if there is not another element. */ const TiXmlElement* NextSiblingElement( const char * ) const; TiXmlElement* NextSiblingElement( const char *_next ) { return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement( _next ) ); } #ifdef TIXML_USE_STL const TiXmlElement* NextSiblingElement( const std::string& _value) const { return NextSiblingElement (_value.c_str ()); } ///< STL std::string form. TiXmlElement* NextSiblingElement( const std::string& _value) { return NextSiblingElement (_value.c_str ()); } ///< STL std::string form. #endif /// Convenience function to get through elements. const TiXmlElement* FirstChildElement() const; TiXmlElement* FirstChildElement() { return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement() ); } /// Convenience function to get through elements. const TiXmlElement* FirstChildElement( const char * _value ) const; TiXmlElement* FirstChildElement( const char * _value ) { return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement( _value ) ); } #ifdef TIXML_USE_STL const TiXmlElement* FirstChildElement( const std::string& _value ) const { return FirstChildElement (_value.c_str ()); } ///< STL std::string form. TiXmlElement* FirstChildElement( const std::string& _value ) { return FirstChildElement (_value.c_str ()); } ///< STL std::string form. #endif /** Query the type (as an enumerated value, above) of this node. The possible types are: TINYXML_DOCUMENT, TINYXML_ELEMENT, TINYXML_COMMENT, TINYXML_UNKNOWN, TINYXML_TEXT, and TINYXML_DECLARATION. */ int Type() const { return type; } /** Return a pointer to the Document this node lives in. Returns null if not in a document. */ const TiXmlDocument* GetDocument() const; TiXmlDocument* GetDocument() { return const_cast< TiXmlDocument* >( (const_cast< const TiXmlNode* >(this))->GetDocument() ); } /// Returns true if this node has no children. bool NoChildren() const { return !firstChild; } virtual const TiXmlDocument* ToDocument() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. virtual const TiXmlElement* ToElement() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. virtual const TiXmlComment* ToComment() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. virtual const TiXmlUnknown* ToUnknown() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. virtual const TiXmlText* ToText() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. virtual const TiXmlDeclaration* ToDeclaration() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. virtual TiXmlDocument* ToDocument() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. virtual TiXmlElement* ToElement() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. virtual TiXmlComment* ToComment() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. virtual TiXmlUnknown* ToUnknown() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. virtual TiXmlText* ToText() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. virtual TiXmlDeclaration* ToDeclaration() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. /** Create an exact duplicate of this node and return it. The memory must be deleted by the caller. */ virtual TiXmlNode* Clone() const = 0; /** Accept a hierchical visit the nodes in the TinyXML DOM. Every node in the XML tree will be conditionally visited and the host will be called back via the TiXmlVisitor interface. This is essentially a SAX interface for TinyXML. (Note however it doesn't re-parse the XML for the callbacks, so the performance of TinyXML is unchanged by using this interface versus any other.) The interface has been based on ideas from: - http://www.saxproject.org/ - http://c2.com/cgi/wiki?HierarchicalVisitorPattern Which are both good references for "visiting". An example of using Accept(): @verbatim TiXmlPrinter printer; tinyxmlDoc.Accept( &printer ); const char* xmlcstr = printer.CStr(); @endverbatim */ virtual bool Accept( TiXmlVisitor* visitor ) const = 0; protected: TiXmlNode( NodeType _type ); // Copy to the allocated object. Shared functionality between Clone, Copy constructor, // and the assignment operator. void CopyTo( TiXmlNode* target ) const; #ifdef TIXML_USE_STL // The real work of the input operator. virtual void StreamIn( std::istream* in, TIXML_STRING* tag ) = 0; #endif // Figure out what is at *p, and parse it. Returns null if it is not an xml node. TiXmlNode* Identify( const char* start, TiXmlEncoding encoding ); TiXmlNode* parent; NodeType type; TiXmlNode* firstChild; TiXmlNode* lastChild; TIXML_STRING value; TiXmlNode* prev; TiXmlNode* next; private: TiXmlNode( const TiXmlNode& ); // not implemented. void operator=( const TiXmlNode& base ); // not allowed. }; /** An attribute is a name-value pair. Elements have an arbitrary number of attributes, each with a unique name. @note The attributes are not TiXmlNodes, since they are not part of the tinyXML document object model. There are other suggested ways to look at this problem. */ class TiXmlAttribute : public TiXmlBase { friend class TiXmlAttributeSet; public: /// Construct an empty attribute. TiXmlAttribute() : TiXmlBase() { document = 0; prev = next = 0; } #ifdef TIXML_USE_STL /// std::string constructor. TiXmlAttribute( const std::string& _name, const std::string& _value ) { name = _name; value = _value; document = 0; prev = next = 0; } #endif /// Construct an attribute with a name and value. TiXmlAttribute( const char * _name, const char * _value ) { name = _name; value = _value; document = 0; prev = next = 0; } const char* Name() const { return name.c_str(); } ///< Return the name of this attribute. const char* Value() const { return value.c_str(); } ///< Return the value of this attribute. #ifdef TIXML_USE_STL const std::string& ValueStr() const { return value; } ///< Return the value of this attribute. #endif int IntValue() const; ///< Return the value of this attribute, converted to an integer. double DoubleValue() const; ///< Return the value of this attribute, converted to a double. // Get the tinyxml string representation const TIXML_STRING& NameTStr() const { return name; } /** QueryIntValue examines the value string. It is an alternative to the IntValue() method with richer error checking. If the value is an integer, it is stored in 'value' and the call returns TIXML_SUCCESS. If it is not an integer, it returns TIXML_WRONG_TYPE. A specialized but useful call. Note that for success it returns 0, which is the opposite of almost all other TinyXml calls. */ int QueryIntValue( int* _value ) const; /// QueryDoubleValue examines the value string. See QueryIntValue(). int QueryDoubleValue( double* _value ) const; void SetName( const char* _name ) { name = _name; } ///< Set the name of this attribute. void SetValue( const char* _value ) { value = _value; } ///< Set the value. void SetIntValue( int _value ); ///< Set the value from an integer. void SetDoubleValue( double _value ); ///< Set the value from a double. #ifdef TIXML_USE_STL /// STL std::string form. void SetName( const std::string& _name ) { name = _name; } /// STL std::string form. void SetValue( const std::string& _value ) { value = _value; } #endif /// Get the next sibling attribute in the DOM. Returns null at end. const TiXmlAttribute* Next() const; TiXmlAttribute* Next() { return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Next() ); } /// Get the previous sibling attribute in the DOM. Returns null at beginning. const TiXmlAttribute* Previous() const; TiXmlAttribute* Previous() { return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Previous() ); } bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; } bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; } bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; } /* Attribute parsing starts: first letter of the name returns: the next char after the value end quote */ virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); // Prints this Attribute to a FILE stream. virtual void Print( FILE* cfile, int depth ) const { Print( cfile, depth, 0 ); } void Print( FILE* cfile, int depth, TIXML_STRING* str ) const; // [internal use] // Set the document pointer so the attribute can report errors. void SetDocument( TiXmlDocument* doc ) { document = doc; } private: TiXmlAttribute( const TiXmlAttribute& ); // not implemented. void operator=( const TiXmlAttribute& base ); // not allowed. TiXmlDocument* document; // A pointer back to a document, for error reporting. TIXML_STRING name; TIXML_STRING value; TiXmlAttribute* prev; TiXmlAttribute* next; }; /* A class used to manage a group of attributes. It is only used internally, both by the ELEMENT and the DECLARATION. The set can be changed transparent to the Element and Declaration classes that use it, but NOT transparent to the Attribute which has to implement a next() and previous() method. Which makes it a bit problematic and prevents the use of STL. This version is implemented with circular lists because: - I like circular lists - it demonstrates some independence from the (typical) doubly linked list. */ class TiXmlAttributeSet { public: TiXmlAttributeSet(); ~TiXmlAttributeSet(); void Add( TiXmlAttribute* attribute ); void Remove( TiXmlAttribute* attribute ); const TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; } TiXmlAttribute* First() { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; } const TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; } TiXmlAttribute* Last() { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; } TiXmlAttribute* Find( const char* _name ) const; TiXmlAttribute* FindOrCreate( const char* _name ); # ifdef TIXML_USE_STL TiXmlAttribute* Find( const std::string& _name ) const; TiXmlAttribute* FindOrCreate( const std::string& _name ); # endif private: //*ME: Because of hidden/disabled copy-constructor in TiXmlAttribute (sentinel-element), //*ME: this class must be also use a hidden/disabled copy-constructor !!! TiXmlAttributeSet( const TiXmlAttributeSet& ); // not allowed void operator=( const TiXmlAttributeSet& ); // not allowed (as TiXmlAttribute) TiXmlAttribute sentinel; }; /** The element is a container class. It has a value, the element name, and can contain other elements, text, comments, and unknowns. Elements also contain an arbitrary number of attributes. */ class TiXmlElement : public TiXmlNode { public: /// Construct an element. TiXmlElement (const char * in_value); #ifdef TIXML_USE_STL /// std::string constructor. TiXmlElement( const std::string& _value ); #endif TiXmlElement( const TiXmlElement& ); TiXmlElement& operator=( const TiXmlElement& base ); virtual ~TiXmlElement(); /** Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists. */ const char* Attribute( const char* name ) const; /** Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists. If the attribute exists and can be converted to an integer, the integer value will be put in the return 'i', if 'i' is non-null. */ const char* Attribute( const char* name, int* i ) const; /** Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists. If the attribute exists and can be converted to an double, the double value will be put in the return 'd', if 'd' is non-null. */ const char* Attribute( const char* name, double* d ) const; /** QueryIntAttribute examines the attribute - it is an alternative to the Attribute() method with richer error checking. If the attribute is an integer, it is stored in 'value' and the call returns TIXML_SUCCESS. If it is not an integer, it returns TIXML_WRONG_TYPE. If the attribute does not exist, then TIXML_NO_ATTRIBUTE is returned. */ int QueryIntAttribute( const char* name, int* _value ) const; /// QueryUnsignedAttribute examines the attribute - see QueryIntAttribute(). int QueryUnsignedAttribute( const char* name, unsigned* _value ) const; /** QueryBoolAttribute examines the attribute - see QueryIntAttribute(). Note that '1', 'true', or 'yes' are considered true, while '0', 'false' and 'no' are considered false. */ int QueryBoolAttribute( const char* name, bool* _value ) const; /// QueryDoubleAttribute examines the attribute - see QueryIntAttribute(). int QueryDoubleAttribute( const char* name, double* _value ) const; /// QueryFloatAttribute examines the attribute - see QueryIntAttribute(). int QueryFloatAttribute( const char* name, float* _value ) const { double d; int result = QueryDoubleAttribute( name, &d ); if ( result == TIXML_SUCCESS ) { *_value = (float)d; } return result; } #ifdef TIXML_USE_STL /// QueryStringAttribute examines the attribute - see QueryIntAttribute(). int QueryStringAttribute( const char* name, std::string* _value ) const { const char* cstr = Attribute( name ); if ( cstr ) { *_value = std::string( cstr ); return TIXML_SUCCESS; } return TIXML_NO_ATTRIBUTE; } /** Template form of the attribute query which will try to read the attribute into the specified type. Very easy, very powerful, but be careful to make sure to call this with the correct type. NOTE: This method doesn't work correctly for 'string' types that contain spaces. @return TIXML_SUCCESS, TIXML_WRONG_TYPE, or TIXML_NO_ATTRIBUTE */ template< typename T > int QueryValueAttribute( const std::string& name, T* outValue ) const { const TiXmlAttribute* node = attributeSet.Find( name ); if ( !node ) return TIXML_NO_ATTRIBUTE; std::stringstream sstream( node->ValueStr() ); sstream >> *outValue; if ( !sstream.fail() ) return TIXML_SUCCESS; return TIXML_WRONG_TYPE; } int QueryValueAttribute( const std::string& name, std::string* outValue ) const { const TiXmlAttribute* node = attributeSet.Find( name ); if ( !node ) return TIXML_NO_ATTRIBUTE; *outValue = node->ValueStr(); return TIXML_SUCCESS; } #endif /** Sets an attribute of name to a given value. The attribute will be created if it does not exist, or changed if it does. */ void SetAttribute( const char* name, const char * _value ); #ifdef TIXML_USE_STL const std::string* Attribute( const std::string& name ) const; const std::string* Attribute( const std::string& name, int* i ) const; const std::string* Attribute( const std::string& name, double* d ) const; int QueryIntAttribute( const std::string& name, int* _value ) const; int QueryDoubleAttribute( const std::string& name, double* _value ) const; /// STL std::string form. void SetAttribute( const std::string& name, const std::string& _value ); ///< STL std::string form. void SetAttribute( const std::string& name, int _value ); ///< STL std::string form. void SetDoubleAttribute( const std::string& name, double value ); #endif /** Sets an attribute of name to a given value. The attribute will be created if it does not exist, or changed if it does. */ void SetAttribute( const char * name, int value ); /** Sets an attribute of name to a given value. The attribute will be created if it does not exist, or changed if it does. */ void SetDoubleAttribute( const char * name, double value ); /** Deletes an attribute with the given name. */ void RemoveAttribute( const char * name ); #ifdef TIXML_USE_STL void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); } ///< STL std::string form. #endif const TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); } ///< Access the first attribute in this element. TiXmlAttribute* FirstAttribute() { return attributeSet.First(); } const TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); } ///< Access the last attribute in this element. TiXmlAttribute* LastAttribute() { return attributeSet.Last(); } /** Convenience function for easy access to the text inside an element. Although easy and concise, GetText() is limited compared to getting the TiXmlText child and accessing it directly. If the first child of 'this' is a TiXmlText, the GetText() returns the character string of the Text node, else null is returned. This is a convenient method for getting the text of simple contained text: @verbatim This is text const char* str = fooElement->GetText(); @endverbatim 'str' will be a pointer to "This is text". Note that this function can be misleading. If the element foo was created from this XML: @verbatim This is text @endverbatim then the value of str would be null. The first child node isn't a text node, it is another element. From this XML: @verbatim This is text @endverbatim GetText() will return "This is ". WARNING: GetText() accesses a child node - don't become confused with the similarly named TiXmlHandle::Text() and TiXmlNode::ToText() which are safe type casts on the referenced node. */ const char* GetText() const; /// Creates a new Element and returns it - the returned element is a copy. virtual TiXmlNode* Clone() const; // Print the Element to a FILE stream. virtual void Print( FILE* cfile, int depth ) const; /* Attribute parsing starts: next char past '<' returns: next char past '>' */ virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); virtual const TiXmlElement* ToElement() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. virtual TiXmlElement* ToElement() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. /** Walk the XML tree visiting this node and all of its children. */ virtual bool Accept( TiXmlVisitor* visitor ) const; protected: void CopyTo( TiXmlElement* target ) const; void ClearThis(); // like clear, but initializes 'this' object as well // Used to be public [internal use] #ifdef TIXML_USE_STL virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); #endif /* [internal use] Reads the "value" of the element -- another element, or text. This should terminate with the current end tag. */ const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding ); private: TiXmlAttributeSet attributeSet; }; /** An XML comment. */ class TiXmlComment : public TiXmlNode { public: /// Constructs an empty comment. TiXmlComment() : TiXmlNode( TiXmlNode::TINYXML_COMMENT ) {} /// Construct a comment from text. TiXmlComment( const char* _value ) : TiXmlNode( TiXmlNode::TINYXML_COMMENT ) { SetValue( _value ); } TiXmlComment( const TiXmlComment& ); TiXmlComment& operator=( const TiXmlComment& base ); virtual ~TiXmlComment() {} /// Returns a copy of this Comment. virtual TiXmlNode* Clone() const; // Write this Comment to a FILE stream. virtual void Print( FILE* cfile, int depth ) const; /* Attribute parsing starts: at the ! of the !-- returns: next char past '>' */ virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); virtual const TiXmlComment* ToComment() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. virtual TiXmlComment* ToComment() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. /** Walk the XML tree visiting this node and all of its children. */ virtual bool Accept( TiXmlVisitor* visitor ) const; protected: void CopyTo( TiXmlComment* target ) const; // used to be public #ifdef TIXML_USE_STL virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); #endif // virtual void StreamOut( TIXML_OSTREAM * out ) const; private: }; /** XML text. A text node can have 2 ways to output the next. "normal" output and CDATA. It will default to the mode it was parsed from the XML file and you generally want to leave it alone, but you can change the output mode with SetCDATA() and query it with CDATA(). */ class TiXmlText : public TiXmlNode { friend class TiXmlElement; public: /** Constructor for text element. By default, it is treated as normal, encoded text. If you want it be output as a CDATA text element, set the parameter _cdata to 'true' */ TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TINYXML_TEXT) { SetValue( initValue ); cdata = false; } virtual ~TiXmlText() {} #ifdef TIXML_USE_STL /// Constructor. TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TINYXML_TEXT) { SetValue( initValue ); cdata = false; } #endif TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TINYXML_TEXT ) { copy.CopyTo( this ); } TiXmlText& operator=( const TiXmlText& base ) { base.CopyTo( this ); return *this; } // Write this text object to a FILE stream. virtual void Print( FILE* cfile, int depth ) const; /// Queries whether this represents text using a CDATA section. bool CDATA() const { return cdata; } /// Turns on or off a CDATA representation of text. void SetCDATA( bool _cdata ) { cdata = _cdata; } virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); virtual const TiXmlText* ToText() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. virtual TiXmlText* ToText() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. /** Walk the XML tree visiting this node and all of its children. */ virtual bool Accept( TiXmlVisitor* content ) const; protected : /// [internal use] Creates a new Element and returns it. virtual TiXmlNode* Clone() const; void CopyTo( TiXmlText* target ) const; bool Blank() const; // returns true if all white space and new lines // [internal use] #ifdef TIXML_USE_STL virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); #endif private: bool cdata; // true if this should be input and output as a CDATA style text element }; /** In correct XML the declaration is the first entry in the file. @verbatim @endverbatim TinyXml will happily read or write files without a declaration, however. There are 3 possible attributes to the declaration: version, encoding, and standalone. Note: In this version of the code, the attributes are handled as special cases, not generic attributes, simply because there can only be at most 3 and they are always the same. */ class TiXmlDeclaration : public TiXmlNode { public: /// Construct an empty declaration. TiXmlDeclaration() : TiXmlNode( TiXmlNode::TINYXML_DECLARATION ) {} #ifdef TIXML_USE_STL /// Constructor. TiXmlDeclaration( const std::string& _version, const std::string& _encoding, const std::string& _standalone ); #endif /// Construct. TiXmlDeclaration( const char* _version, const char* _encoding, const char* _standalone ); TiXmlDeclaration( const TiXmlDeclaration& copy ); TiXmlDeclaration& operator=( const TiXmlDeclaration& copy ); virtual ~TiXmlDeclaration() {} /// Version. Will return an empty string if none was found. const char *Version() const { return version.c_str (); } /// Encoding. Will return an empty string if none was found. const char *Encoding() const { return encoding.c_str (); } /// Is this a standalone document? const char *Standalone() const { return standalone.c_str (); } /// Creates a copy of this Declaration and returns it. virtual TiXmlNode* Clone() const; // Print this declaration to a FILE stream. virtual void Print( FILE* cfile, int depth, TIXML_STRING* str ) const; virtual void Print( FILE* cfile, int depth ) const { Print( cfile, depth, 0 ); } virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); virtual const TiXmlDeclaration* ToDeclaration() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. virtual TiXmlDeclaration* ToDeclaration() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. /** Walk the XML tree visiting this node and all of its children. */ virtual bool Accept( TiXmlVisitor* visitor ) const; protected: void CopyTo( TiXmlDeclaration* target ) const; // used to be public #ifdef TIXML_USE_STL virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); #endif private: TIXML_STRING version; TIXML_STRING encoding; TIXML_STRING standalone; }; /** Any tag that tinyXml doesn't recognize is saved as an unknown. It is a tag of text, but should not be modified. It will be written back to the XML, unchanged, when the file is saved. DTD tags get thrown into TiXmlUnknowns. */ class TiXmlUnknown : public TiXmlNode { public: TiXmlUnknown() : TiXmlNode( TiXmlNode::TINYXML_UNKNOWN ) {} virtual ~TiXmlUnknown() {} TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::TINYXML_UNKNOWN ) { copy.CopyTo( this ); } TiXmlUnknown& operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); return *this; } /// Creates a copy of this Unknown and returns it. virtual TiXmlNode* Clone() const; // Print this Unknown to a FILE stream. virtual void Print( FILE* cfile, int depth ) const; virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); virtual const TiXmlUnknown* ToUnknown() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. virtual TiXmlUnknown* ToUnknown() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. /** Walk the XML tree visiting this node and all of its children. */ virtual bool Accept( TiXmlVisitor* content ) const; protected: void CopyTo( TiXmlUnknown* target ) const; #ifdef TIXML_USE_STL virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); #endif private: }; /** Always the top level node. A document binds together all the XML pieces. It can be saved, loaded, and printed to the screen. The 'value' of a document node is the xml file name. */ class TiXmlDocument : public TiXmlNode { public: /// Create an empty document, that has no name. TiXmlDocument(); /// Create a document with a name. The name of the document is also the filename of the xml. TiXmlDocument( const char * documentName ); #ifdef TIXML_USE_STL /// Constructor. TiXmlDocument( const std::string& documentName ); #endif TiXmlDocument( const TiXmlDocument& copy ); TiXmlDocument& operator=( const TiXmlDocument& copy ); virtual ~TiXmlDocument() {} /** Load a file using the current document value. Returns true if successful. Will delete any existing document data before loading. */ bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); /// Save a file using the current document value. Returns true if successful. bool SaveFile() const; /// Load a file using the given filename. Returns true if successful. bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); /// Save a file using the given filename. Returns true if successful. bool SaveFile( const char * filename ) const; /** Load a file using the given FILE*. Returns true if successful. Note that this method doesn't stream - the entire object pointed at by the FILE* will be interpreted as an XML file. TinyXML doesn't stream in XML from the current file location. Streaming may be added in the future. */ bool LoadFile( FILE*, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); /// Save a file using the given FILE*. Returns true if successful. bool SaveFile( FILE* ) const; #ifdef TIXML_USE_STL bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ) ///< STL std::string version. { return LoadFile( filename.c_str(), encoding ); } bool SaveFile( const std::string& filename ) const ///< STL std::string version. { return SaveFile( filename.c_str() ); } #endif /** Parse the given null terminated block of xml data. Passing in an encoding to this method (either TIXML_ENCODING_LEGACY or TIXML_ENCODING_UTF8 will force TinyXml to use that encoding, regardless of what TinyXml might otherwise try to detect. */ virtual const char* Parse( const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); /** Get the root element -- the only top level element -- of the document. In well formed XML, there should only be one. TinyXml is tolerant of multiple elements at the document level. */ const TiXmlElement* RootElement() const { return FirstChildElement(); } TiXmlElement* RootElement() { return FirstChildElement(); } /** If an error occurs, Error will be set to true. Also, - The ErrorId() will contain the integer identifier of the error (not generally useful) - The ErrorDesc() method will return the name of the error. (very useful) - The ErrorRow() and ErrorCol() will return the location of the error (if known) */ bool Error() const { return error; } /// Contains a textual (english) description of the error if one occurs. const char * ErrorDesc() const { return errorDesc.c_str (); } /** Generally, you probably want the error string ( ErrorDesc() ). But if you prefer the ErrorId, this function will fetch it. */ int ErrorId() const { return errorId; } /** Returns the location (if known) of the error. The first column is column 1, and the first row is row 1. A value of 0 means the row and column wasn't applicable (memory errors, for example, have no row/column) or the parser lost the error. (An error in the error reporting, in that case.) @sa SetTabSize, Row, Column */ int ErrorRow() const { return errorLocation.row+1; } int ErrorCol() const { return errorLocation.col+1; } ///< The column where the error occured. See ErrorRow() /** SetTabSize() allows the error reporting functions (ErrorRow() and ErrorCol()) to report the correct values for row and column. It does not change the output or input in any way. By calling this method, with a tab size greater than 0, the row and column of each node and attribute is stored when the file is loaded. Very useful for tracking the DOM back in to the source file. The tab size is required for calculating the location of nodes. If not set, the default of 4 is used. The tabsize is set per document. Setting the tabsize to 0 disables row/column tracking. Note that row and column tracking is not supported when using operator>>. The tab size needs to be enabled before the parse or load. Correct usage: @verbatim TiXmlDocument doc; doc.SetTabSize( 8 ); doc.Load( "myfile.xml" ); @endverbatim @sa Row, Column */ void SetTabSize( int _tabsize ) { tabsize = _tabsize; } int TabSize() const { return tabsize; } /** If you have handled the error, it can be reset with this call. The error state is automatically cleared if you Parse a new XML block. */ void ClearError() { error = false; errorId = 0; errorDesc = ""; errorLocation.row = errorLocation.col = 0; //errorLocation.last = 0; } /** Write the document to standard out using formatted printing ("pretty print"). */ void Print() const { Print( stdout, 0 ); } /* Write the document to a string using formatted printing ("pretty print"). This will allocate a character array (new char[]) and return it as a pointer. The calling code pust call delete[] on the return char* to avoid a memory leak. */ //char* PrintToMemory() const; /// Print this Document to a FILE stream. virtual void Print( FILE* cfile, int depth = 0 ) const; // [internal use] void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding ); virtual const TiXmlDocument* ToDocument() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. virtual TiXmlDocument* ToDocument() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. /** Walk the XML tree visiting this node and all of its children. */ virtual bool Accept( TiXmlVisitor* content ) const; protected : // [internal use] virtual TiXmlNode* Clone() const; #ifdef TIXML_USE_STL virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); #endif private: void CopyTo( TiXmlDocument* target ) const; bool error; int errorId; TIXML_STRING errorDesc; int tabsize; TiXmlCursor errorLocation; bool useMicrosoftBOM; // the UTF-8 BOM were found when read. Note this, and try to write. }; /** A TiXmlHandle is a class that wraps a node pointer with null checks; this is an incredibly useful thing. Note that TiXmlHandle is not part of the TinyXml DOM structure. It is a separate utility class. Take an example: @verbatim @endverbatim Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very easy to write a *lot* of code that looks like: @verbatim TiXmlElement* root = document.FirstChildElement( "Document" ); if ( root ) { TiXmlElement* element = root->FirstChildElement( "Element" ); if ( element ) { TiXmlElement* child = element->FirstChildElement( "Child" ); if ( child ) { TiXmlElement* child2 = child->NextSiblingElement( "Child" ); if ( child2 ) { // Finally do something useful. @endverbatim And that doesn't even cover "else" cases. TiXmlHandle addresses the verbosity of such code. A TiXmlHandle checks for null pointers so it is perfectly safe and correct to use: @verbatim TiXmlHandle docHandle( &document ); TiXmlElement* child2 = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", 1 ).ToElement(); if ( child2 ) { // do something useful @endverbatim Which is MUCH more concise and useful. It is also safe to copy handles - internally they are nothing more than node pointers. @verbatim TiXmlHandle handleCopy = handle; @endverbatim What they should not be used for is iteration: @verbatim int i=0; while ( true ) { TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", i ).ToElement(); if ( !child ) break; // do something ++i; } @endverbatim It seems reasonable, but it is in fact two embedded while loops. The Child method is a linear walk to find the element, so this code would iterate much more than it needs to. Instead, prefer: @verbatim TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).FirstChild( "Child" ).ToElement(); for( child; child; child=child->NextSiblingElement() ) { // do something } @endverbatim */ class TiXmlHandle { public: /// Create a handle from any node (at any depth of the tree.) This can be a null pointer. TiXmlHandle( TiXmlNode* _node ) { this->node = _node; } /// Copy constructor TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; } TiXmlHandle operator=( const TiXmlHandle& ref ) { if ( &ref != this ) this->node = ref.node; return *this; } /// Return a handle to the first child node. TiXmlHandle FirstChild() const; /// Return a handle to the first child node with the given name. TiXmlHandle FirstChild( const char * value ) const; /// Return a handle to the first child element. TiXmlHandle FirstChildElement() const; /// Return a handle to the first child element with the given name. TiXmlHandle FirstChildElement( const char * value ) const; /** Return a handle to the "index" child with the given name. The first child is 0, the second 1, etc. */ TiXmlHandle Child( const char* value, int index ) const; /** Return a handle to the "index" child. The first child is 0, the second 1, etc. */ TiXmlHandle Child( int index ) const; /** Return a handle to the "index" child element with the given name. The first child element is 0, the second 1, etc. Note that only TiXmlElements are indexed: other types are not counted. */ TiXmlHandle ChildElement( const char* value, int index ) const; /** Return a handle to the "index" child element. The first child element is 0, the second 1, etc. Note that only TiXmlElements are indexed: other types are not counted. */ TiXmlHandle ChildElement( int index ) const; #ifdef TIXML_USE_STL TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); } TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); } TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); } TiXmlHandle ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); } #endif /** Return the handle as a TiXmlNode. This may return null. */ TiXmlNode* ToNode() const { return node; } /** Return the handle as a TiXmlElement. This may return null. */ TiXmlElement* ToElement() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); } /** Return the handle as a TiXmlText. This may return null. */ TiXmlText* ToText() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); } /** Return the handle as a TiXmlUnknown. This may return null. */ TiXmlUnknown* ToUnknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); } /** @deprecated use ToNode. Return the handle as a TiXmlNode. This may return null. */ TiXmlNode* Node() const { return ToNode(); } /** @deprecated use ToElement. Return the handle as a TiXmlElement. This may return null. */ TiXmlElement* Element() const { return ToElement(); } /** @deprecated use ToText() Return the handle as a TiXmlText. This may return null. */ TiXmlText* Text() const { return ToText(); } /** @deprecated use ToUnknown() Return the handle as a TiXmlUnknown. This may return null. */ TiXmlUnknown* Unknown() const { return ToUnknown(); } private: TiXmlNode* node; }; /** Print to memory functionality. The TiXmlPrinter is useful when you need to: -# Print to memory (especially in non-STL mode) -# Control formatting (line endings, etc.) When constructed, the TiXmlPrinter is in its default "pretty printing" mode. Before calling Accept() you can call methods to control the printing of the XML document. After TiXmlNode::Accept() is called, the printed document can be accessed via the CStr(), Str(), and Size() methods. TiXmlPrinter uses the Visitor API. @verbatim TiXmlPrinter printer; printer.SetIndent( "\t" ); doc.Accept( &printer ); fprintf( stdout, "%s", printer.CStr() ); @endverbatim */ class TiXmlPrinter : public TiXmlVisitor { public: TiXmlPrinter() : depth( 0 ), simpleTextPrint( false ), buffer(), indent( " " ), lineBreak( "\n" ) {} virtual bool VisitEnter( const TiXmlDocument& doc ); virtual bool VisitExit( const TiXmlDocument& doc ); virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute ); virtual bool VisitExit( const TiXmlElement& element ); virtual bool Visit( const TiXmlDeclaration& declaration ); virtual bool Visit( const TiXmlText& text ); virtual bool Visit( const TiXmlComment& comment ); virtual bool Visit( const TiXmlUnknown& unknown ); /** Set the indent characters for printing. By default 4 spaces but tab (\t) is also useful, or null/empty string for no indentation. */ void SetIndent( const char* _indent ) { indent = _indent ? _indent : "" ; } /// Query the indention string. const char* Indent() { return indent.c_str(); } /** Set the line breaking string. By default set to newline (\n). Some operating systems prefer other characters, or can be set to the null/empty string for no indenation. */ void SetLineBreak( const char* _lineBreak ) { lineBreak = _lineBreak ? _lineBreak : ""; } /// Query the current line breaking string. const char* LineBreak() { return lineBreak.c_str(); } /** Switch over to "stream printing" which is the most dense formatting without linebreaks. Common when the XML is needed for network transmission. */ void SetStreamPrinting() { indent = ""; lineBreak = ""; } /// Return the result. const char* CStr() { return buffer.c_str(); } /// Return the length of the result string. size_t Size() { return buffer.size(); } #ifdef TIXML_USE_STL /// Return the result. const std::string& Str() { return buffer; } #endif private: void DoIndent() { for( int i=0; i #include #include "tinyxml.h" //#define DEBUG_PARSER #if defined( DEBUG_PARSER ) # if defined( DEBUG ) && defined( _MSC_VER ) # include # define TIXML_LOG OutputDebugString # else # define TIXML_LOG printf # endif #endif // Note that "PutString" hardcodes the same list. This // is less flexible than it appears. Changing the entries // or order will break putstring. TiXmlBase::Entity TiXmlBase::entity[ TiXmlBase::NUM_ENTITY ] = { { "&", 5, '&' }, { "<", 4, '<' }, { ">", 4, '>' }, { """, 6, '\"' }, { "'", 6, '\'' } }; // Bunch of unicode info at: // http://www.unicode.org/faq/utf_bom.html // Including the basic of this table, which determines the #bytes in the // sequence from the lead byte. 1 placed for invalid sequences -- // although the result will be junk, pass it through as much as possible. // Beware of the non-characters in UTF-8: // ef bb bf (Microsoft "lead bytes") // ef bf be // ef bf bf const unsigned char TIXML_UTF_LEAD_0 = 0xefU; const unsigned char TIXML_UTF_LEAD_1 = 0xbbU; const unsigned char TIXML_UTF_LEAD_2 = 0xbfU; const int TiXmlBase::utf8ByteTable[256] = { // 0 1 2 3 4 5 6 7 8 9 a b c d e f 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x00 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x10 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x20 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x30 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x40 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x50 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x60 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x70 End of ASCII range 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x80 0x80 to 0xc1 invalid 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x90 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0xa0 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0xb0 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xc0 0xc2 to 0xdf 2 byte 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xd0 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, // 0xe0 0xe0 to 0xef 3 byte 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // 0xf0 0xf0 to 0xf4 4 byte, 0xf5 and higher invalid }; void TiXmlBase::ConvertUTF32ToUTF8( unsigned long input, char* output, int* length ) { const unsigned long BYTE_MASK = 0xBF; const unsigned long BYTE_MARK = 0x80; const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; if (input < 0x80) *length = 1; else if ( input < 0x800 ) *length = 2; else if ( input < 0x10000 ) *length = 3; else if ( input < 0x200000 ) *length = 4; else { *length = 0; return; } // This code won't covert this correctly anyway. output += *length; // Scary scary fall throughs. switch (*length) { case 4: --output; *output = (char)((input | BYTE_MARK) & BYTE_MASK); input >>= 6; case 3: --output; *output = (char)((input | BYTE_MARK) & BYTE_MASK); input >>= 6; case 2: --output; *output = (char)((input | BYTE_MARK) & BYTE_MASK); input >>= 6; case 1: --output; *output = (char)(input | FIRST_BYTE_MARK[*length]); } } /*static*/ int TiXmlBase::IsAlpha( unsigned char anyByte, TiXmlEncoding /*encoding*/ ) { // This will only work for low-ascii, everything else is assumed to be a valid // letter. I'm not sure this is the best approach, but it is quite tricky trying // to figure out alphabetical vs. not across encoding. So take a very // conservative approach. // if ( encoding == TIXML_ENCODING_UTF8 ) // { if ( anyByte < 127 ) return isalpha( anyByte ); else return 1; // What else to do? The unicode set is huge...get the english ones right. // } // else // { // return isalpha( anyByte ); // } } /*static*/ int TiXmlBase::IsAlphaNum( unsigned char anyByte, TiXmlEncoding /*encoding*/ ) { // This will only work for low-ascii, everything else is assumed to be a valid // letter. I'm not sure this is the best approach, but it is quite tricky trying // to figure out alphabetical vs. not across encoding. So take a very // conservative approach. // if ( encoding == TIXML_ENCODING_UTF8 ) // { if ( anyByte < 127 ) return isalnum( anyByte ); else return 1; // What else to do? The unicode set is huge...get the english ones right. // } // else // { // return isalnum( anyByte ); // } } class TiXmlParsingData { friend class TiXmlDocument; public: void Stamp( const char* now, TiXmlEncoding encoding ); const TiXmlCursor& Cursor() const { return cursor; } private: // Only used by the document! TiXmlParsingData( const char* start, int _tabsize, int row, int col ) { assert( start ); stamp = start; tabsize = _tabsize; cursor.row = row; cursor.col = col; } TiXmlCursor cursor; const char* stamp; int tabsize; }; void TiXmlParsingData::Stamp( const char* now, TiXmlEncoding encoding ) { assert( now ); // Do nothing if the tabsize is 0. if ( tabsize < 1 ) { return; } // Get the current row, column. int row = cursor.row; int col = cursor.col; const char* p = stamp; assert( p ); while ( p < now ) { // Treat p as unsigned, so we have a happy compiler. const unsigned char* pU = (const unsigned char*)p; // Code contributed by Fletcher Dunn: (modified by lee) switch (*pU) { case 0: // We *should* never get here, but in case we do, don't // advance past the terminating null character, ever return; case '\r': // bump down to the next line ++row; col = 0; // Eat the character ++p; // Check for \r\n sequence, and treat this as a single character if (*p == '\n') { ++p; } break; case '\n': // bump down to the next line ++row; col = 0; // Eat the character ++p; // Check for \n\r sequence, and treat this as a single // character. (Yes, this bizarre thing does occur still // on some arcane platforms...) if (*p == '\r') { ++p; } break; case '\t': // Eat the character ++p; // Skip to next tab stop col = (col / tabsize + 1) * tabsize; break; case TIXML_UTF_LEAD_0: if ( encoding == TIXML_ENCODING_UTF8 ) { if ( *(p+1) && *(p+2) ) { // In these cases, don't advance the column. These are // 0-width spaces. if ( *(pU+1)==TIXML_UTF_LEAD_1 && *(pU+2)==TIXML_UTF_LEAD_2 ) p += 3; else if ( *(pU+1)==0xbfU && *(pU+2)==0xbeU ) p += 3; else if ( *(pU+1)==0xbfU && *(pU+2)==0xbfU ) p += 3; else { p +=3; ++col; } // A normal character. } } else { ++p; ++col; } break; default: if ( encoding == TIXML_ENCODING_UTF8 ) { // Eat the 1 to 4 byte utf8 character. int step = TiXmlBase::utf8ByteTable[*((const unsigned char*)p)]; if ( step == 0 ) step = 1; // Error case from bad encoding, but handle gracefully. p += step; // Just advance one column, of course. ++col; } else { ++p; ++col; } break; } } cursor.row = row; cursor.col = col; assert( cursor.row >= -1 ); assert( cursor.col >= -1 ); stamp = p; assert( stamp ); } const char* TiXmlBase::SkipWhiteSpace( const char* p, TiXmlEncoding encoding ) { if ( !p || !*p ) { return 0; } if ( encoding == TIXML_ENCODING_UTF8 ) { while ( *p ) { const unsigned char* pU = (const unsigned char*)p; // Skip the stupid Microsoft UTF-8 Byte order marks if ( *(pU+0)==TIXML_UTF_LEAD_0 && *(pU+1)==TIXML_UTF_LEAD_1 && *(pU+2)==TIXML_UTF_LEAD_2 ) { p += 3; continue; } else if(*(pU+0)==TIXML_UTF_LEAD_0 && *(pU+1)==0xbfU && *(pU+2)==0xbeU ) { p += 3; continue; } else if(*(pU+0)==TIXML_UTF_LEAD_0 && *(pU+1)==0xbfU && *(pU+2)==0xbfU ) { p += 3; continue; } if ( IsWhiteSpace( *p ) ) // Still using old rules for white space. ++p; else break; } } else { while ( *p && IsWhiteSpace( *p ) ) ++p; } return p; } #ifdef TIXML_USE_STL /*static*/ bool TiXmlBase::StreamWhiteSpace( std::istream * in, TIXML_STRING * tag ) { for( ;; ) { if ( !in->good() ) return false; int c = in->peek(); // At this scope, we can't get to a document. So fail silently. if ( !IsWhiteSpace( c ) || c <= 0 ) return true; *tag += (char) in->get(); } } /*static*/ bool TiXmlBase::StreamTo( std::istream * in, int character, TIXML_STRING * tag ) { //assert( character > 0 && character < 128 ); // else it won't work in utf-8 while ( in->good() ) { int c = in->peek(); if ( c == character ) return true; if ( c <= 0 ) // Silent failure: can't get document at this scope return false; in->get(); *tag += (char) c; } return false; } #endif // One of TinyXML's more performance demanding functions. Try to keep the memory overhead down. The // "assign" optimization removes over 10% of the execution time. // const char* TiXmlBase::ReadName( const char* p, TIXML_STRING * name, TiXmlEncoding encoding ) { // Oddly, not supported on some compilers, //name->clear(); // So use this: *name = ""; assert( p ); // Names start with letters or underscores. // Of course, in unicode, tinyxml has no idea what a letter *is*. The // algorithm is generous. // // After that, they can be letters, underscores, numbers, // hyphens, or colons. (Colons are valid only for namespaces, // but tinyxml can't tell namespaces from names.) if ( p && *p && ( IsAlpha( (unsigned char) *p, encoding ) || *p == '_' ) ) { const char* start = p; while( p && *p && ( IsAlphaNum( (unsigned char ) *p, encoding ) || *p == '_' || *p == '-' || *p == '.' || *p == ':' ) ) { //(*name) += *p; // expensive ++p; } if ( p-start > 0 ) { name->assign( start, p-start ); } return p; } return 0; } const char* TiXmlBase::GetEntity( const char* p, char* value, int* length, TiXmlEncoding encoding ) { // Presume an entity, and pull it out. TIXML_STRING ent; int i; *length = 0; if ( *(p+1) && *(p+1) == '#' && *(p+2) ) { unsigned long ucs = 0; ptrdiff_t delta = 0; unsigned mult = 1; if ( *(p+2) == 'x' ) { // Hexadecimal. if ( !*(p+3) ) return 0; const char* q = p+3; q = strchr( q, ';' ); if ( !q || !*q ) return 0; delta = q-p; --q; while ( *q != 'x' ) { if ( *q >= '0' && *q <= '9' ) ucs += mult * (*q - '0'); else if ( *q >= 'a' && *q <= 'f' ) ucs += mult * (*q - 'a' + 10); else if ( *q >= 'A' && *q <= 'F' ) ucs += mult * (*q - 'A' + 10 ); else return 0; mult *= 16; --q; } } else { // Decimal. if ( !*(p+2) ) return 0; const char* q = p+2; q = strchr( q, ';' ); if ( !q || !*q ) return 0; delta = q-p; --q; while ( *q != '#' ) { if ( *q >= '0' && *q <= '9' ) ucs += mult * (*q - '0'); else return 0; mult *= 10; --q; } } if ( encoding == TIXML_ENCODING_UTF8 ) { // convert the UCS to UTF-8 ConvertUTF32ToUTF8( ucs, value, length ); } else { *value = (char)ucs; *length = 1; } return p + delta + 1; } // Now try to match it. for( i=0; iappend( cArr, len ); } } else { bool whitespace = false; // Remove leading white space: p = SkipWhiteSpace( p, encoding ); while ( p && *p && !StringEqual( p, endTag, caseInsensitive, encoding ) ) { if ( *p == '\r' || *p == '\n' ) { whitespace = true; ++p; } else if ( IsWhiteSpace( *p ) ) { whitespace = true; ++p; } else { // If we've found whitespace, add it before the // new character. Any whitespace just becomes a space. if ( whitespace ) { (*text) += ' '; whitespace = false; } int len; char cArr[4] = { 0, 0, 0, 0 }; p = GetChar( p, cArr, &len, encoding ); if ( len == 1 ) (*text) += cArr[0]; // more efficient else text->append( cArr, len ); } } } if ( p && *p ) p += strlen( endTag ); return ( p && *p ) ? p : 0; } #ifdef TIXML_USE_STL void TiXmlDocument::StreamIn( std::istream * in, TIXML_STRING * tag ) { // The basic issue with a document is that we don't know what we're // streaming. Read something presumed to be a tag (and hope), then // identify it, and call the appropriate stream method on the tag. // // This "pre-streaming" will never read the closing ">" so the // sub-tag can orient itself. if ( !StreamTo( in, '<', tag ) ) { SetError( TIXML_ERROR_PARSING_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); return; } while ( in->good() ) { int tagIndex = (int) tag->length(); while ( in->good() && in->peek() != '>' ) { int c = in->get(); if ( c <= 0 ) { SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN ); break; } (*tag) += (char) c; } if ( in->good() ) { // We now have something we presume to be a node of // some sort. Identify it, and call the node to // continue streaming. TiXmlNode* node = Identify( tag->c_str() + tagIndex, TIXML_DEFAULT_ENCODING ); if ( node ) { node->StreamIn( in, tag ); bool isElement = node->ToElement() != 0; delete node; node = 0; // If this is the root element, we're done. Parsing will be // done by the >> operator. if ( isElement ) { return; } } else { SetError( TIXML_ERROR, 0, 0, TIXML_ENCODING_UNKNOWN ); return; } } } // We should have returned sooner. SetError( TIXML_ERROR, 0, 0, TIXML_ENCODING_UNKNOWN ); } #endif const char* TiXmlDocument::Parse( const char* p, TiXmlParsingData* prevData, TiXmlEncoding encoding ) { ClearError(); // Parse away, at the document level. Since a document // contains nothing but other tags, most of what happens // here is skipping white space. if ( !p || !*p ) { SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); return 0; } // Note that, for a document, this needs to come // before the while space skip, so that parsing // starts from the pointer we are given. location.Clear(); if ( prevData ) { location.row = prevData->cursor.row; location.col = prevData->cursor.col; } else { location.row = 0; location.col = 0; } TiXmlParsingData data( p, TabSize(), location.row, location.col ); location = data.Cursor(); if ( encoding == TIXML_ENCODING_UNKNOWN ) { // Check for the Microsoft UTF-8 lead bytes. const unsigned char* pU = (const unsigned char*)p; if ( *(pU+0) && *(pU+0) == TIXML_UTF_LEAD_0 && *(pU+1) && *(pU+1) == TIXML_UTF_LEAD_1 && *(pU+2) && *(pU+2) == TIXML_UTF_LEAD_2 ) { encoding = TIXML_ENCODING_UTF8; useMicrosoftBOM = true; } } p = SkipWhiteSpace( p, encoding ); if ( !p ) { SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); return 0; } while ( p && *p ) { TiXmlNode* node = Identify( p, encoding ); if ( node ) { p = node->Parse( p, &data, encoding ); LinkEndChild( node ); } else { break; } // Did we get encoding info? if ( encoding == TIXML_ENCODING_UNKNOWN && node->ToDeclaration() ) { TiXmlDeclaration* dec = node->ToDeclaration(); const char* enc = dec->Encoding(); assert( enc ); if ( *enc == 0 ) encoding = TIXML_ENCODING_UTF8; else if ( StringEqual( enc, "UTF-8", true, TIXML_ENCODING_UNKNOWN ) ) encoding = TIXML_ENCODING_UTF8; else if ( StringEqual( enc, "UTF8", true, TIXML_ENCODING_UNKNOWN ) ) encoding = TIXML_ENCODING_UTF8; // incorrect, but be nice else encoding = TIXML_ENCODING_LEGACY; } p = SkipWhiteSpace( p, encoding ); } // Was this empty? if ( !firstChild ) { SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, encoding ); return 0; } // All is well. return p; } void TiXmlDocument::SetError( int err, const char* pError, TiXmlParsingData* data, TiXmlEncoding encoding ) { // The first error in a chain is more accurate - don't set again! if ( error ) return; assert( err > 0 && err < TIXML_ERROR_STRING_COUNT ); error = true; errorId = err; errorDesc = errorString[ errorId ]; errorLocation.Clear(); if ( pError && data ) { data->Stamp( pError, encoding ); errorLocation = data->Cursor(); } } TiXmlNode* TiXmlNode::Identify( const char* p, TiXmlEncoding encoding ) { TiXmlNode* returnNode = 0; p = SkipWhiteSpace( p, encoding ); if( !p || !*p || *p != '<' ) { return 0; } p = SkipWhiteSpace( p, encoding ); if ( !p || !*p ) { return 0; } // What is this thing? // - Elements start with a letter or underscore, but xml is reserved. // - Comments: "; if ( !StringEqual( p, startTag, false, encoding ) ) { if ( document ) document->SetError( TIXML_ERROR_PARSING_COMMENT, p, data, encoding ); return 0; } p += strlen( startTag ); // [ 1475201 ] TinyXML parses entities in comments // Oops - ReadText doesn't work, because we don't want to parse the entities. // p = ReadText( p, &value, false, endTag, false, encoding ); // // from the XML spec: /* [Definition: Comments may appear anywhere in a document outside other markup; in addition, they may appear within the document type declaration at places allowed by the grammar. They are not part of the document's character data; an XML processor MAY, but need not, make it possible for an application to retrieve the text of comments. For compatibility, the string "--" (double-hyphen) MUST NOT occur within comments.] Parameter entity references MUST NOT be recognized within comments. An example of a comment: */ value = ""; // Keep all the white space. while ( p && *p && !StringEqual( p, endTag, false, encoding ) ) { value.append( p, 1 ); ++p; } if ( p && *p ) p += strlen( endTag ); return p; } const char* TiXmlAttribute::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ) { p = SkipWhiteSpace( p, encoding ); if ( !p || !*p ) return 0; if ( data ) { data->Stamp( p, encoding ); location = data->Cursor(); } // Read the name, the '=' and the value. const char* pErr = p; p = ReadName( p, &name, encoding ); if ( !p || !*p ) { if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, pErr, data, encoding ); return 0; } p = SkipWhiteSpace( p, encoding ); if ( !p || !*p || *p != '=' ) { if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding ); return 0; } ++p; // skip '=' p = SkipWhiteSpace( p, encoding ); if ( !p || !*p ) { if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding ); return 0; } const char* end; const char SINGLE_QUOTE = '\''; const char DOUBLE_QUOTE = '\"'; if ( *p == SINGLE_QUOTE ) { ++p; end = "\'"; // single quote in string p = ReadText( p, &value, false, end, false, encoding ); } else if ( *p == DOUBLE_QUOTE ) { ++p; end = "\""; // double quote in string p = ReadText( p, &value, false, end, false, encoding ); } else { // All attribute values should be in single or double quotes. // But this is such a common error that the parser will try // its best, even without them. value = ""; while ( p && *p // existence && !IsWhiteSpace( *p ) // whitespace && *p != '/' && *p != '>' ) // tag end { if ( *p == SINGLE_QUOTE || *p == DOUBLE_QUOTE ) { // [ 1451649 ] Attribute values with trailing quotes not handled correctly // We did not have an opening quote but seem to have a // closing one. Give up and throw an error. if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding ); return 0; } value += *p; ++p; } } return p; } #ifdef TIXML_USE_STL void TiXmlText::StreamIn( std::istream * in, TIXML_STRING * tag ) { while ( in->good() ) { int c = in->peek(); if ( !cdata && (c == '<' ) ) { return; } if ( c <= 0 ) { TiXmlDocument* document = GetDocument(); if ( document ) document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN ); return; } (*tag) += (char) c; in->get(); // "commits" the peek made above if ( cdata && c == '>' && tag->size() >= 3 ) { size_t len = tag->size(); if ( (*tag)[len-2] == ']' && (*tag)[len-3] == ']' ) { // terminator of cdata. return; } } } } #endif const char* TiXmlText::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ) { value = ""; TiXmlDocument* document = GetDocument(); if ( data ) { data->Stamp( p, encoding ); location = data->Cursor(); } const char* const startTag = ""; if ( cdata || StringEqual( p, startTag, false, encoding ) ) { cdata = true; if ( !StringEqual( p, startTag, false, encoding ) ) { if ( document ) document->SetError( TIXML_ERROR_PARSING_CDATA, p, data, encoding ); return 0; } p += strlen( startTag ); // Keep all the white space, ignore the encoding, etc. while ( p && *p && !StringEqual( p, endTag, false, encoding ) ) { value += *p; ++p; } TIXML_STRING dummy; p = ReadText( p, &dummy, false, endTag, false, encoding ); return p; } else { bool ignoreWhite = true; const char* end = "<"; p = ReadText( p, &value, ignoreWhite, end, false, encoding ); if ( p && *p ) return p-1; // don't truncate the '<' return 0; } } #ifdef TIXML_USE_STL void TiXmlDeclaration::StreamIn( std::istream * in, TIXML_STRING * tag ) { while ( in->good() ) { int c = in->get(); if ( c <= 0 ) { TiXmlDocument* document = GetDocument(); if ( document ) document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN ); return; } (*tag) += (char) c; if ( c == '>' ) { // All is well. return; } } } #endif const char* TiXmlDeclaration::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding _encoding ) { p = SkipWhiteSpace( p, _encoding ); // Find the beginning, find the end, and look for // the stuff in-between. TiXmlDocument* document = GetDocument(); if ( !p || !*p || !StringEqual( p, "SetError( TIXML_ERROR_PARSING_DECLARATION, 0, 0, _encoding ); return 0; } if ( data ) { data->Stamp( p, _encoding ); location = data->Cursor(); } p += 5; version = ""; encoding = ""; standalone = ""; while ( p && *p ) { if ( *p == '>' ) { ++p; return p; } p = SkipWhiteSpace( p, _encoding ); if ( StringEqual( p, "version", true, _encoding ) ) { TiXmlAttribute attrib; p = attrib.Parse( p, data, _encoding ); version = attrib.Value(); } else if ( StringEqual( p, "encoding", true, _encoding ) ) { TiXmlAttribute attrib; p = attrib.Parse( p, data, _encoding ); encoding = attrib.Value(); } else if ( StringEqual( p, "standalone", true, _encoding ) ) { TiXmlAttribute attrib; p = attrib.Parse( p, data, _encoding ); standalone = attrib.Value(); } else { // Read over whatever it is. while( p && *p && *p != '>' && !IsWhiteSpace( *p ) ) ++p; } } return 0; } bool TiXmlText::Blank() const { for ( unsigned i=0; i. */ #include "user.h" float gGourceBeamDist = 100.0; float gGourceActionDist = 50.0; float gGourcePersonalSpaceDist = 100.0; RUser::RUser(const std::string& name, vec2 pos, int tagid) : Pawn(name,pos,tagid) { this->name = name; speed = gGourceSettings.max_user_speed; size = 20.0 * gGourceSettings.user_scale; shadowOffset = vec2(2.0, 2.0) * gGourceSettings.user_scale; shadow = true; highlighted=false; assignUserImage(); setSelected(false); last_action = 0.0; action_interval = 0.2; name_interval = 5.0; min_units_ps = 100.0; actionCount = activeCount = 0; } void RUser::addAction(RAction* action) { if(action->source != this) return; if(isIdle()) showName(); //name_interval = name_interval > 0.0 ? std::max(name_interval,nametime-1.0f) : nametime; actions.push_back(action); actionCount++; } // remove references to this file void RUser::fileRemoved(RFile* f) { for(std::list::iterator it = actions.begin(); it != actions.end(); ) { RAction* a = *it; if(a->target == f) { it = actions.erase(it); delete a; actionCount--; continue; } it++; } for(std::list::iterator it = activeActions.begin(); it != activeActions.end(); ) { RAction* a = *it; if(a->target == f) { it = activeActions.erase(it); delete a; continue; } it++; } } void RUser::applyForceUser(RUser* u) { if(u==this) return; vec2 u_pos = u->getPos(); vec2 dir = u_pos - pos; float dist = glm::length(dir); //different repelling force depending on how busy the user is float desired_dist = getActionCount() == 0 ? gGourcePersonalSpaceDist : (!actions.empty() && activeActions.empty()) ? gGourcePersonalSpaceDist * 0.1 : gGourcePersonalSpaceDist * 0.5; //resolve overlap if(dist < 0.001) { accel += 1.0f * normalise(vec2( (rand() % 100) - 50, (rand() % 100) - 50)); return; } //repelling force if(dist < desired_dist) { accel -= (desired_dist-dist) * normalise(dir); } } void RUser::applyForceAction(RAction* action) { RFile* f = action->target; vec2 f_pos = f->getAbsolutePos(); vec2 dir = f_pos - pos; float dist = glm::length(dir); float desired_dist = gGourceActionDist; //resolve overlap if(dist < 0.001) { accel += normalise(vec2( (rand() % 100) - 50, (rand() % 100) - 50)); return; } //repelling force if(dist < desired_dist) { accel -= (desired_dist - dist) * normalise(dir); return; } if(dist > gGourceBeamDist) { accel += (dist-gGourceBeamDist) * normalise(dir); } } void RUser::applyForceToActions() { if(activeActions.empty() && actions.empty()) return; last_action = elapsed; int action_influence = 0; int max_influence = 3; // move towards actions being worked on for(std::list::iterator it = activeActions.begin(); it != activeActions.end(); it++) { RAction* action = *it; applyForceAction(action); action_influence++; if(action_influence >= max_influence) break; } if(!activeActions.empty()) return; //if no actions being worked on, move towards one pending action for(std::list::iterator it = actions.begin(); it != actions.end(); it++) { RAction* action = *it; applyForceAction(action); break; } } void RUser::colourize() { usercol = colourHash(name); } void RUser::assignUserImage() { colourize(); TextureResource* graphic = 0; if(gGourceSettings.user_image_dir.size() > 0) { //try their username // TODO: replace with map of name -> image of all pngs and jpgs in directory //gGourceSettings.user_image_dir + name + std::string(".jpg"); std::map::iterator findimage; findimage = gGourceSettings.user_image_map.find(name); //do we have this image if(findimage != gGourceSettings.user_image_map.end()) { std::string imagefile = findimage->second; if(!gGourceSettings.colour_user_images) usercol = vec3(1.0, 1.0, 1.0); graphic = texturemanager.grabFile(imagefile, true, GL_CLAMP_TO_EDGE); } } //TODO: trilinear probably should be an attribute of the texture // perhaps the mipmap option should be an enum: eg TEX_MIPMAP_TRILINEAR //nope if(!graphic) { if(gGourceSettings.default_user_image.size() > 0) { if(!gGourceSettings.colour_user_images) usercol = vec3(1.0, 1.0, 1.0); graphic = texturemanager.grabFile(gGourceSettings.default_user_image, true, GL_CLAMP_TO_EDGE); } else { graphic = texturemanager.grab("user.png", true, GL_CLAMP_TO_EDGE); } } setGraphic(graphic); usercol = usercol * 0.6f + vec3(1.0f) * 0.4f; usercol *= 0.9f; } int RUser::getActionCount() { return actionCount + activeCount; } int RUser::getPendingActionCount() { return actionCount; } void RUser::logic(float t, float dt) { Pawn::logic(dt); action_interval -= dt; bool find_nearby_action = false; if(!actions.empty() && action_interval <= 0) { find_nearby_action = true; } //add next active action, if it is in range for(std::list::iterator it = actions.begin(); it != actions.end();) { RAction* action = *it; //add all files which are too old if(gGourceSettings.max_file_lag>=0.0 && action->t < t - gGourceSettings.max_file_lag) { it = actions.erase(it); actionCount--; action->rate = 2.0; activeActions.push_back(action); activeCount++; continue; } if(!find_nearby_action) break; float action_dist = glm::length(action->target->getAbsolutePos() - pos); //queue first action in range if(action_dist < gGourceBeamDist) { it = actions.erase(it); activeActions.push_back(action); actionCount--; activeCount++; break; } it++; } //reset action interval if(action_interval <= 0) { int total_actions = actionCount + activeCount; action_interval = total_actions ? (1.0 / (float)total_actions) : 1.0; } //update actions for(std::list::iterator it = activeActions.begin(); it != activeActions.end(); ) { RAction* action = *it; action->logic(dt); if(action->isFinished()) { it = activeActions.erase(it); delete action; activeCount--; continue; } it++; } if(glm::length2(accel) > speed * speed) { accel = normalise(accel) * speed; } pos += accel * dt; accel = accel * std::max(0.0f, (1.0f - gGourceSettings.user_friction*dt)); } void RUser::updateFont() { if(selected) { font = fontmanager.grab(gGourceSettings.font_file, 18); font.dropShadow(true); } else { font = fontmanager.grab(gGourceSettings.font_file, gGourceSettings.scaled_user_font_size); font.dropShadow(true); } font.alignTop(false); namewidth = font.getWidth(name); } void RUser::setHighlighted(bool highlight) { this->highlighted = highlight; updateFont(); } void RUser::setSelected(bool selected) { Pawn::setSelected(selected); updateFont(); } const vec3& RUser::getNameColour() const { return selected ? gGourceSettings.selection_colour : highlighted ? gGourceSettings.highlight_colour : namecol; } vec3 RUser::getColour() const{ if(selected) return vec3(1.0, 1.0, 1.0); return usercol; } const std::string& RUser::getName() const { return name; } float RUser::getAlpha() const { float alpha = Pawn::getAlpha(); //user fades out if not doing anything if(elapsed - last_action > gGourceSettings.user_idle_time) { alpha = 1.0 - std::min(elapsed - last_action - gGourceSettings.user_idle_time, 1.0f); } return alpha; } bool RUser::isIdle() { return (activeActions.empty() && actions.empty()); } bool RUser::isFading() { return isIdle() && (elapsed - last_action) > gGourceSettings.user_idle_time; } bool RUser::isInactive() { return isIdle() && (elapsed - last_action) > 10.0; } bool RUser::nameVisible() const { return (Pawn::nameVisible() || gGourceSettings.highlight_all_users || highlighted) ? true : false; } void RUser::calcScreenPos(GLint* viewport, GLdouble* modelview, GLdouble* projection) { static GLdouble screen_x, screen_y, screen_z; vec2 text_pos = pos; text_pos.y -= dims.y * 0.5f; gluProject( text_pos.x, text_pos.y, 0.0f, modelview, projection, viewport, &screen_x, &screen_y, &screen_z); screen_y = (float)viewport[3] - screen_y; screenpos.x = screen_x - namewidth * 0.5; screenpos.y = screen_y - font.getMaxHeight(); } void RUser::drawNameText(float alpha) { float user_alpha = getAlpha(); if(gGourceSettings.highlight_all_users || highlighted || selected || alpha>0.0) { vec3 name_col = getNameColour(); float name_alpha = (selected||highlighted||gGourceSettings.highlight_all_users) ? user_alpha : alpha; font.setColour(vec4(name_col.x, name_col.y, name_col.z, name_alpha)); font.draw(screenpos.x, screenpos.y, name); } } void RUser::updateActionsVBO(quadbuf& buffer) { for(std::list::iterator it = activeActions.begin(); it != activeActions.end(); it++) { RAction* action = *it; action->drawToVBO(buffer); } } void RUser::drawActions(float dt) { for(std::list::iterator it = activeActions.begin(); it != activeActions.end(); it++) { RAction* action = *it; action->draw(dt); } } void RUser::draw(float dt) { if(gGourceSettings.hide_users) return; Pawn::draw(dt); } ================================================ FILE: src/user.h ================================================ /* Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef RUSER_H #define RUSER_H #include "gource_settings.h" #include "pawn.h" #include "action.h" #include "file.h" #include "sys/stat.h" #include class RAction; class RFile; class RUser : public Pawn { void assignUserImage(); std::list actions; std::list activeActions; size_t actionCount; size_t activeCount; float action_interval; float action_dist; float last_action; float min_units_ps; std::string name; vec3 usercol; bool highlighted; bool nameVisible() const; void updateFont(); const vec3& getNameColour() const; void drawNameText(float alpha); public: RUser(const std::string& name, vec2 pos, int tagid); vec3 getColour() const; void colourize(); const std::string& getName() const; void fileRemoved(RFile* f); void addAction(RAction* action); bool isIdle(); bool isFading(); bool isInactive(); void setSelected(bool selected); void setHighlighted(bool highlighted); int getActionCount(); int getPendingActionCount(); float getAlpha() const; void applyForceToActions(); void applyForceAction(RAction* action); void applyForceUser(RUser* u); void calcScreenPos(GLint* viewport, GLdouble* modelview, GLdouble* projection); void logic(float t, float dt); void updateActionsVBO(quadbuf& buffer); void drawActions(float dt); void draw(float dt); }; class UserForceFunctor : public VisitFunctor{ private: RUser * this_user; std::set seen; int loopCount; public: UserForceFunctor(RUser * user) : this_user(user), seen(), loopCount(0){} int getLoopCount() const{ return loopCount; } void operator()(QuadItem * user){ std::set::iterator seentest; RUser * b = (RUser*) (user); if(b==this_user) return; if(b->node_count != 1) { if((seentest = seen.find(b)) != seen.end()) return; seen.insert(b); } this_user->applyForceUser(b); loopCount++; } }; #endif ================================================ FILE: src/zoomcamera.cpp ================================================ /* Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "zoomcamera.h" ZoomCamera::ZoomCamera() { } ZoomCamera::ZoomCamera(vec3 pos, vec3 target, float min_distance, float max_distance) : pos(pos), _pos(pos), target(target), _target(target), dest(pos), fov(90.0f) { znear = 0.1; up = vec3(0.0f, -1.0f, 0.0f); setMinDistance(min_distance); setMaxDistance(max_distance); padding = 1.0; speed = 1.0; lockon = false; lockon_time = 0.0; reset(); } void ZoomCamera::reset() { pos = _pos; target = _target; } float ZoomCamera::getMaxDistance() { return max_distance; } float ZoomCamera::getMinDistance() { return min_distance; } void ZoomCamera::setPadding(float padding) { this->padding = padding; } void ZoomCamera::setMaxDistance(float max) { max_distance = max; zfar = max + 1.0; } void ZoomCamera::setMinDistance(float min) { min_distance = min; } void ZoomCamera::lockOn(bool lockon) { if(lockon) { lockon_time = 1.0; } this->lockon = lockon; } void ZoomCamera::look() { lookAt(target); } void ZoomCamera::lookAt(const vec3& target) { gluLookAt( pos.x, pos.y, pos.z, target.x, target.y, target.z, up.x, up.y, up.z); } void ZoomCamera::focus() { display.mode3D(fov, znear, zfar); look(); } void ZoomCamera::stop() { this->dest = pos; } void ZoomCamera::setSpeed(float speed) { this->speed = speed; } void ZoomCamera::adjust(const Bounds2D& bounds) { adjust(bounds, true); } void ZoomCamera::adjust(const Bounds2D& bounds, bool adjust_distance) { //center camera on bounds vec2 centre = bounds.centre(); //adjust by screen ratio dest.x = centre.x; dest.y = centre.y; if(!adjust_distance) return; //scale by 10% so we dont have stuff right on the edge of the screen float width = bounds.width() * padding; float height = bounds.height() * padding; float aspect_ratio = display.width / (float) display.height; if(aspect_ratio < 1.0) { height /= aspect_ratio; } else { width /= aspect_ratio; } //calc visible width of the opposite wall at a distance of 1 this fov float toa = tan( fov * 0.5f * DEGREES_TO_RADIANS ) * 2.0; float distance; //TOA = tan = opposite/adjacent (distance = adjacent) //use the larger side of the box //cropping: vertical, horizontal or none if(gGourceSettings.crop_vertical) { distance = width / toa; } else if (gGourceSettings.crop_horizontal) { distance = height / toa; } else { if(width >= height) { distance = width / toa; } else { distance = height / toa; } } //debugLog("toa %.2f, distance %.2f width %.2f height %.2f dratio %.2f\n", toa, distance, width, height, dratio); //check bounds are valid if(distance < min_distance) distance = min_distance; if(distance > max_distance) distance = max_distance; this->dest.z = -distance; } void ZoomCamera::setDistance(float distance) { dest.z = -distance; } void ZoomCamera::setPos(const vec3& pos, bool keep_angle) { if(keep_angle) { vec3 dir = target - this->pos; this->pos = pos; this->target = pos + dir; } else { this->pos = pos; } } void ZoomCamera::logic(float dt) { vec3 dp = (dest - pos); vec3 dpt = dp * dt * speed; if(lockon) { dpt = dpt * lockon_time + dp * (1.0f-lockon_time); if(lockon_time>0.0) { lockon_time = std::max(0.0f, lockon_time-dt*0.5f); } } if(glm::length2(dpt) > glm::length2(dp)) dpt = dp; pos += dpt; target = vec3(pos.x, pos.y, 0.0); } ================================================ FILE: src/zoomcamera.h ================================================ /* Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef ZOOM_CAMERA_H #define ZOOM_CAMERA_H #include "core/bounds.h" #include "core/frustum.h" #include "gource_settings.h" class ZoomCamera { vec3 pos; vec3 dest; vec3 target; vec3 up; vec3 _pos; vec3 _target; bool lockon; float speed; float lockon_time; float padding; float min_distance, max_distance; float fov; float znear, zfar; public: ZoomCamera(); ZoomCamera(vec3 start, vec3 target, float min_distance, float max_distance); void setSpeed(float speed); void lockOn(bool lockon); void look(); void lookAt(const vec3& target); void focus(); const vec3& getPos() const { return pos; }; const vec3& getUp() const { return up; }; const vec3& getTarget() const { return target; }; const vec3& getDest() const { return dest; }; float getFOV() { return fov; }; float getZNear() { return znear; }; float getZFar() { return zfar; }; void setPos(const vec3& pos, bool keep_angle = false); float getMinDistance(); float getMaxDistance(); void setPadding(float padding); void setDistance(float distance); void setMinDistance(float min); void setMaxDistance(float max); void reset(); void logic(float dt); void adjustDistance(); void adjust(const Bounds2D& bounds); void adjust(const Bounds2D& bounds, bool adjust_distance); void stop(); }; extern bool gGourceVerticalCrop; extern bool gGourceHorizontalCrop; #endif ================================================ FILE: tests/logs/custom-dir-delete.log ================================================ 1277787455|bob|A|path/to/1.txt 1277787457|bob|A|path/to/blah/1.txt 1277787457|bob|A|path/to/blah/2.txt 1277787457|bob|A|path/to/blah/3.txt 1277787460|bob|D|path/to/ ================================================ FILE: tests/logs/file-removal.log ================================================ 1277787455|bob|A|path/to/file.1 1277787455|bob|A|path/to/file.2 1277787455|bob|A|path/to/file.3 1277787455|bob|A|path/to/file.4 1277787455|bob|A|path/to/file.5 1277787456|bob|D|path/to/file.1 1277787456|bob|D|path/to/file.2 1277787456|bob|D|path/to/file.3 1277787456|bob|D|path/to/file.4 1277787466|bob|D|path/to/file.5 ================================================ FILE: tests/logs/file-to-dir.log ================================================ 1277787456|bob|A|path/to/file/Not 1277787457|bob|A|path/to/file/Not/Not 1277787457|bob|A|path/to/file/Not/Not/Not 1277787459|bob|A|path/to/file/Not/Not/Not/File ================================================ FILE: tests/logs/svn-dir-delete.log ================================================ bob 2010-01-20T08:35:18.022581Z /blah/blah/filea.sh /blah/blah/fileb.sh /blah/blah/filec.sh /blah/blah/filed.sh /blah/blah/filee.sh bob 2010-01-20T08:40:18.022581Z /blah ================================================ FILE: tests/logs/utf8-caption.log ================================================ 1277787455|Árvíztűrő tükörfúrógép adds a file 2010-06-29 16:57:45|Árvíztűrő tükörfúrógép removes a file ================================================ FILE: tests/logs/utf8.log ================================================ 1277787455|Árvíztűrő tükörfúrógép|A|Árvíztűrő/tükörfúrógép/Árvíztűrő tükörfúrógép.txt 1277787465|Árvíztűrő tükörfúrógép|D|Árvíztűrő/tükörfúrógép/Árvíztűrő tükörfúrógép.txt ================================================ FILE: tests/test.conf ================================================ [gource] title=File removal path=logs/file-removal.log file-idle-time=0.0 stop-at-time=10.0 [gource] title=Convert 'file' to a directory path=logs/file-to-dir.log stop-at-time=10.0 [gource] title=User filter (Andrew) user-filter=Andrew stop-at-time=5.0 [gource] title=Filename filter (.cpp) file-filter=\.cpp stop-at-time=5.0 [gource] title=Filename show filter (.cpp) file-show-filter=\.cpp stop-at-time=5.0 [gource] title=Directory delete (SVN) path=logs/svn-dir-delete.log stop-at-time=5.0 [gource] title=Directory delete (Custom) path=logs/custom-dir-delete.log stop-at-time=5.0 [gource] title=UTF-8 handling caption-file=logs/utf8-caption.log user-image-dir=images/ path=logs/utf8.log stop-at-time=5.0