diff --git a/.gitee/ISSUE_TEMPLATE.zh-CN.md b/.gitee/ISSUE_TEMPLATE.zh-CN.md deleted file mode 100644 index f09d98dde9597de75ffcdb237c2b580b8fffa3f9..0000000000000000000000000000000000000000 --- a/.gitee/ISSUE_TEMPLATE.zh-CN.md +++ /dev/null @@ -1,13 +0,0 @@ -### 该问题是怎么引起的? - - - -### 重现步骤 - - - -### 报错信息 - - - - diff --git a/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md b/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md deleted file mode 100644 index 66d4332058d27e3c8ef94919138576d71b524467..0000000000000000000000000000000000000000 --- a/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md +++ /dev/null @@ -1,14 +0,0 @@ -### 相关的Issue - - -### 原因(目的、解决的问题等) - - -### 描述(做了什么,变更了什么) - - -### 测试用例(新增、改动、可能影响的功能) - - - - diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..c34b03eb7f6731e292e2869903fa66230b4d27dd --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +*.o +*.exe +.vs/ +.gitee/ +test/ +target/ +MineSweeper.zip diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000000000000000000000000000000000..5e33924e1937e567d6f129c7775652230079e955 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "opt.h": "c" + } +} \ No newline at end of file diff --git a/LICENSE b/LICENSE index 89e08fb002e48e22363b7b3789a5470ffe71fea1..d159169d1050894d3ea3b98e1c965c4058208fe1 100644 --- a/LICENSE +++ b/LICENSE @@ -1,339 +1,339 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) 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 -this service 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 make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. 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. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -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 -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the 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 a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE 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. - - 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 -convey 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 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., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision 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, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This 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. + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) 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 +this service 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 make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. 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. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +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 +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the 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 a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE 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. + + 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 +convey 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 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., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision 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, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This 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. diff --git a/README.en.md b/README.en.md deleted file mode 100644 index 6c9bb8faf61002e9118579c4f4dae563414be8ca..0000000000000000000000000000000000000000 --- a/README.en.md +++ /dev/null @@ -1,36 +0,0 @@ -# MineSweeper - -#### Description -{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**} - -#### Software Architecture -Software architecture description - -#### Installation - -1. xxxx -2. xxxx -3. xxxx - -#### Instructions - -1. xxxx -2. xxxx -3. xxxx - -#### Contribution - -1. Fork the repository -2. Create Feat_xxx branch -3. Commit your code -4. Create Pull Request - - -#### Gitee Feature - -1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md -2. Gitee blog [blog.gitee.com](https://blog.gitee.com) -3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) -4. The most valuable open source project [GVP](https://gitee.com/gvp) -5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) -6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/README.md b/README.md index 6d6b47a2518c7a29a327a53fffddddfc298aa5d8..8dbff164e8428884ef758bc54562ae3dac2b032d 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,23 @@ # MineSweeper #### 介绍 -{**以下是 Gitee 平台说明,您可以替换此简介** -Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台 -无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)} +扫雷。 #### 软件架构 -软件架构说明 +基于 `PainterEngine` 实现。 +#### 编译 +必须使用 `Threads = win32` 下安装的 `mingw-w64` 进行编译。 -#### 安装教程 +在根目录下直接使用 `mingw32-make.exe` 进行编译,编译结果位于 `/MineSweeper.exe`。 -1. xxxx -2. xxxx -3. xxxx +#### TODOList +~~一定会做的~~ -#### 使用说明 - -1. xxxx -2. xxxx -3. xxxx - -#### 参与贡献 - -1. Fork 本仓库 -2. 新建 Feat_xxx 分支 -3. 提交代码 -4. 新建 Pull Request - - -#### 特技 - -1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md -2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) -3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 -4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 -5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) -6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) +- 基础交互 + - [ ] UI + - [x] 逻辑处理 + - [ ] 局面选项(长宽等等) + - [ ] 存档、读档 +- 高级设计 + - [ ] 高级统计 <= 这东西要是做不出来就扔了吧,都不是专业选手 \ No newline at end of file diff --git a/assets/firstprize.traw b/assets/firstprize.traw new file mode 100644 index 0000000000000000000000000000000000000000..7353a282cda9ad80b34ae25551236fd7c7ac2bb5 Binary files /dev/null and b/assets/firstprize.traw differ diff --git a/assets/flagpicture.traw b/assets/flagpicture.traw new file mode 100644 index 0000000000000000000000000000000000000000..09955e3a7e5319cb11064bf9d93c491a81a950a6 Binary files /dev/null and b/assets/flagpicture.traw differ diff --git a/assets/minepicture.traw b/assets/minepicture.traw new file mode 100644 index 0000000000000000000000000000000000000000..726a0d655a30ad21ec55107678da6cbc23d9e30b Binary files /dev/null and b/assets/minepicture.traw differ diff --git a/assets/potatoboom.traw b/assets/potatoboom.traw new file mode 100644 index 0000000000000000000000000000000000000000..b00fc5e2d4339468fffabe3b26090dab6d57f372 Binary files /dev/null and b/assets/potatoboom.traw differ diff --git a/assets/ranktitlepicture.traw b/assets/ranktitlepicture.traw new file mode 100644 index 0000000000000000000000000000000000000000..966c34fb98a2e7801c08b5ca4c252f00825376d7 Binary files /dev/null and b/assets/ranktitlepicture.traw differ diff --git a/assets/secondprize.traw b/assets/secondprize.traw new file mode 100644 index 0000000000000000000000000000000000000000..f3d701a3d2c9578dd18e6b02dcf0d672dc2fc397 Binary files /dev/null and b/assets/secondprize.traw differ diff --git a/assets/testimage.traw b/assets/testimage.traw new file mode 100644 index 0000000000000000000000000000000000000000..288a73d77597900b72d5ed4113cbd6a308ce1275 Binary files /dev/null and b/assets/testimage.traw differ diff --git a/assets/thirdprize.traw b/assets/thirdprize.traw new file mode 100644 index 0000000000000000000000000000000000000000..764bef3bafc275149c12399ff44ec472bbca1f41 Binary files /dev/null and b/assets/thirdprize.traw differ diff --git a/assets/titlepicture.traw b/assets/titlepicture.traw new file mode 100644 index 0000000000000000000000000000000000000000..9a515994a2a3fd840bba98d17c0866e75418ca69 Binary files /dev/null and b/assets/titlepicture.traw differ diff --git a/assets/titlepicture2.traw b/assets/titlepicture2.traw new file mode 100644 index 0000000000000000000000000000000000000000..d672a48726a29daa06bf020466ce348eb6ce3233 Binary files /dev/null and b/assets/titlepicture2.traw differ diff --git a/include/map.h b/include/map.h new file mode 100644 index 0000000000000000000000000000000000000000..f4e7cc94320b1691152db3044fcc46cc7ec6c389 --- /dev/null +++ b/include/map.h @@ -0,0 +1,21 @@ +#pragma once + +#include "mine_map.h" + +/** + * @brief 生成一个地图 + * + * @param mode 难易度 + * @return map* 生成的地图的指针 + */ +map *CreateMap(int mode); + +/** + * @brief 在地图上生成雷 + * + * @param *Map 地图的指针 + * @param posx 在地图上点击的位置 + * @param posy 在地图上点击的位置 + * @param seed 随机种子 + */ +void Setmine(map *Map, int posx, int posy, unsigned int seed); \ No newline at end of file diff --git a/include/mine_map.h b/include/mine_map.h new file mode 100644 index 0000000000000000000000000000000000000000..a1e4aa396cc9c380ed1a386661785a32d69e60f3 --- /dev/null +++ b/include/mine_map.h @@ -0,0 +1,51 @@ +#pragma once +#include + +#define UNCOVERED 0 +#define COVERED 1 +#define FLAGED 2 +#define MARKED 3 + +/** + * @brief 扫雷地图 + * mx,my地图长宽 + * mineMap[i][j]=1 表示第i行第j列为雷 + * mode 表示困难度 + * stage[i][j] 表示地图显示状态 + * cnt 表示雷的总数 + * autobook 用于自动打开的数组 + */ +typedef struct map{ + int mineMap[105][105]; + int mx, my; + int mode; + int stage[105][105]; + int cnt; + int autobook[105][105]; + bool generated; +}map; + +#define ROW_1 10 +#define COL_1 10 +#define ROW_2 ROW_1 + 2 +#define COL_2 COL_1 + 2 +#define MINECOUNT 9 + +#define MODE_EASY 1 +#define MODE_MID 2 +#define MODE_HARD 3 + +#define MX_EASY 9 +#define MX_MID 16 +#define MX_HARD 16 + +#define MY_EASY 9 +#define MY_MID 16 +#define MY_HARD 30 + +#define NUM_EASY 30 +#define NUM_MID 40 +#define NUM_HARD 99 + + + diff --git a/include/opt.h b/include/opt.h new file mode 100644 index 0000000000000000000000000000000000000000..fd1a83b776233ba55101622e0f33942d0f56141f --- /dev/null +++ b/include/opt.h @@ -0,0 +1,124 @@ +#pragma once +#include "mine_map.h" +#include + +/** + * @brief define status after click + * BOOM Indicates thunder + * UNALLOWED indicates that the behavior is not allowed + * ALLOWED indicates that the lattice was successfully opened + */ +#define BOOM 0 +#define UNALLOWED 1 +#define ALLOWED 2 + +/** + * @brief define Mouse Action + * + */ +#define OPT_LEFT_CLICK 1 +#define OPT_MID_CLICK 2 +#define OPT_RIGTH_CLICK 3 +#define OPT_TOTAL_CLICK 4 +/** + * @brief 用于数周围有多少个雷 + * + * @param map + * @param x + * @param y + * @return int 返回周围雷的数量 + */ + +/** + * @brief 单次操作数据 + * + */ +typedef struct +{ + int x,y; + int mode; +}opt_t; + +/** + * @brief 统计周围雷数量 + * + * @param map + * @param x + * @param y + * @return int + */ +int opt_count(map *map, int x, int y); +/** + * @brief 单次鼠标操作 + * + * @param m 地图 + * @param opt 操作数据,包含坐标,操作类型等信息 + * @return int 操作后状态 + */ +int opt(map* m, opt_t opt); + +/** + * @brief 鼠标左击 + * + * @param x + * @param y + * @param m 指向地图的一个指针 + * @return int 当次操作状态 + */ +int fnOptLeftClick(int x,int y,map *m); + +/** + * @brief 鼠标右击 + * + * @param x + * @param y + * @param m 指向地图的一个指针 + * @return int 当次操作状态 + */ +int fnOptRightClick(int x,int y,map *m ); + +/** + * @brief 鼠标中击 + * + * @param x + * @param y + * @param m 指向地图的一个指针 + * @return int 当次操作状态 + */ +int fnOptMidClick(int x,int y,map *m); + +/** + * @brief 用于自动展开地图 + * + * @param x + * @param y + * @param m 地图指针 + */ +void fnOptAuto(int x,int y, map *m); + +/** + * @brief 用于统计周围旗子数量 + * + * @param map + * @param x + * @param y + * @return int 旗子数量 + */ +int opt_flag_count(map* map, int x, int y); + +/** + * @brief 用于判断是否扫雷成功 + * + * @param m + * @return true + * @return false + */ +bool opt_is_scuess(map m); + +/** + * @brief 如果全部雷标记 打开剩余格子 + * + * @param m + * @return int + */ +int fnTotalFlag(map *m); \ No newline at end of file diff --git a/lib/PainterEngine/architecture/PainterEngine_Console.c b/lib/PainterEngine/architecture/PainterEngine_Console.c new file mode 100644 index 0000000000000000000000000000000000000000..571e282298a4c98b5d581d20b604967c34ec2b52 --- /dev/null +++ b/lib/PainterEngine/architecture/PainterEngine_Console.c @@ -0,0 +1,597 @@ +#include "PainterEngine_Console.h" + +static char const fox_console_logo[]=\ +{ +#include "PainterEngine_FoxLogo.h" +}; + +static char const PC_ScriptPreload[]="#name \"shell\"\r\n\ + #runtime stack 1024\r\n\ + host int print(string s);\r\n\ + host int printimage(string s);\r\n\ + host int printanimation(string s);\r\n\ + host int playanimation(int id,string s);\r\n\ + host int runscriptfunction(string key,string func);\r\n\ + host int close();\r\n"; + + + +px_void PX_ConsoleUpdateEx(PX_Console *pc) +{ + px_int i,y=10; + PX_ConsoleColumn *pCc; + + while (pc->pObjects.size>pc->max_column) + { + pCc=(PX_VECTORAT(PX_ConsoleColumn,&pc->pObjects,0)); + PX_ObjectDelete(pCc->Object); + PX_VectorErase(&pc->pObjects,0); + } + + for (i=0;ipObjects.size;i++) + { + pCc=(PX_VECTORAT(PX_ConsoleColumn,&pc->pObjects,i)); + + switch(pCc->Object->Type) + { + case PX_OBJECT_TYPE_AUTOTEXT: + { + PX_ObjectSetPosition(pCc->Object,0,(px_float)y,0); + y+=PX_Object_AutoTextGetHeight(pCc->Object); + } + break; + case PX_OBJECT_TYPE_IMAGE: + { + PX_ObjectSetPosition(pCc->Object,0,(px_float)y,0); + y+=(px_int)PX_ObjectGetHeight(pCc->Object); + } + break; + case PX_OBJECT_TYPE_ANIMATION: + { + PX_ObjectSetPosition(pCc->Object,0,(px_float)y,0); + y+=(px_int)PX_ObjectGetHeight(pCc->Object); + } + break; + default: + { + PX_ObjectSetPosition(pCc->Object,0,(px_float)y,0); + y+=(px_int)PX_ObjectGetHeight(pCc->Object); + } + break; + } + } + PX_ObjectSetPosition(pc->Input,0,(px_float)y,0); +} +PX_Object * PX_ConsolePrintText(PX_Console *pc,const px_char *text) +{ + PX_ConsoleColumn obj; + PX_Object *pObject=PX_Object_AutoTextCreate(&pc->runtime->mp_ui,pc->Area,0,0,(px_int)pc->Area->Width-1,PX_NULL); + + if (pObject) + { + obj.Object=pObject; + obj.id=pc->id++; + PX_Object_AutoTextSetTextColor(pObject,PX_COLOR(255,0,255,0)); + PX_Object_AutoTextSetText(pObject,text); + PX_VectorPushback(&pc->pObjects,&obj); + PX_ConsoleUpdateEx(pc); + + PX_Object_ScrollAreaMoveToBottom(pc->Area); + } + return pObject; +} + +PX_Object * PX_ConsolePrintImage(PX_Console *pc,px_char *res_image_key) +{ + PX_ConsoleColumn obj; + PX_Resource *pimageRes; + PX_Object *pObject; + if((pimageRes=PX_ResourceLibraryGet(&pc->runtime->ResourceLibrary,res_image_key))!=PX_NULL) + { + if (pimageRes->Type==PX_RESOURCE_TYPE_TEXTURE) + { + pObject=PX_Object_ImageCreate(&pc->runtime->mp_ui,pc->Area,0,0,pimageRes->texture.width,pimageRes->texture.height,&pimageRes->texture); + PX_Object_ImageSetAlign(pObject,PX_ALIGN_LEFTTOP); + PX_ObjectSetSize(pObject,(px_float)pimageRes->texture.width,(px_float)pimageRes->texture.height,0); + obj.Object=pObject; + obj.id=pc->id++; + PX_VectorPushback(&pc->pObjects,&obj); + PX_ConsoleUpdateEx(pc); + PX_Object_ScrollAreaMoveToBottom(pc->Area); + } + else + return PX_NULL; + } + else + { + return PX_NULL; + } + + return pObject; +} + + + +PX_Object * PX_ConsolePrintAnimation(PX_Console *pc,px_char *res_animation_key) +{ + PX_ConsoleColumn obj; + PX_Resource *pAnimationRes; + PX_Object *pObject; + px_rect rect; + if((pAnimationRes=PX_ResourceLibraryGet(&pc->runtime->ResourceLibrary,res_animation_key))!=PX_NULL) + { + if (pAnimationRes->Type==PX_RESOURCE_TYPE_ANIMATIONLIBRARY) + { + pObject=PX_Object_AnimationCreate(&pc->runtime->mp_ui,pc->Area,0,0,&pAnimationRes->animationlibrary); + PX_Object_AnimationSetAlign(pObject,PX_ALIGN_LEFTTOP); + rect=PX_AnimationGetSize(&PX_Object_GetAnimation(pObject)->animation); + PX_ObjectSetSize(pObject,(px_float)rect.width,(px_float)rect.height,0); + obj.Object=pObject; + obj.id=pc->id++; + PX_VectorPushback(&pc->pObjects,&obj); + PX_ConsoleUpdateEx(pc); + PX_Object_ScrollAreaMoveToBottom(pc->Area); + } + else + return PX_NULL; + } + else + { + return PX_NULL; + } + + return pObject; +} + + + + +PX_Object * PX_ConsoleShowImage(PX_Console *pc,px_char *res_image_key) +{ + PX_ConsoleColumn obj; + PX_Resource *pimageRes; + PX_Object *pObject; + if((pimageRes=PX_ResourceLibraryGet(&pc->runtime->ResourceLibrary,res_image_key))!=PX_NULL) + { + if (pimageRes->Type==PX_RESOURCE_TYPE_TEXTURE) + { + pObject=PX_Object_ImageCreate(&pc->runtime->mp_ui,pc->Area,0,0,pimageRes->texture.width,pimageRes->texture.height,&pimageRes->texture); + PX_Object_ImageSetAlign(pObject,PX_ALIGN_LEFTTOP); + obj.Object=pObject; + obj.id=pc->id++; + PX_VectorPushback(&pc->pObjects,&obj); + PX_ConsoleUpdateEx(pc); + PX_Object_ScrollAreaMoveToBottom(pc->Area); + } + else + return PX_NULL; + } + else + { + return PX_NULL; + } + + return pObject; +} + +px_void PX_ConsolePlayAnimation(PX_Console *pc,px_int id,px_char *animation_name) +{ + px_int i; + PX_ConsoleColumn *pCc; + + for (i=0;ipObjects.size;i++) + { + pCc=PX_VECTORAT(PX_ConsoleColumn,&pc->pObjects,i); + if(pCc->id==id) + { + if (pCc->Object->Type==PX_OBJECT_TYPE_ANIMATION) + { + PX_AnimationSetCurrentPlayAnimationByName(&PX_Object_GetAnimation(pCc->Object)->animation,animation_name); + return; + } + } + } +} + +px_void PX_ConsoleSetImageMask(PX_Console *pc,px_int id,px_char *mask_key) +{ + px_int i; + PX_ConsoleColumn *pCc; + + for (i=0;ipObjects.size;i++) + { + pCc=PX_VECTORAT(PX_ConsoleColumn,&pc->pObjects,i); + if(pCc->id==id) + { + if (pCc->Object->Type==PX_OBJECT_TYPE_IMAGE) + { + PX_Resource *pimageRes; + if((pimageRes=PX_ResourceLibraryGet(&pc->runtime->ResourceLibrary,mask_key))!=PX_NULL) + { + if (pimageRes->Type==PX_RESOURCE_TYPE_TEXTURE) + { + PX_Object_ImageSetMask(pCc->Object,&pimageRes->texture); + } + } + + } + return; + } + } +} + + + + +px_bool PX_ConsoleVM_Print(PX_ScriptVM_Instance *Ins,px_void *userptr) +{ + PX_Console *pc=(PX_Console *)userptr; + + if (PX_ScriptVM_STACK(Ins,0).type!=PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_ScriptVM_RET(Ins,PX_ScriptVM_Variable_int(0)); + return PX_TRUE; + } + PX_ConsolePrintText(pc,PX_ScriptVM_STACK(Ins,0)._string.buffer); + PX_ScriptVM_RET(Ins,PX_ScriptVM_Variable_int(PX_VECTORAT(PX_ConsoleColumn,&pc->pObjects,pc->pObjects.size-1)->id)); + return PX_TRUE; +} + +px_bool PX_ConsoleVM_PrintImage(PX_ScriptVM_Instance *Ins,px_void *userptr) +{ + PX_Console *pc=(PX_Console *)userptr; + + if (PX_ScriptVM_STACK(Ins,0).type!=PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_ScriptVM_RET(Ins,PX_ScriptVM_Variable_int(0)); + return PX_TRUE; + } + PX_ConsolePrintImage(pc,PX_ScriptVM_STACK(Ins,0)._string.buffer); + PX_ScriptVM_RET(Ins,PX_ScriptVM_Variable_int(PX_VECTORAT(PX_ConsoleColumn,&pc->pObjects,pc->pObjects.size-1)->id)); + return PX_TRUE; +} + + +px_bool PX_ConsoleVM_PrintAnimation(PX_ScriptVM_Instance *Ins,px_void *userptr) +{ + PX_Console *pc=(PX_Console *)userptr; + if (PX_ScriptVM_STACK(Ins,0).type!=PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_ScriptVM_RET(Ins,PX_ScriptVM_Variable_int(0)); + return PX_TRUE; + } + PX_ConsolePrintAnimation(pc,PX_ScriptVM_STACK(Ins,0)._string.buffer); + PX_ScriptVM_RET(Ins,PX_ScriptVM_Variable_int(PX_VECTORAT(PX_ConsoleColumn,&pc->pObjects,pc->pObjects.size-1)->id)); + return PX_TRUE; +} + +px_bool PX_ConsoleVM_PlayAnimation(PX_ScriptVM_Instance *Ins,px_void *userptr) +{ + PX_Console *pc=(PX_Console *)userptr; + + if (PX_ScriptVM_STACK(Ins,0).type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_RET(Ins,PX_ScriptVM_Variable_int(0)); + return PX_TRUE; + } + + if (PX_ScriptVM_STACK(Ins,1).type!=PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_ScriptVM_RET(Ins,PX_ScriptVM_Variable_int(0)); + return PX_TRUE; + } + + PX_ConsolePlayAnimation(pc,PX_ScriptVM_STACK(Ins,0)._int,PX_ScriptVM_STACK(Ins,1)._string.buffer); + + return PX_TRUE; +} + + +px_bool PX_ConsoleVM_Close(PX_ScriptVM_Instance *Ins,px_void *userptr) +{ + PX_Console *pc=(PX_Console *)userptr; + PX_ConsoleShow(pc,PX_FALSE); + return PX_TRUE; +} + + + + +px_void PX_ConsoleRunScriptFunction(PX_Console *pc,px_char *script_key,px_char *func_name) +{ + PX_Resource *pScriptRes; + if((pScriptRes=PX_ResourceLibraryGet(&pc->runtime->ResourceLibrary,script_key))!=PX_NULL) + { + if (pScriptRes->Type==PX_RESOURCE_TYPE_SCRIPT) + { + PX_ScriptVM_RegistryHostFunction(&pScriptRes->Script,"PRINT",PX_ConsoleVM_Print,pc);//Print + PX_ScriptVM_RegistryHostFunction(&pScriptRes->Script,"PRINTIMAGE",PX_ConsoleVM_PrintImage,pc);//Print Image + PX_ScriptVM_RegistryHostFunction(&pScriptRes->Script,"PRINTANIMATION",PX_ConsoleVM_PrintAnimation,pc);//Print Animation + if(!PX_ScriptVM_InstanceRunFunction(&pScriptRes->Script,0,"_BOOT",PX_NULL,0)) + { + return; + } + if(!PX_ScriptVM_InstanceRunFunction(&pScriptRes->Script,0,func_name,PX_NULL,0)) + { + return ; + } + } + else + return; + } + else + { + return; + } + +} + +px_bool PC_ConsoleVM_RunScriptFunction(PX_ScriptVM_Instance *Ins,px_void *userptr) +{ + PX_Console *pc=(PX_Console *)userptr; + + if (PX_ScriptVM_STACK(Ins,0).type!=PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_ScriptVM_RET(Ins,PX_ScriptVM_Variable_int(0)); + return PX_TRUE; + } + + if (PX_ScriptVM_STACK(Ins,1).type!=PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_ScriptVM_RET(Ins,PX_ScriptVM_Variable_int(0)); + return PX_TRUE; + } + + PX_ConsoleRunScriptFunction(pc,PX_ScriptVM_STACK(Ins,0)._string.buffer,PX_ScriptVM_STACK(Ins,1)._string.buffer); + + return PX_TRUE; +} + +px_bool PX_ConsoleExecute(PX_Console *pc,char *pshellstr) +{ + px_memory bin; + px_string shell; + PX_ScriptVM_Instance Ins; + PX_SCRIPT_LIBRARY lib; + px_string asmcodeString; + px_memorypool mp_calc; + + mp_calc=MP_Create(MP_Malloc(&pc->runtime->mp,PE_MEMORY_CALC_SIZE),PE_MEMORY_CALC_SIZE); + if(mp_calc.StartAddr==PX_NULL) return PX_FALSE; + PX_ConsolePrintText(pc,pshellstr); + MP_Reset(&mp_calc); + PX_MemoryInitialize(&mp_calc,&bin); + PX_StringInitialize(&mp_calc,&shell); + PX_StringCat(&shell,(char *)PC_ScriptPreload); + if(pc->script_header_append) + PX_StringCat(&shell,(char *)pc->script_header_append); + PX_StringCat(&shell,"export void main(){\r\n"); + PX_StringCat(&shell,pshellstr); + PX_StringCat(&shell,"\r\n}"); + + if(!PX_ScriptCompilerInitialize(&lib,&mp_calc)) + { + MP_Free(&pc->runtime->mp,mp_calc.StartAddr); + return PX_FALSE; + } + + if(!PX_ScriptCompilerLoad(&lib,(px_char *)shell.buffer)) + { + MP_Free(&pc->runtime->mp,mp_calc.StartAddr); + return PX_FALSE; + } + + PX_StringFree(&shell); + + PX_StringInitialize(&mp_calc,&asmcodeString); + if(PX_ScriptCompilerCompile(&lib,"shell",&asmcodeString,32)) + { + PX_ScriptAsmOptimization(&asmcodeString); + + if(!PX_ScriptAsmCompile(&mp_calc,asmcodeString.buffer,&bin)) + { + MP_Free(&pc->runtime->mp,mp_calc.StartAddr); + return PX_FALSE; + } + } + else + { + MP_Free(&pc->runtime->mp,mp_calc.StartAddr); + return PX_FALSE; + } + + PX_StringFree(&asmcodeString); + PX_ScriptCompilerFree(&lib); + + if(!PX_ScriptVM_InstanceInitialize(&Ins,&mp_calc,bin.buffer,bin.usedsize)) + { + MP_Free(&pc->runtime->mp,mp_calc.StartAddr); + return PX_FALSE; + } + PX_MemoryFree(&bin); + + PX_ScriptVM_RegistryHostFunction(&Ins,"PRINT",PX_ConsoleVM_Print,pc);//Print + PX_ScriptVM_RegistryHostFunction(&Ins,"PRINTIMAGE",PX_ConsoleVM_PrintImage,pc);//Print Image + PX_ScriptVM_RegistryHostFunction(&Ins,"PRINTANIMATION",PX_ConsoleVM_PrintAnimation,pc);//Print Animation + PX_ScriptVM_RegistryHostFunction(&Ins,"PLAYANIMATION",PX_ConsoleVM_PlayAnimation,pc);//play Animation + PX_ScriptVM_RegistryHostFunction(&Ins,"RUNSCRIPTFUNCTION",PC_ConsoleVM_RunScriptFunction,pc);//Load PatricalScript + PX_ScriptVM_RegistryHostFunction(&Ins,"CLOSE",PX_ConsoleVM_Close,pc);//close + if (pc->registry_call) + { + pc->registry_call(&Ins); + } + if(!PX_ScriptVM_InstanceRunFunction(&Ins,0,"_BOOT",PX_NULL,0)) + { + MP_Free(&pc->runtime->mp,mp_calc.StartAddr); + return PX_FALSE; + } + if(!PX_ScriptVM_InstanceRunFunction(&Ins,0,"MAIN",PX_NULL,0)) + { + MP_Free(&pc->runtime->mp,mp_calc.StartAddr); + return PX_FALSE; + } + + + PX_ScriptVM_InstanceFree(&Ins); +#if defined(PX_DEBUG_MODE) && defined(PX_MEMORYPOOL_DEBUG_CHECK) + MP_UnreleaseInfo(&mp_calc); +#endif + + MP_Free(&pc->runtime->mp,mp_calc.StartAddr); + + return PX_TRUE; + +} + +px_void PX_ConsoleOnEnter(PX_Object *Obj,PX_Object_Event e,px_void *user_ptr) +{ + PX_Console *pc=(PX_Console *)Obj->User_ptr; + + PX_Object_Edit *pEdit=PX_Object_GetEdit(pc->Input); + + if (e.Event==PX_OBJECT_EVENT_KEYDOWN) + { + if (PX_Object_Event_GetKeyDown(e)=='\r') + { + if(!PX_ConsoleExecute(pc,pEdit->text.buffer)) + { + PX_Object_AutoTextSetTextColor(PX_ConsolePrintText(pc,"Invalid shell code."),PX_COLOR(255,255,0,0)); + } + PX_Object_EditSetText(pc->Input,""); + } + } + + if (e.Event==PX_OBJECT_EVENT_CURSORRDOWN) + { + PX_Object_EditSetFocus(pc->Input,PX_TRUE); + } +} + +px_void PX_ConsoleOnMouseDown(PX_Object *Obj,PX_Object_Event e,px_void *user_ptr) +{ + PX_Console *pc=(PX_Console *)Obj->User_ptr; + if (e.Event==PX_OBJECT_EVENT_CURSORDOWN) + { + PX_Object_EditSetFocus(pc->Input,PX_TRUE); + } +} + + +px_bool PX_ConsoleInitializeEx(PX_Runtime *runtime,PX_Console *pc,px_int x,px_int y,px_int width,px_int height) +{ + //console initialize + pc->runtime=runtime; + pc->registry_call=PX_NULL; + pc->script_header_append=PX_NULL; + + pc->show=PX_TRUE; + pc->max_column=PC_CONSOLE_DEFAULT_MAX_COLUMN; + pc->column=0; + if(!(pc->Root=PX_ObjectCreate(&pc->runtime->mp_ui,0,0,0,0,0,0,0))) return PX_FALSE; + if(!(pc->Area=PX_Object_ScrollAreaCreate(&pc->runtime->mp_ui,pc->Root,x,y,width,height))) return PX_FALSE; + + + pc->Area->User_ptr=pc; + PX_ObjectRegisterEvent(pc->Area,PX_OBJECT_EVENT_KEYDOWN,PX_ConsoleOnEnter,PX_NULL); + PX_ObjectRegisterEvent(pc->Area,PX_OBJECT_EVENT_CURSORDOWN,PX_ConsoleOnMouseDown,PX_NULL); + PX_Object_ScrollAreaSetBorder(pc->Area,PX_FALSE); + if(!(pc->Input=PX_Object_EditCreate(&pc->runtime->mp_ui,PX_Object_ScrollAreaGetIncludedObjects(pc->Area),0,0,width-1,PX_FontGetCharactorHeight()+4,PX_NULL))) return PX_FALSE; + PX_Object_EditSetTextColor(pc->Input,PX_COLOR(255,0,255,0)); + PX_Object_EditSetCursorColor(pc->Input,PX_COLOR(255,0,255,0)); + PX_Object_EditSetTextColor(pc->Input,PX_COLOR(255,0,255,0)); + PX_Object_EditSetBorderColor(pc->Input,PX_COLOR(255,0,255,0)); + PX_Object_EditSetOffset(pc->Input,2,3); + PX_Object_ScrollAreaSetBkColor(pc->Area,PX_COLOR(255,0,0,0)); + pc->id=1; + + PX_VectorInitialize(&pc->runtime->mp_ui,&pc->pObjects,sizeof(PX_ConsoleColumn),PC_CONSOLE_DEFAULT_MAX_COLUMN); + + + ////////////////////////////////////////////////////////////////////////// + //logo + + if(!PX_ResourceLibraryLoad(&pc->runtime->ResourceLibrary,PX_RESOURCE_TYPE_TEXTURE,(px_byte *)fox_console_logo,sizeof(fox_console_logo),"console_logo"))return PX_FALSE; + + PX_ConsoleShowImage(pc,"console_logo"); + PX_ConsolePrintText(pc,"----------------------------------------"); + PX_ConsolePrintText(pc,"-PainterEngine JIT Compilation Console -\n-Code By DBinary Build on 2019 -\n-Refer To:www.GitHub.com/matrixcascade -"); + PX_ConsolePrintText(pc,"----------------------------------------"); + return PX_TRUE; +} + + +px_bool PX_ConsoleInitialize(PX_Runtime *runtime,PX_Console *pc) +{ + return PX_ConsoleInitializeEx(runtime,pc,0,0,runtime->surface_width,runtime->surface_height); +} + +px_void PX_ConsolePostEvent(PX_Console *pc,PX_Object_Event e) +{ + if(pc->show) + { + if (e.Event==PX_OBJECT_EVENT_KEYDOWN) + { + if (PX_Object_Event_GetKeyDown(e)==36) + { + PX_ConsoleShow(pc,PX_FALSE); + return; + } + } + + if (e.Event!=PX_OBJECT_EVENT_CURSORMOVE) + { + PX_ObjectPostEvent(pc->Root,e); + } + } + else + { + if (e.Event==PX_OBJECT_EVENT_KEYDOWN) + { + if (PX_Object_Event_GetKeyDown(e)==36) + { + PX_ConsoleShow(pc,PX_TRUE); + } + } + } +} +px_void PX_ConsoleUpdate(PX_Console *pc,px_dword elapsed) +{ + PX_ObjectUpdate(pc->Area,elapsed); +} + + +px_void PX_ConsoleShow(PX_Console *pc,px_bool b) +{ + pc->show=b; +} + +px_void PX_ConsoleRender(px_surface *psurface,PX_Console *pc,px_dword elapsed) +{ + if(pc->show) + { + PX_ObjectRender(psurface,pc->Area,elapsed); + } +} + +px_void PX_ConsoleRegistryHostCall(PX_Console *pc,console_registry_hostcall call_func) +{ + pc->registry_call=call_func; +} + +px_void PX_ConsoleRegistryScriptHeader(PX_Console *pc,const px_char *header) +{ + pc->script_header_append=header; +} + +px_void PX_ConsoleClear(PX_Console *pc) +{ + PX_ConsoleColumn *pCc; + px_int i; + for (i=0;ipObjects.size;i++) + { + pCc=(PX_VECTORAT(PX_ConsoleColumn,&pc->pObjects,i)); + PX_ObjectDelete(pCc->Object); + } + PX_VectorClear(&pc->pObjects); +} + diff --git a/lib/PainterEngine/architecture/PainterEngine_Console.h b/lib/PainterEngine/architecture/PainterEngine_Console.h new file mode 100644 index 0000000000000000000000000000000000000000..14525fd61acc8f3644e60915e778609d7cfe545e --- /dev/null +++ b/lib/PainterEngine/architecture/PainterEngine_Console.h @@ -0,0 +1,56 @@ +#ifndef PX_CONSOLE_H +#define PX_CONSOLE_H + + +#include "PainterEngine_Runtime.h" + +#define PC_CONSOLE_DEFAULT_MAX_COLUMN 48 + +typedef px_bool (*console_registry_hostcall)(PX_ScriptVM_Instance *Ins); +typedef struct +{ + PX_Object *Root; + PX_Object *Area; + PX_Object *Input; + px_int max_column; + px_int column; + px_bool show; + px_vector pObjects; + px_int id; + PX_Runtime *runtime; + union + { + px_void *user_ptr; + px_int user_int; + px_float user_float; + }; + + const px_char *script_header_append; + console_registry_hostcall registry_call; +}PX_Console; + +typedef struct +{ + px_int id; + PX_Object *Object; +}PX_ConsoleColumn; + + +px_bool PX_ConsoleInitializeEx(PX_Runtime *runtime,PX_Console *pc,px_int x,px_int y,px_int width,px_int height); +px_bool PX_ConsoleInitialize(PX_Runtime *runtime,PX_Console *pc); +px_void PX_ConsoleRegistryScriptHeader(PX_Console *pc,const px_char *header); +px_void PX_ConsoleRegistryHostCall(PX_Console *pc,console_registry_hostcall call_func); +px_void PX_ConsoleShow(PX_Console *pc,px_bool b); +px_void PX_ConsolePostEvent(PX_Console *pc,PX_Object_Event e); +px_void PX_ConsoleUpdate(PX_Console *pc,px_dword elapsed); +px_void PX_ConsoleRender(px_surface *psurface,PX_Console *pc,px_dword elapsed); +PX_Object * PX_ConsolePrintText(PX_Console *pc,const px_char *text); +PX_Object * PX_ConsolePrintImage(PX_Console *pc,px_char *res_image_key); +PX_Object * PX_ConsolePrintAnimation(PX_Console *pc,px_char *res_animation_key); +PX_Object * PX_ConsolePrintPartical(PX_Console *pc,px_int x,px_int y,px_char *res_texture,px_char *script,px_char *_init,px_char *_create,px_char *_updata); +PX_Object * PX_ConsoleShowImage(PX_Console *pc,px_char *res_image_key); +px_void PX_ConsoleClear(PX_Console *pc); +px_bool PX_ConsoleExecute(PX_Console *pc,char *pshellstr); + +#endif + diff --git a/lib/PainterEngine/architecture/PainterEngine_Designer.c b/lib/PainterEngine/architecture/PainterEngine_Designer.c new file mode 100644 index 0000000000000000000000000000000000000000..4b20c7fcd3b76d1ae6f0f476d0d4c4301c6ca0eb --- /dev/null +++ b/lib/PainterEngine/architecture/PainterEngine_Designer.c @@ -0,0 +1,1930 @@ +#include "PainterEngine_Designer.h" + + +static px_void PX_Designer_RefreshProperties(PX_Object *pObject) +{ + px_int i; + PX_Designer *pDesignerDesc=PX_ObjectGetDesc(PX_Designer,pObject); + + for (i=0;iedit_propertys);i++) + { + PX_ObjectSetVisible(pDesignerDesc->edit_propertys[i],PX_FALSE); + PX_ObjectSetVisible(pDesignerDesc->label_propertys[i],PX_FALSE); + } + + if (PX_VectorCheckIndex(&pDesignerDesc->Objects,pDesignerDesc->selectObjectIndex)) + { + PX_Designer_Object *pdobject=PX_VECTORAT(PX_Designer_Object,&pDesignerDesc->Objects,pDesignerDesc->selectObjectIndex); + if (PX_VectorCheckIndex(&pDesignerDesc->ObjectDesc,pdobject->descIndex)) + { + px_int j; + PX_Designer_ObjectDesc *pObjectDesc=PX_VECTORAT(PX_Designer_ObjectDesc,&pDesignerDesc->ObjectDesc,pdobject->descIndex); + for (j=0;jproperties);j++) + { + if (!pObjectDesc->properties[j].Name[0]) + { + break; + } + PX_ObjectSetVisible(pDesignerDesc->label_propertys[j],PX_TRUE); + PX_ObjectSetVisible(pDesignerDesc->edit_propertys[j],PX_TRUE); + PX_Object_LabelSetText(pDesignerDesc->label_propertys[j],pObjectDesc->properties[j].Name); + + if(pObjectDesc->properties[j].getbool) + { + px_bool v=pObjectDesc->properties[j].getbool(pdobject->pObject); + if (v) + { + PX_Object_EditSetText(pDesignerDesc->edit_propertys[j],"1"); + } + else + { + PX_Object_EditSetText(pDesignerDesc->edit_propertys[j],"0"); + } + continue; + } + + if(pObjectDesc->properties[j].getfloat) + { + px_float v=pObjectDesc->properties[j].getfloat(pdobject->pObject); + px_char content[32]; + PX_ftoa(v,content,32,2); + if (v) + { + PX_Object_EditSetText(pDesignerDesc->edit_propertys[j],content); + } + else + { + PX_Object_EditSetText(pDesignerDesc->edit_propertys[j],content); + } + continue; + } + + if(pObjectDesc->properties[j].getint) + { + px_int v=pObjectDesc->properties[j].getint(pdobject->pObject); + px_char content[32]; + PX_itoa(v,content,32,10); + PX_Object_EditSetText(pDesignerDesc->edit_propertys[j],content); + continue; + } + + if(pObjectDesc->properties[j].getstring) + { + px_string str; + PX_StringInitialize(pDesignerDesc->mp, &str); + ; + if (pObjectDesc->properties[j].getstring(pdobject->pObject,&str)) + { + PX_Object_EditSetText(pDesignerDesc->edit_propertys[j],str.buffer); + } + else + { + PX_Object_EditSetText(pDesignerDesc->edit_propertys[j],""); + } + + PX_StringFree(&str); + + continue; + } + } + } + } + PX_Object_ScrollAreaUpdateRange(pDesignerDesc->widget_propertyscrollarea); +} +static px_void PX_Designer_UpdateProperties(PX_Object *pObject) +{ + + PX_Designer *pDesignerDesc=PX_ObjectGetDesc(PX_Designer,pObject); + + if (PX_VectorCheckIndex(&pDesignerDesc->Objects,pDesignerDesc->selectObjectIndex)) + { + PX_Designer_Object *pdobject=PX_VECTORAT(PX_Designer_Object,&pDesignerDesc->Objects,pDesignerDesc->selectObjectIndex); + if (PX_VectorCheckIndex(&pDesignerDesc->ObjectDesc,pdobject->descIndex)) + { + px_int j; + PX_Designer_ObjectDesc *pObjectDesc=PX_VECTORAT(PX_Designer_ObjectDesc,&pDesignerDesc->ObjectDesc,pdobject->descIndex); + for (j=0;jproperties);j++) + { + if (!pObjectDesc->properties[j].Name[0]) + { + break; + } + + if(pObjectDesc->properties[j].setbool) + { + const px_char *pContent=PX_Object_EditGetText(pDesignerDesc->edit_propertys[j]);; + if (pContent[0]=='0') + { + pObjectDesc->properties[j].setbool(pdobject->pObject,PX_FALSE); + } + else + { + pObjectDesc->properties[j].setbool(pdobject->pObject,PX_TRUE); + } + continue; + } + + if(pObjectDesc->properties[j].setfloat) + { + const px_char *pContent=PX_Object_EditGetText(pDesignerDesc->edit_propertys[j]);; + + pObjectDesc->properties[j].setfloat(pdobject->pObject,PX_atof(pContent)); + + continue; + } + + if(pObjectDesc->properties[j].setint) + { + const px_char *pContent=PX_Object_EditGetText(pDesignerDesc->edit_propertys[j]);; + pObjectDesc->properties[j].setint(pdobject->pObject,PX_atoi(pContent)); + continue; + } + + if(pObjectDesc->properties[j].setstring) + { + const px_char *pContent=PX_Object_EditGetText(pDesignerDesc->edit_propertys[j]);; + pObjectDesc->properties[j].setstring(pdobject->pObject,pContent); + continue; + } + } + } + } +} + +px_void PX_DesignerOnDesignerBoxValueChanged(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + PX_Object_DesignerBox *pDesignerBox=(PX_Object_DesignerBox *)pObject->pObject; + PX_Designer *pDesc=(PX_Designer *)((PX_Object *)ptr)->pObject; + + if (pDesc->selectObjectIndex>=0&&pDesc->selectObjectIndexObjects.size) + { + PX_Designer_Object *pdobject=PX_VECTORAT(PX_Designer_Object,&pDesc->Objects,pDesc->selectObjectIndex); + + switch (pdobject->type) + { + case PX_DESIGNER_OBJECT_TYPE_UI: + { + if (!pDesc->pLinkObject) + { + return; + } + pdobject->pObject->x = pDesc->designerbox->x; + pdobject->pObject->y = pDesc->designerbox->y; + pdobject->pObject->Width = pDesc->designerbox->Width; + pdobject->pObject->Height = pDesc->designerbox->Height; + } + break; + case PX_DESIGNER_OBJECT_TYPE_GAME: + { + if (!pDesc->pLinkWorld) + { + return; + } + pdobject->pObject->x = pDesc->designerbox->x+pDesc->pLinkWorld->offsetx; + pdobject->pObject->y = pDesc->designerbox->y + pDesc->pLinkWorld->offsety; + pdobject->pObject->Width = pDesc->designerbox->Width; + pdobject->pObject->Height = pDesc->designerbox->Height; + } + break; + default: + return; + } + + + PX_Designer_RefreshProperties((PX_Object *)ptr); + + } +} +px_void PX_DesignerUpdate(PX_Object *pObject,px_dword elapsed) +{ + px_int i,count; + PX_Designer *pDesc=(PX_Designer *)pObject->pObject; + + ////////////////////////////////////////////////////////////////////////// + //designer box + if (pDesc->selectObjectIndex!=-1) + { + PX_Designer_Object *pdobject=PX_VECTORAT(PX_Designer_Object,&pDesc->Objects,pDesc->selectObjectIndex); + + switch (pdobject->type) + { + case PX_DESIGNER_OBJECT_TYPE_UI: + { + if (!pDesc->pLinkObject) + { + return; + } + pDesc->designerbox->x = pdobject->pObject->x; + pDesc->designerbox->y = pdobject->pObject->y; + pDesc->designerbox->Width = pdobject->pObject->Width; + pDesc->designerbox->Height = pdobject->pObject->Height; + pDesc->designerbox->Visible = PX_TRUE; + } + break; + case PX_DESIGNER_OBJECT_TYPE_GAME: + { + if (!pDesc->pLinkWorld) + { + return; + } + pDesc->designerbox->x = pdobject->pObject->x-pDesc->pLinkWorld->offsetx; + pDesc->designerbox->y = pdobject->pObject->y - pDesc->pLinkWorld->offsety; + pDesc->designerbox->Width = pdobject->pObject->Width; + pDesc->designerbox->Height = pdobject->pObject->Height; + PX_ObjectSetVisible(pDesc->designerbox,PX_TRUE); + } + break; + default: + break; + } + + } + else + { + PX_ObjectSetVisible(pDesc->designerbox,PX_FALSE); + } + + ////////////////////////////////////////////////////////////////////////// + //delete button + if (pDesc->selectObjectIndex!=-1) + { + pDesc->button_delete->x=pDesc->designerbox->x+ pDesc->designerbox->Width-pDesc->button_delete->Width; + pDesc->button_delete->y= pDesc->designerbox->y-pDesc->button_delete->Height-8; + PX_ObjectSetVisible(pDesc->button_delete,PX_TRUE); + } + else + { + PX_ObjectSetVisible(pDesc->button_delete,PX_FALSE); + } + + ////////////////////////////////////////////////////////////////////////// + //properties + if (pDesc->selectObjectIndex==-1) + { + px_int i; + for (i=0;ilabel_propertys[i],PX_FALSE); + PX_ObjectSetVisible(pDesc->edit_propertys[i],PX_FALSE); + } + } + + + count= pDesc->ObjectDesc.size; + PX_Object_ListClear(pDesc->list_ObjectDesc); + for (i=0;iObjectDesc,i); + PX_Object_ListAdd(pDesc->list_ObjectDesc, pController); + } + +} + +px_void PX_Designer_ControllersListItemOnRender(px_surface* psurface,PX_Object *pObject, px_dword elapsed) +{ + PX_Designer_ObjectDesc*pDesc=(PX_Designer_ObjectDesc*)PX_Object_ListItemGetData(pObject); + PX_Designer *pDesignerDesc=PX_ObjectGetDesc(PX_Designer,(PX_Object *)pObject->User_ptr); + px_float objx, objy, objWidth, objHeight; + px_float inheritX, inheritY; + PX_ObjectGetInheritXY(pObject, &inheritX, &inheritY); + objx = (pObject->x + inheritX); + objy = (pObject->y + inheritY); + objWidth = pObject->Width; + objHeight = pObject->Height; + + ////////////////////////////////////////////////////////////////////////// + //designer controller + ////////////////////////////////////////////////////////////////////////// + + switch (pDesc->type) + { + case PX_DESIGNER_OBJECT_TYPE_UI: + PX_GeoDrawBorder(psurface,(px_int)objx+1,(px_int)objy+1,(px_int)objx+64,(px_int)objy+PX_DESIGNER_CONTROLLER_ITEM_HEIGHT-2,1,PX_COLOR(255,192,64,255)); + PX_FontModuleDrawText(psurface,pDesignerDesc->fm,(px_int)objx+32,(px_int)objy+PX_DESIGNER_CONTROLLER_ITEM_HEIGHT/2,PX_ALIGN_CENTER,"UI",PX_COLOR(255,192,64,255)); + PX_FontModuleDrawText(psurface, pDesignerDesc->fm, (px_int)objx + 68, (px_int)objy + PX_DESIGNER_CONTROLLER_ITEM_HEIGHT / 2, PX_ALIGN_LEFTMID, pDesc->Name, PX_COLOR(255, 192, 64, 255)); + break; + case PX_DESIGNER_OBJECT_TYPE_GAME: + PX_GeoDrawBorder(psurface,(px_int)objx+1,(px_int)objy+1,(px_int)objx+64,(px_int)objy+PX_DESIGNER_CONTROLLER_ITEM_HEIGHT-2,1,PX_COLOR(255,128,255,64)); + PX_FontModuleDrawText(psurface,pDesignerDesc->fm,(px_int)objx+32,(px_int)objy+PX_DESIGNER_CONTROLLER_ITEM_HEIGHT/2,PX_ALIGN_CENTER,"Game",PX_COLOR(255,128,255,64)); + PX_FontModuleDrawText(psurface, pDesignerDesc->fm, (px_int)objx + 68, (px_int)objy + PX_DESIGNER_CONTROLLER_ITEM_HEIGHT / 2, PX_ALIGN_LEFTMID, pDesc->Name, PX_COLOR(255, 128, 255, 64)); + break; + case PX_DESIGNER_OBJECT_TYPE_FUNCTION: + PX_GeoDrawBorder(psurface,(px_int)objx+1,(px_int)objy+1,(px_int)objx+64,(px_int)objy+PX_DESIGNER_CONTROLLER_ITEM_HEIGHT-2,1,PX_COLOR(255,255,128,64)); + PX_FontModuleDrawText(psurface,pDesignerDesc->fm,(px_int)objx+32,(px_int)objy+PX_DESIGNER_CONTROLLER_ITEM_HEIGHT/2,PX_ALIGN_CENTER,"Function",PX_COLOR(255,255,128,64)); + PX_FontModuleDrawText(psurface, pDesignerDesc->fm, (px_int)objx + 68, (px_int)objy + PX_DESIGNER_CONTROLLER_ITEM_HEIGHT / 2, PX_ALIGN_LEFTMID, pDesc->Name, PX_COLOR(255, 255, 128, 64)); + break; + } + + +} + +px_bool PX_Designer_ControllersListItemOnCreate(px_memorypool* mp, PX_Object* ItemObject, px_void* userptr) +{ + ItemObject->Func_ObjectRender = PX_Designer_ControllersListItemOnRender; + ItemObject->User_ptr = userptr; + return PX_TRUE; +} + +px_void PX_DesignerRender(px_surface* psurface,PX_Object *pObject, px_dword elapsed) +{ + PX_Designer*pDesc=PX_ObjectGetDesc(PX_Designer,pObject); + PX_DesignerUpdate(pObject, elapsed); + if (pDesc->pLinkWorld&&pDesc->showsliderbar) + { + if (pDesc->pLinkWorld->world_width > pDesc->pLinkWorld->surface_width) + { + pDesc->world_hscroll->Visible = PX_TRUE; + pDesc->world_hscroll->x = 0; + pDesc->world_hscroll->y = pDesc->pLinkWorld->surface_height - 24.f; + pDesc->world_hscroll->Height = 24; + pDesc->world_hscroll->Width = pDesc->pLinkWorld->surface_width-24.f; + } + else + { + pDesc->world_hscroll->Visible = PX_FALSE; + } + + if (pDesc->pLinkWorld->world_height > pDesc->pLinkWorld->surface_height) + { + pDesc->world_vscroll->Visible = PX_TRUE; + pDesc->world_vscroll->x = pDesc->pLinkWorld->surface_width - 24.f; + pDesc->world_vscroll->y = 0; + pDesc->world_vscroll->Width = 24; + pDesc->world_vscroll->Height = pDesc->pLinkWorld->surface_height - 24.f; + } + else + { + pDesc->world_vscroll->Visible = PX_FALSE; + } + + } + else + { + pDesc->world_hscroll->Visible = PX_FALSE; + pDesc->world_vscroll->Visible = PX_FALSE; + } + + +} + +////////////////////////////////////////////////////////////////////////// +px_bool PX_Designer_GetID(PX_Object *pObject,px_string *str) +{ + PX_StringSet(str, pObject->id); + return PX_TRUE; +} + +px_void PX_Designer_SetID(PX_Object *pObject,const px_char id[]) +{ + PX_ObjectSetId(pObject,id); +} + +px_float PX_Designer_GetX(PX_Object *pObject) +{ + return pObject->x; +} + +px_float PX_Designer_GetY(PX_Object *pObject) +{ + return pObject->y; +} + +px_float PX_Designer_GetWidth(PX_Object *pObject) +{ + return pObject->Width; +} + +px_float PX_Designer_GetHeight(PX_Object *pObject) +{ + return pObject->Height; +} + +px_void PX_Designer_SetX(PX_Object *pObject,px_float v) +{ + pObject->x=v; +} + +px_void PX_Designer_SetY(PX_Object *pObject,px_float v) +{ + pObject->y=v; +} + +px_void PX_Designer_SetWidth(PX_Object *pObject,px_float v) +{ + pObject->Width=v; +} + +px_void PX_Designer_SetHeight(PX_Object *pObject,px_float v) +{ + pObject->Height=v; +} + +px_void PX_Designer_OnPropertyChanged(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + PX_Designer *pDesignerDesc=PX_ObjectGetDesc(PX_Designer,(PX_Object *)ptr); + PX_Designer_UpdateProperties((PX_Object *)ptr); +} + +px_void PX_Designer_OnPropertyRefresh(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + PX_Designer *pDesignerDesc=PX_ObjectGetDesc(PX_Designer,(PX_Object *)ptr); + PX_Designer_RefreshProperties((PX_Object *)ptr); +} + +px_void PX_Designer_OnDeleteCurrentObject(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + PX_Designer *pDesignerDesc=PX_ObjectGetDesc(PX_Designer,(PX_Object *)ptr); + if (PX_VectorCheckIndex(&pDesignerDesc->Objects,pDesignerDesc->selectObjectIndex)) + { + PX_Designer_Object *pdobject=PX_VECTORAT(PX_Designer_Object,&pDesignerDesc->Objects,pDesignerDesc->selectObjectIndex); + + switch(pdobject->type) + { + case PX_DESIGNER_OBJECT_TYPE_UI: + { + if (!pDesignerDesc->pLinkObject) + { + PX_ASSERT(); + return; + } + PX_ObjectDelete(pdobject->pObject); + } + break; + case PX_DESIGNER_OBJECT_TYPE_GAME: + { + if (!pDesignerDesc->pLinkWorld) + { + PX_ASSERT(); + return; + } + PX_WorldRemoveObject(pDesignerDesc->pLinkWorld,pdobject->pObject); + } + default: + break; + } + PX_VectorErase(&pDesignerDesc->Objects,pDesignerDesc->selectObjectIndex); + } + pDesignerDesc->selectObjectIndex=-1; +} + +px_void PX_Designer_OnCursorDown(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + PX_Designer *pDesignerDesc=PX_ObjectGetDesc(PX_Designer,pObject); + PX_Object *pSelectObject=PX_NULL; + px_int selectObjectIndex=-1; + + if (e.Event==PX_OBJECT_EVENT_CURSORDOWN) + { + px_int i; + px_float x,y; + x=PX_Object_Event_GetCursorX(e); + y=PX_Object_Event_GetCursorY(e); + + if (pDesignerDesc->selectObjectIndex!=-1) + { + if (PX_isXYInRegion(x,y,pDesignerDesc->designerbox->x-6,pDesignerDesc->designerbox->y-6,pDesignerDesc->designerbox->Width+12,pDesignerDesc->designerbox->Height+12)) + { + return; + } + + if (PX_ObjectIsCursorInRegion(pDesignerDesc->button_delete,e)) + { + return; + } + } + + if (pDesignerDesc->world_vscroll->Visible) + { + if (PX_ObjectIsCursorInRegion(pDesignerDesc->world_vscroll, e)) + { + return; + } + } + + if (pDesignerDesc->world_hscroll->Visible) + { + if (PX_ObjectIsCursorInRegion(pDesignerDesc->world_hscroll, e)) + { + return; + } + } + + + for (i=0;iObjects.size;i++) + { + PX_Designer_Object *pdobject=PX_VECTORAT(PX_Designer_Object,&pDesignerDesc->Objects,i); + + if (pDesignerDesc->pLinkWorld&&pdobject->type==PX_DESIGNER_OBJECT_TYPE_GAME) + { + px_rect rect; + rect.x=pdobject->pObject->x-pDesignerDesc->pLinkWorld->offsetx; + rect.y=pdobject->pObject->y-pDesignerDesc->pLinkWorld->offsety; + rect.width=pdobject->pObject->Width; + rect.height=pdobject->pObject->Height; + if(PX_isPointInRect(PX_POINT(x,y,0),rect)) + { + selectObjectIndex=i; + } + } + + if (pDesignerDesc->pLinkObject && pdobject->type==PX_DESIGNER_OBJECT_TYPE_UI) + { + if(PX_ObjectIsCursorInRegion(pdobject->pObject,e)) + { + selectObjectIndex=i; + } + } + + } + + + if (selectObjectIndex==-1&&pDesignerDesc->selectObjectIndex==-1) + { + px_int selectDescIndex=PX_Object_ListGetCurrentSelectIndex(pDesignerDesc->list_ObjectDesc); + PX_Designer_Object dobject; + if (selectDescIndex!=-1) + { + //create new object + PX_Designer_ObjectDesc *pObjectDesc=PX_VECTORAT(PX_Designer_ObjectDesc,&pDesignerDesc->ObjectDesc,selectDescIndex); + + switch (pObjectDesc->type) + { + case PX_DESIGNER_OBJECT_TYPE_UI: + { + if (pDesignerDesc->pLinkObject) + { + PX_Object* pNewObject = pObjectDesc->createfunc(pDesignerDesc->mp_ui, pDesignerDesc->pLinkObject, x, y, 100, 100, pDesignerDesc->fm); + PX_sprintf2(pNewObject->id, sizeof(pNewObject->id), "%1%2", PX_STRINGFORMAT_STRING(pObjectDesc->Name), PX_STRINGFORMAT_INT(pDesignerDesc->allocID++)); + + dobject.pObject = pNewObject; + dobject.type = PX_DESIGNER_OBJECT_TYPE_UI; + dobject.descIndex = selectDescIndex; + PX_VectorPushback(&pDesignerDesc->Objects, &dobject); + } + } + break; + case PX_DESIGNER_OBJECT_TYPE_GAME: + { + if (pDesignerDesc->pLinkWorld) + { + PX_Object* pNewObject = pObjectDesc->createfunc(pDesignerDesc->mp_game, PX_NULL, x + pDesignerDesc->pLinkWorld->offsetx, y + pDesignerDesc->pLinkWorld->offsety, 100, 100, pDesignerDesc->fm); + PX_sprintf2(pNewObject->id, sizeof(pNewObject->id), "%1%2", PX_STRINGFORMAT_STRING(pObjectDesc->Name), PX_STRINGFORMAT_INT(pDesignerDesc->allocID++)); + + PX_WorldAddObject(pDesignerDesc->pLinkWorld, pNewObject); + dobject.pObject = pNewObject; + dobject.type = PX_DESIGNER_OBJECT_TYPE_GAME; + dobject.descIndex = selectDescIndex; + PX_VectorPushback(&pDesignerDesc->Objects, &dobject); + } + } + break; + case PX_DESIGNER_OBJECT_TYPE_FUNCTION: + { + PX_Object *pNewObject=pObjectDesc->createfunc(pDesignerDesc->mp,PX_NULL,x,y,100,100,pDesignerDesc->fm); + if (pNewObject!=PX_NULL) + { + PX_ASSERT(); + } + } + break; + default: + break; + } + + } + else + { + pDesignerDesc->lastcursorx=x; + pDesignerDesc->lastcursory=y; + } + + } + + if (selectObjectIndex!=-1) + { + if (pDesignerDesc->selectObjectIndex!=selectObjectIndex) + { + PX_Designer_Object *pdobject=PX_VECTORAT(PX_Designer_Object,&pDesignerDesc->Objects,selectObjectIndex); + PX_Object_DesignerBox *pDesignerBox=PX_ObjectGetDesc(PX_Object_DesignerBox,pDesignerDesc->designerbox); + + pDesignerDesc->selectObjectIndex=selectObjectIndex; + + + pDesignerDesc->designerbox->x=pdobject->pObject->x; + pDesignerDesc->designerbox->y=pdobject->pObject->y; + pDesignerDesc->designerbox->Width=pdobject->pObject->Width; + pDesignerDesc->designerbox->Height=pdobject->pObject->Height; + + pDesignerBox->bselect=PX_Object_DesignerBox_bselect_center; + pDesignerBox->lastx = x; + pDesignerBox->lasty = y; + + PX_Designer_RefreshProperties(pObject); + } + } + else + { + pDesignerDesc->selectObjectIndex=-1; + } + + } + + +} +////////////////////////////////////////////////////////////////////////// +/* +typedef PX_Object *(*px_designer_createfunc)(px_memorypool *mp,PX_Object *pparent,px_float x,px_float y,px_float width,px_float height,PX_FontModule *fm); +typedef px_float (*px_designer_getproperty_float)(PX_Object *pObject); +typedef px_int (*px_designer_getproperty_int)(PX_Object *pObject); +typedef px_bool (*px_designer_getproperty_string)(PX_Object *pObject); +typedef px_bool (*px_designer_getproperty_bool)(PX_Object *pObject); + +typedef px_void (*px_designer_setproperty_float)(PX_Object *pObject,px_float v); +typedef px_void (*px_designer_setproperty_int)(PX_Object *pObject,px_int v); +typedef px_void (*px_designer_setproperty_string)(PX_Object *pObject,const px_char v[]); +typedef px_void (*px_designer_setproperty_bool)(PX_Object *pObject,px_bool v); +typedef struct +*/ + +////////////////////////////////////////////////////////////////////////// +//Label +////////////////////////////////////////////////////////////////////////// +PX_Object *PX_Designer_LabelCreate(px_memorypool *mp,PX_Object *pparent,px_float x,px_float y,px_float width,px_float height,PX_FontModule *fm) +{ + return PX_Object_LabelCreate(mp,pparent,(px_int)x,(px_int)y,128,32,"Label",fm,PX_OBJECT_UI_DEFAULT_FONTCOLOR); +} + +px_void PX_Designer_LabelSetText(PX_Object *pobject,const px_char text[]) +{ + PX_Object_LabelSetText(pobject,text); +} + +px_bool PX_Designer_LabelGetText(PX_Object *pobject,px_string *str) +{ + return PX_StringSet(str, PX_Object_LabelGetText(pobject)); +} + +px_void PX_Designer_LabelSetAlign(PX_Object *pobject,px_int align) +{ + switch(align) + { + case PX_ALIGN_LEFTTOP: + case PX_ALIGN_MIDTOP: + case PX_ALIGN_RIGHTTOP: + case PX_ALIGN_LEFTMID: + case PX_ALIGN_CENTER: + case PX_ALIGN_RIGHTMID: + case PX_ALIGN_LEFTBOTTOM: + case PX_ALIGN_MIDBOTTOM: + case PX_ALIGN_RIGHTBOTTOM: + { + PX_Object_LabelSetAlign(pobject,(PX_ALIGN)align); + } + default: + break; + } + +} + +px_int PX_Designer_LabelGetAlign(PX_Object *pobject) +{ + return PX_Object_GetLabel(pobject)->Align; +} + +////////////////////////////////////////////////////////////////////////// +//Push button +////////////////////////////////////////////////////////////////////////// +PX_Object *PX_Designer_PushButtonCreate(px_memorypool *mp,PX_Object *pparent,px_float x,px_float y,px_float width,px_float height,PX_FontModule *fm) +{ + return PX_Object_PushButtonCreate(mp,pparent,(px_int)x,(px_int)y,128,64,"PushButton",fm); +} + +px_void PX_Designer_PushButtonSetText(PX_Object *pobject,const px_char text[]) +{ + PX_Object_PushButtonSetText(pobject,text); +} + +px_bool PX_Designer_PushButtonGetText(PX_Object *pobject,px_string *str) +{ + return PX_StringSet(str,PX_Object_PushButtonGetText(pobject)); +} + + +////////////////////////////////////////////////////////////////////////// +//radiobox +////////////////////////////////////////////////////////////////////////// +PX_Object *PX_Designer_RadioBoxCreate(px_memorypool *mp,PX_Object *pparent,px_float x,px_float y,px_float width,px_float height,PX_FontModule *fm) +{ + return PX_Object_RadioBoxCreate(mp,pparent,(px_int)x,(px_int)y,108,28,"RadioButton",fm); +} + +px_void PX_Designer_RadioBoxSetText(PX_Object *pobject,const px_char text[]) +{ + PX_Object_RadioBoxSetText(pobject,text); +} + +px_bool PX_Designer_RadioBoxGetText(PX_Object *pobject,px_string *str) +{ + return PX_StringSet(str,PX_Object_RadioBoxGetText(pobject)); +} + +px_void PX_Designer_RadioBoxSetCheck(PX_Object *pobject,px_bool b) +{ + PX_Object_RadioBoxSetCheck(pobject,b); +} + +px_bool PX_Designer_RadioBoxGetCheck(PX_Object *pobject) +{ + return PX_Object_RadioBoxGetCheck(pobject); +} + +////////////////////////////////////////////////////////////////////////// +//checkbox +////////////////////////////////////////////////////////////////////////// +PX_Object *PX_Designer_CheckBoxCreate(px_memorypool *mp,PX_Object *pparent,px_float x,px_float y,px_float width,px_float height,PX_FontModule *fm) +{ + return PX_Object_CheckBoxCreate(mp,pparent,(px_int)x,(px_int)y,96,28,"CheckBox",fm); +} + +px_void PX_Designer_CheckBoxSetText(PX_Object *pobject,const px_char text[]) +{ + PX_Object_CheckBoxSetText(pobject,text); +} + +px_bool PX_Designer_CheckBoxGetText(PX_Object *pobject,px_string *str) +{ + return PX_StringSet(str,PX_Object_CheckBoxGetText(pobject)); +} + +px_void PX_Designer_CheckBoxSetCheck(PX_Object *pobject,px_bool b) +{ + PX_Object_CheckBoxSetCheck(pobject,b); +} + +px_bool PX_Designer_CheckBoxGetCheck(PX_Object *pobject) +{ + return PX_Object_CheckBoxGetCheck(pobject); +} + +////////////////////////////////////////////////////////////////////////// +//edit +////////////////////////////////////////////////////////////////////////// +PX_Object *PX_Designer_EditCreate(px_memorypool *mp,PX_Object *pparent,px_float x,px_float y,px_float width,px_float height,PX_FontModule *fm) +{ + return PX_Object_EditCreate(mp,pparent,(px_int)x,(px_int)y,128,28,fm); +} + +px_void PX_Designer_EditSetText(PX_Object *pobject,const px_char text[]) +{ + PX_Object_EditSetText(pobject,text); +} + +px_bool PX_Designer_EditGetText(PX_Object *pobject,px_string *str) +{ + return PX_StringSet(str,PX_Object_EditGetText(pobject)); +} + +////////////////////////////////////////////////////////////////////////// +//process bar +////////////////////////////////////////////////////////////////////////// +PX_Object* PX_Designer_ProcessBarCreate(px_memorypool* mp, PX_Object* pparent, px_float x, px_float y, px_float width, px_float height, PX_FontModule* fm) +{ + return PX_Object_ProcessBarCreate(mp, pparent, (px_int)x, (px_int)y, 192, 32); +} + +px_void PX_Designer_ProcessBarSetMax(PX_Object* pobject, px_int max) +{ + PX_Object_ProcessBarSetMax(pobject, max); +} + +px_int PX_Designer_ProcessBarGetMax(PX_Object* pobject) +{ + return PX_Object_ProcessBarGetMax(pobject); +} + +px_void PX_Designer_ProcessBarSetValue(PX_Object* pobject, px_int value) +{ + PX_Object_ProcessBarSetValue(pobject,value); +} + +px_int PX_Designer_ProcessBarGetValue(PX_Object* pobject) +{ + return PX_Object_ProcessBarGetValue(pobject); +} + + + +////////////////////////////////////////////////////////////////////////// +//list +////////////////////////////////////////////////////////////////////////// + +PX_Object* PX_Designer_ListCreate(px_memorypool* mp, PX_Object* pparent, px_float x, px_float y, px_float width, px_float height, PX_FontModule* fm) +{ + return PX_Object_ListContentCreate(mp, pparent, (px_int)x, (px_int)y, 256, 128, fm); +} + + +////////////////////////////////////////////////////////////////////////// +//SelectBar +////////////////////////////////////////////////////////////////////////// + +PX_Object* PX_Designer_SelectBarCreate(px_memorypool* mp, PX_Object* pparent, px_float x, px_float y, px_float width, px_float height, PX_FontModule* fm) +{ + return PX_Object_SelectBarCreate(mp, pparent, (px_int)x, (px_int)y, 96, 24, fm); +} + +px_void PX_Designer_SelectBarSetText(PX_Object* pobject, const px_char text[]) +{ + px_char content[64]; + px_int _strlen; + px_int i, j; + PX_Object_SelectBarClear(pobject); + i = 0; + _strlen = PX_strlen(text); + while (i < _strlen) + { + j = 0; + while (text[i] != '\n' && text[i] != '\0') + { + if (j >= PX_COUNTOF(content) - 1) + { + return; + } + content[j++] = text[i++]; + } + content[j] = '\0'; + if (text[i] == '\n') + { + i++; + } + PX_Object_SelectBarAddItem(pobject, content); + } +} + + +px_bool PX_Designer_SelectBarGetText(PX_Object* pobject,px_string *str) +{ + px_int i; + PX_Object_SelectBar* pdesc = PX_ObjectGetDesc(PX_Object_SelectBar, pobject); + for (i=0;i< pdesc->Items.size;i++) + { + PX_StringCat(str, PX_Object_SelectBarGetItemText(pobject, i)); + PX_StringCat(str, "\n"); + } + PX_StringBackspace(str); + return PX_TRUE; +} + + +////////////////////////////////////////////////////////////////////////// +//SliderBar +////////////////////////////////////////////////////////////////////////// +PX_Object* PX_Designer_SliderBarCreate(px_memorypool* mp, PX_Object* pparent, px_float x, px_float y, px_float width, px_float height, PX_FontModule* fm) +{ + return PX_Object_SliderBarCreate(mp, pparent, (px_int)x, (px_int)y, 192, 32,PX_OBJECT_SLIDERBAR_TYPE_HORIZONTAL,PX_OBJECT_SLIDERBAR_STYLE_LINER); +} + +px_void PX_Designer_SliderBarSetMax(PX_Object* pobject, px_int max) +{ + PX_Object_SliderBarSetRange(pobject,PX_ObjectGetDesc(PX_Object_SliderBar,pobject)->Min ,max); +} + +px_int PX_Designer_SliderBarGetMax(PX_Object* pobject) +{ + return PX_ObjectGetDesc(PX_Object_SliderBar, pobject)->Max; +} + +px_void PX_Designer_SliderBarSetMin(PX_Object* pobject, px_int min) +{ + PX_Object_SliderBarSetRange(pobject,min, PX_ObjectGetDesc(PX_Object_SliderBar, pobject)->Max); +} + +px_int PX_Designer_SliderBarGetMin(PX_Object* pobject) +{ + return PX_ObjectGetDesc(PX_Object_SliderBar, pobject)->Min; +} + +px_void PX_Designer_SliderBarSetType(PX_Object* pobject, px_int type) +{ + switch (type) + { + case PX_OBJECT_SLIDERBAR_TYPE_HORIZONTAL: + case PX_OBJECT_SLIDERBAR_TYPE_VERTICAL: + PX_ObjectGetDesc(PX_Object_SliderBar, pobject)->Type = (PX_OBJECT_SLIDERBAR_TYPE)type; + default: + break; + } + +} +px_int PX_Designer_SliderBarGetType(PX_Object* pobject) +{ + return (px_int)PX_ObjectGetDesc(PX_Object_SliderBar, pobject)->Type; +} + + +px_void PX_Designer_SliderBarSetStyle(PX_Object* pobject, px_int style) +{ + switch (style) + { + case PX_OBJECT_SLIDERBAR_STYLE_BOX: + case PX_OBJECT_SLIDERBAR_STYLE_LINER: + PX_ObjectGetDesc(PX_Object_SliderBar, pobject)->style = (PX_OBJECT_SLIDERBAR_STYLE)style; + default: + break; + } + +} +px_int PX_Designer_SliderBarGetStyle(PX_Object* pobject) +{ + return (px_int)PX_ObjectGetDesc(PX_Object_SliderBar, pobject)->style; +} + +px_void PX_Designer_SliderBarSetValue(PX_Object* pobject, px_int value) +{ + PX_Object_SliderBarSetValue(pobject, value); +} + +px_int PX_Designer_SliderBarGetValue(PX_Object* pobject) +{ + return PX_Object_SliderBarGetValue(pobject); +} + + +px_bool PX_DesignerStandardInitialize(PX_Designer *designer) +{ + + do + { + PX_Designer_ObjectDesc slabel; + px_int i=0; + PX_memset(&slabel,0,sizeof(slabel)); + PX_strcat(slabel.Name,"label"); + slabel.createfunc=PX_Designer_LabelCreate; + slabel.type=PX_DESIGNER_OBJECT_TYPE_UI; + + PX_strcat(slabel.properties[i].Name,"id"); + slabel.properties[i].getstring=PX_Designer_GetID; + slabel.properties[i].setstring=PX_Designer_SetID; + i++; + + PX_strcat(slabel.properties[i].Name,"x"); + slabel.properties[i].getfloat=PX_Designer_GetX; + slabel.properties[i].setfloat=PX_Designer_SetX; + i++; + + PX_strcat(slabel.properties[i].Name,"y"); + slabel.properties[i].getfloat=PX_Designer_GetY; + slabel.properties[i].setfloat=PX_Designer_SetY; + i++; + + PX_strcat(slabel.properties[i].Name,"width"); + slabel.properties[i].getfloat=PX_Designer_GetWidth; + slabel.properties[i].setfloat=PX_Designer_SetWidth; + i++; + + PX_strcat(slabel.properties[i].Name,"height"); + slabel.properties[i].getfloat=PX_Designer_GetHeight; + slabel.properties[i].setfloat=PX_Designer_SetHeight; + i++; + + PX_strcat(slabel.properties[i].Name,"text"); + slabel.properties[i].setstring=PX_Designer_LabelSetText; + slabel.properties[i].getstring=PX_Designer_LabelGetText; + i++; + + + PX_strcat(slabel.properties[i].Name,"align"); + slabel.properties[i].setint=PX_Designer_LabelSetAlign; + slabel.properties[i].getint=PX_Designer_LabelGetAlign; + i++; + + if (designer->pLinkObject) + { + PX_VectorPushback(&designer->ObjectDesc, &slabel); + } + if (designer->pLinkWorld) + { + slabel.type = PX_DESIGNER_OBJECT_TYPE_GAME; + PX_VectorPushback(&designer->ObjectDesc, &slabel); + } + + } while (0); + + do + { + PX_Designer_ObjectDesc spushbutton; + px_int i=0; + PX_memset(&spushbutton,0,sizeof(spushbutton)); + PX_strcat(spushbutton.Name,"pushbutton"); + spushbutton.createfunc=PX_Designer_PushButtonCreate; + spushbutton.type=PX_DESIGNER_OBJECT_TYPE_UI; + + PX_strcat(spushbutton.properties[i].Name,"id"); + spushbutton.properties[i].getstring=PX_Designer_GetID; + spushbutton.properties[i].setstring=PX_Designer_SetID; + i++; + + PX_strcat(spushbutton.properties[i].Name,"x"); + spushbutton.properties[i].getfloat=PX_Designer_GetX; + spushbutton.properties[i].setfloat=PX_Designer_SetX; + i++; + + PX_strcat(spushbutton.properties[i].Name,"y"); + spushbutton.properties[i].getfloat=PX_Designer_GetY; + spushbutton.properties[i].setfloat=PX_Designer_SetY; + i++; + + PX_strcat(spushbutton.properties[i].Name,"width"); + spushbutton.properties[i].getfloat=PX_Designer_GetWidth; + spushbutton.properties[i].setfloat=PX_Designer_SetWidth; + i++; + + PX_strcat(spushbutton.properties[i].Name,"height"); + spushbutton.properties[i].getfloat=PX_Designer_GetHeight; + spushbutton.properties[i].setfloat=PX_Designer_SetHeight; + i++; + + PX_strcat(spushbutton.properties[i].Name,"text"); + spushbutton.properties[i].setstring=PX_Designer_PushButtonSetText; + spushbutton.properties[i].getstring=PX_Designer_PushButtonGetText; + i++; + + if (designer->pLinkObject) + { + PX_VectorPushback(&designer->ObjectDesc, &spushbutton); + } + + if (designer->pLinkWorld) + { + spushbutton.type = PX_DESIGNER_OBJECT_TYPE_GAME; + PX_VectorPushback(&designer->ObjectDesc, &spushbutton); + } + + + } while (0); + + + do + { + PX_Designer_ObjectDesc sradiobutton; + px_int i = 0; + PX_memset(&sradiobutton, 0, sizeof(sradiobutton)); + PX_strcat(sradiobutton.Name, "radiobutton"); + + sradiobutton.createfunc = PX_Designer_RadioBoxCreate; + sradiobutton.type = PX_DESIGNER_OBJECT_TYPE_UI; + + PX_strcat(sradiobutton.properties[i].Name, "id"); + sradiobutton.properties[i].getstring = PX_Designer_GetID; + sradiobutton.properties[i].setstring = PX_Designer_SetID; + i++; + + PX_strcat(sradiobutton.properties[i].Name, "x"); + sradiobutton.properties[i].getfloat = PX_Designer_GetX; + sradiobutton.properties[i].setfloat = PX_Designer_SetX; + i++; + + PX_strcat(sradiobutton.properties[i].Name, "y"); + sradiobutton.properties[i].getfloat = PX_Designer_GetY; + sradiobutton.properties[i].setfloat = PX_Designer_SetY; + i++; + + PX_strcat(sradiobutton.properties[i].Name, "width"); + sradiobutton.properties[i].getfloat = PX_Designer_GetWidth; + sradiobutton.properties[i].setfloat = PX_Designer_SetWidth; + i++; + + PX_strcat(sradiobutton.properties[i].Name, "height"); + sradiobutton.properties[i].getfloat = PX_Designer_GetHeight; + sradiobutton.properties[i].setfloat = PX_Designer_SetHeight; + i++; + + PX_strcat(sradiobutton.properties[i].Name, "text"); + sradiobutton.properties[i].setstring = PX_Designer_RadioBoxSetText; + sradiobutton.properties[i].getstring = PX_Designer_RadioBoxGetText; + i++; + + PX_strcat(sradiobutton.properties[i].Name, "check"); + sradiobutton.properties[i].setbool = PX_Designer_RadioBoxSetCheck; + sradiobutton.properties[i].getbool = PX_Designer_RadioBoxGetCheck; + i++; + + if (designer->pLinkObject) + { + PX_VectorPushback(&designer->ObjectDesc, &sradiobutton); + } + if (designer->pLinkWorld) + { + sradiobutton.type = PX_DESIGNER_OBJECT_TYPE_GAME; + PX_VectorPushback(&designer->ObjectDesc, &sradiobutton); + } + } while (0); + + + do + { + PX_Designer_ObjectDesc scheckbox; + px_int i = 0; + PX_memset(&scheckbox, 0, sizeof(scheckbox)); + PX_strcat(scheckbox.Name, "checkbox"); + + scheckbox.createfunc = PX_Designer_CheckBoxCreate; + scheckbox.type = PX_DESIGNER_OBJECT_TYPE_UI; + + PX_strcat(scheckbox.properties[i].Name, "id"); + scheckbox.properties[i].getstring = PX_Designer_GetID; + scheckbox.properties[i].setstring = PX_Designer_SetID; + i++; + + PX_strcat(scheckbox.properties[i].Name, "x"); + scheckbox.properties[i].getfloat = PX_Designer_GetX; + scheckbox.properties[i].setfloat = PX_Designer_SetX; + i++; + + PX_strcat(scheckbox.properties[i].Name, "y"); + scheckbox.properties[i].getfloat = PX_Designer_GetY; + scheckbox.properties[i].setfloat = PX_Designer_SetY; + i++; + + PX_strcat(scheckbox.properties[i].Name, "width"); + scheckbox.properties[i].getfloat = PX_Designer_GetWidth; + scheckbox.properties[i].setfloat = PX_Designer_SetWidth; + i++; + + PX_strcat(scheckbox.properties[i].Name, "height"); + scheckbox.properties[i].getfloat = PX_Designer_GetHeight; + scheckbox.properties[i].setfloat = PX_Designer_SetHeight; + i++; + + PX_strcat(scheckbox.properties[i].Name, "text"); + scheckbox.properties[i].setstring = PX_Designer_CheckBoxSetText; + scheckbox.properties[i].getstring = PX_Designer_CheckBoxGetText; + i++; + + PX_strcat(scheckbox.properties[i].Name, "check"); + scheckbox.properties[i].setbool = PX_Designer_CheckBoxSetCheck; + scheckbox.properties[i].getbool = PX_Designer_CheckBoxGetCheck; + i++; + + if (designer->pLinkObject) + { + PX_VectorPushback(&designer->ObjectDesc, &scheckbox); + } + if (designer->pLinkWorld) + { + scheckbox.type = PX_DESIGNER_OBJECT_TYPE_GAME; + PX_VectorPushback(&designer->ObjectDesc, &scheckbox); + } + } while (0); + + + do + { + PX_Designer_ObjectDesc edit; + px_int i = 0; + PX_memset(&edit, 0, sizeof(edit)); + PX_strcat(edit.Name, "edit"); + + edit.createfunc = PX_Designer_EditCreate; + edit.type = PX_DESIGNER_OBJECT_TYPE_UI; + + PX_strcat(edit.properties[i].Name, "id"); + edit.properties[i].getstring = PX_Designer_GetID; + edit.properties[i].setstring = PX_Designer_SetID; + i++; + + PX_strcat(edit.properties[i].Name, "x"); + edit.properties[i].getfloat = PX_Designer_GetX; + edit.properties[i].setfloat = PX_Designer_SetX; + i++; + + PX_strcat(edit.properties[i].Name, "y"); + edit.properties[i].getfloat = PX_Designer_GetY; + edit.properties[i].setfloat = PX_Designer_SetY; + i++; + + PX_strcat(edit.properties[i].Name, "width"); + edit.properties[i].getfloat = PX_Designer_GetWidth; + edit.properties[i].setfloat = PX_Designer_SetWidth; + i++; + + PX_strcat(edit.properties[i].Name, "height"); + edit.properties[i].getfloat = PX_Designer_GetHeight; + edit.properties[i].setfloat = PX_Designer_SetHeight; + i++; + + PX_strcat(edit.properties[i].Name, "text"); + edit.properties[i].setstring = PX_Designer_EditSetText; + edit.properties[i].getstring = PX_Designer_EditGetText; + i++; + + if (designer->pLinkObject) + { + PX_VectorPushback(&designer->ObjectDesc, &edit); + } + if (designer->pLinkWorld) + { + edit.type = PX_DESIGNER_OBJECT_TYPE_GAME; + PX_VectorPushback(&designer->ObjectDesc, &edit); + } + + + } while (0); + + + do + { + PX_Designer_ObjectDesc processbar; + px_int i = 0; + PX_memset(&processbar, 0, sizeof(processbar)); + PX_strcat(processbar.Name, "processbar"); + + processbar.createfunc = PX_Designer_ProcessBarCreate; + processbar.type = PX_DESIGNER_OBJECT_TYPE_UI; + + PX_strcat(processbar.properties[i].Name, "id"); + processbar.properties[i].getstring = PX_Designer_GetID; + processbar.properties[i].setstring = PX_Designer_SetID; + i++; + + PX_strcat(processbar.properties[i].Name, "x"); + processbar.properties[i].getfloat = PX_Designer_GetX; + processbar.properties[i].setfloat = PX_Designer_SetX; + i++; + + PX_strcat(processbar.properties[i].Name, "y"); + processbar.properties[i].getfloat = PX_Designer_GetY; + processbar.properties[i].setfloat = PX_Designer_SetY; + i++; + + PX_strcat(processbar.properties[i].Name, "width"); + processbar.properties[i].getfloat = PX_Designer_GetWidth; + processbar.properties[i].setfloat = PX_Designer_SetWidth; + i++; + + PX_strcat(processbar.properties[i].Name, "height"); + processbar.properties[i].getfloat = PX_Designer_GetHeight; + processbar.properties[i].setfloat = PX_Designer_SetHeight; + i++; + + PX_strcat(processbar.properties[i].Name, "max"); + processbar.properties[i].setint = PX_Designer_ProcessBarSetMax; + processbar.properties[i].getint = PX_Designer_ProcessBarGetMax; + i++; + + PX_strcat(processbar.properties[i].Name, "value"); + processbar.properties[i].setint = PX_Designer_ProcessBarSetValue; + processbar.properties[i].getint = PX_Designer_ProcessBarGetValue; + i++; + + if (designer->pLinkObject) + { + PX_VectorPushback(&designer->ObjectDesc, &processbar); + } + if (designer->pLinkWorld) + { + processbar.type = PX_DESIGNER_OBJECT_TYPE_GAME; + PX_VectorPushback(&designer->ObjectDesc, &processbar); + } + } while (0); + + do + { + PX_Designer_ObjectDesc list; + px_int i = 0; + PX_memset(&list, 0, sizeof(list)); + PX_strcat(list.Name, "list"); + + list.createfunc = PX_Designer_ListCreate; + list.type = PX_DESIGNER_OBJECT_TYPE_UI; + + PX_strcat(list.properties[i].Name, "id"); + list.properties[i].getstring = PX_Designer_GetID; + list.properties[i].setstring = PX_Designer_SetID; + i++; + + PX_strcat(list.properties[i].Name, "x"); + list.properties[i].getfloat = PX_Designer_GetX; + list.properties[i].setfloat = PX_Designer_SetX; + i++; + + PX_strcat(list.properties[i].Name, "y"); + list.properties[i].getfloat = PX_Designer_GetY; + list.properties[i].setfloat = PX_Designer_SetY; + i++; + + PX_strcat(list.properties[i].Name, "width"); + list.properties[i].getfloat = PX_Designer_GetWidth; + list.properties[i].setfloat = PX_Designer_SetWidth; + i++; + + PX_strcat(list.properties[i].Name, "height"); + list.properties[i].getfloat = PX_Designer_GetHeight; + list.properties[i].setfloat = PX_Designer_SetHeight; + i++; + + if (designer->pLinkObject) + { + PX_VectorPushback(&designer->ObjectDesc, &list); + } + if (designer->pLinkWorld) + { + list.type = PX_DESIGNER_OBJECT_TYPE_GAME; + PX_VectorPushback(&designer->ObjectDesc, &list); + } + + + } while (0); + + + do + { + PX_Designer_ObjectDesc selectbar; + px_int i = 0; + PX_memset(&selectbar, 0, sizeof(selectbar)); + PX_strcat(selectbar.Name, "selectbar"); + + selectbar.createfunc = PX_Designer_SelectBarCreate; + selectbar.type = PX_DESIGNER_OBJECT_TYPE_UI; + + PX_strcat(selectbar.properties[i].Name, "id"); + selectbar.properties[i].getstring = PX_Designer_GetID; + selectbar.properties[i].setstring = PX_Designer_SetID; + i++; + + PX_strcat(selectbar.properties[i].Name, "x"); + selectbar.properties[i].getfloat = PX_Designer_GetX; + selectbar.properties[i].setfloat = PX_Designer_SetX; + i++; + + PX_strcat(selectbar.properties[i].Name, "y"); + selectbar.properties[i].getfloat = PX_Designer_GetY; + selectbar.properties[i].setfloat = PX_Designer_SetY; + i++; + + PX_strcat(selectbar.properties[i].Name, "width"); + selectbar.properties[i].getfloat = PX_Designer_GetWidth; + selectbar.properties[i].setfloat = PX_Designer_SetWidth; + i++; + + PX_strcat(selectbar.properties[i].Name, "height"); + selectbar.properties[i].getfloat = PX_Designer_GetHeight; + selectbar.properties[i].setfloat = PX_Designer_SetHeight; + i++; + + PX_strcat(selectbar.properties[i].Name, "list"); + selectbar.properties[i].setstring = PX_Designer_SelectBarSetText; + selectbar.properties[i].getstring = PX_Designer_SelectBarGetText; + i++; + + if (designer->pLinkObject) + { + PX_VectorPushback(&designer->ObjectDesc, &selectbar); + } + if (designer->pLinkWorld) + { + selectbar.type = PX_DESIGNER_OBJECT_TYPE_GAME; + PX_VectorPushback(&designer->ObjectDesc, &selectbar); + } + } while (0); + + do + { + PX_Designer_ObjectDesc sliderbar; + px_int i = 0; + PX_memset(&sliderbar, 0, sizeof(sliderbar)); + PX_strcat(sliderbar.Name, "sliderbar"); + + sliderbar.createfunc = PX_Designer_SliderBarCreate; + sliderbar.type = PX_DESIGNER_OBJECT_TYPE_UI; + + PX_strcat(sliderbar.properties[i].Name, "id"); + sliderbar.properties[i].getstring = PX_Designer_GetID; + sliderbar.properties[i].setstring = PX_Designer_SetID; + i++; + + PX_strcat(sliderbar.properties[i].Name, "x"); + sliderbar.properties[i].getfloat = PX_Designer_GetX; + sliderbar.properties[i].setfloat = PX_Designer_SetX; + i++; + + PX_strcat(sliderbar.properties[i].Name, "y"); + sliderbar.properties[i].getfloat = PX_Designer_GetY; + sliderbar.properties[i].setfloat = PX_Designer_SetY; + i++; + + PX_strcat(sliderbar.properties[i].Name, "width"); + sliderbar.properties[i].getfloat = PX_Designer_GetWidth; + sliderbar.properties[i].setfloat = PX_Designer_SetWidth; + i++; + + PX_strcat(sliderbar.properties[i].Name, "height"); + sliderbar.properties[i].getfloat = PX_Designer_GetHeight; + sliderbar.properties[i].setfloat = PX_Designer_SetHeight; + i++; + + PX_strcat(sliderbar.properties[i].Name, "min"); + sliderbar.properties[i].setint = PX_Designer_SliderBarSetMin; + sliderbar.properties[i].getint = PX_Designer_SliderBarGetMin; + i++; + + PX_strcat(sliderbar.properties[i].Name, "max"); + sliderbar.properties[i].setint = PX_Designer_SliderBarSetMax; + sliderbar.properties[i].getint = PX_Designer_SliderBarGetMax; + i++; + + + PX_strcat(sliderbar.properties[i].Name, "type"); + sliderbar.properties[i].setint = PX_Designer_SliderBarSetType; + sliderbar.properties[i].getint = PX_Designer_SliderBarGetType; + i++; + + PX_strcat(sliderbar.properties[i].Name, "style"); + sliderbar.properties[i].setint = PX_Designer_SliderBarSetStyle; + sliderbar.properties[i].getint = PX_Designer_SliderBarGetStyle; + i++; + + PX_strcat(sliderbar.properties[i].Name, "value"); + sliderbar.properties[i].setint = PX_Designer_SliderBarSetValue; + sliderbar.properties[i].getint = PX_Designer_SliderBarGetValue; + i++; + + if (designer->pLinkObject) + { + PX_VectorPushback(&designer->ObjectDesc, &sliderbar); + } + if (designer->pLinkWorld) + { + sliderbar.type = PX_DESIGNER_OBJECT_TYPE_GAME; + PX_VectorPushback(&designer->ObjectDesc, &sliderbar); + } + + + } while (0); + + return PX_TRUE; +} + +px_void PX_DesignerOnMenuExec(px_void *userPtr) +{ + PX_Object *pObject=(PX_Object *)userPtr; + PX_ObjectExecuteEvent(pObject,PX_OBJECT_BUILD_EVENT(PX_OBJECT_EVENT_EXECUTE)); +} + +px_void PX_DesignerOnMenuExit(px_void *userPtr) +{ + PX_Object *pObject=(PX_Object *)userPtr; + PX_ObjectExecuteEvent(pObject,PX_OBJECT_BUILD_EVENT(PX_OBJECT_EVENT_CLOSE)); + PX_DesignerClose(pObject); +} + +px_void PX_DesignerOnMenuWindowControllers(px_void *userPtr) +{ + PX_Object *pObject=(PX_Object *)userPtr; + PX_Designer *pDesc=PX_ObjectGetDesc(PX_Designer,pObject); + + if(pDesc->widget_controllers->Visible) + PX_Object_WidgetHide(pDesc->widget_controllers); + else + PX_Object_WidgetShow(pDesc->widget_controllers); +} + + +px_void PX_DesignerOnMenuViewScrollbar(px_void* userPtr) +{ + PX_Object* pObject = (PX_Object*)userPtr; + PX_Designer* pDesc = PX_ObjectGetDesc(PX_Designer, pObject); + + pDesc->showsliderbar = !pDesc->showsliderbar; +} + +px_void PX_DesignerOnMenuWindowProperties(px_void *userPtr) +{ + PX_Object *pObject=(PX_Object *)userPtr; + PX_Designer *pDesc=PX_ObjectGetDesc(PX_Designer,pObject); + if(pDesc->widget_property->Visible) + PX_Object_WidgetHide(pDesc->widget_property); + else + PX_Object_WidgetShow(pDesc->widget_property); +} + +px_void PX_Designer_OnScrollVChanged(PX_Object* pObject, PX_Object_Event e, px_void* ptr) +{ + PX_Object* pDesignerObject = (PX_Object*)ptr; + PX_Designer* pDesc = PX_ObjectGetDesc(PX_Designer, pDesignerObject); + if (pDesc->pLinkWorld) + { + px_point camera = pDesc->pLinkWorld->camera_offset; + camera.y = PX_Object_SliderBarGetValue(pObject) * 1.0f; + PX_WorldSetCamera(pDesc->pLinkWorld, camera); + } +} + +px_void PX_Designer_OnScrollHChanged(PX_Object* pObject, PX_Object_Event e, px_void* ptr) +{ + PX_Object* pDesignerObject = (PX_Object*)ptr; + PX_Designer* pDesc = PX_ObjectGetDesc(PX_Designer, pDesignerObject); + if (pDesc->pLinkWorld) + { + px_point camera = pDesc->pLinkWorld->camera_offset; + camera.x = PX_Object_SliderBarGetValue(pObject) * 1.0f; + PX_WorldSetCamera(pDesc->pLinkWorld, camera); + } +} + +PX_Object * PX_DesignerCreate(px_memorypool *mp,px_memorypool *mp_ui,px_memorypool *mp_world,PX_Object *pparent,PX_Object *pLinkObject,PX_World *pLinkWorld,PX_FontModule *fm) +{ + px_int i; + PX_Object *pObject; + PX_Designer desc,*pdesc; + PX_memset(&desc,0,sizeof(desc)); + + pObject=PX_ObjectCreateEx(mp,pparent,0,0,0,0,0,0,0x21080210,PX_DesignerUpdate,PX_DesignerRender,PX_NULL,&desc,sizeof(desc)); + pdesc=(PX_Designer *)pObject->pObject; + pdesc->pLinkWorld=pLinkWorld; + pdesc->pLinkObject=pLinkObject; + pdesc->showsliderbar = PX_TRUE; + pdesc->widget_property = PX_Object_WidgetCreate(mp, pObject, 5, 36 + 256, 192, 192, "properties", PX_NULL); + if (!pdesc->widget_property)return PX_FALSE; + if(pdesc->pLinkWorld) + pdesc->widget_property->x = pdesc->pLinkWorld->surface_width - pdesc->widget_property->Width - 25; + + pdesc->widget_propertyscrollarea=PX_Object_ScrollAreaCreate(mp,pdesc->widget_property,0,0,174, 162); + + do + { + PX_Object_Menu_Item *pItem; + pdesc->menu=PX_Object_MenuCreate(mp,pObject,0,0,64,PX_NULL); + + pItem=PX_Object_MenuAddItem(pdesc->menu,PX_Object_MenuGetRootItem(pdesc->menu),"debug",PX_NULL,PX_NULL); + PX_Object_MenuAddItem(pdesc->menu,pItem,"execute",PX_DesignerOnMenuExec,pObject); + PX_Object_MenuAddItem(pdesc->menu,pItem,"exit",PX_DesignerOnMenuExit,pObject); + + pItem=PX_Object_MenuAddItem(pdesc->menu,PX_Object_MenuGetRootItem(pdesc->menu),"window",PX_NULL,PX_NULL); + PX_Object_MenuAddItem(pdesc->menu,pItem,"controllers",PX_DesignerOnMenuWindowControllers,pObject); + PX_Object_MenuAddItem(pdesc->menu,pItem,"properties",PX_DesignerOnMenuWindowProperties,pObject); + + pItem = PX_Object_MenuAddItem(pdesc->menu, PX_Object_MenuGetRootItem(pdesc->menu), "View", PX_NULL, PX_NULL); + PX_Object_MenuAddItem(pdesc->menu, pItem, "ScrollBar", PX_DesignerOnMenuViewScrollbar, pObject); + + } while (0); + + + + for (i=0;ilabel_propertys[i]=PX_Object_LabelCreate(mp,pdesc->widget_propertyscrollarea,5,3+i*24,64,24,"property",fm,PX_OBJECT_UI_DEFAULT_FONTCOLOR); + PX_Object_LabelSetAlign(pdesc->label_propertys[i],PX_ALIGN_LEFTMID); + pdesc->label_propertys[i]->Visible=PX_FALSE; + pdesc->edit_propertys[i]=PX_Object_EditCreate(mp,pdesc->widget_propertyscrollarea,74,3+i*24,96,24,fm); + PX_Object_GetEdit(pdesc->edit_propertys[i])->multiLines = PX_TRUE; + pdesc->edit_propertys[i]->Visible=PX_FALSE; + PX_ObjectRegisterEvent(pdesc->edit_propertys[i],PX_OBJECT_EVENT_VALUECHANGED,PX_Designer_OnPropertyChanged,pObject); + //PX_ObjectRegisterEvent(pdesc->edit_propertys[i],PX_OBJECT_EVENT_LOSTFOCUS,PX_Designer_OnPropertyRefresh,pObject); + } + + + pdesc->widget_controllers=PX_Object_WidgetCreate(mp,pObject,5,25,192,256,"controllers",PX_NULL); + if(!pdesc->widget_controllers)return PX_FALSE; + if (pdesc->pLinkWorld) + pdesc->widget_controllers->x = pdesc->pLinkWorld->surface_width - pdesc->widget_controllers->Width - 25; + + + if (!PX_VectorInitialize(mp, &pdesc->ObjectDesc, sizeof(PX_Designer_ObjectDesc), 16))return PX_FALSE; + if (!PX_VectorInitialize(mp, &pdesc->Objects, sizeof(PX_Designer_Object), 16))return PX_FALSE; + pdesc->mp=mp; + pdesc->mp_ui=mp_ui; + pdesc->mp_game=mp_world; + pdesc->fm=fm; + pdesc->selectObjectIndex=-1; + pdesc->menu=PX_Object_MenuCreate(mp,pObject,0,0,64,fm); + if(!pdesc->menu)return PX_NULL; + pdesc->messagebox=PX_Object_MessageBoxCreate(mp,pObject,fm); + if(!pdesc->messagebox)return PX_NULL; + + pdesc->list_ObjectDesc=PX_Object_ListCreate(mp,PX_Object_WidgetGetRoot(pdesc->widget_controllers),0,1, + (px_int)PX_Object_GetWidget(pdesc->widget_controllers)->renderTarget.width-1, + (px_int)PX_Object_GetWidget(pdesc->widget_controllers)->renderTarget.height-1, + PX_DESIGNER_CONTROLLER_ITEM_HEIGHT, + PX_Designer_ControllersListItemOnCreate, + pObject + ); + pdesc->designerbox=PX_Object_DesignerBoxCreate(mp,pObject,0,0,100,100); + pdesc->designerbox->Visible=PX_FALSE; + + pdesc->button_delete=PX_Object_PushButtonCreate(mp,pObject,0,0,16,16,"x",PX_NULL); + pdesc->button_delete->Visible=PX_FALSE; + PX_ObjectRegisterEvent(pdesc->button_delete,PX_OBJECT_EVENT_EXECUTE,PX_Designer_OnDeleteCurrentObject,pObject); + + pdesc->world_hscroll = PX_Object_SliderBarCreate(mp, pObject, 0, 0, 10, 10, PX_OBJECT_SLIDERBAR_TYPE_HORIZONTAL, PX_OBJECT_SLIDERBAR_STYLE_BOX); + + if (pdesc->pLinkWorld&&pdesc->pLinkWorld->world_width > pdesc->pLinkWorld->surface_width) + { + PX_Object_SliderBarSetRange(pdesc->world_hscroll, (px_int)(pdesc->pLinkWorld->surface_width / 2) - 1, (px_int)(pdesc->pLinkWorld->world_width - pdesc->pLinkWorld->surface_width / 2) + 1); + } + else + { + pdesc->world_hscroll->Visible = PX_FALSE; + } + PX_ObjectRegisterEvent(pdesc->world_hscroll, PX_OBJECT_EVENT_VALUECHANGED, PX_Designer_OnScrollHChanged, pObject); + + + pdesc->world_vscroll = PX_Object_SliderBarCreate(mp, pObject, 0, 0, 10, 10, PX_OBJECT_SLIDERBAR_TYPE_VERTICAL, PX_OBJECT_SLIDERBAR_STYLE_BOX); + if (pdesc->pLinkWorld && pdesc->pLinkWorld->world_height > pdesc->pLinkWorld->surface_height) + { + PX_Object_SliderBarSetRange(pdesc->world_vscroll, (px_int)(pdesc->pLinkWorld->surface_height / 2) - 1, (px_int)(pdesc->pLinkWorld->world_height - pdesc->pLinkWorld->surface_height / 2) + 1); + } + else + { + pdesc->world_vscroll->Visible = PX_FALSE; + } + PX_ObjectRegisterEvent(pdesc->world_vscroll, PX_OBJECT_EVENT_VALUECHANGED, PX_Designer_OnScrollVChanged, pObject); + + if (!PX_DesignerStandardInitialize(pdesc)) + { + return PX_FALSE; + } + + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORDOWN,PX_Designer_OnCursorDown,pObject); + PX_ObjectRegisterEvent(pdesc->designerbox,PX_OBJECT_EVENT_VALUECHANGED,PX_DesignerOnDesignerBoxValueChanged,pObject); + + pObject->Visible = PX_FALSE; + + return pObject; +} + + + +px_void PX_DesignerActivate(PX_Object* pObject) +{ + if (pObject->Type== 0x21080210) + { + PX_ObjectSetVisible(pObject, PX_TRUE); + PX_ObjectSetFocus(pObject); + } +} + +px_void PX_DesignerClose(PX_Object* pObject) +{ + if (pObject->Type == 0x21080210) + { + PX_ObjectSetVisible(pObject, PX_FALSE); + PX_ObjectClearFocus(pObject); + } +} + + + +px_bool PX_DesignerExport(PX_Object *pObject, px_string* pText) +{ + px_int i; + PX_Designer* designer; + if (pObject->Type!=0x21080210) + { + PX_ASSERT(); + return PX_FALSE; + } + designer=PX_ObjectGetDesc(PX_Designer,pObject); + + if (designer->Objects.size==0) + { + return PX_TRUE; + } + + PX_StringCatEx(pText,"{\n"); + + for (i=0;iObjects.size;i++) + { + PX_Designer_Object* pdobject = PX_VECTORAT(PX_Designer_Object, &designer->Objects, i); + PX_Designer_ObjectDesc* pobjectdesc = PX_VECTORAT(PX_Designer_ObjectDesc, &designer->ObjectDesc, pdobject->descIndex); + px_int j; + if (!pobjectdesc) + { + PX_ASSERT(); + goto _ERROR;; + } + //Object Name + if(!PX_StringCatEx(pText,"\""))goto _ERROR; + if(!PX_StringCatEx(pText,pobjectdesc->Name))goto _ERROR; + if(!PX_StringCatEx(pText,"\":{\n"))goto _ERROR; + + //Object Type + switch (pdobject->type) + { + case PX_DESIGNER_OBJECT_TYPE_UI: + if(!PX_StringCatEx(pText,"\"type\":\"ui\",\n"))goto _ERROR; + break; + case PX_DESIGNER_OBJECT_TYPE_GAME: + if(!PX_StringCatEx(pText,"\"type\":\"game\",\n"))goto _ERROR; + break; + case PX_DESIGNER_OBJECT_TYPE_FUNCTION: + PX_ASSERT(); + break; + default: + return PX_FALSE; + } + + for (j=0;jproperties);j++) + { + if (!pobjectdesc->properties[j].Name[0]) + { + break; + } + + if (pobjectdesc->properties[j].getbool) + { + if (pobjectdesc->properties[j].getbool(pdobject->pObject)) + { + if(!PX_StringCatEx(pText,"\""))goto _ERROR; + if(!PX_StringCatEx(pText,pobjectdesc->properties[j].Name))goto _ERROR; + if(!PX_StringCatEx(pText,"\":true"))goto _ERROR; + } + else + { + if(!PX_StringCatEx(pText,"\""))goto _ERROR; + if(!PX_StringCatEx(pText,pobjectdesc->Name))goto _ERROR; + if(!PX_StringCatEx(pText,"\":false"))goto _ERROR; + } + } + else if (pobjectdesc->properties[j].getfloat) + { + if(!PX_StringCatEx(pText,"\""))goto _ERROR; + if(!PX_StringCatEx(pText,pobjectdesc->properties[j].Name))goto _ERROR; + if(!PX_StringCatEx(pText,"\":"))goto _ERROR; + + if(!PX_StringCatEx(pText,PX_ftos(pobjectdesc->properties[j].getfloat(pdobject->pObject),2).data))goto _ERROR; + } + else if (pobjectdesc->properties[j].getint) + { + if(!PX_StringCatEx(pText,"\""))goto _ERROR; + if(!PX_StringCatEx(pText,pobjectdesc->properties[j].Name))goto _ERROR; + if(!PX_StringCatEx(pText,"\":"))goto _ERROR; + + if(!PX_StringCatEx(pText,PX_itos(pobjectdesc->properties[j].getint(pdobject->pObject),10).data))goto _ERROR; + } + else if (pobjectdesc->properties[j].getstring) + { + px_string str; + if(!PX_StringCatEx(pText,"\""))goto _ERROR; + if(!PX_StringCatEx(pText,pobjectdesc->properties[j].Name))goto _ERROR; + if(!PX_StringCatEx(pText,"\":\""))goto _ERROR; + PX_StringInitialize(designer->mp, &str); + pobjectdesc->properties[j].getstring(pdobject->pObject, &str); + + if (!PX_StringCatEx(pText,str.buffer )) + { + PX_StringFree(&str); + goto _ERROR; + } + PX_StringFree(&str); + if(!PX_StringCatEx(pText,"\""))goto _ERROR; + } + if(!PX_StringCatEx(pText,",\n"))goto _ERROR; + } + PX_StringBackspaceEx(pText); + PX_StringBackspaceEx(pText); + PX_StringCatEx(pText,"\n},\n"); + } + PX_StringBackspaceEx(pText); + PX_StringBackspaceEx(pText); + + PX_StringCatEx(pText,"\n}\n"); + + return PX_TRUE; +_ERROR: + PX_StringClear(pText); + return PX_FALSE; + +} + +px_bool PX_DesignerImport(PX_Object* pObject, const px_char* pText) +{ + PX_Json Json; + px_int i; + PX_Designer * pdesigner=PX_ObjectGetDesc(PX_Designer,pObject); + if(!PX_JsonInitialize(pdesigner->mp,&Json))return PX_FALSE; + if (!PX_JsonParse(&Json,pText)) + { + goto _ERROR; + } + for (i=0;itype!=PX_JSON_VALUE_TYPE_OBJECT) + { + continue; + } + pObjectDesc=PX_NULL; + for (j=0;jObjectDesc.size;j++) + { + PX_Designer_ObjectDesc *pEnumObjectDesc=PX_VECTORAT(PX_Designer_ObjectDesc,&pdesigner->ObjectDesc,j); + if (PX_strequ(pJsonValue->name.buffer,pEnumObjectDesc->Name)) + { + pObjectDesc=pEnumObjectDesc; + descindex=j; + break; + } + } + if (pObjectDesc) + { + PX_Json_Value *TypeValue=PX_JsonGetObjectValue(pJsonValue,"type"); + PX_DESIGNER_OBJECT_TYPE type; + PX_Object *pNewObject=PX_NULL; + if (TypeValue&&TypeValue->type==PX_JSON_VALUE_TYPE_STRING) + { + if (PX_strequ(TypeValue->_string.buffer,"ui")) + { + type=PX_DESIGNER_OBJECT_TYPE_UI; + } + else if (PX_strequ(TypeValue->_string.buffer,"game")) + { + type=PX_DESIGNER_OBJECT_TYPE_GAME; + } + else + { + type=PX_DESIGNER_OBJECT_TYPE_FUNCTION; + } + } + + + switch (type) + { + case PX_DESIGNER_OBJECT_TYPE_UI: + { + PX_Designer_Object dobject; + pNewObject=pObjectDesc->createfunc(pdesigner->mp_ui,pdesigner->pLinkObject,0,0,100,100,pdesigner->fm); + dobject.pObject = pNewObject; + dobject.type = PX_DESIGNER_OBJECT_TYPE_UI; + dobject.descIndex = descindex; + PX_VectorPushback(&pdesigner->Objects, &dobject); + } + break; + case PX_DESIGNER_OBJECT_TYPE_GAME: + { + PX_Designer_Object dobject; + pNewObject=pObjectDesc->createfunc(pdesigner->mp_game,PX_NULL,0,0,100,100,pdesigner->fm); + PX_WorldAddObject(pdesigner->pLinkWorld, pNewObject); + dobject.pObject = pNewObject; + dobject.type = PX_DESIGNER_OBJECT_TYPE_GAME; + dobject.descIndex = descindex; + PX_VectorPushback(&pdesigner->Objects, &dobject); + } + break; + default: + break; + } + + if (pNewObject) + { + for(j=0;jproperties);j++) + { + if (pObjectDesc->properties[j].Name[0]=='\0') + { + break; + } + if (pObjectDesc->properties[j].setbool) + { + PX_Json_Value *pvalue=PX_JsonGetObjectValue(pJsonValue,pObjectDesc->properties[j].Name); + if (pvalue&&pvalue->type==PX_JSON_VALUE_TYPE_BOOLEAN) + { + pObjectDesc->properties[j].setbool(pNewObject,pvalue->_boolean); + } + } + else if(pObjectDesc->properties[j].setfloat) + { + PX_Json_Value *pvalue=PX_JsonGetObjectValue(pJsonValue,pObjectDesc->properties[j].Name); + if (pvalue&&pvalue->type==PX_JSON_VALUE_TYPE_NUMBER) + { + pObjectDesc->properties[j].setfloat(pNewObject,(px_float)pvalue->_number); + } + } + else if(pObjectDesc->properties[j].setint) + { + PX_Json_Value *pvalue=PX_JsonGetObjectValue(pJsonValue,pObjectDesc->properties[j].Name); + if (pvalue&&pvalue->type==PX_JSON_VALUE_TYPE_NUMBER) + { + pObjectDesc->properties[j].setint(pNewObject,(px_int)pvalue->_number); + } + } + else if(pObjectDesc->properties[j].setstring) + { + PX_Json_Value *pvalue=PX_JsonGetObjectValue(pJsonValue,pObjectDesc->properties[j].Name); + if (pvalue&&pvalue->type==PX_JSON_VALUE_TYPE_STRING) + { + pObjectDesc->properties[j].setstring(pNewObject,pvalue->_string.buffer); + } + } + } + } + + } + } + + PX_JsonFree(&Json); + return PX_TRUE; +_ERROR: + PX_JsonFree(&Json); + return PX_FALSE; +} diff --git a/lib/PainterEngine/architecture/PainterEngine_Designer.h b/lib/PainterEngine/architecture/PainterEngine_Designer.h new file mode 100644 index 0000000000000000000000000000000000000000..41ad065d403f275368d46fe1ffaa08396688360e --- /dev/null +++ b/lib/PainterEngine/architecture/PainterEngine_Designer.h @@ -0,0 +1,96 @@ +#ifndef PX_DESIGNER_H +#define PX_DESIGNER_H + +#include "../kernel/PX_Kernel.h" + +#define PX_DESIGNER_NAME_LENGTH 48 +#define PX_DESIGNER_MAX_PROPERTYS 32 +#define PX_DESIGNER_CONTROLLER_ITEM_HEIGHT 20 +typedef enum +{ + PX_DESIGNER_OBJECT_TYPE_UI, + PX_DESIGNER_OBJECT_TYPE_GAME, + PX_DESIGNER_OBJECT_TYPE_FUNCTION, +}PX_DESIGNER_OBJECT_TYPE; + + +typedef PX_Object *(*px_designer_createfunc)(px_memorypool *mp,PX_Object *pparent,px_float x,px_float y,px_float width,px_float height,PX_FontModule *fm); + +typedef px_float (*px_designer_getproperty_float)(PX_Object *pObject); +typedef px_int (*px_designer_getproperty_int)(PX_Object *pObject); +typedef px_bool (*px_designer_getproperty_string)(PX_Object *pObject,px_string *str); +typedef px_bool (*px_designer_getproperty_bool)(PX_Object *pObject); + +typedef px_void (*px_designer_setproperty_float)(PX_Object *pObject,px_float v); +typedef px_void (*px_designer_setproperty_int)(PX_Object *pObject,px_int v); +typedef px_void (*px_designer_setproperty_string)(PX_Object *pObject,const px_char v[]); +typedef px_void (*px_designer_setproperty_bool)(PX_Object *pObject,px_bool v); + +typedef struct +{ + px_char Name[PX_DESIGNER_NAME_LENGTH]; + //get + px_designer_getproperty_float getfloat; + px_designer_getproperty_int getint; + px_designer_getproperty_string getstring; + px_designer_getproperty_bool getbool; + + //set + px_designer_setproperty_float setfloat; + px_designer_setproperty_int setint; + px_designer_setproperty_string setstring; + px_designer_setproperty_bool setbool; + +}PX_Designer_Object_property; + + + +typedef struct +{ + px_char Name[PX_DESIGNER_NAME_LENGTH]; + px_designer_createfunc createfunc; + PX_DESIGNER_OBJECT_TYPE type; + PX_Designer_Object_property properties[PX_DESIGNER_MAX_PROPERTYS]; +}PX_Designer_ObjectDesc; + + +typedef struct +{ + PX_Object *pObject; + px_int descIndex; + PX_DESIGNER_OBJECT_TYPE type; +}PX_Designer_Object; + + +typedef struct +{ + px_memorypool *mp,*mp_ui,*mp_game; + PX_Object *pLinkObject; + PX_World *pLinkWorld; + + PX_Object *widget_controllers; + PX_Object *widget_property,*widget_propertyscrollarea; + PX_Object* world_hscroll, *world_vscroll; + PX_Object* designerbox; + PX_Object* list_ObjectDesc; + PX_Object* button_delete; + PX_Object* messagebox; + PX_Object* menu,*menu_run,*menu_exit,menu_window_controllers,menu_window_properties; + PX_Object* label_propertys[PX_DESIGNER_MAX_PROPERTYS]; + PX_Object* edit_propertys[PX_DESIGNER_MAX_PROPERTYS]; + PX_FontModule *fm; + px_int allocID; + px_int selectObjectIndex; + px_bool showsliderbar; + px_float lastcursorx; + px_float lastcursory; + px_vector ObjectDesc; + px_vector Objects; +}PX_Designer; + +PX_Object * PX_DesignerCreate(px_memorypool *mp,px_memorypool *mp_ui,px_memorypool*mp_world,PX_Object *pparent,PX_Object *pLinkObject,PX_World *pLinkWorld,PX_FontModule *fm); +px_void PX_DesignerActivate(PX_Object* pObject); +px_void PX_DesignerClose(PX_Object* pObject); +px_bool PX_DesignerExport(PX_Object* pObject, px_string* pText); +px_bool PX_DesignerImport(PX_Object* pObject, const px_char* pText); +#endif \ No newline at end of file diff --git a/lib/PainterEngine/architecture/PainterEngine_Executer.c b/lib/PainterEngine/architecture/PainterEngine_Executer.c new file mode 100644 index 0000000000000000000000000000000000000000..cbb65f65f300df08b22cc1bb1ea4bb6f98533e9c --- /dev/null +++ b/lib/PainterEngine/architecture/PainterEngine_Executer.c @@ -0,0 +1,578 @@ +#include "PainterEngine_Executer.h" + +static char const fox_executer_logo[]= +{ +#include "PainterEngine_FoxLogo.h" +}; + +px_void PX_ExecuterUpdateEx(PX_Executer *pExecute) +{ + px_int i,y=10; + PX_ExecuterColumn *pCc; + + while (pExecute->pObjects.size>pExecute->max_column) + { + pCc=(PX_VECTORAT(PX_ExecuterColumn,&pExecute->pObjects,0)); + PX_ObjectDelete(pCc->Object); + PX_VectorErase(&pExecute->pObjects,0); + } + + for (i=0;ipObjects.size;i++) + { + pCc=(PX_VECTORAT(PX_ExecuterColumn,&pExecute->pObjects,i)); + + switch(pCc->Object->Type) + { + case PX_OBJECT_TYPE_AUTOTEXT: + { + PX_ObjectSetPosition(pCc->Object,0,(px_float)y,0); + y+=PX_Object_AutoTextGetHeight(pCc->Object); + } + break; + case PX_OBJECT_TYPE_IMAGE: + { + PX_ObjectSetPosition(pCc->Object,0,(px_float)y,0); + y+=(px_int)PX_ObjectGetHeight(pCc->Object); + } + break; + case PX_OBJECT_TYPE_ANIMATION: + { + PX_ObjectSetPosition(pCc->Object,0,(px_float)y,0); + y+=(px_int)PX_ObjectGetHeight(pCc->Object); + } + break; + default: + { + PX_ObjectSetPosition(pCc->Object,0,(px_float)y,0); + y+=(px_int)PX_ObjectGetHeight(pCc->Object); + } + break; + } + } + PX_ObjectSetPosition(pExecute->Input,0,(px_float)y,0); +} +PX_Object * PX_ExecuterPrintText(PX_Executer *pExecute,const px_char *text) +{ + PX_ExecuterColumn obj; + PX_Object *pObject=PX_Object_AutoTextCreate(&pExecute->runtime->mp_ui,(pExecute->Area),0,0,pExecute->runtime->surface_width-1,PX_NULL); + + if (pObject) + { + obj.Object=pObject; + obj.id=pExecute->id++; + PX_Object_AutoTextSetTextColor(pObject,PX_COLOR(255,0,255,0)); + PX_Object_AutoTextSetText(pObject,text); + PX_VectorPushback(&pExecute->pObjects,&obj); + PX_ExecuterUpdateEx(pExecute); + PX_Object_ScrollAreaMoveToBottom(pExecute->Area); + } + return pObject; +} + +PX_Object * PX_ExecuterLastPrintText(PX_Executer *pExecute,const px_char *text) +{ + PX_ExecuterColumn *pobjColumn; + PX_Object *pObject; + if (pExecute->pObjects.size==0) + { + return PX_NULL; + } + pobjColumn=PX_VECTORLAST(PX_ExecuterColumn,&pExecute->pObjects); + pObject=pobjColumn->Object; + if (pObject->Type==PX_OBJECT_TYPE_AUTOTEXT) + { + PX_Object_AutoTextSetTextColor(pObject,PX_COLOR(255,0,255,0)); + PX_Object_AutoTextSetText(pObject,text); + return pObject; + } + else + return PX_NULL; + +} + +PX_Object * PX_ExecuterPrintImage(PX_Executer *pExecute,const px_char *res_image_key) +{ + PX_ExecuterColumn obj; + PX_Resource *pimageRes; + PX_Object *pObject; + if((pimageRes=PX_ResourceLibraryGet(&pExecute->runtime->ResourceLibrary,res_image_key))!=PX_NULL) + { + if (pimageRes->Type==PX_RESOURCE_TYPE_TEXTURE) + { + pObject=PX_Object_ImageCreate(&pExecute->runtime->mp_ui,pExecute->Area,0,0,pimageRes->texture.width,pimageRes->texture.height,&pimageRes->texture); + PX_Object_ImageSetAlign(pObject,PX_ALIGN_LEFTTOP); + PX_ObjectSetSize(pObject,(px_float)pimageRes->texture.width,(px_float)pimageRes->texture.height,0); + obj.Object=pObject; + obj.id=pExecute->id++; + PX_VectorPushback(&pExecute->pObjects,&obj); + PX_ExecuterUpdateEx(pExecute); + PX_Object_ScrollAreaMoveToBottom(pExecute->Area); + } + else + return PX_NULL; + } + else + { + return PX_NULL; + } + + return pObject; +} +px_bool PX_ExecuterVM_LastPrint(PX_ScriptVM_Instance *Ins,px_void *userptr) +{ + PX_Executer *pExecute=(PX_Executer *)userptr; + + if (PX_ScriptVM_STACK(Ins,0).type!=PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_ScriptVM_RET(Ins,PX_ScriptVM_Variable_int(0)); + return PX_TRUE; + } + PX_ExecuterLastPrintText(pExecute,PX_ScriptVM_STACK(Ins,0)._string.buffer); + PX_ScriptVM_RET(Ins,PX_ScriptVM_Variable_int(PX_VECTORAT(PX_ExecuterColumn,&pExecute->pObjects,pExecute->pObjects.size-1)->id)); + return PX_TRUE; +} + +px_bool PX_ExecuterVM_Print(PX_ScriptVM_Instance *Ins,px_void *userptr) +{ + PX_Executer *pExecute=(PX_Executer *)userptr; + + if (PX_ScriptVM_STACK(Ins,0).type!=PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_ScriptVM_RET(Ins,PX_ScriptVM_Variable_int(0)); + return PX_TRUE; + } + PX_ExecuterPrintText(pExecute,PX_ScriptVM_STACK(Ins,0)._string.buffer); + PX_ScriptVM_RET(Ins,PX_ScriptVM_Variable_int(PX_VECTORAT(PX_ExecuterColumn,&pExecute->pObjects,pExecute->pObjects.size-1)->id)); + return PX_TRUE; +} +px_bool PX_ExecuterVM_PrintImage(PX_ScriptVM_Instance *Ins,px_void *userptr) +{ + PX_Executer *pExecute=(PX_Executer *)userptr; + + if (PX_ScriptVM_STACK(Ins,0).type!=PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_ScriptVM_RET(Ins,PX_ScriptVM_Variable_int(0)); + return PX_TRUE; + } + PX_ExecuterPrintImage(pExecute,PX_ScriptVM_STACK(Ins,0)._string.buffer); + PX_ScriptVM_RET(Ins,PX_ScriptVM_Variable_int(PX_VECTORAT(PX_ExecuterColumn,&pExecute->pObjects,pExecute->pObjects.size-1)->id)); + return PX_TRUE; +} + + +px_bool PX_ExecuterVM_Sleep(PX_ScriptVM_Instance *Ins,px_void *userptr) +{ + PX_Executer *pExecute=(PX_Executer *)userptr; + + if (PX_ScriptVM_STACK(Ins,0).type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_RET(Ins,PX_ScriptVM_Variable_int(0)); + return PX_TRUE; + } + pExecute->Sleep[Ins->T]=PX_ScriptVM_STACK(Ins,0)._int; + PX_ScriptVM_ThreadSuspend(Ins,Ins->T); + PX_ScriptVM_RET(Ins,PX_ScriptVM_Variable_int(0)); + return PX_TRUE; +} + +px_bool PX_ExecuterVM_Rand(PX_ScriptVM_Instance *Ins,px_void *userptr) +{ + PX_ScriptVM_RET(Ins,PX_ScriptVM_Variable_int(PX_rand()%0x7fffffff)); + return PX_TRUE; +} + +px_bool PX_ExecuterVM_Sin(PX_ScriptVM_Instance *Ins,px_void *userptr) +{ + if (PX_ScriptVM_STACK(Ins,0).type!=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + PX_ScriptVM_RET(Ins,PX_ScriptVM_Variable_int(0)); + return PX_TRUE; + } + PX_ScriptVM_RET(Ins,PX_ScriptVM_Variable_float((px_float)PX_sind(PX_ScriptVM_STACK(Ins,0)._float))); + return PX_TRUE; +} + +px_bool PX_ExecuterVM_Cos(PX_ScriptVM_Instance *Ins,px_void *userptr) +{ + if (PX_ScriptVM_STACK(Ins,0).type!=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + PX_ScriptVM_RET(Ins,PX_ScriptVM_Variable_int(0)); + return PX_TRUE; + } + PX_ScriptVM_RET(Ins,PX_ScriptVM_Variable_float((px_float)PX_cosd(PX_ScriptVM_STACK(Ins,0)._float))); + return PX_TRUE; +} + +px_bool PX_ExecuterVM_Gets(PX_ScriptVM_Instance *Ins,px_void *userptr) +{ + PX_Executer *pExecute=(PX_Executer *)userptr; + Ins->pThread[Ins->T].suspend=PX_TRUE; + pExecute->bInput=PX_TRUE; + return PX_TRUE; +} + +px_void PX_ExecuterClear(PX_Executer *pExecute) +{ + PX_ExecuterColumn *pCc; + px_int i; + for (i=0;ipObjects.size;i++) + { + pCc=(PX_VECTORAT(PX_ExecuterColumn,&pExecute->pObjects,i)); + PX_ObjectDelete(pCc->Object); + } + PX_VectorClear(&pExecute->pObjects); +} + +px_bool PX_ExecuterVM_Clear(PX_ScriptVM_Instance *Ins,px_void *userptr) +{ + PX_Executer *pExecute=(PX_Executer *)userptr; + PX_ExecuterClear(pExecute); + return PX_TRUE; +} + + +px_bool PX_ExecuterVM_CreateThread(PX_ScriptVM_Instance *Ins,px_void *userptr) +{ + PX_Executer *pExecute=(PX_Executer *)userptr; + + if (PX_ScriptVM_STACK(Ins,0).type!=PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_ScriptVM_RET(Ins,PX_ScriptVM_Variable_int(0)); + return PX_TRUE; + } + + if(!PX_ScriptVM_InstanceBeginThreadFunction(&pExecute->VM_Instance,PX_ScriptVM_InstanceGetFreeThreadId(Ins),PX_ScriptVM_STACK(Ins,0)._string.buffer,PX_NULL,0)) + { + PX_ScriptVM_RET(Ins,PX_ScriptVM_Variable_int(0)); + } + return PX_TRUE; +} + + + + +px_bool PX_ExecuterRunScipt(PX_Executer *pExecute,const px_char *pshellstr) +{ + px_memory bin; + PX_SCRIPT_LIBRARY lib; + px_string asmcodeString; + px_memorypool mp_calc; + const px_char stdio[]="#name \"stdlib.h\"\n\ + host int print(string s);\n\ + host int printImage(string key);\n\ + host string gets();\n\ + host void clear();\n\ + host void sleep(int millionsecond);\n\ + host int rand();\n\ + host float sin(float x);\n\ + host float cos(float x);\n\ + host int lastprint(string s);\n\ + host int createthread(string callname);\n\ + "; + mp_calc=MP_Create(MP_Malloc(&pExecute->runtime->mp,PE_MEMORY_CALC_SIZE),PE_MEMORY_CALC_SIZE); + if(mp_calc.StartAddr==PX_NULL) return PX_FALSE; + MP_Reset(&mp_calc); + PX_MemoryInitialize(&mp_calc,&bin); + + if(!PX_ScriptCompilerInitialize(&lib,&mp_calc)) + { + MP_Free(&pExecute->runtime->mp,mp_calc.StartAddr); + return PX_FALSE; + } + + if(!PX_ScriptCompilerLoad(&lib,stdio)) + { + MP_Free(&pExecute->runtime->mp,mp_calc.StartAddr); + return PX_FALSE; + } + + if(!PX_ScriptCompilerLoad(&lib,pshellstr)) + { + MP_Free(&pExecute->runtime->mp,mp_calc.StartAddr); + return PX_FALSE; + } + + + PX_StringInitialize(&mp_calc,&asmcodeString); + if(PX_ScriptCompilerCompile(&lib,"main",&asmcodeString,128)) + { + PX_ScriptAsmOptimization(&asmcodeString); + + if(!PX_ScriptAsmCompile(&mp_calc,asmcodeString.buffer,&bin)) + { + MP_Free(&pExecute->runtime->mp,mp_calc.StartAddr); + return PX_FALSE; + } + } + else + { + MP_Free(&pExecute->runtime->mp,mp_calc.StartAddr); + return PX_FALSE; + } + + PX_StringFree(&asmcodeString); + PX_ScriptCompilerFree(&lib); + + //Load + if(!PX_ScriptVM_InstanceInitialize(&pExecute->VM_Instance,&pExecute->runtime->mp_game,bin.buffer,bin.usedsize)) + { + MP_Free(&pExecute->runtime->mp,mp_calc.StartAddr); + return PX_FALSE; + } + PX_MemoryFree(&bin); + MP_Free(&pExecute->runtime->mp,mp_calc.StartAddr); + //RegistryFunctions + + PX_ScriptVM_RegistryHostFunction(&pExecute->VM_Instance,"print",PX_ExecuterVM_Print,pExecute);//Print + PX_ScriptVM_RegistryHostFunction(&pExecute->VM_Instance,"printImage",PX_ExecuterVM_PrintImage,pExecute);//Print Image + PX_ScriptVM_RegistryHostFunction(&pExecute->VM_Instance,"gets",PX_ExecuterVM_Gets,pExecute);//Gets + PX_ScriptVM_RegistryHostFunction(&pExecute->VM_Instance,"clear",PX_ExecuterVM_Clear,pExecute);//Clear + PX_ScriptVM_RegistryHostFunction(&pExecute->VM_Instance,"sleep",PX_ExecuterVM_Sleep,pExecute);//Sleep + PX_ScriptVM_RegistryHostFunction(&pExecute->VM_Instance,"rand",PX_ExecuterVM_Rand,pExecute);//Rand + PX_ScriptVM_RegistryHostFunction(&pExecute->VM_Instance,"sin",PX_ExecuterVM_Sin,pExecute);//Rand + PX_ScriptVM_RegistryHostFunction(&pExecute->VM_Instance,"cos",PX_ExecuterVM_Cos,pExecute);//Rand + PX_ScriptVM_RegistryHostFunction(&pExecute->VM_Instance,"lastprint",PX_ExecuterVM_LastPrint,pExecute);//lastprint + PX_ScriptVM_RegistryHostFunction(&pExecute->VM_Instance,"createthread",PX_ExecuterVM_CreateThread,pExecute);//lastprint + ////////////////////////////////////////////////////////////////////////// + //sleep + if (pExecute->Sleep) + { + MP_Free(&pExecute->runtime->mp_game,pExecute->Sleep); + } + pExecute->Sleep=(px_dword *)MP_Malloc(&pExecute->runtime->mp_game,pExecute->VM_Instance.maxThreadCount*sizeof(px_dword)); + + + ////////////////////////////////////////////////////////////////////////// + + if(!PX_ScriptVM_InstanceRunFunction(&pExecute->VM_Instance,0,"_BOOT",PX_NULL,0)) + { + + return PX_FALSE; + } + + if(!PX_ScriptVM_InstanceBeginThreadFunction(&pExecute->VM_Instance,0,"MAIN",PX_NULL,0)) + { + return PX_FALSE; + } + + + return PX_TRUE; + +} + + +px_bool PX_ExecuterLoadScipt(PX_Executer* pExecuter, const px_char* pshellstr) +{ + return PX_ExecuterRunScipt(pExecuter, pshellstr); +} + +px_bool PX_ExecuterRegistryHostFunction(PX_Executer *pExecuter,const px_char Name[],PX_ScriptVM_Function_Modules function,px_void *userptr) +{ + return PX_ScriptVM_RegistryHostFunction(&pExecuter->VM_Instance,Name,function,userptr); +} + +px_void PX_ExecuterOnEnter(PX_Object *Obj,PX_Object_Event e,px_void *user_ptr) +{ + PX_Executer *pExecute=(PX_Executer *)Obj->User_ptr; + PX_Object_Edit *pEdit=PX_Object_GetEdit(pExecute->Input); + + if (!pExecute->Input->Visible) + { + return; + } + + if (e.Event==PX_OBJECT_EVENT_KEYDOWN) + { + if (PX_Object_Event_GetKeyDown(e)=='\r') + { + PX_ScriptVM_RET(&pExecute->VM_Instance,PX_ScriptVM_Variable_const_string(pEdit->text.buffer)); + PX_ExecuterPrintText(pExecute,pEdit->text.buffer); + PX_Object_EditSetText(pExecute->Input,""); + pExecute->bInput=PX_FALSE; + pExecute->VM_Instance.pThread[0].suspend=PX_FALSE; + + } + } + + if (e.Event==PX_OBJECT_EVENT_CURSORRDOWN) + { + PX_Object_EditSetFocus(pExecute->Input,PX_TRUE); + } +} + +px_void PX_ExecuterOnMouseDown(PX_Object *Obj,PX_Object_Event e,px_void *user_ptr) +{ + PX_Executer *pExecute=(PX_Executer *)Obj->User_ptr; + if (e.Event==PX_OBJECT_EVENT_CURSORDOWN) + { + PX_Object_EditSetFocus(pExecute->Input,PX_TRUE); + } +} + + +PX_Object * PX_ExecuterShowImage(PX_Executer *pExecute,const px_char *res_image_key) +{ + PX_ExecuterColumn obj; + PX_Resource *pimageRes; + PX_Object *pObject; + if((pimageRes=PX_ResourceLibraryGet(&pExecute->runtime->ResourceLibrary,res_image_key))!=PX_NULL) + { + if (pimageRes->Type==PX_RESOURCE_TYPE_TEXTURE) + { + pObject=PX_Object_ImageCreate(&pExecute->runtime->mp_ui,PX_Object_ScrollAreaGetIncludedObjects(pExecute->Area),0,0,pimageRes->texture.width,pimageRes->texture.height,&pimageRes->texture); + PX_Object_ImageSetAlign(pObject,PX_ALIGN_LEFTTOP); + obj.Object=pObject; + obj.id=pExecute->id++; + PX_VectorPushback(&pExecute->pObjects,&obj); + PX_ExecuterUpdateEx(pExecute); + PX_Object_ScrollAreaMoveToBottom(pExecute->Area); + } + else + return PX_NULL; + } + else + { + return PX_NULL; + } + + return pObject; +} + + + +px_bool PX_ExecuterInitialize(PX_Runtime *runtime,PX_Executer *pExecute) +{ + //console initialize + PX_memset(pExecute,0,sizeof(PX_Executer)); + + pExecute->runtime=runtime; + pExecute->show=PX_TRUE; + pExecute->max_column=PX_EXECUTER_DEFAULT_MAX_COLUMN; + pExecute->column=0; + if(!(pExecute->Root=PX_ObjectCreate(&pExecute->runtime->mp_ui,0,0,0,0,0,0,0))) return PX_FALSE; + if(!(pExecute->Area=PX_Object_ScrollAreaCreate(&pExecute->runtime->mp_ui,pExecute->Root,0,0,pExecute->runtime->surface_width,pExecute->runtime->surface_height))) return PX_FALSE; + + + pExecute->Area->User_ptr=pExecute; + PX_ObjectRegisterEvent(pExecute->Area,PX_OBJECT_EVENT_KEYDOWN,PX_ExecuterOnEnter,PX_NULL); + PX_ObjectRegisterEvent(pExecute->Area,PX_OBJECT_EVENT_CURSORDOWN,PX_ExecuterOnMouseDown,PX_NULL); + PX_Object_ScrollAreaSetBorder(pExecute->Area,PX_FALSE); + if(!(pExecute->Input=PX_Object_EditCreate(&pExecute->runtime->mp_ui,(pExecute->Area),0,0,pExecute->runtime->surface_width-1,PX_FontGetCharactorHeight()+4,PX_NULL))) return PX_FALSE; + PX_Object_EditSetTextColor(pExecute->Input,PX_COLOR(255,0,255,0)); + PX_Object_EditSetCursorColor(pExecute->Input,PX_COLOR(255,0,255,0)); + PX_Object_EditSetTextColor(pExecute->Input,PX_COLOR(255,0,255,0)); + PX_Object_EditSetBorderColor(pExecute->Input,PX_COLOR(255,0,255,0)); + PX_Object_EditSetOffset(pExecute->Input,2,3); + PX_Object_EditSetLimit(pExecute->Input,"zxcvbnm,./asdfghjkl;'qwertyyuiop[]\\`1234567890-=ZXCVBNM<>?ASDFGHJKL:\"QWERTYUIOP{}|~!@#$%^&*()_+"); + PX_Object_ScrollAreaSetBkColor(pExecute->Area,PX_COLOR(255,0,0,0)); + pExecute->id=1; + + PX_VectorInitialize(&pExecute->runtime->mp_ui,&pExecute->pObjects,sizeof(PX_ExecuterColumn),PX_EXECUTER_DEFAULT_MAX_COLUMN); + + + ////////////////////////////////////////////////////////////////////////// + //logo + + if(!PX_ResourceLibraryLoad(&pExecute->runtime->ResourceLibrary,PX_RESOURCE_TYPE_TEXTURE,(px_byte *)fox_executer_logo,sizeof(fox_executer_logo),"fox_executer_logo"))return PX_FALSE; + + PX_ExecuterShowImage(pExecute,"fox_executer_logo"); + PX_ExecuterShowImage(pExecute,"console_logo"); + PX_ExecuterPrintText(pExecute,"----------------------------------------"); + PX_ExecuterPrintText(pExecute,"-PainterEngine Script Executer -\n-Code By DBinary Build on v2021 -\n-Refer To:www.GitHub.com/matrixcascade -"); + PX_ExecuterPrintText(pExecute,"----------------------------------------"); + + + return PX_TRUE; +} +px_void PX_ExecuterPostEvent(PX_Executer *pExecute,PX_Object_Event e) +{ + if(pExecute->show) + { + if (e.Event==PX_OBJECT_EVENT_KEYDOWN) + { + if (PX_Object_Event_GetKeyDown(e)==36) + { + PX_ExecuterShow(pExecute,PX_FALSE); + return; + } + } + + if (e.Event!=PX_OBJECT_EVENT_CURSORMOVE) + { + PX_ObjectPostEvent(pExecute->Root,e); + } + } + else + { + if (e.Event==PX_OBJECT_EVENT_KEYDOWN) + { + if (PX_Object_Event_GetKeyDown(e)==36) + { + PX_ExecuterShow(pExecute,PX_TRUE); + } + } + } +} +px_void PX_ExecuterUpdate(PX_Executer *pExecute,px_dword elapsed) +{ + px_int i; + + pExecute->Area->Width=(px_float)pExecute->runtime->surface_width; + pExecute->Area->Height=(px_float)pExecute->runtime->surface_height; + pExecute->Input->Width=(px_float)pExecute->runtime->surface_width-1; + PX_ObjectUpdate(pExecute->Area,elapsed); + + if (pExecute->bInput) + { + pExecute->Input->Visible=PX_TRUE; + } + else + { + pExecute->Input->Visible=PX_FALSE; + } + + if (pExecute->VM_Instance.binsize) + { + for (i=0;iVM_Instance.maxThreadCount;i++) + { + if (pExecute->VM_Instance.pThread[i].Activated) + { + if (pExecute->Sleep[i]==0) + { + PX_ScriptVM_InstanceRun(&pExecute->VM_Instance,0xffff); + } + else + { + if (pExecute->Sleep[i]<=elapsed) + { + pExecute->VM_Instance.pThread[i].suspend=PX_FALSE; + pExecute->Sleep[i]=0; + } + else + { + pExecute->VM_Instance.pThread[i].suspend=PX_TRUE; + pExecute->Sleep[i]-=elapsed; + } + } + + } + } + + } + +} + + +px_void PX_ExecuterShow(PX_Executer *pExecute,px_bool b) +{ + pExecute->show=b; +} + +px_void PX_ExecuterRender(PX_Executer *pExecute,px_dword elapsed) +{ + if(pExecute->show) + { + PX_ObjectRender(&pExecute->runtime->RenderSurface,pExecute->Area,elapsed); + } +} + diff --git a/lib/PainterEngine/architecture/PainterEngine_Executer.h b/lib/PainterEngine/architecture/PainterEngine_Executer.h new file mode 100644 index 0000000000000000000000000000000000000000..244b5b29cd9affceacb3a862389891f63dfcef0c --- /dev/null +++ b/lib/PainterEngine/architecture/PainterEngine_Executer.h @@ -0,0 +1,46 @@ +#ifndef PX_EXECUTER_H +#define PX_EXECUTER_H + +#include "PainterEngine_Runtime.h" + +#define PX_EXECUTER_DEFAULT_MAX_COLUMN 48 +#define PX_EXECUTER_INPUT_CONTENT_SIZE 1024 +#define PX_EXECUTER_THREAD_FRAMEINSTR 1024 +typedef struct +{ + PX_Object *Root; + PX_Object *Area; + PX_Object *Input; + px_int max_column; + px_int column; + px_bool show; + px_vector pObjects; + px_int id; + PX_Runtime *runtime; + px_char Input_Content[PX_EXECUTER_INPUT_CONTENT_SIZE]; + px_dword *Sleep; + px_bool bInput; + PX_ScriptVM_Instance VM_Instance; +}PX_Executer; + +typedef struct +{ + px_int id; + PX_Object *Object; +}PX_ExecuterColumn; + + +px_bool PX_ExecuterInitialize(PX_Runtime *runtime,PX_Executer *pExecuter); +px_void PX_ExecuterShow(PX_Executer *pExecuter,px_bool bShow); +px_void PX_ExecuterPostEvent(PX_Executer *pExecuter,PX_Object_Event e); +px_void PX_ExecuterUpdate(PX_Executer *pExecuter,px_dword elapsed); +px_void PX_ExecuterRender(PX_Executer *pExecuter,px_dword elapsed); +PX_Object * PX_ExecuterPrintText(PX_Executer *pExecuter,const px_char *text); +PX_Object * PX_ExecuterPrintImage(PX_Executer *pExecuter,const px_char *res_image_key); +px_void PX_ExecuterClear(PX_Executer *pExecuter); +px_bool PX_ExecuterRunScipt(PX_Executer *pExecuter,const px_char *pshellstr); +px_bool PX_ExecuterLoadScipt(PX_Executer* pExecuter, const px_char* pshellstr); +px_bool PX_ExecuterRegistryHostFunction(PX_Executer *pExecuter,const px_char Name[],PX_ScriptVM_Function_Modules function,px_void *userptr); + +#endif + diff --git a/lib/PainterEngine/architecture/PainterEngine_FoxLogo.h b/lib/PainterEngine/architecture/PainterEngine_FoxLogo.h new file mode 100644 index 0000000000000000000000000000000000000000..86a3d7fdacddd863e6478723c581204c4e9f11da --- /dev/null +++ b/lib/PainterEngine/architecture/PainterEngine_FoxLogo.h @@ -0,0 +1 @@ +0x54,0x52,0x41,0x57,0x40,0x0,0x0,0x0,0x40,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x3a,0x1,0x1,0x3d,0x19,0x2,0x1,0x39,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1e,0x0,0x0,0x31,0xca,0x89,0x5e,0xff,0xed,0xb7,0x7d,0xff,0x7c,0x38,0x26,0xaa,0x11,0x0,0x0,0x19,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x59,0x1f,0x15,0x6c,0xff,0xe6,0x9d,0xff,0xff,0xfb,0xab,0xff,0xff,0xf3,0xa5,0xff,0xd2,0x91,0x63,0xff,0x32,0xa,0x7,0x65,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x86,0x42,0x2d,0x9d,0xff,0xe8,0x9e,0xff,0xfb,0xcb,0x8b,0xff,0xfd,0xd1,0x8f,0xff,0xff,0xf7,0xa9,0xff,0xff,0xd4,0x91,0xff,0x80,0x3b,0x28,0xba,0x3,0x0,0x0,0x3,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x4e,0x4,0x3,0x26,0x52,0x1a,0x11,0x6f,0x48,0x16,0xf,0x63,0x37,0x5,0x3,0x4d,0x28,0x0,0x0,0x34,0x7,0x0,0x0,0x15,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x8d,0x5b,0x3e,0xaf,0xff,0xfc,0xab,0xff,0xfc,0xcc,0x8b,0xff,0xf9,0xcb,0x8a,0xff,0xfa,0xc8,0x89,0xff,0xff,0xe6,0x9d,0xff,0xff,0xf4,0xa6,0xff,0x89,0x5d,0x3f,0xdb,0x34,0x0,0x0,0xf,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x49,0xe,0x9,0x7a,0xf3,0xbc,0x81,0xff,0xff,0xe4,0x9b,0xff,0xff,0xd2,0x8d,0xff,0xec,0xb7,0x7c,0xff,0xc8,0x90,0x62,0xfa,0xb3,0x79,0x52,0xe5,0x99,0x61,0x42,0xc3,0x56,0x1c,0x13,0x83,0x7f,0x40,0x2c,0xd7,0xeb,0xb8,0x7e,0xff,0xff,0xda,0x94,0xff,0xff,0xe2,0x99,0xff,0xfc,0xce,0x8c,0xff,0xf9,0xc7,0x88,0xff,0xff,0xdc,0x95,0xff,0xff,0xf7,0xa9,0xff,0x92,0x52,0x38,0xc7,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x31,0x0,0x0,0xd,0xa1,0x61,0x42,0xe1,0xff,0xf9,0xa9,0xff,0xed,0xc7,0x86,0xff,0xd7,0xa0,0x6b,0xff,0xf0,0xb9,0x78,0xff,0xff,0xe0,0x90,0xff,0xff,0xff,0xb1,0xff,0xff,0xfc,0xae,0xff,0xff,0xe3,0x9b,0xff,0xe2,0xad,0x77,0xff,0xb9,0x81,0x58,0xff,0xb9,0x83,0x59,0xff,0xd1,0x9b,0x6a,0xff,0xfc,0xd6,0x92,0xff,0xff,0xde,0x97,0xff,0xf9,0xc7,0x87,0xff,0xff,0xde,0x97,0xff,0xff,0xec,0xa1,0xff,0x6a,0x33,0x23,0x9f,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x35,0x0,0x0,0x33,0xe2,0xbc,0x80,0xff,0xff,0xe4,0x97,0xff,0xa7,0x6e,0x59,0xff,0xc9,0xa1,0x95,0xff,0xce,0xa4,0x8e,0xff,0xc5,0x95,0x79,0xff,0xbb,0x82,0x57,0xff,0xe0,0xaa,0x6a,0xff,0xff,0xe9,0x9b,0xff,0xff,0xea,0xa1,0xff,0xff,0xdd,0x97,0xff,0xe8,0xb4,0x7b,0xff,0xc1,0x8a,0x5e,0xff,0xb4,0x7b,0x54,0xff,0xe1,0xb1,0x78,0xff,0xff,0xe5,0x9c,0xff,0xfb,0xca,0x8a,0xff,0xff,0xed,0xa2,0xff,0xe7,0xbd,0x81,0xff,0x1f,0x0,0x0,0x42,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x52,0x2,0x1,0x48,0xed,0xc5,0x85,0xff,0xe1,0xab,0x70,0xff,0xc9,0xa1,0x90,0xff,0xff,0xff,0xea,0xff,0xff,0xf5,0xd9,0xff,0xff,0xe4,0xcf,0xff,0xd0,0xa7,0x99,0xff,0xa8,0x74,0x60,0xff,0xc1,0x89,0x5b,0xff,0xf3,0xc7,0x80,0xff,0xff,0xdc,0x96,0xff,0xff,0xd4,0x91,0xff,0xff,0xe6,0x9d,0xff,0xe7,0xb7,0x7d,0xff,0xb1,0x77,0x51,0xff,0xc5,0x8e,0x61,0xff,0xff,0xda,0x95,0xff,0xff,0xe3,0x9b,0xff,0xff,0xff,0xb8,0xff,0x94,0x63,0x43,0xbb,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x71,0x17,0x10,0x5c,0xf4,0xd2,0x8d,0xff,0xdd,0xaa,0x72,0xff,0xd1,0xaa,0x97,0xff,0xff,0xf0,0xd3,0xff,0xfb,0xdb,0xbf,0xff,0xfe,0xdc,0xc0,0xff,0xff,0xf7,0xd8,0xff,0xff,0xf0,0xd8,0xff,0xd0,0xa4,0x96,0xff,0xb2,0x7a,0x5c,0xff,0xeb,0xbc,0x7c,0xff,0xff,0xd9,0x94,0xff,0xf9,0xc8,0x89,0xff,0xff,0xdd,0x97,0xff,0xff,0xdb,0x96,0xff,0xbd,0x82,0x59,0xff,0xb4,0x7b,0x54,0xf7,0xca,0x96,0x66,0xfd,0xda,0xa7,0x72,0xff,0xd0,0x8e,0x61,0xff,0x13,0x0,0x0,0x3e,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x58,0x23,0x18,0x63,0xff,0xd5,0x8f,0xff,0xdd,0xaa,0x70,0xff,0xcf,0xa6,0x92,0xff,0xff,0xf0,0xd3,0xff,0xfc,0xdc,0xc0,0xff,0xfc,0xdc,0xc0,0xff,0xfc,0xdb,0xbf,0xff,0xfe,0xdb,0xbf,0xff,0xff,0xfd,0xdd,0xff,0xef,0xe0,0xd2,0xff,0xaf,0x77,0x64,0xff,0xef,0xbd,0x7a,0xff,0xff,0xd3,0x90,0xff,0xf9,0xca,0x8a,0xff,0xfd,0xd2,0x8e,0xff,0xff,0xdc,0x96,0xff,0xe5,0xb3,0x7a,0xfc,0xd6,0xa1,0x6e,0xfe,0xc8,0x92,0x64,0xff,0xd0,0x92,0x64,0xff,0x63,0x25,0x19,0xa9,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x3a,0x0,0x0,0x3,0x4b,0x0,0x0,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x36,0x6,0x4,0x4d,0xfb,0xc7,0x87,0xff,0xe8,0xb5,0x76,0xff,0xc9,0xa0,0x8a,0xff,0xff,0xf2,0xd6,0xff,0xfc,0xdb,0xc0,0xff,0xfc,0xdc,0xc0,0xff,0xfc,0xd9,0xbd,0xff,0xff,0xed,0xcf,0xff,0xf4,0xdc,0xc8,0xff,0xd1,0xa6,0x91,0xff,0xd6,0xa5,0x77,0xff,0xf5,0xc5,0x84,0xff,0xfe,0xd0,0x8e,0xff,0xfa,0xcc,0x8b,0xff,0xf9,0xcb,0x8b,0xff,0xfb,0xcc,0x8b,0xff,0xff,0xd5,0x91,0xff,0xff,0xdb,0x96,0xff,0xff,0xe4,0x9c,0xff,0xff,0xea,0x9f,0xff,0xf9,0xba,0x7f,0xff,0x4e,0x25,0x19,0x8a,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x8e,0x50,0x45,0x6b,0x4a,0x0,0x0,0x5d,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1d,0x0,0x0,0x32,0xe4,0xac,0x76,0xff,0xf9,0xc9,0x81,0xff,0xc2,0x97,0x7d,0xff,0xff,0xec,0xd3,0xff,0xfc,0xdb,0xc0,0xff,0xfc,0xd9,0xbd,0xff,0xff,0xef,0xd1,0xff,0xed,0xd3,0xc1,0xff,0xbe,0x8a,0x70,0xff,0xdb,0xa5,0x67,0xff,0xff,0xdb,0x90,0xff,0xfd,0xd2,0x90,0xff,0xf9,0xca,0x8a,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xf9,0xcb,0x8a,0xff,0xfb,0xc9,0x89,0xff,0xff,0xf3,0xa6,0xff,0xff,0xda,0x94,0xff,0x5c,0x13,0xd,0x68,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2c,0x0,0x0,0x4,0x9d,0x63,0x56,0xba,0xcd,0xa1,0x8c,0xff,0x4e,0x7,0x7,0x3d,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x17,0x0,0x0,0x19,0xc9,0x92,0x63,0xf9,0xff,0xe2,0x92,0xff,0xc1,0x92,0x74,0xff,0xf9,0xdd,0xc8,0xff,0xfd,0xda,0xbe,0xff,0xff,0xef,0xd1,0xff,0xeb,0xd3,0xc1,0xff,0xb6,0x7e,0x63,0xff,0xec,0xbb,0x75,0xff,0xff,0xe0,0x97,0xff,0xfa,0xcb,0x8b,0xff,0xfa,0xcb,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xf9,0xc8,0x88,0xff,0xff,0xfa,0xaa,0xff,0xbc,0x8f,0x62,0xec,0xd,0x0,0x0,0xc,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x3f,0x0,0x0,0x3e,0xb8,0x80,0x6f,0xf0,0xff,0xff,0xf0,0xff,0xc5,0xa8,0x93,0xd9,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xa8,0x6e,0x4b,0xd5,0xff,0xfb,0xa6,0xff,0xc1,0x8e,0x68,0xff,0xe3,0xc4,0xb3,0xff,0xff,0xf3,0xd3,0xff,0xed,0xd3,0xbf,0xff,0xb4,0x7c,0x61,0xff,0xec,0xbe,0x78,0xff,0xff,0xde,0x96,0xff,0xf9,0xca,0x8a,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xff,0xd8,0x93,0xff,0xff,0xd8,0x93,0xff,0x55,0x1d,0x14,0x6a,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x60,0x1e,0x1a,0x8a,0xe8,0xc4,0xab,0xff,0xff,0xff,0xeb,0xff,0xff,0xff,0xee,0xff,0xad,0x7a,0x6b,0xb1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x7a,0x41,0x2c,0x9a,0xff,0xff,0xad,0xff,0xca,0x92,0x61,0xff,0xce,0xaa,0x98,0xff,0xff,0xff,0xe7,0xff,0xba,0x89,0x70,0xff,0xe3,0xb2,0x6e,0xff,0xff,0xdf,0x98,0xff,0xf9,0xca,0x8a,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xca,0x8a,0xff,0xff,0xf5,0xa7,0xff,0x9d,0x6a,0x48,0xc9,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x7a,0x3c,0x33,0xb5,0xff,0xef,0xd1,0xff,0xff,0xff,0xe1,0xff,0xfe,0xdc,0xc0,0xff,0xff,0xff,0xe0,0xff,0x9b,0x65,0x58,0xa0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x5c,0x15,0xe,0x3e,0xfb,0xd4,0x91,0xff,0xf3,0xc5,0x7e,0xff,0xc7,0x9f,0x86,0xff,0xd5,0xb7,0xaa,0xff,0xcd,0x99,0x64,0xff,0xff,0xe3,0x98,0xff,0xf9,0xc9,0x89,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcb,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcb,0x8b,0xff,0xff,0xe4,0x9c,0xff,0xe9,0xb6,0x7c,0xff,0x2b,0x0,0x0,0x48,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x7d,0x40,0x38,0xc0,0xff,0xfa,0xda,0xff,0xff,0xf8,0xd9,0xff,0xfc,0xd8,0xbd,0xff,0xfc,0xdc,0xc0,0xff,0xff,0xff,0xe1,0xff,0x9a,0x67,0x5a,0xa8,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x8f,0x5b,0x3c,0xb5,0xff,0xff,0xb2,0xff,0xb6,0x80,0x5e,0xff,0x9b,0x61,0x4c,0xff,0xff,0xd8,0x8e,0xff,0xfe,0xd0,0x8e,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xf9,0xc9,0x89,0xff,0xfd,0xd5,0x92,0xff,0xff,0xeb,0xa1,0xff,0xfe,0xe0,0x98,0xff,0xfa,0xc7,0x87,0xff,0xfc,0xcd,0x8c,0xff,0xff,0xeb,0xa1,0xff,0x75,0x42,0x2d,0xa0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x70,0x33,0x2c,0xbb,0xff,0xf6,0xd7,0xff,0xff,0xf7,0xd7,0xff,0xfc,0xd8,0xbc,0xff,0xfc,0xdc,0xc0,0xff,0xfc,0xdc,0xc0,0xff,0xff,0xff,0xe2,0xff,0xb0,0x88,0x76,0xd6,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x51,0xc,0x12,0x4b,0xec,0xc1,0x85,0xff,0xf5,0xca,0x86,0xff,0xd8,0xa6,0x6d,0xff,0xff,0xdd,0x97,0xff,0xf9,0xcb,0x8a,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xff,0xd3,0x90,0xff,0xf2,0xc3,0x85,0xff,0xba,0x83,0x5a,0xff,0xdb,0xa9,0x74,0xff,0xff,0xd9,0x94,0xff,0xf9,0xca,0x8a,0xff,0xff,0xf1,0xa5,0xff,0xad,0x80,0x57,0xe2,0x0,0x0,0x0,0x3,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x5e,0x1f,0x1a,0x9f,0xfe,0xea,0xcd,0xff,0xff,0xfa,0xda,0xff,0xfc,0xd7,0xbc,0xff,0xfc,0xdc,0xc0,0xff,0xfc,0xdc,0xc0,0xff,0xfc,0xdc,0xc0,0xff,0xff,0xf2,0xd3,0xff,0xe2,0xc2,0xaa,0xff,0x46,0x0,0x0,0x3a,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xa0,0x63,0x4e,0x5,0xbf,0x88,0x5d,0xe6,0xff,0xee,0xa1,0xff,0xfe,0xda,0x94,0xff,0xf9,0xc8,0x89,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfb,0xcd,0x8c,0xff,0xff,0xe3,0x9a,0xff,0x9f,0x61,0x42,0xff,0x3b,0x0,0x0,0xff,0x6b,0x35,0x24,0xff,0xff,0xe3,0x9b,0xff,0xfd,0xcf,0x8d,0xff,0xff,0xdf,0x98,0xff,0xf2,0xc0,0x83,0xff,0x39,0x7,0x5,0x52,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x47,0x6,0x5,0x6f,0xed,0xd4,0xb9,0xff,0xff,0xff,0xe1,0xff,0xfc,0xd7,0xbc,0xff,0xfc,0xdc,0xc0,0xff,0xfc,0xdc,0xc0,0xfe,0xfc,0xdc,0xc0,0xff,0xfc,0xdc,0xc0,0xff,0xff,0xdd,0xc1,0xff,0xff,0xff,0xdf,0xff,0x6c,0x36,0x33,0x99,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xc1,0x8b,0x5f,0x9e,0xf0,0xc3,0x85,0xff,0xfe,0xd0,0x8e,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfb,0xcc,0x8b,0xff,0xff,0xec,0xa1,0xff,0x9f,0x62,0x43,0xff,0x1f,0x0,0x0,0xff,0xa1,0x65,0x45,0xff,0xff,0xe5,0x9c,0xff,0xfc,0xce,0x8c,0xff,0xfb,0xcb,0x8a,0xff,0xff,0xf0,0xa3,0xff,0x97,0x67,0x46,0xd1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2c,0x0,0x0,0x2c,0xc0,0x9e,0x8a,0xfd,0xff,0xff,0xeb,0xff,0xfc,0xd8,0xbd,0xff,0xfc,0xdc,0xc0,0xff,0xfc,0xdc,0xc0,0xff,0xfc,0xdc,0xc0,0xfe,0xfc,0xdc,0xc0,0xff,0xfc,0xdc,0xc0,0xff,0xfc,0xda,0xbe,0xff,0xff,0xff,0xe0,0xff,0xb7,0x8f,0x81,0xff,0x80,0x37,0x20,0x65,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xbf,0x87,0x5c,0x79,0xdb,0xa9,0x74,0xff,0xff,0xda,0x94,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfd,0xd0,0x8e,0xff,0xf5,0xcd,0x8c,0xff,0xdd,0xaf,0x77,0xff,0xfa,0xd7,0x93,0xff,0xfc,0xd0,0x8d,0xff,0xfa,0xcb,0x8b,0xff,0xf9,0xcb,0x8a,0xff,0xff,0xd8,0x93,0xff,0xff,0xe3,0x9b,0xff,0x80,0x3b,0x28,0xb0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x87,0x5b,0x4f,0xc7,0xff,0xff,0xe5,0xff,0xff,0xe0,0xc3,0xff,0xfc,0xdb,0xbf,0xff,0xfc,0xdc,0xc0,0xfc,0xfc,0xdd,0xc1,0xf5,0xff,0xe4,0xc7,0xf7,0xfd,0xdd,0xc1,0xfc,0xfc,0xdb,0xbf,0xff,0xfc,0xdc,0xc0,0xff,0xff,0xf0,0xd3,0xff,0xe4,0xc0,0xa6,0xff,0x76,0x30,0x1f,0xff,0xac,0x71,0x4b,0x70,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xc7,0x90,0x62,0x5d,0xd2,0x9d,0x6b,0xff,0xff,0xde,0x97,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xf9,0xc9,0x89,0xff,0xfc,0xd3,0x90,0xff,0xff,0xe5,0x9c,0xff,0xfc,0xd1,0x8e,0xff,0xf9,0xc9,0x89,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xf9,0xc8,0x88,0xff,0xff,0xdf,0x98,0xff,0xff,0xe9,0x9e,0xff,0xa6,0x6a,0x49,0xe6,0x3c,0x2,0x1,0x58,0x45,0x0,0x0,0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x4c,0xc,0xb,0x5f,0xf2,0xdf,0xc3,0xff,0xff,0xf6,0xd7,0xff,0xfc,0xd9,0xbe,0xff,0xfc,0xdc,0xc0,0xff,0xfc,0xdb,0xbf,0xfb,0xfe,0xdf,0xc2,0xf7,0xf4,0xd3,0xbd,0xfc,0xfb,0xeb,0xd2,0xff,0xff,0xef,0xd0,0xff,0xfd,0xdb,0xbf,0xff,0xff,0xec,0xce,0xff,0xd7,0xb0,0x9f,0xff,0xcd,0xa1,0x70,0xff,0xc0,0x89,0x5b,0xff,0xbb,0x84,0x5a,0x60,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xd3,0xa1,0x6d,0x3c,0xcb,0x95,0x65,0xff,0xff,0xdd,0x97,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xf9,0xc8,0x88,0xff,0xff,0xf9,0xaa,0xff,0xc2,0x95,0x66,0xff,0x78,0x24,0x19,0xff,0x58,0x1a,0x12,0x4e,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x29,0x0,0x0,0x6,0xa9,0x86,0x76,0xdc,0xff,0xff,0xe9,0xff,0xfc,0xd8,0xbd,0xfc,0xfc,0xdc,0xc0,0xff,0xfc,0xdc,0xc0,0xff,0xff,0xe3,0xc7,0xff,0xf3,0xd2,0xba,0xff,0xa3,0x6d,0x56,0xff,0xb6,0x84,0x6d,0xff,0xdd,0xb6,0xa7,0xff,0xff,0xee,0xd6,0xff,0xff,0xff,0xe3,0xff,0xd9,0xb3,0xa3,0xff,0xbf,0x8c,0x62,0xff,0xff,0xf6,0xa5,0xff,0xae,0x71,0x4e,0xff,0xbd,0x88,0x5c,0x55,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xe4,0xbd,0x80,0x2f,0xc4,0x8c,0x5f,0xff,0xff,0xd9,0x94,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xff,0xdf,0x98,0xff,0xdf,0xac,0x75,0xff,0x75,0x2d,0x1f,0xee,0x2a,0x0,0x0,0x14,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x58,0x1e,0x1a,0x72,0xfe,0xea,0xcc,0xff,0xff,0xea,0xcd,0xfb,0xfc,0xdb,0xbf,0xff,0xfc,0xdc,0xc0,0xff,0xfc,0xdc,0xc0,0xff,0xff,0xee,0xd1,0xff,0xd2,0xad,0x9d,0xff,0xc0,0x89,0x58,0xff,0xeb,0xb9,0x72,0xff,0xb8,0x81,0x5a,0xff,0xb7,0x84,0x6e,0xff,0xdf,0xba,0xa9,0xff,0xd4,0xae,0xa4,0xff,0xbe,0x89,0x60,0xff,0xff,0xe9,0x9b,0xff,0xff,0xdc,0x96,0xff,0xa4,0x64,0x45,0xff,0xd4,0xa8,0x73,0x2f,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xe7,0xbe,0x81,0x26,0xc4,0x8b,0x5f,0xff,0xff,0xd7,0x92,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcb,0x8a,0xff,0xff,0xd4,0x91,0xff,0xff,0xf6,0xa7,0xff,0x67,0x3b,0x28,0x82,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x29,0x0,0x0,0x17,0xaf,0x8d,0x7b,0xe3,0xff,0xff,0xe8,0xff,0xfc,0xd9,0xbd,0xfe,0xfc,0xdc,0xc0,0xff,0xfc,0xdc,0xc0,0xff,0xfc,0xdc,0xc0,0xff,0xff,0xf6,0xd8,0xff,0xc4,0x9d,0x8b,0xff,0xcb,0x93,0x60,0xff,0xff,0xf3,0xa5,0xff,0xff,0xe1,0x95,0xff,0xe5,0xaf,0x6d,0xff,0xc4,0x8f,0x62,0xff,0x9c,0x64,0x52,0xff,0xd0,0x9e,0x6e,0xff,0xff,0xe0,0x98,0xff,0xff,0xdc,0x95,0xff,0xec,0xc4,0x86,0xff,0xa7,0x6a,0x49,0xd4,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xe5,0xbf,0x82,0x35,0xc4,0x8b,0x5f,0xff,0xff,0xd8,0x93,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xf9,0xcb,0x8a,0xff,0xfb,0xcd,0x8c,0xff,0xff,0xd2,0x8f,0xff,0xff,0xd6,0x92,0xff,0xfc,0xd0,0x8e,0xff,0xf9,0xc9,0x89,0xff,0xfc,0xcd,0x8c,0xff,0xff,0xff,0xad,0xff,0xa8,0x78,0x52,0xdc,0x18,0x0,0x0,0x5,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x62,0x28,0x23,0x82,0xff,0xf1,0xd2,0xff,0xff,0xf8,0xdb,0xff,0xff,0xf1,0xd6,0xff,0xfe,0xe6,0xc8,0xff,0xfc,0xda,0xbe,0xff,0xfc,0xdb,0xbf,0xff,0xff,0xf4,0xd8,0xff,0xbe,0x94,0x7e,0xff,0xd9,0xa3,0x67,0xff,0xff,0xd8,0x93,0xff,0xfb,0xca,0x8a,0xff,0xff,0xd8,0x93,0xff,0xff,0xdf,0x95,0xff,0xee,0xbf,0x7c,0xff,0xf7,0xca,0x89,0xff,0xfb,0xcd,0x8c,0xff,0xf9,0xc9,0x89,0xff,0xff,0xe9,0x9f,0xff,0xc4,0x8f,0x63,0xff,0xb8,0x82,0x58,0x79,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xe0,0xb6,0x7c,0x55,0xc3,0x8c,0x60,0xff,0xff,0xdc,0x96,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfc,0xce,0x8d,0xff,0xf6,0xc8,0x88,0xff,0xea,0xba,0x7f,0xff,0xe0,0xaf,0x77,0xff,0xf0,0xc1,0x84,0xff,0xff,0xcf,0x8d,0xff,0xff,0xf7,0xa9,0xff,0xcf,0x9f,0x6c,0xff,0x33,0x0,0x0,0x3e,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2c,0x0,0x0,0xe,0xb9,0x9c,0x88,0xe4,0xff,0xff,0xfb,0xff,0xc7,0x99,0x85,0xff,0xbb,0x8a,0x75,0xff,0xec,0xcf,0xbc,0xff,0xff,0xf8,0xdb,0xff,0xff,0xe2,0xc4,0xff,0xf5,0xdb,0xc6,0xff,0xb6,0x88,0x6b,0xff,0xf5,0xc3,0x7e,0xff,0xfc,0xce,0x8c,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcb,0x8a,0xff,0xff,0xd3,0x90,0xff,0xfc,0xd0,0x8e,0xff,0xf9,0xca,0x8a,0xff,0xfa,0xcc,0x8b,0xff,0xfc,0xcd,0x8c,0xff,0xff,0xdc,0x97,0xff,0xab,0x6f,0x4d,0xfb,0xdb,0xae,0x75,0x24,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xde,0xaf,0x77,0x62,0xc7,0x90,0x62,0xff,0xff,0xdd,0x97,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfb,0xcd,0x8c,0xff,0xfc,0xce,0x8c,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xff,0xd5,0x91,0xff,0xed,0xbd,0x81,0xff,0xbb,0x83,0x59,0xff,0xc1,0x8a,0x5e,0xff,0xf2,0xbf,0x82,0xff,0xff,0xfc,0xac,0xff,0xe5,0xb1,0x79,0xff,0x40,0x0,0x0,0x53,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x5b,0x1c,0x18,0x61,0xff,0xfb,0xe2,0xff,0xce,0xa9,0x98,0xff,0xc3,0x89,0x56,0xff,0xdd,0xa6,0x66,0xff,0xb7,0x83,0x62,0xff,0xcb,0xa1,0x91,0xff,0xff,0xef,0xd9,0xff,0xd9,0xc1,0xb2,0xff,0xb6,0x82,0x59,0xff,0xff,0xe2,0x96,0xff,0xfa,0xcb,0x8a,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xf9,0xcb,0x8a,0xff,0xff,0xe1,0x99,0xff,0xd4,0xa2,0x70,0xff,0xae,0x73,0x4f,0xa8,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xd6,0xaa,0x74,0x70,0xca,0x93,0x64,0xff,0xff,0xde,0x97,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfb,0xcd,0x8c,0xff,0xf6,0xc6,0x87,0xff,0xf8,0xcf,0x8d,0xff,0xff,0xde,0x97,0xff,0xfd,0xcd,0x8c,0xff,0xf9,0xcb,0x8a,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xf9,0xcb,0x8a,0xff,0xfb,0xcd,0x8c,0xff,0xff,0xd1,0x8e,0xff,0xff,0xd5,0x91,0xff,0xff,0xfc,0xac,0xff,0xed,0xbe,0x82,0xff,0x32,0x8,0x6,0x63,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xac,0x87,0x7a,0xba,0xe9,0xd1,0xc0,0xff,0xbb,0x80,0x52,0xff,0xff,0xdf,0x92,0xff,0xff,0xe5,0x9d,0xff,0xf9,0xce,0x84,0xff,0xca,0x91,0x5e,0xff,0xc7,0x9a,0x7d,0xff,0x9f,0x6c,0x5e,0xff,0xd4,0xa4,0x6c,0xff,0xff,0xe1,0x99,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xca,0x8a,0xff,0xff,0xe4,0x9b,0xff,0xb6,0x80,0x58,0xff,0xd8,0xa5,0x72,0x2f,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xcb,0x97,0x67,0x80,0xd3,0x9e,0x6c,0xff,0xff,0xdc,0x96,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfc,0xcf,0x8d,0xff,0xfa,0xcd,0x8b,0xff,0xcf,0x9a,0x68,0xff,0xd2,0x9c,0x6a,0xff,0xf9,0xd0,0x8e,0xff,0xff,0xea,0xa0,0xff,0xff,0xe4,0x9c,0xff,0xff,0xdb,0x96,0xff,0xff,0xd9,0x94,0xff,0xff,0xd9,0x94,0xff,0xff,0xdf,0x98,0xff,0xff,0xfd,0xad,0xff,0xec,0xb5,0x7c,0xff,0x46,0xc,0x9,0x70,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x47,0x4,0x3,0x2e,0xc3,0xa5,0x99,0xff,0xd0,0x9e,0x76,0xff,0xfd,0xd4,0x89,0xff,0xff,0xd3,0x90,0xff,0xf9,0xc9,0x89,0xff,0xfc,0xd0,0x8e,0xff,0xff,0xe2,0x98,0xff,0xef,0xc0,0x7b,0xff,0xd7,0xa5,0x6b,0xff,0xfa,0xcf,0x8e,0xff,0xfb,0xcd,0x8c,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcb,0x8b,0xff,0xff,0xe0,0x99,0xff,0xd0,0x9f,0x6d,0xff,0xc1,0x87,0x5e,0x8a,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xb9,0x81,0x58,0x94,0xde,0xad,0x76,0xff,0xff,0xd8,0x93,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xff,0xd4,0x91,0xff,0xf2,0xc4,0x85,0xff,0xc6,0x8e,0x60,0xff,0xb4,0x71,0x4c,0xff,0xba,0x7e,0x55,0xff,0xc5,0x95,0x66,0xff,0xd6,0xaa,0x75,0xff,0xdd,0xb1,0x79,0xff,0xdc,0xaf,0x79,0xff,0xe3,0xb6,0x7d,0xff,0xc7,0x89,0x5d,0xff,0x48,0x8,0x6,0x53,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x67,0x2c,0x2d,0x8e,0xc8,0x9a,0x81,0xff,0xef,0xc3,0x7d,0xff,0xff,0xdb,0x95,0xff,0xf9,0xca,0x8a,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xf9,0xca,0x8a,0xff,0xfd,0xd0,0x8d,0xff,0xff,0xdd,0x96,0xff,0xfb,0xcf,0x8d,0xff,0xf9,0xca,0x8a,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xff,0xd0,0x8e,0xff,0xed,0xc1,0x84,0xff,0xba,0x81,0x59,0xc4,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xba,0x82,0x59,0xbc,0xea,0xba,0x7f,0xff,0xff,0xd2,0x8f,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xf9,0xca,0x89,0xff,0xfd,0xd4,0x90,0xff,0xff,0xe4,0x9b,0xff,0xf4,0xbd,0x7f,0xff,0xc2,0x7a,0x51,0xff,0xa9,0x5a,0x39,0xff,0xab,0x5a,0x39,0xff,0xb0,0x60,0x3d,0xff,0xbc,0x6a,0x44,0xff,0xa5,0x55,0x37,0xff,0x26,0x0,0x0,0x40,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x34,0x0,0x0,0x1f,0x7c,0x41,0x3b,0xfb,0xf7,0xcd,0x91,0xff,0xff,0xdc,0x93,0xff,0xf9,0xca,0x8a,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfb,0xcb,0x8b,0xff,0xff,0xd5,0x91,0xff,0xbb,0x84,0x5a,0xe6,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xb8,0x80,0x57,0xf0,0xff,0xd3,0x90,0xff,0xfb,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xf9,0xc9,0x8a,0xff,0xfd,0xd4,0x92,0xff,0xff,0xe2,0x9b,0xff,0xff,0xd4,0x8f,0xff,0xfd,0xbc,0x7d,0xff,0xf7,0xb0,0x74,0xff,0xff,0xb3,0x75,0xff,0xf5,0x9d,0x65,0xff,0x2e,0xb,0x7,0x3a,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x3f,0x0,0x0,0x77,0xc6,0x94,0x64,0xff,0xff,0xe8,0x9c,0xff,0xfc,0xcd,0x8d,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcb,0x8b,0xff,0xff,0xde,0x98,0xff,0xcb,0x96,0x66,0xff,0xbc,0x83,0x59,0x5,0xa7,0x68,0x47,0x1f,0xc8,0x93,0x65,0xff,0xff,0xe3,0x9b,0xff,0xfa,0xcb,0x8a,0xff,0xfa,0xcb,0x8b,0xff,0xf9,0xca,0x8a,0xff,0xf9,0xca,0x8a,0xff,0xf9,0xca,0x8a,0xff,0xf9,0xca,0x8a,0xff,0xf9,0xca,0x8a,0xff,0xf9,0xca,0x8a,0xff,0xf9,0xca,0x8a,0xff,0xf9,0xca,0x8a,0xff,0xf9,0xc9,0x8a,0xff,0xf9,0xc9,0x8a,0xff,0xf9,0xc9,0x8a,0xff,0xfb,0xcf,0x8f,0xff,0xfe,0xd4,0x93,0xff,0xfd,0xd3,0x92,0xff,0xff,0xd6,0x94,0xff,0xff,0xda,0x96,0xff,0x5c,0x2d,0x1f,0x76,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x77,0x38,0x26,0xd5,0xff,0xeb,0x9f,0xff,0xff,0xd3,0x90,0xff,0xfa,0xcb,0x8a,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcb,0x8b,0xff,0xfa,0xcc,0x8b,0xff,0xfa,0xcb,0x8b,0xff,0xfa,0xcb,0x8b,0xff,0xfa,0xcb,0x8b,0xff,0xfa,0xcb,0x8b,0xff,0xfa,0xcb,0x8b,0xff,0xfa,0xcb,0x8b,0xff,0xfa,0xcb,0x8b,0xff,0xfa,0xcb,0x8b,0xff,0xf9,0xca,0x8a,0xff,0xfa,0xca,0x8b,0xff,0xf9,0xca,0x8a,0xff,0xfa,0xca,0x8a,0xff,0xf9,0xca,0x8a,0xff,0xf9,0xc9,0x8a,0xff,0xf9,0xca,0x8a,0xff,0xf9,0xca,0x8a,0xff,0xf9,0xca,0x8a,0xff,0xff,0xde,0x98,0xff,0xd7,0xa3,0x70,0xff,0x97,0x57,0x3c,0x13,0x8b,0x4a,0x33,0x51,0xe5,0xb5,0x7d,0xff,0xff,0xd6,0x93,0xff,0xf9,0xc9,0x8a,0xff,0xf9,0xc9,0x8a,0xff,0xf9,0xc8,0x8a,0xff,0xf9,0xc8,0x8a,0xff,0xf9,0xc8,0x8a,0xff,0xf9,0xc8,0x8a,0xff,0xf9,0xc8,0x8a,0xff,0xf9,0xc8,0x8a,0xff,0xf9,0xc8,0x8a,0xff,0xf9,0xc8,0x89,0xff,0xf9,0xc8,0x8a,0xff,0xf8,0xc7,0x8a,0xff,0xf9,0xc7,0x8a,0xff,0xf9,0xc7,0x89,0xff,0xf9,0xc7,0x89,0xff,0xf9,0xc7,0x8a,0xff,0xfb,0xca,0x8c,0xff,0xff,0xe4,0x9e,0xff,0x7d,0x47,0x31,0x9a,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x16,0x0,0x0,0x2d,0xb6,0x82,0x59,0xff,0xff,0xf2,0xa5,0xff,0xf9,0xc8,0x89,0xff,0xfa,0xca,0x8a,0xff,0xfa,0xca,0x8b,0xff,0xf9,0xca,0x8a,0xff,0xf9,0xca,0x8a,0xff,0xf9,0xc9,0x8a,0xff,0xf9,0xc9,0x8a,0xff,0xf9,0xc9,0x8a,0xff,0xf9,0xc9,0x8a,0xff,0xf9,0xc9,0x8a,0xff,0xf9,0xc9,0x8a,0xff,0xf9,0xc9,0x8a,0xff,0xf9,0xc9,0x8a,0xff,0xf9,0xc8,0x8a,0xff,0xf9,0xc8,0x8a,0xff,0xf9,0xc8,0x8a,0xff,0xf9,0xc8,0x8a,0xff,0xf9,0xc8,0x8a,0xff,0xf9,0xc8,0x8a,0xff,0xf9,0xc8,0x8a,0xff,0xf9,0xc8,0x8a,0xff,0xf9,0xc8,0x89,0xff,0xff,0xd9,0x95,0xff,0xdb,0xa7,0x73,0xff,0x9c,0x5c,0x40,0x50,0xb9,0x80,0x59,0xb4,0xff,0xd2,0x91,0xff,0xf9,0xc7,0x8a,0xff,0xf9,0xc7,0x89,0xff,0xf9,0xc7,0x89,0xff,0xf9,0xc7,0x8a,0xff,0xf8,0xc7,0x89,0xff,0xf8,0xc7,0x89,0xff,0xf9,0xc7,0x89,0xff,0xf8,0xc6,0x89,0xff,0xf8,0xc6,0x89,0xff,0xf8,0xc6,0x89,0xff,0xf8,0xc6,0x89,0xff,0xf8,0xc6,0x89,0xff,0xf8,0xc6,0x89,0xff,0xf8,0xc6,0x89,0xff,0xf8,0xc6,0x89,0xff,0xf8,0xc5,0x89,0xff,0xf8,0xc5,0x89,0xff,0xf8,0xc6,0x89,0xff,0xff,0xe5,0x9f,0xff,0x94,0x5a,0x3e,0xba,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x39,0x0,0x0,0x56,0xe5,0xb0,0x78,0xff,0xff,0xdf,0x9a,0xff,0xf9,0xc8,0x8a,0xff,0xf9,0xc8,0x8a,0xff,0xf9,0xc8,0x8a,0xff,0xf9,0xc8,0x8a,0xff,0xf9,0xc8,0x8a,0xff,0xf9,0xc8,0x8a,0xff,0xf9,0xc8,0x8a,0xff,0xf9,0xc8,0x89,0xff,0xf9,0xc7,0x8a,0xff,0xf9,0xc7,0x8a,0xff,0xf8,0xc7,0x89,0xff,0xf9,0xc7,0x89,0xff,0xf9,0xc7,0x8a,0xff,0xf9,0xc7,0x8a,0xff,0xf9,0xc7,0x89,0xff,0xf9,0xc7,0x89,0xff,0xf9,0xc6,0x89,0xff,0xf8,0xc6,0x89,0xff,0xf8,0xc7,0x89,0xff,0xf8,0xc6,0x89,0xff,0xf9,0xc6,0x89,0xff,0xf8,0xc6,0x89,0xff,0xff,0xd4,0x93,0xff,0xea,0xb7,0x7f,0xf3,0x97,0x55,0x3b,0xb0,0xc9,0x93,0x66,0xfc,0xff,0xde,0x9a,0xff,0xf8,0xc4,0x88,0xff,0xf8,0xc5,0x89,0xff,0xf8,0xc5,0x89,0xff,0xf8,0xc5,0x89,0xff,0xf8,0xc5,0x89,0xff,0xf8,0xc5,0x89,0xff,0xf8,0xc5,0x89,0xff,0xf8,0xc5,0x89,0xff,0xf8,0xc4,0x89,0xff,0xf8,0xc4,0x89,0xff,0xf8,0xc4,0x89,0xff,0xf8,0xc4,0x89,0xff,0xf8,0xc4,0x89,0xff,0xf8,0xc4,0x88,0xff,0xf8,0xc4,0x88,0xff,0xf8,0xc3,0x88,0xff,0xf8,0xc4,0x89,0xff,0xf7,0xc3,0x88,0xff,0xff,0xe6,0xa0,0xff,0xa7,0x6c,0x4b,0xd4,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x67,0x25,0x1a,0x8e,0xff,0xd3,0x91,0xff,0xfe,0xcd,0x8e,0xff,0xf9,0xc6,0x89,0xff,0xf8,0xc6,0x89,0xff,0xf8,0xc6,0x89,0xff,0xf8,0xc6,0x89,0xff,0xf8,0xc6,0x89,0xff,0xf8,0xc6,0x89,0xff,0xf8,0xc6,0x89,0xff,0xf8,0xc6,0x89,0xff,0xf8,0xc6,0x89,0xff,0xf8,0xc5,0x89,0xff,0xf8,0xc5,0x89,0xff,0xf8,0xc5,0x89,0xff,0xf8,0xc5,0x89,0xff,0xf8,0xc5,0x89,0xff,0xf8,0xc5,0x89,0xff,0xf8,0xc5,0x89,0xff,0xf8,0xc4,0x89,0xff,0xf8,0xc5,0x89,0xff,0xf8,0xc5,0x89,0xff,0xf8,0xc4,0x89,0xff,0xf8,0xc4,0x89,0xff,0xf8,0xc4,0x89,0xff,0xff,0xd5,0x95,0xff,0xd6,0xa0,0x70,0xf2,0x8c,0x4b,0x34,0xeb,0xf7,0xc6,0x8b,0xff,0xfe,0xc9,0x8d,0xff,0xf8,0xc4,0x88,0xff,0xf8,0xc3,0x89,0xff,0xf8,0xc3,0x88,0xff,0xf8,0xc3,0x88,0xff,0xf7,0xc3,0x88,0xff,0xf7,0xc3,0x88,0xff,0xf7,0xc3,0x88,0xff,0xf8,0xc3,0x88,0xff,0xf8,0xc3,0x88,0xff,0xf7,0xc3,0x88,0xff,0xf7,0xc2,0x88,0xff,0xf7,0xc2,0x88,0xff,0xf7,0xc2,0x88,0xff,0xf7,0xc2,0x88,0xff,0xf7,0xc2,0x88,0xff,0xf7,0xc2,0x88,0xff,0xf7,0xc2,0x88,0xff,0xf7,0xc2,0x88,0xff,0xff,0xe2,0x9f,0xff,0xb2,0x79,0x55,0xe4,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x83,0x45,0x30,0xb5,0xff,0xe2,0x9d,0xff,0xfa,0xc6,0x89,0xff,0xf8,0xc5,0x89,0xff,0xf8,0xc4,0x89,0xff,0xf8,0xc4,0x89,0xff,0xf8,0xc4,0x89,0xff,0xf8,0xc4,0x88,0xff,0xf8,0xc4,0x88,0xff,0xf8,0xc4,0x88,0xff,0xf8,0xc4,0x89,0xff,0xf8,0xc4,0x89,0xff,0xf8,0xc3,0x89,0xff,0xf7,0xc3,0x88,0xff,0xf8,0xc3,0x88,0xff,0xf7,0xc3,0x88,0xff,0xf7,0xc3,0x88,0xff,0xf7,0xc3,0x88,0xff,0xf7,0xc3,0x88,0xff,0xf7,0xc3,0x88,0xff,0xf7,0xc3,0x88,0xff,0xf7,0xc2,0x88,0xff,0xf7,0xc2,0x88,0xff,0xf7,0xc2,0x88,0xff,0xf6,0xc1,0x87,0xff,0xff,0xe2,0x9e,0xff,0xb0,0x77,0x54,0xfe,0xa6,0x68,0x49,0xfe,0xff,0xe0,0x9d,0xff,0xf6,0xc0,0x87,0xff,0xf7,0xc2,0x88,0xff,0xf7,0xc1,0x88,0xff,0xf7,0xc1,0x88,0xff,0xf7,0xc1,0x88,0xff,0xf7,0xc1,0x88,0xff,0xf7,0xc1,0x88,0xff,0xf7,0xc1,0x87,0xff,0xf7,0xc1,0x88,0xff,0xf7,0xc1,0x88,0xff,0xf7,0xc1,0x88,0xff,0xf7,0xc1,0x88,0xff,0xf7,0xc0,0x88,0xff,0xf7,0xc0,0x87,0xff,0xf7,0xc0,0x88,0xff,0xf7,0xc0,0x88,0xff,0xf7,0xc0,0x87,0xff,0xf7,0xc0,0x87,0xff,0xf6,0xc0,0x87,0xff,0xff,0xdf,0x9d,0xff,0xc1,0x81,0x5b,0xf2,0x7,0x0,0x0,0x11,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xa2,0x67,0x48,0xde,0xff,0xe6,0xa1,0xff,0xf8,0xc3,0x88,0xff,0xf7,0xc3,0x88,0xff,0xf7,0xc2,0x88,0xff,0xf7,0xc2,0x88,0xff,0xf7,0xc2,0x88,0xff,0xf7,0xc2,0x88,0xff,0xf7,0xc2,0x88,0xff,0xf7,0xc2,0x88,0xff,0xf7,0xc2,0x88,0xff,0xf7,0xc2,0x88,0xff,0xf7,0xc2,0x88,0xff,0xf7,0xc1,0x88,0xff,0xf7,0xc1,0x88,0xff,0xf7,0xc1,0x88,0xff,0xf7,0xc1,0x88,0xff,0xf7,0xc1,0x88,0xff,0xf7,0xc1,0x88,0xff,0xf7,0xc1,0x88,0xff,0xf7,0xc1,0x88,0xff,0xf7,0xc1,0x88,0xff,0xf7,0xc1,0x88,0xff,0xf7,0xc0,0x87,0xff,0xf8,0xc0,0x87,0xff,0xfd,0xcc,0x90,0xff,0xa7,0x6c,0x4c,0xff,0xe4,0xaf,0x7c,0xff,0xff,0xc9,0x8d,0xff,0xf7,0xc0,0x87,0xff,0xf7,0xc0,0x87,0xff,0xf7,0xbf,0x87,0xff,0xf6,0xc0,0x87,0xff,0xf7,0xc0,0x87,0xff,0xf6,0xbf,0x87,0xff,0xf6,0xbf,0x87,0xff,0xf6,0xbf,0x87,0xff,0xf6,0xbf,0x87,0xff,0xf6,0xbf,0x87,0xff,0xf6,0xbf,0x87,0xff,0xf6,0xbf,0x87,0xff,0xf6,0xbf,0x87,0xff,0xf6,0xbf,0x87,0xff,0xf6,0xbf,0x87,0xff,0xf6,0xbe,0x87,0xff,0xf6,0xbe,0x87,0xff,0xf6,0xbe,0x87,0xff,0xf6,0xbe,0x87,0xff,0xff,0xd9,0x9a,0xff,0xcf,0x8d,0x65,0xff,0x0,0x0,0x0,0x1e,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2c,0x0,0x0,0x1b,0xba,0x83,0x5c,0xfc,0xff,0xe4,0xa0,0xff,0xf7,0xc0,0x88,0xff,0xf7,0xc1,0x88,0xff,0xf7,0xc1,0x88,0xff,0xf7,0xc1,0x88,0xff,0xf7,0xc1,0x88,0xff,0xf7,0xc1,0x88,0xff,0xf7,0xc0,0x88,0xff,0xf7,0xc0,0x87,0xff,0xf7,0xc0,0x87,0xff,0xf7,0xc0,0x87,0xff,0xf7,0xc0,0x87,0xff,0xf6,0xc0,0x87,0xff,0xf7,0xc0,0x87,0xff,0xf7,0xc0,0x87,0xff,0xf7,0xc0,0x87,0xff,0xf7,0xbf,0x87,0xff,0xf7,0xbf,0x87,0xff,0xf6,0xbf,0x87,0xff,0xf6,0xbf,0x87,0xff,0xf6,0xbf,0x87,0xff,0xf6,0xbf,0x87,0xff,0xf6,0xbe,0x86,0xff,0xff,0xd5,0x97,0xff,0xc9,0x8e,0x65,0xff,0xb0,0x75,0x53,0xff,0xff,0xdb,0x9b,0xff,0xf5,0xbb,0x85,0xff,0xf6,0xbe,0x87,0xff,0xf6,0xbe,0x87,0xff,0xf5,0xbd,0x86,0xff,0xfc,0xc4,0x8b,0xff,0xff,0xcc,0x91,0xff,0xff,0xcb,0x90,0xff,0xfe,0xc7,0x8d,0xff,0xfe,0xc8,0x8d,0xff,0xff,0xcd,0x92,0xff,0xfc,0xc5,0x8c,0xff,0xf5,0xbc,0x85,0xff,0xf6,0xbd,0x86,0xff,0xf6,0xbd,0x86,0xff,0xf6,0xbd,0x86,0xff,0xf6,0xbd,0x86,0xff,0xf6,0xbd,0x86,0xff,0xf6,0xbc,0x86,0xff,0xf6,0xbc,0x86,0xff,0xf6,0xbc,0x86,0xff,0xff,0xd2,0x96,0xff,0xd6,0x9b,0x6f,0xff,0x2f,0x0,0x0,0x2b,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2f,0x0,0x0,0x37,0xd2,0x96,0x6b,0xff,0xff,0xdb,0x9b,0xff,0xf6,0xbf,0x87,0xff,0xf6,0xbf,0x87,0xff,0xf7,0xbf,0x87,0xff,0xf6,0xbf,0x87,0xff,0xf6,0xbf,0x87,0xff,0xf6,0xbf,0x87,0xff,0xf6,0xbf,0x87,0xff,0xf6,0xbf,0x87,0xff,0xf6,0xbe,0x87,0xff,0xf6,0xbe,0x87,0xff,0xf6,0xbe,0x87,0xff,0xf6,0xbe,0x87,0xff,0xf6,0xbe,0x87,0xff,0xf6,0xbe,0x87,0xff,0xf6,0xbe,0x87,0xff,0xf6,0xbe,0x87,0xff,0xf6,0xbe,0x87,0xff,0xf6,0xbd,0x87,0xff,0xf6,0xbd,0x87,0xff,0xf6,0xbd,0x87,0xff,0xf6,0xbd,0x86,0xff,0xf7,0xbd,0x87,0xff,0xff,0xcd,0x92,0xff,0xa9,0x6b,0x4c,0xff,0xdd,0xa6,0x76,0xff,0xff,0xc9,0x8f,0xff,0xf6,0xbc,0x86,0xff,0xf6,0xbc,0x86,0xff,0xf7,0xbe,0x87,0xff,0xfb,0xc3,0x8b,0xff,0xe6,0xab,0x7a,0xff,0xd6,0x99,0x6d,0xff,0xd0,0x92,0x68,0xff,0xcd,0x8f,0x66,0xff,0xcb,0x8d,0x64,0xff,0xcb,0x8c,0x64,0xff,0xe6,0xab,0x7a,0xff,0xff,0xce,0x93,0xff,0xf8,0xbf,0x88,0xff,0xf4,0xba,0x85,0xff,0xf5,0xbb,0x86,0xff,0xf5,0xbb,0x86,0xff,0xf5,0xbb,0x86,0xff,0xf5,0xbb,0x86,0xff,0xf5,0xba,0x86,0xff,0xf5,0xbb,0x86,0xff,0xff,0xcd,0x93,0xff,0xe3,0xa6,0x77,0xff,0x49,0x1,0x1,0x3e,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x3c,0x0,0x0,0x4f,0xe3,0xa5,0x75,0xff,0xff,0xd2,0x95,0xff,0xf6,0xbd,0x86,0xff,0xf6,0xbd,0x87,0xff,0xf6,0xbd,0x86,0xff,0xf6,0xbd,0x87,0xff,0xf6,0xbd,0x86,0xff,0xf6,0xbd,0x86,0xff,0xf6,0xbd,0x86,0xff,0xf6,0xbd,0x86,0xff,0xf6,0xbd,0x86,0xff,0xf6,0xbc,0x86,0xff,0xf5,0xbc,0x86,0xff,0xf6,0xbc,0x86,0xff,0xf6,0xbc,0x86,0xff,0xf5,0xbc,0x86,0xff,0xf5,0xbc,0x86,0xff,0xf6,0xbc,0x86,0xff,0xf6,0xbc,0x86,0xff,0xf5,0xbc,0x86,0xff,0xf5,0xbb,0x86,0xff,0xf5,0xbb,0x86,0xff,0xf4,0xba,0x85,0xff,0xff,0xd4,0x98,0xff,0xbc,0x7d,0x5a,0xff,0xae,0x6f,0x50,0xff,0xff,0xd6,0x99,0xff,0xf4,0xb8,0x84,0xff,0xf5,0xbb,0x86,0xff,0xf6,0xbc,0x86,0xff,0xf9,0xbf,0x89,0xff,0xdc,0x9e,0x72,0xff,0xcd,0x8e,0x65,0xff,0xd4,0x95,0x6c,0xff,0xdc,0x9f,0x72,0xff,0xe4,0xa7,0x78,0xff,0xe4,0xa7,0x78,0xff,0xd4,0x96,0x6c,0xff,0xbc,0x7b,0x59,0xff,0xc7,0x88,0x61,0xff,0xfb,0xc3,0x8d,0xff,0xf9,0xbe,0x89,0xff,0xf4,0xb8,0x84,0xff,0xf5,0xb9,0x85,0xff,0xf5,0xb9,0x85,0xff,0xf5,0xb9,0x85,0xff,0xf5,0xb9,0x85,0xff,0xf4,0xb9,0x85,0xff,0xff,0xc7,0x8f,0xff,0xf1,0xae,0x7d,0xff,0x42,0x9,0x7,0x52,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x43,0x6,0x4,0x5d,0xeb,0xad,0x7b,0xff,0xff,0xcc,0x92,0xff,0xf5,0xbb,0x86,0xff,0xf5,0xbb,0x86,0xff,0xf5,0xbb,0x86,0xff,0xf5,0xbb,0x86,0xff,0xf5,0xbb,0x86,0xff,0xf5,0xbb,0x86,0xff,0xf5,0xbb,0x86,0xff,0xf5,0xbb,0x86,0xff,0xf5,0xbb,0x86,0xff,0xf5,0xbb,0x85,0xff,0xf5,0xba,0x86,0xff,0xf5,0xba,0x86,0xff,0xf5,0xba,0x85,0xff,0xf5,0xba,0x86,0xff,0xf5,0xba,0x86,0xff,0xf5,0xba,0x85,0xff,0xf5,0xba,0x85,0xff,0xf5,0xb9,0x85,0xff,0xf5,0xb9,0x85,0xff,0xf5,0xba,0x85,0xff,0xf8,0xbc,0x87,0xff,0xf4,0xbc,0x88,0xff,0xa5,0x65,0x48,0xff,0xe9,0xaf,0x7e,0xff,0xfd,0xc2,0x8b,0xff,0xf4,0xb8,0x85,0xff,0xf5,0xb9,0x85,0xff,0xf5,0xb9,0x85,0xff,0xf3,0xb8,0x84,0xff,0xeb,0xad,0x7d,0xff,0xfa,0xc0,0x8a,0xff,0xff,0xc9,0x91,0xff,0xfd,0xc2,0x8c,0xff,0xfa,0xbe,0x89,0xff,0xfb,0xbf,0x8a,0xff,0xff,0xca,0x92,0xff,0xfd,0xc2,0x8d,0xff,0xbc,0x79,0x58,0xff,0xc3,0x83,0x5f,0xff,0xff,0xc7,0x90,0xff,0xf4,0xb6,0x84,0xff,0xf4,0xb8,0x85,0xff,0xf4,0xb8,0x85,0xff,0xf4,0xb7,0x85,0xff,0xf4,0xb7,0x85,0xff,0xf4,0xb7,0x85,0xff,0xff,0xc3,0x8e,0xff,0xf4,0xb1,0x81,0xff,0x4b,0xf,0xb,0x5c,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x45,0x6,0x4,0x5a,0xea,0xab,0x7b,0xff,0xff,0xca,0x91,0xff,0xf5,0xba,0x86,0xff,0xf5,0xb9,0x85,0xff,0xf5,0xb9,0x85,0xff,0xf5,0xb9,0x85,0xff,0xf5,0xb9,0x85,0xff,0xf5,0xb9,0x85,0xff,0xf5,0xb9,0x85,0xff,0xf5,0xb9,0x85,0xff,0xf5,0xb9,0x85,0xff,0xf5,0xb9,0x85,0xff,0xf5,0xb8,0x85,0xff,0xf5,0xb8,0x85,0xff,0xf5,0xb9,0x85,0xff,0xf5,0xb8,0x85,0xff,0xf5,0xb8,0x85,0xff,0xf4,0xb8,0x85,0xff,0xf4,0xb8,0x85,0xff,0xf4,0xb8,0x85,0xff,0xf4,0xb8,0x85,0xff,0xf4,0xb7,0x84,0xff,0xff,0xcd,0x94,0xff,0xc2,0x84,0x60,0xff,0xb7,0x78,0x57,0xff,0xff,0xd4,0x99,0xff,0xf3,0xb5,0x83,0xff,0xf4,0xb7,0x85,0xff,0xf4,0xb7,0x85,0xff,0xf4,0xb7,0x84,0xff,0xf4,0xb7,0x85,0xff,0xf7,0xba,0x87,0xff,0xf5,0xb7,0x85,0xff,0xf4,0xb6,0x84,0xff,0xf4,0xb7,0x85,0xff,0xf4,0xb6,0x84,0xff,0xf4,0xb6,0x84,0xff,0xf3,0xb5,0x84,0xff,0xf7,0xb9,0x87,0xff,0xff,0xcd,0x95,0xff,0xb7,0x74,0x55,0xff,0xd7,0x98,0x6f,0xff,0xff,0xc3,0x8e,0xff,0xf4,0xb5,0x84,0xff,0xf4,0xb6,0x84,0xff,0xf4,0xb5,0x84,0xff,0xf4,0xb5,0x84,0xff,0xf4,0xb5,0x84,0xff,0xfd,0xbf,0x8b,0xff,0xff,0xb4,0x84,0xff,0x3a,0x14,0xf,0x60,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x4a,0xdb,0x9d,0x71,0xff,0xff,0xce,0x94,0xff,0xf4,0xb8,0x85,0xff,0xf4,0xb8,0x85,0xff,0xf4,0xb8,0x85,0xff,0xf4,0xb8,0x85,0xff,0xf4,0xb7,0x85,0xff,0xf4,0xb7,0x85,0xff,0xf4,0xb7,0x85,0xff,0xf4,0xb7,0x85,0xff,0xf4,0xb7,0x85,0xff,0xf4,0xb7,0x85,0xff,0xf4,0xb7,0x85,0xff,0xf4,0xb7,0x85,0xff,0xf4,0xb7,0x85,0xff,0xf4,0xb6,0x84,0xff,0xf4,0xb6,0x84,0xff,0xf4,0xb6,0x84,0xff,0xf4,0xb6,0x84,0xff,0xf4,0xb6,0x85,0xff,0xf4,0xb6,0x84,0xff,0xf4,0xb5,0x83,0xff,0xff,0xc8,0x91,0xff,0xac,0x6c,0x4f,0xff,0xd8,0x9a,0x70,0xff,0xfe,0xc0,0x8c,0xff,0xf4,0xb6,0x84,0xff,0xf4,0xb5,0x84,0xff,0xf4,0xb5,0x84,0xff,0xf4,0xb5,0x84,0xff,0xf3,0xb5,0x84,0xff,0xf3,0xb5,0x84,0xff,0xf4,0xb5,0x84,0xff,0xf4,0xb5,0x84,0xff,0xf3,0xb5,0x84,0xff,0xf3,0xb4,0x84,0xff,0xf3,0xb4,0x84,0xff,0xf3,0xb5,0x84,0xff,0xf3,0xb3,0x83,0xff,0xff,0xc3,0x8e,0xff,0xd6,0x95,0x6d,0xff,0xbe,0x7b,0x5a,0xff,0xff,0xc7,0x92,0xff,0xf2,0xb3,0x83,0xff,0xf3,0xb4,0x84,0xff,0xf3,0xb4,0x84,0xff,0xf3,0xb3,0x84,0xff,0xf3,0xb3,0x84,0xff,0xfa,0xbb,0x89,0xff,0xff,0xb9,0x87,0xff,0x45,0x1d,0x15,0x7b,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x36,0x0,0x0,0x2a,0xc3,0x85,0x61,0xff,0xff,0xd5,0x9b,0xff,0xf4,0xb5,0x83,0xff,0xf4,0xb6,0x84,0xff,0xf4,0xb6,0x84,0xff,0xf4,0xb6,0x84,0xff,0xf4,0xb6,0x84,0xff,0xf4,0xb6,0x84,0xff,0xf4,0xb5,0x84,0xff,0xf4,0xb5,0x84,0xff,0xf4,0xb5,0x84,0xff,0xf4,0xb5,0x84,0xff,0xf3,0xb5,0x84,0xff,0xf4,0xb5,0x84,0xff,0xf3,0xb5,0x84,0xff,0xf4,0xb5,0x84,0xff,0xf4,0xb5,0x84,0xff,0xf4,0xb4,0x84,0xff,0xf4,0xb4,0x84,0xff,0xf3,0xb4,0x84,0xff,0xf3,0xb4,0x84,0xff,0xfe,0xc0,0x8c,0xff,0xd5,0x95,0x6d,0xff,0xb0,0x6e,0x50,0xff,0xff,0xc7,0x91,0xff,0xf2,0xb2,0x83,0xff,0xf3,0xb4,0x84,0xff,0xf3,0xb4,0x84,0xff,0xf3,0xb3,0x84,0xff,0xf3,0xb3,0x84,0xff,0xf3,0xb3,0x83,0xff,0xf3,0xb3,0x83,0xff,0xf3,0xb3,0x84,0xff,0xf3,0xb3,0x83,0xff,0xf3,0xb3,0x83,0xff,0xf3,0xb3,0x83,0xff,0xf3,0xb3,0x83,0xff,0xf3,0xb3,0x83,0xff,0xf3,0xb3,0x83,0xff,0xf4,0xb2,0x83,0xff,0xf5,0xb6,0x86,0xff,0xbf,0x7b,0x5a,0xff,0xeb,0xa8,0x7c,0xff,0xf6,0xb6,0x86,0xff,0xf3,0xb2,0x83,0xff,0xf3,0xb2,0x83,0xff,0xf3,0xb2,0x83,0xff,0xf3,0xb2,0x83,0xff,0xf9,0xb8,0x88,0xff,0xff,0xbd,0x8c,0xff,0x6b,0x2f,0x23,0xa4,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x98,0x5a,0x42,0xd6,0xff,0xd7,0x9d,0xff,0xf2,0xb3,0x83,0xff,0xf3,0xb4,0x84,0xff,0xf3,0xb4,0x84,0xff,0xf3,0xb4,0x84,0xff,0xf3,0xb4,0x84,0xff,0xf3,0xb4,0x84,0xff,0xf3,0xb4,0x83,0xff,0xf3,0xb4,0x84,0xff,0xf3,0xb3,0x84,0xff,0xf3,0xb3,0x84,0xff,0xf3,0xb3,0x83,0xff,0xf3,0xb3,0x84,0xff,0xf3,0xb3,0x84,0xff,0xf3,0xb3,0x84,0xff,0xf3,0xb3,0x83,0xff,0xf3,0xb3,0x83,0xff,0xf3,0xb3,0x83,0xff,0xf3,0xb2,0x83,0xff,0xf2,0xb1,0x82,0xff,0xff,0xcb,0x95,0xff,0xb9,0x75,0x56,0xff,0xc7,0x86,0x63,0xff,0xff,0xc5,0x91,0xff,0xf3,0xb1,0x83,0xff,0xf3,0xb2,0x83,0xff,0xf3,0xb2,0x83,0xff,0xf3,0xb2,0x83,0xff,0xf3,0xb1,0x83,0xff,0xf3,0xb1,0x83,0xff,0xf3,0xb1,0x83,0xff,0xf3,0xb1,0x83,0xff,0xf3,0xb1,0x83,0xff,0xf3,0xb1,0x83,0xff,0xf2,0xb1,0x83,0xff,0xf3,0xb1,0x83,0xff,0xf2,0xb1,0x83,0xff,0xf2,0xb1,0x83,0xff,0xf2,0xb0,0x82,0xff,0xff,0xc2,0x90,0xff,0xc3,0x80,0x5e,0xff,0xd0,0x88,0x65,0xff,0xff,0xbd,0x8c,0xff,0xf6,0xb5,0x86,0xff,0xf1,0xae,0x81,0xff,0xf2,0xb0,0x82,0xff,0xf2,0xb0,0x82,0xff,0xf6,0xb4,0x86,0xff,0xff,0xbe,0x8d,0xff,0x88,0x41,0x31,0xde,0x9,0x0,0x0,0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x5a,0x23,0x1a,0x91,0xff,0xc1,0x8f,0xff,0xf8,0xb7,0x87,0xff,0xf3,0xb2,0x83,0xff,0xf3,0xb2,0x83,0xff,0xf3,0xb2,0x83,0xff,0xf3,0xb2,0x83,0xff,0xf3,0xb2,0x83,0xff,0xf3,0xb2,0x83,0xff,0xf3,0xb2,0x83,0xff,0xf3,0xb2,0x83,0xff,0xf3,0xb2,0x83,0xff,0xf3,0xb1,0x83,0xff,0xf3,0xb1,0x83,0xff,0xf2,0xb1,0x83,0xff,0xf3,0xb1,0x83,0xff,0xf3,0xb1,0x83,0xff,0xf2,0xb1,0x83,0xff,0xf2,0xb1,0x83,0xff,0xf3,0xb1,0x83,0xff,0xf5,0xb3,0x84,0xff,0xf1,0xaf,0x82,0xff,0xb0,0x6b,0x4f,0xff,0xe9,0xa8,0x7d,0xff,0xf6,0xb3,0x85,0xff,0xf2,0xb0,0x82,0xff,0xf2,0xb0,0x83,0xff,0xf2,0xb0,0x82,0xff,0xf2,0xb0,0x83,0xff,0xf2,0xb0,0x83,0xff,0xf2,0xb0,0x82,0xff,0xf2,0xaf,0x82,0xff,0xf2,0xaf,0x82,0xff,0xf2,0xaf,0x82,0xff,0xf2,0xaf,0x82,0xff,0xf2,0xaf,0x82,0xff,0xf2,0xaf,0x82,0xff,0xf2,0xaf,0x82,0xff,0xf2,0xaf,0x82,0xff,0xf2,0xaf,0x82,0xff,0xff,0xbf,0x8e,0xff,0xc8,0x84,0x62,0xff,0xcb,0x82,0x61,0xff,0xf4,0xae,0x82,0xff,0xe9,0xa6,0x7c,0xff,0xf6,0xb2,0x85,0xff,0xf2,0xae,0x82,0xff,0xf2,0xae,0x82,0xff,0xf4,0xb1,0x84,0xff,0xfc,0xbb,0x8b,0xff,0xac,0x5b,0x45,0xff,0x44,0x0,0x0,0x46,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x31,0x0,0x0,0x43,0xd5,0x98,0x70,0xff,0xff,0xc8,0x94,0xff,0xf2,0xb0,0x82,0xff,0xf2,0xb0,0x83,0xff,0xf2,0xb0,0x83,0xff,0xf2,0xb0,0x83,0xff,0xf2,0xb0,0x82,0xff,0xf2,0xb0,0x83,0xff,0xf2,0xb0,0x83,0xff,0xf2,0xb0,0x82,0xff,0xf2,0xaf,0x82,0xff,0xf2,0xaf,0x82,0xff,0xf2,0xb0,0x82,0xff,0xf2,0xaf,0x82,0xff,0xf2,0xaf,0x82,0xff,0xf2,0xaf,0x82,0xff,0xf2,0xaf,0x82,0xff,0xf2,0xaf,0x82,0xff,0xf2,0xaf,0x82,0xff,0xfe,0xbb,0x8b,0xff,0xcf,0x89,0x66,0xff,0xaa,0x64,0x4a,0xff,0xff,0xc1,0x90,0xff,0xf1,0xad,0x81,0xff,0xf2,0xae,0x82,0xff,0xf2,0xae,0x82,0xff,0xf2,0xae,0x82,0xff,0xf2,0xae,0x82,0xff,0xf2,0xae,0x82,0xff,0xf2,0xae,0x82,0xff,0xf2,0xae,0x82,0xff,0xf2,0xae,0x82,0xff,0xf2,0xae,0x82,0xff,0xf2,0xad,0x82,0xff,0xf2,0xad,0x82,0xff,0xf1,0xad,0x81,0xff,0xf2,0xad,0x82,0xff,0xf2,0xad,0x82,0xff,0xf2,0xad,0x82,0xff,0xff,0xbd,0x8e,0xff,0xc7,0x81,0x61,0xff,0xcf,0x86,0x65,0xff,0xe6,0x9d,0x76,0xff,0xd2,0x8b,0x69,0xff,0xfd,0xb9,0x8b,0xff,0xf1,0xac,0x81,0xff,0xf1,0xac,0x81,0xff,0xf2,0xad,0x82,0xff,0xf4,0xb3,0x86,0xff,0xd4,0x7c,0x5f,0xff,0x59,0x14,0x10,0x7b,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x24,0x0,0x0,0x4,0x9d,0x60,0x48,0xe2,0xff,0xd5,0x9e,0xff,0xf1,0xac,0x80,0xff,0xf2,0xaf,0x82,0xff,0xf2,0xaf,0x82,0xff,0xf2,0xae,0x82,0xff,0xf2,0xae,0x82,0xff,0xf2,0xae,0x82,0xff,0xf2,0xae,0x82,0xff,0xf2,0xae,0x82,0xff,0xf2,0xae,0x82,0xff,0xf1,0xae,0x82,0xff,0xf2,0xae,0x82,0xff,0xf2,0xae,0x82,0xff,0xf1,0xae,0x82,0xff,0xf1,0xae,0x82,0xff,0xf1,0xad,0x82,0xff,0xf2,0xad,0x82,0xff,0xf1,0xad,0x82,0xff,0xff,0xbf,0x8f,0xff,0xc1,0x7a,0x5b,0xff,0xbb,0x74,0x57,0xff,0xff,0xc1,0x91,0xff,0xf1,0xac,0x82,0xff,0xf1,0xad,0x82,0xff,0xf1,0xad,0x82,0xff,0xf1,0xac,0x81,0xff,0xf1,0xac,0x81,0xff,0xf1,0xac,0x81,0xff,0xf1,0xac,0x81,0xff,0xf1,0xac,0x81,0xff,0xf1,0xac,0x81,0xff,0xf1,0xac,0x81,0xff,0xf1,0xac,0x81,0xff,0xf1,0xac,0x81,0xff,0xf1,0xab,0x81,0xff,0xf1,0xac,0x81,0xff,0xf1,0xac,0x81,0xff,0xf1,0xab,0x81,0xff,0xff,0xbc,0x8e,0xff,0xc1,0x7a,0x5c,0xff,0xd2,0x86,0x66,0xff,0xeb,0x9e,0x78,0xff,0xcb,0x82,0x63,0xff,0xfa,0xb5,0x89,0xff,0xf0,0xaa,0x80,0xff,0xf1,0xab,0x81,0xff,0xf2,0xac,0x82,0xff,0xf5,0xb2,0x86,0xff,0xdf,0x85,0x66,0xff,0x6d,0x28,0x20,0xa2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x5a,0x17,0x12,0x86,0xff,0xba,0x8c,0xff,0xfb,0xb8,0x8a,0xff,0xf1,0xac,0x82,0xff,0xf1,0xad,0x81,0xff,0xf1,0xad,0x81,0xff,0xf1,0xad,0x81,0xff,0xf1,0xad,0x82,0xff,0xf1,0xac,0x81,0xff,0xf1,0xac,0x81,0xff,0xf1,0xac,0x81,0xff,0xf1,0xac,0x81,0xff,0xf1,0xac,0x81,0xff,0xf1,0xab,0x81,0xff,0xf1,0xac,0x81,0xff,0xf1,0xac,0x81,0xff,0xf1,0xac,0x81,0xff,0xf1,0xab,0x81,0xff,0xf1,0xab,0x81,0xff,0xff,0xbd,0x8e,0xff,0xbd,0x76,0x59,0xff,0xcb,0x84,0x64,0xff,0xff,0xb9,0x8c,0xff,0xf1,0xab,0x81,0xff,0xf1,0xab,0x81,0xff,0xf1,0xab,0x81,0xff,0xf1,0xab,0x81,0xff,0xf1,0xab,0x81,0xff,0xf1,0xaa,0x81,0xff,0xf1,0xaa,0x81,0xff,0xf0,0xaa,0x81,0xff,0xf0,0xaa,0x81,0xff,0xf1,0xaa,0x81,0xff,0xf1,0xaa,0x81,0xff,0xf1,0xaa,0x81,0xff,0xf1,0xaa,0x81,0xff,0xf1,0xaa,0x81,0xff,0xf0,0xa9,0x80,0xff,0xf0,0xa9,0x80,0xff,0xf9,0xb3,0x87,0xff,0xbc,0x73,0x57,0xff,0xdc,0x8c,0x6b,0xff,0xf3,0xa2,0x7c,0xff,0xc4,0x77,0x5b,0xff,0xe5,0x9f,0x79,0xff,0xf4,0xac,0x83,0xff,0xf0,0xa9,0x80,0xff,0xf0,0xa8,0x80,0xff,0xf9,0xb5,0x89,0xff,0xd9,0x85,0x66,0xff,0x83,0x35,0x2a,0xc6,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xa,0x0,0x0,0x1b,0xa5,0x65,0x4c,0xf9,0xff,0xd0,0x9d,0xff,0xef,0xa8,0x7f,0xff,0xf1,0xab,0x81,0xff,0xf1,0xab,0x81,0xff,0xf1,0xab,0x81,0xff,0xf0,0xaa,0x81,0xff,0xf0,0xaa,0x81,0xff,0xf1,0xaa,0x81,0xff,0xf1,0xaa,0x81,0xff,0xf0,0xaa,0x81,0xff,0xf1,0xaa,0x81,0xff,0xf1,0xaa,0x81,0xff,0xf1,0xaa,0x80,0xff,0xf0,0xaa,0x81,0xff,0xf0,0xaa,0x81,0xff,0xf0,0xaa,0x80,0xff,0xf0,0xa9,0x81,0xff,0xff,0xb9,0x8d,0xff,0xbe,0x75,0x59,0xff,0xcf,0x87,0x67,0xff,0xfc,0xb5,0x8a,0xff,0xf0,0xa9,0x81,0xff,0xf0,0xa9,0x80,0xff,0xf0,0xa9,0x80,0xff,0xf0,0xa9,0x80,0xff,0xf0,0xa8,0x80,0xff,0xf0,0xa8,0x80,0xff,0xf0,0xa8,0x80,0xff,0xf0,0xa8,0x80,0xff,0xf0,0xa8,0x80,0xff,0xf0,0xa8,0x80,0xff,0xf0,0xa8,0x80,0xff,0xf0,0xa8,0x80,0xff,0xf0,0xa8,0x80,0xff,0xf0,0xa8,0x80,0xff,0xf0,0xa8,0x80,0xff,0xf4,0xac,0x83,0xff,0xe5,0x9e,0x78,0xff,0xb9,0x6d,0x54,0xff,0xec,0x9a,0x77,0xff,0xf8,0xa4,0x7e,0xff,0xbc,0x66,0x50,0xff,0xcb,0x82,0x64,0xff,0xff,0xb7,0x8c,0xff,0xf0,0xa7,0x80,0xff,0xef,0xa7,0x80,0xff,0xfc,0xb5,0x8b,0xff,0xd3,0x83,0x66,0xff,0x9b,0x46,0x37,0xea,0x26,0x0,0x0,0xa,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0xa,0x8,0x7a,0xf7,0xae,0x84,0xff,0xff,0xbd,0x8f,0xff,0xee,0xa7,0x7f,0xff,0xf0,0xa9,0x80,0xff,0xf0,0xa9,0x80,0xff,0xf0,0xa9,0x80,0xff,0xf0,0xa9,0x80,0xff,0xf0,0xa9,0x81,0xff,0xf0,0xa9,0x80,0xff,0xf0,0xa8,0x80,0xff,0xf0,0xa8,0x80,0xff,0xf0,0xa8,0x80,0xff,0xf0,0xa8,0x80,0xff,0xf0,0xa8,0x80,0xff,0xf0,0xa8,0x80,0xff,0xf0,0xa8,0x80,0xff,0xf0,0xa8,0x80,0xff,0xff,0xb9,0x8d,0xff,0xbd,0x73,0x58,0xff,0xcc,0x83,0x64,0xff,0xfd,0xb5,0x8a,0xff,0xf0,0xa7,0x80,0xff,0xf0,0xa7,0x80,0xff,0xf0,0xa7,0x80,0xff,0xf0,0xa7,0x80,0xff,0xf0,0xa7,0x80,0xff,0xf0,0xa7,0x80,0xff,0xf0,0xa7,0x80,0xff,0xf0,0xa7,0x80,0xff,0xef,0xa6,0x80,0xff,0xef,0xa6,0x80,0xff,0xef,0xa6,0x80,0xff,0xef,0xa6,0x80,0xff,0xef,0xa6,0x7f,0xff,0xef,0xa6,0x80,0xff,0xf0,0xa6,0x80,0xff,0xfa,0xb0,0x87,0xff,0xd3,0x8b,0x6b,0xff,0xb7,0x66,0x4f,0xff,0xf7,0xa2,0x7e,0xff,0xf1,0x9d,0x7b,0xff,0xc4,0x67,0x52,0xff,0xb9,0x6b,0x53,0xff,0xff,0xb8,0x8d,0xff,0xee,0xa5,0x7f,0xff,0xef,0xa5,0x7f,0xff,0xfe,0xb4,0x8b,0xff,0xcc,0x7e,0x62,0xff,0xae,0x56,0x44,0xff,0x3e,0x5,0x4,0x2e,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x8f,0x47,0x36,0xd3,0xff,0xcd,0x9d,0xff,0xf5,0xac,0x84,0xff,0xee,0xa6,0x7f,0xff,0xf0,0xa7,0x80,0xff,0xf0,0xa7,0x80,0xff,0xf0,0xa7,0x80,0xff,0xf0,0xa7,0x80,0xff,0xf0,0xa7,0x80,0xff,0xf0,0xa7,0x80,0xff,0xf0,0xa7,0x80,0xff,0xef,0xa7,0x80,0xff,0xef,0xa6,0x7f,0xff,0xef,0xa6,0x7f,0xff,0xef,0xa6,0x80,0xff,0xef,0xa6,0x80,0xff,0xef,0xa6,0x7f,0xff,0xff,0xb8,0x8d,0xff,0xbd,0x73,0x58,0xff,0xb9,0x6f,0x55,0xff,0xff,0xba,0x8f,0xff,0xef,0xa6,0x7f,0xff,0xef,0xa5,0x7f,0xff,0xef,0xa5,0x7f,0xff,0xef,0xa5,0x7f,0xff,0xef,0xa5,0x7f,0xff,0xef,0xa5,0x7f,0xff,0xef,0xa5,0x7f,0xff,0xef,0xa5,0x7f,0xff,0xef,0xa5,0x7f,0xff,0xef,0xa5,0x7f,0xff,0xef,0xa4,0x7f,0xff,0xef,0xa5,0x7f,0xff,0xef,0xa4,0x7f,0xff,0xef,0xa4,0x7f,0xff,0xef,0xa4,0x7f,0xff,0xff,0xb4,0x8c,0xff,0xc4,0x79,0x5d,0xff,0xbc,0x65,0x4f,0xff,0xf5,0x9e,0x7c,0xff,0xea,0x92,0x74,0xff,0xd4,0x73,0x5d,0xff,0xb2,0x5d,0x4a,0xff,0xf4,0xac,0x85,0xff,0xf0,0xa4,0x7f,0xff,0xef,0xa3,0x7f,0xff,0xff,0xb4,0x8c,0xff,0xc5,0x79,0x5e,0xff,0xbb,0x60,0x4c,0xff,0x50,0x16,0x11,0x4e,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x25,0x0,0x0,0x2c,0xae,0x66,0x4e,0xfd,0xff,0xce,0x9e,0xff,0xf3,0xaa,0x83,0xff,0xed,0xa3,0x7e,0xff,0xef,0xa5,0x7f,0xff,0xef,0xa5,0x7f,0xff,0xef,0xa5,0x7f,0xff,0xef,0xa5,0x7f,0xff,0xef,0xa5,0x7f,0xff,0xef,0xa5,0x7f,0xff,0xef,0xa5,0x7f,0xff,0xef,0xa4,0x7f,0xff,0xef,0xa4,0x7f,0xff,0xef,0xa4,0x7f,0xff,0xef,0xa4,0x7f,0xff,0xef,0xa4,0x7f,0xff,0xfb,0xb0,0x88,0xff,0xcb,0x7f,0x62,0xff,0xa7,0x5e,0x48,0xff,0xff,0xb8,0x8e,0xff,0xee,0xa3,0x7e,0xff,0xef,0xa4,0x7f,0xff,0xef,0xa3,0x7f,0xff,0xef,0xa4,0x7f,0xff,0xef,0xa3,0x7f,0xff,0xef,0xa3,0x7f,0xff,0xef,0xa3,0x7f,0xff,0xef,0xa3,0x7f,0xff,0xef,0xa3,0x7f,0xff,0xef,0xa3,0x7f,0xff,0xef,0xa3,0x7e,0xff,0xee,0xa3,0x7e,0xff,0xef,0xa2,0x7f,0xff,0xef,0xa3,0x7e,0xff,0xef,0xa2,0x7e,0xff,0xff,0xb4,0x8c,0xff,0xba,0x6b,0x54,0xff,0xc8,0x6a,0x55,0xff,0xec,0x92,0x74,0xff,0xe4,0x89,0x6d,0xff,0xe4,0x81,0x68,0xff,0x92,0x40,0x32,0xe8,0xda,0x90,0x70,0xf9,0xf7,0xab,0x85,0xff,0xee,0xa2,0x7e,0xff,0xff,0xb2,0x8b,0xff,0xc2,0x77,0x5d,0xff,0xc6,0x69,0x54,0xff,0x6e,0x28,0x20,0x76,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x29,0x0,0x0,0x45,0xb5,0x68,0x50,0xff,0xff,0xcd,0x9f,0xff,0xfa,0xb1,0x89,0xff,0xed,0xa1,0x7d,0xff,0xef,0xa3,0x7f,0xff,0xef,0xa3,0x7f,0xff,0xef,0xa3,0x7f,0xff,0xef,0xa3,0x7f,0xff,0xef,0xa3,0x7f,0xff,0xee,0xa3,0x7e,0xff,0xee,0xa3,0x7e,0xff,0xee,0xa2,0x7e,0xff,0xee,0xa2,0x7e,0xff,0xee,0xa2,0x7e,0xff,0xee,0xa2,0x7e,0xff,0xef,0xa3,0x7f,0xff,0xf2,0xa6,0x81,0xff,0xad,0x61,0x4c,0xff,0xe4,0x99,0x77,0xff,0xf3,0xa6,0x81,0xff,0xee,0xa2,0x7e,0xff,0xee,0xa2,0x7e,0xff,0xee,0xa2,0x7e,0xff,0xee,0xa1,0x7e,0xff,0xee,0xa1,0x7e,0xff,0xee,0xa1,0x7e,0xff,0xee,0xa1,0x7e,0xff,0xee,0xa1,0x7e,0xff,0xee,0xa1,0x7e,0xff,0xee,0xa1,0x7e,0xff,0xee,0xa1,0x7e,0xff,0xee,0xa1,0x7e,0xff,0xee,0xa1,0x7e,0xff,0xee,0xa1,0x7e,0xff,0xff,0xb1,0x8b,0xff,0xbc,0x71,0x58,0xff,0xb6,0x57,0x47,0xff,0xf9,0x93,0x77,0xff,0xec,0x8c,0x71,0xff,0xdb,0x77,0x60,0xff,0x36,0x0,0x0,0x78,0xb3,0x6f,0x57,0xd6,0xff,0xb8,0x91,0xff,0xee,0x9f,0x7d,0xff,0xfd,0xaf,0x89,0xff,0xc3,0x78,0x5e,0xff,0xd3,0x71,0x5a,0xff,0x88,0x3e,0x31,0xa5,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1a,0x0,0x0,0x34,0x9e,0x4b,0x3b,0xef,0xff,0xb5,0x8d,0xff,0xff,0xbd,0x94,0xff,0xef,0xa2,0x7e,0xff,0xed,0xa0,0x7d,0xff,0xee,0xa1,0x7e,0xff,0xee,0xa1,0x7e,0xff,0xee,0xa1,0x7e,0xff,0xee,0xa1,0x7e,0xff,0xee,0xa1,0x7e,0xff,0xee,0xa1,0x7e,0xff,0xee,0xa0,0x7e,0xff,0xee,0xa0,0x7e,0xff,0xee,0xa0,0x7e,0xff,0xed,0x9f,0x7d,0xff,0xff,0xb6,0x8f,0xff,0xb9,0x6c,0x55,0xff,0xba,0x6e,0x57,0xff,0xff,0xb6,0x8f,0xff,0xed,0x9e,0x7d,0xff,0xee,0xa0,0x7e,0xff,0xee,0xa0,0x7e,0xff,0xed,0x9f,0x7d,0xff,0xed,0xa0,0x7d,0xff,0xee,0x9f,0x7d,0xff,0xed,0x9f,0x7d,0xff,0xee,0x9f,0x7d,0xff,0xed,0x9f,0x7d,0xff,0xed,0x9f,0x7e,0xff,0xee,0x9f,0x7d,0xff,0xee,0x9f,0x7d,0xff,0xed,0x9f,0x7d,0xff,0xed,0x9f,0x7d,0xff,0xf2,0xa3,0x80,0xff,0xed,0xa1,0x7e,0xff,0xa9,0x5b,0x48,0xff,0xb0,0x4f,0x41,0xff,0xf3,0x88,0x6f,0xff,0xde,0x73,0x5d,0xff,0x0,0x0,0x0,0x2d,0x79,0x4b,0x3c,0x94,0xff,0xbc,0x95,0xff,0xec,0x9d,0x7c,0xff,0xfa,0xab,0x88,0xff,0xc9,0x7d,0x63,0xff,0xd4,0x6f,0x5b,0xff,0xa0,0x4e,0x3f,0xc7,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2e,0x0,0x0,0x6,0x5c,0x12,0xe,0xa7,0xd0,0x82,0x66,0xff,0xff,0xc5,0x9b,0xff,0xfc,0xb0,0x8b,0xff,0xed,0x9d,0x7c,0xff,0xed,0x9e,0x7c,0xff,0xee,0x9f,0x7d,0xff,0xee,0x9f,0x7d,0xff,0xed,0x9f,0x7d,0xff,0xed,0x9f,0x7d,0xff,0xed,0x9f,0x7d,0xff,0xee,0x9f,0x7d,0xff,0xed,0x9f,0x7d,0xff,0xed,0x9f,0x7d,0xff,0xf2,0xa3,0x81,0xff,0xe5,0x97,0x77,0xff,0xa5,0x58,0x45,0xff,0xf1,0xa3,0x81,0xff,0xf1,0xa2,0x80,0xff,0xed,0x9e,0x7d,0xff,0xed,0x9e,0x7d,0xff,0xed,0x9e,0x7d,0xff,0xed,0x9e,0x7d,0xff,0xed,0x9e,0x7d,0xff,0xed,0x9e,0x7d,0xff,0xed,0x9e,0x7d,0xff,0xed,0x9e,0x7d,0xff,0xed,0x9d,0x7d,0xff,0xed,0x9d,0x7d,0xff,0xed,0x9d,0x7d,0xff,0xed,0x9d,0x7d,0xff,0xed,0x9d,0x7d,0xff,0xeb,0x9b,0x7b,0xff,0xf8,0xa8,0x86,0xff,0xef,0xa2,0x80,0xff,0xb2,0x66,0x51,0xff,0xa2,0x49,0x3c,0xff,0xc9,0x5f,0x4e,0xff,0x72,0x28,0x21,0xa7,0x5b,0x21,0x1b,0xa6,0xfb,0xa6,0x85,0xff,0xf1,0xa0,0x7f,0xff,0xf7,0xa6,0x84,0xff,0xd1,0x84,0x69,0xff,0xcf,0x6b,0x57,0xff,0xba,0x5a,0x49,0xeb,0x4,0x0,0x0,0xc,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x34,0x0,0x0,0x41,0x96,0x43,0x35,0xe8,0xf1,0x9e,0x7d,0xff,0xff,0xc0,0x98,0xff,0xff,0xb5,0x90,0xff,0xf3,0xa2,0x81,0xff,0xeb,0x9c,0x7c,0xff,0xed,0x9d,0x7d,0xff,0xed,0x9d,0x7d,0xff,0xed,0x9d,0x7d,0xff,0xed,0x9d,0x7d,0xff,0xed,0x9d,0x7d,0xff,0xed,0x9d,0x7d,0xff,0xeb,0x9b,0x7b,0xff,0xff,0xb2,0x8d,0xff,0xb8,0x6a,0x54,0xff,0xb0,0x61,0x4e,0xff,0xff,0xb8,0x93,0xff,0xed,0x9c,0x7c,0xff,0xec,0x9b,0x7c,0xff,0xed,0x9c,0x7d,0xff,0xec,0x9c,0x7c,0xff,0xec,0x9c,0x7c,0xff,0xed,0x9c,0x7c,0xff,0xed,0x9c,0x7c,0xff,0xed,0x9c,0x7c,0xff,0xed,0x9c,0x7c,0xff,0xec,0x9c,0x7c,0xff,0xec,0x9c,0x7c,0xff,0xed,0x9c,0x7c,0xff,0xed,0x9b,0x7c,0xff,0xec,0x9b,0x7c,0xff,0xea,0x99,0x7a,0xff,0xf3,0xa1,0x81,0xff,0xff,0xb2,0x8e,0xff,0xde,0x92,0x74,0xff,0xb0,0x62,0x4f,0xff,0xcc,0x61,0x50,0xff,0xa2,0x3f,0x34,0xff,0xc7,0x7c,0x63,0xff,0xfb,0xaa,0x88,0xff,0xf1,0x9f,0x80,0xff,0xdd,0x90,0x73,0xff,0xc5,0x65,0x52,0xff,0xd0,0x62,0x51,0xff,0x20,0x0,0x0,0x36,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x17,0x0,0x0,0x1,0x43,0x6,0x5,0x69,0x95,0x45,0x37,0xdf,0xd7,0x82,0x68,0xff,0xff,0xab,0x88,0xff,0xff,0xbb,0x96,0xff,0xff,0xb5,0x91,0xff,0xfe,0xac,0x8a,0xff,0xfa,0xa8,0x87,0xff,0xfa,0xa8,0x86,0xff,0xfa,0xa8,0x87,0xff,0xf9,0xa8,0x86,0xff,0xf9,0xa7,0x86,0xff,0xfd,0xaa,0x88,0xff,0xff,0xb1,0x8f,0xff,0xae,0x60,0x4e,0xff,0xc8,0x77,0x5f,0xff,0xff,0xb8,0x94,0xff,0xff,0xae,0x8c,0xff,0xfe,0xab,0x89,0xff,0xfe,0xab,0x89,0xff,0xfd,0xaa,0x89,0xff,0xfc,0xa9,0x88,0xff,0xfa,0xa7,0x86,0xff,0xf7,0xa4,0x84,0xff,0xf5,0xa2,0x83,0xff,0xf4,0xa1,0x82,0xff,0xf3,0xa1,0x82,0xff,0xf3,0xa0,0x81,0xff,0xf3,0x9f,0x80,0xff,0xf2,0x9f,0x80,0xff,0xf2,0x9f,0x80,0xff,0xf2,0x9f,0x81,0xff,0xf2,0x9f,0x80,0xff,0xfd,0xab,0x8a,0xff,0xff,0xbe,0x99,0xff,0xd1,0x7f,0x67,0xff,0x94,0x30,0x29,0xff,0xcf,0x7a,0x63,0xff,0xff,0xb5,0x92,0xff,0xf0,0x9d,0x7f,0xff,0xeb,0x9c,0x7e,0xff,0xbc,0x5f,0x4e,0xff,0xe2,0x6a,0x59,0xff,0x4e,0x12,0xf,0x6c,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x30,0x0,0x0,0x3c,0x64,0x1c,0x17,0x95,0x95,0x4b,0x3c,0xdf,0xc4,0x72,0x5c,0xff,0xdc,0x89,0x6f,0xff,0xe2,0x90,0x74,0xff,0xe3,0x90,0x74,0xff,0xe1,0x8f,0x73,0xff,0xe3,0x91,0x75,0xff,0xe4,0x91,0x75,0xff,0xe1,0x8e,0x73,0xff,0xf0,0x9b,0x7e,0xff,0xec,0x97,0x7a,0xff,0x99,0x48,0x3b,0xff,0xa8,0x58,0x47,0xff,0xdb,0x88,0x6e,0xff,0xd8,0x85,0x6c,0xff,0xd6,0x84,0x6b,0xff,0xd8,0x85,0x6c,0xff,0xdc,0x89,0x6e,0xff,0xe1,0x8e,0x73,0xff,0xe8,0x95,0x79,0xff,0xed,0x9a,0x7d,0xff,0xef,0x9c,0x7f,0xff,0xf1,0x9d,0x80,0xff,0xf2,0x9f,0x80,0xff,0xf3,0x9f,0x81,0xff,0xf4,0xa0,0x82,0xff,0xf4,0xa0,0x82,0xff,0xf4,0x9e,0x81,0xff,0xf1,0x9c,0x7f,0xff,0xef,0x9a,0x7d,0xff,0xf8,0xa2,0x84,0xff,0xdd,0x8f,0x74,0xff,0xa3,0x3e,0x34,0xff,0xbc,0x5a,0x4b,0xff,0xf2,0xa2,0x84,0xff,0xff,0xa9,0x8a,0xff,0xff,0xaf,0x8f,0xff,0xc2,0x69,0x56,0xff,0xef,0x73,0x60,0xff,0x76,0x2a,0x23,0xb2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x38,0x0,0x0,0x4a,0x4d,0x0,0x0,0x8d,0x54,0x5,0x4,0x96,0x56,0x8,0x7,0x88,0x55,0x7,0x6,0x7d,0x57,0x9,0x7,0x7a,0x55,0x8,0x7,0x78,0x53,0x7,0x5,0x7b,0x54,0x8,0x7,0x80,0x58,0xe,0xb,0x87,0x57,0xe,0xb,0x90,0x3b,0x0,0x0,0x96,0x47,0x0,0x0,0x96,0x4b,0x0,0x0,0x8e,0x49,0x0,0x0,0x83,0x4a,0x0,0x0,0x7b,0x4c,0x1,0x1,0x77,0x52,0x7,0x6,0x77,0x5b,0xf,0xc,0x7b,0x60,0x15,0x11,0x83,0x64,0x17,0x13,0x8d,0x65,0x18,0x14,0x97,0x66,0x1a,0x16,0xa1,0x68,0x1c,0x17,0xa9,0x6a,0x1c,0x17,0xaf,0x6a,0x1c,0x17,0xb2,0x69,0x1b,0x16,0xb6,0x67,0x19,0x14,0xbb,0x65,0x16,0x13,0xb6,0x65,0x17,0x13,0xaf,0x5a,0xe,0xc,0xac,0x65,0x11,0xe,0xac,0x5c,0xc,0xa,0xb3,0x60,0x15,0x11,0xbc,0x77,0x29,0x21,0xc4,0x79,0x2c,0x25,0xc9,0x68,0x1c,0x17,0xc9,0x72,0x1f,0x1a,0xe1,0x5b,0xd,0xb,0x85,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0 \ No newline at end of file diff --git a/lib/PainterEngine/architecture/PainterEngine_Runtime.c b/lib/PainterEngine/architecture/PainterEngine_Runtime.c new file mode 100644 index 0000000000000000000000000000000000000000..1e80fcffd21c35972ff1390131041482f1440c8d --- /dev/null +++ b/lib/PainterEngine/architecture/PainterEngine_Runtime.c @@ -0,0 +1,118 @@ +#include "PainterEngine_Runtime.h" + + +px_void PE_MP_ErrorCall(PX_MEMORYPOOL_ERROR err) +{ + switch(err) + { + case PX_MEMORYPOOL_ERROR_INVALID_ACCESS: + PX_ERROR("Memory access error"); + break; + case PX_MEMORYPOOL_ERROR_INVALID_ADDRESS: + PX_ERROR("Memory address error"); + break; + case PX_MEMORYPOOL_ERROR_OUTOFMEMORY: + PX_ERROR("Out of memory"); + break; + } +} + + + +px_bool PX_RuntimeInitialize(PX_Runtime *pe,px_int surface_width,px_int surface_height,px_int window_width,px_int window_height,px_void *runtime_memoryPtr,px_uint size,px_uint ui_size,px_uint resource_size,px_uint game_size) +{ + PX_memset(pe,0,sizeof(PX_Runtime)); + pe->surface_width=surface_width; + pe->surface_height=surface_height; + pe->window_width=window_width; + pe->window_height=window_height; + + pe->mp=MP_Create(runtime_memoryPtr,size); + pe->mp_ui=MP_Create(MP_Malloc(&pe->mp,ui_size),ui_size); + pe->mp_resources=MP_Create(MP_Malloc(&pe->mp,resource_size),resource_size); + pe->mp_game=MP_Create(MP_Malloc(&pe->mp,game_size),game_size); + + + MP_ErrorCatch(&pe->mp_ui,PE_MP_ErrorCall); + MP_ErrorCatch(&pe->mp_resources,PE_MP_ErrorCall); + MP_ErrorCatch(&pe->mp_game,PE_MP_ErrorCall); + + //resources + if(!PX_ResourceLibraryInitialize(&pe->mp_resources,&pe->ResourceLibrary))return PX_FALSE; + //surface + if (pe->surface_width==0||pe->surface_height==0) + { + pe->RenderSurface.height=0; + pe->RenderSurface.width=0; + pe->RenderSurface.surfaceBuffer=PX_NULL; + pe->RenderSurface.MP=PX_NULL; + } + else + { + if(!PX_SurfaceCreate(&pe->mp,surface_width,surface_height,&pe->RenderSurface)) + { + return PX_FALSE; + } + PX_SurfaceClear(&pe->RenderSurface,0,0,pe->RenderSurface.width-1,pe->RenderSurface.height-1,PX_COLOR(255,255,255,255)); + } + + + + return PX_TRUE; +} + + +px_bool PX_RuntimeResize(PX_Runtime *pe,px_int surface_width,px_int surface_height,px_int window_width,px_int window_height) +{ + if (PX_SurfaceMemorySize(surface_width,surface_height)+64>(px_int)pe->mp.FreeSize) + { + return PX_FALSE; + } + + PX_SurfaceFree(&pe->RenderSurface); + + pe->surface_width=surface_width; + pe->surface_height=surface_height; + pe->window_width=window_width; + pe->window_height=window_height; + + if(!PX_SurfaceCreate(&pe->mp,surface_width,surface_height,&pe->RenderSurface)) + { + PX_ASSERT(); + return PX_FALSE; + } + PX_SurfaceClear(&pe->RenderSurface,0,0,pe->RenderSurface.width-1,pe->RenderSurface.height-1,PX_COLOR(255,255,255,255)); + + return PX_TRUE; +} + + +px_void PX_RuntimeReset(PX_Runtime *pe) +{ + MP_Reset(&pe->mp_game); + MP_Reset(&pe->mp_resources); + MP_Reset(&pe->mp_ui); + PX_ResourceLibraryInitialize(&pe->mp_resources,&pe->ResourceLibrary); + PX_SurfaceClear(&pe->RenderSurface,0,0,pe->RenderSurface.width-1,pe->RenderSurface.height-1,PX_COLOR(0,0,0,0)); +} + +px_memorypool PX_RuntimeCreateCalcMemoryPool(PX_Runtime *pe) +{ + return MP_Create(MP_Malloc(&pe->mp,PE_MEMORY_CALC_SIZE),PE_MEMORY_CALC_SIZE); +} + +px_void PX_RuntimeFreeCalcMemoryPool(PX_Runtime *pe,px_memorypool mp) +{ + MP_Free(&pe->mp,mp.StartAddr); +} + + +px_surface * PX_RuntimeGetRenderSurface(PX_Runtime *pe) +{ + return &pe->RenderSurface; +} + +px_void PX_RuntimeRenderClear(PX_Runtime *runtime,px_color color) +{ + PX_SurfaceClear(&runtime->RenderSurface,0,0,runtime->RenderSurface.width-1,runtime->RenderSurface.height-1,color); +} diff --git a/lib/PainterEngine/architecture/PainterEngine_Runtime.h b/lib/PainterEngine/architecture/PainterEngine_Runtime.h new file mode 100644 index 0000000000000000000000000000000000000000..678cec186b45f99c05654e9eb07124c850d271af --- /dev/null +++ b/lib/PainterEngine/architecture/PainterEngine_Runtime.h @@ -0,0 +1,36 @@ +#ifndef PAINTERENGINE_RUNTIME_H +#define PAINTERENGINE_RUNTIME_H + +#include "../kernel/PX_Kernel.h" + +#define PE_MEMORY_CALC_SIZE 1024*1024*2//2M + +typedef struct +{ + px_int window_width; + px_int window_height; + px_int surface_width; + px_int surface_height; + px_memorypool mp; + px_memorypool mp_ui; + px_memorypool mp_resources; + px_memorypool mp_game; + PX_ResourceLibrary ResourceLibrary; + px_surface RenderSurface; + + ////////////////////////////////////////////////////////////////////////// + PX_FontModule fontmodule; + PX_SoundPlay soundplay; + + +}PX_Runtime; + + +px_bool PX_RuntimeInitialize(PX_Runtime *pe,px_int surface_width,px_int surface_height,px_int window_width,px_int window_height,px_void *runtime_memoryPtr,px_uint size,px_uint ui_size,px_uint resource_size,px_uint game_size); +px_bool PX_RuntimeResize(PX_Runtime *pe,px_int surface_width,px_int surface_height,px_int window_width,px_int window_height); +px_void PX_RuntimeReset(PX_Runtime *pe); +px_memorypool PX_RuntimeCreateCalcMemoryPool(PX_Runtime *pe); +px_void PX_RuntimeFreeCalcMemoryPool(PX_Runtime *pe,px_memorypool mp); +px_surface *PX_RuntimeGetRenderSurface(PX_Runtime *pe); +px_void PX_RuntimeRenderClear(PX_Runtime *runtime,px_color color); +#endif diff --git a/lib/PainterEngine/core/PX_3D.c b/lib/PainterEngine/core/PX_3D.c new file mode 100644 index 0000000000000000000000000000000000000000..26abb99c711699e0993453180f21e4fc17930bc7 --- /dev/null +++ b/lib/PainterEngine/core/PX_3D.c @@ -0,0 +1,1265 @@ +#include "PX_3D.h" + +px_void PX_3D_RenderListTransform_LocalToGlobal(PX_3D_RenderList *list,PX_3D_World *world); +px_void PX_3D_RenderListTransform_Camera(PX_3D_RenderList *list,PX_3D_Camera *camera); +px_void PX_3D_RenderListCullRegion(PX_3D_RenderList *list,PX_3D_Camera *camera); +px_void PX_3D_RenderListCalculateNormal(PX_3D_RenderList *list); +px_void PX_3D_RenderListUpdateBackFace(PX_3D_RenderList *list,PX_3D_CULLMODE cullmode); +px_void PX_3D_RenderListTransform_Perspective(PX_3D_RenderList *list,PX_3D_Camera *camera); +px_void PX_3D_RenderListCullOutSide(PX_3D_RenderList *list,PX_3D_Camera *camera); +px_void PX_3D_RenderListTransform_Screen(PX_3D_RenderList *list,PX_3D_Camera *camera); +px_void PX_3D_CameraBuildEulerMatrix(PX_3D_Camera *camera,PX_3D_CAMERAROTMODE rotmode); +px_void PX_3D_CameraBuildUVNMatrix(PX_3D_Camera *camera); + + +px_void PX_3D_WorldInitialize(PX_3D_World *world,px_float x,px_float y,px_float z,px_float rotX,px_float rotY,px_float rotZ,px_float scale) +{ + px_matrix mrotx,mroty,mrotz,mscale,mtrans; + PX_MatrixIdentity(&world->mat); + PX_MatrixRotateX(&mrotx,rotX); + PX_MatrixRotateY(&mroty,rotY); + PX_MatrixRotateZ(&mrotz,rotZ); + PX_MatrixScale(&mscale,scale,scale,scale); + PX_MatrixTranslation(&mtrans,x,y,z); + + world->mat=PX_MatrixMultiply(world->mat,mscale); + world->mat=PX_MatrixMultiply(world->mat,mrotx); + world->mat=PX_MatrixMultiply(world->mat,mroty); + world->mat=PX_MatrixMultiply(world->mat,mrotz); + world->mat=PX_MatrixMultiply(world->mat,mtrans); + +} + +px_bool PX_3D_CameraEulerInitialize(px_memorypool *mp,PX_3D_Camera *camera,px_point4D cameraPosition,px_float rotX,px_float rotY,px_float rotZ,px_float near,px_float far,px_float fov,px_float viewPortWidth,px_float viewPortHeight) +{ + PX_memset(camera,0,sizeof(PX_3D_Camera)); + camera->mp=mp; + camera->type=PX_3D_CAMERA_TYPE_EULER; + camera->position=cameraPosition; + camera->rotDirection.x=rotX; + camera->rotDirection.y=rotY; + camera->rotDirection.z=rotZ; + + camera->near_z=near; + camera->far_z=far; + + camera->viewport_width=viewPortWidth; + camera->viewport_height=viewPortHeight; + + camera->viewport_center_x=(viewPortWidth-1)/2; + camera->viewport_center_y=(viewPortHeight-1)/2; + + camera->aspect_ratio=viewPortWidth/(px_float)viewPortHeight; + + PX_MatrixIdentity(&camera->mat_cam); + PX_MatrixIdentity(&camera->mat_per); + PX_MatrixIdentity(&camera->mat_scr); + + camera->fov=fov; + camera->viewplane_width=2.0f; + camera->viewplane_height=2.0f/camera->aspect_ratio; + + + if (fov==90) + { + camera->d=1; + } + else + { + camera->d=(0.5f)*(camera->viewplane_width)*PX_tan_angle(fov); + } + camera->zbuffer=(px_float *)MP_Malloc(mp,(px_int)(sizeof(px_float)*camera->viewport_height*camera->viewport_width)); + return camera->zbuffer!=PX_NULL; +} + +px_bool PX_3D_CameraUVNInitialize(px_memorypool *mp,PX_3D_Camera *camera,px_point4D cameraPosition,px_point4D cameraTarget,px_float near,px_float far,px_float fov,px_float viewPortWidth,px_float viewPortHeight) +{ + PX_memset(camera,0,sizeof(PX_3D_Camera)); + camera->type=PX_3D_CAMERA_TYPE_UVN; + camera->position=cameraPosition; + camera->targetDirection=cameraTarget; + camera->near_z=near; + camera->far_z=far; + camera->mp=mp; + camera->viewport_width=viewPortWidth; + camera->viewport_height=viewPortHeight; + + camera->viewport_center_x=(viewPortWidth-1)/2; + camera->viewport_center_y=(viewPortHeight-1)/2; + + camera->aspect_ratio=viewPortWidth/(px_float)viewPortHeight; + + PX_MatrixIdentity(&camera->mat_cam); + PX_MatrixIdentity(&camera->mat_per); + PX_MatrixIdentity(&camera->mat_scr); + + camera->fov=fov; + camera->viewplane_width=2.0f; + camera->viewplane_height=2.0f/camera->aspect_ratio; + + if (fov==90) + { + camera->d=1; + } + else + { + camera->d=(0.5f)*(camera->viewplane_width)*PX_tan_angle(fov); + } + camera->zbuffer=(px_float *)MP_Malloc(mp,(px_int)(sizeof(px_float)*camera->viewport_height*camera->viewport_width)); + return camera->zbuffer!=PX_NULL; +} + +px_void PX_3D_CameraSetPosition(PX_3D_Camera *camera,px_point4D cameraPosition,px_point4D cameraTarget) +{ + camera->position=cameraPosition; + camera->targetDirection=cameraTarget; +} + +px_void PX_3D_CameraBuildEulerMatrix(PX_3D_Camera *camera,PX_3D_CAMERAROTMODE rotmode) +{ + px_matrix mt_inv,mx_inv,my_inv,mz_inv,mrot,mtmp; + px_float theta_x=camera->rotDirection.x; + px_float theta_y=camera->rotDirection.y; + px_float theta_z=camera->rotDirection.z; + + PX_MatrixIdentity(&mt_inv); + mt_inv._41=-camera->position.x; + mt_inv._42=-camera->position.y; + mt_inv._43=-camera->position.z; + + + PX_MatrixRotateX(&mx_inv,-theta_x); + PX_MatrixRotateY(&my_inv,-theta_y); + PX_MatrixRotateZ(&mz_inv,-theta_z); + + + switch(rotmode) + { + case PX_3D_CAMERAROTMODE_XYZ: + { + mtmp=PX_MatrixMultiply(mx_inv,my_inv); + mrot=PX_MatrixMultiply(mtmp,mz_inv); + } + break; + case PX_3D_CAMERAROTMODE_YXZ: + { + mtmp=PX_MatrixMultiply(my_inv,mx_inv); + mrot=PX_MatrixMultiply(mtmp,mz_inv); + } + break; + case PX_3D_CAMERAROTMODE_XZY: + { + mtmp=PX_MatrixMultiply(mx_inv,mz_inv); + mrot=PX_MatrixMultiply(mtmp,my_inv); + } + break; + case PX_3D_CAMERAROTMODE_YZX: + { + mtmp=PX_MatrixMultiply(my_inv,mz_inv); + mrot=PX_MatrixMultiply(mtmp,mx_inv); + } + break; + case PX_3D_CAMERAROTMODE_ZYX: + { + mtmp=PX_MatrixMultiply(mz_inv,my_inv); + mrot=PX_MatrixMultiply(mtmp,mx_inv); + } + break; + case PX_3D_CAMERAROTMODE_ZXY: + { + mtmp=PX_MatrixMultiply(mz_inv,mx_inv); + mrot=PX_MatrixMultiply(mtmp,my_inv); + } + break; + default: + { + PX_MatrixIdentity(&mrot); + } + break; + } + camera->mat_cam=PX_MatrixMultiply(mt_inv,mrot); +} + +px_void PX_3D_CameraBuildUVNMatrix(PX_3D_Camera *camera) +{ + px_matrix mt_inv; + px_matrix mt_uvn; + px_point4D u,v,n; + + PX_MatrixIdentity(&mt_inv); + mt_inv._41=-camera->position.x; + mt_inv._42=-camera->position.y; + mt_inv._43=-camera->position.z; + + n.x=camera->targetDirection.x-camera->position.x; + n.y=camera->targetDirection.y-camera->position.y; + n.z=camera->targetDirection.z-camera->position.z; + n.w=1; + + n=PX_Point4DUnit(n); + v=PX_POINT4D(0,1,0); + u=PX_Point4DCross(v,n); + + PX_MatrixZero(&mt_uvn); + mt_uvn._11=u.x; + mt_uvn._12=v.x; + mt_uvn._13=n.x; + + mt_uvn._21=u.y; + mt_uvn._22=v.y; + mt_uvn._23=n.y; + + mt_uvn._31=u.z; + mt_uvn._32=v.z; + mt_uvn._33=n.z; + + mt_uvn._44=1; + camera->mat_cam=PX_MatrixMultiply(mt_inv,mt_uvn); +} + +px_void PX_3D_RenderListUpdateBackFace(PX_3D_RenderList *list,PX_3D_CULLMODE cullmode) +{ + px_int i,j; + PX_3D_Face *pface=PX_NULL; + px_float dot; + px_bool bBackFace; + px_vector4D v1,v2; + for (i=0;ifacestream.size;i++) + { + bBackFace=PX_TRUE; + pface=PX_VECTORAT(PX_3D_Face,&list->facestream,i); + v1=pface->transform_vertex[0].normal; + for (j=0;j<3;j++) + { + v2=pface->transform_vertex[j].position; + dot=PX_Point4DDot(v1,v2); + if (cullmode==PX_3D_CULLMODE_NONE) + { + bBackFace=PX_FALSE; + } + else + { + if (dot>0) + { + if (cullmode!=PX_3D_CULLMODE_CCW) + { + bBackFace=PX_FALSE; + break; + } + } + else + { + if (cullmode!=PX_3D_CULLMODE_CW) + { + bBackFace=PX_FALSE; + break; + } + } + } + } + if (bBackFace) + { + pface->state|=PX_3D_FACESTATE_BACKFACE; + } + else + { + pface->state&=~PX_3D_FACESTATE_BACKFACE; + } + } +} + +px_void PX_3D_RenderListCalculateNormal(PX_3D_RenderList *list) +{ + px_int i; + PX_3D_Face *pface=PX_NULL; + px_vector4D v1,v2; + for (i=0;ifacestream.size;i++) + { + pface=PX_VECTORAT(PX_3D_Face,&list->facestream,i); + v1=PX_Point4DSub(pface->transform_vertex[1].position,pface->transform_vertex[0].position); + v2=PX_Point4DSub(pface->transform_vertex[2].position,pface->transform_vertex[1].position); + pface->transform_vertex[0].normal=PX_Point4DUnit(PX_Point4DCross(v1,v2)); + pface->transform_vertex[1].normal=pface->transform_vertex[0].normal; + pface->transform_vertex[2].normal=pface->transform_vertex[0].normal; + } +} + +px_void PX_3D_RenderListTransform_Screen(PX_3D_RenderList *list,PX_3D_Camera *camera) +{ + px_int i; + PX_3D_Face *pface=PX_NULL; + px_float alpha=(0.5f*camera->viewport_width-0.5f); + px_float beta=(0.5f*camera->viewport_height-0.5f); + + for (i=0;ifacestream.size;i++) + { + pface=PX_VECTORAT(PX_3D_Face,&list->facestream,i); + + pface->transform_vertex[0].position.x=alpha+alpha*pface->transform_vertex[0].position.x; + pface->transform_vertex[0].position.y=beta+beta*pface->transform_vertex[0].position.y; + + pface->transform_vertex[1].position.x=alpha+alpha*pface->transform_vertex[1].position.x; + pface->transform_vertex[1].position.y=beta+beta*pface->transform_vertex[1].position.y; + + pface->transform_vertex[2].position.x=alpha+alpha*pface->transform_vertex[2].position.x; + pface->transform_vertex[2].position.y=beta+beta*pface->transform_vertex[2].position.y; + + //inv y + pface->transform_vertex[0].position.y=-pface->transform_vertex[0].position.y+camera->viewport_height; + pface->transform_vertex[1].position.y=-pface->transform_vertex[1].position.y+camera->viewport_height; + pface->transform_vertex[2].position.y=-pface->transform_vertex[2].position.y+camera->viewport_height; + } +} + + + +px_void PX_3D_RenderListPixelShader(px_surface *psurface,px_int x,px_int y,px_float z,px_float u,px_float v,px_point4D normal,px_texture *pTexture,px_color color/*px_float *zbuffer,px_int zw*/) +{ + //texture mapping + px_double SampleX,SampleY,mapX,mapY; + px_double mixa,mixr,mixg,mixb,Weight; + px_color sampleColor; + px_int resWidth; + px_int resHeight; + + + + if (pTexture) + { + resWidth=pTexture->width; + resHeight=pTexture->height; + u=PX_ABS(u); + v=PX_ABS(v); + u-=(px_int)u; + v-=(px_int)v; + + mapX=u*resWidth; + mapY=v*resHeight; + + if (mapX<-0.5||mapX>resWidth+0.5) + { + return; + } + if (mapY<-0.5||mapY>resHeight+0.5) + { + return; + } + mixa=0; + mixr=0; + mixg=0; + mixb=0; + //Sample 4 points + //lt + + SampleX=(mapX-0.5f); + SampleY=(mapY-0.5f); + + if (SampleX>0&&(SampleX)0&&(SampleY)0&&(SampleX)0&&(SampleY)0&&(SampleX)0&&(SampleY)0&&(SampleX)0&&(SampleY)255?mixa=255:0; + mixr>255?mixr=255:0; + mixg>255?mixg=255:0; + mixb>255?mixb=255:0; + + PX_SurfaceDrawPixel(psurface,x,y,PX_COLOR((px_uchar)mixa,(px_uchar)mixr,(px_uchar)mixg,(px_uchar)mixb)); + + } + + if (color._argb.ucolor!=0) + { + PX_SurfaceDrawPixel(psurface,x,y,color); + + } +} + + +static px_void PX_3D_RenderListRasterization(px_surface *psurface,PX_3D_RenderList *pList,PX_3D_Vertex p0,PX_3D_Vertex p1,PX_3D_Vertex p2,px_texture *ptexture,px_color color,px_int view_width,px_int view_height,px_float zbuffer[],px_int zw) +{ + px_int ix,iy; + px_bool k01infinite=PX_FALSE; + px_bool k02infinite=PX_FALSE; + px_bool k12infinite=PX_FALSE; + px_float k01,b01,k02,b02,k12,b12; + px_float x0; + px_float y0; + px_float z0; + px_float s0; + px_float t0; + + px_float x1; + px_float y1; + px_float z1; + px_float s1; + px_float t1; + + px_float x2; + px_float y2; + px_float z2; + px_float s2; + px_float t2; + + + px_float y, xleft, xright; + px_float oneoverz_left, oneoverz_right; + px_float oneoverz_top, oneoverz_bottom; + px_float oneoverz, oneoverz_step; + px_float soverz_top, soverz_bottom; + px_float toverz_top, toverz_bottom; + px_float soverz_left, soverz_right; + px_float toverz_left, toverz_right; + px_float soverz, soverz_step; + px_float toverz, toverz_step; + px_float s, t; + px_float btmy,midy; + px_float originalZ; + + px_float a,b,c; + px_point position; + a=(px_float)PX_sqrtd((p1.position.x-p2.position.x)*(p1.position.x-p2.position.x)); + b=(px_float)PX_sqrtd((p0.position.x-p2.position.x)*(p0.position.x-p2.position.x)); + c=(px_float)PX_sqrtd((p1.position.x-p0.position.x)*(p1.position.x-p0.position.x)); + + position.x=(a*p0.position.x+b*p1.position.x+c*p2.position.x)/(a+b+c); + position.y=(a*p0.position.y+b*p1.position.y+c*p2.position.y)/(a+b+c); + + // p0 + // p1 p2 + + if (p1.position.ybtmy) + { + midy=p1.position.y; + btmy=p2.position.y; + } + + + + do + { + px_float x01m; + + x0=p0.position.x; + y0=p0.position.y; + x1=p1.position.x; + y1=p1.position.y; + x2=p2.position.x; + y2=p2.position.y; + + + if (x0==x1) + { + x01m=x0; + } + else + { + k01=(y0-y1)/(x0-x1); + b01=y0-k01*x0; + x01m=(y2-b01)/k01; + } + + if (x01m>x2) + { + PX_3D_Vertex t; + t=p2; + p2=p1; + p1=t; + } + } while (0); + + + + x0=p0.position.x; + y0=p0.position.y; + z0=p0.position.z; + s0=p0.u; + t0=p0.v; + + x1=p1.position.x; + y1=p1.position.y; + z1=p1.position.z; + s1=p1.u; + t1=p1.v; + + x2=p2.position.x; + y2=p2.position.y; + z2=p2.position.z; + s2=p2.u; + t2=p2.v; + + k01infinite=PX_FALSE; + k02infinite=PX_FALSE; + k12infinite=PX_FALSE; + if (x0==x1) + { + k01infinite=PX_TRUE; + k01 = 1; + b01=x0; + } + else + { + k01=(y0-y1)/(x0-x1); + b01=y0-k01*x0; + } + + if (x0==x2) + { + k02infinite=PX_TRUE; + k02 = 1; + b02=x0; + } + else + { + k02=(y0-y2)/(x0-x2); + b02=y0-k02*x0; + } + + if (x1==x2) + { + k12infinite=PX_TRUE; + b12=x0; + } + else + { + k12=(y1-y2)/(x1-x2); + b12=y1-k12*x1; + } + + + for(y = (px_int)(y0+0.5f)+0.5f; y <=midy; y++) + { + if (k01infinite==PX_TRUE) + { + xleft=b01; + } + else + { + xleft = (y-b01)/k01; + } + + if (k02infinite==PX_TRUE) + { + xright=b02; + } + else + { + xright = (y-b02)/k02; + } + + + oneoverz_top = 1.0f / z0; + oneoverz_bottom = 1.0f/z1; + oneoverz_left = (y-y0) * (oneoverz_bottom-oneoverz_top) / (y1-y0) + oneoverz_top; + oneoverz_bottom = 1.0f / z2; + oneoverz_right = (y-y0) * (oneoverz_bottom-oneoverz_top) / (y2-y0) + oneoverz_top; + oneoverz_step = (oneoverz_right-oneoverz_left) / (xright-xleft); + soverz_top = s0 / z0; + soverz_bottom = s1 / z1; + soverz_left = (y-y0) * (soverz_bottom-soverz_top) / (y1-y0) + soverz_top; + soverz_bottom = s2 / z2; + soverz_right = (y-y0) * (soverz_bottom-soverz_top) / (y2-y0) + soverz_top; + soverz_step = (soverz_right-soverz_left) / (xright-xleft); + toverz_top = t0 / z0; + toverz_bottom = t1 / z1; + toverz_left = (y-y0) * (toverz_bottom-toverz_top) / (y1-y0) + toverz_top; + toverz_bottom = t2 / z2; + toverz_right = (y-y0) * (toverz_bottom-toverz_top) / (y2-y0) + toverz_top; + toverz_step = (toverz_right-toverz_left) / (xright-xleft); + oneoverz = oneoverz_left,soverz = soverz_left, toverz = toverz_left; + + for(ix = (px_int)(xleft+0.5);ix < (px_int)(xright+0.5f); ++ix) + { + s = soverz / oneoverz; + t = toverz / oneoverz; + originalZ=1.0f/oneoverz; + + iy=(px_int)y; + + if (ix>0&&ix=0&&iypixelShader) + { + position.z=originalZ; + pList->pixelShader(psurface,ix,iy,position,s,t,p0.normal,ptexture,color/*,zbuffer,zw*/); + } + else + { + PX_3D_RenderListPixelShader(psurface,ix,iy,originalZ,s,t,p0.normal,ptexture,color/*,zbuffer,zw*/); + } + } + + oneoverz += oneoverz_step; + soverz += soverz_step; + toverz += toverz_step; + } + } + + // p1 p2 + // p0 + if (p1.position.y>p0.position.y) + { + PX_3D_Vertex vt; + vt=p1; + p1=p0; + p0=vt; + } + + if (p2.position.y>p0.position.y) + { + PX_3D_Vertex vt; + vt=p2; + p2=p0; + p0=vt; + } + + btmy=p1.position.y; + midy=p2.position.y; + if (p2.position.yx2) + { + PX_3D_Vertex t; + t=p2; + p2=p1; + p1=t; + } + } while (0); + + + + x0=p0.position.x; + y0=p0.position.y; + z0=p0.position.z; + s0=p0.u; + t0=p0.v; + + x1=p1.position.x; + y1=p1.position.y; + z1=p1.position.z; + s1=p1.u; + t1=p1.v; + + x2=p2.position.x; + y2=p2.position.y; + z2=p2.position.z; + s2=p2.u; + t2=p2.v; + + k01infinite=PX_FALSE; + k02infinite=PX_FALSE; + k12infinite=PX_FALSE; + if (x0==x1) + { + k01infinite=PX_TRUE; + b01=x0; + } + else + { + k01=(y0-y1)/(x0-x1); + b01=y0-k01*x0; + } + + if (x0==x2) + { + k02infinite=PX_TRUE; + b02=x0; + } + else + { + k02=(y0-y2)/(x0-x2); + b02=y0-k02*x0; + } + + if (x1==x2) + { + k12infinite=PX_TRUE; + b12=x0; + } + else + { + k12=(y1-y2)/(x1-x2); + b12=y1-k12*x1; + } + + + for(y = (px_int)(midy+0.5f)+0.5f; y < y0; y++) + { + if (k01infinite) + { + xleft=b01; + } + else + { + xleft = (y-b01)/k01; + } + + if (k02infinite) + { + xright=b02; + } + else + { + xright = (y-b02)/k02; + } + + + oneoverz_top = 1.0f / z0; + oneoverz_bottom = 1.0f/z1; + oneoverz_left = (y-y0) * (oneoverz_bottom-oneoverz_top) / (y1-y0) + oneoverz_top; + oneoverz_bottom = 1.0f / z2; + oneoverz_right = (y-y0) * (oneoverz_bottom-oneoverz_top) / (y2-y0) + oneoverz_top; + oneoverz_step = (oneoverz_right-oneoverz_left) / (xright-xleft); + soverz_top = s0 / z0; + soverz_bottom = s1 / z1; + soverz_left = (y-y0) * (soverz_bottom-soverz_top) / (y1-y0) + soverz_top; + soverz_bottom = s2 / z2; + soverz_right = (y-y0) * (soverz_bottom-soverz_top) / (y2-y0) + soverz_top; + soverz_step = (soverz_right-soverz_left) / (xright-xleft); + toverz_top = t0 / z0; + toverz_bottom = t1 / z1; + toverz_left = (y-y0) * (toverz_bottom-toverz_top) / (y1-y0) + toverz_top; + toverz_bottom = t2 / z2; + toverz_right = (y-y0) * (toverz_bottom-toverz_top) / (y2-y0) + toverz_top; + toverz_step = (toverz_right-toverz_left) / (xright-xleft); + oneoverz = oneoverz_left,soverz = soverz_left, toverz = toverz_left; + + for(ix = (px_int)(xleft+0.5);ix < (px_int)(xright+0.5f); ++ix) + { + s = soverz / oneoverz; + t = toverz / oneoverz; + originalZ=1.0f/oneoverz; + + iy=(px_int)y; + + if (ix>0&&ix=0&&iypixelShader) + { + position.z=originalZ; + pList->pixelShader(psurface,ix,iy,position,s,t,p0.normal,ptexture,color/*,zbuffer,zw*/); + } + else + { + PX_3D_RenderListPixelShader(psurface,ix,iy,originalZ,s,t,p0.normal,ptexture,color/*,zbuffer,zw*/); + } + } + oneoverz += oneoverz_step; + soverz += soverz_step; + toverz += toverz_step; + } + } + +} + + +px_void PX_3D_Scene(PX_3D_RenderList *list,PX_3D_World *world,PX_3D_Camera *camera) +{ + PX_3D_CULLMODE cullmode; + PX_memset(camera->zbuffer,0,(px_int)(sizeof(px_float)*camera->viewport_height*camera->viewport_width)); + cullmode=list->cullmode; + PX_3D_RenderListTransform_LocalToGlobal(list,world); + switch (camera->type) + { + case PX_3D_CAMERA_TYPE_EULER: + PX_3D_CameraBuildEulerMatrix(camera,PX_3D_CAMERAROTMODE_XYZ); + break; + case PX_3D_CAMERA_TYPE_UVN: + PX_3D_CameraBuildUVNMatrix(camera); + break; + } + PX_3D_RenderListTransform_Camera(list,camera); + PX_3D_RenderListCullRegion(list,camera); + PX_3D_RenderListCalculateNormal(list); + PX_3D_RenderListUpdateBackFace(list,cullmode); + PX_3D_RenderListTransform_Perspective(list,camera); + PX_3D_RenderListCullOutSide(list,camera); + PX_3D_RenderListTransform_Screen(list,camera); +} + +px_void PX_3D_Present(px_surface *psurface, PX_3D_RenderList *list,PX_3D_Camera *camera) +{ + px_int i; + PX_3D_Face *pface=PX_NULL; + px_texture *ptex; + px_color clr; + + + if (list->PX_3D_PRESENTMODE&PX_3D_PRESENTMODE_PURE) + { + if (list->facestream.size) + { + pface=PX_VECTORAT(PX_3D_Face,&list->facestream,0); + clr=pface->transform_vertex[0].clr; + } + else + { + clr._argb.ucolor=0; + } + } + else + { + clr._argb.ucolor=0; + } + + if (list->PX_3D_PRESENTMODE&PX_3D_PRESENTMODE_TEXTURE) + { + ptex=list->ptexture; + } + else + { + ptex=PX_NULL; + } + + if (ptex||clr._argb.ucolor) + { + for (i=0;ifacestream.size;i++) + { + pface=PX_VECTORAT(PX_3D_Face,&list->facestream,i); + if (!(pface->state&PX_3D_FACESTATE_BACKFACE||pface->state&PX_3D_FACESTATE_CLIPPED)) + { + if (list->PX_3D_PRESENTMODE&PX_3D_PRESENTMODE_PURE) + { + PX_3D_RenderListRasterization(psurface,list,pface->transform_vertex[0],pface->transform_vertex[1],pface->transform_vertex[2],list->ptexture,clr,(px_int)camera->viewport_width,(px_int)camera->viewport_height,camera->zbuffer,(px_int)camera->viewport_width); + } + else + { + PX_3D_RenderListRasterization(psurface,list,pface->transform_vertex[0],pface->transform_vertex[1],pface->transform_vertex[2],ptex,PX_COLOR(0,0,0,0),(px_int)camera->viewport_width,(px_int)camera->viewport_height,camera->zbuffer,(px_int)camera->viewport_width); + } + + } + + } + } + + if (list->PX_3D_PRESENTMODE&PX_3D_PRESENTMODE_POINT) + { + for (i=0;ifacestream.size;i++) + { + pface=PX_VECTORAT(PX_3D_Face,&list->facestream,i); + PX_GeoDrawSolidCircle(psurface,(px_int)pface->transform_vertex[0].position.x,(px_int)pface->transform_vertex[0].position.y,2,pface->transform_vertex[0].clr); + PX_GeoDrawSolidCircle(psurface,(px_int)pface->transform_vertex[1].position.x,(px_int)pface->transform_vertex[1].position.y,2,pface->transform_vertex[1].clr); + PX_GeoDrawSolidCircle(psurface,(px_int)pface->transform_vertex[2].position.x,(px_int)pface->transform_vertex[2].position.y,2,pface->transform_vertex[2].clr); + + } + } + + if (list->PX_3D_PRESENTMODE&PX_3D_PRESENTMODE_LINE) + { + for (i=0;ifacestream.size;i++) + { + pface=PX_VECTORAT(PX_3D_Face,&list->facestream,i); + if (!(pface->state&PX_3D_FACESTATE_BACKFACE||pface->state&PX_3D_FACESTATE_CLIPPED)) + { + PX_GeoDrawLine(psurface,(px_int)pface->transform_vertex[0].position.x,(px_int)pface->transform_vertex[0].position.y,(px_int)pface->transform_vertex[1].position.x,(px_int)pface->transform_vertex[1].position.y,1,pface->transform_vertex[0].clr); + PX_GeoDrawLine(psurface,(px_int)pface->transform_vertex[1].position.x,(px_int)pface->transform_vertex[1].position.y,(px_int)pface->transform_vertex[2].position.x,(px_int)pface->transform_vertex[2].position.y,1,pface->transform_vertex[1].clr); + PX_GeoDrawLine(psurface,(px_int)pface->transform_vertex[2].position.x,(px_int)pface->transform_vertex[2].position.y,(px_int)pface->transform_vertex[0].position.x,(px_int)pface->transform_vertex[0].position.y,1,pface->transform_vertex[2].clr); + } + + } + } + + +} + +px_void PX_3D_RenderListSetPixelShader(PX_3D_RenderList *list,PX_3D_PixelShader func) +{ + list->pixelShader=func; +} + +px_void PX_3D_RenderListTransform_Perspective(PX_3D_RenderList *list,PX_3D_Camera *camera) +{ + px_int i; + PX_3D_Face *pface=PX_NULL; + for (i=0;ifacestream.size;i++) + { + px_float z; + pface=PX_VECTORAT(PX_3D_Face,&list->facestream,i); + z=pface->transform_vertex[0].position.z; + pface->transform_vertex[0].position.x=camera->d*pface->transform_vertex[0].position.x/z; + pface->transform_vertex[0].position.y=camera->d*pface->transform_vertex[0].position.y/z; + + z=pface->transform_vertex[1].position.z; + pface->transform_vertex[1].position.x=camera->d*pface->transform_vertex[1].position.x/z; + pface->transform_vertex[1].position.y=camera->d*pface->transform_vertex[1].position.y/z; + + z=pface->transform_vertex[2].position.z; + pface->transform_vertex[2].position.x=camera->d*pface->transform_vertex[2].position.x/z; + pface->transform_vertex[2].position.y=camera->d*pface->transform_vertex[2].position.y/z; + + } +} + +px_void PX_3D_RenderListCullOutSide(PX_3D_RenderList *list,PX_3D_Camera *camera) +{ + px_int i; + PX_3D_Face *pface=PX_NULL; + px_bool outside; + for (i=0;ifacestream.size;i++) + { + pface=PX_VECTORAT(PX_3D_Face,&list->facestream,i); + outside=PX_FALSE; + + if (pface->transform_vertex[0].position.y>camera->viewplane_height/2&&\ + pface->transform_vertex[1].position.y>camera->viewplane_height/2&&\ + pface->transform_vertex[2].position.y>camera->viewplane_height/2) + { + //up + outside=PX_TRUE; + } + else\ + if (pface->transform_vertex[0].position.y<-camera->viewplane_height/2&&\ + pface->transform_vertex[1].position.y<-camera->viewplane_height/2&&\ + pface->transform_vertex[2].position.y<-camera->viewplane_height/2) + { + //down + outside=PX_TRUE; + } + else \ + if (pface->transform_vertex[0].position.x<-camera->viewplane_width/2&&\ + pface->transform_vertex[1].position.x<-camera->viewplane_width/2&&\ + pface->transform_vertex[2].position.x<-camera->viewplane_width/2) + { + //left + outside=PX_TRUE; + } + else \ + if (pface->transform_vertex[0].position.x>camera->viewplane_width/2&&\ + pface->transform_vertex[1].position.x>camera->viewplane_width/2&&\ + pface->transform_vertex[2].position.x>camera->viewplane_width/2) + { + //right + outside=PX_TRUE; + } + + + if (outside) + { + pface->state|=PX_3D_FACESTATE_CLIPPED; + } + else + { + pface->state&=~PX_3D_FACESTATE_CLIPPED; + } + } +} + +px_void PX_3D_RenderListTransform_Camera(PX_3D_RenderList *list,PX_3D_Camera *camera) +{ + PX_3D_RenderListTransform(list,camera->mat_cam,PX_3D_RENDERLIST_TRANSFORM_GLOBAL_TO_GLOBAL); +} + +px_void PX_3D_RenderListCullRegion(PX_3D_RenderList *list,PX_3D_Camera *camera) +{ + px_int i,j; + PX_3D_Face *pface=PX_NULL; + px_bool outside; + for (i=0;ifacestream.size;i++) + { + pface=PX_VECTORAT(PX_3D_Face,&list->facestream,i); + outside=PX_FALSE; + for (j=0;j<3;j++) + { + //behind + if (pface->transform_vertex[j].position.z<=camera->near_z) + { + outside=PX_TRUE; + break; + } + } + if (pface->transform_vertex[0].position.z>camera->far_z&&\ + pface->transform_vertex[1].position.z>camera->far_z&&\ + pface->transform_vertex[2].position.z>camera->far_z) + { + outside=PX_TRUE; + } + if (outside) + { + pface->state|=PX_3D_FACESTATE_CLIPPED; + } + else + { + pface->state&=~PX_3D_FACESTATE_CLIPPED; + } + } +} + +px_void PX_3D_RenderListTransform(PX_3D_RenderList *list,px_matrix mat,PX_3D_RENDERLIST_TRANSFORM t) +{ + switch (t) + { + case PX_3D_RENDERLIST_TRANSFORM_LOCAL_TO_LOCAL: + { + px_int i; + PX_3D_Face *pface=PX_NULL; + for (i=0;ifacestream.size;i++) + { + pface=PX_VECTORAT(PX_3D_Face,&list->facestream,i); + pface->vertex[0].position=PX_Point4DMulMatrix(pface->vertex[0].position,mat); + pface->vertex[1].position=PX_Point4DMulMatrix(pface->vertex[1].position,mat); + pface->vertex[2].position=PX_Point4DMulMatrix(pface->vertex[2].position,mat); + } + } + break; + case PX_3D_RENDERLIST_TRANSFORM_LOACL_TO_GLOBAL: + { + px_int i; + PX_3D_Face *pface=PX_NULL; + + for (i=0;ifacestream.size;i++) + { + pface=PX_VECTORAT(PX_3D_Face,&list->facestream,i); + pface->transform_vertex[0]=pface->vertex[0]; + pface->transform_vertex[1]=pface->vertex[1]; + pface->transform_vertex[2]=pface->vertex[2]; + pface->transform_vertex[0].position=PX_Point4DMulMatrix(pface->vertex[0].position,mat); + pface->transform_vertex[1].position=PX_Point4DMulMatrix(pface->vertex[1].position,mat); + pface->transform_vertex[2].position=PX_Point4DMulMatrix(pface->vertex[2].position,mat); + } + } + break; + case PX_3D_RENDERLIST_TRANSFORM_GLOBAL_TO_GLOBAL: + { + px_int i; + PX_3D_Face *pface=PX_NULL; + + for (i=0;ifacestream.size;i++) + { + pface=PX_VECTORAT(PX_3D_Face,&list->facestream,i); + pface->transform_vertex[0].position=PX_Point4DMulMatrix(pface->transform_vertex[0].position,mat); + pface->transform_vertex[1].position=PX_Point4DMulMatrix(pface->transform_vertex[1].position,mat); + pface->transform_vertex[2].position=PX_Point4DMulMatrix(pface->transform_vertex[2].position,mat); + } + } + break; + } +} + + + +px_void PX_3D_RenderListReset(PX_3D_RenderList *list) +{ + PX_VectorClear(&list->facestream); +} + +px_void PX_3D_RenderListFree(PX_3D_RenderList *list) +{ + PX_VectorFree(&list->facestream); +} + +px_bool PX_3D_RenderListInitialize(px_memorypool *mp,PX_3D_RenderList *list,px_dword PX_3D_PRESENTMODE,PX_3D_CULLMODE cullmode,px_texture *ptexture) +{ + list->mp=mp; + list->ptexture=ptexture; + list->PX_3D_PRESENTMODE=PX_3D_PRESENTMODE; + list->cullmode=cullmode; + list->pixelShader=PX_NULL; + if(!PX_VectorInitialize(mp,&list->facestream,sizeof(PX_3D_Face),64)) + { + return PX_FALSE; + } + return PX_TRUE; + +} + +px_void PX_3D_CameraFree(PX_3D_Camera *camera) +{ + MP_Free(camera->mp,camera->zbuffer); +} + +px_bool PX_3D_RenderListPush(PX_3D_RenderList *list,PX_3D_Face face) +{ + if(!PX_VectorPushback(&list->facestream,&face))return PX_FALSE; + return PX_TRUE; +} + +px_void PX_3D_RenderListTransform_LocalToGlobal(PX_3D_RenderList *list,PX_3D_World *world) +{ + PX_3D_RenderListTransform(list,world->mat,PX_3D_RENDERLIST_TRANSFORM_LOACL_TO_GLOBAL); +} + +px_point *PX_3D_CreateTextureNormal(px_memorypool *mp,px_texture *pTexture) +{ + px_int i,j; + px_point *pmatrix=(px_point *)MP_Malloc(mp,sizeof(px_point)*pTexture->width*pTexture->height); + px_float *gradient_x=(px_float *)MP_Malloc(mp,sizeof(px_float)*pTexture->width*pTexture->height); + px_float *gradient_y=(px_float *)MP_Malloc(mp,sizeof(px_float)*pTexture->width*pTexture->height); + + PX_ImageFilter_SobelX(pTexture,gradient_x); + PX_ImageFilter_SobelY(pTexture,gradient_y); + + for(j=0;jheight;j++) + { + for (i=0;iwidth;i++) + { + pmatrix[j*pTexture->width+i].x=(px_float)(-gradient_x[j*pTexture->width+i]/PX_sqrtd(gradient_x[j*pTexture->width+i]*gradient_x[j*pTexture->width+i]+gradient_y[j*pTexture->width+i]*gradient_y[j*pTexture->width+i]+1)); + pmatrix[j*pTexture->width+i].y=(px_float)(-gradient_y[j*pTexture->width+i]/PX_sqrtd(gradient_x[j*pTexture->width+i]*gradient_x[j*pTexture->width+i]+gradient_y[j*pTexture->width+i]*gradient_y[j*pTexture->width+i]+1)); + pmatrix[j*pTexture->width+i].z=(px_float)(1/PX_sqrtd(gradient_x[j*pTexture->width+i]*gradient_x[j*pTexture->width+i]+gradient_y[j*pTexture->width+i]*gradient_y[j*pTexture->width+i]+1)); + } + } + MP_Free(mp,gradient_x); + MP_Free(mp,gradient_y); + return pmatrix; +} + + +px_point *PX_3D_CreateBumpTextureNormal(px_memorypool *mp,px_texture *pTexture) +{ + px_int i,j; + px_point *pmatrix=(px_point *)MP_Malloc(mp,sizeof(px_point)*pTexture->width*pTexture->height); + px_float *gradient_x=(px_float *)MP_Malloc(mp,sizeof(px_float)*pTexture->width*pTexture->height); + px_float *gradient_y=(px_float *)MP_Malloc(mp,sizeof(px_float)*pTexture->width*pTexture->height); + + PX_ImageFilter_SobelX(pTexture,gradient_x); + PX_ImageFilter_SobelY(pTexture,gradient_y); + + for(j=0;jheight;j++) + { + for (i=0;iwidth;i++) + { + px_point v; + if (gradient_x[j*pTexture->width+i]==0&&gradient_y[j*pTexture->width+i]==0) + { + + v=PX_POINT(0,0,-1); + + } + else + { + px_float rad,scale; + px_color clr; + + clr=pTexture->surfaceBuffer[j*pTexture->width+i]; + v.x=-gradient_x[j*pTexture->width+i]; + v.y=-gradient_y[j*pTexture->width+i]; + v=PX_PointNormalization(v); + + rad=(clr._argb.r+clr._argb.g+clr._argb.b)/3/255.0f; + v.z=-(px_float)PX_sind(rad*PX_PI/2); + scale=(px_float)PX_cosd(rad*PX_PI/2); + v.x*=scale; + v.y*=scale; + } + + + pmatrix[j*pTexture->width+i]=v; +// px_point v1,v2; +// v1.z=0; +// v1.x=(px_float)PX_cosd(gradient_x[j*pTexture->width+i]*PX_PI/2); +// v1.y=(px_float)PX_sind(gradient_x[j*pTexture->width+i]*PX_PI/2); +// +// v2.z=-(px_float)PX_sind(gradient_y[j*pTexture->width+i]*PX_PI/2); +// v2.x=0; +// v2.y=-(px_float)PX_cosd(gradient_y[j*pTexture->width+i]*PX_PI/2); +// +// pmatrix[j*pTexture->width+i]=PX_PointUnit(PX_PointCross(v1,v2)); + } + } + MP_Free(mp,gradient_x); + MP_Free(mp,gradient_y); + return pmatrix; +} diff --git a/lib/PainterEngine/core/PX_3D.h b/lib/PainterEngine/core/PX_3D.h new file mode 100644 index 0000000000000000000000000000000000000000..3acca5ecd225a06a470c81070173bc6c1983c1ba --- /dev/null +++ b/lib/PainterEngine/core/PX_3D.h @@ -0,0 +1,127 @@ +#ifndef PX_3D_H +#define PX_3D_H + + +#include "PX_BaseGeo.h" +#include "PX_Vector.h" +#include "PX_Texture.h" +#include "PX_ImageFilter.h" + +#define PX_3D_FACESTATE_ACTIVE 1 +#define PX_3D_FACESTATE_CLIPPED 2 +#define PX_3D_FACESTATE_BACKFACE 4 + +typedef enum +{ + PX_3D_RENDERLIST_TRANSFORM_LOCAL_TO_LOCAL, + PX_3D_RENDERLIST_TRANSFORM_LOACL_TO_GLOBAL, + PX_3D_RENDERLIST_TRANSFORM_GLOBAL_TO_GLOBAL, +}PX_3D_RENDERLIST_TRANSFORM; + +typedef enum +{ + PX_3D_CAMERAROTMODE_XYZ, + PX_3D_CAMERAROTMODE_YXZ, + PX_3D_CAMERAROTMODE_XZY, + PX_3D_CAMERAROTMODE_YZX, + PX_3D_CAMERAROTMODE_ZYX, + PX_3D_CAMERAROTMODE_ZXY, +}PX_3D_CAMERAROTMODE; + +typedef enum +{ + PX_3D_CULLMODE_NONE, + PX_3D_CULLMODE_CW, + PX_3D_CULLMODE_CCW, +}PX_3D_CULLMODE; + +#define PX_3D_PRESENTMODE_POINT 1 +#define PX_3D_PRESENTMODE_LINE 2 +#define PX_3D_PRESENTMODE_TEXTURE 4 +#define PX_3D_PRESENTMODE_PURE 8 + +typedef px_void (*PX_3D_PixelShader)(px_surface *psurface,px_int x,px_int y,px_point position,px_float u,px_float v,px_point4D normal,px_texture *pTexture,px_color color); + + + +typedef struct +{ + px_point4D position; + px_vector4D normal; + px_color clr; + px_float u,v; +}PX_3D_Vertex; + +typedef struct +{ + px_dword state; + PX_3D_Vertex vertex[3]; + PX_3D_Vertex transform_vertex[3]; +}PX_3D_Face; + +typedef struct +{ + px_memorypool *mp; + px_texture *ptexture; + px_vector facestream; + px_dword PX_3D_PRESENTMODE; + PX_3D_CULLMODE cullmode; + PX_3D_PixelShader pixelShader; +}PX_3D_RenderList; + +typedef struct +{ + px_matrix mat; +}PX_3D_World; + +typedef enum +{ + PX_3D_CAMERA_TYPE_EULER, + PX_3D_CAMERA_TYPE_UVN, +}PX_3D_CAMERA_TYPE; + +typedef struct +{ + PX_3D_CAMERA_TYPE type; + px_memorypool *mp; + px_float near_z,far_z; + + px_float fov; + px_float d; + + px_point4D position; + union + { + px_point4D targetDirection; + px_point4D rotDirection; + }; + px_float viewplane_width,viewplane_height; + px_float viewport_width,viewport_height,viewport_center_x,viewport_center_y; + px_float aspect_ratio; + + px_matrix mat_cam,mat_per,mat_scr; + + px_float *zbuffer; +}PX_3D_Camera; + + + +px_void PX_3D_WorldInitialize(PX_3D_World *world,px_float x,px_float y,px_float z,px_float rotX,px_float rotY,px_float rotZ,px_float scale); +px_bool PX_3D_CameraEulerInitialize(px_memorypool *mp,PX_3D_Camera *camera,px_point4D cameraPosition,px_float rotX,px_float rotY,px_float rotZ,px_float near,px_float far,px_float fov,px_float viewPortWidth,px_float viewPortHeight); +px_bool PX_3D_CameraUVNInitialize(px_memorypool *mp,PX_3D_Camera *camera,px_point4D cameraPosition,px_point4D cameraTarget,px_float near,px_float far,px_float fov,px_float viewPortWidth,px_float viewPortHeight); +px_void PX_3D_CameraSetPosition(PX_3D_Camera *camera,px_point4D cameraPosition,px_point4D cameraTarget); +px_bool PX_3D_RenderListInitialize(px_memorypool *mp,PX_3D_RenderList *list,px_dword PX_3D_PRESENTMODE,PX_3D_CULLMODE cullmode,px_texture *ptexture); +px_void PX_3D_CameraFree(PX_3D_Camera *camera); +px_bool PX_3D_RenderListPush(PX_3D_RenderList *list,PX_3D_Face face); +px_point *PX_3D_CreateTextureNormal(px_memorypool *mp,px_texture *pTexture); +px_point *PX_3D_CreateBumpTextureNormal(px_memorypool *mp,px_texture *pTexture); +px_void PX_3D_RenderListTransform(PX_3D_RenderList *list,px_matrix mat,PX_3D_RENDERLIST_TRANSFORM t); +px_void PX_3D_RenderListReset(PX_3D_RenderList *list); +px_void PX_3D_RenderListFree(PX_3D_RenderList *list); +px_void PX_3D_Scene(PX_3D_RenderList *list,PX_3D_World *world,PX_3D_Camera *camera); +px_void PX_3D_Present(px_surface *psurface, PX_3D_RenderList *list,PX_3D_Camera *camera); +px_void PX_3D_RenderListSetPixelShader(PX_3D_RenderList *list,PX_3D_PixelShader func); + + + +#endif diff --git a/lib/PainterEngine/core/PX_AES.c b/lib/PainterEngine/core/PX_AES.c new file mode 100644 index 0000000000000000000000000000000000000000..c029170029c6b5771a84c523b6da2ea2879d7454 --- /dev/null +++ b/lib/PainterEngine/core/PX_AES.c @@ -0,0 +1,448 @@ +#include "PX_AES.h" + +const AES_BYTE Sbox[][16]= +{ // populate the Sbox matrix + /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */ + /*0*/ {0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76}, + /*1*/ {0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0}, + /*2*/ {0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15}, + /*3*/ {0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75}, + /*4*/ {0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84}, + /*5*/ {0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf}, + /*6*/ {0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8}, + /*7*/ {0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2}, + /*8*/ {0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73}, + /*9*/ {0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb}, + /*a*/ {0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79}, + /*b*/ {0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08}, + /*c*/ {0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a}, + /*d*/ {0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e}, + /*e*/ {0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf}, + /*f*/ {0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16}, +}; + +const AES_BYTE iSbox[][16]= +{ // populate the iSbox matrix + /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */ + /*0*/ {0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb}, + /*1*/ {0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb}, + /*2*/ {0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e}, + /*3*/ {0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25}, + /*4*/ {0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92}, + /*5*/ {0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84}, + /*6*/ {0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06}, + /*7*/ {0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02, 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b}, + /*8*/ {0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73}, + /*9*/ {0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e}, + /*a*/ {0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b}, + /*b*/ {0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4}, + /*c*/ {0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f}, + /*d*/ {0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef}, + /*e*/ {0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61}, + /*f*/ {0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d} +}; + +const AES_BYTE Rcon[][4]= +{ + {0x00, 0x00, 0x00, 0x00}, + {0x01, 0x00, 0x00, 0x00}, + {0x02, 0x00, 0x00, 0x00}, + {0x04, 0x00, 0x00, 0x00}, + {0x08, 0x00, 0x00, 0x00}, + {0x10, 0x00, 0x00, 0x00}, + {0x20, 0x00, 0x00, 0x00}, + {0x40, 0x00, 0x00, 0x00}, + {0x80, 0x00, 0x00, 0x00}, + {0x1b, 0x00, 0x00, 0x00}, + {0x36, 0x00, 0x00, 0x00} +}; + +static px_bool PX_AES_i_Cipher(PX_AES *aesStruct,AES_BYTE input[PX_AES_BLOCK_BYTES_SIZE], AES_BYTE output[PX_AES_BLOCK_BYTES_SIZE]) /* encipher 16-bit input */; +static px_void PX_AES_i_InvCipher(PX_AES *aesStruct,AES_BYTE input[PX_AES_BLOCK_BYTES_SIZE], AES_BYTE output[PX_AES_BLOCK_BYTES_SIZE]) /* decipher 16-bit input */; +AES_BYTE* PX_AES_SubWord(PX_AES *aesStruct,AES_BYTE* word); +AES_BYTE* PX_AES_RotWord(PX_AES *aesStruct,AES_BYTE* word); + +px_void PX_AES_SetNbNkNr(PX_AES *aesStruct,PX_AES_KeySize keySize); +px_void PX_AES_KeyExpansion(PX_AES *aesStruct); +px_void PX_AES_AddRoundKey(PX_AES *aesStruct,px_int round); +px_void PX_AES_SubBytes(PX_AES *aesStruct); +px_void PX_AES_ShiftRows(PX_AES *aesStruct); +px_void PX_AES_InvShiftRows(PX_AES *aesStruct); +px_void PX_AES_MixColumns(PX_AES *aesStruct); +px_void PX_AES_InvSubBytes(PX_AES *aesStruct); +px_void PX_AES_InvMixColumns(PX_AES *aesStruct); + + +px_void PX_AES_Initialize(PX_AES *aesStruct,PX_AES_KeySize keySize,AES_BYTE keyByte[]) +{ + PX_AES_SetNbNkNr(aesStruct,keySize); + /*Bytes copied*/ + PX_memcpy(aesStruct->key,keyByte,aesStruct->Nk*4); + + PX_AES_KeyExpansion(aesStruct); // expand the seed key into a key schedule and store in w +} + +px_void PX_AES_SetNbNkNr(PX_AES *aesStruct, PX_AES_KeySize keySize ) +{ + aesStruct->Nb = 4; // block size always = 4 words = 16 bytes = 128 bits for AES + + if (keySize == PX_AES_KeySize_Bits128) + { + aesStruct->Nk = 4; // key size = 4 words = 16 bytes = 128 bits + aesStruct->Nr = 10; // rounds for algorithm = 10 + } + else if (keySize == PX_AES_KeySize_Bits192) + { + aesStruct->Nk = 6; // 6 words = 24 bytes = 192 bits + aesStruct->Nr = 12; + } + else if (keySize == PX_AES_KeySize_Bits256) + { + aesStruct->Nk = 8; // 8 words = 32 bytes = 256 bits + aesStruct->Nr = 14; + } +} + +px_void PX_AES_AddRoundKey(PX_AES *aesStruct, px_int round ) +{ + px_int r,c; + for (r = 0; r < 4; ++r) + { + for (c = 0; c < 4; ++c) + { + aesStruct->State[r][c] = (AES_BYTE) ( (px_int)aesStruct->State[r][c] ^ (px_int)aesStruct->w[(round*4)+c][r] ); + } + } +} + +px_void PX_AES_KeyExpansion(PX_AES *aesStruct) +{ + px_int row; + AES_BYTE temp[4]; + for (row = 0; row < aesStruct->Nk; ++row) + { + aesStruct->w[row][0] = aesStruct->key[4*row]; + aesStruct->w[row][1] = aesStruct->key[4*row+1]; + aesStruct->w[row][2] = aesStruct->key[4*row+2]; + aesStruct->w[row][3] = aesStruct->key[4*row+3]; + } + + + + for (row = aesStruct->Nk; row < aesStruct->Nb * (aesStruct->Nr+1); ++row) + { + temp[0] = aesStruct->w[row-1][0]; temp[1] = aesStruct->w[row-1][1]; + temp[2] = aesStruct->w[row-1][2]; temp[3] = aesStruct->w[row-1][3]; + + if (row % aesStruct->Nk == 0) + { + PX_memcpy(temp ,PX_AES_SubWord(aesStruct,PX_AES_RotWord(aesStruct,temp)),4); + + temp[0] = (AES_BYTE)( (px_int)temp[0] ^ (px_int)Rcon[row/aesStruct->Nk][0] ); + temp[1] = (AES_BYTE)( (px_int)temp[1] ^ (px_int)Rcon[row/aesStruct->Nk][1] ); + temp[2] = (AES_BYTE)( (px_int)temp[2] ^ (px_int)Rcon[row/aesStruct->Nk][2] ); + temp[3] = (AES_BYTE)( (px_int)temp[3] ^ (px_int)Rcon[row/aesStruct->Nk][3] ); + } + else if ( aesStruct->Nk > 6 && (row % aesStruct->Nk == 4) ) + { + PX_memcpy(temp,PX_AES_SubWord(aesStruct,temp),4); + } + + // w[row] = w[row-Nk] xor temp + aesStruct->w[row][0] = (AES_BYTE) ( (px_int)aesStruct->w[row-aesStruct->Nk][0] ^ (px_int)temp[0] ); + aesStruct->w[row][1] = (AES_BYTE) ( (px_int)aesStruct->w[row-aesStruct->Nk][1] ^ (px_int)temp[1] ); + aesStruct->w[row][2] = (AES_BYTE) ( (px_int)aesStruct->w[row-aesStruct->Nk][2] ^ (px_int)temp[2] ); + aesStruct->w[row][3] = (AES_BYTE) ( (px_int)aesStruct->w[row-aesStruct->Nk][3] ^ (px_int)temp[3] ); + + } // for loop +} + + +AES_BYTE* PX_AES_SubWord(PX_AES *aesStruct,AES_BYTE* word) +{ + static AES_BYTE result[4]; + result[0] = Sbox[ word[0] >> 4][word[0] & 0x0f ]; + result[1] = Sbox[ word[1] >> 4][word[1] & 0x0f ]; + result[2] = Sbox[ word[2] >> 4][word[2] & 0x0f ]; + result[3] = Sbox[ word[3] >> 4][word[3] & 0x0f ]; + return result; +} + +AES_BYTE* PX_AES_RotWord(PX_AES *aesStruct,AES_BYTE* word) +{ + static AES_BYTE result[4]; + result[0] = word[1]; + result[1] = word[2]; + result[2] = word[3]; + result[3] = word[0]; + return result; +} + + +static px_bool PX_AES_i_Cipher(PX_AES *aesStruct,AES_BYTE input[PX_AES_BLOCK_BYTES_SIZE], AES_BYTE output[PX_AES_BLOCK_BYTES_SIZE]) // encipher 16-bit input +{ + px_int i,round; + for ( i = 0; i < (4 * aesStruct->Nb); ++i) + { + aesStruct->State[i % 4][i / 4] = input[i]; + } + + PX_AES_AddRoundKey(aesStruct,0); + + for (round = 1; round <= (aesStruct->Nr - 1); ++round) // main round loop + { + PX_AES_SubBytes(aesStruct); + PX_AES_ShiftRows(aesStruct); + PX_AES_MixColumns(aesStruct); + PX_AES_AddRoundKey(aesStruct,round); + } // main round loop + + PX_AES_SubBytes(aesStruct); + PX_AES_ShiftRows(aesStruct); + PX_AES_AddRoundKey(aesStruct,aesStruct->Nr); + + // output = state + for (i = 0; i < (4 * aesStruct->Nb); ++i) + { + output[i] = aesStruct->State[i % 4][i / 4]; + } + return PX_TRUE; +} // Cipher() + +px_bool PX_AES_Cipher(PX_AES *aesStruct,px_byte input[16], px_byte output[16]) /* encipher 16-bit input */ +{ + return PX_AES_i_Cipher(aesStruct,(AES_BYTE *)input,(AES_BYTE *)output); +} + + + +px_void PX_AES_SubBytes(PX_AES *aesStruct) +{ + px_int r,c; + for ( r = 0; r < 4; ++r) + { + for (c = 0; c < 4; ++c) + { + aesStruct->State[r][c] = Sbox[ (aesStruct->State[r][c] >> 4)][(aesStruct->State[r][c] & 0x0f) ]; + } + } +} + + +px_void PX_AES_ShiftRows(PX_AES *aesStruct) +{ + AES_BYTE temp[4][4]; + px_int r,c; + for ( r = 0; r < 4; ++r) // copy State into temp[] + { + for ( c = 0; c < 4; ++c) + { + temp[r][c] = aesStruct->State[r][c]; + } + } + + for ( r = 1; r < 4; ++r) // shift temp into State + { + for ( c = 0; c < 4; ++c) + { + aesStruct->State[r][c] = temp[ r][ (c + r) % aesStruct->Nb ]; + } + } +} // ShiftRows() + + +px_void PX_AES_InvShiftRows(PX_AES *aesStruct) +{ + AES_BYTE temp[4][4]; + px_int r,c; + for (r = 0; r < 4; ++r) // copy State into temp[] + { + for (c = 0; c < 4; ++c) + { + temp[r][c] = aesStruct->State[r][c]; + } + } + for ( r = 1; r < 4; ++r) // shift temp into State + { + for ( c = 0; c < 4; ++c) + { + aesStruct->State[r][(c + r) % aesStruct->Nb ] = temp[r][c]; + } + } +} // InvShiftRows() + +/////////////////////////////////////////////////////////////////////////// +// GF(2^8) Operation.... +////////////////////////////////////////////////////////////////////////// +AES_BYTE PX_AES_gfmultby01(AES_BYTE b) +{ + return b; +} + +AES_BYTE PX_AES_gfmultby02(AES_BYTE b) +{ + if (b < 0x80) + return (AES_BYTE)(px_int)(b <<1); + else + return (AES_BYTE)( (px_int)(b << 1) ^ (px_int)(0x1b) ); +} + +AES_BYTE PX_AES_gfmultby03(AES_BYTE b) +{ + return (AES_BYTE) ( (px_int)PX_AES_gfmultby02(b) ^ (px_int)b ); +} + +AES_BYTE PX_AES_gfmultby09(AES_BYTE b) +{ + return (AES_BYTE)( (px_int)PX_AES_gfmultby02(PX_AES_gfmultby02(PX_AES_gfmultby02(b))) ^ + (px_int)b ); +} + +AES_BYTE PX_AES_gfmultby0b(AES_BYTE b) +{ + return (AES_BYTE)( (px_int)PX_AES_gfmultby02(PX_AES_gfmultby02(PX_AES_gfmultby02(b))) ^ + (px_int)PX_AES_gfmultby02(b) ^ + (px_int)b ); +} + +AES_BYTE PX_AES_gfmultby0d(AES_BYTE b) +{ + return (AES_BYTE)( (px_int)PX_AES_gfmultby02(PX_AES_gfmultby02(PX_AES_gfmultby02(b))) ^ + (px_int)PX_AES_gfmultby02(PX_AES_gfmultby02(b)) ^ + (px_int)(b) ); +} + +AES_BYTE PX_AES_gfmultby0e(AES_BYTE b) +{ + return (AES_BYTE)( (px_int)PX_AES_gfmultby02(PX_AES_gfmultby02(PX_AES_gfmultby02(b))) ^ + (px_int)PX_AES_gfmultby02(PX_AES_gfmultby02(b)) ^ + (px_int)PX_AES_gfmultby02(b) ); +} + +px_void PX_AES_MixColumns(PX_AES *aesStruct) +{ + AES_BYTE temp[4][4]; + px_int r,c; + for ( r = 0; r < 4; ++r) // copy State into temp[] + { + for ( c = 0; c < 4; ++c) + { + temp[r][c] = aesStruct->State[r][c]; + } + } + + for ( c = 0; c < 4; ++c) + { + aesStruct->State[0][c] = (AES_BYTE) ( (px_int)PX_AES_gfmultby02(temp[0][c]) ^ (px_int)PX_AES_gfmultby03(temp[1][c]) ^ + (px_int)PX_AES_gfmultby01(temp[2][c]) ^ (px_int)PX_AES_gfmultby01(temp[3][c]) ); + aesStruct->State[1][c] = (AES_BYTE) ( (px_int)PX_AES_gfmultby01(temp[0][c]) ^ (px_int)PX_AES_gfmultby02(temp[1][c]) ^ + (px_int)PX_AES_gfmultby03(temp[2][c]) ^ (px_int)PX_AES_gfmultby01(temp[3][c]) ); + aesStruct->State[2][c] = (AES_BYTE) ( (px_int)PX_AES_gfmultby01(temp[0][c]) ^ (px_int)PX_AES_gfmultby01(temp[1][c]) ^ + (px_int)PX_AES_gfmultby02(temp[2][c]) ^ (px_int)PX_AES_gfmultby03(temp[3][c]) ); + aesStruct->State[3][c] = (AES_BYTE) ( (px_int)PX_AES_gfmultby03(temp[0][c]) ^ (px_int)PX_AES_gfmultby01(temp[1][c]) ^ + (px_int)PX_AES_gfmultby01(temp[2][c]) ^ (px_int)PX_AES_gfmultby02(temp[3][c]) ); + } +} // MixColumns + +px_void PX_AES_InvMixColumns(PX_AES *aesStruct) +{ + AES_BYTE temp[4][4]; + px_int r,c; + for ( r = 0; r < 4; ++r) // copy State into temp[] + { + for ( c = 0; c < 4; ++c) + { + temp[r][c] =aesStruct->State[r][c]; + } + } + + for ( c = 0; c < 4; ++c) + { + aesStruct->State[0][c] = (AES_BYTE) ( (px_int)PX_AES_gfmultby0e(temp[0][c]) ^ (px_int)PX_AES_gfmultby0b(temp[1][c]) ^ + (px_int)PX_AES_gfmultby0d(temp[2][c]) ^ (px_int)PX_AES_gfmultby09(temp[3][c]) ); + aesStruct->State[1][c] = (AES_BYTE) ( (px_int)PX_AES_gfmultby09(temp[0][c]) ^ (px_int)PX_AES_gfmultby0e(temp[1][c]) ^ + (px_int)PX_AES_gfmultby0b(temp[2][c]) ^ (px_int)PX_AES_gfmultby0d(temp[3][c]) ); + aesStruct->State[2][c] = (AES_BYTE) ( (px_int)PX_AES_gfmultby0d(temp[0][c]) ^ (px_int)PX_AES_gfmultby09(temp[1][c]) ^ + (px_int)PX_AES_gfmultby0e(temp[2][c]) ^ (px_int)PX_AES_gfmultby0b(temp[3][c]) ); + aesStruct->State[3][c] = (AES_BYTE) ( (px_int)PX_AES_gfmultby0b(temp[0][c]) ^ (px_int)PX_AES_gfmultby0d(temp[1][c]) ^ + (px_int)PX_AES_gfmultby09(temp[2][c]) ^ (px_int)PX_AES_gfmultby0e(temp[3][c]) ); + } +} // InvMixColumns + +static px_void PX_AES_i_InvCipher(PX_AES *aesStruct,AES_BYTE input[PX_AES_BLOCK_BYTES_SIZE], AES_BYTE output[PX_AES_BLOCK_BYTES_SIZE]) // decipher 16-bit input +{ + px_int i,round; + + for (i = 0; i < (4 * aesStruct->Nb); ++i) + { + aesStruct->State[i % 4][i / 4] = input[i]; + } + + PX_AES_AddRoundKey(aesStruct,aesStruct->Nr); + + for (round = aesStruct->Nr-1; round >= 1; --round) // main round loop + { + PX_AES_InvShiftRows(aesStruct); + PX_AES_InvSubBytes(aesStruct); + PX_AES_AddRoundKey(aesStruct,round); + PX_AES_InvMixColumns(aesStruct); + } // end main round loop for InvCipher + + PX_AES_InvShiftRows(aesStruct); + PX_AES_InvSubBytes(aesStruct); + PX_AES_AddRoundKey(aesStruct,0); + + // output = state + for ( i = 0; i < (4 * aesStruct->Nb); ++i) + { + output[i] = aesStruct->State[i % 4][i / 4]; + } + +} // InvCipher() + + + +px_void PX_AES_InvCipher(PX_AES *aesStruct,px_byte input[16], px_byte output[16]) /* decipher 16-bit input */ +{ + PX_AES_i_InvCipher(aesStruct,(AES_BYTE *)input,(AES_BYTE *)output); +} + +px_void PX_AES_InvSubBytes(PX_AES *aesStruct) +{ + px_int r,c; + for (r = 0; r < 4; ++r) + { + for (c = 0; c < 4; ++c) + { + aesStruct->State[r][c] = iSbox[ (aesStruct->State[r][c] >> 4)][(aesStruct->State[r][c] & 0x0f) ]; + } + } +} // InvSubBytes + +px_bool PX_AES_CipherBuffer(PX_AES *aesStruct,px_byte input[],px_int size,px_byte output[]) +{ + px_int i; + if (size%16) + { + return PX_FALSE; + } + for (i=0;imp=mp; + pANN->LayerCount=0; + pANN->Layer=PX_NULL; + pANN->learningRate=learningRate; + pANN->regularzation=regularzation; + pANN->regularization_rate=regularization_rate; + return PX_TRUE; +} + +px_bool PX_ANNAddLayer(PX_ANN *pAnn,px_int Neurals,px_double bias,PX_ANN_ACTIVATION_FUNCTION activation,PX_ANN_LAYER_WEIGHT_INITMODE mode,px_double weight_c) +{ + px_int i; + PX_ANN_Layer *newLayer,*p; + + + newLayer=(PX_ANN_Layer *)MP_Malloc(pAnn->mp,sizeof(PX_ANN_Layer)); + + newLayer->out=PX_NULL; + newLayer->net=PX_NULL; + newLayer->w=PX_NULL; + newLayer->back=PX_NULL; + newLayer->weight_init=weight_c; + if(!newLayer) return PX_FALSE; + + newLayer->activation=activation; + newLayer->Neurals=Neurals; + + newLayer->out=(px_double *)MP_Malloc(pAnn->mp,sizeof(px_double)*Neurals); + if(!newLayer->out) goto _ERROR; + + newLayer->back=(px_double *)MP_Malloc(pAnn->mp,sizeof(px_double)*Neurals); + if(!newLayer->back) goto _ERROR; + + newLayer->net=(px_double *)MP_Malloc(pAnn->mp,sizeof(px_double)*Neurals); + if(!newLayer->net) goto _ERROR; + + newLayer->bias=(px_double *)MP_Malloc(pAnn->mp,sizeof(px_double)*Neurals); + if(!newLayer->bias) goto _ERROR; + + for (i=0;ibias[i]=bias; + } + + newLayer->pNext=PX_NULL; + newLayer->w_initMode=mode; + + if (pAnn->Layer==PX_NULL) + { + newLayer->pPrevious=PX_NULL; + newLayer->w_count=0; + newLayer->w=PX_NULL; + pAnn->Layer=newLayer; + } + else + { + p=pAnn->Layer; + while (p->pNext) p=p->pNext; + + newLayer->pPrevious=p; + newLayer->w_count=p->Neurals*Neurals; + + newLayer->w=(px_double *)MP_Malloc(pAnn->mp,sizeof(px_double)*newLayer->w_count); + if(!newLayer->w) goto _ERROR; + + switch(mode) + { + + case PX_ANN_LAYER_WEIGHT_INITMODE_RAND: + for (i=0;iw_count;i++) + { + newLayer->w[i]=PX_rand()/1.0/PX_RAND_MAX; + } + break; + case PX_ANN_LAYER_WEIGHT_INITMODE_GAUSSRAND: + for (i=0;iw_count;i++) + { + newLayer->w[i]=PX_GaussRand(); + } + break; + + case PX_ANN_LAYER_WEIGHT_INITMODE_CONST: + default: + for (i=0;iw_count;i++) + { + newLayer->w[i]=weight_c; + } + break; + } + p->pNext=newLayer; + } + pAnn->LayerCount++; + return PX_TRUE; +_ERROR: + MP_Free(pAnn->mp,newLayer); + if(newLayer->out) MP_Free(pAnn->mp,newLayer->out); + if(newLayer->net) MP_Free(pAnn->mp,newLayer->net); + if(newLayer->w) MP_Free(pAnn->mp,newLayer->w); + if(newLayer->back) MP_Free(pAnn->mp,newLayer->back); + if(newLayer->back) MP_Free(pAnn->mp,newLayer->bias); + return PX_FALSE; + +} +px_double PX_ANNBackward(PX_ANN *pAnn,px_double *expect) +{ + PX_ANN_Layer *p; + px_int i,j; + px_double e=0; + p=pAnn->Layer; + while(p->pNext) p=p->pNext; + + //output layer + for (i=0;iNeurals;i++) + { + switch(p->activation) + { + case PX_ANN_ACTIVATION_FUNCTION_TANH: + p->net[i]=(1-PX_tanh(p->net[i])*PX_tanh(p->net[i])); + break; + case PX_ANN_ACTIVATION_FUNCTION_SIGMOID: + p->net[i]=PX_sigmoid(p->net[i])*(1-PX_sigmoid(p->net[i])); + break; + case PX_ANN_ACTIVATION_FUNCTION_RELU: + if (p->net[i]<0) + { + p->net[i]=0; + } + else + { + p->net[i]=1; + } + break; + default: + case PX_ANN_ACTIVATION_FUNCTION_LINEAR: + p->net[i]=1; + break; + } + p->net[i]*=-(expect[i]-p->out[i]); + e+=(expect[i]-p->out[i])*(expect[i]-p->out[i]); + } + + p=p->pPrevious; + //hidden + while (p->pPrevious) + { + for (i=0;iNeurals;i++) + { + p->back[i]=0; + for (j=0;jpNext->Neurals;j++) + { + p->back[i]+=p->pNext->net[j]*p->pNext->w[i*p->pNext->Neurals+j]; + } + + switch(p->activation) + { + case PX_ANN_ACTIVATION_FUNCTION_TANH: + p->net[i]=(1-PX_tanh(p->net[i])*PX_tanh(p->net[i])); + break; + case PX_ANN_ACTIVATION_FUNCTION_SIGMOID: + p->net[i]=PX_sigmoid(p->net[i])*(1-PX_sigmoid(p->net[i])); + break; + case PX_ANN_ACTIVATION_FUNCTION_RELU: + if (p->net[i]<0) + { + p->net[i]=0; + } + else + { + p->net[i]=1; + } + break; + default: + case PX_ANN_ACTIVATION_FUNCTION_LINEAR: + break; + } + p->net[i]*=p->back[i]; + } + p=p->pPrevious; + } + return e; +} + +px_double PX_ANNTrain(PX_ANN *pAnn,px_double *input,px_double *expect) +{ + px_int i,j; + px_double delta,e; + PX_ANN_Layer *p=pAnn->Layer; + + if (!p) return -1; + + PX_ANNForward(pAnn,input); + e=PX_ANNBackward(pAnn,expect); + //update weight + //input layer + p=p->pNext; + + while (p) + { + for (i=0;iNeurals;i++) + { + for (j=0;jpPrevious->Neurals;j++) + { + delta=p->net[i]*p->pPrevious->out[j]; + switch(pAnn->regularzation) + { + case PX_ANN_REGULARZATION_L1: + delta=delta-delta*pAnn->regularization_rate/pAnn->Layer->Neurals; + break; + case PX_ANN_REGULARZATION_L2: + delta=delta-delta*pAnn->regularization_rate/pAnn->Layer->Neurals*p->w[i*p->pPrevious->Neurals+j]; + break; + case PX_ANN_REGULARZATION_NONE: + default: + break; + } + p->w[i*p->pPrevious->Neurals+j]-=delta*pAnn->learningRate; + } + } + p=p->pNext; + } + + return e; +} + + + +px_void PX_ANNForward(PX_ANN *pAnn,px_double *input) +{ + px_int i,j; + PX_ANN_Layer *pPre,*p; + px_int inputCount; + + p=pAnn->Layer; + if (!p) return; + + + inputCount=pAnn->Layer->Neurals; + + for (i=0;iLayer->net[i]=input[i]; + } + + + while (PX_TRUE) + { + if (p->pPrevious==PX_NULL) + { + for (i=0;iNeurals;i++) + { + switch(p->activation) + { + case PX_ANN_ACTIVATION_FUNCTION_SIGMOID: + p->out[i]=PX_sigmoid(p->net[i]); + break; + case PX_ANN_ACTIVATION_FUNCTION_TANH: + p->out[i]=PX_tanh(p->net[i]); + break; + case PX_ANN_ACTIVATION_FUNCTION_RELU: + p->out[i]=PX_ReLU(p->net[i]); + break; + default: + case PX_ANN_ACTIVATION_FUNCTION_LINEAR: + p->out[i]=p->net[i]; + break; + } + } + p=p->pNext; + continue; + } + pPre=p->pPrevious; + + for (i=0;iNeurals;i++) + { + p->net[i]=0; + for (j=0;jNeurals;j++) + { + p->net[i]+=pPre->out[j]*p->w[i*pPre->Neurals+j]; + } + p->net[i]+=p->bias[i]; + + switch(p->activation) + { + case PX_ANN_ACTIVATION_FUNCTION_SIGMOID: + p->out[i]=PX_sigmoid(p->net[i]); + break; + case PX_ANN_ACTIVATION_FUNCTION_TANH: + p->out[i]=PX_tanh(p->net[i]); + break; + case PX_ANN_ACTIVATION_FUNCTION_RELU: + p->out[i]=PX_ReLU(p->net[i]); + break; + default: + case PX_ANN_ACTIVATION_FUNCTION_LINEAR: + p->out[i]=p->net[i]; + break; + } + } + if (p->pNext) + { + p=p->pNext; + } + else + break; + } +} + +px_void PX_LayerFree(PX_ANN *pANN,PX_ANN_Layer *layer) +{ + MP_Free(pANN->mp,layer->back); + MP_Free(pANN->mp,layer->net); + MP_Free(pANN->mp,layer->out); + if(layer->w) + MP_Free(pANN->mp,layer->w); + if(layer->bias) + MP_Free(pANN->mp,layer->bias); +} + +px_void PX_ANNFree(PX_ANN *pANN) +{ + PX_ANN_Layer *p=pANN->Layer,*pnext; + while (p) + { + pnext=p->pNext; + PX_LayerFree(pANN,p); + MP_Free(pANN->mp,p); + p=pnext; + } + pANN->mp=PX_NULL; + pANN->LayerCount=0; + pANN->Layer=PX_NULL; +} + + +px_bool PX_ANNExport(PX_ANN *pAnn,px_void *buffer,px_int *size) +{ + PX_ANN_Layer *pLayer; + px_byte *wBuffer=(px_byte *)buffer; + PX_ANN_Data_Header dataheader; + PX_ANN_Data_LayerHeader Layerheader; + + *size=0; + + pLayer=pAnn->Layer; + + dataheader.LayerCount=pAnn->LayerCount; + dataheader.learningRate=pAnn->LayerCount; + dataheader.regularization_rate=pAnn->regularization_rate; + dataheader.regularzation=pAnn->regularzation; + + //write dataheader + if (wBuffer) + { + PX_memcpy(wBuffer,&dataheader,sizeof(dataheader)); + wBuffer+=sizeof(dataheader); + } + + *size+=sizeof(dataheader); + //write layers + while (pLayer) + { + //layer headers + Layerheader.NeuralsCount=pLayer->Neurals; + Layerheader.weight_count=pLayer->w_count; + Layerheader.activation=pLayer->activation; + + if (wBuffer) + { + PX_memcpy(wBuffer,&Layerheader,sizeof(Layerheader)); + wBuffer+=sizeof(Layerheader); + } + + *size+=sizeof(Layerheader); + + //weights + if (wBuffer) + { + PX_memcpy(wBuffer,pLayer->w,sizeof(pLayer->w[0])*pLayer->w_count); + wBuffer+=sizeof(pLayer->w[0])*pLayer->w_count; + } + *size+=sizeof(pLayer->w[0])*pLayer->w_count; + + //bias + if (wBuffer) + { + PX_memcpy(wBuffer,pLayer->bias,sizeof(pLayer->bias[0])*pLayer->Neurals); + wBuffer+=sizeof(pLayer->bias[0])*pLayer->Neurals; + } + *size+=sizeof(pLayer->bias[0])*pLayer->Neurals; + + pLayer=pLayer->pNext; + } + return PX_TRUE; +} + + +px_bool PX_ANNImport(px_memorypool *mp,PX_ANN *pAnn,px_void *buffer,px_int size) +{ + px_int i; + px_byte *rBuffer=(px_byte *)buffer; + PX_ANN_Data_Header dataheader; + PX_ANN_Data_LayerHeader Layerheader; + PX_ANN_Layer *pLastLayer; + PX_memcpy(&dataheader,rBuffer,sizeof(dataheader)); + rBuffer+=sizeof(PX_ANN_Data_Header); + size-=sizeof(PX_ANN_Data_Header); + if (size<=0){return PX_FALSE;} + + if(!PX_ANNInitialize(mp,pAnn,dataheader.learningRate,(PX_ANN_REGULARZATION)dataheader.regularzation,dataheader.regularization_rate)) + return PX_FALSE; + + for (i=0;i<(px_int)dataheader.LayerCount;i++) + { + PX_memcpy(&Layerheader,rBuffer,sizeof(Layerheader)); + rBuffer+=sizeof(Layerheader); + size-=sizeof(Layerheader); + if (size<=0){PX_ANNFree(pAnn); return PX_FALSE;} + + if(!PX_ANNAddLayer(pAnn,Layerheader.NeuralsCount,0,(PX_ANN_ACTIVATION_FUNCTION)Layerheader.activation,PX_ANN_LAYER_WEIGHT_INITMODE_CONST,0)) + { + PX_ANNFree(pAnn); + return PX_FALSE; + } + pLastLayer=pAnn->Layer; + while (pLastLayer->pNext) + { + pLastLayer=pLastLayer->pNext; + } + + PX_memcpy(pLastLayer->w,rBuffer,Layerheader.weight_count*sizeof(px_double)); + rBuffer+=Layerheader.weight_count*sizeof(px_double); + size-=Layerheader.weight_count*sizeof(px_double); + if (size<=0){PX_ANNFree(pAnn); return PX_FALSE;} + + PX_memcpy(pLastLayer->bias,rBuffer,Layerheader.NeuralsCount*sizeof(px_double)); + rBuffer+=Layerheader.NeuralsCount*sizeof(px_double); + size-=Layerheader.NeuralsCount*sizeof(px_double); + if (size<0){PX_ANNFree(pAnn); return PX_FALSE;} + + } + return PX_TRUE; +} + +px_void PX_ANNGetOutput(PX_ANN *pAnn,px_double *result) +{ + PX_ANN_Layer *p=pAnn->Layer; + if(!p) return; + while (p->pNext) p=p->pNext; + PX_memcpy(result,p->out,p->Neurals*sizeof(px_double)); +} + +px_void PX_ANNReset(PX_ANN *pANN) +{ + PX_ANN_Layer *pLayer=pANN->Layer; + px_int i; + while (pLayer) + { + switch(pLayer->w_initMode) + { + + case PX_ANN_LAYER_WEIGHT_INITMODE_RAND: + for (i=0;iw_count;i++) + { + pLayer->w[i]=PX_rand()/1.0/PX_RAND_MAX; + } + break; + case PX_ANN_LAYER_WEIGHT_INITMODE_GAUSSRAND: + for (i=0;iw_count;i++) + { + pLayer->w[i]=PX_GaussRand(); + } + break; + + case PX_ANN_LAYER_WEIGHT_INITMODE_CONST: + default: + for (i=0;iw_count;i++) + { + pLayer->w[i]=pLayer->weight_init; + } + break; + } + pLayer=pLayer->pNext; + } +} + diff --git a/lib/PainterEngine/core/PX_ANN.h b/lib/PainterEngine/core/PX_ANN.h new file mode 100644 index 0000000000000000000000000000000000000000..34f53efdf3104549b59b63ccc1833f46d30c0073 --- /dev/null +++ b/lib/PainterEngine/core/PX_ANN.h @@ -0,0 +1,78 @@ +#ifndef PX_ANN_H +#define PX_ANN_H + +#include "PX_MemoryPool.h" + +typedef enum +{ + PX_ANN_LAYER_WEIGHT_INITMODE_CONST, + PX_ANN_LAYER_WEIGHT_INITMODE_RAND, + PX_ANN_LAYER_WEIGHT_INITMODE_GAUSSRAND, +}PX_ANN_LAYER_WEIGHT_INITMODE; + +typedef enum +{ + PX_ANN_ACTIVATION_FUNCTION_SIGMOID, + PX_ANN_ACTIVATION_FUNCTION_TANH, + PX_ANN_ACTIVATION_FUNCTION_LINEAR, + PX_ANN_ACTIVATION_FUNCTION_RELU, +}PX_ANN_ACTIVATION_FUNCTION; + +typedef enum +{ + PX_ANN_REGULARZATION_NONE, + PX_ANN_REGULARZATION_L1, + PX_ANN_REGULARZATION_L2 +}PX_ANN_REGULARZATION; + +typedef struct __PX_ANN_Layer +{ + px_double *net; + px_double *out; + px_double *back; + px_double *w; + px_double *bias; + px_int Neurals; + px_int w_count; + px_double weight_init; + PX_ANN_ACTIVATION_FUNCTION activation; + PX_ANN_LAYER_WEIGHT_INITMODE w_initMode; + struct __PX_ANN_Layer *pNext,*pPrevious; +}PX_ANN_Layer; + +typedef struct +{ + px_int LayerCount; + PX_ANN_Layer *Layer; + px_double learningRate; + px_double regularization_rate; + PX_ANN_REGULARZATION regularzation; + px_memorypool *mp; +}PX_ANN; + + +typedef struct +{ + px_dword LayerCount; + px_double learningRate; + px_double regularization_rate; + px_dword regularzation; +}PX_ANN_Data_Header; + +typedef struct +{ + px_int weight_count; + px_dword NeuralsCount; + px_dword activation; +}PX_ANN_Data_LayerHeader; + +px_bool PX_ANNInitialize(px_memorypool *mp,PX_ANN *ann,px_double learningRate,PX_ANN_REGULARZATION regularzation,px_double regularization_rate); +px_bool PX_ANNAddLayer(PX_ANN *pAnn,px_int Neurals,px_double bias,PX_ANN_ACTIVATION_FUNCTION activation,PX_ANN_LAYER_WEIGHT_INITMODE mode,px_double weight_c); +px_double PX_ANNTrain(PX_ANN *pAnn,px_double *input,px_double *expect); +px_void PX_ANNForward(PX_ANN *pAnn,px_double *input); +px_void PX_ANNGetOutput(PX_ANN *pAnn,px_double *result); +px_void PX_ANNReset(PX_ANN *pANN); +px_void PX_ANNFree(PX_ANN *pAnn); +px_bool PX_ANNExport(PX_ANN *pAnn,px_void *buffer,px_int *size); +px_bool PX_ANNImport(px_memorypool *mp,PX_ANN *pAnn,px_void *buffer,px_int size); +#endif diff --git a/lib/PainterEngine/core/PX_Arle.c b/lib/PainterEngine/core/PX_Arle.c new file mode 100644 index 0000000000000000000000000000000000000000..5ce616b26b5e0d6b88ba6c6af3778a41288f6621 --- /dev/null +++ b/lib/PainterEngine/core/PX_Arle.c @@ -0,0 +1,163 @@ +#include "PX_Arle.h" + +typedef enum +{ + PX_ARLE_TYPE_UNKNOW, + PX_ARLE_TYPE_UNEQUAL, + PX_ARLE_TYPE_EQUAL, +}PX_ARLE_TYPE; + + +px_int PX_ArleCompressData(px_byte *_in,px_uchar size,PX_ARLE_TYPE type,px_byte *_out) +{ + px_uchar ecode; + if (size==0) + { + return 0; + } + switch (type) + { + case PX_ARLE_TYPE_UNKNOW: + { + if (_out) + { + ecode=1;//0000 0001 + _out[0]=ecode; + _out[1]=_in[0]; + } + return 2; + } + break; + case PX_ARLE_TYPE_UNEQUAL: + { + if (_out) + { + ecode=0; + ecode|=size; + _out[0]=ecode; + PX_memcpy(_out+1,_in,size); + } + return size+1; + + } + break; + case PX_ARLE_TYPE_EQUAL: + { + if (_out) + { + ecode&=0x80; + ecode|=size; + _out[0]=ecode; + _out[1]=_in[0]; + } + return 2; + } + break; + } + return 0; +} + +px_void PX_ArleCompress(px_byte *_in,px_uint input_size,px_byte *_out,px_uint *_outsize) +{ + PX_ARLE_TYPE type=PX_ARLE_TYPE_UNKNOW; + px_uint wsize; + px_byte rlv=_in[0];//last value of read + px_uint p_cursor=0,r_cursor=1,w_cursor=0; + *_outsize=0; + + while (r_cursor=127) + { + wsize=PX_ArleCompressData(_in+p_cursor,r_cursor-p_cursor,type,_out?_out+w_cursor:PX_NULL); + *_outsize+=wsize; + w_cursor+=wsize; + p_cursor=r_cursor; + type=PX_ARLE_TYPE_UNKNOW; + rlv=_in[r_cursor]; + r_cursor++; + continue; + } + + switch (type) + { + case PX_ARLE_TYPE_UNKNOW: + { + if (rlv==_in[r_cursor]) + { + type=PX_ARLE_TYPE_EQUAL; + } + else + { + type=PX_ARLE_TYPE_UNEQUAL; + } + } + break; + case PX_ARLE_TYPE_UNEQUAL: + { + if (rlv==_in[r_cursor]) + { + //rollback + r_cursor--; + wsize=PX_ArleCompressData(_in+p_cursor,r_cursor-p_cursor,type,_out?_out+w_cursor:PX_NULL); + *_outsize+=wsize; + w_cursor+=wsize; + p_cursor=r_cursor; + type=PX_ARLE_TYPE_EQUAL; + } + } + break; + case PX_ARLE_TYPE_EQUAL: + { + if (rlv!=_in[r_cursor]) + { + //rollback + wsize=PX_ArleCompressData(_in+p_cursor,r_cursor-p_cursor,type,_out?_out+w_cursor:PX_NULL); + *_outsize+=wsize; + w_cursor+=wsize; + p_cursor=r_cursor; + type=PX_ARLE_TYPE_UNEQUAL; + } + } + break; + } + rlv=_in[r_cursor]; + r_cursor++; + } + //encode last token + *_outsize+=PX_ArleCompressData(_in+p_cursor,r_cursor-p_cursor,type,_out?_out+w_cursor:PX_NULL); + return; +} + +px_void PX_ArleDecompress(px_byte *_in,px_uint input_size,px_byte *_out,px_uint *_outsize) +{ + px_uint r_cursor=0,w_cursor=0; + px_uchar rep,size; + *_outsize=0; + while (r_cursor', '?', */ + 60, 61, 255, 255, 255, 255, 255, 255, + + /* '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', */ + 255, 0, 1, 2, 3, 4, 5, 6, + + /* 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', */ + 7, 8, 9, 10, 11, 12, 13, 14, + + /* 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', */ + 15, 16, 17, 18, 19, 20, 21, 22, + + /* 'X', 'Y', 'Z', '[', '\', ']', '^', '_', */ + 23, 24, 25, 255, 255, 255, 255, 255, + + /* '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', */ + 255, 26, 27, 28, 29, 30, 31, 32, + + /* 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', */ + 33, 34, 35, 36, 37, 38, 39, 40, + + /* 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', */ + 41, 42, 43, 44, 45, 46, 47, 48, + + /* 'x', 'y', 'z', '{', '|', '}', '~', del, */ + 49, 50, 51, 255, 255, 255, 255, 255 +}; + +px_uint PX_Base64Encode(const px_byte *in, px_uint inlen, px_char *out) +{ + int s; + px_uint i; + px_uint j; + px_byte c; + px_byte l; + + s = 0; + l = 0; + for (i = j = 0; i < inlen; i++) { + c = in[i]; + + switch (s) { + case 0: + s = 1; + out[j++] = base64en[(c >> 2) & 0x3F]; + break; + case 1: + s = 2; + out[j++] = base64en[((l & 0x3) << 4) | ((c >> 4) & 0xF)]; + break; + case 2: + s = 0; + out[j++] = base64en[((l & 0xF) << 2) | ((c >> 6) & 0x3)]; + out[j++] = base64en[c & 0x3F]; + break; + } + l = c; + } + + switch (s) { + case 1: + out[j++] = base64en[(l & 0x3) << 4]; + out[j++] = BASE64_PAD; + out[j++] = BASE64_PAD; + break; + case 2: + out[j++] = base64en[(l & 0xF) << 2]; + out[j++] = BASE64_PAD; + break; + } + + out[j] = 0; + + return j; +} + +px_uint PX_Base64Decode(const px_char *in, px_uint inlen, px_byte *out) +{ + px_uint i; + px_uint j; + px_byte c; + + if (inlen & 0x3) { + return 0; + } + + for (i = j = 0; i < inlen; i++) { + if (in[i] == BASE64_PAD) { + break; + } + if (in[i] < 0) { + return 0; + } + + c = base64de[(px_byte)in[i]]; + if (c == 255) { + return 0; + } + + switch (i & 0x3) { + case 0: + out[j] = (c << 2) & 0xFF; + break; + case 1: + out[j++] |= (c >> 4) & 0x3; + out[j] = (c & 0xF) << 4; + break; + case 2: + out[j++] |= (c >> 2) & 0xF; + out[j] = (c & 0x3) << 6; + break; + case 3: + out[j++] |= c; + break; + } + } + + return j; +} + +px_uint PX_Base64GetEncodeLen(px_uint beforeEncodeLen) +{ + if(beforeEncodeLen%3) + return (beforeEncodeLen/3+1)*4; + else + return (beforeEncodeLen/3)*4; +} + +px_uint PX_Base64GetDecodeLen(px_uint beforeEncodeLen) +{ + if(beforeEncodeLen%4) + return 0; + return (beforeEncodeLen/4)*3; +} \ No newline at end of file diff --git a/lib/PainterEngine/core/PX_Base64.h b/lib/PainterEngine/core/PX_Base64.h new file mode 100644 index 0000000000000000000000000000000000000000..db7b932b0d13bafd54af79fbe52993ccf28d2fa2 --- /dev/null +++ b/lib/PainterEngine/core/PX_Base64.h @@ -0,0 +1,9 @@ +#ifndef PX_BASE64_H +#define PX_BASE64_H +#include "PX_Typedef.h" +px_uint PX_Base64Encode(const px_byte *_in, px_uint input_size, px_char *out); +px_uint PX_Base64Decode(const px_char *_in, px_uint input_size, px_byte *out); +px_uint PX_Base64GetEncodeLen(px_uint codeLen); +px_uint PX_Base64GetDecodeLen(px_uint codeLen); + +#endif diff --git a/lib/PainterEngine/core/PX_BaseGeo.c b/lib/PainterEngine/core/PX_BaseGeo.c new file mode 100644 index 0000000000000000000000000000000000000000..eff99ceaccf27ee7c86211fc8b183a5d74560ccd --- /dev/null +++ b/lib/PainterEngine/core/PX_BaseGeo.c @@ -0,0 +1,3478 @@ +#include "PX_BaseGeo.h" +static px_int st_symmetry_axis; + +#define PX_ABS_FRAC(x) ((x)>0?PX_FRAC(x):PX_FRAC(-(x))) + +static px_void PX_DrawLinePixel_RecK(px_surface *psurface,px_int x,px_int y,px_color color) +{ + PX_SurfaceDrawPixel(psurface,y,x,color); +} + +static px_void PX_DrawLinePixel_InvK(px_surface *psurface,px_int x,px_int y,px_color color) +{ + PX_SurfaceDrawPixel(psurface,2*st_symmetry_axis-x,y,color); +} + +static px_void PX_DrawLinePixel_InvRecK(px_surface *psurface,px_int x,px_int y,px_color color) +{ + PX_SurfaceDrawPixel(psurface,2*st_symmetry_axis-y,x,color); +} +px_void PX_GeoDrawLine(px_surface *psurface, px_int x0, px_int y0, px_int x1, px_int y1 ,px_int lineWidth, px_color color) +{ + px_int i,len,lm,x,y,temp1,temp2,xleft,xright; + px_float p0x,p0y,p1x,p1y,p2x,p2y,p3x,p3y,vx,vy,rx,ry,xlen,ylen,S,ftemp,ryL,ryR,rxL,rxR; + px_float k,recK; + px_color clr; + px_void (*func_DrawPixel)(px_surface *psurface,px_int x,px_int y,px_color color); + + if (lineWidth==0) + { + return; + } + + ////////////////////////////////////////////////////////////////////////// + //Trim + do + { + px_int trimTop,trimRight,trimLeft,trimBottom; + px_int vector_x,vector_y; + px_float step; + trimTop=0-lineWidth; + trimBottom=psurface->height+lineWidth; + trimLeft=0-lineWidth; + trimRight=psurface->width+lineWidth; + + ////////////////////////////////////////////////////////////////////////// + //Trim top/bottom + if (y0>y1) + { + //swap p0<-->p1 + lm=x0; + x0=x1; + x1=lm; + + lm=y0; + y0=y1; + y1=lm; + } + //trim top + if (y10&&step<1) + { + x0=(px_int)(x0+vector_x*step); + y0=(px_int)(y0+vector_y*step); + } + } + + //trim bottom + if (y0>trimBottom) + { + return; + } + + vector_x=x1-x0; + vector_y=y1-y0; + + if (vector_y!=0) + { + step=(trimBottom-y0)*1.0f/vector_y; + if (step>0&&step<1) + { + x1=(px_int)(x1+vector_x*step); + y1=(px_int)(y1+vector_y*step); + } + } + + ////////////////////////////////////////////////////////////////////////// + //Trim left/right + if (x0>x1) + { + //swap p0<-->p1 + lm=x0; + x0=x1; + x1=lm; + + lm=y0; + y0=y1; + y1=lm; + } + + //trim left + if (x10&&step<1) + { + x0=(px_int)(x0+vector_x*step); + y0=(px_int)(y0+vector_y*step); + } + } + + //trim right + if (x0>trimRight) + { + return; + } + + vector_x=x1-x0; + vector_y=y1-y0; + + if (vector_x!=0) + { + step=(trimRight-x0)*1.0f/vector_x; + if (step>0&&step<1) + { + x1=(px_int)(x0+vector_x*step); + y1=(px_int)(y0+vector_y*step); + } + } + + } while (0); + + ////////////////////////////////////////////////////////////////////////// + + + + ////////////////////////////////////////////////////////////////////////// + //Draw Point + if (x0==x1&&y0==y1) + { + PX_SurfaceDrawPixel(psurface,x0,y0,color); + return; + } + + + if (x0==x1) + { + if (y0<0) + { + y0=0; + } + if (y1<0) + { + y1=0; + } + if (y0>psurface->height-1) + { + y0=psurface->height-1; + } + if (y1>psurface->height-1) + { + y1=psurface->height-1; + } + if (lineWidth&1) + { + PX_GeoDrawRect(psurface,x0-lineWidth/2,y0,x1+lineWidth/2,y1,color); + } + else + { + PX_GeoDrawRect(psurface,x0-lineWidth/2+1,y0,x1+lineWidth/2-1,y1,color); + len=PX_ABS(y0-y1)+1; + y0>y1?(lm=y1):(lm=y0); + color._argb.a=(color._argb.a>>1); + for (i=0;i=psurface->height) + { + break; + } + PX_SurfaceDrawPixel(psurface,x0-lineWidth/2,lm+i,color); + PX_SurfaceDrawPixel(psurface,x0+lineWidth/2,lm+i,color); + } + } + return; + } + + if (y0==y1) + { + if (x0<0) + { + x0=0; + } + if (x1<0) + { + x1=0; + } + if (x0>psurface->width-1) + { + x0=psurface->width-1; + } + if (x1>psurface->width-1) + { + x1=psurface->width-1; + } + if (lineWidth&1) + { + PX_GeoDrawRect(psurface,x0,y0-lineWidth/2,x1,y1+lineWidth/2,color); + } + else + { + PX_GeoDrawRect(psurface,x0,y0-lineWidth/2+1,x1,y1+lineWidth/2-1,color); + len=PX_ABS(x0-x1)+1; + x0>x1?(lm=x1):(lm=x0); + color._argb.a=(color._argb.a>>1); + for (i=0;i0) + { + if(k<1.f) + { + func_DrawPixel=PX_SurfaceDrawPixel; + } + else + { + lm=x0; + x0=y0; + y0=lm; + + lm=x1; + x1=y1; + y1=lm; + + k=((px_float)(y1-y0))/(x1-x0); + recK=1/k; + + func_DrawPixel=PX_DrawLinePixel_RecK; + } + } + else + { + if (k>-1.f) + { + lm=x0; + x0=x1; + x1=lm; + + lm=y0; + y0=y1; + y1=lm; + + st_symmetry_axis=x0; + x1=2*x0-x1; + + k=((px_float)(y1-y0))/(x1-x0); + recK=1/k; + + func_DrawPixel=PX_DrawLinePixel_InvK; + } + else + { + lm=x0; + x0=x1; + x1=lm; + + lm=y0; + y0=y1; + y1=lm; + + st_symmetry_axis=x0; + x1=2*x0-x1; + + lm=x0; + x0=y0; + y0=lm; + + lm=x1; + x1=y1; + y1=lm; + + k=((px_float)(y1-y0))/(x1-x0); + recK=1/k; + + func_DrawPixel=PX_DrawLinePixel_InvRecK; + } + } + + vx=(lineWidth/(2*PX_sqrt(1+recK*recK))); + vy=(lineWidth*recK/(2*PX_sqrt(1+recK*recK))); + + p0x=x0+vx+0.5f; + p0y=y0-vy+0.5f; + + p1x=x0-vx+0.5f; + p1y=y0+vy+0.5f; + + p2x=x1+vx+0.5f; + p2y=y1-vy+0.5f; + + p3x=x1-vx+0.5f; + p3y=y1+vy+0.5f; + + + if (p1y<=p2y) + { + + //p0-->p1 draw triangle + xlen=k; + + rx=p0x-(1-PX_ABS_FRAC(p0y))*k; + y=PX_TRUNC(p0y)+1; + temp1=PX_TRUNC(p0x); + temp2=PX_TRUNC(p1y); + while (p1y>y) + { + //Draw full color + for (x=PX_TRUNC(rx)+1;x<=temp1;x++) + { + func_DrawPixel(psurface,x,y,color); + } + //Draw edge point + ftemp=PX_FRAC(rx); + x=PX_TRUNC(rx); + if (PX_TRUNC(rx-xlen)p2 draw triangle + //Draw full color + y=PX_TRUNC(ry); + if(PX_TRUNC(ry+ylen)>PX_TRUNC(ry)) + { + //top + ftemp=1-PX_FRAC(ry); + S=ftemp*ftemp/k/2; + clr=color; + clr._argb.a=(px_uchar)(clr._argb.a*S); + func_DrawPixel(psurface,x,y,clr); + + if (yPX_TRUNC(p2x)) + { + break; + } + } + xright=x; + ryR=ry; + + ryL=p1y+(1-PX_ABS_FRAC(p1x))*k; + xleft=PX_TRUNC(p1x)+1; + + y=PX_TRUNC(p1y)+1; + while(PX_TRUNC(ryL)=p2x) + { + break; + } + + if(PX_TRUNC(ryR+ylen)==y) + { + S=1-PX_FRAC(ryR)-ylen/2; + clr=color; + clr._argb.a=(px_uchar)(clr._argb.a*S); + func_DrawPixel(psurface,xright,y,clr); + } + else + { + ftemp=1-PX_FRAC(ryR); + S=ftemp*ftemp/2/k; + clr=color; + clr._argb.a=(px_uchar)(clr._argb.a*S); + func_DrawPixel(psurface,xright,y,clr); + } + xright++; + ryR+=ylen; + } + + } + else + { + while (PX_TRUNC(ryR)==y) + { + if(PX_TRUNC(ryR+ylen)==y) + { + S=1-PX_FRAC(ryR)-ylen/2; + clr=color; + clr._argb.a=(px_uchar)(clr._argb.a*S); + func_DrawPixel(psurface,xright,y,clr); + } + else + { + ftemp=1-PX_FRAC(ryR); + S=ftemp*ftemp/2/k; + clr=color; + clr._argb.a=(px_uchar)(clr._argb.a*S); + func_DrawPixel(psurface,xright,y,clr); + } + xright++; + ryR+=ylen; + } + } + + + //draw horizontal + for (x=xleft;xp1 triangle + ry=p3y-(1-PX_ABS_FRAC(p3x))*k; + x=PX_TRUNC(p3x)-1; + temp2=PX_TRUNC(p2y); + temp1=PX_TRUNC(p3x-(p3y-p2y)/k); + + while (x>temp1) + { + //Draw full color + y=PX_TRUNC(ry); + if(PX_TRUNC(ry-ylen)!=PX_TRUNC(ry)) + { + //bottom + ftemp=PX_FRAC(ry); + S=ftemp*ftemp/k/2; + clr=color; + clr._argb.a=(px_uchar)(clr._argb.a*S); + func_DrawPixel(psurface,x,y,clr); + + //top + ftemp=1-PX_FRAC(ry-ylen); + S=1-ftemp*ftemp/k/2; + clr=color; + clr._argb.a=(px_uchar)(clr._argb.a*S); + func_DrawPixel(psurface,x,y-1,clr); + + for (i=y-2;i>temp2;i--) + { + func_DrawPixel(psurface,x,i,color); + } + + } + else + { + ftemp=PX_FRAC(ry-ylen); + ftemp+=ylen/2; + + clr=color; + clr._argb.a=(px_uchar)(clr._argb.a*ftemp); + + func_DrawPixel(psurface,x,y,clr); + + for (i=y-1;i>temp2;i--) + { + func_DrawPixel(psurface,x,i,color); + } + } + ry-=ylen; + x--; + + if (xp3 draw triangle + rx=p2x-(1-PX_ABS_FRAC(p2y))*k; + y=PX_TRUNC(p2y)+1; + temp1=PX_TRUNC(p3x); + + //while() + + while (ytemp1-1;x--) + { + func_DrawPixel(psurface,x,y,color); + + } + //Draw edge point + ftemp=PX_FRAC(rx); + x=PX_TRUNC(rx); + if (PX_TRUNC(rx-xlen)p2 draw triangle + + //Draw full color + temp2=PX_TRUNC(p2y); + y=PX_TRUNC(ry); + if(PX_TRUNC(ry+ylen)>PX_TRUNC(ry)) + { + //top + ftemp=1-PX_FRAC(ry); + S=ftemp*ftemp/k/2; + clr=color; + clr._argb.a=(px_uchar)(clr._argb.a*S); + func_DrawPixel(psurface,x,y,clr); + + //bottom + if(yPX_TRUNC(p2x)) + { + break; + } + } + + //p0-->p1 draw triangle + xlen=k; + + rx=p0x-(1-PX_ABS_FRAC(p0y))*k; + y=PX_TRUNC(p0y)+1; + temp1=PX_TRUNC(p0x); + while (y<=PX_TRUNC(p2y)) + { + //Draw full color + for (x=PX_TRUNC(rx)+1;x<=temp1;x++) + { + func_DrawPixel(psurface,x,y,color); + + } + //Draw edge point + ftemp=PX_FRAC(rx); + x=PX_TRUNC(rx); + if (PX_TRUNC(rx-xlen)p3 draw triangle + while (yp1 triangle + ry=p3y-(1-PX_ABS_FRAC(p3x))*k; + x=PX_TRUNC(p3x)-1; + + temp2=PX_TRUNC(p1y)+1; + while (x>PX_TRUNC(p1x)) + { + //Draw full color + y=PX_TRUNC(ry); + if(PX_TRUNC(ry-ylen)!=PX_TRUNC(ry)) + { + //bottom + ftemp=PX_FRAC(ry); + S=ftemp*ftemp/k/2; + clr=color; + clr._argb.a=(px_uchar)(clr._argb.a*S); + func_DrawPixel(psurface,x,y,clr); + + //top + if(y>temp2) + { + ftemp=1-PX_FRAC(ry-ylen); + S=1-ftemp*ftemp/k/2; + clr=color; + clr._argb.a=(px_uchar)(clr._argb.a*S); + func_DrawPixel(psurface,x,y-1,clr); + } + for (i=temp2;i0) + lineWidth-=1; + else + return; + + + + PX_GeoDrawRect(psurface,left,top,right,top+lineWidth,color); + PX_GeoDrawRect(psurface,left,bottom-lineWidth,right,bottom,color); + PX_GeoDrawRect(psurface,left,top+lineWidth+1,left+lineWidth,bottom-lineWidth-1,color); + PX_GeoDrawRect(psurface,right-lineWidth,top+lineWidth+1,right,bottom-lineWidth-1,color); +} + + + +px_void PX_GeoDrawRect(px_surface *psurface, px_int left, px_int top, px_int right, px_int bottom,px_color color) +{ + px_int i,j,mid; + if(color._argb.a==0) + { + return; + } + + if (left>right) + { + mid=left; + left=right; + right=mid; + } + if (top>bottom) + { + mid=top; + top=bottom; + bottom=mid; + } + + if (left<0) + { + left=0; + } + if (leftlimit_left) + { + left=psurface->limit_left; + } + + if (top<0) + { + top=0; + } + if (toplimit_top) + { + top=psurface->limit_top; + } + + if (right>psurface->width-1) + { + right=psurface->width-1; + } + if (right>psurface->limit_right) + { + right=psurface->limit_right; + } + + if (bottom>psurface->height-1) + { + bottom=psurface->height-1; + } + if (bottom>psurface->limit_bottom) + { + bottom=psurface->limit_bottom; + } + + if (left>psurface->width-1) + { + return; + } + + if (bottom<0) + { + return; + } + + if (right<0) + { + return; + } + + if (top>psurface->height-1) + { + return; + } + + + + + + + if(color._argb.a==0xff) + { + for (i=top;i<=bottom;i++) + { + PX_memdwordset(psurface->surfaceBuffer+i*psurface->width+left,color._argb.ucolor,right-left+1); + } + } + else + for (i=top;i<=bottom;i++) + { + for (j=left;j<=right;j++) + { + PX_SurfaceDrawPixel(psurface,j,i,color); + } + } +} + +static px_void PX_GeoDrawSolidCircle_Ex1(px_surface *psurface, px_int x,px_int y,px_int Radius,px_color color ) +{ + px_int ry,dy,i,xleft,xright,Sy,cY,drx,dry; + px_float rad2,xoft1,xoft2,S,fy,fdis; + px_color clr; + + if (Radius==0) + { + return; + } + //Draw origin + PX_SurfaceDrawPixel(psurface,x,y,color); + + //Draw cross + + if (x>=0-Radius&&y>=0-Radius&&xwidth+Radius&&yheight+Radius) + { + clr=color; + clr._argb.a>>=1; + dy=Radius; + PX_SurfaceDrawPixel(psurface,x,y+dy,clr); + PX_SurfaceDrawPixel(psurface,x,y-dy,clr); + PX_SurfaceDrawPixel(psurface,x+dy,y,clr); + PX_SurfaceDrawPixel(psurface,x-dy,y,clr); + + for (i=1;i0.5f) + { + fdis=1-PX_FRAC(fy); + S=1-fdis*fdis*2; + clr=color; + clr._argb.a=(px_uchar)(clr._argb.a*S); + PX_SurfaceDrawPixel(psurface,x+dy,y+dy,clr); + PX_SurfaceDrawPixel(psurface,x-dy,y+dy,clr); + PX_SurfaceDrawPixel(psurface,x+dy,y-dy,clr); + PX_SurfaceDrawPixel(psurface,x-dy,y-dy,clr); + } + else + { + fdis=PX_FRAC(fy); + S=fdis*fdis*2; + clr=color; + clr._argb.a=(px_uchar)(clr._argb.a*S); + PX_SurfaceDrawPixel(psurface,x+dy,y+dy,clr); + PX_SurfaceDrawPixel(psurface,x-dy,y+dy,clr); + PX_SurfaceDrawPixel(psurface,x+dy,y-dy,clr); + PX_SurfaceDrawPixel(psurface,x-dy,y-dy,clr); + } + + + for (i=ry+1;ipsurface->width-1) + { + right=psurface->width-1; + } + + if (bottom>psurface->height-1) + { + bottom=psurface->height-1; + } + + if (left>psurface->width-1) + { + return; + } + + if (bottom<0) + { + return; + } + + if (right<0) + { + return; + } + + if (top>psurface->height-1) + { + return; + } + + + if (left>right) + { + mid=left; + left=right; + right=mid; + } + if (top>bottom) + { + mid=top; + top=bottom; + bottom=mid; + } + + for (i=top;i<=bottom;i++) + { + for (j=left;j<=right;j++) + { + d=PX_sqrt((px_float)((i-y)*(i-y)+(j-x)*(j-x))); + if (dpsurface->width-1) + { + right=psurface->width-1; + } + + if (bottom>psurface->height-1) + { + bottom=psurface->height-1; + } + + if (left>psurface->width-1) + { + return; + } + + if (bottom<0) + { + return; + } + + if (right<0) + { + return; + } + + if (top>psurface->height-1) + { + return; + } + + + if (left>right) + { + mid=left; + left=right; + right=mid; + } + if (top>bottom) + { + mid=top; + top=bottom; + bottom=mid; + } + + Sc=(px_int)(PX_PI*Radius*Radius); + Sr=(right-left+1)*(bottom-top+1); + if (SrRadius*2) + { + lineWidth=Radius*2; + } + + if (x>=0-Radius&&y>=0-Radius&&xwidth+Radius&&yheight+Radius) + { + i=x*x+y*y; + + if (i<(x-psurface->width)*(x-psurface->width)+y*y) + { + i=(x-psurface->width)*(x-psurface->width)+y*y; + } + + if (i<(x-psurface->width)*(x-psurface->width)+(y-psurface->height)*(y-psurface->height)) + { + i=(x-psurface->width)*(x-psurface->width)+(y-psurface->height)*(y-psurface->height); + } + + if (iheight)*(y-psurface->height)) + { + i=x*x+(y-psurface->height)*(y-psurface->height); + } + + if (i<(Radius-lineWidth/2)*(Radius-lineWidth/2)&&!PX_isPointInRect(PX_POINT((px_float)x,(px_float)y,0),PX_RECT(0,0,(px_float)psurface->width,(px_float)psurface->height))) + { + return; + } + } + else + { + return; + } + + + + + + + if (lineWidth&1) + { + ry=Radius+(lineWidth>>1); + for (rx=Radius-(lineWidth>>1);rx<=ry;rx++) + { + PX_SurfaceDrawPixel(psurface,x+rx,y,color); + PX_SurfaceDrawPixel(psurface,x-rx,y,color); + PX_SurfaceDrawPixel(psurface,x,rx+y,color); + PX_SurfaceDrawPixel(psurface,x,-rx+y,color); + } + } + else + { + clr=color; + clr._argb.a>>=1; + dy=Radius+(lineWidth>>1); + PX_SurfaceDrawPixel(psurface,x,y+dy,clr); + PX_SurfaceDrawPixel(psurface,x,y-dy,clr); + PX_SurfaceDrawPixel(psurface,x+dy,y,clr); + PX_SurfaceDrawPixel(psurface,x-dy,y,clr); + + ry=Radius-(lineWidth>>1); + PX_SurfaceDrawPixel(psurface,x,y+ry,clr); + PX_SurfaceDrawPixel(psurface,x,y-ry,clr); + PX_SurfaceDrawPixel(psurface,x+ry,y,clr); + PX_SurfaceDrawPixel(psurface,x-ry,y,clr); + + for (i=ry+1;i0.5f) + { + fdis=1-PX_FRAC(fy); + S=fdis*fdis*2; + clr=color; + clr._argb.a=(px_uchar)(clr._argb.a*S); + PX_SurfaceDrawPixel(psurface,x+ry,y+ry,clr); + PX_SurfaceDrawPixel(psurface,x-ry,y+ry,clr); + PX_SurfaceDrawPixel(psurface,x+ry,y-ry,clr); + PX_SurfaceDrawPixel(psurface,x-ry,y-ry,clr); + } + else + { + fdis=PX_FRAC(fy); + S=1-fdis*fdis*2; + clr=color; + clr._argb.a=(px_uchar)(clr._argb.a*S); + PX_SurfaceDrawPixel(psurface,x+ry,y+ry,clr); + PX_SurfaceDrawPixel(psurface,x-ry,y+ry,clr); + PX_SurfaceDrawPixel(psurface,x+ry,y-ry,clr); + PX_SurfaceDrawPixel(psurface,x-ry,y-ry,clr); + } + + + //out side + rad2=Radius+lineWidth/2.0f; + dy=PX_TRUNC(rad2/1.4142135623731f+0.5f); + fy=rad2/1.4142135623731f+0.5f; + if (PX_FRAC(fy)>0.5f) + { + fdis=1-PX_FRAC(fy); + S=1-fdis*fdis*2; + clr=color; + clr._argb.a=(px_uchar)(clr._argb.a*S); + PX_SurfaceDrawPixel(psurface,x+dy,y+dy,clr); + PX_SurfaceDrawPixel(psurface,x-dy,y+dy,clr); + PX_SurfaceDrawPixel(psurface,x+dy,y-dy,clr); + PX_SurfaceDrawPixel(psurface,x-dy,y-dy,clr); + } + else + { + fdis=PX_FRAC(fy); + S=fdis*fdis*2; + clr=color; + clr._argb.a=(px_uchar)(clr._argb.a*S); + PX_SurfaceDrawPixel(psurface,x+dy,y+dy,clr); + PX_SurfaceDrawPixel(psurface,x-dy,y+dy,clr); + PX_SurfaceDrawPixel(psurface,x+dy,y-dy,clr); + PX_SurfaceDrawPixel(psurface,x-dy,y-dy,clr); + } + + + for (i=ry+1;i0) + { + if (vy<0) + { + math_region+=4; + } + } + else + math_region=2-math_region; + + if ((math_region>s_r&&math_regionend_angle) + { + px_int temp=start_angle; + start_angle=end_angle; + end_angle=temp; + } + + if (start_angle<0) + { + repeat=start_angle/360; + repeat-=1; + start_angle-=repeat*360; + end_angle-=repeat*360; + } + + repeat=start_angle/360; + start_angle-=repeat*360; + end_angle-=repeat*360; + + s_quadrant=(start_angle%360)/90+1; + e_quadrant=(end_angle%360)/90+1; + + start_mathRegion=PX_sin_angle((px_float)start_angle); + end_mathRegion=PX_sin_angle((px_float)end_angle); + + switch (s_quadrant) + { + case 1: + break; + case 2: + case 3: + start_mathRegion=2-start_mathRegion; + break; + case 4: + start_mathRegion+=4; + break; + default: + PX_ASSERT(); + } + start_mathRegion+=4*(start_angle/360); + + switch (e_quadrant) + { + case 1: + break; + case 2: + case 3: + end_mathRegion=2-end_mathRegion; + break; + case 4: + end_mathRegion+=4; + break; + default: + PX_ASSERT(); + } + end_mathRegion+=4*(end_angle/360); + + if (end_mathRegionRadius*2) + { + lineWidth=Radius*2; + } + + if (x>=0-Radius&&y>=0-Radius&&xwidth+Radius&&yheight+Radius) + { + i=x*x+y*y; + + if (i<(x-psurface->width)*(x-psurface->width)+y*y) + { + i=(x-psurface->width)*(x-psurface->width)+y*y; + } + + if (i<(x-psurface->width)*(x-psurface->width)+(y-psurface->height)*(y-psurface->height)) + { + i=(x-psurface->width)*(x-psurface->width)+(y-psurface->height)*(y-psurface->height); + } + + if (iheight)*(y-psurface->height)) + { + i=x*x+(y-psurface->height)*(y-psurface->height); + } + + if (i<(Radius-lineWidth/2)*(Radius-lineWidth/2)&&!PX_isPointInRect(PX_POINT((px_float)x,(px_float)y,0),PX_RECT(0,0,(px_float)psurface->width,(px_float)psurface->height))) + { + return; + } + } + else + { + return; + } + + + + if (lineWidth&1) + { + ry=Radius+(lineWidth>>1); + for (rx=Radius-(lineWidth>>1);rx<=ry;rx++) + { + PX_GeoDrawRingPoint(psurface,x+rx,y,color,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x-rx,y,color,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x,rx+y,color,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x,-rx+y,color,x,y,start_mathRegion,end_mathRegion); + } + } + else + { + clr=color; + clr._argb.a>>=1; + dy=Radius+(lineWidth>>1); + PX_GeoDrawRingPoint(psurface,x,y+dy,clr,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x,y-dy,clr,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x+dy,y,clr,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x-dy,y,clr,x,y,start_mathRegion,end_mathRegion); + + ry=Radius-(lineWidth>>1); + PX_GeoDrawRingPoint(psurface,x,y+ry,clr,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x,y-ry,clr,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x+ry,y,clr,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x-ry,y,clr,x,y,start_mathRegion,end_mathRegion); + + for (i=ry+1;i0.5f) + { + fdis=1-PX_FRAC(fy); + S=fdis*fdis*2; + clr=color; + clr._argb.a=(px_uchar)(clr._argb.a*S); + PX_GeoDrawRingPoint(psurface,x+ry,y+ry,clr,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x-ry,y+ry,clr,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x+ry,y-ry,clr,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x-ry,y-ry,clr,x,y,start_mathRegion,end_mathRegion); + } + else + { + fdis=PX_FRAC(fy); + S=1-fdis*fdis*2; + clr=color; + clr._argb.a=(px_uchar)(clr._argb.a*S); + PX_GeoDrawRingPoint(psurface,x+ry,y+ry,clr,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x-ry,y+ry,clr,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x+ry,y-ry,clr,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x-ry,y-ry,clr,x,y,start_mathRegion,end_mathRegion); + } + + + //out side + rad2=Radius+lineWidth/2.0f; + dy=PX_TRUNC(rad2/1.4142135623731f+0.5f); + fy=rad2/1.4142135623731f+0.5f; + if (PX_FRAC(fy)>0.5f) + { + fdis=1-PX_FRAC(fy); + S=1-fdis*fdis*2; + clr=color; + clr._argb.a=(px_uchar)(clr._argb.a*S); + PX_GeoDrawRingPoint(psurface,x+dy,y+dy,clr,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x-dy,y+dy,clr,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x+dy,y-dy,clr,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x-dy,y-dy,clr,x,y,start_mathRegion,end_mathRegion); + } + else + { + fdis=PX_FRAC(fy); + S=fdis*fdis*2; + clr=color; + clr._argb.a=(px_uchar)(clr._argb.a*S); + PX_GeoDrawRingPoint(psurface,x+dy,y+dy,clr,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x-dy,y+dy,clr,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x+dy,y-dy,clr,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x-dy,y-dy,clr,x,y,start_mathRegion,end_mathRegion); + } + + + for (i=ry+1;iend_angle) + { + px_int temp=start_angle; + start_angle=end_angle; + end_angle=temp; + } + + if (start_angle<0) + { + repeat=start_angle/360; + repeat-=1; + start_angle-=repeat*360; + end_angle-=repeat*360; + } + + repeat=start_angle/360; + start_angle-=repeat*360; + end_angle-=repeat*360; + + + s_quadrant=(start_angle%360)/90+1; + e_quadrant=(end_angle%360)/90+1; + + start_mathRegion=PX_sin_angle((px_float)start_angle); + end_mathRegion=PX_sin_angle((px_float)end_angle); + + switch (s_quadrant) + { + case 1: + break; + case 2: + case 3: + start_mathRegion=2-start_mathRegion; + break; + case 4: + start_mathRegion+=4; + break; + default: + PX_ASSERT(); + } + start_mathRegion+=4*(start_angle/360); + + switch (e_quadrant) + { + case 1: + break; + case 2: + case 3: + end_mathRegion=2-end_mathRegion; + break; + case 4: + end_mathRegion+=4; + break; + default: + PX_ASSERT(); + } + end_mathRegion+=4*(end_angle/360); + + if (end_mathRegion=0-Radius_outside&&y>=0-Radius_outside&&xwidth+Radius_outside&&yheight+Radius_outside) + { + i=x*x+y*y; + + if (i<(x-psurface->width)*(x-psurface->width)+y*y) + { + i=(x-psurface->width)*(x-psurface->width)+y*y; + } + + if (i<(x-psurface->width)*(x-psurface->width)+(y-psurface->height)*(y-psurface->height)) + { + i=(x-psurface->width)*(x-psurface->width)+(y-psurface->height)*(y-psurface->height); + } + + if (iheight)*(y-psurface->height)) + { + i=x*x+(y-psurface->height)*(y-psurface->height); + } + + if (iwidth,(px_float)psurface->height))) + { + return; + } + } + else + { + return; + } + + ry=Radius_outside; + for (rx=Radius_inside;rx<=ry;rx++) + { + PX_GeoDrawRingPoint(psurface,x+rx,y,color,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x-rx,y,color,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x,rx+y,color,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x,-rx+y,color,x,y,start_mathRegion,end_mathRegion); + } + + // Draw 45-degree cross + //inside + rad=(px_float)Radius_inside; + ry=PX_TRUNC(rad/1.4142135623731f+0.5f); + fy=rad/1.4142135623731f+0.5f; + if (PX_FRAC(fy)>0.5f) + { + fdis=1-PX_FRAC(fy); + S=fdis*fdis*2; + clr=color; + clr._argb.a=(px_uchar)(clr._argb.a*S); + PX_GeoDrawRingPoint(psurface,x+ry,y+ry,clr,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x-ry,y+ry,clr,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x+ry,y-ry,clr,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x-ry,y-ry,clr,x,y,start_mathRegion,end_mathRegion); + } + else + { + fdis=PX_FRAC(fy); + S=1-fdis*fdis*2; + clr=color; + clr._argb.a=(px_uchar)(clr._argb.a*S); + PX_GeoDrawRingPoint(psurface,x+ry,y+ry,clr,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x-ry,y+ry,clr,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x+ry,y-ry,clr,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x-ry,y-ry,clr,x,y,start_mathRegion,end_mathRegion); + } + + + //outside + rad2=(px_float)Radius_outside; + dy=PX_TRUNC(rad2/1.4142135623731f+0.5f); + fy=rad2/1.4142135623731f+0.5f; + if (PX_FRAC(fy)>0.5f) + { + fdis=1-PX_FRAC(fy); + S=1-fdis*fdis*2; + clr=color; + clr._argb.a=(px_uchar)(clr._argb.a*S); + PX_GeoDrawRingPoint(psurface,x+dy,y+dy,clr,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x-dy,y+dy,clr,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x+dy,y-dy,clr,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x-dy,y-dy,clr,x,y,start_mathRegion,end_mathRegion); + } + else + { + fdis=PX_FRAC(fy); + S=fdis*fdis*2; + clr=color; + clr._argb.a=(px_uchar)(clr._argb.a*S); + PX_GeoDrawRingPoint(psurface,x+dy,y+dy,clr,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x-dy,y+dy,clr,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x+dy,y-dy,clr,x,y,start_mathRegion,end_mathRegion); + PX_GeoDrawRingPoint(psurface,x-dy,y-dy,clr,x,y,start_mathRegion,end_mathRegion); + } + + + for (i=ry+1;iright) + { + Height=left; + left=right; + right=Height; + } + if (top>bottom) + { + Height=top; + top=bottom; + bottom=Height; + } + Height=(bottom-top)+1; + Width=(right-left)+1; + + r_y=roundRaduis; + r_x=roundRaduis; + for (y=0;y<(px_int)roundRaduis;y++) + { + if (Height&1) + { + if (y>Height/2) + { + break; + } + } + else + { + if (y>Height/2-1) + { + break; + } + } + + x=(px_int)roundRaduis-(px_int)(PX_sqrt(roundRaduis*roundRaduis-(roundRaduis-y-1)*(roundRaduis-y-1)))-1; + if(x<0) x=0; + for (;x<(px_int)roundRaduis;x++) + { + if (Width&1) + { + if (x>Width/2) + { + break; + } + } + else + { + if (x>Width/2-1) + { + break; + } + } + + if (x>Width/2) + { + break; + } + + dis=PX_sqrt((x-r_x)*(x-r_x)+(y-r_y)*(y-r_y)); + if (disroundRaduis) + drawColor._argb.a=(px_uchar)(color._argb.a*(dis-roundRaduis+0.5f)); + + PX_SurfaceDrawPixel(psurface,left+x,top+y,drawColor); + + if(2*xHeight/2) + { + drawHeight=(px_int)roundRaduis-Height/2; + } + else + { + drawHeight=(px_int)roundRaduis; + } + + + if (Width>2*(px_int)roundRaduis) + { + drawWidth=Width-2*(px_int)roundRaduis; + + if(drawWidth>0&&drawHeight>0) + { + PX_GeoDrawRect(psurface,left+(px_int)roundRaduis,top,left+(px_int)roundRaduis+drawWidth-1,top+drawHeight-1,color); + PX_GeoDrawRect(psurface,left+(px_int)roundRaduis,bottom-drawHeight+1,left+(px_int)roundRaduis+drawWidth-1,bottom,color); + } + } + + if(Height>2*(px_int)roundRaduis) + PX_GeoDrawRect(psurface,left,top+(px_int)roundRaduis,right,bottom-(px_int)roundRaduis,color); + +} + +px_void PX_GeoDrawRoundRect(px_surface *psurface, px_int left, px_int top, px_int right, px_int bottom,px_float roundRaduis,px_float linewidth,px_color color) +{ + px_int y,x,Height,Width; + px_float r_x,r_y,dis; + px_int drawWidth; + px_int drawHeight; + px_int drawlinewidth_int; + px_color drawColor; + if(color._argb.a==0) + { + return; + } + + if (left>right) + { + Height=left; + left=right; + right=Height; + } + if (top>bottom) + { + Height=top; + top=bottom; + bottom=Height; + } + Height=(bottom-top)+1; + Width=(right-left)+1; + + r_y=roundRaduis; + r_x=roundRaduis; + for (y=0;y<(px_int)roundRaduis;y++) + { + if (Height&1) + { + if (y>Height/2) + { + break; + } + } + else + { + if (y>Height/2-1) + { + break; + } + } + + x=(px_int)roundRaduis-(px_int)(PX_sqrt(roundRaduis*roundRaduis-(roundRaduis-y-1)*(roundRaduis-y-1)))-1; + if(x<0)x=0; + for (;x<(px_int)roundRaduis;x++) + { + if (Width&1) + { + if (x>Width/2) + { + break; + } + } + else + { + if (x>Width/2-1) + { + break; + } + } + + if (x>Width/2) + { + break; + } + + dis=PX_sqrt((x-r_x)*(x-r_x)+(y-r_y)*(y-r_y)); + if (disroundRaduis-linewidth-0.5f) + { + drawColor=color; + + if (dis>roundRaduis) + drawColor._argb.a=(px_uchar)(color._argb.a*(dis-roundRaduis+0.5f)); + + if (disHeight/2) + { + drawHeight=(px_int)roundRaduis-Height/2; + } + else + { + drawHeight=(px_int)roundRaduis; + } + if (drawHeight>linewidth) + { + drawHeight=drawlinewidth_int; + } + + if (Width>2*(px_int)roundRaduis) + { + drawWidth=Width-2*(px_int)roundRaduis; + if(drawWidth>0&&drawHeight>0) + { + PX_GeoDrawRect(psurface,left+(px_int)roundRaduis,top,left+(px_int)roundRaduis+drawWidth-1,top+drawHeight-1,color); + PX_GeoDrawRect(psurface,left+(px_int)roundRaduis,bottom-drawHeight+1,left+(px_int)roundRaduis+drawWidth-1,bottom,color); + } + } + + if(Height>2*(px_int)roundRaduis) + { + PX_GeoDrawRect(psurface,left,top+(px_int)roundRaduis,left+drawlinewidth_int-1,bottom-(px_int)roundRaduis,color); + PX_GeoDrawRect(psurface,right-drawlinewidth_int+1,top+(px_int)roundRaduis,right,bottom-(px_int)roundRaduis,color); + } +} + + +px_void PX_GeoDrawBezierCurvePoint(px_surface *rendersurface,px_point pt[],px_int pt_count,px_float t,px_float radius,px_color clr) +{ + px_int i; + + if (pt_count<=0) + { + return; + } + + if (pt_count==1) + { + if(rendersurface) + PX_GeoDrawPenCircle(rendersurface,pt[0].x,pt[0].y,radius,clr); + return; + } + + //update path + for (i=0;ipsurface->height-1) + { + y0=psurface->height-1; + } + if (y1>psurface->height-1) + { + y1=psurface->height-1; + } + PX_GeoDrawRect(psurface,x0,y0,x1,y1,color); + return; + } + + if (y0==y1) + { + if (x0<0) + { + x0=0; + } + if (x1<0) + { + x1=0; + } + if (x0>psurface->width-1) + { + x0=psurface->width-1; + } + if (x1>psurface->width-1) + { + x1=psurface->width-1; + } + PX_GeoDrawRect(psurface,x0,y0,x1,y1,color); + return; + } + + if (x0>x1) + { + lm=x0; + x0=x1; + x1=lm; + + lm=y0; + y0=y1; + y1=lm; + } + + k=((px_float)(y1-y0))/(x1-x0); + recK=1/k; + + //trim + trimLX=0-1; + trimRX=psurface->width+1; + trimTY=0-1; + trimBY=psurface->height+1; + + //calculate c + //TrimLX + fconst=y0-k*x0; + ftemp=trimLX*k+fconst; + + do + { + if (ftemp>=trimTY&&ftemp<=trimBY) + { + Cross2points[CrossCount].x=(px_float)trimLX; + Cross2points[CrossCount].y=ftemp; + CrossCount++; + } + + //TrimRX + ftemp=trimRX*k+fconst; + + if (ftemp>=trimTY&&ftemp<=trimBY) + { + Cross2points[CrossCount].x=(px_float)trimRX; + Cross2points[CrossCount].y=ftemp; + CrossCount++; + if (CrossCount==2) + { + break; + } + } + + //trimBY + ftemp=(trimBY-fconst)/k; + if (ftemp>trimLX&&ftemptrimLX&&ftempCross2points[1].x) + { + ftemp=Cross2points[0].x; + Cross2points[0].x=Cross2points[1].x; + Cross2points[1].x=ftemp; + + ftemp=Cross2points[0].y; + Cross2points[0].y=Cross2points[1].y; + Cross2points[1].y=ftemp; + } + + + if (x0Cross2points[1].x) + { + return; + } + + + if (x1Cross2points[1].x) + { + x1=(px_int)Cross2points[1].x; + y1=(px_int)Cross2points[1].y; + } + + if (x1==x0&&y1==y0) + { + return; + } + + + do + { + int dx = PX_ABS(x1-x0), sx = x0dy ? dx : -dy)/2, e2; + while(PX_TRUE) + { + PX_SurfaceDrawPixel(psurface,x0,y0,color); + if (x0==x1 && y0==y1) break; + e2 = err; + if (e2 >-dx) { err -= dy; x0 += sx; } + if (e2 < dy) { err += dx; y0 += sy; } + } + } while (0); + +} + +px_void PX_GeoDrawTriangle(px_surface *psurface,px_point2D p0,px_point2D p1,px_point2D p2,px_color color) +{ + px_int ix,iy; + px_bool k01infinite=PX_FALSE; + px_bool k02infinite=PX_FALSE; + px_bool k12infinite=PX_FALSE; + px_float k01,b01,k02,b02,k12,b12; + + px_float lAlpha=1,rAlpha=1; + + px_float x0; + px_float y0; + + px_float x1; + px_float y1; + + px_float x2; + px_float y2; + + + + px_float x, y, xleft, xright; + px_float btmy,midy; + + px_float a,b,c; + a=(px_float)PX_sqrtd((p1.x-p2.x)*(p1.x-p2.x)); + b=(px_float)PX_sqrtd((p0.x-p2.x)*(p0.x-p2.x)); + c=(px_float)PX_sqrtd((p1.x-p0.x)*(p1.x-p0.x)); + + x=(a*p0.x+b*p1.x+c*p2.x)/(a+b+c); + y=(a*p0.y+b*p1.y+c*p2.y)/(a+b+c); + + // p0 + // p1 p2 + + if (p1.ybtmy) + { + midy=p1.y; + btmy=p2.y; + } + + + + do + { + px_float x01m; + + x0=p0.x; + y0=p0.y; + x1=p1.x; + y1=p1.y; + x2=p2.x; + y2=p2.y; + + + if (x0==x1) + { + x01m=x0; + } + else + { + k01=(y0-y1)/(x0-x1); + b01=y0-k01*x0; + x01m=(y2-b01)/k01; + } + + if (x01m>x2) + { + px_point2D t; + t=p2; + p2=p1; + p1=t; + } + } while (0); + + + + x0=p0.x; + y0=p0.y; + + x1=p1.x; + y1=p1.y; + + x2=p2.x; + y2=p2.y; + + + k01infinite=PX_FALSE; + k02infinite=PX_FALSE; + k12infinite=PX_FALSE; + if (x0==x1) + { + k01infinite=PX_TRUE; + b01=x0; + } + else + { + k01=(y0-y1)/(x0-x1); + b01=y0-k01*x0; + } + + if (x0==x2) + { + k02infinite=PX_TRUE; + b02=x0; + } + else + { + k02=(y0-y2)/(x0-x2); + b02=y0-k02*x0; + } + + if (x1==x2) + { + k12infinite=PX_TRUE; + b12=x0; + } + else + { + k12=(y1-y2)/(x1-x2); + b12=y1-k12*x1; + } + + + for(y = (px_int)(y0+0.5f)+0.5f; y <=midy; y++) + { + if (k01infinite) + { + xleft=b01; + lAlpha=1; + } + else + { + xleft = (y-b01)/k01; + lAlpha=PX_ABS_FRAC(xleft); + } + + if (k02infinite) + { + xright=b02; + rAlpha=1; + } + else + { + xright = (y-b02)/k02; + rAlpha=PX_ABS_FRAC(xright); + } + + ix = (px_int)xleft; + iy=(px_int)y; + do + { + px_color aClr=color; + aClr._argb.a=(px_byte)(aClr._argb.a*lAlpha); + PX_SurfaceDrawPixel(psurface,ix,iy,color); + } while (0); + + for(ix = (px_int)xleft+1;ix < (px_int)xright; ++ix) + { + PX_SurfaceDrawPixel(psurface,ix,iy,color); + } + +// do +// { +// px_color aClr=color; +// aClr._argb.a=(px_byte)(aClr._argb.a*rAlpha); +// PX_SurfaceDrawPixel(psurface,ix,iy,color); +// } while (0); + } + + // p1 p2 + // p0 + if (p1.y>p0.y) + { + px_point2D t; + t=p1; + p1=p0; + p0=t; + } + + if (p2.y>p0.y) + { + px_point2D t; + t=p2; + p2=p0; + p0=t; + } + + btmy=p1.y; + midy=p2.y; + if (p2.yx2) + { + px_point2D t; + t=p2; + p2=p1; + p1=t; + } + } while (0); + + + + x0=p0.x; + y0=p0.y; + + x1=p1.x; + y1=p1.y; + + x2=p2.x; + y2=p2.y; + + + k01infinite=PX_FALSE; + k02infinite=PX_FALSE; + k12infinite=PX_FALSE; + if (x0==x1) + { + k01infinite=PX_TRUE; + b01=x0; + } + else + { + k01=(y0-y1)/(x0-x1); + b01=y0-k01*x0; + } + + if (x0==x2) + { + k02infinite=PX_TRUE; + b02=x0; + } + else + { + k02=(y0-y2)/(x0-x2); + b02=y0-k02*x0; + } + + if (x1==x2) + { + k12infinite=PX_TRUE; + b12=x0; + } + else + { + k12=(y1-y2)/(x1-x2); + b12=y1-k12*x1; + } + + + for(y = (px_int)(midy+0.5f)+0.5f; y < y0; y++) + { + if (k01infinite) + { + xleft=b01; + lAlpha=1; + } + else + { + xleft = (y-b01)/k01; + lAlpha=PX_ABS_FRAC(xleft); + } + + if (k02infinite) + { + xright=b02; + rAlpha=1; + } + else + { + xright = (y-b02)/k02; + rAlpha=PX_ABS_FRAC(xright); + } + + ix = (px_int)xleft; + iy=(px_int)y; + do + { + px_color aClr=color; + aClr._argb.a=(px_byte)(aClr._argb.a*lAlpha); + PX_SurfaceDrawPixel(psurface,ix,iy,color); + } while (0); + + for(ix = (px_int)xleft+1;ix < (px_int)xright; ++ix) + { + PX_SurfaceDrawPixel(psurface,ix,iy,color); + } + +// do +// { +// px_color aClr=color; +// aClr._argb.a=(px_byte)(aClr._argb.a*rAlpha); +// PX_SurfaceDrawPixel(psurface,ix,iy,color); +// } while (0); + } + +} + +px_void PX_GeoDrawArrow(px_surface *psurface,px_point2D p0,px_point2D p1,px_float size,px_color color) +{ + px_point2D p0_5,v,vn; + px_float arrowsize,distance; + + if (size<1) + { + return; + } + + arrowsize=size*5; + + + + //draw line + v=PX_Point2DNormalization(PX_Point2DSub(p1,p0)); + distance=PX_Point2DMod(PX_Point2DSub(p1,p0)); + distance-=arrowsize; + p0_5=PX_Point2DAdd(p0,PX_Point2DMul(v,distance)); + PX_GeoDrawLine(psurface,(px_int)p0.x,(px_int)p0.y,(px_int)p0_5.x,(px_int)p0_5.y,(px_int)size,color); + + //normal + vn.x=-v.y; + vn.y=v.x; + + PX_GeoDrawTriangle(psurface,p0_5,p1,PX_Point2DAdd(p0_5,PX_Point2DMul(vn,arrowsize)),color); + PX_GeoDrawTriangle(psurface,p0_5,p1,PX_Point2DAdd(p0_5,PX_Point2DMul(vn,-arrowsize)),color); +} + diff --git a/lib/PainterEngine/core/PX_BaseGeo.h b/lib/PainterEngine/core/PX_BaseGeo.h new file mode 100644 index 0000000000000000000000000000000000000000..c167dbf620a72a24fc04210666cc22230fb4c952 --- /dev/null +++ b/lib/PainterEngine/core/PX_BaseGeo.h @@ -0,0 +1,21 @@ +#ifndef PIXELSES_BASEGEO +#define PIXELSES_BASEGEO + +#include "PX_Surface.h" + +px_void PX_GeoDrawLine(px_surface *psurface, px_int x0, px_int y0, px_int x1, px_int y1 ,px_int lineWidth, px_color color); +px_void PX_GeoDrawBorder(px_surface *psurface, px_int left, px_int top, px_int right, px_int bottom ,px_int lineWidth,px_color color); +px_void PX_GeoDrawRect(px_surface *psurface, px_int left, px_int top, px_int right, px_int bottom,px_color color); +px_void PX_GeoDrawSolidCircle(px_surface *psurface, px_int x,px_int y,px_int Radius,px_color color ); +px_void PX_GeoDrawPenCircle(px_surface *psurface, px_float x,px_float y,px_float Radius,px_color color ); +px_void PX_GeoDrawPath(px_surface *psurface, px_point path[],px_int pathCount,px_float linewidth,px_color color); +px_void PX_GeoDrawCircle(px_surface *psurface,px_int x,px_int y,px_int Radius,px_int lineWidth,px_color color); +px_void PX_GeoDrawRing(px_surface *psurface, px_int x,px_int y,px_int Radius,px_int lineWidth,px_color color,px_int start_angle,px_int end_angle); +px_void PX_GeoDrawSector(px_surface *psurface, px_int x,px_int y,px_int Radius_outside,px_int Radius_inside,px_color color,px_int start_angle,px_int end_angle); +px_void PX_GeoDrawSolidRoundRect(px_surface *psurface, px_int left, px_int top, px_int right, px_int bottom,px_float roundRaduis,px_color color); +px_void PX_GeoDrawRoundRect(px_surface *psurface, px_int left, px_int top, px_int right, px_int bottom,px_float roundRaduis,px_float linewidth,px_color color); +px_void PX_GeoDrawBezierCurvePoint(px_surface *rendersurface,px_point pt[],px_int pt_count,px_float t,px_float radius,px_color clr); +px_void PX_GeoDrawBresenhamLine(px_surface *psurface,int x0, int y0, int x1, int y1,px_color clr); +px_void PX_GeoDrawTriangle(px_surface *psurface,px_point2D p0,px_point2D p1,px_point2D p2,px_color color); +px_void PX_GeoDrawArrow(px_surface *psurface,px_point2D p0,px_point2D p1,px_float size,px_color color); +#endif diff --git a/lib/PainterEngine/core/PX_Bitmap.c b/lib/PainterEngine/core/PX_Bitmap.c new file mode 100644 index 0000000000000000000000000000000000000000..a84fefe2d9143e278fa45453c1548aaf1fff3467 --- /dev/null +++ b/lib/PainterEngine/core/PX_Bitmap.c @@ -0,0 +1,331 @@ +#include "PX_Bitmap.h" + +px_uint PX_BitmapGetHeight( void *BitmapBuffer ) +{ + return (px_dword)(*(px_dword *)((px_char *)BitmapBuffer+22)); +} + +px_uint PX_BitmapGetWidth( void *BitmapBuffer ) +{ + return (px_dword)(*(px_dword *)((px_char *)BitmapBuffer+18)); +} + +px_word PX_BitmapGetBitCount( void *BitmapBuffer ) +{ + return (px_word)(*(px_word *)((px_char *)BitmapBuffer+28)); +} + +px_dword PX_BitmapGetDataOffset(void *BitmapBuffer) +{ + return (px_dword)(*(px_dword *)((px_char *)BitmapBuffer+10)); +} + +px_void PX_BitmapRender(px_surface *psurface, void *BitmapBuffer,px_int BufferSize,px_int x,px_int y ) +{ + px_int i,j; + px_int Height; + px_int Width; + px_int RowBytes; + px_word bitCount; + px_char *ByteColor; + PX_BITMAP_RGB32 *rgb32; + PX_BITMAP_RGB24 *rgb24; + px_word *rgb16; + px_color PXcolor32; + if (x>psurface->width||y>psurface->height) + { + return; + } + + Height=PX_BitmapGetHeight(BitmapBuffer); + Width=PX_BitmapGetWidth(BitmapBuffer); + bitCount=PX_BitmapGetBitCount(BitmapBuffer); + if (Height>0) + { + if (x<-Width||y<-Height) + { + return; + } + } + else + { + if (x<-Width||yBufferSize-(px_int)PX_BitmapGetDataOffset(BitmapBuffer)) + { + return; + } + if(Height>0) + { + for (i=0;iBufferSize-(px_int)PX_BitmapGetDataOffset(BitmapBuffer)) + { + return; + } + if(Height>0) + { + for (i=0;iwidth&&i+yheight) + PX_SurfaceSetPixel(psurface,j+x,i+y,PXcolor32); + } + } + } + else + { + for (i=0;i<-Height;i++) + { + rgb24=(PX_BITMAP_RGB24 *)(ByteColor+RowBytes*(i)); + for (j=0;j0&&i+y>0&&j+xwidth&&i+yheight) + PX_SurfaceSetPixel(psurface,j+x,i+y,PXcolor32); + } + } + } + return; + } + + //16bit Color for R5G6B5 + if(bitCount==16) + { + //Translate buffer as format + rgb16=(px_word *)ByteColor; + if((Width*2)%4) + RowBytes=Width*2+4-((Width*2)%4); + else + RowBytes=Width*2; + + if (Height*RowBytes>BufferSize-(px_int)PX_BitmapGetDataOffset(BitmapBuffer)) + { + return; + } + if(Height>0) + { + for (i=0;i>5)&0x1F) *255)/31; + PXcolor32._argb.r=(((rgb16[j]>>10)&0x1F)*255)/31; + if(j+x>0&&i+y>0&&j+xwidth&&i+yheight) + PX_SurfaceSetPixel(psurface,j+x,i+y,PXcolor32); + } + } + } + else + { + for (i=0;i<-Height;i++) + { + rgb16=(px_word *)(ByteColor+RowBytes*(i)); + for (j=0;j>5)&0x1F) *255)/31; + PXcolor32._argb.r=(((rgb16[j]>>10)&0x1F)*255)/31; + if(j+x>0&&i+y>0&&j+xwidth&&i+yheight) + PX_SurfaceSetPixel(psurface,j+x,i+y,PXcolor32); + } + } + } + return; + } + + //Other bit format is no support + return; +} + +px_bool PX_BitmapVerify(void *BitmapBuffer,px_int BufferSize) +{ + + px_int Height; + px_int Width; + px_int RowBytes; + px_word bitCount; + + if (BufferSize<54) + { + return PX_FALSE; + } + if (((px_char *)BitmapBuffer)[0]!='B') + { + return PX_FALSE; + } + + if (((px_char *)BitmapBuffer)[1]!='M') + { + return PX_FALSE; + } + + + Height=PX_BitmapGetHeight(BitmapBuffer); + Width=PX_BitmapGetWidth(BitmapBuffer); + bitCount=PX_BitmapGetBitCount(BitmapBuffer); + + //32bit Color for A8R8G8B8(X8R8G8B8) + if(bitCount==32) + { + if (Height*Width>BufferSize-(px_int)PX_BitmapGetDataOffset(BitmapBuffer)) + { + return PX_FALSE; + } + } + + + //24bit Color for R8G8B8 + if(bitCount==24) + { + //Translate buffer as format + + if((Width*3)%4) + RowBytes=Width*3+4-((Width*3)%4); + else + RowBytes=Width*3; + + if (Height*RowBytes>BufferSize-(px_int)PX_BitmapGetDataOffset(BitmapBuffer)) + { + return PX_FALSE; + } + } + + //16bit Color for R5G6B5 + if(bitCount==16) + { + //Translate buffer as format + if((Width*2)%4) + RowBytes=Width*2+4-((Width*2)%4); + else + RowBytes=Width*2; + + if (Height*RowBytes>BufferSize-(px_int)PX_BitmapGetDataOffset(BitmapBuffer)) + { + return PX_FALSE; + } + } + + return PX_TRUE; +} + +px_bool PX_BitmapBuild(px_surface *psurface,px_char *BitmapBuffer,px_int *size) +{ + px_int _outsize,x,y,rowAppendSize; + PX_BITMAPFILEHEADER fileheader; + PX_BITMAPINFOHEADER infoheader; + PX_BITMAP_RGB24 *pdata; + + rowAppendSize=psurface->width%4; + + + _outsize=psurface->height*psurface->width*3+sizeof(PX_BITMAPFILEHEADER)+sizeof(PX_BITMAPINFOHEADER)+rowAppendSize*psurface->height; + + *size=_outsize; + if (BitmapBuffer) + { + px_dword bfoftsize=sizeof(PX_BITMAPFILEHEADER)+sizeof(PX_BITMAPINFOHEADER); + fileheader.bfType[0]='B'; + fileheader.bfType[1]='M'; + PX_memcpy(fileheader.bfSize,&_outsize,4); + fileheader.bfReserbed[0]=0; + fileheader.bfReserbed[1]=0; + fileheader.bfReserbed[2]=0; + fileheader.bfReserbed[3]=0; + PX_memcpy(fileheader.bfOffbits,&bfoftsize,4); + + infoheader.biBitCount=24; + infoheader.biClrImportant=0; + infoheader.biClrUsed=0; + infoheader.biCompression=0; + infoheader.biHeight=psurface->height; + infoheader.biWidth=psurface->width; + infoheader.biPlanes=1; + infoheader.biSize=40; + infoheader.biSizeImage=psurface->height*psurface->width*3; + infoheader.biXPelsPerMeter=2834; + infoheader.biYPelsPerMeter=2834; + + PX_memcpy(BitmapBuffer,&fileheader,sizeof(fileheader)); + PX_memcpy(BitmapBuffer+14,&infoheader,sizeof(infoheader)); + + pdata=(PX_BITMAP_RGB24 *)(BitmapBuffer+sizeof(PX_BITMAPFILEHEADER)+sizeof(PX_BITMAPINFOHEADER)); + for (y=psurface->height-1;y>=0;y--) + { + for (x=0;xwidth;x++) + { + (*pdata).R=(px_char)(PX_SURFACECOLOR(psurface,x,y)._argb.r*PX_SURFACECOLOR(psurface,x,y)._argb.a/256); + (*pdata).G= (px_char)(PX_SURFACECOLOR(psurface,x,y)._argb.g*PX_SURFACECOLOR(psurface,x,y)._argb.a/256); + (*pdata).B= (px_char)(PX_SURFACECOLOR(psurface,x,y)._argb.b*PX_SURFACECOLOR(psurface,x,y)._argb.a/256); + pdata++; + } + pdata=(PX_BITMAP_RGB24 *)(((px_char *)pdata)+rowAppendSize); + } + return PX_TRUE; + } + else + return PX_TRUE; +} diff --git a/lib/PainterEngine/core/PX_Bitmap.h b/lib/PainterEngine/core/PX_Bitmap.h new file mode 100644 index 0000000000000000000000000000000000000000..a33d472d3463ea19c07ab6bcde8f4e02dce7491d --- /dev/null +++ b/lib/PainterEngine/core/PX_Bitmap.h @@ -0,0 +1,66 @@ +#ifndef PIXELSES_BITMAP +#define PIXELSES_BITMAP + +#include "PX_Surface.h" + +typedef struct PX_BITMAPFILEHEADER { + px_char bfType[2]; //Must be "BM" offset 0-1 + px_char bfSize[4]; //offset 2-5 + px_char bfReserbed[4]; //offset 6-13 + px_uchar bfOffbits[4]; +} PX_BITMAPFILEHEADER; //14 Byte + +typedef struct PX_BITMAPINFOHEADER{ + px_dword biSize; //offset 14-17 + px_dword biWidth; //offset 18-21 + px_dword biHeight; //offset 22-25 + px_word biPlanes; //offset 26-27 + px_word biBitCount; //offset 28-29 + px_dword biCompression; + px_dword biSizeImage; + px_dword biXPelsPerMeter; + px_dword biYPelsPerMeter; + px_dword biClrUsed; + px_dword biClrImportant; +} PX_BITMAPINFOHEADER; + +typedef struct PX_BITMAP_tagRBG24 +{ + px_char B; + px_char G; + px_char R; +}PX_BITMAP_RGB24; + +typedef struct PX_BITMAP_tagRBG32 +{ + px_char B; + px_char G; + px_char R; + px_char A; +}PX_BITMAP_RGB32; + +//Bitmap Verify +px_bool PX_BitmapVerify(void *BitmapBuffer,px_int size); + +//Get bitmap height +px_uint PX_BitmapGetHeight(void *BitmapBuffer); +//Get bitmap width +px_uint PX_BitmapGetWidth(void *BitmapBuffer); +//Get bitmap BitCount +px_word PX_BitmapGetBitCount(void *BitmapBuffer); +////////////////////////////////////////////////////////////////////////// +// Draw bitmap to panel +// param:void *BitmapBuffer -Point to buffer of bitmap +// param:int x -Offset of X +// param:int y -Offset of Y +///////////////////////////////////////////////////////////////////////// +px_void PX_BitmapRender(px_surface *psurface,void *BitmapBuffer,px_int BufferSize,int x,int y); + +////////////////////////////////////////////////////////////////////////// +// build bitmap from surface +// param:px_memory *BitmapBuffer -Pointer of px_buffer to save bmpfile data +///////////////////////////////////////////////////////////////////////// + +px_bool PX_BitmapBuild(px_surface *psurface,px_char *BitmapBuffer,px_int *size); + +#endif diff --git a/lib/PainterEngine/core/PX_Core.h b/lib/PainterEngine/core/PX_Core.h new file mode 100644 index 0000000000000000000000000000000000000000..f69455c0265eb403546011bc627c5ce4f919bba5 --- /dev/null +++ b/lib/PainterEngine/core/PX_Core.h @@ -0,0 +1,40 @@ +////////////////////////////////////////////////////////////////////////// +/* + PainterEngine Core + (C)2019 DBinary + + This program is free software; you can redistribute it and/or modify + it under the terms of the BSD General Public License +*/ +////////////////////////////////////////////////////////////////////////// + +#ifndef __PX_CORE_H +#define __PX_CORE_H +#include "PX_Texture.h" +#include "PX_BaseGeo.h" +#include "PX_Font.h" +#include "PX_String.h" +#include "PX_Memory.h" +#include "PX_Hashmap.h" +#include "PX_Vector.h" +#include "PX_List.h" +#include "PX_AES.h" +#include "PX_ANN.h" +#include "PX_Sound.h" +#include "PX_Effect.h" +#include "PX_Quicksort.h" +#include "PX_Quadtree.h" +#include "PX_curve25519.h" +#include "PX_Sha256.h" +#include "PX_Arle.h" +#include "PX_Huffman.h" +#include "PX_Packet.h" +#include "PX_Base64.h" +#include "PX_3D.h" +#include "PX_PointsMesh.h" +#include "PX_MFCC.h" +#include "PX_KalmanFilter.h" +#include "PX_ImageFilter.h" +#include "PX_Linker.h" +#include "PX_Tuning.h" +#endif diff --git a/lib/PainterEngine/core/PX_Delaunay.c b/lib/PainterEngine/core/PX_Delaunay.c new file mode 100644 index 0000000000000000000000000000000000000000..4d9f25702ab2cc537a4df16699a799b420aa0024 --- /dev/null +++ b/lib/PainterEngine/core/PX_Delaunay.c @@ -0,0 +1,513 @@ +#include "PX_Delaunay.h" +#include "PX_Quicksort.h" + + +typedef enum +{ + PX_DELAUNAY_ROUND_TEST_INSIDE, + PX_DELAUNAY_ROUND_TEST_OUTSIDE, + PX_DELAUNAY_ROUND_TEST_DELAUNAY, +}PX_DELAUNAY_ROUND_TEST; + +px_bool PX_DelaunaryVerifyCircle(px_point2D pt[],px_int p1,px_int p2,px_int p3) +{ + if (pt[p1].x==pt[p2].x&&pt[p1].x==pt[p3].x) + { + return PX_FALSE; + } + if ((pt[p1].y-pt[p2].y)/(pt[p1].x-pt[p2].x)==(pt[p1].y-pt[p3].y)/(pt[p1].x-pt[p3].x)) + { + return PX_FALSE; + } + return PX_TRUE; +} + +PX_DELAUNAY_ROUND_TEST PX_DelaunaryTest(px_point2D pt_array[],px_int testIndex,PX_Delaunay_Triangle triangle) +{ + px_float x,y,r; + px_float x1,x2,x3,y1,y2,y3; + px_float testx,testy; + px_float d; + x1=pt_array[triangle.index1].x; + y1=pt_array[triangle.index1].y; + + x2=pt_array[triangle.index2].x; + y2=pt_array[triangle.index2].y; + + + x3=pt_array[triangle.index3].x; + y3=pt_array[triangle.index3].y; + + testx=pt_array[testIndex].x; + testy=pt_array[testIndex].y; + + x=((y2-y1)*(y3*y3-y1*y1+x3*x3-x1*x1)-(y3-y1)*(y2*y2-y1*y1+x2*x2-x1*x1))/(2.0f*((x3-x1)*(y2-y1)-(x2-x1)*(y3-y1))); + y=((x2-x1)*(x3*x3-x1*x1+y3*y3-y1*y1)-(x3-x1)*(x2*x2-x1*x1+y2*y2-y1*y1))/(2.0f*((y3-y1)*(x2-x1)-(y2-y1)*(x3-x1))); + r=PX_sqrt((x1-x)*(x1-x)+(y1-y)*(y1-y)); + + d=((testx-x)*(testx-x)+(testy-y)*(testy-y)); + + if (d>r*r) + { + if (testx>x+r) + { + return PX_DELAUNAY_ROUND_TEST_DELAUNAY; + } + else + { + return PX_DELAUNAY_ROUND_TEST_OUTSIDE; + } + } + else + { + return PX_DELAUNAY_ROUND_TEST_INSIDE; + } +} + +px_bool PX_DelaunaryTriangleNeighbor(PX_Delaunay_Triangle *t1,PX_Delaunay_Triangle *t2) +{ + px_int c1_3[3]; + px_int c2_3[3]; + px_int i,j,k=0; + c1_3[0]=t1->index1; + c1_3[1]=t1->index2; + c1_3[2]=t1->index3; + + c2_3[0]=t2->index1; + c2_3[1]=t2->index2; + c2_3[2]=t2->index3; + + for (i=0;i<3;i++) + { + for (j=0;j<3;j++) + { + if (c1_3[i]==c2_3[j]) + { + k++; + } + } + } + return k==2; +} + +px_void PX_DelaunaryTriangleSwitch(PX_Delaunay_Triangle *t1,PX_Delaunay_Triangle *t2) +{ + px_int c1_3[3]; + px_int c2_3[3]; + px_int c[3],d[3]; + px_int j,k; + c1_3[0]=t1->index1; + c1_3[1]=t1->index2; + c1_3[2]=t1->index3; + + c2_3[0]=t2->index1; + c2_3[1]=t2->index2; + c2_3[2]=t2->index3; + + j=0;k=0; + if (c1_3[0]==c2_3[0]||c1_3[0]==c2_3[1]||c1_3[0]==c2_3[2]) + { + c[j]=c1_3[0]; + j++; + } + else + { + d[k]=c1_3[0]; + k++; + } + + if (c1_3[1]==c2_3[0]||c1_3[1]==c2_3[1]||c1_3[1]==c2_3[2]) + { + c[j]=c1_3[1]; + j++; + } + else + { + d[k]=c1_3[1]; + k++; + } + + if (c1_3[2]==c2_3[0]||c1_3[2]==c2_3[1]||c1_3[2]==c2_3[2]) + { + c[j]=c1_3[2]; + j++; + } + else + { + d[k]=c1_3[2]; + k++; + } + + if (c2_3[0]!=c1_3[0]&&c2_3[0]!=c1_3[1]&&c2_3[0]!=c1_3[2]) + { + d[k]=c2_3[0]; + } + + if (c2_3[1]!=c1_3[0]&&c2_3[1]!=c1_3[1]&&c2_3[1]!=c1_3[2]) + { + d[k]=c2_3[1]; + } + + if (c2_3[2]!=c1_3[0]&&c2_3[2]!=c1_3[1]&&c2_3[2]!=c1_3[2]) + { + d[k]=c2_3[2]; + } + + t1->index1=c[0]; + t1->index2=d[1]; + t1->index3=d[2]; + + t2->index1=c[1]; + t2->index2=d[1]; + t2->index3=d[2]; + +} + +px_bool PX_DelaunaryPointsBuild(px_memorypool *mp,px_point2D pt[],px_int count,px_vector *out_triangles,PX_DELAUNAY_RETURN_TYPE type) +{ + + PX_QuickSortAtom *pAtoms; + px_point2D *sortPt; + px_int *mapPt; + //edge + px_float minx,miny,maxx,maxy=0; + px_int i,j; + px_vector edges; + px_vector triangles; + px_vector DelaunaryTriangle; + + + PX_VectorInitialize(mp,&triangles,sizeof(PX_Delaunay_Triangle),1); + PX_VectorInitialize(mp,&DelaunaryTriangle,sizeof(PX_Delaunay_Triangle),1); + PX_VectorInitialize(mp,&edges,sizeof(PX_Delaunay_Edge),1); + + pAtoms=(PX_QuickSortAtom *)MP_Malloc(mp,sizeof(PX_QuickSortAtom)*count); + sortPt=(px_point2D *)MP_Malloc(mp,sizeof(px_point2D)*(count+3)); + mapPt=(px_int *)MP_Malloc(mp,sizeof(px_int)*(count)); + + if (!pAtoms) + { + return PX_FALSE; + } + for (i=0;imaxy) + { + maxy=sortPt[i].y; + } + + if (sortPt[i].yindex1==pCompareEdge->index1&&pEdge->index2==pCompareEdge->index2) + { + PX_VectorErase(&edges,k); + k--; + bremove=PX_TRUE; + } + if (pEdge->index1==pCompareEdge->index2&&pEdge->index2==pCompareEdge->index1) + { + PX_VectorErase(&edges,k); + k--; + bremove=PX_TRUE; + } + } + if (bremove) + { + PX_VectorErase(&edges,j); + j--; + } + } + + //generate triangles + for (j=0;jindex1,pEdge->index2)) + { + gtrianle.index1=i; + gtrianle.index2=pEdge->index1; + gtrianle.index3=pEdge->index2; + + PX_VectorPushback(&triangles,>rianle); + } + } + } + + for (i=0;iindex1-count>=0) + { + k++; + } + if (pTriangle->index2-count>=0) + { + k++; + } + if (pTriangle->index3-count>=0) + { + k++; + } + if (k==1) + { + PX_VectorPushback(&sortTriangles,&pTriangle); + } + } + + index=0; + + while (indexindex1!=pTriangle2->index1&&pTriangle1->index1!=pTriangle2->index2&&pTriangle1->index1!=pTriangle2->index3) + pA=pTriangle1->index1; + else + if(pTriangle1->index2!=pTriangle2->index1&&pTriangle1->index2!=pTriangle2->index2&&pTriangle1->index2!=pTriangle2->index3) + pA=pTriangle1->index2; + else + pA=pTriangle1->index3; + + if(pTriangle2->index1!=pTriangle1->index1&&pTriangle2->index1!=pTriangle1->index2&&pTriangle2->index1!=pTriangle1->index3) + pB=pTriangle2->index1; + else + if(pTriangle2->index2!=pTriangle1->index1&&pTriangle2->index2!=pTriangle1->index2&&pTriangle2->index2!=pTriangle1->index3) + pB=pTriangle2->index2; + else + pB=pTriangle2->index3; + + if(pTriangle1->index1-count>=0) + pC=pTriangle1->index1; + + if(pTriangle1->index2-count>=0) + pC=pTriangle1->index2; + + if(pTriangle1->index3-count>=0) + pC=pTriangle1->index3; + + + if(pTriangle1->index1-count<0&&pTriangle1->index1!=pA) + pO=pTriangle1->index1; + + if(pTriangle1->index2-count<0&&pTriangle1->index2!=pA) + pO=pTriangle1->index2; + + if(pTriangle1->index3-count<0&&pTriangle1->index3!=pA) + pO=pTriangle1->index3; + + t1v.x=sortPt[pO].x-sortPt[pA].x; + t1v.y=sortPt[pO].y-sortPt[pA].y; + t1v.z=0; + + t2v.x=sortPt[pB].x-sortPt[pO].x; + t2v.y=sortPt[pB].y-sortPt[pO].y; + t2v.z=0; + + t3v.x=sortPt[pC].x-sortPt[pB].x; + t3v.y=sortPt[pC].y-sortPt[pB].y; + t3v.z=0; + + if (PX_PointCross(t1v,t2v).z*PX_PointCross(t2v,t3v).z>0) + { + pTriangle1->index1=pC; + pTriangle1->index2=pA; + pTriangle1->index3=pB; + + pTriangle2->index1=pO; + pTriangle2->index2=pA; + pTriangle2->index3=pB; + + + PX_VectorErase(&sortTriangles,i); + index=-1; + break; + } + } + } + index++; + } + PX_VectorFree(&sortTriangles); + } while (0); + + + + for (i=0;iindex1-count>=0||pTriangle->index2-count>=0||pTriangle->index3-count>=0) + { + PX_VectorErase(&DelaunaryTriangle,i); + i--; + } + else + { + switch (type) + { + case PX_DELAUNAY_RETURN_TYPE_TRIANGLE: + { + px_triangle dtriangle; + dtriangle.Vertex_1.x=sortPt[pTriangle->index1].x; + dtriangle.Vertex_1.y=sortPt[pTriangle->index1].y; + dtriangle.Vertex_1.z=0; + + dtriangle.Vertex_2.x=sortPt[pTriangle->index2].x; + dtriangle.Vertex_2.y=sortPt[pTriangle->index2].y; + dtriangle.Vertex_2.z=0; + + dtriangle.Vertex_3.x=sortPt[pTriangle->index3].x; + dtriangle.Vertex_3.y=sortPt[pTriangle->index3].y; + dtriangle.Vertex_3.z=0; + + PX_VectorPushback(out_triangles,&dtriangle); + } + break; + case PX_DELAUNAY_RETURN_TYPE_TRIANGLE_INDEX: + { + PX_Delaunay_Triangle mapTriangleIndex; + mapTriangleIndex.index1=mapPt[pTriangle->index1]; + mapTriangleIndex.index2=mapPt[pTriangle->index2]; + mapTriangleIndex.index3=mapPt[pTriangle->index3]; + PX_VectorPushback(out_triangles,&mapTriangleIndex); + } + break; + default: + break; + } + + } + } + + PX_VectorFree(&triangles); + PX_VectorFree(&DelaunaryTriangle); + PX_VectorFree(&edges); + MP_Free(mp,mapPt); + MP_Free(mp,sortPt); + return PX_TRUE; +} + diff --git a/lib/PainterEngine/core/PX_Delaunay.h b/lib/PainterEngine/core/PX_Delaunay.h new file mode 100644 index 0000000000000000000000000000000000000000..c1f21cffdc9c2e49ce39ff4fb1d70706c85cc241 --- /dev/null +++ b/lib/PainterEngine/core/PX_Delaunay.h @@ -0,0 +1,25 @@ +#ifndef PX_DELAUNAY_H +#define PX_DELAUNAY_H +#include "PX_3D.h" + +typedef struct +{ + px_int index1; + px_int index2; +}PX_Delaunay_Edge; + +typedef struct +{ + px_int index1; + px_int index2; + px_int index3; +}PX_Delaunay_Triangle; + +typedef enum +{ + PX_DELAUNAY_RETURN_TYPE_TRIANGLE, + PX_DELAUNAY_RETURN_TYPE_TRIANGLE_INDEX, +}PX_DELAUNAY_RETURN_TYPE; +px_bool PX_DelaunaryPointsBuild(px_memorypool *mp,px_point2D pt[],px_int count,px_vector *out_triangles,PX_DELAUNAY_RETURN_TYPE type); + +#endif diff --git a/lib/PainterEngine/core/PX_Effect.c b/lib/PainterEngine/core/PX_Effect.c new file mode 100644 index 0000000000000000000000000000000000000000..8f19c142049113e1ca9de894d7ec5069e10b20fe --- /dev/null +++ b/lib/PainterEngine/core/PX_Effect.c @@ -0,0 +1,89 @@ +#include "PX_Effect.h" + + + +px_bool PX_EffectShine(px_surface *s,px_int radius,px_color color,px_float intension) +{ + px_int x,y,sampleX,sampleY; + px_surface ns; + px_int alpha; + px_color bindColor; + if(!PX_SurfaceCreate(s->MP,s->width,s->height,&ns)) + return PX_FALSE; + + for(y=0;yheight;y++) + for (x=0;xwidth;x++) + { + if(PX_SurfaceGetPixel(s,x,y)._argb.a==0) + { + alpha=0; + for (sampleY=y-radius;sampleY<=y+radius;sampleY++) + { + for (sampleX=x-radius;sampleX<=x+radius;sampleX++) + { + if(sampleX>=0&&sampleXwidth&&sampleY>=0&&sampleY<=s->height-1) + alpha+=PX_SurfaceGetPixel(s,sampleX,sampleY)._argb.a; + } + } + alpha/=((radius*2-1)*(radius*2-1)); + alpha=(px_int)(alpha*intension); + alpha=alpha>255?255:alpha; + bindColor=color; + if(alpha!=0) + { + bindColor._argb.a=(px_uchar)alpha; + PX_SurfaceSetPixel(&ns,x,y,bindColor); + } + } + else + { + PX_SurfaceSetPixel(&ns,x,y,PX_SurfaceGetPixel(s,x,y)); + } + } + PX_memcpy(s->surfaceBuffer,ns.surfaceBuffer,s->width*s->height*sizeof(px_color)); + PX_SurfaceFree(&ns); + return PX_TRUE; +} + +px_bool PX_EffectOutline(px_surface *s,px_int radius,px_color color) +{ + px_int x,y,sampleX,sampleY; + px_surface ns; + px_int alpha; + px_color bindColor; + if(!PX_SurfaceCreate(s->MP,s->width,s->height,&ns)) + return PX_FALSE; + + for(y=0;yheight;y++) + for (x=0;xwidth;x++) + { + if(PX_SurfaceGetPixel(s,x,y)._argb.a==0) + { + alpha=0; + for (sampleY=y-radius;sampleY<=y+radius;sampleY++) + { + for (sampleX=x-radius;sampleX<=x+radius;sampleX++) + { + if(sampleX>=0&&sampleXwidth&&sampleY>=0&&sampleY<=s->height-1) + alpha+=PX_SurfaceGetPixel(s,sampleX,sampleY)._argb.a; + } + } + alpha/=((radius*2-1)*(radius-1)); + alpha=alpha>255?255:alpha; + bindColor=color; + if(alpha!=0) + { + bindColor._argb.a= (px_uchar)alpha; + PX_SurfaceSetPixel(&ns,x,y,bindColor); + } + } + else + { + PX_SurfaceSetPixel(&ns,x,y,PX_SurfaceGetPixel(s,x,y)); + } + + } + PX_memcpy(s->surfaceBuffer,ns.surfaceBuffer,s->width*s->height*sizeof(px_color)); + PX_SurfaceFree(&ns); + return PX_TRUE; +} diff --git a/lib/PainterEngine/core/PX_Effect.h b/lib/PainterEngine/core/PX_Effect.h new file mode 100644 index 0000000000000000000000000000000000000000..e16286d8684222c2546ecb2f3138f6cdb3a35b87 --- /dev/null +++ b/lib/PainterEngine/core/PX_Effect.h @@ -0,0 +1,7 @@ +#ifndef PX_EFFECT_H +#define PX_EFFECT_H +#include "PX_Surface.h" + +px_bool PX_EffectShine(px_surface *s,px_int radius,px_color color,px_float intension); +px_bool PX_EffectOutline(px_surface *s,px_int radius,px_color color); +#endif diff --git a/lib/PainterEngine/core/PX_Font.c b/lib/PainterEngine/core/PX_Font.c new file mode 100644 index 0000000000000000000000000000000000000000..e8e0809b88e6b5f314b00c48b3690da7a878ddac --- /dev/null +++ b/lib/PainterEngine/core/PX_Font.c @@ -0,0 +1,750 @@ + +#include "PX_Font.h" + +static px_uchar const AsciiLib[95][16] = { + {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*" ",0*/ + + {0x00,0x00,0x00,0x18,0x3C,0x3C,0x3C,0x18,0x18,0x00,0x18,0x18,0x00,0x00,0x00,0x00},/*"!",1*/ + + {0x00,0x00,0x00,0x66,0x66,0x66,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*""",2*/ + + {0x00,0x00,0x00,0x36,0x36,0x7F,0x36,0x36,0x36,0x7F,0x36,0x36,0x00,0x00,0x00,0x00},/*"#",3*/ + + {0x00,0x18,0x18,0x3C,0x66,0x60,0x30,0x18,0x0C,0x06,0x66,0x3C,0x18,0x18,0x00,0x00},/*"$",4*/ + + {0x00,0x00,0x70,0xD8,0xDA,0x76,0x0C,0x18,0x30,0x6E,0x5B,0x1B,0x0E,0x00,0x00,0x00},/*"%",5*/ + + {0x00,0x00,0x00,0x38,0x6C,0x6C,0x38,0x60,0x6F,0x66,0x66,0x3B,0x00,0x00,0x00,0x00},/*"&",6*/ + + {0x00,0x00,0x00,0x18,0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"'",7*/ + + {0x00,0x00,0x00,0x0C,0x18,0x18,0x30,0x30,0x30,0x30,0x30,0x18,0x18,0x0C,0x00,0x00},/*"(",8*/ + + {0x00,0x00,0x00,0x30,0x18,0x18,0x0C,0x0C,0x0C,0x0C,0x0C,0x18,0x18,0x30,0x00,0x00},/*")",9*/ + + {0x00,0x00,0x00,0x00,0x00,0x36,0x1C,0x7F,0x1C,0x36,0x00,0x00,0x00,0x00,0x00,0x00},/*"*",10*/ + + {0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x7E,0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00},/*"+",11*/ + + {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x1C,0x0C,0x18,0x00,0x00},/*",",12*/ + + {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"-",13*/ + + {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x1C,0x00,0x00,0x00,0x00},/*".",14*/ + + {0x00,0x00,0x00,0x06,0x06,0x0C,0x0C,0x18,0x18,0x30,0x30,0x60,0x60,0x00,0x00,0x00},/*"/",15*/ + + {0x00,0x00,0x00,0x1E,0x33,0x37,0x37,0x33,0x3B,0x3B,0x33,0x1E,0x00,0x00,0x00,0x00},/*"0",16*/ + + {0x00,0x00,0x00,0x0C,0x1C,0x7C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x00,0x00,0x00,0x00},/*"1",17*/ + + {0x00,0x00,0x00,0x3C,0x66,0x66,0x06,0x0C,0x18,0x30,0x60,0x7E,0x00,0x00,0x00,0x00},/*"2",18*/ + + {0x00,0x00,0x00,0x3C,0x66,0x66,0x06,0x1C,0x06,0x66,0x66,0x3C,0x00,0x00,0x00,0x00},/*"3",19*/ + + {0x00,0x00,0x00,0x30,0x30,0x36,0x36,0x36,0x66,0x7F,0x06,0x06,0x00,0x00,0x00,0x00},/*"4",20*/ + + {0x00,0x00,0x00,0x7E,0x60,0x60,0x60,0x7C,0x06,0x06,0x0C,0x78,0x00,0x00,0x00,0x00},/*"5",21*/ + + {0x00,0x00,0x00,0x1C,0x18,0x30,0x7C,0x66,0x66,0x66,0x66,0x3C,0x00,0x00,0x00,0x00},/*"6",22*/ + + {0x00,0x00,0x00,0x7E,0x06,0x0C,0x0C,0x18,0x18,0x30,0x30,0x30,0x00,0x00,0x00,0x00},/*"7",23*/ + + {0x00,0x00,0x00,0x3C,0x66,0x66,0x76,0x3C,0x6E,0x66,0x66,0x3C,0x00,0x00,0x00,0x00},/*"8",24*/ + + {0x00,0x00,0x00,0x3C,0x66,0x66,0x66,0x66,0x3E,0x0C,0x18,0x38,0x00,0x00,0x00,0x00},/*"9",25*/ + + {0x00,0x00,0x00,0x00,0x00,0x1C,0x1C,0x00,0x00,0x00,0x1C,0x1C,0x00,0x00,0x00,0x00},/*":",26*/ + + {0x00,0x00,0x00,0x00,0x00,0x1C,0x1C,0x00,0x00,0x00,0x1C,0x1C,0x0C,0x18,0x00,0x00},/*";",27*/ + + {0x00,0x00,0x00,0x06,0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x06,0x00,0x00,0x00,0x00},/*"<",28*/ + + {0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"=",29*/ + + {0x00,0x00,0x00,0x60,0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x60,0x00,0x00,0x00,0x00},/*">",30*/ + + {0x00,0x00,0x00,0x3C,0x66,0x66,0x0C,0x18,0x18,0x00,0x18,0x18,0x00,0x00,0x00,0x00},/*"?",31*/ + + {0x00,0x00,0x00,0x7E,0xC3,0xC3,0xCF,0xDB,0xDB,0xCF,0xC0,0x7F,0x00,0x00,0x00,0x00},/*"@",32*/ + + {0x00,0x00,0x00,0x18,0x3C,0x66,0x66,0x66,0x7E,0x66,0x66,0x66,0x00,0x00,0x00,0x00},/*"A",33*/ + + {0x00,0x00,0x00,0x7C,0x66,0x66,0x66,0x7C,0x66,0x66,0x66,0x7C,0x00,0x00,0x00,0x00},/*"B",34*/ + + {0x00,0x00,0x00,0x3C,0x66,0x66,0x60,0x60,0x60,0x66,0x66,0x3C,0x00,0x00,0x00,0x00},/*"C",35*/ + + {0x00,0x00,0x00,0x78,0x6C,0x66,0x66,0x66,0x66,0x66,0x6C,0x78,0x00,0x00,0x00,0x00},/*"D",36*/ + + {0x00,0x00,0x00,0x7E,0x60,0x60,0x60,0x7C,0x60,0x60,0x60,0x7E,0x00,0x00,0x00,0x00},/*"E",37*/ + + {0x00,0x00,0x00,0x7E,0x60,0x60,0x60,0x7C,0x60,0x60,0x60,0x60,0x00,0x00,0x00,0x00},/*"F",38*/ + + {0x00,0x00,0x00,0x3C,0x66,0x66,0x60,0x60,0x6E,0x66,0x66,0x3E,0x00,0x00,0x00,0x00},/*"G",39*/ + + {0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x7E,0x66,0x66,0x66,0x66,0x00,0x00,0x00,0x00},/*"H",40*/ + + {0x00,0x00,0x00,0x3C,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x3C,0x00,0x00,0x00,0x00},/*"I",41*/ + + {0x00,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x06,0x66,0x66,0x3C,0x00,0x00,0x00,0x00},/*"J",42*/ + + {0x00,0x00,0x00,0x66,0x66,0x6C,0x6C,0x78,0x6C,0x6C,0x66,0x66,0x00,0x00,0x00,0x00},/*"K",43*/ + + {0x00,0x00,0x00,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x7E,0x00,0x00,0x00,0x00},/*"L",44*/ + + {0x00,0x00,0x00,0x63,0x63,0x77,0x6B,0x6B,0x6B,0x63,0x63,0x63,0x00,0x00,0x00,0x00},/*"M",45*/ + + {0x00,0x00,0x00,0x63,0x63,0x73,0x7B,0x6F,0x67,0x63,0x63,0x63,0x00,0x00,0x00,0x00},/*"N",46*/ + + {0x00,0x00,0x00,0x3C,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x3C,0x00,0x00,0x00,0x00},/*"O",47*/ + + {0x00,0x00,0x00,0x7C,0x66,0x66,0x66,0x7C,0x60,0x60,0x60,0x60,0x00,0x00,0x00,0x00},/*"P",48*/ + + {0x00,0x00,0x00,0x3C,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x3C,0x0C,0x06,0x00,0x00},/*"Q",49*/ + + {0x00,0x00,0x00,0x7C,0x66,0x66,0x66,0x7C,0x6C,0x66,0x66,0x66,0x00,0x00,0x00,0x00},/*"R",50*/ + + {0x00,0x00,0x00,0x3C,0x66,0x60,0x30,0x18,0x0C,0x06,0x66,0x3C,0x00,0x00,0x00,0x00},/*"S",51*/ + + {0x00,0x00,0x00,0x7E,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x00,0x00,0x00,0x00},/*"T",52*/ + + {0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x3C,0x00,0x00,0x00,0x00},/*"U",53*/ + + {0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x3C,0x18,0x00,0x00,0x00,0x00},/*"V",54*/ + + {0x00,0x00,0x00,0x63,0x63,0x63,0x6B,0x6B,0x6B,0x36,0x36,0x36,0x00,0x00,0x00,0x00},/*"W",55*/ + + {0x00,0x00,0x00,0x66,0x66,0x34,0x18,0x18,0x2C,0x66,0x66,0x66,0x00,0x00,0x00,0x00},/*"X",56*/ + + {0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x3C,0x18,0x18,0x18,0x18,0x00,0x00,0x00,0x00},/*"Y",57*/ + + {0x00,0x00,0x00,0x7E,0x06,0x06,0x0C,0x18,0x30,0x60,0x60,0x7E,0x00,0x00,0x00,0x00},/*"Z",58*/ + + {0x00,0x00,0x00,0x3C,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x3C,0x00},/*"[",59*/ + + {0x00,0x00,0x00,0x60,0x60,0x30,0x30,0x18,0x18,0x0C,0x0C,0x06,0x06,0x00,0x00,0x00},/*"\",60*/ + + {0x00,0x00,0x00,0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00},/*"]",61*/ + + {0x00,0x18,0x3C,0x66,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"^",62*/ + + {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00},/*"_",63*/ + + {0x00,0x00,0x00,0x18,0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"'",64*/ + + {0x00,0x00,0x00,0x00,0x00,0x3C,0x06,0x06,0x3E,0x66,0x66,0x3E,0x00,0x00,0x00,0x00},/*"a",65*/ + + {0x00,0x00,0x00,0x60,0x60,0x7C,0x66,0x66,0x66,0x66,0x66,0x7C,0x00,0x00,0x00,0x00},/*"b",66*/ + + {0x00,0x00,0x00,0x00,0x00,0x3C,0x66,0x60,0x60,0x60,0x66,0x3C,0x00,0x00,0x00,0x00},/*"c",67*/ + + {0x00,0x00,0x00,0x06,0x06,0x3E,0x66,0x66,0x66,0x66,0x66,0x3E,0x00,0x00,0x00,0x00},/*"d",68*/ + + {0x00,0x00,0x00,0x00,0x00,0x3C,0x66,0x66,0x7E,0x60,0x60,0x3C,0x00,0x00,0x00,0x00},/*"e",69*/ + + {0x00,0x00,0x00,0x1E,0x30,0x30,0x30,0x7E,0x30,0x30,0x30,0x30,0x00,0x00,0x00,0x00},/*"f",70*/ + + {0x00,0x00,0x00,0x00,0x00,0x3E,0x66,0x66,0x66,0x66,0x66,0x3E,0x06,0x06,0x7C,0x00},/*"g",71*/ + + {0x00,0x00,0x00,0x60,0x60,0x7C,0x66,0x66,0x66,0x66,0x66,0x66,0x00,0x00,0x00,0x00},/*"h",72*/ + + {0x00,0x00,0x18,0x18,0x00,0x78,0x18,0x18,0x18,0x18,0x18,0x7E,0x00,0x00,0x00,0x00},/*"i",73*/ + + {0x00,0x00,0x0C,0x0C,0x00,0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x78,0x00},/*"j",74*/ + + {0x00,0x00,0x00,0x60,0x60,0x66,0x66,0x6C,0x78,0x6C,0x66,0x66,0x00,0x00,0x00,0x00},/*"k",75*/ + + {0x00,0x00,0x00,0x78,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x7E,0x00,0x00,0x00,0x00},/*"l",76*/ + + {0x00,0x00,0x00,0x00,0x00,0x7E,0x6B,0x6B,0x6B,0x6B,0x6B,0x63,0x00,0x00,0x00,0x00},/*"m",77*/ + + {0x00,0x00,0x00,0x00,0x00,0x7C,0x66,0x66,0x66,0x66,0x66,0x66,0x00,0x00,0x00,0x00},/*"n",78*/ + + {0x00,0x00,0x00,0x00,0x00,0x3C,0x66,0x66,0x66,0x66,0x66,0x3C,0x00,0x00,0x00,0x00},/*"o",79*/ + + {0x00,0x00,0x00,0x00,0x00,0x7C,0x66,0x66,0x66,0x66,0x66,0x7C,0x60,0x60,0x60,0x00},/*"p",80*/ + + {0x00,0x00,0x00,0x00,0x00,0x3E,0x66,0x66,0x66,0x66,0x66,0x3E,0x06,0x06,0x06,0x00},/*"q",81*/ + + {0x00,0x00,0x00,0x00,0x00,0x66,0x6E,0x70,0x60,0x60,0x60,0x60,0x00,0x00,0x00,0x00},/*"r",82*/ + + {0x00,0x00,0x00,0x00,0x00,0x3E,0x60,0x60,0x3C,0x06,0x06,0x7C,0x00,0x00,0x00,0x00},/*"s",83*/ + + {0x00,0x00,0x00,0x30,0x30,0x7E,0x30,0x30,0x30,0x30,0x30,0x1E,0x00,0x00,0x00,0x00},/*"t",84*/ + + {0x00,0x00,0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x66,0x66,0x3E,0x00,0x00,0x00,0x00},/*"u",85*/ + + {0x00,0x00,0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x66,0x3C,0x18,0x00,0x00,0x00,0x00},/*"v",86*/ + + {0x00,0x00,0x00,0x00,0x00,0x63,0x6B,0x6B,0x6B,0x6B,0x36,0x36,0x00,0x00,0x00,0x00},/*"w",87*/ + + {0x00,0x00,0x00,0x00,0x00,0x66,0x66,0x3C,0x18,0x3C,0x66,0x66,0x00,0x00,0x00,0x00},/*"x",88*/ + + {0x00,0x00,0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x66,0x66,0x3C,0x0C,0x18,0xF0,0x00},/*"y",89*/ + + {0x00,0x00,0x00,0x00,0x00,0x7E,0x06,0x0C,0x18,0x30,0x60,0x7E,0x00,0x00,0x00,0x00},/*"z",90*/ + + {0x00,0x00,0x00,0x0C,0x18,0x18,0x18,0x30,0x60,0x30,0x18,0x18,0x18,0x0C,0x00,0x00},/*"{",91*/ + + {0x00,0x00,0x00,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x00},/*"|",92*/ + + {0x00,0x00,0x00,0x30,0x18,0x18,0x18,0x0C,0x06,0x0C,0x18,0x18,0x18,0x30,0x00,0x00},/*"}",93*/ + + {0x00,0x00,0x00,0x71,0xDB,0x8E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"~",94*/ +}; + +px_void PX_GetASCIICode(px_uchar* pBuffer,px_uchar ASCII) +{ + if(ASCII-32<95) + PX_memcpy(pBuffer,(px_void *)AsciiLib[(ASCII - 32)] ,16); + else + PX_memset(pBuffer,0xff,16); +} + + +px_int PX_FontDrawChar(px_surface *psurface, px_int x,px_int y,px_uchar ASCI,px_color Color ) +{ + unsigned short i, j; + px_uchar buffer[16], tmp_char; + + if (ASCI==' ') + { + return 0; + } + + PX_GetASCIICode(buffer,ASCI); + + for( i=0; i<16; i++ ) + { + tmp_char = buffer[i]; + for( j=0; j<8; j++ ) + { + if( (tmp_char >> (7 - j)) & 0x01 ) + { + PX_SurfaceDrawPixel(psurface,x+j,y+i,Color); + } + } + } + return 16; +} + +px_int PX_FontDrawText(px_surface *psurface,px_int x,px_int y,PX_ALIGN align,const px_char *Text,px_color Color) +{ + px_uchar TempChar; + px_int resX=x; + px_int xlen=0; + px_int frWidth,frHeight; + const px_char *CalcText=Text; + + PX_FontTextGetRenderWidthHeight(Text,&frWidth,&frHeight); + + switch (align) + { + case PX_ALIGN_LEFTTOP: + break; + case PX_ALIGN_MIDTOP: + x-=frWidth/2; + break; + case PX_ALIGN_RIGHTTOP: + x-=frWidth; + break; + case PX_ALIGN_LEFTMID: + y-=frHeight/2; + break; + case PX_ALIGN_CENTER: + y-=frHeight/2; + x-=frWidth/2; + break; + case PX_ALIGN_RIGHTMID: + y-=frHeight/2; + x-=frWidth; + break; + case PX_ALIGN_LEFTBOTTOM: + y-=frHeight; + break; + case PX_ALIGN_MIDBOTTOM: + y-=frHeight; + x-=frWidth/2; + break; + case PX_ALIGN_RIGHTBOTTOM: + y-=frHeight; + x-=frWidth; + break; + } + + + while(*Text!=0) + { + if (*Text=='\r'||*Text=='\n') + { + y+=__PX_FONT_HEIGHT+4; + x=resX; + Text++; + continue; + } + + TempChar = *Text++; + PX_FontDrawChar(psurface, x, y, TempChar, Color); + x += __PX_FONT_ASCSIZE; + continue; + } + return x-resX+1; +} + + + + + +px_void PX_FontTextGetRenderWidthHeight(const px_char *Text,px_int *width,px_int *height) +{ + px_int x=0,y=0; + px_int max_width=0,max_height=0; + + while(*Text!=0) + { + if (*Text=='\r'||*Text=='\n') + { + y+=__PX_FONT_HEIGHT+4; + if (y>max_height) + { + max_height=y; + } + Text++; + continue; + } + + if((*Text)&0x80) + { + //not support + Text++; + continue; + } + + if (*Text==' ') + { + Text++; + x += __PX_FONT_ASCSIZE; + if (x>max_width) + { + max_width=x; + } + continue; + } + + Text++; + + x += __PX_FONT_ASCSIZE; + if (x>max_width) + { + max_width=x; + } + if (y+__PX_FONT_HEIGHT>max_height) + { + max_height=y+__PX_FONT_HEIGHT; + } + } + *width=max_width; + *height=max_height; +} + + +px_int PX_FontModuleGetCharacterCode(PX_FONTMODULE_CODEPAGE codePage,const px_char *Text,px_dword *code) +{ + const px_uchar *uText=(const px_uchar *)Text; + + switch(codePage) + { + case PX_FONTMODULE_CODEPAGE_GBK: + if (*uText==0) + { + *code=0; + return 0; + } + if ((*uText)&0x80) + { + *code=(px_dword)((*uText)+*(uText+1)*256); + return 2; + } + else + { + *code=(px_dword)(*uText); + return 1; + } + break; + case PX_FONTMODULE_CODEPAGE_UTF8: + { + px_dword bc=1; + px_dword rcode=0; + px_uchar pageHead=(px_uchar)(*uText); + px_uchar oftbit=0x80; + if (pageHead==0) + { + return 0; + } + + rcode=(*uText); + while (1) + { + if ((pageHead&oftbit)==0) + { + break; + } + + oftbit>>=1; + + if ((pageHead&oftbit)==0) + { + break; + } + uText++; + rcode+=((*uText)<<(bc*8)); + bc++; + }; + *code=rcode; + return bc; + } + break; + case PX_FONTMODULE_CODEPAGE_UTF16: + { + *code=(px_dword)((*uText)+*(uText+1)*256); + if (*code==0) + { + return 0; + } + return 2; + } + break; + default: + return 0; + break; + } + *code=0; + return 0; +} + +px_bool PX_FontModuleInitialize(px_memorypool *mp,PX_FontModule *module) +{ + module->mp=mp; + module->codePage=PX_FONTMODULE_CODEPAGE_UNDEFINED; + module->max_BearingY=0; + module->max_Height=0; + module->max_Width=0; + return PX_MapInitialize(mp,&module->characters_map); +} + +px_bool PX_FontModuleLoad(PX_FontModule *module,px_byte *buffer,px_int size) +{ + px_int offset=0; + PX_FontModule_Charactor *cpy; + + if(module->mp==PX_NULL) + { + PX_ASSERT(); + return PX_FALSE; + } + + while (offsetc_magic[0]!='P') + goto _ERROR; + if(pcHeader->c_magic[1]!='X') + goto _ERROR; + if(pcHeader->c_magic[2]!='F') + goto _ERROR; + if(pcHeader->c_magic[3]!='M') + goto _ERROR; + + if (module->codePage==PX_FONTMODULE_CODEPAGE_UNDEFINED) + { + module->codePage=(PX_FONTMODULE_CODEPAGE)pcHeader->codePage; + } + else + { + if (pcHeader->codePage!=(px_dword)module->codePage) + { + offset+=pcHeader->Font_Width*pcHeader->Font_Height; + continue; + } + } + + + PX_Base64Encode((px_byte *)&pcHeader->charactor_code,sizeof(pcHeader->charactor_code),hex); + + //PX_itoa(pcHeader->charactor_code,hex,sizeof(hex),16); + + + if (PX_MapGet(&module->characters_map,hex)) + { + offset+=pcHeader->Font_Width*pcHeader->Font_Height; + continue; + } + if ((px_int)pcHeader->BearingY>module->max_BearingY) + { + module->max_BearingY=pcHeader->BearingY; + } + if ((px_int)pcHeader->Font_Height>module->max_Height) + { + module->max_Height=pcHeader->Font_Height; + } + + if ((px_int)pcHeader->Font_Width>module->max_Width) + { + module->max_Width=pcHeader->Font_Width; + + } + cpy=(PX_FontModule_Charactor *)MP_Malloc(module->mp,sizeof(PX_FontModule_Charactor)); + + if (!cpy) + { + goto _ERROR; + } + + PX_memcpy(cpy,pcHeader,sizeof(PX_FontModule_Charactor_Header)); + + if(!PX_ShapeCreate(module->mp,&cpy->shape,cpy->header.Font_Width,cpy->header.Font_Height)) + { + goto _ERROR; + } + PX_memcpy(cpy->shape.alpha,pData,cpy->header.Font_Width*cpy->header.Font_Height); + offset+=cpy->header.Font_Width*cpy->header.Font_Height; + PX_MapPut(&module->characters_map,hex,cpy); + } + return PX_TRUE; +_ERROR: + //PX_FontModuleFree(module); + return PX_FALSE; +} + +px_void PX_FontModuleFree(PX_FontModule *module) +{ + px_map_element *pme; + pme=PX_MapFirst(&module->characters_map); + while (pme) + { + PX_FontModule_Charactor *pmc=(PX_FontModule_Charactor *)pme->Ptr; + PX_ShapeFree(&pmc->shape); + MP_Free(module->mp,pmc); + pme=PX_MapNext(&module->characters_map,pme); + } + PX_MapFree(&module->characters_map); +} + + + + +px_int PX_FontModuleGetCharacterDesc(PX_FontModule *module,const px_char *Text,px_dword *code,px_int *advance,px_int *height) +{ + px_char hex[16]; + px_int f_size; + PX_FontModule_Charactor *pChar=PX_NULL; + + if(!(f_size=PX_FontModuleGetCharacterCode(module->codePage,Text,code))) + { + return 0; + } + + if (*code==' ') + { + *advance=module->max_Width/2; + *height=module->max_Height; + return f_size; + } + + PX_Base64Encode((px_byte *)code,sizeof(px_dword),hex); + + pChar=(PX_FontModule_Charactor *)PX_MapGet(&module->characters_map,hex); + if (pChar) + { + *advance=(px_int)pChar->header.Advance; + *height=(px_int)pChar->header.Font_Height; + } + else + { + *advance=0; + *height=0; + } + + return f_size; +} + +px_void PX_FontModuleTextGetRenderWidthHeight(PX_FontModule *module,const px_char *Text,px_int *width,px_int *height) +{ + px_int dx=0; + px_int dy=0; + px_int max_width=0,max_height=0; + const px_char *pTextPointer=Text; + + if (module==PX_NULL) + { + PX_FontTextGetRenderWidthHeight(pTextPointer,width,height); + return; + } + + + while (PX_TRUE) + { + px_dword code=0; + px_char hex[16]; + px_int f_size; + PX_FontModule_Charactor *pChar=PX_NULL; + + if(!(f_size=PX_FontModuleGetCharacterCode(module->codePage,pTextPointer,&code))) + { + break; + } + pTextPointer+=f_size; + + if (code==' ') + { + dx+=module->max_Width/2; + } + else if(code=='\n') + { + dx=0; + dy+=module->max_Height; + } + else + { + PX_Base64Encode((px_byte *)&code,sizeof(code),hex); + + pChar=(PX_FontModule_Charactor *)PX_MapGet(&module->characters_map,hex); + if (pChar) + { + // + dx+=pChar->header.Advance; + } + } + + if (dx>max_width) + { + max_width=dx; + } + + if (pChar) + { + if ((px_int)(dy+module->max_BearingY-pChar->header.BearingY+pChar->shape.height)>max_height) + { + max_height=dy+module->max_BearingY-pChar->header.BearingY+pChar->shape.height; + } + } + } + *width=max_width; + *height=max_height; +} + +px_int PX_FontModuleDrawCharacter(px_surface *psurface,PX_FontModule *mod,int x,int y,const px_dword code,px_color Color) +{ + px_char hex[16]; + PX_FontModule_Charactor *pChar; + PX_Base64Encode((px_byte *)&code,sizeof(code),hex); + pChar=(PX_FontModule_Charactor *)PX_MapGet(&mod->characters_map,hex); + if (pChar) + { + PX_ShapeRender(psurface,&pChar->shape,x+pChar->header.BearingX,y+mod->max_BearingY-pChar->header.BearingY,PX_ALIGN_LEFTTOP,Color); + return pChar->header.Advance; + } + + return 0; +} + +px_int PX_FontModuleDrawText(px_surface *psurface,PX_FontModule *mod,int x,int y,PX_ALIGN align,const px_char *Text,px_color Color) +{ + px_int dx,dy,content_width=0; + px_int frWidth,frHeight; + const px_char *pTextPointer=Text; + + if (!Text) + { + PX_ASSERT(); + return 0; + } + + if (mod==PX_NULL) + { + return PX_FontDrawText(psurface,x,y,align,Text,Color); + } + + + PX_FontModuleTextGetRenderWidthHeight(mod,Text,&frWidth,&frHeight); + + switch (align) + { + case PX_ALIGN_LEFTTOP: + break; + case PX_ALIGN_MIDTOP: + x-=frWidth/2; + break; + case PX_ALIGN_RIGHTTOP: + x-=frWidth; + break; + case PX_ALIGN_LEFTMID: + y-=frHeight/2; + break; + case PX_ALIGN_CENTER: + y-=frHeight/2; + x-=frWidth/2; + break; + case PX_ALIGN_RIGHTMID: + y-=frHeight/2; + x-=frWidth; + break; + case PX_ALIGN_LEFTBOTTOM: + y-=frHeight; + break; + case PX_ALIGN_MIDBOTTOM: + y-=frHeight; + x-=frWidth/2; + break; + case PX_ALIGN_RIGHTBOTTOM: + y-=frHeight; + x-=frWidth; + break; + } + + dx=x; + dy=y; + pTextPointer=Text; + + while (PX_TRUE) + { + px_dword code=0; + px_char hex[16]; + px_int f_size; + PX_FontModule_Charactor *pChar; + + if(!(f_size=PX_FontModuleGetCharacterCode(mod->codePage,pTextPointer,&code))) + { + break; + } + pTextPointer+=f_size; + + if (code==' ') + { + dx+=mod->max_Width/2; + } + else if(code=='\n') + { + dy+=mod->max_Height; + dx=x; + } + else + { + PX_Base64Encode((px_byte *)&code,sizeof(code),hex); + //PX_itoa(code,hex,sizeof(hex),16); + pChar=(PX_FontModule_Charactor *)PX_MapGet(&mod->characters_map,hex); + if (pChar) + { + PX_ShapeRender(psurface,&pChar->shape,dx+pChar->header.BearingX,dy+mod->max_BearingY-pChar->header.BearingY,PX_ALIGN_LEFTTOP,Color); + dx+=pChar->header.Advance; + } + } + } + return dx-x+1; +} + diff --git a/lib/PainterEngine/core/PX_Font.h b/lib/PainterEngine/core/PX_Font.h new file mode 100644 index 0000000000000000000000000000000000000000..79a3d58620f797cb65a91211146d212297c58de2 --- /dev/null +++ b/lib/PainterEngine/core/PX_Font.h @@ -0,0 +1,84 @@ +#ifndef PIXELSES_FONT +#define PIXELSES_FONT + +#include "../core/PX_Surface.h" +#include "../core/PX_Texture.h" +#include "../core/PX_Base64.h" + +#include "PX_Hashmap.h" + +//#define __PX_FONT_GBKSIZE 13 +#define __PX_FONT_ASCSIZE 8 +#define __PX_FONT_HEIGHT 15 +#define __PX_FONT_MODULE_XSPACE_SIZE 0 +#define __PX_FONT_MODULE_YSPACE_SIZE 0 +//////////////////////////////////////////////////////////////////////////////////////////// +/////// Private function //// +////// //// +//////////////////////////////////////////////////////////////////////////////////////////// + +#define PX_FontGetCharactorHeight() (__PX_FONT_HEIGHT) +#define PX_FontGetAscCharactorWidth() (__PX_FONT_ASCSIZE) +//#define PX_FontGetGbkCharactorWidth() (__PX_FONT_GBKSIZE) + +typedef struct +{ + union + { + px_char c_magic[4];//PXFM + px_dword magic; + }; + px_dword codePage; + px_dword charactor_code; + px_dword BearingX; + px_dword BearingY; + px_dword Advance; + px_dword Font_Width; + px_dword Font_Height; +}PX_FontModule_Charactor_Header; + +typedef struct +{ + PX_FontModule_Charactor_Header header; + px_shape shape; +}PX_FontModule_Charactor; + +typedef enum +{ + PX_FONTMODULE_CODEPAGE_GBK, + PX_FONTMODULE_CODEPAGE_UTF8, + PX_FONTMODULE_CODEPAGE_UTF16, + PX_FONTMODULE_CODEPAGE_UNDEFINED, +}PX_FONTMODULE_CODEPAGE; + +typedef struct +{ + px_memorypool *mp; + px_map characters_map; + + px_int max_BearingY; + px_int max_Height; + px_int max_Width; + PX_FONTMODULE_CODEPAGE codePage; +}PX_FontModule; + + + +px_int PX_FontDrawChar(px_surface *psurface, px_int x,px_int y,px_uchar chr,px_color Color ); +px_int PX_FontDrawText(px_surface *psurface,int x,int y,PX_ALIGN align,const px_char *Text,px_color Color); +px_void PX_FontTextGetRenderWidthHeight(const px_char *Text,px_int *width,px_int *height); + + + +px_int PX_FontModuleGetCharacterCode(PX_FONTMODULE_CODEPAGE codePage,const px_char *Text,px_dword *code); +px_bool PX_FontModuleInitialize(px_memorypool *mp,PX_FontModule *module); +px_bool PX_FontModuleLoad(PX_FontModule *module,px_byte *buffer,px_int size); +px_void PX_FontModuleFree(PX_FontModule *module); +px_int PX_FontModuleGetCharacterDesc(PX_FontModule *module,const px_char *Text,px_dword *code,px_int *width,px_int *height); +px_void PX_FontModuleTextGetRenderWidthHeight(PX_FontModule *module,const px_char *Text,px_int *advance,px_int *height); +px_int PX_FontModuleDrawCharacter(px_surface *psurface,PX_FontModule *mod,int x,int y,const px_dword code,px_color Color); +px_int PX_FontModuleDrawText(px_surface *psurface,PX_FontModule *mod,int x,int y,PX_ALIGN align,const px_char *Text,px_color Color); + + +#endif + diff --git a/lib/PainterEngine/core/PX_Hashmap.c b/lib/PainterEngine/core/PX_Hashmap.c new file mode 100644 index 0000000000000000000000000000000000000000..78b2d0bddd8284e9ef90702213bbab2cb5e3144a --- /dev/null +++ b/lib/PainterEngine/core/PX_Hashmap.c @@ -0,0 +1,185 @@ +/* + * Generic map implementation. + */ +#include "PX_Hashmap.h" + + +px_bool PX_MapInitialize(px_memorypool *mp,px_map *m) +{ + m->mp=mp; + m->root.rb_node = PX_NULL; + m->size = 0; + + return PX_TRUE; +} + + + + +px_map_element * px_rbtree_search(struct px_rb_root *root,const char string[]) +{ + struct px_rb_node *node = root->rb_node; + + while (node) { + px_map_element *data =(px_map_element *)node; + int result; + + result = PX_strcmp(string, data->string); + + if (result < 0) + node = node->rb_left; + else if (result > 0) + node = node->rb_right; + else + return data; + } + return PX_NULL; +} + +px_bool px_rbtree_insert(struct px_rb_root *root, px_map_element *data) +{ + struct px_rb_node **newnode = &(root->rb_node), *parent = PX_NULL; + + /* Figure out where to put new node */ + while (*newnode) { + px_map_element *__this = (px_map_element *)(*newnode); + int result = PX_strcmp(data->string, __this->string); + + parent = *newnode; + if (result < 0) + newnode = &((*newnode)->rb_left); + else if (result > 0) + newnode = &((*newnode)->rb_right); + else + return PX_FALSE; + } + + /* Add new node and rebalance tree. */ + rb_link_node(&data->node, parent, newnode); + rb_insert_color(&data->node, root); + + return PX_TRUE; +} + + + +PX_HASHMAP_RETURN PX_MapPut(px_map * m,const px_char stringkey[], px_void * value) +{ + px_map_element *newnode = (px_map_element *)MP_Malloc(m->mp,sizeof(px_map_element)); + newnode->Ptr=value; + PX_strcpy(newnode->string,stringkey,sizeof(newnode->string)); + if(px_rbtree_insert(&m->root,newnode)) + { + m->size++; + return PX_HASHMAP_RETURN_OK; + } + else + return PX_HASHMAP_RETURN_NULL; +} + +PX_HASHMAP_RETURN PX_MapPutInt(px_map * m,const px_char stringkey[], px_int value) +{ + px_map_element *newnode = (px_map_element *)MP_Malloc(m->mp,sizeof(px_map_element)); + newnode->_int=value; + PX_strcpy(newnode->string,stringkey,sizeof(newnode->string)); + if(px_rbtree_insert(&m->root,newnode)) + { + m->size++; + return PX_HASHMAP_RETURN_OK; + } + else + return PX_HASHMAP_RETURN_NULL; +} + +PX_HASHMAP_RETURN PX_MapPutFloat(px_map * m,const px_char stringkey[], px_float value) +{ + px_map_element *newnode = (px_map_element *)MP_Malloc(m->mp,sizeof(px_map_element)); + newnode->_float=value; + PX_strcpy(newnode->string,stringkey,sizeof(newnode->string)); + if(px_rbtree_insert(&m->root,newnode)) + { + m->size++; + return PX_HASHMAP_RETURN_OK; + } + else + return PX_HASHMAP_RETURN_NULL; +} + +px_void * PX_MapGet(px_map * m, const px_char stringkey[]) +{ + px_map_element *p=px_rbtree_search(&m->root,stringkey); + if (p) + { + return p->Ptr; + } + return PX_NULL; +} + +px_void PX_MapFree(px_map * m) +{ + struct px_rb_node *node; + m->size=0; + node = rb_first(&m->root); + while (node) + { + struct px_rb_node *p_delete_node; + p_delete_node=node; + node = rb_next(node); + rb_erase(p_delete_node,&m->root); + MP_Free(m->mp,p_delete_node); + } + m->size=0; +} + +px_int PX_MapGetSize(px_map * m) +{ + return m->size; +} + +PX_HASHMAP_RETURN PX_MapErase(px_map * m,const px_char stringkey[]) +{ + px_map_element *data = px_rbtree_search(&m->root,stringkey); + if (data) { + m->size--; + rb_erase(&data->node, &m->root); + MP_Free(m->mp,data); + return PX_HASHMAP_RETURN_OK; + } + return PX_HASHMAP_RETURN_NULL; +} + +px_map_element * PX_MapFirst(px_map * m) +{ + struct px_rb_node *node; + m->size=0; + node = rb_first(&m->root); + return (px_map_element *)node; +} + +px_map_element * PX_MapNext(px_map * m,px_map_element *node) +{ + return (px_map_element *)rb_next((struct px_rb_node *)node); +} + +px_bool PX_MapGetInt(px_map * m, const px_char stringkey[],px_int *v) +{ + px_map_element *p=px_rbtree_search(&m->root,stringkey); + if (p) + { + *v= p->_int; + return PX_TRUE; + } + return PX_FALSE; +} + + +px_bool PX_MapGetFloat(px_map * m, const px_char stringkey[],px_float *v) +{ + px_map_element *p=px_rbtree_search(&m->root,stringkey); + if (p) + { + *v= p->_float; + return PX_TRUE; + } + return PX_FALSE; +} diff --git a/lib/PainterEngine/core/PX_Hashmap.h b/lib/PainterEngine/core/PX_Hashmap.h new file mode 100644 index 0000000000000000000000000000000000000000..3d3e29d8b71d47bb63bfae0e6049d697130e2b8e --- /dev/null +++ b/lib/PainterEngine/core/PX_Hashmap.h @@ -0,0 +1,59 @@ + +#ifndef PX_HASHMAP_H__ +#define PX_HASHMAP_H__ + +#include "PX_MemoryPool.h" +#include "PX_rbtree.h" + +#define PX_HASHMAP_STRINGKEY_LEN 64 + + +typedef enum +{ + PX_HASHMAP_RETURN_OK, + PX_HASHMAP_RETURN_NULL, + PX_HASHMAP_RETURN_KEYEXIST, + PX_HASHMAP_RETURN_OUTOFMEMORY, + PX_HASHMAP_RETURN_FULL, +}PX_HASHMAP_RETURN; + + + +typedef struct +{ + px_memorypool *mp; + px_int size; + struct px_rb_root root; +}px_map; + +typedef struct __px_map_element +{ + struct px_rb_node node;//must be first member + px_char string[PX_HASHMAP_STRINGKEY_LEN]; + union + { + px_void *Ptr; + px_int _int; + px_float _float; + }; + +}px_map_element; + + + +px_bool PX_MapInitialize(px_memorypool *mp,px_map *hashmap); + +PX_HASHMAP_RETURN PX_MapPut(px_map * m,const px_char stringkey[], px_void * value); +PX_HASHMAP_RETURN PX_MapPutInt(px_map * m,const px_char stringkey[], px_int value); +PX_HASHMAP_RETURN PX_MapPutFloat(px_map * m,const px_char stringkey[], px_float value); +PX_HASHMAP_RETURN PX_MapErase(px_map * m,const px_char stringkey[]); +px_map_element * PX_MapFirst(px_map * m); +px_map_element * PX_MapNext(px_map * m,px_map_element *node); +px_void *PX_MapGet(px_map * m, const px_char stringkey[]); +px_bool PX_MapGetInt(px_map * m, const px_char stringkey[],px_int *_int); +px_bool PX_MapGetFloat(px_map * m, const px_char stringkey[],px_float *_float); +px_void PX_MapFree(px_map * m); +px_int PX_MapGetSize(px_map * m); + + +#endif diff --git a/lib/PainterEngine/core/PX_Huffman.c b/lib/PainterEngine/core/PX_Huffman.c new file mode 100644 index 0000000000000000000000000000000000000000..dc9ea7cdc552b15377b93cbced726af96b88b6a5 --- /dev/null +++ b/lib/PainterEngine/core/PX_Huffman.c @@ -0,0 +1,268 @@ +#include "PX_Huffman.h" + +struct _huffman_node +{ + px_word left,right; + px_uint weight; + px_byte data; +}; +typedef struct _huffman_node huffman_node; + +typedef struct +{ + union + { + px_word left; + px_word bNode; + }; + union + { + px_word right; + px_byte data; + }; +}huffman_snode; + +typedef struct +{ + px_dword len; + px_byte encode[32]; +}huffman_map; + +px_void px_huffmanTraversalTree(huffman_node *pNodeHead,huffman_node *node,huffman_map map,huffman_map *pTable) +{ + huffman_map genMap; + if (node->left) + { + genMap=map; + genMap.len++; + px_huffmanTraversalTree(pNodeHead,&pNodeHead[node->left],genMap,pTable); + genMap=map; + genMap.encode[genMap.len/8]|=(1<<(genMap.len%8)); + genMap.len++; + px_huffmanTraversalTree(pNodeHead,&pNodeHead[node->right],genMap,pTable); + } + else + { + pTable[node->data]=map; + } +} + +px_void PX_huffmanCompress(px_byte *_in,px_uint input_size,px_byte *_out,px_uint *out_size) +{ + px_uint i,j; + huffman_node nodes[511]; + huffman_snode snodes[511]; + px_uint sortCursor=255; + huffman_map huffmanMap[256]={0}; + px_uint encodeNecessaryNodeCount; + px_uint sortIndex; + px_uint w_size=0; + huffman_map mapnode; + px_byte w_byte=0; + px_uchar w_byte_offset=0; + + PX_memset(nodes,0,sizeof(nodes)); + for (i=0;i<256;i++) + { + nodes[i].data=(px_byte)i; + } + for (i=0;i0) + { + huffman_node newNode; + //move node to end + nodes[sortCursor*2]=nodes[sortCursor]; + nodes[sortCursor*2-1]=nodes[sortCursor-1]; + newNode.left=sortCursor*2; + newNode.right=sortCursor*2-1; + newNode.data=0; + newNode.weight=nodes[sortCursor*2].weight+nodes[sortCursor*2-1].weight; + nodes[sortCursor-1]=newNode; + sortCursor--; + //re-sort + sortIndex=sortCursor; + while (sortIndex>0) + { + if (nodes[sortIndex].weight>nodes[sortIndex-1].weight) + { + huffman_node temp=nodes[sortIndex-1]; + nodes[sortIndex-1]=nodes[sortIndex]; + nodes[sortIndex]=temp; + } + else + { + break; + } + sortIndex--; + } + } + + PX_memset(snodes,0,sizeof(snodes)); + for (i=0;i=8) + { + w_byte_offset=0; + if(_out) + _out[w_size]=w_byte; + w_byte=0; + w_size++; + } + } + } + //last + if(_out) + _out[w_size]=w_byte; + w_size++; + *out_size=w_size; +} + +px_void PX_huffmanDecompress(px_byte *_in,px_uint input_size,px_byte *_out,px_uint *out_size) +{ + px_uint r_offset/*read*/,w_offset; + px_uchar leaf; + px_uint bit_offset; + px_uint bit; + px_dword datasize; + huffman_snode *pheader,*pNode; + *out_size=*(px_dword *)(_in+1); + if (!_out) + { + return; + } + + datasize=*(px_dword *)(_in+1); + pheader=(huffman_snode *)(_in+1+4); + if (!pheader->bNode) + { + //only one node + if(_out) + PX_memset(_out,pheader->data,datasize); + } + + leaf=_in[0]; + bit_offset=0; + w_offset=0; + pNode=pheader; + r_offset=1+4+((leaf+1)*2-1)*sizeof(huffman_snode); + + while (r_offsetright]; + if (!pNode->bNode) + { + _out[w_offset]=pNode->data; + w_offset++; + pNode=pheader; + if (w_offset>=datasize) + { + return; + } + } + + } + else + { + pNode=&pheader[pNode->left]; + if (!pNode->bNode) + { + _out[w_offset]=pNode->data; + w_offset++; + pNode=pheader; + if (w_offset>=datasize) + { + return; + } + } + } + + bit_offset++; + if (bit_offset>=8) + { + r_offset++; + bit_offset=0; + } + } + //error + PX_ASSERT(); +} + diff --git a/lib/PainterEngine/core/PX_Huffman.h b/lib/PainterEngine/core/PX_Huffman.h new file mode 100644 index 0000000000000000000000000000000000000000..7575245732f54bfffcab080afd8c25117d3878b4 --- /dev/null +++ b/lib/PainterEngine/core/PX_Huffman.h @@ -0,0 +1,7 @@ +#ifndef PX_HUFFMAN_H +#define PX_HUFFMAN_H +#include "PX_Quicksort.h" + +px_void PX_huffmanCompress(px_byte *_in,px_uint input_size,px_byte *_out,px_uint *out_size); +px_void PX_huffmanDecompress(px_byte *_in,px_uint input_size,px_byte *_out,px_uint *out_size); +#endif diff --git a/lib/PainterEngine/core/PX_ImageFilter.c b/lib/PainterEngine/core/PX_ImageFilter.c new file mode 100644 index 0000000000000000000000000000000000000000..a2b1975d9663833a2f02977220c0afcbac3e9e9a --- /dev/null +++ b/lib/PainterEngine/core/PX_ImageFilter.c @@ -0,0 +1,229 @@ +#include "PX_ImageFilter.h" + +px_void PX_ImageFilter_Convolution(px_texture *ptexture,px_float out[],px_float matrix_operator[3][3],px_bool raw) +{ + px_int i,j; + px_float uniform=0; + px_float maxGray=0; + for (i=0;i<3;i++) + { + for (j=0;j<3;j++) + { + if (matrix_operator[i][j]>0) + { + uniform+=matrix_operator[i][j]; + } + } + } + + for (j=0;jheight-1;j++) + { + for (i=0;iwidth-1;i++) + { + px_color clr; + px_float Gray; + clr=PX_SurfaceGetPixel(ptexture,i-1,j-1); + Gray = clr._argb.r*0.299f+ clr._argb.g*0.587f + clr._argb.b*0.114f; + if (Gray>maxGray) + { + maxGray=Gray; + } + } + } + + for (j=1;jheight-1;j++) + { + for (i=1;iwidth-1;i++) + { + px_color clr; + px_float Gray; + px_float weight=0; + clr=PX_SurfaceGetPixel(ptexture,i-1,j-1); + Gray = clr._argb.r*0.299f+ clr._argb.g*0.587f + clr._argb.b*0.114f; + Gray*=clr._argb.a/255.f; + + weight+=Gray*matrix_operator[0][0]; + + clr=PX_SurfaceGetPixel(ptexture,i,j-1); + Gray = clr._argb.r*0.299f+ clr._argb.g*0.587f + clr._argb.b*0.114f; + Gray*=clr._argb.a/255.f; + weight+=Gray*matrix_operator[0][1]; + + clr=PX_SurfaceGetPixel(ptexture,i+1,j-1); + Gray = clr._argb.r*0.299f+ clr._argb.g*0.587f + clr._argb.b*0.114f; + Gray*=clr._argb.a/255.f; + weight+=Gray*matrix_operator[0][2]; + + + clr=PX_SurfaceGetPixel(ptexture,i-1,j); + Gray = clr._argb.r*0.299f+ clr._argb.g*0.587f + clr._argb.b*0.114f; + Gray*=clr._argb.a/255.f; + weight+=Gray*matrix_operator[1][0]; + + clr=PX_SurfaceGetPixel(ptexture,i,j); + Gray = clr._argb.r*0.299f+ clr._argb.g*0.587f + clr._argb.b*0.114f; + Gray*=clr._argb.a/255.f; + weight+=Gray*matrix_operator[1][1]; + + clr=PX_SurfaceGetPixel(ptexture,i+1,j); + Gray = clr._argb.r*0.299f+ clr._argb.g*0.587f + clr._argb.b*0.114f; + Gray*=clr._argb.a/255.f; + weight+=Gray*matrix_operator[1][2]; + + + + clr=PX_SurfaceGetPixel(ptexture,i-1,j+1); + Gray = clr._argb.r*0.299f+ clr._argb.g*0.587f + clr._argb.b*0.114f; + Gray*=clr._argb.a/255.f; + weight+=Gray*matrix_operator[2][0]; + + clr=PX_SurfaceGetPixel(ptexture,i,j+1); + Gray = clr._argb.r*0.299f+ clr._argb.g*0.587f + clr._argb.b*0.114f; + Gray*=clr._argb.a/255.f; + weight+=Gray*matrix_operator[2][1]; + + clr=PX_SurfaceGetPixel(ptexture,i+1,j+1); + Gray = clr._argb.r*0.299f+ clr._argb.g*0.587f + clr._argb.b*0.114f; + Gray*=clr._argb.a/255.f; + weight+=Gray*matrix_operator[2][2]; + + if (raw) + { + out[j*ptexture->width+i]+=(weight)/(uniform*maxGray); + } + else + { + out[j*ptexture->width+i]+=PX_ABS(weight)/(uniform*maxGray); + } + + } + } + +} + +px_void PX_ImageFilter_PriwittX(px_texture *ptexture,px_float out[]) +{ + px_float Priwitt_h[3][3]={{-1,0,1},{-1,0,1},{-1,0,1}}; + PX_memset(out,0,ptexture->width*ptexture->height*sizeof(px_float)); + PX_ImageFilter_Convolution(ptexture,out,Priwitt_h,PX_TRUE); +} + +px_void PX_ImageFilter_PriwittY(px_texture *ptexture,px_float out[]) +{ + px_float Priwitt_v[3][3]={{-1,-1,-1},{0,0,0},{1,1,1}}; + PX_memset(out,0,ptexture->width*ptexture->height*sizeof(px_float)); + PX_ImageFilter_Convolution(ptexture,out,Priwitt_v,PX_TRUE); +} + + +px_void PX_ImageFilter_Priwitt(px_texture *ptexture,px_float out[]) +{ + px_float Priwitt_h[3][3]={{-1,0,1},{-1,0,1},{-1,0,1}}; + px_float Priwitt_v[3][3]={{-1,-1,-1},{0,0,0},{1,1,1}}; + PX_memset(out,0,ptexture->width*ptexture->height*sizeof(px_float)); + PX_ImageFilter_Convolution(ptexture,out,Priwitt_h,PX_FALSE); + PX_ImageFilter_Convolution(ptexture,out,Priwitt_v,PX_FALSE); + + do + { + px_int i; + for (i=0;iwidth*ptexture->height;i++) + { + out[i]/=2; + } + } while (0); +} + + +px_void PX_ImageFilter_SobelX(px_texture *ptexture,px_float out[]) +{ + px_float Sobel_h[3][3]={{-1,0,1},{-2,0,2},{-1,0,1}}; + PX_memset(out,0,ptexture->width*ptexture->height*sizeof(px_float)); + PX_ImageFilter_Convolution(ptexture,out,Sobel_h,PX_TRUE); +} +px_void PX_ImageFilter_SobelY(px_texture *ptexture,px_float out[]) +{ + px_float Sobel_v[3][3]={{-1,-2,-1},{0,0,0},{1,2,1}}; + PX_memset(out,0,ptexture->width*ptexture->height*sizeof(px_float)); + PX_ImageFilter_Convolution(ptexture,out,Sobel_v,PX_TRUE); +} +px_void PX_ImageFilter_Sobel(px_texture *ptexture,px_float out[]) +{ + px_float Sobel_h[3][3]={{-1,0,1},{-2,0,2},{-1,0,1}}; + px_float Sobel_v[3][3]={{-1,-2,-1},{0,0,0},{1,2,1}}; + PX_memset(out,0,ptexture->width*ptexture->height*sizeof(px_float)); + PX_ImageFilter_Convolution(ptexture,out,Sobel_h,PX_FALSE); + PX_ImageFilter_Convolution(ptexture,out,Sobel_v,PX_FALSE); + do + { + px_int i; + for (i=0;iwidth*ptexture->height;i++) + { + out[i]/=2; + } + } while (0); +} + +px_void PX_ImageFilter_RobertsX(px_texture *ptexture,px_float out[]) +{ + px_float Roberts_h[3][3]={{0,0,0},{0,-1,0},{0,0,1}}; + PX_memset(out,0,ptexture->width*ptexture->height*sizeof(px_float)); + PX_ImageFilter_Convolution(ptexture,out,Roberts_h,PX_TRUE); +} +px_void PX_ImageFilter_RobertsY(px_texture *ptexture,px_float out[]) +{ + px_float Roberts_v[3][3]={{0,0,0},{0,0,-1},{0,1,0}}; + PX_memset(out,0,ptexture->width*ptexture->height*sizeof(px_float)); + PX_ImageFilter_Convolution(ptexture,out,Roberts_v,PX_TRUE); +} + +px_void PX_ImageFilter_Roberts(px_texture *ptexture,px_float out[]) +{ + px_float Roberts_h[3][3]={{0,0,0},{0,-1,0},{0,0,1}}; + px_float Roberts_v[3][3]={{0,0,0},{0,0,-1},{0,1,0}}; + PX_memset(out,0,ptexture->width*ptexture->height*sizeof(px_float)); + PX_ImageFilter_Convolution(ptexture,out,Roberts_h,PX_FALSE); + PX_ImageFilter_Convolution(ptexture,out,Roberts_v,PX_FALSE); + do + { + px_int i; + for (i=0;iwidth*ptexture->height;i++) + { + out[i]/=2; + } + } while (0); +} + +px_void PX_ImageFilter_LaplacianX(px_texture *ptexture,px_float out[]) +{ + px_float Roberts_h[3][3]={{0,-1,0},{-1,4,-1},{0,-1,0}}; + PX_memset(out,0,ptexture->width*ptexture->height*sizeof(px_float)); + PX_ImageFilter_Convolution(ptexture,out,Roberts_h,PX_TRUE); +} + + +px_void PX_ImageFilter_LaplacianY(px_texture *ptexture,px_float out[]) +{ + px_float Roberts_v[3][3]={{-1,-1,-1},{-1,8,-1},{-1,-1,-1}}; + PX_memset(out,0,ptexture->width*ptexture->height*sizeof(px_float)); + PX_ImageFilter_Convolution(ptexture,out,Roberts_v,PX_TRUE); +} + +px_void PX_ImageFilter_Laplacian(px_texture *ptexture,px_float out[]) +{ + px_float Roberts_h[3][3]={{0,-1,0},{-1,4,-1},{0,-1,0}}; + px_float Roberts_v[3][3]={{-1,-1,-1},{-1,8,-1},{-1,-1,-1}}; + PX_memset(out,0,ptexture->width*ptexture->height*sizeof(px_float)); + PX_ImageFilter_Convolution(ptexture,out,Roberts_h,PX_FALSE); + PX_ImageFilter_Convolution(ptexture,out,Roberts_v,PX_FALSE); + do + { + px_int i; + for (i=0;iwidth*ptexture->height;i++) + { + out[i]/=2; + } + } while (0); +} + + diff --git a/lib/PainterEngine/core/PX_ImageFilter.h b/lib/PainterEngine/core/PX_ImageFilter.h new file mode 100644 index 0000000000000000000000000000000000000000..fe88191e6b7bc35c460fea40a05199593fc9c68a --- /dev/null +++ b/lib/PainterEngine/core/PX_ImageFilter.h @@ -0,0 +1,18 @@ +#ifndef __PX_IMAGEFILTER_H +#define __PX_IMAGEFILTER_H +#include "PX_Texture.h" + +px_void PX_ImageFilter_PriwittX(px_texture *ptexture,px_float out[]); +px_void PX_ImageFilter_PriwittY(px_texture *ptexture,px_float out[]); +px_void PX_ImageFilter_Priwitt(px_texture *ptexture,px_float out[]); +px_void PX_ImageFilter_SobelX(px_texture *ptexture,px_float out[]); +px_void PX_ImageFilter_SobelY(px_texture *ptexture,px_float out[]); +px_void PX_ImageFilter_Sobel(px_texture *ptexture,px_float out[]); +px_void PX_ImageFilter_RobertsX(px_texture *ptexture,px_float out[]); +px_void PX_ImageFilter_RobertsY(px_texture *ptexture,px_float out[]); +px_void PX_ImageFilter_Roberts(px_texture *ptexture,px_float out[]); +px_void PX_ImageFilter_LaplacianX(px_texture *ptexture,px_float out[]); +px_void PX_ImageFilter_LaplacianY(px_texture *ptexture,px_float out[]); +px_void PX_ImageFilter_Laplacian(px_texture *ptexture,px_float out[]); + +#endif diff --git a/lib/PainterEngine/core/PX_KalmanFilter.c b/lib/PainterEngine/core/PX_KalmanFilter.c new file mode 100644 index 0000000000000000000000000000000000000000..cc7a648b1e32641a460acdc69f1559784ae433bf --- /dev/null +++ b/lib/PainterEngine/core/PX_KalmanFilter.c @@ -0,0 +1,28 @@ +#include "PX_KalmanFilter.h" + +px_void PX_KalmanFilterInitialize(PX_KalmanFilter *filter,px_double A,px_double B,px_double Q,px_double H,px_double R) +{ + filter->A=A; + filter->B=B; + filter->H=H; + filter->Kk=0; + filter->Pk=1; + filter->Q=Q; + filter->R=R; + filter->Xk=0; +} + +px_void PX_KalmanFilterUpdate(PX_KalmanFilter *filter,px_double Zk,px_double uk,px_double wk) +{ + filter->Xk=filter->A*filter->Xk+filter->B*uk; + filter->Pk=filter->A*filter->Pk*filter->A+filter->Q; + + filter->Kk=filter->Pk/(filter->H*filter->Pk*filter->H+filter->R); + filter->Xk=filter->Xk+filter->Kk*(Zk-filter->Xk); + filter->Pk=(1-filter->Kk*filter->H)*filter->Pk; +} + +px_double PX_KalmanFilterGetGuess(PX_KalmanFilter *filter) +{ + return filter->Xk; +} diff --git a/lib/PainterEngine/core/PX_KalmanFilter.h b/lib/PainterEngine/core/PX_KalmanFilter.h new file mode 100644 index 0000000000000000000000000000000000000000..f193b6e849f110e0178103e0e26ac6a017ac4ecf --- /dev/null +++ b/lib/PainterEngine/core/PX_KalmanFilter.h @@ -0,0 +1,15 @@ +#ifndef PX_KALMANFILTER_H +#define PX_KALMANFILTER_H +#include "PX_Typedef.h" + +typedef struct +{ + px_double Xk,Kk,Pk; + px_double A,B,Q,H,R; +}PX_KalmanFilter; + +px_void PX_KalmanFilterInitialize(PX_KalmanFilter *filter,px_double A,px_double B,px_double Q,px_double H,px_double R); +px_void PX_KalmanFilterUpdate(PX_KalmanFilter *filter,px_double Zk,px_double uk,px_double wk); +px_double PX_KalmanFilterGetGuess(PX_KalmanFilter *filter); + +#endif diff --git a/lib/PainterEngine/core/PX_Linker.c b/lib/PainterEngine/core/PX_Linker.c new file mode 100644 index 0000000000000000000000000000000000000000..15300e2ff7ba5dc9e89555af98bec52283dbba29 --- /dev/null +++ b/lib/PainterEngine/core/PX_Linker.c @@ -0,0 +1,19 @@ +#include "PX_Linker.h" +px_void PX_LinkerInitialize(PX_Linker *linker,PX_LinkerRead_func read,px_void *readUserPtr,PX_LinkerWrite_func write,px_void *writeUserPtr) +{ + linker->read=read; + linker->write=write; + linker->readUserPtr=readUserPtr; + linker->writeUserPtr=writeUserPtr; +} + +px_int PX_LinkerRead(PX_Linker *linker,px_void *data,px_int datasize) +{ + return linker->read(linker->readUserPtr,data,datasize); +} + +px_int PX_LinkerWrite(PX_Linker *linker,px_void *data,px_int datasize) +{ + return linker->write(linker->readUserPtr,data,datasize); +} + diff --git a/lib/PainterEngine/core/PX_Linker.h b/lib/PainterEngine/core/PX_Linker.h new file mode 100644 index 0000000000000000000000000000000000000000..6285cd91dced5d0625ecdb7320ae6b0b0d8f0e25 --- /dev/null +++ b/lib/PainterEngine/core/PX_Linker.h @@ -0,0 +1,23 @@ +#ifndef PX_LINKER_H +#define PX_LINKER_H + +#include "PX_Typedef.h" + +typedef px_int (*PX_LinkerRead_func)(px_void *userPtr,px_void *data,px_int datasize); +typedef px_int (*PX_LinkerWrite_func)(px_void *userPtr,px_void *data,px_int datasize); + + +typedef struct +{ + PX_LinkerRead_func read; + px_void *readUserPtr; + PX_LinkerWrite_func write; + px_void *writeUserPtr; +}PX_Linker; + +px_void PX_LinkerInitialize(PX_Linker *linker,PX_LinkerRead_func read,px_void *readUserPtr,PX_LinkerWrite_func write,px_void *writeUserPtr); +px_int PX_LinkerRead(PX_Linker *linker,px_void *data,px_int datasize); +px_int PX_LinkerWrite(PX_Linker *linker,px_void *data,px_int datasize); + + +#endif diff --git a/lib/PainterEngine/core/PX_List.c b/lib/PainterEngine/core/PX_List.c new file mode 100644 index 0000000000000000000000000000000000000000..dd12d8f120babcf37441693387a5f84ed6075c0f --- /dev/null +++ b/lib/PainterEngine/core/PX_List.c @@ -0,0 +1,204 @@ +#include "PX_List.h" + +px_void PX_ListInitialize(px_memorypool *mp,px_list *list) +{ + list->end=PX_NULL; + list->head=PX_NULL; + list->size=0; + list->mp=mp; +} + +px_void *PX_ListPush(px_list *list,px_void *data,px_int size) +{ + px_list_node *node; + if (list->head==PX_NULL) + { + list->head=(px_list_node *)MP_Malloc(list->mp,sizeof(px_list_node)); + list->head->pdata=MP_Malloc(list->mp,size); + PX_memcpy(list->head->pdata,data,size); + list->head->pnext=PX_NULL; + list->head->ppre=PX_NULL; + list->end=list->head; + list->size++; + return list->head->pdata; + } + else + { + node=(px_list_node *)MP_Malloc(list->mp,sizeof(px_list_node)); + node->pdata=MP_Malloc(list->mp,size); + PX_memcpy(node->pdata,data,size); + node->pnext=PX_NULL; + node->ppre=list->end; + list->end->pnext=node; + list->end=node; + list->size++; + return node->pdata; + } +} + +px_bool PX_ListPop(px_list *list,px_list_node *node) +{ + if (!node) + { + PX_ERROR("Error List node pop"); + return PX_FALSE; + } + MP_Free(list->mp,node->pdata); + if (node==list->head) + { + list->head=list->head->pnext; + if (list->head) + { + list->head->ppre=PX_NULL; + } + MP_Free(list->mp,node); + list->size--; + if (list->size==0) + { + list->head=PX_NULL; + list->end=PX_NULL; + } + return PX_TRUE; + } + + if (node==list->end) + { + list->end=list->end->ppre; + if (list->end) + { + list->end->pnext=PX_NULL; + } + MP_Free(list->mp,node); + list->size--; + if (list->size==0) + { + list->head=PX_NULL; + list->end=PX_NULL; + } + return PX_TRUE; + } + node->ppre->pnext=node->pnext; + node->pnext->ppre=node->ppre; + MP_Free(list->mp,node); + list->size--; + + return PX_TRUE; +} + + +px_bool PX_ListErase(px_list *list,px_int i) +{ + return PX_ListPop(list,PX_ListNodeAt(list,i)); +} + +px_list_node* PX_ListNodeAt(px_list *list,px_int index) +{ + px_list_node *node=list->head; + if (index>=list->size) + { + return PX_NULL; + } + while (index--) + { + node=node->pnext; + } + return node; +} + + +px_list_node* PX_ListNodeNext(px_list_node* node) +{ + return node->pnext; +} + +px_void PX_ListMove(px_list *list,px_int index,px_int moveto) +{ + px_list_node *pNode=list->head; + px_list_node *pMoveToNode=list->head; + if (index>=list->size||index==moveto) + { + return; + } + + while (index) + { + pNode=pNode->pnext; + index--; + } + + while (moveto) + { + pMoveToNode=pMoveToNode->pnext; + moveto--; + } + + //disconnect + if (pNode==list->head) + { + list->head=pNode->pnext; + pNode->pnext->ppre=pNode->ppre; + } + else if (pNode==list->end) + { + pNode->ppre->pnext=PX_NULL; + list->end=pNode->ppre; + } + else + { + pNode->ppre->pnext=pNode->pnext; + pNode->pnext->ppre=pNode->ppre; + } + + //insert + if (pMoveToNode==list->head) + { + pNode->pnext=list->head; + pNode->ppre=PX_NULL; + + list->head->ppre=pNode; + list->head=pNode; + } + else if (pMoveToNode==list->end) + { + pNode->ppre=list->end; + pNode->pnext=PX_NULL; + + list->end->pnext=pNode; + list->end=pNode; + } + else + { + pNode->pnext=pMoveToNode; + pNode->ppre=pMoveToNode->ppre; + pMoveToNode->ppre->pnext=pNode; + pMoveToNode->ppre=pNode; + } + + +} + +px_int PX_ListSize(px_list *list) +{ + return list->size; +} + +px_void PX_ListClear(px_list *list) +{ + px_list_node *node=list->head; + px_list_node *pn; + while (node) + { + pn=node; + node=node->pnext; + MP_Free(list->mp,pn->pdata); + MP_Free(list->mp,pn); + } + list->end=PX_NULL; + list->head=PX_NULL; + list->size=0; +} + +px_void PX_ListFree(px_list *list) +{ + PX_ListClear(list); +} diff --git a/lib/PainterEngine/core/PX_List.h b/lib/PainterEngine/core/PX_List.h new file mode 100644 index 0000000000000000000000000000000000000000..2e924f57c3514da633d25e0c9ae088a5dc16284d --- /dev/null +++ b/lib/PainterEngine/core/PX_List.h @@ -0,0 +1,40 @@ +#ifndef __PX_LIST_H +#define __PX_LIST_H +#include "PX_MemoryPool.h" +typedef struct __px_list_node +{ + px_void *pdata; + struct __px_list_node *pnext; + struct __px_list_node *ppre; +}px_list_node; + +typedef struct __px_list +{ + px_memorypool *mp; + px_int size; + struct __px_list_node *head; + struct __px_list_node *end; +}px_list; + + + + +////////////////////////////////////////////////////////////////////////// +//List +px_void PX_ListInitialize(px_memorypool *mp,px_list *list); +px_void *PX_ListPush(px_list *list,px_void *data,px_int size); +px_bool PX_ListPop(px_list *list,px_list_node *node); +px_bool PX_ListErase(px_list *list,px_int i); +px_list_node* PX_ListNodeAt(px_list *list,px_int index); +px_list_node* PX_ListNodeNext(px_list_node* node); + + +px_void PX_ListMove(px_list *list,px_int index,px_int moveto); +px_int PX_ListSize(px_list *list); +px_void PX_ListClear(px_list *list); +px_void PX_ListFree(px_list *list); + +#define PX_LIST_NODEDATA(x) ((x)->pdata) +#define PX_LIST_NODETDATA(t,x) ((t *)(x->pdata)) +#define PX_LISTAT(t,x,i) ((t *)(PX_ListNodeAt(x,i)->pdata)) +#endif diff --git a/lib/PainterEngine/core/PX_Log.c b/lib/PainterEngine/core/PX_Log.c new file mode 100644 index 0000000000000000000000000000000000000000..182336f8a83eed51de70d96a6bb3c8157960b699 --- /dev/null +++ b/lib/PainterEngine/core/PX_Log.c @@ -0,0 +1,26 @@ +#include "PX_Typedef.h" + + +void PX_ASSERT(void) +{ +#ifdef PX_DEBUG_MODE + while(1) *(char *)(0)=1; +#endif +} + +void PX_ERROR(px_char fmt[]) +{ + PX_ASSERT(); +} + + +px_char * PX_GETLOG(void) +{ + return ""; +} + +void PX_LOG(px_char fmt[]) +{ + + //while(1); +} diff --git a/lib/PainterEngine/core/PX_Log.h b/lib/PainterEngine/core/PX_Log.h new file mode 100644 index 0000000000000000000000000000000000000000..1539be5834b213ed7202bef1ff09464fcfde7f43 --- /dev/null +++ b/lib/PainterEngine/core/PX_Log.h @@ -0,0 +1,7 @@ +#ifndef __PX_LOG_H +#define __PX_LOG_H +void PX_LOG(char fmt[]); +void PX_ERROR(char fmt[]); +char *PX_GETLOG(void); +void PX_ASSERT(void); +#endif diff --git a/lib/PainterEngine/core/PX_MFCC.c b/lib/PainterEngine/core/PX_MFCC.c new file mode 100644 index 0000000000000000000000000000000000000000..b3bc7e9c810e2f86b1973fd70a203503e116fedf --- /dev/null +++ b/lib/PainterEngine/core/PX_MFCC.c @@ -0,0 +1,138 @@ +#include "PX_MFCC.h" + + +static px_double PX_HzToMel(px_double freq) +{ + return 1127*PX_log(1.0 + freq/700); +} + +static px_double PX_MelToHz(px_double freq) +{ + return 700 * (PX_exp(freq/1127) - 1); +} + + +void PX_liftwindow(px_double* p, int m) +{ + int i; + px_double max_value = 0.0f; + for(i = 1; i <= m; i++) + { + p[i-1] = 1+ 0.5 * m * PX_sind( PX_PI * i/m ); + if( p[i-1] > max_value) + { + max_value = p[i-1]; + } + } + for(i = 1; i <= m; i++) + { + p[i-1] /= max_value; + } +} + +px_void PX_MFCCInitialize(PX_MFCC *mfcc,px_int framesize,px_int sampleRate,px_int low,px_int high) +{ + px_int i,j; + px_double fre_bin = (px_double)sampleRate / framesize; + px_double low_mel = PX_HzToMel(low); + px_double high_mel = PX_HzToMel(high); + px_double mel_bw = (high_mel - low_mel)/(PX_MFCC_DCT_FACTOR_SIZE + 1); + px_int valid_nfft = framesize/2 + 1; + + mfcc->N=framesize; + PX_memset(mfcc->filter,0,sizeof(mfcc->filter)); + + for(j = 1; j <= PX_MFCC_DCT_FACTOR_SIZE; j++) + { + px_double mel_cent = j * mel_bw + low_mel; + px_double mel_left = mel_cent - mel_bw; + px_double mel_right = mel_cent + mel_bw; + px_double freq_cent = PX_MelToHz(mel_cent); + px_double freq_left = PX_MelToHz(mel_left); + px_double freq_bw_left = freq_cent - freq_left; + px_double freq_right = PX_MelToHz(mel_right); + px_double freq_bw_right = freq_right - freq_cent; + for(i = 1; i <= valid_nfft; i++) + { + px_double freq = (i-1) * fre_bin ; + if( freq > freq_left && freq < freq_right ) + { + if( freq <= freq_cent) + { + mfcc->filter[j-1].w[i-1] = (freq - freq_left) / freq_bw_left; + } + else + { + mfcc->filter[j-1].w[i-1] = (freq_right - freq) / freq_bw_right; + } + } + } + } + +} + +px_bool PX_MFCCParse(PX_MFCC *mfcc,px_double *data,PX_MFCC_FEATURE *out) +{ + px_int i,j; + px_complex cal[PX_MFCC_FRAME_MAX_SIZE]; + px_double window[PX_MFCC_FRAME_MAX_SIZE]; + px_double dct_data[PX_MFCC_DCT_FACTOR_SIZE]; + px_double dct_rdata[PX_MFCC_DCT_FACTOR_SIZE]; + + PX_WindowFunction_hamming(window,mfcc->N); + + for(i = mfcc->N - 1; i >= 1; i--) + { + cal[i].re = data[i] - 0.9375 * data[i-1]; + cal[i].im=0; + } + cal[0].re = data[0]; + cal[0].im=0; + + for (i=0;iN;i++) + { + cal[i].re*=window[i]; + } + + PX_FFT(cal,cal,mfcc->N); + + //re,im->power,phase + for (i=0;iN;i++) + { + px_double pw,phase; + pw=(cal[i].re*cal[i].re+cal[i].im*cal[i].im)/mfcc->N; + phase=PX_atan2(cal[i].re,cal[i].im); + cal[i].re=pw; + cal[i].im=phase; + } + + PX_memset(dct_data,0,sizeof(dct_data)); + + //filter bank + for (i=0;iN;j++) + { + dct_data[i]+=cal[i].re*mfcc->filter[i].w[j]; + } + if (dct_data[i]>1) + { + dct_data[i]=PX_ln(dct_data[i]); + } + else + { + dct_data[i]=0; + } + } + + + //dct + PX_DCT(dct_data,dct_rdata,PX_MFCC_DCT_FACTOR_SIZE); + + for (i=0;ifactor[i]=dct_rdata[i]; + } + + return PX_TRUE; +} diff --git a/lib/PainterEngine/core/PX_MFCC.h b/lib/PainterEngine/core/PX_MFCC.h new file mode 100644 index 0000000000000000000000000000000000000000..8980dbafff430edc81fda6513cc889efdc6e8943 --- /dev/null +++ b/lib/PainterEngine/core/PX_MFCC.h @@ -0,0 +1,28 @@ +#ifndef PX_MFCC_H +#define PX_MFCC_H +#include "PX_MemoryPool.h" + +#define PX_MFCC_FRAME_MAX_SIZE 2048 +#define PX_MFCC_DCT_FACTOR_SIZE 32 +typedef struct +{ + px_double w[PX_MFCC_FRAME_MAX_SIZE]; +}PX_MFCC_Filter; + + +typedef struct +{ + PX_MFCC_Filter filter[PX_MFCC_DCT_FACTOR_SIZE]; + px_int N; +}PX_MFCC; + +typedef struct +{ + px_double factor[PX_MFCC_DCT_FACTOR_SIZE]; +}PX_MFCC_FEATURE; + +px_void PX_MFCCInitialize(PX_MFCC *mfcc,px_int framesize,px_int sampleRate,px_int low,px_int high); +px_bool PX_MFCCParse(PX_MFCC *mfcc,px_double *data,PX_MFCC_FEATURE *out); +#endif + + diff --git a/lib/PainterEngine/core/PX_MathTable.h b/lib/PainterEngine/core/PX_MathTable.h new file mode 100644 index 0000000000000000000000000000000000000000..e93b4571d83beb59081830a63cde8be36a19aef2 --- /dev/null +++ b/lib/PainterEngine/core/PX_MathTable.h @@ -0,0 +1,15 @@ +#ifndef __PX_MATH_TABLE_H +#define __PX_MATH_TABLE_H +static int const px_hex_to_dex_table[]={0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0, + 0,0,0,0,1,2,3,4,5,6, + 7,8,9,0,0,0,0,0,0, + 0,10,11,12,13,14,15,0,0, + 0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,10, + 11,12,13,14,15}; +#endif diff --git a/lib/PainterEngine/core/PX_Memory.c b/lib/PainterEngine/core/PX_Memory.c new file mode 100644 index 0000000000000000000000000000000000000000..f27b22258b250c8d31964461aec4c04418c523f6 --- /dev/null +++ b/lib/PainterEngine/core/PX_Memory.c @@ -0,0 +1,158 @@ +#include "PX_Memory.h" +px_void PX_MemoryInitialize(px_memorypool *mp,px_memory *memory) +{ + memory->buffer=PX_NULL; + memory->allocsize=0; + memory->usedsize=0; + memory->mp=mp; +} + +px_bool PX_MemoryCat(px_memory *memory,const px_void *buffer,px_int size) +{ + px_byte *old; + px_int length,shl; + + if (size==0) + { + return PX_TRUE; + } + + if (memory->usedsize+size>memory->allocsize) + { + shl=0; + old=memory->buffer; + length=memory->usedsize+size; + while ((px_int)(1<<++shl)<=length); + memory->allocsize=(1<buffer=(px_byte*)MP_Malloc(memory->mp,memory->allocsize); + if(!memory->buffer) return PX_FALSE; + if(old) + PX_memcpy(memory->buffer,old,memory->usedsize); + + PX_memcpy(memory->buffer+memory->usedsize,buffer,size); + + if(old) + MP_Free(memory->mp,old); + } + else + { + PX_memcpy(memory->buffer+memory->usedsize,buffer,size); + } + memory->usedsize+=size; + return PX_TRUE; +} + +px_void PX_MemoryFree(px_memory *memory) +{ + if (memory->allocsize==0||memory->buffer==PX_NULL) + { + return; + } + MP_Free(memory->mp,memory->buffer); + memory->buffer=PX_NULL; + memory->usedsize=0; + memory->allocsize=0; +} + +px_byte * PX_MemoryData(px_memory *memory) +{ + return memory->buffer; +} + +px_bool PX_MemoryAlloc(px_memory *memory,px_int size) +{ + PX_MemoryFree(memory); + memory->allocsize=size; + memory->usedsize=0; + if (size==0) + { + memory->buffer=PX_NULL; + return PX_TRUE; + } + else + { + return (memory->buffer=(px_byte *)MP_Malloc(memory->mp,size))!=0; + } + +} + +px_bool PX_MemoryResize(px_memory *memory,px_int size) +{ + return PX_MemoryAlloc(memory,size); +} + + +px_byte *PX_MemoryFind(px_memory *memory,const px_void *buffer,px_int size) +{ + px_int offest; + if (memory->usedsizeusedsize-size+1;offest++) + { + if (PX_memequ(memory->buffer+offest,buffer,size)) + { + return (memory->buffer+offest); + } + } + return PX_NULL; +} + + +px_void PX_MemoryRemove(px_memory *memory,px_int start,px_int end) +{ + if (start<0||start=memory->usedsize) + { + return; + } + PX_memcpy(memory->buffer+start,memory->buffer+end+1,start-end+1); +} + + +px_void PX_MemoryClear(px_memory *memory) +{ + memory->usedsize=0; +} + +px_bool PX_MemoryCopy(px_memory *memory,const px_void *buffer,px_int startoffset,px_int size) +{ + px_byte *old; + px_int length,shl; + + if (startoffset+size>memory->allocsize) + { + shl=0; + old=memory->buffer; + length=startoffset+size; + while ((px_int)(1<<++shl)<=length); + memory->allocsize=(1<buffer=(px_byte*)MP_Malloc(memory->mp,memory->allocsize); + if (!memory->buffer) + { + MP_Free(memory->mp,old); + return PX_FALSE; + } + if(old) + PX_memcpy(memory->buffer,old,memory->usedsize); + + PX_memcpy(memory->buffer+startoffset,buffer,size); + + if(old) + MP_Free(memory->mp,old); + + memory->usedsize=startoffset+size; + } + else + { + if (startoffset+size>memory->usedsize) + { + memory->usedsize=startoffset+size; + } + + PX_memcpy(memory->buffer+startoffset,buffer,size); + + } + return PX_TRUE; +} + diff --git a/lib/PainterEngine/core/PX_Memory.h b/lib/PainterEngine/core/PX_Memory.h new file mode 100644 index 0000000000000000000000000000000000000000..8b620e7e79f7fe2714b0acb43fc54599e6c6cc9b --- /dev/null +++ b/lib/PainterEngine/core/PX_Memory.h @@ -0,0 +1,25 @@ +#ifndef __PX_MEMORY_H +#define __PX_MEMORY_H + +#include "PX_MemoryPool.h" + +typedef struct __PX_memroy +{ + px_byte *buffer; + px_memorypool *mp; + px_int usedsize; + px_int allocsize; +}px_memory; + +px_void PX_MemoryInitialize(px_memorypool *mp,px_memory *memory); +px_void PX_MemoryClear(px_memory *memory); +px_bool PX_MemoryAlloc(px_memory *memory,px_int size); +px_bool PX_MemoryResize(px_memory *memory,px_int size); +px_bool PX_MemoryCat(px_memory *memory,const px_void *buffer,px_int size); +px_bool PX_MemoryCopy(px_memory *memory,const px_void *buffer,px_int startoffset,px_int size); +px_byte *PX_MemoryFind(px_memory *memory,const px_void *buffer,px_int size); +px_void PX_MemoryRemove(px_memory *memory,px_int start,px_int end); +px_void PX_MemoryFree(px_memory *memory); +px_byte *PX_MemoryData(px_memory *memory); + +#endif diff --git a/lib/PainterEngine/core/PX_MemoryPool.c b/lib/PainterEngine/core/PX_MemoryPool.c new file mode 100644 index 0000000000000000000000000000000000000000..ebe1300da91907023507bbbd6a201c072cdabcba --- /dev/null +++ b/lib/PainterEngine/core/PX_MemoryPool.c @@ -0,0 +1,538 @@ +#include "PX_MemoryPool.h" + +#if defined(PX_DEBUG_MODE) && defined(PX_MEMORYPOOL_DEBUG_CHECK) + +#include "stdio.h" +static px_int DEBUG_i; +static px_int DEBUG_assert; +px_void MP_UnreleaseInfo(px_memorypool *mp) +{ + px_int i; + for (i=0;iDEBUG_allocdata)/sizeof(mp->DEBUG_allocdata[0]);i++) + { + if(mp->DEBUG_allocdata[i].addr) + printf("Warning:Unreleased memory in MID %p\n",mp->DEBUG_allocdata[i].addr); + + } +} + +#endif + + +typedef struct _MemoryNode +{ + px_void *StartAddr; + px_void *EndAddr; +}MemoryNode; + + + + + MemoryNode * PX_MemoryPool_GetFreeTableAddr(px_memorypool *MP) +{ + return (MemoryNode *)((px_uchar *)MP->EndAddr-(sizeof(MemoryNode)*MP->FreeTableCount)+1); +} + + MemoryNode *PX_MemoryPool_GetFreeTable(px_memorypool *MP,px_uint Index) +{ + Index++; + return (MemoryNode *)((px_uchar *)MP->EndAddr-(sizeof(MemoryNode)*Index)+1); +} + +MemoryNode *PX_AllocFromFree(px_memorypool *MP,px_uint Size) +{ + MemoryNode *Node; + if (Size+2*sizeof(MemoryNode)>MP->FreeSize) + { + return 0; + } + Node=(MemoryNode *)MP->AllocAddr; + (*Node).StartAddr=(px_uchar *)MP->AllocAddr+sizeof(MemoryNode); + (*Node).EndAddr=(px_uchar *)Node->StartAddr+Size-1; + + + MP->FreeSize-=(Size+2*sizeof(MemoryNode)); + MP->AllocAddr=(px_char *)MP->AllocAddr+Size+sizeof(MemoryNode); + + return Node; +} + + + + +px_void PX_MemoryPoolRemoveFreeNode(px_memorypool *MP,px_uint Index) +{ + px_uint i; + MemoryNode *pFreeNode=PX_MemoryPool_GetFreeTable(MP,Index); + + + for (i=Index;iFreeTableCount;i++) + { + (*pFreeNode)=*(pFreeNode-1); + pFreeNode--; + } + + MP->FreeTableCount--; + if (MP->FreeTableCount==0) + { + MP->MaxMemoryfragSize=0; + } + +} + +MemoryNode *PX_AllocFreeMemoryNode(px_memorypool *MP) +{ + MP->FreeTableCount++; + return PX_MemoryPool_GetFreeTable(MP,MP->FreeTableCount-1); +} + +px_void PX_UpdateMaxFreqSize(px_memorypool *MP) +{ + MemoryNode *itNode; + px_uint i,Size; + + MP->MaxMemoryfragSize=0; + + for(i=0;iFreeTableCount;i++) + { + itNode=PX_MemoryPool_GetFreeTable(MP,i); + if ((Size=(px_uint)(((px_char *)itNode->EndAddr-(px_char *)itNode->StartAddr)+1))>MP->MaxMemoryfragSize) + { + MP->MaxMemoryfragSize=Size; + } + } +} + +MemoryNode *PX_AllocFromFreq(px_memorypool *MP,px_uint Size) +{ + px_uint i,fSize; + MemoryNode *itNode,*allocNode; + + Size+=sizeof(MemoryNode); + + if (MP->MaxMemoryfragSize>=Size) + { + + for(i=0;iFreeTableCount;i++) + { + itNode=PX_MemoryPool_GetFreeTable(MP,i); + fSize=(px_uint)((px_char *)itNode->EndAddr-(px_char *)itNode->StartAddr+1); + + if (Size<=fSize&&(Size+sizeof(MemoryNode)>=fSize)) + { + allocNode=(MemoryNode *)itNode->StartAddr; + + + allocNode->StartAddr=(px_char *)itNode->StartAddr+sizeof(MemoryNode); + allocNode->EndAddr=itNode->EndAddr; + + + PX_MemoryPoolRemoveFreeNode(MP,i); + PX_UpdateMaxFreqSize(MP); + return allocNode; + } + else + { + if(SizeFreeSizeStartAddr; + allocNode->StartAddr=(px_char *)itNode->StartAddr+sizeof(MemoryNode); + allocNode->EndAddr=(px_char *)itNode->StartAddr+Size-1; + + itNode->StartAddr=(px_char *)allocNode->EndAddr+1; + MP->FreeSize-=sizeof(MemoryNode); + PX_UpdateMaxFreqSize(MP); + return allocNode; + } + } + + } + return 0; + } + else + { + return 0; + } +} + + + + + +px_memorypool MP_Create( px_void *MemoryAddr,px_uint MemorySize ) +{ + px_uint Index=0; + px_memorypool MP; + MP.StartAddr=MemoryAddr; + MP.AllocAddr=MemoryAddr; + if(MemorySize) + MP.EndAddr=((px_uchar*)MemoryAddr)+MemorySize-1; + else + MP.EndAddr=MP.StartAddr; + + MP.Size=MemorySize; + MP.FreeSize=MemorySize; + MP.FreeTableCount=0; + MP.MaxMemoryfragSize=0; + MP.nodeCount=0; + MP.ErrorCall_Ptr=PX_NULL; + PX_memset(MemoryAddr,0,MemorySize); + +#if defined(PX_DEBUG_MODE) && defined(PX_MEMORYPOOL_DEBUG_CHECK) + + for (DEBUG_i=0;DEBUG_iDEBUG_allocdata)/sizeof(MP->DEBUG_allocdata[0]);DEBUG_i++) + { + if (MP->DEBUG_allocdata[DEBUG_i].addr!=PX_NULL) + { + MP_Append_data *pAppend; + pAppend=(MP_Append_data *)((px_uchar *)MP->DEBUG_allocdata[DEBUG_i].endAddr-sizeof(MP_Append_data)+1); + itNode=(MemoryNode *)((px_uchar *)MP->DEBUG_allocdata[DEBUG_i].addr-sizeof(MemoryNode)); + if(MP->DEBUG_allocdata[DEBUG_i].startAddr!=itNode->StartAddr) + { + PX_ASSERT(); + return PX_NULL; + } + if(MP->DEBUG_allocdata[DEBUG_i].endAddr!=itNode->EndAddr) + { + PX_ASSERT(); + return PX_NULL; + } + if(pAppend->append!=MP_APPENDDATA_MAGIC) + { + PX_ASSERT(); + return PX_NULL; + } + } + } + +#endif + if (Size==0) + { + return PX_NULL; + } +#if defined(PX_DEBUG_MODE) && defined(PX_MEMORYPOOL_DEBUG_CHECK) + Size+=sizeof(MP_Append_data); +#endif + if (Size%__PX_MEMORYPOOL_ALIGN_BYTES) + { + Size=(Size/__PX_MEMORYPOOL_ALIGN_BYTES+1)*__PX_MEMORYPOOL_ALIGN_BYTES; + } + //Allocate from freq + + MemNode=PX_AllocFromFreq(MP,Size); + if (MemNode!=0) + { +#if defined(PX_DEBUG_MODE) && defined(PX_MEMORYPOOL_DEBUG_CHECK) + for (DEBUG_i=0;DEBUG_iDEBUG_allocdata)/sizeof(MP->DEBUG_allocdata[0]);DEBUG_i++) + { + if(MP->DEBUG_allocdata[DEBUG_i].addr==0) + { + MP->DEBUG_allocdata[DEBUG_i].addr=MemNode->StartAddr; + MP->DEBUG_allocdata[DEBUG_i].startAddr=MemNode->StartAddr; + MP->DEBUG_allocdata[DEBUG_i].endAddr=MemNode->EndAddr; + break; + } + } + pAppend=(MP_Append_data *)((px_uchar *)MemNode->EndAddr-sizeof(MP_Append_data)+1); + pAppend->append=MP_APPENDDATA_MAGIC; + #endif + MP->nodeCount++; + return MemNode->StartAddr; + } + + //Allocate from free + + MemNode=PX_AllocFromFree(MP,Size); + if (MemNode!=0) + { +#if defined(PX_DEBUG_MODE) && defined(PX_MEMORYPOOL_DEBUG_CHECK) + for (DEBUG_i=0;DEBUG_iDEBUG_allocdata)/sizeof(MP->DEBUG_allocdata[0]);DEBUG_i++) + { + if(MP->DEBUG_allocdata[DEBUG_i].addr==0) + { + MP->DEBUG_allocdata[DEBUG_i].addr=MemNode->StartAddr; + MP->DEBUG_allocdata[DEBUG_i].startAddr=MemNode->StartAddr; + MP->DEBUG_allocdata[DEBUG_i].endAddr=MemNode->EndAddr; + break; + } + } + pAppend=(MP_Append_data *)((px_uchar *)MemNode->EndAddr-sizeof(MP_Append_data)+1); + pAppend->append=MP_APPENDDATA_MAGIC; + #endif + MP->nodeCount++; + return MemNode->StartAddr; + } + + if(MP->ErrorCall_Ptr==PX_NULL) + PX_ERROR("MemoryPool Out Of Memory!"); + else + MP->ErrorCall_Ptr(PX_MEMORYPOOL_ERROR_OUTOFMEMORY); + + return PX_NULL; + +} + + + +px_void MP_Free(px_memorypool *MP, px_void *pAddress ) +{ + px_uint32 i,sIndex; + MemoryNode *itNode; + MemoryNode FreeNode; + px_uchar *pcTempStart,*pcTempEnd; + px_uchar bExist; + px_void *TempPointer; + MemoryNode *TempNode; + MP->nodeCount--; + bExist=0; + #if defined(PX_DEBUG_MODE) + if (!pAddress) + { + PX_ASSERT(); + return; + } + #endif + //Get Memory node information + TempPointer=(px_uchar *)pAddress-sizeof(MemoryNode); + TempNode=(MemoryNode *)TempPointer; + FreeNode.StartAddr=TempNode->StartAddr; + FreeNode.EndAddr=TempNode->EndAddr; + + +#if defined(PX_DEBUG_MODE) && defined(PX_MEMORYPOOL_DEBUG_CHECK) + if(FreeNode.StartAddr!=pAddress) PX_ASSERT(); + + for (DEBUG_i=0;DEBUG_iDEBUG_allocdata)/sizeof(MP->DEBUG_allocdata[0]);DEBUG_i++) + { + if(MP->DEBUG_allocdata[DEBUG_i].addr==pAddress) + { + MP_Append_data *pAppend; + pAppend=(MP_Append_data *)((px_uchar *)MP->DEBUG_allocdata[DEBUG_i].endAddr-sizeof(MP_Append_data)+1); + if(MP->DEBUG_allocdata[DEBUG_i].startAddr!=FreeNode.StartAddr) PX_ASSERT(); + if(MP->DEBUG_allocdata[DEBUG_i].endAddr!=FreeNode.EndAddr) PX_ASSERT(); + if(pAppend->append!=MP_APPENDDATA_MAGIC)PX_ASSERT(); + MP->DEBUG_allocdata[DEBUG_i].addr=PX_NULL; + MP->DEBUG_allocdata[DEBUG_i].startAddr=PX_NULL; + MP->DEBUG_allocdata[DEBUG_i].endAddr=PX_NULL; + break; + } + } + + if (MP->DEBUG_allocdata[PX_COUNTOF(MP->DEBUG_allocdata)-1].addr==PX_NULL) + { + if(DEBUG_i==sizeof(MP->DEBUG_allocdata)/sizeof(MP->DEBUG_allocdata[0])) + { + if(MP->ErrorCall_Ptr==PX_NULL) + PX_LOG("Invalid address free"); + else + MP->ErrorCall_Ptr(PX_MEMORYPOOL_ERROR_INVALID_ADDRESS); + + PX_ASSERT(); + goto _END; + } + } + + + + +#endif + + //px_memset(FreeNode.StartAddr,0xff,(px_int)FreeNode.EndAddr-(px_int)FreeNode.StartAddr+1); + //Reset address + FreeNode.StartAddr=(px_uchar *)FreeNode.StartAddr-sizeof(MemoryNode); + + //If this memory node is last + if ((px_char *)FreeNode.EndAddr+1==(px_char *)MP->AllocAddr) + { + for(i=0;iFreeTableCount;i++) + { + itNode=PX_MemoryPool_GetFreeTable(MP,i); + if ((px_char *)itNode->EndAddr+1==(px_char *)FreeNode.StartAddr) + { + MP->AllocAddr=itNode->StartAddr; + MP->FreeSize+=(px_uint32)((px_char *)FreeNode.EndAddr-(px_char *)FreeNode.StartAddr+sizeof(MemoryNode)+1); + MP->FreeSize+=(px_uint32)((px_char *)itNode->EndAddr-(px_char *)itNode->StartAddr+1+sizeof(MemoryNode)); + PX_MemoryPoolRemoveFreeNode(MP,i); + goto _END; + + } + } + + //just reset allocAddr to release this memory node + MP->AllocAddr=(px_char *)FreeNode.StartAddr; + MP->FreeSize+=(px_uint32)((px_char *)FreeNode.EndAddr-(px_char *)FreeNode.StartAddr+sizeof(MemoryNode)+1); + + goto _END; + } + + + + //Search memory node which can be combine + sIndex=0xffffffff; + for(i=0;iFreeTableCount;i++) + { + itNode=PX_MemoryPool_GetFreeTable(MP,i); + pcTempStart=(px_uchar *)itNode->StartAddr; + pcTempEnd=(px_uchar *)itNode->EndAddr; + + + if (pcTempStart==(px_uchar *)FreeNode.EndAddr+1) + { + if(sIndex==0xffffffff) + { + sIndex=i; + //Refresh this node + itNode->StartAddr=FreeNode.StartAddr; + FreeNode=*itNode; + MP->FreeSize+=sizeof(MemoryNode); + } + else + { + MP->FreeSize+=sizeof(MemoryNode); + itNode->StartAddr=FreeNode.StartAddr; + PX_MemoryPoolRemoveFreeNode(MP,sIndex); + } + bExist=1; + } + + + if (pcTempEnd+1==(px_uchar *)FreeNode.StartAddr) + { + if(sIndex==0xffffffff) + { + sIndex=i; + //Refresh this node + itNode->EndAddr=FreeNode.EndAddr; + FreeNode=*itNode; + MP->FreeSize+=sizeof(MemoryNode); + } + else + { + itNode->EndAddr=FreeNode.EndAddr; + MP->FreeSize+=sizeof(MemoryNode); + PX_MemoryPoolRemoveFreeNode(MP,sIndex); + + } + bExist=1; + } + } + if(bExist==0) + { +#if defined(PX_DEBUG_MODE) && defined(PX_MEMORYPOOL_DEBUG_CHECK) + for(i=0;iFreeTableCount;i++) + { + itNode=PX_MemoryPool_GetFreeTable(MP,i); + if (FreeNode.StartAddr>=itNode->StartAddr&&FreeNode.StartAddr<=itNode->EndAddr) + { + //alloc error + PX_ASSERT(); + goto _END; + } + if (FreeNode.EndAddr>=itNode->StartAddr&&FreeNode.EndAddr<=itNode->EndAddr) + { + PX_ASSERT(); + goto _END; + } + } +#endif + *PX_AllocFreeMemoryNode(MP)=FreeNode; + } + +_END: + PX_UpdateMaxFreqSize(MP); + +#if defined(PX_DEBUG_MODE) && defined(PX_MEMORYPOOL_DEBUG_CHECK) + for (DEBUG_i=0;DEBUG_iDEBUG_allocdata)/sizeof(MP->DEBUG_allocdata[0]);DEBUG_i++) + { + if(MP->DEBUG_allocdata[DEBUG_i].addr!=PX_NULL) + { + for(i=0;iFreeTableCount;i++) + { + itNode=PX_MemoryPool_GetFreeTable(MP,i); + if (MP->DEBUG_allocdata[DEBUG_i].startAddr>=itNode->StartAddr&&MP->DEBUG_allocdata[DEBUG_i].startAddr<=itNode->EndAddr) + { + //error free + PX_ASSERT(); + } + if (MP->DEBUG_allocdata[DEBUG_i].endAddr>=itNode->StartAddr&&MP->DEBUG_allocdata[DEBUG_i].endAddr<=itNode->EndAddr) + { + PX_ASSERT(); + } + } + } + } +#endif + return; +} + +px_void MP_Release(px_memorypool *Node) +{ + //free(G_MemoryPool.StartAddr); +} + +px_void MP_ErrorCatch(px_memorypool *Pool,PX_MP_ErrorCall ErrorCall) +{ + Pool->ErrorCall_Ptr=ErrorCall; +} + +px_uint MP_Size(px_memorypool *Pool,px_void *pAddress) +{ + px_void *TempPointer; + MemoryNode *TempNode; + //Get Memory node information + if (pAddress==PX_NULL) + { + PX_ASSERT(); + return 0; + } + TempPointer=(px_uchar *)pAddress-sizeof(MemoryNode); + TempNode=(MemoryNode *)TempPointer; +#if defined(PX_DEBUG_MODE) && defined(PX_MEMORYPOOL_DEBUG_CHECK) +return (px_uint)(((px_char *)(TempNode->EndAddr)-(px_char *)(TempNode->StartAddr))+1-sizeof(MP_Append_data)); +#else + return (px_uint32)((px_char *)(TempNode->EndAddr)-(px_char *)(TempNode->StartAddr))+1; +#endif + +} + +px_void MP_Reset(px_memorypool *Pool) +{ + Pool->AllocAddr=Pool->StartAddr; + Pool->EndAddr=((px_uchar*)Pool->StartAddr)+Pool->Size-1; + Pool->FreeSize=Pool->Size; + Pool->FreeTableCount=0; + Pool->MaxMemoryfragSize=0; + Pool->nodeCount=0; +#if defined(PX_DEBUG_MODE) && defined(PX_MEMORYPOOL_DEBUG_CHECK) + PX_memset(Pool->DEBUG_allocdata,0,sizeof(Pool->DEBUG_allocdata)); +#endif +} + diff --git a/lib/PainterEngine/core/PX_MemoryPool.h b/lib/PainterEngine/core/PX_MemoryPool.h new file mode 100644 index 0000000000000000000000000000000000000000..7a1c37f0473c1c7a0259b6d6cd804cb6c56838c3 --- /dev/null +++ b/lib/PainterEngine/core/PX_MemoryPool.h @@ -0,0 +1,89 @@ +#ifndef PIXELSES_MEMORYPOOL +#define PIXELSES_MEMORYPOOL +#include "PX_Typedef.h" + +#define __PX_MEMORYPOOL_ALIGN_BYTES (sizeof(void *)) +#define PX_MEMORYPOOL_DEBUG_CHECK + + +typedef enum +{ + PX_MEMORYPOOL_ERROR_OUTOFMEMORY, + PX_MEMORYPOOL_ERROR_INVALID_ACCESS, + PX_MEMORYPOOL_ERROR_INVALID_ADDRESS +}PX_MEMORYPOOL_ERROR; + +typedef px_void (*PX_MP_ErrorCall)(PX_MEMORYPOOL_ERROR); + +#if defined(PX_DEBUG_MODE) && defined(PX_MEMORYPOOL_DEBUG_CHECK) +typedef struct +{ + px_void *addr; + px_void *startAddr; + px_void *endAddr; +}MP_alloc_debug; + + +typedef struct +{ + px_dword append; +}MP_Append_data; +#define MP_APPENDDATA_MAGIC 0x31415926 +#endif + +typedef struct _memoryPool +{ + px_void *AllocAddr; + px_void *StartAddr; + px_void *EndAddr; + px_uint32 Size; + px_uint32 FreeSize; + px_uint32 nodeCount; + px_uint32 FreeTableCount; + px_uint32 MaxMemoryfragSize; + PX_MP_ErrorCall ErrorCall_Ptr; +#if defined(PX_DEBUG_MODE) && defined(PX_MEMORYPOOL_DEBUG_CHECK) + MP_alloc_debug DEBUG_allocdata[1024]; +#endif +}px_memorypool; + + +#if defined(PX_DEBUG_MODE) && defined(PX_MEMORYPOOL_DEBUG_CHECK) +px_void MP_UnreleaseInfo(px_memorypool *mp); +#define MP_DEBUG_AID(x) MP_UnreleaseInfo(x) +#else +#define MP_DEBUG_AID(x) +#endif + + +//Create a memory pool & return a MemoryPool structure +//MemoryAddr :Start address of memory +//MemorySize :Size of memory pool +px_memorypool MP_Create (px_void *MemoryAddr,px_uint MemorySize); + +//Get memory size of Ptr +//Pool: Pool MemoryPool structure pointer +//Ptr: memory pointer +//Return - if succeeded return the size of Ptr,else return zero +px_uint MP_Size(px_memorypool *Pool,px_void *Ptr); + +//Alloc a memory from memory pool +//Pool: Pool MemoryPool structure pointer +//Size: Size of alloc +//Return - if succeeded return the begin address of memories +// if faith return null +px_void *MP_Malloc (px_memorypool *Pool,px_uint Size); + +//Free the memory from memory pool +//Pool: Pool MemoryPool structure pointer +//pAddress: Pointer memory need to be free +px_void MP_Free (px_memorypool *Pool,px_void *pAddress); +px_void MP_Release (px_memorypool *Pool); +px_void MP_Reset (px_memorypool *Pool); + + +//Register memoryPool error +px_void MP_ErrorCatch(px_memorypool *Pool,PX_MP_ErrorCall ErrorCall); + +#endif + diff --git a/lib/PainterEngine/core/PX_Packet.c b/lib/PainterEngine/core/PX_Packet.c new file mode 100644 index 0000000000000000000000000000000000000000..0577f3e2dbbced93866abdeb74dabd7cbbf8bb0a --- /dev/null +++ b/lib/PainterEngine/core/PX_Packet.c @@ -0,0 +1,100 @@ +#include "PX_Packet.h" + + +px_bool PX_PacketCompress(px_byte *_in,px_uint input_size,px_byte *_out,px_uint *out_size,px_dword algorithm) +{ + PX_Packet_Header *pHeader=(PX_Packet_Header *)_out; + px_byte *pw=PX_NULL; + + if (!_out) + { + switch (algorithm) + { + case PX_PACKET_ALOGRITHM_HUFFMAN: + { + PX_huffmanCompress(_in,input_size,_out,out_size); + *out_size+=sizeof(PX_Packet_Header); + } + break; + case PX_PACKET_ALOGRITHM_ARLE: + { + PX_ArleCompress(_in,input_size,_out,out_size); + *out_size+=sizeof(PX_Packet_Header); + } + break; + } + return PX_TRUE; + } + + pHeader->algorithm=algorithm; + PX_memcpy(pHeader->magic,"PACK",4); + pHeader->CRC=PX_crc32(_in,input_size); + + switch (algorithm) + { + case PX_PACKET_ALOGRITHM_HUFFMAN: + { + PX_huffmanCompress(_in,input_size,_out+sizeof(PX_Packet_Header),out_size); + *out_size+=sizeof(PX_Packet_Header); + } + break; + case PX_PACKET_ALOGRITHM_ARLE: + { + PX_ArleCompress(_in,input_size,_out+sizeof(PX_Packet_Header),out_size); + *out_size+=sizeof(PX_Packet_Header); + } + break; + } + return PX_TRUE; +} + +px_bool PX_PacketDecompress(px_byte *_in,px_uint input_size,px_byte *_out,px_uint *out_size) +{ + PX_Packet_Header *pHeader=(PX_Packet_Header *)_in; + px_byte *pw=PX_NULL; + + if (!_out) + { + switch (pHeader->algorithm) + { + case PX_PACKET_ALOGRITHM_HUFFMAN: + { + PX_huffmanDecompress(_in+sizeof(PX_Packet_Header),input_size-sizeof(PX_Packet_Header),_out,out_size); + } + break; + case PX_PACKET_ALOGRITHM_ARLE: + { + PX_ArleDecompress(_in+sizeof(PX_Packet_Header),input_size-sizeof(PX_Packet_Header),_out,out_size); + } + break; + } + return PX_TRUE; + } + + + switch (pHeader->algorithm) + { + case PX_PACKET_ALOGRITHM_HUFFMAN: + { + PX_huffmanDecompress(_in+sizeof(PX_Packet_Header),input_size-sizeof(PX_Packet_Header),_out,out_size); + if (PX_crc32(_out,*out_size)!=pHeader->CRC) + { + return PX_FALSE; + } + return PX_TRUE; + } + break; + case PX_PACKET_ALOGRITHM_ARLE: + { + PX_ArleDecompress(_in+sizeof(PX_Packet_Header),input_size-sizeof(PX_Packet_Header),_out,out_size); + if (PX_crc32(_out,*out_size)!=pHeader->CRC) + { + return PX_FALSE; + } + return PX_TRUE; + } + break; + } + return PX_FALSE; +} + diff --git a/lib/PainterEngine/core/PX_Packet.h b/lib/PainterEngine/core/PX_Packet.h new file mode 100644 index 0000000000000000000000000000000000000000..30ca642ca46143ef8837feaa66bd229dfd7cd78f --- /dev/null +++ b/lib/PainterEngine/core/PX_Packet.h @@ -0,0 +1,20 @@ +#ifndef PX_PACKET_H +#define PX_PACKET_H + +#include "PX_Arle.h" +#include "PX_Huffman.h" + +#define PX_PACKET_ALOGRITHM_HUFFMAN 0 +#define PX_PACKET_ALOGRITHM_ARLE 1 + + +typedef struct +{ + px_char magic[4];//PACK + px_dword algorithm; + px_dword CRC; +}PX_Packet_Header; + +px_bool PX_PacketCompress(px_byte *_in,px_uint input_size,px_byte *_out,px_uint *out_size,px_dword algotithm); +px_bool PX_PacketDecompress(px_byte *_in,px_uint input_size,px_byte *_out,px_uint *out_size); +#endif diff --git a/lib/PainterEngine/core/PX_PointsMesh.c b/lib/PainterEngine/core/PX_PointsMesh.c new file mode 100644 index 0000000000000000000000000000000000000000..9caf84ab625b6113c1f38cc26ac67675936cff64 --- /dev/null +++ b/lib/PainterEngine/core/PX_PointsMesh.c @@ -0,0 +1,103 @@ +#include "PX_PointsMesh.h" + + +px_bool PX_PointsMeshBuild(px_memorypool *mp,px_point2D limit_line_pt[],px_int line_pt_count,px_point2D pt[],px_int pt_count,px_vector *out_triangles,PX_DELAUNAY_RETURN_TYPE type) +{ + px_int i; + px_float left=0,top=0,right=0,bottom=0; + px_float offsetx,offsety,width,height; + px_texture testTexture; + if (pt_count<2) + { + return PX_FALSE; + } + + left=pt[0].x; + right=pt[0].x; + bottom=pt[0].y; + top=pt[0].y; + + + for (i=0;iright) + { + right=pt[i].x; + } + + if (pt[i].ybottom) + { + bottom=pt[i].y; + } + } + + left-=2; + top-=2; + right+=2; + bottom+=2; + + offsetx=-left; + offsety=-top; + + width=right-left; + height=bottom-top; + + + PX_TextureCreate(mp,&testTexture,(px_int)(width+1),(px_int)(height+1)); + for (i=1;isize;i++) + { + px_int testx=0,testy=0; + + switch(type) + { + case PX_DELAUNAY_RETURN_TYPE_TRIANGLE: + { + px_triangle *ptriangle=PX_VECTORAT(px_triangle,out_triangles,i); + testx=(px_int)((ptriangle->Vertex_1.x+ptriangle->Vertex_2.x+ptriangle->Vertex_3.x)/3+offsetx); + testy=(px_int)((ptriangle->Vertex_1.y+ptriangle->Vertex_2.y+ptriangle->Vertex_3.y)/3+offsety); + } + break; + case PX_DELAUNAY_RETURN_TYPE_TRIANGLE_INDEX: + { + PX_Delaunay_Triangle *ptriangle=PX_VECTORAT(PX_Delaunay_Triangle,out_triangles,i); + px_point2D v1,v2,v3; + v1=pt[ptriangle->index1]; + v2=pt[ptriangle->index2]; + v3=pt[ptriangle->index3]; + testx=(px_int)((v1.x+v2.x+v3.x)/3+offsetx); + testy=(px_int)((v1.y+v2.y+v3.y)/3+offsety); + } + break; + } + + if (PX_SurfaceGetPixel(&testTexture,testx,testy)._argb.ucolor==0x00ffffff) + { + //remove + PX_VectorErase(out_triangles,i); + i--; + } + } + PX_TextureFree(&testTexture); + return PX_TRUE; +} + diff --git a/lib/PainterEngine/core/PX_PointsMesh.h b/lib/PainterEngine/core/PX_PointsMesh.h new file mode 100644 index 0000000000000000000000000000000000000000..e06fee5395f938f2be3ef81430ed484d7ef88caf --- /dev/null +++ b/lib/PainterEngine/core/PX_PointsMesh.h @@ -0,0 +1,10 @@ +#ifndef PX_POINTSMESH_H +#define PX_POINTSMESH_H + +#include "PX_Delaunay.h" +#include "PX_Texture.h" + +px_bool PX_PointsMeshBuild(px_memorypool *mp,px_point2D limit_line_pt[],px_int line_pt_count,px_point2D pt[],px_int pt_count,px_vector *out_triangles,PX_DELAUNAY_RETURN_TYPE type); + + +#endif diff --git a/lib/PainterEngine/core/PX_Quadtree.c b/lib/PainterEngine/core/PX_Quadtree.c new file mode 100644 index 0000000000000000000000000000000000000000..4b4e004b8a6faa639bb2d2c94636e9c46c4ba82e --- /dev/null +++ b/lib/PainterEngine/core/PX_Quadtree.c @@ -0,0 +1,257 @@ +#include "PX_Quadtree.h" + +//#include "stdio.h" + +static px_bool PX_Quadtree_InitAABB(px_memorypool *mp,px_int PX_AABB_MAX_DEEP,PX_Quadtree_AABB *aabb) +{ + if (aabb) + { + if (aabb->deep>=PX_AABB_MAX_DEEP) + { + PX_ListInitialize(mp,&aabb->dataList); + return PX_TRUE; + } + else + { + aabb->Area1=(PX_Quadtree_AABB *)MP_Malloc(mp,sizeof(PX_Quadtree_AABB)); + aabb->Area1->deep=aabb->deep+1; + aabb->Area1->Left=aabb->Left; + aabb->Area1->Right=(aabb->Left+aabb->Right)/2; + aabb->Area1->Top=aabb->Top; + aabb->Area1->Bottom=(aabb->Top+aabb->Bottom)/2; + aabb->Area1->objectCount=0; + aabb->Area1->Area1=PX_NULL; + aabb->Area1->Area2=PX_NULL; + aabb->Area1->Area3=PX_NULL; + aabb->Area1->Area4=PX_NULL; + aabb->Area1->dataList.size=0; + aabb->Area1->dataList.head=PX_NULL; + aabb->Area1->dataList.end=PX_NULL; + aabb->Area1->dataList.mp=PX_NULL; + if(!PX_Quadtree_InitAABB(mp,PX_AABB_MAX_DEEP,aabb->Area1)) return PX_FALSE; + + aabb->Area2=(PX_Quadtree_AABB *)MP_Malloc(mp,sizeof(PX_Quadtree_AABB)); + aabb->Area2->deep=aabb->deep+1; + aabb->Area2->Left=aabb->Area1->Left+(aabb->Right-aabb->Left)/2; + aabb->Area2->Right=aabb->Area1->Right+(aabb->Right-aabb->Left)/2; + aabb->Area2->Top=aabb->Area1->Top; + aabb->Area2->Bottom=aabb->Area1->Bottom; + aabb->Area2->objectCount=0; + aabb->Area2->Area1=PX_NULL; + aabb->Area2->Area2=PX_NULL; + aabb->Area2->Area3=PX_NULL; + aabb->Area2->Area4=PX_NULL; + aabb->Area2->dataList.size=0; + aabb->Area2->dataList.head=PX_NULL; + aabb->Area2->dataList.end=PX_NULL; + aabb->Area2->dataList.mp=PX_NULL; + if(!PX_Quadtree_InitAABB(mp,PX_AABB_MAX_DEEP,aabb->Area2)) return PX_FALSE; + + aabb->Area3=(PX_Quadtree_AABB *)MP_Malloc(mp,sizeof(PX_Quadtree_AABB)); + aabb->Area3->deep=aabb->deep+1; + aabb->Area3->Left=aabb->Area1->Left; + aabb->Area3->Right=aabb->Area1->Right; + aabb->Area3->Top=aabb->Area1->Top+(aabb->Bottom-aabb->Top)/2; + aabb->Area3->Bottom=aabb->Area1->Bottom+(aabb->Bottom-aabb->Top)/2;; + aabb->Area3->objectCount=0; + aabb->Area3->Area1=PX_NULL; + aabb->Area3->Area2=PX_NULL; + aabb->Area3->Area3=PX_NULL; + aabb->Area3->Area4=PX_NULL; + aabb->Area3->dataList.size=0; + aabb->Area3->dataList.head=PX_NULL; + aabb->Area3->dataList.end=PX_NULL; + aabb->Area3->dataList.mp=PX_NULL; + if(!PX_Quadtree_InitAABB(mp,PX_AABB_MAX_DEEP,aabb->Area3)) return PX_FALSE; + + aabb->Area4=(PX_Quadtree_AABB *)MP_Malloc(mp,sizeof(PX_Quadtree_AABB)); + aabb->Area4->deep=aabb->deep+1; + aabb->Area4->Left=aabb->Area1->Left+(aabb->Right-aabb->Left)/2; + aabb->Area4->Right=aabb->Area1->Right+(aabb->Right-aabb->Left)/2; + aabb->Area4->Top=aabb->Area1->Top+(aabb->Bottom-aabb->Top)/2; + aabb->Area4->Bottom=aabb->Area1->Bottom+(aabb->Bottom-aabb->Top)/2; + aabb->Area4->objectCount=0; + aabb->Area4->Area1=PX_NULL; + aabb->Area4->Area2=PX_NULL; + aabb->Area4->Area3=PX_NULL; + aabb->Area4->Area4=PX_NULL; + aabb->Area4->dataList.size=0; + aabb->Area4->dataList.head=PX_NULL; + aabb->Area4->dataList.end=PX_NULL; + aabb->Area4->dataList.mp=PX_NULL; + if(!PX_Quadtree_InitAABB(mp,PX_AABB_MAX_DEEP,aabb->Area4)) return PX_FALSE; + + return PX_TRUE; + } + } + return PX_FALSE; +} + +px_bool PX_QuadtreeCreate(px_memorypool *mp,PX_Quadtree *pQuadtree,px_float mapStartX,px_float mapStartY,px_float mapWidth,px_float mapHeight,px_int ObjectsCount,px_int deep) +{ + + pQuadtree->mp=mp; + pQuadtree->PX_AABB_MAX_DEEP=deep; + if(!PX_VectorInitialize(mp,&pQuadtree->boxes,sizeof(PX_Quadtree_AABB_BOX),ObjectsCount)) + { + PX_ASSERT(); + return PX_FALSE; + } + if(!PX_VectorInitialize(mp,&pQuadtree->Impacts,sizeof(PX_Quadtree_UserData),ObjectsCount)) + { + PX_ASSERT(); + PX_VectorFree(&pQuadtree->boxes); + return PX_FALSE; + } + pQuadtree->AABB=(PX_Quadtree_AABB *)MP_Malloc(mp,sizeof(PX_Quadtree_AABB)); + pQuadtree->AABB->deep=0; + pQuadtree->AABB->Area1=PX_NULL; + pQuadtree->AABB->Area2=PX_NULL; + pQuadtree->AABB->Area3=PX_NULL; + pQuadtree->AABB->Area4=PX_NULL; + pQuadtree->AABB->Left=mapStartX; + pQuadtree->AABB->Right=mapStartX+mapWidth; + pQuadtree->AABB->Top=mapStartY; + pQuadtree->AABB->Bottom=mapStartY+mapHeight; + pQuadtree->AABB->objectCount=0; + pQuadtree->AABB->dataList.size=0; + pQuadtree->AABB->dataList.head=PX_NULL; + pQuadtree->AABB->dataList.end=PX_NULL; + pQuadtree->AABB->dataList.mp=PX_NULL; + return PX_Quadtree_InitAABB(mp,pQuadtree->PX_AABB_MAX_DEEP,pQuadtree->AABB); +} + +static px_void PX_QuadtreeTest(PX_Quadtree *pQuadtree,PX_Quadtree_AABB *aabb,PX_Quadtree_AABB_BOX testBox) +{ + px_list_node *pnode=aabb->dataList.head; + px_rect r1,r2; + PX_Quadtree_AABB_BOX *pBox; + + + while (pnode) + { + pBox=PX_VECTORAT(PX_Quadtree_AABB_BOX,&pQuadtree->boxes,*(px_int *)pnode->pdata); + if (pBox->userdata.ptr!=testBox.userdata.ptr) + { + r1.x=pBox->x-pBox->width/2; + r1.y=pBox->y-pBox->height/2; + r1.width=pBox->width; + r1.height=pBox->height; + + r2.x=testBox.x-testBox.width/2; + r2.y=testBox.y-testBox.height/2; + r2.width=testBox.width; + r2.height=testBox.height; + + if (PX_isRectCrossRect(r1,r2)) + { + px_int i; + for (i=0;iImpacts.size;i++) + { + if (PX_VECTORAT(PX_Quadtree_UserData,&pQuadtree->Impacts,i)->ptr==pBox->userdata.ptr) + { + break; + } + } + + if(i==pQuadtree->Impacts.size) + PX_VectorPushback(&pQuadtree->Impacts,&pBox->userdata); + + } + } + pnode=pnode->pnext; + } + +} + +static px_void PX_QuadtreeSortBox(PX_Quadtree *pQuadtree,PX_Quadtree_AABB *aabb,px_int index) +{ + px_rect r1,r2; + PX_Quadtree_AABB_BOX *pBox; + pBox=PX_VECTORAT(PX_Quadtree_AABB_BOX,&pQuadtree->boxes,index); + r1.x=pBox->x-pBox->width/2; + r1.y=pBox->y-pBox->height/2; + r1.width=pBox->width; + r1.height=pBox->height; + + r2.x=aabb->Left; + r2.y=aabb->Top; + r2.width=aabb->Right-aabb->Left+1; + r2.height=aabb->Bottom-aabb->Top+1; + if (PX_isRectCrossRect(r1,r2)) + { + if (aabb->deep>=pQuadtree->PX_AABB_MAX_DEEP) + { + PX_ListPush(&aabb->dataList,&index,sizeof(px_int)); + } + else + { + PX_QuadtreeSortBox(pQuadtree,aabb->Area1,index); + PX_QuadtreeSortBox(pQuadtree,aabb->Area2,index); + PX_QuadtreeSortBox(pQuadtree,aabb->Area3,index); + PX_QuadtreeSortBox(pQuadtree,aabb->Area4,index); + } + } +} + + +static px_void PX_QuadtreeTestBox(PX_Quadtree *pQuadtree,PX_Quadtree_AABB *aabb,PX_Quadtree_AABB_BOX Box) +{ + px_rect r1,r2; + r1.x=Box.x-Box.width/2; + r1.y=Box.y-Box.height/2; + r1.width=Box.width; + r1.height=Box.height; + + r2.x=aabb->Left; + r2.y=aabb->Top; + r2.width=aabb->Right-aabb->Left+1; + r2.height=aabb->Bottom-aabb->Top+1; + if (PX_isRectCrossRect(r1,r2)) + { + if (aabb->deep>=pQuadtree->PX_AABB_MAX_DEEP) + { + PX_QuadtreeTest(pQuadtree,aabb,Box); + } + else + { + PX_QuadtreeTestBox(pQuadtree,aabb->Area1,Box); + PX_QuadtreeTestBox(pQuadtree,aabb->Area2,Box); + PX_QuadtreeTestBox(pQuadtree,aabb->Area3,Box); + PX_QuadtreeTestBox(pQuadtree,aabb->Area4,Box); + } + } +} + + +px_void PX_QuadtreeAddNode(PX_Quadtree *pQuadtree,px_float x,px_float y,px_float width,px_float height,PX_Quadtree_UserData userData) +{ + PX_Quadtree_AABB_BOX box; + box.height=height; + box.width=width; + box.x=x; + box.y=y; + box.userdata=userData; + PX_VectorPushback(&pQuadtree->boxes,&box); + + PX_QuadtreeSortBox(pQuadtree,pQuadtree->AABB,pQuadtree->boxes.size-1); +} + +px_void PX_QuadtreeTestNode(PX_Quadtree *pQuadtree,px_float x,px_float y,px_float width,px_float height,PX_Quadtree_UserData userData) +{ + PX_Quadtree_AABB_BOX box; + box.height=height; + box.width=width; + box.x=x; + box.y=y; + box.userdata=userData; + if (pQuadtree->boxes.size) + { + PX_QuadtreeTestBox(pQuadtree,pQuadtree->AABB,box); + } +} + +px_void PX_QuadtreeResetTest(PX_Quadtree *pQuadtree) +{ + PX_VectorClear(&pQuadtree->Impacts); +} diff --git a/lib/PainterEngine/core/PX_Quadtree.h b/lib/PainterEngine/core/PX_Quadtree.h new file mode 100644 index 0000000000000000000000000000000000000000..66fa202476f530002b73f9f4504b61cbf09b38e1 --- /dev/null +++ b/lib/PainterEngine/core/PX_Quadtree.h @@ -0,0 +1,44 @@ +#ifndef PX_QUADTREE_H +#define PX_QUADTREE_H +#include "PX_List.h" +#include "PX_Vector.h" + +#define PX_AABB_TEST_COUNT 32 + +typedef struct _PX_AABB +{ + px_float Left,Right,Bottom,Top; + px_int objectCount; + px_int deep; + px_list dataList; + struct _PX_AABB *Area1; + struct _PX_AABB *Area2; + struct _PX_AABB *Area3; + struct _PX_AABB *Area4; +}PX_Quadtree_AABB; + +typedef struct +{ + px_void *ptr; +}PX_Quadtree_UserData; +typedef struct +{ + px_float x,y,height,width; + PX_Quadtree_UserData userdata; +}PX_Quadtree_AABB_BOX; + + +typedef struct +{ + px_memorypool *mp; + px_int PX_AABB_MAX_DEEP; + PX_Quadtree_AABB *AABB; + px_vector boxes; + px_vector Impacts; +}PX_Quadtree; + +px_bool PX_QuadtreeCreate(px_memorypool *mp,PX_Quadtree *pQuadtree,px_float mapStartX,px_float mapStartY,px_float mapWidth,px_float mapHeight,px_int ObjectsCount,px_int deep); +px_void PX_QuadtreeAddNode(PX_Quadtree *pQuadtree,px_float CenterX,px_float CenterY,px_float width,px_float height,PX_Quadtree_UserData userData); +px_void PX_QuadtreeTestNode(PX_Quadtree *pQuadtree,px_float CenterX,px_float CenterY,px_float width,px_float height,PX_Quadtree_UserData user); +px_void PX_QuadtreeResetTest(PX_Quadtree *pQuadtree); +#endif diff --git a/lib/PainterEngine/core/PX_Quicksort.c b/lib/PainterEngine/core/PX_Quicksort.c new file mode 100644 index 0000000000000000000000000000000000000000..8d0925dd72d5271d9c58f008678558a9683be8b9 --- /dev/null +++ b/lib/PainterEngine/core/PX_Quicksort.c @@ -0,0 +1,74 @@ +#include "PX_Quicksort.h" + +static void swap(PX_QuickSortAtom array[], px_int left, px_int right) +{ + PX_QuickSortAtom temp; + temp = array[left]; + array[left] = array[right]; + array[right] = temp; +} + + +static px_int partition_l(PX_QuickSortAtom array[], px_int left, px_int right, px_int pivot_index) +{ + px_float pivot_value = array[pivot_index].weight; + px_int store_index = left; + px_int i; + + swap(array, pivot_index, right); + for (i = left; i < right; i++) + if (array[i].weight < pivot_value) { + swap(array, i, store_index); + ++store_index; + } + swap(array, store_index, right); + return store_index; +} + +static px_int partition_m(PX_QuickSortAtom array[], px_int left, px_int right, px_int pivot_index) +{ + px_float pivot_value = array[pivot_index].weight; + px_int store_index = left; + px_int i; + + swap(array, pivot_index, right); + for (i = left; i < right; i++) + if (array[i].weight > pivot_value) { + swap(array, i, store_index); + ++store_index; + } + swap(array, store_index, right); + return store_index; +} + +void PX_Quicksort_MinToMax(PX_QuickSortAtom array[], px_int left, px_int right) +{ + px_int pivot_index = left; + px_int pivot_new_index; + + + while (right > left) + { + pivot_new_index = partition_l(array, left, right, pivot_index); + PX_Quicksort_MinToMax(array, left, pivot_new_index - 1); + pivot_index = left = pivot_new_index + 1; + + } +} + +void PX_Quicksort_MaxToMin(PX_QuickSortAtom array[], px_int left, px_int right) +{ + px_int pivot_index = left; + px_int pivot_new_index; + + + while (right > left) + { + pivot_new_index = partition_m(array, left, right, pivot_index); + PX_Quicksort_MaxToMin(array, left, pivot_new_index - 1); + pivot_index = left = pivot_new_index + 1; + + } +} + + diff --git a/lib/PainterEngine/core/PX_Quicksort.h b/lib/PainterEngine/core/PX_Quicksort.h new file mode 100644 index 0000000000000000000000000000000000000000..efc27989724a9c6f321b7d24515e25f989dc2cef --- /dev/null +++ b/lib/PainterEngine/core/PX_Quicksort.h @@ -0,0 +1,13 @@ +#ifndef PX_QUICKSORT_H +#define PX_QUICKSORT_H + +#include "PX_Typedef.h" + +typedef struct +{ + px_float weight; + px_void *pData; +}PX_QuickSortAtom; +void PX_Quicksort_MinToMax(PX_QuickSortAtom array[], px_int left, px_int right); +void PX_Quicksort_MaxToMin(PX_QuickSortAtom array[], px_int left, px_int right); +#endif diff --git a/lib/PainterEngine/core/PX_Sha256.c b/lib/PainterEngine/core/PX_Sha256.c new file mode 100644 index 0000000000000000000000000000000000000000..936ad252593b28829b7a90c51b147720e0efe2f2 --- /dev/null +++ b/lib/PainterEngine/core/PX_Sha256.c @@ -0,0 +1,311 @@ +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// PX_Sha256 +// +// Implementation of SHA256 hash function. +// Original author: Tom St Denis, tomstdenis@gmail.com, http://libtom.org +// Modified by WaterJuice retaining Public Domain license. +// +// This is free and unencumbered software released into the public domain - June 2013 waterjuice.org +// Modified by DBinary retaining Public Domain license. 2019-3-11 matrixcascade@gmail.com 0-0i.com +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// IMPORTS +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +#include "PX_Sha256.h" + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// MACROS +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +#define ror(value, bits) (((value) >> (bits)) | ((value) << (32 - (bits)))) + +#define MIN(x, y) ( ((x)<(y))?(x):(y) ) + +#define STORE32H(x, y) \ + { (y)[0] = (px_uchar)(((x)>>24)&255); (y)[1] = (px_uchar)(((x)>>16)&255); \ + (y)[2] = (px_uchar)(((x)>>8)&255); (y)[3] = (px_uchar)((x)&255); } + +#define LOAD32H(x, y) \ + { x = ((px_uint32)((y)[0] & 255)<<24) | \ + ((px_uint32)((y)[1] & 255)<<16) | \ + ((px_uint32)((y)[2] & 255)<<8) | \ + ((px_uint32)((y)[3] & 255)); } + +#define STORE64H(x, y) \ + { (y)[0] = (px_uchar)(((x)>>56)&255); (y)[1] = (px_uchar)(((x)>>48)&255); \ + (y)[2] = (px_uchar)(((x)>>40)&255); (y)[3] = (px_uchar)(((x)>>32)&255); \ + (y)[4] = (px_uchar)(((x)>>24)&255); (y)[5] = (px_uchar)(((x)>>16)&255); \ + (y)[6] = (px_uchar)(((x)>>8)&255); (y)[7] = (px_uchar)((x)&255); } + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// CONSTANTS +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +// The K array +static const px_uint32 K[64] = { + 0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL, 0x3956c25bUL, + 0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL, 0xd807aa98UL, 0x12835b01UL, + 0x243185beUL, 0x550c7dc3UL, 0x72be5d74UL, 0x80deb1feUL, 0x9bdc06a7UL, + 0xc19bf174UL, 0xe49b69c1UL, 0xefbe4786UL, 0x0fc19dc6UL, 0x240ca1ccUL, + 0x2de92c6fUL, 0x4a7484aaUL, 0x5cb0a9dcUL, 0x76f988daUL, 0x983e5152UL, + 0xa831c66dUL, 0xb00327c8UL, 0xbf597fc7UL, 0xc6e00bf3UL, 0xd5a79147UL, + 0x06ca6351UL, 0x14292967UL, 0x27b70a85UL, 0x2e1b2138UL, 0x4d2c6dfcUL, + 0x53380d13UL, 0x650a7354UL, 0x766a0abbUL, 0x81c2c92eUL, 0x92722c85UL, + 0xa2bfe8a1UL, 0xa81a664bUL, 0xc24b8b70UL, 0xc76c51a3UL, 0xd192e819UL, + 0xd6990624UL, 0xf40e3585UL, 0x106aa070UL, 0x19a4c116UL, 0x1e376c08UL, + 0x2748774cUL, 0x34b0bcb5UL, 0x391c0cb3UL, 0x4ed8aa4aUL, 0x5b9cca4fUL, + 0x682e6ff3UL, 0x748f82eeUL, 0x78a5636fUL, 0x84c87814UL, 0x8cc70208UL, + 0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL +}; + +#define BLOCK_SIZE 64 + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// INTERNAL FUNCTIONS +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +// Various logical functions +#define Ch( x, y, z ) (z ^ (x & (y ^ z))) +#define Maj( x, y, z ) (((x | y) & z) | (x & y)) +#define S( x, n ) ror((x),(n)) +#define R( x, n ) (((x)&0xFFFFFFFFUL)>>(n)) +#define Sigma0( x ) (S(x, 2) ^ S(x, 13) ^ S(x, 22)) +#define Sigma1( x ) (S(x, 6) ^ S(x, 11) ^ S(x, 25)) +#define Gamma0( x ) (S(x, 7) ^ S(x, 18) ^ R(x, 3)) +#define Gamma1( x ) (S(x, 17) ^ S(x, 19) ^ R(x, 10)) + +#define Sha256Round( a, b, c, d, e, f, g, h, i ) \ + t0 = h + Sigma1(e) + Ch(e, f, g) + K[i] + W[i]; \ + t1 = Sigma0(a) + Maj(a, b, c); \ + d += t0; \ + h = t0 + t1; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// TransformFunction +// +// Compress 512-bits +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +static +void + TransformFunction + ( + PX_Sha256Context* Context, + px_uchar const* Buffer + ) +{ + px_uint32 S[8]; + px_uint32 W[64]; + px_uint32 t0; + px_uint32 t1; + px_uint32 t; + int i; + + // Copy state into S + for( i=0; i<8; i++ ) + { + S[i] = Context->state[i]; + } + + // Copy the state into 512-bits into W[0..15] + for( i=0; i<16; i++ ) + { + LOAD32H( W[i], Buffer + (4*i) ); + } + + // Fill W[16..63] + for( i=16; i<64; i++ ) + { + W[i] = Gamma1( W[i-2]) + W[i-7] + Gamma0( W[i-15] ) + W[i-16]; + } + + // Compress + for( i=0; i<64; i++ ) + { + Sha256Round( S[0], S[1], S[2], S[3], S[4], S[5], S[6], S[7], i ); + t = S[7]; + S[7] = S[6]; + S[6] = S[5]; + S[5] = S[4]; + S[4] = S[3]; + S[3] = S[2]; + S[2] = S[1]; + S[1] = S[0]; + S[0] = t; + } + + // Feedback + for( i=0; i<8; i++ ) + { + Context->state[i] = Context->state[i] + S[i]; + } +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// PUBLIC FUNCTIONS +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Sha256Initialise +// +// Initialises a SHA256 Context. Use this to initialise/reset a context. +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +void + PX_Sha256Initialise + ( + PX_Sha256Context* Context // [out] + ) +{ + Context->curlen = 0; + Context->length = 0; + Context->state[0] = 0x6A09E667UL; + Context->state[1] = 0xBB67AE85UL; + Context->state[2] = 0x3C6EF372UL; + Context->state[3] = 0xA54FF53AUL; + Context->state[4] = 0x510E527FUL; + Context->state[5] = 0x9B05688CUL; + Context->state[6] = 0x1F83D9ABUL; + Context->state[7] = 0x5BE0CD19UL; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Sha256Update +// +// Adds data to the SHA256 context. This will process the data and update the internal state of the context. Keep on +// calling this function until all the data has been added. Then call Sha256Finalise to calculate the hash. +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +void + PX_Sha256Update + ( + PX_Sha256Context* Context, // [in out] + void * Buffer, // [in] + px_uint32 BufferSize // [in] + ) +{ + px_uint32 n; + + if( Context->curlen > sizeof(Context->buf) ) + { + return; + } + + while( BufferSize > 0 ) + { + if( Context->curlen == 0 && BufferSize >= BLOCK_SIZE ) + { + TransformFunction( Context, (px_uchar*)Buffer ); + Context->length += BLOCK_SIZE * 8; + Buffer = (px_uchar*)Buffer + BLOCK_SIZE; + BufferSize -= BLOCK_SIZE; + } + else + { + n = MIN( BufferSize, (BLOCK_SIZE - Context->curlen) ); + PX_memcpy( Context->buf + Context->curlen, (px_void *)Buffer, (px_int)n ); + Context->curlen += n; + Buffer = (px_uchar*)Buffer + n; + BufferSize -= n; + if( Context->curlen == BLOCK_SIZE ) + { + TransformFunction( Context, Context->buf ); + Context->length += 8*BLOCK_SIZE; + Context->curlen = 0; + } + } + } +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Sha256Finalise +// +// Performs the final calculation of the hash and returns the digest (32 byte buffer containing 256bit hash). After +// calling this, Sha256Initialised must be used to reuse the context. +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +void + PX_Sha256Finalise + ( + PX_Sha256Context* Context, // [in out] + PX_SHA256_HASH* Digest // [out] + ) +{ + int i; + + if( Context->curlen >= sizeof(Context->buf) ) + { + return; + } + + // Increase the length of the message + Context->length += Context->curlen * 8; + + // Append the '1' bit + Context->buf[Context->curlen++] = (px_uchar)0x80; + + // if the length is currently above 56 bytes we append zeros + // then compress. Then we can fall back to padding zeros and length + // encoding like normal. + if( Context->curlen > 56 ) + { + while( Context->curlen < 64 ) + { + Context->buf[Context->curlen++] = (px_uchar)0; + } + TransformFunction(Context, Context->buf); + Context->curlen = 0; + } + + // Pad up to 56 bytes of zeroes + while( Context->curlen < 56 ) + { + Context->buf[Context->curlen++] = (px_uchar)0; + } + + // Store length + STORE64H( Context->length, Context->buf+56 ); + TransformFunction( Context, Context->buf ); + + // Copy output + for( i=0; i<8; i++ ) + { + STORE32H( Context->state[i], Digest->bytes+(4*i) ); + } +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Sha256Calculate +// +// Combines Sha256Initialise, Sha256Update, and Sha256Finalise into one function. Calculates the SHA256 hash of the +// buffer. +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +void + PX_Sha256Calculate + ( + px_void* Buffer, // [in] + px_uint32 BufferSize, // [in] + PX_SHA256_HASH* Digest // [in] + ) +{ + PX_Sha256Context context; + + PX_Sha256Initialise( &context ); + PX_Sha256Update( &context, Buffer, BufferSize ); + PX_Sha256Finalise( &context, Digest ); +} + +void PX_Sha256CalculateHashString(px_void *buffer,px_uint32 bufferSize,px_char stringKey[32]) +{ + px_int i; + PX_SHA256_HASH hash; + PX_Sha256Calculate(buffer,bufferSize,&hash); + for (i=0;i<31;i++) + { + if (hash.bytes[i]==0) + { + hash.bytes[i]=1; + } + } + hash.bytes[31]=0; + PX_memcpy(stringKey,hash.bytes,sizeof(hash.bytes)); +} diff --git a/lib/PainterEngine/core/PX_Sha256.h b/lib/PainterEngine/core/PX_Sha256.h new file mode 100644 index 0000000000000000000000000000000000000000..1674ed2f77a489ae8fef51b598a2c6f6b315fe16 --- /dev/null +++ b/lib/PainterEngine/core/PX_Sha256.h @@ -0,0 +1,56 @@ +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// WjCryptLib_Sha256 +// +// Implementation of SHA256 hash function. +// Original author: Tom St Denis, tomstdenis@gmail.com, http://libtom.org +// Modified by WaterJuice retaining Public Domain license. +// +// This is free and unencumbered software released into the public domain - June 2013 waterjuice.org +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +#ifndef PX_SHA256 +#define PX_SHA256 +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// IMPORTS +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +#include "PX_Typedef.h" + +typedef struct +{ + px_uint64 length; + px_uint32 state[8]; + px_uint32 curlen; + px_uchar buf[64]; +} PX_Sha256Context; + +#define SHA256_HASH_SIZE ( 256 / 8 ) + +typedef struct +{ + px_uchar bytes [SHA256_HASH_SIZE]; +} PX_SHA256_HASH; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// PUBLIC FUNCTIONS +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Sha256Calculate +// +// Combines Sha256Initialise, Sha256Update, and Sha256Finalise into one function. Calculates the SHA256 hash of the +// buffer. +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +void + PX_Sha256Calculate + ( + void* Buffer, // [in] + px_uint32 BufferSize, // [in] + PX_SHA256_HASH* Digest // [in] + ); + +void PX_Sha256CalculateHashString(px_void *buffer,px_uint32 bufferSize,px_char stringKey[32]); +#endif + diff --git a/lib/PainterEngine/core/PX_Sound.c b/lib/PainterEngine/core/PX_Sound.c new file mode 100644 index 0000000000000000000000000000000000000000..a85494ab826ec42432762e437ce936713340dcff --- /dev/null +++ b/lib/PainterEngine/core/PX_Sound.c @@ -0,0 +1,398 @@ +#include "PX_Sound.h" + +px_bool PX_SoundPlayInitialize(px_memorypool *mp, PX_SoundPlay *pSoundPlay) +{ + PX_memset(pSoundPlay,0,sizeof(PX_SoundPlay)); + pSoundPlay->mp=mp; + pSoundPlay->bLock=PX_FALSE; + pSoundPlay->mix_mode=PX_SOUND_MIX_MODE_PARALLEL; + pSoundPlay->parallel=PX_SOUND_DEFAULT_PARALLEL; + pSoundPlay->pause=PX_FALSE; + PX_memset(pSoundPlay->Sounds, 0, sizeof(pSoundPlay->Sounds)); + return PX_TRUE; +} + + +px_void PX_SoundPlaySetUserRead(PX_SoundPlay *pSoundPlay,px_void (*userread)(px_void *userptr,px_byte *pBuffer,px_int readSize),px_void *ptr) +{ + pSoundPlay->userread=userread; + pSoundPlay->userptr=ptr; +} + +px_void PX_SoundPlayPause(PX_SoundPlay *pSoundPlay,px_bool pause) +{ + pSoundPlay->pause=pause; +} + +px_bool PX_SoundPlayAdd(PX_SoundPlay *pSound,PX_Sound sounddata) +{ + px_int i; + px_int min_size=0,index=-1; + while(pSound->bLock); + pSound->bLock=PX_TRUE; + + for (i=0;iSounds);i++) + { + if (pSound->Sounds[i].data==PX_NULL) + { + index=i; + break; + } + else + { + if (min_size==0&&!pSound->Sounds[i].loop) + { + min_size=pSound->Sounds[i].data->size-pSound->Sounds[i].offset; + index=i; + } + else + { + if (!pSound->Sounds[i].loop && pSound->Sounds[i].data->size-pSound->Sounds[i].offsetSounds[i].data->size-pSound->Sounds[i].offset; + index=i; + } + } + } + } + if (indexSounds)) + { + pSound->Sounds[index]=sounddata; + pSound->bLock=PX_FALSE; + return PX_TRUE; + } + else + { + pSound->bLock=PX_FALSE; + return PX_FALSE; + } + +} + + +px_bool PX_SoundPlayRead(PX_SoundPlay *pSoundPlay,px_byte *pBuffer,px_int readSize) +{ + px_int i,j,CpySize,ReadblockSize,SourceblockLen; + PX_Sound *pSound; + px_short *pSourcePCM16,*pTargetPCM16=(px_short *)pBuffer; + px_short div; + if (readSize%4) + { + return PX_FALSE; + } + + if (pSoundPlay->userread) + { + pSoundPlay->userread(pSoundPlay->userptr,pBuffer,readSize); + return PX_TRUE; + } + + while(pSoundPlay->bLock); + pSoundPlay->bLock=PX_TRUE; + + PX_memset(pBuffer,0,readSize); + + if (pSoundPlay->pause) + { + pSoundPlay->bLock=PX_FALSE; + return PX_TRUE; + } + + div=PX_COUNTOF(pSoundPlay->Sounds); + + for (j=0;jSounds);j++) + { + pSound=pSoundPlay->Sounds+j; + if (!pSound->data) + { + continue; + } + + pSourcePCM16=(px_short *)pSound->data->buffer; + + if (!pSound->loop) + { + px_int resvSize=pSound->data->size-pSound->offset; + if (pSound->data->channel==PX_SOUND_CHANNEL_ONE) + { + if (resvSize*2>readSize) + { + CpySize=readSize; + } + else + { + CpySize=resvSize*2; + } + } + else + { + if (resvSize>readSize) + { + CpySize=readSize; + } + else + { + CpySize=resvSize; + } + } + } + else + { + CpySize=readSize; + } + + ReadblockSize=CpySize/2; + SourceblockLen=pSound->data->size/2; + + if (pSound->data->channel==PX_SOUND_CHANNEL_ONE) + { + for (i=0;imix_mode) + { + case PX_SOUND_MIX_MODE_PARALLEL: + pTargetPCM16[i]+=pSourcePCM16[pSound->offset/2]/pSoundPlay->parallel; + pTargetPCM16[i+1]+=pSourcePCM16[pSound->offset/2]/pSoundPlay->parallel; + pSound->offset+=2; + break; + case PX_SOUND_MIX_MODE_AVG: + pTargetPCM16[i]+=pSourcePCM16[pSound->offset/2]/div; + pTargetPCM16[i+1]+=pSourcePCM16[pSound->offset/2+1]/div; + pSound->offset+=2; + break; + } + + if (pSound->offset>=pSound->data->size) + { + if (pSound->loop) + { + pSound->offset=0; + } + else + { + break; + } + } + } + } + else + { + for (i=0;imix_mode) + { + case PX_SOUND_MIX_MODE_PARALLEL: + pTargetPCM16[i]+=pSourcePCM16[pSound->offset/2]/pSoundPlay->parallel; + pSound->offset+=2; + break; + case PX_SOUND_MIX_MODE_AVG: + pTargetPCM16[i]+=pSourcePCM16[pSound->offset/2]/div; + pSound->offset+=2; + break; + } + if (pSound->offset>=pSound->data->size) + { + if (pSound->loop) + { + pSound->offset=0; + } + else + { + break; + } + } + } + } + + if (pSound->offset>=pSound->data->size) + { + if (!pSoundPlay->Sounds[j].loop) + { + pSoundPlay->Sounds[j].data=PX_NULL; + } + continue; + } + } + + pSoundPlay->bLock=PX_FALSE; + return PX_TRUE; +} + + +px_bool PX_SoundPlayReadCurrentPlayingData(PX_SoundPlay *pSoundPlay,px_int soundIndex,px_int channel,px_int16 *out,px_int count) +{ + PX_SoundData *pData; + px_int offset; + if (soundIndex>=PX_COUNTOF(pSoundPlay->Sounds)||soundIndex<0) + { + return PX_FALSE; + } + if (pSoundPlay->Sounds[soundIndex].data==PX_NULL) + { + return PX_FALSE; + } + if (channel<0||channel>=2) + { + return PX_FALSE; + } + + pData=pSoundPlay->Sounds[soundIndex].data; + offset=pSoundPlay->Sounds[soundIndex].offset; + switch (pData->channel) + { + case PX_SOUND_CHANNEL_ONE: + { + if (pData->size-offsetbuffer+offset,count*2); + } + break; + case PX_SOUND_CHANNEL_DOUBLE: + { + px_int i; + px_int16 *pdptr; + if (pData->size-offset<2*count*2) + { + return PX_FALSE; + } + pdptr=(px_int16 *)(pData->buffer+offset); + for (i=0;iSounds);j++) + { + pSoundPlay->Sounds[j].data=PX_NULL; + pSoundPlay->Sounds[j].offset=0; + } +} + +px_int PX_SoundPlayGetDataCount(PX_SoundPlay *pSoundPlay) +{ + px_int count=0,j; + if (pSoundPlay->userread) + { + return 1; + } + + for (j=0;jSounds);j++) + { + if (pSoundPlay->Sounds[j].data) + { + count++; + } + } + return count; +} + +PX_Sound PX_SoundCreate(PX_SoundData *data,px_bool loop) +{ + PX_Sound sound; + sound.data=data; + sound.offset=0; + sound.loop=loop; + return sound; +} + + +px_bool PX_SoundStaticDataCopy(px_memorypool *mp,PX_SoundData *resSounddata,PX_SoundData *targetSounddata) +{ + targetSounddata->buffer=(px_byte *)MP_Malloc(mp,resSounddata->size); + if(!targetSounddata->buffer) + { + return PX_FALSE; + } + targetSounddata->channel=resSounddata->channel; + targetSounddata->mp=mp; + targetSounddata->size=resSounddata->size; + PX_memcpy(targetSounddata->buffer,resSounddata->buffer,resSounddata->size); + return PX_TRUE; +} + +px_bool PX_SoundStaticDataCreate(PX_SoundData *sounddata,px_memorypool *mp,px_byte *data,px_int datasize) +{ + if (PX_WaveVerify(data,datasize)) + { + px_uint offset=0,pcmSize,woffset; + + pcmSize=PX_WaveGetPCMSize(data,datasize); + + if (pcmSize!=0) + { + PX_WAVE_DATA_BLOCK *pBlock; + PX_WAVE_RIFF_HEADER *pHeader=(PX_WAVE_RIFF_HEADER *)data; + PX_WAVE_FMT_BLOCK *pfmt_block; + sounddata->buffer=(px_byte *)MP_Malloc(mp,pcmSize); + sounddata->size=pcmSize; + sounddata->channel=PX_WaveGetChannel(data,pcmSize)==1?PX_SOUND_CHANNEL_ONE:PX_SOUND_CHANNEL_DOUBLE; + if (!sounddata->buffer) + { + goto _ERROR; + } + pfmt_block=(PX_WAVE_FMT_BLOCK *)(data+sizeof(PX_WAVE_RIFF_HEADER)); + offset+=sizeof(PX_WAVE_RIFF_HEADER); + offset+=8; + offset+=pfmt_block->dwFmtSize; + + pcmSize=0; + woffset=0; + while (offset<(px_uint)datasize) + { + pBlock=(PX_WAVE_DATA_BLOCK*)(data+offset); + if(!PX_memequ(pBlock->szDataID,"data",4)) + { + offset+=pBlock->dwDataSize+sizeof(PX_WAVE_DATA_BLOCK); + continue; + } + offset+=sizeof(PX_WAVE_DATA_BLOCK); + PX_memcpy(sounddata->buffer+woffset,data+offset,pBlock->dwDataSize); + offset+=pBlock->dwDataSize; + woffset+=pBlock->dwDataSize; + } + } + else + goto _ERROR; + } + else + { + goto _ERROR; + } + sounddata->mp=mp; + return PX_TRUE; +_ERROR: + sounddata->mp=PX_NULL; + sounddata->size=0; + sounddata->buffer=PX_NULL; + return PX_FALSE; +} + +px_void PX_SoundStaticDataFree(PX_SoundData *sounddata) +{ + if (sounddata->mp) + { + MP_Free(sounddata->mp,sounddata->buffer); + sounddata->buffer=PX_NULL; + sounddata->size=0; + sounddata->mp=PX_NULL; + } + +} + diff --git a/lib/PainterEngine/core/PX_Sound.h b/lib/PainterEngine/core/PX_Sound.h new file mode 100644 index 0000000000000000000000000000000000000000..4d741721fc77cf22e08160f8f847efd1ef406789 --- /dev/null +++ b/lib/PainterEngine/core/PX_Sound.h @@ -0,0 +1,67 @@ +#ifndef PX_SOUND_H +#define PX_SOUND_H +//painter engine sound-mixer +//44100HZ +//16bit +//1/2-channel supported +#include "PX_Wave.h" +#include "PX_Vector.h" +#include "PX_Tuning.h" + +#define PX_SOUND_DEFAULT_PARALLEL 8 + +typedef enum +{ + PX_SOUND_CHANNEL_ONE, + PX_SOUND_CHANNEL_DOUBLE +}PX_SOUND_CHANNEL; + +typedef enum +{ + PX_SOUND_MIX_MODE_AVG, + PX_SOUND_MIX_MODE_PARALLEL, +}PX_SOUND_MIX_MODE; + +typedef struct +{ + px_memorypool *mp; + px_byte *buffer; + px_int size; + PX_SOUND_CHANNEL channel; +}PX_SoundData; + +typedef struct +{ + px_int offset; + px_bool loop; + PX_SoundData *data; +}PX_Sound; + +typedef px_void (*px_soundplay_userread)(px_void *userptr,px_byte *pBuffer,px_int readSize); + +typedef struct +{ + px_memorypool *mp; + px_int parallel; + px_bool pause; + volatile px_bool bLock; + PX_SOUND_MIX_MODE mix_mode; + px_soundplay_userread userread; + px_void *userptr; + PX_Sound Sounds[PX_SOUND_DEFAULT_PARALLEL]; +}PX_SoundPlay; + +px_bool PX_SoundPlayInitialize(px_memorypool *mp, PX_SoundPlay *pSoundPlay); +px_void PX_SoundPlaySetUserRead(PX_SoundPlay *pSoundPlay,px_void (*userread)(px_void *userptr,px_byte *pBuffer,px_int readSize),px_void *ptr); +px_void PX_SoundPlayPause(PX_SoundPlay *pSoundPlay,px_bool pause); +px_bool PX_SoundPlayAdd(PX_SoundPlay *pSoundPlay,PX_Sound sound); +px_bool PX_SoundPlayRead(PX_SoundPlay *pSoundPlay,px_byte *pBuffer,px_int readSize); +px_bool PX_SoundPlayReadCurrentPlayingData(PX_SoundPlay *pSoundPlay,px_int soundIndex,px_int channel,px_int16 *out,px_int count); +px_void PX_SoundPlayFree(PX_SoundPlay *pSoundPlay); +px_void PX_SoundPlayClear(PX_SoundPlay *pSoundPlay); +px_int PX_SoundPlayGetDataCount(PX_SoundPlay *pSoundPlay); +PX_Sound PX_SoundCreate(PX_SoundData *data,px_bool loop); +px_bool PX_SoundStaticDataCopy(px_memorypool *mp,PX_SoundData *resSounddata,PX_SoundData *targetSounddata); +px_bool PX_SoundStaticDataCreate(PX_SoundData *sounddata,px_memorypool *mp,px_byte *data,px_int datasize); +px_void PX_SoundStaticDataFree(PX_SoundData *sounddata); +#endif diff --git a/lib/PainterEngine/core/PX_SoundModule.c b/lib/PainterEngine/core/PX_SoundModule.c new file mode 100644 index 0000000000000000000000000000000000000000..408cfcfe1c4a538cbf1e24f4d7c333adb86ff625 --- /dev/null +++ b/lib/PainterEngine/core/PX_SoundModule.c @@ -0,0 +1,250 @@ +#include "PX_SoundModule.h" + +px_void PX_SoundModuleSortSpectrum(PX_SoundModule *SoundModule,px_complex AnalysisFrame[]) +{ + px_int i; + px_double amplitude=0,phase=0; + PX_FFT(AnalysisFrame,AnalysisFrame,PX_SOUNDMODULE_N); + + //re,im to amplitude,phase + + //DC sort + if (AnalysisFrame[0].re>0) + { + AnalysisFrame[0].im=0; + } + else + { + AnalysisFrame[0].re=PX_ABS(AnalysisFrame[0].re); + AnalysisFrame[0].im=PX_PI; + } + + //others + for (i=1;i0) + { + AnalysisFrame[PX_SOUNDMODULE_N/2].im=0; + } + else + { + AnalysisFrame[PX_SOUNDMODULE_N/2].re=PX_ABS(AnalysisFrame[0].re); + AnalysisFrame[PX_SOUNDMODULE_N/2].im=PX_PI; + } +} + + +px_void PX_SoundModuleInitialize(px_memorypool *mp,PX_SoundModule *SoundModule,px_int SampleRate,px_double pitchShift,PX_SoundModule_Formant Formant[],px_int FormantCount) +{ + PX_memset(SoundModule,0,sizeof(PX_SoundModule)); + if (FormantCount>PX_COUNTOF(SoundModule->Formant)) + { + return; + } + PX_memcpy(SoundModule->Formant,Formant,FormantCount*sizeof(PX_SoundModule_Formant)); + SoundModule->mp=mp; + SoundModule->pitchShift=pitchShift; + SoundModule->SampleRate=SampleRate; + SoundModule->searchHzW=PX_SOUNDMODULE_DEFALUT_SEARCH_HZ; + SoundModule->ZCR_High=100; + SoundModule->Pitch_threshold_High=800; + SoundModule->amp_max=32768.0; +} + +px_int PX_SoundModuleFilter(PX_SoundModule *SoundModule,_IN px_double _in[],px_int count,_OUT px_double _out[]) +{ + px_complex Frame[PX_SOUNDMODULE_N]; + px_double InstantaneousPhase[PX_SOUNDMODULE_N]; + px_double sincWindow[PX_SOUNDMODULE_N]; + px_double ModuleAmplitude[PX_SOUNDMODULE_FORMANT_COUNT]; + px_double Pitch; + px_double ZCR; + px_double *Data; + px_double durHZ=SoundModule->SampleRate*1.0/PX_SOUNDMODULE_N; + px_int blkCount,dataCount,remian; + px_int blk; + px_int blkSize=PX_SOUNDMODULE_N/2; + + dataCount=count+SoundModule->remainCount; + + Data=(px_double *)MP_Malloc(SoundModule->mp,dataCount*sizeof(px_double)); + + PX_memcpy(Data,SoundModule->remian,SoundModule->remainCount*sizeof(px_double)); + PX_memcpy(Data+SoundModule->remainCount,_in,count*sizeof(px_double)); + + blkCount=dataCount/(blkSize); + + if (blkCount>1) + { + remian=dataCount%(blkSize)+blkSize; + PX_memcpy(SoundModule->remian,Data+(blkCount-1)*blkSize,remian*sizeof(px_double)); + SoundModule->remainCount=remian; + } + else + { + remian=dataCount; + PX_memcpy(SoundModule->remian,Data,remian*sizeof(px_double)); + MP_Free(SoundModule->mp,Data); + return 0; + } + + PX_WindowFunction_sinc(sincWindow,PX_SOUNDMODULE_N); + + for (blk=0;blkSampleRate,100,300); + + for (i=0;iamp_max*sincWindow[i]; + Frame[i].im=0; + } + + if (Pitch!=0&&!(ZCRZCR_Low||ZCR>SoundModule->ZCR_High||PitchPitch_threshold_Low||Pitch>SoundModule->Pitch_threshold_High)) + { + PX_SoundModuleSortSpectrum(SoundModule,Frame); + + //Instantaneous frequency + for (i=0;ilastPhase[i]; + SoundModule->lastPhase[i]=Frame[i].im; + } + + //Build sound module + for (i=0;isearchHzW/2)/durHZ); + + if (HZindex<0) + { + HZindex=0; + } + + max=Frame[HZindex].re; + + while (PX_TRUE) + { + HZindex++; + if (HZindex>=PX_SOUNDMODULE_FORMANT_COUNT) + { + break; + } + if (HZindex*durHZ>Pitch*i+SoundModule->searchHzW/2) + { + break; + } + if (Frame[HZindex].re>max) + { + max=Frame[HZindex].re; + } + } + + ModuleAmplitude[HZindex]=max; + } + + //now rebuild signal + + PX_memset(Frame,0,sizeof(Frame)); + for (i=0;isearchHzW/2)/durHZ); + if (HZindex<0) + { + HZindex=0; + } + + while (PX_TRUE) + { + px_double distanceHZ; + if (HZindex>=PX_SOUNDMODULE_FORMANT_COUNT) + { + break; + } + if (HZindex*durHZ>Pitch*i+SoundModule->Formant[i].W/2) + { + break; + } + distanceHZ=PX_ABS(HZindex*durHZ-Pitch*i); + Frame[HZindex].re=SoundModule->Formant[i].A*PX_sind(PX_PI/2*(1-PX_ABS(distanceHZ-Pitch*i)/SoundModule->Formant[i].W*2)); + + HZindex++; + } + } + + //rebuild instantaneous phase + for (i=0;ire im + for (i=0;ire,im + Frame[i].re=amp*PX_cosd(phase); + Frame[i].im=amp*PX_sind(phase); + } + + PX_FT_Symmetry(Frame,Frame,PX_SOUNDMODULE_N); + PX_IFFT(Frame,Frame,PX_SOUNDMODULE_N); + } + + for (i=0;ihalfRebuild[i]; + if ((_out+blk*blkSize)[i]<-1) + { + (_out+blk*blkSize)[i]=-1; + } + if ((_out+blk*blkSize)[i]>1) + { + (_out+blk*blkSize)[i]=1; + } + (_out+blk*blkSize)[i]*=SoundModule->amp_max; + SoundModule->halfRebuild[i]=Frame[i+blkSize].re*sincWindow[i+blkSize]; + } + } + + MP_Free(SoundModule->mp,Data); + + return blkCount*blkSize; +} + +px_void PX_SoundModulePitchShift(PX_SoundModule *SoundModule,px_double pitchShift) +{ + SoundModule->pitchShift=pitchShift; +} + +px_void PX_SoundModuleSetZCR(PX_SoundModule *SoundModule,px_double low,px_double high) +{ + SoundModule->ZCR_Low=low; + SoundModule->ZCR_High=high; +} diff --git a/lib/PainterEngine/core/PX_SoundModule.h b/lib/PainterEngine/core/PX_SoundModule.h new file mode 100644 index 0000000000000000000000000000000000000000..a7b6516c07ef1f49feecde70f95fb5a7bfd008f0 --- /dev/null +++ b/lib/PainterEngine/core/PX_SoundModule.h @@ -0,0 +1,39 @@ +#ifndef PX_SOUNDMODULE +#define PX_SOUNDMODULE + +#include "../core/PX_Core.h" + +#define PX_SOUNDMODULE_N 1024 +#define PX_SOUNDMODULE_FORMANT_COUNT 32 +#define PX_SOUNDMODULE_DEFALUT_SEARCH_HZ 90 + +typedef struct +{ + px_double A,W; +}PX_SoundModule_Formant; + +typedef struct +{ + px_memorypool *mp; + px_double lastPhase[PX_SOUNDMODULE_N/2]; + px_double remian[PX_SOUNDMODULE_N*2]; + px_double halfRebuild[PX_SOUNDMODULE_N/2]; + PX_SoundModule_Formant Formant[PX_SOUNDMODULE_FORMANT_COUNT]; + + px_int remainCount; + px_int SampleRate; + px_double searchHzW; + px_double pitchShift; + px_double ZCR_Low,ZCR_High; + px_double amp_threshold; + px_double amp_max; + px_double Pitch_threshold_Low,Pitch_threshold_High; +}PX_SoundModule; + + +px_void PX_SoundModuleInitialize(px_memorypool *mp,PX_SoundModule *SoundModule,px_int SampleRate,px_double pitchShift,PX_SoundModule_Formant Formant[],px_int FormantCount); +px_int PX_SoundModuleFilter(PX_SoundModule *SoundModule,_IN px_double _in[],px_int count,_OUT px_double _out[]); +px_void PX_SoundModulePitchShift(PX_SoundModule *SoundModule,px_double pitchShift); +px_void PX_SoundModuleSetZCR(PX_SoundModule *SoundModule,px_double low,px_double high); + +#endif diff --git a/lib/PainterEngine/core/PX_String.c b/lib/PainterEngine/core/PX_String.c new file mode 100644 index 0000000000000000000000000000000000000000..576b6ef824002e17ff3f0b232ceed5ace4b3b939 --- /dev/null +++ b/lib/PainterEngine/core/PX_String.c @@ -0,0 +1,697 @@ +#include "PX_String.h" + +px_int PX_StringToInteger(px_string *str) +{ + if (str->buffer[0]=='0'&&(str->buffer[1]=='x'||str->buffer[1]=='X')) + { + return PX_htoi(str->buffer+2); + } + else + return PX_atoi(str->buffer); +} + +px_void PX_StringTrim(px_string *str) +{ + if (str->buffer) + { + px_int loft=0; + px_int i; + while (str->buffer[loft]==' ') + { + loft++; + } + i=0; + while(PX_TRUE) + { + if (str->buffer[loft]=='\0'||loft>=str->bufferlen) + { + break; + } + str->buffer[i++]=str->buffer[loft++]; + } + str->buffer[i]='\0'; + i=PX_strlen(str->buffer); + if (i) + { + i--; + } + else + return; + + while (i&&str->buffer[i]==' ') + { + str->buffer[i--]='\0'; + } + } + PX_StringUpdateExReg(str); +} + +px_void PX_StringTrimLeft(px_string *str,px_int leftCount) +{ + px_int i; + if (leftCount==0) + { + return; + } + if (leftCount>=PX_strlen(str->buffer)) + { + PX_StringClear(str); + } + else + { + for (i=0;str->buffer[i+leftCount];i++) + { + str->buffer[i]=str->buffer[i+leftCount]; + } + str->buffer[i]='\0'; + } + PX_StringUpdateExReg(str); +} + +px_void PX_StringTrimRight(px_string *str,px_int RightCount) +{ + if (RightCount==0) + { + return; + } + if (RightCount>=PX_strlen(str->buffer)) + { + PX_StringClear(str); + } + else + { + str->buffer[PX_strlen(str->buffer)-RightCount]='\0'; + } + PX_StringUpdateExReg(str); +} + +px_void PX_StringFree(px_string *str) +{ + if(str->buffer&&str->bufferlen) + MP_Free(str->mp,str->buffer); + + str->buffer=PX_NULL; + str->bufferlen=0; + str->exreg_strlen = 0; +} + +px_bool PX_StringInitialize(px_memorypool *mp,px_string *str) +{ + str->buffer=(px_char *)MP_Malloc(mp,16); + if(!str->buffer)return PX_FALSE; + str->bufferlen=16; + PX_memset(str->buffer,0,16); + str->mp=mp; + str->exreg_strlen = 0; + return PX_TRUE; +} + +px_void PX_StringInitAlloc(px_memorypool *mp,px_string *str,px_int allocSize) +{ + int size=16; + while(sizebuffer=(px_char *)MP_Malloc(mp,allocSize); + str->bufferlen=allocSize; + PX_memset(str->buffer,0,size); + str->mp=mp; + str->exreg_strlen = 0; +} + + +px_bool PX_StringFormat8(px_string *str,const px_char fmt[],px_stringformat _1, px_stringformat _2, px_stringformat _3, px_stringformat _4,px_stringformat _5, px_stringformat _6, px_stringformat _7, px_stringformat _8) +{ + px_char *oldptr; + px_uint finalLen=0; + px_uchar shl=0; + + finalLen=PX_sprintf8(PX_NULL,0,fmt,_1,_2,_3,_4,_5,_6,_7,_8); + + oldptr=str->buffer; + + while ((px_uint)(1<<++shl)<=finalLen); + str->bufferlen=(1<buffer=(px_char *)MP_Malloc(str->mp,str->bufferlen); + if (!str->buffer) + { + PX_StringUpdateExReg(str); + return PX_FALSE; + } + + finalLen=PX_sprintf8(str->buffer,str->bufferlen,fmt,_1,_2,_3,_4,_5,_6,_7,_8); + + if(oldptr) + MP_Free(str->mp,oldptr); + + PX_StringUpdateExReg(str); + return PX_TRUE; +} +px_bool PX_StringFormat7(px_string *str,const px_char fmt[],px_stringformat _1, px_stringformat _2, px_stringformat _3, px_stringformat _4,px_stringformat _5, px_stringformat _6, px_stringformat _7) +{ + return PX_StringFormat8(str,fmt,_1,_2,_3,_4,_5,_6,_7,PX_STRINGFORMAT_INT(0)); +} + +px_bool PX_StringFormat6(px_string *str,const px_char fmt[],px_stringformat _1, px_stringformat _2, px_stringformat _3, px_stringformat _4,px_stringformat _5, px_stringformat _6) +{ + return PX_StringFormat8(str,fmt,_1,_2,_3,_4,_5,_6,PX_STRINGFORMAT_INT(0),PX_STRINGFORMAT_INT(0)); +} + +px_bool PX_StringFormat5(px_string *str,const px_char fmt[],px_stringformat _1, px_stringformat _2, px_stringformat _3, px_stringformat _4,px_stringformat _5) +{ + return PX_StringFormat8(str,fmt,_1,_2,_3,_4,_5,PX_STRINGFORMAT_INT(0),PX_STRINGFORMAT_INT(0),PX_STRINGFORMAT_INT(0)); +} + +px_bool PX_StringFormat4(px_string *str,const px_char fmt[],px_stringformat _1, px_stringformat _2, px_stringformat _3, px_stringformat _4) +{ + return PX_StringFormat8(str,fmt,_1,_2,_3,_4,PX_STRINGFORMAT_INT(0),PX_STRINGFORMAT_INT(0),PX_STRINGFORMAT_INT(0),PX_STRINGFORMAT_INT(0)); +} + +px_bool PX_StringFormat3(px_string *str,const px_char fmt[],px_stringformat _1, px_stringformat _2, px_stringformat _3) +{ + return PX_StringFormat8(str,fmt,_1,_2,_3,PX_STRINGFORMAT_INT(0),PX_STRINGFORMAT_INT(0),PX_STRINGFORMAT_INT(0),PX_STRINGFORMAT_INT(0),PX_STRINGFORMAT_INT(0)); +} + +px_bool PX_StringFormat2(px_string *str,const px_char fmt[],px_stringformat _1, px_stringformat _2) +{ + return PX_StringFormat8(str,fmt,_1,_2,PX_STRINGFORMAT_INT(0),PX_STRINGFORMAT_INT(0),PX_STRINGFORMAT_INT(0),PX_STRINGFORMAT_INT(0),PX_STRINGFORMAT_INT(0),PX_STRINGFORMAT_INT(0)); +} + +px_bool PX_StringFormat1(px_string *str,const px_char fmt[],px_stringformat _1) +{ + return PX_StringFormat8(str,fmt,_1,PX_STRINGFORMAT_INT(0),PX_STRINGFORMAT_INT(0),PX_STRINGFORMAT_INT(0),PX_STRINGFORMAT_INT(0),PX_STRINGFORMAT_INT(0),PX_STRINGFORMAT_INT(0),PX_STRINGFORMAT_INT(0)); +} + +px_bool PX_StringSet(px_string *str,const px_char fmt[]) +{ + px_char *oldptr; + px_uint finalLen=0; + px_uchar shl=0; + + finalLen=PX_strlen(fmt); + + if (finalLen<(px_uint)str->bufferlen) + { + PX_strset(str->buffer,fmt); + PX_StringUpdateExReg(str); + return PX_TRUE; + } + + oldptr=str->buffer; + + while ((px_uint)(1<<++shl)<=finalLen); + str->bufferlen=(1<buffer=(px_char *)MP_Malloc(str->mp,str->bufferlen); + if (!str->buffer) + { + return PX_FALSE; + } + PX_strset(str->buffer,fmt); + + if(oldptr) + MP_Free(str->mp,oldptr); + + PX_StringUpdateExReg(str); + return PX_TRUE; +} + +px_float PX_StringToFloat(px_string *str) +{ + return PX_atof(PX_STRING_DATA(str)); +} + +px_bool PX_StringIsNumeric(px_string *str) +{ + return PX_strIsNumeric(str->buffer); +} + +px_bool PX_StringIsFloat(px_string *str) +{ + return PX_strIsFloat(str->buffer); +} + +px_bool PX_StringCat(px_string *str,const px_char *str2) +{ + px_uchar shl=0; + px_char *old=str->buffer; + px_int length=PX_strlen(str->buffer)+PX_strlen(str2); + if (lengthbufferlen) + { + PX_strcat(str->buffer,str2); + PX_StringUpdateExReg(str); + return PX_TRUE; + } + + while ((px_int)(1<<++shl)<=length); + str->bufferlen=(1<buffer=(px_char *)MP_Malloc(str->mp,str->bufferlen); + if(!str->buffer)return PX_FALSE; + str->buffer[0]='\0'; + PX_strcat(str->buffer,old); + PX_strcat(str->buffer,str2); + if(old) + MP_Free(str->mp,old); + PX_StringUpdateExReg(str); + return PX_TRUE; +} + +px_void PX_StringClear(px_string *str) +{ + str->buffer[0]='\0'; + str->exreg_strlen = 0; +} + +px_bool PX_StringCatChar(px_string *str,px_char ch) +{ + px_uchar shl=0; + px_char *old=str->buffer; + px_int length=PX_strlen(str->buffer)+1; + if (lengthbufferlen) + { + str->buffer[length-1]=ch; + str->buffer[length]='\0'; + PX_StringUpdateExReg(str); + return PX_TRUE; + } + + while ((px_int)(1<<++shl)<=length); + str->bufferlen=(1<buffer=(px_char *)MP_Malloc(str->mp,str->bufferlen); + if(!str->buffer)return PX_FALSE; + str->buffer[0]='\0'; + PX_strcat(str->buffer,old); + str->buffer[length-1]=ch; + str->buffer[length]='\0'; + if(old) + MP_Free(str->mp,old); + + PX_StringUpdateExReg(str); + return PX_TRUE; +} + +px_int PX_StringLen(px_string *str) +{ + return PX_strlen(str->buffer); +} + +px_bool PX_StringCopy(px_string *dest,px_string *res) +{ + if (res==dest) + { + PX_ERROR("px_sting Self-copied error"); + return PX_FALSE; + } + dest->buffer[0]='\0'; + return PX_StringCat(dest,res->buffer); +} + +px_bool PX_StringInsertChar(px_string *str,px_int index,px_char ch) +{ + px_int cpysize=PX_strlen(str->buffer+index); + if (PX_StringCatChar(str,' ')) + { + PX_memcpy(str->buffer+index+1,str->buffer+index,cpysize); + str->buffer[index]=ch; + str->exreg_strlen++; + return PX_TRUE; + } + return PX_FALSE; +} + +px_bool PX_StringRemoveChar(px_string *str,px_int index) +{ + if (index>=0&&indexbuffer)) + { + PX_memcpy(str->buffer+index,str->buffer+index+1,PX_strlen(str->buffer+index)); + str->exreg_strlen--; + return PX_TRUE; + } + return PX_FALSE; +} + +px_void PX_StringReplace(px_string *str,px_char *source,px_char *replaceto) +{ + px_string tempstr; + int i; + if (PX_StringLen(str)==0) + { + return; + } + PX_StringInitialize(str->mp,&tempstr); + PX_StringCopy(&tempstr,str); + PX_StringClear(str); + + for (i=0;i<=PX_StringLen(&tempstr)-PX_strlen(source);i++) + { + if (PX_memequ(tempstr.buffer+i,source,PX_strlen(source))) + { + PX_StringCat(str,replaceto); + i+=PX_strlen(source)-1; + } + else + { + PX_StringCatChar(str,tempstr.buffer[i]); + } + } + PX_StringCat(str,tempstr.buffer+i); + PX_StringFree(&tempstr); + +} + +px_bool PX_StringInsert(px_string *str,px_int insertIndex,const px_char *InstrString) +{ + px_int length=PX_strlen(InstrString); + px_int resLen=PX_strlen(str->buffer+insertIndex); + if (!PX_StringCat(str, InstrString)) + { + return PX_FALSE; + } + PX_memcpy(str->buffer+insertIndex+length,str->buffer+insertIndex,resLen); + PX_memcpy(str->buffer+insertIndex,InstrString,length); + PX_StringUpdateExReg(str); + return PX_TRUE; +} + + +px_void PX_StringReplaceRange(px_string *str,px_int startindex,px_int endindex,px_char *replaceto) +{ + px_string tempStr; + + if (startindex>endindex) + { + PX_ERROR("string trim error"); + return; + } + + if (endindex>=PX_strlen(str->buffer)) + { + PX_ERROR("string trim error"); + return; + } + + PX_StringInitialize(str->mp,&tempStr); + PX_StringCopy(&tempStr,str); + + PX_StringClear(str); + + tempStr.buffer[startindex]=0; + PX_StringCat(str,tempStr.buffer); + PX_StringCat(str,replaceto); + PX_StringCat(str,tempStr.buffer+endindex+1); + PX_StringFree(&tempStr); +} + +#define PX_STRING_TRIMER_REG_COUNT 16 + +px_bool PX_StringTrimer_Solve(px_string *pstring,px_char *parseCode,px_char *ReplaceCode) +{ + px_int oft,j,k,resi,repj,regindex; + px_char regbuf[3]; + px_char endc; + px_bool ret; + px_string reg[PX_STRING_TRIMER_REG_COUNT],matchedString,replaceString; + px_bool mark[PX_STRING_TRIMER_REG_COUNT],matchd; + ret=PX_FALSE; + for (oft=0;oftmp,reg+oft); + mark[oft]=PX_FALSE; + } + + PX_StringInitialize(pstring->mp,&matchedString); + + oft=0; + + while(pstring->buffer[oft]) + { + repj=0; + resi=oft; + matchd=PX_FALSE; + + while(PX_TRUE) + { + + if (parseCode[repj]=='%') + { + j=0; + repj++; + + PX_StringClear(&matchedString); + + while(PX_TRUE) + { + if (parseCode[repj]>='0'&&parseCode[repj]<='9') + { + regbuf[j++]=parseCode[repj++]; + if (j>2) + { + goto _DONE; + } + regbuf[j]=0; + + } + else + break; + + } + if (j==0) + { + goto _DONE; + } + regindex=PX_atoi(regbuf); + if (regindex>=PX_STRING_TRIMER_REG_COUNT) + { + goto _DONE; + } + endc=parseCode[repj]; + + while (PX_TRUE) + { + if (pstring->buffer[resi]==endc) + { + break; + } + if (pstring->buffer[resi]=='\0') + { + goto _DONE; + } + PX_StringCatChar(&matchedString,pstring->buffer[resi]); + resi++; + } + + if (mark[regindex]) + { + //reg 0 as wildcard + if (PX_strequ(reg[regindex].buffer,matchedString.buffer)||!regindex) + { + matchd=PX_TRUE; + } + else + { + matchd=PX_FALSE; + break; + } + } + else + { + PX_StringCopy(®[regindex],&matchedString); + mark[regindex]=PX_TRUE; + } + + } + else + { + if (parseCode[repj]=='\0') + { + matchd=PX_TRUE; + break; + } + if (pstring->buffer[resi]=='\0') + { + break; + } + if (pstring->buffer[resi]==parseCode[repj]) + { + resi++; + repj++; + } + else + break; + } + } + + + + if (matchd) + { + PX_StringInitialize(pstring->mp,&replaceString); + j=0; + k=0; + while(PX_TRUE) + { + if (ReplaceCode[j]==0) + { + break; + } + if (ReplaceCode[j]=='%') + { + j++; + k=0; + while(PX_TRUE) + { + if (ReplaceCode[j]>='0'&&ReplaceCode[j]<='9') + { + regbuf[k++]=ReplaceCode[j++]; + + if (k>2) + { + PX_StringFree(&replaceString); + goto _DONE; + } + + regbuf[k]='\0'; + + regindex=PX_atoi(regbuf); + if (regindex>=PX_STRING_TRIMER_REG_COUNT) + { + PX_StringFree(&replaceString); + goto _DONE; + } + PX_StringCat(&replaceString,reg[regindex].buffer); + } + else + break; + } + } + else + { + PX_StringCatChar(&replaceString,ReplaceCode[j++]); + } + } + + + PX_StringReplaceRange(pstring,oft,resi-1,replaceString.buffer); + ret=PX_TRUE; + + oft+=PX_strlen(replaceString.buffer); + + PX_StringFree(&replaceString); + } + else + { + oft++; + } + + for (k=0;kbuffer=(px_char *)constchar; + str->mp=PX_NULL; + str->bufferlen=0; + +} + + +px_void PX_StringUpdateExReg(px_string *text) +{ + if (text->buffer) + { + text->exreg_strlen =PX_strlen(text->buffer); + } + else + text->exreg_strlen =0; +} + +px_bool PX_StringCatEx(px_string* text, const px_char* str2) +{ + px_uchar shl = 0; + px_int len2 = PX_strlen(str2); + px_char* old = text->buffer; + px_int length = text->exreg_strlen + len2; + if (length < text->bufferlen) + { + PX_strcat(text->buffer + text->exreg_strlen, str2); + text->exreg_strlen += len2; + return PX_TRUE; + } + + while ((px_int)(1 << ++shl) <= length); + text->bufferlen = (1 << shl); + text->buffer = (px_char*)MP_Malloc(text->mp, text->bufferlen); + if (!text->buffer) + { + return PX_FALSE; + } + + text->buffer[0] = '\0'; + + PX_strcat(text->buffer, old); + PX_strcat(text->buffer + text->exreg_strlen, str2); + + if (old) + MP_Free(text->mp, old); + + text->exreg_strlen += len2; + return PX_TRUE; +} + +px_void PX_StringBackspace(px_string* text) +{ + px_int len = PX_strlen(text->buffer); + if (len) + { + text->buffer[len - 1] = '\0'; + } +} + + +px_void PX_StringBackspaceEx(px_string* text) +{ + if (text->exreg_strlen > 0) + { + text->buffer[text->exreg_strlen - 1] = '\0'; + text->exreg_strlen--; + } +} + +px_bool PX_StringCatCharEx(px_string* text, px_char ch) +{ + px_uchar shl = 0; + px_char* old = text->buffer; + px_int length = text->exreg_strlen + 1; + if (length < text->bufferlen) + { + text->buffer[length - 1] = ch; + text->buffer[length] = '\0'; + text->exreg_strlen++; + return PX_TRUE; + } + + while ((px_int)(1 << ++shl) <= length); + text->bufferlen = (1 << shl); + text->buffer = (px_char*)MP_Malloc(text->mp, text->bufferlen); + if (!text->buffer)return PX_FALSE; + text->buffer[0] = '\0'; + PX_strcat(text->buffer, old); + text->buffer[length - 1] = ch; + text->buffer[length] = '\0'; + text->exreg_strlen++; + if (old) + MP_Free(text->mp, old); + return PX_TRUE; +} diff --git a/lib/PainterEngine/core/PX_String.h b/lib/PainterEngine/core/PX_String.h new file mode 100644 index 0000000000000000000000000000000000000000..bfa4c8eff5c58706b0383f3304c7d49d16a57e5a --- /dev/null +++ b/lib/PainterEngine/core/PX_String.h @@ -0,0 +1,59 @@ +#ifndef __PX_STRING_H +#define __PX_STRING_H +#include "PX_MemoryPool.h" + +typedef struct __px_string +{ + px_char *buffer; + px_memorypool *mp; + px_int bufferlen; + px_int exreg_strlen; +}px_string; + + +#define PX_STRING_DATA(x) (x->buffer) + +px_bool PX_StringInitialize(px_memorypool *mp,px_string *str); +px_void PX_StringInitFromConst(px_string *str,const px_char *constchar); +px_void PX_StringUpdateExReg(px_string* text); +px_int PX_StringToInteger(px_string* str); +px_float PX_StringToFloat(px_string *str); +px_void PX_StringTrim(px_string *str); +px_bool PX_StringCat(px_string *str,const px_char *str2); +px_void PX_StringClear(px_string *str); +px_bool PX_StringCatChar(px_string *str,px_char ch); +px_int PX_StringLen(px_string *str); +px_void PX_StringFree(px_string *str); +px_bool PX_StringCopy(px_string *dest,px_string *res); +px_bool PX_StringInsertChar(px_string *str,px_int index,px_char ch); +px_bool PX_StringRemoveChar(px_string *str,px_int index); +px_void PX_StringReplaceRange(px_string *str,px_int startindex,px_int endindex,px_char *replaceto); +px_void PX_StringTrimLeft(px_string *str,px_int leftCount); +px_void PX_StringTrimRight(px_string *str,px_int RightCount); + +px_bool PX_StringIsNumeric(px_string *str); +px_bool PX_StringIsFloat(px_string *str); + +//px_void PX_StringFormat(px_string *str,px_char fmt[],...); +px_void PX_StringReplace(px_string *str,px_char *source,px_char *replaceto); +px_bool PX_StringInsert(px_string *str,px_int insertIndex,const px_char *InstrString); +px_bool PX_StringTrimer_Solve(px_string *pstring,px_char *parseCode,px_char *ReplaceCode); +px_void PX_StringInitAlloc(px_memorypool *mp,px_string *str,px_int allocSize); + +px_bool PX_StringFormat8(px_string *str,const px_char fmt[],px_stringformat _1, px_stringformat _2, px_stringformat _3, px_stringformat _4,px_stringformat _5, px_stringformat _6, px_stringformat _7, px_stringformat _8); +px_bool PX_StringFormat7(px_string *str,const px_char fmt[],px_stringformat _1, px_stringformat _2, px_stringformat _3, px_stringformat _4,px_stringformat _5, px_stringformat _6, px_stringformat _7); +px_bool PX_StringFormat6(px_string *str,const px_char fmt[],px_stringformat _1, px_stringformat _2, px_stringformat _3, px_stringformat _4,px_stringformat _5, px_stringformat _6); +px_bool PX_StringFormat5(px_string *str,const px_char fmt[],px_stringformat _1, px_stringformat _2, px_stringformat _3, px_stringformat _4,px_stringformat _5); +px_bool PX_StringFormat4(px_string *str,const px_char fmt[],px_stringformat _1, px_stringformat _2, px_stringformat _3, px_stringformat _4); +px_bool PX_StringFormat3(px_string *str,const px_char fmt[],px_stringformat _1, px_stringformat _2, px_stringformat _3); +px_bool PX_StringFormat2(px_string *str,const px_char fmt[],px_stringformat _1, px_stringformat _2); +px_bool PX_StringFormat1(px_string *str,const px_char fmt[],px_stringformat _1); +px_bool PX_StringSet(px_string *str,const px_char fmt[]); + +px_bool PX_StringCatEx(px_string *text,const px_char *str2); +px_void PX_StringBackspace(px_string *text); +px_void PX_StringBackspaceEx(px_string* text); +px_bool PX_StringCatCharEx(px_string* text, px_char ch); + + +#endif diff --git a/lib/PainterEngine/core/PX_Surface.c b/lib/PainterEngine/core/PX_Surface.c new file mode 100644 index 0000000000000000000000000000000000000000..a5ffc695cecf613d5c3447548de10f7f994dfa1a --- /dev/null +++ b/lib/PainterEngine/core/PX_Surface.c @@ -0,0 +1,174 @@ +#include "PX_Surface.h" + +px_bool PX_SurfaceCreate(px_memorypool *mp,px_uint width,px_uint height,px_surface *surface) +{ + px_void *p=MP_Malloc(mp,height*width*sizeof(px_color)); + if (p!=PX_NULL) + { + surface->height=height; + surface->width=width; + surface->surfaceBuffer=(px_color *)p; + surface->MP=mp; + surface->limit_left=0; + surface->limit_top=0; + surface->limit_right=width-1; + surface->limit_bottom=height-1; + PX_memdwordset(p,0,height*width); + return PX_TRUE; + } + return PX_FALSE; +} + +px_void PX_SurfaceFree(px_surface *psurface) +{ + if (psurface->surfaceBuffer==PX_NULL) + { + return; + } + MP_Free(psurface->MP,psurface->surfaceBuffer); + psurface->surfaceBuffer=PX_NULL; + psurface->MP=0; + psurface->height=0; + psurface->width=0; +} + + +px_int PX_SurfaceMemorySize(px_uint width,px_uint height) +{ + return width*height*sizeof(px_color); +} + + +PX_SurfaceLimitInfo PX_SurfaceGetLimit(px_surface *ps) +{ + PX_SurfaceLimitInfo info; + info.limit_bottom=ps->limit_bottom; + info.limit_left=ps->limit_left; + info.limit_right=ps->limit_right; + info.limit_top=ps->limit_top; + return info; +} + + +px_void PX_SurfaceSetLimitInfo(px_surface *ps,PX_SurfaceLimitInfo info) +{ + PX_SurfaceSetLimit(ps,info.limit_left,info.limit_top,info.limit_right,info.limit_bottom); +} + +px_void PX_SurfaceSetLimit(px_surface *ps,px_int limit_left,px_int limit_top,px_int limit_right,px_int limit_bottom) +{ + + + if (limit_left<0) + { + limit_left=0; + } + + if (limit_top<0) + { + limit_top=0; + } + + if (limit_right>ps->width-1) + { + limit_right=ps->width-1; + } + + + if (limit_bottom>ps->height-1) + { + limit_bottom=ps->height-1; + } + + ps->limit_left=limit_left; + ps->limit_right=limit_right; + ps->limit_top=limit_top; + ps->limit_bottom=limit_bottom; +} + + +px_void PX_SurfaceSetPixel(px_surface *psurface,px_int X,px_int Y,px_color color) +{ + if(X<=psurface->limit_right&&X>=psurface->limit_left&&Y<=psurface->limit_bottom&&Y>=psurface->limit_top) + { + psurface->surfaceBuffer[X+psurface->width*Y]=color; + } +} + +px_void PX_SurfaceDrawPixel(px_surface *psurface,px_int X,px_int Y,px_color COLOR) +{ + px_color c; + if (COLOR._argb.a==0) + { + return; + } + if(X<=psurface->limit_right&&X>=psurface->limit_left&&Y<=psurface->limit_bottom&&Y>=psurface->limit_top) + { + if(COLOR._argb.a==0xff) + { + psurface->surfaceBuffer[X+psurface->width*Y]=COLOR; + } + else + { + c=psurface->surfaceBuffer[X+psurface->width*Y]; + c._argb.r=(px_uchar)(((255-COLOR._argb.a)*c._argb.r+COLOR._argb.r*COLOR._argb.a)/255); + c._argb.g=(px_uchar)(((255-COLOR._argb.a)*c._argb.g+COLOR._argb.g*COLOR._argb.a)/255); + c._argb.b=(px_uchar)(((255-COLOR._argb.a)*c._argb.b+COLOR._argb.b*COLOR._argb.a)/255); + c._argb.a=255-(255-c._argb.a)*(255-COLOR._argb.a)/255; + psurface->surfaceBuffer[X+psurface->width*Y]=c; + } + } +} + +px_void PX_SurfaceClear(px_surface *psurface, px_int left, px_int top, px_int right, px_int bottom,px_color color) +{ + px_int i,mid; + + if (left>right) + { + mid=left; + left=right; + right=mid; + } + if (top>bottom) + { + mid=top; + top=bottom; + bottom=mid; + } + if (left<0) + { + left=0; + } + if (top<0) + { + top=0; + } + + if (left>psurface->width-1) + { + return; + } + + if (bottom<0) + { + return; + } + + if (right>psurface->width-1) + { + right=psurface->width-1; + } + + if (bottom>psurface->height-1) + { + bottom=psurface->height-1; + } + + + for (i=top;i<=bottom;i++) + { + PX_memdwordset(psurface->surfaceBuffer+i*psurface->width+left,color._argb.ucolor,right-left+1); + } + +} diff --git a/lib/PainterEngine/core/PX_Surface.h b/lib/PainterEngine/core/PX_Surface.h new file mode 100644 index 0000000000000000000000000000000000000000..b462415879172757d0ef63c88b2ab155dae8eafd --- /dev/null +++ b/lib/PainterEngine/core/PX_Surface.h @@ -0,0 +1,36 @@ +#ifndef __PX_SURFACE_H +#define __PX_SURFACE_H +#include "PX_MemoryPool.h" + +typedef struct _PX_Surface +{ + px_memorypool *MP; + px_color *surfaceBuffer; + px_int height; + px_int width; + px_int limit_left; + px_int limit_top; + px_int limit_right; + px_int limit_bottom; +}px_surface; +#define PX_SURFACECOLOR(main_pSurface,X,Y) ((main_pSurface)->surfaceBuffer[(X)+(main_pSurface)->width*(Y)]) +#define PX_SurfaceGetPixel(main_pSurface,X,Y) PX_SURFACECOLOR(main_pSurface,X,Y) + +typedef struct +{ + px_int limit_left; + px_int limit_top; + px_int limit_right; + px_int limit_bottom; +}PX_SurfaceLimitInfo; + +PX_SurfaceLimitInfo PX_SurfaceGetLimit(px_surface *ps); +px_void PX_SurfaceSetLimitInfo(px_surface *ps,PX_SurfaceLimitInfo info); +px_void PX_SurfaceSetLimit(px_surface *ps,px_int limit_left,px_int limit_top,px_int limit_right,px_int limit_bottom); +px_void PX_SurfaceSetPixel(px_surface *ps,px_int x,px_int y,px_color color); +px_void PX_SurfaceDrawPixel(px_surface *ps,px_int x,px_int y,px_color color); +px_bool PX_SurfaceCreate(px_memorypool *mp,px_uint width,px_uint height,_OUT px_surface *surface); +px_void PX_SurfaceClear(px_surface *ps, px_int left, px_int top, px_int right, px_int bottom,px_color color); +px_void PX_SurfaceFree(px_surface *psurface); +px_int PX_SurfaceMemorySize(px_uint width,px_uint height); +#endif diff --git a/lib/PainterEngine/core/PX_TRaw.c b/lib/PainterEngine/core/PX_TRaw.c new file mode 100644 index 0000000000000000000000000000000000000000..d627e3c99f02648e1811bea70d96e66d8d84e1b7 --- /dev/null +++ b/lib/PainterEngine/core/PX_TRaw.c @@ -0,0 +1,103 @@ +#include "PX_TRaw.h" + +px_bool PX_TRawVerify(px_void *data,px_int size) +{ + PX_TRaw_Header *pHeader=(PX_TRaw_Header *)data; + if (sizeMagic[0]!='T'||pHeader->Magic[1]!='R'||pHeader->Magic[2]!='A'||pHeader->Magic[3]!='W') + { + return PX_FALSE; + } + + if (size-sizeof(PX_TRaw_Header)Height*pHeader->Width*sizeof(px_color)) + { + return PX_FALSE; + } + + return PX_TRUE; +} + +px_int PX_TRawGetWidth(px_void *data) +{ + PX_TRaw_Header *pHeader=(PX_TRaw_Header *)data; + return pHeader->Width; +} + +px_int PX_TRawGetHeight(px_void *data) +{ + PX_TRaw_Header *pHeader=(PX_TRaw_Header *)data; + return pHeader->Height; +} + +px_void PX_TRawRender(px_surface *psurface,px_void *data,px_int x,px_int y) +{ + px_int i,j; + px_int Height; + px_int Width; + px_color *pdataColor=(px_color *)((px_char *)data+sizeof(PX_TRaw_Header)); + if (x>psurface->width||y>psurface->height) + { + return; + } + + Height=PX_TRawGetHeight(data); + Width=PX_TRawGetWidth(data); + + if (Height>0&&Width>0) + { + if (x<-Width||y<-Height) + { + return; + } + } + else + { + return; + } + + for (i=0;iheight*psurface->width*sizeof(px_color)+sizeof(header); + *size=_outsize; + header.Magic[0]='T'; + header.Magic[1]='R'; + header.Magic[2]='A'; + header.Magic[3]='W'; + + header.Height=psurface->height; + header.Width=psurface->width; + + if (TRawBuffer) + { + PX_memcpy(TRawBuffer,&header,sizeof(header)); + PX_memcpy(TRawBuffer+sizeof(header),psurface->surfaceBuffer,psurface->height*psurface->width*sizeof(px_color)); + return PX_TRUE; + } + else + return PX_FALSE; +} + +px_uint PX_TRawGetSize(PX_TRaw_Header *header) +{ + return header->Height*header->Width*sizeof(px_color)+sizeof(PX_TRaw_Header); +} diff --git a/lib/PainterEngine/core/PX_TRaw.h b/lib/PainterEngine/core/PX_TRaw.h new file mode 100644 index 0000000000000000000000000000000000000000..7f06edc3dbbae80195e2dc2fbd82df1ba67ea835 --- /dev/null +++ b/lib/PainterEngine/core/PX_TRaw.h @@ -0,0 +1,19 @@ +#ifndef _PX_TRAW_H +#define _PX_TRAW_H + +#include "../core/PX_Surface.h" + +typedef struct _PX_TRaw_Header +{ + px_byte Magic[4];//TRAW 0x57415254 + px_int32 Width; + px_int32 Height; +}PX_TRaw_Header; + +px_bool PX_TRawVerify(px_void *data,px_int size); +px_int PX_TRawGetWidth(px_void *data); +px_int PX_TRawGetHeight(px_void *data); +px_uint PX_TRawGetSize(PX_TRaw_Header *header); +px_void PX_TRawRender(px_surface *psurface,px_void *data,px_int x,px_int y); +px_bool PX_TRawBuild(px_surface *psurface,px_byte *TRawBuffer,px_int *size); +#endif diff --git a/lib/PainterEngine/core/PX_Texture.c b/lib/PainterEngine/core/PX_Texture.c new file mode 100644 index 0000000000000000000000000000000000000000..d4ed3684d18b83987f8f009700bf9e98fbe23be5 --- /dev/null +++ b/lib/PainterEngine/core/PX_Texture.c @@ -0,0 +1,2896 @@ +#include "PX_Texture.h" + +px_bool PX_TextureCreate(px_memorypool *mp,px_texture *tex,px_int width,px_int height) +{ + return PX_SurfaceCreate(mp,width,height,tex); +} + + +px_bool PX_TextureCreateFromMemory(px_memorypool *mp,px_void *data,px_int size,px_texture *tex) +{ + px_int width; + px_int height; + if (PX_BitmapVerify(data,size)) + { + width=PX_BitmapGetWidth(data); + height=PX_BitmapGetHeight(data); + if(PX_TextureCreate(mp,tex,width,height)) + { + PX_BitmapRender(tex,data,size,0,0); + return PX_TRUE; + } + else + { + return PX_FALSE; + } + + } + + if (PX_TRawVerify(data,size)) + { + width=PX_TRawGetWidth(data); + height=PX_TRawGetHeight(data); + if(PX_TextureCreate(mp,tex,width,height)) + { + PX_TRawRender(tex,data,0,0); + return PX_TRUE; + } + else + { + return PX_FALSE; + } + } + + //image-format not supported + return PX_FALSE; +} + +typedef struct +{ + px_surface *psurface; + px_texture *Server; + px_int x,y,top,bottom,left,right; + PX_ALIGN refPoint; + PX_TEXTURERENDER_BLEND *blend; +}PX_TEXTURERENDER_PARALLEL_DATA; + + +static px_int PX_TextureRenderParallel(px_void *parallel_data) +{ + PX_TEXTURERENDER_PARALLEL_DATA *param_data=(PX_TEXTURERENDER_PARALLEL_DATA *)parallel_data; + px_int i,j; + px_int bR,bG,bB,bA; + px_color clr; + + px_color *pdata=(px_color *)param_data->Server->surfaceBuffer; + if (param_data->blend) + { + for (j=param_data->top;j<=param_data->bottom;j++) + { + for (i=param_data->left;i<=param_data->right;i++) + { + clr=pdata[j*param_data->Server->width+i]; + bA=(px_int)(clr._argb.a*param_data->blend->alpha); + bR=(px_int)(clr._argb.r*param_data->blend->hdr_R); + bG=(px_int)(clr._argb.g*param_data->blend->hdr_G); + bB=(px_int)(clr._argb.b*param_data->blend->hdr_B); + + clr._argb.a=bA>255?255:(px_uchar)bA; + clr._argb.r=bR>255?255:(px_uchar)bR; + clr._argb.g=bG>255?255:(px_uchar)bG; + clr._argb.b=bB>255?255:(px_uchar)bB; + PX_SurfaceDrawPixel(param_data->psurface,param_data->x+i,param_data->y+j,clr); + } + } + } + else + { + for (j=param_data->top;j<=param_data->bottom;j++) + { + for (i=param_data->left;i<=param_data->right;i++) + { + clr=pdata[j*param_data->Server->width+i]; + PX_SurfaceDrawPixel(param_data->psurface,param_data->x+i,param_data->y+j,clr); + } + } + } + return 0; +} + +px_void PX_TextureRender(px_surface *psurface,px_texture *tex,px_int x,px_int y,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend) +{ + px_int left,right,top,bottom,i,j; + px_int bR,bG,bB,bA; + px_color *pdata; + px_color clr; + + pdata=(px_color *)tex->surfaceBuffer; + switch (refPoint) + { + case PX_ALIGN_LEFTTOP: + break; + case PX_ALIGN_MIDTOP: + x-=tex->width/2; + break; + case PX_ALIGN_RIGHTTOP: + x-=tex->width; + break; + case PX_ALIGN_LEFTMID: + y-=tex->height/2; + break; + case PX_ALIGN_CENTER: + y-=tex->height/2; + x-=tex->width/2; + break; + case PX_ALIGN_RIGHTMID: + y-=tex->height/2; + x-=tex->width; + break; + case PX_ALIGN_LEFTBOTTOM: + y-=tex->height; + break; + case PX_ALIGN_MIDBOTTOM: + y-=tex->height; + x-=tex->width/2; + break; + case PX_ALIGN_RIGHTBOTTOM: + y-=tex->height; + x-=tex->width; + break; + } + + + if (x<-tex->width) + { + return; + } + if (x>psurface->width-1) + { + return; + } + if (y<-tex->height) + { + return; + } + if (y>psurface->height-1) + { + return; + } + + if (x<0) + { + left=-x; + } + else + { + left=0; + } + + if (x+tex->width>psurface->width) + { + right=psurface->width-x-1; + } + else + { + right=tex->width-1; + } + + if (y<0) + { + top=-y; + } + else + { + top=0; + } + + if (y+tex->height>psurface->height) + { + bottom=psurface->height-y-1; + } + else + { + bottom=tex->height-1; + } + + + if (blend) + { + px_int Ab=(px_int)(blend->alpha*1000); + px_int Rb=(px_int)(blend->hdr_R*1000); + px_int Gb=(px_int)(blend->hdr_G*1000); + px_int Bb=(px_int)(blend->hdr_B*1000); + + for (j=top;j<=bottom;j++) + { + for (i=left;i<=right;i++) + { + clr=pdata[j*tex->width+i]; + bA=(px_int)(clr._argb.a*Ab/1000); + bR=(px_int)(clr._argb.r*Rb/1000); + bG=(px_int)(clr._argb.g*Gb/1000); + bB=(px_int)(clr._argb.b*Bb/1000); + + clr._argb.a=bA>255?255:(px_uchar)bA; + clr._argb.r=bR>255?255:(px_uchar)bR; + clr._argb.g=bG>255?255:(px_uchar)bG; + clr._argb.b=bB>255?255:(px_uchar)bB; + PX_SurfaceDrawPixel(psurface,x+i,y+j,clr); + } + } + } + else + { + for (j=top;j<=bottom;j++) + { + for (i=left;i<=right;i++) + { + clr=pdata[j*tex->width+i]; + PX_SurfaceDrawPixel(psurface,x+i,y+j,clr); + } + } + } + +} + + + +px_void PX_TextureCover(px_surface *psurface,px_texture *tex,px_int x,px_int y,PX_ALIGN refPoint) +{ + px_int left,right,top,bottom,j; + + switch (refPoint) + { + case PX_ALIGN_LEFTTOP: + break; + case PX_ALIGN_MIDTOP: + x-=tex->width/2; + break; + case PX_ALIGN_RIGHTTOP: + x-=tex->width; + break; + case PX_ALIGN_LEFTMID: + y-=tex->height/2; + break; + case PX_ALIGN_CENTER: + y-=tex->height/2; + x-=tex->width/2; + break; + case PX_ALIGN_RIGHTMID: + y-=tex->height/2; + x-=tex->width; + break; + case PX_ALIGN_LEFTBOTTOM: + y-=tex->height; + break; + case PX_ALIGN_MIDBOTTOM: + y-=tex->height; + x-=tex->width/2; + break; + case PX_ALIGN_RIGHTBOTTOM: + y-=tex->height; + x-=tex->width; + break; + } + + + if (x<-tex->width) + { + return; + } + if (x>psurface->width-1) + { + return; + } + if (y<-tex->height) + { + return; + } + if (y>psurface->height-1) + { + return; + } + + if (x<0) + { + left=-x; + } + else + { + left=0; + } + + if (x+tex->width>psurface->width) + { + right=psurface->width-x-1; + } + else + { + right=tex->width-1; + } + + if (y<0) + { + top=-y; + } + else + { + top=0; + } + + if (y+tex->height>psurface->height) + { + bottom=psurface->height-y-1; + } + else + { + bottom=tex->height-1; + } + + + for (j=top;j<=bottom;j++) + { + PX_memcpy(&psurface->surfaceBuffer[x+left+psurface->width*(y+j)],&tex->surfaceBuffer[tex->width*(j)+left],sizeof(px_color)*(right-left+1)); + } + + +} + +px_void PX_TextureGetVisibleRange(px_texture *ptexture,px_int *pLeft,px_int *pRight,px_int *pTop,px_int *pBottom) +{ + px_int x=0,y=0; + px_int left=ptexture->width-1,right=0,top=ptexture->height-1,bottom=0; + for (y=0;yheight-1;y++) + { + for (x=0;xwidth-1;x++) + { + if (PX_SurfaceGetPixel(ptexture,x,y)._argb.a) + { + if (xright) + { + right=x; + } + if (ybottom) + { + bottom=y; + } + } + } + } + *pLeft=left; + *pRight=right; + *pTop=top; + *pBottom=bottom; +} + +px_void PX_TextureRenderPixelShader(px_surface *psurface,px_texture *tex,px_int x,px_int y,PX_ALIGN refPoint,PX_TexturePixelShader shader,px_void *ptr) +{ + px_int left,right,top,bottom,i,j; + px_color *pdata; + px_color clr; + + pdata=(px_color *)tex->surfaceBuffer; + switch (refPoint) + { + case PX_ALIGN_LEFTTOP: + break; + case PX_ALIGN_MIDTOP: + x-=tex->width/2; + break; + case PX_ALIGN_RIGHTTOP: + x-=tex->width; + break; + case PX_ALIGN_LEFTMID: + y-=tex->height/2; + break; + case PX_ALIGN_CENTER: + y-=tex->height/2; + x-=tex->width/2; + break; + case PX_ALIGN_RIGHTMID: + y-=tex->height/2; + x-=tex->width; + break; + case PX_ALIGN_LEFTBOTTOM: + y-=tex->height; + break; + case PX_ALIGN_MIDBOTTOM: + y-=tex->height; + x-=tex->width/2; + break; + case PX_ALIGN_RIGHTBOTTOM: + y-=tex->height; + x-=tex->width; + break; + } + + + if (x<-tex->width) + { + return; + } + if (x>psurface->width-1) + { + return; + } + if (y<-tex->height) + { + return; + } + if (y>psurface->height-1) + { + return; + } + + if (x<0) + { + left=-x; + } + else + { + left=0; + } + + if (x+tex->width>psurface->width) + { + right=psurface->width-x-1; + } + else + { + right=tex->width-1; + } + + if (y<0) + { + top=-y; + } + else + { + top=0; + } + + if (y+tex->height>psurface->height) + { + bottom=psurface->height-y-1; + } + else + { + bottom=tex->height-1; + } + + + for (j=top;j<=bottom;j++) + { + for (i=left;i<=right;i++) + { + clr=pdata[j*tex->width+i]; + shader(psurface,x+i,y+j,clr,ptr); + } + } +} + +px_void PX_TextureRenderRotation(px_surface *psurface,px_texture *tex,px_int x,px_int y,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend,px_int Angle) +{ + PX_TextureRenderRotation_sincos(psurface,tex,x,y,refPoint,blend,PX_sin_angle((px_float)Angle),PX_cos_angle((px_float)Angle)); +} + +px_void PX_TextureRenderRotation_vector(px_surface *psurface,px_texture *tex,px_int x,px_int y,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend,px_point p_vector) +{ + PX_TextureRenderRotation_sincos(psurface,tex,x,y,refPoint,blend,PX_Point_sin(p_vector),PX_Point_cos(p_vector)); +} + +px_void PX_TextureRenderRotation_sincos(px_surface *psurface,px_texture *tex,px_int x,px_int y,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend,px_float sinx,px_float cosx) +{ + px_int newheight,newwidth,i,j,resHeight,resWidth; + px_point CornerPoint[4]; + px_matrix rotMat; + px_double SampleX,SampleY,mapX,mapY; + px_double mixa,mixr,mixg,mixb,Weight; + px_float invCosAgl,invSinAgl; + px_color sampleColor; + px_int left,right,top,bottom; + + + + resHeight=tex->height; + resWidth=tex->width; + + CornerPoint[0].x=-tex->width/2.f; + CornerPoint[0].y=-tex->height/2.f; + CornerPoint[0].z=0; + + CornerPoint[1].x=tex->width/2.f; + CornerPoint[1].y=-tex->height/2.f; + CornerPoint[1].z=0; + + CornerPoint[2].x=-tex->width/2.f; + CornerPoint[2].y=tex->height/2.f; + CornerPoint[2].z=0; + + CornerPoint[3].x=tex->width/2.f; + CornerPoint[3].y=tex->height/2.f; + CornerPoint[3].z=0; + + rotMat._11=cosx; rotMat._12=sinx; rotMat._13=0.0f; rotMat._14=0.0f; + rotMat._21=-sinx; rotMat._22=cosx; rotMat._23=0.0f; rotMat._24=0.0f; + rotMat._31=0.0f; rotMat._32=0.0f; rotMat._33=1.0f; rotMat._34=0.0f; + rotMat._41=0.0f; rotMat._42=0.0f; rotMat._43=0.0f; rotMat._44=1.0f; + + + CornerPoint[0]=PX_PointMulMatrix(CornerPoint[0],rotMat); + CornerPoint[1]=PX_PointMulMatrix(CornerPoint[1],rotMat); + CornerPoint[2]=PX_PointMulMatrix(CornerPoint[2],rotMat); + CornerPoint[3]=PX_PointMulMatrix(CornerPoint[3],rotMat); + + newheight=0; + newwidth=0; + for (i=0;i<4;i++) + { + if (CornerPoint[i].y>newheight) + { + newheight=(px_int)CornerPoint[i].y; + } + if (CornerPoint[i].x>newwidth) + { + newwidth=(px_int)CornerPoint[i].x; + } + } + newheight=PX_TRUNC(newheight*2+2); + newwidth=PX_TRUNC(newwidth*2+2); + + + switch (refPoint) + { + case PX_ALIGN_LEFTTOP: + break; + case PX_ALIGN_MIDTOP: + x-=newwidth/2; + break; + case PX_ALIGN_RIGHTTOP: + x-=newwidth; + break; + case PX_ALIGN_LEFTMID: + y-=newheight/2; + break; + case PX_ALIGN_CENTER: + y-=newheight/2; + x-=newwidth/2; + break; + case PX_ALIGN_RIGHTMID: + y-=newheight/2; + x-=newwidth; + break; + case PX_ALIGN_LEFTBOTTOM: + y-=newheight; + break; + case PX_ALIGN_MIDBOTTOM: + y-=newheight; + x-=newwidth/2; + break; + case PX_ALIGN_RIGHTBOTTOM: + y-=newheight; + x-=newwidth; + break; + } + + + if (x<-newwidth) + { + return; + } + if (x>psurface->width-1) + { + return; + } + if (y<-newheight) + { + return; + } + if (y>psurface->height-1) + { + return; + } + + if (x<0) + { + left=-x; + } + else + { + left=0; + } + + if (x+newwidth>psurface->width) + { + right=psurface->width-x-1; + } + else + { + right=newwidth-1; + } + + if (y<0) + { + top=-y; + } + else + { + top=0; + } + + if (y+newheight>psurface->height) + { + bottom=psurface->height-y-1; + } + else + { + bottom=newheight-1; + } + + + + + + invCosAgl=cosx; + invSinAgl=-sinx; + + + for (j=top;jresWidth+0.5) + { + continue; + } + if (mapY<-0.5||mapY>resHeight+0.5) + { + continue; + } + mixa=0; + mixr=0; + mixg=0; + mixb=0; + //Sample 4 points + //lt + + SampleX=(mapX-0.5f); + SampleY=(mapY-0.5f); + + if (SampleX>0&&(SampleX)0&&(SampleY)0&&(SampleX)0&&(SampleY)0&&(SampleX)0&&(SampleY)0&&(SampleX)0&&(SampleY)255?mixa=255:0; + mixr>255?mixr=255:0; + mixg>255?mixg=255:0; + mixb>255?mixb=255:0; + if (blend) + { + px_int bA,bR,bG,bB; + px_color clr=PX_COLOR((px_uchar)mixa,(px_uchar)mixr,(px_uchar)mixg,(px_uchar)mixb); + px_int Ab=(px_int)(blend->alpha*1000); + px_int Rb=(px_int)(blend->hdr_R*1000); + px_int Gb=(px_int)(blend->hdr_G*1000); + px_int Bb=(px_int)(blend->hdr_B*1000); + + bA=(px_int)(clr._argb.a*Ab/1000); + bR=(px_int)(clr._argb.r*Rb/1000); + bG=(px_int)(clr._argb.g*Gb/1000); + bB=(px_int)(clr._argb.b*Bb/1000); + + clr._argb.a=bA>255?255:(px_uchar)bA; + clr._argb.r=bR>255?255:(px_uchar)bR; + clr._argb.g=bG>255?255:(px_uchar)bG; + clr._argb.b=bB>255?255:(px_uchar)bB; + + PX_SurfaceDrawPixel(psurface,i+x,j+y,clr); + } + else + { + PX_SurfaceDrawPixel(psurface,i+x,j+y,PX_COLOR((px_uchar)mixa,(px_uchar)mixr,(px_uchar)mixg,(px_uchar)mixb)); + } + + } + } + return; +} + +px_void PX_TextureRenderMask(px_surface *psurface,px_texture *mask_tex,px_texture *map_tex,px_int x,px_int y,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend) +{ + px_int left,right,top,bottom,i,j; + px_int bR,bG,bB,bA; + px_color *pmapdata,*pmaskdata; + px_color clr; + + pmaskdata=(px_color *)mask_tex->surfaceBuffer; + pmapdata=(px_color *)map_tex->surfaceBuffer; + + switch (refPoint) + { + case PX_ALIGN_LEFTTOP: + break; + case PX_ALIGN_MIDTOP: + x-=mask_tex->width/2; + break; + case PX_ALIGN_RIGHTTOP: + x-=mask_tex->width; + break; + case PX_ALIGN_LEFTMID: + y-=mask_tex->height/2; + break; + case PX_ALIGN_CENTER: + y-=mask_tex->height/2; + x-=mask_tex->width/2; + break; + case PX_ALIGN_RIGHTMID: + y-=mask_tex->height/2; + x-=mask_tex->width; + break; + case PX_ALIGN_LEFTBOTTOM: + y-=mask_tex->height; + break; + case PX_ALIGN_MIDBOTTOM: + y-=mask_tex->height; + x-=mask_tex->width/2; + break; + case PX_ALIGN_RIGHTBOTTOM: + y-=mask_tex->height; + x-=mask_tex->width; + break; + } + + if (mask_tex->width>map_tex->width) + { + if (x<-map_tex->width) + { + return; + } + } + else + { + if (x<-mask_tex->width) + { + return; + } + } + + if (x>psurface->width-1) + { + return; + } + if (mask_tex->height>map_tex->height) + { + if (y<-map_tex->height) + { + return; + } + } + else + { + if (y<-mask_tex->height) + { + return; + } + } + + if (y>psurface->height-1) + { + return; + } + + if (x<0) + { + left=-x; + } + else + { + left=0; + } + if (mask_tex->width>map_tex->width) + { + if (x+mask_tex->width>psurface->width) + { + right=psurface->width-x-1; + } + else + { + right=mask_tex->width-1; + } + } + else + { + if (x+map_tex->width>psurface->width) + { + right=psurface->width-x-1; + } + else + { + right=map_tex->width-1; + } + } + + + + if (y<0) + { + top=-y; + } + else + { + top=0; + } + if (mask_tex->height>map_tex->height) + { + if (y+mask_tex->height>psurface->height) + { + bottom=psurface->height-y-1; + } + else + { + bottom=mask_tex->height-1; + } + } + else + { + if (y+map_tex->height>psurface->height) + { + bottom=psurface->height-y-1; + } + else + { + bottom=map_tex->height-1; + } + } + + if (blend) + { + px_int Ab=(px_int)(blend->alpha*1000); + px_int Rb=(px_int)(blend->hdr_R*1000); + px_int Gb=(px_int)(blend->hdr_G*1000); + px_int Bb=(px_int)(blend->hdr_B*1000); + + for (j=top;j<=bottom;j++) + { + for (i=left;i<=right;i++) + { + clr=pmapdata[j*map_tex->width+i]; + clr._argb.a=1*clr._argb.a*pmaskdata[j*mask_tex->width+i]._argb.a/255; + bA=(px_int)(clr._argb.a*Ab/1000); + bR=(px_int)(clr._argb.r*Rb/1000); + bG=(px_int)(clr._argb.g*Gb/1000); + bB=(px_int)(clr._argb.b*Bb/1000); + + clr._argb.a=bA>255?255:(px_uchar)bA; + clr._argb.r=bR>255?255:(px_uchar)bR; + clr._argb.g=bG>255?255:(px_uchar)bG; + clr._argb.b=bB>255?255:(px_uchar)bB; + PX_SurfaceDrawPixel(psurface,x+i,y+j,clr); + } + } + } + else + { + for (j=top;j<=bottom;j++) + { + for (i=left;i<=right;i++) + { + clr=pmapdata[j*map_tex->width+i]; + clr._argb.a=1*clr._argb.a*pmaskdata[j*mask_tex->width+i]._argb.a/255; + PX_SurfaceDrawPixel(psurface,x+i,y+j,clr); + } + } + } + +} + + +px_bool PX_TextureCreateScale(px_memorypool *mp,px_texture *resTexture,px_int newWidth,px_int newHeight,px_texture *out) +{ + px_double SampleWidth=(px_double)(resTexture->width)/(newWidth); + px_double SampleHeight=(px_double)(resTexture->height)/(newHeight); + px_double SampleX,SampleY,SampleArea,u,v,cellw,cellh,mixa,mixr,mixg,mixb; + px_color *Dst,*Src=(px_color *)resTexture->surfaceBuffer; + px_color SampleColor,MixColor; + px_int xoft,yoft,horz,vcl; + + if (newWidth<0||newHeight<0) + { + return PX_FALSE; + } + if (!(newHeight&&newWidth)) + { + return PX_FALSE; + } + + if (!PX_TextureCreate(mp,out,newWidth,newHeight)) + { + return PX_FALSE; + } + + Dst=(px_color *)out->surfaceBuffer; + + SampleArea=SampleHeight*SampleWidth; + + for (yoft=0;yoftwidth&&vclheight) + SampleColor=PX_SURFACECOLOR(resTexture,horz,vcl); + else + SampleColor._argb.ucolor=0; + + mixa+=SampleColor._argb.a*cellh*cellw/SampleArea; + mixr+=SampleColor._argb.r*cellh*cellw/SampleArea; + mixg+=SampleColor._argb.g*cellh*cellw/SampleArea; + mixb+=SampleColor._argb.b*cellh*cellw/SampleArea; + + + vcl++; + v=(px_double)vcl; + } + horz++; + u=(px_double)horz; + } + mixa>255?mixa=255:0; + mixr>255?mixr=255:0; + mixg>255?mixg=255:0; + mixb>255?mixb=255:0; + Dst[xoft+yoft*newWidth]=PX_COLOR((px_uchar)PX_APO(mixa),(px_uchar)mixr,(px_uchar)mixg,(px_uchar)mixb);; + } + } + return PX_TRUE; +} + +px_bool PX_TextureCreateRotationRadian(px_memorypool *mp,px_texture *resTexture,px_float radian,px_texture *out) +{ + return PX_TextureCreateRotationAngle(mp,resTexture,(px_float)(radian*180/PX_PI),out); +} + +px_bool PX_TextureCreateRotationAngle(px_memorypool *mp,px_texture *resTexture,px_float Angle,px_texture *out) +{ + px_int height,width,i,j,resHeight,resWidth; + px_point CornerPoint[4]; + px_matrix rotMat; + px_double SampleX,SampleY,mapX,mapY; + px_double mixa,mixr,mixg,mixb,Weight; + px_float invCosAgl,invSinAgl; + px_color sampleColor; + + resHeight=resTexture->height; + resWidth=resTexture->width; + CornerPoint[0].x=-resTexture->width/2.f; + CornerPoint[0].y=-resTexture->height/2.f; + CornerPoint[0].z=0; + + CornerPoint[1].x=resTexture->width/2.f; + CornerPoint[1].y=-resTexture->height/2.f; + CornerPoint[1].z=0; + + CornerPoint[2].x=-resTexture->width/2.f; + CornerPoint[2].y=resTexture->height/2.f; + CornerPoint[2].z=0; + + CornerPoint[3].x=resTexture->width/2.f; + CornerPoint[3].y=resTexture->height/2.f; + CornerPoint[3].z=0; + + PX_MatrixRotateZ(&rotMat,Angle); + CornerPoint[0]=PX_PointMulMatrix(CornerPoint[0],rotMat); + CornerPoint[1]=PX_PointMulMatrix(CornerPoint[1],rotMat); + CornerPoint[2]=PX_PointMulMatrix(CornerPoint[2],rotMat); + CornerPoint[3]=PX_PointMulMatrix(CornerPoint[3],rotMat); + + height=0; + width=0; + for (i=0;i<4;i++) + { + if (CornerPoint[i].y>height) + { + height=(px_int)CornerPoint[i].y; + } + if (CornerPoint[i].x>width) + { + width=(px_int)CornerPoint[i].x; + } + } + height=PX_TRUNC(height*2+2); + width=PX_TRUNC(width*2+2); + if (!PX_TextureCreate(mp,out,width,height)) + { + return PX_FALSE; + } + invCosAgl=PX_cos_angle(-Angle); + invSinAgl=PX_sin_angle(-Angle); + for (j=0;jresWidth+0.5) + { + continue; + } + if (mapY<-0.5||mapY>resHeight+0.5) + { + continue; + } + mixa=0; + mixr=0; + mixg=0; + mixb=0; + //Sample 4 points + //lt + + SampleX=(mapX-0.5f); + SampleY=(mapY-0.5f); + + if (SampleX>0&&(SampleX)0&&(SampleY)0&&(SampleX)0&&(SampleY)0&&(SampleX)0&&(SampleY)0&&(SampleX)0&&(SampleY)255?mixa=255:0; + mixr>255?mixr=255:0; + mixg>255?mixg=255:0; + mixb>255?mixb=255:0; + + PX_SurfaceSetPixel(out,i,j,PX_COLOR((px_uchar)mixa,(px_uchar)mixr,(px_uchar)mixg,(px_uchar)mixb)); + + } + } + return PX_TRUE; +} + +px_bool PX_TextureRotationAngleToTexture(px_texture *resTexture,px_float Angle,px_texture *out) +{ + px_int height,width,i,j,resHeight,resWidth; + px_double SampleX,SampleY,mapX,mapY; + px_double mixa,mixr,mixg,mixb,Weight; + px_float invCosAgl,invSinAgl; + px_color sampleColor; + + resHeight=resTexture->height; + resWidth=resTexture->width; + + height=out->height; + width=out->width; + + invCosAgl=PX_cos_angle(-Angle); + invSinAgl=PX_sin_angle(-Angle); + for (j=0;jresWidth+0.5) + { + continue; + } + if (mapY<-0.5||mapY>resHeight+0.5) + { + continue; + } + mixa=0; + mixr=0; + mixg=0; + mixb=0; + //Sample 4 points + //lt + + SampleX=(mapX-0.5f); + SampleY=(mapY-0.5f); + + if (SampleX>0&&(SampleX)0&&(SampleY)0&&(SampleX)0&&(SampleY)0&&(SampleX)0&&(SampleY)0&&(SampleX)0&&(SampleY)255?mixa=255:0; + mixr>255?mixr=255:0; + mixg>255?mixg=255:0; + mixb>255?mixb=255:0; + + PX_SurfaceSetPixel(out,i,j,PX_COLOR((px_uchar)mixa,(px_uchar)mixr,(px_uchar)mixg,(px_uchar)mixb)); + + } + } + return PX_TRUE; +} + +px_void PX_TextureFree(px_texture *tex) +{ + PX_SurfaceFree(tex); +} + + +px_void PX_SurfaceRender(px_surface *psurface,px_surface *surface,px_int x,px_int y,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend) +{ + PX_TextureRender(psurface,surface,x,y,refPoint,blend); +} + +px_void PX_SurfaceCover(px_surface *pdestSurface,px_surface *pResSurface,px_int x,px_int y,PX_ALIGN refPoint) +{ + PX_TextureCover(pdestSurface,pResSurface,x,y,refPoint); +} + +px_void PX_SurfaceSetRect(px_surface *psurface, px_int left, px_int top, px_int right, px_int bottom,px_color color) +{ + px_int i,mid; + + if (left>right) + { + mid=left; + left=right; + right=mid; + } + if (top>bottom) + { + mid=top; + top=bottom; + bottom=mid; + } + if (left<0) + { + left=0; + } + if (top<0) + { + top=0; + } + if (left>psurface->width-1) + { + return; + } + + if (bottom>psurface->height-1) + { + return; + } + + if (right>psurface->width-1) + { + right=psurface->width-1; + } + + if (bottom>psurface->height-1) + { + right=psurface->height-1; + } + + for (i=top;i<=bottom;i++) + { + PX_memdwordset(psurface->surfaceBuffer+i*psurface->width+left,color._argb.ucolor,right-left+1); + } +} + + + +px_void PX_TextureRenderEx(px_surface *psurface,px_texture *resTexture,px_int x,px_int y,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend,px_float scale,px_float Angle) +{ + px_int newWidth,newHeight; + + px_int i,j,resHeight,resWidth; + + px_float invCosAgl,invSinAgl; + + px_double ref_x,ref_y; + px_int mapX,mapY; + + px_color clr; + px_int bA,bR,bG,bB; + + ////////////////////////////////////////////////////////////////////////// + px_int left,right,top,bottom; + + + ////////////////////////////////////////////////////////////////////////// + + resHeight=resTexture->height; + resWidth=resTexture->width; + + newHeight=PX_TRUNC(resHeight*scale); + newWidth=PX_TRUNC(resWidth*scale); + + ////////////////////////////////////////////////////////////////////////// + switch (refPoint) + { + case PX_ALIGN_LEFTTOP: + break; + case PX_ALIGN_MIDTOP: + x-=newWidth/2; + break; + case PX_ALIGN_RIGHTTOP: + x-=newWidth; + break; + case PX_ALIGN_LEFTMID: + y-=newHeight/2; + break; + case PX_ALIGN_CENTER: + y-=newHeight/2; + x-=newWidth/2; + break; + case PX_ALIGN_RIGHTMID: + y-=newHeight/2; + x-=newWidth; + break; + case PX_ALIGN_LEFTBOTTOM: + y-=newHeight; + break; + case PX_ALIGN_MIDBOTTOM: + y-=newHeight; + x-=newWidth/2; + break; + case PX_ALIGN_RIGHTBOTTOM: + y-=newHeight; + x-=newWidth; + break; + } + + + if (x<-newWidth) + { + return; + } + if (x>psurface->width-1) + { + return; + } + if (y<-newHeight) + { + return; + } + if (y>psurface->height-1) + { + return; + } + + if (x<0) + { + left=-x; + } + else + { + left=0; + } + + if (x+newWidth>psurface->width) + { + right=psurface->width-x-1; + } + else + { + right=newWidth-1; + } + + if (y<0) + { + top=-y; + } + else + { + top=0; + } + + if (y+newHeight>psurface->height) + { + bottom=psurface->height-y-1; + } + else + { + bottom=newHeight-1; + } + ////////////////////////////////////////////////////////////////////////// + + + + invCosAgl=PX_cos_angle(-Angle); + invSinAgl=PX_sin_angle(-Angle); + + if (blend) + { + px_int Ab=(px_int)(blend->alpha*1000); + px_int Rb=(px_int)(blend->hdr_R*1000); + px_int Gb=(px_int)(blend->hdr_G*1000); + px_int Bb=(px_int)(blend->hdr_B*1000); + + for (j=top;j<=bottom;j++) + { + for (i=left;i<=right;i++) + { + ref_x=i*1.0/newWidth-0.5; + ref_y=j*1.0/newHeight-0.5; + + mapX=(px_int)((ref_x*invCosAgl-ref_y*invSinAgl)*resWidth+resWidth/2); + mapY=(px_int)((ref_x*invSinAgl+ref_y*invCosAgl)*resHeight+resHeight/2); + + if (mapX<0||mapX>=resWidth) + { + continue; + } + + if (mapY<0||mapY>=resHeight) + { + continue; + } + + clr=PX_SURFACECOLOR(resTexture,mapX,mapY); + bA=(px_int)(clr._argb.a*Ab/1000); + bR=(px_int)(clr._argb.r*Rb/1000); + bG=(px_int)(clr._argb.g*Gb/1000); + bB=(px_int)(clr._argb.b*Bb/1000); + + clr._argb.a=bA>255?255:(px_uchar)bA; + clr._argb.r=bR>255?255:(px_uchar)bR; + clr._argb.g=bG>255?255:(px_uchar)bG; + clr._argb.b=bB>255?255:(px_uchar)bB; + PX_SurfaceDrawPixel(psurface,x+i,y+j,clr); + } + + } + + } + else + { + for (j=top;j<=bottom;j++) + { + for (i=left;i<=right;i++) + { + ref_x=i*1.0/newWidth-0.5; + ref_y=j*1.0/newHeight-0.5; + + mapX=(px_int)((ref_x*invCosAgl-ref_y*invSinAgl)*resWidth+resWidth/2); + mapY=(px_int)((ref_x*invSinAgl+ref_y*invCosAgl)*resHeight+resHeight/2); + + if (mapX<0||mapX>=resWidth) + { + continue; + } + + if (mapY<0||mapY>=resHeight) + { + continue; + } + + PX_SurfaceDrawPixel(psurface,x+i,y+j,PX_SURFACECOLOR(resTexture,mapX,mapY)); + } + + } + } +} + +px_void PX_TextureRenderMaskEx(px_surface *psurface,px_texture *mask_tex,px_texture *map_tex,px_int x,px_int y,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend,px_float scale,px_float Angle) +{ + px_int newWidth,newHeight; + + px_int i,j,resHeight,resWidth; + px_int bA,bB,bG,bR; + px_float invCosAgl,invSinAgl; + + px_double ref_x,ref_y; + px_int mapX,mapY; + + px_color *pmapdata,*pmaskdata; + px_color clr; + + + ////////////////////////////////////////////////////////////////////////// + px_int left,right,top,bottom; + + + ////////////////////////////////////////////////////////////////////////// + + + pmaskdata=(px_color *)mask_tex->surfaceBuffer; + pmapdata=(px_color *)map_tex->surfaceBuffer; + + resHeight=mask_tex->height; + resWidth=mask_tex->width; + + newHeight=PX_TRUNC(resHeight*scale); + newWidth=PX_TRUNC(resWidth*scale); + + ////////////////////////////////////////////////////////////////////////// + switch (refPoint) + { + case PX_ALIGN_LEFTTOP: + break; + case PX_ALIGN_MIDTOP: + x-=newWidth/2; + break; + case PX_ALIGN_RIGHTTOP: + x-=newWidth; + break; + case PX_ALIGN_LEFTMID: + y-=newHeight/2; + break; + case PX_ALIGN_CENTER: + y-=newHeight/2; + x-=newWidth/2; + break; + case PX_ALIGN_RIGHTMID: + y-=newHeight/2; + x-=newWidth; + break; + case PX_ALIGN_LEFTBOTTOM: + y-=newHeight; + break; + case PX_ALIGN_MIDBOTTOM: + y-=newHeight; + x-=newWidth/2; + break; + case PX_ALIGN_RIGHTBOTTOM: + y-=newHeight; + x-=newWidth; + break; + } + + + if (x<-newWidth) + { + return; + } + if (x>psurface->width-1) + { + return; + } + if (y<-newHeight) + { + return; + } + if (y>psurface->height-1) + { + return; + } + + if (x<0) + { + left=-x; + } + else + { + left=0; + } + + if (newWidth>map_tex->width) + { + if (x+map_tex->width>psurface->width) + { + right=psurface->width-x-1; + } + else + { + right=map_tex->width-1; + } + } + else + { + if (x+newWidth>psurface->width) + { + right=psurface->width-x-1; + } + else + { + right=newWidth-1; + } + } + + + if (y<0) + { + top=-y; + } + else + { + top=0; + } + + if (newHeight>map_tex->height) + { + if (y+newHeight>psurface->height) + { + bottom=psurface->height-y-1; + } + else + { + bottom=newHeight-1; + } + } + else + { + if (y+newHeight>psurface->height) + { + bottom=psurface->height-y-1; + } + else + { + bottom=newHeight-1; + } + } + + ////////////////////////////////////////////////////////////////////////// + + + invCosAgl=PX_cos_angle(-Angle); + invSinAgl=PX_sin_angle(-Angle); + + if (blend) + { + px_int Ab=(px_int)(blend->alpha*1000); + px_int Rb=(px_int)(blend->hdr_R*1000); + px_int Gb=(px_int)(blend->hdr_G*1000); + px_int Bb=(px_int)(blend->hdr_B*1000); + + for (j=top;j<=bottom;j++) + { + for (i=left;i<=right;i++) + { + ref_x=i*1.0/newWidth-0.5; + ref_y=j*1.0/newHeight-0.5; + + mapX=(px_int)((ref_x*invCosAgl-ref_y*invSinAgl)*resWidth+resWidth/2); + mapY=(px_int)((ref_x*invSinAgl+ref_y*invCosAgl)*resHeight+resHeight/2); + + if (mapX<0||mapX>=resWidth) + { + continue; + } + + if (mapY<0||mapY>=resHeight) + { + continue; + } + + clr=pmapdata[j*map_tex->width+i]; + clr._argb.a=1*clr._argb.a*pmaskdata[j*mask_tex->width+i]._argb.a/255; + + bA=(px_int)(clr._argb.a*Ab/1000); + bR=(px_int)(clr._argb.r*Rb/1000); + bG=(px_int)(clr._argb.g*Gb/1000); + bB=(px_int)(clr._argb.b*Bb/1000); + + clr._argb.a=bA>255?255:(px_uchar)bA; + clr._argb.r=bR>255?255:(px_uchar)bR; + clr._argb.g=bG>255?255:(px_uchar)bG; + clr._argb.b=bB>255?255:(px_uchar)bB; + PX_SurfaceDrawPixel(psurface,x+i,y+j,clr); + } + + } + + } + else + { + for (j=top;j<=bottom;j++) + { + for (i=left;i<=right;i++) + { + ref_x=i*1.0/newWidth-0.5; + ref_y=j*1.0/newHeight-0.5; + + mapX=(px_int)((ref_x*invCosAgl-ref_y*invSinAgl)*resWidth+resWidth/2); + mapY=(px_int)((ref_x*invSinAgl+ref_y*invCosAgl)*resHeight+resHeight/2); + + if (mapX<0||mapX>=resWidth) + { + continue; + } + + if (mapY<0||mapY>=resHeight) + { + continue; + } + clr=pmapdata[j*map_tex->width+i]; + clr._argb.a=1*clr._argb.a*pmaskdata[j*mask_tex->width+i]._argb.a/255; + + PX_SurfaceDrawPixel(psurface,x+i,y+j,clr); + } + + } + } + +} + + + +px_void PX_TextureFill(px_memorypool *mp,px_texture *ptexture,px_int x,px_int y,px_color test_color,px_color fill_color) +{ + typedef struct + { + px_int x,y; + }__PX_POINT; + px_vector pstack; + PX_VectorInitialize(mp,&pstack,sizeof(__PX_POINT),8); + + do + { + __PX_POINT pt; + pt.x=x; + pt.y=y; + PX_VectorPushback(&pstack,&pt); + } while (0); + + while (pstack.size) + { + __PX_POINT retPt=*PX_VECTORLAST(__PX_POINT,&pstack); + PX_VectorPop(&pstack); + + x=retPt.x; + y=retPt.y; + + //xo mark + while (x>0&&(PX_SurfaceGetPixel(ptexture,x-1,y)._argb.ucolor==test_color._argb.ucolor)) + { + x--; + } + + //up + if (y>0) + { + if (PX_SurfaceGetPixel(ptexture,x,y-1)._argb.ucolor==test_color._argb.ucolor) + { + __PX_POINT pt; + pt.x=x; + pt.y=y-1; + PX_VectorPushback(&pstack,&pt); + } + } + + //down + if (yheight-1) + { + if (PX_SurfaceGetPixel(ptexture,x,y+1)._argb.ucolor==test_color._argb.ucolor) + { + __PX_POINT pt; + pt.x=x; + pt.y=y+1; + PX_VectorPushback(&pstack,&pt); + } + } + + PX_SurfaceSetPixel(ptexture,x,y,fill_color); + x++; + + //left top + while (xwidth) + { + if (PX_SurfaceGetPixel(ptexture,x,y)._argb.ucolor!=test_color._argb.ucolor) + { + break; + } + + PX_SurfaceSetPixel(ptexture,x,y,fill_color); + + if (x>0) + { + //up + if (y>0) + { + if (PX_SurfaceGetPixel(ptexture,x-1,y-1)._argb.ucolor!=test_color._argb.ucolor&&PX_SurfaceGetPixel(ptexture,x,y-1)._argb.ucolor==test_color._argb.ucolor) + { + __PX_POINT pt; + pt.x=x; + pt.y=y-1; + PX_VectorPushback(&pstack,&pt); + } + } + + //down + if (yheight-1) + { + if (PX_SurfaceGetPixel(ptexture,x-1,y+1)._argb.ucolor!=test_color._argb.ucolor&&PX_SurfaceGetPixel(ptexture,x,y+1)._argb.ucolor==test_color._argb.ucolor) + { + __PX_POINT pt; + pt.x=x; + pt.y=y+1; + PX_VectorPushback(&pstack,&pt); + } + } + + } + else + { + //up + if (y>0) + { + if (PX_SurfaceGetPixel(ptexture,x,y-1)._argb.ucolor==test_color._argb.ucolor) + { + __PX_POINT pt; + pt.x=x; + pt.y=y-1; + PX_VectorPushback(&pstack,&pt); + } + } + + //down + if (yheight-1) + { + if (PX_SurfaceGetPixel(ptexture,x,y+1)._argb.ucolor==test_color._argb.ucolor) + { + __PX_POINT pt; + pt.x=x; + pt.y=y+1; + PX_VectorPushback(&pstack,&pt); + } + } + + } + x++; + } + } + +} + +px_void PX_TextureRegionRender(px_surface *psurface,px_texture *resTexture,px_int x,px_int y,px_int oft_left,px_int oft_top,px_int oft_right,px_int oft_bottom,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend) +{ + px_int left,right,top,bottom,i,j; + px_int bR,bG,bB,bA; + px_color *pdata; + px_color clr; + px_int width=oft_right-oft_left+1; + px_int height=oft_bottom-oft_top+1; + + pdata=(px_color *)resTexture->surfaceBuffer; + + switch (refPoint) + { + case PX_ALIGN_LEFTTOP: + break; + case PX_ALIGN_MIDTOP: + x-=width/2; + break; + case PX_ALIGN_RIGHTTOP: + x-=width; + break; + case PX_ALIGN_LEFTMID: + y-=height/2; + break; + case PX_ALIGN_CENTER: + y-=height/2; + x-=width/2; + break; + case PX_ALIGN_RIGHTMID: + y-=height/2; + x-=width; + break; + case PX_ALIGN_LEFTBOTTOM: + y-=height; + break; + case PX_ALIGN_MIDBOTTOM: + y-=height; + x-=width/2; + break; + case PX_ALIGN_RIGHTBOTTOM: + y-=height; + x-=width; + break; + } + + + if (x<-width) + { + return; + } + if (x>psurface->width-1) + { + return; + } + if (y<-height) + { + return; + } + if (y>psurface->height-1) + { + return; + } + + if (x<0) + { + left=-x; + } + else + { + left=0; + } + + if (x+width>psurface->width) + { + right=psurface->width-x-1; + } + else + { + right=width-1; + } + + if (y<0) + { + top=-y; + } + else + { + top=0; + } + + if (y+height>psurface->height) + { + bottom=psurface->height-y-1; + } + else + { + bottom=height-1; + } + + + if (blend) + { + px_int Ab=(px_int)(blend->alpha*1000); + px_int Rb=(px_int)(blend->hdr_R*1000); + px_int Gb=(px_int)(blend->hdr_G*1000); + px_int Bb=(px_int)(blend->hdr_B*1000); + + for (j=top;j<=bottom;j++) + { + for (i=left;i<=right;i++) + { + clr=pdata[(j+oft_top)*resTexture->width+i+oft_left]; + bA=(px_int)(clr._argb.a*Ab/1000); + bR=(px_int)(clr._argb.r*Rb/1000); + bG=(px_int)(clr._argb.g*Gb/1000); + bB=(px_int)(clr._argb.b*Bb/1000); + + clr._argb.a=bA>255?255:(px_uchar)bA; + clr._argb.r=bR>255?255:(px_uchar)bR; + clr._argb.g=bG>255?255:(px_uchar)bG; + clr._argb.b=bB>255?255:(px_uchar)bB; + PX_SurfaceDrawPixel(psurface,x+i,y+j,clr); + } + } + } + else + { + for (j=top;j<=bottom;j++) + { + for (i=left;i<=right;i++) + { + clr=pdata[(j+oft_top)*resTexture->width+i+oft_left]; + PX_SurfaceDrawPixel(psurface,x+i,y+j,clr); + } + } + } +} +px_void PX_TextureRegionCopy(px_surface *psurface,px_texture *resTexture,px_int x,px_int y,px_int oft_left,px_int oft_top,px_int oft_right,px_int oft_bottom,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend) +{ + px_int left,right,top,bottom,i,j; + px_int bR,bG,bB,bA; + px_color *pdata; + px_color clr; + px_int width=oft_right-oft_left+1; + px_int height=oft_bottom-oft_top+1; + + pdata=(px_color *)resTexture->surfaceBuffer; + + switch (refPoint) + { + case PX_ALIGN_LEFTTOP: + break; + case PX_ALIGN_MIDTOP: + x-=width/2; + break; + case PX_ALIGN_RIGHTTOP: + x-=width; + break; + case PX_ALIGN_LEFTMID: + y-=height/2; + break; + case PX_ALIGN_CENTER: + y-=height/2; + x-=width/2; + break; + case PX_ALIGN_RIGHTMID: + y-=height/2; + x-=width; + break; + case PX_ALIGN_LEFTBOTTOM: + y-=height; + break; + case PX_ALIGN_MIDBOTTOM: + y-=height; + x-=width/2; + break; + case PX_ALIGN_RIGHTBOTTOM: + y-=height; + x-=width; + break; + } + + + if (x<-width) + { + return; + } + if (x>psurface->width-1) + { + return; + } + if (y<-height) + { + return; + } + if (y>psurface->height-1) + { + return; + } + + if (x<0) + { + left=-x; + } + else + { + left=0; + } + + if (x+width>psurface->width) + { + right=psurface->width-x-1; + } + else + { + right=width-1; + } + + if (y<0) + { + top=-y; + } + else + { + top=0; + } + + if (y+height>psurface->height) + { + bottom=psurface->height-y-1; + } + else + { + bottom=height-1; + } + + + if (blend) + { + px_int Ab=(px_int)(blend->alpha*1000); + px_int Rb=(px_int)(blend->hdr_R*1000); + px_int Gb=(px_int)(blend->hdr_G*1000); + px_int Bb=(px_int)(blend->hdr_B*1000); + + for (j=top;j<=bottom;j++) + { + for (i=left;i<=right;i++) + { + clr=pdata[(j+oft_top)*resTexture->width+i+oft_left]; + bA=(px_int)(clr._argb.a*Ab/1000); + bR=(px_int)(clr._argb.r*Rb/1000); + bG=(px_int)(clr._argb.g*Gb/1000); + bB=(px_int)(clr._argb.b*Bb/1000); + + clr._argb.a=bA>255?255:(px_uchar)bA; + clr._argb.r=bR>255?255:(px_uchar)bR; + clr._argb.g=bG>255?255:(px_uchar)bG; + clr._argb.b=bB>255?255:(px_uchar)bB; + PX_SurfaceSetPixel(psurface,x+i,y+j,clr); + } + } + } + else + { + for (j=top;j<=bottom;j++) + { + for (i=left;i<=right;i++) + { + clr=pdata[(j+oft_top)*resTexture->width+i+oft_left]; + PX_SurfaceSetPixel(psurface,x+i,y+j,clr); + } + } + } +} + +px_bool PX_ShapeCreate(px_memorypool *mp,px_shape *shape,px_int width,px_int height) +{ + px_void *p=MP_Malloc(mp,height*width*sizeof(px_uchar)); + if (p!=PX_NULL) + { + shape->height=height; + shape->width=width; + shape->alpha=(px_uchar *)p; + shape->MP=mp; + PX_memset(p,0,height*width); + return PX_TRUE; + } + return PX_FALSE; +} + + + +px_bool PX_ShapeCreateFromTexture(px_memorypool *mp,px_shape *shape,px_texture *texture) +{ + px_int x,y; + px_void *p=MP_Malloc(mp,texture->height*texture->width*sizeof(px_uchar)); + if (p!=PX_NULL) + { + shape->height=texture->height; + shape->width=texture->width; + shape->alpha=(px_uchar *)p; + shape->MP=mp; + PX_memdwordset(p,0,texture->height*texture->width); + + //Map texture to shape + for (y=0;yheight;y++) + { + for (x=0;xwidth;x++) + { + shape->alpha[y*shape->width+x]=((px_color *)texture->surfaceBuffer)[y*texture->width+x]._argb.a; + } + } + return PX_TRUE; + } + return PX_FALSE; +} + +px_void PX_ShapeFree(px_shape *shape) +{ + MP_Free(shape->MP,shape->alpha); +} + +px_void PX_ShapeRender(px_surface *psurface,px_shape *shape,px_int x,px_int y,PX_ALIGN refPoint,px_color blendColor) +{ + px_int left,right,top,bottom,i,j; + px_uchar *pdata; + px_color clr; + + pdata=(px_uchar *)shape->alpha; + + switch (refPoint) + { + case PX_ALIGN_LEFTTOP: + break; + case PX_ALIGN_MIDTOP: + x-=shape->width/2; + break; + case PX_ALIGN_RIGHTTOP: + x-=shape->width; + break; + case PX_ALIGN_LEFTMID: + y-=shape->height/2; + break; + case PX_ALIGN_CENTER: + y-=shape->height/2; + x-=shape->width/2; + break; + case PX_ALIGN_RIGHTMID: + y-=shape->height/2; + x-=shape->width; + break; + case PX_ALIGN_LEFTBOTTOM: + y-=shape->height; + break; + case PX_ALIGN_MIDBOTTOM: + y-=shape->height; + x-=shape->width/2; + break; + case PX_ALIGN_RIGHTBOTTOM: + y-=shape->height; + x-=shape->width; + break; + } + + + if (x<-shape->width) + { + return; + } + if (x>psurface->width-1) + { + return; + } + if (y<-shape->height) + { + return; + } + if (y>psurface->height-1) + { + return; + } + + if (x<0) + { + left=-x; + } + else + { + left=0; + } + + if (x+shape->width>psurface->width) + { + right=psurface->width-x-1; + } + else + { + right=shape->width-1; + } + + if (y<0) + { + top=-y; + } + else + { + top=0; + } + + if (y+shape->height>psurface->height) + { + bottom=psurface->height-y-1; + } + else + { + bottom=shape->height-1; + } + + for (j=top;j<=bottom;j++) + { + for (i=left;i<=right;i++) + { + if (pdata[j*shape->width+i]!=0) + { + clr=blendColor; + clr._argb.a=1*clr._argb.a*pdata[j*shape->width+i]/255; + PX_SurfaceDrawPixel(psurface,x+i,y+j,clr); + } + + } + } + +} + + + +px_void PX_ShapeRenderEx(px_surface *psurface,px_shape *shape,px_int x,px_int y,PX_ALIGN refPoint,px_color blendColor,px_float scale,px_float Angle) +{ + px_int newWidth,newHeight; + + px_int i,j,resHeight,resWidth; + + px_float invCosAgl,invSinAgl; + + px_double ref_x,ref_y; + px_int mapX,mapY; + + px_color clr; + + ////////////////////////////////////////////////////////////////////////// + px_int left,right,top,bottom; + + + ////////////////////////////////////////////////////////////////////////// + + resHeight=shape->height; + resWidth=shape->width; + + newHeight=PX_TRUNC(resHeight*scale); + newWidth=PX_TRUNC(resWidth*scale); + + ////////////////////////////////////////////////////////////////////////// + switch (refPoint) + { + case PX_ALIGN_LEFTTOP: + break; + case PX_ALIGN_MIDTOP: + x-=newWidth/2; + break; + case PX_ALIGN_RIGHTTOP: + x-=newWidth; + break; + case PX_ALIGN_LEFTMID: + y-=newHeight/2; + break; + case PX_ALIGN_CENTER: + y-=newHeight/2; + x-=newWidth/2; + break; + case PX_ALIGN_RIGHTMID: + y-=newHeight/2; + x-=newWidth; + break; + case PX_ALIGN_LEFTBOTTOM: + y-=newHeight; + break; + case PX_ALIGN_MIDBOTTOM: + y-=newHeight; + x-=newWidth/2; + break; + case PX_ALIGN_RIGHTBOTTOM: + y-=newHeight; + x-=newWidth; + break; + } + + + if (x<-newWidth) + { + return; + } + if (x>psurface->width-1) + { + return; + } + if (y<-newHeight) + { + return; + } + if (y>psurface->height-1) + { + return; + } + + if (x<0) + { + left=-x; + } + else + { + left=0; + } + + if (x+newWidth>psurface->width) + { + right=psurface->width-x-1; + } + else + { + right=newWidth-1; + } + + if (y<0) + { + top=-y; + } + else + { + top=0; + } + + if (y+newHeight>psurface->height) + { + bottom=psurface->height-y-1; + } + else + { + bottom=newHeight-1; + } + ////////////////////////////////////////////////////////////////////////// + + + + invCosAgl=PX_cos_angle(-Angle); + invSinAgl=PX_sin_angle(-Angle); + + for (j=top;j<=bottom;j++) + { + for (i=left;i<=right;i++) + { + ref_x=i*1.0/newWidth-0.5; + ref_y=j*1.0/newHeight-0.5; + + mapX=(px_int)((ref_x*invCosAgl-ref_y*invSinAgl)*resWidth+resWidth/2); + mapY=(px_int)((ref_x*invSinAgl+ref_y*invCosAgl)*resHeight+resHeight/2); + + if (mapX<0||mapX>=resWidth) + { + continue; + } + + if (mapY<0||mapY>=resHeight) + { + continue; + } + clr=blendColor; + clr._argb.a=1*clr._argb.a*shape->alpha[mapY*shape->width+mapX]/255; + PX_SurfaceDrawPixel(psurface,x+i,y+j,clr); + } + + } + +} + +px_bool PX_ShapeCreateFromMemory(px_memorypool *mp,px_void *data,px_int size,px_shape *shape) +{ + px_int width; + px_int height; + if (PX_BitmapVerify(data,size)) + { + return PX_FALSE; + } + + if (PX_TRawVerify(data,size)) + { + width=PX_TRawGetWidth(data); + height=PX_TRawGetHeight(data); + if(PX_ShapeCreate(mp,shape,width,height)) + { + px_int i,j; + px_color *pdataColor=(px_color *)((px_char *)data+sizeof(PX_TRaw_Header)); + + for (i=0;ialpha[width*i+j]=pdataColor[width*i+j]._argb.a; + } + } + } + else + { + return PX_FALSE; + } + } + + return PX_TRUE; +} + +px_void PX_ShapeRenderEx_sincos(px_surface *psurface,px_shape *shape,px_int x,px_int y,PX_ALIGN refPoint,px_color blendColor,px_float scale,px_float sinx,px_float cosx) +{ + px_int newWidth,newHeight; + + px_int i,j,resHeight,resWidth; + + px_float invCosAgl,invSinAgl; + + px_double ref_x,ref_y; + px_int mapX,mapY; + + px_color clr; + + ////////////////////////////////////////////////////////////////////////// + px_int left,right,top,bottom; + + + ////////////////////////////////////////////////////////////////////////// + + resHeight=shape->height; + resWidth=shape->width; + + newHeight=PX_TRUNC(resHeight*scale); + newWidth=PX_TRUNC(resWidth*scale); + + ////////////////////////////////////////////////////////////////////////// + switch (refPoint) + { + case PX_ALIGN_LEFTTOP: + break; + case PX_ALIGN_MIDTOP: + x-=newWidth/2; + break; + case PX_ALIGN_RIGHTTOP: + x-=newWidth; + break; + case PX_ALIGN_LEFTMID: + y-=newHeight/2; + break; + case PX_ALIGN_CENTER: + y-=newHeight/2; + x-=newWidth/2; + break; + case PX_ALIGN_RIGHTMID: + y-=newHeight/2; + x-=newWidth; + break; + case PX_ALIGN_LEFTBOTTOM: + y-=newHeight; + break; + case PX_ALIGN_MIDBOTTOM: + y-=newHeight; + x-=newWidth/2; + break; + case PX_ALIGN_RIGHTBOTTOM: + y-=newHeight; + x-=newWidth; + break; + } + + + if (x<-newWidth) + { + return; + } + if (x>psurface->width-1) + { + return; + } + if (y<-newHeight) + { + return; + } + if (y>psurface->height-1) + { + return; + } + + if (x<0) + { + left=-x; + } + else + { + left=0; + } + + if (x+newWidth>psurface->width) + { + right=psurface->width-x-1; + } + else + { + right=newWidth-1; + } + + if (y<0) + { + top=-y; + } + else + { + top=0; + } + + if (y+newHeight>psurface->height) + { + bottom=psurface->height-y-1; + } + else + { + bottom=newHeight-1; + } + ////////////////////////////////////////////////////////////////////////// + + + + invCosAgl=cosx; + invSinAgl=sinx; + + for (j=top;j<=bottom;j++) + { + for (i=left;i<=right;i++) + { + ref_x=i*1.0/newWidth-0.5; + ref_y=j*1.0/newHeight-0.5; + + mapX=(px_int)((ref_x*invCosAgl-ref_y*invSinAgl)*resWidth+resWidth/2); + mapY=(px_int)((ref_x*invSinAgl+ref_y*invCosAgl)*resHeight+resHeight/2); + + if (mapX<0||mapX>=resWidth) + { + continue; + } + + if (mapY<0||mapY>=resHeight) + { + continue; + } + clr=blendColor; + clr._argb.a=1*clr._argb.a*shape->alpha[shape->width*mapY+mapX]/255; + PX_SurfaceDrawPixel(psurface,x+i,y+j,clr); + } + + } +} + +px_void PX_ShapeRenderEx_vector(px_surface *psurface,px_shape *shape,px_int x,px_int y,PX_ALIGN refPoint,px_color blendColor,px_float scale,px_point p_vector) +{ + PX_ShapeRenderEx_sincos(psurface,shape,x,y,refPoint,blendColor,scale,PX_Point_sin(p_vector),PX_Point_cos(p_vector)); +} + +px_void PX_TextureRenderEx_sincos(px_surface *psurface,px_texture *resTexture,px_int x,px_int y,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend,px_float scale,px_float sinx,px_float cosx) +{ + px_int newWidth,newHeight; + + px_int i,j,resHeight,resWidth; + + px_float invCosAgl,invSinAgl; + + px_double ref_x,ref_y; + px_int mapX,mapY; + + px_color clr; + px_int bA,bR,bG,bB; + + ////////////////////////////////////////////////////////////////////////// + px_int left,right,top,bottom; + + + ////////////////////////////////////////////////////////////////////////// + + resHeight=resTexture->height; + resWidth=resTexture->width; + + newHeight=PX_TRUNC(resHeight*scale); + newWidth=PX_TRUNC(resWidth*scale); + + ////////////////////////////////////////////////////////////////////////// + switch (refPoint) + { + case PX_ALIGN_LEFTTOP: + break; + case PX_ALIGN_MIDTOP: + x-=newWidth/2; + break; + case PX_ALIGN_RIGHTTOP: + x-=newWidth; + break; + case PX_ALIGN_LEFTMID: + y-=newHeight/2; + break; + case PX_ALIGN_CENTER: + y-=newHeight/2; + x-=newWidth/2; + break; + case PX_ALIGN_RIGHTMID: + y-=newHeight/2; + x-=newWidth; + break; + case PX_ALIGN_LEFTBOTTOM: + y-=newHeight; + break; + case PX_ALIGN_MIDBOTTOM: + y-=newHeight; + x-=newWidth/2; + break; + case PX_ALIGN_RIGHTBOTTOM: + y-=newHeight; + x-=newWidth; + break; + } + + + if (x<-newWidth) + { + return; + } + if (x>psurface->width-1) + { + return; + } + if (y<-newHeight) + { + return; + } + if (y>psurface->height-1) + { + return; + } + + if (x<0) + { + left=-x; + } + else + { + left=0; + } + + if (x+newWidth>psurface->width) + { + right=psurface->width-x-1; + } + else + { + right=newWidth-1; + } + + if (y<0) + { + top=-y; + } + else + { + top=0; + } + + if (y+newHeight>psurface->height) + { + bottom=psurface->height-y-1; + } + else + { + bottom=newHeight-1; + } + ////////////////////////////////////////////////////////////////////////// + + + + invCosAgl=cosx; + invSinAgl=-sinx; + + if (blend) + { + px_int Ab=(px_int)(blend->alpha*1000); + px_int Rb=(px_int)(blend->hdr_R*1000); + px_int Gb=(px_int)(blend->hdr_G*1000); + px_int Bb=(px_int)(blend->hdr_B*1000); + + for (j=top;j<=bottom;j++) + { + for (i=left;i<=right;i++) + { + ref_x=i*1.0/newWidth-0.5; + ref_y=j*1.0/newHeight-0.5; + + mapX=(px_int)((ref_x*invCosAgl-ref_y*invSinAgl)*resWidth+resWidth/2); + mapY=(px_int)((ref_x*invSinAgl+ref_y*invCosAgl)*resHeight+resHeight/2); + + if (mapX<0||mapX>=resWidth) + { + continue; + } + + if (mapY<0||mapY>=resHeight) + { + continue; + } + + clr=PX_SURFACECOLOR(resTexture,mapX,mapY); + bA=(px_int)(clr._argb.a*Ab/1000); + bR=(px_int)(clr._argb.r*Rb/1000); + bG=(px_int)(clr._argb.g*Gb/1000); + bB=(px_int)(clr._argb.b*Bb/1000); + + clr._argb.a=bA>255?255:(px_uchar)bA; + clr._argb.r=bR>255?255:(px_uchar)bR; + clr._argb.g=bG>255?255:(px_uchar)bG; + clr._argb.b=bB>255?255:(px_uchar)bB; + PX_SurfaceDrawPixel(psurface,x+i,y+j,clr); + } + + } + + } + else + { + for (j=top;j<=bottom;j++) + { + for (i=left;i<=right;i++) + { + ref_x=i*1.0/newWidth-0.5; + ref_y=j*1.0/newHeight-0.5; + + mapX=(px_int)((ref_x*invCosAgl-ref_y*invSinAgl)*resWidth+resWidth/2); + mapY=(px_int)((ref_x*invSinAgl+ref_y*invCosAgl)*resHeight+resHeight/2); + + if (mapX<0||mapX>=resWidth) + { + continue; + } + + if (mapY<0||mapY>=resHeight) + { + continue; + } + + PX_SurfaceDrawPixel(psurface,x+i,y+j,PX_SURFACECOLOR(resTexture,mapX,mapY)); + } + + } + } +} + + +px_void PX_TextureRenderEx_vector(px_surface *psurface,px_texture *resTexture,px_int x,px_int y,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend,px_float scale,px_point p_vector) +{ + PX_TextureRenderEx_sincos(psurface,resTexture,x,y,refPoint,blend,scale,PX_Point_sin(p_vector),PX_Point_cos(p_vector)); +} + + + +px_bool PX_TextureCopy(px_memorypool *mp,px_texture *restexture,px_texture *dest) +{ + if(!PX_TextureCreate(mp,dest,restexture->width,restexture->height)) return PX_FALSE; + PX_memcpy(dest->surfaceBuffer,restexture->surfaceBuffer,restexture->width*restexture->height*sizeof(px_color)); + return PX_TRUE; +} + diff --git a/lib/PainterEngine/core/PX_Texture.h b/lib/PainterEngine/core/PX_Texture.h new file mode 100644 index 0000000000000000000000000000000000000000..cc0b5d56387580fb9e6323d506201c52ff148eaa --- /dev/null +++ b/lib/PainterEngine/core/PX_Texture.h @@ -0,0 +1,69 @@ +#ifndef __PX_TEXTURE_H +#define __PX_TEXTURE_H + +#include "PX_Vector.h" +#include "PX_Surface.h" +#include "PX_Bitmap.h" +#include "PX_TRaw.h" + +typedef px_surface px_texture; + + +typedef struct +{ + float hdr_R; + float hdr_G; + float hdr_B; + float alpha; +}PX_TEXTURERENDER_BLEND; + +typedef struct +{ + px_uchar *alpha; + px_int height; + px_int width; + px_memorypool *MP; +}px_shape; + + +px_bool PX_TextureCreate(px_memorypool *mp,px_texture *tex,px_int width,px_int height); +px_bool PX_TextureCreateFromMemory(px_memorypool *mp,px_void *data,px_int size,px_texture *tex); +px_bool PX_TextureCopy(px_memorypool *mp,px_texture *restexture,px_texture *dest); +px_bool PX_TextureCreateScale(px_memorypool *mp,px_texture *resTexture,px_int newWidth,px_int newHeight,px_texture *out); +px_void PX_TextureRender(px_surface *psurface,px_texture *tex,px_int x,px_int y,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend); +px_void PX_TextureCover(px_surface *psurface,px_texture *tex,px_int x,px_int y,PX_ALIGN refPoint); +px_void PX_TextureGetVisibleRange(px_texture *ptexture,px_int *pLeft,px_int *pRight,px_int *pTop,px_int *pBottom); +typedef px_void (*PX_TexturePixelShader)(px_surface *psurface,px_int x,px_int y,px_color clr,px_void *ptr); +px_void PX_TextureRenderPixelShader(px_surface *psurface,px_texture *tex,px_int x,px_int y,PX_ALIGN refPoint,PX_TexturePixelShader shader,px_void *ptr); +px_void PX_TextureRenderRotation(px_surface *psurface,px_texture *tex,px_int x,px_int y,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend,px_int Angle); +px_void PX_TextureRenderRotation_vector(px_surface *psurface,px_texture *tex,px_int x,px_int y,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend,px_point p_vector); +px_void PX_TextureRenderRotation_sincos(px_surface *psurface,px_texture *tex,px_int x,px_int y,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend,px_float sin,px_float cos); + +px_void PX_TextureRenderEx(px_surface *psurface,px_texture *resTexture,px_int x,px_int y,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend,px_float scale,px_float Angle); +px_void PX_TextureRenderEx_sincos(px_surface *psurface,px_texture *resTexture,px_int x,px_int y,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend,px_float scale,px_float sin,px_float cos); +px_void PX_TextureRenderEx_vector(px_surface *psurface,px_texture *resTexture,px_int x,px_int y,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend,px_float scale,px_point p_vector); +px_void PX_TextureRenderMask(px_surface *psurface,px_texture *mask_tex,px_texture *map_tex,px_int x,px_int y,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend); +px_void PX_TextureRenderMaskEx(px_surface *psurface,px_texture *mask_tex,px_texture *map_tex,px_int x,px_int y,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend,px_float scale,px_float Angle); +px_void PX_TextureFill(px_memorypool *mp,px_texture *ptexture,px_int x,px_int y,px_color test_color,px_color fill_color); +px_void PX_TextureRegionRender(px_surface *psurface,px_texture *resTexture,px_int x,px_int y,px_int left,px_int top,px_int right,px_int bottom,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend); +px_void PX_TextureRegionCopy(px_surface *psurface,px_texture *resTexture,px_int x,px_int y,px_int oft_left,px_int oft_top,px_int oft_right,px_int oft_bottom,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend); +px_void PX_SurfaceRender(px_surface *pdestSurface,px_surface *pResSurface,px_int x,px_int y,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend); +px_void PX_SurfaceCover(px_surface *pdestSurface,px_surface *pResSurface,px_int x,px_int y,PX_ALIGN refPoint); +px_void PX_SurfaceSetRect(px_surface *psurface, px_int left, px_int top, px_int right, px_int bottom,px_color color); +px_bool PX_TextureCreateRotationAngle(px_memorypool *mp,px_texture *resTexture,px_float Angle,px_texture *out); +px_bool PX_TextureRotationAngleToTexture(px_texture *resTexture,px_float Angle,px_texture *out); +px_bool PX_TextureCreateRotationRadian(px_memorypool *mp,px_texture *resTexture,px_float Angle,px_texture *out); +px_void PX_TextureFree(px_texture *tex); + +px_bool PX_ShapeCreate(px_memorypool *mp,px_shape *shape,px_int width,px_int height); +px_bool PX_ShapeCreateFromTexture(px_memorypool *mp,px_shape *shape,px_texture *texture); +px_bool PX_ShapeCreateFromMemory(px_memorypool *mp,px_void *data,px_int size,px_shape *shape); +px_void PX_ShapeRender(px_surface *psurface,px_shape *shape,px_int x,px_int y,PX_ALIGN refPoint,px_color blendColor); +px_void PX_ShapeRenderEx(px_surface *psurface,px_shape *shape,px_int x,px_int y,PX_ALIGN refPoint,px_color blendColor,px_float scale,px_float Angle); +px_void PX_ShapeRenderEx_sincos(px_surface *psurface,px_shape *shape,px_int x,px_int y,PX_ALIGN refPoint,px_color blendColor,px_float scale,px_float sinx,px_float cosx); +px_void PX_ShapeRenderEx_vector(px_surface *psurface,px_shape *shape,px_int x,px_int y,PX_ALIGN refPoint,px_color blendcolor,px_float scale,px_point p_vector); +px_void PX_ShapeFree(px_shape *shape); + + + +#endif diff --git a/lib/PainterEngine/core/PX_TriangleCross.c b/lib/PainterEngine/core/PX_TriangleCross.c new file mode 100644 index 0000000000000000000000000000000000000000..a7d0014a3d790e290239297ea82c0412bb8c9cd2 --- /dev/null +++ b/lib/PainterEngine/core/PX_TriangleCross.c @@ -0,0 +1,453 @@ +#include "PX_Typedef.h" + + +static void px_triangle_copy_point( px_point2D* p, px_point f ) +{ + p->x = f.x; + p->y = f.y; +} + + +static px_float px_triangleget_vector4_det( px_point v1, px_point v2, px_point v3, px_point v4 ) +{ + px_float a[3][3]; + + a[0][0] = v1.x - v4.x; + a[1][0] = v2.x - v4.x; + a[2][0] = v3.x - v4.x; + + a[0][1] = v1.y - v4.y; + a[1][1] = v2.y - v4.y; + a[2][1] = v3.y - v4.y; + + a[0][2] = v1.z - v4.z; + a[1][2] = v2.z - v4.z; + a[2][2] = v3.z - v4.z; + + + return a[0][0] * a[1][1] * a[2][2] + + a[0][1] * a[1][2] * a[2][0] + + a[0][2] * a[1][0] * a[2][1] + - a[0][2] * a[1][1] * a[2][0] + - a[0][1] * a[1][0] * a[2][2] + - a[0][0] * a[1][2] * a[2][1]; +} + + +static px_double px_triangle_direction( px_point2D p1, px_point2D p2, px_point2D p ){ + return ( p.x - p1.x ) * ( p2.y - p1.y ) - ( p2.x - p1.x ) * ( p.y - p1.y ) ; +} + + +static px_int px_triangle_on_segment( px_point2D p1, px_point2D p2, px_point2D p ){ + px_double max = p1.x > p2.x ? p1.x : p2.x ; + px_double min = p1.x < p2.x ? p1.x : p2.x ; + px_double max1 = p1.y > p2.y ? p1.y : p2.y ; + px_double min1 = p1.y < p2.y ? p1.y : p2.y ; + if ( p.x >= min && p.x <= max && p.y >= min1 && p.y <= max1 ) + { + return 1; + } + else + { + return 0; + } +} + + +static px_int px_triangle_segments_intersert( px_point2D p1, px_point2D p2, px_point2D p3, px_point2D p4 ){ + px_double d1, d2, d3, d4; + d1 = px_triangle_direction( p3, p4, p1 ); + d2 = px_triangle_direction( p3, p4, p2 ); + d3 = px_triangle_direction( p1, p2, p3 ); + d4 = px_triangle_direction( p1, p2, p4 ); + if ( d1 * d2 < 0 && d3 * d4 < 0 ) + { + return 1; + } + else if ( d1 == 0 && px_triangle_on_segment( p3, p4, p1 ) == 1 ) + { + return 1; + } + else if ( d2 == 0 && px_triangle_on_segment( p3, p4, p2 ) == 1 ) + { + return 1; + } + else if ( d3 == 0 && px_triangle_on_segment( p1, p2, p3 ) == 1 ) + { + return 1; + } + else if ( d4 == 0 && px_triangle_on_segment( p1, p2, p4 ) == 1 ) + { + return 1; + } + return 0; +} + +static px_bool px_triangle_line_triangle_intersert_inSamePlane( px_triangle* tri, px_point f1, px_point f2 ) +{ + px_point2D p1, p2, p3, p4; + + px_triangle_copy_point( &p1, f1 ); + + px_triangle_copy_point( &p2, f2 ); + + px_triangle_copy_point( &p3, tri->Vertex_1 ); + + px_triangle_copy_point( &p4, tri->Vertex_2 ); + + if ( px_triangle_segments_intersert( p1, p2, p3, p4 ) ) + { + return PX_TRUE; + } + + px_triangle_copy_point( &p3, tri->Vertex_2 ); + + px_triangle_copy_point( &p4, tri->Vertex_3 ); + + if ( px_triangle_segments_intersert( p1, p2, p3, p4 ) ) + { + return PX_TRUE; + } + + px_triangle_copy_point( &p3, tri->Vertex_1 ); + + px_triangle_copy_point( &p4, tri->Vertex_3 ); + + if ( px_triangle_segments_intersert( p1, p2, p3, p4 ) ) + { + return PX_TRUE; + } + + return PX_FALSE; +} + + +static void px_triangle_get_central_point(px_point *centralPoint,px_triangle* tri) +{ + centralPoint->x=(tri->Vertex_1.x+tri->Vertex_2.x+tri->Vertex_3.x)/3; + + centralPoint->y=(tri->Vertex_1.y+tri->Vertex_2.y+tri->Vertex_3.y)/3; + + centralPoint->z=(tri->Vertex_1.z+tri->Vertex_2.z+tri->Vertex_3.z)/3; +} + + + +static px_point px_triangle_get_vector_diff( const px_point a, const px_point b ) +{ + px_point result; + + result.x = b.x - a.x ; + + result.y = b.y - a.y; + + result.z = b.z - a.z; + return result; +} + +static px_bool px_triangle_is_point_within_triangle( px_triangle* tri, px_point pt ) +{ + px_point v0=px_triangle_get_vector_diff( tri->Vertex_1, tri->Vertex_3 ); + px_point v1=px_triangle_get_vector_diff( tri->Vertex_1, tri->Vertex_2 ); + px_point v2=px_triangle_get_vector_diff( tri->Vertex_1, pt ); + + px_float dot00 = PX_PointDot( v0, v0 ) ; + px_float dot01 = PX_PointDot( v0, v1 ) ; + px_float dot02 = PX_PointDot( v0, v2 ) ; + px_float dot11 = PX_PointDot( v1, v1 ) ; + px_float dot12 = PX_PointDot( v1, v2 ) ; + px_float inverDeno = 1 / ( dot00* dot11 - dot01* dot01 ) ; + px_float u = ( dot11* dot02 - dot01* dot12 ) * inverDeno ; + px_float v; + if ( u < 0 || u > 1 ) // if u out of range, return directly + { + return PX_FALSE ; + } + v = ( dot00* dot12 - dot01* dot02 ) * inverDeno ; + if ( v < 0 || v > 1 ) // if v out of range, return directly + { + return PX_FALSE ; + } + return u + v <= 1 ; +} + + +static px_bool px_triangle_intersert_inSamePlane( px_triangle* tri1, px_triangle* tri2 ) +{ + if ( px_triangle_line_triangle_intersert_inSamePlane( tri2, tri1->Vertex_1, tri1->Vertex_2 ) ) + { + return PX_TRUE; + } + else if ( px_triangle_line_triangle_intersert_inSamePlane( tri2, tri1->Vertex_2, tri1->Vertex_3 ) ) + { + return PX_TRUE; + } + else if ( px_triangle_line_triangle_intersert_inSamePlane( tri2, tri1->Vertex_1, tri1->Vertex_3 ) ) + { + return PX_TRUE; + } + else + { + px_point centralPoint1,centralPoint2; + + px_triangle_get_central_point(¢ralPoint1,tri1); + + px_triangle_get_central_point(¢ralPoint2,tri2); + + if(px_triangle_is_point_within_triangle( tri2, centralPoint1 ) || px_triangle_is_point_within_triangle( tri1, centralPoint2 ) ) + { + return PX_TRUE; + } + + return PX_FALSE; + } +} + +px_bool PX_TriangleIsCross( px_triangle* tri1, px_triangle* tri2 ) +{ + px_float p1_tri2_vertex1 = px_triangleget_vector4_det( tri1->Vertex_1, tri1->Vertex_2, tri1->Vertex_3, tri2->Vertex_1 ); + + px_float p1_tri2_vertex2 = px_triangleget_vector4_det( tri1->Vertex_1, tri1->Vertex_2, tri1->Vertex_3, tri2->Vertex_2 ); + + px_float p1_tri2_vertex3 = px_triangleget_vector4_det( tri1->Vertex_1, tri1->Vertex_2, tri1->Vertex_3, tri2->Vertex_3 ); + + + px_float p2_tri1_vertex1; + + px_float p2_tri1_vertex2; + + px_float p2_tri1_vertex3; + + px_point tri1_a , tri1_b , tri1_c , tri2_a , tri2_b, tri2_c ; + + px_point m; + px_float im; + + + if ( p1_tri2_vertex1 > 0 && p1_tri2_vertex2 > 0 && p1_tri2_vertex3 > 0 ) + { + return PX_FALSE; + } + + if ( p1_tri2_vertex1 < 0 && p1_tri2_vertex2 < 0 && p1_tri2_vertex3 < 0 ) + { + return PX_FALSE; + } + + + if ( p1_tri2_vertex1 == 0 && p1_tri2_vertex2 == 0 && p1_tri2_vertex3 == 0 ) + { + if ( px_triangle_intersert_inSamePlane( tri1, tri2 ) ) + { + return PX_TRUE; + } + else + { + return PX_FALSE; + } + } + + + if ( p1_tri2_vertex1 == 0 && p1_tri2_vertex2 * p1_tri2_vertex3 > 0 ) + { + if ( px_triangle_is_point_within_triangle( tri1, tri2->Vertex_1 ) ) + { + return PX_TRUE; + } + else + { + return PX_FALSE; + } + } + else if ( p1_tri2_vertex2 == 0 && p1_tri2_vertex1 * p1_tri2_vertex3 > 0 ) + { + if ( px_triangle_is_point_within_triangle( tri1, tri2->Vertex_2 ) ) + { + return PX_TRUE; + } + else + { + return PX_FALSE; + } + } + else if ( p1_tri2_vertex3 == 0 && p1_tri2_vertex1 * p1_tri2_vertex2 > 0 ) + { + if ( px_triangle_is_point_within_triangle( tri1, tri2->Vertex_3 ) ) + { + return PX_TRUE; + } + else + { + return PX_FALSE; + } + } + + + + p2_tri1_vertex1 = px_triangleget_vector4_det( tri2->Vertex_1, tri2->Vertex_2, tri2->Vertex_3, tri1->Vertex_1 ); + + p2_tri1_vertex2 = px_triangleget_vector4_det( tri2->Vertex_1, tri2->Vertex_2, tri2->Vertex_3, tri1->Vertex_2 ); + + p2_tri1_vertex3 = px_triangleget_vector4_det( tri2->Vertex_1, tri2->Vertex_2, tri2->Vertex_3, tri1->Vertex_3 ); + + + if ( p2_tri1_vertex1 > 0 && p2_tri1_vertex2 > 0 && p2_tri1_vertex3 > 0 ) + { + return PX_FALSE; + } + + if ( p2_tri1_vertex1 < 0 && p2_tri1_vertex2 < 0 && p2_tri1_vertex3 < 0 ) + { + return PX_FALSE; + } + + + if ( p2_tri1_vertex1 == 0 && p2_tri1_vertex2 * p2_tri1_vertex3 > 0 ) + { + if ( px_triangle_is_point_within_triangle( tri2, tri1->Vertex_1 ) ) + { + return PX_TRUE; + } + else + { + return PX_FALSE; + } + } + + if ( p2_tri1_vertex2 == 0 && p2_tri1_vertex1 * p2_tri1_vertex3 > 0 ) + { + if ( px_triangle_is_point_within_triangle( tri2, tri1->Vertex_2 ) ) + { + return PX_TRUE; + } + else + { + return PX_FALSE; + } + } + + if ( p2_tri1_vertex3 == 0 && p2_tri1_vertex1 * p2_tri1_vertex2 > 0 ) + { + if ( px_triangle_is_point_within_triangle( tri2, tri1->Vertex_3 ) ) + { + return PX_TRUE; + } + else + { + return PX_FALSE; + } + } + + + + tri1_a = tri1->Vertex_1, tri1_b = tri1->Vertex_2, tri1_c = tri1->Vertex_3 + , tri2_a = tri2->Vertex_1, tri2_b = tri2->Vertex_2, tri2_c = tri2->Vertex_3; + + + if ( p2_tri1_vertex2 * p2_tri1_vertex3 >= 0 && p2_tri1_vertex1 != 0 ) + { + if ( p2_tri1_vertex1 < 0 ) + { + m = tri2_b; + tri2_b = tri2_c; + tri2_c = m; + + im = p1_tri2_vertex2; + p1_tri2_vertex2 = p1_tri2_vertex3; + p1_tri2_vertex3 = im; + } + } + else if ( p2_tri1_vertex1 * p2_tri1_vertex3 >= 0 && p2_tri1_vertex2 != 0 ) + { + m = tri1_a; + tri1_a = tri1_b; + tri1_b = tri1_c; + tri1_c = m; + + if ( p2_tri1_vertex2 < 0 ) + { + m = tri2_b; + tri2_b = tri2_c; + tri2_c = m; + + im = p1_tri2_vertex2; + p1_tri2_vertex2 = p1_tri2_vertex3; + p1_tri2_vertex3 = im; + } + } + else if ( p2_tri1_vertex1 * p2_tri1_vertex2 >= 0 && p2_tri1_vertex3 != 0 ) + { + m = tri1_a; + + tri1_a = tri1_c; + + tri1_c = tri1_b; + + tri1_b = m; + + if ( p2_tri1_vertex3 < 0 ) + { + m = tri2_b; + tri2_b = tri2_c; + tri2_c = m; + + im = p1_tri2_vertex2; + p1_tri2_vertex2 = p1_tri2_vertex3; + p1_tri2_vertex3 = im; + } + } + + if ( p1_tri2_vertex2 * p1_tri2_vertex3 >= 0 && p1_tri2_vertex1 != 0 ) + { + if ( p1_tri2_vertex1 < 0 ) + { + m = tri1_b; + tri1_b = tri1_c; + tri1_c = m; + } + } + else if ( p1_tri2_vertex1 * p1_tri2_vertex3 >= 0 && p1_tri2_vertex2 != 0 ) + { + m = tri2_a; + + tri2_a = tri2_b; + + tri2_b = tri2_c; + + tri2_c = m; + + if ( p1_tri2_vertex2 < 0 ) + { + m = tri1_b; + tri1_b = tri1_c; + tri1_c = m; + } + } + else if ( p1_tri2_vertex1 * p1_tri2_vertex2 >= 0 && p1_tri2_vertex3 != 0 ) + { + m = tri2_a; + + tri2_a = tri2_c; + + tri2_c = tri2_b; + + tri2_b = m; + + if ( p1_tri2_vertex3 < 0 ) + { + m = tri1_b; + tri1_b = tri1_c; + tri1_c = m; + } + } + + if ( px_triangleget_vector4_det( tri1_a, tri1_b, tri2_a, tri2_b ) <= 0 && px_triangleget_vector4_det( tri1_a, tri1_c, tri2_c, tri2_a ) <= 0 ) + { + return PX_TRUE; + } + else + { + return PX_TRUE; + } +} \ No newline at end of file diff --git a/lib/PainterEngine/core/PX_Tuning.c b/lib/PainterEngine/core/PX_Tuning.c new file mode 100644 index 0000000000000000000000000000000000000000..986e2dfe98199e972ce6c359818f1a698498daa1 --- /dev/null +++ b/lib/PainterEngine/core/PX_Tuning.c @@ -0,0 +1,713 @@ +#include "PX_Tuning.h" + + +px_void PX_TuningInitialize(px_memorypool *mp,PX_Tuning *tuning,px_int SampleRate,px_double pitchShift,px_double timeShift,px_double window[],px_double filter[],px_double fix[],PX_TUNING_WINDOW_SIZE windowsize) +{ + px_int i; + px_int N; + + switch (windowsize) + { + case PX_TUNING_WINDOW_SIZE_8: + N=8; + break; + case PX_TUNING_WINDOW_SIZE_128: + N=128; + break; + case PX_TUNING_WINDOW_SIZE_256: + N=256; + break; + case PX_TUNING_WINDOW_SIZE_512: + N=512; + break; + case PX_TUNING_WINDOW_SIZE_1024: + N=1024; + break; + case PX_TUNING_WINDOW_SIZE_2048: + N=2048; + break; + default: + PX_ASSERT(); + return; + } + + tuning->mp=mp; + tuning->pitchShift=pitchShift; + tuning->timeScale=timeShift; + tuning->N=N; + tuning->remainCount=0; + tuning->previousInterpolationOffset=0; + tuning->previousInterpolationValue=0; + tuning->spectrumInterpolationOffset=2; + tuning->spectrumInterpolationFactor=1/(pitchShift*timeShift); + tuning->interpolationFactor=pitchShift; + tuning->ZCR_Low=0; + tuning->ZCR_High=1; + tuning->amp_threshold=0; + tuning->SampleRate=SampleRate; + PX_memset(tuning->lastphase,0,sizeof(tuning->lastphase)); + PX_memset(tuning->previous_frame,0,sizeof(tuning->previous_frame)); + PX_memset(tuning->half_previous_out,0,sizeof(tuning->half_previous_out)); + PX_memset(tuning->remian,0,sizeof(tuning->remian)); + + if(filter) + { + PX_memcpy(tuning->filter,filter,sizeof(px_double)*N); + } + else + { + for (i=0;ifilter[i]=1; + } + } + + if(window) + { + PX_memcpy(tuning->window,window,sizeof(px_double)*N); + } + else + { + PX_WindowFunction_sinc(tuning->window,N); + } + + if(fix) + { + PX_memcpy(tuning->fix,fix,sizeof(px_double)*N); + } + else + { + PX_memset(tuning->fix,0,sizeof(px_double)*PX_TUNING_MAX_FRAME_SIZE); + } + + +} + +px_void PX_TuningSortSpectrum(PX_Tuning *tuning,px_complex AnalysisFrame[]) +{ + px_int i; + px_double amplitude=0,phase=0; + PX_FFT(AnalysisFrame,AnalysisFrame,tuning->N); + + //re,im to amplitude,phase + + //DC sort + if (AnalysisFrame[0].re>0) + { + AnalysisFrame[0].im=0; + } + else + { + AnalysisFrame[0].re=PX_ABS(AnalysisFrame[0].re); + AnalysisFrame[0].im=PX_PI; + } + + //others + for (i=1;iN;i++) + { + amplitude=PX_sqrtd(AnalysisFrame[i].re*AnalysisFrame[i].re+AnalysisFrame[i].im*AnalysisFrame[i].im); + phase=PX_atan2(AnalysisFrame[i].im,AnalysisFrame[i].re); + AnalysisFrame[i].re=amplitude; + AnalysisFrame[i].im=phase; + } + + if (AnalysisFrame[tuning->N/2].re>0) + { + AnalysisFrame[tuning->N/2].im=0; + } + else + { + AnalysisFrame[tuning->N/2].re=PX_ABS(AnalysisFrame[0].re); + AnalysisFrame[tuning->N/2].im=PX_PI; + } +} + + + +px_int PX_TuningFilter(PX_Tuning *tuning,_IN px_double frame_unit[],px_int Size,_OUT px_double out_unit[]) +{ + px_int oft=0,i=0,remainCount=0,outSize=0,resampleAllocSize=0; + px_double AmpAvg; + px_double ZCR; + px_int blockCount; + px_int blocksize; + px_complex *AnalysisFrame; + px_complex *Frame0; + px_complex *Frame1; + px_complex *Frame2; + + px_double *resampledFrame; + + blocksize=tuning->N/2; + AnalysisFrame=(px_complex *)MP_Malloc(tuning->mp,tuning->N*sizeof(px_complex)); + + Frame0=(px_complex *)MP_Malloc(tuning->mp,tuning->N*sizeof(px_complex)); + Frame1=(px_complex *)MP_Malloc(tuning->mp,tuning->N*sizeof(px_complex)); + Frame2=(px_complex *)MP_Malloc(tuning->mp,tuning->N*sizeof(px_complex)); + + if (tuning->pitchShift<1) + { + resampleAllocSize+=(px_int)(Size/tuning->pitchShift); + } + else + { + resampleAllocSize+=(Size); + } + + resampleAllocSize+=tuning->remainCount; + resampleAllocSize+=blocksize*3; + resampleAllocSize+=(px_int)((1-PX_FRAC(tuning->previousInterpolationOffset))/tuning->interpolationFactor); + resampleAllocSize+=1; + resampleAllocSize*=sizeof(px_double); + resampledFrame=(px_double *)MP_Malloc(tuning->mp,resampleAllocSize); + + //copy previous + PX_memcpy(resampledFrame+oft,tuning->previous_frame,sizeof(px_double)*blocksize*3); + oft+=blocksize*3; + + //copy remain + PX_memcpy(resampledFrame+oft,tuning->remian,sizeof(px_double)*tuning->remainCount); + oft+=tuning->remainCount; + + ZCR=PX_ZeroCrossingRate(frame_unit,Size); + AmpAvg=0; + for (i=0;iZCR_Low||ZCR>tuning->ZCR_High||AmpAvgamp_threshold) + { + for (i=0;ipreviousInterpolationOffset+=tuning->interpolationFactor; + + if (tuning->previousInterpolationOffset>Size) + { + tuning->previousInterpolationOffset-=tuning->interpolationFactor; + tuning->previousInterpolationOffset=tuning->previousInterpolationOffset-Size; + break; + } + + if (oft>PX_TUNING_MAX_EXECUTE_SIZE-1) + { + break; + } + + index=(px_int)tuning->previousInterpolationOffset; + + if (index) + { + d1=frame_unit[index-1]; + } + else + { + d1=tuning->previousInterpolationValue; + } + + d2=frame_unit[index]; + + fraction=tuning->previousInterpolationOffset-(px_int)tuning->previousInterpolationOffset; + + dm=d1+fraction*(d2-d1); + + resampledFrame[oft]=dm; + + oft++; + } + } + + + tuning->previousInterpolationValue=frame_unit[Size-1]; + + + //spectrum + blockCount=oft/blocksize; + remainCount=oft%blocksize; + + //save remain + PX_memcpy(tuning->remian,resampledFrame+oft-remainCount,remainCount*sizeof(px_double)); + tuning->remainCount=remainCount; + + while (PX_TRUE) + { + px_double d1=0,d2=0,dm,fraction=0; + px_int index; + px_double unitMaxAmp=0; + + if (tuning->spectrumInterpolationOffset>=blockCount-1) + { + PX_memcpy(tuning->previous_frame,resampledFrame+(blockCount-3)*blocksize,blocksize*3*sizeof(px_double)); + tuning->spectrumInterpolationOffset=tuning->spectrumInterpolationOffset+3-blockCount; + break; + } + + index=(px_int)tuning->spectrumInterpolationOffset; + + //frame0 + + for (i=0;iN;i++) + { + AnalysisFrame[i].re=*(resampledFrame+(index-2)*blocksize+i); + //apply window + AnalysisFrame[i].re*=tuning->window[i]; + AnalysisFrame[i].im=0; + } + + PX_TuningSortSpectrum(tuning,AnalysisFrame); + PX_memcpy(Frame0,AnalysisFrame,tuning->N*sizeof(px_complex)); + + //frame1 + + for (i=0;iN;i++) + { + AnalysisFrame[i].re=*(resampledFrame+(index-1)*blocksize+i); + //apply window + AnalysisFrame[i].re*=tuning->window[i]; + AnalysisFrame[i].im=0; + } + + PX_TuningSortSpectrum(tuning,AnalysisFrame); + PX_memcpy(Frame1,AnalysisFrame,tuning->N*sizeof(px_complex)); + + //frame2 + for (i=0;iN;i++) + { + AnalysisFrame[i].re=*(resampledFrame+(index)*blocksize+i); + //apply window + AnalysisFrame[i].re*=tuning->window[i]; + AnalysisFrame[i].im=0; + } + + PX_TuningSortSpectrum(tuning,AnalysisFrame); + PX_memcpy(Frame2,AnalysisFrame,tuning->N*sizeof(px_complex)); + + + //instantaneous frequency + for (i=0;i<=tuning->N/2;i++) + { + Frame2[i].im-=Frame1[i].im; + if (Frame2[i].im>PX_PI) + { + Frame2[i].im-=PX_PI*2; + } + else if(Frame2[i].im<-PX_PI) + { + Frame2[i].im+=PX_PI*2; + } + + Frame1[i].im-=Frame0[i].im; + + if (Frame1[i].im>PX_PI) + { + Frame1[i].im-=PX_PI*2; + } + else if(Frame1[i].im<-PX_PI) + { + Frame1[i].im+=PX_PI*2; + } + } + + fraction=tuning->spectrumInterpolationOffset-(px_int)tuning->spectrumInterpolationOffset; + + for (i=0;i<=tuning->N/2;i++) + { + px_double distance; + + //amplitude + d1=Frame1[i].re; + d2=Frame2[i].re; + dm=d1+fraction*(d2-d1); + AnalysisFrame[i].re=dm; + + //phase + d1=Frame1[i].im; + d2=Frame2[i].im; + + distance=d2-d1; + + if (distance<-PX_PI) + { + d2+=PX_PI*2; + } + else if (distance>PX_PI) + { + d2-=PX_PI*2; + } + + + dm=d1+fraction*(d2-d1); + dm=tuning->lastphase[i]+dm; + + if (dm>PX_PI) + { + dm-=PX_PI*2; + } + else if(dm<-PX_PI) + { + dm+=PX_PI*2; + } + + + //rebuild signal + AnalysisFrame[i].im=dm; + + //update last phase + tuning->lastphase[i]=dm; + } + + AmpAvg=0; + + for (i=0;i<=tuning->N/2;i++) + { + AmpAvg+=AnalysisFrame[i].re; + } + + AmpAvg/=(tuning->N/2+1); + + + + + //filter & fix + for (i=0;i<=tuning->N/2;i++) + { + px_double amp,phase; + amp=AnalysisFrame[i].re; + phase=AnalysisFrame[i].im; + + //filter + amp*=tuning->filter[i]; + amp+=(tuning->fix[i]*AmpAvg); + + + if (amp<0) + { + amp=0; + } + + //amp,phase->re,im + AnalysisFrame[i].re=amp*PX_cosd(phase); + AnalysisFrame[i].im=amp*PX_sind(phase); + } + + + AnalysisFrame[0].im=0; + AnalysisFrame[tuning->N/2].im=0; + PX_FT_Symmetry(AnalysisFrame,AnalysisFrame,tuning->N); + PX_IFFT(AnalysisFrame,AnalysisFrame,tuning->N); + + for (i=0;iwindow[i]+tuning->half_previous_out[i]*tuning->window[i+blocksize]; + outSize++; + tuning->half_previous_out[i]=AnalysisFrame[i+tuning->N/2].re; + } + + tuning->spectrumInterpolationOffset+=tuning->spectrumInterpolationFactor; + } + + MP_Free(tuning->mp,Frame0); + MP_Free(tuning->mp,resampledFrame); + MP_Free(tuning->mp,Frame1); + MP_Free(tuning->mp,Frame2); + MP_Free(tuning->mp,AnalysisFrame); + return outSize; +} + +px_void PX_TuningTimeScale(px_double timescale,px_double in[],px_int count,px_memory *out) +{ + px_int i,index,blockcount,blocksize; + px_double d1,d2,dm,fraction; + px_double amplitude,phase,lastphase[PX_TUNING_DEFAULT_FRAME_SIZE]; + px_double lastwindow[PX_TUNING_DEFAULT_FRAME_SIZE/2]; + px_complex Frame0[PX_TUNING_DEFAULT_FRAME_SIZE]; + px_complex Frame1[PX_TUNING_DEFAULT_FRAME_SIZE]; + px_complex Frame2[PX_TUNING_DEFAULT_FRAME_SIZE]; + px_complex AnalysisFrame[PX_TUNING_DEFAULT_FRAME_SIZE]; + px_double window[PX_TUNING_DEFAULT_FRAME_SIZE]; + px_double step=0; + px_double offset=0;; + + PX_memset(lastphase,0,sizeof(lastphase)); + PX_memset(lastwindow,0,sizeof(lastwindow)); + PX_memset(Frame0,0,sizeof(Frame0)); + PX_memset(Frame1,0,sizeof(Frame1)); + PX_memset(Frame2,0,sizeof(Frame2)); + PX_memset(AnalysisFrame,0,sizeof(AnalysisFrame)); + + PX_WindowFunction_sinc(window,PX_TUNING_DEFAULT_FRAME_SIZE); + + + + step=1/timescale; + offset=2.0; + blocksize=PX_TUNING_DEFAULT_FRAME_SIZE/2; + blockcount=count/blocksize; + + while (PX_TRUE) + { + index=(px_int)offset; + if (index>=blockcount-1) + { + break; + } + + //Frame 0 + for (i=0;iamplitude phase + if (Frame0[0].re>=0) + { + Frame0[0].im=0; + } + else + { + Frame0[0].re=-Frame0[0].re; + Frame0[0].im=PX_PI; + } + + for (i=1;i=0) + { + Frame0[i].im=0; + } + else + { + Frame0[i].re=-Frame0[i].re; + Frame0[i].im=PX_PI; + } + + + + + Frame1[0].im=0; + if (Frame1[0].re>=0) + { + Frame1[0].im=0; + } + else + { + Frame1[0].re=-Frame1[0].re; + Frame1[0].im=PX_PI; + } + + for (i=1;i=0) + { + Frame1[i].im=0; + } + else + { + Frame1[i].re=-Frame1[i].re; + Frame1[i].im=PX_PI; + } + + + + Frame2[0].im=0; + if (Frame2[0].re>=0) + { + Frame2[0].im=0; + } + else + { + Frame2[0].re=-Frame2[0].re; + Frame2[0].im=PX_PI; + } + + for (i=1;i=0) + { + Frame2[i].im=0; + } + else + { + Frame2[i].re=-Frame2[i].re; + Frame2[i].im=PX_PI; + } + + //Instantaneous Frequency + for (i=0;i<=blocksize;i++) + { + Frame2[i].im-=Frame1[i].im; + if (Frame2[i].im<-PX_PI) + { + Frame2[i].im+=PX_PI*2; + } + else if (Frame2[i].im>PX_PI) + { + Frame2[i].im-=PX_PI*2; + } + + Frame1[i].im-=Frame0[i].im; + if (Frame1[i].im<-PX_PI) + { + Frame1[i].im+=PX_PI*2; + } + else if (Frame1[i].im>PX_PI) + { + Frame1[i].im-=PX_PI*2; + } + } + + fraction=PX_FRAC(offset); + + for (i=0;i<=blocksize;i++) + { + px_double distance; + px_double amp,phase; + + //amplitude + d1=Frame1[i].re; + d2=Frame2[i].re; + dm=d1+fraction*(d2-d1); + AnalysisFrame[i].re=dm; + + //phase + d1=Frame1[i].im; + d2=Frame2[i].im; + + distance=d2-d1; + + if (distance<-PX_PI) + { + d2+=PX_PI*2; + } + else if (distance>PX_PI) + { + d2-=PX_PI*2; + } + + + dm=d1+fraction*(d2-d1); + dm=lastphase[i]+dm; + + if (dm>PX_PI) + { + dm-=PX_PI*2; + } + else if(dm<-PX_PI) + { + dm+=PX_PI*2; + } + + + //rebuild signal + AnalysisFrame[i].im=dm; + + //update last phase + lastphase[i]=dm; + + amp=AnalysisFrame[i].re; + phase=AnalysisFrame[i].im; + + + //amplitude phase->real imaginary + AnalysisFrame[i].re=amp*PX_cosd(phase); + AnalysisFrame[i].im=amp*PX_sind(phase); + + } + AnalysisFrame[0].im=0; + AnalysisFrame[blocksize].im=0; + PX_FT_Symmetry(AnalysisFrame,AnalysisFrame,PX_TUNING_DEFAULT_FRAME_SIZE); + + PX_IFFT(AnalysisFrame,AnalysisFrame,PX_TUNING_DEFAULT_FRAME_SIZE); + + for (i=0;i=0.999999) + { + val=0.999999; + } + PX_MemoryCat(out,&val,sizeof(px_double)); + } + + offset+=step; + } + +} + +px_void PX_TuningSetPitchShift(PX_Tuning *tuning,px_double pitchShift) +{ + tuning->pitchShift=pitchShift; + tuning->spectrumInterpolationFactor=1/(pitchShift*tuning->timeScale); + tuning->interpolationFactor=pitchShift; +} + +px_void PX_TuningSetTimeScale(PX_Tuning *tuning,px_double TimeScale) +{ + tuning->timeScale=TimeScale; +} + +px_void PX_TuningSetFilter(PX_Tuning *tuning,px_double filter[]) +{ + PX_memcpy(tuning->filter,filter,sizeof(px_double)*tuning->N); +} + +px_void PX_TuningSetFix(PX_Tuning *tuning,px_double fix[]) +{ + PX_memcpy(tuning->fix,fix,sizeof(px_double)*tuning->N); +} + +px_void PX_TuningSetZCR(PX_Tuning *tuning,px_double low,px_double high) +{ + tuning->ZCR_Low=low; + tuning->ZCR_High=high; +} diff --git a/lib/PainterEngine/core/PX_Tuning.h b/lib/PainterEngine/core/PX_Tuning.h new file mode 100644 index 0000000000000000000000000000000000000000..59e68e8da212e37716990e3e9b8783aa554aa0b6 --- /dev/null +++ b/lib/PainterEngine/core/PX_Tuning.h @@ -0,0 +1,52 @@ +#ifndef PX_TUNING +#define PX_TUNING + +#include "../core/PX_Core.h" + +#define PX_TUNING_MAX_EXECUTE_SIZE 8192 +#define PX_TUNING_DEFAULT_FRAME_SIZE 1024 +#define PX_TUNING_MAX_FRAME_SIZE 2048 + + +typedef struct +{ + px_memorypool *mp; + px_double previous_frame[PX_TUNING_MAX_FRAME_SIZE/2*3]; + px_double half_previous_out[PX_TUNING_MAX_FRAME_SIZE/2]; + px_double filter[PX_TUNING_MAX_FRAME_SIZE]; + px_double window[PX_TUNING_MAX_FRAME_SIZE]; + px_double fix[PX_TUNING_MAX_FRAME_SIZE]; + px_double remian[PX_TUNING_MAX_EXECUTE_SIZE]; + px_int SampleRate; + px_int remainCount; + px_double pitchShift,timeScale; + px_double previousInterpolationValue; + px_double previousInterpolationOffset; + px_double spectrumInterpolationOffset; + px_double spectrumInterpolationFactor; + px_double interpolationFactor; + px_double ZCR_Low,ZCR_High; + px_double amp_threshold; + px_double lastphase[PX_TUNING_MAX_FRAME_SIZE]; + px_int N; +}PX_Tuning; + +typedef enum +{ + PX_TUNING_WINDOW_SIZE_8, + PX_TUNING_WINDOW_SIZE_128, + PX_TUNING_WINDOW_SIZE_256, + PX_TUNING_WINDOW_SIZE_512, + PX_TUNING_WINDOW_SIZE_1024, + PX_TUNING_WINDOW_SIZE_2048, +}PX_TUNING_WINDOW_SIZE; + +px_void PX_TuningInitialize(px_memorypool *mp,PX_Tuning *tuning,px_int SampleRate,px_double pitchShift,px_double timeShift,px_double window[],px_double filter[],px_double fix[],PX_TUNING_WINDOW_SIZE windowsize); +px_int PX_TuningFilter(PX_Tuning *tuning,_IN px_double frame_unit[],px_int Size,_OUT px_double out_unit[]); +px_void PX_TuningTimeScale(px_double timescale,px_double in[],px_int count,px_memory *out); +px_void PX_TuningSetPitchShift(PX_Tuning *tuning,px_double pitchShift); +px_void PX_TuningSetTimeScale(PX_Tuning *tuning,px_double TimeScale); +px_void PX_TuningSetFilter(PX_Tuning *tuning,px_double filter[]); +px_void PX_TuningSetFix(PX_Tuning *tuning,px_double fix[]); +px_void PX_TuningSetZCR(PX_Tuning *tuning,px_double low,px_double high); +#endif diff --git a/lib/PainterEngine/core/PX_Typedef.c b/lib/PainterEngine/core/PX_Typedef.c new file mode 100644 index 0000000000000000000000000000000000000000..f7ee1e35cd82d7393b73bdcb4869fa7c66834cfb --- /dev/null +++ b/lib/PainterEngine/core/PX_Typedef.c @@ -0,0 +1,4431 @@ +#include "PX_Typedef.h" + +static px_bool PX_isBigEndianCPU() +{ + union{ + px_dword i; + unsigned char s[4]; + }c; + c.i = 0x12345678; + return (0x12 == c.s[0]); + +} + +px_uint PX_htoi(const px_char hex_str[]) +{ + px_char ch; + px_uint iret=0; + while((ch=*hex_str++)!=0) + { + iret=(iret<<4)|px_hex_to_dex_table[ch]; + } + return iret; +} + + +px_int PX_atoi(const px_char s[]) +{ + px_int i,n,sign=1; + for(i=0;s[i]==' ';i++); + if(s[i]=='+'||s[i]=='-') + { + sign=(s[i]=='-')?-1:1; + i++; + } + for(n=0;s[i]>='0'&&s[i]<='9';i++) + n=10*n+(s[i]-'0'); + return sign *n; +} + + +px_float PX_atof(const px_char fstr[]) +{ + px_double temp=10; + px_bool ispnum=PX_TRUE; + px_double ans=0; + px_bool be=PX_FALSE; + if(*fstr=='-') + { + ispnum=PX_FALSE; + fstr++; + } + else if(*fstr=='+') + { + fstr++; + } + + while(*fstr!='\0') + { + if(*fstr=='.'){ fstr++;break;} + if(*fstr=='e'||*fstr=='E'){ fstr++;be=PX_TRUE;break;} + ans=ans*10+(*fstr-'0'); + fstr++; + } + if (be) + { + int e=PX_atoi(fstr); + float e10=1; + if (e>0) + { + while (e) + { + e10*=10; + e--; + } + } + else + { + while(e) + { + e10/=10; + e++; + } + } + ans*=e10; + } + else + { + while(*fstr!='\0') + { + ans=ans+(*fstr-'0')/temp; + temp*=10; + fstr++; + } + } + + if(ispnum) return (px_float)ans; + else return (px_float)ans*(-1); +} + + +PX_RETURN_STRING PX_ftos(px_float f, px_int precision) +{ + PX_RETURN_STRING str; + PX_ftoa(f,str.data,sizeof(str.data),precision); + return str; +} + + +PX_RETURN_STRING PX_itos(px_int num,px_int radix) +{ + PX_RETURN_STRING str; + PX_itoa(num,str.data,sizeof(str.data),radix); + return str; +} + + +px_void PX_AscToWord(const px_char *asc,px_word *u16) +{ + while(*asc) + { + *u16=*asc; + u16++; + asc++; + + } + *u16=0; +} + +px_int PX_ftoa(px_float f, char *outbuf, px_int maxlen, px_int precision) +{ + px_int i_value; + px_int f_value; + px_int shl=10; + px_int len; + px_int zero_oft=0; + if (maxlen==0) + { + return 0; + } + shl=PX_pow_ii(shl,precision); + i_value=(px_int)f; + f_value=(px_int)PX_ABS(shl*(f-(px_int)f)); + if (i_value==0&&f<0) + { + outbuf[0]='-'; + PX_itoa(i_value,outbuf+1,maxlen-1,10); + } + else + { + PX_itoa(i_value,outbuf,maxlen,10); + } + + len=PX_strlen(outbuf); + + if (precision==0) + { + return len; + } + + if (len>maxlen-3) + { + return len; + } + outbuf[len]='.'; + outbuf[len+1]='\0'; + + while (f_value> 8)&0x00FF00FF); + return (val << 16)|(val >> 16); +} + +px_dword PX_SwapEndian(px_dword val) +{ + val = ((val << 8)&0xFF00FF00) | ((val >> 8)&0x00FF00FF); + return (val << 16)|(val >> 16); +} + +static px_int64 PX_i64SwapEndian(px_int64 val) +{ + px_int32 u32_host_h, u32_host_l; + px_int64 u64_net; + u32_host_l = val & 0xffffffff; + u32_host_h = (val >> 32) & 0xffffffff; + + u64_net = PX_i32SwapEndian(u32_host_l); + u64_net = ( u64_net << 32 ) | PX_i32SwapEndian(u32_host_h); + return u64_net; +} + + + +px_float PX_sqrt( px_float number ) +{ + px_int32 i; + px_float x2, y; + const px_float threehalfs = 1.5F; + x2 = number * 0.5F; + y = number; + i = * ( px_int32 * ) &y; + + if (PX_isBigEndianCPU()) + { + i=PX_i32SwapEndian(i); + } + + i = 0x5f375a86 - ( i >> 1 ); + y = * ( px_float * ) &i; + y = y * ( threehalfs - ( x2 * y * y ) ); + y = y * ( threehalfs - ( x2 * y * y ) ); + y = y * ( threehalfs - ( x2 * y * y ) ); + y = y * ( threehalfs - ( x2 * y * y ) ); + y = y * ( threehalfs - ( x2 * y * y ) ); + y = y * ( threehalfs - ( x2 * y * y ) ); + return number*y; +} + +//0x5fe6ec85e7de30da + +px_double PX_sqrtd( px_double number ) +{ + px_int64 i; + px_double x2, y; + const px_double threehalfs = 1.5; + x2 = number * 0.5; + y = number; + i = * ( px_int64 * ) &y; + + if (PX_isBigEndianCPU()) + { + i=PX_i64SwapEndian(i); + } + + i = 0x5fe6ec85e7de30da - ( i / 2 ); + y = * ( px_double * ) &i; + y = y * ( threehalfs - ( x2 * y * y ) ); + y = y * ( threehalfs - ( x2 * y * y ) ); + y = y * ( threehalfs - ( x2 * y * y ) ); + y = y * ( threehalfs - ( x2 * y * y ) ); + y = y * ( threehalfs - ( x2 * y * y ) ); + y = y * ( threehalfs - ( x2 * y * y ) ); + y = y * ( threehalfs - ( x2 * y * y ) ); + y = y * ( threehalfs - ( x2 * y * y ) ); + return number*y; +} + +px_float PX_SqrtRec( px_float number ) +{ + px_int i; + px_float x2, y; + const px_float threehalfs = 1.5F; + + x2 = number * 0.5F; + y = number; + i = * ( px_int * ) &y; + if (PX_isBigEndianCPU()) + { + i=PX_i32SwapEndian(i); + } + i = 0x5f375a86 - ( i >> 1 ); + y = * ( px_float * ) &i; + y = y * ( threehalfs - ( x2 * y * y ) ); + y = y * ( threehalfs - ( x2 * y * y ) ); + y = y * ( threehalfs - ( x2 * y * y ) ); + return y; +} + +px_double PX_fast_exp(px_double x) { + x = 1.0 + x / (65536); + x *= x; x *= x; x *= x; x *= x; + x *= x; x *= x; x *= x; x *= x; + x *= x; x *= x; x *= x; x *= x; + x *= x; x *= x; x *= x; x *= x; + return x; +} + +px_double PX_exp(px_double x) +{ + return PX_pow_dd(PX_e,x); +} + +px_double PX_tanh(px_double x) +{ + px_double ex,eix; + ex=PX_exp(x); + eix=1/ex; + return (ex-eix)/(ex+eix); +} + + +px_double PX_sigmoid(px_double x) +{ + px_double eix; + eix=PX_exp(-x); + return 1/(1+eix); +} + +px_double PX_ReLU(px_double x) +{ + return x<=0?0:x; +} + +px_double PX_sind(px_double x) +{ + px_double it; + px_double term; + px_double result; + + it=x/(2*PX_PI); + x=x-(2*PX_PI)*PX_TRUNC(it); + + term=x; + result=0; + + result+=term; + term*=(-x*x)/(2*3); + result+=term; + term*=(-x*x)/(4*5); + result+=term; + term*=(-x*x)/(6*7); + result+=term; + term*=(-x*x)/(8*9); + result+=term; + term*=(-x*x)/(10*11); + result+=term; + term*=(-x*x)/(12*13); + result+=term; + term*=(-x*x)/(14*15); + result+=term; + term*=(-x*x)/(16*17); + result+=term; + term*=(-x*x)/(18*19); + result+=term; + term*=(-x*x)/(20*21); + result+=term; + term*=(-x*x)/(22*23); + result+=term; + term*=(-x*x)/(24*25); + result+=term; + term*=(-x*x)/(26*27); + result+=term; + term*=(-x*x)/(28*29); + result+=term; + term*=(-x*x)/(30*31); + result+=term; + term*=(-x*x)/(32*33); + return result; + +} + +px_double PX_cosd(px_double radian) +{ + return PX_sind((PX_PI/2-radian)); +} + +px_float PX_sin_radian(px_float radian) +{ + return (px_float)PX_sind(radian); +} + + +px_float PX_cos_radian(px_float radian) +{ + return PX_sin_radian((px_float)(PX_PI/2-radian)); +} + +px_float PX_tan_radian(px_float radian) +{ + return PX_sin_radian(radian)/PX_cos_radian(radian); +} + +px_float PX_sin_angle(px_float angle) +{ + angle-=((px_int)angle/360)*360; + return (px_float)PX_sin_radian((angle*0.0174532925f)); +} +px_float PX_cos_angle(px_float angle) +{ + angle-=((px_int)angle/360)*360; + return PX_cos_radian((angle*0.0174532925f)); +} + + +px_float PX_tan_angle(px_float angle) +{ + return PX_sin_angle(angle)/PX_cos_angle(angle); +} + +px_float PX_Point_sin(px_point v) +{ + return v.y/PX_sqrt(v.x*v.x+v.y*v.y); +} + + +px_float PX_Point_cos(px_point v) +{ + return v.x/PX_sqrt(v.x*v.x+v.y*v.y); +} + +px_void PX_BufferToHexString(px_byte data[],px_int size,px_char hex_str[]) +{ + px_int i; + hex_str[0]=0; + for (i=0;i0) + { + return PX_atan(y/x);; + } + else if (y >= 0 && x < 0) + { + return PX_atan(y/x) + PX_PI; + } + else if (y < 0 && x < 0) + { + return PX_atan(y/x) - PX_PI; + } + else if (y > 0 && x == 0) + { + return PX_PI / 2; + } + else if (y < 0 && x == 0) + { + return -1 * PX_PI / 2; + } + else + { + return 0; + } + +} + +px_double PX_asin(px_double x) +{ + return PX_atan2 (x, PX_sqrtd (1.0 - x * x)); +} + +px_double PX_acos(px_double x) +{ + return PX_atan2 (PX_sqrtd (1.0 - x * x), x); +} + +px_stringformat PX_STRINGFORMAT_INT(px_int _i) +{ + px_stringformat fmt; + fmt.type=PX_STRINGFORMAT_TYPE_INT; + fmt._int=_i; + return fmt; +} + + +px_stringformat PX_STRINGFORMAT_FLOAT(px_float _f) +{ + px_stringformat fmt; + fmt.type=PX_STRINGFORMAT_TYPE_FLOAT; + fmt._float=_f; + return fmt; +} + + +px_stringformat PX_STRINGFORMAT_STRING(const px_char *_s) +{ + px_stringformat fmt; + fmt.type=PX_STRINGFORMAT_TYPE_STRING; + fmt._pstring=_s; + return fmt; +} + + +px_int PX_sprintf8(px_char *_out_str,px_int str_size,const px_char fmt[], px_stringformat _1, px_stringformat _2, px_stringformat _3, px_stringformat _4,px_stringformat _5, px_stringformat _6, px_stringformat _7, px_stringformat _8) +{ + px_int length=0; + const px_char *p=PX_NULL; + PX_RETURN_STRING tret; + px_stringformat pstringfmt; + px_int precision=3; + + if (!_out_str||!str_size) + { + for (p = fmt;*p; p++) + { + if(*p != '%') { + length++; + continue; + } + switch(*(p+1)) + { + case '1': pstringfmt=_1; break; + case '2': pstringfmt=_2; break; + case '3': pstringfmt=_3; break; + case '4': pstringfmt=_4; break; + case '5': pstringfmt=_5; break; + case '6': pstringfmt=_6; break; + case '7': pstringfmt=_7; break; + case '8': pstringfmt=_8; break; + default: + length++; + continue; + } + + if (*(p+2)=='.'&&PX_charIsNumeric(*(p+3))) + { + precision=*(p+3)-'0'; + p+=3; + } + else + { + p++; + } + + switch (pstringfmt.type) + { + case PX_STRINGFORMAT_TYPE_INT: + length+=PX_strlen(PX_itos(pstringfmt._int,10).data); + break; + case PX_STRINGFORMAT_TYPE_FLOAT: + length+=PX_strlen(PX_ftos(pstringfmt._float,precision).data); + break; + case PX_STRINGFORMAT_TYPE_STRING: + length+=PX_strlen(pstringfmt._pstring); + break; + default: + return 0; + } + + } + return length; + } + PX_memset(_out_str,0,str_size); + for (p = fmt;*p; p++) + { + if(*p != '%') { + _out_str[length]=*p; + length++; + continue; + } + switch(*(p+1)) + { + case '1': pstringfmt=_1; break; + case '2': pstringfmt=_2; break; + case '3': pstringfmt=_3; break; + case '4': pstringfmt=_4; break; + case '5': pstringfmt=_5; break; + case '6': pstringfmt=_6; break; + case '7': pstringfmt=_7; break; + case '8': pstringfmt=_8; break; + default: + _out_str[length]=*p; + length++; + continue; + } + + if (*(p+2)=='.'&&PX_charIsNumeric(*(p+3))) + { + precision=*(p+3)-'0'; + p+=3; + } + else + { + p++; + } + + switch (pstringfmt.type) + { + case PX_STRINGFORMAT_TYPE_INT: + tret=PX_itos(pstringfmt._int,10); + if(length+PX_strlen(tret.data)m[0][0]=0;Mat->m[0][1]=0;Mat->m[0][2]=0;Mat->m[0][3]=0; + Mat->m[1][0]=0;Mat->m[1][1]=0;Mat->m[1][2]=0;Mat->m[1][3]=0; + Mat->m[2][0]=0;Mat->m[2][1]=0;Mat->m[2][2]=0;Mat->m[2][3]=0; + Mat->m[3][0]=0;Mat->m[3][1]=0;Mat->m[3][2]=0;Mat->m[3][3]=0; +} + +void PX_MatrixIdentity(px_matrix *Mat) +{ + Mat->_11=1.0f; Mat->_12=0.0f; Mat->_13=0.0f; Mat->_14=0.0f; + Mat->_21=0.0f; Mat->_22=1.0f; Mat->_23=0.0f; Mat->_24=0.0f; + Mat->_31=0.0f; Mat->_32=0.0f; Mat->_33=1.0f; Mat->_34=0.0f; + Mat->_41=0.0f; Mat->_42=0.0f; Mat->_43=0.0f; Mat->_44=1.0f; +} + +px_matrix PX_MatrixMultiply(px_matrix Mat1,px_matrix Mat2) +{ + px_matrix ptmat; + ptmat.m[0][0]=Mat1.m[0][0]*Mat2.m[0][0]/**/+Mat1.m[0][1]*Mat2.m[1][0]/**/+Mat1.m[0][2]*Mat2.m[2][0]/**/+Mat1.m[0][3]*Mat2.m[3][0]; + ptmat.m[0][1]=Mat1.m[0][0]*Mat2.m[0][1]/**/+Mat1.m[0][1]*Mat2.m[1][1]/**/+Mat1.m[0][2]*Mat2.m[2][1]/**/+Mat1.m[0][3]*Mat2.m[3][1]; + ptmat.m[0][2]=Mat1.m[0][0]*Mat2.m[0][2]/**/+Mat1.m[0][1]*Mat2.m[1][2]/**/+Mat1.m[0][2]*Mat2.m[2][2]/**/+Mat1.m[0][3]*Mat2.m[3][2]; + ptmat.m[0][3]=Mat1.m[0][0]*Mat2.m[0][3]/**/+Mat1.m[0][1]*Mat2.m[1][3]/**/+Mat1.m[0][2]*Mat2.m[2][3]/**/+Mat1.m[0][3]*Mat2.m[3][3]; + + ptmat.m[1][0]=Mat1.m[1][0]*Mat2.m[0][0]/**/+Mat1.m[1][1]*Mat2.m[1][0]/**/+Mat1.m[1][2]*Mat2.m[2][0]/**/+Mat1.m[1][3]*Mat2.m[3][0]; + ptmat.m[1][1]=Mat1.m[1][0]*Mat2.m[0][1]/**/+Mat1.m[1][1]*Mat2.m[1][1]/**/+Mat1.m[1][2]*Mat2.m[2][1]/**/+Mat1.m[1][3]*Mat2.m[3][1]; + ptmat.m[1][2]=Mat1.m[1][0]*Mat2.m[0][2]/**/+Mat1.m[1][1]*Mat2.m[1][2]/**/+Mat1.m[1][2]*Mat2.m[2][2]/**/+Mat1.m[1][3]*Mat2.m[3][2]; + ptmat.m[1][3]=Mat1.m[1][0]*Mat2.m[0][3]/**/+Mat1.m[1][1]*Mat2.m[1][3]/**/+Mat1.m[1][2]*Mat2.m[2][3]/**/+Mat1.m[1][3]*Mat2.m[3][3]; + + ptmat.m[2][0]=Mat1.m[2][0]*Mat2.m[0][0]/**/+Mat1.m[2][1]*Mat2.m[1][0]/**/+Mat1.m[2][2]*Mat2.m[2][0]/**/+Mat1.m[2][3]*Mat2.m[3][0]; + ptmat.m[2][1]=Mat1.m[2][0]*Mat2.m[0][1]/**/+Mat1.m[2][1]*Mat2.m[1][1]/**/+Mat1.m[2][2]*Mat2.m[2][1]/**/+Mat1.m[2][3]*Mat2.m[3][1]; + ptmat.m[2][2]=Mat1.m[2][0]*Mat2.m[0][2]/**/+Mat1.m[2][1]*Mat2.m[1][2]/**/+Mat1.m[2][2]*Mat2.m[2][2]/**/+Mat1.m[2][3]*Mat2.m[3][2]; + ptmat.m[2][3]=Mat1.m[2][0]*Mat2.m[0][3]/**/+Mat1.m[2][1]*Mat2.m[1][3]/**/+Mat1.m[2][2]*Mat2.m[2][3]/**/+Mat1.m[2][3]*Mat2.m[3][3]; + + ptmat.m[3][0]=Mat1.m[3][0]*Mat2.m[0][0]/**/+Mat1.m[3][1]*Mat2.m[1][0]/**/+Mat1.m[3][2]*Mat2.m[2][0]/**/+Mat1.m[3][3]*Mat2.m[3][0]; + ptmat.m[3][1]=Mat1.m[3][0]*Mat2.m[0][1]/**/+Mat1.m[3][1]*Mat2.m[1][1]/**/+Mat1.m[3][2]*Mat2.m[2][1]/**/+Mat1.m[3][3]*Mat2.m[3][1]; + ptmat.m[3][2]=Mat1.m[3][0]*Mat2.m[0][2]/**/+Mat1.m[3][1]*Mat2.m[1][2]/**/+Mat1.m[3][2]*Mat2.m[2][2]/**/+Mat1.m[3][3]*Mat2.m[3][2]; + ptmat.m[3][3]=Mat1.m[3][0]*Mat2.m[0][3]/**/+Mat1.m[3][1]*Mat2.m[1][3]/**/+Mat1.m[3][2]*Mat2.m[2][3]/**/+Mat1.m[3][3]*Mat2.m[3][3]; + return ptmat; +} + +px_matrix PX_MatrixAdd(px_matrix Mat1,px_matrix Mat2) +{ + px_matrix ptmat; + ptmat._11=Mat1._11+Mat2._11;ptmat._12=Mat1._12+Mat2._12;ptmat._13=Mat1._13+Mat2._13;ptmat._14=Mat1._14+Mat2._14; + ptmat._21=Mat1._21+Mat2._21;ptmat._22=Mat1._22+Mat2._22;ptmat._23=Mat1._23+Mat2._23;ptmat._24=Mat1._24+Mat2._24; + ptmat._31=Mat1._31+Mat2._31;ptmat._32=Mat1._32+Mat2._32;ptmat._33=Mat1._33+Mat2._33;ptmat._34=Mat1._34+Mat2._34; + ptmat._41=Mat1._41+Mat2._41;ptmat._42=Mat1._42+Mat2._42;ptmat._43=Mat1._43+Mat2._43;ptmat._44=Mat1._44+Mat2._44; + return ptmat; +} + +px_matrix PX_MatrixSub(px_matrix Mat1,px_matrix Mat2) +{ + px_matrix ptmat; + ptmat._11=Mat1._11-Mat2._11;ptmat._12=Mat1._12-Mat2._12;ptmat._13=Mat1._13-Mat2._13;ptmat._14=Mat1._14-Mat2._14; + ptmat._21=Mat1._21-Mat2._21;ptmat._22=Mat1._22-Mat2._22;ptmat._23=Mat1._23-Mat2._23;ptmat._24=Mat1._24-Mat2._24; + ptmat._31=Mat1._31-Mat2._31;ptmat._32=Mat1._32-Mat2._32;ptmat._33=Mat1._33-Mat2._33;ptmat._34=Mat1._34-Mat2._34; + ptmat._41=Mat1._41-Mat2._41;ptmat._42=Mat1._42-Mat2._42;ptmat._43=Mat1._43-Mat2._43;ptmat._44=Mat1._44-Mat2._44; + return ptmat; +} + +px_bool PX_MatrixEqual(px_matrix Mat1,px_matrix Mat2) +{ + px_int i,j; + for (i=0;i<4;i++) + { + for (j=0;j<4;j++) + { + if (Mat1.m[i][j]!=Mat2.m[i][j]) + { + return PX_FALSE; + } + } + } + return PX_TRUE; +} + +px_void PX_MatrixRotateVector(px_matrix *mat,px_point v_base,px_point v) +{ + px_point cross=PX_PointCross(v_base,v); + px_float cosv=PX_PointDot(v_base,v)/PX_PointMod(v_base)/PX_PointMod(v); + px_float sinv=(px_float)PX_sqrtd(1-cosv*cosv); + if(cross.z<0) sinv=-sinv; + mat->_11=cosv; mat->_12=sinv; mat->_13=0.0f; mat->_14=0.0f; + mat->_21=-sinv; mat->_22=cosv; mat->_23=0.0f; mat->_24=0.0f; + mat->_31=0.0f; mat->_32=0.0f; mat->_33=1.0f; mat->_34=0.0f; + mat->_41=0.0f; mat->_42=0.0f; mat->_43=0.0f; mat->_44=1.0f; +} + +px_void PX_MatrixTranslation(px_matrix *mat,px_float x,px_float y,px_float z) +{ + mat->_11=1.0f; mat->_12=0.0f; mat->_13=0.0f; mat->_14=0.0f; + mat->_21=0.0f; mat->_22=1.0f; mat->_23=0.0f; mat->_24=0.0f; + mat->_31=0.0f; mat->_32=0.0f; mat->_33=1.0f; mat->_34=0.0f; + mat->_41=x; mat->_42=y; mat->_43=z; mat->_44=1.0f; +} + +px_void PX_MatrixRotateX(px_matrix *mat,px_float Angle) +{ + mat->_11=1.0f; mat->_12=0; mat->_13=0.0f; mat->_14=0.0f; + mat->_21=0.0f; mat->_22=PX_cos_angle(Angle); mat->_23=PX_sin_angle(Angle); mat->_24=0.0f; + mat->_31=0.0f; mat->_32=-PX_sin_angle(Angle); mat->_33=PX_cos_angle(Angle); mat->_34=0.0f; + mat->_41=0.0f; mat->_42=0.0f; mat->_43=0.0f; mat->_44=1.0f; +} + +px_void PX_MatrixRotateY(px_matrix *mat,px_float Angle) +{ + mat->_11=PX_cos_angle(Angle); mat->_12=0.0f; mat->_13=PX_sin_angle(Angle); mat->_14=0.0f; + mat->_21=0.0f; mat->_22=1.0f; mat->_23=0.0f; mat->_24=0.0f; + mat->_31=-PX_sin_angle(Angle); mat->_32=0.0f; mat->_33=PX_cos_angle(Angle); mat->_34=0.0f; + mat->_41=0.0f; mat->_42=0.0f; mat->_43=0.0f; mat->_44=1.0f; +} + +px_void PX_MatrixRotateZ(px_matrix *mat,px_float Angle) +{ + + mat->_11=PX_cos_angle(Angle); mat->_12=PX_sin_angle(Angle); mat->_13=0.0f; mat->_14=0.0f; + mat->_21=-PX_sin_angle(Angle); mat->_22=PX_cos_angle(Angle); mat->_23=0.0f; mat->_24=0.0f; + mat->_31=0.0f; mat->_32=0.0f; mat->_33=1.0f; mat->_34=0.0f; + mat->_41=0.0f; mat->_42=0.0f; mat->_43=0.0f; mat->_44=1.0f; +} + + +px_void PX_MatrixRotateXRadian(px_matrix *mat,px_float rad) +{ + mat->_11=1.0f; mat->_12=0; mat->_13=0.0f; mat->_14=0.0f; + mat->_21=0.0f; mat->_22=PX_cos_radian(rad); mat->_23=PX_sin_radian(rad); mat->_24=0.0f; + mat->_31=0.0f; mat->_32=-PX_sin_radian(rad); mat->_33=PX_cos_radian(rad); mat->_34=0.0f; + mat->_41=0.0f; mat->_42=0.0f; mat->_43=0.0f; mat->_44=1.0f; +} + +px_void PX_MatrixRotateYRadian(px_matrix *mat,px_float rad) +{ + mat->_11=PX_cos_radian(rad); mat->_12=0.0f; mat->_13=PX_sin_radian(rad); mat->_14=0.0f; + mat->_21=0.0f; mat->_22=1.0f; mat->_23=0.0f; mat->_24=0.0f; + mat->_31=-PX_sin_radian(rad); mat->_32=0.0f; mat->_33=PX_cos_radian(rad); mat->_34=0.0f; + mat->_41=0.0f; mat->_42=0.0f; mat->_43=0.0f; mat->_44=1.0f; +} + +px_void PX_MatrixRotateZRadian(px_matrix *mat,px_float rad) +{ + + mat->_11=PX_cos_radian(rad); mat->_12=PX_sin_radian(rad); mat->_13=0.0f; mat->_14=0.0f; + mat->_21=-PX_sin_radian(rad); mat->_22=PX_cos_radian(rad); mat->_23=0.0f; mat->_24=0.0f; + mat->_31=0.0f; mat->_32=0.0f; mat->_33=1.0f; mat->_34=0.0f; + mat->_41=0.0f; mat->_42=0.0f; mat->_43=0.0f; mat->_44=1.0f; +} + +px_void PX_MatrixScale(px_matrix *mat,px_float x,px_float y,px_float z) +{ + mat->_11=x; mat->_12=0.0f; mat->_13=0.0f; mat->_14=0.0f; + mat->_21=0.0f; mat->_22=y; mat->_23=0.0f; mat->_24=0.0f; + mat->_31=0.0f; mat->_32=0.0f; mat->_33=z; mat->_34=0.0f; + mat->_41=0.0f; mat->_42=0.0f; mat->_43=0.0f; mat->_44=1.0f; +} + +static px_float ptabs(px_float x){return x>0?x:-x;} +static px_bool Gauss(px_float A[][4], px_float B[][4]) +{ + + px_int i, j, k; + px_float max, temp; + px_float t[4][4]; + for (i = 0; i < 4; i++) + { + for (j = 0; j < 4; j++) + { + t[i][j] = A[i][j]; + } + } + for (i = 0; i < 4; i++) + { + for (j = 0; j < 4; j++) + { + B[i][j] = (i == j) ? (px_float)1 : 0; + } + } + for (i = 0; i < 4; i++) + { + max = t[i][i]; + k = i; + for (j = i+1; j < 4; j++) + { + if (ptabs(t[j][i]) > ptabs(max)) + { + max = t[j][i]; + k = j; + } + } + if (k != i) + { + for (j = 0; j < 4; j++) + { + temp = t[i][j]; + t[i][j] = t[k][j]; + t[k][j] = temp; + temp = B[i][j]; + B[i][j] = B[k][j]; + B[k][j] = temp; + } + } + if (t[i][i] == 0) + { + return PX_FALSE; + } + temp = t[i][i]; + for (j = 0; j < 4; j++) + { + t[i][j] = t[i][j] / temp; + B[i][j] = B[i][j] / temp; + } + for (j = 0; j < 4; j++) + { + if (j != i) + { + temp = t[j][i]; + for (k = 0; k < 4; k++) + { + t[j][k] = t[j][k] - t[i][k]*temp; + B[j][k] = B[j][k] - B[i][k]*temp; + } + } + } + } + return PX_TRUE; +} + + +px_bool PX_MatrixInverse(px_matrix *mat) +{ + return Gauss(mat->m,mat->m); +} + +px_void PX_MatrixTranspose(px_matrix *matrix) +{ + px_matrix mat=*matrix; + matrix->_11=mat._11; matrix->_12=mat._21; matrix->_13=mat._31; matrix->_14=mat._41; + matrix->_21=mat._12; matrix->_22=mat._22; matrix->_23=mat._32; matrix->_24=mat._42; + matrix->_31=mat._13; matrix->_32=mat._23; matrix->_33=mat._33; matrix->_34=mat._43; + matrix->_41=mat._14; matrix->_42=mat._24; matrix->_43=mat._34; matrix->_44=mat._44; +} + + +px_color PX_COLOR(px_uchar a,px_uchar r,px_uchar g,px_uchar b) +{ + px_color color; + color._argb.a=a; + color._argb.r=r; + color._argb.g=g; + color._argb.b=b; + return color; +} + + +px_void PX_ColorIncrease(px_color *color,px_uchar inc) +{ + if(color->_argb.r+inc>=0xff) + { + color->_argb.r=0xff; + } + else + { + color->_argb.r+=inc; + } + + if(color->_argb.g+inc>=0xff) + { + color->_argb.g=0xff; + } + else + { + color->_argb.g+=inc; + } + + if(color->_argb.b+inc>=0xff) + { + color->_argb.b=0xff; + } + else + { + color->_argb.b+=inc; + } +}; + +px_color PX_ColorAdd(px_color color1,px_color color2) +{ + if(color1._argb.r+color2._argb.r>=0xff) + { + color1._argb.r=0xff; + } + else + { + color1._argb.r+=color2._argb.r; + } + + if(color1._argb.g+color2._argb.g>=0xff) + { + color1._argb.g=0xff; + } + else + { + color1._argb.g+=color2._argb.g; + } + + if(color1._argb.b+color2._argb.b>=0xff) + { + color1._argb.b=0xff; + } + else + { + color1._argb.b+=color2._argb.b; + } + + if(color1._argb.a+color2._argb.a>=0xff) + { + color1._argb.a=0xff; + } + else + { + color1._argb.a+=color2._argb.a; + } + return color1; +}; + +px_color PX_ColorSub(px_color color1,px_color color2) +{ + if(color1._argb.r-color2._argb.r<0) + { + color1._argb.r=0; + } + else + { + color1._argb.r-=color2._argb.r; + } + + if(color1._argb.g-color2._argb.g<0) + { + color1._argb.g=0; + } + else + { + color1._argb.g-=color2._argb.g; + } + + if(color1._argb.b-color2._argb.b<0) + { + color1._argb.b=0; + } + else + { + color1._argb.b-=color2._argb.b; + } + + if(color1._argb.a-color2._argb.a<0) + { + color1._argb.a=0; + } + else + { + color1._argb.a-=color2._argb.a; + } + return color1; +} + +px_bool PX_ColorEqual(px_color color1,px_color color2) +{ + return color1._argb.ucolor==color2._argb.ucolor; +} + +px_color_hsl PX_ColorRGBToHSL(px_color color_rgb) +{ + px_color_hsl hsl; + px_float max=0,min=0; + px_float r,g,b; + + r=color_rgb._argb.r/255.f; + g=color_rgb._argb.g/255.f; + b=color_rgb._argb.b/255.f; + + max=r; + max=maxg?g:min; + min=min>b?b:min; + + + hsl.L=(max+min)/2.0f; + if (max==min) + { + hsl.S=0; + } + else + { + hsl.S=(hsl.L<0.5f?(max-min)/(max + min):(max-min)/(2.0f-max-min)); + } + if(r==max) hsl.H=(g-b)*1.0f/(max-min); + if(g==max) hsl.H=2.0f+(b-r)*1.0f/(max-min); + if(b==max) hsl.H=4.0f+(r-g)*1.0f/(max-min); + hsl.H=hsl.H*60; + if (hsl.H<0) + { + hsl.H+=360; + } + hsl.a=color_rgb._argb.a/255.f; + return hsl; +} + +px_color PX_ColorHSLToRGB(px_color_hsl color_hsl) +{ + px_float r,g,b,temp1,temp2,temp3,H,S,L; + H=color_hsl.H; + S=color_hsl.S; + L=color_hsl.L; + + if (color_hsl.S==0) + { + r=g=b=color_hsl.L; + } + else + { + if(L<0.5) + temp2=L*(1.0f+S); + else + temp2=L+S-L*S; + + temp1 = 2.0f * L - temp2; + H /= 360; + + r = temp3 = H + 1.0f / 3.0f; + if (temp3 < 0) + temp3 = temp3 + 1.0f; + if (temp3 > 1) + temp3 = temp3 - 1.0f; + + if (6.0f * temp3 < 1)r = temp1 + (temp2 - temp1) * 6.0f * temp3; + else if (2.0f * temp3 < 1)r = temp2; + else if (3.0f * temp3 < 2)r = temp1 + (temp2 - temp1) * ((2.0f / 3.0f) - temp3) * 6.0f; + else r = temp1; + + temp3 = H; + if (temp3 < 0) + temp3 = temp3 + 1.0f; + if (temp3 > 1) + temp3 = temp3 - 1.0f; + if (6.0f * temp3 < 1)g = temp1 + (temp2 - temp1) * 6.0f * temp3; + else if (2.0f * temp3 < 1)g = temp2; + else if (3.0f * temp3 < 2)g = temp1 + (temp2 - temp1) * ((2.0f / 3.0f) - temp3) * 6.0f; + else g = temp1; + + temp3 = H - 1.0f / 3.0f; + if (temp3 < 0) + temp3 = temp3 + 1.0f; + if (temp3 > 1) + temp3 = temp3 - 1.0f; + if (6.0f * temp3 < 1)b = temp1 + (temp2 - temp1) * 6.0f * temp3; + else if (2.0f * temp3 < 1)b = temp2; + else if (3.0f * temp3 < 2)b = temp1 + (temp2 - temp1) * ((2.0f / 3.0f) - temp3) * 6.0f; + else b = temp1; + } + + return PX_COLOR((px_uchar)(color_hsl.a*255),(px_uchar)(r*255),(px_uchar)(g*255),(px_uchar)(b*255)); +} + +px_color PX_ColorMul(px_color color1,px_double muls) +{ + color1._argb.a=(px_uchar)(color1._argb.a*muls); + color1._argb.r=(px_uchar)(color1._argb.r*muls); + color1._argb.g=(px_uchar)(color1._argb.g*muls); + color1._argb.b=(px_uchar)(color1._argb.b*muls); + return color1; +} + + + +px_point PX_PointAdd(px_point p1,px_point p2) +{ + p1.x+=p2.x; + p1.y+=p2.y; + p1.z+=p2.z; + return p1; +} + +px_point2D PX_Point2DAdd(px_point2D p1,px_point2D p2) +{ + p1.x+=p2.x; + p1.y+=p2.y; + return p1; +} + + +px_point PX_PointSub(px_point p1,px_point p2) +{ + p1.x-=p2.x; + p1.y-=p2.y; + p1.z-=p2.z; + return p1; +} + +px_point2D PX_Point2DSub(px_point2D p1,px_point2D p2) +{ + p1.x-=p2.x; + p1.y-=p2.y; + return p1; +} + + +px_point4D PX_Point4DSub(px_point4D p1,px_point4D p2) +{ + px_point4D v; + v.x=p1.x-p2.x; + v.y=p1.y-p2.y; + v.z=p1.z-p2.z; + v.w=1; + return v; +} + +px_point PX_PointMul(px_point p1,px_float m) +{ + p1.x*=m; + p1.y*=m; + p1.z*=m; + return p1; +} + +px_point2D PX_Point2DMul(px_point2D p1,px_float m) +{ + p1.x*=m; + p1.y*=m; + return p1; +} + +px_point PX_PointDiv(px_point p1,px_float m) +{ + p1.x/=m; + p1.y/=m; + p1.z/=m; + return p1; +} + +px_point2D PX_Point2DRrthonormal(px_point2D v) +{ + return PX_Point2DNormalization(PX_POINT2D(v.y,-v.x)); +} + +px_point2D PX_Point2DBase(px_point2D base1,px_point2D base2,px_point2D target) +{ + base1=PX_Point2DNormalization(base1); + base2=PX_Point2DNormalization(base2); + + return PX_POINT2D( + (target.x*base2.y-base2.x*target.y)/(base1.x*base2.y-base2.x*base1.y), + (target.x*base1.y-base1.x*target.y)/(base2.x*base1.y-base1.x*base2.y) + ); +} + +px_point2D PX_Point2DDiv(px_point2D p1,px_float m) +{ + p1.x/=m; + p1.y/=m; + return p1; +} + +px_float PX_PointDot(px_point p1,px_point p2) +{ + return p1.x*p2.x+p1.y*p2.y+p1.z*p2.z; +} + +px_float PX_Point2DDot(px_point2D p1,px_point2D p2) +{ + return p1.x*p2.x+p1.y*p2.y; +} + +px_float PX_Point4DDot(px_point4D p1,px_point4D p2) +{ + return p1.x*p2.x+p1.y*p2.y+p1.z*p2.z; +} + +px_point PX_PointCross(px_point p1,px_point p2) +{ + px_point pt; + pt.x=p1.y*p2.z-p2.y*p1.z; + pt.y=p1.z*p2.x-p2.z*p1.x; + pt.z=p1.x*p2.y-p2.x*p1.y; + return pt; +} + + +px_point4D PX_Point4DCross(px_point4D p1,px_point4D p2) +{ + px_point4D pt; + pt.x=p1.y*p2.z-p2.y*p1.z; + pt.y=p1.z*p2.x-p2.z*p1.x; + pt.z=p1.x*p2.y-p2.x*p1.y; + pt.w=1; + return pt; +} + +px_point PX_PointInverse(px_point p1) +{ + return PX_POINT(-p1.x,-p1.y,-p1.z); +} + +px_float PX_PointMod(px_point p) +{ + return PX_sqrt(p.x*p.x+p.y*p.y+p.z*p.z); +} + +px_float PX_Point2DMod(px_point2D p) +{ + return PX_sqrt(p.x*p.x+p.y*p.y); +} + + +px_float PX_PointSquare(px_point p) +{ + return (p.x*p.x+p.y*p.y+p.z*p.z); +} + +px_point PX_PointNormalization(px_point p) +{ + if (p.x||p.y||p.z) + { + return PX_PointDiv(p,PX_PointMod(p)); + } + return p; +} + +px_point2D PX_Point2DNormalization(px_point2D p) +{ + if (p.x||p.y) + { + return PX_Point2DDiv(p,PX_Point2DMod(p)); + } + return p; +} + + + +px_point4D PX_Point4DUnit(px_point4D p) +{ + px_point4D pt; + if (p.x||p.y||p.z) + { + px_float sqare=PX_sqrt(p.x*p.x+p.y*p.y+p.z*p.z); + pt.x=p.x/sqare; + pt.y=p.y/sqare; + pt.z=p.z/sqare; + pt.w=1; + return pt; + } + return p; +} + +px_point PX_PointReflectX(px_point vector_refer,px_point respoint) +{ + px_point ret; + px_float cosx,sinx; + px_float mod=PX_PointMod(vector_refer); + cosx=vector_refer.x/mod; + sinx=-vector_refer.y/mod; + + ret.x=respoint.x*cosx+respoint.y*sinx; + ret.y=respoint.y*cosx-respoint.x*sinx; + ret.z=respoint.z; + return ret; +} + + + +px_bool PX_isRectCrossRect(px_rect rect1,px_rect rect2) +{ + px_float disx,disy; + disx=PX_ABS(rect1.x+rect1.width/2-rect2.x-rect2.width/2); + disy=PX_ABS(rect1.y+rect1.height/2-rect2.y-rect2.height/2); + if (disx*2rect.x+rect.width) + { + return PX_FALSE; + } + if (p.yrect.y+rect.height) + { + return PX_FALSE; + } + return PX_TRUE; +} + + +px_bool PX_isXYInRegion(px_float x,px_float y,px_float rectx,px_float recty,px_float width,px_float height) +{ + if (xrectx+width) + { + return PX_FALSE; + } + if (yrecty+height) + { + return PX_FALSE; + } + return PX_TRUE; +} + + +px_bool PX_isLineCrossRect(px_point p1,px_point p2,px_rect rect,px_point *cp1,px_point *cp2) +{ + px_float k,b; + px_float calx,caly; + px_bool bcross=PX_FALSE; + + if (!cp1||!cp2) + { + return PX_FALSE; + } + if (cp1&&cp2) + { + *cp1=p1; + *cp2=p2; + } + + if (PX_isPointInRect(p1,rect)&&PX_isPointInRect(p2,rect)) + { + return PX_TRUE; + } + + if (PX_ABS(p1.x-p2.x)<0.000001f) + { + if (p2.yrect.x&&p1.xrect.y+rect.height) + { + return PX_FALSE; + } + if (p2.yy=rect.y; + } + if (p2.y>rect.y+rect.height) + { + cp2->y=rect.y+rect.height; + } + return PX_TRUE; + } + return PX_FALSE; + } + + + if (PX_ABS(p1.y-p2.y)<0.000001f) + { + if (p2.xrect.y&&p1.yrect.x+rect.width) + { + return PX_FALSE; + } + if (p2.xx=rect.x; + } + if (p2.x>rect.x+rect.width) + { + cp2->x=rect.x+rect.width; + } + return PX_TRUE; + } + return PX_FALSE; + } + + + if (p2.xp1.x&&calxx=calx; + cp1->y=caly; + bcross=PX_TRUE; + } + } + + calx=rect.x+rect.width; + caly=calx*k+b; + if (PX_isPointInRect(PX_POINT(calx,caly,0),rect)) + { + if (calx>p1.x&&calxx=calx; + cp2->y=caly; + } + bcross=PX_TRUE; + } + } + + caly=rect.y; + calx=(caly-b)/k; + if (PX_isPointInRect(PX_POINT(calx,caly,0),rect)) + { + if (calx>p1.x&&calx0) + { + if (cp1) + { + cp1->x=calx; + cp1->y=caly; + } + } + else + { + if (cp2) + { + cp2->x=calx; + cp2->y=caly; + } + } + + + bcross=PX_TRUE; + } + } + + caly=rect.y+rect.height; + calx=(caly-b)/k; + if (PX_isPointInRect(PX_POINT(calx,caly,0),rect)) + { + if (calx>p1.x&&calx0) + { + if (cp2) + { + cp2->x=calx; + cp2->y=caly; + } + } + else + { + if (cp1) + { + cp1->x=calx; + cp1->y=caly; + } + } + + bcross=PX_TRUE; + } + } + + return bcross; +} + +void PX_memset(void *dst,px_byte byte,px_int size) +{ + px_dword dw=byte?(byte<<24)|(byte<<16)|(byte<<8)|byte:0; + px_dword *_4byteMovDst=(px_dword *)dst; + px_uchar *pdst=(px_uchar *)dst+(size&~3); + px_uint _movTs=size>>2; + while (_movTs--) + { + *_4byteMovDst++=dw; + } + _movTs=size&3; + while (_movTs--) + *(pdst++)=byte; +} + + +void PX_memdwordset(void *dst,px_dword dw,px_int count) +{ + px_dword *p=(px_dword *)dst; + while(count--)*p++=dw; +} + + +px_bool PX_memequ(const void *dst,const void *src,px_int size) +{ + px_dword *_4byteMovSrc=(px_dword *)src; + px_dword *_4byteMovDst=(px_dword *)dst; + px_uchar *psrc=(px_uchar *)src+(size&~3); + px_uchar *pdst=(px_uchar *)dst+(size&~3); + px_uint _movTs=size>>2; + if (dst==PX_NULL||src==PX_NULL) + { + PX_ASSERT(); + return PX_FALSE; + } + while (_movTs--) + { + if(*_4byteMovDst++!=*_4byteMovSrc++) + return PX_FALSE; + } + _movTs=size&3; + while (_movTs--) + if(*(pdst++)!=*(psrc++)) + return PX_FALSE; + return PX_TRUE; +} + + +px_void PX_memcpy(px_void *dst,const px_void *src,px_int size) +{ + typedef struct + { + px_byte m[16]; + }PX_MEMCPY_16; + + typedef struct + { + px_byte m[32]; + }PX_MEMCPY_32; + + typedef struct + { + px_byte m[64]; + }PX_MEMCPY_64; + + typedef struct + { + px_byte m[128]; + }PX_MEMCPY_128; + + typedef struct + { + px_byte m[256]; + }PX_MEMCPY_256; + + typedef struct + { + px_byte m[512]; + }PX_MEMCPY_512; + + typedef struct + { + px_byte m[1024]; + }PX_MEMCPY_1024; + + typedef struct + { + px_byte m[2048]; + }PX_MEMCPY_2048; + + typedef struct + { + px_byte m[4096]; + }PX_MEMCPY_4096; + + px_dword *_4byteMovSrc; + px_dword *_4byteMovDst; + px_uchar *psrc; + px_uchar *pdst; + PX_MEMCPY_4096 *_4kbyteMovSrc,*_4kbyteMovDst; + PX_MEMCPY_2048 *_2kbyteMovSrc,*_2kbyteMovDst; + PX_MEMCPY_1024 *_1kbyteMovSrc,*_1kbyteMovDst; + PX_MEMCPY_512 *_512byteMovSrc,*_512byteMovDst; + PX_MEMCPY_256 *_256byteMovSrc,*_256byteMovDst; + PX_MEMCPY_128 *_128byteMovSrc,*_128byteMovDst; + PX_MEMCPY_64 *_64byteMovSrc,*_64byteMovDst; + PX_MEMCPY_32 *_32byteMovSrc,*_32byteMovDst; + PX_MEMCPY_16 *_16byteMovSrc,*_16byteMovDst; + px_uint _movTs; + + + //is overlap? + if (dst>src&&(px_char *)dst<(px_char *)src+size) + { + px_dword _4byteMov=0;//4bytes unit-copy + //backward overlap + psrc=(px_uchar *)src+size-1; + pdst=(px_uchar *)dst+size-1; + + _movTs=size&3; + + while (_movTs--) + *(pdst--)=*(psrc--); + + pdst-=3; + psrc-=3; + _4byteMovDst=(px_dword *)pdst; + _4byteMovSrc=(px_dword *)psrc; + _movTs=size>>2; + while (_movTs--) + { + _4byteMov=*_4byteMovSrc; + _4byteMovSrc--; + *_4byteMovDst=_4byteMov; + _4byteMovDst--; + } + } + else if (src>dst&&(px_char *)src<(px_char *)dst+size) + { + px_dword _4byteMov=0;//4bytes unit-copy + + //forward overlap + psrc=(px_uchar *)src; + pdst=(px_uchar *)dst; + + _4byteMovDst=(px_dword *)pdst; + _4byteMovSrc=(px_dword *)psrc; + _movTs=size>>2; + while (_movTs--) + { + _4byteMov=*_4byteMovSrc; + _4byteMovSrc++; + *_4byteMovDst=_4byteMov; + _4byteMovDst++; + } + _movTs=size&3; + + psrc=(px_uchar *)_4byteMovSrc; + pdst=(px_uchar *)_4byteMovDst; + + while (_movTs--) + *(pdst++)=*(psrc++); + + pdst+=3; + psrc+=3; + } + else + { + //no overlap,using block-copy + //high->low + _movTs=size>>12; + if(_movTs) + { + _4kbyteMovSrc=(PX_MEMCPY_4096 *)src; + _4kbyteMovDst=(PX_MEMCPY_4096 *)dst; + while(_movTs--)*_4kbyteMovDst++=*_4kbyteMovSrc++; + src=_4kbyteMovSrc; + dst=_4kbyteMovDst; + } + + _movTs=size&(1<<11); + if(_movTs) + { + _2kbyteMovSrc=(PX_MEMCPY_2048 *)src; + _2kbyteMovDst=(PX_MEMCPY_2048 *)dst; + *_2kbyteMovDst++=*_2kbyteMovSrc++; + src=_2kbyteMovSrc; + dst=_2kbyteMovDst; + } + + _movTs=size&(1<<10); + if(_movTs) + { + _1kbyteMovSrc=(PX_MEMCPY_1024 *)src; + _1kbyteMovDst=(PX_MEMCPY_1024 *)dst; + *_1kbyteMovDst++=*_1kbyteMovSrc++; + src=_1kbyteMovSrc; + dst=_1kbyteMovDst; + } + + _movTs=size&(1<<9); + if(_movTs) + { + _512byteMovSrc=(PX_MEMCPY_512 *)src; + _512byteMovDst=(PX_MEMCPY_512 *)dst; + *_512byteMovDst++=*_512byteMovSrc++; + src=_512byteMovSrc; + dst=_512byteMovDst; + } + + _movTs=size&(1<<8); + if(_movTs) + { + _256byteMovSrc=(PX_MEMCPY_256 *)src; + _256byteMovDst=(PX_MEMCPY_256 *)dst; + *_256byteMovDst++=*_256byteMovSrc++; + src=_256byteMovSrc; + dst=_256byteMovDst; + } + + _movTs=size&(1<<7); + if(_movTs) + { + _128byteMovSrc=(PX_MEMCPY_128 *)src; + _128byteMovDst=(PX_MEMCPY_128 *)dst; + *_128byteMovDst++=*_128byteMovSrc++; + src=_128byteMovSrc; + dst=_128byteMovDst; + } + + _movTs=size&(1<<6); + if(_movTs) + { + _64byteMovSrc=(PX_MEMCPY_64 *)src; + _64byteMovDst=(PX_MEMCPY_64 *)dst; + *_64byteMovDst++=*_64byteMovSrc++; + src=_64byteMovSrc; + dst=_64byteMovDst; + } + + _movTs=size&(1<<5); + if(_movTs) + { + _32byteMovSrc=(PX_MEMCPY_32 *)src; + _32byteMovDst=(PX_MEMCPY_32 *)dst; + *_32byteMovDst++=*_32byteMovSrc++; + src=_32byteMovSrc; + dst=_32byteMovDst; + } + + _movTs=size&(1<<4); + if(_movTs) + { + _16byteMovSrc=(PX_MEMCPY_16 *)src; + _16byteMovDst=(PX_MEMCPY_16 *)dst; + *_16byteMovDst++=*_16byteMovSrc++; + src=_16byteMovSrc; + dst=_16byteMovDst; + } + + _movTs=size&0x0F; + if(_movTs>=12) + { + _4byteMovSrc=(px_dword *)src; + _4byteMovDst=(px_dword *)dst; + *_4byteMovDst++=*_4byteMovSrc++; + *_4byteMovDst++=*_4byteMovSrc++; + *_4byteMovDst++=*_4byteMovSrc++; + _movTs-=12; + psrc=(px_uchar *)_4byteMovSrc; + pdst=(px_uchar *)_4byteMovDst; + while(_movTs--)*pdst++=*psrc++; + } + else if(_movTs>=8) + { + _4byteMovSrc=(px_dword *)src; + _4byteMovDst=(px_dword *)dst; + *_4byteMovDst++=*_4byteMovSrc++; + *_4byteMovDst++=*_4byteMovSrc++; + _movTs-=8; + psrc=(px_uchar *)_4byteMovSrc; + pdst=(px_uchar *)_4byteMovDst; + while(_movTs--)*pdst++=*psrc++; + } + else if(_movTs>=4) + { + _4byteMovSrc=(px_dword *)src; + _4byteMovDst=(px_dword *)dst; + *_4byteMovDst++=*_4byteMovSrc++; + _movTs-=4; + psrc=(px_uchar *)_4byteMovSrc; + pdst=(px_uchar *)_4byteMovDst; + while(_movTs--)*pdst++=*psrc++; + } + else + { + psrc=(px_uchar *)src; + pdst=(px_uchar *)dst; + while(_movTs--)*pdst++=*psrc++; + } + + } +} + + + +px_void PX_strcpy(px_char *dst,const px_char *src,px_int size) +{ + while(size--) + if(*src) + *(dst++)=*(src++); + else + { + *dst='\0'; + return; + } + *(dst-1)='\0'; +} + +px_void PX_wstrcpy(px_word *dst,const px_word *src,px_int size) +{ + while(size--) + if(*src) + *(dst++)=*(src++); + else + { + *dst='\0'; + return; + } + *(dst-1)='\0'; +} + +px_void PX_strcat(px_char *src,const px_char *cat) +{ + px_int len=PX_strlen(cat); + while(*src)src++; + while(len--)*src++=*cat++; + *src='\0'; +} + +px_void PX_strcat_s(px_char* src, const px_char* cat, px_int size) +{ + if (PX_strlen(src)+PX_strlen(cat)='a'&&_l<='z') + { + _l += 'A' - 'a'; + } + if (_r >= 'a' && _r <= 'z') + { + _r += 'A' - 'a'; + } + if (_l == _r) + { + if (_l == 0)return PX_TRUE; + } + else + { + return PX_FALSE; + } + src++; + dst++; + } + return PX_FALSE; +} + +px_void PX_strupr(px_char *src) +{ + while (*src != '\0') + { + if (*src >= 'a' && *src <= 'z') + *src -= 32; + src++; + } +} + +px_void PX_strlwr(px_char *src) +{ + while (*src != '\0') + { + if (*src > 'A' && *src <= 'Z'){ + *src += 32; + } + src++; + } +} + + +px_point2D PX_Point2DMulMatrix(px_point2D p,px_matrix mat) +{ + px_point2D point; + point.x=p.x*mat._11+p.y*mat._21+1*mat._41; + point.y=p.x*mat._12+p.y*mat._22+1*mat._42; + return point; +} + +px_point PX_PointMulMatrix(px_point p,px_matrix mat) +{ + px_point point; + point.x=p.x*mat._11+p.y*mat._21+p.z*mat._31+1*mat._41; + point.y=p.x*mat._12+p.y*mat._22+p.z*mat._32+1*mat._42; + point.z=p.x*mat._13+p.y*mat._23+p.z*mat._33+1*mat._43; + return point; +} + + +px_point4D PX_Point4DMulMatrix(px_point4D p,px_matrix mat) +{ + px_point4D point; + point.x=p.x*mat._11+p.y*mat._21+p.z*mat._31+1*mat._41; + point.y=p.x*mat._12+p.y*mat._22+p.z*mat._32+1*mat._42; + point.z=p.x*mat._13+p.y*mat._23+p.z*mat._33+1*mat._43; + point.w=p.x*mat._14+p.y*mat._24+p.z*mat._34+1*mat._44; + return point; +} + + +px_plane PX_PLANE(px_point3D p,px_vector3D n) +{ + px_plane pl; + pl.n=n; + pl.p0=p; + return pl; +} + +px_rect PX_RECT(px_float x,px_float y,px_float width,px_float height) +{ + px_rect rect; + rect.x=x; + rect.y=y; + rect.width=width; + rect.height=height; + + if (width<0) + { + rect.width=-width; + rect.x+=width; + } + + if (height<0) + { + rect.height=-height; + rect.y+=height; + } + return rect; +} + + +px_rect PX_RECTPOINT2(px_point p1,px_point p2) +{ + px_rect rect; + rect.width=PX_ABS(p2.x-p1.x); + rect.height=PX_ABS(p2.y-p1.y); + + if (p1.x>2) + { + // x[] 4 base odd/even Sort + exbase=1; + exrang=0; + while (exrang>1); + FFT_Base2(x+(N>>1),N>>1); + + for(k=0;k>1;k++) + { + Wnk.re=(px_float)PX_cosd((-2*PX_PI*k/N)); + Wnk.im=(px_float)PX_sind((-2*PX_PI*k/N)); + cx0=x[k]; + cx1=x[k+(N>>1)]; + x[k]=PX_complexAdd(cx0,PX_complexMult(Wnk,cx1)); + Wnk.re=-Wnk.re; + Wnk.im=-Wnk.im; + x[k+(N>>1)]=PX_complexAdd(cx0,PX_complexMult(Wnk,cx1)); + } + } + else + { + //2 dot DFT + cx0=x[0]; + cx1=x[1]; + x[0]=PX_complexAdd(cx0,cx1); + cx1.im=-cx1.im; + cx1.re=-cx1.re; + x[1]=PX_complexAdd(cx0,cx1); + } + + +} +void PX_FFT(_IN px_complex x[],_OUT px_complex X[],px_int N) +{ + PX_memcpy(X,x,sizeof(px_complex)*N); + FFT_Base2(X,N); +} + +void IFFT_Base2(_IN _OUT px_complex X[],px_int N) +{ + px_int exbase,exrang,i,j,n; + px_complex excomplex,Wnnk,cx0,cx1; + if (N>>2) + { + // x[] 4 base odd/even Sort + exbase=1; + exrang=0; + while (exrang>1); + IFFT_Base2(X+(N>>1),N>>1); + + for(n=0;n>1;n++) + { + Wnnk.re=(px_float)PX_cosd((2*PX_PI*n/N)); + Wnnk.im=(px_float)PX_sind((2*PX_PI*n/N)); + cx0=X[n]; + cx1=X[n+(N>>1)]; + X[n]=PX_complexAdd(cx0,PX_complexMult(Wnnk,cx1)); + + Wnnk.re=-Wnnk.re; + Wnnk.im=-Wnnk.im; + X[n+(N>>1)]=PX_complexAdd(cx0,PX_complexMult(Wnnk,cx1)); + + } + } + else + { + //2 dot IDFT + cx0=X[0]; + cx1=X[1]; + X[0]=PX_complexAdd(cx0,cx1); + + cx1.im=-cx1.im; + cx1.re=-cx1.re; + X[1]=PX_complexAdd(cx0,cx1); + + } +} +void PX_IFFT(_IN px_complex X[],_OUT px_complex x[],px_int N) +{ + px_int i; + PX_memcpy(X,x,sizeof(px_complex)*N); + IFFT_Base2(X,N); + // 1/N operate + for (i=0;i0.15) + { + return 0; + } + + PX_Cepstrum(x,x,N,PX_CEPTRUM_TYPE_REAL); + + if (high>=N||high==low) + { + return 0; + } + + for (i=low;i<=high;i++) + { + if(x[i].re>max) + { + max=x[i].re; + idx=i; + } + } + if (idx==0) + { + return 0; + } + return sampleRate/idx; +} + +void PX_PreEmphasise(const px_double *data, int len, px_double *out, px_double preF)//0.9= 1; i--) + { + out[i] = data[i] - preF * data[i-1]; + } + out[0] = data[0]; +} + +void PX_LinearInterpolationResample(_IN px_double x[],_OUT px_double X[],px_int N,px_int M) +{ + px_int k,m=0; + px_double d1=0,d2=0; + px_double freqscale=N*1.0/M; + for (k=0;k=1.0){ + m+=(px_int)(d2); + d2-=(px_int)(d2); + + } + X[k]=d1; + } +} + +void PX_UpSampled(_IN px_complex x[],_OUT px_complex X[],px_int N,px_int L) +{ + px_int i,j; + for (i=0;i=('0')&&chr<=('9')) + { + return PX_TRUE; + } + return PX_FALSE; +} + +px_bool PX_strIsInt(const px_char *str) +{ + if (PX_strIsNumeric(str)) + { + if (PX_strIsFloat(str)) + { + return PX_FALSE; + } + return PX_TRUE; + } + return PX_FALSE; +} + +static px_double __px_pow_i(px_double num,px_int n) +{ + px_double powint=1; + px_int i; + for(i=1;i<=n;i++) + { + powint*=num; + if (powint==0) + { + break; + } + if (powint>0) + { + if (powint>=PX_DBL_POSITIVE_MAX||powint<=PX_DBL_POSITIVE_MIN) + { + PX_ASSERT(); + break; + } + } + else + { + if (powint<=PX_DBL_NEGATIVE_MIN||powint>=PX_DBL_NEGATIVE_MAX) + { + PX_ASSERT(); + break; + } + } + } + return powint; +} + +static px_double __px_pow_f(px_double num,px_double m) +{ + px_int i,j; + px_double powd=0,x,tmpm=1; + x=num-1; + for(i=1;tmpm>0.0000000001 || tmpm<-0.0000000001;i++) + { + for(j=1,tmpm=1;j<=i;j++) + { + tmpm*=(m-j+1)*x/j; + } + powd+=tmpm; + + if (powd==0) + { + break; + } + if (powd>0) + { + if (powd>=PX_DBL_POSITIVE_MAX||powd<=PX_DBL_POSITIVE_MIN) + { + PX_ASSERT(); + break; + } + } + else + { + if (powd<=PX_DBL_NEGATIVE_MIN||powd>=PX_DBL_NEGATIVE_MAX) + { + PX_ASSERT(); + break; + } + } + } + return powd+1; +} + +px_double PX_pow_dd(px_double num,px_double m) +{ + while (num>2) + { + num=PX_sqrtd(num); + m*=2; + } + if(num==0 && m!=0) return 0; + else if(num==0 && m==0) return 1; + else if(num<0 && m-(px_int)(m)!=0) return 0; + if(num>2) + { + num=1/num; + m=-m; + } + if(m<0) return 1/PX_pow_dd(num,-m); + if(m-(px_int)(m)==0) + return __px_pow_i(num,(px_int)m); + else + return __px_pow_f(num,m-(px_int)(m))*__px_pow_i(num,(px_int)(m)); + //return __px_pow_f(num,m); +} + +px_int PX_pow_ii(px_int i,px_int n) +{ + px_int fin=1; + if (n==0) + { + return 1; + } + if (n<0) + { + return 0; + } + while(n--) + fin*=i; + return fin; +} + + +px_double PX_ln(px_double __x) +{ + px_int N = 128; + px_int k,nk; + px_double x,xx,y; + px_double m=1; + while (__x>PX_e) + { + __x=PX_sqrtd(__x); + m*=2; + } + x = (__x-1)/(__x+1); + xx = x*x; + nk = 2*N+1; + y = 1.0/nk; + for(k=N;k>0;k--) + { + nk = nk - 2; + y = 1.0/nk+xx*y; + } + return 2.0*x*y*m; +} + +px_double PX_log(px_double __x) +{ + return PX_ln(__x); +} + +px_double PX_lg(px_double __x) +{ + return PX_log10(__x); +} + +px_double PX_log10(px_double __x) +{ + return PX_ln(__x)/2.30258509299404568401799145468; +} + + + +static px_uint64 px_srand_seed=0x31415926; + +px_void PX_srand(px_uint64 seed) +{ + seed = (seed*16807)%(0xefffffff); + px_srand_seed=seed; +} + +px_uint32 PX_rand() +{ + return ((px_uint32)(px_srand_seed = (px_srand_seed*764261123)%(0xefffffff)))&PX_RAND_MAX; +} + + +px_double PX_randRange(px_double min,px_double max) +{ + return min+PX_rand()*1.0/PX_RAND_MAX*(max-min); +} + +px_uint32 PX_randEx(px_uint64 seed) +{ + return (px_uint32)(seed = (seed*764261123)%(0xefffffff)); +} + + +px_double PX_GaussRand() +{ + px_double u ; + px_double v; + px_double r; + px_double c; + while (PX_TRUE) + { + u = ((px_double) PX_rand() / (PX_RAND_MAX)) * 2 - 1; + v = ((px_double) PX_rand() / (PX_RAND_MAX)) * 2 - 1; + r = u * u + v * v; + if (r == 0 || r > 1) continue; + c = (px_double)PX_sqrt((px_float)(-2 * PX_ln(r) / r)); + return u * c; + } +} + +px_double PX_Ceil(px_double v) +{ + return v-(px_int)v?(px_double)((px_int)(v+1)):v; +} + +px_void PX_FileGetName(const px_char filefullName[],px_char _out[],px_int outSize) +{ + px_int s; + if (outSize==0) + { + return; + } + _out[0]=0; + s=PX_strlen(filefullName); + if (s==0) + { + return; + } + s--; + while (s) + { + if (filefullName[s]=='/'||filefullName[s]=='\\') + { + s++; + break; + } + s--; + } + + while (outSize>1&&filefullName[s]&&filefullName[s]!='.') + { + outSize--; + *_out=filefullName[s++]; + _out[1]='\0'; + _out++; + } + +} +px_void PX_FileGetPath(const px_char filefullName[],px_char _out[],px_int outSize) +{ + px_int s,i; + if (outSize==0) + { + return; + } + _out[0]=0; + s=PX_strlen(filefullName); + if (s==0) + { + return; + } + s--; + while (s) + { + if (filefullName[s]=='/'||filefullName[s]=='\\') + { + break; + } + s--; + } + + for (i=0;i=outSize-1) + { + _out[0]=0; + return; + } + } + if (i>0&&_out[i-1]==':') + { + _out[i]='/'; + i++; + } + _out[i]=0; + +} + +px_void PX_FileGetExt(const px_char filefullName[],px_char _out[],px_int outSize) +{ + px_int s; + px_bool bDot=PX_FALSE; + if (outSize==0) + { + return; + } + _out[0]=0; + s=PX_strlen(filefullName); + if (s==0) + { + return; + } + s--; + while (s) + { + if (filefullName[s]=='.') + { + s++; + bDot=PX_TRUE; + break; + } + s--; + } + + while (outSize>1&&filefullName[s]) + { + outSize--; + *_out=filefullName[s++]; + _out[1]='\0'; + _out++; + } +} + +static const px_uint32 crc32tab[] = { + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, + 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, + 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, + 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, + 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, + 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, + 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, + 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, + 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, + 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, + 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, + 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, + 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, + 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, + 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, + 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, + 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, + 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, + 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, + 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, + 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, + 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, + 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, + 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, + 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, + 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, + 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, + 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, + 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, + 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, + 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, + 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, + 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, + 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, + 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, + 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, + 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, + 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, + 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, + 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, + 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, + 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, + 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d +}; + + +px_uint32 PX_crc32( px_void *buffer, px_uint size) +{ + px_uint32 i, crc; + crc = 0xFFFFFFFF; + + + for (i = 0; i < size; i++) + crc = crc32tab[(crc ^ ((px_byte *)buffer)[i]) & 0xff] ^ (crc >> 8); + + return crc^0xFFFFFFFF; +} + + + + +px_word PX_crc16(px_void *buffer,px_uint size) +{ + px_uint pos,i; + px_word crc = 0xFFFF; + px_byte *p_data=(px_byte *)buffer; + for (pos = 0; pos < size; pos++) + { + crc ^= (px_word)p_data[pos]; // XOR byte into least sig. byte of crc + for (i = 8; i != 0; i--) // Loop over each bit + { + if ((crc & 0x0001) != 0) // If the LSB is set + { + crc >>= 1; // Shift right and XOR 0xA001 + crc ^= 0xA001; + } + else // Else LSB is not set + { + crc >>= 1; // Just shift right + } + } + } + + crc = ((crc & 0x00ff) << 8) | ((crc & 0xff00) >> 8); + return crc; + +} + +px_char *PX_strchr(const char *s,px_int ch) +{ + + while(*s!='\0') + { + if(*s-ch==0) + return (px_char*)s; + s++; + } + return PX_NULL; +} + +px_int PX_strcmp(const px_char *str1, const px_char *str2) +{ + px_int ret=0; + while( !(ret = *(px_uchar*)str1 - *(px_uchar*)str2 ) && *str1 ) + { + str1++; + str2++; + } + return ret; +} + +px_char* PX_strstr(const char* dest, const char* src) +{ + px_char* start = (px_char*)dest; + px_char* substart = (px_char*)src; + px_char* cp = (px_char*)dest; + while (*cp) + { + start = cp; + while (*start != '\0' && *substart !='\0' && *start == *substart) + { + start++; + substart++; + } + if (*substart == '\0') + { + return cp; + } + substart = (px_char*)src; + cp++; + } + return PX_NULL; +} + + + +px_bool PX_isPointInCircle(px_point p,px_point circle,px_float radius) +{ + if ((p.x-circle.x)*(p.x-circle.x)+(p.y-circle.y)*(p.y-circle.y)<=radius*radius) + { + return PX_TRUE; + } + return PX_FALSE; +} + + +px_bool PX_isPoint2DInCircle(px_point2D p,px_point2D circle,px_float radius) +{ + if ((p.x-circle.x)*(p.x-circle.x)+(p.y-circle.y)*(p.y-circle.y)<=radius*radius) + { + return PX_TRUE; + } + return PX_FALSE; +} + +px_dword PX_inet_addr( const px_char cp[] ) +{ + px_uchar ipBytes[4]={0}; + px_int i; + for( i=0; i<4; i++, cp++ ){ + ipBytes[i] = (px_uchar)PX_atoi( cp ); + if( !(cp = PX_strchr( cp, '.' )) ){ break; } + } + return *(px_dword*)ipBytes; +} + + +px_char* PX_inet_ntoa(px_dword ipv4) +{ + px_int b[4]; + static px_char a[17]; + a[0]='\0'; + b[0]=((ipv4 & 0xff000000)>>24); + b[1]=((ipv4 & 0x00ff0000)>>16); + b[2]=((ipv4 & 0x0000ff00)>>8); + b[3]=((ipv4 & 0x000000ff)>>0); + + PX_itoa(b[3],a+PX_strlen(a),5,10); + PX_strcat(a,"."); + PX_itoa(b[2],a+PX_strlen(a),5,10); + PX_strcat(a,"."); + PX_itoa(b[1],a+PX_strlen(a),5,10); + PX_strcat(a,"."); + PX_itoa(b[0],a+PX_strlen(a),5,10); + return a; +} + +px_bool PX_IsValidIPAddress(const px_char *ip_addr) +{ + // Only supports Ipv4 + px_int len; + px_int position = 0; // Current parser position + px_int bitsNumber = 0; // how many bits in ip_addr,The valid ip address should be 4 bits + px_int bitsLen; // The length of a single bit + px_int bits;// The value of a single bit + px_int n, i; + + len = PX_strlen(ip_addr); + if (len < 7 || len > 15) return PX_FALSE; // The valid IP address length should be 7 to 15 + + for (i = 0; i < len; i++) + { + if (ip_addr[i] == '.' || i == len - 1) + { + bitsLen = i - position; + if (i == len - 1) bitsLen++; // at the end, Need to add an extra length 1 + if (bitsLen > 3 || bitsLen == 0) return PX_FALSE; + if (bitsLen != 1 && ip_addr[position] == '0') return PX_FALSE; + + for (n = 0, bits = 0; n < bitsLen; n++, position++) bits = 10 * bits + (ip_addr[position] - '0'); + if (bits > 255) return PX_FALSE; + position++; + bitsNumber++; + } + else if (ip_addr[i] >= '0' && ip_addr[i] <= '9') continue; + else return PX_FALSE; + } + if (bitsNumber != 4) return PX_FALSE; + return PX_TRUE; +} + +px_dword PX_htonl(px_dword h) +{ + return PX_isBigEndianCPU() ? h : BigLittleSwap32(h); +} + + +px_dword PX_ntohl(px_dword n) +{ + return PX_isBigEndianCPU() ? n : BigLittleSwap32(n); +} + +px_word PX_htons(px_word h) +{ + return PX_isBigEndianCPU() ? h : BigLittleSwap16(h); +} + +px_word PX_ntohs(px_word n) +{ + return PX_isBigEndianCPU() ? n : BigLittleSwap16(n); +} + +px_uint32 PX_sum32(px_void *buffer, px_uint size) +{ + px_uint32 _sum32=0; + px_uint i; + px_byte *pbuffer=(px_byte *)buffer; + for (i=0;i0;i--) + { + re=br; + im=bi; + br=(re+b[i])*zr-im*zi; + bi=(re+b[i])*zi+im*zr; + } + ar=0.0; + ai=0; + for(i=n;i>0;i--) + { + re=ar; + im=ai; + ar=(re+a[i])*zr-im*zi; + ai=(re+a[i])*zi+im*zr; + } + br=br+b[0]; + ar=ar+1.0; + numr=ar*br+ai*bi; + numi=ar*bi-ai*br; + den=ar*ar+ai*ai; + x[k]=numr/den; + y[k]=numi/den; + switch(sign) + { + case 1: + { + temp=PX_sqrtd(x[k]*x[k]+y[k]*y[k]); + y[k]=PX_atan2(y[k],x[k]); + x[k]=temp; + } + break; + case 2: + { + temp=(x[k]*x[k]+y[k]*y[k]); + y[k]=PX_atan2(y[k],x[k]); + x[k]=10*PX_log10(temp); + } + break; + } + + } +} + +px_void PX_gainc(px_double b[],px_double a[],px_int n,px_int ns,px_double x[],px_double y[],px_int len,px_int sign) +{ + px_int i,j,k,nl; + px_double ar,ai,br,bi,zr,zi,im,re,den,numr,numi,freq,temp; + px_double hr,hi,tr,ti; + nl=n+1; + for (k=0;k0;i--) + { + re=br; + im=bi; + br=(re+b[j*nl+i])*zr-im*zi; + bi=(re+b[j*nl+i])*zi+im*zr; + } + ar=0; + ai=0; + for (i=n;i>0;i--) + { + re=ar; + im=ai; + ar=(re+a[j*nl+i])*zr-im*zi; + ai=(re+b[j*nl+i])*zi+im*zr; + } + br=br+b[j*nl+0]; + ar=ar+1.0; + numr=ar*br+ai*bi; + numi=ar*bi-ai*br; + den=ar*ar+ai*ai; + hr=numr/den; + hi=numi/den; + tr=x[k]*hr-y[k]*hi; + ti=x[k]*hi+y[k]*hr; + x[k]=tr; + y[k]=ti; + } + switch(sign) + { + case 1: + { + temp=PX_sqrtd(x[k]*x[k]+y[k]*y[k]); + if (temp!=0) + { + y[k]=PX_atan2(y[k],x[k]); + } + else + { + y[k]=0; + } + x[k]=temp; + } + break; + case 2: + { + temp=(x[k]*x[k]+y[k]*y[k]); + if (temp!=0) + { + y[k]=PX_atan2(y[k],x[k]); + } + else + { + temp=1.0e-40; + y[k]=0; + } + x[k]=10*PX_log10(temp); + } + break; + } + } +} + + + +px_void PX_WindowFunction_blackMan(px_double data[],px_int N) +{ + px_int n; + for(n=0;n=0; i--) + p=p*y+a[i]; + } + else + { + y=3.75/t; p=c[8]; + for (i=7; i>=0; i--) + p=p*y+c[i]; + p=p*PX_exp(t)/PX_sqrtd(t); + } + } + if (n==0) return(p); + q=p; + if (t<3.75) + { + y=(x/3.75)*(x/3.75); p=b[6]; + for (i=5; i>=0; i--) p=p*y+b[i]; + p=p*t; + } + else + { + y=3.75/t; p=d[8]; + for (i=7; i>=0; i--) p=p*y+d[i]; + p=p*PX_exp(t)/PX_sqrtd(t); + } + if (x<0.0) p=-p; + if (n==1) return(p); + if (x==0.0) return(0.0); + y=2.0/t; t=0.0; b1=1.0; b0=0.0; + m=n+(px_int)PX_sqrtd(40.0*n); + m=2*m; + + for (i=m; i>0; i--) + { + p=b0+i*y*b1; b0=b1; b1=p; + if (PX_ABS(b1)>1.0e+10) + { + t=t*1.0e-10; b0=b0*1.0e-10; + b1=b1*1.0e-10; + } + if (i==n) t=b0; + } + p=t*q/b1; + if ((x<0.0)&&(n%2==1)) p=-p; + return(p); +} + +px_void PX_WindowFunction_tukey(px_double data[],px_int N) +{ + px_int n; + if (N<16) + { + return; + } + for (n=0;n<=(N-2)/10;n++) + { + data[n]=0.5*(1-PX_cosd((px_float)(10*PX_PI*n/(N+8)))); + } + for (n=(N-2)/10;n<=9*(N-2)/10;n++) + { + data[n]=1; + } + for (n=9*(N-2)/10;n<=N-1;n++) + { + data[n]=0.5*(1-PX_cosd((px_float)(10*PX_PI*(N-n-1)/(N+8))));; + } +} + +px_void PX_WindowFunction_hanning(px_double data[],px_int N) +{ + px_int n; + for(n=0;nn-k-2) + { + w=0.5*((px_float)(1.0-PX_cos_radian((px_float)((n-i-1)*pi/(k+1))))); + } + break; + } + case PX_FIRFILTER_WINDOW_TYPE_TRIANGULAR: + { + w=1.0-PX_ABS(1.0-2*i/(n-1.0)); + break; + } + case PX_FIRFILTER_WINDOW_TYPE_HANNING: + { + w=0.5*(1.0-PX_cos_radian((px_float)(2*i*pi/(n-1)))); + break; + } + case PX_FIRFILTER_WINDOW_TYPE_HAMMING: + { + w=0.54-0.46*PX_cos_radian((px_float)(2*i*pi/(n-1))); + break; + } + case PX_FIRFILTER_WINDOW_TYPE_BLACKMAN: + { + w=0.42-0.5*PX_cos_radian((px_float)(2*i*pi/(n-1)))+0.08*PX_cos_radian((px_float)(4*i*pi/(n-1))); + break; + } + case PX_FIRFILTER_WINDOW_TYPE_KAISER: + { + w=PX_FIRKaiser(i,n,beta); + break; + } + } + return w; +} + +px_sine PX_SINE(px_double A,px_double P,px_double F) +{ + px_sine s; + s.A=A; + s.p=P; + s.f=F; + return s; +} + +px_sine PX_InstantaneousFrequency(px_sine src,px_double p2,px_double delta_t) +{ + px_double delta=(p2-src.p); + delta=delta-(px_int)delta-1/2; + delta/=delta_t; + src.f+=delta; + return src; +} + + +px_void PX_FIRFilterBuild(PX_FIRFILTER_TYPE bandtype,px_double fln,px_double fhn,PX_FIRFILTER_WINDOW_TYPE wn,px_double h[],px_int n,px_double beta) +{ + px_int i,n2,mid; + px_double s,pi,wc1,wc2=0,delay; + + pi=4.0*PX_atan(1.0); + if ((n%2)==0) + { + n2=n/2-1; + mid=1; + } + else + { + n2=n/2; + mid=0; + } + delay=n/2.0; + wc1=2.0*pi*fln; + if (bandtype>=3) + { + wc2=2.0*pi*fhn; + } + switch(bandtype) + { + case PX_FIRFILTER_TYPE_LOWPASS: + { + for (i=0;i<=n2;i++) + { + s=i-delay; + h[i]=(PX_sind((wc1*s))/(pi*s))*PX_FIRWindow(wn,n+1,i,beta); + h[n-i]=h[i]; + } + if (mid==1) + { + h[n/2]=wc1/pi; + } + } + break; + case PX_FIRFILTER_TYPE_HIGHPASS: + { + for (i=0;i<=n2;i++) + { + s=i-delay; + h[i]=(PX_sind((pi*s))-PX_sind((wc1*s)))/(pi*s); + h[i]=h[i]*PX_FIRWindow(wn,n+1,i,beta); + h[n-i]=h[i]; + } + if (mid==1) + { + h[n/2]=1.0-wc1/pi; + } + } + break; + case PX_FIRFILTER_TYPE_BANDPASS: + { + for (i=0;i<=n2;i++) + { + s=i-delay; + h[i]=(PX_sind((wc2*s))-PX_sind((wc1*s)))/(pi*s); + h[i]=h[i]*PX_FIRWindow(wn,n+1,i,beta); + h[n-i]=h[i]; + } + if (mid==1) + { + h[n/2]=(wc2-wc1)/pi; + } + } + break; + case PX_FIRFILTER_TYPE_STOPBANDFILTER: + { + for (i=0;i<=n2;i++) + { + s=i-delay; + h[i]=(PX_sind((wc1*s))-PX_sind((wc2*s)))/(pi*s); + h[i]=h[i]*PX_FIRWindow(wn,n+1,i,beta); + h[n-i]=h[i]; + } + if (mid==1) + { + h[n/2]=(wc1+pi-wc2)/pi; + } + } + break; + } +} diff --git a/lib/PainterEngine/core/PX_Typedef.h b/lib/PainterEngine/core/PX_Typedef.h new file mode 100644 index 0000000000000000000000000000000000000000..f43e2598f2c6b9c43a1ccaedf36f004e049475da --- /dev/null +++ b/lib/PainterEngine/core/PX_Typedef.h @@ -0,0 +1,615 @@ +#ifndef __PX_TYPEDEF_H +#define __PX_TYPEDEF_H + +#include "PX_MathTable.h" + +#define PX_DBL_POSITIVE_MAX 1.7976931348623158e+308 +#define PX_DBL_POSITIVE_MIN 4.94065645841246544e-324 + +#define PX_DBL_NEGATIVE_MIN -1.79769313486231570E+308 +#define PX_DBL_NEGATIVE_MAX -4.94065645841246544E-324 + +#define _IN +#define _OUT +#define _LIMIT +#define PX_FALSE 0 +#define PX_TRUE 1 +#define PX_NULL 0 +#define PX_PI 3.141592653589793238462 +#define PX_e (2.7182818284590452353602) +#define PX_e2 (PX_e*PX_e) +#define PX_RAND_MAX (0xffffff) + + +#ifdef _DEBUG +#define PX_DEBUG_MODE _DEBUG +#endif + + +#define PX_COUNTOF(x) (sizeof(x)/sizeof(x[0])) + + + +typedef void px_void; +typedef int px_bool; +typedef unsigned int px_dword;//typedef uint32_t px_dword; +typedef short px_short; +typedef short px_int16; +typedef unsigned short px_uint16; +typedef unsigned short px_word; //typedef uint16_t px_word; +typedef unsigned short px_ushort; +typedef unsigned int px_uint; +typedef unsigned int px_uint32;//typedef uint32_t px_uint32; +typedef int px_int; +typedef int px_int32;//typedef int32_t px_int32; +typedef char px_char; +typedef unsigned char px_byte; +typedef unsigned char px_uchar; +typedef unsigned long px_ulong; +typedef long px_long; +typedef float px_float; +typedef float px_float32;//IEEE 754 little-endian +typedef double px_double; +typedef double px_double64; +typedef unsigned long long px_qword; +typedef unsigned long long px_uint64;//typedef uint64_t px_uint64; +typedef long long px_int64;//typedef int64_t px_int64; + + + +typedef struct +{ + union + { + px_char data[256]; + px_word wdata[128]; + }; + +}PX_RETURN_STRING; + +#include "PX_Log.h" + + +#define PX_STRUCT_OFFSET(t,m) ((((t *)0)->m-(px_byte *)0)) +#define BigLittleSwap16(A) ((((px_word)(A) & 0xff00) >> 8)|(((px_word)(A) & 0x00ff) << 8)) +#define BigLittleSwap32(A) ((((px_dword)(A) & 0xff000000) >> 24)|(((px_dword)(A) & 0x00ff0000) >> 8)|(((px_dword)(A) & 0x0000ff00) << 8)|(((px_dword)(A) & 0x000000ff)<<24)) + + +typedef enum +{ + PX_ALIGN_LEFTTOP, + PX_ALIGN_MIDTOP, + PX_ALIGN_RIGHTTOP, + PX_ALIGN_LEFTMID, + PX_ALIGN_CENTER, + PX_ALIGN_RIGHTMID, + PX_ALIGN_LEFTBOTTOM, + PX_ALIGN_MIDBOTTOM, + PX_ALIGN_RIGHTBOTTOM, +}PX_ALIGN; + + +typedef struct _px_matrix +{ + union { + struct { + px_float _11, _12, _13, _14; + px_float _21, _22, _23, _24; + px_float _31, _32, _33, _34; + px_float _41, _42, _43, _44; + }; + px_float m[4][4]; + }; +}px_matrix; + +typedef struct _px_color +{ + union + { + struct + { + px_uchar r; + px_uchar g; + px_uchar b; + px_uchar a; + }; + px_dword ucolor; + }_argb; +}px_color; + +typedef struct _px_color_hsl +{ + px_float a;//Alpha 0--1 + px_float H;//Hue 0-360 + px_float S;//Saturation 0--1 + px_float L;//Lightness 0--1 +}px_color_hsl; + +typedef struct _px_point +{ + px_float x; + px_float y; + px_float z; +}px_point; +typedef px_point px_point32; + +typedef struct _px_wpoint +{ + px_double x; + px_double y; + px_double z; +}px_wpoint; + +typedef struct +{ + px_float x, y; +}px_point2D; + +typedef px_point2D px_vector2D; +typedef px_point px_point3D; +typedef px_point px_vector3D; + +typedef struct _px_point4 +{ + px_float x; + px_float y; + px_float z; + px_float w; +}px_point4D; + +typedef px_point4D px_vertex; +typedef px_point4D px_vector4D; + +typedef struct +{ + px_point3D p0; // point on the plane + px_vector3D n; // normal to the plane +}px_plane; + +typedef struct _px_rect +{ + px_float x,y,width,height; +}px_rect; + +typedef struct __px_complex +{ + px_double re;// really + px_double im;// imaginary +}px_complex; + + + +////////////////////////////////////////////////////////////////////////// +//endian + +px_dword PX_htonl(px_dword h); +px_dword PX_ntohl(px_dword n); +px_word PX_htons(px_word h); +px_word PX_ntohs(px_word n); + + +////////////////////////////////////////////////////////////////////////// +// +px_double PX_exp(px_double x); + +////////////////////////////////////////////////////////////////////////// +//functions +px_double PX_tanh(px_double x); +px_double PX_sigmoid(px_double x); +px_double PX_ReLU(px_double x); + +////////////////////////////////////////////////////////////////////////// +//PMMCLCG +px_void PX_srand(px_uint64 seed); +px_uint32 PX_rand(void); +px_double PX_randRange(px_double min,px_double max); +px_uint32 PX_randEx(px_uint64 seed); +//gauss rand +px_double PX_GaussRand(void); + +//ceil +px_double PX_Ceil(px_double v); + +////////////////////////////////////////////////////////////////////////// +//file ext +px_void PX_FileGetName(const px_char filefullName[],px_char _out[],px_int outSize); +px_void PX_FileGetPath(const px_char filefullName[],px_char _out[],px_int outSize); +px_void PX_FileGetExt(const px_char filefullName[],px_char _out[],px_int outSize); + +////////////////////////////////////////////////////////////////////////// +//CRC +px_uint32 PX_crc32( px_void *buffer, px_uint size); +px_word PX_crc16(px_void *buffer,px_uint size); +////////////////////////////////////////////////////////////////////////// +//Sum +px_uint32 PX_sum32(px_void *buffer, px_uint size); + +////////////////////////////////////////////////////////////////////////// +//maths +px_int PX_pow_ii(px_int i,px_int n); +px_double PX_pow_dd(px_double num,px_double m); +px_float PX_sqrt( px_float number ); +px_double PX_sqrtd( px_double number ); +px_float PX_SqrtRec( px_float number ); +px_double PX_ln(px_double __x); +px_double PX_log(px_double __x); +px_double PX_lg(px_double __x); +px_double PX_log10(px_double __x); + +#define PX_RadianToAngle(radian) ((radian)*180/PX_PI) +#define PX_AngleToRadian(angle) ((angle)*PX_PI/180) + +px_double PX_sind(px_double radian); +px_double PX_cosd(px_double radian); +px_float PX_sin_radian(px_float radian); +px_float PX_cos_radian(px_float radian); +px_float PX_tan_radian(px_float radian); +px_float PX_sin_angle(px_float angle); +px_float PX_cos_angle(px_float angle); +px_float PX_tan_angle(px_float angle); +px_double PX_atan(px_double x); +px_double PX_atan2(px_double y, px_double x); + +px_double PX_asin(px_double x); +px_double PX_acos(px_double x); +px_float PX_Point_sin(px_point v); +px_float PX_Point_cos(px_point v); + +#define PX_APO(x) ((px_int)((x)+0.5f)) +#define PX_ABS(x) ((x)>0?(x):-(x)) +#define PX_SGN(x) ((x)?((x)>0?1:-1):0) +#define PX_FRAC(x) ((x)-(px_int)(x)) +#define PX_TRUNC(x) ((px_int)(x)) + +////////////////////////////////////////////////////////////////////////// +//string to others +px_void PX_BufferToHexString(px_byte data[],px_int size,px_char hex_str[]); +px_int PX_HexStringToBuffer(const px_char hex_str[],px_byte data[]); +px_uint PX_htoi(const px_char hex_str[]); +px_int PX_atoi(const px_char str[]); +px_float PX_atof(const px_char fstr[]); +PX_RETURN_STRING PX_ftos(px_float f, int precision); +PX_RETURN_STRING PX_itos(px_int num,px_int radix); +px_void PX_AscToWord(const px_char *asc,px_word *u16); +px_int PX_ftoa(px_float f, char *outbuf, int maxlen, int precision); +px_int PX_itoa(px_int num,px_char *str,px_int MaxStrSize,px_int radix); +px_dword PX_SwapEndian(px_dword val); +px_char *PX_strchr(const char *s,int ch); +px_char* PX_strstr(const char* dest, const char* src); + +/////////////////////////////////////////////////////////////////////////// +//rectangle circle +px_bool PX_isPointInCircle(px_point p,px_point circle,px_float radius); +px_bool PX_isPoint2DInCircle(px_point2D p,px_point2D circle,px_float radius); +px_bool PX_isPointInRect(px_point p,px_rect rect); +px_bool PX_isXYInRegion(px_float x,px_float y,px_float rectx,px_float recty,px_float width,px_float height); +////////////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////////////// +//cross +px_bool PX_isLineCrossRect(px_point p1,px_point p2,px_rect rect,px_point *cp1,px_point *cp2); +px_bool PX_isRectCrossRect(px_rect rect1,px_rect rect2); +px_bool PX_isRectCrossCircle(px_rect rect1,px_point center,px_float radius); +px_bool PX_isCircleCrossCircle(px_point center1,px_float radius1,px_point center2,px_float radius2); + +////////////////////////////////////////////////////////////////////////// +px_double PX_Covariance(px_double x[],px_double y[],px_int n); +px_double PX_Variance(px_double x[],px_int n); + +////////////////////////////////////////////////////////////////////////// +//memory +void PX_memset(void *dst,px_byte byte,px_int size); +void PX_memdwordset(void *dst,px_dword dw,px_int count); +#define PX_zeromemory(dst,size) PX_memset(dst,0,size) +px_bool PX_memequ(const void *dst,const void *src,px_int size); +px_void PX_memcpy(px_void *dst,const px_void *src,px_int size); +px_void PX_strcpy(px_char *dst,const px_char *src,px_int size); +px_void PX_wstrcpy(px_word *dst,const px_word *src,px_int size); +px_void PX_strcat(px_char *src,const px_char *cat); +px_void PX_strcat_s(px_char* src, const px_char* cat,px_int size); +px_void PX_wstrcat(px_word *src,const px_word *cat); +px_void PX_strset(px_char *dst,const px_char *src); +px_int PX_strlen(const px_char *dst); +px_int PX_wstrlen(const px_word *dst); +px_int PX_strcmp(const px_char *str1, const px_char *str2); +px_bool PX_strequ(const px_char *src,const char *dst); +px_bool PX_strequ2(const px_char* src, const char* dst); +px_void PX_strupr(px_char *src); +px_void PX_strlwr(px_char *src); +px_bool PX_strIsNumeric(const px_char *str); +px_bool PX_strIsFloat(const px_char *str); +px_bool PX_strIsInt(const px_char *str); +px_bool PX_charIsNumeric(px_char ch); + +typedef enum +{ + PX_STRINGFORMAT_TYPE_INT, + PX_STRINGFORMAT_TYPE_FLOAT, + PX_STRINGFORMAT_TYPE_STRING, +}PX_STRINGFORMAT_TYPE; + +typedef struct +{ + PX_STRINGFORMAT_TYPE type; + union + { + px_int _int; + px_float _float; + const px_char *_pstring; + }; +}px_stringformat; + + +px_stringformat PX_STRINGFORMAT_INT(px_int _i); +px_stringformat PX_STRINGFORMAT_FLOAT(px_float _f); +px_stringformat PX_STRINGFORMAT_STRING(const px_char *_s); +px_int PX_sprintf8(px_char *str,px_int str_size,const px_char fmt[],\ + px_stringformat _1,\ + px_stringformat _2,\ + px_stringformat _3,\ + px_stringformat _4,\ + px_stringformat _5,\ + px_stringformat _6,\ + px_stringformat _7,\ + px_stringformat _8\ + ); +px_int PX_sprintf7(px_char *str,px_int str_size,const px_char fmt[],\ + px_stringformat _1,\ + px_stringformat _2,\ + px_stringformat _3,\ + px_stringformat _4,\ + px_stringformat _5,\ + px_stringformat _6,\ + px_stringformat _7 + ); +px_int PX_sprintf6(px_char *str,px_int str_size,const px_char fmt[],\ + px_stringformat _1,\ + px_stringformat _2,\ + px_stringformat _3,\ + px_stringformat _4,\ + px_stringformat _5,\ + px_stringformat _6\ + ); +px_int PX_sprintf5(px_char *str,px_int str_size,const px_char fmt[],\ + px_stringformat _1,\ + px_stringformat _2,\ + px_stringformat _3,\ + px_stringformat _4,\ + px_stringformat _5\ + ); +px_int PX_sprintf4(px_char *str,px_int str_size,const px_char fmt[],\ + px_stringformat _1,\ + px_stringformat _2,\ + px_stringformat _3,\ + px_stringformat _4\ + ); +px_int PX_sprintf3(px_char *str,px_int str_size,const px_char fmt[],\ + px_stringformat _1,\ + px_stringformat _2,\ + px_stringformat _3\ + ); +px_int PX_sprintf2(px_char *str,px_int str_size,const px_char fmt[],\ + px_stringformat _1,\ + px_stringformat _2\ + ); +px_int PX_sprintf1(px_char *str,px_int str_size,const px_char fmt[],\ + px_stringformat _1\ + ); +px_int PX_sprintf0(px_char *str,px_int str_size,const px_char fmt[]); +/*px_int px_sprintf(px_char *str,px_int str_size,px_char fmt[],...);*/ +////////////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////////////// +//matrix +void PX_MatrixZero(px_matrix *Mat); +void PX_MatrixIdentity(px_matrix *Mat); +px_matrix PX_MatrixMultiply(px_matrix Mat1,px_matrix Mat2); +px_matrix PX_MatrixAdd(px_matrix Mat1,px_matrix Mat2); +px_matrix PX_MatrixSub(px_matrix Mat1,px_matrix Mat2); +px_bool PX_MatrixEqual(px_matrix Mat1,px_matrix Mat2); +px_void PX_MatrixRotateVector(px_matrix *mat,px_point v_base,px_point v); +px_void PX_MatrixTranslation(px_matrix *mat,px_float x,px_float y,px_float z); +px_void PX_MatrixRotateX(px_matrix *mat,px_float Angle); +px_void PX_MatrixRotateY(px_matrix *mat,px_float Angle); +px_void PX_MatrixRotateZ(px_matrix *mat,px_float Angle); +px_void PX_MatrixRotateXRadian(px_matrix *mat,px_float rad); +px_void PX_MatrixRotateYRadian(px_matrix *mat,px_float rad); +px_void PX_MatrixRotateZRadian(px_matrix *mat,px_float rad); +px_void PX_MatrixScale(px_matrix *mat,px_float x,px_float y,px_float z); +px_bool PX_MatrixInverse(px_matrix *mat); +px_void PX_MatrixTranspose(px_matrix *matrix); +////////////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////////////// +//color +px_color PX_COLOR(px_uchar a,px_uchar r,px_uchar g,px_uchar b); +px_void PX_ColorIncrease(px_color *color,px_uchar inc); +px_color PX_ColorAdd(px_color color1,px_color color2); +px_color PX_ColorSub(px_color color1,px_color color2); +px_color PX_ColorMul(px_color color1,px_double muls); +px_bool PX_ColorEqual(px_color color1,px_color color2); +px_color_hsl PX_ColorRGBToHSL(px_color color_rgb); +px_color PX_ColorHSLToRGB(px_color_hsl color_hsl); +////////////////////////////////////////////////////////////////////////// + + +////////////////////////////////////////////////////////////////////////// +//point +px_point PX_POINT(px_float x,px_float y,px_float z); +px_point2D PX_POINT2D(px_float x,px_float y); +px_point4D PX_POINT4D(px_float x,px_float y,px_float z); +px_point PX_PointRotate(px_point p,px_float angle); +px_point2D PX_Point2DRotate(px_point2D p,px_float angle); +px_float PX_PointDistance(px_point p1,px_point p2); + + +px_point PX_PointAdd(px_point p1,px_point p2); +px_point2D PX_Point2DAdd(px_point2D p1,px_point2D p2); +px_point PX_PointSub(px_point p1,px_point p2); +px_point2D PX_Point2DSub(px_point2D p1,px_point2D p2); +px_point4D PX_Point4DSub(px_point4D p1,px_point4D p2); +px_point PX_PointMul(px_point p1,px_float m); +px_point2D PX_Point2DMul(px_point2D p1,px_float m); +px_point PX_PointDiv(px_point p1,px_float m); + +px_point2D PX_Point2DRrthonormal(px_point2D v); +px_point2D PX_Point2DBase(px_point2D base1,px_point2D base2,px_point2D target); +px_point2D PX_Point2DDiv(px_point2D p1,px_float m); +px_float PX_PointDot(px_point p1,px_point p2); +px_float PX_Point2DDot(px_point2D p1,px_point2D p2); +px_float PX_Point4DDot(px_point4D p1,px_point4D p2); +px_point PX_PointCross(px_point p1,px_point p2); +px_point4D PX_Point4DCross(px_point4D p1,px_point4D p2); +px_point PX_PointInverse(px_point p1); +px_float PX_PointMod(px_point p); +px_float PX_Point2DMod(px_point2D p); +px_float PX_PointSquare(px_point p); +px_point PX_PointNormalization(px_point p); +px_point2D PX_Point2DNormalization(px_point2D p); +px_point4D PX_Point4DUnit(px_point4D p); +px_point PX_PointReflectX(px_point vector_refer,px_point respoint); + +px_point2D PX_Point2DMulMatrix(px_point2D p,px_matrix m); +px_point PX_PointMulMatrix(px_point p,px_matrix m); +px_point4D PX_Point4DMulMatrix(px_point4D p,px_matrix m); + +////////////////////////////////////////////////////////////////////////// +//Triangle +typedef struct +{ + px_point Vertex_1, Vertex_2, Vertex_3; +}px_triangle; +px_bool PX_TriangleIsCross( px_triangle* tri1, px_triangle* tri2 ); + +////////////////////////////////////////////////////////////////////////// +//plane +px_plane PX_PLANE(px_point3D p,px_vector3D n); + +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// +//Rect +px_rect PX_RECT(px_float x,px_float y,px_float width,px_float height); +px_rect PX_RECTPOINT2(px_point p1,px_point p2); + + +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// +//complex +px_complex PX_complexBuild(px_float re,px_float im); +px_complex PX_complexAdd(px_complex a,px_complex b); +px_complex PX_complexMult(px_complex a,px_complex b); +px_double PX_complexMod(px_complex a); +px_complex PX_complexLog(px_complex a); +px_complex PX_complexExp(px_complex a); +px_complex PX_complexSin(px_complex a); + +////////////////////////////////////////////////////////////////////////// +//DFT/FFT +void PX_DFT(_IN px_complex x[],_OUT px_complex X[],px_int N); +void PX_DCT(_IN px_double x[],_OUT px_double X[],px_int N); +void PX_IDFT(_IN px_complex X[],_OUT px_complex x[],px_int N); +void PX_IDCT(_IN px_double x[],_OUT px_double X[],px_int N); +void PX_FFT(_IN px_complex x[],_OUT px_complex X[],px_int N); +void PX_IFFT(_IN px_complex X[],_OUT px_complex x[],px_int N); +void PX_FFT_2(_IN px_complex x[],_OUT px_complex X[],px_int N_N); +void PX_IFFT_2(_IN px_complex X[],_OUT px_complex x[],px_int N_N); +void PX_FFT_2_Shift(_IN px_complex _in[],_OUT px_complex _out[],px_int N_N); +void PX_FT_Symmetry(_IN px_complex x[],_OUT px_complex X[],px_int N); + +////////////////////////////////////////////////////////////////////////// +//cepstrum +typedef enum +{ + PX_CEPTRUM_TYPE_REAL, + PX_CEPSTRUM_TYPE_COMPLEX, +}PX_CEPSTRUM_TYPE; +void PX_Cepstrum(_IN px_complex x[],_OUT px_complex X[],px_int N,PX_CEPSTRUM_TYPE type); + +////////////////////////////////////////////////////////////////////////// +//zero-crossing rate,ZCR +px_double PX_ZeroCrossingRate(_IN px_double x[],px_int N); +px_double PX_ZeroCrossingRateComplex(_IN px_complex x[],px_int N); +////////////////////////////////////////////////////////////////////////// +//PitchEstimation +px_int PX_PitchEstimation(_IN px_complex x[],px_int N,px_int sampleRate,px_int low_Hz,px_int high_Hz); +////////////////////////////////////////////////////////////////////////// +//PreEmphasise +void PX_PreEmphasise(const px_double *data, int len, px_double *out, px_double preF);//0.9allocsize=init_size; + vec->nodesize=nodeSize; + vec->size=0; + vec->mp=mp; + + + if (init_size==0) + { + vec->data=PX_NULL; + return PX_TRUE; + } + + if(!(vec->data=MP_Malloc(mp,init_size*nodeSize))) + return PX_FALSE; + + return PX_TRUE; +} + + +px_bool PX_VectorSet(px_vector *vec,px_uint index,px_void *data) +{ + px_void *old; + px_uint allocsize=1; + if (index>(px_uint)vec->allocsize-1) + { + while(allocsize<=(px_uint)index) allocsize<<=1; + + old=vec->data; + vec->data=MP_Malloc(vec->mp,allocsize*vec->nodesize); + if (vec->data==PX_NULL) + { + return PX_FALSE; + } + PX_memcpy(vec->data,old,vec->allocsize*vec->nodesize); + vec->allocsize=allocsize; + MP_Free(vec->mp,old); + } + if (index>(px_uint)vec->size-1) + { + vec->size=index+1; + } + PX_memcpy((px_byte *)vec->data+index*vec->nodesize,data,vec->nodesize); + return PX_TRUE; +} + + +px_bool PX_VectorPushback(px_vector *vec,px_void *data) +{ + px_void *old; + if (vec->sizeallocsize) + { + PX_memcpy((px_byte *)vec->data+vec->size*vec->nodesize,data,vec->nodesize); + vec->size++; + } + else + { + px_int allocSize=vec->allocsize; + if (allocSize==0) + { + allocSize=2; + } + else + { + allocSize=vec->allocsize*2; + } + + old=vec->data; + vec->data=MP_Malloc(vec->mp,allocSize*vec->nodesize); + if (vec->data==PX_NULL) + { + return PX_FALSE; + } + PX_memcpy(vec->data,old,vec->allocsize*vec->nodesize); + vec->allocsize=allocSize; + PX_memcpy((px_byte *)vec->data+vec->size*vec->nodesize,data,vec->nodesize); + vec->size++; + if(old) + MP_Free(vec->mp,old); + } + return PX_TRUE; +} + + +px_bool PX_VectorPushTo(px_vector *vec,px_void *data,px_int index) +{ + if(!PX_VectorPushback(vec,data)) return PX_FALSE; + if (index<0||index>=vec->size) + { + return PX_TRUE; + } +#ifndef PX_DEBUG_MODE + if (index<0) + { + PX_ASSERT(); + return PX_FALSE; + } +#endif + PX_memcpy((px_byte *)vec->data+(index+1)*vec->nodesize,(px_byte *)vec->data+(index)*vec->nodesize,(vec->size-index-1)*vec->nodesize); + PX_memcpy((px_byte *)vec->data+(index)*vec->nodesize,data,vec->nodesize); + return PX_TRUE; +} + +px_bool PX_VectorErase(px_vector *vec,px_int index) +{ + px_int i; + if (index<0||index>=vec->size) + { + PX_ERROR("Vector Erase Error!"); + return PX_FALSE; + } + for (i=index;isize-1;i++) + { + PX_memcpy((px_byte *)vec->data+i*vec->nodesize,(px_byte *)vec->data+(i+1)*vec->nodesize,vec->nodesize); + } + vec->size--; + return PX_TRUE; +} + +px_bool PX_VectorPop(px_vector *vec) +{ + if (vec->size==0) + { + return PX_FALSE; + } + vec->size--; + return PX_TRUE; +} + + +px_bool PX_VectorCopy(px_vector *destvec,px_vector *resvec) +{ + if (destvec->nodesize!=resvec->nodesize) + { + return PX_FALSE; + } + if (destvec->allocsizeallocsize) + { + PX_VectorResize(destvec,resvec->allocsize); + } + PX_memcpy(destvec->data,resvec->data,resvec->nodesize*resvec->size); + destvec->size=resvec->size; + return PX_TRUE; +} + + +px_void PX_VectorFree(px_vector *vec) +{ + if((vec->data)!=PX_NULL) + MP_Free(vec->mp,vec->data); +} + + +px_bool PX_VectorResize(px_vector *vec,px_int size) +{ + if (size!=vec->size) + { + PX_VectorFree(vec); + if(!PX_VectorInitialize(vec->mp,vec,vec->nodesize,size))return PX_FALSE; + PX_memset(vec->data,0,vec->nodesize*vec->allocsize); + vec->size=size; + return PX_TRUE; + } + return PX_FALSE; +} + +px_bool PX_VectorCheckIndex(px_vector *vec,px_int index) +{ + if (index<0||index>=vec->size) + { + return PX_FALSE; + } + return PX_TRUE; +} + +px_bool PX_VectorAllocSize(px_vector *vec,px_int size) +{ + if (size<0||sizesize) + { + return PX_FALSE; + } + vec->size=size; + return PX_TRUE; +} + + diff --git a/lib/PainterEngine/core/PX_Vector.h b/lib/PainterEngine/core/PX_Vector.h new file mode 100644 index 0000000000000000000000000000000000000000..629897557d738421b6c9c1ac42ed53611d35f261 --- /dev/null +++ b/lib/PainterEngine/core/PX_Vector.h @@ -0,0 +1,36 @@ +#ifndef __PX_VECTOR_H +#define __PX_VECTOR_H +#include "PX_MemoryPool.h" +typedef struct __px_vector +{ + px_void *data; + px_int nodesize; + px_int size; + px_int allocsize; + px_memorypool *mp; +}px_vector; + +px_bool PX_VectorInitialize(px_memorypool *mp,px_vector *vec,px_int nodeSize,px_int init_size); +px_bool PX_VectorSet(px_vector *vec,px_uint index,px_void *data); +px_bool PX_VectorAllocSize(px_vector *vec,px_int size); +px_bool PX_VectorPushback(px_vector *vec,px_void *data); +px_bool PX_VectorPushTo(px_vector *vec,px_void *data,px_int index); +px_bool PX_VectorErase(px_vector *vec,px_int index); +px_bool PX_VectorPop(px_vector *vec); +px_bool PX_VectorCopy(px_vector *destvec,px_vector *resvec); +px_void PX_VectorFree(px_vector *vec); +px_bool PX_VectorResize(px_vector *vec,px_int size); +px_bool PX_VectorCheckIndex(px_vector *vec,px_int index); +#define PX_VectorSize(x) ((x)->size) + +#ifdef PX_DEBUG_MODE +#define PX_VECTORAT(t,vec,i) (sizeof(t)==(vec)->nodesize?((t *)((px_byte *)((vec)->data)+(vec)->nodesize*(i))):PX_NULL) +#else +#define PX_VECTORAT(t,vec,i) ((t *)((px_byte *)((vec)->data)+(vec)->nodesize*(i))) +#endif + +#define PX_VECTORLAST(t,vec) PX_VECTORAT(t,vec,(vec)->size-1) + +#define PX_VectorClear(vec) ((vec)->size=0) + +#endif diff --git a/lib/PainterEngine/core/PX_Wave.c b/lib/PainterEngine/core/PX_Wave.c new file mode 100644 index 0000000000000000000000000000000000000000..f89d32b15336eb29bf4df3c3531806b8b9e16282 --- /dev/null +++ b/lib/PainterEngine/core/PX_Wave.c @@ -0,0 +1,130 @@ +#include "PX_Wave.h" + +px_uint PX_WaveGetPCMSize(px_byte *buffer,px_int size) +{ + px_int offset=0,pcmSize; + PX_WAVE_DATA_BLOCK *pBlock; + PX_WAVE_RIFF_HEADER *pHeader=(PX_WAVE_RIFF_HEADER *)buffer; + PX_WAVE_FMT_BLOCK *pfmt_block; + if (!PX_WaveVerify(buffer,size)) + { + return 0; + } + offset+=sizeof(PX_WAVE_RIFF_HEADER); + pfmt_block=(PX_WAVE_FMT_BLOCK *)(buffer+sizeof(PX_WAVE_RIFF_HEADER)); + offset+=8; + offset+=pfmt_block->dwFmtSize; + pcmSize=0; + while (offset+(px_int)sizeof(PX_WAVE_DATA_BLOCK)szDataID,"data",4)) + { + offset+=pBlock->dwDataSize+sizeof(PX_WAVE_DATA_BLOCK); + continue; + } + offset+=sizeof(PX_WAVE_DATA_BLOCK); + offset+=pBlock->dwDataSize; + pcmSize+=pBlock->dwDataSize; + } + return pcmSize; +} + +px_byte* PX_WaveGetPCMDataPtr(px_int index,px_byte *data,px_int datasize) +{ + if (PX_WaveVerify(data,datasize)) + { + px_uint offset=0,pcmSize; + pcmSize=PX_WaveGetPCMSize(data,datasize); + + if (pcmSize!=0) + { + PX_WAVE_DATA_BLOCK *pBlock; + PX_WAVE_RIFF_HEADER *pHeader=(PX_WAVE_RIFF_HEADER *)data; + PX_WAVE_FMT_BLOCK *pfmt_block; + + pfmt_block=(PX_WAVE_FMT_BLOCK *)(data+sizeof(PX_WAVE_RIFF_HEADER)); + offset+=sizeof(PX_WAVE_RIFF_HEADER); + offset+=8; + offset+=pfmt_block->dwFmtSize; + pcmSize=0; + + while (offset<(px_uint)datasize) + { + pBlock=(PX_WAVE_DATA_BLOCK*)(data+offset); + if(!PX_memequ(pBlock->szDataID,"data",4)) + { + offset+=pBlock->dwDataSize+sizeof(PX_WAVE_DATA_BLOCK); + continue; + } + offset+=sizeof(PX_WAVE_DATA_BLOCK); + if (index==0) + { + return data+offset; + } + else + { + offset+=pBlock->dwDataSize; + } + } + return PX_NULL; + } + else + return PX_NULL; + } + else + { + return PX_NULL; + } +} + +px_bool PX_WaveVerify(px_byte *buffer,px_int size) +{ + PX_WAVE_RIFF_HEADER *pHeader=(PX_WAVE_RIFF_HEADER *)buffer; + PX_WAVE_FMT_BLOCK *pfmt_block; + if (sizeszRiffId,"RIFF",4)) + { + return PX_FALSE; + } + if (!PX_memequ(pHeader->szRiffFormat,"WAVE",4)) + { + return PX_FALSE; + } + pfmt_block=(PX_WAVE_FMT_BLOCK *)(buffer+sizeof(PX_WAVE_RIFF_HEADER)); + if (!PX_memequ(pfmt_block->szFmtID,"fmt",3)) + { + return PX_FALSE; + } + if (pfmt_block->wavFormat.wChannels!=1&&pfmt_block->wavFormat.wChannels!=2) + { + return PX_FALSE; + } + if (pfmt_block->wavFormat.wBitsPerSample!=16) + { + return PX_FALSE; + } + if (pfmt_block->wavFormat.dwSamplesPerSec!=44100) + { + return PX_FALSE; + } + if (pfmt_block->wavFormat.wFormatTag!=0x0001) + { + return PX_FALSE; + } + return PX_TRUE; +} + +px_uint PX_WaveGetChannel(px_byte *buffer,px_int size) +{ + PX_WAVE_FMT_BLOCK *pfmt_block; + if (!PX_WaveVerify(buffer,size)) + { + return 0; + } + pfmt_block=(PX_WAVE_FMT_BLOCK *)(buffer+sizeof(PX_WAVE_RIFF_HEADER)); + return pfmt_block->wavFormat.wChannels; +} diff --git a/lib/PainterEngine/core/PX_Wave.h b/lib/PainterEngine/core/PX_Wave.h new file mode 100644 index 0000000000000000000000000000000000000000..e722e1f10ff0ed226e0ee283c452ef329fe12a3d --- /dev/null +++ b/lib/PainterEngine/core/PX_Wave.h @@ -0,0 +1,44 @@ +#ifndef PX_WAVE_H +#define PX_WAVE_H +#include "PX_Typedef.h" + +typedef struct +{ + px_byte szRiffId[4]; + px_dword dwRiffSize; + px_byte szRiffFormat[4]; +}PX_WAVE_RIFF_HEADER; + +typedef struct +{ + px_word wFormatTag; + px_word wChannels; + px_dword dwSamplesPerSec; + px_dword dwAvgBytesPerSec; + px_word wBlockAlign; + px_word wBitsPerSample; +}PX_WAVE_FORMAT; + +typedef struct +{ + px_byte szFmtID[4]; // 'f','m','t',' ' please note the + // space character at the fourth location. + px_dword dwFmtSize; + PX_WAVE_FORMAT wavFormat; +}PX_WAVE_FMT_BLOCK; + + +typedef struct +{ + px_byte szDataID[4]; + px_dword dwDataSize; +}PX_WAVE_DATA_BLOCK; + +px_uint PX_WaveGetChannel(px_byte *buffer,px_int size); +px_bool PX_WaveVerify(px_byte *buffer,px_int size); +px_uint PX_WaveGetPCMSize(px_byte *buffer,px_int size); +px_byte* PX_WaveGetPCMDataPtr(px_int index,px_byte *buffer,px_int size); + +#endif + + diff --git a/lib/PainterEngine/core/PX_curve25519.c b/lib/PainterEngine/core/PX_curve25519.c new file mode 100644 index 0000000000000000000000000000000000000000..2122e56ce218e3a4570d64b83bc3aa292ee13692 --- /dev/null +++ b/lib/PainterEngine/core/PX_curve25519.c @@ -0,0 +1,867 @@ +/* Copyright 2008, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 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. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "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 COPYRIGHT + * OWNER OR CONTRIBUTORS 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. + * + * curve25519-donna: Curve25519 elliptic curve, public key function + * + * http://code.google.com/p/curve25519-donna/ + * + * Adam Langley + * + * Derived from public domain C code by Daniel J. Bernstein + * + * More information about curve25519 can be found here + * http://cr.yp.to/ecdh.html + * + * djb's sample implementation of curve25519 is written in a special assembly + * language called qhasm and uses the floating point registers. + * + * This is, almost, a clean room reimplementation from the curve25519 paper. It + * uses many of the tricks described therein. Only the crecip function is taken + * from the sample implementation. + + To generate a private key, generate 32 random bytes and: + px_byte mysecret[32]; + mysecret[0] &= 248; + mysecret[31] &= 127; + mysecret[31] |= 64; + To generate the public key, just do: + + static const uint8_t basepoint[32] = {9}; + curve25519_donna(mypublic, mysecret, basepoint); + To generate a shared key do: + + uint8_t shared_key[32]; + curve25519_donna(shared_key, mysecret, theirpublic); + + + */ + +#include "PX_curve25519.h" + +typedef px_int64 limb; + +/* Field element representation: + * + * Field elements are written as an array of signed, 64-bit limbs, least + * significant first. The value of the field element is: + * x[0] + 2^26·x[1] + x^51·x[2] + 2^102·x[3] + ... + * + * i.e. the limbs are 26, 25, 26, 25, ... bits wide. */ + +/* Sum two numbers: output += in */ +static void fsum(limb *output, const limb *in) { + unsigned i; + for (i = 0; i < 10; i += 2) { + output[0+i] = output[0+i] + in[0+i]; + output[1+i] = output[1+i] + in[1+i]; + } +} + +/* Find the difference of two numbers: output = in - output + * (note the order of the arguments!). */ +static void fdifference(limb *output, const limb *in) { + unsigned i; + for (i = 0; i < 10; ++i) { + output[i] = in[i] - output[i]; + } +} + +/* Multiply a number by a scalar: output = in * scalar */ +static void fscalar_product(limb *output, const limb *in, const limb scalar) { + unsigned i; + for (i = 0; i < 10; ++i) { + output[i] = in[i] * scalar; + } +} + +/* Multiply two numbers: output = in2 * in + * + * output must be distinct to both inputs. The inputs are reduced coefficient + * form, the output is not. + * + * output[x] <= 14 * the largest product of the input limbs. */ +static void fproduct(limb *output, const limb *in2, const limb *in) { + output[0] = ((limb) ((px_int32) in2[0])) * ((px_int32) in[0]); + output[1] = ((limb) ((px_int32) in2[0])) * ((px_int32) in[1]) + + ((limb) ((px_int32) in2[1])) * ((px_int32) in[0]); + output[2] = 2 * ((limb) ((px_int32) in2[1])) * ((px_int32) in[1]) + + ((limb) ((px_int32) in2[0])) * ((px_int32) in[2]) + + ((limb) ((px_int32) in2[2])) * ((px_int32) in[0]); + output[3] = ((limb) ((px_int32) in2[1])) * ((px_int32) in[2]) + + ((limb) ((px_int32) in2[2])) * ((px_int32) in[1]) + + ((limb) ((px_int32) in2[0])) * ((px_int32) in[3]) + + ((limb) ((px_int32) in2[3])) * ((px_int32) in[0]); + output[4] = ((limb) ((px_int32) in2[2])) * ((px_int32) in[2]) + + 2 * (((limb) ((px_int32) in2[1])) * ((px_int32) in[3]) + + ((limb) ((px_int32) in2[3])) * ((px_int32) in[1])) + + ((limb) ((px_int32) in2[0])) * ((px_int32) in[4]) + + ((limb) ((px_int32) in2[4])) * ((px_int32) in[0]); + output[5] = ((limb) ((px_int32) in2[2])) * ((px_int32) in[3]) + + ((limb) ((px_int32) in2[3])) * ((px_int32) in[2]) + + ((limb) ((px_int32) in2[1])) * ((px_int32) in[4]) + + ((limb) ((px_int32) in2[4])) * ((px_int32) in[1]) + + ((limb) ((px_int32) in2[0])) * ((px_int32) in[5]) + + ((limb) ((px_int32) in2[5])) * ((px_int32) in[0]); + output[6] = 2 * (((limb) ((px_int32) in2[3])) * ((px_int32) in[3]) + + ((limb) ((px_int32) in2[1])) * ((px_int32) in[5]) + + ((limb) ((px_int32) in2[5])) * ((px_int32) in[1])) + + ((limb) ((px_int32) in2[2])) * ((px_int32) in[4]) + + ((limb) ((px_int32) in2[4])) * ((px_int32) in[2]) + + ((limb) ((px_int32) in2[0])) * ((px_int32) in[6]) + + ((limb) ((px_int32) in2[6])) * ((px_int32) in[0]); + output[7] = ((limb) ((px_int32) in2[3])) * ((px_int32) in[4]) + + ((limb) ((px_int32) in2[4])) * ((px_int32) in[3]) + + ((limb) ((px_int32) in2[2])) * ((px_int32) in[5]) + + ((limb) ((px_int32) in2[5])) * ((px_int32) in[2]) + + ((limb) ((px_int32) in2[1])) * ((px_int32) in[6]) + + ((limb) ((px_int32) in2[6])) * ((px_int32) in[1]) + + ((limb) ((px_int32) in2[0])) * ((px_int32) in[7]) + + ((limb) ((px_int32) in2[7])) * ((px_int32) in[0]); + output[8] = ((limb) ((px_int32) in2[4])) * ((px_int32) in[4]) + + 2 * (((limb) ((px_int32) in2[3])) * ((px_int32) in[5]) + + ((limb) ((px_int32) in2[5])) * ((px_int32) in[3]) + + ((limb) ((px_int32) in2[1])) * ((px_int32) in[7]) + + ((limb) ((px_int32) in2[7])) * ((px_int32) in[1])) + + ((limb) ((px_int32) in2[2])) * ((px_int32) in[6]) + + ((limb) ((px_int32) in2[6])) * ((px_int32) in[2]) + + ((limb) ((px_int32) in2[0])) * ((px_int32) in[8]) + + ((limb) ((px_int32) in2[8])) * ((px_int32) in[0]); + output[9] = ((limb) ((px_int32) in2[4])) * ((px_int32) in[5]) + + ((limb) ((px_int32) in2[5])) * ((px_int32) in[4]) + + ((limb) ((px_int32) in2[3])) * ((px_int32) in[6]) + + ((limb) ((px_int32) in2[6])) * ((px_int32) in[3]) + + ((limb) ((px_int32) in2[2])) * ((px_int32) in[7]) + + ((limb) ((px_int32) in2[7])) * ((px_int32) in[2]) + + ((limb) ((px_int32) in2[1])) * ((px_int32) in[8]) + + ((limb) ((px_int32) in2[8])) * ((px_int32) in[1]) + + ((limb) ((px_int32) in2[0])) * ((px_int32) in[9]) + + ((limb) ((px_int32) in2[9])) * ((px_int32) in[0]); + output[10] = 2 * (((limb) ((px_int32) in2[5])) * ((px_int32) in[5]) + + ((limb) ((px_int32) in2[3])) * ((px_int32) in[7]) + + ((limb) ((px_int32) in2[7])) * ((px_int32) in[3]) + + ((limb) ((px_int32) in2[1])) * ((px_int32) in[9]) + + ((limb) ((px_int32) in2[9])) * ((px_int32) in[1])) + + ((limb) ((px_int32) in2[4])) * ((px_int32) in[6]) + + ((limb) ((px_int32) in2[6])) * ((px_int32) in[4]) + + ((limb) ((px_int32) in2[2])) * ((px_int32) in[8]) + + ((limb) ((px_int32) in2[8])) * ((px_int32) in[2]); + output[11] = ((limb) ((px_int32) in2[5])) * ((px_int32) in[6]) + + ((limb) ((px_int32) in2[6])) * ((px_int32) in[5]) + + ((limb) ((px_int32) in2[4])) * ((px_int32) in[7]) + + ((limb) ((px_int32) in2[7])) * ((px_int32) in[4]) + + ((limb) ((px_int32) in2[3])) * ((px_int32) in[8]) + + ((limb) ((px_int32) in2[8])) * ((px_int32) in[3]) + + ((limb) ((px_int32) in2[2])) * ((px_int32) in[9]) + + ((limb) ((px_int32) in2[9])) * ((px_int32) in[2]); + output[12] = ((limb) ((px_int32) in2[6])) * ((px_int32) in[6]) + + 2 * (((limb) ((px_int32) in2[5])) * ((px_int32) in[7]) + + ((limb) ((px_int32) in2[7])) * ((px_int32) in[5]) + + ((limb) ((px_int32) in2[3])) * ((px_int32) in[9]) + + ((limb) ((px_int32) in2[9])) * ((px_int32) in[3])) + + ((limb) ((px_int32) in2[4])) * ((px_int32) in[8]) + + ((limb) ((px_int32) in2[8])) * ((px_int32) in[4]); + output[13] = ((limb) ((px_int32) in2[6])) * ((px_int32) in[7]) + + ((limb) ((px_int32) in2[7])) * ((px_int32) in[6]) + + ((limb) ((px_int32) in2[5])) * ((px_int32) in[8]) + + ((limb) ((px_int32) in2[8])) * ((px_int32) in[5]) + + ((limb) ((px_int32) in2[4])) * ((px_int32) in[9]) + + ((limb) ((px_int32) in2[9])) * ((px_int32) in[4]); + output[14] = 2 * (((limb) ((px_int32) in2[7])) * ((px_int32) in[7]) + + ((limb) ((px_int32) in2[5])) * ((px_int32) in[9]) + + ((limb) ((px_int32) in2[9])) * ((px_int32) in[5])) + + ((limb) ((px_int32) in2[6])) * ((px_int32) in[8]) + + ((limb) ((px_int32) in2[8])) * ((px_int32) in[6]); + output[15] = ((limb) ((px_int32) in2[7])) * ((px_int32) in[8]) + + ((limb) ((px_int32) in2[8])) * ((px_int32) in[7]) + + ((limb) ((px_int32) in2[6])) * ((px_int32) in[9]) + + ((limb) ((px_int32) in2[9])) * ((px_int32) in[6]); + output[16] = ((limb) ((px_int32) in2[8])) * ((px_int32) in[8]) + + 2 * (((limb) ((px_int32) in2[7])) * ((px_int32) in[9]) + + ((limb) ((px_int32) in2[9])) * ((px_int32) in[7])); + output[17] = ((limb) ((px_int32) in2[8])) * ((px_int32) in[9]) + + ((limb) ((px_int32) in2[9])) * ((px_int32) in[8]); + output[18] = 2 * ((limb) ((px_int32) in2[9])) * ((px_int32) in[9]); +} + +/* Reduce a long form to a short form by taking the input mod 2^255 - 19. + * + * On entry: |output[i]| < 14*2^54 + * On exit: |output[0..8]| < 280*2^54 */ +static void freduce_degree(limb *output) { + /* Each of these shifts and adds ends up multiplying the value by 19. + * + * For output[0..8], the absolute entry value is < 14*2^54 and we add, at + * most, 19*14*2^54 thus, on exit, |output[0..8]| < 280*2^54. */ + output[8] += output[18] << 4; + output[8] += output[18] << 1; + output[8] += output[18]; + output[7] += output[17] << 4; + output[7] += output[17] << 1; + output[7] += output[17]; + output[6] += output[16] << 4; + output[6] += output[16] << 1; + output[6] += output[16]; + output[5] += output[15] << 4; + output[5] += output[15] << 1; + output[5] += output[15]; + output[4] += output[14] << 4; + output[4] += output[14] << 1; + output[4] += output[14]; + output[3] += output[13] << 4; + output[3] += output[13] << 1; + output[3] += output[13]; + output[2] += output[12] << 4; + output[2] += output[12] << 1; + output[2] += output[12]; + output[1] += output[11] << 4; + output[1] += output[11] << 1; + output[1] += output[11]; + output[0] += output[10] << 4; + output[0] += output[10] << 1; + output[0] += output[10]; +} + +#if (-1 & 3) != 3 +#error "This code only works on a two's complement system" +#endif + +/* return v / 2^26, using only shifts and adds. + * + * On entry: v can take any value. */ +static limb div_by_2_26(const limb v) +{ + /* High word of v; no shift needed. */ + const px_dword highword = (px_dword) (((px_uint64) v) >> 32); + /* Set to all 1s if v was negative; else set to 0s. */ + const px_int32 sign = ((px_int32) highword) >> 31; + /* Set to 0x3ffffff if v was negative; else set to 0. */ + const px_int32 roundoff = ((px_dword) sign) >> 6; + /* Should return v / (1<<26) */ + return (v + roundoff) >> 26; +} + +/* return v / (2^25), using only shifts and adds. + * + * On entry: v can take any value. */ +static limb div_by_2_25(const limb v) +{ + /* High word of v; no shift needed*/ + const px_dword highword = (px_dword) (((px_uint64) v) >> 32); + /* Set to all 1s if v was negative; else set to 0s. */ + const px_int32 sign = ((px_int32) highword) >> 31; + /* Set to 0x1ffffff if v was negative; else set to 0. */ + const px_int32 roundoff = ((px_dword) sign) >> 7; + /* Should return v / (1<<25) */ + return (v + roundoff) >> 25; +} + +/* Reduce all coefficients of the short form input so that |x| < 2^26. + * + * On entry: |output[i]| < 280*2^54 */ +static void freduce_coefficients(limb *output) { + unsigned i; + + output[10] = 0; + + for (i = 0; i < 10; i += 2) { + limb over = div_by_2_26(output[i]); + /* The entry condition (that |output[i]| < 280*2^54) means that over is, at + * most, 280*2^28 in the first iteration of this loop. This is added to the + * next limb and we can approximate the resulting bound of that limb by + * 281*2^54. */ + output[i] -= over << 26; + output[i+1] += over; + + /* For the first iteration, |output[i+1]| < 281*2^54, thus |over| < + * 281*2^29. When this is added to the next limb, the resulting bound can + * be approximated as 281*2^54. + * + * For subsequent iterations of the loop, 281*2^54 remains a conservative + * bound and no overflow occurs. */ + over = div_by_2_25(output[i+1]); + output[i+1] -= over << 25; + output[i+2] += over; + } + /* Now |output[10]| < 281*2^29 and all other coefficients are reduced. */ + output[0] += output[10] << 4; + output[0] += output[10] << 1; + output[0] += output[10]; + + output[10] = 0; + + /* Now output[1..9] are reduced, and |output[0]| < 2^26 + 19*281*2^29 + * So |over| will be no more than 2^16. */ + { + limb over = div_by_2_26(output[0]); + output[0] -= over << 26; + output[1] += over; + } + + /* Now output[0,2..9] are reduced, and |output[1]| < 2^25 + 2^16 < 2^26. The + * bound on |output[1]| is sufficient to meet our needs. */ +} + +/* A helpful wrapper around fproduct: output = in * in2. + * + * On entry: |in[i]| < 2^27 and |in2[i]| < 2^27. + * + * output must be distinct to both inputs. The output is reduced degree + * (indeed, one need only provide storage for 10 limbs) and |output[i]| < 2^26. */ +static void +fmul(limb *output, const limb *in, const limb *in2) { + limb t[19]; + fproduct(t, in, in2); + /* |t[i]| < 14*2^54 */ + freduce_degree(t); + freduce_coefficients(t); + /* |t[i]| < 2^26 */ + PX_memcpy(output, t, sizeof(limb) * 10); +} + +/* Square a number: output = in**2 + * + * output must be distinct from the input. The inputs are reduced coefficient + * form, the output is not. + * + * output[x] <= 14 * the largest product of the input limbs. */ +static void fsquare_inner(limb *output, const limb *in) { + output[0] = ((limb) ((px_int32) in[0])) * ((px_int32) in[0]); + output[1] = 2 * ((limb) ((px_int32) in[0])) * ((px_int32) in[1]); + output[2] = 2 * (((limb) ((px_int32) in[1])) * ((px_int32) in[1]) + + ((limb) ((px_int32) in[0])) * ((px_int32) in[2])); + output[3] = 2 * (((limb) ((px_int32) in[1])) * ((px_int32) in[2]) + + ((limb) ((px_int32) in[0])) * ((px_int32) in[3])); + output[4] = ((limb) ((px_int32) in[2])) * ((px_int32) in[2]) + + 4 * ((limb) ((px_int32) in[1])) * ((px_int32) in[3]) + + 2 * ((limb) ((px_int32) in[0])) * ((px_int32) in[4]); + output[5] = 2 * (((limb) ((px_int32) in[2])) * ((px_int32) in[3]) + + ((limb) ((px_int32) in[1])) * ((px_int32) in[4]) + + ((limb) ((px_int32) in[0])) * ((px_int32) in[5])); + output[6] = 2 * (((limb) ((px_int32) in[3])) * ((px_int32) in[3]) + + ((limb) ((px_int32) in[2])) * ((px_int32) in[4]) + + ((limb) ((px_int32) in[0])) * ((px_int32) in[6]) + + 2 * ((limb) ((px_int32) in[1])) * ((px_int32) in[5])); + output[7] = 2 * (((limb) ((px_int32) in[3])) * ((px_int32) in[4]) + + ((limb) ((px_int32) in[2])) * ((px_int32) in[5]) + + ((limb) ((px_int32) in[1])) * ((px_int32) in[6]) + + ((limb) ((px_int32) in[0])) * ((px_int32) in[7])); + output[8] = ((limb) ((px_int32) in[4])) * ((px_int32) in[4]) + + 2 * (((limb) ((px_int32) in[2])) * ((px_int32) in[6]) + + ((limb) ((px_int32) in[0])) * ((px_int32) in[8]) + + 2 * (((limb) ((px_int32) in[1])) * ((px_int32) in[7]) + + ((limb) ((px_int32) in[3])) * ((px_int32) in[5]))); + output[9] = 2 * (((limb) ((px_int32) in[4])) * ((px_int32) in[5]) + + ((limb) ((px_int32) in[3])) * ((px_int32) in[6]) + + ((limb) ((px_int32) in[2])) * ((px_int32) in[7]) + + ((limb) ((px_int32) in[1])) * ((px_int32) in[8]) + + ((limb) ((px_int32) in[0])) * ((px_int32) in[9])); + output[10] = 2 * (((limb) ((px_int32) in[5])) * ((px_int32) in[5]) + + ((limb) ((px_int32) in[4])) * ((px_int32) in[6]) + + ((limb) ((px_int32) in[2])) * ((px_int32) in[8]) + + 2 * (((limb) ((px_int32) in[3])) * ((px_int32) in[7]) + + ((limb) ((px_int32) in[1])) * ((px_int32) in[9]))); + output[11] = 2 * (((limb) ((px_int32) in[5])) * ((px_int32) in[6]) + + ((limb) ((px_int32) in[4])) * ((px_int32) in[7]) + + ((limb) ((px_int32) in[3])) * ((px_int32) in[8]) + + ((limb) ((px_int32) in[2])) * ((px_int32) in[9])); + output[12] = ((limb) ((px_int32) in[6])) * ((px_int32) in[6]) + + 2 * (((limb) ((px_int32) in[4])) * ((px_int32) in[8]) + + 2 * (((limb) ((px_int32) in[5])) * ((px_int32) in[7]) + + ((limb) ((px_int32) in[3])) * ((px_int32) in[9]))); + output[13] = 2 * (((limb) ((px_int32) in[6])) * ((px_int32) in[7]) + + ((limb) ((px_int32) in[5])) * ((px_int32) in[8]) + + ((limb) ((px_int32) in[4])) * ((px_int32) in[9])); + output[14] = 2 * (((limb) ((px_int32) in[7])) * ((px_int32) in[7]) + + ((limb) ((px_int32) in[6])) * ((px_int32) in[8]) + + 2 * ((limb) ((px_int32) in[5])) * ((px_int32) in[9])); + output[15] = 2 * (((limb) ((px_int32) in[7])) * ((px_int32) in[8]) + + ((limb) ((px_int32) in[6])) * ((px_int32) in[9])); + output[16] = ((limb) ((px_int32) in[8])) * ((px_int32) in[8]) + + 4 * ((limb) ((px_int32) in[7])) * ((px_int32) in[9]); + output[17] = 2 * ((limb) ((px_int32) in[8])) * ((px_int32) in[9]); + output[18] = 2 * ((limb) ((px_int32) in[9])) * ((px_int32) in[9]); +} + +/* fsquare sets output = in^2. + * + * On entry: The |in| argument is in reduced coefficients form and |in[i]| < + * 2^27. + * + * On exit: The |output| argument is in reduced coefficients form (indeed, one + * need only provide storage for 10 limbs) and |out[i]| < 2^26. */ +static void +fsquare(limb *output, const limb *in) { + limb t[19]; + fsquare_inner(t, in); + /* |t[i]| < 14*2^54 because the largest product of two limbs will be < + * 2^(27+27) and fsquare_inner adds together, at most, 14 of those + * products. */ + freduce_degree(t); + freduce_coefficients(t); + /* |t[i]| < 2^26 */ + PX_memcpy(output, t, sizeof(limb) * 10); +} + +/* Take a little-endian, 32-byte number and expand it into polynomial form */ +static void +fexpand(limb *output, const px_byte *input) { +#define F(n,start,shift,mask) \ + output[n] = ((((limb) input[start + 0]) | \ + ((limb) input[start + 1]) << 8 | \ + ((limb) input[start + 2]) << 16 | \ + ((limb) input[start + 3]) << 24) >> shift) & mask; + F(0, 0, 0, 0x3ffffff); + F(1, 3, 2, 0x1ffffff); + F(2, 6, 3, 0x3ffffff); + F(3, 9, 5, 0x1ffffff); + F(4, 12, 6, 0x3ffffff); + F(5, 16, 0, 0x1ffffff); + F(6, 19, 1, 0x3ffffff); + F(7, 22, 3, 0x1ffffff); + F(8, 25, 4, 0x3ffffff); + F(9, 28, 6, 0x1ffffff); +#undef F +} + +#if (-32 >> 1) != -16 +#error "This code only works when >> does sign-extension on negative numbers" +#endif + +/* s32_eq returns 0xffffffff iff a == b and zero otherwise. */ +static px_int32 s32_eq(px_int32 a, px_int32 b) { + a = ~(a ^ b); + a &= a << 16; + a &= a << 8; + a &= a << 4; + a &= a << 2; + a &= a << 1; + return a >> 31; +} + +/* s32_gte returns 0xffffffff if a >= b and zero otherwise, where a and b are + * both non-negative. */ +static px_int32 s32_gte(px_int32 a, px_int32 b) { + a -= b; + /* a >= 0 iff a >= b. */ + return ~(a >> 31); +} + +/* Take a fully reduced polynomial form number and contract it into a + * little-endian, 32-byte array. + * + * On entry: |input_limbs[i]| < 2^26 */ +static void +fcontract(px_byte *output, limb *input_limbs) { + px_int i; + px_int j; + px_int32 input[10]; + px_int32 mask; + + /* |input_limbs[i]| < 2^26, so it's valid to convert to an s32. */ + for (i = 0; i < 10; i++) { + input[i] = (px_int32)input_limbs[i]; + } + + for (j = 0; j < 2; ++j) { + for (i = 0; i < 9; ++i) { + if ((i & 1) == 1) { + /* This calculation is a time-invariant way to make input[i] + * non-negative by borrowing from the next-larger limb. */ + const px_int32 mask = input[i] >> 31; + const px_int32 carry = -((input[i] & mask) >> 25); + input[i] = input[i] + (carry << 25); + input[i+1] = input[i+1] - carry; + } else { + const px_int32 mask = input[i] >> 31; + const px_int32 carry = -((input[i] & mask) >> 26); + input[i] = input[i] + (carry << 26); + input[i+1] = input[i+1] - carry; + } + } + + /* There's no greater limb for input[9] to borrow from, but we can multiply + * by 19 and borrow from input[0], which is valid mod 2^255-19. */ + { + const px_int32 mask = input[9] >> 31; + const px_int32 carry = -((input[9] & mask) >> 25); + input[9] = input[9] + (carry << 25); + input[0] = input[0] - (carry * 19); + } + + /* After the first iteration, input[1..9] are non-negative and fit within + * 25 or 26 bits, depending on position. However, input[0] may be + * negative. */ + } + + /* The first borrow-propagation pass above ended with every limb + except (possibly) input[0] non-negative. + + If input[0] was negative after the first pass, then it was because of a + carry from input[9]. On entry, input[9] < 2^26 so the carry was, at most, + one, since (2**26-1) >> 25 = 1. Thus input[0] >= -19. + + In the second pass, each limb is decreased by at most one. Thus the second + borrow-propagation pass could only have wrapped around to decrease + input[0] again if the first pass left input[0] negative *and* input[1] + through input[9] were all zero. In that case, input[1] is now 2^25 - 1, + and this last borrow-propagation step will leave input[1] non-negative. */ + { + const px_int32 mask = input[0] >> 31; + const px_int32 carry = -((input[0] & mask) >> 26); + input[0] = input[0] + (carry << 26); + input[1] = input[1] - carry; + } + + /* All input[i] are now non-negative. However, there might be values between + * 2^25 and 2^26 in a limb which is, nominally, 25 bits wide. */ + for (j = 0; j < 2; j++) { + for (i = 0; i < 9; i++) { + if ((i & 1) == 1) { + const px_int32 carry = input[i] >> 25; + input[i] &= 0x1ffffff; + input[i+1] += carry; + } else { + const px_int32 carry = input[i] >> 26; + input[i] &= 0x3ffffff; + input[i+1] += carry; + } + } + + { + const px_int32 carry = input[9] >> 25; + input[9] &= 0x1ffffff; + input[0] += 19*carry; + } + } + + /* If the first carry-chain pass, just above, ended up with a carry from + * input[9], and that caused input[0] to be out-of-bounds, then input[0] was + * < 2^26 + 2*19, because the carry was, at most, two. + * + * If the second pass carried from input[9] again then input[0] is < 2*19 and + * the input[9] -> input[0] carry didn't push input[0] out of bounds. */ + + /* It still remains the case that input might be between 2^255-19 and 2^255. + * In this case, input[1..9] must take their maximum value and input[0] must + * be >= (2^255-19) & 0x3ffffff, which is 0x3ffffed. */ + mask = s32_gte(input[0], 0x3ffffed); + for (i = 1; i < 10; i++) { + if ((i & 1) == 1) { + mask &= s32_eq(input[i], 0x1ffffff); + } else { + mask &= s32_eq(input[i], 0x3ffffff); + } + } + + /* mask is either 0xffffffff (if input >= 2^255-19) and zero otherwise. Thus + * this conditionally subtracts 2^255-19. */ + input[0] -= mask & 0x3ffffed; + + for (i = 1; i < 10; i++) { + if ((i & 1) == 1) { + input[i] -= mask & 0x1ffffff; + } else { + input[i] -= mask & 0x3ffffff; + } + } + + input[1] <<= 2; + input[2] <<= 3; + input[3] <<= 5; + input[4] <<= 6; + input[6] <<= 1; + input[7] <<= 3; + input[8] <<= 4; + input[9] <<= 6; +#define F(i, s) \ + output[s+0] |= input[i] & 0xff; \ + output[s+1] = (input[i] >> 8) & 0xff; \ + output[s+2] = (input[i] >> 16) & 0xff; \ + output[s+3] = (input[i] >> 24) & 0xff; + output[0] = 0; + output[16] = 0; + F(0,0); + F(1,3); + F(2,6); + F(3,9); + F(4,12); + F(5,16); + F(6,19); + F(7,22); + F(8,25); + F(9,28); +#undef F +} + +/* Input: Q, Q', Q-Q' + * Output: 2Q, Q+Q' + * + * x2 z3: long form + * x3 z3: long form + * x z: short form, destroyed + * xprime zprime: short form, destroyed + * qmqp: short form, preserved + * + * On entry and exit, the absolute value of the limbs of all inputs and outputs + * are < 2^26. */ +static void fmonty(limb *x2, limb *z2, /* output 2Q */ + limb *x3, limb *z3, /* output Q + Q' */ + limb *x, limb *z, /* input Q */ + limb *xprime, limb *zprime, /* input Q' */ + const limb *qmqp /* input Q - Q' */) { + limb origx[10], origxprime[10], zzz[19], xx[19], zz[19], xxprime[19], + zzprime[19], zzzprime[19], xxxprime[19]; + + PX_memcpy(origx, x, 10 * sizeof(limb)); + fsum(x, z); + /* |x[i]| < 2^27 */ + fdifference(z, origx); /* does x - z */ + /* |z[i]| < 2^27 */ + + PX_memcpy(origxprime, xprime, sizeof(limb) * 10); + fsum(xprime, zprime); + /* |xprime[i]| < 2^27 */ + fdifference(zprime, origxprime); + /* |zprime[i]| < 2^27 */ + fproduct(xxprime, xprime, z); + /* |xxprime[i]| < 14*2^54: the largest product of two limbs will be < + * 2^(27+27) and fproduct adds together, at most, 14 of those products. + * (Approximating that to 2^58 doesn't work out.) */ + fproduct(zzprime, x, zprime); + /* |zzprime[i]| < 14*2^54 */ + freduce_degree(xxprime); + freduce_coefficients(xxprime); + /* |xxprime[i]| < 2^26 */ + freduce_degree(zzprime); + freduce_coefficients(zzprime); + /* |zzprime[i]| < 2^26 */ + PX_memcpy(origxprime, xxprime, sizeof(limb) * 10); + fsum(xxprime, zzprime); + /* |xxprime[i]| < 2^27 */ + fdifference(zzprime, origxprime); + /* |zzprime[i]| < 2^27 */ + fsquare(xxxprime, xxprime); + /* |xxxprime[i]| < 2^26 */ + fsquare(zzzprime, zzprime); + /* |zzzprime[i]| < 2^26 */ + fproduct(zzprime, zzzprime, qmqp); + /* |zzprime[i]| < 14*2^52 */ + freduce_degree(zzprime); + freduce_coefficients(zzprime); + /* |zzprime[i]| < 2^26 */ + PX_memcpy(x3, xxxprime, sizeof(limb) * 10); + PX_memcpy(z3, zzprime, sizeof(limb) * 10); + + fsquare(xx, x); + /* |xx[i]| < 2^26 */ + fsquare(zz, z); + /* |zz[i]| < 2^26 */ + fproduct(x2, xx, zz); + /* |x2[i]| < 14*2^52 */ + freduce_degree(x2); + freduce_coefficients(x2); + /* |x2[i]| < 2^26 */ + fdifference(zz, xx); // does zz = xx - zz + /* |zz[i]| < 2^27 */ + PX_memset(zzz + 10, 0, sizeof(limb) * 9); + fscalar_product(zzz, zz, 121665); + /* |zzz[i]| < 2^(27+17) */ + /* No need to call freduce_degree here: + fscalar_product doesn't increase the degree of its input. */ + freduce_coefficients(zzz); + /* |zzz[i]| < 2^26 */ + fsum(zzz, xx); + /* |zzz[i]| < 2^27 */ + fproduct(z2, zz, zzz); + /* |z2[i]| < 14*2^(26+27) */ + freduce_degree(z2); + freduce_coefficients(z2); + /* |z2|i| < 2^26 */ +} + +/* Conditionally swap two reduced-form limb arrays if 'iswap' is 1, but leave + * them unchanged if 'iswap' is 0. Runs in data-invariant time to avoid + * side-channel attacks. + * + * NOTE that this function requires that 'iswap' be 1 or 0; other values give + * wrong results. Also, the two limb arrays must be in reduced-coefficient, + * reduced-degree form: the values in a[10..19] or b[10..19] aren't swapped, + * and all all values in a[0..9],b[0..9] must have magnitude less than + * INT32_MAX. */ +static void +swap_conditional(limb a[19], limb b[19], limb iswap) { + unsigned i; + const px_int32 swap = (px_int32) -iswap; + + for (i = 0; i < 10; ++i) { + const px_int32 x = swap & ( ((px_int32)a[i]) ^ ((px_int32)b[i]) ); + a[i] = ((px_int32)a[i]) ^ x; + b[i] = ((px_int32)b[i]) ^ x; + } +} + +/* Calculates nQ where Q is the x-coordinate of a point on the curve + * + * resultx/resultz: the x coordinate of the resulting curve point (short form) + * n: a little endian, 32-byte number + * q: a point of the curve (short form) */ +static void +cmult(limb *resultx, limb *resultz, const px_byte *n, const limb *q) { + limb a[19] = {0}, b[19] = {1}, c[19] = {1}, d[19] = {0}; + limb *nqpqx = a, *nqpqz = b, *nqx = c, *nqz = d, *t; + limb e[19] = {0}, f[19] = {1}, g[19] = {0}, h[19] = {1}; + limb *nqpqx2 = e, *nqpqz2 = f, *nqx2 = g, *nqz2 = h; + + unsigned i, j; + + PX_memcpy(nqpqx, (void *)q, sizeof(limb) * 10); + + for (i = 0; i < 32; ++i) { + px_byte byte = n[31 - i]; + for (j = 0; j < 8; ++j) { + const limb bit = byte >> 7; + + swap_conditional(nqx, nqpqx, bit); + swap_conditional(nqz, nqpqz, bit); + fmonty(nqx2, nqz2, + nqpqx2, nqpqz2, + nqx, nqz, + nqpqx, nqpqz, + q); + swap_conditional(nqx2, nqpqx2, bit); + swap_conditional(nqz2, nqpqz2, bit); + + t = nqx; + nqx = nqx2; + nqx2 = t; + t = nqz; + nqz = nqz2; + nqz2 = t; + t = nqpqx; + nqpqx = nqpqx2; + nqpqx2 = t; + t = nqpqz; + nqpqz = nqpqz2; + nqpqz2 = t; + + byte <<= 1; + } + } + + PX_memcpy(resultx, nqx, sizeof(limb) * 10); + PX_memcpy(resultz, nqz, sizeof(limb) * 10); +} + +// ----------------------------------------------------------------------------- +// Shamelessly copied from djb's code +// ----------------------------------------------------------------------------- +static void +crecip(limb *out, const limb *z) { + limb z2[10]; + limb z9[10]; + limb z11[10]; + limb z2_5_0[10]; + limb z2_10_0[10]; + limb z2_20_0[10]; + limb z2_50_0[10]; + limb z2_100_0[10]; + limb t0[10]; + limb t1[10]; + px_int i; + + /* 2 */ fsquare(z2,z); + /* 4 */ fsquare(t1,z2); + /* 8 */ fsquare(t0,t1); + /* 9 */ fmul(z9,t0,z); + /* 11 */ fmul(z11,z9,z2); + /* 22 */ fsquare(t0,z11); + /* 2^5 - 2^0 = 31 */ fmul(z2_5_0,t0,z9); + + /* 2^6 - 2^1 */ fsquare(t0,z2_5_0); + /* 2^7 - 2^2 */ fsquare(t1,t0); + /* 2^8 - 2^3 */ fsquare(t0,t1); + /* 2^9 - 2^4 */ fsquare(t1,t0); + /* 2^10 - 2^5 */ fsquare(t0,t1); + /* 2^10 - 2^0 */ fmul(z2_10_0,t0,z2_5_0); + + /* 2^11 - 2^1 */ fsquare(t0,z2_10_0); + /* 2^12 - 2^2 */ fsquare(t1,t0); + /* 2^20 - 2^10 */ for (i = 2;i < 10;i += 2) { fsquare(t0,t1); fsquare(t1,t0); } + /* 2^20 - 2^0 */ fmul(z2_20_0,t1,z2_10_0); + + /* 2^21 - 2^1 */ fsquare(t0,z2_20_0); + /* 2^22 - 2^2 */ fsquare(t1,t0); + /* 2^40 - 2^20 */ for (i = 2;i < 20;i += 2) { fsquare(t0,t1); fsquare(t1,t0); } + /* 2^40 - 2^0 */ fmul(t0,t1,z2_20_0); + + /* 2^41 - 2^1 */ fsquare(t1,t0); + /* 2^42 - 2^2 */ fsquare(t0,t1); + /* 2^50 - 2^10 */ for (i = 2;i < 10;i += 2) { fsquare(t1,t0); fsquare(t0,t1); } + /* 2^50 - 2^0 */ fmul(z2_50_0,t0,z2_10_0); + + /* 2^51 - 2^1 */ fsquare(t0,z2_50_0); + /* 2^52 - 2^2 */ fsquare(t1,t0); + /* 2^100 - 2^50 */ for (i = 2;i < 50;i += 2) { fsquare(t0,t1); fsquare(t1,t0); } + /* 2^100 - 2^0 */ fmul(z2_100_0,t1,z2_50_0); + + /* 2^101 - 2^1 */ fsquare(t1,z2_100_0); + /* 2^102 - 2^2 */ fsquare(t0,t1); + /* 2^200 - 2^100 */ for (i = 2;i < 100;i += 2) { fsquare(t1,t0); fsquare(t0,t1); } + /* 2^200 - 2^0 */ fmul(t1,t0,z2_100_0); + + /* 2^201 - 2^1 */ fsquare(t0,t1); + /* 2^202 - 2^2 */ fsquare(t1,t0); + /* 2^250 - 2^50 */ for (i = 2;i < 50;i += 2) { fsquare(t0,t1); fsquare(t1,t0); } + /* 2^250 - 2^0 */ fmul(t0,t1,z2_50_0); + + /* 2^251 - 2^1 */ fsquare(t1,t0); + /* 2^252 - 2^2 */ fsquare(t0,t1); + /* 2^253 - 2^3 */ fsquare(t1,t0); + /* 2^254 - 2^4 */ fsquare(t0,t1); + /* 2^255 - 2^5 */ fsquare(t1,t0); + /* 2^255 - 21 */ fmul(out,t1,z11); +} + +px_void PX_Curve25519(px_byte *mypublic, const px_byte *secret, const px_byte *basepoint) +{ + limb bp[10], x[10], z[11], zmone[10]; + px_byte e[32]; + px_int i; + + for (i = 0; i < 32; ++i) e[i] = secret[i]; + e[0] &= 248; + e[31] &= 127; + e[31] |= 64; + + fexpand(bp, basepoint); + cmult(x, z, e, bp); + crecip(zmone, z); + fmul(z, x, zmone); + fcontract(mypublic, z); +} diff --git a/lib/PainterEngine/core/PX_curve25519.h b/lib/PainterEngine/core/PX_curve25519.h new file mode 100644 index 0000000000000000000000000000000000000000..116511a07cc5ed60807d4bf9d39e1b47d92baa5b --- /dev/null +++ b/lib/PainterEngine/core/PX_curve25519.h @@ -0,0 +1,20 @@ +#ifndef PX_CURVE25519_H +#define PX_CURVE25519_H +#include "PX_MemoryPool.h" +/* +To generate a private key, generate 32 random bytes and: +px_byte mysecret[32]; +mysecret[0] &= 248; +mysecret[31] &= 127; +mysecret[31] |= 64; +To generate the public key, just do: + +static const uint8_t basepoint[32] = {9}; +curve25519_donna(mypublic, mysecret, basepoint); +To generate a shared key do: + +uint8_t shared_key[32]; +curve25519_donna(shared_key, mysecret, theirpublic); +*/ +px_void PX_Curve25519(px_byte *mypublic, const px_byte *secret, const px_byte *basepoint); +#endif diff --git a/lib/PainterEngine/core/PX_rbtree.c b/lib/PainterEngine/core/PX_rbtree.c new file mode 100644 index 0000000000000000000000000000000000000000..c7e55255f909e5fdf07d3f44b86f0f24d98e9807 --- /dev/null +++ b/lib/PainterEngine/core/PX_rbtree.c @@ -0,0 +1,453 @@ +/* + Red Black Trees + (C) 1999 Andrea Arcangeli + (C) 2002 David Woodhouse + + 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 + + linux/lib/rbtree.c +*/ + +#include "PX_rbtree.h" + +static void __rb_rotate_left(struct px_rb_node *node, struct px_rb_root *root) +{ + struct px_rb_node *right = node->rb_right; + struct px_rb_node *parent = rb_parent(node); + + if ((node->rb_right = right->rb_left)) + rb_set_parent(right->rb_left, node); + right->rb_left = node; + + rb_set_parent(right, parent); + + if (parent) + { + if (node == parent->rb_left) + parent->rb_left = right; + else + parent->rb_right = right; + } + else + root->rb_node = right; + rb_set_parent(node, right); +} + +static void __rb_rotate_right(struct px_rb_node *node, struct px_rb_root *root) +{ + struct px_rb_node *left = node->rb_left; + struct px_rb_node *parent = rb_parent(node); + + if ((node->rb_left = left->rb_right)) + rb_set_parent(left->rb_right, node); + left->rb_right = node; + + rb_set_parent(left, parent); + + if (parent) + { + if (node == parent->rb_right) + parent->rb_right = left; + else + parent->rb_left = left; + } + else + root->rb_node = left; + rb_set_parent(node, left); +} + +void rb_insert_color(struct px_rb_node *node, struct px_rb_root *root) +{ + struct px_rb_node *parent, *gparent; + + while ((parent = rb_parent(node)) && rb_is_red(parent)) + { + gparent = rb_parent(parent); + + if (parent == gparent->rb_left) + { + { + register struct px_rb_node *uncle = gparent->rb_right; + if (uncle && rb_is_red(uncle)) + { + rb_set_black(uncle); + rb_set_black(parent); + rb_set_red(gparent); + node = gparent; + continue; + } + } + + if (parent->rb_right == node) + { + register struct px_rb_node *tmp; + __rb_rotate_left(parent, root); + tmp = parent; + parent = node; + node = tmp; + } + + rb_set_black(parent); + rb_set_red(gparent); + __rb_rotate_right(gparent, root); + } else { + { + register struct px_rb_node *uncle = gparent->rb_left; + if (uncle && rb_is_red(uncle)) + { + rb_set_black(uncle); + rb_set_black(parent); + rb_set_red(gparent); + node = gparent; + continue; + } + } + + if (parent->rb_left == node) + { + register struct px_rb_node *tmp; + __rb_rotate_right(parent, root); + tmp = parent; + parent = node; + node = tmp; + } + + rb_set_black(parent); + rb_set_red(gparent); + __rb_rotate_left(gparent, root); + } + } + + rb_set_black(root->rb_node); +} + +static void __rb_erase_color(struct px_rb_node *node, struct px_rb_node *parent, + struct px_rb_root *root) +{ + struct px_rb_node *other; + + while ((!node || rb_is_black(node)) && node != root->rb_node) + { + if (parent->rb_left == node) + { + other = parent->rb_right; + if (rb_is_red(other)) + { + rb_set_black(other); + rb_set_red(parent); + __rb_rotate_left(parent, root); + other = parent->rb_right; + } + if ((!other->rb_left || rb_is_black(other->rb_left)) && + (!other->rb_right || rb_is_black(other->rb_right))) + { + rb_set_red(other); + node = parent; + parent = rb_parent(node); + } + else + { + if (!other->rb_right || rb_is_black(other->rb_right)) + { + rb_set_black(other->rb_left); + rb_set_red(other); + __rb_rotate_right(other, root); + other = parent->rb_right; + } + rb_set_color(other, rb_color(parent)); + rb_set_black(parent); + rb_set_black(other->rb_right); + __rb_rotate_left(parent, root); + node = root->rb_node; + break; + } + } + else + { + other = parent->rb_left; + if (rb_is_red(other)) + { + rb_set_black(other); + rb_set_red(parent); + __rb_rotate_right(parent, root); + other = parent->rb_left; + } + if ((!other->rb_left || rb_is_black(other->rb_left)) && + (!other->rb_right || rb_is_black(other->rb_right))) + { + rb_set_red(other); + node = parent; + parent = rb_parent(node); + } + else + { + if (!other->rb_left || rb_is_black(other->rb_left)) + { + rb_set_black(other->rb_right); + rb_set_red(other); + __rb_rotate_left(other, root); + other = parent->rb_left; + } + rb_set_color(other, rb_color(parent)); + rb_set_black(parent); + rb_set_black(other->rb_left); + __rb_rotate_right(parent, root); + node = root->rb_node; + break; + } + } + } + if (node) + rb_set_black(node); +} + +void rb_erase(struct px_rb_node *node, struct px_rb_root *root) +{ + struct px_rb_node *child, *parent; + int color; + + if (!node->rb_left) + child = node->rb_right; + else if (!node->rb_right) + child = node->rb_left; + else + { + struct px_rb_node *old = node, *left; + + node = node->rb_right; + while ((left = node->rb_left) != PX_RB_NULL) + node = left; + + if (rb_parent(old)) { + if (rb_parent(old)->rb_left == old) + rb_parent(old)->rb_left = node; + else + rb_parent(old)->rb_right = node; + } else + root->rb_node = node; + + child = node->rb_right; + parent = rb_parent(node); + color = rb_color(node); + + if (parent == old) { + parent = node; + } else { + if (child) + rb_set_parent(child, parent); + parent->rb_left = child; + + node->rb_right = old->rb_right; + rb_set_parent(old->rb_right, node); + } + + //node->rb_parent_color = old->rb_parent_color; + node->parent=old->parent; + node->color=old->color; + node->rb_left = old->rb_left; + rb_set_parent(old->rb_left, node); + + goto color; + } + + parent = rb_parent(node); + color = rb_color(node); + + if (child) + rb_set_parent(child, parent); + if (parent) + { + if (parent->rb_left == node) + parent->rb_left = child; + else + parent->rb_right = child; + } + else + root->rb_node = child; + + color: + if (color == RB_BLACK) + __rb_erase_color(child, parent, root); +} + +static void rb_augment_path(struct px_rb_node *node, rb_augment_f func, void *data) +{ + struct px_rb_node *parent; + +up: + func(node, data); + parent = rb_parent(node); + if (!parent) + return; + + if (node == parent->rb_left && parent->rb_right) + func(parent->rb_right, data); + else if (parent->rb_left) + func(parent->rb_left, data); + + node = parent; + goto up; +} + +/* + * after inserting @node into the tree, update the tree to account for + * both the new entry and any damage done by rebalance + */ +void rb_augment_insert(struct px_rb_node *node, rb_augment_f func, void *data) +{ + if (node->rb_left) + node = node->rb_left; + else if (node->rb_right) + node = node->rb_right; + + rb_augment_path(node, func, data); +} + +/* + * before removing the node, find the deepest node on the rebalance path + * that will still be there after @node gets removed + */ +struct px_rb_node *rb_augment_erase_begin(struct px_rb_node *node) +{ + struct px_rb_node *deepest; + + if (!node->rb_right && !node->rb_left) + deepest = rb_parent(node); + else if (!node->rb_right) + deepest = node->rb_left; + else if (!node->rb_left) + deepest = node->rb_right; + else { + deepest = rb_next(node); + if (deepest->rb_right) + deepest = deepest->rb_right; + else if (rb_parent(deepest) != node) + deepest = rb_parent(deepest); + } + + return deepest; +} + +/* + * after removal, update the tree to account for the removed entry + * and any rebalance damage. + */ +void rb_augment_erase_end(struct px_rb_node *node, rb_augment_f func, void *data) +{ + if (node) + rb_augment_path(node, func, data); +} + +/* + * This function returns the first node (in sort order) of the tree. + */ +struct px_rb_node *rb_first(const struct px_rb_root *root) +{ + struct px_rb_node *n; + + n = root->rb_node; + if (!n) + return PX_RB_NULL; + while (n->rb_left) + n = n->rb_left; + return n; +} + +struct px_rb_node *rb_last(const struct px_rb_root *root) +{ + struct px_rb_node *n; + + n = root->rb_node; + if (!n) + return PX_RB_NULL; + while (n->rb_right) + n = n->rb_right; + return n; +} + +struct px_rb_node *rb_next(const struct px_rb_node *node) +{ + struct px_rb_node *parent; + + if (rb_parent(node) == node) + return PX_RB_NULL; + + /* If we have a right-hand child, go down and then left as far + as we can. */ + if (node->rb_right) { + node = node->rb_right; + while (node->rb_left) + node=node->rb_left; + return (struct px_rb_node *)node; + } + + /* No right-hand children. Everything down and left is + smaller than us, so any 'next' node must be in the general + direction of our parent. Go up the tree; any time the + ancestor is a right-hand child of its parent, keep going + up. First time it's a left-hand child of its parent, said + parent is our 'next' node. */ + while ((parent = rb_parent(node)) && node == parent->rb_right) + node = parent; + + return parent; +} + +struct px_rb_node *rb_prev(const struct px_rb_node *node) +{ + struct px_rb_node *parent; + + if (rb_parent(node) == node) + return PX_RB_NULL; + + /* If we have a left-hand child, go down and then right as far + as we can. */ + if (node->rb_left) { + node = node->rb_left; + while (node->rb_right) + node=node->rb_right; + return (struct px_rb_node *)node; + } + + /* No left-hand children. Go up till we find an ancestor which + is a right-hand child of its parent */ + while ((parent = rb_parent(node)) && node == parent->rb_left) + node = parent; + + return parent; +} + +void rb_replace_node(struct px_rb_node *victim, struct px_rb_node *newnode, + struct px_rb_root *root) +{ + struct px_rb_node *parent = rb_parent(victim); + + /* Set the surrounding nodes to point to the replacement */ + if (parent) { + if (victim == parent->rb_left) + parent->rb_left = newnode; + else + parent->rb_right = newnode; + } else { + root->rb_node = newnode; + } + if (victim->rb_left) + rb_set_parent(victim->rb_left, newnode); + if (victim->rb_right) + rb_set_parent(victim->rb_right, newnode); + + /* Copy the pointers/colour from the victim to the replacement */ + *newnode = *victim; +} diff --git a/lib/PainterEngine/core/PX_rbtree.h b/lib/PainterEngine/core/PX_rbtree.h new file mode 100644 index 0000000000000000000000000000000000000000..9cf836d3908030c144780bcfc81adac3ce2e6f25 --- /dev/null +++ b/lib/PainterEngine/core/PX_rbtree.h @@ -0,0 +1,135 @@ + +/* + Red Black Trees + (C) 1999 Andrea Arcangeli + + 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 + + linux/include/linux/rbtree.h + + To use rbtrees you'll have to implement your own insert and search cores. + This will avoid us to use callbacks and to drop drammatically performances. + I know it's not the cleaner way, but in C (not in C++) to get + performances and genericity... + + Some example of insert and search follows here. The search is a plain + normal search over an ordered tree. The insert instead must be implemented + in two steps: First, the code must insert the element in order as a red leaf + in the tree, and then the support library function rb_insert_color() must + be called. Such function will do the not trivial work to rebalance the + rbtree, if necessary. + +----------------------------------------------------------------------- +*/ + +#ifndef _PX_RBTREE_H +#define _PX_RBTREE_H + +#undef PX_RB_NULL +#if defined(__cplusplus) + #define PX_RB_NULL 0 +#else + #define PX_RB_NULL ((void *)0) +#endif + +struct px_rb_node +{ +#define RB_RED 0 +#define RB_BLACK 1 + struct px_rb_node *parent; + unsigned long color; + struct px_rb_node *rb_right; + struct px_rb_node *rb_left; +}; + /* The alignment might seem pointless, but allegedly CRIS needs it */ + +struct px_rb_root +{ + struct px_rb_node *rb_node; +}; + + +//#define rb_parent(r) ((struct px_rb_node *)((r)->rb_parent_color & ~3)) +#define rb_parent(r) ((struct px_rb_node *)((r)->parent)) +//#define rb_color(r) ((r)->rb_parent_color & 1) +#define rb_color(r) ((r)->color) +#define rb_is_red(r) (!rb_color(r)) +#define rb_is_black(r) rb_color(r) +// #define rb_set_red(r) do { (r)->rb_parent_color &= ~1; } while (0) +// #define rb_set_black(r) do { (r)->rb_parent_color |= 1; } while (0) +#define rb_set_red(r) do { (r)->color = 0; } while (0) +#define rb_set_black(r) do { (r)->color = 1; } while (0) +static void rb_set_parent(struct px_rb_node *rb, struct px_rb_node *p) +{ + //rb->rb_parent_color = (rb->rb_parent_color & 3) | (unsigned long)p; + rb->parent = p; +} +static void rb_set_color(struct px_rb_node *rb, int color) +{ + //rb->rb_parent_color = (rb->rb_parent_color & ~1) | color; + rb->color = color; +} + +#define RB_ROOT (struct px_rb_root) { PX_RB_NULL, } + +#define RB_EMPTY_ROOT(root) ((root)->px_rb_node == PX_RB_NULL) +#define RB_EMPTY_NODE(node) (rb_parent(node) == node) +#define RB_CLEAR_NODE(node) (rb_set_parent(node, node)) + +static void rb_init_node(struct px_rb_node *rb) +{ + //rb->rb_parent_color = 0; + rb->parent=0; + rb->color=0; + rb->rb_right = PX_RB_NULL; + rb->rb_left = PX_RB_NULL; + RB_CLEAR_NODE(rb); +} + +extern void rb_insert_color(struct px_rb_node *, struct px_rb_root *); +extern void rb_erase(struct px_rb_node *, struct px_rb_root *); + +typedef void (*rb_augment_f)(struct px_rb_node *node, void *data); + +extern void rb_augment_insert(struct px_rb_node *node, + rb_augment_f func, void *data); +extern struct px_rb_node *rb_augment_erase_begin(struct px_rb_node *node); +extern void rb_augment_erase_end(struct px_rb_node *node, + rb_augment_f func, void *data); + +/* Find logical next and previous nodes in a tree */ +extern struct px_rb_node *rb_next(const struct px_rb_node *); +extern struct px_rb_node *rb_prev(const struct px_rb_node *); +extern struct px_rb_node *rb_first(const struct px_rb_root *); +extern struct px_rb_node *rb_last(const struct px_rb_root *); + +/* Fast replacement of a single node without remove/rebalance/add/rebalance */ +extern void rb_replace_node(struct px_rb_node *victim, struct px_rb_node *newnode, + struct px_rb_root *root); + +static void rb_link_node(struct px_rb_node * node, struct px_rb_node * parent, + struct px_rb_node ** rb_link) +{ +// node->rb_parent_color = (unsigned long )parent; + node->parent=parent; + node->color=0; + + node->rb_left = node->rb_right = PX_RB_NULL; + + *rb_link = node; +} + +#endif /* _LINUX_RBTREE_H */ + diff --git a/lib/PainterEngine/kernel/PX_2dxCommon.h b/lib/PainterEngine/kernel/PX_2dxCommon.h new file mode 100644 index 0000000000000000000000000000000000000000..023e3868dabcbdcee9e5e91e9eb0c4329a677faf --- /dev/null +++ b/lib/PainterEngine/kernel/PX_2dxCommon.h @@ -0,0 +1,40 @@ +#ifndef PX_2DXCOMMON_H +#define PX_2DXCOMMON_H +#include "../core/PX_Core.h" +typedef struct +{ + px_dword magic; + px_dword framecount; + px_dword animationCount; +}PX_2DX_Header; + + +typedef struct +{ + px_dword size; +}PX_2DX_CODE_Header; + +typedef enum +{ + PX_2DX_OPCODE_FRAME =1, + PX_2DX_OPCODE_SLEEP, + PX_2DX_OPCODE_GOTO, + PX_2DX_OPCODE_LOOP, + PX_2DX_OPCODE_END, +}PX_2DX_OPCODE; + +//Instrument format +//opcode 1byte +//other 3byte + +typedef struct +{ + px_word opcode; + px_word param; +}PX_2DX_INSTR; + +//frame [index] //opcode 1 byte //param 3 byte +//sleep [index] //opcode 1 byte //param 3 byte +//goto [index] //jmp addr 3 byte //loop times 4 byte + +#endif diff --git a/lib/PainterEngine/kernel/PX_3D_ObjData.c b/lib/PainterEngine/kernel/PX_3D_ObjData.c new file mode 100644 index 0000000000000000000000000000000000000000..0b08352ebe4059fee0cc0c03adf0ae5b48100001 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_3D_ObjData.c @@ -0,0 +1,356 @@ +#include "PX_3D_ObjData.h" + +static PX_LEXER_LEXEME_TYPE PX_3D_ObjectDataNextTokenSN(px_lexer *lexer) +{ + PX_LEXER_LEXEME_TYPE type; + while ((type= PX_LexerGetNextLexeme(lexer))==PX_LEXER_LEXEME_TYPE_SPACER||type==PX_LEXER_LEXEME_TYPE_NEWLINE); + + return type; +} + +px_bool PX_3D_ObjectDataInitialize(px_memorypool *mp,PX_3D_ObjectData *ObjectData) +{ + ObjectData->mp=mp; + + if(!PX_VectorInitialize(mp,&ObjectData->v,sizeof(PX_3D_ObjectData_v),8)) return PX_FALSE; + if(!PX_VectorInitialize(mp,&ObjectData->vt,sizeof(PX_3D_ObjectData_vt),8)) return PX_FALSE; + if(!PX_VectorInitialize(mp,&ObjectData->vn,sizeof(PX_3D_ObjectData_vn),8)) return PX_FALSE; + if(!PX_VectorInitialize(mp,&ObjectData->face,sizeof(PX_3D_ObjectDataFace),8)) return PX_FALSE; + if(!PX_VectorInitialize(mp,&ObjectData->mtlFile,sizeof(px_string),8)) return PX_FALSE; + if(!PX_VectorInitialize(mp,&ObjectData->mtlName,sizeof(px_string),8)) return PX_FALSE; + return PX_TRUE; +} + +px_bool PX_3D_ObjectDataLoad(PX_3D_ObjectData *ObjectData,const px_byte *data,px_int size) +{ + PX_LEXER_STATE state; + px_lexer Lexer; + PX_LEXER_LEXEME_TYPE type; + PX_LexerInit(&Lexer,ObjectData->mp); + PX_LexerRegisterSpacer(&Lexer,' '); + PX_LexerRegisterSpacer(&Lexer,'\t'); + PX_LexerRegisterComment(&Lexer,"#","\n"); + PX_LexerRegisterDelimiter(&Lexer,'/'); + PX_LexerSetTokenCase(&Lexer,PX_LEXER_LEXEME_CASE_LOWER); + + if(!PX_LexerLoadSourceFromMemory(&Lexer,(const char *)data)) return PX_FALSE; + + while (PX_TRUE) + { + type=PX_3D_ObjectDataNextTokenSN(&Lexer); + if (type==PX_LEXER_LEXEME_TYPE_TOKEN) + { + //g s o note:The flag is useless,we register it but not solve it + + if (PX_strequ(Lexer.CurLexeme.buffer,"g")\ + ||PX_strequ(Lexer.CurLexeme.buffer,"s")\ + ||PX_strequ(Lexer.CurLexeme.buffer,"o")) + { + while (PX_TRUE) + { + type=PX_LexerGetNextLexeme(&Lexer); + if (type==PX_LEXER_LEXEME_TYPE_NEWLINE||type==PX_LEXER_LEXEME_TYPE_END) + { + break; + } + } + continue; + } + + + if (PX_strequ(Lexer.CurLexeme.buffer,"mtllib")) + { + type=PX_3D_ObjectDataNextTokenSN(&Lexer); + if (type==PX_LEXER_LEXEME_TYPE_TOKEN) + { + px_string strName; + if(!PX_StringInitialize(ObjectData->mp,&strName)) + { + goto _ERROR; + } + PX_StringSet(&strName,Lexer.CurLexeme.buffer); + if(!PX_VectorPushback(&ObjectData->mtlFile,&strName)) goto _ERROR; + } + else + { + goto _ERROR; + } + continue; + } + + //usemtl + if (PX_strequ(Lexer.CurLexeme.buffer,"usemtl")) + { + type=PX_3D_ObjectDataNextTokenSN(&Lexer); + if (type==PX_LEXER_LEXEME_TYPE_TOKEN) + { + px_string strName; + if(!PX_StringInitialize(ObjectData->mp,&strName)) + { + goto _ERROR; + } + PX_StringSet(&strName,Lexer.CurLexeme.buffer); + if(!PX_VectorPushback(&ObjectData->mtlName,&strName)) goto _ERROR; + } + else + { + goto _ERROR; + } + continue; + } + + //v + if (PX_strequ(Lexer.CurLexeme.buffer,"v")) + { + px_int i; + px_float v[3]; + PX_3D_ObjectData_v ov; + + for (i=0;i<3;i++) + { + type=PX_3D_ObjectDataNextTokenSN(&Lexer); + if (!PX_LexerIsLememeIsNumeric(&Lexer)) + { + PX_LOG(" Numeric block is expected but not found"); + goto _ERROR; + } + v[i]=(px_float)PX_atof(Lexer.CurLexeme.buffer); + + } + ov.x=v[0]; + ov.y=v[1]; + ov.z=v[2]; + if(!PX_VectorPushback(&ObjectData->v,&ov)) goto _ERROR; + continue; + } + + //vn // + if (PX_strequ(Lexer.CurLexeme.buffer,"vn")) + { + px_int i; + px_float v[3]; + PX_3D_ObjectData_vn ov; + for (i=0;i<3;i++) + { + type=PX_3D_ObjectDataNextTokenSN(&Lexer); + if (!PX_LexerIsLememeIsNumeric(&Lexer)) + { + PX_LOG(" Numeric block is expected but not found"); + goto _ERROR; + } + v[i]=(px_float)PX_atof(Lexer.CurLexeme.buffer); + } + ov.x=v[0]; + ov.y=v[1]; + ov.z=v[2]; + if(!PX_VectorPushback(&ObjectData->vn,&ov)) goto _ERROR; + + + + continue; + } + + //vt + if (PX_strequ(Lexer.CurLexeme.buffer,"vt")) + { + px_int i; + px_float v[2]; + PX_3D_ObjectData_vt ov; + for (i=0;i<2;i++) + { + type=PX_3D_ObjectDataNextTokenSN(&Lexer); + if (!PX_LexerIsLememeIsNumeric(&Lexer)) + { + PX_LOG(" Numeric block is expected but not found"); + goto _ERROR; + } + v[i]=(px_float)PX_atof(Lexer.CurLexeme.buffer); + } + ov.u=v[0]; + ov.v=v[1]; + if(!PX_VectorPushback(&ObjectData->vt,&ov)) goto _ERROR; + + while (PX_TRUE) + { + type=PX_LexerGetNextLexeme(&Lexer); + if (type==PX_LEXER_LEXEME_TYPE_NEWLINE||type==PX_LEXER_LEXEME_TYPE_END) + { + break; + } + } + + continue; + } + + //f + PX_LexerGetState(&Lexer); + if (PX_strequ(Lexer.CurLexeme.buffer,"f")) + { + PX_3D_ObjectDataFace Face; + px_int v; + px_int i; + + // Face.mtlFileNameIndex=GetMtlFileIndex(); + Face.mtlNameIndex=ObjectData->mtlName.size-1; + Face.mtlFileNameIndex=ObjectData->mtlFile.size-1; + + for (i=0;i<3;i++) + { + Face.v[i].v=-1; + Face.v[i].vt=-1; + Face.v[i].vn=-1; + type=PX_3D_ObjectDataNextTokenSN(&Lexer); + if (!PX_LexerIsLememeIsNumeric(&Lexer)) + { + PX_LOG(" Numeric block is expected but not found"); + goto _ERROR; + } + v=PX_atoi(Lexer.CurLexeme.buffer); + + if(v>ObjectData->v.size) + goto _ERROR; + + Face.v[i].v=v; + + state=PX_LexerGetState(&Lexer); + type=PX_3D_ObjectDataNextTokenSN(&Lexer); + + // vt + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER&&Lexer.Symbol=='/') + { + state=PX_LexerGetState(&Lexer); + type=PX_3D_ObjectDataNextTokenSN(&Lexer); + if (PX_LexerIsLememeIsNumeric(&Lexer)) + { + v=PX_atoi(Lexer.CurLexeme.buffer); + if(v>ObjectData->vt.size) + goto _ERROR; + Face.v[i].vt=v; + } + else + { + PX_LexerSetState(state); + } + } + else + { + PX_LexerSetState(state); + continue; + } + + // vn + state=PX_LexerGetState(&Lexer); + type=PX_3D_ObjectDataNextTokenSN(&Lexer); + + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER&&Lexer.Symbol=='/') + { + state=PX_LexerGetState(&Lexer); + type=PX_3D_ObjectDataNextTokenSN(&Lexer); + if (PX_LexerIsLememeIsNumeric(&Lexer)) + { + v=PX_atoi(Lexer.CurLexeme.buffer); + if(v>ObjectData->vn.size) + goto _ERROR; + Face.v[i].vn=v; + } + else + { + PX_LexerSetState(state); + } + } + else + { + PX_LexerSetState(state); + continue; + } + + } + if(!PX_VectorPushback(&ObjectData->face,&Face)) goto _ERROR; + continue; + } + } + + if (type==PX_LEXER_LEXEME_TYPE_END) + { + break; + } + + goto _ERROR; + + } + PX_LexerFree(&Lexer); + return PX_TRUE; +_ERROR: + PX_3D_ObjectDataFree(ObjectData); + PX_LexerFree(&Lexer); + return PX_FALSE; +} + +px_bool PX_3D_ObjectDataToRenderList(PX_3D_ObjectData *ObjectData,PX_3D_RenderList *renderList) +{ + px_int i,j; + PX_3D_Face face; + PX_3D_ObjectDataFace *pObjFace; + for (i=0;iface.size;i++) + { + pObjFace=PX_VECTORAT(PX_3D_ObjectDataFace,&ObjectData->face,i); + PX_memset(&face,0,sizeof(PX_3D_Face)); + for (j=0;j<3;j++) + { + if(pObjFace->v[j].v>0&&pObjFace->v[j].v<=ObjectData->v.size) + { + PX_3D_ObjectData_v *pv=PX_VECTORAT(PX_3D_ObjectData_v,&ObjectData->v,pObjFace->v[j].v-1); + face.vertex[j].position=PX_POINT4D(pv->x,pv->y,pv->z); + } + else + goto _ERROR; + + if(pObjFace->v[j].vn>0&&pObjFace->v[j].vn<=ObjectData->vn.size) + { + PX_3D_ObjectData_vn *pvn=PX_VECTORAT(PX_3D_ObjectData_vn,&ObjectData->vn,pObjFace->v[j].vn-1); + face.vertex[j].normal=PX_POINT4D(pvn->x,pvn->y,pvn->z); + } + else + goto _ERROR; + + if(pObjFace->v[j].vt>0&&pObjFace->v[j].vt<=ObjectData->vt.size) + { + PX_3D_ObjectData_vt *pvt=PX_VECTORAT(PX_3D_ObjectData_vt,&ObjectData->vt,pObjFace->v[j].vt-1); + face.vertex[j].u=pvt->u; + face.vertex[j].v=pvt->v; + } + else + goto _ERROR; + + face.vertex[j].clr=PX_COLOR(255,0,0,0); + } + if(!PX_3D_RenderListPush(renderList,face)) + goto _ERROR; + } + return PX_TRUE; +_ERROR: + PX_3D_RenderListReset(renderList); + return PX_FALSE; +} + +px_void PX_3D_ObjectDataFree(PX_3D_ObjectData *ObjectData) +{ + px_int i; + PX_VectorFree(&ObjectData->v); + PX_VectorFree(&ObjectData->vt); + PX_VectorFree(&ObjectData->vn); + PX_VectorFree(&ObjectData->face); + for (i=0;imtlName.size;i++) + { + PX_StringFree(PX_VECTORAT(px_string,&ObjectData->mtlName,i)); + } + PX_VectorFree(&ObjectData->mtlName); + + for (i=0;imtlFile.size;i++) + { + PX_StringFree(PX_VECTORAT(px_string,&ObjectData->mtlFile,i)); + } + PX_VectorFree(&ObjectData->mtlFile); + +} + diff --git a/lib/PainterEngine/kernel/PX_3D_ObjData.h b/lib/PainterEngine/kernel/PX_3D_ObjData.h new file mode 100644 index 0000000000000000000000000000000000000000..4644174b442796406e3d233fa56b497856cfb0d9 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_3D_ObjData.h @@ -0,0 +1,50 @@ +#ifndef PX_3D_OBJDATA_H +#define PX_3D_OBJDATA_H +#include "PX_Lexer.h" + +typedef struct +{ + px_int v,vn,vt; +}PX_3D_ObjectDataVertex; + + +typedef struct +{ + px_uint mtlFileNameIndex; + px_uint mtlNameIndex; + PX_3D_ObjectDataVertex v[3]; +}PX_3D_ObjectDataFace; + + +typedef struct +{ + px_float x,y,z; +}PX_3D_ObjectData_v; + +typedef struct +{ + px_float x,y,z; +}PX_3D_ObjectData_vn; + +typedef struct +{ + px_float u,v; +}PX_3D_ObjectData_vt; + +typedef struct +{ + px_memorypool *mp; + px_vector v; + px_vector vt; + px_vector vn; + px_vector face; + px_vector mtlFile; + px_vector mtlName; +}PX_3D_ObjectData; + +px_bool PX_3D_ObjectDataInitialize(px_memorypool *mp,PX_3D_ObjectData *ObjectData); +px_bool PX_3D_ObjectDataLoad(PX_3D_ObjectData *ObjectData,const px_byte *data,px_int size); +px_bool PX_3D_ObjectDataToRenderList(PX_3D_ObjectData *ObjectData,PX_3D_RenderList *renderList); +px_void PX_3D_ObjectDataFree(PX_3D_ObjectData *ObjectData); + +#endif diff --git a/lib/PainterEngine/kernel/PX_Animation.c b/lib/PainterEngine/kernel/PX_Animation.c new file mode 100644 index 0000000000000000000000000000000000000000..67cbec54af33fcb398838aa51e6c576e623a3917 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Animation.c @@ -0,0 +1,483 @@ +#include "PX_Animation.h" + +px_bool PX_AnimationLibraryCreateFromMemory(px_memorypool *mp,PX_AnimationLibrary *panimation,px_byte *_2dxBuffer,px_uint size) +{ + PX_2DX_Header _header; + PX_TRaw_Header _trawheader; + px_int i,j; + px_byte *pbuffer; + px_uint reservedSize=size; + px_texture texture; + PX_2DX_CODE_Header _codeheader; + + _header=*(PX_2DX_Header *)_2dxBuffer; + if (!PX_memequ(&_header.magic,"2DX",sizeof(_header.magic))) + { + return PX_FALSE; + } + reservedSize-=sizeof(_header); + pbuffer=_2dxBuffer+sizeof(_header); + PX_VectorInitialize(mp,&panimation->animation,sizeof(PX_Animationlibrary_tagInfo),_header.animationCount); + for (i=0;i<(px_int)_header.animationCount;i++) + { + PX_Animationlibrary_tagInfo tag; + tag.ip=*(px_dword *)pbuffer; + pbuffer+=sizeof(px_dword); + PX_StringInitialize(mp,&tag.name); + PX_StringCat(&tag.name,(px_char *)pbuffer); + pbuffer+=PX_strlen((px_char *)pbuffer)+1; + PX_VectorPushback(&panimation->animation,&tag); + } + + + PX_VectorInitialize(mp,&panimation->frames,sizeof(px_texture),_header.framecount); + PX_MemoryInitialize(mp,&panimation->code); + for (i=0;i<(px_int)_header.framecount;i++) + { + for(j=0;jframes,&texture); + pbuffer+=PX_TRawGetSize(&_trawheader); + reservedSize-=PX_TRawGetSize(&_trawheader); + } + + if (reservedSizecode,pbuffer,_codeheader.size); + + return PX_TRUE; + + +_ERROR: + for (i=0;iframes.size;i++) + { + PX_TextureFree(PX_VECTORAT(px_texture,&panimation->frames,i)); + } + PX_VectorFree(&panimation->frames); + PX_MemoryFree(&panimation->code); + return PX_FALSE; +} + +px_void PX_AnimationLibraryFree(PX_AnimationLibrary *panimation) +{ + px_int i; + for (i=0;ianimation.size;i++) + { + PX_Animationlibrary_tagInfo *tagInfo=PX_VECTORAT(PX_Animationlibrary_tagInfo,&panimation->animation,i); + PX_StringFree(&tagInfo->name); + } + PX_VectorFree(&panimation->animation); + for (i=0;iframes.size;i++) + { + PX_TextureFree(PX_VECTORAT(px_texture,&panimation->frames,i)); + } + PX_VectorFree(&panimation->frames); + PX_MemoryFree(&panimation->code); +} + +px_void PX_AnimationUpdate(PX_Animation *panimation,px_uint elapsed) +{ + PX_2DX_INSTR *pInstr; + + if (!panimation->linker) + { + return; + } + if (panimation->reg_reservedTime>=elapsed) + { + panimation->reg_reservedTime-=elapsed; + return; + } + else + { + elapsed-=panimation->reg_reservedTime; + } + + while(elapsed) + { + if (panimation->ip>panimation->linker->code.usedsize-sizeof(PX_2DX_INSTR)) + { + PX_ERROR("2dx code error"); + return; + } + pInstr=(PX_2DX_INSTR *)(panimation->linker->code.buffer+panimation->ip); + switch(pInstr->opcode) + { + case PX_2DX_OPCODE_END: + return; + case PX_2DX_OPCODE_FRAME: + if(pInstr->paramlinker->frames.size) + panimation->reg_currentFrameIndex=pInstr->param; + else + { + PX_ERROR("2dx code error"); + return; + } + panimation->ip+=sizeof(PX_2DX_INSTR); + break; + case PX_2DX_OPCODE_GOTO: + + if(panimation->reg_loopTimes!=0) + { + panimation->ip=pInstr->param; + if(panimation->reg_loopTimes!=0xffff) + { + panimation->reg_loopTimes--; + } + } + else + panimation->ip+=sizeof(PX_2DX_INSTR); + + break; + case PX_2DX_OPCODE_LOOP: + panimation->reg_loopTimes=pInstr->param; + panimation->ip+=sizeof(PX_2DX_INSTR); + break; + case PX_2DX_OPCODE_SLEEP: + + if (pInstr->param>elapsed) + { + panimation->reg_reservedTime=pInstr->param-elapsed; + panimation->ip+=sizeof(PX_2DX_INSTR); + return; + } + else + { + elapsed-=pInstr->param; + panimation->ip+=sizeof(PX_2DX_INSTR); + } + break; + } + } +} + +px_void PX_AnimationRender(px_surface *psurface,PX_Animation *animation,px_int x,px_int y,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend) +{ + px_texture *pTexture; + if (!animation->linker) + { + return; + } + if(animation->reg_currentFrameIndex>=0&&animation->reg_currentFrameIndexlinker->frames.size) + { + pTexture=PX_VECTORAT(px_texture,&animation->linker->frames,animation->reg_currentFrameIndex); + PX_TextureRender(psurface,pTexture,x,y,refPoint,blend); + } +} + +px_void PX_AnimationRenderEx(px_surface *psurface,PX_Animation *animation,px_int x,px_int y,px_float scale,px_point direction,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend) +{ + px_texture *pTexture; + if (!animation->linker) + { + return; + } + if(animation->reg_currentFrameIndex>=0&&animation->reg_currentFrameIndexlinker->frames.size) + { + pTexture=PX_VECTORAT(px_texture,&animation->linker->frames,animation->reg_currentFrameIndex); + + if (scale!=1) + { + PX_TextureRenderEx_vector(psurface,pTexture,x,y,refPoint,blend,scale,direction); + } + else + { + PX_TextureRenderRotation_vector(psurface,pTexture,x,y,refPoint,blend,direction); + } + } +} + +px_void PX_AnimationRender_scale(px_surface *psurface,PX_Animation *animation,px_int x,px_int y,px_float scale,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend) +{ + px_texture *pTexture; + if (!animation->linker) + { + return; + } + if(animation->reg_currentFrameIndex>=0&&animation->reg_currentFrameIndexlinker->frames.size) + { + pTexture=PX_VECTORAT(px_texture,&animation->linker->frames,animation->reg_currentFrameIndex); + PX_TextureRenderEx(psurface,pTexture,x,y,refPoint,blend,scale,0); + } +} + + +px_void PX_AnimationRender_vector(px_surface *psurface,PX_Animation *animation,px_int x,px_int y,px_point direction,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend) +{ + px_texture *pTexture; + if (!animation->linker) + { + return; + } + if(animation->reg_currentFrameIndex>=0&&animation->reg_currentFrameIndexlinker->frames.size) + { + pTexture=PX_VECTORAT(px_texture,&animation->linker->frames,animation->reg_currentFrameIndex); + PX_TextureRenderRotation_vector(psurface,pTexture,x,y,refPoint,blend,direction); + } +} + + +px_int PX_AnimationLibraryGetFrameWidth(PX_AnimationLibrary *panimationLib,px_int frameIndex) +{ + return PX_VECTORAT(px_texture,&panimationLib->frames,frameIndex)->width; +} + + +px_int PX_AnimationLibraryGetFrameHeight(PX_AnimationLibrary *panimationLib,px_int frameIndex) +{ + return PX_VECTORAT(px_texture,&panimationLib->frames,frameIndex)->height; +} + +px_bool PX_AnimationCreate(PX_Animation *animation,PX_AnimationLibrary *linker) +{ + animation->elapsed=0; + animation->linker=linker; + animation->reg_currentFrameIndex=-1; + animation->reg_loopTimes=0; + animation->reg_reservedTime=0; + animation->reg_currentAnimation = -1; + animation->ip=0; + + return PX_TRUE; +} + +px_bool PX_AnimationSetLibrary(PX_Animation *animation,PX_AnimationLibrary *linker) +{ + PX_AnimationFree(animation); + animation->elapsed=0; + animation->linker=linker; + animation->reg_currentFrameIndex=-1; + animation->reg_loopTimes=0; + animation->reg_reservedTime=0; + animation->ip=0; + return PX_TRUE; +} + + + +px_void PX_AnimationFree(PX_Animation *animation) +{ + +} + +px_void PX_AnimationReset(PX_Animation *animation) +{ + animation->elapsed=0; + animation->reg_currentFrameIndex=-1; + animation->reg_loopTimes=0; + animation->reg_reservedTime=0; + animation->ip=0; +} + +px_bool PX_AnimationLibrary_CreateEffect_JumpVertical(px_memorypool *mp,PX_AnimationLibrary *panimation,px_texture *effectTexture) +{ + px_int i; + px_int volume=effectTexture->width*effectTexture->height; + px_int eff_height[6],eff_width[6]; + px_texture tex; + + PX_VectorInitialize(mp,&panimation->frames,sizeof(px_texture),6); + PX_MemoryInitialize(mp,&panimation->code); + PX_MemoryResize(&panimation->code,sizeof(PX_2DX_INSTR)*13); + + PX_AnimationLibraryAddInstr(panimation,PX_2DX_OPCODE_FRAME,0); + PX_AnimationLibraryAddInstr(panimation,PX_2DX_OPCODE_SLEEP,50); + PX_AnimationLibraryAddInstr(panimation,PX_2DX_OPCODE_FRAME,1); + PX_AnimationLibraryAddInstr(panimation,PX_2DX_OPCODE_SLEEP,50); + PX_AnimationLibraryAddInstr(panimation,PX_2DX_OPCODE_FRAME,2); + PX_AnimationLibraryAddInstr(panimation,PX_2DX_OPCODE_SLEEP,50); + PX_AnimationLibraryAddInstr(panimation,PX_2DX_OPCODE_FRAME,3); + PX_AnimationLibraryAddInstr(panimation,PX_2DX_OPCODE_SLEEP,50); + PX_AnimationLibraryAddInstr(panimation,PX_2DX_OPCODE_FRAME,4); + PX_AnimationLibraryAddInstr(panimation,PX_2DX_OPCODE_SLEEP,50); + PX_AnimationLibraryAddInstr(panimation,PX_2DX_OPCODE_FRAME,5); + PX_AnimationLibraryAddInstr(panimation,PX_2DX_OPCODE_SLEEP,50); + PX_AnimationLibraryAddInstr(panimation,PX_2DX_OPCODE_END,0); + + eff_height[0]=(px_int)(effectTexture->height*0.2); + eff_height[1]=(px_int)(effectTexture->height*0.25); + eff_height[2]=(px_int)(effectTexture->height*0.45); + eff_height[3]=(px_int)(effectTexture->height*1.25); + eff_height[4]=(px_int)(effectTexture->height*1.15); + eff_height[5]=(px_int)(effectTexture->height*1); + + for(i=0;i<6;i++) + { + eff_width[i]=volume/eff_height[i]; + if (eff_width[i]>effectTexture->width*2) + { + eff_width[i]=(px_int)(eff_width[i]*0.4); + } + if(!PX_TextureCreateScale(mp,effectTexture,eff_width[i],eff_height[i],&tex)) + { + PX_AnimationLibraryFree(panimation); + return PX_FALSE; + } + PX_VectorPushback(&panimation->frames,&tex); + } + return PX_TRUE; +} + +px_void PX_AnimationLibraryAddInstr(PX_AnimationLibrary *panimationLib,PX_2DX_OPCODE opcode,px_word param) +{ + PX_2DX_INSTR instr; + instr.opcode=opcode; + instr.param=param; + PX_MemoryCat(&panimationLib->code,&instr,sizeof(PX_2DX_INSTR)); +} + +px_bool PX_AnimationIsEnd(PX_Animation *panimation) +{ + if (!panimation->linker) + { + return PX_TRUE; + } + return (((PX_2DX_INSTR *)(panimation->linker->code.buffer+panimation->ip))->opcode==PX_2DX_OPCODE_END); +} + + +px_rect PX_AnimationGetSize(PX_Animation *panimation) +{ + px_rect rect; + px_int i,w=0,h=0; + px_texture *pTexture; + if (!panimation->linker) + { + rect.x=0; + rect.y=0; + rect.height=0; + rect.width=0; + return rect; + } + for (i=0;ilinker->frames.size;i++) + { + pTexture=PX_VECTORAT(px_texture,&panimation->linker->frames,i); + if (wwidth) + { + w=pTexture->width; + } + if (hheight) + { + h=pTexture->height; + } + } + rect.x=0; + rect.y=0; + rect.height=(px_float)h; + rect.width=(px_float)w; + return rect; +} + + +px_texture * PX_AnimationGetCurrentTexture(PX_Animation *panimation) +{ + return PX_VECTORAT(px_texture,&panimation->linker->frames,panimation->reg_currentFrameIndex); +} + +px_void PX_AnimationRenderRotation(px_surface *psurface,PX_Animation *animation,px_point position,px_int angle,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend) +{ + px_texture *pTexture; + if (!animation->linker) + { + return; + } + if(animation->reg_currentFrameIndex>=0&&animation->reg_currentFrameIndexlinker->frames.size) + { + pTexture=PX_VECTORAT(px_texture,&animation->linker->frames,animation->reg_currentFrameIndex); + PX_TextureRenderRotation(psurface,pTexture,(px_int)position.x,(px_int)position.y,refPoint,blend,angle); + } +} + +px_int PX_AnimationGetAnimationsCount(PX_Animation *animation) +{ + if(animation->linker) + return animation->linker->frames.size; + else + return 0; +} + +px_dword PX_AnimationGetCurrentPlayAnimation(PX_Animation *animation) +{ + return animation->reg_currentAnimation; +} + +px_bool PX_AnimationSetCurrentPlayAnimation(PX_Animation *animation,px_int i) +{ + if(animation->linker) + if (i>=0&&ilinker->animation.size) + { + PX_Animationlibrary_tagInfo *tag=PX_VECTORAT(PX_Animationlibrary_tagInfo,&animation->linker->animation,i); + animation->ip=tag->ip; + animation->reg_currentAnimation=i; + return PX_TRUE; + } + return PX_FALSE; +} + +px_bool PX_AnimationSetCurrentPlayAnimationByName(PX_Animation *animation,const px_char *name) +{ + px_int i; + if(animation->linker) + for (i=0;ilinker->animation.size;i++) + { + PX_Animationlibrary_tagInfo *tag=PX_VECTORAT(PX_Animationlibrary_tagInfo,&animation->linker->animation,i); + if (PX_strequ2(name,tag->name.buffer)) + { + animation->ip=tag->ip; + animation->reg_reservedTime=0; + animation->reg_currentAnimation= i; + return PX_TRUE; + } + } + return PX_FALSE; +} + +px_int PX_AnimationLibraryGetPlayAnimationIndexByName(PX_AnimationLibrary* pLib, const px_char* name) +{ + px_int i; + if (pLib) + for (i = 0; i < pLib->animation.size; i++) + { + PX_Animationlibrary_tagInfo* tag = PX_VECTORAT(PX_Animationlibrary_tagInfo, &pLib->animation, i); + if (PX_strequ2(name, tag->name.buffer)) + { + return i; + } + } + return -1; +} + + +px_int PX_AnimationGetPlayAnimationIndexByName(PX_Animation *animation,const px_char *name) +{ + px_int i; + if(animation->linker) + for (i=0;ilinker->animation.size;i++) + { + PX_Animationlibrary_tagInfo *tag=PX_VECTORAT(PX_Animationlibrary_tagInfo,&animation->linker->animation,i); + if (PX_strequ(name,tag->name.buffer)) + { + return i; + } + } + return -1; +} diff --git a/lib/PainterEngine/kernel/PX_Animation.h b/lib/PainterEngine/kernel/PX_Animation.h new file mode 100644 index 0000000000000000000000000000000000000000..148e7045eafac38267a7fda6b23d9fa970b4109f --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Animation.h @@ -0,0 +1,56 @@ +#ifndef PX_ANIMATION_H +#define PX_ANIMATION_H +#include "PX_2dxCommon.h" +typedef struct +{ + px_vector frames; //vector frames + px_vector animation; + px_memory code; +}PX_AnimationLibrary; + +typedef struct +{ + px_uint elapsed; + px_uint ip; + px_uint reg_loopTimes; + px_uint reg_reservedTime; + px_int reg_currentFrameIndex; + px_dword reg_currentAnimation; + PX_AnimationLibrary *linker; +}PX_Animation; + +typedef struct +{ + px_dword ip; + px_string name; //image file path +}PX_Animationlibrary_tagInfo; + +px_bool PX_AnimationCreate(PX_Animation *animation,PX_AnimationLibrary *linker); +px_bool PX_AnimationSetLibrary(PX_Animation *animation,PX_AnimationLibrary *linker); +px_int PX_AnimationLibraryGetPlayAnimationIndexByName(PX_AnimationLibrary* pLib, const px_char* name); +px_void PX_AnimationLibraryAddInstr(PX_AnimationLibrary *panimationLib,PX_2DX_OPCODE opcode,px_word param); +px_void PX_AnimationLibraryFree(PX_AnimationLibrary *panimationLib); +px_int PX_AnimationGetAnimationsCount(PX_Animation *animation); +px_dword PX_AnimationGetCurrentPlayAnimation(PX_Animation *animation); +px_bool PX_AnimationSetCurrentPlayAnimation(PX_Animation *animation,px_int i); +px_bool PX_AnimationSetCurrentPlayAnimationByName(PX_Animation *animation,const px_char *name); +px_int PX_AnimationGetPlayAnimationIndexByName(PX_Animation* animation, const px_char* name); +px_void PX_AnimationFree(PX_Animation *animation); +px_void PX_AnimationReset(PX_Animation *animation); +px_void PX_AnimationUpdate(PX_Animation *panimation,px_uint elapsed); +px_bool PX_AnimationIsEnd(PX_Animation *panimation); +px_rect PX_AnimationGetSize(PX_Animation *panimation); +px_texture *PX_AnimationGetCurrentTexture(PX_Animation *panimation); +px_void PX_AnimationRenderRotation(px_surface *psurface,PX_Animation *animation,px_point position,px_int angle,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend); +px_void PX_AnimationRender(px_surface *psurface,PX_Animation *animation,px_int x,px_int y,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend); +px_void PX_AnimationRenderEx(px_surface *psurface,PX_Animation *animation,px_int x,px_int y,px_float scale,px_point direction,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend); +px_void PX_AnimationRender_scale(px_surface *psurface,PX_Animation *animation,px_int x,px_int y,px_float scale,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend); +px_void PX_AnimationRender_vector(px_surface *psurface,PX_Animation *animation,px_int x,px_int y,px_point direction,PX_ALIGN refPoint,PX_TEXTURERENDER_BLEND *blend); + +//Create Animation from 2dx data +px_int PX_AnimationLibraryGetFrameWidth(PX_AnimationLibrary *panimationLib,px_int frameIndex); +px_int PX_AnimationLibraryGetFrameHeight(PX_AnimationLibrary *panimationLib,px_int frameIndex); +px_bool PX_AnimationLibraryCreateFromMemory(px_memorypool *mp,PX_AnimationLibrary *panimationLib,px_byte *_2dxBuffer,px_uint size); +px_bool PX_AnimationLibrary_CreateEffect_JumpVertical(px_memorypool *mp,PX_AnimationLibrary *panimation,px_texture *effectTexture); +#endif + diff --git a/lib/PainterEngine/kernel/PX_Compiler.c b/lib/PainterEngine/kernel/PX_Compiler.c new file mode 100644 index 0000000000000000000000000000000000000000..8aaa9f827df2a5e7ae138475bd6c9119fb7c0d3f --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Compiler.c @@ -0,0 +1,50 @@ +#include "PX_Compiler.h" + +px_bool PX_CompilerInitialize(px_memorypool *mp,PX_Compiler *compiler) +{ + compiler->mp=mp; + if(!PX_ScriptCompilerInitialize(&compiler->lib,mp)) + { + return PX_FALSE; + } + return PX_TRUE; +} + +px_bool PX_CompilerAddSource(PX_Compiler *compiler,const px_char script[]) +{ + if(!PX_ScriptCompilerLoad(&compiler->lib,script)) + { + return PX_FALSE; + } + return PX_TRUE; + +} + +px_bool PX_CompilerCompile(PX_Compiler *compiler,px_memory *bin,const px_char entryScript[]) +{ + + px_string asmcodeString; + + PX_StringInitialize(compiler->mp,&asmcodeString); + if(PX_ScriptCompilerCompile(&compiler->lib,entryScript,&asmcodeString,128)) + { + PX_ScriptAsmOptimization(&asmcodeString); + + if(!PX_ScriptAsmCompile(compiler->mp,asmcodeString.buffer,bin)) + { + return PX_FALSE; + } + PX_StringFree(&asmcodeString); + return PX_TRUE; + } + + PX_StringFree(&asmcodeString); + + return PX_FALSE; +} + +px_void PX_CompilerFree(PX_Compiler *compiler) +{ + PX_ScriptCompilerFree(&compiler->lib); +} + diff --git a/lib/PainterEngine/kernel/PX_Compiler.h b/lib/PainterEngine/kernel/PX_Compiler.h new file mode 100644 index 0000000000000000000000000000000000000000..86e106d49e327eb1e1ca680aba869e0d43a2ec9f --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Compiler.h @@ -0,0 +1,17 @@ +#ifndef PX_COMPILER_H +#define PX_COMPILER_H + +#include "PX_Script_Interpreter.h" +#include "PX_Script_ASMCompiler.h" +#include "PX_Script_VM.h" +typedef struct +{ + px_memorypool *mp; + PX_SCRIPT_LIBRARY lib; +}PX_Compiler; + +px_bool PX_CompilerInitialize(px_memorypool *mp,PX_Compiler *compiler); +px_bool PX_CompilerAddSource(PX_Compiler *compiler,const px_char script[]); +px_bool PX_CompilerCompile(PX_Compiler *compiler,px_memory *bin,const px_char entryScript[]); +px_void PX_CompilerFree(PX_Compiler *compiler); +#endif diff --git a/lib/PainterEngine/kernel/PX_Json.c b/lib/PainterEngine/kernel/PX_Json.c new file mode 100644 index 0000000000000000000000000000000000000000..7ea3f5316e04f001e0795ea991a6126dfc76e9c0 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Json.c @@ -0,0 +1,1170 @@ +#include "PX_Json.h" +static px_uint json_quotes; + +px_bool PX_JsonInterpret_Object(PX_Json *pjson,px_lexer *lexer,PX_Json_Object *json_Object); +px_bool PX_JsonInterpret_Value(PX_Json *pjson,px_lexer *lexer,PX_Json_Value *_value,px_bool arrayElement); +px_void PX_JsonFreeValue(PX_Json *pjson,PX_Json_Value *json_Value); + +PX_LEXER_LEXEME_TYPE PX_JsonNextToken(px_lexer *lexer) +{ + PX_LEXER_LEXEME_TYPE type; + while ((type= PX_LexerGetNextLexeme(lexer))==PX_LEXER_LEXEME_TYPE_SPACER||type==PX_LEXER_LEXEME_TYPE_NEWLINE); + + return type; +} + +PX_Json_Value * PX_JsonGetObjectValue(PX_Json_Value *json_value,const px_char name[]) +{ + px_int i; + if (json_value->type!=PX_JSON_VALUE_TYPE_OBJECT) + { + return PX_NULL; + } + for (i=0;i_object.values.size;i++) + { + PX_Json_Value *pValue=PX_LISTAT(PX_Json_Value,&json_value->_object.values,i); + if (PX_strequ(name,pValue->name.buffer)) + { + return pValue; + } + } + return PX_NULL; +} + +PX_Json_Value * PX_JsonGetObjectValueByIndex(PX_Json_Value *json_value,px_int i) +{ + if (i<0||i>=json_value->_object.values.size) + { + return PX_NULL; + } + return PX_LISTAT(PX_Json_Value,&json_value->_object.values,i); +} + +PX_Json_Value * PX_JsonGetValue(PX_Json *json,const px_char _payload[]) +{ + px_int r_offset=0; + px_int s_offset=0; + px_char payload[256]={0}; + px_char *lexeme=PX_NULL; + px_int i=0,array=-1; + + PX_Json_Value * it=&json->rootValue; + if (PX_strlen(_payload)>=sizeof(payload)) + { + return PX_NULL; + } + PX_strset(payload,_payload); + + while (payload[r_offset]!=0) + { + + while (PX_TRUE) + { + if (payload[s_offset]=='.') + { + payload[s_offset]='\0'; + s_offset++; + break; + } + if (payload[s_offset]=='\0') + { + break; + } + s_offset++; + } + + lexeme=payload+r_offset; + i=PX_strlen(lexeme); + //array? + if (lexeme[i-1]==']') + { + + lexeme[i-1]='\0'; + i--; + while (i>0) + { + if (lexeme[i]=='[') + { + lexeme[i]='\0'; + array=PX_atoi(lexeme+i+1); + break; + } + i--; + } + } + else + { + array=-1; + } + if (array!=-1) + { + it=PX_JsonGetObjectValue(it,lexeme); + if (it&&it->type==PX_JSON_VALUE_TYPE_ARRAY) + { + it=PX_JsonGetArrayValue(it,array); + } + else + { + return PX_NULL; + } + + } + else + { + it=PX_JsonGetObjectValue(it,lexeme); + } + + r_offset=s_offset; + if (!it) + { + break; + } + + } + return it; +} + +PX_Json_Value * PX_JsonGetArrayValue(PX_Json_Value *value,px_int i) +{ + if (value->type!=PX_JSON_VALUE_TYPE_ARRAY) + { + return PX_NULL; + } + if (i_array.size) + { + return PX_LISTAT(PX_Json_Value,&value->_array,i); + } + return PX_NULL; +} + +px_bool PX_JsonInitialize(px_memorypool *mp,PX_Json *pjson) +{ + PX_memset(pjson,0,sizeof(PX_Json)); + pjson->mp=mp; + pjson->rootValue.type=PX_JSON_VALUE_TYPE_OBJECT; + PX_StringInitialize(mp,&pjson->rootValue.name); + PX_ListInitialize(pjson->mp,&pjson->rootValue._object.values); + return PX_TRUE; +} + + + +static px_bool PX_JsonInterpret_Value_Array(PX_Json *pjson,px_lexer *lexer,PX_Json_Value *_value) +{ + PX_LEXER_LEXEME_TYPE type; + PX_Json_Value array_value; + PX_LEXER_STATE state; + px_int i; + type=PX_JsonNextToken(lexer); + + if (type!=PX_LEXER_LEXEME_TYPE_DELIMITER||lexer->Symbol!='[') + goto _ERROR; + + while (PX_TRUE) + { + state=PX_LexerGetState(lexer); + type=PX_JsonNextToken(lexer); + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER) + { + if(lexer->Symbol==']') + { + return PX_TRUE; + } + + if(lexer->Symbol!='{') + { + goto _ERROR; + } + } + + PX_LexerSetState(state); + if (!PX_JsonInterpret_Value(pjson,lexer,&array_value,PX_TRUE)) + { + goto _ERROR; + } + + if(!PX_ListPush(&_value->_array,&array_value,sizeof(array_value))) + goto _ERROR; + + type=PX_JsonNextToken(lexer); + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER) + { + if (lexer->Symbol==',') + { + continue; + } + + if (lexer->Symbol==']') + { + return PX_TRUE; + } + goto _ERROR; + } + else + { + goto _ERROR; + } + + } +_ERROR: + for (i=0;i<_value->_array.size;i++) + { + PX_JsonFreeValue(pjson,PX_LISTAT(PX_Json_Value,&_value->_array,i)); + } + PX_ListFree(&_value->_array); + return PX_FALSE; +} + + + + + + +px_bool PX_JsonInterpret_Value(PX_Json *pjson,px_lexer *lexer,PX_Json_Value *_value,px_bool arrayElement) +{ + PX_LEXER_STATE state; + PX_LEXER_LEXEME_TYPE type; + + + PX_memset(_value,0,sizeof(PX_Json_Value)); + PX_StringInitialize(pjson->mp,&_value->name); + if (!arrayElement) + { + type=PX_JsonNextToken(lexer); + if (type!=PX_LEXER_LEXEME_TYPE_CONATINER)//{name + { + goto _ERROR; + } + PX_LexerGetIncludedString(lexer,&lexer->CurLexeme); + PX_StringCopy(&_value->name,&lexer->CurLexeme); + + type=PX_JsonNextToken(lexer); + if (type!=PX_LEXER_LEXEME_TYPE_DELIMITER||lexer->Symbol!=':')//{\spacer name : + { + goto _ERROR; + } + } + + state=PX_LexerGetState(lexer); + type=PX_JsonNextToken(lexer); + + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER) + { + if(lexer->Symbol=='[') + { + PX_LexerSetState(state); + _value->type=PX_JSON_VALUE_TYPE_ARRAY; + PX_ListInitialize(pjson->mp,&_value->_array); + if(!PX_JsonInterpret_Value_Array(pjson,lexer,_value)) + { + + goto _ERROR; + } + else + return PX_TRUE; + } + else + if(lexer->Symbol=='{') + { + PX_LexerSetState(state); + _value->type=PX_JSON_VALUE_TYPE_OBJECT; + if(!PX_JsonInterpret_Object(pjson,lexer,&_value->_object)) + { + return PX_FALSE; + } + return PX_TRUE; + + } + + goto _ERROR; + + } + else + { + if (type==PX_LEXER_LEXEME_TYPE_TOKEN) + { + if(PX_StringIsNumeric(&lexer->CurLexeme)) + { + _value->type=PX_JSON_VALUE_TYPE_NUMBER; + _value->_number=PX_atof(lexer->CurLexeme.buffer); + return PX_TRUE; + } + + if(PX_strequ(lexer->CurLexeme.buffer,"true")) + { + _value->type=PX_JSON_VALUE_TYPE_BOOLEAN; + _value->_boolean=PX_TRUE; + return PX_TRUE; + } + + if(PX_strequ(lexer->CurLexeme.buffer,"false")) + { + _value->type=PX_JSON_VALUE_TYPE_BOOLEAN; + _value->_boolean=PX_FALSE; + return PX_TRUE; + } + + if(PX_strequ(lexer->CurLexeme.buffer,"null")) + { + _value->type=PX_JSON_VALUE_TYPE_NULL; + return PX_TRUE; + } + + if (PX_strlen(lexer->CurLexeme.buffer)>=3) + { + if (lexer->CurLexeme.buffer[0]=='0'&&(lexer->CurLexeme.buffer[1]=='x'||lexer->CurLexeme.buffer[1]=='X')) + { + _value->type=PX_JSON_VALUE_TYPE_NUMBER; + _value->_number=(px_dword)PX_htoi(lexer->CurLexeme.buffer+2); + return PX_TRUE; + } + } + } + else if(type==PX_LEXER_LEXEME_TYPE_CONATINER&&lexer->CurrentContainerType==json_quotes) + { + px_int i; + _value->type=PX_JSON_VALUE_TYPE_STRING; + if(!PX_StringInitialize(pjson->mp,&_value->_string))goto _ERROR;; + PX_LexerGetIncludedString(lexer,&lexer->CurLexeme); + + if(!PX_StringCopy(&_value->_string,&lexer->CurLexeme)) + { + PX_StringFree(&_value->_string); + goto _ERROR; + } + + for (i=0;_value->_string.buffer[i];i++) + { + if (_value->_string.buffer[i]=='\\') + { + if (_value->_string.buffer[i+1]=='\\') + { + PX_StringRemoveChar(&_value->_string,i+1); + } + if (_value->_string.buffer[i+1]=='n') + { + _value->_string.buffer[i]='\n'; + PX_StringRemoveChar(&_value->_string,i+1); + } + if (_value->_string.buffer[i+1]=='r') + { + _value->_string.buffer[i]='\r'; + PX_StringRemoveChar(&_value->_string,i+1); + } + if (_value->_string.buffer[i+1]=='t') + { + _value->_string.buffer[i]='\t'; + PX_StringRemoveChar(&_value->_string,i+1); + } + } + } + return PX_TRUE; + } + + goto _ERROR; + + } +_ERROR: + PX_StringFree(&_value->name); + return PX_FALSE; +} + +px_bool PX_JsonInterpret_Object(PX_Json *pjson,px_lexer *lexer,PX_Json_Object *json_Object) +{ + PX_LEXER_LEXEME_TYPE type; + PX_Json_Value _value; + PX_LEXER_STATE state; + px_int i; + PX_memset(json_Object,0,sizeof(PX_Json_Object)); + + if (!json_Object->values.mp) + { + PX_ListInitialize(pjson->mp,&json_Object->values); + } + + + while (PX_TRUE) + { + type=PX_JsonNextToken(lexer); + if (type==PX_LEXER_LEXEME_TYPE_END) + { + goto _ERROR; + } + + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER&&lexer->Symbol=='{')//{ + { + state=PX_LexerGetState(lexer); + type=PX_JsonNextToken(lexer); + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER&&lexer->Symbol=='}')//{} + { + return PX_TRUE; + } + else + { + PX_LexerSetState(state); + while (PX_TRUE) + { + + + if (!PX_JsonInterpret_Value(pjson,lexer,&_value,PX_FALSE)) + { + goto _ERROR; + } + + if(!PX_ListPush(&json_Object->values,&_value,sizeof(_value))) + goto _ERROR; + + type=PX_JsonNextToken(lexer); + if (type!=PX_LEXER_LEXEME_TYPE_DELIMITER) + { + goto _ERROR; + } + + if (lexer->Symbol=='}') + { + return PX_TRUE; + } + else if(lexer->Symbol==',') + { + continue; + } + else + { + PX_StringFree(&_value.name); + goto _ERROR; + } + } + } + } + } +_ERROR: + ////////////////////////////////////////////////////////////////////////// + //remove object + + for (i=0;ivalues.size;i++) + { + PX_JsonFreeValue(pjson,PX_LISTAT(PX_Json_Value,&json_Object->values,i)); + } + PX_ListFree(&json_Object->values); + + return PX_FALSE; +} + +px_bool PX_JsonParse(PX_Json *pjson,const px_char *json_content) +{ + px_lexer lexer; + + PX_LexerInit(&lexer,pjson->mp); + PX_LexerRegisterDelimiter(&lexer,','); + PX_LexerRegisterDelimiter(&lexer,':'); + PX_LexerRegisterDelimiter(&lexer,'{'); + PX_LexerRegisterDelimiter(&lexer,'}'); + PX_LexerRegisterDelimiter(&lexer,'['); + PX_LexerRegisterDelimiter(&lexer,']'); + PX_LexerRegisterSpacer(&lexer,' '); + PX_LexerRegisterSpacer(&lexer,'\t'); + PX_LexerRegisterComment(&lexer,"//","\n"); + json_quotes=PX_LexerRegisterContainer(&lexer,"\"","\""); + if(!PX_LexerLoadSourceFromMemory(&lexer,json_content)) goto _ERROR; + + if(!PX_JsonInterpret_Object(pjson,&lexer,&pjson->rootValue._object)) + goto _ERROR; + PX_LexerFree(&lexer); + return PX_TRUE; +_ERROR: + PX_LexerFree(&lexer); + return PX_FALSE; +} + +px_bool PX_JsonBuild_Value(PX_Json_Value *pValue,px_string *_out,px_bool bArrayValue) +{ + if (!bArrayValue) + { + //name + if(!PX_StringCatCharEx(_out,'"'))return PX_FALSE; + if(!PX_StringCatEx(_out,pValue->name.buffer)) return PX_FALSE; + if(!PX_StringCatCharEx(_out,'"'))return PX_FALSE; + //: + if(!PX_StringCatCharEx(_out,':')) return PX_FALSE; + } + + switch(pValue->type) + { + case PX_JSON_VALUE_TYPE_ARRAY: + { + px_int i; + if(!PX_StringCatCharEx(_out,'['))return PX_FALSE; + for (i=0;i_array.size;i++) + { + PX_Json_Value *pv=PX_LISTAT(PX_Json_Value,&pValue->_array,i); + if(!PX_JsonBuild_Value(pv,_out,PX_TRUE))return PX_FALSE; + if(i!=pValue->_array.size-1)if(!PX_StringCatCharEx(_out,','))return PX_FALSE; + } + if(!PX_StringCatCharEx(_out,']'))return PX_FALSE; + } + break; + case PX_JSON_VALUE_TYPE_BOOLEAN: + { + if (pValue->_boolean) + { + if(!PX_StringCatEx(_out,"true"))return PX_FALSE; + } + else + { + if(!PX_StringCatEx(_out,"false"))return PX_FALSE; + } + } + break; + case PX_JSON_VALUE_TYPE_NULL: + { + if(!PX_StringCatEx(_out,"null"))return PX_FALSE; + } + break; + case PX_JSON_VALUE_TYPE_NUMBER: + { + if(!PX_StringCatEx(_out,PX_ftos((px_float)pValue->_number,6).data))return PX_FALSE; + } + break; + case PX_JSON_VALUE_TYPE_STRING: + { + if(!PX_StringCatEx(_out,"\""))return PX_FALSE; + if(!PX_StringCatEx(_out,pValue->_string.buffer))return PX_FALSE; + if(!PX_StringCatEx(_out,"\""))return PX_FALSE; + } + break; + case PX_JSON_VALUE_TYPE_OBJECT: + { + px_int i; + if(!PX_StringCatEx(_out,"{\n")) return PX_FALSE; + for (i=0;i_object.values.size;i++) + { + PX_Json_Value *ptmpValue=PX_LISTAT(PX_Json_Value,&pValue->_object.values,i); + if(!PX_JsonBuild_Value(ptmpValue,_out,PX_FALSE))return PX_FALSE; + if(i!=pValue->_object.values.size-1)if(!PX_StringCatEx(_out,",")) return PX_FALSE; + if(!PX_StringCatEx(_out,"\n")) return PX_FALSE; + } + if(!PX_StringCatEx(_out,"}")) return PX_FALSE; + } + break; + } + return PX_TRUE; +} + + +px_bool PX_JsonBuild(PX_Json *pjson,px_string *_out) +{ + PX_StringUpdateExReg(_out); + return PX_JsonBuild_Value(&pjson->rootValue,_out,PX_TRUE); +} + +static px_void PX_JsonDeleteValue(PX_Json *pjson,PX_Json_Value *pValue) +{ + switch (pValue->type) + { + case PX_JSON_VALUE_TYPE_ARRAY: + { + px_int i; + for (i=0;i_array.size;i++) + { + PX_Json_Value *pSubValue=PX_LISTAT(PX_Json_Value,&pValue->_array,i); + PX_JsonDeleteValue(pjson,pSubValue); + } + PX_ListFree(&pValue->_array); + } + break; + case PX_JSON_VALUE_TYPE_OBJECT: + { + px_int i; + for (i=0;i_object.values.size;i++) + { + PX_Json_Value *pSubValue=PX_LISTAT(PX_Json_Value,&pValue->_object.values,i); + PX_JsonDeleteValue(pjson,pSubValue); + } + PX_ListFree(&pValue->_object.values); + } + break; + case PX_JSON_VALUE_TYPE_STRING: + { + PX_StringFree(&pValue->_string); + } + break; + default: + break; + } +} + + +px_void PX_JsonDelete(PX_Json *pjson,const px_char _payload[]) +{ + px_int i; + PX_Json_Value *pParentValue,*pValue; + px_char payload[256]={0}; + + + if (PX_strlen(_payload)>=sizeof(payload)) + { + return; + } + + pValue=PX_JsonGetValue(pjson,_payload); + if (!pValue) + { + return; + } + + PX_strset(payload,_payload); + + if (payload[PX_strlen(payload)-1]==']') + { + //array + for (i=PX_strlen(payload);i>0;i--) + { + if (payload[i]=='[') + { + break; + } + } + } + else + { + for (i=PX_strlen(payload);i>0;i--) + { + if (payload[i]=='.') + { + break; + } + } + } + payload[i]='\0'; + pParentValue=PX_JsonGetValue(pjson,payload); + + if (!pParentValue) + { + return; + } + switch(pParentValue->type) + { + case PX_JSON_VALUE_TYPE_ARRAY: + { + px_int j; + for (j=0;j_array.size;j++) + { + PX_Json_Value *pTarget; + pTarget=PX_LISTAT(PX_Json_Value,&pParentValue->_array,j); + if (pTarget==pValue) + { + PX_JsonDeleteValue(pjson,pTarget); + PX_ListErase(&pParentValue->_array,j); + return; + } + } + } + break; + case PX_JSON_VALUE_TYPE_OBJECT: + { + px_int j; + for (j=0;j_object.values.size;j++) + { + PX_Json_Value *pTarget; + pTarget=PX_LISTAT(PX_Json_Value,&pParentValue->_object.values,j); + if (pTarget==pValue) + { + PX_JsonDeleteValue(pjson,pTarget); + PX_ListErase(&pParentValue->_object.values,j); + return; + } + } + } + break; + default: + break; + } + + +} + +px_void PX_JsonFreeValue(PX_Json *pjson,PX_Json_Value *json_Value) +{ + PX_StringFree(&json_Value->name); + switch (json_Value->type) + { + case PX_JSON_VALUE_TYPE_ARRAY: + { + px_int i; + for (i=0;i_array.size;i++) + { + PX_JsonFreeValue(pjson,PX_LISTAT(PX_Json_Value,&json_Value->_array,i)); + } + PX_ListFree(&json_Value->_array); + } + break; + case PX_JSON_VALUE_TYPE_STRING: + PX_StringFree(&json_Value->_string); + break; + case PX_JSON_VALUE_TYPE_OBJECT: + { + px_int i; + for (i=0;i_object.values.size;i++) + { + PX_JsonFreeValue(pjson,PX_LISTAT(PX_Json_Value,&json_Value->_object.values,i)); + } + PX_ListFree(&json_Value->_object.values); + } + break; + case PX_JSON_VALUE_TYPE_BOOLEAN: + case PX_JSON_VALUE_TYPE_NULL: + case PX_JSON_VALUE_TYPE_NUMBER: + default: + break; + } +} + +px_void PX_JsonFree(PX_Json *pjson) +{ + PX_JsonFreeValue(pjson,&pjson->rootValue); +} + +px_bool PX_JsonCreateObjectValue(px_memorypool *mp,PX_Json_Value *pValue,const px_char name[]) +{ + PX_memset(pValue,0,sizeof(PX_Json_Value)); + pValue->type=PX_JSON_VALUE_TYPE_OBJECT; + + if (!PX_StringInitialize(mp,&pValue->name)) + { + return PX_FALSE; + } + if(!PX_StringSet(&pValue->name,name)) return PX_FALSE; + PX_ListInitialize(mp,&pValue->_object.values); + return PX_TRUE; +} + +px_bool PX_JsonCreateStringValue(px_memorypool *mp,PX_Json_Value *pValue,const px_char name[],const px_char text[]) +{ + PX_memset(pValue,0,sizeof(PX_Json_Value)); + pValue->type=PX_JSON_VALUE_TYPE_STRING; + + if (!PX_StringInitialize(mp,&pValue->name)) + { + return PX_FALSE; + } + PX_StringSet(&pValue->name,name); + + if (!PX_StringInitialize(mp,&pValue->_string)) + { + return PX_FALSE; + } + if(!PX_StringSet(&pValue->_string,text)) return PX_FALSE; + return PX_TRUE; +} + +px_bool PX_JsonCreateNumberValue(px_memorypool *mp,PX_Json_Value *pValue,const px_char name[],px_double value) +{ + PX_memset(pValue,0,sizeof(PX_Json_Value)); + pValue->type=PX_JSON_VALUE_TYPE_NUMBER; + + if (!PX_StringInitialize(mp,&pValue->name)) + { + return PX_FALSE; + } + if(!PX_StringSet(&pValue->name,name)) return PX_FALSE; + + pValue->_number=value; + return PX_TRUE; +} + +px_bool PX_JsonCreateBooleanValue(px_memorypool *mp,PX_Json_Value *pValue,const px_char name[],px_bool b) +{ + PX_memset(pValue,0,sizeof(PX_Json_Value)); + pValue->type=PX_JSON_VALUE_TYPE_BOOLEAN; + + if (!PX_StringInitialize(mp,&pValue->name)) + { + return PX_FALSE; + } + if(!PX_StringSet(&pValue->name,name)) return PX_FALSE; + + pValue->_boolean=b; + return PX_TRUE; +} + +px_bool PX_JsonCreateArrayValue(px_memorypool *mp,PX_Json_Value *pValue,const px_char name[]) +{ + PX_memset(pValue,0,sizeof(PX_Json_Value)); + pValue->type=PX_JSON_VALUE_TYPE_ARRAY; + + if (!PX_StringInitialize(mp,&pValue->name)) + { + return PX_FALSE; + } + if(!PX_StringSet(&pValue->name,name)) return PX_FALSE; + PX_ListInitialize(mp,&pValue->_array); + return PX_TRUE; +} + +px_bool PX_JsonAddString(PX_Json *pjson,const px_char parent_payload[],const px_char name[],const px_char text[]) +{ + PX_Json_Value *pValue=PX_JsonGetValue(pjson,parent_payload); + + PX_Json_Value newValue; + if (!pValue) + { + return PX_FALSE; + } + switch (pValue->type) + { + case PX_JSON_VALUE_TYPE_ARRAY: + { + PX_Json_Value *pExistValue=PX_JsonGetObjectValue(pValue,name); + if (!pExistValue) + { + PX_JsonCreateStringValue(pjson->mp,&newValue,name,text); + PX_ListPush(&pValue->_array,&newValue,sizeof(newValue)); + } + else + { + if (pExistValue->type!=PX_JSON_VALUE_TYPE_STRING) + { + return PX_FALSE; + } + PX_StringSet(&pExistValue->_string,text); + } + + + return PX_TRUE; + } + //break; + case PX_JSON_VALUE_TYPE_OBJECT: + { + PX_Json_Value *pExistValue=PX_JsonGetObjectValue(pValue,name); + if (!pExistValue) + { + PX_JsonCreateStringValue(pjson->mp,&newValue,name,text); + PX_ListPush(&pValue->_object.values,&newValue,sizeof(newValue)); + } + else + { + if (pExistValue->type!=PX_JSON_VALUE_TYPE_STRING) + { + return PX_FALSE; + } + PX_StringSet(&pExistValue->_string,text); + } + return PX_TRUE; + } + //break; + default: + return PX_FALSE; + } + + return PX_FALSE; +} + +px_bool PX_JsonAddNumber(PX_Json *pjson,const px_char parent_payload[],const px_char name[],const px_double number) +{ + PX_Json_Value *pValue=PX_JsonGetValue(pjson,parent_payload); + PX_Json_Value newValue; + if (!pValue) + { + return PX_FALSE; + } + switch (pValue->type) + { + case PX_JSON_VALUE_TYPE_ARRAY: + { + + PX_Json_Value *pExistValue=PX_JsonGetObjectValue(pValue,name); + if (!pExistValue) + { + PX_JsonCreateNumberValue(pjson->mp,&newValue,name,number); + PX_ListPush(&pValue->_array,&newValue,sizeof(newValue)); + } + else + { + if (pExistValue->type!=PX_JSON_VALUE_TYPE_NUMBER) + { + return PX_FALSE; + } + pExistValue->_number=number; + } + + + return PX_TRUE; + } + //break; + case PX_JSON_VALUE_TYPE_OBJECT: + { + PX_Json_Value *pExistValue=PX_JsonGetObjectValue(pValue,name); + if (!pExistValue) + { + PX_JsonCreateNumberValue(pjson->mp,&newValue,name,number); + PX_ListPush(&pValue->_object.values,&newValue,sizeof(newValue)); + } + else + { + if (pExistValue->type!=PX_JSON_VALUE_TYPE_NUMBER) + { + return PX_FALSE; + } + pExistValue->_number=number; + } + return PX_TRUE; + } + //break; + default: + return PX_FALSE; + } + + return PX_FALSE; + + +} + +px_bool PX_JsonAddBoolean(PX_Json *pjson,const px_char parent_payload[],const px_char name[],const px_bool b) +{ + PX_Json_Value *pValue=PX_JsonGetValue(pjson,parent_payload); + PX_Json_Value newValue; + if (!pValue) + { + return PX_FALSE; + } + switch (pValue->type) + { + case PX_JSON_VALUE_TYPE_ARRAY: + { + PX_Json_Value *pExistValue=PX_JsonGetObjectValue(pValue,name); + if (!pExistValue) + { + PX_JsonCreateBooleanValue(pjson->mp,&newValue,name,b); + PX_ListPush(&pValue->_array,&newValue,sizeof(newValue)); + } + else + { + if (pExistValue->type!=PX_JSON_VALUE_TYPE_BOOLEAN) + { + return PX_FALSE; + } + pExistValue->_boolean=b; + } + + return PX_TRUE; + } + //break; + case PX_JSON_VALUE_TYPE_OBJECT: + { + PX_Json_Value *pExistValue=PX_JsonGetObjectValue(pValue,name); + if (!pExistValue) + { + PX_JsonCreateBooleanValue(pjson->mp,&newValue,name,b); + PX_ListPush(&pValue->_object.values,&newValue,sizeof(newValue)); + } + else + { + if (pExistValue->type!=PX_JSON_VALUE_TYPE_BOOLEAN) + { + return PX_FALSE; + } + pExistValue->_boolean=b; + } + + return PX_TRUE; + } + //break; + default: + return PX_FALSE; + } + + return PX_FALSE; +} + +px_bool PX_JsonAddArray(PX_Json *pjson,const px_char parent_payload[],const px_char name[]) +{ + PX_Json_Value *pValue=PX_JsonGetValue(pjson,parent_payload); + PX_Json_Value newValue; + if (!pValue) + { + return PX_FALSE; + } + switch (pValue->type) + { + case PX_JSON_VALUE_TYPE_ARRAY: + { + PX_Json_Value *pExistValue=PX_JsonGetObjectValue(pValue,name); + if (!pExistValue) + { + PX_JsonCreateArrayValue(pjson->mp,&newValue,name); + PX_ListPush(&pValue->_array,&newValue,sizeof(newValue)); + } + else + { + if (pExistValue->type!=PX_JSON_VALUE_TYPE_ARRAY) + { + return PX_FALSE; + } + } + + return PX_TRUE; + } + //break; + case PX_JSON_VALUE_TYPE_OBJECT: + { + PX_Json_Value *pExistValue=PX_JsonGetObjectValue(pValue,name); + if (!pExistValue) + { + PX_JsonCreateArrayValue(pjson->mp,&newValue,name); + PX_ListPush(&pValue->_object.values,&newValue,sizeof(newValue)); + } + else + { + if (pExistValue->type!=PX_JSON_VALUE_TYPE_ARRAY) + { + return PX_FALSE; + } + } + + return PX_TRUE; + } + //break; + default: + return PX_FALSE; + } + + return PX_FALSE; +} + +px_bool PX_JsonAddObject(PX_Json *pjson,const px_char parent_payload[],const px_char name[]) +{ + PX_Json_Value *pValue=PX_JsonGetValue(pjson,parent_payload); + PX_Json_Value newValue; + if (!pValue) + { + return PX_FALSE; + } + switch (pValue->type) + { + case PX_JSON_VALUE_TYPE_ARRAY: + { + + PX_Json_Value *pExistValue=PX_JsonGetObjectValue(pValue,name); + if (!pExistValue) + { + PX_JsonCreateObjectValue(pjson->mp,&newValue,name); + PX_ListPush(&pValue->_array,&newValue,sizeof(newValue)); + } + else + { + if (pExistValue->type!=PX_JSON_VALUE_TYPE_OBJECT) + { + return PX_FALSE; + } + } + + + return PX_TRUE; + } + //break; + case PX_JSON_VALUE_TYPE_OBJECT: + { + + PX_Json_Value *pExistValue=PX_JsonGetObjectValue(pValue,name); + if (!pExistValue) + { + PX_JsonCreateObjectValue(pjson->mp,&newValue,name); + PX_ListPush(&pValue->_object.values,&newValue,sizeof(newValue)); + } + else + { + if (pExistValue->type!=PX_JSON_VALUE_TYPE_OBJECT) + { + return PX_FALSE; + } + } + return PX_TRUE; + } + //break; + default: + return PX_FALSE; + } + + return PX_FALSE; +} + +const px_char * PX_JsonGetString(PX_Json *pjson,const px_char payload[]) +{ + PX_Json_Value *pValue=PX_JsonGetValue(pjson,payload); + if (pValue&&pValue->type==PX_JSON_VALUE_TYPE_STRING) + { + return pValue->_string.buffer; + } + return ""; +} + +px_double PX_JsonGetNumber(PX_Json *pjson,const px_char payload[]) +{ + PX_Json_Value *pValue=PX_JsonGetValue(pjson,payload); + if (pValue&&pValue->type==PX_JSON_VALUE_TYPE_NUMBER) + { + return pValue->_number; + } + return 0; +} + +px_bool PX_JsonGetBoolean(PX_Json *pjson,const px_char payload[]) +{ + PX_Json_Value *pValue=PX_JsonGetValue(pjson,payload); + if (pValue&&pValue->type==PX_JSON_VALUE_TYPE_BOOLEAN) + { + return pValue->_boolean; + } + return 0; +} + +px_bool PX_JsonSetString(PX_Json *pjson,const px_char payload[],const px_char text[]) +{ + PX_Json_Value *pValue=PX_JsonGetValue(pjson,payload); + if (pValue&&pValue->type==PX_JSON_VALUE_TYPE_STRING) + { + return PX_StringSet(&pValue->_string,text); + } + return PX_FALSE; +} + +px_bool PX_JsonSetNumber(PX_Json *pjson,const px_char payload[],const px_double number) +{ + PX_Json_Value *pValue=PX_JsonGetValue(pjson,payload); + if (pValue&&pValue->type==PX_JSON_VALUE_TYPE_NUMBER) + { + pValue->_number=number; + return PX_TRUE; + } + return PX_FALSE; +} + +px_bool PX_JsonSetBoolean(PX_Json *pjson,const px_char payload[],const px_bool b) +{ + PX_Json_Value *pValue=PX_JsonGetValue(pjson,payload); + if (pValue&&pValue->type==PX_JSON_VALUE_TYPE_BOOLEAN) + { + pValue->_boolean=b; + return PX_TRUE; + } + return PX_FALSE; +} + +px_bool PX_JsonObjectAddValue(PX_Json_Value *pObject,PX_Json_Value *value) +{ + if (pObject->type==PX_JSON_VALUE_TYPE_OBJECT) + { + return PX_ListPush(&pObject->_object.values,value,sizeof(PX_Json_Value))!=PX_NULL; + } + return PX_FALSE; +} + +px_bool PX_JsonArrayAddValue(PX_Json_Value *pArray,PX_Json_Value *value) +{ + if (pArray->type==PX_JSON_VALUE_TYPE_ARRAY) + { + return PX_ListPush(&pArray->_array,value,sizeof(PX_Json_Value))!=PX_NULL; + } + return PX_FALSE; +} + diff --git a/lib/PainterEngine/kernel/PX_Json.h b/lib/PainterEngine/kernel/PX_Json.h new file mode 100644 index 0000000000000000000000000000000000000000..12898b6e9f19ab1d937ed1eabccf793b7432f931 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Json.h @@ -0,0 +1,84 @@ +#ifndef PX_JSON_H +#define PX_JSON_H +#include "PX_Lexer.h" + + + +typedef enum +{ + PX_JSON_VALUE_TYPE_STRING, + PX_JSON_VALUE_TYPE_NUMBER, + PX_JSON_VALUE_TYPE_BOOLEAN, + PX_JSON_VALUE_TYPE_NULL, + PX_JSON_VALUE_TYPE_OBJECT, + PX_JSON_VALUE_TYPE_ARRAY, +}PX_JSON_VALUE_TYPE; + +typedef struct _PX_Json_Object +{ + px_list values; //values +}PX_Json_Object; + +typedef struct +{ + PX_JSON_VALUE_TYPE type; + px_string name; + union + { + px_string _string; + px_double _number; + px_bool _boolean; + PX_Json_Object _object; + px_list _array;//values + }; +}PX_Json_Value; + +typedef struct _PX_Json_Object PX_Json_Object; + +typedef struct +{ + px_memorypool *mp; + PX_Json_Value rootValue; +}PX_Json; + + +PX_Json_Value *PX_JsonGetObjectValue(PX_Json_Value *json_value,const px_char name[]); +PX_Json_Value *PX_JsonGetObjectValueByIndex(PX_Json_Value *json_value,px_int i); +PX_Json_Value * PX_JsonGetValue(PX_Json *json,const px_char payload[]); +PX_Json_Value * PX_JsonGetArrayValue(PX_Json_Value *value,px_int i); + + +px_bool PX_JsonInitialize(px_memorypool *mp,PX_Json *pjson); + +px_bool PX_JsonParse(PX_Json *pjson,const px_char *json_content); +px_bool PX_JsonBuild_Value(PX_Json_Value *pValue,px_string *_out,px_bool bArrayValue); +px_bool PX_JsonBuild(PX_Json *pjson,px_string *_out); +px_void PX_JsonDelete(PX_Json *pjson,const px_char payload[]); +px_void PX_JsonFree(PX_Json *pjson); + + +px_bool PX_JsonCreateObjectValue(px_memorypool *mp,PX_Json_Value *pValue,const px_char name[]); +px_bool PX_JsonCreateStringValue(px_memorypool *mp,PX_Json_Value *pValue,const px_char name[],const px_char text[]); +px_bool PX_JsonCreateNumberValue(px_memorypool *mp,PX_Json_Value *pValue,const px_char name[],px_double value); +px_bool PX_JsonCreateBooleanValue(px_memorypool *mp,PX_Json_Value *pValue,const px_char name[],px_bool b); +px_bool PX_JsonCreateArrayValue(px_memorypool *mp,PX_Json_Value *pValue,const px_char name[]); + +px_bool PX_JsonAddString(PX_Json *pjson,const px_char parent_payload[],const px_char name[],const px_char text[]); +px_bool PX_JsonAddNumber(PX_Json *pjson,const px_char parent_payload[],const px_char name[],const px_double number); +px_bool PX_JsonAddBoolean(PX_Json *pjson,const px_char parent_payload[],const px_char name[],const px_bool b); +px_bool PX_JsonAddArray(PX_Json *pjson,const px_char parent_payload[],const px_char name[]); +px_bool PX_JsonAddObject(PX_Json *pjson,const px_char parent_payload[],const px_char name[]); + +const px_char *PX_JsonGetString(PX_Json *pjson,const px_char payload[]); +px_double PX_JsonGetNumber(PX_Json *pjson,const px_char payload[]); +px_bool PX_JsonGetBoolean(PX_Json *pjson,const px_char payload[]); + +px_bool PX_JsonSetString(PX_Json *pjson,const px_char payload[],const px_char text[]); +px_bool PX_JsonSetNumber(PX_Json *pjson,const px_char payload[],const px_double number); +px_bool PX_JsonSetBoolean(PX_Json *pjson,const px_char payload[],const px_bool b); + +px_bool PX_JsonObjectAddValue(PX_Json_Value *pObject,PX_Json_Value *value); +px_bool PX_JsonArrayAddValue(PX_Json_Value *pArray,PX_Json_Value *value); + +#endif + diff --git a/lib/PainterEngine/kernel/PX_Kernel.h b/lib/PainterEngine/kernel/PX_Kernel.h new file mode 100644 index 0000000000000000000000000000000000000000..320629e7f51e81c4300fb04d65bc3ef10b86657a --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Kernel.h @@ -0,0 +1,27 @@ +////////////////////////////////////////////////////////////////////////// +/* + PainterEngine Kernel + (C)2019 DBinary + + This program is free software; you can redistribute it and/or modify + it under the terms of the BSD General Public License +*/ +////////////////////////////////////////////////////////////////////////// +#ifndef _PX_KERNEL_H +#define _PX_KERNEL_H +#include "PX_Script_Interpreter.h" +#include "PX_Script_ASMCompiler.h" +#include "PX_Script_VM.h" +#include "PX_Partical.h" +#include "PX_Animation.h" +#include "PX_World.h" +#include "PX_Sync.h" +#include "PX_MQTT.h" +#include "PX_Object.h" +#include "PX_Json.h" +#include "PX_3D_ObjData.h" +#include "PX_MODBUS.h" +#include "PX_LiveFramework.h" +#include "PX_UI.h" +#include "PX_Compiler.h" +#endif diff --git a/lib/PainterEngine/kernel/PX_Lexer.c b/lib/PainterEngine/kernel/PX_Lexer.c new file mode 100644 index 0000000000000000000000000000000000000000..6026a8da8d8e61aedf4462d9302fcaf7213a59f0 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Lexer.c @@ -0,0 +1,710 @@ +#include "./PX_Lexer.h" + +static px_char * PX_LexerIsCommentStart(px_lexer *lexer,const px_char ch[]); +static px_char * PX_LexerIsCommentEnd(px_lexer *lexer,const px_char startch[],const px_char ch[]); +static px_char* PX_LexerIsContainerStart(px_lexer *lexer,const px_char ch[]); +static char* PX_LexerIsContainerEnd(px_lexer *lexer,const px_char startch[],const px_char ch[]); +static px_bool PX_LexerIsContainerTransfer(px_lexer *lexer,const px_char startch[],px_char ch); + +static px_int PX_LexerIsSpacer(px_lexer *lexer,px_char chr); +static px_int PX_LexerIsDelimiter(px_lexer *lexer,px_char chr); +static px_int PX_LexerFilterChar(px_lexer *lexer,px_char ch); +static px_int PX_LexerIsSourcsEnd(px_lexer *lexer); +static px_int PX_LexerIsNewLine(px_char ch); + +//CA_Token *GetToken(px_lexer *lexer,pt_string Mnemonic); +//px_void RegisterToken(pt_string Mnemonic,px_uint Type); + + + +//---------------------------------------------------------------------------------- + +//-------------------------------------------Lexer---------------------------------- + +px_bool PX_LexerIsCharNumeric(px_char chr) +{ + if (chr>=('0')&&chr<=('9')) + { + return PX_TRUE; + } + return PX_FALSE; +} + +px_bool PX_LexerIsStringNumeric(px_string *pString) +{ + return PX_StringIsNumeric(pString); +} + + + +// -------------------------------------------New Line------------------------------- +px_bool PX_LexerIsNewLine(px_char ch) +{ + return ch=='\r'||ch=='\n'; +} + +//-------------------------------------------Comment---------------------------------- + + +px_char * PX_LexerIsCommentStart(px_lexer *lexer,const px_char ch[]) +{ + px_int i=0; + for (i=0;iCommentCount;i++) + { + if(PX_memequ(ch,lexer->Comment[i].CommentBegin,PX_strlen(lexer->Comment[i].CommentBegin))) + return lexer->Comment[i].CommentBegin; + } + return PX_NULL; +} + +px_char * PX_LexerIsCommentEnd(px_lexer *lexer,const px_char startch[],const px_char ch[]) +{ + px_int i=0; + for (i=0;iCommentCount;i++) + { + if(PX_memequ(startch,lexer->Comment[i].CommentBegin,PX_strlen(lexer->Comment[i].CommentBegin))&&PX_memequ(ch,lexer->Comment[i].CommentEnd,PX_strlen(lexer->Comment[i].CommentEnd))) + { + lexer->CurrentCommentType=i; + return lexer->Comment[i].CommentEnd; + } + } + return PX_NULL; +} + + +//--------------------------------------------Spacer----------------------------------- + + +px_void PX_LexerRegisterSpacer(px_lexer *lexer,px_char Spacer) +{ + px_int i; + if (lexer->SpacerCountSpacerCount;i++) + { + if (lexer->Spacer[i]==Spacer) + { + return; + } + } + lexer->Spacer[lexer->SpacerCount++]=Spacer; + } +} + +px_bool PX_LexerIsSpacer(px_lexer *lexer,px_char chr) +{ + px_int i; + for (i=0;iSpacerCount;i++) + { + if (lexer->Spacer[i]==chr) + { + return PX_TRUE; + } + } + return PX_FALSE; +} +//--------------------------------------------Delimiter-------------------------------- + + +px_int PX_LexerRegisterDelimiter(px_lexer *lexer,px_char Delimiter) +{ + px_int i; + if (lexer->DelimiterCountDelimiterCount;i++) + { + if (lexer->Delimiter[i]==Delimiter) + { + return i; + } + } + lexer->Delimiter[lexer->DelimiterCount++]=Delimiter; + return lexer->DelimiterCount-1; + } + return -1; +} + + + + + +px_int PX_LexerIsDelimiter(px_lexer *lexer,px_char chr) +{ + px_int i; + for (i=0;iDelimiterCount;i++) + { + if (lexer->Delimiter[i]==chr) + { + return PX_TRUE; + } + } + return PX_FALSE; +} + +px_int PX_LexerGetDelimiterType(px_lexer *lexer,px_char Delimiter) +{ + px_int i; + for (i=0;iDelimiterCount;i++) + { + if (lexer->Delimiter[i]==Delimiter) + { + return i; + } + } + return -1; +} + +//--------------------------------------------Container--------------------------------- + + + +px_int PX_LexerRegisterContainer(px_lexer *lexer,const px_char Begin[],const px_char End[]) +{ + px_int i; + if (lexer->ContainerCountContainerCount;i++) + { + if (lexer->Container[i].ContainerBegin==Begin&&lexer->Container[i].ContainerEnd==End) + { + return i; + } + } + PX_strcpy(lexer->Container[lexer->ContainerCount].ContainerBegin,Begin,sizeof(lexer->Container[lexer->ContainerCount].ContainerBegin)); + PX_strcpy(lexer->Container[lexer->ContainerCount].ContainerEnd,End,sizeof(lexer->Container[lexer->ContainerCount].ContainerEnd)); + lexer->ContainerCount++; + return lexer->ContainerCount-1; + } + return -1; +} + + +px_void PX_LexerRegisterContainerTransfer(px_lexer *lexer,px_uint containerIndex,px_char transfer) +{ + if(containerIndexContainer[containerIndex].transfer=transfer; +} + +px_int PX_LexerGetContainerType(px_lexer *lexer,px_char *pContainerText) +{ + return lexer->CurrentContainerType; +} + +px_char * PX_LexerIsContainerStart(px_lexer *lexer,const px_char chr[]) +{ + px_int i=0; + for (i=0;iContainerCount;i++) + { + if(PX_memequ(chr,lexer->Container[i].ContainerBegin,PX_strlen(lexer->Container[i].ContainerBegin))) + return lexer->Container[i].ContainerBegin; + } + return PX_NULL; +} + +px_char * PX_LexerIsContainerEnd(px_lexer *lexer,const px_char startch[],const px_char ch[]) +{ + px_int i=0; + for (i=0;iContainerCount;i++) + { + if(PX_memequ(startch,lexer->Container[i].ContainerBegin,PX_strlen(startch))&&PX_memequ(ch,lexer->Container[i].ContainerEnd,PX_strlen(lexer->Container[i].ContainerEnd))) + { + lexer->CurrentContainerType=i; + return lexer->Container[i].ContainerEnd; + } + } + return PX_NULL; +} + + +//--------------------------------------------TOKEN------------------------------------- +// +// +// CA_Token *Pt_Lexer::GetToken(pt_string Mnemonic) +// { +// for (px_uint i=0;iTokens.size();i++) +// { +// if (strcmp(Mnemonic,lexer->Tokens[i].Mnemonic)==0) +// { +// return &lexer->Tokens[i]; +// } +// } +// return NULL; +// } +// +// +// px_void Pt_Lexer::RegisterToken(pt_string Mnemonic,px_uint Type) +// { +// +// if (GetToken(Mnemonic)!=NULL) +// { +// return; +// } +// +// CA_Token Token; +// PT_STRING_COPY(Token.Mnemonic,sizeof(Token.Mnemonic),Mnemonic); +// Token.Type=Type; +// +// lexer->Tokens.push_back(Token); +// +// } +px_void PX_LexerInit(px_lexer *lexer,px_memorypool *mp) +{ + lexer->CommentCount=0; + lexer->SpacerCount=0; + lexer->DelimiterCount=0; + lexer->ContainerCount=0; + lexer->SourceOffset=0; + lexer->Sources=PX_NULL; + lexer->mp=mp; + lexer->lexemeTokenCase=PX_LEXER_LEXEME_CASE_NORMAL; + lexer->NumericMath=PX_FALSE; + PX_StringInitialize(mp,&lexer->CurLexeme); + PX_memset(lexer->Delimiter,0,sizeof(lexer->Delimiter)); + PX_memset(lexer->Spacer,0,sizeof(lexer->Spacer)); + PX_memset(lexer->Container,0,sizeof(lexer->Container)); + PX_memset(lexer->Comment,0,sizeof(lexer->Comment)); +} + + + +px_int PX_LexerFilterChar(px_lexer *lexer,px_char ch) +{ + + switch(lexer->SortStatus) + { + case PX_LEXERSORT_STATUS_NORMAL: + { + if (PX_LexerIsSpacer(lexer,ch)) + { + lexer->SortStatus=PX_LEXER_SORT_STATUS_SPACER; + return PX_TRUE; + } + if (PX_LexerIsNewLine(ch)) + { + lexer->SortStatus=PX_LEXER_SORT_STATUS_NEWLINE; + return PX_TRUE; + } + return PX_TRUE; + } + break; + case PX_LEXER_SORT_STATUS_SPACER: + { + if (PX_LexerIsSpacer(lexer,ch)) + { + return PX_FALSE; + } + if (PX_LexerIsNewLine(ch)) + { + lexer->SortStatus=PX_LEXER_SORT_STATUS_NEWLINE; + return PX_TRUE; + } + lexer->SortStatus=PX_LEXERSORT_STATUS_NORMAL; + return PX_TRUE; + } + break; + + case PX_LEXER_SORT_STATUS_NEWLINE: + if (PX_LexerIsSpacer(lexer,ch)||PX_LexerIsNewLine(ch)) + { + return PX_FALSE; + } + lexer->SortStatus=PX_LEXERSORT_STATUS_NORMAL; + return PX_TRUE; + + case PX_LEXER_SORT_STATUS_COMMENT: + break; + } + return PX_TRUE; +} + +px_bool PX_LexerSortText(px_lexer *lexer,const px_char *SourceText) +{ + px_char *chrst,*chred; + px_char *pNewSourceText; + unsigned long Offset=0; + if (lexer->Sources) + { + MP_Free(lexer->mp,lexer->Sources); + lexer->SourceOffset=0; + lexer->SortStatus=PX_LEXERSORT_STATUS_NORMAL; + } + if ((lexer->Sources=(px_char *)MP_Malloc(lexer->mp,PX_strlen(SourceText)+1))==PX_NULL) + { + return PX_FALSE; + } + PX_memset(lexer->Sources,0,PX_strlen(SourceText)+1); + lexer->SortStatus=PX_LEXER_SORT_STATUS_NEWLINE; + + while(*SourceText) + { + //Comment trim + if ((chrst=PX_LexerIsCommentStart(lexer,SourceText))!=0) + { + SourceText+=PX_strlen(chrst); + while (!(chred=PX_LexerIsCommentEnd(lexer,chrst,SourceText))) + { + if (!*SourceText) + { + return PX_FALSE; + } + SourceText++; + } + //special end '\n' + if(*SourceText=='\n') + SourceText+=PX_strlen(chred)-1; + else + SourceText+=PX_strlen(chred); + continue; + } + + //container skip + if ((chrst=PX_LexerIsContainerStart(lexer,SourceText))!=0) + { + PX_memcpy(lexer->Sources+Offset,chrst,PX_strlen(chrst)); + Offset+=PX_strlen(chrst);; + SourceText+=PX_strlen(chrst); + + while (!(chred=PX_LexerIsContainerEnd(lexer,chrst,SourceText))) + { + if (*SourceText=='\0') + { + return PX_FALSE; + } + + if(PX_LexerIsContainerTransfer(lexer,chrst,*SourceText)&&PX_memequ(SourceText+1,chrst,PX_strlen(chrst))) + { + lexer->Sources[Offset++]=*(SourceText++); + lexer->Sources[Offset++]=*(SourceText++); + } + else + lexer->Sources[Offset++]=*(SourceText++); + } + PX_memcpy(lexer->Sources+Offset,chred,PX_strlen(chred)); + Offset+=PX_strlen(chred);; + SourceText+=PX_strlen(chred); + continue; + } + + + if (PX_LexerFilterChar(lexer,*SourceText)) + { + if(Offset>0)//forward trim + { + if(PX_LexerIsNewLine(*SourceText)&&PX_LexerIsSpacer(lexer,lexer->Sources[Offset-1])) + Offset--; + if(PX_LexerIsDelimiter(lexer,*SourceText)&&PX_LexerIsSpacer(lexer,lexer->Sources[Offset-1])) + Offset--; + } + lexer->Sources[Offset++]=*(SourceText); + } + SourceText++; + } + lexer->Sources[Offset]='\0'; + pNewSourceText=lexer->Sources; + + while (*pNewSourceText) + { + //replace \r + if(*pNewSourceText=='\r') + *pNewSourceText='\n'; + pNewSourceText++; + } + + return PX_TRUE; +} + + + + +px_int PX_LexerIsSourcsEnd(px_lexer *lexer) +{ + return !lexer->Sources[lexer->SourceOffset]; +} + + +PX_LEXER_LEXEME_TYPE PX_LexerGetNextLexeme(px_lexer *lexer) +{ + px_char *chrst,*chred; + px_uint i,oft; + px_bool match; + PX_StringClear(&lexer->CurLexeme); + lexer->Symbol=0; + if (lexer->Sources[lexer->SourceOffset]=='\0') + { + //printf("\n"); + lexer->Symbol='0'; + PX_StringCatChar(&lexer->CurLexeme,'\0'); + lexer->CurrentLexemeFlag=PX_LEXER_LEXEME_TYPE_END; + return PX_LEXER_LEXEME_TYPE_END; + } + if ((chrst=PX_LexerIsContainerStart(lexer,(&lexer->Sources[lexer->SourceOffset])))!=0) + { + PX_StringCat(&lexer->CurLexeme,chrst); + lexer->SourceOffset+=PX_strlen(chrst); + while (!(chred=PX_LexerIsContainerEnd(lexer,chrst,&lexer->Sources[lexer->SourceOffset]))) + { + if (PX_LexerIsSourcsEnd(lexer)) + { + return PX_LEXER_LEXEME_TYPE_ERR; + } + if(PX_LexerIsContainerTransfer(lexer,chrst,lexer->Sources[lexer->SourceOffset])&&PX_memequ(&lexer->Sources[lexer->SourceOffset+1],chrst,PX_strlen(chrst))) + { + PX_StringCatChar(&lexer->CurLexeme,lexer->Sources[lexer->SourceOffset++]); + PX_StringCatChar(&lexer->CurLexeme,lexer->Sources[lexer->SourceOffset++]); + } + else + PX_StringCatChar(&lexer->CurLexeme,lexer->Sources[lexer->SourceOffset++]); + } + PX_StringCat(&lexer->CurLexeme,chred); + lexer->SourceOffset+=PX_strlen(chred); + + //printf(" %s\n",lexer->CurLexeme); + lexer->CurrentLexemeFlag=PX_LEXER_LEXEME_TYPE_CONATINER; + return PX_LEXER_LEXEME_TYPE_CONATINER; + } + + if (PX_LexerIsSpacer(lexer,lexer->Sources[lexer->SourceOffset])) + { + lexer->Symbol=lexer->Sources[lexer->SourceOffset]; + PX_StringCatChar(&lexer->CurLexeme,lexer->Sources[lexer->SourceOffset]); + lexer->SourceOffset++; + //printf("\n"); + lexer->CurrentLexemeFlag=PX_LEXER_LEXEME_TYPE_SPACER; + return PX_LEXER_LEXEME_TYPE_SPACER; + } + + if (PX_LexerIsNewLine(lexer->Sources[lexer->SourceOffset])) + { + lexer->Symbol=lexer->Sources[lexer->SourceOffset]; + PX_StringCatChar(&lexer->CurLexeme,lexer->Sources[lexer->SourceOffset]); + lexer->SourceOffset++; + //printf("\n"); + lexer->CurrentLexemeFlag=PX_LEXER_LEXEME_TYPE_NEWLINE; + return PX_LEXER_LEXEME_TYPE_NEWLINE; + } + + + if (PX_LexerIsDelimiter(lexer,lexer->Sources[lexer->SourceOffset])) + { + lexer->Symbol=lexer->Sources[lexer->SourceOffset]; + for (i=0;(px_int)iDelimiterCount;i++) + { + if (lexer->Symbol==lexer->Delimiter[i]) + { + lexer->CurrentDelimiterType=i; + break; + } + } + + PX_StringCatChar(&lexer->CurLexeme,lexer->Sources[lexer->SourceOffset]); + //printf(" %c\n",lexer->Sources[lexer->SourceOffset]); + lexer->SourceOffset++; + lexer->CurrentLexemeFlag=PX_LEXER_LEXEME_TYPE_DELIMITER; + return PX_LEXER_LEXEME_TYPE_DELIMITER; + } + PX_StringClear(&lexer->CurLexeme); + lexer->Symbol='\0'; + while (!PX_LexerIsSourcsEnd(lexer)&&!PX_LexerIsDelimiter(lexer,lexer->Sources[lexer->SourceOffset])&&!PX_LexerIsSpacer(lexer,lexer->Sources[lexer->SourceOffset])&&!PX_LexerIsNewLine(lexer->Sources[lexer->SourceOffset])&&!PX_LexerIsContainerStart(lexer,&lexer->Sources[lexer->SourceOffset])) + { + PX_StringCatChar(&lexer->CurLexeme,lexer->Sources[lexer->SourceOffset++]); + oft=lexer->SourceOffset; + + if (lexer->NumericMath&&lexer->Sources[lexer->SourceOffset]=='.'&&PX_LexerIsDelimiter(lexer,'.')) + { + match=PX_TRUE; + if (PX_StringIsNumeric(&lexer->CurLexeme)&&lexer->Sources[lexer->SourceOffset]=='.') + { + lexer->SourceOffset++; + while (!PX_LexerIsSourcsEnd(lexer)&&!PX_LexerIsDelimiter(lexer,lexer->Sources[lexer->SourceOffset])&&!PX_LexerIsSpacer(lexer,lexer->Sources[lexer->SourceOffset])&&!PX_LexerIsNewLine(lexer->Sources[lexer->SourceOffset])&&!PX_LexerIsContainerStart(lexer,&lexer->Sources[lexer->SourceOffset])) + { + if(lexer->Sources[lexer->SourceOffset]>='0'&&lexer->Sources[lexer->SourceOffset]<='9') + { + lexer->SourceOffset++; + continue; + } + else + { + match=PX_FALSE; + break; + } + } + } + else + match=PX_FALSE; + + if (lexer->SourceOffset==oft+1) + { + match=PX_FALSE; + } + + lexer->SourceOffset=oft; + if (match) + { + PX_StringCatChar(&lexer->CurLexeme,lexer->Sources[lexer->SourceOffset++]); + while (!PX_LexerIsSourcsEnd(lexer)&&!PX_LexerIsDelimiter(lexer,lexer->Sources[lexer->SourceOffset])&&!PX_LexerIsSpacer(lexer,lexer->Sources[lexer->SourceOffset])&&!PX_LexerIsNewLine(lexer->Sources[lexer->SourceOffset])&&!PX_LexerIsContainerStart(lexer,&lexer->Sources[lexer->SourceOffset])) + PX_StringCatChar(&lexer->CurLexeme,lexer->Sources[lexer->SourceOffset++]); + } + } + + } + //printf(" %s\n",m_CurLexeme); + if (lexer->lexemeTokenCase==PX_LEXER_LEXEME_CASE_UPPER) + { + PX_strupr(lexer->CurLexeme.buffer); + } + + if (lexer->lexemeTokenCase==PX_LEXER_LEXEME_CASE_LOWER) + { + PX_strlwr(lexer->CurLexeme.buffer); + } + lexer->CurrentLexemeFlag=PX_LEXER_LEXEME_TYPE_TOKEN; + return PX_LEXER_LEXEME_TYPE_TOKEN; +} + +px_bool PX_LexerReadString(px_lexer *lexer,px_string *str,px_uint size) +{ + PX_StringClear(str); + while (size) + { + if (PX_LexerIsSourcsEnd(lexer)) + { + return PX_FALSE; + } + PX_StringCatChar(str,lexer->Sources[lexer->SourceOffset++]); + size--; + } + return PX_TRUE; +} + +px_void PX_LexerGetIncludedString(px_lexer *lexer,px_string *str) +{ + px_int left,right; + if(str!=&lexer->CurLexeme) + PX_StringCopy(str,&lexer->CurLexeme); + + if (lexer->CurrentLexemeFlag==PX_LEXER_LEXEME_TYPE_CONATINER) + { + left=PX_strlen(lexer->Container[lexer->CurrentContainerType].ContainerBegin); + right=PX_strlen(lexer->Container[lexer->CurrentContainerType].ContainerEnd); + PX_StringTrimRight(str,right); + PX_StringTrimLeft(str,left); + } +} + + +PX_LEXER_LEXEME_TYPE PX_LexerGetCurrentLexeme(px_lexer *lexer) +{ + return lexer->CurrentLexemeFlag; +} + +px_void PX_LexerRegisterComment(px_lexer *lexer,const px_char Begin[],const px_char End[] ) +{ + px_int i; + if (lexer->CommentCountCommentCount;i++) + { + if (lexer->Comment[i].CommentBegin==Begin&&lexer->Comment[i].CommentEnd==End) + { + return; + } + } + PX_strcpy(lexer->Comment[lexer->CommentCount].CommentBegin,Begin,sizeof(lexer->Comment[lexer->CommentCount].CommentBegin)); + PX_strcpy(lexer->Comment[lexer->CommentCount].CommentEnd,End,sizeof(lexer->Comment[lexer->CommentCount].CommentEnd)); + lexer->CommentCount++; + } +} + + +px_int PX_LexerLoadSourceFromMemory(px_lexer *lexer,const px_char *buffer) +{ + return PX_LexerSortText(lexer,buffer); +} + + +px_void PX_LexerFree(px_lexer *lexer) +{ + if(lexer->Sources) + MP_Free(lexer->mp,lexer->Sources); + + + PX_StringFree(&lexer->CurLexeme); + lexer->Sources=PX_NULL; +} + +px_void PX_LexerGetLexemeString(px_lexer *lexer,px_string *str) +{ + PX_StringCopy(str,&lexer->CurLexeme); +} + +px_char PX_LexerGetSymbol(px_lexer *lexer) +{ + return lexer->Symbol; +} + +PX_LEXER_STATE PX_LexerGetState(px_lexer *lexer) +{ + PX_LEXER_STATE state; + state.lexer=lexer; + state.offset=lexer->SourceOffset; + return state; +} + +px_void PX_LexerSetState(PX_LEXER_STATE state) +{ + state.lexer->SourceOffset=state.offset; +} + +px_char PX_LexerGetNextChar(px_lexer *lexer) +{ + char ch; + PX_StringClear(&lexer->CurLexeme); + ch=lexer->Sources[lexer->SourceOffset]; + lexer->SourceOffset++; + return ch; +} + +px_bool PX_LexerIsLememeIsNumeric(px_lexer *lexer) +{ + return PX_StringIsNumeric(&lexer->CurLexeme); +} + +px_void PX_LexerSetTokenCase(px_lexer *lexer,PX_LEXER_LEXEME_CASE _case) +{ + lexer->lexemeTokenCase=_case; +} + +px_bool PX_LexerSetSourcePointer(px_lexer *lexer,const px_char *buffer) +{ + lexer->Sources=(px_char *)buffer; + return PX_TRUE; +} + +px_int PX_LexerGetCurrentContainerType(px_lexer *lexer) +{ + return lexer->CurrentContainerType; +} + +px_int PX_LexerGetCurrentDelimiterType(px_lexer *lexer) +{ + return lexer->CurrentDelimiterType; +} + +px_void PX_LexerSetNumericMatch(px_lexer *lexer,px_bool b) +{ + lexer->NumericMath=b; +} + +px_bool PX_LexerIsContainerTransfer(px_lexer *lexer,const px_char startch[],px_char ch) +{ + px_int i=0; + for (i=0;iContainerCount;i++) + { + if(PX_memequ(startch,lexer->Container[i].ContainerBegin,PX_strlen(startch))&&lexer->Container[i].transfer&&lexer->Container[i].transfer==ch) + { + return PX_TRUE; + } + } + return PX_FALSE; +} + diff --git a/lib/PainterEngine/kernel/PX_Lexer.h b/lib/PainterEngine/kernel/PX_Lexer.h new file mode 100644 index 0000000000000000000000000000000000000000..5efef8a178283ef89cdb1b099886857cbd644439 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Lexer.h @@ -0,0 +1,116 @@ +#ifndef __PX_LEXER_H +#define __PX_LEXER_H +#include "../core/PX_Core.h" + +#define PX_LEXER_CA_COMMENT_MAX_COUNT 32 +#define PX_LEXER_CA_SPACER_MAX_COUNT 32 +#define PX_LEXER_CA_DELIMITER_MAX_COUNT 32 +#define PX_LEXER_CA_CONTAINER_MAX_COUNT 32 + +typedef enum __PX_LEXER_SORT_STATUS +{ + PX_LEXERSORT_STATUS_NORMAL= 0, + PX_LEXER_SORT_STATUS_SPACER= 1, + PX_LEXER_SORT_STATUS_COMMENT= 2, + PX_LEXER_SORT_STATUS_NEWLINE= 3, +}PX_LEXER_SORT_STATUS; + +typedef enum __PX_LEXER_LEXEME_CASE +{ + PX_LEXER_LEXEME_CASE_NORMAL, + PX_LEXER_LEXEME_CASE_LOWER, + PX_LEXER_LEXEME_CASE_UPPER, + +}PX_LEXER_LEXEME_CASE; + + +typedef struct PX_LEXER_CA_Container +{ + px_char ContainerBegin[8]; + px_char ContainerEnd[8]; + px_char transfer; +}PX_LEXER_CA_Container; + + +typedef struct PX_LEXER_CA_COMMENT +{ + px_char CommentBegin[8]; + px_char CommentEnd[8]; +}PX_LEXER_CA_Comment; + + +typedef enum __PX_LEXER_LEXEME_TYPE +{ + PX_LEXER_LEXEME_TYPE_END =0, + PX_LEXER_LEXEME_TYPE_SPACER =1, + PX_LEXER_LEXEME_TYPE_DELIMITER =2, + PX_LEXER_LEXEME_TYPE_CONATINER =3, + PX_LEXER_LEXEME_TYPE_NEWLINE =4, + PX_LEXER_LEXEME_TYPE_TOKEN =5, + PX_LEXER_LEXEME_TYPE_ERR = -1, +}PX_LEXER_LEXEME_TYPE; + +typedef struct __Pt_Lexer +{ + px_int ContainerCount; + px_int DelimiterCount; + px_int CommentCount; + px_char *Sources; + px_char SortComment; + px_ulong SourceOffset; + px_int SpacerCount; + px_char Symbol; + px_bool NumericMath; + px_uint CurrentDelimiterType; + px_uint CurrentContainerType; + px_uint CurrentCommentType; + + PX_LEXER_LEXEME_TYPE CurrentLexemeFlag; + PX_LEXER_SORT_STATUS SortStatus; + PX_LEXER_LEXEME_CASE lexemeTokenCase; + + px_string CurLexeme; + px_memorypool *mp; + + PX_LEXER_CA_Comment Comment[PX_LEXER_CA_COMMENT_MAX_COUNT]; + PX_LEXER_CA_Container Container[PX_LEXER_CA_CONTAINER_MAX_COUNT]; + px_char Spacer[PX_LEXER_CA_SPACER_MAX_COUNT]; + px_char Delimiter[PX_LEXER_CA_DELIMITER_MAX_COUNT]; + +}px_lexer; + +typedef struct __PX_LEXER_START +{ + px_int offset; + px_lexer *lexer; +}PX_LEXER_STATE; + +px_void PX_LexerInit(px_lexer *lexer,px_memorypool *mp); +px_void PX_LexerRegisterComment(px_lexer *lexer,const px_char Begin[],const px_char End[]); +px_int PX_LexerRegisterContainer(px_lexer *lexer,const px_char Begin[],const px_char End[]); +px_void PX_LexerRegisterContainerTransfer(px_lexer *lexer,px_uint containerIndex,px_char transfer); + +px_void PX_LexerRegisterSpacer(px_lexer *lexer,px_char Spacer); +px_int PX_LexerRegisterDelimiter(px_lexer *lexer,px_char Delimiter); +px_int PX_LexerGetDelimiterType(px_lexer *lexer,px_char Delimiter); +px_int PX_LexerGetContainerType(px_lexer *lexer,px_char *pContainerText); +px_int PX_LexerGetCurrentContainerType(px_lexer *lexer); +px_int PX_LexerGetCurrentDelimiterType(px_lexer *lexer); +px_void PX_LexerFree(px_lexer *lexer); +px_bool PX_LexerSortText(px_lexer *lexer,const px_char *SourceText); +px_bool PX_LexerLoadSourceFromMemory(px_lexer *lexer,const px_char *buffer); +px_bool PX_LexerSetSourcePointer(px_lexer *lexer,const px_char *buffer); +px_bool PX_LexerReadString(px_lexer *lexer,px_string *str,px_uint size); +px_char PX_LexerGetSymbol(px_lexer *lexer); +px_void PX_LexerGetLexemeString(px_lexer *lexer,px_string *str); +px_void PX_LexerGetIncludedString(px_lexer *lexer,px_string *str); +px_void PX_LexerSetTokenCase(px_lexer *lexer,PX_LEXER_LEXEME_CASE _case); +px_void PX_LexerSetNumericMatch(px_lexer *lexer,px_bool b); + +PX_LEXER_STATE PX_LexerGetState(px_lexer *lexer); +px_void PX_LexerSetState(PX_LEXER_STATE state); +px_bool PX_LexerIsLememeIsNumeric(px_lexer *lexer); +px_char PX_LexerGetNextChar(px_lexer *lexer); +PX_LEXER_LEXEME_TYPE PX_LexerGetNextLexeme(px_lexer *lexer); +PX_LEXER_LEXEME_TYPE PX_LexerGetCurrentLexeme(px_lexer *lexer); +#endif diff --git a/lib/PainterEngine/kernel/PX_LiveFramework.c b/lib/PainterEngine/kernel/PX_LiveFramework.c new file mode 100644 index 0000000000000000000000000000000000000000..5678855a38c96ea06ee782d671b81907ece5bb3f --- /dev/null +++ b/lib/PainterEngine/kernel/PX_LiveFramework.c @@ -0,0 +1,2733 @@ +#include "PX_LiveFramework.h" + +typedef struct +{ + px_point position; + px_point normal; + px_float u,v; +}PX_LiveRenderVertex; +static px_void PX_LiveFramework_RenderListPixelShaderFaster(px_surface *psurface,px_int x,px_int y,px_float z,px_float u,px_float v,px_point normal,px_texture *pTexture,PX_TEXTURERENDER_BLEND *blend) +{ + //texture mapping + + px_int resWidth; + px_int resHeight; + + if (u<0||u>1||v<0||v>1) + { + return; + } + + if (pTexture) + { + resWidth=pTexture->width; + resHeight=pTexture->height; + + PX_SurfaceDrawPixel(psurface,x,y,PX_SURFACECOLOR(pTexture,(px_int)(u*resWidth),(px_int)(v*resHeight))); + } +} +static px_void PX_LiveFramework_RenderListPixelShader(px_surface *psurface,px_int x,px_int y,px_float z,px_float u,px_float v,px_point normal,px_texture *pTexture,PX_TEXTURERENDER_BLEND *blend) +{ + //texture mapping + px_double SampleX,SampleY,mapX,mapY; + px_double mixa,mixr,mixg,mixb,Weight; + px_color sampleColor; + px_int resWidth; + px_int resHeight; + + if (u<0||u>1||v<0||v>1) + { + return; + } + + + if (pTexture) + { + resWidth=pTexture->width; + resHeight=pTexture->height; + u=PX_ABS(u); + v=PX_ABS(v); + u-=(px_int)u; + v-=(px_int)v; + + mapX=u*resWidth; + mapY=v*resHeight; + + if (mapX<-0.5||mapX>resWidth+0.5) + { + return; + } + if (mapY<-0.5||mapY>resHeight+0.5) + { + return; + } + mixa=0; + mixr=0; + mixg=0; + mixb=0; + //Sample 4 points + //lt + + SampleX=(mapX-0.5f); + SampleY=(mapY-0.5f); + + if (SampleX>0&&(SampleX)0&&(SampleY)0&&(SampleX)0&&(SampleY)0&&(SampleX)0&&(SampleY)0&&(SampleX)0&&(SampleY)alpha; + mixr*=blend->hdr_R; + mixg*=blend->hdr_G; + mixb*=blend->hdr_B; + } + + mixa>255?mixa=255:0; + mixr>255?mixr=255:0; + mixg>255?mixg=255:0; + mixb>255?mixb=255:0; + + PX_SurfaceDrawPixel(psurface,x,y,PX_COLOR((px_uchar)mixa,(px_uchar)mixr,(px_uchar)mixg,(px_uchar)mixb)); + + } +} +static px_void PX_LiveFramework_RenderListRasterization(px_surface *psurface,PX_LiveFramework *pLiveFramework,PX_LiveRenderVertex p0,PX_LiveRenderVertex p1,PX_LiveRenderVertex p2,px_texture *ptexture,PX_TEXTURERENDER_BLEND *blend) +{ + px_int ix,iy; + px_bool k01infinite=PX_FALSE; + px_bool k02infinite=PX_FALSE; + px_bool k12infinite=PX_FALSE; + px_float k01,b01,k02,b02,k12,b12; + px_float x0; + px_float y0; + px_float z0; + px_float s0; + px_float t0; + + px_float x1; + px_float y1; + px_float z1; + px_float s1; + px_float t1; + + px_float x2; + px_float y2; + px_float z2; + px_float s2; + px_float t2; + + + px_float y,xleft, xright; + px_float oneoverz_left, oneoverz_right; + px_float oneoverz_top, oneoverz_bottom; + px_float oneoverz, oneoverz_step; + px_float soverz_top, soverz_bottom; + px_float toverz_top, toverz_bottom; + px_float soverz_left, soverz_right; + px_float toverz_left, toverz_right; + px_float soverz, soverz_step; + px_float toverz, toverz_step; + px_float s, t; + px_float btmy,midy; + px_float originalZ; + + px_float a,b,c; + px_point position; + a=(px_float)PX_sqrtd((p1.position.x-p2.position.x)*(p1.position.x-p2.position.x)); + b=(px_float)PX_sqrtd((p0.position.x-p2.position.x)*(p0.position.x-p2.position.x)); + c=(px_float)PX_sqrtd((p1.position.x-p0.position.x)*(p1.position.x-p0.position.x)); + + position.x=(a*p0.position.x+b*p1.position.x+c*p2.position.x)/(a+b+c); + position.y=(a*p0.position.y+b*p1.position.y+c*p2.position.y)/(a+b+c); + + // p0 + // p1 p2 + + if (p1.position.ybtmy) + { + midy=p1.position.y; + btmy=p2.position.y; + } + + + + do + { + px_float x01m; + + x0=p0.position.x; + y0=p0.position.y; + x1=p1.position.x; + y1=p1.position.y; + x2=p2.position.x; + y2=p2.position.y; + + + if (x0==x1) + { + x01m=x0; + } + else + { + k01=(y0-y1)/(x0-x1); + b01=y0-k01*x0; + x01m=(y2-b01)/k01; + } + + if (x01m>x2) + { + PX_LiveRenderVertex t; + t=p2; + p2=p1; + p1=t; + } + } while (0); + + + + x0=p0.position.x; + y0=p0.position.y; + z0=p0.position.z; + s0=p0.u; + t0=p0.v; + + x1=p1.position.x; + y1=p1.position.y; + z1=p1.position.z; + s1=p1.u; + t1=p1.v; + + x2=p2.position.x; + y2=p2.position.y; + z2=p2.position.z; + s2=p2.u; + t2=p2.v; + + k01infinite=PX_FALSE; + k02infinite=PX_FALSE; + k12infinite=PX_FALSE; + if (x0==x1) + { + k01infinite=PX_TRUE; + k01 = 1; + b01=x0; + } + else + { + k01=(y0-y1)/(x0-x1); + b01=y0-k01*x0; + } + + if (x0==x2) + { + k02infinite=PX_TRUE; + k02 = 1; + b02=x0; + } + else + { + k02=(y0-y2)/(x0-x2); + b02=y0-k02*x0; + } + + if (x1==x2) + { + k12infinite=PX_TRUE; + b12=x0; + } + else + { + k12=(y1-y2)/(x1-x2); + b12=y1-k12*x1; + } + + + for(y = (px_int)(y0+0.5f)+0.5f; y <=midy; y++) + { + if (k01infinite) + { + xleft=b01; + } + else + { + xleft = (y-b01)/k01; + } + + if (k02infinite) + { + xright=b02; + } + else + { + xright = (y-b02)/k02; + } + + + oneoverz_top = 1.0f / z0; + oneoverz_bottom = 1.0f/z1; + oneoverz_left = (y-y0) * (oneoverz_bottom-oneoverz_top) / (y1-y0) + oneoverz_top; + oneoverz_bottom = 1.0f / z2; + oneoverz_right = (y-y0) * (oneoverz_bottom-oneoverz_top) / (y2-y0) + oneoverz_top; + oneoverz_step = (oneoverz_right-oneoverz_left) / (xright-xleft); + soverz_top = s0 / z0; + soverz_bottom = s1 / z1; + soverz_left = (y-y0) * (soverz_bottom-soverz_top) / (y1-y0) + soverz_top; + soverz_bottom = s2 / z2; + soverz_right = (y-y0) * (soverz_bottom-soverz_top) / (y2-y0) + soverz_top; + soverz_step = (soverz_right-soverz_left) / (xright-xleft); + toverz_top = t0 / z0; + toverz_bottom = t1 / z1; + toverz_left = (y-y0) * (toverz_bottom-toverz_top) / (y1-y0) + toverz_top; + toverz_bottom = t2 / z2; + toverz_right = (y-y0) * (toverz_bottom-toverz_top) / (y2-y0) + toverz_top; + toverz_step = (toverz_right-toverz_left) / (xright-xleft); + oneoverz = oneoverz_left,soverz = soverz_left, toverz = toverz_left; + + for(ix = (px_int)(xleft+0.5);ix < (px_int)(xright+0.5f); ++ix) + { + s = soverz / oneoverz; + t = toverz / oneoverz; + originalZ=1.0f/oneoverz; + + iy=(px_int)y; + if (pLiveFramework->pixelShader) + { + position.z=originalZ; + pLiveFramework->pixelShader(psurface,ix,iy,position,s,t,p0.normal,ptexture,blend); + } + else + { + PX_LiveFramework_RenderListPixelShader(psurface,ix,iy,originalZ,s,t,p0.normal,ptexture,blend); + } + + + oneoverz += oneoverz_step; + soverz += soverz_step; + toverz += toverz_step; + } + } + + // p1 p2 + // p0 + if (p1.position.y>p0.position.y) + { + PX_LiveRenderVertex t; + t=p1; + p1=p0; + p0=t; + } + + if (p2.position.y>p0.position.y) + { + PX_LiveRenderVertex t; + t=p2; + p2=p0; + p0=t; + } + + btmy=p1.position.y; + midy=p2.position.y; + if (p2.position.yx2) + { + PX_LiveRenderVertex t; + t=p2; + p2=p1; + p1=t; + } + } while (0); + + + + x0=p0.position.x; + y0=p0.position.y; + z0=p0.position.z; + s0=p0.u; + t0=p0.v; + + x1=p1.position.x; + y1=p1.position.y; + z1=p1.position.z; + s1=p1.u; + t1=p1.v; + + x2=p2.position.x; + y2=p2.position.y; + z2=p2.position.z; + s2=p2.u; + t2=p2.v; + + k01infinite=PX_FALSE; + k02infinite=PX_FALSE; + k12infinite=PX_FALSE; + if (x0==x1) + { + k01infinite=PX_TRUE; + b01=x0; + } + else + { + k01=(y0-y1)/(x0-x1); + b01=y0-k01*x0; + } + + if (x0==x2) + { + k02infinite=PX_TRUE; + b02=x0; + } + else + { + k02=(y0-y2)/(x0-x2); + b02=y0-k02*x0; + } + + if (x1==x2) + { + k12infinite=PX_TRUE; + b12=x0; + } + else + { + k12=(y1-y2)/(x1-x2); + b12=y1-k12*x1; + } + + + for(y = (px_int)(midy+0.5f)+0.5f; y < y0; y++) + { + if (k01infinite) + { + xleft=b01; + } + else + { + xleft = (y-b01)/k01; + } + + if (k02infinite) + { + xright=b02; + } + else + { + xright = (y-b02)/k02; + } + + + oneoverz_top = 1.0f / z0; + oneoverz_bottom = 1.0f/z1; + oneoverz_left = (y-y0) * (oneoverz_bottom-oneoverz_top) / (y1-y0) + oneoverz_top; + oneoverz_bottom = 1.0f / z2; + oneoverz_right = (y-y0) * (oneoverz_bottom-oneoverz_top) / (y2-y0) + oneoverz_top; + oneoverz_step = (oneoverz_right-oneoverz_left) / (xright-xleft); + soverz_top = s0 / z0; + soverz_bottom = s1 / z1; + soverz_left = (y-y0) * (soverz_bottom-soverz_top) / (y1-y0) + soverz_top; + soverz_bottom = s2 / z2; + soverz_right = (y-y0) * (soverz_bottom-soverz_top) / (y2-y0) + soverz_top; + soverz_step = (soverz_right-soverz_left) / (xright-xleft); + toverz_top = t0 / z0; + toverz_bottom = t1 / z1; + toverz_left = (y-y0) * (toverz_bottom-toverz_top) / (y1-y0) + toverz_top; + toverz_bottom = t2 / z2; + toverz_right = (y-y0) * (toverz_bottom-toverz_top) / (y2-y0) + toverz_top; + toverz_step = (toverz_right-toverz_left) / (xright-xleft); + oneoverz = oneoverz_left,soverz = soverz_left, toverz = toverz_left; + + for(ix = (px_int)(xleft+0.5);ix < (px_int)(xright+0.5f); ++ix) + { + s = soverz / oneoverz; + t = toverz / oneoverz; + originalZ=1.0f/oneoverz; + iy=(px_int)y; + if (pLiveFramework->pixelShader) + { + position.z=originalZ; + pLiveFramework->pixelShader(psurface,ix,iy,position,s,t,p0.normal,ptexture,blend); + } + else + { + PX_LiveFramework_RenderListPixelShader(psurface,ix,iy,originalZ,s,t,p0.normal,ptexture,blend); + } + oneoverz += oneoverz_step; + soverz += soverz_step; + toverz += toverz_step; + } + } + +} + +px_bool PX_LiveFrameworkInitialize(px_memorypool *mp,PX_LiveFramework *plive,px_int width,px_int height) +{ + PX_memset(plive,0,sizeof(PX_LiveFramework)); + plive->mp=mp; + if(!PX_VectorInitialize(mp,&plive->layers,sizeof(PX_LiveLayer),1))return PX_FALSE; + if(!PX_VectorInitialize(mp,&plive->livetextures,sizeof(PX_LiveTexture),1))return PX_FALSE; + if(!PX_VectorInitialize(mp,&plive->liveAnimations,sizeof(PX_LiveAnimation),1))return PX_FALSE; + plive->width=width; + plive->height=height; + plive->showFocusLayer=PX_TRUE; + plive->currentEditAnimationIndex=-1; + plive->currentEditFrameIndex=-1; + plive->currentEditVertexIndex=-1; + plive->currentEditLayerIndex=-1; + return PX_TRUE; +} + +px_void PX_LiveFrameworkPlay(PX_LiveFramework *plive) +{ + plive->status=PX_LIVEFRAMEWORK_STATUS_PLAYING; +} + +px_void PX_LiveFrameworkPause(PX_LiveFramework *plive) +{ + plive->status=PX_LIVEFRAMEWORK_STATUS_STOP; +} + +px_void PX_LiveFrameworkReset(PX_LiveFramework *plive) +{ + px_int i; + plive->reg_duration=0; + plive->reg_ip=0; + plive->reg_elapsed=0; + plive->reg_bp=-1; + plive->status=PX_LIVEFRAMEWORK_STATUS_STOP; + + for (i=0;ilayers.size;i++) + { + px_int j; + PX_LiveLayer *pLayer=PX_VECTORAT(PX_LiveLayer,&plive->layers,i); + pLayer->rel_beginRotationAngle=0; + pLayer->rel_currentRotationAngle=0; + pLayer->rel_endRotationAngle=0; + + pLayer->rel_beginTranslation=PX_POINT(0,0,0); + pLayer->rel_currentTranslation=PX_POINT(0,0,0); + pLayer->rel_endTranslation=PX_POINT(0,0,0); + + pLayer->rel_beginStretch=1; + pLayer->rel_currentStretch=1; + pLayer->rel_endStretch=1; + + pLayer->RenderTextureIndex=pLayer->LinkTextureIndex; + + for (j=0;jvertices.size;j++) + { + PX_LiveVertex *pVertex=PX_VECTORAT(PX_LiveVertex,&pLayer->vertices,j); + pVertex->beginTranslation=PX_POINT(0,0,0); + pVertex->currentTranslation=PX_POINT(0,0,0); + pVertex->endTranslation=PX_POINT(0,0,0); + + pVertex->currentPosition=pVertex->sourcePosition; + pVertex->velocity=PX_POINT(0,0,0); + } + } +} + +px_void PX_LiveFrameworkStop(PX_LiveFramework *plive) +{ + PX_LiveFrameworkReset(plive); +} + +static px_void PX_LiveFrameworkUpdateLayerInterpolation(PX_LiveFramework *plive,PX_LiveLayer *pLayer) +{ + px_float schedule; + px_int i; + + if (plive->status==PX_LIVEFRAMEWORK_STATUS_STOP) + { + schedule = 1; + } + else if (plive->reg_duration==0) + { + schedule=1; + } + else + { + schedule=plive->reg_elapsed*1.0f/plive->reg_duration; + } + + if (schedule>1) + { + schedule=1; + } + + //update parameters + pLayer->panc_currentx= pLayer->panc_beginx + (pLayer->panc_endx - pLayer->panc_beginx) * schedule; + pLayer->panc_currenty = pLayer->panc_beginy + (pLayer->panc_endy - pLayer->panc_beginy) * schedule; + + //point translation + for (i=0;ivertices.size;i++) + { + px_point *pbegin,*pcurrent,*pend; + pbegin=&PX_VECTORAT(PX_LiveVertex,&pLayer->vertices,i)->beginTranslation; + pcurrent=&PX_VECTORAT(PX_LiveVertex,&pLayer->vertices,i)->currentTranslation; + pend=&PX_VECTORAT(PX_LiveVertex,&pLayer->vertices,i)->endTranslation; + + pcurrent->x=pbegin->x+(pend->x-pbegin->x)*schedule; + pcurrent->y=pbegin->y+(pend->y-pbegin->y)*schedule; + } + + if (pLayer->parent_index!=-1) + { + //stretch + pLayer->rel_currentStretch=pLayer->rel_beginStretch+(pLayer->rel_endStretch-pLayer->rel_beginStretch)*schedule; + } + else + { + //keypoint translation + pLayer->rel_currentTranslation.x=pLayer->rel_beginTranslation.x+(pLayer->rel_endTranslation.x-pLayer->rel_beginTranslation.x)*schedule; + pLayer->rel_currentTranslation.y=pLayer->rel_beginTranslation.y+(pLayer->rel_endTranslation.y-pLayer->rel_beginTranslation.y)*schedule; + pLayer->rel_currentTranslation.z=0; + } + + //rotation + pLayer->rel_currentRotationAngle=pLayer->rel_beginRotationAngle+(pLayer->rel_endRotationAngle-pLayer->rel_beginRotationAngle)*schedule; + + + +} + +static px_void PX_LiveFramework_UpdateLayerKeyPoint(PX_LiveFramework *pLive,PX_LiveLayer *pLayer) +{ + px_int i; + if (pLayer->parent_index!=-1) + { + //stretch + px_point v=PX_PointSub(pLayer->keyPoint,PX_LiveFrameworkGetLayerParent(pLive,pLayer)->keyPoint); + v=PX_PointMul(v,pLayer->rel_currentStretch); + v=PX_PointRotate(v,PX_LiveFrameworkGetLayerParent(pLive,pLayer)->rel_currentRotationAngle); + pLayer->currentKeyPoint=PX_PointAdd(v,PX_LiveFrameworkGetLayerParent(pLive,pLayer)->currentKeyPoint); + } + else + { + pLayer->currentKeyPoint=PX_PointAdd(pLayer->keyPoint,pLayer->rel_currentTranslation); + } + pLayer->currentKeyPoint.z=pLayer->keyPoint.z; + + for (i=0;ichild_index);i++) + { + if (pLayer->child_index[i]!=-1) + { + PX_LiveFramework_UpdateLayerKeyPoint(pLive,PX_LiveFrameworkGetLayerChild(pLive,pLayer,pLayer->child_index[i])); + } + else + { + break; + } + } +} + +static px_void PX_LiveFramework_UpdateLayerVertices(PX_LiveFramework *pLive,PX_LiveLayer *pLayer,px_dword elapsed) +{ + px_int i; + px_point2D keyDirection; + px_int k; + + + PX_LiveFrameworkUpdateLayerRenderVerticesUV(pLive,pLayer); + + if (pLayer->child_index[0]==-1) + { + keyDirection=PX_POINT2D(0,1); + } + else + { + keyDirection=PX_POINT2D(0,0); + for (i=0;ichild_index);i++) + { + px_point v; + if (pLayer->child_index[i]==-1) + { + break; + } + + v=PX_PointNormalization(PX_PointSub(pLayer->currentKeyPoint,PX_LiveFrameworkGetLayerChild(pLive,pLayer,pLayer->child_index[i])->currentKeyPoint)); + keyDirection=PX_Point2DAdd(keyDirection,PX_POINT2D(v.x,v.y)); + } + keyDirection=PX_Point2DNormalization(keyDirection); + } + + //for each vertex + for (i=0;ivertices.size;i++) + { + PX_LiveVertex *plv=PX_VECTORAT(PX_LiveVertex,&pLayer->vertices,i); + px_point resultPosition; + + //get relative position + resultPosition.x=plv->sourcePosition.x-pLayer->keyPoint.x; + resultPosition.y=plv->sourcePosition.y-pLayer->keyPoint.y; + resultPosition.z=plv->sourcePosition.z-pLayer->keyPoint.z; + //panc translation + if (pLayer->panc_currentx!=pLayer->panc_sx|| pLayer->panc_currenty != pLayer->panc_sy) + { + if (plv->sourcePosition.x>pLayer->panc_x&& plv->sourcePosition.x < pLayer->panc_x+pLayer->panc_width) + { + if (plv->sourcePosition.x < pLayer->panc_sx) + { + px_float disx = plv->sourcePosition.x - pLayer->panc_x; + resultPosition.x += disx * (pLayer->panc_currentx-pLayer->panc_x) /(pLayer->panc_sx- pLayer->panc_x) - disx; + } + else + { + px_float disx = (pLayer->panc_x+pLayer->panc_width)- plv->sourcePosition.x; + resultPosition.x -= disx * (pLayer->panc_x + pLayer->panc_width - pLayer->panc_currentx) / (pLayer->panc_x + pLayer->panc_width - pLayer->panc_sx) - disx; + } + } + + if (plv->sourcePosition.y > pLayer->panc_y && plv->sourcePosition.y < pLayer->panc_y + pLayer->panc_height) + { + if (plv->sourcePosition.y < pLayer->panc_sy) + { + px_float disy = plv->sourcePosition.y - pLayer->panc_y; + resultPosition.y += disy * (pLayer->panc_currenty - pLayer->panc_y) / (pLayer->panc_sy - pLayer->panc_y) - disy; + } + else + { + px_float disy = (pLayer->panc_y + pLayer->panc_height) - plv->sourcePosition.y; + resultPosition.y -= disy * (pLayer->panc_y + pLayer->panc_height - pLayer->panc_currenty) / (pLayer->panc_y + pLayer->panc_height - pLayer->panc_sy) - disy; + } + } + + + } + + + //relative translation + resultPosition.x+=plv->currentTranslation.x; + resultPosition.y+=plv->currentTranslation.y; + resultPosition.z+=plv->currentTranslation.z; + + //stretch + do + { + px_int j; + for (j=0;jchild_index);j++) + { + PX_LiveLayer *pChild=PX_LiveFrameworkGetLayerChild(pLive,pLayer,pLayer->child_index[j]); + if(!pChild) + break; + + + if (pChild->rel_currentStretch!=1) + { + px_float cos_v12; + px_point v1,v2,u1; + v1=PX_PointSub(pChild->keyPoint,pLayer->keyPoint); + v2=resultPosition; + cos_v12=PX_PointDot(v1,v2)/PX_PointMod(v1)/PX_PointMod(v2); + if (cos_v12>0) + { + px_float distance; + u1=PX_PointNormalization(v1); + distance=cos_v12*PX_PointMod(v2); + resultPosition=PX_PointAdd(resultPosition,PX_PointMul(u1,distance*(pChild->rel_currentStretch-1))); + } + } + } + } while (0); + + + //Rotation + resultPosition=PX_PointRotate(resultPosition,pLayer->rel_currentRotationAngle); + + //absolute translation + resultPosition.x+=pLayer->currentKeyPoint.x; + resultPosition.y+=pLayer->currentKeyPoint.y; + + + //elastic + k=plv->k; + + if (k==0) + { + plv->currentPosition=resultPosition; + } + else + { + px_point2D direction,direction_normal; + px_float distance; + px_dword updateelapsed=elapsed+elapsed/2; + px_dword atomelapsed; + + while (updateelapsed) + { + if (updateelapsed>50) + { + atomelapsed=50; + updateelapsed-=50; + } + else + { + atomelapsed=updateelapsed; + updateelapsed=0; + } + direction.x=resultPosition.x-plv->currentPosition.x; + direction.y=resultPosition.y-plv->currentPosition.y; + + direction_normal=PX_Point2DNormalization(direction); + distance=PX_Point2DMod(direction); + + + if (distance>k) + { + plv->currentPosition.x=resultPosition.x-direction_normal.x*(k); + plv->currentPosition.y=resultPosition.y-direction_normal.y*(k); + distance=k*1.0f; + } + + + do + { + px_point2D incv=PX_Point2DMul(direction_normal,distance*distance); + px_point2D velocity; + px_point velocity_vx,velocity_vy; + px_float _cos,length; + incv.x+=pLayer->rel_impulse.x; + incv.y+=pLayer->rel_impulse.y; + incv=PX_Point2DMul(incv,atomelapsed/1000.f); + velocity=PX_Point2DAdd(PX_POINT2D(plv->velocity.x,plv->velocity.y),incv); + if (velocity.x||velocity.y) + { + //resistance + _cos=PX_Point2DDot(velocity,keyDirection)/PX_Point2DMod(velocity)/PX_Point2DMod(keyDirection); + length=_cos*PX_Point2DMod(velocity); + velocity_vx.x=length*keyDirection.x; + velocity_vx.y=length*keyDirection.y; + velocity_vx.z=0; + + velocity_vy.x=velocity.x-velocity_vx.x; + velocity_vy.y=velocity.y-velocity_vx.y; + velocity_vy.z=0; + + + velocity_vx=PX_PointMul(velocity_vx,1.0f-atomelapsed/(k*10.f+50)); + velocity_vy=PX_PointMul(velocity_vy,1.0f-atomelapsed/(k*30.f+50)); + + if (velocity_vx.x>10000||velocity_vx.y>10000||velocity_vy.x>10000||velocity_vy.y>10000) + { + PX_ASSERT(); + } + + plv->velocity=PX_PointAdd(velocity_vx,velocity_vy); + } + plv->currentPosition=PX_PointAdd(plv->currentPosition,PX_PointMul(plv->velocity,atomelapsed/1000.f)); + + }while(0); + } + + } + + } +} + +static px_void PX_LiveFrameworkUpdatePhysical(PX_LiveFramework *plive,px_dword elapsed) +{ + px_int i; + + for (i=0;ilayers.size;i++) + { + PX_LiveLayer *pLayer=PX_VECTORAT(PX_LiveLayer,&plive->layers,i); + PX_LiveFrameworkUpdateLayerInterpolation(plive,pLayer); + } + + //LayerUpdate + for (i=0;ilayers.size;i++) + { + PX_LiveLayer *pLayer=PX_VECTORAT(PX_LiveLayer,&plive->layers,i); + if (pLayer->parent_index==-1) + { + PX_LiveFramework_UpdateLayerKeyPoint(plive,pLayer); + } + } + + for (i=0;ilayers.size;i++) + { + PX_LiveLayer *pLayer=PX_VECTORAT(PX_LiveLayer,&plive->layers,i); + PX_LiveFramework_UpdateLayerVertices(plive,pLayer,elapsed); + } +} + +static px_bool PX_LiveFrameworkExecuteInstr(PX_LiveFramework *plive,px_int animation_index,px_int frameindex) +{ + //execute instr + px_int frame_offset=0,frame_size=0; + px_int layerindex=0; + PX_LiveAnimation *pAnimation; + px_byte *pFrameInstrData; + PX_LiveAnimationFrameHeader *pFrameHeader; + if (animation_index<0||animation_index>=plive->liveAnimations.size) + { + goto _ERROR; + } + pAnimation=PX_VECTORAT(PX_LiveAnimation,&plive->liveAnimations,animation_index); + if (frameindex<0) + { + goto _ERROR; + } + if (frameindex >= pAnimation->framesMemPtr.size) + { + goto _ERROR; + } + pFrameInstrData=*PX_VECTORAT(px_byte *,&pAnimation->framesMemPtr,frameindex); + pFrameHeader=(PX_LiveAnimationFrameHeader *)pFrameInstrData; + frame_size=pFrameHeader->size+sizeof(PX_LiveAnimationFrameHeader); + ////////////////////////////////////////////////////////////////////////// + //time stamp update + plive->reg_duration=pFrameHeader->duration_ms; + frame_offset+=sizeof(PX_LiveAnimationFrameHeader); + ////////////////////////////////////////////////////////////////////////// + //payload + ////////////////////////////////////////////////////////////////////////// + while (frame_offsetlayers,layerindex); + + ////////////////////////////////////////////////////////////////////////// + //maptexture + pLayer->RenderTextureIndex=pPayload->mapTexture; + + ////////////////////////////////////////////////////////////////////////// + //rotation register + pLayer->rel_beginRotationAngle=pLayer->rel_endRotationAngle; + pLayer->rel_currentRotationAngle=pLayer->rel_beginRotationAngle; + pLayer->rel_endRotationAngle=pPayload->rotation; + + ////////////////////////////////////////////////////////////////////////// + //stretch register + pLayer->rel_beginStretch=pLayer->rel_endStretch; + pLayer->rel_currentStretch=pLayer->rel_beginStretch; + pLayer->rel_endStretch=pPayload->stretch; + + ////////////////////////////////////////////////////////////////////////// + //translation register + pLayer->rel_beginTranslation=pLayer->rel_endTranslation; + pLayer->rel_currentTranslation=pLayer->rel_beginTranslation; + pLayer->rel_endTranslation=pPayload->translation; + + ////////////////////////////////////////////////////////////////////////// + //impulse + pLayer->rel_impulse=pPayload->impulse; + + + ////////////////////////////////////////////////////////////////////////// + //panc + pLayer->panc_x = pPayload->panc_x; + pLayer->panc_y = pPayload->panc_y; + + pLayer->panc_width = pPayload->panc_width; + pLayer->panc_height = pPayload->panc_height; + + pLayer->panc_sx = pPayload->panc_sx; + pLayer->panc_sy = pPayload->panc_sy; + + pLayer->panc_beginx = pLayer->panc_endx; + pLayer->panc_beginy = pLayer->panc_endy; + + pLayer->panc_currentx = pLayer->panc_beginx; + pLayer->panc_currenty = pLayer->panc_beginy; + + pLayer->panc_endx = pPayload->panc_endx; + pLayer->panc_endy = pPayload->panc_endy; + + ////////////////////////////////////////////////////////////////////////// + //vertices register + if (pPayload->translationVerticesCount!=pLayer->vertices.size) + { + goto _ERROR; + } + else + { + px_int j; + px_point *pVertexTranslation=(px_point *)(pFrameInstrData+frame_offset+sizeof(PX_LiveAnimationFramePayload)); + + for (j=0;j<(px_int)pPayload->translationVerticesCount;j++) + { + PX_VECTORAT(PX_LiveVertex,&pLayer->vertices,j)->beginTranslation=PX_VECTORAT(PX_LiveVertex,&pLayer->vertices,j)->endTranslation; + PX_VECTORAT(PX_LiveVertex,&pLayer->vertices,j)->currentTranslation=PX_VECTORAT(PX_LiveVertex,&pLayer->vertices,j)->beginTranslation; + PX_VECTORAT(PX_LiveVertex,&pLayer->vertices,j)->endTranslation=pVertexTranslation[j]; + } + } + frame_offset+=sizeof(PX_LiveAnimationFramePayload); + frame_offset+=sizeof(px_point)*pPayload->translationVerticesCount; + layerindex++; + } + if (layerindex!=plive->layers.size) + { + goto _ERROR; + } + return PX_TRUE; +_ERROR: + return PX_FALSE; +} + +static px_void PX_LiveFrameworkUpdateVM(PX_LiveFramework *plive,px_dword elapsed) +{ + if (plive->status==PX_LIVEFRAMEWORK_STATUS_STOP) + { + return; + } + + plive->reg_elapsed+=elapsed; + + + while (PX_TRUE) + { + + if (plive->reg_elapsed>=plive->reg_duration) + { + px_dword duration = plive->reg_duration; + if (!PX_LiveFrameworkExecuteInstr(plive, plive->reg_animation, plive->reg_ip)) + { + plive->status = PX_LIVEFRAMEWORK_STATUS_STOP; + goto _ERROR; + } + + //update time + plive->reg_elapsed -= duration; + + //update ip + plive->reg_ip++; + } + else + break; + } + return; +_ERROR: + return; +} + +static px_void PX_LiveFrameworkRenderLayer(px_surface *psurface,PX_LiveFramework *plive,PX_LiveLayer *pLayer,px_int x,px_int y,px_dword elapsed) +{ + PX_TEXTURERENDER_BLEND blend; + PX_LiveTexture *pLiveTexture; + if (!pLayer->visible) + { + return; + } + pLiveTexture=PX_LiveFrameworkGetLiveTexture(plive,pLayer->RenderTextureIndex); + if (pLiveTexture) + { + px_texture *pTexture; + pTexture=&pLiveTexture->Texture; + + if (pLayer->triangles.size&&pLayer->vertices.size) + { + px_int t; + PX_Delaunay_Triangle *pTriangleIndex; + for (t=0;ttriangles.size;t++) + { + PX_LiveRenderVertex v0,v1,v2; + PX_LiveVertex *pv0,*pv1,*pv2; + pTriangleIndex=PX_VECTORAT(PX_Delaunay_Triangle,&pLayer->triangles,t); + pv0=PX_VECTORAT(PX_LiveVertex,&pLayer->vertices,pTriangleIndex->index1); + pv1=PX_VECTORAT(PX_LiveVertex,&pLayer->vertices,pTriangleIndex->index2); + pv2=PX_VECTORAT(PX_LiveVertex,&pLayer->vertices,pTriangleIndex->index3); + v0.position.x=pv0->currentPosition.x+x; + v0.position.y=pv0->currentPosition.y+y; + v0.position.z=1; + v0.normal=pv0->normal; + v0.u=pv0->u; + v0.v=pv0->v; + + v1.position.x=pv1->currentPosition.x+x; + v1.position.y=pv1->currentPosition.y+y; + v1.position.z=1; + v1.normal=pv1->normal; + v1.u=pv1->u; + v1.v=pv1->v; + + v2.position.x=pv2->currentPosition.x+x; + v2.position.y=pv2->currentPosition.y+y; + v2.position.z=1; + v2.normal=pv2->normal; + v2.u=pv2->u; + v2.v=pv2->v; + + if (plive->currentEditLayerIndex>=0&&plive->currentEditLayerIndexlayers.size) + { + if (pLayer==PX_VECTORAT(PX_LiveLayer,&plive->layers,plive->currentEditLayerIndex)||!plive->showFocusLayer) + { + PX_LiveFramework_RenderListRasterization(psurface,plive,v0,v1,v2,pTexture,PX_NULL); + } + else + { + blend.alpha=0.2f; + blend.hdr_B=1; + blend.hdr_G=1; + blend.hdr_R=1; + PX_LiveFramework_RenderListRasterization(psurface,plive,v0,v1,v2,pTexture,&blend); + } + } + else + { + PX_LiveFramework_RenderListRasterization(psurface,plive,v0,v1,v2,pTexture,PX_NULL); + } + + } + + if (pLayer->showMesh) + { + for (t=0;ttriangles.size;t++) + { + PX_LiveRenderVertex v0,v1,v2; + PX_LiveVertex *pv0,*pv1,*pv2; + pTriangleIndex=PX_VECTORAT(PX_Delaunay_Triangle,&pLayer->triangles,t); + pv0=PX_VECTORAT(PX_LiveVertex,&pLayer->vertices,pTriangleIndex->index1); + pv1=PX_VECTORAT(PX_LiveVertex,&pLayer->vertices,pTriangleIndex->index2); + pv2=PX_VECTORAT(PX_LiveVertex,&pLayer->vertices,pTriangleIndex->index3); + v0.position.x=pv0->currentPosition.x+x; + v0.position.y=pv0->currentPosition.y+y; + v0.normal=pv0->normal; + v0.u=pv0->u; + v0.v=pv0->v; + + v1.position.x=pv1->currentPosition.x+x; + v1.position.y=pv1->currentPosition.y+y; + v1.normal=pv1->normal; + v1.u=pv1->u; + v1.v=pv1->v; + + v2.position.x=pv2->currentPosition.x+x; + v2.position.y=pv2->currentPosition.y+y; + v2.normal=pv2->normal; + v2.u=pv2->u; + v2.v=pv2->v; + + + PX_GeoDrawLine(psurface,(px_int)v0.position.x,(px_int)v0.position.y,(px_int)v1.position.x,(px_int)v1.position.y,1,PX_COLOR(128,255,0,0)); + PX_GeoDrawLine(psurface,(px_int)v0.position.x,(px_int)v0.position.y,(px_int)v2.position.x,(px_int)v2.position.y,1,PX_COLOR(128,255,0,0)); + PX_GeoDrawLine(psurface,(px_int)v1.position.x,(px_int)v1.position.y,(px_int)v2.position.x,(px_int)v2.position.y,1,PX_COLOR(128,255,0,0)); + + PX_GeoDrawSolidCircle(psurface,(px_int)v0.position.x,(px_int)v0.position.y,3,PX_COLOR(128,255,0,0)); + PX_GeoDrawSolidCircle(psurface,(px_int)v1.position.x,(px_int)v1.position.y,3,PX_COLOR(128,255,0,0)); + PX_GeoDrawSolidCircle(psurface,(px_int)v2.position.x,(px_int)v2.position.y,3,PX_COLOR(128,255,0,0)); + } + + if (plive->currentEditLayerIndex>=0&&plive->currentEditLayerIndexlayers.size) + { + if (pLayer==PX_VECTORAT(PX_LiveLayer,&plive->layers,plive->currentEditLayerIndex)) + { + if (plive->currentEditVertexIndex>=0&&plive->currentEditVertexIndexvertices.size) + { + PX_LiveVertex *pLiveVertex=PX_VECTORAT(PX_LiveVertex,&pLayer->vertices,plive->currentEditVertexIndex); + PX_GeoDrawCircle(psurface,(px_int)(pLiveVertex->currentPosition.x+x),(px_int)(pLiveVertex->currentPosition.y+y),5,1,PX_COLOR(255,255,128,0)); + } + } + } + + } + } + else + { + if (plive->currentEditLayerIndex>=0&&plive->currentEditLayerIndexlayers.size) + { + if (plive->showFocusLayer) + { + if (pLayer==PX_VECTORAT(PX_LiveLayer,&plive->layers,plive->currentEditLayerIndex)) + { + PX_TextureRender(psurface,pTexture,(px_int)(x+pLiveTexture->textureOffsetX), + (px_int)(y+pLiveTexture->textureOffsetY),PX_ALIGN_LEFTTOP,PX_NULL); + } + else + { + blend.alpha=0.2f; + blend.hdr_B=1; + blend.hdr_G=1; + blend.hdr_R=1; + PX_TextureRender(psurface,pTexture,(px_int)(x+pLiveTexture->textureOffsetX), + (px_int)(y+pLiveTexture->textureOffsetY),PX_ALIGN_LEFTTOP,&blend); + } + } + else + { + PX_TextureRender(psurface,pTexture,(px_int)(x+pLiveTexture->textureOffsetX), + (px_int)(y+pLiveTexture->textureOffsetY),PX_ALIGN_LEFTTOP,PX_NULL); + } + + } + else + { + PX_TextureRender(psurface,pTexture,(px_int)(x+pLiveTexture->textureOffsetX), + (px_int)(y+pLiveTexture->textureOffsetY),PX_ALIGN_LEFTTOP,PX_NULL); + + } + } + + } +} + +px_void PX_LiveFrameworkRender(px_surface *psurface,PX_LiveFramework *plive,px_int x,px_int y,PX_ALIGN refPoint,px_dword elapsed) +{ + PX_QuickSortAtom sAtom[PX_LIVEFRAMEWORK_MAX_SUPPORT_LAYER]; + px_int i,count; + + PX_LiveFrameworkUpdateVM(plive,elapsed); + PX_LiveFrameworkUpdatePhysical(plive,elapsed); + switch (refPoint) + { + case PX_ALIGN_LEFTTOP: + break; + case PX_ALIGN_MIDTOP: + x-=plive->width/2; + break; + case PX_ALIGN_RIGHTTOP: + x-=plive->width; + break; + case PX_ALIGN_LEFTMID: + y-=plive->height/2; + break; + case PX_ALIGN_CENTER: + y-=plive->height/2; + x-=plive->width/2; + break; + case PX_ALIGN_RIGHTMID: + y-=plive->height/2; + x-=plive->width; + break; + case PX_ALIGN_LEFTBOTTOM: + y-=plive->height; + break; + case PX_ALIGN_MIDBOTTOM: + y-=plive->height; + x-=plive->width/2; + break; + case PX_ALIGN_RIGHTBOTTOM: + y-=plive->height; + x-=plive->width; + break; + } + + + if (plive->layers.size) + { + for (i=0;ilayers.size;i++) + { + PX_LiveLayer *pLayer=PX_VECTORAT(PX_LiveLayer,&plive->layers,i); + sAtom[i].weight=pLayer->currentKeyPoint.z; + sAtom[i].pData=pLayer; + if (i>=PX_LIVEFRAMEWORK_MAX_SUPPORT_LAYER-1) + { + break; + } + } + count=i; + PX_Quicksort_MaxToMin(sAtom,0,count-1); + + for (i=0;ishowKeypoint&&!plive->showlinker) + { + for (i=0;ilayers.size;i++) + { + PX_LiveLayer *pLayer=PX_VECTORAT(PX_LiveLayer,&plive->layers,i); + if (pLayer->parent_index!=-1) + { + PX_GeoDrawSolidCircle(psurface,(px_int)(pLayer->currentKeyPoint.x+plive->refer_x),(px_int)(pLayer->currentKeyPoint.y+plive->refer_y),3,PX_COLOR(255,0,64,192)); + PX_GeoDrawCircle(psurface,(px_int)(pLayer->currentKeyPoint.x+plive->refer_x),(px_int)(pLayer->currentKeyPoint.y+plive->refer_y),5,1,PX_COLOR(255,0,64,192)); + } + else + { + PX_GeoDrawSolidCircle(psurface,(px_int)(pLayer->currentKeyPoint.x+plive->refer_x),(px_int)(pLayer->currentKeyPoint.y+plive->refer_y),3,PX_COLOR(255,255,0,0)); + PX_GeoDrawCircle(psurface,(px_int)(pLayer->currentKeyPoint.x+plive->refer_x),(px_int)(pLayer->currentKeyPoint.y+plive->refer_y),5,1,PX_COLOR(255,255,0,0)); + } + + } + } + + if (plive->showlinker) + { + for (i=0;ilayers.size;i++) + { + px_int j; + PX_LiveLayer *pLayer=PX_VECTORAT(PX_LiveLayer,&plive->layers,i); + + if (pLayer->parent_index!=-1) + { + PX_GeoDrawSolidCircle(psurface,(px_int)(pLayer->currentKeyPoint.x+plive->refer_x),(px_int)(pLayer->currentKeyPoint.y+plive->refer_y),3,PX_COLOR(255,0,64,192)); + PX_GeoDrawCircle(psurface,(px_int)(pLayer->currentKeyPoint.x+plive->refer_x),(px_int)(pLayer->currentKeyPoint.y+plive->refer_y),5,1,PX_COLOR(255,0,64,192)); + } + else + { + PX_GeoDrawSolidCircle(psurface,(px_int)(pLayer->currentKeyPoint.x+plive->refer_x),(px_int)(pLayer->currentKeyPoint.y+plive->refer_y),3,PX_COLOR(255,255,0,0)); + PX_GeoDrawCircle(psurface,(px_int)(pLayer->currentKeyPoint.x+plive->refer_x),(px_int)(pLayer->currentKeyPoint.y+plive->refer_y),5,1,PX_COLOR(255,255,0,0)); + } + + for (j=0;jchild_index[j]); + + if (!pLinkLayer) + { + break; + } + + PX_GeoDrawArrow(psurface, + PX_POINT2D(pLayer->currentKeyPoint.x+plive->refer_x,pLayer->currentKeyPoint.y+plive->refer_y), + PX_POINT2D(pLinkLayer->currentKeyPoint.x+plive->refer_x,pLinkLayer->currentKeyPoint.y+plive->refer_y), + 1, + PX_COLOR(255,255,0,0) + ); + + } + } + } + + + if (plive->showRange) + { + PX_GeoDrawBorder(psurface,x,y,x+plive->width,y+plive->height,1,PX_COLOR(255,0,0,255)); + } + + if (plive->showRootHelperLine) + { + PX_LiveLayer *pLayer=PX_LiveFrameworkGetCurrentEditLiveLayer(plive); + if (pLayer&&pLayer->parent_index==-1) + { + PX_GeoDrawLine(psurface,(px_int)(x+pLayer->keyPoint.x),(px_int)(y+pLayer->keyPoint.y),(px_int)(x+pLayer->currentKeyPoint.x),(px_int)(y+pLayer->currentKeyPoint.y),1,PX_COLOR(255,255,0,255)); + } + } + +} + +px_void PX_LiveFrameworkRenderRefer(px_surface *psurface,PX_LiveFramework *plive,PX_ALIGN refPoint,px_dword elapsed) +{ + PX_LiveFrameworkRender(psurface,plive,(px_int)plive->refer_x,(px_int)plive->refer_y,refPoint,elapsed); +} + + + +px_bool PX_LiveFrameworkPlayAnimation(PX_LiveFramework *plive,px_int index) +{ + if (index>=0&&indexliveAnimations.size) + { + plive->currentEditFrameIndex=-1; + plive->currentEditLayerIndex=-1; + plive->currentEditVertexIndex=-1; + plive->reg_animation=index; + plive->reg_ip = 0; + plive->status=PX_LIVEFRAMEWORK_STATUS_PLAYING; + return PX_TRUE; + } + return PX_FALSE; +} + +px_bool PX_LiveFrameworkPlayAnimationByName(PX_LiveFramework *plive,const px_char name[]) +{ + px_int i; + for (i=0;iliveAnimations.size;i++) + { + PX_LiveAnimation *pAnimation=PX_VECTORAT(PX_LiveAnimation,&plive->liveAnimations,i); + if (PX_strequ(name,pAnimation->id)) + { + PX_LiveFrameworkPlayAnimation(plive,i); + return PX_TRUE; + } + } + return PX_FALSE; +} + +PX_LiveLayer * PX_LiveFrameworkGetLayerById(PX_LiveFramework *plive,const px_char id[]) +{ + px_int i; + for (i=0;ilayers.size;i++) + { + PX_LiveLayer *pLayer=PX_LiveFrameworkGetLayer(plive,i); + if (pLayer&&PX_memequ(pLayer->id,id,PX_LIVE_ID_MAX_LEN)) + { + return pLayer; + } + } + return PX_NULL; +} + +PX_LiveLayer * PX_LiveFrameworkCreateLayer(PX_LiveFramework *plive,const px_char id[PX_LIVEFRAMEWORK_MAX_SUPPORT_LAYER]) +{ + PX_LiveLayer layer; + px_int i; + + if (plive->layers.size>=PX_LIVEFRAMEWORK_MAX_SUPPORT_LAYER) + { + return PX_NULL; + } + + if (PX_LiveFrameworkGetLayerById(plive,id)) + { + return PX_NULL; + } + + + PX_memset(&layer,0,sizeof(layer)); + + if(!PX_VectorInitialize(plive->mp,&layer.triangles,sizeof(PX_Delaunay_Triangle),0))return PX_FALSE; + if(!PX_VectorInitialize(plive->mp,&layer.vertices,sizeof(PX_LiveVertex),0))return PX_FALSE; + + + layer.rotationAngle=0; + layer.visible=PX_TRUE; + layer.keyPoint.z=1; + + layer.rel_beginStretch=1; + layer.rel_currentStretch=1; + layer.rel_endStretch=1; + + layer.RenderTextureIndex = -1; + layer.LinkTextureIndex = -1; + + layer.parent_index=-1; + for (i=0;ilayers,&layer)) + return PX_FALSE; + + return PX_VECTORLAST(PX_LiveLayer,&plive->layers); + +} + +PX_LiveLayer * PX_LiveFrameworkGetLayerParent(PX_LiveFramework *plive,PX_LiveLayer *pLayer) +{ + if (pLayer->parent_index>=0&&pLayer->parent_indexlayers.size) + { + return PX_VECTORAT(PX_LiveLayer,&plive->layers,pLayer->parent_index); + } + +#ifdef PX_DEBUG_MODE + if (pLayer->parent_index!=-1) + { + //Data Crash + PX_ASSERT(); + } +#endif + + return PX_NULL; +} + +PX_LiveLayer * PX_LiveFrameworkGetLayerChild(PX_LiveFramework *plive,PX_LiveLayer *pLayer,px_int childIndex) +{ + if (childIndex>=0&&childIndexlayers.size) + { + return PX_VECTORAT(PX_LiveLayer,&plive->layers,childIndex); + } + + if (childIndex!=-1) + { + PX_ASSERT(); + } + + return PX_NULL; +} + +px_bool PX_LiveFrameworkLinkLayerTexture(PX_LiveFramework *plive,const px_char layer_id[],const px_char texture_id[]) +{ + px_int index=PX_LiveFrameworkGetLiveTextureIndexById(plive,texture_id); + PX_LiveTexture *pLiveTexture=PX_LiveFrameworkGetLiveTextureById(plive,texture_id); + PX_LiveLayer *pLayer=PX_LiveFrameworkGetLayerById(plive,layer_id); + if (pLiveTexture&&pLayer) + { + pLayer->LinkTextureIndex=index; + pLayer->RenderTextureIndex=index; + pLayer->keyPoint.x=pLiveTexture->textureOffsetX+pLiveTexture->Texture.width/2.0f; + pLayer->keyPoint.y=pLiveTexture->textureOffsetY+pLiveTexture->Texture.height/2.0f; + pLayer->rel_currentTranslation=PX_POINT(0,0,0); + return PX_TRUE; + } + return PX_FALSE; +} + +PX_LiveLayer * PX_LiveFrameworkGetLayer(PX_LiveFramework *plive,px_int i) +{ + if (i>=0&&ilayers.size) + { + return PX_VECTORAT(PX_LiveLayer,&plive->layers,i); + } + return PX_NULL; +} + +px_int PX_LiveFrameworkGetLayerIndex(PX_LiveFramework *plive,PX_LiveLayer *pLayer) +{ + px_int i; + for (i=0;ilayers.size;i++) + { + if (pLayer==PX_VECTORAT(PX_LiveLayer,&plive->layers,i)) + { + return i; + } + } + return -1; +} + +PX_LiveLayer *PX_LiveFrameworkGetLastCreateLayer(PX_LiveFramework *plive) +{ + if (plive->layers.size) + { + return PX_VECTORLAST(PX_LiveLayer,&plive->layers); + } + return PX_NULL; +} + +px_void PX_LiveFrameworkUpdateLayerSourceVerticesUV(PX_LiveFramework *plive,PX_LiveLayer *pLayer) +{ + px_int i; + for (i=0;ivertices.size;i++) + { + PX_LiveVertex *pVertex=PX_VECTORAT(PX_LiveVertex,&pLayer->vertices,i); + + if (pLayer->LinkTextureIndex>=0&&pLayer->LinkTextureIndexlivetextures.size) + { + PX_LiveTexture *pLiveTexture=PX_VECTORAT(PX_LiveTexture,&plive->livetextures,pLayer->LinkTextureIndex); + pVertex->u=(pVertex->sourcePosition.x-pLiveTexture->textureOffsetX)*1.0f/pLiveTexture->Texture.width; + pVertex->v=(pVertex->sourcePosition.y-pLiveTexture->textureOffsetY)*1.0f/pLiveTexture->Texture.height; + } + } +} + +px_void PX_LiveFrameworkUpdateSourceVerticesUV(PX_LiveFramework *plive) +{ + px_int i; + for (i=0;ilayers.size;i++) + { + PX_LiveLayer *pLayer=PX_VECTORAT(PX_LiveLayer,&plive->layers,i); + PX_LiveFrameworkUpdateLayerSourceVerticesUV(plive,pLayer); + } +} + +px_void PX_LiveFrameworkUpdateLayerRenderVerticesUV(PX_LiveFramework *plive,PX_LiveLayer *pLayer) +{ + px_int i; + for (i=0;ivertices.size;i++) + { + PX_LiveVertex *pVertex=PX_VECTORAT(PX_LiveVertex,&pLayer->vertices,i); + + if (pLayer->RenderTextureIndex>=0&&pLayer->RenderTextureIndexlivetextures.size) + { + PX_LiveTexture *pLiveTexture=PX_VECTORAT(PX_LiveTexture,&plive->livetextures,pLayer->RenderTextureIndex); + pVertex->u=(pVertex->sourcePosition.x-pLiveTexture->textureOffsetX)*1.0f/pLiveTexture->Texture.width; + pVertex->v=(pVertex->sourcePosition.y-pLiveTexture->textureOffsetY)*1.0f/pLiveTexture->Texture.height; + } + } +} + +PX_LiveAnimation * PX_LiveFrameworkGetAnimationById(PX_LiveFramework *plive,const px_char id[]) +{ + px_int i; + for (i=0;iliveAnimations.size;i++) + { + PX_LiveAnimation *pAnimation=PX_LiveFrameworkGetAnimation(plive,i); + if (pAnimation&&PX_strequ(pAnimation->id,id)) + { + return pAnimation; + } + } + return PX_NULL; + +} + +PX_LiveAnimation * PX_LiveFrameworkCreateAnimation(PX_LiveFramework *plive,const px_char id[]) +{ + PX_LiveAnimation animation; + PX_memset(&animation,0,sizeof(animation)); + PX_VectorInitialize(plive->mp,&animation.framesMemPtr,sizeof(px_void *),1); + PX_strcpy(animation.id,id,sizeof(animation.id)); + if(!PX_VectorPushback(&plive->liveAnimations,&animation))return PX_NULL; + return PX_VECTORLAST(PX_LiveAnimation,&plive->liveAnimations); +} + +PX_LiveAnimation * PX_LiveFrameworkGetAnimation(PX_LiveFramework *plive,px_int index) +{ + if (index>=0&&indexliveAnimations.size) + { + return PX_VECTORAT(PX_LiveAnimation,&plive->liveAnimations,index); + } + return PX_NULL; +} + +PX_LiveAnimation * PX_LiveFrameworkGetLastCreateAnimation(PX_LiveFramework *plive) +{ + if (plive->liveAnimations.size) + { + return PX_VECTORLAST(PX_LiveAnimation,&plive->liveAnimations); + } + return PX_NULL; +} + +px_bool PX_LiveFrameworkAddLiveTexture(PX_LiveFramework *plive,PX_LiveTexture livetexture) +{ + return PX_VectorPushback(&plive->livetextures,&livetexture); +} + +PX_LiveTexture * PX_LiveFrameworkGetLiveTextureById(PX_LiveFramework *plive,const px_char id[]) +{ + px_int i; + for (i=0;ilivetextures.size;i++) + { + PX_LiveTexture *pTexture=PX_VECTORAT(PX_LiveTexture,&plive->livetextures,i); + if (PX_strequ(id,pTexture->id)) + { + return pTexture; + } + } + return PX_NULL; +} + +px_int PX_LiveFrameworkGetLiveTextureIndexById(PX_LiveFramework *plive,const px_char id[]) +{ + px_int i; + for (i=0;ilivetextures.size;i++) + { + PX_LiveTexture *pTexture=PX_VECTORAT(PX_LiveTexture,&plive->livetextures,i); + if (PX_strequ(id,pTexture->id)) + { + return i; + } + } + return -1; +} + +px_int PX_LiveFrameworkGetLiveTextureIndex(PX_LiveFramework *plive,PX_LiveTexture *pCompareTexture) +{ + px_int i; + for (i=0;ilivetextures.size;i++) + { + PX_LiveTexture *pTexture=PX_VECTORAT(PX_LiveTexture,&plive->livetextures,i); + if (pTexture==pCompareTexture) + { + return i; + } + } + return -1; +} + +PX_LiveTexture * PX_LiveFrameworkGetLiveTexture(PX_LiveFramework *plive,px_int index) +{ + if (index>=0&&indexlivetextures.size) + { + return PX_VECTORAT(PX_LiveTexture,&plive->livetextures,index); + } + return PX_NULL; +} + +px_void PX_LiveFrameworkDeleteLiveTextureById(PX_LiveFramework *plive,const px_char id[]) +{ + px_int i; + for (i=0;ilivetextures.size;i++) + { + PX_LiveTexture *pTexture=PX_VECTORAT(PX_LiveTexture,&plive->livetextures,i); + if (PX_strequ(id,pTexture->id)) + { + PX_LiveFrameworkDeleteLiveTexture(plive,i); + return; + } + } +} + +px_void PX_LiveFrameworkDeleteLiveAnimationById(PX_LiveFramework *plive,const px_char id[]) +{ + px_int i; + for (i=0;iliveAnimations.size;i++) + { + PX_LiveAnimation *pAnimation=PX_VECTORAT(PX_LiveAnimation,&plive->liveAnimations,i); + if (PX_strequ(id,pAnimation->id)) + { + PX_LiveFrameworkDeleteLiveAnimation(plive,i); + return; + } + } +} + +px_bool PX_LiveFrameworkLinkLayerSearchSubLayer(PX_LiveFramework *plive,PX_LiveLayer *pLayer,PX_LiveLayer *pSearchLayer) +{ + px_int i; + for (i=0;ichild_index[i]); + + if (pSubLinkLayer==PX_NULL) + { + return PX_FALSE; + } + + if (pSubLinkLayer==pSearchLayer) + { + return PX_TRUE; + } + else + { + if(pSubLinkLayer!=PX_NULL) + return PX_LiveFrameworkLinkLayerSearchSubLayer(plive,pSubLinkLayer,pSearchLayer); + } + } + return PX_FALSE; +} + +px_void PX_LiveFrameworkLinkLayer(PX_LiveFramework *plive,PX_LiveLayer *pLayer,PX_LiveLayer *linkLayer) +{ + px_int i; + if (pLayer==linkLayer) + { + return; + } + + if (PX_LiveFrameworkLinkLayerSearchSubLayer(plive,pLayer,pLayer)) + { + return; + } + + for (i=0;ichild_index[i]); + + if (!pSubLinkLayer) + { + break; + } + + if (pSubLinkLayer==linkLayer) + { + return; + } + + } + if(iparent_index==-1) + { + pLayer->child_index[i]=PX_LiveFrameworkGetLayerIndex(plive,linkLayer); + linkLayer->parent_index=PX_LiveFrameworkGetLayerIndex(plive,pLayer); + } + } +} + +px_void PX_LiveFrameworkClearLinker(PX_LiveFramework *plive) +{ + px_int i; + for (i=0;ilayers.size;i++) + { + px_int j; + PX_LiveLayer *pLayer=PX_VECTORAT(PX_LiveLayer,&plive->layers,i); + for (j=0;jchild_index);j++) + { + pLayer->child_index[j]=-1; + } + pLayer->parent_index=-1; + } +} + +px_void PX_LiveFrameworkDeleteLayer(PX_LiveFramework *plive,px_int index) +{ + if (index>=0&&indexlayers.size) + { + px_int i,j; + PX_LiveLayer *pLayer=PX_VECTORAT(PX_LiveLayer,&plive->layers,index); + for (i=0;ilayers.size;i++) + { + PX_LiveLayer *pSearchLayer=PX_VECTORAT(PX_LiveLayer,&plive->layers,i); + + if (pSearchLayer->parent_index == index) + { + pSearchLayer->parent_index = -1; + } + else if (pSearchLayer->parent_index > index) + { + pSearchLayer->parent_index--; + } + + for (j=0;jchild_index[j]==index) + { + px_int k; + for (k=j;kchild_index);k++) + { + pSearchLayer->child_index[k]=pSearchLayer->child_index[k+1]; + if (pSearchLayer->child_index[k]==-1) + { + break; + } + } + } + + if (pSearchLayer->child_index[j] > index) + { + pSearchLayer->child_index[j]--; + } + } + } + + PX_VectorFree(&pLayer->vertices); + PX_VectorFree(&pLayer->triangles); + PX_VectorErase(&plive->layers,index); + } +} + +px_void PX_LiveFrameworkDeleteLiveTexture(PX_LiveFramework *plive,px_int index) +{ + if (index>=0&&indexlivetextures.size) + { + px_int i; + PX_LiveTexture *pTexture=PX_VECTORAT(PX_LiveTexture,&plive->livetextures,index); + for (i=0;ilayers.size;i++) + { + PX_LiveLayer *player=PX_VECTORAT(PX_LiveLayer,&plive->layers,i); + if (player->LinkTextureIndex>=index) + { + if (player->LinkTextureIndex>index) + { + player->LinkTextureIndex--; + player->RenderTextureIndex=player->LinkTextureIndex; + } + else + { + player->LinkTextureIndex=-1; + player->RenderTextureIndex=player->LinkTextureIndex; + } + + } + } + PX_TextureFree(&pTexture->Texture); + PX_VectorErase(&plive->livetextures,index); + } +} + +px_void PX_LiveFrameworkDeleteLiveAnimationFrame(PX_LiveFramework *plive,PX_LiveAnimation *pliveAnimation,px_int index) +{ + if (index>=0&&indexframesMemPtr.size) + { + px_void *pFrameMemories=*PX_VECTORAT(px_void*,&pliveAnimation->framesMemPtr,index); + if(pFrameMemories) + MP_Free(plive->mp,pFrameMemories); + PX_VectorErase(&pliveAnimation->framesMemPtr,index); + } +} + +px_void PX_LiveFrameworkDeleteLiveAnimation(PX_LiveFramework *plive,px_int index) +{ + if (index>=0&&indexliveAnimations.size) + { + PX_LiveAnimation *pAnimation=PX_VECTORAT(PX_LiveAnimation,&plive->liveAnimations,index); + while (pAnimation->framesMemPtr.size) + { + PX_LiveFrameworkDeleteLiveAnimationFrame(plive,pAnimation,0); + } + PX_VectorFree(&pAnimation->framesMemPtr); + PX_VectorErase(&plive->liveAnimations,index); + + plive->currentEditAnimationIndex=-1; + plive->currentEditFrameIndex=-1; + plive->currentEditLayerIndex=-1; + plive->currentEditVertexIndex=1; + } +} + +px_void PX_LiveFrameworkDeleteLiveAnimationFrameByIndex(PX_LiveFramework *plive,px_int AnimationIndex,px_int frameIndex) +{ + if (AnimationIndex>=0&&AnimationIndexliveAnimations.size) + { + PX_LiveAnimation *pAnimation=PX_VECTORAT(PX_LiveAnimation,&plive->liveAnimations,AnimationIndex); + if (frameIndex>=0&&frameIndexframesMemPtr.size) + { + PX_LiveFrameworkDeleteLiveAnimationFrame(plive,pAnimation,frameIndex); + } + PX_VectorErase(&pAnimation->framesMemPtr,frameIndex); + } +} + +px_void PX_LiveFrameworkFree(PX_LiveFramework *plive) +{ + while (plive->liveAnimations.size) + { + PX_LiveFrameworkDeleteLiveAnimation(plive,0); + } + while (plive->layers.size) + { + PX_LiveFrameworkDeleteLayer(plive,0); + } + while(plive->livetextures.size) + { + PX_LiveFrameworkDeleteLiveTexture(plive,0); + } + PX_VectorFree(&plive->liveAnimations); + PX_VectorFree(&plive->layers); + PX_VectorFree(&plive->livetextures); +} + +px_void * PX_LiveFrameworkGetCurrentEditFrame(PX_LiveFramework *plive) +{ + if (plive->currentEditAnimationIndex>=0&&plive->currentEditAnimationIndexliveAnimations.size) + { + PX_LiveAnimation *pAnimation=PX_VECTORAT(PX_LiveAnimation,&plive->liveAnimations,plive->currentEditAnimationIndex); + if (plive->currentEditFrameIndex>=0&&plive->currentEditFrameIndexframesMemPtr.size) + { + return *PX_VECTORAT(px_void *,&pAnimation->framesMemPtr,plive->currentEditFrameIndex); + } + } + return PX_NULL; +} + +PX_LiveLayer * PX_LiveFrameworkGetCurrentEditLiveLayer(PX_LiveFramework *plive) +{ + if (plive->currentEditLayerIndex>=0&&plive->currentEditLayerIndexlayers.size) + { + return PX_VECTORAT(PX_LiveLayer,&plive->layers,plive->currentEditLayerIndex); + } + return PX_NULL; +} + +PX_LiveAnimationFramePayload *PX_LiveFrameworkGetCurrentEditAnimationFramePayloadIndex(PX_LiveFramework *plive,px_int payloadIndex) +{ + px_int boffset=0; + px_int FramePayloadSize; + px_byte *pOffset; + PX_LiveAnimationFrameHeader *pHeader; + pOffset=(px_byte *)PX_LiveFrameworkGetCurrentEditFrame(plive); + if (!pOffset) + { + return PX_NULL; + } + + pHeader=(PX_LiveAnimationFrameHeader *)pOffset; + FramePayloadSize=pHeader->size+sizeof(PX_LiveAnimationFrameHeader); + boffset+=sizeof(PX_LiveAnimationFrameHeader); + while (PX_TRUE) + { + PX_LiveAnimationFramePayload *pPayloadHeder; + if (boffset>FramePayloadSize) + { + break; + } + pPayloadHeder=(PX_LiveAnimationFramePayload *)(pOffset+boffset); + if (payloadIndex<=0) + { + return pPayloadHeder; + } + boffset+=sizeof(PX_LiveAnimationFramePayload); + boffset+=pPayloadHeder->translationVerticesCount*sizeof(px_point); + payloadIndex--; + } + return PX_NULL; +} + +PX_LiveAnimationFramePayload * PX_LiveFrameworkGetCurrentEditAnimationFramePayload(PX_LiveFramework *plive) +{ + return PX_LiveFrameworkGetCurrentEditAnimationFramePayloadIndex(plive,plive->currentEditLayerIndex); +} + +px_void PX_LiveFrameworkCurrentEditMoveFrameDown(PX_LiveFramework *plive) +{ + PX_LiveAnimation *pAnimation=PX_LiveFrameworkGetCurrentEditAnimation(plive); + if (!pAnimation) + { + return; + } + if (plive->currentEditFrameIndex>=0&&plive->currentEditFrameIndexframesMemPtr.size) + { + if (plive->currentEditFrameIndex==pAnimation->framesMemPtr.size-1) + { + return; + } + else + { + px_void **ptr1,**ptr2,*temp; + ptr1=PX_VECTORAT(px_void *,&pAnimation->framesMemPtr,plive->currentEditFrameIndex); + ptr2=PX_VECTORAT(px_void *,&pAnimation->framesMemPtr,plive->currentEditFrameIndex+1); + temp=*ptr1; + *ptr1=*ptr2; + *ptr2=temp; + } + } +} + +px_void PX_LiveFrameworkCurrentEditMoveFrameUp(PX_LiveFramework *plive) +{ + PX_LiveAnimation *pAnimation=PX_LiveFrameworkGetCurrentEditAnimation(plive); + if (!pAnimation) + { + return; + } + if (plive->currentEditFrameIndex>=0&&plive->currentEditFrameIndexframesMemPtr.size) + { + if (plive->currentEditFrameIndex==0) + { + return; + } + else + { + px_void **ptr1,**ptr2,*temp; + ptr1=PX_VECTORAT(px_void *,&pAnimation->framesMemPtr,plive->currentEditFrameIndex); + ptr2=PX_VECTORAT(px_void *,&pAnimation->framesMemPtr,plive->currentEditFrameIndex-1); + temp=*ptr1; + *ptr1=*ptr2; + *ptr2=temp; + } + } +} + +PX_LiveAnimation * PX_LiveFrameworkGetCurrentEditAnimation(PX_LiveFramework *plive) +{ + if (plive->currentEditAnimationIndex>=0&&plive->currentEditAnimationIndexliveAnimations.size) + { + PX_LiveAnimation *pAnimation=PX_VECTORAT(PX_LiveAnimation,&plive->liveAnimations,plive->currentEditAnimationIndex); + return pAnimation; + } + return PX_NULL; +} + +PX_LiveAnimationFrameHeader * PX_LiveFrameworkGetCurrentEditAnimationFrame(PX_LiveFramework *plive) +{ + PX_LiveAnimation *pAnimation=PX_LiveFrameworkGetCurrentEditAnimation(plive); + if (pAnimation) + { + if (plive->currentEditFrameIndex>=0&&plive->currentEditFrameIndexframesMemPtr.size) + { + return (PX_LiveAnimationFrameHeader *)(*PX_VECTORAT(px_void*,&pAnimation->framesMemPtr,plive->currentEditFrameIndex)); + } + } + return PX_NULL; +} + +PX_LiveVertex * PX_LiveFrameworkGetCurrentEditLiveVertex(PX_LiveFramework *plive) +{ + PX_LiveLayer *currentEditLayer=PX_LiveFrameworkGetCurrentEditLiveLayer(plive); + if (currentEditLayer) + { + if (plive->currentEditVertexIndex>=0&&plive->currentEditVertexIndexvertices.size) + { + return PX_VECTORAT(PX_LiveVertex,¤tEditLayer->vertices,plive->currentEditVertexIndex); + } + } + return PX_NULL; +} + +px_point * PX_LiveFrameworkGetCurrentEditAnimationFramePayloadVertex(PX_LiveFramework *plive) +{ + px_byte *pPayloadByte=(px_byte *)PX_LiveFrameworkGetCurrentEditAnimationFramePayload(plive); + PX_LiveAnimationFramePayload *ppayload=(PX_LiveAnimationFramePayload *)pPayloadByte; + if (pPayloadByte) + { + if (plive->currentEditVertexIndex>=0&&plive->currentEditVertexIndex<(px_int)ppayload->translationVerticesCount) + { + return (px_point *)(pPayloadByte+sizeof(PX_LiveAnimationFramePayload)+plive->currentEditVertexIndex*sizeof(px_point)); + } + } + return PX_NULL; +} + +px_void PX_LiveFrameworkDeleteCurrentEditAnimation(PX_LiveFramework *plive) +{ + PX_LiveFrameworkDeleteLiveAnimation(plive,plive->currentEditAnimationIndex); +} + +px_void PX_LiveFrameworkDeleteCurrentEditAnimationFrame(PX_LiveFramework *plive) +{ + PX_LiveAnimation *pAnimation=PX_LiveFrameworkGetCurrentEditAnimation(plive); + if (pAnimation) + { + PX_LiveFrameworkDeleteLiveAnimationFrame(plive,pAnimation,plive->currentEditFrameIndex); + } + +} + +px_bool PX_LiveFrameworkNewEditFrame(PX_LiveFramework *plive,px_char id[],px_bool bCopyFrame) +{ + PX_LiveAnimation *pAnimation; + px_void *pFramebuffer; + pAnimation=PX_LiveFrameworkGetCurrentEditAnimation(plive); + if (!pAnimation) + { + return PX_FALSE; + } + pFramebuffer=PX_LiveFrameworkGetCurrentEditAnimationFrame(plive); + + if (pFramebuffer) + { + px_uint size; + PX_LiveAnimationFrameHeader *pHeader; + px_void *newFramePtr; + px_void *buffer=pFramebuffer; + pHeader=(PX_LiveAnimationFrameHeader *)buffer; + size=pHeader->size+sizeof(PX_LiveAnimationFrameHeader); + newFramePtr=MP_Malloc(plive->mp,size); + if (newFramePtr) + { + PX_memcpy(newFramePtr,buffer,size); + PX_memcpy(pHeader->frameid,id,sizeof(pHeader->frameid)); + if (bCopyFrame) + { + PX_VectorPushTo(&pAnimation->framesMemPtr,&newFramePtr,plive->currentEditFrameIndex+1); + } + else + { + PX_VectorPushback(&pAnimation->framesMemPtr,&newFramePtr); + } + + return PX_TRUE; + } + else + { + return PX_FALSE; + } + } + else + { + px_void *newFramePtr; + //create new frame + px_int i; + px_uint size=0; + //header + size+=sizeof(PX_LiveAnimationFrameHeader); + for (i=0;ilayers.size;i++) + { + PX_LiveLayer *player=PX_VECTORAT(PX_LiveLayer,&plive->layers,i); + //payload + size+=sizeof(PX_LiveAnimationFramePayload); + //translation + size+=sizeof(px_point)*player->vertices.size; + } + newFramePtr=MP_Malloc(plive->mp,size); + + if (newFramePtr) + { + PX_LiveAnimationFrameHeader *pHeader=(PX_LiveAnimationFrameHeader *)newFramePtr; + PX_LiveAnimationFramePayload *pPayload; + px_byte *pdata; + px_int offset=0; + PX_memset(newFramePtr,0,size); + pdata=(px_byte *)newFramePtr; + pHeader->size=size-sizeof(PX_LiveAnimationFrameHeader); + offset+=sizeof(PX_LiveAnimationFrameHeader); + for (i=0;ilayers.size;i++) + { + PX_LiveLayer *player=PX_VECTORAT(PX_LiveLayer,&plive->layers,i); + pPayload=(PX_LiveAnimationFramePayload *)(pdata+offset); + pPayload->translationVerticesCount=player->vertices.size; + pPayload->mapTexture=player->LinkTextureIndex; + pPayload->stretch=1; + offset+=sizeof(PX_LiveAnimationFramePayload)+sizeof(px_point)*player->vertices.size; + } + PX_memcpy(pHeader->frameid,id,sizeof(pHeader->frameid)); + return PX_VectorPushback(&pAnimation->framesMemPtr,&newFramePtr); + } + else + { + return PX_FALSE; + } + } + + + + + return PX_FALSE; +} + +px_void PX_LiveFrameworkRunCurrentEditFrame(PX_LiveFramework *plive) +{ + PX_LiveFrameworkExecuteInstr(plive,plive->currentEditAnimationIndex,plive->currentEditFrameIndex); + PX_LiveFrameworkExecuteInstr(plive,plive->currentEditAnimationIndex,plive->currentEditFrameIndex); +} + +px_bool PX_LiveFrameworkExport(PX_LiveFramework *plive,px_memory *exportbuffer) +{ + //header + if(!PX_MemoryCat(exportbuffer,"PainterEngineLiveDBinary",24))return PX_FALSE; + + //export LiveFramework structure + do + { + + typedef struct + { + px_char id[PX_LIVE_ID_MAX_LEN]; + px_dword version; + px_int32 width; + px_int32 height; + px_int32 layerCount; + px_int32 animationCount; + px_int32 textureCount; + }PX_LiveFrameworkBaseAttributes; + + PX_LiveFrameworkBaseAttributes desc; + + PX_memset(&desc,0,sizeof(PX_LiveFrameworkBaseAttributes)); + + PX_memcpy(desc.id,plive->id,PX_LIVE_ID_MAX_LEN); + desc.version = PX_LIVE_VERSION; + + desc.width=plive->width; + + desc.height=plive->height; + + desc.layerCount=plive->layers.size; + + desc.animationCount=plive->liveAnimations.size; + + desc.textureCount=plive->livetextures.size; + + if(!PX_MemoryCat(exportbuffer,&desc,sizeof(desc)))return PX_FALSE; + } while (0); + + //export live texture + do + { + typedef struct + { + px_char id[PX_LIVE_ID_MAX_LEN]; + px_int32 width; + px_int32 height; + px_int32 textureOffsetX; + px_int32 textureOffsetY; + }PX_LiveTextureExportInfo; + + px_int i; + for (i=0;ilivetextures.size;i++) + { + PX_LiveTexture *pTexture=PX_VECTORAT(PX_LiveTexture,&plive->livetextures,i); + + //export live texture structure + do + { + PX_LiveTextureExportInfo desc; + desc.height=pTexture->Texture.height; + desc.width=pTexture->Texture.width; + PX_memcpy(desc.id,pTexture->id,sizeof(desc.id)); + desc.textureOffsetX=pTexture->textureOffsetX; + desc.textureOffsetY=pTexture->textureOffsetY; + if(!PX_MemoryCat(exportbuffer,&desc,sizeof(desc)))return PX_FALSE; + } while (0); + + //export pixels data + do + { + if(!PX_MemoryCat(exportbuffer,pTexture->Texture.surfaceBuffer,sizeof(px_color)*pTexture->Texture.height*pTexture->Texture.width))return PX_FALSE; + } while (0); + } + } while (0); + + //export layers + do + { + typedef struct + { + px_char id[PX_LIVE_ID_MAX_LEN]; + px_int32 parent_index; + px_int32 child_index[PX_LIVE_LAYER_MAX_LINK_NODE]; + px_int32 triangleCount; + px_int32 verticesCount; + px_point32 KeyPoint; + px_int32 LinkTextureIndex; + }PX_LiveFramework_LayerExportInfo; + px_int i; + for (i=0;ilayers.size;i++) + { + PX_LiveLayer *pLayer=PX_VECTORAT(PX_LiveLayer,&plive->layers,i); + PX_LiveFramework_LayerExportInfo desc; + PX_memcpy(desc.id,pLayer->id,sizeof(desc.id)); + + desc.triangleCount=pLayer->triangles.size; + desc.verticesCount=pLayer->vertices.size; + + desc.parent_index=pLayer->parent_index; + + do + { + px_int j; + for (j=0;jchild_index);j++) + { + desc.child_index[j]=pLayer->child_index[j]; + } + } while (0); + + desc.KeyPoint=pLayer->keyPoint; + desc.LinkTextureIndex=pLayer->LinkTextureIndex; + + if(!PX_MemoryCat(exportbuffer,&desc,sizeof(desc)))return PX_FALSE; + + + //export layer triangles + do + { + if(!PX_MemoryCat(exportbuffer,pLayer->triangles.data,pLayer->triangles.nodesize*pLayer->triangles.size))return PX_FALSE; + } while (0); + + //export layer vertex + do + { + if(!PX_MemoryCat(exportbuffer,pLayer->vertices.data,pLayer->vertices.nodesize*pLayer->vertices.size))return PX_FALSE; + } while (0); + } + } while (0); + + //export live animation + do + { + px_int i; + for (i=0;iliveAnimations.size;i++) + { + PX_LiveAnimation *pAnimation=PX_VECTORAT(PX_LiveAnimation,&plive->liveAnimations,i); + //export Live Animation structure + do + { + typedef struct + { + px_char id[PX_LIVE_ID_MAX_LEN]; + px_int32 size; + }PX_LiveAnimationExportInfo; + + PX_LiveAnimationExportInfo desc; + PX_memcpy(desc.id,pAnimation->id,sizeof(desc.id)); + desc.size=pAnimation->framesMemPtr.size; + if(!PX_MemoryCat(exportbuffer,&desc,sizeof(desc)))return PX_FALSE; + } while (0); + + //export live animation frame + do + { + px_int j; + for (j=0;jframesMemPtr.size;j++) + { + //export size + px_void *pdata; + px_int32 payloadsize; + PX_LiveAnimationFrameHeader *pheader; + pdata=*PX_VECTORAT(px_void*,&pAnimation->framesMemPtr,j); + pheader=(PX_LiveAnimationFrameHeader *)pdata; + payloadsize=sizeof(PX_LiveAnimationFrameHeader)+pheader->size; + + if(!PX_MemoryCat(exportbuffer,pdata,payloadsize))return PX_FALSE; + } + } while (0); + + + } + } while (0); + return PX_TRUE; +} + +px_bool PX_LiveFrameworkImport(px_memorypool *mp,PX_LiveFramework *plive,px_void *buffer,px_int size) +{ + px_byte*bBuffer = (px_byte *)buffer; + px_int rOffset=0; + ////////////////////////////////////////////////////////////////////////// + //check header + + do + { + if (!PX_memequ(buffer,"PainterEngineLiveDBinary",24)) + { + return PX_FALSE; + } + rOffset+=24;if(rOffset>size) return PX_FALSE; + + } while (0); + + ////////////////////////////////////////////////////////////////////////// + //import live framework structure + do + { + typedef struct + { + px_char id[PX_LIVE_ID_MAX_LEN]; + px_dword version; + px_int32 width; + px_int32 height; + px_int32 layerCount; + px_int32 animationCount; + px_int32 textureCount; + }PX_LiveFrameworkBaseAttributes; + + PX_LiveFrameworkBaseAttributes *pReadLiveFrameworkAttributes=(PX_LiveFrameworkBaseAttributes *)(bBuffer+rOffset); + rOffset+=sizeof(PX_LiveFrameworkBaseAttributes);if(rOffset>size) return PX_FALSE; + + ////////////////////////////////////////////////////////////////////////// + if (pReadLiveFrameworkAttributes->version != PX_LIVE_VERSION) + { + return PX_FALSE; + } + + PX_memset(plive,0,sizeof(PX_LiveFramework)); + + PX_memcpy(plive->id,pReadLiveFrameworkAttributes->id,sizeof(plive->id)); + plive->width=pReadLiveFrameworkAttributes->width; + plive->height=pReadLiveFrameworkAttributes->height; + + ////////////////////////////////////////////////////////////////////////// + plive->mp=mp; + if(!PX_VectorInitialize(mp,&plive->layers,sizeof(PX_LiveLayer),pReadLiveFrameworkAttributes->layerCount))return PX_FALSE; + plive->layers.size=pReadLiveFrameworkAttributes->layerCount; + + if(!PX_VectorInitialize(mp,&plive->livetextures,sizeof(PX_LiveTexture),pReadLiveFrameworkAttributes->textureCount))return PX_FALSE; + plive->livetextures.size=pReadLiveFrameworkAttributes->textureCount; + + if(!PX_VectorInitialize(mp,&plive->liveAnimations,sizeof(PX_LiveAnimation),pReadLiveFrameworkAttributes->animationCount))return PX_FALSE; + plive->liveAnimations.size=pReadLiveFrameworkAttributes->animationCount; + + plive->reg_animation=0; + plive->reg_bp=0; + plive->reg_duration=0; + plive->reg_elapsed=0; + plive->reg_ip=0; + + plive->currentEditAnimationIndex=-1; + plive->currentEditFrameIndex=-1; + plive->currentEditLayerIndex=-1; + plive->currentEditVertexIndex=-1; + } while (0); + + + ////////////////////////////////////////////////////////////////////////// + // + //import live texture + do + { + typedef struct + { + px_char id[PX_LIVE_ID_MAX_LEN]; + px_int32 width; + px_int32 height; + px_int32 textureOffsetX; + px_int32 textureOffsetY; + }PX_LiveTextureImportInfo; + + px_int i; + for (i=0;ilivetextures.size;i++) + { + PX_LiveTexture *pTexture=PX_VECTORAT(PX_LiveTexture,&plive->livetextures,i); + do + { + //import live texture structure + PX_LiveTextureImportInfo *pLiveTextureImportInfo; + pLiveTextureImportInfo=((PX_LiveTextureImportInfo *)(bBuffer+rOffset)); + PX_memset(pTexture,0,sizeof(PX_LiveTexture)); + + if(!PX_TextureCreate(mp,&pTexture->Texture,pLiveTextureImportInfo->width,pLiveTextureImportInfo->height)) + goto _ERROR; + PX_memcpy(pTexture->id,pLiveTextureImportInfo->id,sizeof(pTexture->id)); + pTexture->textureOffsetX=pLiveTextureImportInfo->textureOffsetX; + pTexture->textureOffsetY=pLiveTextureImportInfo->textureOffsetY; + + rOffset+=sizeof(PX_LiveTextureImportInfo);if(rOffset>size) + goto _ERROR; + //import texture data + PX_memcpy(pTexture->Texture.surfaceBuffer,(bBuffer+rOffset),pTexture->Texture.width*pTexture->Texture.height*sizeof(px_color)); + rOffset+=pTexture->Texture.width*pTexture->Texture.height*sizeof(px_color);if(rOffset>size) + goto _ERROR; + } while (0); + } + } while (0); + + ////////////////////////////////////////////////////////////////////////// + //import layer + do + { + typedef struct + { + px_char id[PX_LIVE_ID_MAX_LEN]; + px_int parent_index; + px_int child_index[PX_LIVE_LAYER_MAX_LINK_NODE]; + px_int triangleCount; + px_int verticesCount; + px_point KeyPoint; + px_int LinkTextureIndex; + }PX_LiveFramework_LayerExportInfo; + + px_int i; + for (i=0;ilayers.size;i++) + { + PX_LiveLayer *pLayer=PX_VECTORAT(PX_LiveLayer,&plive->layers,i); + PX_LiveFramework_LayerExportInfo *pReadLayer=(PX_LiveFramework_LayerExportInfo *)(bBuffer+rOffset); + rOffset+=sizeof(PX_LiveFramework_LayerExportInfo);if(rOffset>size) goto _ERROR; + + PX_memset(pLayer,0,sizeof(PX_LiveLayer)); + PX_memcpy(pLayer->id,pReadLayer->id,sizeof(pLayer->id)); + pLayer->keyPoint=pReadLayer->KeyPoint; + pLayer->LinkTextureIndex=pReadLayer->LinkTextureIndex; + pLayer->RenderTextureIndex=pLayer->LinkTextureIndex; + + pLayer->rel_beginStretch=1; + pLayer->rel_currentStretch=1; + pLayer->rel_endStretch=1; + pLayer->visible=PX_TRUE; + + if(!PX_VectorInitialize(mp,&pLayer->triangles,sizeof(PX_Delaunay_Triangle),pReadLayer->triangleCount)) + goto _ERROR; + pLayer->triangles.size=pReadLayer->triangleCount; + + if(!PX_VectorInitialize(mp,&pLayer->vertices,sizeof(PX_LiveVertex),pReadLayer->verticesCount)) + goto _ERROR; + pLayer->vertices.size=pReadLayer->verticesCount; + + + pLayer->parent_index=pReadLayer->parent_index; + + do + { + px_int j; + for (j=0;jchild_index);j++) + { + pLayer->child_index[j]=pReadLayer->child_index[j]; + } + } while (0); + + + //import layer triangles + do + { + PX_memcpy(pLayer->triangles.data,bBuffer+rOffset,pLayer->triangles.nodesize*pLayer->triangles.size); + rOffset+=pLayer->triangles.nodesize*pLayer->triangles.size;if(rOffset>size) goto _ERROR; + } while (0); + + //import layer vertex + do + { + PX_memcpy(pLayer->vertices.data,bBuffer+rOffset,pLayer->vertices.nodesize*pLayer->vertices.size); + rOffset+=pLayer->vertices.nodesize*pLayer->vertices.size;if(rOffset>size) goto _ERROR; + } while (0); + } + } while (0); + + //import live animation + do + { + typedef struct + { + px_char id[PX_LIVE_ID_MAX_LEN]; + px_int32 size; + }PX_LiveAnimationImportInfo; + + px_int i; + for (i=0;iliveAnimations.size;i++) + { + PX_LiveAnimation *pAnimation=PX_VECTORAT(PX_LiveAnimation,&plive->liveAnimations,i); + + //import Live Animation structure + do + { + PX_LiveAnimationImportInfo *pLiveAnimationImport=(PX_LiveAnimationImportInfo *)(bBuffer+rOffset); + rOffset+=sizeof(PX_LiveAnimationImportInfo);if(rOffset>size) goto _ERROR; + + PX_memcpy(pAnimation->id,pLiveAnimationImport->id,sizeof(pAnimation->id)); + + if(!PX_VectorInitialize(mp,&pAnimation->framesMemPtr,sizeof(px_void *),pLiveAnimationImport->size))goto _ERROR; + pAnimation->framesMemPtr.size=pLiveAnimationImport->size; + } while (0); + + //import live animation frame + do + { + px_int j; + for (j=0;jframesMemPtr.size;j++) + { + //import size + px_void **ppdata; + px_int32 payloadsize; + PX_LiveAnimationFrameHeader *pheader; + ppdata=PX_VECTORAT(px_void*,&pAnimation->framesMemPtr,j); + pheader=(PX_LiveAnimationFrameHeader *)(bBuffer+rOffset); + payloadsize=sizeof(PX_LiveAnimationFrameHeader)+pheader->size; + + *ppdata=MP_Malloc(mp,payloadsize); + if(*ppdata==PX_NULL) goto _ERROR; + PX_memcpy(*ppdata,bBuffer+rOffset,payloadsize); + rOffset+=payloadsize;if(rOffset>size) goto _ERROR; + } + } while (0); + } + } while (0); + PX_LiveFrameworkReset(plive); + return PX_TRUE; +_ERROR: + PX_LiveFrameworkFree(plive); + return PX_FALSE; +} + +////////////////////////////////////////////////////////////////////////// +//liveframework mirror + +px_bool PX_LiveCreate(px_memorypool *mp,PX_LiveFramework *pLiveFramework,PX_Live *pLive) +{ + px_int i; + pLive->mp=mp; + *pLive=*pLiveFramework; + if(!PX_VectorInitialize(mp,&pLive->layers,sizeof(PX_LiveLayer),0))return PX_FALSE; + if(!PX_VectorCopy(&pLive->layers,&pLiveFramework->layers)) return PX_FALSE; + for (i=0;ilayers.size;i++) + { + PX_LiveLayer *pLayer=PX_VECTORAT(PX_LiveLayer,&pLive->layers,i); + PX_LiveLayer *pFrameworkLayer=PX_VECTORAT(PX_LiveLayer,&pLiveFramework->layers,i); + if(!PX_VectorInitialize(mp,&pLayer->vertices,sizeof(PX_LiveVertex),0)) + { + px_int j; + for (j=0;jlayers,j); + PX_VectorFree(&pLayer->vertices); + } + return PX_FALSE; + } + if(!PX_VectorCopy(&pLayer->vertices,&pFrameworkLayer->vertices)) + { + px_int j; + for (j=0;jlayers,j); + PX_VectorFree(&pLayer->vertices); + } + return PX_FALSE; + } + } + return PX_TRUE; +} + +px_void PX_LiveFree(PX_Live *pLive) +{ + px_int i; + for (i=0;ilayers.size;i++) + { + PX_LiveLayer *pLayer=PX_VECTORAT(PX_LiveLayer,&pLive->layers,i); + PX_VectorFree(&pLayer->vertices); + } + PX_VectorFree(&pLive->layers); +} + +px_void PX_LivePlay(PX_Live*plive) +{ + PX_LiveFrameworkPlay(plive); +} + +px_bool PX_LivePlayAnimation(PX_Live *plive,px_int index) +{ + return PX_LiveFrameworkPlayAnimation(plive,index); +} + +px_bool PX_LivePlayAnimationByName(PX_Live *plive,const px_char name[]) +{ + return PX_LiveFrameworkPlayAnimationByName(plive,name); +} + +px_void PX_LivePause(PX_Live *plive) +{ + PX_LiveFrameworkPause(plive); +} + +px_void PX_LiveReset(PX_Live *plive) +{ + PX_LiveFrameworkReset(plive); +} + +px_void PX_LiveStop(PX_Live *plive) +{ + PX_LiveFrameworkStop(plive); +} + +px_void PX_LiveRender(px_surface *psurface,PX_Live *plive,px_int x,px_int y,PX_ALIGN refPoint,px_dword elapsed) +{ + PX_LiveFrameworkRender(psurface,plive,x,y,refPoint,elapsed); +} diff --git a/lib/PainterEngine/kernel/PX_LiveFramework.h b/lib/PainterEngine/kernel/PX_LiveFramework.h new file mode 100644 index 0000000000000000000000000000000000000000..2f8e545a3c6e081cd4eb9988fb0631003a6b2a81 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_LiveFramework.h @@ -0,0 +1,267 @@ +#ifndef PX_LIVEFRAMEWORK_H +#define PX_LIVEFRAMEWORK_H + +#include "../core/PX_Core.h" + +#define PX_LIVEFRAMEWORK_MAX_SUPPORT_LAYER 256 +#define PX_LIVE_ID_MAX_LEN 32 +#define PX_LIVE_LAYER_MAX_LINK_NODE 16 +#define PX_LIVE_VERSION 0x00000001 +typedef enum +{ + PX_LIVE_ANIMATION_FRAME_OPCODE_STAMP=0, + PX_LIVE_ANIMATION_FRAME_OPCODE_TRANSLATION, +}PX_LIVE_ANIMATION_FRAME_OPCODE; + +////////////////////////////////////////////////////////////////////////// +//live base struct +typedef struct +{ + px_point sourcePosition; + px_point currentPosition; + px_point normal; + px_point beginTranslation;//point + px_point currentTranslation;//point + px_point endTranslation;//point + px_point velocity; + px_int32 k; + px_float32 u,v; +}PX_LiveVertex; + +typedef struct +{ + px_int index1; + px_int index2; + px_int index3; +}PX_LiveTriangle; + +typedef struct +{ + px_char id[PX_LIVE_ID_MAX_LEN]; + px_texture Texture; + px_int textureOffsetX; + px_int textureOffsetY; +}PX_LiveTexture; + +////////////////////////////////////////////////////////////////////////// +//live animation +typedef struct +{ + px_char id[PX_LIVE_ID_MAX_LEN]; + px_vector framesMemPtr;//px_void * +}PX_LiveAnimation; +////////////////////////////////////////////////////////////////////////// +//shell codes struct + +typedef struct +{ + px_char frameid[PX_LIVE_ID_MAX_LEN]; + px_int32 size; + px_uint32 duration_ms; +}PX_LiveAnimationFrameHeader; + +////////////////////////////////////////////////////////////////////////// + +typedef struct +{ + px_point32 translation;//only root layer + px_float32 stretch;//only child layer + px_float32 rotation; + px_int32 mapTexture; + px_int32 translationVerticesCount; + px_point32 impulse; + + px_float panc_x, panc_y, panc_width, panc_height; + px_float panc_sx,panc_sy; + px_float panc_endx, panc_endy; + px_dword reserve[32]; +}PX_LiveAnimationFramePayload; +////////////////////////////////////////////////////////////////////////// + + + +struct _PX_LiveLayer +{ + px_char id[PX_LIVE_ID_MAX_LEN]; + + px_int32 parent_index; + px_int32 child_index[PX_LIVE_LAYER_MAX_LINK_NODE]; + + + //second Transform + px_float rotationAngle; + px_float rel_beginRotationAngle; + px_float rel_currentRotationAngle; + px_float rel_endRotationAngle; + + //third Transform + px_float rel_beginStretch; + px_float rel_currentStretch; + px_float rel_endStretch; + + px_point rel_beginTranslation; + px_point rel_currentTranslation; + px_point rel_endTranslation; + + //impulse + px_point rel_impulse; + + //keyPoint + px_point keyPoint; + px_point currentKeyPoint; + + //vertices + px_vector vertices;//PX_LiveVertex + //triangle + px_vector triangles;//PX_LiveTriangle + + //panc + px_float panc_x, panc_y, panc_width, panc_height, panc_sx, panc_sy; + px_float panc_beginx, panc_beginy; + px_float panc_currentx, panc_currenty; + px_float panc_endx, panc_endy; + + px_bool visible; + px_bool showMesh; + px_int LinkTextureIndex; + px_int RenderTextureIndex; +}; +typedef struct _PX_LiveLayer PX_LiveLayer; + +////////////////////////////////////////////////////////////////////////// +typedef px_void (*PX_LiveFramework_PixelShader)(px_surface *psurface,px_int x,px_int y,px_point position,px_float u,px_float v,px_point normal,px_texture *pTexture,PX_TEXTURERENDER_BLEND *blend); + +typedef enum +{ + PX_LIVEFRAMEWORK_STATUS_STOP, + PX_LIVEFRAMEWORK_STATUS_PLAYING, +}PX_LIVEFRAMEWORK_STATUS; + +typedef struct +{ + px_memorypool *mp; + ////////////////////////////////////////////////////////////////////////// + //attributes + px_char id[PX_LIVE_ID_MAX_LEN]; + + ////////////////////////////////////////////////////////////////////////// + //controller + px_int currentEditLayerIndex; + px_int currentEditAnimationIndex; + px_int currentEditFrameIndex; + px_int currentEditVertexIndex; + + ////////////////////////////////////////////////////////////////////////// + //render + px_vector layers; + px_vector livetextures; + px_vector liveAnimations; + px_int width; + px_int height; + px_bool showRange; + px_bool showKeypoint; + px_bool showlinker; + px_bool showFocusLayer; + px_bool showRootHelperLine; + px_float refer_x,refer_y; + PX_LIVEFRAMEWORK_STATUS status; + PX_LiveFramework_PixelShader pixelShader; + + ////////////////////////////////////////////////////////////////////////// + //VirtualMachine + px_int32 reg_duration; + px_int32 reg_ip; + px_int32 reg_elapsed; + px_int32 reg_animation; + px_int32 reg_bp; +}PX_LiveFramework; + + + +px_bool PX_LiveFrameworkInitialize(px_memorypool *mp,PX_LiveFramework *plive,px_int width,px_int height); +px_void PX_LiveFrameworkPlay(PX_LiveFramework *plive); +px_void PX_LiveFrameworkPause(PX_LiveFramework *plive); +px_void PX_LiveFrameworkReset(PX_LiveFramework *plive); +px_void PX_LiveFrameworkStop(PX_LiveFramework *plive); + + +px_void PX_LiveFrameworkRender(px_surface *psurface,PX_LiveFramework *plive,px_int x,px_int y,PX_ALIGN refPoint,px_dword elapsed); +px_void PX_LiveFrameworkRenderRefer(px_surface *psurface,PX_LiveFramework *plive,PX_ALIGN refPoint,px_dword elapsed); + +px_bool PX_LiveFrameworkPlayAnimation(PX_LiveFramework *plive,px_int index); +px_bool PX_LiveFrameworkPlayAnimationByName(PX_LiveFramework *plive,const px_char name[]); +PX_LiveLayer *PX_LiveFrameworkGetLayerById(PX_LiveFramework *plive,const px_char id[]); +PX_LiveLayer *PX_LiveFrameworkCreateLayer(PX_LiveFramework *plive,const px_char id[]); +PX_LiveLayer *PX_LiveFrameworkGetLayerParent(PX_LiveFramework *plive,PX_LiveLayer *pLayer); +PX_LiveLayer *PX_LiveFrameworkGetLayerChild(PX_LiveFramework *plive,PX_LiveLayer *pLayer,px_int childIndex); + +px_bool PX_LiveFrameworkLinkLayerTexture(PX_LiveFramework *plive,const px_char layer_id[],const px_char texture_id[]); +PX_LiveLayer *PX_LiveFrameworkGetLayer(PX_LiveFramework *plive,px_int index); +px_int PX_LiveFrameworkGetLayerIndex(PX_LiveFramework *plive,PX_LiveLayer *pLayer); +PX_LiveLayer *PX_LiveFrameworkGetLastCreateLayer(PX_LiveFramework *plive); + +px_void PX_LiveFrameworkUpdateLayerSourceVerticesUV(PX_LiveFramework *plive,PX_LiveLayer *pLayer); +px_void PX_LiveFrameworkUpdateSourceVerticesUV(PX_LiveFramework *plive); +px_void PX_LiveFrameworkUpdateLayerRenderVerticesUV(PX_LiveFramework *plive,PX_LiveLayer *pLayer); + +PX_LiveAnimation *PX_LiveFrameworkGetAnimationById(PX_LiveFramework *plive,const px_char id[]); +PX_LiveAnimation *PX_LiveFrameworkCreateAnimation(PX_LiveFramework *plive,const px_char id[]); +PX_LiveAnimation *PX_LiveFrameworkGetAnimation(PX_LiveFramework *plive,px_int index); +PX_LiveAnimation *PX_LiveFrameworkGetLastCreateAnimation(PX_LiveFramework *plive); + +px_bool PX_LiveFrameworkAddLiveTexture(PX_LiveFramework *plive,PX_LiveTexture livetexture); +PX_LiveTexture *PX_LiveFrameworkGetLiveTextureById(PX_LiveFramework *plive,const px_char id[]); +px_int PX_LiveFrameworkGetLiveTextureIndexById(PX_LiveFramework *plive,const px_char id[]); +PX_LiveTexture *PX_LiveFrameworkGetLiveTexture(PX_LiveFramework *plive,px_int index); +px_void PX_LiveFrameworkDeleteLiveTextureById(PX_LiveFramework *plive,const px_char id[]); +px_void PX_LiveFrameworkDeleteLiveAnimationById(PX_LiveFramework *plive,const px_char id[]); +px_bool PX_LiveFrameworkLinkLayerSearchSubLayer(PX_LiveFramework *plive,PX_LiveLayer *pLayer,PX_LiveLayer *pSearchLayer); +px_void PX_LiveFrameworkLinkLayer(PX_LiveFramework *plive,PX_LiveLayer *pLayer,PX_LiveLayer *linkLayer); +px_void PX_LiveFrameworkClearLinker(PX_LiveFramework *plive); +px_void PX_LiveFrameworkDeleteLayer(PX_LiveFramework *plive,px_int index); +px_void PX_LiveFrameworkDeleteLiveTexture(PX_LiveFramework *plive,px_int index); +px_void PX_LiveFrameworkDeleteLiveAnimation(PX_LiveFramework *plive,px_int index); +px_void PX_LiveFrameworkDeleteLiveAnimationFrameByIndex(PX_LiveFramework *plive,px_int AnimationIndex,px_int frameIndex); +px_void PX_LiveFrameworkFree(PX_LiveFramework *plive); + + +////////////////////////////////////////////////////////////////////////// +//edit functions +px_void *PX_LiveFrameworkGetCurrentEditFrame(PX_LiveFramework *plive); +PX_LiveLayer *PX_LiveFrameworkGetCurrentEditLiveLayer(PX_LiveFramework *plive); +PX_LiveVertex *PX_LiveFrameworkGetCurrentEditLiveVertex(PX_LiveFramework *plive); + +px_void PX_LiveFrameworkCurrentEditMoveFrameDown(PX_LiveFramework *plive); +px_void PX_LiveFrameworkCurrentEditMoveFrameUp(PX_LiveFramework *plive); + +PX_LiveAnimation * PX_LiveFrameworkGetCurrentEditAnimation(PX_LiveFramework *plive); +PX_LiveAnimationFrameHeader * PX_LiveFrameworkGetCurrentEditAnimationFrame(PX_LiveFramework *plive); +PX_LiveAnimationFramePayload *PX_LiveFrameworkGetCurrentEditAnimationFramePayloadIndex(PX_LiveFramework *plive,px_int payloadIndex); +PX_LiveAnimationFramePayload *PX_LiveFrameworkGetCurrentEditAnimationFramePayload(PX_LiveFramework *plive); +px_point *PX_LiveFrameworkGetCurrentEditAnimationFramePayloadVertex(PX_LiveFramework *plive); +px_void PX_LiveFrameworkDeleteCurrentEditAnimation(PX_LiveFramework *plive); +px_void PX_LiveFrameworkDeleteCurrentEditAnimationFrame(PX_LiveFramework *plive); +px_bool PX_LiveFrameworkNewEditFrame(PX_LiveFramework *plive,px_char id[],px_bool bCopyFrame); +px_void PX_LiveFrameworkRunCurrentEditFrame(PX_LiveFramework *plive); + +px_bool PX_LiveFrameworkExport(PX_LiveFramework *plive,px_memory *exportbuffer); +px_bool PX_LiveFrameworkImport(px_memorypool *mp,PX_LiveFramework *plive,px_void *buffer,px_int size); + + +////////////////////////////////////////////////////////////////////////// +//mirror +typedef PX_LiveFramework PX_Live; +px_bool PX_LiveCreate(px_memorypool *mp,PX_LiveFramework *pLiveFramework,PX_Live *pLive); +px_void PX_LiveFree(PX_Live *pLive); + +px_void PX_LivePlay(PX_Live*plive); +px_bool PX_LivePlayAnimation(PX_Live *plive,px_int index); +px_bool PX_LivePlayAnimationByName(PX_Live *plive,const px_char name[]); +px_void PX_LivePause(PX_Live *plive); +px_void PX_LiveReset(PX_Live *plive); +px_void PX_LiveStop(PX_Live *plive); + +px_void PX_LiveRender(px_surface *psurface,PX_Live *plive,px_int x,px_int y,PX_ALIGN refPoint,px_dword elapsed); + + +#endif diff --git a/lib/PainterEngine/kernel/PX_MODBUS.c b/lib/PainterEngine/kernel/PX_MODBUS.c new file mode 100644 index 0000000000000000000000000000000000000000..daa22c367db7513016e0a85066b57d455b1a00ad --- /dev/null +++ b/lib/PainterEngine/kernel/PX_MODBUS.c @@ -0,0 +1,27 @@ +#include "PX_MODBUS.h" + +px_int PX_ModbusPacketBuild(PX_ModbusPacket *packet,px_byte opcode,px_word startAddr,px_word regcount, px_byte *buffer,px_int size) +{ + packet->magic=0; + packet->protocol=0; + packet->size=size+6; + packet->startAddress[0]=0xff&(startAddr>>8); + packet->startAddress[1]=0xff&(startAddr); + packet->regcount[0]=0xff&(regcount>>8); + packet->regcount[1]=0xff&(regcount); + packet->opcode=opcode; + packet->unit=1; + if(size) + PX_memcpy(packet->data,buffer,size); + return size+9; +} + +px_int PX_ModbusWrite(PX_ModbusPacket *packet,px_word startAddr,px_word regcount, px_word *buffer,px_int size) +{ + return PX_ModbusPacketBuild(packet,0x06,startAddr,regcount,(px_byte *)buffer,size*2); +} + +px_int PX_ModbusRead(PX_ModbusPacket *packet,px_word startAddr,px_word regcount) +{ + return PX_ModbusPacketBuild(packet,0x03,startAddr,regcount,(px_byte *)"",0); +} diff --git a/lib/PainterEngine/kernel/PX_MODBUS.h b/lib/PainterEngine/kernel/PX_MODBUS.h new file mode 100644 index 0000000000000000000000000000000000000000..78c543e366dd63c86a6508f97ceb6b3051adb69f --- /dev/null +++ b/lib/PainterEngine/kernel/PX_MODBUS.h @@ -0,0 +1,26 @@ +//Modbus RTU +//Code by DBinary 2019-11-25 for PainterEngine + +#ifndef PX_MODBUS_H +#define PX_MODBUS_H +#include "../core/PX_Core.h" + + +typedef struct +{ + px_word protocol; + px_word magic; + px_byte size; + px_byte unit; + px_byte opcode; + px_byte startAddress[2]; + px_byte regcount[2]; + px_byte data[247]; +}PX_ModbusPacket; + +px_int PX_ModbusPacketBuild(PX_ModbusPacket *packet,px_byte opcode,px_word startAddr,px_word regcount, px_byte *buffer,px_int size); +px_int PX_ModbusWrite(PX_ModbusPacket *packet,px_word startAddr,px_word regcount, px_word *buffer,px_int size); +px_int PX_ModbusRead(PX_ModbusPacket *packet,px_word startAddr,px_word regcount); + +#endif + diff --git a/lib/PainterEngine/kernel/PX_MQTT.c b/lib/PainterEngine/kernel/PX_MQTT.c new file mode 100644 index 0000000000000000000000000000000000000000..e45ba7c220b6e8422f75828dd0b0e5f870d59845 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_MQTT.c @@ -0,0 +1,1052 @@ +#include "PX_MQTT.h" +px_int PX_MQTT_GetSize(px_byte *sizeBuffer) +{ + px_int multiplier=1; + px_int value=0; + px_byte encodeByte; + px_int i=0; + do + { + encodeByte=sizeBuffer[i]; + i++; + value+=(encodeByte&127)*multiplier; + multiplier*=128; + if (multiplier>128*128*128) + { + return 0; + } + } while ((encodeByte&128)!=0); + return value; +} +px_uint PX_MQTT_GetContentSizeOfSize(px_int size) +{ + px_int len=0; + do + { + size/=128; + len++; + } while (size>0); + return len; +} +px_uint PX_MQTTCatRemainingLength(px_memory *memory,px_int size) +{ + px_int encode=0; + px_int len=0; + do + { + encode=size%128; + size/=128; + if(size>0) + { + encode|=128; + } + if(!PX_MemoryCat(memory,&encode,1)) return 0; + len++; + } while (size>0); + return len; +} +px_bool PX_MQTTCatUTF8String(px_memory *memory,const px_char *pstring) +{ + px_word size=PX_strlen(pstring); + px_byte sizeEncode[2]; + sizeEncode[0]=(px_byte)((size&0xff00)>>8); + sizeEncode[1]=(px_byte)((size&0xff)); + if(!PX_MemoryCat(memory,&sizeEncode,2))return PX_FALSE; + return PX_MemoryCat(memory,pstring,PX_strlen(pstring)); +} +px_bool PX_MQTTCatData(px_memory *memory,const px_void *payload,px_int size) +{ + if(!PX_MQTTCatRemainingLength(memory,size)) return PX_FALSE; + return PX_MemoryCat(memory,payload,size); +} +px_bool PX_MQTTInitialize(PX_MQTT *Mqtt,px_memorypool *buildmp,PX_Linker *linker) +{ + PX_memset(Mqtt,0,sizeof(PX_MQTT)); + Mqtt->linker=linker; + Mqtt->buildmp=buildmp; + PX_MemoryInitialize(buildmp,&Mqtt->topic); + PX_MemoryInitialize(buildmp,&Mqtt->payload); + return PX_TRUE; +} +PX_MQTT_CONNECT PX_MQTT_WaitConnACK(PX_MQTT *Mqtt) +{ + px_byte readBuffer[4]; + px_int readSize=PX_LinkerRead(Mqtt->linker,readBuffer,sizeof(readBuffer)); + if(readSize==0) + { + return PX_MQTT_CONNECT_ERROR_DISCONNECT; + } + if (readSize==4) + { + typedef struct + { + px_byte byte1; + px_byte byte2; + px_byte sp; + px_byte ret; + }PX_MQTT_CONNACK; + PX_MQTT_CONNACK *pACK=(PX_MQTT_CONNACK *)readBuffer; + + if (pACK->ret==0) + { + return PX_MQTT_CONNECT_SUCCEEDED; + } + else + { + switch(pACK->ret) + { + case 0x01: + { + return PX_MQTT_CONNECT_ERROR_PROTOCAL_NO_SUPPORT; + } + //break; + case 0x02: + { + return PX_MQTT_CONNECT_ERROR_SESSION_ILLEGAL; + } + //break; + case 0x03: + { + return PX_MQTT_CONNECT_ERROR_SERVER_CRASH; + } + //break; + case 0x04: + { + return PX_MQTT_CONNECT_ERROR_USER_WRONG; + } + //break; + case 0x05: + { + return PX_MQTT_CONNECT_ERROR_ILLEGAL; + } + //break; + default: + return PX_MQTT_CONNECT_ERROR_UNKNOW; + //break; + } + } + + } + return PX_MQTT_CONNECT_ERROR_UNKNOW; +} +px_bool PX_MQTT_SendConnect(PX_MQTT *Mqtt,PX_MQTT_ConnectDesc connectDesc) +{ + px_memory packbuild; + px_uint size=0; + px_int i; + //Generate Session + for (i=0;iconnectionKeySession)-1;i++) + { + Mqtt->connectionKeySession[i]='a'+PX_rand()%26; + } + Mqtt->connectionKeySession[i]=0; + + PX_MemoryInitialize(Mqtt->buildmp,&packbuild); + //fixed header + do + { + typedef struct + { + px_byte flag:4; + px_byte type:4; + }PX_MQTT_FixedHeader; + + PX_MQTT_FixedHeader header; + header.flag=0; + header.type=PX_MQTT_FIXERHEADER_CONTROLLERTYPE_CONNECT; + + //10 bytes for variable header + size+=10; + + //payload size + + //connectionSession + 2byte size + size+=PX_MQTT_CONNECTION_SESSION_SIZE+2; + + if (connectDesc.willTopic&&connectDesc.willTopic[0]) + { + size+=PX_strlen(connectDesc.willTopic)+2; + } + + if (connectDesc.willContent&&connectDesc.willSize) + { + size+=connectDesc.willSize+2; + } + + + if (connectDesc.userName) + { + size+=PX_strlen(connectDesc.userName)+2; + } + + if (connectDesc.password) + { + size+=PX_strlen(connectDesc.password)+2; + } + + + PX_MemoryCat(&packbuild,&header,sizeof(header)); + PX_MQTTCatRemainingLength(&packbuild,size); + + }while(0); + + //Variable Header + + //Protocol Name 6 bytes + do + { + typedef struct + { + px_byte size_MSB; + px_byte size_LSB; + px_byte cMQTT[4]; + }PX_MQTT_VariableHeader; + + PX_MQTT_VariableHeader variableHeader; + variableHeader.size_MSB=0; + variableHeader.size_LSB=4; + PX_memcpy(variableHeader.cMQTT,"MQTT",4); + + PX_MemoryCat(&packbuild,&variableHeader,sizeof(variableHeader)); + } while (0); + + //Protocol level byte 1 bytes + do + { + typedef struct + { + px_byte level; + }PX_MQTT_ProtocalLevel; + + PX_MQTT_ProtocalLevel Protocallevel; + Protocallevel.level=0x04; + + PX_MemoryCat(&packbuild,&Protocallevel,sizeof(Protocallevel)); + } while (0); + + //Connection flag 1 bytes + do + { + typedef struct + { + px_byte reserved:1; + px_byte cleanSession:1; + px_byte Willflag:1; + px_byte WillQoS:2; + px_byte WillRetain:1; + px_byte PasswordFlag:1; + px_byte UserNameFlag:1; + }PX_MQTT_ConnectionFlag; + + PX_MQTT_ConnectionFlag ConnectionFlag; + ConnectionFlag.reserved=0; + ConnectionFlag.cleanSession=connectDesc.CleanSession; + if (connectDesc.willSize&&connectDesc.willContent) + { + ConnectionFlag.Willflag=1; + } + else + { + ConnectionFlag.Willflag=0; + } + + ConnectionFlag.WillQoS=connectDesc.willQoS; + ConnectionFlag.WillRetain=connectDesc.willRetain; + + if (connectDesc.userName) + { + ConnectionFlag.UserNameFlag=1; + } + else + { + ConnectionFlag.UserNameFlag=0; + } + + + if (connectDesc.password) + { + ConnectionFlag.PasswordFlag=1; + } + else + { + ConnectionFlag.PasswordFlag=0; + } + + PX_MemoryCat(&packbuild,&ConnectionFlag,sizeof(ConnectionFlag)); + } while (0); + + + //KeepAlive time 2 Bytes + do + { + typedef struct + { + px_byte Alive_MSB; + px_byte Alive_LSB; + }PX_MQTT_ConnectionAlive; + + PX_MQTT_ConnectionAlive ConnectionAlive; + + ConnectionAlive.Alive_MSB=(connectDesc.KeepAliveTime&0xff00)>>8; + ConnectionAlive.Alive_LSB=(connectDesc.KeepAliveTime&0xff); + + PX_MemoryCat(&packbuild,&ConnectionAlive,sizeof(ConnectionAlive)); + } while (0); + + //ClientID + do + { + PX_MQTTCatUTF8String(&packbuild,Mqtt->connectionKeySession); + } while (0); + + //will topic + do + { + if (connectDesc.willTopic&&connectDesc.willTopic[0]) + { + PX_MQTTCatUTF8String(&packbuild,connectDesc.willTopic); + } + + } while (0); + + + //will content + do + { + if (connectDesc.willContent) + { + px_word willsize=connectDesc.willSize; + px_byte willsizeEncode[2]; + willsizeEncode[0]=(px_byte)((willsize&0xff00)>>8); + willsizeEncode[1]=(px_byte)((willsize&0xff)); + PX_MemoryCat(&packbuild,willsizeEncode,2); + PX_MemoryCat(&packbuild,connectDesc.willContent,willsize); + } + + } while (0); + + //userName + do + { + if (connectDesc.userName) + { + PX_MQTTCatUTF8String(&packbuild,connectDesc.userName); + } + } while (0); + + //password + do + { + if (connectDesc.password) + { + PX_MQTTCatUTF8String(&packbuild,connectDesc.password); + } + + } while (0); + + if(!PX_LinkerWrite(Mqtt->linker,packbuild.buffer,packbuild.usedsize)) + { + PX_MemoryFree(&packbuild); + return PX_FALSE; + } + PX_MemoryFree(&packbuild); + return PX_TRUE; +} +PX_MQTT_CONNECT PX_MQTTConnect(PX_MQTT *Mqtt,PX_MQTT_ConnectDesc connectDesc) +{ + if (PX_MQTT_SendConnect(Mqtt,connectDesc)) + { + return PX_MQTT_WaitConnACK(Mqtt); + } + return PX_MQTT_CONNECT_ERROR_DISCONNECT; +} +px_bool PX_MQTT_SendPublih(PX_MQTT *Mqtt,PX_MQTT_PublishDesc publishDesc) +{ + px_memory packbuild; + PX_MemoryInitialize(Mqtt->buildmp,&packbuild); + + //Fixed Header + do + { + typedef struct + { + unsigned int ratain:1; + unsigned int QoS:2; + unsigned int DUP:1; + unsigned int Type:4; + }PX_MQTT_FixedHeader; + px_int size=0; + PX_MQTT_FixedHeader header; + + header.ratain=publishDesc.retain; + header.DUP=0; + header.QoS=publishDesc.qosLevel; + header.Type=0x03; + + PX_MemoryCat(&packbuild,&header,1); + + //variable header + size+=PX_strlen(publishDesc.Topic)+2; + + //Packet Identifier + if (publishDesc.qosLevel==PX_MQTT_QOS_LEVEL_1||publishDesc.qosLevel==PX_MQTT_QOS_LEVEL_2) + { + size+=2; + } + + size+=publishDesc.payloadSize; + + PX_MQTTCatRemainingLength(&packbuild,size); + + } while (0); + + //variable header + do + { + PX_MQTTCatUTF8String(&packbuild,publishDesc.Topic); + if (publishDesc.qosLevel==PX_MQTT_QOS_LEVEL_1||publishDesc.qosLevel==PX_MQTT_QOS_LEVEL_2) + { + Mqtt->identify++; + PX_MemoryCat(&packbuild,&Mqtt->identify,2); + + } + }while(0); + + //payload + PX_MemoryCat(&packbuild,publishDesc.payload,publishDesc.payloadSize); + + if(!PX_LinkerWrite(Mqtt->linker,packbuild.buffer,packbuild.usedsize)) + { + PX_MemoryFree(&packbuild); + return PX_FALSE; + } + PX_MemoryFree(&packbuild); + return PX_TRUE; +} +px_bool PX_MQTT_WaitPUBACK(PX_MQTT *Mqtt) +{ + px_byte readBuffer[4]; + px_int readSize=PX_LinkerRead(Mqtt->linker,readBuffer,sizeof(readBuffer)); + if(readSize==0) + { + return PX_FALSE; + } + if (readSize==4) + { + typedef struct + { + px_byte b1; + px_byte b2; + px_word identify; + }PX_MQTT_PUBACK; + PX_MQTT_PUBACK *pAck=(PX_MQTT_PUBACK *)readBuffer; + if (pAck->b1==64&&pAck->b2==2&&pAck->identify==Mqtt->identify) + { + return PX_TRUE; + } + } + return PX_FALSE; +} +px_bool PX_MQTT_SendPUBACK(PX_MQTT *Mqtt,px_word identify) +{ + typedef struct + { + px_byte b1; + px_byte b2; + px_word identify; + }PX_MQTT_PUBACK; + PX_MQTT_PUBACK Ack; + Ack.b1=64; + Ack.b2=2; + Ack.identify=identify; + + return PX_LinkerWrite(Mqtt->linker,&Ack,sizeof(Ack)); +} +px_bool PX_MQTT_WaitPUBREC(PX_MQTT *Mqtt) +{ + px_byte readBuffer[4]; + px_int readSize=PX_LinkerRead(Mqtt->linker,readBuffer,sizeof(readBuffer)); + if(readSize==0) + { + return PX_FALSE; + } + if (readSize==4) + { + typedef struct + { + px_byte b1; + px_byte b2; + px_word identify; + }PX_MQTT_PUBACK; + PX_MQTT_PUBACK *pAck=(PX_MQTT_PUBACK *)readBuffer; + if (pAck->b1==(64+16)&&pAck->b2==2&&pAck->identify==Mqtt->identify) + { + return PX_TRUE; + } + } + return PX_FALSE; +} +px_bool PX_MQTT_SendPUBREC(PX_MQTT *Mqtt,px_word identify) +{ + typedef struct + { + px_byte b1; + px_byte b2; + px_word identify; + }PX_MQTT_PUBREC; + PX_MQTT_PUBREC rec; + rec.b1=(64+16); + rec.b2=2; + rec.identify=identify; + return PX_LinkerWrite(Mqtt->linker,&rec,sizeof(rec)); +} +px_bool PX_MQTT_SendPUBREL(PX_MQTT *Mqtt) +{ + typedef struct + { + px_byte b1; + px_byte b2; + px_word identify; + }PX_MQTT_PUBREL; + + PX_MQTT_PUBREL pubrel; + pubrel.b1=64+32+2; + pubrel.b2=2; + pubrel.identify=Mqtt->identify; + if(!PX_LinkerWrite(Mqtt->linker,&pubrel,sizeof(pubrel))) + { + return PX_FALSE; + } + return PX_TRUE; +} +px_bool PX_MQTT_WaitPUBREL(PX_MQTT *Mqtt,px_word identify) +{ + px_byte readBuffer[4]; + px_int readSize=PX_LinkerRead(Mqtt->linker,readBuffer,sizeof(readBuffer)); + if(readSize==0) + { + return PX_FALSE; + } + if (readSize==4) + { + typedef struct + { + px_byte b1; + px_byte b2; + px_word identify; + }PX_MQTT_PUBREL; + PX_MQTT_PUBREL *pRel=(PX_MQTT_PUBREL *)readBuffer; + if (pRel->b1==(64+32+2)&&pRel->b2==2&&pRel->identify==identify) + { + return PX_TRUE; + } + } + return PX_FALSE; +} +px_bool PX_MQTT_SendPUBCOMP(PX_MQTT *Mqtt,px_word identify) +{ + typedef struct + { + px_byte b1; + px_byte b2; + px_word identify; + }PX_MQTT_PUBCOMP; + + PX_MQTT_PUBCOMP pubcomp; + pubcomp.b1=64+32+16; + pubcomp.b2=2; + pubcomp.identify=identify; + if(!PX_LinkerWrite(Mqtt->linker,&pubcomp,sizeof(pubcomp))) + { + return PX_FALSE; + } + return PX_TRUE; +} +px_bool PX_MQTT_WaitPUBCOMP(PX_MQTT *Mqtt) +{ + px_byte readBuffer[4]; + px_int readSize=PX_LinkerRead(Mqtt->linker,readBuffer,sizeof(readBuffer)); + if(readSize==0) + { + return PX_FALSE; + } + if (readSize==4) + { + typedef struct + { + px_byte b1; + px_byte b2; + px_word identify; + }PX_MQTT_PUBACK; + PX_MQTT_PUBACK *pAck=(PX_MQTT_PUBACK *)readBuffer; + if (pAck->b1==(64+32+16)&&pAck->b2==2&&pAck->identify==Mqtt->identify) + { + return PX_TRUE; + } + } + return PX_FALSE; +} +px_bool PX_MQTTPublish(PX_MQTT *Mqtt,PX_MQTT_PublishDesc publishDesc) +{ + if(PX_MQTT_SendPublih(Mqtt,publishDesc)) + { + switch(publishDesc.qosLevel) + { + case PX_MQTT_QOS_LEVEL_0: + { + return PX_TRUE; + } + //break; + case PX_MQTT_QOS_LEVEL_1: + { + if (PX_MQTT_WaitPUBACK(Mqtt)) + { + return PX_TRUE; + } + } + break; + case PX_MQTT_QOS_LEVEL_2: + { + if (PX_MQTT_WaitPUBREC(Mqtt)) + { + if (PX_MQTT_SendPUBREL(Mqtt)) + { + if (PX_MQTT_WaitPUBCOMP(Mqtt)) + { + return PX_TRUE; + } + } + } + return PX_FALSE; + } + //break; + } + } + return PX_FALSE; +} +px_bool PX_MQTT_SendSubscribe(PX_MQTT *Mqtt,PX_MQTT_SubscribeDesc subscribeDesc) +{ + px_memory packbuild; + PX_MemoryInitialize(Mqtt->buildmp,&packbuild); + + //header + do + { + + typedef struct + { + px_byte b1; + }PX_MQTT_FixedHeader; + px_int size=0; + PX_MQTT_FixedHeader fixedHeader; + fixedHeader.b1=128+2; + + PX_MemoryCat(&packbuild,&fixedHeader,1); + + //variable + size+=2; + + //payload + + //topic + size+=2+PX_strlen(subscribeDesc.Topic); + + //Requested + size+=1; + + PX_MQTTCatRemainingLength(&packbuild,size); + } while (0); + + //variable header + do + { + Mqtt->identify++; + PX_MemoryCat(&packbuild,&Mqtt->identify,2); + }while(0); + + //payload + + //topic + do + { + PX_MQTTCatUTF8String(&packbuild,subscribeDesc.Topic); + }while(0); + + //qos + do + { + px_byte qos=subscribeDesc.qosLevel; + PX_MemoryCat(&packbuild,&qos,1); + } while (0); + + + if(!PX_LinkerWrite(Mqtt->linker,packbuild.buffer,packbuild.usedsize)) + { + PX_MemoryFree(&packbuild); + return PX_FALSE; + } + PX_MemoryFree(&packbuild); + return PX_TRUE; + +} +px_bool PX_MQTT_WaitSUBACK(PX_MQTT *Mqtt) +{ + px_byte readBuffer[5]; + px_int readSize=PX_LinkerRead(Mqtt->linker,readBuffer,sizeof(readBuffer)); + if(readSize==0) + { + return PX_FALSE; + } + if (readSize==5) + { + typedef struct + { + px_byte b1; + px_byte remainingLength; + px_word identify; + px_byte qos; + }PX_MQTT_PUBACK; + PX_MQTT_PUBACK *pAck=(PX_MQTT_PUBACK *)readBuffer; + if (pAck->b1==(128+16)&&pAck->remainingLength==3&&pAck->identify==Mqtt->identify&&(pAck->qos&0x80)==0) + { + return PX_TRUE; + } + } + return PX_FALSE; +} +px_bool PX_MQTTSubscribe(PX_MQTT *Mqtt,PX_MQTT_SubscribeDesc subscribeDesc) +{ + if (PX_MQTT_SendSubscribe(Mqtt,subscribeDesc)) + { + if (PX_MQTT_WaitSUBACK(Mqtt)) + { + return PX_TRUE; + } + } + return PX_FALSE; +} +px_bool PX_MQTT_SendUnsubscribe(PX_MQTT *Mqtt,const px_char *Topic) +{ + px_memory packbuild; + PX_MemoryInitialize(Mqtt->buildmp,&packbuild); + + //header + do + { + + typedef struct + { + px_byte b1; + }PX_MQTT_FixedHeader; + px_int size=0; + PX_MQTT_FixedHeader fixedHeader; + fixedHeader.b1=128+32+2; + + PX_MemoryCat(&packbuild,&fixedHeader,1); + + //variable + size+=2; + + //payload + + //topic + size+=2+PX_strlen(Topic); + + PX_MQTTCatRemainingLength(&packbuild,size); + } while (0); + + //variable header + do + { + Mqtt->identify++; + PX_MemoryCat(&packbuild,&Mqtt->identify,2); + }while(0); + + //payload + + //topic + do + { + PX_MQTTCatUTF8String(&packbuild,Topic); + }while(0); + + if(!PX_LinkerWrite(Mqtt->linker,packbuild.buffer,packbuild.usedsize)) + { + PX_MemoryFree(&packbuild); + return PX_FALSE; + } + PX_MemoryFree(&packbuild); + return PX_TRUE; + +} +px_bool PX_MQTT_WaitUNSUBACK(PX_MQTT *Mqtt) +{ + px_byte readBuffer[4]; + px_int readSize=PX_LinkerRead(Mqtt->linker,readBuffer,sizeof(readBuffer)); + if(readSize==0) + { + return PX_FALSE; + } + if (readSize==4) + { + typedef struct + { + px_byte b1; + px_byte remainingLength; + px_word identify; + }PX_MQTT_PUBACK; + PX_MQTT_PUBACK *pAck=(PX_MQTT_PUBACK *)readBuffer; + if (pAck->b1==(128+32+16)&&pAck->remainingLength==2&&pAck->identify==Mqtt->identify) + { + return PX_TRUE; + } + } + return PX_FALSE; +} +px_bool PX_MQTTUnsubscribe(PX_MQTT *Mqtt,const px_char *Topic) +{ + if (PX_MQTT_SendUnsubscribe(Mqtt,Topic)) + { + if (PX_MQTT_WaitUNSUBACK(Mqtt)) + { + return PX_TRUE; + } + } + return PX_FALSE; +} +px_bool PX_MQTT_SendPINGREQ(PX_MQTT *Mqtt) +{ + typedef struct + { + px_byte b1; + px_byte b2; + }PX_MQTT_PINGREQ; + + PX_MQTT_PINGREQ pingreq; + pingreq.b1=128+64+16; + pingreq.b2=0; + + if(!PX_LinkerWrite(Mqtt->linker,&pingreq,2)) + { + return PX_FALSE; + } + return PX_TRUE; +} +px_bool PX_MQTT_WaitPINGRESP(PX_MQTT *Mqtt) +{ + px_byte readBuffer[2]; + px_int readSize=PX_LinkerRead(Mqtt->linker,readBuffer,sizeof(readBuffer)); + if(readSize==0) + { + return PX_FALSE; + } + if (readSize==2) + { + typedef struct + { + px_byte b1; + px_byte remainingLength; + }PX_MQTT_PINGRESP; + PX_MQTT_PINGRESP *pAck=(PX_MQTT_PINGRESP *)readBuffer; + if (pAck->b1==192&&pAck->remainingLength==0) + { + return PX_TRUE; + } + } + return PX_FALSE; +} +px_bool PX_MQTTPingReq(PX_MQTT *Mqtt) +{ + if (PX_MQTT_SendPINGREQ(Mqtt)) + { + if (PX_MQTT_WaitPINGRESP(Mqtt)) + { + return PX_TRUE; + } + } + return PX_FALSE; +} + +px_bool PX_MQTTListen(PX_MQTT *Mqtt) +{ + + px_word id; + px_byte rByte; + px_int size=0; + PX_MQTT_QOS_LEVEL qos; + + if (!PX_LinkerRead(Mqtt->linker,&rByte,1)) + { + return PX_FALSE; + } + + //is Publish? + do + { + typedef struct + { + unsigned int ratain:1; + unsigned int QoS:2; + unsigned int DUP:1; + unsigned int Type:4; + }PX_MQTT_FixedHeader; + + PX_MQTT_FixedHeader *pFixHeader=(PX_MQTT_FixedHeader *)&rByte; + + if (pFixHeader->Type!=3) + { + return PX_FALSE; + } + qos=(PX_MQTT_QOS_LEVEL)pFixHeader->QoS; + } while (0); + + //getsize + do + { + px_int multiplier=1; + while (PX_TRUE) + { + if (!PX_LinkerRead(Mqtt->linker,&rByte,1)) + { + return PX_FALSE; + } + size+=(rByte&127)*multiplier; + if ((rByte&128)!=0) + { + multiplier*=128; + } + else + { + break; + } + if (multiplier>128*128*128) + { + return PX_FALSE; + } + } + } while (0); + + //recv Topic + do + { + px_int utf8Size=0; + PX_MemoryClear(&Mqtt->topic); + if (!PX_LinkerRead(Mqtt->linker,&rByte,1)) + { + return PX_FALSE; + } + utf8Size=rByte*256; + size--; + + if (!PX_LinkerRead(Mqtt->linker,&rByte,1)) + { + return PX_FALSE; + } + utf8Size+=rByte; + size--; + + while (utf8Size) + { + if (!PX_LinkerRead(Mqtt->linker,&rByte,1)) + { + return PX_FALSE; + } + PX_MemoryCat(&Mqtt->topic,&rByte,1); + utf8Size--; + size--; + } + } while (0); + PX_MemoryCat(&Mqtt->topic,"",1); + + //recv ID + do + { + if (!PX_LinkerRead(Mqtt->linker,&id,2)) + { + return PX_FALSE; + } + size-=2; + } while (0); + + + //recv payload + do + { + px_int rsize,retSize; + px_byte cache[128]; + PX_MemoryClear(&Mqtt->payload); + while (size) + { + if (size>sizeof(cache)) + { + rsize=sizeof(cache); + } + else + { + rsize=size; + } + if ((retSize=PX_LinkerRead(Mqtt->linker,cache,rsize))==0) + { + return PX_FALSE; + } + size-=retSize; + PX_MemoryCat(&Mqtt->payload,cache,retSize); + } + } while (0); + + switch (qos) + { + case PX_MQTT_QOS_LEVEL_0: + return PX_TRUE; + //break; + case PX_MQTT_QOS_LEVEL_1: + if(!PX_MQTT_SendPUBACK(Mqtt,id))return PX_FALSE; + return PX_TRUE; + //break; + case PX_MQTT_QOS_LEVEL_2: + { + if (!PX_MQTT_SendPUBREC(Mqtt,id)) + { + return PX_FALSE; + } + if (!PX_MQTT_WaitPUBREL(Mqtt,id)) + { + return PX_FALSE; + } + if (!PX_MQTT_SendPUBCOMP(Mqtt,id)) + { + return PX_FALSE; + } + return PX_TRUE; + } + //break; + } + + + return PX_TRUE; +} + +px_bool PX_MQTT_VerifyFrame(px_byte *data,px_int size) +{ + px_byte *pdata=data; + px_int bsize=1; + px_int datasize=PX_MQTT_GetSize(data+1); + if (datasize==0) + { + return PX_FALSE; + } + while ((*pdata)&0x80) + { + bsize++; + pdata++; + } + return size>=(bsize+datasize+1); +} + + +px_void PX_MQTTFree(PX_MQTT *Mqtt) +{ + PX_MemoryFree(&Mqtt->payload); + PX_MemoryFree(&Mqtt->topic); +} + diff --git a/lib/PainterEngine/kernel/PX_MQTT.h b/lib/PainterEngine/kernel/PX_MQTT.h new file mode 100644 index 0000000000000000000000000000000000000000..80801d864b3157b07135a418bf6f72246377d04c --- /dev/null +++ b/lib/PainterEngine/kernel/PX_MQTT.h @@ -0,0 +1,106 @@ +////////////////////////////////////////////////////////////////////////// +//MQTT 3.1.1 for PainterEngine +//code by:DBinary 2020-12-28 +////////////////////////////////////////////////////////////////////////// + +#ifndef PX_MQTT_H +#define PX_MQTT_H + +#include "../core/PX_Core.h" + +typedef enum +{ + PX_MQTT_QOS_LEVEL_0, + PX_MQTT_QOS_LEVEL_1, + PX_MQTT_QOS_LEVEL_2, +}PX_MQTT_QOS_LEVEL; + +#define PX_MQTT_DEFAULT_TIMEOUT 2000 +#define PX_MQTT_CONNECTION_SESSION_SIZE 32 + +#define PX_MQTT_FIXERHEADER_CONTROLLERTYPE_RESERVED0 0 +#define PX_MQTT_FIXERHEADER_CONTROLLERTYPE_CONNECT 1 +#define PX_MQTT_FIXERHEADER_CONTROLLERTYPE_CONNACK 2 +#define PX_MQTT_FIXERHEADER_CONTROLLERTYPE_PUBLISH 3 +#define PX_MQTT_FIXERHEADER_CONTROLLERTYPE_PUBACK 4 +#define PX_MQTT_FIXERHEADER_CONTROLLERTYPE_PUBREC 5 +#define PX_MQTT_FIXERHEADER_CONTROLLERTYPE_PUBREL 6 +#define PX_MQTT_FIXERHEADER_CONTROLLERTYPE_PUBCOMP 7 +#define PX_MQTT_FIXERHEADER_CONTROLLERTYPE_SUBSCRIBE 8 +#define PX_MQTT_FIXERHEADER_CONTROLLERTYPE_SUBACK 9 +#define PX_MQTT_FIXERHEADER_CONTROLLERTYPE_UNSUBSCRIBE 10 +#define PX_MQTT_FIXERHEADER_CONTROLLERTYPE_UNSUBACK 11 +#define PX_MQTT_FIXERHEADER_CONTROLLERTYPE_PINGREQ 12 +#define PX_MQTT_FIXERHEADER_CONTROLLERTYPE_PINGRESP 13 +#define PX_MQTT_FIXERHEADER_CONTROLLERTYPE_DISCONNECT 14 +#define PX_MQTT_FIXERHEADER_CONTROLLERTYPE_RESERVED1 15 + +typedef enum +{ + PX_MQTT_STATUS_DISCONNECT, + PX_MQTT_STATUS_CONNECTING, +}PX_MQTT_STATUS; + +typedef enum +{ + PX_MQTT_CONNECT_SUCCEEDED, + PX_MQTT_CONNECT_ERROR_UNKNOW, + PX_MQTT_CONNECT_ERROR_DISCONNECT, + PX_MQTT_CONNECT_ERROR_PROTOCAL_NO_SUPPORT, + PX_MQTT_CONNECT_ERROR_SESSION_ILLEGAL, + PX_MQTT_CONNECT_ERROR_SERVER_CRASH, + PX_MQTT_CONNECT_ERROR_USER_WRONG, + PX_MQTT_CONNECT_ERROR_ILLEGAL, +}PX_MQTT_CONNECT; + +struct _PX_MQTT +{ + px_memorypool *buildmp; + px_dword sessionKey; + PX_Linker *linker; + px_dword identify; + px_memory topic; + px_memory payload; + px_char connectionKeySession[PX_MQTT_CONNECTION_SESSION_SIZE+1]; +}; +typedef struct _PX_MQTT PX_MQTT; + +typedef struct +{ + const px_char *userName; + const px_char *password; + const px_char *willTopic; + const px_void *willContent; + px_uint willSize; + px_bool willRetain; + px_bool CleanSession; + PX_MQTT_QOS_LEVEL willQoS; + px_word KeepAliveTime;//seconds +}PX_MQTT_ConnectDesc; + + +typedef struct +{ + PX_MQTT_QOS_LEVEL qosLevel; + px_bool retain; + const px_char *Topic; + const px_void *payload; + px_int payloadSize; +}PX_MQTT_PublishDesc; + +typedef struct +{ + PX_MQTT_QOS_LEVEL qosLevel; + const px_char *Topic; +}PX_MQTT_SubscribeDesc; + +px_bool PX_MQTTInitialize(PX_MQTT *Mqtt,px_memorypool *mp,PX_Linker *linker); +PX_MQTT_CONNECT PX_MQTTConnect(PX_MQTT *Mqtt,PX_MQTT_ConnectDesc connectDesc); +px_bool PX_MQTTPublish(PX_MQTT *Mqtt,PX_MQTT_PublishDesc publishDesc); +px_bool PX_MQTTSubscribe(PX_MQTT *Mqtt,PX_MQTT_SubscribeDesc subscribeDesc); +px_bool PX_MQTTUnsubscribe(PX_MQTT *Mqtt,const px_char *Topic); +px_bool PX_MQTTPingReq(PX_MQTT *Mqtt); +px_bool PX_MQTTListen(PX_MQTT *Mqtt); +px_void PX_MQTTFree(PX_MQTT *Mqtt); +#endif + diff --git a/lib/PainterEngine/kernel/PX_Object.c b/lib/PainterEngine/kernel/PX_Object.c new file mode 100644 index 0000000000000000000000000000000000000000..af82fd3ffd541269bccfecb6c7dd0911c13dc0ee --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object.c @@ -0,0 +1,986 @@ +#include "PX_Object.h" + + +PX_Object * PX_ObjectGetChild( PX_Object *Object,px_int Index ) +{ + PX_Object *pObject; + if (!Object) + { + return PX_NULL; + } + pObject=Object->pChilds; + while (Index>0&&pObject) + { + pObject=pObject->pNextBrother; + Index--; + } + return pObject; + +} + +static PX_Object * PX_ObjectGetObjectLink(PX_Object *pObject,const px_char payload[]) +{ + px_char id[PX_OBJECT_ID_MAXLEN]={0}; + px_int oft=0; + if (!pObject) + { + return PX_NULL; + } + + while (payload[oft]!='.'&&payload[oft]!='\0'&&oftid,id)) + { + return pObject; + } + else + { + return PX_ObjectGetObjectLink(pObject->pNextBrother,payload); + } + } + else + { + if (PX_strequ(pObject->id,id)) + { + return PX_ObjectGetObjectLink(pObject->pChilds,payload+oft); + } + else + { + return PX_ObjectGetObjectLink(pObject->pNextBrother,payload); + } + } + return PX_NULL; +} + +PX_Object * PX_ObjectGetObject(PX_Object *pObject,const px_char payload[]) +{ + px_char id[PX_OBJECT_ID_MAXLEN]={0}; + + px_int oft=0; + if (!pObject) + { + return PX_NULL; + } + + while (payload[oft]!='.'&&payload[oft]!='\0'&&oftid,id)) + { + return pObject; + } + else + { + return PX_NULL; + } + } + else + { + if (PX_strequ(pObject->id,id)) + { + return PX_ObjectGetObjectLink(pObject->pChilds,payload+oft); + } + } + return PX_NULL; +} + + +static px_void PX_ObjectSetFocusEx(PX_Object *pObject) +{ + while(pObject) + { + pObject->OnFocus=PX_TRUE; + pObject=pObject->pParent; + } +} + +static px_void PX_ObjectClearFocusEx(PX_Object *pObject) +{ + if (!pObject) + { + return; + } + pObject->OnFocus=PX_FALSE; + pObject->OnFocusNode=PX_FALSE; + PX_ObjectClearFocusEx(pObject->pChilds); + PX_ObjectClearFocusEx(pObject->pNextBrother); +} + +px_void PX_ObjectClearFocus(PX_Object *pObject) +{ + PX_Object *pClearObject=pObject; + if (!pObject->OnFocus) + { + return; + } + while(pClearObject->pParent) + { + pClearObject=pClearObject->pParent; + + if (pClearObject->OnFocusNode) + { + pClearObject=pClearObject->pChilds; + break; + } + } + PX_ObjectClearFocusEx(pClearObject); +} + +px_void PX_ObjectSetFocus(PX_Object *pObject) +{ + PX_Object *pClearObject=pObject; + while(pClearObject->pParent) + { + pClearObject=pClearObject->pParent; + if (pClearObject->OnFocusNode) + { + pClearObject=pClearObject->pChilds; + break; + } + } + PX_ObjectClearFocusEx(pClearObject); + pObject->OnFocusNode=PX_TRUE; + PX_ObjectSetFocusEx(pObject); +} + + +PX_Object * PX_ObjectGetRoot(PX_Object *Object) +{ + while(Object->pParent) + { + Object=Object->pParent; + } + return Object; +} + +PX_Object_Event PX_OBJECT_BUILD_EVENT(px_uint Event) +{ + PX_Object_Event e; + PX_memset(&e,0,sizeof(e)); + e.Event=Event; + return e; +} + +PX_Object_Event PX_OBJECT_BUILD_EVENT_STRING(px_uint Event,const px_char *content) +{ + PX_Object_Event e; + PX_memset(&e,0,sizeof(e)); + e.Event=Event; + PX_Object_Event_SetStringPtr(&e,(px_void *)content); + return e; +} + +PX_Object_Event PX_Object_Event_CursorOffset(PX_Object_Event e,px_point offset) +{ + switch(e.Event) + { + case PX_OBJECT_EVENT_CURSORMOVE: + case PX_OBJECT_EVENT_CURSORUP: + case PX_OBJECT_EVENT_CURSORRDOWN: + case PX_OBJECT_EVENT_CURSORDOWN: + case PX_OBJECT_EVENT_CURSORRUP: + case PX_OBJECT_EVENT_CURSOROVER: + case PX_OBJECT_EVENT_CURSOROUT: + case PX_OBJECT_EVENT_CURSORWHEEL: + case PX_OBJECT_EVENT_CURSORCLICK: + case PX_OBJECT_EVENT_CURSORDRAG: + PX_Object_Event_SetCursorX(&e,PX_Object_Event_GetCursorX(e)+offset.x); + PX_Object_Event_SetCursorY(&e,PX_Object_Event_GetCursorY(e)+offset.y); + return e; + default: + return e; + } +} + +px_float PX_Object_Event_GetCursorX(PX_Object_Event e) +{ + return e.Param_float[0]; +} + +px_float PX_Object_Event_GetCursorY(PX_Object_Event e) +{ + return e.Param_float[1]; +} + + +px_float PX_Object_Event_GetCursorZ(PX_Object_Event e) +{ + return e.Param_float[2]; +} + +px_int PX_Object_Event_GetCursorIndex(PX_Object_Event e) +{ + return e.Param_int[2]; +} + +px_float PX_Object_Event_GetWidth(PX_Object_Event e) +{ + return e.Param_float[0]; +} + +px_float PX_Object_Event_GetHeight(PX_Object_Event e) +{ + return e.Param_float[1]; +} + +px_int PX_Object_Event_GetIndex(PX_Object_Event e) +{ + return e.Param_int[0]; +} + +px_void PX_Object_Event_SetWidth(PX_Object_Event *e,px_float w) +{ + e->Param_float[0]=w; +} + +px_void PX_Object_Event_SetHeight(PX_Object_Event *e,px_float h) +{ + e->Param_float[1]=h; +} + +px_void PX_Object_Event_SetCursorX(PX_Object_Event *e,px_float x) +{ + e->Param_float[0]=x; +} + +px_void PX_Object_Event_SetCursorY(PX_Object_Event *e,px_float y) +{ + e->Param_float[1]=y; +} + +px_void PX_Object_Event_SetCursorZ(PX_Object_Event *e,px_float z) +{ + e->Param_float[2]=z; +} + +px_void PX_Object_Event_SetCursorIndex(PX_Object_Event *e,px_int index) +{ + e->Param_int[2]=index; +} + +px_float PX_Object_Event_GetScaleCursorX(PX_Object_Event e) +{ + return e.Param_float[0]; +} + +px_float PX_Object_Event_GetScaleCursorY(PX_Object_Event e) +{ + return e.Param_float[1]; +} + +px_float PX_Object_Event_GetScaleCursorZ(PX_Object_Event e) +{ + return e.Param_float[2]; +} + +px_void PX_Object_Event_SetScaleCursorX(PX_Object_Event *e,px_float x) +{ + e->Param_float[0]=x; +} + +px_void PX_Object_Event_SetScaleCursorY(PX_Object_Event *e,px_float y) +{ + e->Param_float[1]=y; +} + +px_void PX_Object_Event_SetScaleCursorZ(PX_Object_Event *e,px_float z) +{ + e->Param_float[2]=z; +} + +px_uint PX_Object_Event_GetKeyDown(PX_Object_Event e) +{ + return e.Param_uint[0]; +} + +px_void PX_Object_Event_SetKeyDown(PX_Object_Event *e,px_uint key) +{ + e->Param_uint[0]=key; +} + +px_void PX_Object_Event_SetKeyUp(PX_Object_Event *e,px_uint key) +{ + e->Param_uint[0]=key; +} + +px_char* PX_Object_Event_GetStringPtr(PX_Object_Event e) +{ + return (px_char *)e.Param_ptr[0]; +} + +px_void* PX_Object_Event_GetDataPtr(PX_Object_Event e) +{ + return (px_void *)e.Param_ptr[0]; +} + + +px_void PX_Object_Event_SetStringPtr(PX_Object_Event *e,px_void *ptr) +{ + e->Param_ptr[0]=ptr; +} + +px_void PX_Object_Event_SetDataPtr(PX_Object_Event *e,px_void *ptr) +{ + e->Param_ptr[0]=ptr; +} + +px_void PX_Object_Event_SetIndex(PX_Object_Event *e,px_int index) +{ + e->Param_int[0]=index; +} + +PX_Object * PX_ObjectCreate(px_memorypool *mp,PX_Object *Parent,px_float x,px_float y,px_float z,px_float Width,px_float Height,px_float Lenght) +{ + + PX_Object *pObject=(PX_Object *)MP_Malloc(mp,sizeof(PX_Object)); + if (pObject==PX_NULL) + { + return PX_NULL; + } + + PX_ObjectInitialize(mp,pObject,Parent,x,y,z,Width,Height,Lenght); + + return pObject; +} + + + +PX_Object * PX_ObjectCreateEx(px_memorypool *mp,PX_Object *Parent,px_float x,px_float y,px_float z,px_float Width,px_float Height,px_float Lenght,px_int type,Function_ObjectUpdate Func_ObjectUpdate,Function_ObjectRender Func_ObjectRender,Function_ObjectFree Func_ObjectFree,px_void *desc,px_int size) +{ + PX_Object *pObject=PX_ObjectCreate(mp,Parent,x,y,z,Width,Height,Lenght); + if (pObject) + { + pObject->pObject=MP_Malloc(mp,size); + if (!pObject->pObject) + { + MP_Free(mp,pObject); + return PX_NULL; + } + if (desc) + { + PX_memcpy(pObject->pObject,desc,size); + } + else + { + PX_memset(pObject->pObject,0,size); + } + + pObject->Type=type; + pObject->Func_ObjectFree=Func_ObjectFree; + pObject->Func_ObjectRender=Func_ObjectRender; + pObject->Func_ObjectUpdate=Func_ObjectUpdate; + } + return pObject; +} + + +px_void PX_ObjectGetInheritXY(PX_Object *Object,px_float *x,px_float *y) +{ + *x=0; + *y=0; + Object=Object->pParent; + while (Object) + { + *x+=Object->x; + *y+=Object->y; + Object=Object->pParent; + } +} + +static px_void PX_Object_ObjectEventFree( PX_Object **Object ) +{ + PX_OBJECT_EventAction *pNext,*pCur;; + //PX_Object_Free Events linker + pCur=(*Object)->pEventActions; + while (pCur) + { + pNext=pCur->pNext; + MP_Free((*Object)->mp,pCur); + pCur=pNext; + } + + (*Object)->pEventActions=PX_NULL; +} + + + +static px_void PX_Object_ObjectFree( PX_Object *Object ) +{ + PX_Object_ObjectEventFree(&Object); + if (Object->Func_ObjectFree!=0) + { + Object->Func_ObjectFree(Object); + } + if(Object->pObject) + MP_Free(Object->mp,Object->pObject); + + MP_Free(Object->mp,Object); +} + + +static px_void PX_Object_DeleteLinkerObject( PX_Object **ppObject ) +{ + PX_Object *Object=(*ppObject); + + if (Object==PX_NULL) + { + return; + } + PX_Object_DeleteLinkerObject(&Object->pNextBrother); + PX_Object_DeleteLinkerObject(&Object->pChilds); + + PX_Object_ObjectFree(Object); + + (*ppObject)=PX_NULL; +} + +px_void PX_ObjectDelete( PX_Object *pObject ) +{ + if (pObject==PX_NULL) + { + return; + } + if (pObject->OnFocus) + { + PX_ObjectClearFocus(pObject); + } + + if (pObject->pChilds!=PX_NULL) + { + PX_Object_DeleteLinkerObject(&pObject->pChilds); + } + + if (pObject->pParent!=PX_NULL) + { + if (pObject->pParent->pChilds==pObject) + { + pObject->pParent->pChilds=pObject->pNextBrother; + if(pObject->pNextBrother) + { + pObject->pNextBrother->pParent=pObject->pParent; + pObject->pNextBrother->pPreBrother=PX_NULL; + } + } + else + { + if (pObject->pPreBrother!=PX_NULL) + { + pObject->pPreBrother->pNextBrother=pObject->pNextBrother; + if(pObject->pNextBrother) + pObject->pNextBrother->pPreBrother=pObject->pPreBrother; + } + else + { + PX_ERROR("Invalid GUI Object struct"); + } + } + } + else + { + if (pObject->pPreBrother!=PX_NULL) + { + pObject->pPreBrother=pObject->pNextBrother; + } + } + + + PX_Object_ObjectFree(pObject); + +} + + +px_void PX_ObjectDeleteChilds( PX_Object *pObject ) +{ + if (pObject==PX_NULL) + { + return; + } + + if (pObject->pChilds!=PX_NULL) + { + PX_Object_DeleteLinkerObject(&pObject->pChilds); + } +} + +px_void PX_Object_ObjectLinkerUpdate( PX_Object *Object,px_uint elapsed) +{ + if (Object==PX_NULL) + { + return; + } + if (Object->Enabled) + { + if (Object->Func_ObjectUpdate!=0) + { + Object->Func_ObjectUpdate(Object,elapsed); + } + PX_Object_ObjectLinkerUpdate(Object->pChilds,elapsed); + } + PX_Object_ObjectLinkerUpdate(Object->pNextBrother,elapsed); +} + + +px_void PX_ObjectUpdate(PX_Object *Object,px_uint elapsed ) +{ + if (Object==PX_NULL) + { + PX_ASSERT(); + return; + } + if (Object->Enabled==PX_FALSE) + { + return; + } + if (Object->Func_ObjectUpdate!=0) + { + Object->Func_ObjectUpdate(Object,elapsed); + } + if (Object->pChilds!=PX_NULL) + { + PX_Object_ObjectLinkerUpdate(Object->pChilds,elapsed); + } +} + +static px_void PX_ObjectRenderEx(px_surface *pSurface, PX_Object *Object,px_uint elapsed ) +{ + if (Object==PX_NULL) + { + return; + } + + if (Object->OnFocus) + { + PX_ObjectRenderEx(pSurface,Object->pNextBrother,elapsed); + + if (Object->Visible!=PX_FALSE) + { + if (Object->Func_ObjectBeginRender) + { + Object->Func_ObjectBeginRender(pSurface,Object,elapsed); + } + + if (Object->Func_ObjectRender!=0) + { + Object->Func_ObjectRender(pSurface,Object,elapsed); + } + + PX_ObjectRenderEx(pSurface,Object->pChilds,elapsed); + + + if (Object->Func_ObjectEndRender) + { + Object->Func_ObjectEndRender(pSurface,Object,elapsed); + } + } + } + else + { + if (Object->Visible!=PX_FALSE) + { + if (Object->Func_ObjectBeginRender) + { + Object->Func_ObjectBeginRender(pSurface,Object,elapsed); + } + if (Object->Func_ObjectRender!=0) + { + Object->Func_ObjectRender(pSurface,Object,elapsed); + } + PX_ObjectRenderEx(pSurface,Object->pChilds,elapsed); + + if (Object->Func_ObjectEndRender) + { + Object->Func_ObjectEndRender(pSurface,Object,elapsed); + } + } + PX_ObjectRenderEx(pSurface,Object->pNextBrother,elapsed); + } +} + +px_void PX_ObjectRender(px_surface *pSurface, PX_Object *Object,px_uint elapsed ) +{ + if (Object==PX_NULL) + { + return; + } + + if (Object->OnFocus) + { + + if (Object->Visible!=PX_FALSE) + { + if (Object->Func_ObjectBeginRender) + { + Object->Func_ObjectBeginRender(pSurface,Object,elapsed); + } + + if (Object->Func_ObjectRender!=0) + { + Object->Func_ObjectRender(pSurface,Object,elapsed); + } + + PX_ObjectRenderEx(pSurface,Object->pChilds,elapsed); + + + if (Object->Func_ObjectEndRender) + { + Object->Func_ObjectEndRender(pSurface,Object,elapsed); + } + } + } + else + { + if (Object->Visible!=PX_FALSE) + { + if (Object->Func_ObjectBeginRender) + { + Object->Func_ObjectBeginRender(pSurface,Object,elapsed); + } + if (Object->Func_ObjectRender!=0) + { + Object->Func_ObjectRender(pSurface,Object,elapsed); + } + PX_ObjectRenderEx(pSurface,Object->pChilds,elapsed); + + if (Object->Func_ObjectEndRender) + { + Object->Func_ObjectEndRender(pSurface,Object,elapsed); + } + } + } +} + +px_bool PX_ObjectIsPointInRegion( PX_Object *pObject,px_float x,px_float y ) +{ + px_float objx,objy,objw,objh; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objw=pObject->Width; + objh=pObject->Height; + + return PX_isXYInRegion(x,y,objx,objy,objw,objh); +} + +px_bool PX_ObjectIsCursorInRegion(PX_Object *Object,PX_Object_Event e) +{ + return PX_ObjectIsPointInRegion(Object,PX_Object_Event_GetCursorX(e),PX_Object_Event_GetCursorY(e)); +} + +px_float PX_ObjectGetHeight(PX_Object *Object) +{ + return Object->Height; +} + +px_float PX_ObjectGetWidth(PX_Object *Object) +{ + return Object->Width; +} + +px_void PX_ObjectAddClild(PX_Object *Parent,PX_Object *child) +{ + PX_Object *pLinker; + child->pParent=Parent; + if(Parent->pChilds==PX_NULL) + { + Parent->pChilds=child; + } + else + { + pLinker=Parent->pChilds; + while (pLinker->pNextBrother) + { + pLinker=pLinker->pNextBrother; + } + pLinker->pNextBrother=child; + child->pPreBrother=pLinker; + } + child->pNextBrother=PX_NULL; +} + +px_void PX_ObjectInitialize(px_memorypool *mp,PX_Object *pObject,PX_Object *Parent,px_float x,px_float y,px_float z,px_float Width,px_float Height,px_float Lenght ) +{ + PX_memset(pObject,0,sizeof(PX_Object)); + + pObject->x=x; + pObject->y=y; + pObject->z=z; + pObject->Width=Width; + pObject->Height=Height; + + pObject->Enabled=PX_TRUE; + pObject->Visible=PX_TRUE; + pObject->pChilds=PX_NULL; + pObject->pObject=PX_NULL; + pObject->pNextBrother=PX_NULL; + pObject->pPreBrother=PX_NULL; + pObject->Type=PX_OBJECT_TYPE_NULL; + pObject->ReceiveEvents=PX_TRUE; + pObject->impact_target_type=0; + pObject->impact_object_type=0; + pObject->pEventActions=PX_NULL; + pObject->world_index=-1; + pObject->User_int=0; + pObject->diameter=0; + pObject->User_ptr=PX_NULL; + pObject->OnFocus=PX_FALSE; + pObject->mp=mp; + pObject->Func_ObjectFree=PX_NULL; + pObject->Func_ObjectRender=PX_NULL; + pObject->Func_ObjectUpdate=PX_NULL; + pObject->Func_ObjectLinkChild=PX_NULL; + pObject->Func_ObjectBeginRender=PX_NULL; + pObject->Func_ObjectEndRender=PX_NULL; + + if (Parent!=PX_NULL) + { + if (Parent->Func_ObjectLinkChild!=PX_NULL) + { + Parent->Func_ObjectLinkChild(Parent,pObject); + } + else + { + PX_ObjectAddClild(Parent,pObject); + } + + } +} + + +px_void PX_ObjectSetId(PX_Object *pObject,const px_char id[]) +{ + PX_strcpy(pObject->id,id,sizeof(pObject->id)); +} + +px_void PX_ObjectSetVisible( PX_Object *pObject,px_bool visible ) +{ + if(pObject!=PX_NULL) + { + if (pObject->OnFocus) + { + PX_ObjectClearFocus(pObject); + } + pObject->Visible=visible; + } +} + + +px_void PX_ObjectSetEnabled(PX_Object *Object,px_bool enabled) +{ + Object->Enabled=enabled; +} + +px_void PX_ObjectEnable(PX_Object *Object) +{ + Object->Enabled=PX_TRUE; +} + +px_void PX_ObjectDisable(PX_Object *Object) +{ + Object->Enabled=PX_FALSE; +} + +px_int PX_ObjectRegisterEvent( PX_Object *Object,px_uint Event,px_void (*ProcessFunc)(PX_Object *,PX_Object_Event e,px_void *user_ptr),px_void *user) +{ + PX_OBJECT_EventAction *pPoint; + PX_OBJECT_EventAction *pAction=(PX_OBJECT_EventAction *)MP_Malloc(Object->mp,sizeof(PX_OBJECT_EventAction)); + if (pAction==PX_NULL) + { + return PX_FALSE; + } + pAction->pNext=PX_NULL; + pAction->pPre=PX_NULL; + pAction->EventAction=Event; + pAction->EventActionFunc=ProcessFunc; + + pAction->user_ptr=user; + + pPoint=Object->pEventActions; + if (pPoint==PX_NULL) + { + Object->pEventActions=pAction; + return PX_TRUE; + } + + while(pPoint->pNext) + { + pPoint=pPoint->pNext; + } + pAction->pPre=pPoint; + pPoint->pNext=pAction; + + return PX_TRUE; +} + + +px_void PX_ObjectExecuteEvent(PX_Object *pPost,PX_Object_Event Event) +{ + PX_OBJECT_EventAction *EventAction; + + if (pPost->Visible==PX_FALSE||pPost->Enabled==PX_FALSE||pPost->ReceiveEvents==PX_FALSE) + { + return; + } + + EventAction=pPost->pEventActions; + while(EventAction) + { + if (EventAction->EventAction==PX_OBJECT_EVENT_ANY||EventAction->EventAction==Event.Event) + { + EventAction->EventActionFunc(pPost,Event,EventAction->user_ptr); + } + EventAction=EventAction->pNext; + } +} + + +px_bool PX_ObjectPostEventLink( PX_Object *pPost,PX_Object_Event Event ) +{ + if (pPost==PX_NULL) + { + return PX_TRUE; + } + + if (pPost->Visible==PX_FALSE||pPost->Enabled==PX_FALSE||pPost->ReceiveEvents==PX_FALSE) + { + if(PX_ObjectPostEventLink(pPost->pNextBrother,Event)==PX_FALSE) return PX_FALSE; + return PX_TRUE; + } + + if (pPost->OnFocus) + { + if(PX_ObjectPostEventLink(pPost->pChilds,Event)==PX_FALSE) + { + return PX_FALSE; + } + else + { + PX_ObjectExecuteEvent(pPost,Event); + } + + if (!pPost->OnFocus&&!pPost->OnLostFocusReleaseEvent) + { + return PX_ObjectPostEventLink(pPost->pNextBrother,Event); + } + + return PX_FALSE; + } + else + { + if(PX_ObjectPostEventLink(pPost->pNextBrother,Event)==PX_FALSE) return PX_FALSE; + if(PX_ObjectPostEventLink(pPost->pChilds,Event)==PX_FALSE) return PX_FALSE; + PX_ObjectExecuteEvent(pPost,Event); + if (pPost->OnFocus) + { + return PX_FALSE; + } + return PX_TRUE; + } + +} + +px_void PX_ObjectPostEvent( PX_Object *pPost,PX_Object_Event Event ) +{ + + if (pPost==PX_NULL) + { + return; + } + + if (pPost->Visible==PX_FALSE||pPost->Enabled==PX_FALSE||pPost->ReceiveEvents==PX_FALSE) + { + return; + } + + if (pPost->OnFocus) + { + if(PX_ObjectPostEventLink(pPost->pChilds,Event)==PX_FALSE) + { + if (!pPost->OnFocus) + { + PX_ObjectExecuteEvent(pPost,Event); + } + } + else + { + PX_ObjectExecuteEvent(pPost,Event); + } + return; + } + else + { + if(PX_ObjectPostEventLink(pPost->pChilds,Event)==PX_FALSE) return; + PX_ObjectExecuteEvent(pPost,Event); + return; + } +} + + +px_void PX_ObjectSetPosition( PX_Object *Object,px_float x,px_float y,px_float z) +{ + if (Object==PX_NULL) + { + PX_ASSERT(); + return; + } + + Object->x=x; + Object->y=y; + Object->z=z; +} + + + +px_void PX_ObjectSetSize( PX_Object *Object,px_float Width,px_float Height,px_float length) +{ + if (Object!=PX_NULL) + { + Object->Width=Width; + Object->Height=Height; + + } + else + { + PX_ASSERT(); + } +} + + +px_void PX_ObjectSetUserCode(PX_Object *pObject,px_int user) +{ + pObject->User_int=user; +} + +px_void PX_ObjectSetUserPointer(PX_Object *pObject,px_void *user_ptr) +{ + pObject->User_ptr=user_ptr; +} + + + + diff --git a/lib/PainterEngine/kernel/PX_Object.h b/lib/PainterEngine/kernel/PX_Object.h new file mode 100644 index 0000000000000000000000000000000000000000..338b5f0257cfb3316ad20b3f9a67198598502beb --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object.h @@ -0,0 +1,469 @@ +#ifndef PIXELSES_OBJECT_H +#define PIXELSES_OBJECT_H + +#include "../core/PX_Core.h" +#include "PX_Animation.h" +#include "PX_Partical.h" + + +////////////////////////////////////////////////////////////////////////// +/// Common Events +////////////////////////////////////////////////////////////////////////// +#define PX_OBJECT_EVENT_ANY 0 +#define PX_OBJECT_EVENT_CURSORMOVE 1 +#define PX_OBJECT_EVENT_CURSORUP 2 +#define PX_OBJECT_EVENT_CURSORRDOWN 3 +#define PX_OBJECT_EVENT_CURSORDOWN 4 +#define PX_OBJECT_EVENT_CURSORRUP 5 +#define PX_OBJECT_EVENT_CURSOROVER 6 +#define PX_OBJECT_EVENT_CURSOROUT 7 +#define PX_OBJECT_EVENT_CURSORWHEEL 8 +#define PX_OBJECT_EVENT_CURSORCLICK 9 +#define PX_OBJECT_EVENT_CURSORDRAG 10 +#define PX_OBJECT_EVENT_STRING 11 +#define PX_OBJECT_EVENT_EXECUTE 12 +#define PX_OBJECT_EVENT_VALUECHANGED 13 +#define PX_OBJECT_EVENT_DRAGFILE 14 +#define PX_OBJECT_EVENT_KEYDOWN 15 +#define PX_OBJECT_EVENT_KEYUP 16 +#define PX_OBJECT_EVENT_IMPACT 17 +#define PX_OBJECT_EVENT_SCALE 18 +#define PX_OBJECT_EVENT_WINDOWRESIZE 19 +#define PX_OBJECT_EVENT_ONFOCUS 20 +#define PX_OBJECT_EVENT_LOSTFOCUS 21 +#define PX_OBJECT_EVENT_CANCEL 22 +#define PX_OBJECT_EVENT_CLOSE 23 +#define PX_OBJECT_EVENT_CURSORMUP 24 +#define PX_OBJECT_EVENT_CURSORMDOWN 25 +////////////////////////////////////////////////////////////////////////////// +// Type of Controls +///////////////////////////////////////////////////////////////////////////// + +enum PX_OBJECT_TYPE +{ + PX_OBJECT_TYPE_NULL , + PX_OBJECT_TYPE_LABEL , + PX_OBJECT_TYPE_PROCESSBAR , + PX_OBJECT_TYPE_IMAGE , + PX_OBJECT_TYPE_PARTICAL , + PX_OBJECT_TYPE_SLIDERBAR , + PX_OBJECT_TYPE_LIST , + PX_OBJECT_TYPE_LISTITEM , + PX_OBJECT_TYPE_PUSHBUTTON , + PX_OBJECT_TYPE_EDIT , + PX_OBJECT_TYPE_SCROLLAREA , + PX_OBJECT_TYPE_AUTOTEXT , + PX_OBJECT_TYPE_ANIMATION , + PX_OBJECT_TYPE_CURSORBUTTON , + PX_OBJECT_TYPE_VKEYBOARD , + PX_OBJECT_TYPE_VNKEYBOARD , + PX_OBJECT_TYPE_COORDINATE , + PX_OBJECT_TYPE_FILTEREDITOR , + PX_OBJECT_TYPE_CHECKBOX , + PX_OBJECT_TYPE_ROTATION , + PX_OBJECT_TYPE_MENU , + PX_OBJECT_TYPE_SELECTBAR , + PX_OBJECT_TYPE_RADIOBOX , + PX_OBJECT_TYPE_EXPLORER , + PX_OBJECT_TYPE_WIDGET , + PX_OBJECT_TYPE_SCALEBOX , + PX_OBJECT_TYPE_MESSAGEBOX , + PX_OBJECT_TYPE_PROTRACTOR , + PX_OBJECT_TYPE_TRANSFORMADAPTER, + PX_OBJECT_TYPE_PANC, + PX_OBJECT_TYPE_DESIGNERBOX, + PX_OBJECT_TYPE_JOYSTICK, + PX_OBJECT_TYPE_RINGPROCESSBAR, + PX_OBJECT_TYPE_MEMORYVIEW, + PX_OBJECT_TYPE_VARIOUS, + PX_OBJECT_TYPE_IPBOX, + PX_OBJECT_TYPE_VARBOX, + PX_OBJECT_TYPE_COMBOX, +}; + + +////////////////////////////////////////////////////////////////////////// +// +////////////////////////////////////////////////////////////////////////// + +#define PX_OBJECT_ID_MAXLEN 32 + +#define PX_OBJECT_IMAGE_LISTITEM_STYLE_NONE 0 +#define PX_OBJECT_IMAGE_LISTITEM_STYLE_BORDER 1 + +#define PX_OBJECT_IMAGE_LISTBOX_ITEMHEIGHT 18 +#define PX_OBJECT_IMAGE_LISTBOX_SLIDERWITDH 8 + +#define PX_OBJECT_IMAGE_LISTBOX_STYLE_ITEMBORDER 1 +#define PX_OBJECT_IMAGE_LISTBOX_STYLE_SELECT 2 + +#ifndef PX_OBJECT_UI_DEFAULT_BACKGROUNDCOLOR +#define PX_OBJECT_UI_DEFAULT_BACKGROUNDCOLOR PX_COLOR(255,48,48,48) +#endif + +#ifndef PX_OBJECT_UI_DEFAULT_CURSORCOLOR +#define PX_OBJECT_UI_DEFAULT_CURSORCOLOR PX_COLOR(255,32,32,32) +#endif + +#ifndef PX_OBJECT_UI_DEFAULT_FONTCOLOR +#define PX_OBJECT_UI_DEFAULT_FONTCOLOR PX_COLOR(255,192,192,192) +#endif + +#ifndef PX_OBJECT_UI_DEFAULT_BORDERCOLOR +#define PX_OBJECT_UI_DEFAULT_BORDERCOLOR PX_COLOR(255,192,192,192) +#endif + +#ifndef PX_OBJECT_UI_DEFAULT_PUSHCOLOR +#define PX_OBJECT_UI_DEFAULT_PUSHCOLOR PX_COLOR(255,64,64,64) +#endif + +#define PX_OBJECT_UI_DISABLE_FONTCOLOR PX_COLOR(255,128,128,128) + +#define PX_COLOR_WHITE PX_COLOR(255,255,255,255) +#define PX_COLOR_BLACK PX_COLOR(255,0,0,0) +#define PX_COLOR_RED PX_COLOR(255,255,0,0) +#define PX_COLOR_GREEN PX_COLOR(255,0,255,0) +#define PX_COLOR_BLUE PX_COLOR(255,0,0,255) + + +#define PX_OBJECT_FILTEREDITOR_DEFAULE_HORIZONTALPIXELDIVIDING 48 +#define PX_OBJECT_FILTEREDITOR_DEFAULE_VERTICALPIXELDIVIDING 20 +#define PX_OBJECT_FILTEREDITOR_DEFAULT_FRAMELINE_WIDTH 2 + + +/////////////////////////////////////////////////////////////////////////// +//// PainterEngine Object +////////////////////////////////////////////////////////////////////////// +struct _PX_Object; +typedef struct _PX_Object PX_Object; + +typedef px_void (*Function_ObjectUpdate)(PX_Object *,px_uint elapsed); +typedef px_void (*Function_ObjectBeginRender)(px_surface *,PX_Object *,px_dword); +typedef px_void (*Function_ObjectRender)(px_surface *psurface,PX_Object *,px_uint elapsed); +typedef px_void (*Function_ObjectEndRender)(px_surface *,PX_Object *,px_dword); +typedef px_void (*Function_ObjectFree)(PX_Object *); +typedef px_void (*Function_ObjectLinkChild)(PX_Object *parent,PX_Object *child); + +struct _PX_Object +{ + px_char id[PX_OBJECT_ID_MAXLEN]; + px_float x; + px_float y; + px_float z; + px_float Width; + px_float Height; + px_float Length; + px_float diameter;//if the member is not zero,The Object is round shape + px_bool OnFocus; + px_bool OnFocusNode; + px_bool OnLostFocusReleaseEvent; + px_bool Enabled; + px_bool Visible; + px_bool ReceiveEvents; + px_int Type; + px_int designerTyoe; + union + { + px_int User_int; + px_void *User_ptr; + }; + + px_int world_index; + px_dword impact_object_type; + px_dword impact_target_type; + px_void *pObject; + px_memorypool *mp; + struct _PX_Object *pChilds; + struct _PX_Object *pParent; + struct _PX_Object *pPreBrother; + struct _PX_Object *pNextBrother; + + struct _PX_Object_EventAction *pEventActions; + Function_ObjectUpdate Func_ObjectUpdate; + Function_ObjectRender Func_ObjectRender; + Function_ObjectFree Func_ObjectFree; + Function_ObjectLinkChild Func_ObjectLinkChild; + Function_ObjectBeginRender Func_ObjectBeginRender; + Function_ObjectEndRender Func_ObjectEndRender; +}; + + +////////////////////////////////////////////////////////////////////////// +/// Controllers +////////////////////////////////////////////////////////////////////////// + + + + +typedef struct +{ + PX_ALIGN Align; + PX_Animation animation; +}PX_Object_Animation; + + + + +typedef struct +{ + px_shape *shape; + px_point cursorPoint; + px_color blendColor; +}PX_Object_RoundCursor; + + + +typedef struct _PX_Object_Event +{ + px_uint Event; + union + { + px_char Param_char[16]; + px_uint Param_uint[4]; + px_int Param_int[4]; + px_float Param_float[4]; + px_void *Param_ptr[4]; + px_bool Param_bool[4]; + }; +}PX_Object_Event; + +////////////////////////////////////////////////////////////////////////// +//EVENT params +PX_Object_Event PX_OBJECT_BUILD_EVENT(px_uint Event); +PX_Object_Event PX_OBJECT_BUILD_EVENT_STRING(px_uint Event,const px_char *content); +PX_Object_Event PX_Object_Event_CursorOffset(PX_Object_Event e,px_point offset); + +px_float PX_Object_Event_GetCursorX(PX_Object_Event e); +px_float PX_Object_Event_GetCursorY(PX_Object_Event e); +px_float PX_Object_Event_GetCursorZ(PX_Object_Event e); +px_int PX_Object_Event_GetCursorIndex(PX_Object_Event e); + +px_float PX_Object_Event_GetWidth(PX_Object_Event e); +px_float PX_Object_Event_GetHeight(PX_Object_Event e); +px_int PX_Object_Event_GetIndex(PX_Object_Event e); + +px_void PX_Object_Event_SetWidth(PX_Object_Event *e,px_float w); +px_void PX_Object_Event_SetHeight(PX_Object_Event *e,px_float h); +px_void PX_Object_Event_SetCursorX(PX_Object_Event *e,px_float x); +px_void PX_Object_Event_SetCursorY(PX_Object_Event *e,px_float y); +px_void PX_Object_Event_SetCursorZ(PX_Object_Event *e,px_float z); +px_void PX_Object_Event_SetCursorIndex(PX_Object_Event *e,px_int index); + +px_float PX_Object_Event_GetScaleCursorX(PX_Object_Event e); +px_float PX_Object_Event_GetScaleCursorY(PX_Object_Event e); +px_float PX_Object_Event_GetScaleCursorZ(PX_Object_Event e); + +px_void PX_Object_Event_SetScaleCursorX(PX_Object_Event *e,px_float x); +px_void PX_Object_Event_SetScaleCursorY(PX_Object_Event *e,px_float y); +px_void PX_Object_Event_SetScaleCursorZ(PX_Object_Event *e,px_float z); + +px_uint PX_Object_Event_GetKeyDown(PX_Object_Event e); +px_void PX_Object_Event_SetKeyDown(PX_Object_Event *e,px_uint key); +px_void PX_Object_Event_SetKeyUp(PX_Object_Event *e,px_uint key); +px_char* PX_Object_Event_GetStringPtr(PX_Object_Event e); +px_void* PX_Object_Event_GetDataPtr(PX_Object_Event e); +px_void PX_Object_Event_SetStringPtr(PX_Object_Event *e,px_void *ptr); +px_void PX_Object_Event_SetDataPtr(PX_Object_Event *e,px_void *ptr); +px_void PX_Object_Event_SetIndex(PX_Object_Event *e,px_int index); +struct _PX_Object_EventAction +{ + px_uint EventAction; + px_void (*EventActionFunc)(PX_Object *,PX_Object_Event e,px_void *user_ptr); + px_void *user_ptr; + struct _PX_Object_EventAction *pNext; + struct _PX_Object_EventAction *pPre; +}; + +typedef struct _PX_Object_EventAction PX_OBJECT_EventAction; + + +PX_Object *PX_ObjectCreate(px_memorypool *mp,PX_Object *Parent,px_float x,px_float y,px_float z,px_float Width,px_float Height,px_float Length); +PX_Object *PX_ObjectCreateEx(px_memorypool *mp,PX_Object *Parent,\ + px_float x,px_float y,px_float z,px_float Width,px_float Height,px_float Length,\ + px_int type,\ + Function_ObjectUpdate Func_ObjectUpdate,\ + Function_ObjectRender Func_ObjectRender,\ + Function_ObjectFree Func_ObjectFree,\ + px_void *desc,\ + px_int size + ); +#define PX_ObjectGetDesc(type,pobject) ((type *)((pobject)->pObject)) +px_void PX_ObjectGetInheritXY(PX_Object *Object,px_float *x,px_float *y); +px_void PX_ObjectInitialize(px_memorypool *mp,PX_Object *Object,PX_Object *Parent,px_float x,px_float y,px_float z,px_float Width,px_float Height,px_float Length); +px_void PX_ObjectSetId(PX_Object *pObject,const px_char id[]); +px_void PX_ObjectSetUserCode(PX_Object *pObject,px_int user_int); +px_void PX_ObjectSetUserPointer(PX_Object *pObject,px_void *user_ptr); +px_void PX_ObjectDelete(PX_Object *pObject); +px_void PX_ObjectDeleteChilds( PX_Object *pObject ); +px_void PX_ObjectSetPosition(PX_Object *Object,px_float x,px_float y,px_float z); +px_void PX_ObjectSetSize(PX_Object *Object,px_float Width,px_float Height,px_float length); +px_void PX_ObjectSetVisible(PX_Object *Object,px_bool visible); +px_void PX_ObjectSetEnabled(PX_Object *Object,px_bool enabled); +px_void PX_ObjectEnable(PX_Object *Object); +px_void PX_ObjectDisable(PX_Object *Object); +PX_Object *PX_ObjectGetChild(PX_Object *Object,px_int Index); +PX_Object *PX_ObjectGetObject(PX_Object *pObject,const px_char payload[]); +px_void PX_ObjectSetFocus(PX_Object *Object); +px_void PX_ObjectClearFocus(PX_Object *Object); +#define PX_ObjectReleaseFocus PX_ObjectClearFocus + +px_bool PX_ObjectIsPointInRegion(PX_Object *Object,px_float x,px_float y); +px_bool PX_ObjectIsCursorInRegion(PX_Object *Object,PX_Object_Event e); +px_float PX_ObjectGetHeight(PX_Object *Object); +px_float PX_ObjectGetWidth(PX_Object *Object); + +px_void PX_ObjectAddClild(PX_Object *Parent,PX_Object *child); +px_void PX_ObjectUpdate(PX_Object *Object,px_uint elapsed ); +px_void PX_ObjectRender(px_surface *pSurface,PX_Object *Object,px_uint elapsed); + +px_int PX_ObjectRegisterEvent(PX_Object *Object,px_uint Event,px_void (*ProcessFunc)(PX_Object *,PX_Object_Event e,px_void *user_ptr),px_void *ptr); +px_void PX_ObjectPostEvent(PX_Object *pPost,PX_Object_Event Event); +px_void PX_ObjectExecuteEvent(PX_Object *pPost,PX_Object_Event Event); + +////////////////////////////////////////////////////////////////////////// +//Label +////////////////////////////////////////////////////////////////////////// +#include "PX_Object_Label.h" + +////////////////////////////////////////////////////////////////////////// +//ProcessBar +////////////////////////////////////////////////////////////////////////// +#include "PX_Object_Processbar.h" + +////////////////////////////////////////////////////////////////////////// +//Image +////////////////////////////////////////////////////////////////////////// +#include "PX_Object_Image.h" + +////////////////////////////////////////////////////////////////////////// +//SliderBar +////////////////////////////////////////////////////////////////////////// +#include "PX_Object_Sliderbar.h" + +////////////////////////////////////////////////////////////////////////// +//PushButton +////////////////////////////////////////////////////////////////////////// +#include "PX_Object_PushButton.h" + +////////////////////////////////////////////////////////////////////////// +//Edit +////////////////////////////////////////////////////////////////////////// +#include "PX_Object_Edit.h" + +///////////////////////////////////////////////////////////////////////////////////////// +//ScrollArea +////////////////////////////////////////////////////////////////////////// +#include "PX_Object_ScrollArea.h" + +/////////////////////////////////////////////////////////////////////////////////////////////// +//AutoText +////////////////////////////////////////////////////////////////////////// +#include "PX_Object_AutoText.h" + +////////////////////////////////////////////////////////////////////////// +//Animation +#include "PX_Object_Animation.h" + +////////////////////////////////////////////////////////////////////////// +//CursorButton +////////////////////////////////////////////////////////////////////////// +#include "PX_Object_CursorButton.h" + +////////////////////////////////////////////////////////////////////////// +//list +////////////////////////////////////////////////////////////////////////// +#include "PX_Object_List.h" +////////////////////////////////////////////////////////////////////////// +//virtual keyboard +#include "PX_Object_VirtualKeyboard.h" +////////////////////////////////////////////////////////////////////////// +//coordinate +#include "PX_Object_Coordinate.h" + +////////////////////////////////////////////////////////////////////////// +//checkbox +#include "PX_Object_CheckBox.h" +////////////////////////////////////////////////////////////////////////// +//menu +#include "PX_Object_Menu.h" + +////////////////////////////////////////////////////////////////////////// +//selectbar +#include "PX_Object_Selectbar.h" + +////////////////////////////////////////////////////////////////////////// +//radiobox +#include "PX_Object_RadioBox.h" + +////////////////////////////////////////////////////////////////////////// +//explorer +#include "PX_Object_Explorer.h" +////////////////////////////////////////////////////////////////////////// +//widget +////////////////////////////////////////////////////////////////////////// +#include "PX_Object_Widget.h" + + +////////////////////////////////////////////////////////////////////////// +//scalebox +////////////////////////////////////////////////////////////////////////// +#include "PX_Object_ScaleBox.h" + + + +////////////////////////////////////////////////////////////////////////// +//messagebox +////////////////////////////////////////////////////////////////////////// +#include "PX_Object_MessageBox.h" + + +////////////////////////////////////////////////////////////////////////// +//protractor +////////////////////////////////////////////////////////////////////////// +#include "PX_Object_Protractor.h" + +////////////////////////////////////////////////////////////////////////// +//transform adapter +#include "PX_Object_TransformAdapter.h" + +////////////////////////////////////////////////////////////////////////// +//panc +#include "PX_Object_Panc.h" + + +////////////////////////////////////////////////////////////////////////// +//designerbox +#include "PX_Object_DesignerBox.h" + +////////////////////////////////////////////////////////////////////////// +//joystick +#include "PX_Object_Joystick.h" + +////////////////////////////////////////////////////////////////////////// +//ringprocessbar +#include "PX_Object_RingProcessbar.h" + +////////////////////////////////////////////////////////////////////////// +//memoryview +#include "PX_Object_MemoryView.h" + +////////////////////////////////////////////////////////////////////////// +//various +#include "PX_Object_Various.h" + + +////////////////////////////////////////////////////////////////////////// +//ipbox +#include "PX_Object_IPBox.h" + +////////////////////////////////////////////////////////////////////////// +//varbox +#include "PX_Object_VarBox.h" + +////////////////////////////////////////////////////////////////////////// +//combox +#include "PX_Object_COMBox.h" + +#endif + + diff --git a/lib/PainterEngine/kernel/PX_Object_Animation.c b/lib/PainterEngine/kernel/PX_Object_Animation.c new file mode 100644 index 0000000000000000000000000000000000000000..f444c06fcfa7bea2028efa86de2434b3076e837e --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_Animation.c @@ -0,0 +1,130 @@ +#include "PX_Object_Animation.h" + +PX_Object * PX_Object_AnimationCreate(px_memorypool *mp,PX_Object *Parent,px_int x,px_int y,PX_AnimationLibrary *lib) +{ + PX_Object *pObject; + PX_Object_Animation *pAnimation=(PX_Object_Animation *)MP_Malloc(mp,sizeof(PX_Object_Animation)); + if (pAnimation==PX_NULL) + { + return PX_NULL; + } + pObject=PX_ObjectCreate(mp,Parent,(px_float)x,(px_float)y,0,0,0,0); + if (pObject==PX_NULL) + { + MP_Free(pObject->mp,pAnimation); + return PX_NULL; + } + + pObject->pObject=pAnimation; + pObject->Enabled=PX_TRUE; + pObject->Visible=PX_TRUE; + pObject->Type=PX_OBJECT_TYPE_ANIMATION; + pObject->ReceiveEvents=PX_FALSE; + pObject->Func_ObjectFree=PX_Object_AnimationFree; + pObject->Func_ObjectRender=PX_Object_AnimationRender; + PX_AnimationCreate(&pAnimation->animation,lib); + pAnimation->Align=PX_ALIGN_CENTER; + return pObject; +} + +px_void PX_Object_AnimationSetLibrary(PX_Object *Object,PX_AnimationLibrary *lib) +{ + PX_Object_Animation *pA=PX_Object_GetAnimation(Object); + if (pA) + { + PX_AnimationSetLibrary(&pA->animation,lib); + } +} + +PX_Object_Animation * PX_Object_GetAnimation(PX_Object *Object) +{ + if(Object->Type==PX_OBJECT_TYPE_ANIMATION) + return (PX_Object_Animation *)Object->pObject; + else + return PX_NULL; +} + +px_void PX_Object_AnimationSetAlign(PX_Object *panimation,PX_ALIGN Align) +{ + PX_Object_Animation *pA=PX_Object_GetAnimation(panimation); + if (pA) + { + pA->Align=Align; + } +} + +px_void PX_Object_AnimationRender(px_surface *psurface,PX_Object *pObject,px_uint elapsed) +{ + PX_Object_Animation *pA=PX_Object_GetAnimation(pObject); + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + if (pA) + { + PX_AnimationUpdate(&pA->animation,elapsed); + + switch(pA->Align) + { + case PX_ALIGN_LEFTTOP: + { + PX_AnimationRender(psurface,&pA->animation,(px_int)objx,(px_int)objy,PX_ALIGN_LEFTTOP,PX_NULL); + } + break; + case PX_ALIGN_LEFTMID: + { + PX_AnimationRender(psurface,&pA->animation,(px_int)objx,(px_int)(objy+objHeight/2),PX_ALIGN_LEFTMID,PX_NULL); + } + break; + case PX_ALIGN_LEFTBOTTOM: + { + PX_AnimationRender(psurface,&pA->animation,(px_int)objx,(px_int)(objy+objHeight),PX_ALIGN_LEFTBOTTOM,PX_NULL); + } + break; + case PX_ALIGN_MIDTOP: + { + PX_AnimationRender(psurface,&pA->animation,(px_int)(objx+objWidth/2),(px_int)(objy),PX_ALIGN_MIDTOP,PX_NULL); + } + break; + case PX_ALIGN_CENTER: + { + PX_AnimationRender(psurface,&pA->animation,(px_int)(objx+objWidth/2),(px_int)(objy+objHeight/2),PX_ALIGN_CENTER,PX_NULL); + } + break; + case PX_ALIGN_MIDBOTTOM: + { + PX_AnimationRender(psurface,&pA->animation,(px_int)(objx+objWidth/2),(px_int)(objy+objHeight),PX_ALIGN_MIDBOTTOM,PX_NULL); + } + break; + case PX_ALIGN_RIGHTTOP: + { + PX_AnimationRender(psurface,&pA->animation,(px_int)(objx+objWidth),(px_int)(objy),PX_ALIGN_RIGHTTOP,PX_NULL); + } + break; + case PX_ALIGN_RIGHTMID: + { + PX_AnimationRender(psurface,&pA->animation,(px_int)(objx+objWidth),(px_int)(objy+objHeight/2),PX_ALIGN_RIGHTMID,PX_NULL); + } + break; + case PX_ALIGN_RIGHTBOTTOM: + { + PX_AnimationRender(psurface,&pA->animation,(px_int)(objx+objWidth),(px_int)(objy+objHeight),PX_ALIGN_RIGHTBOTTOM,PX_NULL); + } + break; + } + } + +} + +px_void PX_Object_AnimationFree(PX_Object *pObj) +{ + PX_Object_Animation *pA=PX_Object_GetAnimation(pObj); + if (pA) + PX_AnimationFree(&pA->animation); +} diff --git a/lib/PainterEngine/kernel/PX_Object_Animation.h b/lib/PainterEngine/kernel/PX_Object_Animation.h new file mode 100644 index 0000000000000000000000000000000000000000..efe2fb76e6fdcdb6cee6288a837563e5dc071948 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_Animation.h @@ -0,0 +1,15 @@ +#ifndef PX_OBJECT_ANIMATION_H +#define PX_OBJECT_ANIMATION_H +#include "PX_Object.h" + + +PX_Object *PX_Object_AnimationCreate(px_memorypool *mp,PX_Object *Parent,px_int x,px_int y,PX_AnimationLibrary *lib); +px_void PX_Object_AnimationSetLibrary(PX_Object *Object,PX_AnimationLibrary *lib); +PX_Object_Animation *PX_Object_GetAnimation(PX_Object *Object); +px_void PX_Object_AnimationSetAlign(PX_Object *pObject,PX_ALIGN Align); +px_void PX_Object_AnimationRender(px_surface *psurface,PX_Object *pImage,px_uint elapsed); +px_void PX_Object_AnimationFree(PX_Object *pObject); + + +#endif + diff --git a/lib/PainterEngine/kernel/PX_Object_AutoText.c b/lib/PainterEngine/kernel/PX_Object_AutoText.c new file mode 100644 index 0000000000000000000000000000000000000000..6812c2a6e02619b465f34319f03613dd9d910a8d --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_AutoText.c @@ -0,0 +1,231 @@ +#include "PX_Object_AutoText.h" + +PX_Object * PX_Object_AutoTextCreate(px_memorypool *mp,PX_Object *Parent,px_int x,px_int y,px_int width,PX_FontModule *fm) +{ + PX_Object *pObject; + + PX_Object_AutoText *pAt=(PX_Object_AutoText *)MP_Malloc(mp,sizeof(PX_Object_AutoText)); + PX_StringInitialize(mp,&pAt->text); + if (pAt==PX_NULL) + { + return PX_NULL; + } + + if (width<=0) + { + return PX_NULL; + } + + + pObject=PX_ObjectCreate(mp,Parent,(px_float)x,(px_float)y,0,(px_float)width,0,0); + + if (pObject==PX_NULL) + { + return PX_NULL; + } + + if (!pObject) + { + MP_Free(mp,pAt); + return PX_NULL; + } + + pObject->pObject=pAt; + pObject->Type=PX_OBJECT_TYPE_AUTOTEXT; + pObject->ReceiveEvents=PX_TRUE; + pObject->Func_ObjectFree=PX_Object_AutoTextFree; + pObject->Func_ObjectRender=PX_Object_AutoTextRender; + + pAt->TextColor=PX_OBJECT_UI_DEFAULT_FONTCOLOR; + pAt->fontModule=fm; + return pObject; +} + +px_void PX_Object_AutoTextRender(px_surface *psurface, PX_Object *pObject,px_uint elapsed) +{ + px_int x_draw_oft,y_draw_oft,cursor,fsize; + PX_Object_AutoText *pAt=(PX_Object_AutoText *)pObject->pObject; + const px_char *Text=pAt->text.buffer; + px_float objx,objy,objHeight,objWidth; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + if (pAt==PX_NULL) + { + return; + } + + if (!pObject->Visible) + { + return; + } + + x_draw_oft=(px_int)objx; + y_draw_oft=(px_int)objy; + + cursor=0; + + while (PX_TRUE) + { + fsize=0; + + if (pAt->fontModule) + { + px_dword code; + px_int width,height; + fsize=PX_FontModuleGetCharacterDesc(pAt->fontModule,Text+cursor,&code,&width,&height); + if (!fsize) + { + break; + } + if (code=='\r') + { + //skip + }else if (code=='\n') + { + x_draw_oft=(px_int)objx; + y_draw_oft+=pAt->fontModule->max_Height; + } + else + { + PX_FontModuleDrawCharacter(psurface,pAt->fontModule,x_draw_oft,y_draw_oft,code,pAt->TextColor); + x_draw_oft+=width; + } + + if (x_draw_oft>objx+objWidth-PX_FontGetAscCharactorWidth()*2) + { + x_draw_oft=(px_int)objx; + y_draw_oft+=pAt->fontModule->max_Height; + } + + } + else + { + fsize=1; + + if (Text[cursor]=='\r') + { + //skip + }else if (Text[cursor]=='\n') + { + x_draw_oft=(px_int)objx; + y_draw_oft+=__PX_FONT_HEIGHT; + } + else if(Text[cursor]) + { + PX_FontDrawChar(psurface,x_draw_oft,y_draw_oft,Text[cursor],pAt->TextColor); + x_draw_oft+=__PX_FONT_ASCSIZE; + } + else + { + break; + } + + if (x_draw_oft>objx+objWidth-PX_FontGetAscCharactorWidth()*2) + { + x_draw_oft=(px_int)objx; + y_draw_oft+=__PX_FONT_HEIGHT; + } + } + cursor+=fsize; + } +} + +px_void PX_Object_AutoTextFree(PX_Object *Obj) +{ + PX_Object_AutoText * pAt=PX_Object_GetAutoText(Obj); + if (!pAt) + { + return; + } + PX_StringFree(&pAt->text); +} + +px_int PX_Object_AutoTextGetHeight(PX_Object *pObject) +{ + px_int i; + px_int w=0; + px_int h=0; + PX_Object_AutoText * pAt=PX_Object_GetAutoText(pObject); + + if (!pAt) + { + return 0; + } + + for (i=0;itext.buffer);i++) + { + if (pAt->text.buffer[i]=='\n') + { + w=0; + h+=PX_FontGetCharactorHeight(); + continue; + } + if (pAt->text.buffer[i]=='\r') + { + continue; + } + + if (pAt->text.buffer[i]=='\t') + { + w+=PX_FontGetAscCharactorWidth(); + continue; + } + + if (pAt->text.buffer[i]&0x80) + { + i++; + } + else + { + if(w+PX_FontGetAscCharactorWidth()>pObject->Width-PX_FontGetAscCharactorWidth()*2) + { + w=0; + h+=PX_FontGetCharactorHeight(); + w+=PX_FontGetAscCharactorWidth(); + } + else + { + w+=PX_FontGetAscCharactorWidth(); + } + } + } + return h+PX_FontGetCharactorHeight(); +} + +PX_Object_AutoText * PX_Object_GetAutoText(PX_Object *Object) +{ + if(Object->Type==PX_OBJECT_TYPE_AUTOTEXT) + return (PX_Object_AutoText *)Object->pObject; + else + return PX_NULL; +} + +px_void PX_Object_AutoTextSetTextColor(PX_Object *pObject,px_color Color) +{ + PX_Object_AutoText * pAt=PX_Object_GetAutoText(pObject); + if (!pAt) + { + return; + } + pAt->TextColor=Color; +} + +px_void PX_Object_AutoTextSetText(PX_Object *Obj,const px_char *Text) +{ + PX_Object_AutoText * pAt=PX_Object_GetAutoText(Obj); + if (!pAt) + { + return; + } + PX_StringClear(&pAt->text); + PX_StringCat(&pAt->text,Text); + Obj->Height=(px_float)PX_Object_AutoTextGetHeight(Obj); +} + diff --git a/lib/PainterEngine/kernel/PX_Object_AutoText.h b/lib/PainterEngine/kernel/PX_Object_AutoText.h new file mode 100644 index 0000000000000000000000000000000000000000..db22a8f6f647caeee4e92b4a10d44c4f63b6c5a0 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_AutoText.h @@ -0,0 +1,23 @@ +#ifndef PX_OBJECT_AUTOTEXT_H +#define PX_OBJECT_AUTOTEXT_H +#include "PX_Object.h" + +typedef struct +{ + px_color TextColor; + PX_FontModule *fontModule; + px_string text; +}PX_Object_AutoText; + + +PX_Object *PX_Object_AutoTextCreate(px_memorypool *mp,PX_Object *Parent,int x,int y,int limit_width,PX_FontModule *fm); +PX_Object_AutoText * PX_Object_GetAutoText( PX_Object *Object ); +px_void PX_Object_AutoTextSetTextColor( PX_Object *pObject,px_color Color ); +px_void PX_Object_AutoTextSetText(PX_Object *Obj,const px_char *Text); +px_void PX_Object_AutoTextRender(px_surface *psurface, PX_Object *pObject,px_uint elapsed); +px_void PX_Object_AutoTextFree(PX_Object *Obj); +px_int PX_Object_AutoTextGetHeight(PX_Object *Obj); + + +#endif + diff --git a/lib/PainterEngine/kernel/PX_Object_COMBox.c b/lib/PainterEngine/kernel/PX_Object_COMBox.c new file mode 100644 index 0000000000000000000000000000000000000000..9abca2c51976a7fbf9de1a6e6956724da9e271ea --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_COMBox.c @@ -0,0 +1,202 @@ +#include "PX_Object_COMBox.h" + + +PX_Object_COMBox_Return PX_Object_COMBoxGetReturn(PX_Object *pObject) +{ + PX_Object_COMBox_Return info; + PX_Object_COMBox* pDesc; + + if (pObject->Type!=PX_OBJECT_TYPE_COMBOX) + { + PX_ASSERT(); + PX_zeromemory(&info, sizeof(info)); + return info; + } + pDesc = PX_ObjectGetDesc(PX_Object_COMBox, pObject); + PX_strcpy(info.com, PX_Object_VariousGetText(pDesc->various_com),sizeof(info.com)); + switch (PX_Object_VariousSelectBarGetCurrentIndex(pDesc->various_baudrate)) + { + case 0: + info.baudRate=300; + break; + case 1: + info.baudRate=600; + break; + case 2: + info.baudRate=1200; + break; + case 3: + info.baudRate=2400; + break; + case 4: + info.baudRate=4800; + break; + case 5: + info.baudRate=9600; + break; + case 6: + info.baudRate=19200; + break; + case 7: + info.baudRate=38400; + break; + case 8: + info.baudRate=56000; + break; + case 9: + info.baudRate=57600; + break; + case 10: + info.baudRate=115200; + break; + default: + info.baudRate=128000; + break; + } + + switch(PX_Object_SelectBarGetCurrentIndex(pDesc->various_databits)) + { + case 0: + info.DataBits=5; + break; + case 1: + info.DataBits=6; + break; + case 2: + info.DataBits=7; + break; + case 3: + info.DataBits=8; + break; + default: + info.DataBits=8; + break; + } + + switch(PX_Object_SelectBarGetCurrentIndex(pDesc->various_stopbits)) + { + case 0: + info.stopBit=1; + break; + case 1: + info.stopBit=1; + break; + case 2: + info.stopBit=2; + break; + default: + info.stopBit=1; + break; + } + + switch(PX_Object_SelectBarGetCurrentIndex(pDesc->various_parity)) + { + case 0: + info.ParityType='N'; + break; + case 1: + info.ParityType='E'; + break; + case 2: + info.ParityType='O'; + break; + case 3: + info.ParityType='M'; + break; + default: + info.ParityType='N'; + break; + } + return info; +} + +px_void PX_Object_COMBoxOnConfirm(PX_Object* pObject, PX_Object_Event e, px_void* ptr) +{ + PX_Object_COMBox* pdesc = PX_ObjectGetDesc(PX_Object_COMBox, ((PX_Object*)ptr)); + + PX_ObjectExecuteEvent(((PX_Object*)ptr), PX_OBJECT_BUILD_EVENT(PX_OBJECT_EVENT_EXECUTE)); + PX_Object_COMBoxClose((PX_Object*)ptr); +} + + +px_void PX_Object_COMBoxOnCancel(PX_Object* pObject, PX_Object_Event e, px_void* ptr) +{ + PX_Object_COMBoxClose((PX_Object*)ptr); +} + + + + +PX_Object_COMBox* PX_Object_GetCOMBox(PX_Object* pObject) +{ + if (pObject->Type==PX_OBJECT_TYPE_COMBOX) + { + return PX_ObjectGetDesc(PX_Object_COMBox, pObject); + } + return PX_NULL; +} + +PX_Object* PX_Object_COMBoxCreate(px_memorypool* mp, PX_Object* Parent, int x, int y, int width, int height, const px_char title[], PX_FontModule* fontmodule) +{ + PX_Object_COMBox desc, * pdesc; + PX_Object* pObject; + pObject = PX_ObjectCreateEx(mp, Parent, (px_float)x, (px_float)y, 0, (px_float)width, (px_float)height, 0, PX_OBJECT_TYPE_COMBOX, PX_NULL, PX_NULL, PX_NULL, &desc, sizeof(desc)); + pdesc = PX_ObjectGetDesc(PX_Object_COMBox, pObject); + + pdesc->widget = PX_Object_WidgetCreate(mp, pObject, 0, 0, width, height, "", fontmodule); + PX_Object_WidgetShowHideCloseButton(pdesc->widget, PX_FALSE); + + pdesc->various_com = PX_Object_VariousCreate(mp, pdesc->widget, width / 2 - 128, 32, 256, 32, "COM:", PX_OBJECT_VARIOUS_TYPE_SELECTBAR, fontmodule); + pdesc->various_baudrate = PX_Object_VariousCreate(mp, pdesc->widget, width / 2 - 128, 72, 256, 32, "BaudRate:", PX_OBJECT_VARIOUS_TYPE_SELECTBAR, fontmodule); + PX_Object_VariousAddItem(pdesc->various_baudrate, "300"); + PX_Object_VariousAddItem(pdesc->various_baudrate, "600"); + PX_Object_VariousAddItem(pdesc->various_baudrate, "1200"); + PX_Object_VariousAddItem(pdesc->various_baudrate, "2400"); + PX_Object_VariousAddItem(pdesc->various_baudrate, "4800"); + PX_Object_VariousAddItem(pdesc->various_baudrate, "9600"); + PX_Object_VariousAddItem(pdesc->various_baudrate, "19200"); + PX_Object_VariousAddItem(pdesc->various_baudrate, "38400"); + PX_Object_VariousAddItem(pdesc->various_baudrate, "56000"); + PX_Object_VariousAddItem(pdesc->various_baudrate, "57600"); + PX_Object_VariousAddItem(pdesc->various_baudrate, "115200"); + + pdesc->various_databits = PX_Object_VariousCreate(mp, pdesc->widget, width / 2 - 128, 112, 256, 32, "DataBits:", PX_OBJECT_VARIOUS_TYPE_SELECTBAR, fontmodule); + PX_Object_VariousAddItem(pdesc->various_databits, "5"); + PX_Object_VariousAddItem(pdesc->various_databits, "6"); + PX_Object_VariousAddItem(pdesc->various_databits, "7"); + PX_Object_VariousAddItem(pdesc->various_databits, "8"); + + + pdesc->various_stopbits = PX_Object_VariousCreate(mp, pdesc->widget, width / 2 - 128, 152, 256, 32, "StopBits:", PX_OBJECT_VARIOUS_TYPE_SELECTBAR, fontmodule); + PX_Object_VariousAddItem(pdesc->various_stopbits, "0"); + PX_Object_VariousAddItem(pdesc->various_stopbits, "1"); + PX_Object_VariousAddItem(pdesc->various_stopbits, "2"); + + pdesc->various_parity = PX_Object_VariousCreate(mp, pdesc->widget, width / 2 - 128, 192, 256, 32, "Parity:", PX_OBJECT_VARIOUS_TYPE_SELECTBAR, fontmodule); + PX_Object_VariousAddItem(pdesc->various_parity, "N"); + PX_Object_VariousAddItem(pdesc->various_parity, "E"); + PX_Object_VariousAddItem(pdesc->various_parity, "O"); + PX_Object_VariousAddItem(pdesc->various_parity, "M"); + + pdesc->btn_ok = PX_Object_PushButtonCreate(mp, pdesc->widget, width - 256, height - 68, 96, 32, "OK", fontmodule); + pdesc->btn_close = PX_Object_PushButtonCreate(mp, pdesc->widget, width - 128, height - 68, 96, 32, "Cancel", fontmodule); + + PX_ObjectRegisterEvent(pdesc->btn_ok, PX_OBJECT_EVENT_EXECUTE, PX_Object_COMBoxOnConfirm, pObject); + PX_ObjectRegisterEvent(pdesc->btn_close, PX_OBJECT_EVENT_EXECUTE, PX_Object_COMBoxOnCancel, pObject); + + pdesc->widget->Visible = PX_TRUE; + pObject->Visible = PX_FALSE; + return pObject; +} + +px_void PX_Object_COMBoxShow(PX_Object* pObject) +{ + pObject->Visible = PX_TRUE; + PX_ObjectSetFocus(pObject); +} + +px_void PX_Object_COMBoxClose(PX_Object* pObject) +{ + pObject->Visible = PX_FALSE; + PX_ObjectClearFocus(pObject); +} diff --git a/lib/PainterEngine/kernel/PX_Object_COMBox.h b/lib/PainterEngine/kernel/PX_Object_COMBox.h new file mode 100644 index 0000000000000000000000000000000000000000..8a21c6accb12a8277988aac3c85ca79f78521a78 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_COMBox.h @@ -0,0 +1,29 @@ +#ifndef PX_MODULE_SERIALPORT_H +#define PX_MODULE_SERIALPORT_H + +#include "PX_Object.h" + +#define PX_INSTANCE_SERIALPORTCONFIGURARION_NEXT 0x1000 + +typedef struct +{ + px_char com[16]; + px_uint baudRate; + px_uint DataBits;/*5,6,7,8*/ + px_char ParityType;/*'O','E','N'*/ + px_int stopBit;/*0,1,2*/ +}PX_Object_COMBox_Return; + +typedef struct +{ + PX_Object *widget; + PX_FontModule *fm; + PX_Object *various_com,* various_baudrate,* various_databits,* various_stopbits,* various_parity; + PX_Object *btn_ok,*btn_close; +}PX_Object_COMBox; + +PX_Object_COMBox* PX_Object_GetCOMBox(PX_Object* Object); +PX_Object* PX_Object_COMBoxCreate(px_memorypool* mp, PX_Object* Parent, int x, int y, int width, int height, const px_char title[], PX_FontModule* fontmodule); +px_void PX_Object_COMBoxShow(PX_Object* pObject); +px_void PX_Object_COMBoxClose(PX_Object* pObject); +#endif \ No newline at end of file diff --git a/lib/PainterEngine/kernel/PX_Object_CheckBox.c b/lib/PainterEngine/kernel/PX_Object_CheckBox.c new file mode 100644 index 0000000000000000000000000000000000000000..f04f08333fc3252833ef31f592ab3ac79c6b9d57 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_CheckBox.c @@ -0,0 +1,245 @@ +#include "PX_Object_CheckBox.h" + +PX_Object_CheckBox * PX_Object_GetCheckBox(PX_Object *Object) +{ + PX_Object_CheckBox *pcb=(PX_Object_CheckBox *)Object->pObject; + if (Object->Type==PX_OBJECT_TYPE_CHECKBOX) + { + return pcb; + } + return PX_NULL; +} + +px_void PX_Object_CheckBoxOnMouseMove(PX_Object *Object,PX_Object_Event e,px_void *user_ptr) +{ + PX_Object_CheckBox *pcb=PX_Object_GetCheckBox(Object); + + px_float x=(PX_Object_Event_GetCursorX(e)); + px_float y=(PX_Object_Event_GetCursorY(e)); + + if (pcb) + { + if(PX_ObjectIsPointInRegion(Object,(px_float)x,(px_float)y)) + { + if (pcb->state!=PX_OBJECT_BUTTON_STATE_ONPUSH) + { + if (pcb->state!=PX_OBJECT_BUTTON_STATE_ONCURSOR) + { + PX_Object_Event e; + e.Event=PX_OBJECT_EVENT_CURSOROVER; + e.Param_uint[0]=0; + e.Param_uint[1]=0; + e.Param_uint[2]=0; + e.Param_uint[3]=0; + e.Param_ptr[0]=PX_NULL; + PX_ObjectExecuteEvent(Object,e); + } + pcb->state=PX_OBJECT_CHECKBOX_STATE_ONCURSOR; + } + } + else + { + if (pcb->state!=PX_OBJECT_BUTTON_STATE_NORMAL) + { + PX_Object_Event e; + e.Event=PX_OBJECT_EVENT_CURSOROUT; + e.Param_uint[0]=0; + e.Param_uint[1]=0; + e.Param_uint[2]=0; + e.Param_uint[3]=0; + PX_ObjectExecuteEvent(Object,e); + } + pcb->state=PX_OBJECT_CHECKBOX_STATE_NORMAL; + } + } +} + +px_void PX_Object_CheckBoxOnMouseLButtonDown(PX_Object *Object,PX_Object_Event e,px_void *user_ptr) +{ + PX_Object_CheckBox *pcb=PX_Object_GetCheckBox(Object); + px_float x=(PX_Object_Event_GetCursorX(e)); + px_float y=(PX_Object_Event_GetCursorY(e)); + + if (pcb) + { + if(PX_ObjectIsPointInRegion(Object,(px_float)x,(px_float)y)) + pcb->state=PX_OBJECT_CHECKBOX_STATE_ONPUSH; + else + { + if (pcb->state!=PX_OBJECT_BUTTON_STATE_NORMAL) + { + PX_Object_Event e; + e.Event=PX_OBJECT_EVENT_CURSOROUT; + e.Param_uint[0]=0; + e.Param_uint[1]=0; + e.Param_uint[2]=0; + e.Param_uint[3]=0; + PX_ObjectExecuteEvent(Object,e); + } + pcb->state=PX_OBJECT_CHECKBOX_STATE_NORMAL; + } + } +} + +px_void PX_Object_CheckBoxOnMouseLButtonUp(PX_Object *Object,PX_Object_Event e,px_void *user_ptr) +{ + PX_Object_CheckBox *pcb=PX_Object_GetCheckBox(Object); + + px_float x,y; + + x=PX_Object_Event_GetCursorX(e); + y=PX_Object_Event_GetCursorY(e); + + if (pcb) + { + if(PX_ObjectIsPointInRegion(Object,(px_float)x,(px_float)y)) + if(pcb->state==PX_OBJECT_CHECKBOX_STATE_ONPUSH) + { + PX_Object_Event e; + pcb->state=PX_OBJECT_CHECKBOX_STATE_ONCURSOR; + pcb->bCheck=!pcb->bCheck; + + e.Event=PX_OBJECT_EVENT_VALUECHANGED; + e.Param_uint[0]=0; + e.Param_uint[1]=0; + e.Param_uint[2]=0; + e.Param_uint[3]=0; + PX_ObjectExecuteEvent(Object,e); + } + } +} + +px_void PX_Object_CheckBoxRender(px_surface *psurface, PX_Object *pObject,px_uint elapsed) +{ + PX_Object_CheckBox *pcb=PX_Object_GetCheckBox(pObject); + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + + if (pcb==PX_NULL) + { + return; + } + + if (!pObject->Visible) + { + return; + } + + PX_GeoDrawRect(psurface,(px_int)objx,(px_int)objy,(px_int)objx+(px_int)objWidth-1,(px_int)objy+(px_int)objHeight-1,pcb->BackgroundColor); + switch (pcb->state) + { + case PX_OBJECT_BUTTON_STATE_NORMAL: + PX_GeoDrawRect(psurface,(px_int)objx,(px_int)objy,(px_int)objx+(px_int)objWidth-1,(px_int)objy+(px_int)objHeight-1,pcb->BackgroundColor); + break; + case PX_OBJECT_BUTTON_STATE_ONPUSH: + PX_GeoDrawRect(psurface,(px_int)objx,(px_int)objy,(px_int)objx+(px_int)objWidth-1,(px_int)objy+(px_int)objHeight-1,pcb->PushColor); + break; + case PX_OBJECT_BUTTON_STATE_ONCURSOR: + PX_GeoDrawRect(psurface,(px_int)objx,(px_int)objy,(px_int)objx+(px_int)objWidth-1,(px_int)objy+(px_int)objHeight-1,pcb->CursorColor); + break; + } + + if (pcb->Border) + { + PX_GeoDrawBorder(psurface,(px_int)objx,(px_int)objy,(px_int)objx+(px_int)objWidth-1,(px_int)objy+(px_int)objHeight-1,1,pcb->BorderColor); + } + + PX_FontModuleDrawText(psurface,pcb->fm,(px_int)objx+18,(px_int)(objy+objHeight/2),PX_ALIGN_LEFTMID,pcb->Text,pcb->TextColor); + + //draw CheckState + PX_GeoDrawBorder(psurface,(px_int)objx,(px_int)(objy+objHeight/2-7),(px_int)objx+14,(px_int)(objy+objHeight/2+7),1,pcb->BorderColor); + if (pcb->bCheck) + { + PX_GeoDrawRect(psurface,(px_int)objx+2,(px_int)(objy+objHeight/2-5),(px_int)objx+12,(px_int)(objy+objHeight/2+5),pcb->BorderColor); + } + +} + +PX_Object * PX_Object_CheckBoxCreate(px_memorypool *mp, PX_Object *Parent,px_int x,px_int y,px_int Width,px_int Height,const char text[],PX_FontModule *fm) +{ + PX_Object *pObject; + PX_Object_CheckBox cbx; + cbx.Align=PX_ALIGN_LEFTMID; + cbx.BackgroundColor=PX_COLOR(0,0,0,0); + cbx.bCheck=PX_FALSE; + cbx.Border=PX_FALSE; + cbx.BorderColor=PX_OBJECT_UI_DEFAULT_FONTCOLOR; + cbx.CursorColor=PX_OBJECT_UI_DEFAULT_CURSORCOLOR; + cbx.PushColor=PX_OBJECT_UI_DEFAULT_PUSHCOLOR; + cbx.fm=fm; + cbx.state=PX_OBJECT_CHECKBOX_STATE_NORMAL; + PX_strset(cbx.Text,text); + cbx.TextColor=PX_OBJECT_UI_DEFAULT_FONTCOLOR; + pObject=PX_ObjectCreateEx(mp,Parent,(px_float)x,(px_float)y,0,(px_float)Width,(px_float)Height,0,PX_OBJECT_TYPE_CHECKBOX,PX_NULL,PX_Object_CheckBoxRender,PX_NULL,&cbx,sizeof(cbx)); + if (!pObject) + { + return PX_NULL; + } + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORMOVE,PX_Object_CheckBoxOnMouseMove,PX_NULL); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORDOWN,PX_Object_CheckBoxOnMouseLButtonDown,PX_NULL); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORUP,PX_Object_CheckBoxOnMouseLButtonUp,PX_NULL); + return pObject; +} + +px_bool PX_Object_CheckBoxGetCheck(PX_Object *Object) +{ + return PX_Object_GetCheckBox(Object)->bCheck; +} + +px_void PX_Object_CheckBoxSetBackgroundColor(PX_Object *Object,px_color clr) +{ + PX_Object_GetCheckBox(Object)->BackgroundColor=clr; +} + +px_void PX_Object_CheckBoxSetBorderColor(PX_Object *Object,px_color clr) +{ + PX_Object_GetCheckBox(Object)->BorderColor=clr; +} + +px_void PX_Object_CheckBoxSetPushColor(PX_Object *Object,px_color clr) +{ + PX_Object_GetCheckBox(Object)->PushColor=clr; +} + +px_void PX_Object_CheckBoxSetCursorColor(PX_Object *Object,px_color clr) +{ + PX_Object_GetCheckBox(Object)->CursorColor=clr; +} + +px_void PX_Object_CheckBoxSetText(PX_Object *Object,const px_char text[]) +{ + PX_strset(PX_Object_GetCheckBox(Object)->Text,text); +} + +px_char *PX_Object_CheckBoxGetText(PX_Object *Object) +{ + PX_Object_CheckBox *pCheckBox=PX_Object_GetCheckBox(Object); + if (pCheckBox) + { + return pCheckBox->Text; + } + else + { + PX_ASSERT(); + return PX_NULL; + } +} + +px_void PX_Object_CheckBoxSetTextColor(PX_Object *Object,px_color clr) +{ + PX_Object_GetCheckBox(Object)->TextColor=clr; +} + +px_void PX_Object_CheckBoxSetCheck(PX_Object *Object,px_bool check) +{ + PX_Object_GetCheckBox(Object)->bCheck=check; +} + diff --git a/lib/PainterEngine/kernel/PX_Object_CheckBox.h b/lib/PainterEngine/kernel/PX_Object_CheckBox.h new file mode 100644 index 0000000000000000000000000000000000000000..54eac5f14290c123cd4547ea69157e008470e679 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_CheckBox.h @@ -0,0 +1,48 @@ +#ifndef PX_OBJECT_CHECKBOX_H +#define PX_OBJECT_CHECKBOX_H +#include "PX_Object.h" + + +#define PX_OBJECT_CHECKBOX_MAX_CONTENT 64 + + +typedef enum +{ + PX_OBJECT_CHECKBOX_STATE_ONCURSOR, + PX_OBJECT_CHECKBOX_STATE_ONPUSH, + PX_OBJECT_CHECKBOX_STATE_NORMAL, +}PX_Object_CHECKBOX_STATE; + +typedef struct +{ + px_dword Align; + px_bool Border; + px_color TextColor; + px_color BorderColor; + px_color BackgroundColor; + px_color CursorColor; + px_color PushColor; + px_char Text[PX_OBJECT_CHECKBOX_MAX_CONTENT]; + px_bool bCheck; + PX_FontModule *fm; + PX_Object_CHECKBOX_STATE state; +}PX_Object_CheckBox; + +PX_Object_CheckBox *PX_Object_GetCheckBox(PX_Object *Object); +PX_Object * PX_Object_CheckBoxCreate(px_memorypool *mp, PX_Object *Parent,px_int x,px_int y,px_int Width,px_int Height,const char text[],PX_FontModule *fm); +px_bool PX_Object_CheckBoxGetCheck(PX_Object *Object); +px_void PX_Object_CheckBoxSetBackgroundColor(PX_Object *Object,px_color clr); +px_void PX_Object_CheckBoxSetBorderColor(PX_Object *Object,px_color clr); +px_void PX_Object_CheckBoxSetPushColor(PX_Object *Object,px_color clr); +px_void PX_Object_CheckBoxSetCursorColor(PX_Object *Object,px_color clr); +px_void PX_Object_CheckBoxSetText(PX_Object *Object,const px_char text[]); +px_char *PX_Object_CheckBoxGetText(PX_Object *Object); +px_void PX_Object_CheckBoxSetTextColor(PX_Object *Object,px_color clr); +px_void PX_Object_CheckBoxSetCheck(PX_Object *Object,px_bool check); + + + + + +#endif + diff --git a/lib/PainterEngine/kernel/PX_Object_Coordinate.c b/lib/PainterEngine/kernel/PX_Object_Coordinate.c new file mode 100644 index 0000000000000000000000000000000000000000..a9a73cc600608197e764fbc405fe7c6af013b983 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_Coordinate.c @@ -0,0 +1,2445 @@ +#include "PX_Object_Coordinate.h" + +////////////////////////////////////////////////////////////////////////// +// +static px_int PX_Object_CoordinatesDichotomy(px_double *p,px_int Size,px_double Mark) +{ + px_int Minx,Maxx; + px_int Index; + if (Mark<=p[0]) + { + return 0; + } + if (Mark>=p[Size-1]) + { + return Size-1; + } + + Minx=0; + Maxx=Size-1; + + + + while (Maxx-Minx>1) + { + Index=(Maxx+Minx)/2; + if (p[Index]>=Mark) + { + Maxx=Index; + } + else + { + Minx=Index; + } + } + + if (Index==Size-1) + { + return Minx; + } + + + if (Mark-p[Index]Type==PX_OBJECT_TYPE_COORDINATE) + { + return (PX_Object_Coordinates *)pObject->pObject; + } + return PX_NULL; +} + +px_void PX_Object_CoordinatesSetMinVerticalPixelDividing(PX_Object *pObj,px_int val) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObj); + if (!pcd) + { + PX_ASSERT(); + return; + } + pcd->MinVerticalPixelDividing=val; +} + +px_void PX_Object_CoordinatesSetMinHorizontalPixelDividing(PX_Object *pObj,px_int val) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObj); + if (!pcd) + { + PX_ASSERT(); + return; + } + pcd->MinHorizontalPixelDividing=val; +} + +px_void PX_Object_CoordinatesSetHorizontalDividing(PX_Object *pObj,px_int Count) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObj); + if (!pcd) + { + PX_ASSERT(); + return; + } + pcd->HorizontalDividing=Count; +} + +px_void PX_Object_CoordinatesSetLeftVerticalDividing(PX_Object *pObj,px_int Count) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObj); + if (!pcd) + { + PX_ASSERT(); + return; + } + pcd->LeftVerticalDividing=Count; +} + +px_void PX_Object_CoordinatesSetRightVerticalDividing(PX_Object *pObj,px_int Count) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObj); + if (!pcd) + { + PX_ASSERT(); + return; + } + pcd->RightVerticalDividing=Count; +} + + + +px_void PX_Object_CoordinatesSetStyle(PX_Object *pObj,PX_OBJECT_COORDINATES_LINEMODE mode) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObj); + if (!pcd) + { + PX_ASSERT(); + return; + } + pcd->LineMode=mode; +} + + + +px_void PX_Object_CoordinatesSetScaleEnabled(PX_Object *pObject,px_bool Enabled) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (!pcd) + { + PX_ASSERT(); + return; + } + pcd->ScaleEnabled=Enabled; +} + +px_void PX_Object_CoordinatesSetGuidesVisible(PX_Object *pObject,px_bool Visible) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (!pcd) + { + PX_ASSERT(); + return; + } + pcd->ShowGuides=Visible; +} + +px_void PX_Object_CoordinatesSetGuidesShowMode(PX_Object *pObject,PX_OBJECT_COORDINATES_GUIDESSHOWMODE mode) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (!pcd) + { + PX_ASSERT(); + return; + } + pcd->guidesShowMode=mode; +} + + +px_void PX_Object_CoordinatesShowHelpLine(PX_Object *pObject,px_bool show) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (!pcd) + { + PX_ASSERT(); + return; + } + pcd->ShowHelpLine=show; +} + +px_void PX_Object_CoordinatesSetDataLineWidth(PX_Object *pObject,px_float linewidth) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (!pcd) + { + PX_ASSERT(); + return; + } + pcd->DataLineWidth=linewidth; +} + +void PX_Object_CoordinatesSetDataShow(PX_Object *pObject,px_int index,px_bool show) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + PX_Object_CoordinateData *pData; + if (!pcd) + { + PX_ASSERT(); + return; + } + if (index>=pcd->vData.size) + { + return; + } + pData=PX_VECTORAT(PX_Object_CoordinateData,&pcd->vData,index); + pData->Visibled=show; +} + +px_void PX_Object_CoordinatesSetGuidesLineWidth(PX_Object *pObject,px_float linewidth) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (!pcd) + { + PX_ASSERT(); + return; + } + pcd->GuidesLineWidth=linewidth; +} + +px_void PX_Object_CoordinatesSetGuidesLineColor(PX_Object *pObject,px_color clr) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (!pcd) + { + PX_ASSERT(); + return; + } + pcd->helpLineColor=clr; +} + +px_void PX_Object_CoordinatesSetTitleFontSize(PX_Object *pObject,px_int size) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (!pcd) + { + PX_ASSERT(); + return; + } + pcd->FontSize=size; +} + +px_void PX_Object_CoordinatesSetTitleFontColor(PX_Object *pObject,px_color clr) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (!pcd) + { + PX_ASSERT(); + return; + } + pcd->FontColor=clr; +} + +px_void PX_Object_CoordinatesSetDashLineColor(PX_Object *pObject,px_color clr) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (!pcd) + { + PX_ASSERT(); + return; + } + pcd->DashColor=clr; +} + +px_void PX_Object_CoordinatesSetLeftTextShow(PX_Object *pObject,px_bool bshow) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (!pcd) + { + PX_ASSERT(); + return; + } + pcd->LeftTextShow=bshow; +} + +px_void PX_Object_CoordinatesSetRightTextShow(PX_Object *pObject,px_bool bshow) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (!pcd) + { + PX_ASSERT(); + return; + } + pcd->RightTextShow=bshow; +} + +px_void PX_Object_CoordinatesSetHorizontalTextShow(PX_Object *pObject,px_bool bshow) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (!pcd) + { + PX_ASSERT(); + return; + } + pcd->HorizontalTextShow=bshow; +} + +px_void PX_Object_CoordinatesSetFloatFlagFormatHorizontal(PX_Object *pObject,const char *fmt) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (!pcd) + { + PX_ASSERT(); + return; + } + pcd->FloatFlagFormat_H=fmt; +} + +px_void PX_Object_CoordinatesSetIntFlagFormatHorizontal(PX_Object *pObject,const char *fmt) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (!pcd) + { + PX_ASSERT(); + return; + } + pcd->IntFlagFormat_H=fmt; +} + +px_void PX_Object_CoordinatesSetFloatFlagFormatVerticalLeft(PX_Object *pObject,const char *fmt) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (!pcd) + { + PX_ASSERT(); + return; + } + pcd->FloatFlagFormat_L=fmt; +} + +px_void PX_Object_CoordinatesSetIntFlagFormatVerticalLeft(PX_Object *pObject,const char *fmt) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (!pcd) + { + PX_ASSERT(); + return; + } + pcd->IntFlagFormat_L=fmt; +} + +px_void PX_Object_CoordinatesSetFloatFlagFormatVerticalRight(PX_Object *pObject,const char *fmt) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (!pcd) + { + PX_ASSERT(); + return; + } + pcd->FloatFlagFormat_R=fmt; +} + +px_void PX_Object_CoordinatesSetIntFlagFormatVericalRight(PX_Object *pObject,const char *fmt) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (!pcd) + { + PX_ASSERT(); + return; + } + pcd->IntFlagFormat_R=fmt; +} + +px_void PX_Object_CoordinatesSetLeftTextMode(PX_Object *pObject,PX_OBJECT_COORDINATES_TEXT_DISPLAYMODE mode) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (!pcd) + { + PX_ASSERT(); + return; + } + pcd->leftTextDisplayMode=mode; +} + +px_void PX_Object_CoordinatesSetRightTextMode(PX_Object *pObject,PX_OBJECT_COORDINATES_TEXT_DISPLAYMODE mode) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (!pcd) + { + PX_ASSERT(); + return; + } + pcd->RightTextDisplayMode=mode; +} + +px_void PX_Object_CoordinatesSetHorizontalMin(PX_Object *pObject,px_double Min) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (!pcd) + { + PX_ASSERT(); + return; + } + pcd->HorizontalRangeMin=Min; +} + +px_void PX_Object_CoordinatesSetHorizontalMax(PX_Object *pObject,px_double Max) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (!pcd) + { + PX_ASSERT(); + return; + } + pcd->HorizontalRangeMax=Max; +} + +px_void PX_Object_CoordinatesSetLeftVerticalMin(PX_Object *pObject,px_double Min) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (!pcd) + { + PX_ASSERT(); + return; + } + pcd->LeftVerticalRangeMin=Min; +} + +px_void PX_Object_CoordinatesSetLeftVerticalMax(PX_Object *pObject,px_double Max) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (!pcd) + { + PX_ASSERT(); + return; + } + pcd->LeftVerticalRangeMax=Max; +} + +px_void PX_Object_CoordinatesSetRightVerticalMax(PX_Object *pObject,px_double Max) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (!pcd) + { + PX_ASSERT(); + return; + } + pcd->RightVerticalRangeMax=Max; +} + +px_void PX_Object_CoordinatesSetRightVerticalMin(PX_Object *pObject,px_double Min) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (!pcd) + { + PX_ASSERT(); + return; + } + pcd->RightVerticalRangeMin=Min; +} + +px_void PX_Object_CoordinatesSetBorderColor(PX_Object *pObject,px_color clr) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (pcd) + { + pcd->borderColor=clr; + } +} + +PX_Object_CoordinateData * PX_Object_CoordinatesGetCoordinateData(PX_Object *pObject,px_int index) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (index>pcd->vData.size-1) + { + return PX_NULL; + } + return PX_VECTORAT(PX_Object_CoordinateData,&pcd->vData,index); +} + +px_int PX_Object_CoordinatesGetCoordinateWidth(PX_Object *pObject) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + + return (px_int)(pObject->Width-pcd->LeftSpacer-pcd->RightSpacer); +} + +px_int PX_Object_CoordinatesGetCoordinateHeight(PX_Object *pObject) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + + return (px_int)(pObject->Height-pcd->TopSpacer-pcd->BottomSpacer); +} + +void PX_Object_CoordinatesSetTitleTop(PX_Object *pObject,const px_char * title) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (pcd) + { + pcd->TopTitle=title; + } +} + +void PX_Object_CoordinatesSetTitleBottom(PX_Object *pObject,const px_char * title) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (pcd) + { + pcd->BottomTitle=title; + } +} + +void PX_Object_CoordinatesSetMarkValueEnabled(PX_Object *pObject,px_bool Enabled) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + pcd->MarkValueEnabled=Enabled; +} + +void PX_Object_CoordinatesSetFontColor(PX_Object *pObject,px_color clr) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (pcd) + { + pcd->FontColor=clr; + } +} + +void PX_Object_CoordinatesClearContext(PX_Object *pObject) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + PX_Object_CoordinatesRestoreCoordinates(pObject); + PX_VectorClear(&pcd->vData); +} + +void PX_Object_CoordinatesClearFlagLine(PX_Object *pObject) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + PX_VectorClear(&pcd->vFlagLine); +} + +void PX_Object_CoordinatesAddData(PX_Object *pObject,PX_Object_CoordinateData data) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + PX_VectorPushback(&pcd->vData,&data); +} + +void PX_Object_CoordinatesAddCoordinateFlagLine(PX_Object *pObject,PX_Object_CoordinateFlagLine Line) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + PX_VectorPushback(&pcd->vFlagLine,&Line); +} + + +px_void PX_Object_CoordinatesSetMargin(PX_Object *pObject,px_int Left,px_int Right,px_int Top,px_int Bottom) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + pcd->LeftSpacer=Left; + pcd->RightSpacer=Right; + pcd->TopSpacer=Top; + pcd->BottomSpacer=Bottom; +} + +px_int PX_Object_CoordinatesMapHorizontalValueToPixel(PX_Object *pObject,px_double val) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + px_double scale=PX_Object_CoordinatesGetCoordinateWidth(pObject)/(pcd->HorizontalRangeMax-pcd->HorizontalRangeMin); + return (px_int)((val-pcd->HorizontalRangeMin)*scale)+pcd->LeftSpacer; +} + +px_int PX_Object_CoordinatesMapVerticalValueToPixel(PX_Object *pObject,px_double val,px_int Map) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + px_double scale; + + if(Map==PX_OBJECT_COORDINATEDATA_MAP_LEFT) + { + scale=PX_Object_CoordinatesGetCoordinateHeight(pObject)/(pcd->LeftVerticalRangeMax-pcd->LeftVerticalRangeMin); + return (px_int)(pObject->Height-pcd->BottomSpacer-(px_int)((val-pcd->LeftVerticalRangeMin)*scale)); + } + else if(Map==PX_OBJECT_COORDINATEDATA_MAP_RIGHT) + { + scale=PX_Object_CoordinatesGetCoordinateHeight(pObject)/(pcd->RightVerticalRangeMax-pcd->RightVerticalRangeMin); + return (px_int)(pObject->Height-pcd->BottomSpacer-(px_int)((val-pcd->RightVerticalRangeMin)*scale)); + } + + return 0; + +} + +px_double PX_Object_CoordinatesMapPixelValueToHorizontal(PX_Object *pObject,px_int Pixel) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + px_int XDisten=Pixel-pcd->LeftSpacer; + return pcd->HorizontalRangeMin+XDisten*(pcd->HorizontalRangeMax-pcd->HorizontalRangeMin)/PX_Object_CoordinatesGetCoordinateWidth(pObject); + +} + +px_double PX_Object_CoordinatesMapPixelValueToVertical(PX_Object *pObject,px_int Pixel,px_int Map) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + px_double Min,Max; + if (Map==PX_OBJECT_COORDINATEDATA_MAP_LEFT) + { + Max=pcd->LeftVerticalRangeMax; + Min=pcd->LeftVerticalRangeMin; + return pcd->LeftVerticalRangeMin+(pObject->Height-pcd->BottomSpacer-Pixel)*(Max-Min)/PX_Object_CoordinatesGetCoordinateHeight(pObject); + } + + if (Map==PX_OBJECT_COORDINATEDATA_MAP_RIGHT) + { + Max=pcd->RightVerticalRangeMax; + Min=pcd->RightVerticalRangeMin; + return pcd->RightVerticalRangeMin+(pObject->Height-pcd->BottomSpacer-Pixel)*(Max-Min)/PX_Object_CoordinatesGetCoordinateHeight(pObject); + } + + if (Map==PX_OBJECT_COORDINATEDATA_MAP_HORIZONTAL) + { + Max=pcd->HorizontalRangeMax; + Min=pcd->HorizontalRangeMin; + return pcd->HorizontalRangeMin+(Pixel-pcd->LeftSpacer)*(Max-Min)/PX_Object_CoordinatesGetCoordinateWidth(pObject); + } + return 0; +} + + +px_void PX_Object_CoordinatesUpdate(PX_Object *pObject,px_uint elapsed) +{ + +} + + +static px_void PX_Object_CoordinatesDrawFrameLine(px_surface *psurface,PX_Object *pObject) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + px_int offsetx; + px_int offsety; + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + offsetx=(px_int)objx; + offsety=(px_int)objy; + + PX_GeoDrawLine(psurface,offsetx+pcd->LeftSpacer,offsety+pcd->TopSpacer,offsetx+(px_int)(objWidth-pcd->RightSpacer),offsety+pcd->TopSpacer,PX_OBJECT_COORDINATES_DEFAULT_FRAMELINE_WIDTH,pcd->borderColor); + PX_GeoDrawLine(psurface,offsetx+pcd->LeftSpacer,offsety+pcd->TopSpacer,offsetx+pcd->LeftSpacer,offsety+(px_int)(objHeight-pcd->BottomSpacer),PX_OBJECT_COORDINATES_DEFAULT_FRAMELINE_WIDTH,pcd->borderColor); + PX_GeoDrawLine(psurface,(px_int)(offsetx+objWidth-pcd->RightSpacer),offsety+(px_int)(objHeight-pcd->BottomSpacer),offsetx+(pcd->LeftSpacer),offsety+(px_int)objHeight-pcd->BottomSpacer,PX_OBJECT_COORDINATES_DEFAULT_FRAMELINE_WIDTH,pcd->borderColor); + PX_GeoDrawLine(psurface,(px_int)(offsetx+objWidth-pcd->RightSpacer),offsety+(px_int)(objHeight-pcd->BottomSpacer),offsetx+(px_int)(objWidth-pcd->RightSpacer),offsety+pcd->TopSpacer,PX_OBJECT_COORDINATES_DEFAULT_FRAMELINE_WIDTH,pcd->borderColor); +} + +static px_void PX_Object_CoordinatesDrawDashed(px_surface *psurface,PX_Object *pObject) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + px_double HorizontalInc=0; + px_int i; + px_double VerticalInc=0; + px_int offsetx; + px_int offsety; + + px_int Divid=PX_Object_CoordinatesGetCoordinateWidth(pObject)/pcd->MinHorizontalPixelDividing; + + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + offsetx=(px_int)objx; + offsety=(px_int)objy; + + + if (Divid>pcd->HorizontalDividing) + { + Divid=pcd->HorizontalDividing; + } + + + if(Divid>1) + { + HorizontalInc=(px_double)PX_Object_CoordinatesGetCoordinateWidth(pObject)/Divid; + if(pcd->guidesShowMode==PX_OBJECT_COORDINATES_GUIDESSHOWMODE_ALL||pcd->guidesShowMode==PX_OBJECT_COORDINATES_GUIDESSHOWMODE_HORIZONTAL) + { + for (i=1;i<=Divid;i++) + { + PX_GeoDrawLine(psurface,\ + offsetx+(px_int)(pcd->LeftSpacer+i*HorizontalInc),offsety+pcd->TopSpacer,\ + offsetx+(px_int)(pcd->LeftSpacer+i*HorizontalInc),offsety+pcd->TopSpacer+PX_Object_CoordinatesGetCoordinateHeight(pObject),\ + 1,\ + pcd->DashColor + ); + } + } + } + + + + Divid=PX_Object_CoordinatesGetCoordinateHeight(pObject)/pcd->MinVerticalPixelDividing; + if (pcd->LeftVerticalDividing>=pcd->RightVerticalDividing) + { + if (Divid>pcd->LeftVerticalDividing) + { + Divid=pcd->LeftVerticalDividing; + } + } + else + { + if (Divid>pcd->RightVerticalDividing) + { + Divid=pcd->RightVerticalDividing; + } + } + + if(Divid>1) + { + VerticalInc=(px_double)PX_Object_CoordinatesGetCoordinateHeight(pObject)/Divid; + if(pcd->guidesShowMode==PX_OBJECT_COORDINATES_GUIDESSHOWMODE_ALL||pcd->guidesShowMode==PX_OBJECT_COORDINATES_GUIDESSHOWMODE_VERTICAL) + { + for (i=1;i<=Divid;i++) + { + PX_GeoDrawLine(psurface,\ + offsetx+(px_int)pcd->LeftSpacer,\ + offsety+(px_int)(objHeight-pcd->BottomSpacer-i*VerticalInc),\ + offsetx+(px_int)(pcd->LeftSpacer+PX_Object_CoordinatesGetCoordinateWidth(pObject)),\ + offsety+(px_int)(objHeight-pcd->BottomSpacer-i*VerticalInc),\ + 1,\ + pcd->DashColor\ + ); + } + } + } +} + +static px_void PX_Object_CoordinatesDrawDashText(px_surface *psurface,PX_Object *pObject) +{ + + px_double HorizontalInc=0; + px_double VerticalInc=0; + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + px_double ValInc; + px_int IsFloat; + px_int i; + px_int offsetx; + px_int offsety; + + px_int Divid=PX_Object_CoordinatesGetCoordinateWidth(pObject)/pcd->MinHorizontalPixelDividing; + + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + offsetx=(px_int)objx; + offsety=(px_int)objy; + + if (Divid>pcd->HorizontalDividing) + { + Divid=pcd->HorizontalDividing; + } + + + + if(Divid>0&&pcd->HorizontalTextShow) + { + HorizontalInc=(px_double)PX_Object_CoordinatesGetCoordinateWidth(pObject)/Divid; + ValInc=(pcd->HorizontalRangeMax-pcd->HorizontalRangeMin)/Divid; + if (PX_ABS(ValInc-(px_int)ValInc)<0.000001f) + { + IsFloat=PX_FALSE; + } + else + { + IsFloat=PX_TRUE; + } + + //paint for horizontal coordinates text + for (i=0;i<=Divid;i++) + { + px_char text[32]={0}; + + if(IsFloat) + PX_sprintf1(text,sizeof(text),pcd->FloatFlagFormat_H,PX_STRINGFORMAT_FLOAT((px_float)(pcd->HorizontalRangeMin+i*ValInc))); + else + PX_sprintf1(text,sizeof(text),pcd->IntFlagFormat_H,PX_STRINGFORMAT_INT((px_int)(pcd->HorizontalRangeMin+i*ValInc))); + + PX_FontModuleDrawText(psurface,PX_NULL,offsetx+(px_int)(pcd->LeftSpacer+(i)*HorizontalInc),offsety+(px_int)(pObject->Height-pcd->BottomSpacer+PX_OBJECT_COORDINATES_DEFAULT_FLAGTEXT_SPACER+2),PX_ALIGN_CENTER,text,pcd->FontColor); + } + } + + Divid=PX_Object_CoordinatesGetCoordinateHeight(pObject)/pcd->MinVerticalPixelDividing; + if (pcd->LeftVerticalDividing>=pcd->RightVerticalDividing) + { + if (Divid>pcd->LeftVerticalDividing) + { + Divid=pcd->LeftVerticalDividing; + } + } + else + { + if (Divid>pcd->RightVerticalDividing) + { + Divid=pcd->RightVerticalDividing; + } + } + + if(Divid>0) + { + VerticalInc=(px_double)PX_Object_CoordinatesGetCoordinateHeight(pObject)/Divid; + + + //paint for Left vertical coordinates text + if (pcd->LeftTextShow) + { + ValInc=(pcd->LeftVerticalRangeMax-pcd->LeftVerticalRangeMin)/Divid; + if (PX_ABS(ValInc-(px_int)ValInc)<0.000001f) + { + IsFloat=PX_FALSE; + } + else + { + IsFloat=PX_TRUE; + } + + + for (i=0;i<=Divid;i++) + { + px_char text[32]={0}; + + switch (pcd->leftTextDisplayMode) + { + case PX_OBJECT_COORDINATES_TEXT_DISPLAYMODE_EXPONENTRAL: + { + px_double value=PX_ABS(pcd->LeftVerticalRangeMin)>PX_ABS(pcd->LeftVerticalRangeMax)?PX_ABS(pcd->LeftVerticalRangeMin):PX_ABS(pcd->LeftVerticalRangeMax); + px_int e=0; + px_double e10=1; + while(value>10){value/=10,e++;e10*=10;}; + value=pcd->LeftVerticalRangeMin+i*ValInc; + value/=e10; + + if (e>=3) + { + PX_sprintf2(text,sizeof(text),pcd->Exponential_Format,PX_STRINGFORMAT_FLOAT((px_float)(value)),PX_STRINGFORMAT_INT(e)); + } + else + { + if(IsFloat) + PX_sprintf1(text,sizeof(text),pcd->FloatFlagFormat_L,PX_STRINGFORMAT_FLOAT((px_float)(pcd->LeftVerticalRangeMin+i*ValInc))); + else + PX_sprintf1(text,sizeof(text),pcd->IntFlagFormat_L,PX_STRINGFORMAT_INT((px_int)(pcd->LeftVerticalRangeMin+i*ValInc))); + } + + + } + break; + default: + case PX_OBJECT_COORDINATES_TEXT_DISPLAYMODE_NORMAL: + { + if(IsFloat) + PX_sprintf1(text,sizeof(text),pcd->FloatFlagFormat_L,PX_STRINGFORMAT_FLOAT((px_float)(pcd->LeftVerticalRangeMin+i*ValInc))); + else + PX_sprintf1(text,sizeof(text),pcd->IntFlagFormat_L,PX_STRINGFORMAT_INT((px_int)(pcd->LeftVerticalRangeMin+i*ValInc))); + } + break; + } + + PX_FontModuleDrawText(psurface,PX_NULL,offsetx+pcd->LeftSpacer-6,offsety+(px_int)(pObject->Height-pcd->BottomSpacer-(i)*VerticalInc-6),PX_ALIGN_RIGHTTOP,text,pcd->FontColor); + } + } + + + //paint for Right vertical coordinates text + if (pcd->RightTextShow) + { + ValInc=(pcd->RightVerticalRangeMax-pcd->RightVerticalRangeMin)/Divid; + if (PX_ABS(ValInc-(px_int)ValInc)<0.000001f) + { + IsFloat=PX_FALSE; + } + else + { + IsFloat=PX_TRUE; + } + + + for (i=0;i<=Divid;i++) + { + px_char text[32]={0}; + + switch (pcd->leftTextDisplayMode) + { + case PX_OBJECT_COORDINATES_TEXT_DISPLAYMODE_EXPONENTRAL: + { + px_double value=PX_ABS(pcd->RightVerticalRangeMin)>PX_ABS(pcd->RightVerticalRangeMax)?PX_ABS(pcd->RightVerticalRangeMin):PX_ABS(pcd->RightVerticalRangeMax); + px_int e=0; + px_double e10=1; + while(value>10){value/=10,e++;e10*=10;}; + value=pcd->RightVerticalRangeMin+i*ValInc; + value/=e10; + + if (e>=3) + { + PX_sprintf2(text,sizeof(text),pcd->Exponential_Format,PX_STRINGFORMAT_FLOAT((px_float)(value)),PX_STRINGFORMAT_INT(e)); + } + else + { + if(IsFloat) + PX_sprintf1(text,sizeof(text),pcd->FloatFlagFormat_L,PX_STRINGFORMAT_FLOAT((px_float)(pcd->LeftVerticalRangeMin+i*ValInc))); + else + PX_sprintf1(text,sizeof(text),pcd->IntFlagFormat_L,PX_STRINGFORMAT_INT((px_int)(pcd->LeftVerticalRangeMin+i*ValInc))); + } + + + } + break; + default: + case PX_OBJECT_COORDINATES_TEXT_DISPLAYMODE_NORMAL: + { + if(IsFloat) + PX_sprintf1(text,sizeof(text),pcd->FloatFlagFormat_L,PX_STRINGFORMAT_FLOAT((px_float)(pcd->RightVerticalRangeMin+i*ValInc))); + else + PX_sprintf1(text,sizeof(text),pcd->IntFlagFormat_L,PX_STRINGFORMAT_INT((px_int)(pcd->RightVerticalRangeMin+i*ValInc))); + } + break; + } + PX_FontModuleDrawText(psurface,PX_NULL,offsetx+(px_int)(pObject->Width-pcd->RightSpacer+PX_OBJECT_COORDINATES_DEFAULT_FLAGTEXT_SPACER),offsety+(px_int)(pObject->Height-pcd->BottomSpacer-(i)*VerticalInc-6),PX_ALIGN_LEFTTOP,text,pcd->FontColor); + } + } + } + + +} + +static px_void PX_Object_CoordinatesDrawTitle(px_surface *psurface,PX_Object *pObject) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + px_int offsetx; + px_int offsety; + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + offsetx=(px_int)objx; + offsety=(px_int)objy; + if (pcd->TopTitle[0]) + { + PX_FontModuleDrawText(psurface,pcd->fontmodule,offsetx+(px_int)(pObject->Width/2),offsety,PX_ALIGN_MIDTOP,pcd->TopTitle,pcd->FontColor); + } + + if (pcd->BottomTitle[0]) + { + PX_FontModuleDrawText(psurface,pcd->fontmodule,offsetx+(px_int)(pObject->Width/2),offsety+(px_int)(pObject->Height-pcd->BottomSpacer+32),PX_ALIGN_MIDBOTTOM,pcd->BottomTitle,pcd->FontColor); + } + + + // px_int x = this->width()-20; + // + // px_int y = ( this->height()/ 2); + // painter.rotate(90); + // painter.drawText(y-30, -x+12,m_RightTitle ); + // + // painter.rotate(180); + // painter.drawText(-y-70, 45,m_LeftTitle); +} + +static px_void PX_Object_CoordinatesDrawDataInfo(px_surface *psurface,PX_Object *pObject,px_double *Horizontal,px_double n,px_double *Vertical,px_int linewidth,px_int Size,px_int Map,px_color Color) +{ + px_double RangeMin,RangeMax; + px_double x,y,w,btm,zeroy; + px_int dx1,dy1,dx2,dy2; + px_int i; + px_int offsetx; + px_int offsety; + + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + offsetx=(px_int)objx; + offsety=(px_int)objy; + + if (Map==PX_OBJECT_COORDINATEDATA_MAP_LEFT) + { + RangeMin=pcd->LeftVerticalRangeMin; + RangeMax=pcd->LeftVerticalRangeMax; + } + + if (Map==PX_OBJECT_COORDINATEDATA_MAP_RIGHT) + { + RangeMin=pcd->RightVerticalRangeMin; + RangeMax=pcd->RightVerticalRangeMax; + } + + switch(pcd->LineMode) + { + case PX_OBJECT_COORDINATES_LINEMODE_PILLAR: + { + zeroy=PX_Object_CoordinatesMapVerticalValueToPixel(pObject,0,Map); + for (i=0;i=pcd->HorizontalRangeMin) + { + + x=PX_Object_CoordinatesMapHorizontalValueToPixel(pObject,Horizontal[i-1])-pcd->DataPillarWidth/2; + y=PX_Object_CoordinatesMapVerticalValueToPixel(pObject,Vertical[i]/n,Map); + + w=pcd->DataPillarWidth; + btm=zeroy; + + if (y>btm) + { + double tem; + tem=btm; + btm=y; + y=tem; + } + + if (!(btmTopSpacer||y>pObject->Height-pcd->BottomSpacer)) + { + if (yTopSpacer) + { + y=pcd->TopSpacer; + } + if (btm>pObject->Height-pcd->BottomSpacer) + { + btm=pObject->Height-pcd->BottomSpacer; + } + if (x-(px_int)x>0.1) + { + PX_GeoDrawRect(psurface,offsetx+(px_int)x,offsety+(px_int)y,offsetx+(px_int)(x+w),offsety+(px_int)(btm),Color); + } + else + { + PX_GeoDrawRect(psurface,offsetx+(px_int)x,offsety+(px_int)y,offsetx+(px_int)(x+w),offsety+(px_int)(btm),Color); + } + } + + + + } + if(Horizontal[i]>pcd->HorizontalRangeMax) + break; + } + } + break; + case PX_OBJECT_COORDINATES_LINEMODE_LINES: + default: + { + for (i=0;i=pcd->HorizontalRangeMin) + { + + if(i>0){ + px_point pt1,pt2; + + dx1=PX_Object_CoordinatesMapHorizontalValueToPixel(pObject,Horizontal[i-1]); + dy1=PX_Object_CoordinatesMapVerticalValueToPixel(pObject,Vertical[i-1]/n,Map); + dx2=PX_Object_CoordinatesMapHorizontalValueToPixel(pObject,Horizontal[i]); + dy2=PX_Object_CoordinatesMapVerticalValueToPixel(pObject,Vertical[i]/n,Map); + + if(PX_isLineCrossRect(PX_POINT((px_float)dx1,(px_float)dy1,0),PX_POINT((px_float)dx2,(px_float)dy2,0),PX_RECT((px_float)pcd->LeftSpacer,(px_float)pcd->TopSpacer,(px_float)PX_Object_CoordinatesGetCoordinateWidth(pObject),(px_float)PX_Object_CoordinatesGetCoordinateHeight(pObject)),&pt1,&pt2)) + { + PX_GeoDrawLine(psurface,(px_int)(offsetx+pt1.x),(px_int)(offsety+pt1.y),(px_int)(offsetx+pt2.x),(px_int)(offsety+pt2.y),linewidth,Color); + } + + } + } + if(Horizontal[i]>pcd->HorizontalRangeMax) + { + if(i>0){ + px_point pt1,pt2; + + dx1=PX_Object_CoordinatesMapHorizontalValueToPixel(pObject,Horizontal[i-1]); + dy1=PX_Object_CoordinatesMapVerticalValueToPixel(pObject,Vertical[i-1]/n,Map); + dx2=PX_Object_CoordinatesMapHorizontalValueToPixel(pObject,Horizontal[i]); + dy2=PX_Object_CoordinatesMapVerticalValueToPixel(pObject,Vertical[i]/n,Map); + if(PX_isLineCrossRect(PX_POINT((px_float)dx1,(px_float)dy1,0),PX_POINT((px_float)dx2,(px_float)dy2,0),PX_RECT((px_float)pcd->TopSpacer,(px_float)pcd->LeftSpacer,(px_float)PX_Object_CoordinatesGetCoordinateWidth(pObject),(px_float)PX_Object_CoordinatesGetCoordinateHeight(pObject)),&pt1,&pt2)) + PX_GeoDrawLine(psurface,(px_int)(offsetx+pt1.x),(px_int)(offsety+pt1.y),(px_int)(offsetx+pt2.x),(px_int)(offsety+pt2.y),linewidth,Color); + } + break; + } + } + } + break; + + } +} + + +static px_void PX_Object_CoordinatesDrawData(px_surface *psurface,PX_Object *pObject) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + px_int i; + if(pcd->bDataUpdatePainter) + { + for ( i=0;ivData.size;i++) + { + PX_Object_CoordinateData *pData=PX_VECTORAT(PX_Object_CoordinateData,&pcd->vData,i); + if(pData->Visibled) + { + if (pData->Normalization==0) + { + PX_Object_CoordinatesDrawDataInfo(psurface,pObject,pData->MapHorizontalArray,1.0,pData->MapVerticalArray,pData->linewidth,pData->Size,pData->Map,pData->Color); + } + else + { + PX_Object_CoordinatesDrawDataInfo(psurface,pObject,pData->MapHorizontalArray,pData->Normalization,pData->MapVerticalArray,pData->linewidth,pData->Size,pData->Map,pData->Color); + } + } + + } + } +} +static px_void PX_Object_CoordinatesDrawScaleDraging(px_surface *psurface,PX_Object *pObject) +{ + px_int offsetx; + px_int offsety; + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + offsetx=(px_int)objx; + offsety=(px_int)objy; + + if (!pcd->bScaleDrag) + { + return; + } + + if(pcd->DragingPoint.yDragStartPoint.y&&pcd->DragingPoint.xDragStartPoint.x) + PX_GeoDrawRect(psurface,offsetx+(px_int)pcd->DragStartPoint.x,offsety+(px_int)pcd->DragStartPoint.y,offsetx+(px_int)pcd->DragingPoint.x,offsety+(px_int)pcd->DragingPoint.y,PX_COLOR(96,171,81,128)); + else + PX_GeoDrawRect(psurface,offsetx+(px_int)pcd->DragStartPoint.x,offsety+(px_int)pcd->DragStartPoint.y,offsetx+(px_int)pcd->DragingPoint.x,offsety+(px_int)pcd->DragingPoint.y,PX_COLOR(96,167,233,128)); + +} + +static px_void PX_Object_CoordinatesDrawHelpLine(px_surface *psurface,PX_Object *pObject) +{ + px_int x,y; + px_double value; + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + if (!pcd->ShowHelpLine) + { + return; + } + //Draw X line + + + value=PX_Object_CoordinatesMapPixelValueToVertical(pObject,pcd->helpLineX,PX_OBJECT_COORDINATEDATA_MAP_HORIZONTAL); + + if (value>pcd->HorizontalRangeMin&&valueHorizontalRangeMax) + { + px_int IsFloat; + px_int X,Y; + px_double ValInc=value; + px_char text[16]; + x=PX_Object_CoordinatesMapHorizontalValueToPixel(pObject,value); + + PX_GeoDrawLine(psurface,(px_int)objx+x,(px_int)(objy+objHeight-pcd->BottomSpacer),(px_int)objx+x,(px_int)objy+pcd->TopSpacer,(px_int)1,pcd->helpLineColor); + + + //Draw text + + if (PX_ABS(ValInc-(px_int)ValInc)<0.000001f) + { + IsFloat=PX_FALSE; + } + else + { + IsFloat=PX_TRUE; + } + + + X=PX_Object_CoordinatesMapHorizontalValueToPixel(pObject,value); + Y=(px_int)(objHeight-pcd->BottomSpacer); + + if(IsFloat) + PX_sprintf1(text,sizeof(text),"%1",PX_STRINGFORMAT_FLOAT((px_float)ValInc)); + else + PX_sprintf1(text,sizeof(text),"%1",PX_STRINGFORMAT_INT((px_int)ValInc)); + + PX_FontModuleDrawText(psurface,PX_NULL,(px_int)(objx+X-PX_OBJECT_COORDINATES_DEFAULT_FLAGTEXT_SPACER*1.5),(px_int)objy+Y,PX_ALIGN_LEFTTOP,text,pcd->helpLineColor); + + } + + + + //Draw YL line + + + value=PX_Object_CoordinatesMapPixelValueToVertical(pObject,pcd->helpLineY,PX_OBJECT_COORDINATEDATA_MAP_LEFT); + + if (value>pcd->LeftVerticalRangeMin&&valueLeftVerticalRangeMax) + { + px_int IsFloat; + px_int X,Y; + px_double ValInc=value; + px_char text[16]; + + y=pcd->helpLineY;//PX_Object_CoordinatesMapVerticalValueToPixel(pObject,value,PX_OBJECT_COORDINATEDATA_MAP_LEFT); + + PX_GeoDrawLine(psurface,(px_int)objx+pcd->LeftSpacer,(px_int)objy+y,(px_int)(objx+objWidth-pcd->RightSpacer),(px_int)objy+y,1,pcd->helpLineColor); + //Draw text + + if (PX_ABS(ValInc-(px_int)ValInc)<0.000000001) + { + IsFloat=PX_FALSE; + } + else + { + IsFloat=PX_TRUE; + } + + + X=pcd->LeftSpacer; + Y=y;//PX_Object_CoordinatesMapVerticalValueToPixel(pObject,ValInc,PX_OBJECT_COORDINATEDATA_MAP_LEFT); + + if(IsFloat) + PX_sprintf1(text,sizeof(text),"%1",PX_STRINGFORMAT_FLOAT((px_float)ValInc)); + else + PX_sprintf1(text,sizeof(text),"%1",PX_STRINGFORMAT_INT((px_int)ValInc)); + + PX_FontModuleDrawText(psurface,PX_NULL,(px_int)objx+X,(px_int)objy+Y-PX_OBJECT_COORDINATES_DEFAULT_FLAGTEXT_SPACER*2-1,PX_ALIGN_LEFTTOP,text,pcd->helpLineColor); + + } + + + //Draw YR line + + value=PX_Object_CoordinatesMapPixelValueToVertical(pObject,pcd->helpLineY,PX_OBJECT_COORDINATEDATA_MAP_RIGHT); + + if (value>pcd->RightVerticalRangeMin&&valueRightVerticalRangeMax) + { + px_int IsFloat; + px_int X,Y; + px_double ValInc=value; + px_char text[16]; + + y=pcd->helpLineY;//PX_Object_CoordinatesMapVerticalValueToPixel(pObject,pflgl->Y,PX_OBJECT_COORDINATEDATA_MAP_RIGHT); + PX_GeoDrawLine(psurface,(px_int)objx+pcd->LeftSpacer,(px_int)objy+y,(px_int)(objx+objWidth-pcd->RightSpacer),(px_int)objy+y,(px_int)(1),pcd->helpLineColor); + + + if (PX_ABS(ValInc-(px_int)ValInc)<0.000001f) + { + IsFloat=PX_FALSE; + } + else + { + IsFloat=PX_TRUE; + } + + X=(px_int)(objWidth-pcd->RightSpacer); + Y=y;//PX_Object_CoordinatesMapVerticalValueToPixel(pObject,ValInc,PX_OBJECT_COORDINATEDATA_MAP_RIGHT); + + if(IsFloat) + PX_sprintf1(text,sizeof(text),"%1",PX_STRINGFORMAT_FLOAT((px_float)ValInc)); + else + PX_sprintf1(text,sizeof(text),"%1",PX_STRINGFORMAT_INT((px_int)ValInc)); + + PX_FontModuleDrawText(psurface,PX_NULL,(px_int)objx+X,(px_int)objy+Y-PX_OBJECT_COORDINATES_DEFAULT_FLAGTEXT_SPACER*2-1,PX_ALIGN_LEFTTOP,text,pcd->helpLineColor); + + } +} + + + +static px_void PX_Object_CoordinatesDrawFlagLine(px_surface *psurface,PX_Object *pObject) +{ + px_int x,y,i; + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + for (i=0;ivFlagLine.size;i++) + { + //Draw X line + PX_Object_CoordinateFlagLine *pflgl=PX_VECTORAT(PX_Object_CoordinateFlagLine,&pcd->vFlagLine,i); + if(pflgl->XYshow&PX_OBJECT_COORDINATEFLAGLINE_XSHOW) + { + if (pflgl->X>=pcd->HorizontalRangeMin&&pflgl->X<=pcd->HorizontalRangeMax) + { + px_int IsFloat; + px_int X,Y; + px_double ValInc=pflgl->X; + px_char text[16]; + x=PX_Object_CoordinatesMapHorizontalValueToPixel(pObject,pflgl->X); + + PX_GeoDrawLine(psurface,(px_int)objx+x,(px_int)((px_int)objy+objHeight-pcd->BottomSpacer),(px_int)objx+x,(px_int)objy+pcd->TopSpacer,(px_int)pflgl->LineWidth,pflgl->color); + //Draw text + + if (PX_ABS(ValInc-(px_int)ValInc)<0.000001f) + { + IsFloat=PX_FALSE; + } + else + { + IsFloat=PX_TRUE; + } + + + X=PX_Object_CoordinatesMapHorizontalValueToPixel(pObject,pflgl->X); + Y=(px_int)(objHeight-pcd->BottomSpacer); + + if(IsFloat) + PX_sprintf1(text,sizeof(text),"%1",PX_STRINGFORMAT_FLOAT((px_float)ValInc)); + else + PX_sprintf1(text,sizeof(text),"%1",PX_STRINGFORMAT_INT((px_int)ValInc)); + + PX_FontModuleDrawText(psurface,PX_NULL,(px_int)((px_int)objx+X-PX_OBJECT_COORDINATES_DEFAULT_FLAGTEXT_SPACER*1.5),(px_int)objy+Y,PX_ALIGN_LEFTTOP,text,pcd->FontColor); + } + } + + + //Draw YL line + + if(pflgl->XYshow&PX_OBJECT_COORDINATEFLAGLINE_XSHOW) + { + if (pflgl->Y>=pcd->LeftVerticalRangeMin&&pflgl->Y<=pcd->LeftVerticalRangeMax) + { + px_int IsFloat; + px_int X,Y; + px_double ValInc=pflgl->Y; + px_char text[16]; + y=PX_Object_CoordinatesMapVerticalValueToPixel(pObject,pflgl->Y,PX_OBJECT_COORDINATEDATA_MAP_LEFT); + + PX_GeoDrawLine(psurface,(px_int)objx+pcd->LeftSpacer,(px_int)objy+y,(px_int)((px_int)objx+objWidth-pcd->RightSpacer),(px_int)objy+y,(px_int)(pflgl->LineWidth),pflgl->color); + //Draw text + + if (PX_ABS(ValInc-(px_int)ValInc)<0.000000001) + { + IsFloat=PX_FALSE; + } + else + { + IsFloat=PX_TRUE; + } + + + X=pcd->LeftSpacer; + Y=y;//PX_Object_CoordinatesMapVerticalValueToPixel(pObject,ValInc,PX_OBJECT_COORDINATEDATA_MAP_LEFT); + + if(IsFloat) + PX_sprintf1(text,sizeof(text),"%1",PX_STRINGFORMAT_FLOAT((px_float)ValInc)); + else + PX_sprintf1(text,sizeof(text),"%1",PX_STRINGFORMAT_INT((px_int)ValInc)); + + PX_FontModuleDrawText(psurface,PX_NULL,(px_int)objx+X-4*PX_OBJECT_COORDINATES_DEFAULT_FLAGTEXT_SPACER,(px_int)objy+Y-PX_OBJECT_COORDINATES_DEFAULT_FLAGTEXT_SPACER,PX_ALIGN_LEFTTOP,text,pcd->FontColor); + } + } + + + //Draw YR line + if(pflgl->XYshow&PX_OBJECT_COORDINATEFLAGLINE_YRSHOW) + { + if (pflgl->Y>=pcd->RightVerticalRangeMin&&pflgl->Y<=pcd->RightVerticalRangeMax) + { + px_int IsFloat; + px_int X,Y; + px_double ValInc=pflgl->Y; + px_char text[16]; + + y=PX_Object_CoordinatesMapVerticalValueToPixel(pObject,pflgl->Y,PX_OBJECT_COORDINATEDATA_MAP_RIGHT); + PX_GeoDrawLine(psurface,(px_int)objx+pcd->LeftSpacer,(px_int)objy+y,(px_int)((px_int)objx+objWidth-pcd->RightSpacer),(px_int)objy+y,(px_int)(pflgl->LineWidth),pflgl->color); + + if (PX_ABS(ValInc-(px_int)ValInc)<0.000001f) + { + IsFloat=PX_FALSE; + } + else + { + IsFloat=PX_TRUE; + } + + X=(px_int)(objWidth-pcd->RightSpacer); + Y=y;//PX_Object_CoordinatesMapVerticalValueToPixel(pObject,ValInc,PX_OBJECT_COORDINATEDATA_MAP_RIGHT); + + PX_FontModuleDrawText(psurface,PX_NULL,(px_int)objx+X,(px_int)objy+Y-PX_OBJECT_COORDINATES_DEFAULT_FLAGTEXT_SPACER,PX_ALIGN_LEFTTOP,text,pcd->FontColor); + } + } + } +} + + +px_void PX_Object_CoordinatesDrawMarkLine(px_surface *psurface,PX_Object *pObject) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + + if (pcd->MarkValueEnabled&&pcd->OnMarkStatus) + { + if(pcd->MarkLineX!=-1) + { + PX_GeoDrawLine(psurface,pcd->MarkLineX,pcd->TopSpacer,pcd->MarkLineX,(px_int)(pObject->Height-pcd->BottomSpacer),1,PX_COLOR(255,255,0,0)); + } + } +} + + + +px_void PX_Object_CoordinatesRestoreCoordinates(PX_Object *pObject) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (!pcd->bScaling) + { + return; + } + PX_Object_CoordinatesSetHorizontalMin(pObject,pcd->ResHorizontalRangeMin); + PX_Object_CoordinatesSetHorizontalMax(pObject,pcd->ResHorizontalRangeMax); + PX_Object_CoordinatesSetLeftVerticalMin(pObject,pcd->ResLeftVerticalRangeMin); + PX_Object_CoordinatesSetLeftVerticalMax(pObject,pcd->ResLeftVerticalRangeMax); + PX_Object_CoordinatesSetRightVerticalMin(pObject,pcd->ResRightVerticalRangeMin); + PX_Object_CoordinatesSetRightVerticalMax(pObject,pcd->ResRightVerticalRangeMax); + pcd->bScaling=PX_FALSE; +} +px_void PX_Object_CoordinatesScaleCoordinates(PX_Object *pObject) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + px_double Min,Max; + px_double dMin; + px_double dMax; + if(!pcd->ScaleEnabled) + { + return; + } + + if (pcd->DragingPoint.x==pcd->DragStartPoint.x) + { + return; + } + if (pcd->DragingPoint.y==pcd->DragStartPoint.y) + { + return; + } + if (!pcd->bScaling) + { + pcd->ResHorizontalRangeMax=pcd->HorizontalRangeMax; + pcd->ResHorizontalRangeMin=pcd->HorizontalRangeMin; + + pcd->ResLeftVerticalRangeMax=pcd->LeftVerticalRangeMax; + pcd->ResLeftVerticalRangeMin=pcd->LeftVerticalRangeMin; + pcd->ResRightVerticalRangeMin=pcd->RightVerticalRangeMin; + pcd->ResRightVerticalRangeMax=pcd->RightVerticalRangeMax; + + pcd->bScaling=PX_TRUE; + } + + + if (pcd->DragStartPoint.xDragingPoint.x) + { + Min=pcd->DragStartPoint.x; + Max=pcd->DragingPoint.x; + } + else + { + Max=pcd->DragStartPoint.x; + Min=pcd->DragingPoint.x; + } + dMin=PX_Object_CoordinatesMapPixelValueToHorizontal(pObject,(px_int)Min); + dMax=PX_Object_CoordinatesMapPixelValueToHorizontal(pObject,(px_int)Max); + + PX_Object_CoordinatesSetHorizontalMin(pObject,dMin); + PX_Object_CoordinatesSetHorizontalMax(pObject,dMax); + + if (pcd->DragStartPoint.yDragingPoint.y) + { + Max=pcd->DragStartPoint.y; + Min=pcd->DragingPoint.y; + } + else + { + Min=pcd->DragStartPoint.y; + Max=pcd->DragingPoint.y; + } + + dMin=PX_Object_CoordinatesMapPixelValueToVertical(pObject,(px_int)Min,PX_OBJECT_COORDINATEDATA_MAP_LEFT); + dMax=PX_Object_CoordinatesMapPixelValueToVertical(pObject,(px_int)Max,PX_OBJECT_COORDINATEDATA_MAP_LEFT); + PX_Object_CoordinatesSetLeftVerticalMin(pObject,dMin); + PX_Object_CoordinatesSetLeftVerticalMax(pObject,dMax); + + dMin=PX_Object_CoordinatesMapPixelValueToVertical(pObject,(px_int)Min,PX_OBJECT_COORDINATEDATA_MAP_RIGHT); + dMax=PX_Object_CoordinatesMapPixelValueToVertical(pObject,(px_int)Max,PX_OBJECT_COORDINATEDATA_MAP_RIGHT); + + PX_Object_CoordinatesSetRightVerticalMin(pObject,dMin); + PX_Object_CoordinatesSetRightVerticalMax(pObject,dMax); +} + + +px_void PX_Object_CoordinatesRender(px_surface *psurface, PX_Object *pObject,px_uint elapsed) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + if (!pcd) + { + PX_ASSERT(); + return; + } + + // + // PX_Object_CoordinatesDrawMarkLine(psurface,pObject); + + if(pcd->ShowGuides) + PX_Object_CoordinatesDrawDashed(psurface,pObject); + + PX_Object_CoordinatesDrawDashText(psurface,pObject); + + PX_Object_CoordinatesDrawTitle(psurface,pObject); + + PX_Object_CoordinatesDrawData(psurface,pObject); + + PX_Object_CoordinatesDrawFrameLine(psurface,pObject); + + if(pcd->ScaleEnabled) + PX_Object_CoordinatesDrawScaleDraging(psurface,pObject); + + PX_Object_CoordinatesDrawHelpLine(psurface,pObject); + + PX_Object_CoordinatesDrawFlagLine(psurface,pObject); +} + +px_void PX_Object_CoordinatesFree(PX_Object *pObject) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + PX_VectorFree(&pcd->vData); + PX_VectorFree(&pcd->vFlagLine); +} + +px_void PX_Object_CoordinatesCursorPressEvent(PX_Object *pObject, PX_Object_Event e,px_void *ptr) +{ + px_float x; + px_float y; + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + x=(PX_Object_Event_GetCursorX(e)-objx); + y=(PX_Object_Event_GetCursorY(e)-objy); + if(!PX_ObjectIsPointInRegion(pObject,PX_Object_Event_GetCursorX(e),PX_Object_Event_GetCursorY(e))) + { + return; + } + + if (xLeftSpacer) + { + x=(px_float)pcd->LeftSpacer; + } + if (x>objWidth-pcd->RightSpacer) + { + x=(objWidth-pcd->RightSpacer); + } + if (yTopSpacer) + { + y=(px_float)pcd->TopSpacer; + } + if (y>objHeight-pcd->BottomSpacer) + { + y=(objHeight-pcd->BottomSpacer); + } + + pcd->DragStartPoint.x=(px_float)(x); + pcd->DragStartPoint.y=(px_float)(y); + + pcd->DragingPoint=pcd->DragStartPoint; + + pcd->bScaleDrag=PX_TRUE; +} + +px_void PX_Object_CoordinatesCursorReleaseEvent( PX_Object *pObject, PX_Object_Event e,px_void *ptr ) +{ + + px_float x=PX_Object_Event_GetCursorX(e); + px_float y=PX_Object_Event_GetCursorY(e); + + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + pcd->OnMarkStatus=PX_FALSE; + pcd->MarkLineX=-1; + + if (pcd->bScaleDrag) + { + pcd->bScaleDrag=PX_FALSE; + pcd->DragingPoint.x=(px_float)(PX_Object_Event_GetCursorX(e)-objx); + pcd->DragingPoint.y=(px_float)(PX_Object_Event_GetCursorY(e)-objy); + + if(pcd->DragingPoint.yDragStartPoint.y&&pcd->DragingPoint.xDragStartPoint.x) + { + PX_Object_CoordinatesRestoreCoordinates(pObject); + } + else + { + PX_Object_CoordinatesScaleCoordinates(pObject); + } + } + +} + +px_void PX_Object_CoordinatesCursorDragEvent(PX_Object *pObject, PX_Object_Event e,px_void *ptr ) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + if (pcd->bScaleDrag) + { + px_float x=(PX_Object_Event_GetCursorX(e)-objx); + px_float y=(PX_Object_Event_GetCursorY(e)-objy); + + pcd->OnMarkStatus=PX_FALSE; + pcd->MarkLineX=-1; + + // emit SignalOnMousePosition(this->MapPixelValueToHorizontal(e->x()), + // e->x(), + // this->MapPixelValueToVertical(e->y(),COORDINATEDATA_MAP_RIGHT)); + if (xLeftSpacer) + { + x=(px_float)pcd->LeftSpacer; + } + if (x>objWidth-pcd->RightSpacer) + { + x=(objWidth-pcd->RightSpacer); + } + if (yTopSpacer) + { + y=(px_float)pcd->TopSpacer; + } + if (y>objHeight-pcd->BottomSpacer) + { + y=(objHeight-pcd->BottomSpacer); + } + + pcd->DragingPoint.x=(px_float)(x); + pcd->DragingPoint.y=(px_float)(y); + } + +} + +px_void PX_Object_CoordinatesCursorMoveEvent(PX_Object *pObject, PX_Object_Event e,px_void *ptr ) +{ + PX_Object_Coordinates *pcd=PX_Object_GetCoordinates(pObject); + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + if (pcd->ShowHelpLine) + { + px_float x=(PX_Object_Event_GetCursorX(e)-objx); + px_float y=(PX_Object_Event_GetCursorY(e)-objy); + + pcd->OnMarkStatus=PX_FALSE; + pcd->MarkLineX=-1; + + // emit SignalOnMousePosition(this->MapPixelValueToHorizontal(e->x()), + // e->x(), + // this->MapPixelValueToVertical(e->y(),COORDINATEDATA_MAP_RIGHT)); + if (xLeftSpacer) + { + x=(px_float)pcd->LeftSpacer; + } + if (x>objWidth-pcd->RightSpacer) + { + x=(objWidth-pcd->RightSpacer); + } + if (yTopSpacer) + { + y=(px_float)pcd->TopSpacer; + } + if (y>objHeight-pcd->BottomSpacer) + { + y=(objHeight-pcd->BottomSpacer); + } + + if (pcd->bScaleDrag) + { + pcd->DragingPoint.x=(px_float)(x); + pcd->DragingPoint.y=(px_float)(y); + } + + pcd->helpLineX=(px_int)(x); + pcd->helpLineY=(px_int)(y); + } +} + + + + +PX_Object *PX_Object_CoordinatesCreate(px_memorypool *mp, PX_Object *Parent,px_int x,px_int y,px_int Width,px_int Height,PX_FontModule *fontmodule) +{ + PX_Object *pObject; + PX_Object_Coordinates Coordinates; + PX_memset(&Coordinates,0,sizeof(Coordinates)); + Coordinates.mp=mp; + Coordinates.MinHorizontalPixelDividing=PX_OBJECT_COORDINATES_DEFAULE_MINHORIZONTALPIXELDIVIDING; + Coordinates.MinVerticalPixelDividing=PX_OBJECT_COORDINATES_DEFAULE_MINVERTICALPIXELDIVIDING; + Coordinates.HorizontalDividing=PX_OBJECT_COORDINATES_DEFAULE_DIVIDING; + Coordinates.LeftVerticalDividing=PX_OBJECT_COORDINATES_DEFAULE_DIVIDING; + Coordinates.RightVerticalDividing=PX_OBJECT_COORDINATES_DEFAULE_DIVIDING; + Coordinates.bScaleDrag=PX_FALSE; + Coordinates.guidesShowMode=PX_OBJECT_COORDINATES_GUIDESSHOWMODE_ALL; + Coordinates.helpLineColor=PX_COLOR(255,255,0,0); + Coordinates.ShowHelpLine=PX_TRUE; + + Coordinates.LeftSpacer=(px_int)(1.5f*PX_OBJECT_COORDINATES_DEFAULT_SPACER); + Coordinates.RightSpacer=(px_int)(1.5*PX_OBJECT_COORDINATES_DEFAULT_SPACER); + Coordinates.TopSpacer=PX_OBJECT_COORDINATES_DEFAULT_SPACER; + Coordinates.BottomSpacer=PX_OBJECT_COORDINATES_DEFAULT_SPACER; + + Coordinates.HorizontalRangeMin=-150; + Coordinates.HorizontalRangeMax=150; + + Coordinates.LeftVerticalRangeMin=0; + Coordinates.LeftVerticalRangeMax=100; + + Coordinates.RightVerticalRangeMax=1.0; + Coordinates.RightVerticalRangeMin=0; + + Coordinates.FloatFlagFormat_H=PX_OBJECT_COORDINATES_DEFAULT_FLOAT_FLAGFORMAT_H; + Coordinates.IntFlagFormat_H=PX_OBJECT_COORDINATES_DEFAULT_INT_FLAGFORMAT_H; + + Coordinates.FloatFlagFormat_L=PX_OBJECT_COORDINATES_DEFAULT_FLOAT_FLAGFORMAT_L; + Coordinates.IntFlagFormat_L=PX_OBJECT_COORDINATES_DEFAULT_INT_FLAGFORMAT_L; + + Coordinates.FloatFlagFormat_R=PX_OBJECT_COORDINATES_DEFAULT_FLOAT_FLAGFORMAT_R; + Coordinates.IntFlagFormat_R=PX_OBJECT_COORDINATES_DEFAULT_INT_FLAGFORMAT_R; + + Coordinates.Exponential_Format=PX_OBJECT_COORDINATES_DEFAULT_EXPONENTIAL_FORMAT; + + Coordinates.bScaling=PX_FALSE; + + Coordinates.FontSize=PX_OBJECT_COORDINATES_DEFAULT_FONT_SIZE; + Coordinates.DataLineWidth=PX_OBJECT_COORDINATES_DEFAULT_LINE_WIDTH; + Coordinates.FontColor= PX_OBJECT_UI_DEFAULT_FONTCOLOR; + Coordinates.borderColor= PX_OBJECT_UI_DEFAULT_BORDERCOLOR; + Coordinates.DashColor=PX_COLOR(PX_OBJECT_COORDINATES_DEFAULT_DASH_RGB); + Coordinates.OnMarkStatus=PX_FALSE; + Coordinates.MarkValueEnabled=PX_TRUE; + Coordinates.MarkLineX=-1; + + Coordinates.bDataUpdatePainter=PX_TRUE; + + Coordinates.LineMode=PX_OBJECT_COORDINATES_LINEMODE_LINES; + + Coordinates.LeftTextShow=PX_TRUE; + Coordinates.RightTextShow=PX_TRUE; + Coordinates.HorizontalTextShow=PX_TRUE; + Coordinates.ScaleEnabled=PX_TRUE; + Coordinates.ShowGuides=PX_TRUE; + + Coordinates.LeftTitle=""; + Coordinates.RightTitle=""; + Coordinates.TopTitle=""; + Coordinates.BottomTitle=""; + Coordinates.fontmodule=fontmodule; + Coordinates.leftTextDisplayMode=PX_OBJECT_COORDINATES_TEXT_DISPLAYMODE_NORMAL; + Coordinates.RightTextDisplayMode=PX_OBJECT_COORDINATES_TEXT_DISPLAYMODE_NORMAL; + + PX_VectorInitialize(mp,&Coordinates.vData,sizeof(PX_Object_CoordinateData),16); + PX_VectorInitialize(mp,&Coordinates.vFlagLine,sizeof(PX_Object_CoordinateFlagLine),16); + + pObject=PX_ObjectCreateEx(mp,Parent,(px_float)x,(px_float)y,0,(px_float)Width,(px_float)Height,0,PX_OBJECT_TYPE_COORDINATE,PX_Object_CoordinatesUpdate,PX_Object_CoordinatesRender,PX_Object_CoordinatesFree,&Coordinates,sizeof(PX_Object_Coordinates)); + + //PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORMOVE,PX_Object_CoordinatesCursorMoveEvent,PX_NULL); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORMOVE,PX_Object_CoordinatesCursorMoveEvent,PX_NULL); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORDRAG,PX_Object_CoordinatesCursorDragEvent,PX_NULL); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORDOWN,PX_Object_CoordinatesCursorPressEvent,PX_NULL); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORUP,PX_Object_CoordinatesCursorReleaseEvent,PX_NULL); + + return pObject; +} + +PX_Object_FilterEditor * PX_Object_GetFilterEditor(PX_Object *Object) +{ + if (Object->Type==PX_OBJECT_TYPE_FILTEREDITOR) + { + return (PX_Object_FilterEditor *)Object->pObject; + } + return PX_NULL; +} + +static px_void PX_Object_FilterEditorDrawFrameLine(px_surface *psurface,PX_Object *pObject) +{ + PX_Object_FilterEditor *pfe=PX_Object_GetFilterEditor(pObject); + px_int offsetx; + px_int offsety; + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + offsetx=(px_int)objx; + offsety=(px_int)objy; + + PX_GeoDrawLine(psurface,offsetx,offsety,offsetx+(px_int)(objWidth-1),offsety,PX_OBJECT_FILTEREDITOR_DEFAULT_FRAMELINE_WIDTH,pfe->borderColor); + PX_GeoDrawLine(psurface,offsetx,offsety,offsetx,offsety+(px_int)(objHeight-1),PX_OBJECT_FILTEREDITOR_DEFAULT_FRAMELINE_WIDTH,pfe->borderColor); + PX_GeoDrawLine(psurface,(px_int)(offsetx+objWidth-1),offsety+(px_int)(objHeight-1),offsetx,offsety+(px_int)objHeight-1,PX_OBJECT_COORDINATES_DEFAULT_FRAMELINE_WIDTH,pfe->borderColor); + PX_GeoDrawLine(psurface,(px_int)(offsetx+objWidth-1),offsety+(px_int)(objHeight-1),offsetx+(px_int)(objWidth-1),offsety,PX_OBJECT_COORDINATES_DEFAULT_FRAMELINE_WIDTH,pfe->borderColor); +} + +static px_void PX_Object_FilterEditorDrawSelectDraging(px_surface *psurface,PX_Object *pObject) +{ + PX_Object_FilterEditor *pfe=PX_Object_GetFilterEditor(pObject); + px_int offsetx; + px_int offsety; + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + offsetx=(px_int)objx; + offsety=(px_int)objy; + + if (!pfe->bSelectDrag) + { + return; + } + + PX_GeoDrawRect(psurface,(px_int)(offsetx+pfe->DragStartPoint.x),(px_int)(offsety+(px_int)pfe->DragStartPoint.y),(px_int)(offsetx+(px_int)pfe->DragingPoint.x),(px_int)(offsety+(px_int)pfe->DragingPoint.y),PX_COLOR(96,171,81,128)); +} + +static px_void PX_Object_FilterEditorDrawPt(px_surface *psurface,PX_Object *pObject) +{ + PX_Object_FilterEditor *pfe=PX_Object_GetFilterEditor(pObject); + px_int i; + px_float oftx; + px_float ofty; + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + oftx=objx; + ofty=objy; + + for (i=0;iopCount;i++) + { + PX_GeoDrawSolidCircle(psurface,(px_int)(oftx+pfe->pt[i].x),(px_int)(ofty+pfe->pt[i].y),pfe->radius,pfe->ptColor); + if (pfe->pt[i].bselect||pfe->pt[i].bCursor) + { + PX_GeoDrawCircle(psurface,(px_int)(oftx+pfe->pt[i].x),(px_int)(ofty+pfe->pt[i].y),pfe->radius+2,1,pfe->ptColor); + } + } + + for (i=0;iopCount-1;i++) + { + PX_GeoDrawLine(psurface,(px_int)(oftx+pfe->pt[i].x),(px_int)(ofty+pfe->pt[i].y),(px_int)(oftx+pfe->pt[i+1].x),(px_int)(ofty+pfe->pt[i+1].y),2,pfe->ptColor); + } + +} + +static px_void PX_Object_FilterEditorDrawHelpLine(px_surface *psurface,PX_Object *pObject) +{ + PX_Object_FilterEditor *pfe=PX_Object_GetFilterEditor(pObject); + px_char text[16]; + px_double midy,incx,incy,x,y,val; + px_double oftx,ofty; + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + + if (!pfe->ShowHelpLine) + { + return; + } + oftx=objx; + ofty=objy; + midy=objHeight/2; + incy=objHeight/2/(pfe->VerticalDividing/2); + + //up + for (y=midy;y>=0;y-=incy) + { + //line + PX_GeoDrawLine(psurface,(px_int)(oftx),(px_int)(ofty+y),(px_int)(oftx+objWidth),(px_int)(ofty+y),1,pfe->helpLineColor); + val=(midy-y)/(objHeight/2)*pfe->rangedb; + switch (pfe->FilterType) + { + case PX_OBJECT_FILTER_TYPE_dB: + PX_sprintf1(text,sizeof(text),"+%1.2db",PX_STRINGFORMAT_FLOAT((px_float)val)); + break; + case PX_OBJECT_FILTER_TYPE_Liner: + PX_sprintf1(text,sizeof(text),"+%1.2",PX_STRINGFORMAT_FLOAT((px_float)val)); + break; + } + + //text + PX_FontModuleDrawText(psurface,PX_NULL,(px_int)(oftx-1),(px_int)(ofty+y-5),PX_ALIGN_RIGHTTOP,text,pfe->FontColor); + } + //down + for (y=midy;y<=objHeight;y+=incy) + { + //line + PX_GeoDrawLine(psurface,(px_int)(oftx),(px_int)(ofty+y),(px_int)(oftx+objWidth),(px_int)(ofty+y),1,pfe->helpLineColor); + val=(midy-y)/(objHeight/2)*pfe->rangedb; + switch (pfe->FilterType) + { + case PX_OBJECT_FILTER_TYPE_dB: + PX_sprintf1(text,sizeof(text),"%1.2db",PX_STRINGFORMAT_FLOAT((px_float)val)); + break; + case PX_OBJECT_FILTER_TYPE_Liner: + PX_sprintf1(text,sizeof(text),"%1.2",PX_STRINGFORMAT_FLOAT((px_float)val)); + break; + } + //text + PX_FontModuleDrawText(psurface,PX_NULL,(px_int)(oftx-1),(px_int)(ofty+y-5),PX_ALIGN_RIGHTTOP,text,pfe->FontColor); + } + + //horizontal + incx=objWidth/pfe->HorizontalDividing; + for (x=0;xhelpLineColor); + val=x/objWidth; + //text + if (pfe->showHorizontal) + { + PX_sprintf1(text,sizeof(text),"%1.2",PX_STRINGFORMAT_FLOAT((px_float)val)); + PX_FontModuleDrawText(psurface,PX_NULL,(px_int)(oftx+x-1),(px_int)(ofty+objHeight+3),PX_ALIGN_CENTER,text,pfe->FontColor); + } + } + +} + +px_void PX_Object_FilterEditorCursorReleaseEvent( PX_Object *pObject, PX_Object_Event e,px_void *ptr ) +{ + PX_Object_FilterEditor *pfe=PX_Object_GetFilterEditor(pObject); + + pfe->bSelectDrag=PX_FALSE; + pfe->bAdjust=PX_FALSE; +} + + +px_void PX_Object_FilterEditorRender(px_surface *psurface, PX_Object *pObject,px_uint elapsed) +{ + PX_Object_FilterEditorDrawFrameLine(psurface,pObject); + PX_Object_FilterEditorDrawHelpLine(psurface,pObject); + PX_Object_FilterEditorDrawPt(psurface,pObject); + PX_Object_FilterEditorDrawSelectDraging(psurface,pObject); +} + +px_void PX_Object_FilterEditorCursorPressEvent(PX_Object *pObject, PX_Object_Event e,px_void *ptr) +{ + px_int i,j; + px_bool bSelectlge1=PX_FALSE; + px_float x; + px_float y; + PX_Object_FilterEditor *pfe=PX_Object_GetFilterEditor(pObject); + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + x=(PX_Object_Event_GetCursorX(e)-objx); + y=(PX_Object_Event_GetCursorY(e)-objy); + + + if(!PX_ObjectIsPointInRegion(pObject,PX_Object_Event_GetCursorX(e),PX_Object_Event_GetCursorY(e))) + { + return; + } + + for (i=0;iopCount;i++) + { + if(PX_isPointInCircle(PX_POINT(x,y,0),PX_POINT((px_float)pfe->pt[i].x,(px_float)pfe->pt[i].y,0),(px_float)pfe->radius)) + { + if (!pfe->pt[i].bselect) + { + for (j=0;jopCount;j++) + { + pfe->pt[j].bselect=PX_FALSE; + } + pfe->pt[i].bselect=PX_TRUE; + } + bSelectlge1=PX_TRUE; + } + + } + + if (bSelectlge1) + { + pfe->bSelectDrag=PX_FALSE; + pfe->bAdjust=PX_TRUE; + pfe->lastAdjustPoint.x=(x); + pfe->lastAdjustPoint.y=(y); + } + else + { + for (i=0;iopCount;i++) + { + pfe->pt[i].bselect=PX_FALSE; + } + pfe->DragStartPoint.x=(x); + pfe->DragStartPoint.y=(y); + pfe->DragingPoint=pfe->DragStartPoint; + pfe->bSelectDrag=PX_TRUE; + pfe->bAdjust=PX_FALSE; + } + +} + +px_void PX_Object_FilterEditorCursorMoveEvent(PX_Object *pObject, PX_Object_Event e,px_void *ptr ) +{ + PX_Object_FilterEditor *pfe=PX_Object_GetFilterEditor(pObject); + px_int i; + px_float x,y; + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + x=(PX_Object_Event_GetCursorX(e)-objx); + y=(PX_Object_Event_GetCursorY(e)-objy); + + + if(!PX_ObjectIsPointInRegion(pObject,PX_Object_Event_GetCursorX(e),PX_Object_Event_GetCursorY(e))) + { + return; + } + + for (i=0;iopCount;i++) + { + if(PX_isPointInCircle(PX_POINT(x,y,0),PX_POINT((px_float)pfe->pt[i].x,(px_float)pfe->pt[i].y,0),(px_float)pfe->radius)) + { + pfe->pt[i].bCursor=PX_TRUE; + } + else + { + pfe->pt[i].bCursor=PX_FALSE; + } + } + +} + + +px_void PX_Object_FilterEditorCursorDragEvent(PX_Object *pObject, PX_Object_Event e,px_void *ptr ) +{ + px_int i; + PX_Object_FilterEditor *pfe=PX_Object_GetFilterEditor(pObject); + px_float x,y; + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + x=(PX_Object_Event_GetCursorX(e)-objx); + y=(PX_Object_Event_GetCursorY(e)-objy); + + if (pfe->bSelectDrag) + { + px_rect rect; + + if (x<0) + { + x=0; + } + if (x>objWidth) + { + x=(objWidth); + } + if (y<0) + { + y=0; + } + if (y>objHeight) + { + y=(objHeight); + } + + pfe->DragingPoint.x=(px_float)(x); + pfe->DragingPoint.y=(px_float)(y); + rect=PX_RECT(pfe->DragStartPoint.x,pfe->DragStartPoint.y,x-pfe->DragStartPoint.x,y-pfe->DragStartPoint.y); + for (i=0;iopCount;i++) + { + if(PX_isPointInRect(PX_POINT((px_float)pfe->pt[i].x,(px_float)pfe->pt[i].y,0),rect)) + { + pfe->pt[i].bselect=PX_TRUE; + } + else + { + pfe->pt[i].bselect=PX_FALSE; + } + } + } + + else if (pfe->bAdjust) + { + for (i=0;iopCount;i++) + { + if(pfe->pt[i].bselect==PX_TRUE) + { + pfe->pt[i].y+=(px_int)(y-pfe->lastAdjustPoint.y); + if (pfe->pt[i].y<0) + { + pfe->pt[i].y=0; + } + if (pfe->pt[i].y>objHeight-1) + { + pfe->pt[i].y=(px_int)objHeight-1; + } + } + } + pfe->lastAdjustPoint=PX_POINT(x,y,0); + } +} + + +px_void PX_Object_FilterEditorSetOperateCount(PX_Object *pObject,px_int count) +{ + px_int i; + PX_Object_FilterEditor *pfe=PX_Object_GetFilterEditor(pObject); + px_float Inc; + px_int y; + if (count<2) + { + count=2; + } + if (count>PX_COUNTOF(pfe->pt)) + { + count=PX_COUNTOF(pfe->pt); + } + Inc=pObject->Width/(count-1); + y=(px_int)(pObject->Height/2); + for (i=0;ipt[i].x=(px_int)(Inc*i); + pfe->pt[i].y=y; + } + pfe->opCount=count; +} + +px_void PX_Object_FilterEditorSetType(PX_Object *Object,PX_OBJECT_FILTER_TYPE type) +{ + PX_Object_FilterEditor *pfe=PX_Object_GetFilterEditor(Object); + if (pfe) + { + pfe->FilterType=type; + } +} + +px_void PX_Object_FilterEditorSetHorizontalShow(PX_Object *Object,px_bool HorizontalShow) +{ + PX_Object_FilterEditor *pfe=PX_Object_GetFilterEditor(Object); + if (pfe) + { + pfe->showHorizontal=HorizontalShow; + } +} + +px_void PX_Object_FilterEditorReset(PX_Object *Object) +{ + px_int i,y; + PX_Object_FilterEditor *pfe=PX_Object_GetFilterEditor(Object); + y=(px_int)(Object->Height/2); + for (i=0;iopCount;i++) + { + pfe->pt[i].y=y; + } +} + +px_void PX_Object_FilterEditorSetRange(PX_Object *Object,px_double range) +{ + + PX_Object_FilterEditor *pfe=PX_Object_GetFilterEditor(Object); + if (pfe) + { + pfe->rangedb=range; + } +} + +px_void PX_Object_FilterEditorSetFontColor(PX_Object *Object,px_color clr) +{ + PX_Object_FilterEditor *pfe=PX_Object_GetFilterEditor(Object); + if (pfe) + { + pfe->FontColor=clr; + } +} + +px_void PX_Object_FilterEditorSetBorderColor(PX_Object *Object,px_color clr) +{ + PX_Object_FilterEditor *pfe=PX_Object_GetFilterEditor(Object); + if (pfe) + { + pfe->borderColor=clr; + } +} + +px_void PX_Object_FilterEditorSethelpLineColor(PX_Object *Object,px_color clr) +{ + PX_Object_FilterEditor *pfe=PX_Object_GetFilterEditor(Object); + if (pfe) + { + pfe->helpLineColor=clr; + } +} + +px_void PX_Object_FilterEditorSetFontSize(PX_Object *Object,px_int size) +{ + PX_Object_FilterEditor *pfe=PX_Object_GetFilterEditor(Object); + if (pfe) + { + pfe->FontSize=size; + } +} + +px_void PX_Object_FilterEditorSetHorizontalDividing(PX_Object *Object,px_int div) +{ + PX_Object_FilterEditor *pfe=PX_Object_GetFilterEditor(Object); + if (pfe) + { + pfe->HorizontalDividing=div; + } +} + +px_void PX_Object_FilterEditorSetVerticalDividing(PX_Object *Object,px_int div) +{ + PX_Object_FilterEditor *pfe=PX_Object_GetFilterEditor(Object); + if (pfe) + { + pfe->VerticalDividing=div; + } +} + +px_void PX_Object_FilterEditorMapData(PX_Object *Object,px_double data[],px_int size) +{ + px_int i,mapIndex; + px_double ptValue[PX_OBJECT_FILTER_EDITOR_MAX_PT]; + px_double step,frac,d2,d1,dm; + PX_Object_FilterEditor *pfe=PX_Object_GetFilterEditor(Object); + if (!pfe) + { + return; + } + //pt to value + for (i=0;iopCount;i++) + { + if (pfe->pt[i].y>Object->Height-10) + { + ptValue[i]=-1000; + } + else + { + ptValue[i]=((Object->Height/2)-pfe->pt[i].y)/(Object->Height/2)*pfe->rangedb; + } + } + + step=1.0/(pfe->opCount-1); + + for (i=0;iFilterType) + { + case PX_OBJECT_FILTER_TYPE_dB: + dm=PX_pow_dd(10,dm/20.0); + break; + case PX_OBJECT_FILTER_TYPE_Liner: + break; + } + data[i]=dm; + } +} + +px_double PX_Object_FilterEditorMapValue(PX_Object *pObject,px_double precent) +{ + px_int mapIndex; + px_double step,frac,d2,d1,dm; + PX_Object_FilterEditor *pfe=PX_Object_GetFilterEditor(pObject); + if (!pfe) + { + return 1; + } + + step=1.0/(pfe->opCount-1); + mapIndex=(px_int)(precent/step); + if (mapIndex>pfe->opCount-1) + { + return 1; + } + frac=(precent-mapIndex*step)/step; + d2=((pObject->Height/2)-pfe->pt[mapIndex+1].y)/(pObject->Height/2)*pfe->rangedb; + d1=((pObject->Height/2)-pfe->pt[mapIndex].y)/(pObject->Height/2)*pfe->rangedb; + dm=d1+frac*(d2-d1); + switch(pfe->FilterType) + { + case PX_OBJECT_FILTER_TYPE_dB: + dm=PX_pow_dd(10,dm/20.0); + break; + case PX_OBJECT_FILTER_TYPE_Liner: + break; + } + return dm; +} + +PX_Object * PX_Object_FilterEditorCreate(px_memorypool *mp, PX_Object *Parent,px_int x,px_int y,px_int Width,px_int Height,PX_OBJECT_FILTER_TYPE type) +{ + PX_Object *pObject; + PX_Object_FilterEditor FilterEditor; + PX_memset(&FilterEditor,0,sizeof(FilterEditor)); + FilterEditor.showHorizontal=PX_TRUE; + FilterEditor.borderColor=PX_COLOR(255,0,0,0); + FilterEditor.FontColor=PX_COLOR(255,0,0,0); + FilterEditor.bSelectDrag=PX_FALSE; + FilterEditor.bAdjust=PX_FALSE; + FilterEditor.DragingPoint=PX_POINT(0,0,0); + FilterEditor.DragStartPoint=PX_POINT(0,0,0); + FilterEditor.FontSize=16; + FilterEditor.helpLineColor=PX_COLOR(255,0,0,0); + FilterEditor.ptColor=PX_COLOR(255,0,0,0); + FilterEditor.HorizontalDividing=16; + FilterEditor.VerticalDividing=16; + FilterEditor.ShowHelpLine=PX_TRUE; + FilterEditor.showHorizontal=PX_FALSE; + FilterEditor.FilterType=type; + FilterEditor.rangedb=6; + FilterEditor.radius=PX_OBJECT_FILTER_EDITOR_DEFAULT_RADIUS; + pObject=PX_ObjectCreateEx(mp,Parent,(px_float)x,(px_float)y,0,(px_float)Width,(px_float)Height,0,PX_OBJECT_TYPE_FILTEREDITOR,PX_NULL,PX_Object_FilterEditorRender,PX_NULL,&FilterEditor,sizeof(PX_Object_FilterEditor)); + PX_Object_FilterEditorSetOperateCount(pObject,8); + + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORMOVE,PX_Object_FilterEditorCursorMoveEvent,PX_NULL); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORDRAG,PX_Object_FilterEditorCursorDragEvent,PX_NULL); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORDOWN,PX_Object_FilterEditorCursorPressEvent,PX_NULL); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORUP,PX_Object_FilterEditorCursorReleaseEvent,PX_NULL); + return pObject; +} + +px_void PX_Object_FilterEditorSetborderColor(PX_Object *Object,px_color clr) +{ + PX_Object_FilterEditor *pfe=PX_Object_GetFilterEditor(Object); + pfe->borderColor=clr; +} + + + +px_void PX_Object_FilterEditorSetptColor(PX_Object *Object,px_color clr) +{ + PX_Object_FilterEditor *pfe=PX_Object_GetFilterEditor(Object); + pfe->ptColor=clr; +} + diff --git a/lib/PainterEngine/kernel/PX_Object_Coordinate.h b/lib/PainterEngine/kernel/PX_Object_Coordinate.h new file mode 100644 index 0000000000000000000000000000000000000000..2b2c5793de00e22c62f8db1b2fd378ed58492b9a --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_Coordinate.h @@ -0,0 +1,279 @@ +#ifndef PX_OBJECT_COORDINATE_H +#define PX_OBJECT_COORDINATE_H +#include "PX_Object.h" + +#define PX_OBJECT_COORDINATEDATA_MAP_LEFT 0 +#define PX_OBJECT_COORDINATEDATA_MAP_RIGHT 1 +#define PX_OBJECT_COORDINATEDATA_MAP_HORIZONTAL 2 + +#define PX_OBJECT_COORDINATES_DEFAULE_MINHORIZONTALPIXELDIVIDING 48 +#define PX_OBJECT_COORDINATES_DEFAULE_MINVERTICALPIXELDIVIDING 20 +#define PX_OBJECT_COORDINATES_DEFAULE_DIVIDING 10 +#define PX_OBJECT_COORDINATES_DEFAULT_SPACER 64 +#define PX_OBJECT_COORDINATES_DEFAULT_VERTICALFLAG_OFFSET 8 +#define PX_OBJECT_COORDINATES_DEFAULT_FLAGTEXT_SPACER 8 + +#define PX_OBJECT_COORDINATES_DEFAULT_FRAMELINE_WIDTH 2 +#define PX_OBJECT_COORDINATES_DEFAULT_FONT_SIZE 16 +#define PX_OBJECT_COORDINATES_DEFAULT_DASH_RGB 255,100,100,255 +#define PX_OBJECT_COORDINATES_DEFAULT_LINE_WIDTH 2.0f + +#define PX_OBJECT_COORDINATES_DEFAULT_EXPONENTIAL_FORMAT "%1.2e%2" +#define PX_OBJECT_COORDINATES_DEFAULT_FLOAT_FLAGFORMAT_H "%1.2" +#define PX_OBJECT_COORDINATES_DEFAULT_INT_FLAGFORMAT_H "%1" + +#define PX_OBJECT_COORDINATES_DEFAULT_FLOAT_FLAGFORMAT_L "%1.2" +#define PX_OBJECT_COORDINATES_DEFAULT_INT_FLAGFORMAT_L "%1" + +#define PX_OBJECT_COORDINATES_DEFAULT_FLOAT_FLAGFORMAT_R "%1.2" +#define PX_OBJECT_COORDINATES_DEFAULT_INT_FLAGFORMAT_R "%1" + + +#define PX_OBJECT_COORDINATEFLAGLINE_XSHOW 1 +#define PX_OBJECT_COORDINATEFLAGLINE_YLSHOW 2 +#define PX_OBJECT_COORDINATEFLAGLINE_YRSHOW 4 + +typedef enum +{ + PX_OBJECT_COORDINATES_LINEMODE_LINES=0, + PX_OBJECT_COORDINATES_LINEMODE_PILLAR=1, +}PX_OBJECT_COORDINATES_LINEMODE; + +typedef enum +{ + PX_OBJECT_COORDINATES_GUIDESSHOWMODE_ALL=0, + PX_OBJECT_COORDINATES_GUIDESSHOWMODE_HORIZONTAL=1, + PX_OBJECT_COORDINATES_GUIDESSHOWMODE_VERTICAL=2 +}PX_OBJECT_COORDINATES_GUIDESSHOWMODE; + +typedef enum +{ + PX_OBJECT_COORDINATES_COORDINATEDATA_MAP_LEFT, + PX_OBJECT_COORDINATES_COORDINATEDATA_MAP_RIGHT, +}PX_OBJECT_COORDINATES_COORDINATEDATA_MAP; + +typedef enum +{ + PX_OBJECT_COORDINATES_TEXT_DISPLAYMODE_NORMAL, + PX_OBJECT_COORDINATES_TEXT_DISPLAYMODE_EXPONENTRAL, +}PX_OBJECT_COORDINATES_TEXT_DISPLAYMODE; + + +typedef struct +{ + px_double X,Y; + px_color color; + px_float LineWidth; + px_uchar XYshow; +}PX_Object_CoordinateFlagLine; + +typedef struct +{ + px_double *MapHorizontalArray; + px_double *MapVerticalArray; + px_double Normalization; + px_color Color; + PX_OBJECT_COORDINATES_COORDINATEDATA_MAP Map; + px_int linewidth; + px_int ID; + px_int Visibled; + px_int Size; +}PX_Object_CoordinateData; + + +typedef struct +{ + px_memorypool *mp; + px_double HorizontalRangeMin; + px_double HorizontalRangeMax; + px_double LeftVerticalRangeMin,LeftVerticalRangeMax; + px_double RightVerticalRangeMin,RightVerticalRangeMax; + PX_OBJECT_COORDINATES_TEXT_DISPLAYMODE leftTextDisplayMode,RightTextDisplayMode; + + px_double ResHorizontalRangeMin; + px_double ResHorizontalRangeMax; + px_double ResLeftVerticalRangeMin,ResLeftVerticalRangeMax; + px_double ResRightVerticalRangeMin,ResRightVerticalRangeMax; + + + px_int MinVerticalPixelDividing; + px_int MinHorizontalPixelDividing; + px_int HorizontalDividing; + px_int LeftVerticalDividing; + px_int RightVerticalDividing; + + px_int LeftSpacer,RightSpacer,TopSpacer,BottomSpacer; + + const px_char *Exponential_Format; + const px_char *FloatFlagFormat_H; + const px_char *IntFlagFormat_H; + const px_char *FloatFlagFormat_L; + const px_char *IntFlagFormat_L; + const px_char *FloatFlagFormat_R; + const px_char *IntFlagFormat_R; + const px_char *LeftTitle,*RightTitle,*TopTitle,*BottomTitle; + + px_point DragStartPoint; + px_point DragingPoint; + px_int bScaleDrag; + px_int bScaling; + px_int MarkLineX; + + px_bool ScaleEnabled; + px_bool ShowGuides; + px_bool MarkValueEnabled; + px_bool OnMarkStatus; + px_bool bDataUpdatePainter; + px_bool ShowHelpLine; + + px_bool LeftTextShow,RightTextShow,HorizontalTextShow; + + px_color DashColor; + px_color FontColor; + px_color borderColor; + px_color helpLineColor; + int FontSize; + + PX_OBJECT_COORDINATES_LINEMODE LineMode; + PX_OBJECT_COORDINATES_GUIDESSHOWMODE guidesShowMode; + + px_float DataLineWidth; + px_float DataPillarWidth; + + px_float GuidesLineWidth; + px_vector vData; + px_vector vFlagLine; + + px_int helpLineX,helpLineY; + PX_FontModule *fontmodule; +}PX_Object_Coordinates; + + +PX_Object_Coordinates *PX_Object_GetCoordinates(PX_Object *pObject); +// +px_void PX_Object_CoordinatesSetMinVerticalPixelDividing(PX_Object *pObject,int val); +px_void PX_Object_CoordinatesSetMinHorizontalPixelDividing(PX_Object *pObject,int val); +px_void PX_Object_CoordinatesSetHorizontalDividing(PX_Object *pObject,int Count); +px_void PX_Object_CoordinatesSetLeftVerticalDividing(PX_Object *pObject,int Count); +px_void PX_Object_CoordinatesSetRightVerticalDividing(PX_Object *pObject,int Count); +px_void PX_Object_CoordinatesSetStyle(PX_Object *pObject,PX_OBJECT_COORDINATES_LINEMODE mode); +px_void PX_Object_CoordinatesSetScaleEnabled(PX_Object *pObject,px_bool Enabled); +px_void PX_Object_CoordinatesSetGuidesVisible(PX_Object *pObject,px_bool Visible); +px_void PX_Object_CoordinatesSetGuidesShowMode(PX_Object *pObject,PX_OBJECT_COORDINATES_GUIDESSHOWMODE mode); +px_void PX_Object_CoordinatesShowHelpLine(PX_Object *pObject,px_bool show); + +px_void PX_Object_CoordinatesSetDataLineWidth(PX_Object *pObject,px_float linewidth ); +px_void PX_Object_CoordinatesSetDataShow(PX_Object *pObject,px_int index,px_bool show ); +px_void PX_Object_CoordinatesSetGuidesLineWidth(PX_Object *pObject,px_float linewidth); +px_void PX_Object_CoordinatesSetGuidesLineColor(PX_Object *pObject,px_color clr); +px_void PX_Object_CoordinatesSetTitleFontSize(PX_Object *pObject,int size); +px_void PX_Object_CoordinatesSetTitleFontColor(PX_Object *pObject,px_color clr); +px_void PX_Object_CoordinatesSetDashLineColor(PX_Object *pObject,px_color clr); +px_void PX_Object_CoordinatesSetLeftTextShow(PX_Object *pObject,px_bool bshow); +px_void PX_Object_CoordinatesSetRightTextShow(PX_Object *pObject,px_bool bshow); +px_void PX_Object_CoordinatesSetHorizontalTextShow(PX_Object *pObject,px_bool bshow); +px_void PX_Object_CoordinatesSetFloatFlagFormatHorizontal(PX_Object *pObject,const char *fmt); +px_void PX_Object_CoordinatesSetIntFlagFormatHorizontal(PX_Object *pObject,const char *fmt); +px_void PX_Object_CoordinatesSetFloatFlagFormatVerticalLeft(PX_Object *pObject,const char *fmt); +px_void PX_Object_CoordinatesSetIntFlagFormatVerticalLeft(PX_Object *pObject,const char *fmt); +px_void PX_Object_CoordinatesSetFloatFlagFormatVerticalRight(PX_Object *pObject,const char *fmt); +px_void PX_Object_CoordinatesSetIntFlagFormatVericalRight(PX_Object *pObject,const char *fmt); + + +px_void PX_Object_CoordinatesSetLeftTextMode(PX_Object *pObject,PX_OBJECT_COORDINATES_TEXT_DISPLAYMODE mode); +px_void PX_Object_CoordinatesSetRightTextMode(PX_Object *pObject,PX_OBJECT_COORDINATES_TEXT_DISPLAYMODE mode); +px_void PX_Object_CoordinatesSetHorizontalMin(PX_Object *pObject,double Min); +px_void PX_Object_CoordinatesSetHorizontalMax(PX_Object *pObject,double Max); +px_void PX_Object_CoordinatesSetLeftVerticalMin(PX_Object *pObject,double Min); +px_void PX_Object_CoordinatesSetLeftVerticalMax(PX_Object *pObject,double Max); +px_void PX_Object_CoordinatesSetRightVerticalMax(PX_Object *pObject,double Max); +px_void PX_Object_CoordinatesSetRightVerticalMin(PX_Object *pObject,double Min); + +px_void PX_Object_CoordinatesSetBorderColor(PX_Object *pObject,px_color clr); +PX_Object_CoordinateData *PX_Object_CoordinatesGetCoordinateData(PX_Object *pObject,px_int index); +int PX_Object_CoordinatesGetCoordinateWidth(PX_Object *pObject); +int PX_Object_CoordinatesGetCoordinateHeight(PX_Object *pObject); +//px_void PX_Object_CoordinatesSetTitleLeft(PX_Object *pObject,const px_char * title); +//px_void PX_Object_CoordinatesSetTitleRight(PX_Object *pObject,const px_char * title); +px_void PX_Object_CoordinatesSetTitleTop(PX_Object *pObject,const px_char * title); +px_void PX_Object_CoordinatesSetTitleBottom(PX_Object *pObject,const px_char * title); + + +px_void PX_Object_CoordinatesSetMarkValueEnabled(PX_Object *pObject,px_bool Enabled); +px_void PX_Object_CoordinatesSetFontColor(PX_Object *pObject,px_color clr); +px_void PX_Object_CoordinatesClearContext(PX_Object *pObject); +px_void PX_Object_CoordinatesClearFlagLine(PX_Object *pObject); +px_void PX_Object_CoordinatesAddData(PX_Object *pObject,PX_Object_CoordinateData data); +px_void PX_Object_CoordinatesAddCoordinateFlagLine(PX_Object *pObject,PX_Object_CoordinateFlagLine Line); +// +px_void PX_Object_CoordinatesSetMargin(PX_Object *pObject,px_int Left,px_int Right,px_int Top,px_int Bottom); +px_void PX_Object_CoordinatesRestoreCoordinates(PX_Object *pObject); +PX_Object *PX_Object_CoordinatesCreate(px_memorypool *mp, PX_Object *Parent,px_int x,px_int y,px_int Width,px_int Height,PX_FontModule *fontmodule); + + +#define PX_OBJECT_FILTER_EDITOR_MAX_PT 256 +#define PX_OBJECT_FILTER_EDITOR_DEFAULT_RADIUS 6 + +typedef enum +{ + PX_OBJECT_FILTER_TYPE_Liner, + PX_OBJECT_FILTER_TYPE_dB, +}PX_OBJECT_FILTER_TYPE; + + +typedef struct +{ + px_int x,y; + px_bool bselect; + px_bool bCursor; +}PX_Object_FilterEditor_OperatorPoint; + + +typedef struct +{ + px_bool ShowHelpLine; + px_color FontColor; + px_color borderColor; + px_color helpLineColor; + px_color ptColor; + px_bool showHorizontal; + int FontSize; + px_int HorizontalDividing; + px_int VerticalDividing; + px_point DragStartPoint; + px_point lastAdjustPoint; + px_point DragingPoint; + px_int bSelectDrag; + px_int bAdjust; + px_int opCount; + px_int radius; + px_double rangedb; + PX_OBJECT_FILTER_TYPE FilterType; + PX_Object_FilterEditor_OperatorPoint pt[PX_OBJECT_FILTER_EDITOR_MAX_PT]; +}PX_Object_FilterEditor; + +PX_Object_FilterEditor *PX_Object_GetFilterEditor(PX_Object *Object); + +PX_Object *PX_Object_FilterEditorCreate(px_memorypool *mp, PX_Object *Parent,px_int x,px_int y,px_int Width,px_int Height,PX_OBJECT_FILTER_TYPE type); +px_void PX_Object_FilterEditorSethelpLineColor(PX_Object *Object,px_color clr); +px_void PX_Object_FilterEditorSetptColor(PX_Object *Object,px_color clr); + +px_void PX_Object_FilterEditorSetOperateCount(PX_Object *Object,px_int opcount); +px_void PX_Object_FilterEditorSetType(PX_Object *Object,PX_OBJECT_FILTER_TYPE type); +px_void PX_Object_FilterEditorSetHorizontalShow(PX_Object *Object,px_bool HorizontalShow); +px_void PX_Object_FilterEditorReset(PX_Object *Object); +px_void PX_Object_FilterEditorSetRange(PX_Object *Object,px_double range); +px_void PX_Object_FilterEditorSetFontColor(PX_Object *Object,px_color clr); +px_void PX_Object_FilterEditorSetBorderColor(PX_Object *Object,px_color clr); +px_void PX_Object_FilterEditorSethelpLineColor(PX_Object *Object,px_color clr); +px_void PX_Object_FilterEditorSetFontSize(PX_Object *Object,px_int size); +px_void PX_Object_FilterEditorSetHorizontalDividing(PX_Object *Object,px_int div); +px_void PX_Object_FilterEditorSetVerticalDividing(PX_Object *Object,px_int div); +px_void PX_Object_FilterEditorMapData(PX_Object *Object,px_double data[],px_int size); +px_double PX_Object_FilterEditorMapValue(PX_Object *Object,px_double precent); + + + + +#endif + diff --git a/lib/PainterEngine/kernel/PX_Object_CursorButton.c b/lib/PainterEngine/kernel/PX_Object_CursorButton.c new file mode 100644 index 0000000000000000000000000000000000000000..c95a4f4c6982732907c6d0b3e5e3595328d70ecb --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_CursorButton.c @@ -0,0 +1,161 @@ +#include "PX_Object_CursorButton.h" + + +px_void PX_Object_CursorButtonRender(px_surface *psurface, PX_Object *pObject,px_uint elapsed) +{ + px_float w,h,_x,_y; + px_uchar alpha; + PX_Object_CursorButton *pcb; + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + + w=objWidth/4.f; + h=objHeight/4.f; + pcb=PX_Object_GetCursorButton(pObject); + if (!pcb) + { + return; + } + pcb->pushbutton->x=0; + pcb->pushbutton->y=0; + pcb->pushbutton->z=0; + + if(pcb->enter) + { + if(PX_ABS(pcb->c_distance-pcb->c_distance_near)>=1) + pcb->c_distance+=(pcb->c_distance_near-pcb->c_distance)*(elapsed*1.f/200); + else + pcb->c_distance=pcb->c_distance_near; + } + else + { + if(PX_ABS(pcb->c_distance-pcb->c_distance_far)>=1) + pcb->c_distance+=(pcb->c_distance_far-pcb->c_distance)*(elapsed*1.f/200); + else + pcb->c_distance=pcb->c_distance_far; + } + alpha=(px_uchar)(PX_ABS(pcb->c_distance-pcb->c_distance_far)/PX_ABS(pcb->c_distance_far-pcb->c_distance_near)*255); + pcb->c_color._argb.a=alpha; + //left top + _x=objx-pcb->c_distance-1; + _y=objy-pcb->c_distance-1; + PX_GeoDrawRect(psurface,(px_int)_x,(px_int)_y,(px_int)(_x+w),(px_int)_y+pcb->c_width,pcb->c_color); + PX_GeoDrawRect(psurface,(px_int)_x,(px_int)_y+pcb->c_width+1,(px_int)_x+pcb->c_width,(px_int)(_y+h),pcb->c_color); + + //left bottom + _x=objx-pcb->c_distance-1; + _y=objy+objHeight+pcb->c_distance; + PX_GeoDrawRect(psurface,(px_int)_x,(px_int)_y,(px_int)(_x+w),(px_int)_y-pcb->c_width,pcb->c_color); + PX_GeoDrawRect(psurface,(px_int)_x,(px_int)_y-pcb->c_width-1,(px_int)_x+pcb->c_width,(px_int)(_y-h),pcb->c_color); + + //right top + _x=objx+objWidth+pcb->c_distance; + _y=objy-pcb->c_distance-1; + PX_GeoDrawRect(psurface,(px_int)_x,(px_int)_y,(px_int)(_x-w),(px_int)_y+pcb->c_width,pcb->c_color); + PX_GeoDrawRect(psurface,(px_int)_x,(px_int)_y+pcb->c_width+1,(px_int)_x-pcb->c_width,(px_int)(_y+h),pcb->c_color); + + //right bottom + _x=objx+objWidth+pcb->c_distance; + _y=objy+objHeight+pcb->c_distance; + PX_GeoDrawRect(psurface,(px_int)_x,(px_int)_y,(px_int)(_x-w),(px_int)_y-pcb->c_width,pcb->c_color); + PX_GeoDrawRect(psurface,(px_int)_x,(px_int)_y-pcb->c_width-1,(px_int)_x-pcb->c_width,(px_int)(_y-h),pcb->c_color); +} + +px_void PX_Object_CursorButtonFree( PX_Object *Obj ) +{ + +} +px_void PX_Object_CursorButtonOnMouseMove(PX_Object *Object,PX_Object_Event e,px_void *user_ptr) +{ + + PX_Object_CursorButton *pCB=PX_Object_GetCursorButton(Object); + px_float x,y; + x=PX_Object_Event_GetCursorX(e); + y=PX_Object_Event_GetCursorY(e); + + if(PX_ObjectIsPointInRegion(Object,(px_float)x,(px_float)y)) + { + if (!pCB->enter) + { + pCB->enter=PX_TRUE; + //pCB->c_distance=pCB->c_distance_far; + } + } + else + { + if (pCB->enter) + { + pCB->enter=PX_FALSE; + //pCB->c_distance=pCB->c_distance_near; + } + } +} + +PX_Object *PX_Object_CursorButtonCreate(px_memorypool *mp,PX_Object *Parent,px_int x,px_int y,px_int Width,px_int Height,const px_char *Text,PX_FontModule *fontmodule,px_color Color) +{ + PX_Object *pObject; + PX_Object_CursorButton *pCb=(PX_Object_CursorButton *)MP_Malloc(mp,sizeof(PX_Object_CursorButton)); + if (pCb==PX_NULL) + { + return PX_NULL; + } + pObject=PX_ObjectCreate(mp,Parent,(px_float)x,(px_float)y,0,(px_float)Width,(px_float)Height,0); + if (pObject==PX_NULL) + { + MP_Free(pObject->mp,pCb); + return PX_NULL; + } + pObject->pObject=pCb; + pObject->Enabled=PX_TRUE; + pObject->Visible=PX_TRUE; + pObject->Type=PX_OBJECT_TYPE_CURSORBUTTON; + pObject->ReceiveEvents=PX_TRUE; + pObject->Func_ObjectFree=PX_NULL; + pObject->Func_ObjectUpdate=PX_NULL; + pObject->Func_ObjectRender=PX_Object_CursorButtonRender; + + + pCb->pushbutton=PX_Object_PushButtonCreate(mp,pObject,x,y,Width,Height,Text,fontmodule); + pCb->c_color= PX_OBJECT_UI_DEFAULT_BORDERCOLOR; + pCb->c_distance=0; + pCb->c_distance_far=(px_float)(Width>Height?Height/4:Width/4); + pCb->c_distance_near=3; + pCb->enter=PX_FALSE; + if (Height<16) + { + pCb->c_width=1; + } + else + pCb->c_width=Height/16; + + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORMOVE,PX_Object_CursorButtonOnMouseMove,PX_NULL); + return pObject; +} +PX_Object_CursorButton * PX_Object_GetCursorButton( PX_Object *Object ) +{ + if(Object->Type==PX_OBJECT_TYPE_CURSORBUTTON) + return (PX_Object_CursorButton *)Object->pObject; + else + return PX_NULL; +} + +PX_Object * PX_Object_GetCursorButtonPushButton(PX_Object *Object) +{ + PX_Object_CursorButton *pcb; + pcb=PX_Object_GetCursorButton(Object); + if (!pcb) + { + return PX_NULL; + } + return pcb->pushbutton; +} + + diff --git a/lib/PainterEngine/kernel/PX_Object_CursorButton.h b/lib/PainterEngine/kernel/PX_Object_CursorButton.h new file mode 100644 index 0000000000000000000000000000000000000000..dcce202bfbec9c0f532a25af9f1827f8169cf951 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_CursorButton.h @@ -0,0 +1,22 @@ +#ifndef PX_OBJECT_CURSORBUTTON_H +#define PX_OBJECT_CURSORBUTTON_H +#include "PX_Object.h" + +typedef struct +{ + PX_Object *pushbutton; + px_float c_distance; + px_float c_distance_far; + px_float c_distance_near; + px_color c_color; + px_int c_width; + px_bool enter; +}PX_Object_CursorButton; + +//use pushbutton function to operate cursor-button +PX_Object *PX_Object_CursorButtonCreate(px_memorypool *mp,PX_Object *Parent,px_int x,px_int y,px_int Width,px_int Height,const px_char *Text,PX_FontModule *fontmodule,px_color Color); +PX_Object_CursorButton * PX_Object_GetCursorButton( PX_Object *Object ); +PX_Object * PX_Object_GetCursorButtonPushButton(PX_Object *Object); + +#endif + diff --git a/lib/PainterEngine/kernel/PX_Object_DesignerBox.c b/lib/PainterEngine/kernel/PX_Object_DesignerBox.c new file mode 100644 index 0000000000000000000000000000000000000000..e02e889621a295c83514e22ec69c746ecbb8d38d --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_DesignerBox.c @@ -0,0 +1,249 @@ +#include "PX_Object_DesignerBox.h" +#include "PX_Object_DesignerBox.h" + +px_void PX_Object_DesignerBoxRender(px_surface *pSurface,PX_Object *pObject,px_dword elapsed) +{ + PX_Object_DesignerBox*pDesc=PX_ObjectGetDesc(PX_Object_DesignerBox,pObject); + px_color renderColor; + + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + renderColor=pDesc->borderColor; + renderColor._argb.a/=2; + + PX_GeoDrawBorder(pSurface, (px_int)objx, (px_int)objy, (px_int)(objx + objWidth), (px_int)(objy + objHeight), 1, renderColor); + + ////////////////////////////////////////////////////////////////////////// + //controller point + renderColor=pDesc->borderColor; + renderColor._argb.a/=2; + + PX_GeoDrawSolidCircle(pSurface,(px_int)(objx),(px_int)(objy),5,renderColor); + PX_GeoDrawSolidCircle(pSurface,(px_int)(objx+objWidth),(px_int)(objy),5,renderColor); + PX_GeoDrawSolidCircle(pSurface,(px_int)(objx),(px_int)(objy+objHeight),5,renderColor); + PX_GeoDrawSolidCircle(pSurface,(px_int)(objx+objWidth),(px_int)(objy+objHeight),5,renderColor); + +} + +px_void PX_Object_DesignerBoxOnCursorDown(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + px_float x,y; + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + PX_Object_DesignerBox *pDesc=PX_ObjectGetDesc(PX_Object_DesignerBox,pObject); + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + x=PX_Object_Event_GetCursorX(e); + y=PX_Object_Event_GetCursorY(e); + + + pDesc->bselect=PX_Object_DesignerBox_bselect_none; + + if ((x-objx)*(x-objx)+(y-objy)*(y-objy)<25) + { + pDesc->bselect=PX_Object_DesignerBox_bselect_lefttop; + return; + } + + if ((x-objx-objWidth)*(x-objx-objWidth)+(y-objy)*(y-objy)<25) + { + pDesc->bselect=PX_Object_DesignerBox_bselect_righttop; + return; + } + + if ((x-objx)*(x-objx)+(y-objy-objHeight)*(y-objy-objHeight)<25) + { + pDesc->bselect=PX_Object_DesignerBox_bselect_leftbottom; + return; + } + + if ((x-objx-objWidth)*(x-objx-objWidth)+(y-objy-objHeight)*(y-objy-objHeight)<25) + { + pDesc->bselect=PX_Object_DesignerBox_bselect_rightbottom; + return; + } + + if (PX_ObjectIsCursorInRegion(pObject,e)) + { + pDesc->bselect=PX_Object_DesignerBox_bselect_center; + pDesc->lastx = x; + pDesc->lasty = y; + return; + } + + + + +} + + + +px_void PX_Object_DesignerBoxOnCursorDrag(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + px_float x,y; + PX_Object_DesignerBox*pDesc=PX_ObjectGetDesc(PX_Object_DesignerBox,pObject); + px_float objx, objy, objWidth, objHeight; + px_float inheritX, inheritY; + PX_ObjectGetInheritXY(pObject, &inheritX, &inheritY); + + objx = (pObject->x + inheritX); + objy = (pObject->y + inheritY); + objWidth = pObject->Width; + objHeight = pObject->Height; + + + x=PX_Object_Event_GetCursorX(e); + y=PX_Object_Event_GetCursorY(e); + + switch (pDesc->bselect) + { + case PX_Object_DesignerBox_bselect_center: + { + + pObject->x+=x-pDesc->lastx; + pObject->y+=y-pDesc->lasty; + pDesc->lastx= x; + pDesc->lasty =y; + PX_ObjectExecuteEvent(pObject, PX_OBJECT_BUILD_EVENT(PX_OBJECT_EVENT_VALUECHANGED)); + } + break; + case PX_Object_DesignerBox_bselect_lefttop: + { + px_float widthinc,heightinc; + widthinc=objx-x; + heightinc=objy-y; + + if (objWidth+widthinc<=10) + { + return; + } + + if (objHeight+heightinc<=10) + { + return; + } + + pObject->x=x-inheritX; + pObject->y=y-inheritY; + pObject->Width+=widthinc; + pObject->Height+=heightinc; + PX_ObjectExecuteEvent(pObject, PX_OBJECT_BUILD_EVENT(PX_OBJECT_EVENT_VALUECHANGED)); + } + break; + case PX_Object_DesignerBox_bselect_righttop: + { + px_float widthinc,heightinc; + widthinc=x-objx-objWidth; + heightinc=objy-y; + + if (objWidth+widthinc<=10) + { + return; + } + + if (objHeight+heightinc<=10) + { + return; + } + + pObject->y=y-inheritY; + + pObject->Width+=widthinc; + pObject->Height+=heightinc; + PX_ObjectExecuteEvent(pObject, PX_OBJECT_BUILD_EVENT(PX_OBJECT_EVENT_VALUECHANGED)); + } + break; + case PX_Object_DesignerBox_bselect_leftbottom: + { + px_float widthinc,heightinc; + widthinc=objx-x; + heightinc=y-objy-objHeight; + + if (pObject->Width+widthinc<=10) + { + return; + } + + if (pObject->Height+heightinc<=10) + { + return; + } + + pObject->x=x-inheritX; + + pObject->Width+=widthinc; + pObject->Height+=heightinc; + PX_ObjectExecuteEvent(pObject, PX_OBJECT_BUILD_EVENT(PX_OBJECT_EVENT_VALUECHANGED)); + } + break; + + case PX_Object_DesignerBox_bselect_rightbottom: + { + px_float widthinc,heightinc; + widthinc=x-objx-objWidth; + heightinc=y-objy-objHeight; + + if (pObject->Width+widthinc<=10) + { + return; + } + + if (pObject->Height+heightinc<=10) + { + return; + } + + pObject->Width+=widthinc; + pObject->Height+=heightinc; + PX_ObjectExecuteEvent(pObject, PX_OBJECT_BUILD_EVENT(PX_OBJECT_EVENT_VALUECHANGED)); + } + break; + default: + break; + } + +} + +PX_Object * PX_Object_DesignerBoxCreate(px_memorypool *mp,PX_Object *Parent,px_float x,px_float y,px_float widht,px_float height) +{ + PX_Object_DesignerBox desc; + PX_Object *pObject; + PX_memset(&desc, 0, sizeof(desc)); + + + desc.borderColor=PX_OBJECT_UI_DEFAULT_FONTCOLOR; + + pObject=PX_ObjectCreateEx(mp,Parent,x,y,0,widht,height,0,PX_OBJECT_TYPE_DESIGNERBOX,PX_NULL,PX_Object_DesignerBoxRender,PX_NULL,&desc,sizeof(desc)); + PX_ObjectRegisterEvent(pObject, PX_OBJECT_EVENT_CURSORDOWN, PX_Object_DesignerBoxOnCursorDown, PX_NULL); + PX_ObjectRegisterEvent(pObject, PX_OBJECT_EVENT_CURSORDRAG, PX_Object_DesignerBoxOnCursorDrag, PX_NULL); + return pObject; + +} + +PX_Object_DesignerBox* PX_Object_GetDesignerBox(PX_Object *pObject) +{ + return PX_ObjectGetDesc(PX_Object_DesignerBox, pObject); +} + +px_void PX_Object_DesignerBoxReset(PX_Object* pObject, px_float x, px_float y, px_float width, px_float height) +{ + PX_Object_DesignerBox* pDesc = PX_ObjectGetDesc(PX_Object_DesignerBox, pObject); + pObject->x = x; + pObject->y = y; + pObject->Width = width; + pObject->Height = height; +} + diff --git a/lib/PainterEngine/kernel/PX_Object_DesignerBox.h b/lib/PainterEngine/kernel/PX_Object_DesignerBox.h new file mode 100644 index 0000000000000000000000000000000000000000..511fd4e418840b45c2ab4f55ca39a6053407103e --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_DesignerBox.h @@ -0,0 +1,29 @@ +#ifndef PX_OBJECT_DESIGNERBOX_H +#define PX_OBJECT_DESIGNERBOX_H +#include "PX_Object.h" + +typedef enum +{ + PX_Object_DesignerBox_bselect_none=0, + PX_Object_DesignerBox_bselect_center, + PX_Object_DesignerBox_bselect_lefttop, + PX_Object_DesignerBox_bselect_righttop, + PX_Object_DesignerBox_bselect_leftbottom, + PX_Object_DesignerBox_bselect_rightbottom, +}PX_Object_DesignerBox_bselect; + + +typedef struct +{ + px_float lastx, lasty; + + px_color borderColor; + PX_Object_DesignerBox_bselect bselect; +}PX_Object_DesignerBox; + +PX_Object * PX_Object_DesignerBoxCreate(px_memorypool *mp,PX_Object *Parent,px_float x,px_float y,px_float width,px_float height); +PX_Object_DesignerBox* PX_Object_GetDesignerBox(PX_Object *pObject ); +px_void PX_Object_DesignerBoxReset(PX_Object* pObject, px_float x, px_float y, px_float widht, px_float height); + +#endif + diff --git a/lib/PainterEngine/kernel/PX_Object_Edit.c b/lib/PainterEngine/kernel/PX_Object_Edit.c new file mode 100644 index 0000000000000000000000000000000000000000..09329a2e33593c2d2010a842aa8a3e5fc678e032 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_Edit.c @@ -0,0 +1,961 @@ +#include "PX_Object_Edit.h" + + +px_void PX_Object_EditGetCursorXY(PX_Object *pObject, px_int *cx, px_int *cy, px_int *height) +{ + px_int x = 0, y = 0, cursor = 0, fsize = 0; + PX_Object_Edit *pEdit = (PX_Object_Edit *)pObject->pObject; + const px_char *Text = pEdit->text.buffer; + px_float objx, objy, objWidth, objHeight; + px_float inheritX, inheritY; + + PX_ObjectGetInheritXY(pObject, &inheritX, &inheritY); + + objx = (pObject->x + inheritX); + objy = (pObject->y + inheritY); + objWidth = pObject->Width; + objHeight = pObject->Height; + + + if (pEdit == PX_NULL) + { + return; + } + + x = pEdit->HorizontalOffset; + y = pEdit->VerticalOffset; + + + + while (PX_TRUE) + { + fsize = 0; + + if (cursor == pEdit->cursor_index) + { + *cx = x; + *cy = y; + *height = pEdit->fontModule ? pEdit->fontModule->max_Height : __PX_FONT_HEIGHT; + return; + } + + if (pEdit->fontModule) + { + px_dword code; + px_int width, height; + fsize = PX_FontModuleGetCharacterDesc(pEdit->fontModule, Text + cursor, &code, &width, &height); + if (!fsize) + { + break; + } + if (code == '\r') + { + //skip + } + else if (code == '\n') + { + x = 0; + y += pEdit->fontModule->max_Height + pEdit->yFontSpacing; + } + else + { + x += width + pEdit->xFontSpacing; + } + + if (pEdit->AutoNewline) + { + if (x > objWidth - pEdit->AutoNewLineSpacing) + { + x = 0; + y += pEdit->fontModule->max_Height + pEdit->yFontSpacing; + } + } + + } + else + { + fsize = 1; + + if (Text[cursor] == '\r') + { + //skip + } + else if (Text[cursor] == '\n') + { + x = pEdit->HorizontalOffset; + y += __PX_FONT_HEIGHT + pEdit->yFontSpacing; + } + else if (Text[cursor]) + { + x += __PX_FONT_ASCSIZE + pEdit->xFontSpacing; + } + else + { + break; + } + + if (pEdit->AutoNewline) + { + if (x > objWidth - pEdit->AutoNewLineSpacing) + { + x = 0; + y += __PX_FONT_HEIGHT + pEdit->yFontSpacing; + } + } + } + cursor += fsize; + } + + *cx = x; + *cy = y; + *height = pEdit->fontModule ? pEdit->fontModule->max_Height : __PX_FONT_HEIGHT; +} + +px_void PX_Object_EditUpdateCursorViewRegion(PX_Object *pObject) +{ + px_int cursorX, cursorY, cursorHeight; + PX_Object_Edit *pEdit = (PX_Object_Edit *)pObject->pObject; + px_float objWidth, objHeight; + objWidth = pObject->Width; + objHeight = pObject->Height; + + if (pEdit == PX_NULL) + { + return; + } + + + PX_Object_EditGetCursorXY(pObject, &cursorX, &cursorY, &cursorHeight); + + + if (cursorX > objWidth - 8) + { + pEdit->XOffset = cursorX - (px_int)objWidth + 8; + } + else + { + pEdit->XOffset = 0; + } + + if (cursorY + cursorHeight > objHeight - 2) + { + pEdit->YOffset = cursorY + cursorHeight - (px_int)objHeight + 2; + } + else + { + pEdit->YOffset = 0; + } + +} + +px_void PX_Object_EditOnMouseMove(PX_Object *Object,PX_Object_Event e,px_void *user_ptr) +{ + PX_Object_Edit *pEdit=PX_Object_GetEdit(Object); + px_float x,y; + x=PX_Object_Event_GetCursorX(e); + y=PX_Object_Event_GetCursorY(e); + + if (pEdit) + { + if(PX_ObjectIsPointInRegion(Object,(px_float)x,(px_float)y)) + { + pEdit->state=PX_OBJECT_EDIT_STATE_ONCURSOR; + } + else + { + pEdit->state=PX_OBJECT_EDIT_STATE_NORMAL; + } + } +} +px_void PX_Object_EditUpdateCursorOnDown(PX_Object *pObject,px_int cx,px_int cy); +px_void PX_Object_EditOnMouseLButtonDown(PX_Object *Object,PX_Object_Event e,px_void *user_ptr) +{ + PX_Object_Edit *pEdit=PX_Object_GetEdit(Object); + px_float x,y; + px_float objx,objy; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(Object,&inheritX,&inheritY); + + objx=(Object->x+inheritX); + objy=(Object->y+inheritY); + + x=PX_Object_Event_GetCursorX(e); + y=PX_Object_Event_GetCursorY(e); + + if (pEdit) + { + if(PX_ObjectIsPointInRegion(Object,(px_float)x,(px_float)y)) + { + PX_Object_EditSetFocus(Object,PX_TRUE); + PX_Object_EditUpdateCursorOnDown(Object,(px_int)(x-objx),(px_int)(y-objy)); + } + else + PX_Object_EditSetFocus(Object,PX_FALSE); + } +} + +px_void PX_Object_EditOnKeyboardString(PX_Object *Object,PX_Object_Event e,px_void *user_ptr) +{ + PX_Object_Edit *pEdit=PX_Object_GetEdit(Object); + + if (pEdit->onFocus) + { + PX_Object_EditAddString(Object,PX_Object_Event_GetStringPtr(e)); + } +} + +static px_void PX_Object_EditCheckCursor(PX_Object_Edit*pedit) +{ + if (pedit->cursor_index<0) + { + pedit->cursor_index=0; + } + if (pedit->cursor_index>PX_strlen(pedit->text.buffer)) + { + pedit->cursor_index=PX_strlen(pedit->text.buffer); + } +} + +PX_Object* PX_Object_EditCreate(px_memorypool *mp, PX_Object *Parent,px_int x,px_int y,px_int Width,px_int Height,PX_FontModule *fontModule ) +{ + PX_Object *pObject; + PX_Object_Edit *pEdit=(PX_Object_Edit *)MP_Malloc(mp,sizeof(PX_Object_Edit)); + if (pEdit==PX_NULL) + { + return PX_NULL; + } + pObject=PX_ObjectCreate(mp,Parent,(px_float)x,(px_float)y,0,(px_float)Width,(px_float)Height,0); + + if (pObject==PX_NULL) + { + return PX_NULL; + } + + if (!pObject) + { + MP_Free(mp,pEdit); + return PX_NULL; + } + + if(!PX_SurfaceCreate(mp,Width,Height,&pEdit->EditSurface)) + { + MP_Free(mp,pEdit); + MP_Free(mp,pObject); + return PX_NULL; + } + + pObject->pObject=pEdit; + pObject->Type=PX_OBJECT_TYPE_EDIT; + pObject->ReceiveEvents=PX_TRUE; + pObject->Func_ObjectFree=PX_Object_EditFree; + pObject->Func_ObjectRender=PX_Object_EditRender; + + + + PX_StringInitialize(mp,&pEdit->text); + + + pEdit->TextColor=PX_OBJECT_UI_DEFAULT_FONTCOLOR; + + pEdit->CursorColor=PX_COLOR_WHITE; + pEdit->BorderColor=PX_OBJECT_UI_DEFAULT_BORDERCOLOR; + pEdit->BackgroundColor=PX_OBJECT_UI_DEFAULT_BACKGROUNDCOLOR; + pEdit->XOffset=0; + pEdit->YOffset=0; + pEdit->Border=PX_TRUE; + pEdit->Password=PX_FALSE; + pEdit->onFocus=PX_FALSE; + pEdit->state=PX_OBJECT_EDIT_STATE_NORMAL; + pEdit->AutoNewline=PX_FALSE; + pEdit->xFontSpacing=0; + pEdit->yFontSpacing=0; + pEdit->HorizontalOffset=3; + pEdit->VerticalOffset=3; + pEdit->cursor_index=0; + pEdit->max_length=-1; + pEdit->fontModule=fontModule; + pEdit->AutoNewLineSpacing=__PX_FONT_ASCSIZE+2; + pEdit->style=PX_OBJECT_EDIT_STYLE_RECT; + pEdit->multiLines=PX_FALSE; + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORMOVE,PX_Object_EditOnMouseMove,PX_NULL); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORDOWN,PX_Object_EditOnMouseLButtonDown,PX_NULL); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_STRING,PX_Object_EditOnKeyboardString,PX_NULL); + + return pObject; +} + +PX_Object_Edit * PX_Object_GetEdit( PX_Object *Object ) +{ + if(Object->Type==PX_OBJECT_TYPE_EDIT) + return (PX_Object_Edit *)Object->pObject; + else + return PX_NULL; +} + +px_char * PX_Object_EditGetText( PX_Object *Object ) +{ + PX_Object_Edit *pEdit=PX_Object_GetEdit(Object); + if (pEdit!=PX_NULL) + { + return pEdit->text.buffer; + } + return PX_NULL; +} + +px_void PX_Object_EditSetMaxTextLength(PX_Object *pObject,px_int max_length) +{ + PX_Object_Edit *pEdit=PX_Object_GetEdit(pObject); + if (pEdit!=PX_NULL) + { + pEdit->max_length=max_length; + } +} + +px_void PX_Object_EditSetText( PX_Object *pObject,const px_char *Text ) +{ + PX_Object_Edit *pEdit=PX_Object_GetEdit(pObject); + if(pEdit) + { + PX_StringClear(&pEdit->text); + PX_StringCat(&pEdit->text,Text); + pEdit->cursor_index=PX_strlen(Text); + PX_Object_EditUpdateCursorViewRegion(pObject); + } +} + +px_void PX_Object_EditAppendText(PX_Object *pObject,const px_char *Text) +{ + PX_Object_Edit *pEdit=PX_Object_GetEdit(pObject); + if(pEdit) + { + PX_StringCat(&pEdit->text,Text); + pEdit->cursor_index=PX_strlen(Text); + PX_Object_EditUpdateCursorViewRegion(pObject); + } +} + +px_void PX_Object_EditSetFocus(PX_Object *pObject,px_bool OnFocus) +{ + PX_Object_Edit *pEdit=PX_Object_GetEdit(pObject); + if(pEdit) + { + if (pEdit->onFocus!=OnFocus) + { + if (OnFocus) + { + PX_Object_Event e; + pEdit->onFocus=OnFocus; + e.Event=PX_OBJECT_EVENT_ONFOCUS; + e.Param_bool[0]=OnFocus; + PX_ObjectPostEvent(pObject,e); + } + else + { + PX_Object_Event e; + pEdit->onFocus=OnFocus; + e.Event=PX_OBJECT_EVENT_LOSTFOCUS; + e.Param_bool[0]=OnFocus; + PX_ObjectPostEvent(pObject,e); + } + + } + + } +} + +px_void PX_Object_EditSetPasswordStyle( PX_Object *pLabel,px_uchar Enabled ) +{ + PX_Object_Edit *pEdit=PX_Object_GetEdit(pLabel); + if (pEdit) + { + pEdit->Password=Enabled; + pEdit->fontModule=PX_NULL; + } +} +px_void PX_Object_EditSetBackgroundColor( PX_Object *pObject,px_color Color ) +{ + PX_Object_Edit * pEdit=PX_Object_GetEdit(pObject); + if (pEdit) + { + pEdit->BackgroundColor=Color; + } +} + +px_void PX_Object_EditSetBorderColor( PX_Object *pObject,px_color Color ) +{ + PX_Object_Edit * pEdit=PX_Object_GetEdit(pObject); + if (pEdit) + { + + pEdit->BorderColor=Color; + } +} + +px_void PX_Object_EditSetCursorColor( PX_Object *pObject,px_color Color ) +{ + PX_Object_Edit * pEdit=PX_Object_GetEdit(pObject); + if (pEdit) + { + + pEdit->CursorColor=Color; + } +} + +px_void PX_Object_EditSetTextColor(PX_Object *pObject,px_color Color) +{ + PX_Object_Edit * pEdit=PX_Object_GetEdit(pObject); + if (pEdit) + { + pEdit->TextColor=Color; + } +} + +px_void PX_Object_EditSetLimit(PX_Object *pObject,const px_char *Limit) +{ + PX_Object_Edit * pEdit=PX_Object_GetEdit(pObject); + if (pEdit) + { + PX_strcpy(pEdit->Limit,Limit,sizeof(pEdit->Limit)); + } +} + +px_void PX_Object_EditSetStyle(PX_Object *pObject,PX_OBJECT_EDIT_STYLE style) +{ + PX_Object_Edit * pEdit=PX_Object_GetEdit(pObject); + if (pEdit) + { + pEdit->style=style; + } +} + +px_void PX_Object_EditSetBorder( PX_Object *pObj,px_bool Border ) +{ + PX_Object_Edit *pEdit=PX_Object_GetEdit(pObj); + if (pEdit) + { + + pEdit->Border=Border; + } +} + + + +px_void PX_Object_EditUpdateCursorOnDown(PX_Object *pObject,px_int cx,px_int cy) +{ + px_int x_draw_oft=0,y_draw_oft=0,x=0,y=0,cursor=0,fsize=0; + PX_Object_Edit *pEdit=(PX_Object_Edit *)pObject->pObject; + const px_char *Text=pEdit->text.buffer; + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + if (pEdit==PX_NULL) + { + return; + } + + x=pEdit->HorizontalOffset; + y=pEdit->VerticalOffset; + + + + while (PX_TRUE) + { + fsize=0; + x_draw_oft=x-pEdit->XOffset; + y_draw_oft=y-pEdit->YOffset; + + if (pEdit->fontModule) + { + px_dword code; + px_int width,height; + fsize=PX_FontModuleGetCharacterDesc(pEdit->fontModule,Text+cursor,&code,&width,&height); + if (!fsize) + { + break; + } + if (code=='\r') + { + //skip + }else if (code=='\n') + { + x=pEdit->HorizontalOffset; + y+=pEdit->fontModule->max_Height+pEdit->yFontSpacing; + } + else + { + if (cx<=x_draw_oft+width/2+pEdit->xFontSpacing/2&&cy<=y_draw_oft+pEdit->fontModule->max_Height+pEdit->yFontSpacing/2) + { + pEdit->cursor_index=cursor; + return; + } + else + { + pEdit->cursor_index=cursor+fsize; + } + + x+=width+pEdit->xFontSpacing; + } + + if (pEdit->AutoNewline) + { + if (x>objWidth-pEdit->AutoNewLineSpacing) + { + x=pEdit->HorizontalOffset; + y+=pEdit->fontModule->max_Height+pEdit->yFontSpacing; + } + } + + } + else + { + fsize=1; + + if (Text[cursor]=='\r') + { + //skip + }else if (Text[cursor]=='\n') + { + x=0; + y+=__PX_FONT_HEIGHT+pEdit->yFontSpacing; + } + else if(Text[cursor]) + { + if (cx<=x_draw_oft+__PX_FONT_ASCSIZE/2+pEdit->xFontSpacing/2&&cy<=y_draw_oft+__PX_FONT_HEIGHT+pEdit->yFontSpacing/2) + { + pEdit->cursor_index=cursor; + return; + } + else + { + pEdit->cursor_index=cursor+fsize; + } + + x+=__PX_FONT_ASCSIZE+pEdit->xFontSpacing; + } + else + { + break; + } + + if (pEdit->AutoNewline) + { + if (x>objWidth-pEdit->AutoNewLineSpacing) + { + x=pEdit->HorizontalOffset; + y+=__PX_FONT_HEIGHT+pEdit->yFontSpacing; + } + } + } + cursor+=fsize; + } + +} + + +px_void PX_Object_EditRender(px_surface *psurface, PX_Object *pObject,px_uint elapsed) +{ + px_int x_draw_oft,y_draw_oft,x,y,cursor,fsize; + PX_Object_Edit *pEdit=(PX_Object_Edit *)pObject->pObject; + const px_char *Text=pEdit->text.buffer; + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + if (pEdit==PX_NULL) + { + return; + } + + if (!pObject->Visible) + { + return; + } + + if (pEdit->EditSurface.width!=(px_int)objWidth||pEdit->EditSurface.height!=(px_int)objHeight) + { + PX_SurfaceFree(&pEdit->EditSurface); + if(!PX_SurfaceCreate(pObject->mp,(px_int)objWidth,(px_int)objHeight,&pEdit->EditSurface)) + { + return; + } + } + + + if (pEdit->style==PX_OBJECT_EDIT_STYLE_RECT) + { + //clear + PX_SurfaceClear(&pEdit->EditSurface,0,0,(px_int)objWidth-1,(px_int)objHeight-1,pEdit->BackgroundColor); + if (pEdit->Border) + { + if(pEdit->state==PX_OBJECT_EDIT_STATE_NORMAL) + PX_GeoDrawBorder(&pEdit->EditSurface,0,0,(px_int)objWidth-1,(px_int)objHeight-1,1,pEdit->BorderColor); + else + PX_GeoDrawBorder(&pEdit->EditSurface,0,0,(px_int)objWidth-1,(px_int)objHeight-1,1,pEdit->CursorColor); + } + } + else if(pEdit->style==PX_OBJECT_EDIT_STYLE_ROUNDRECT) + { + PX_SurfaceClear(&pEdit->EditSurface,0,0,(px_int)objWidth-1,(px_int)objHeight-1,PX_COLOR(0,0,0,0)); + PX_GeoDrawSolidRoundRect(&pEdit->EditSurface,0,0,(px_int)objWidth-1,(px_int)objHeight-1,objHeight/2,pEdit->BackgroundColor); + if (pEdit->Border) + { + if(pEdit->state==PX_OBJECT_EDIT_STATE_NORMAL) + PX_GeoDrawRoundRect(&pEdit->EditSurface,0,0,(px_int)objWidth-1,(px_int)objHeight-1,objHeight/2,1,pEdit->BorderColor); + else + PX_GeoDrawRoundRect(&pEdit->EditSurface,0,0,(px_int)objWidth-1,(px_int)objHeight-1,objHeight/2,1,pEdit->CursorColor); + } + } + + + + x=pEdit->HorizontalOffset; + y=pEdit->VerticalOffset; + + cursor=0; + + while (PX_TRUE) + { + fsize=0; + x_draw_oft=x-pEdit->XOffset; + y_draw_oft=y-pEdit->YOffset; + + //Draw Cursor + if (pEdit->onFocus&&pEdit->cursor_index==cursor) + { + pEdit->elapsed+=elapsed; + if ((pEdit->elapsed/200)&1) + { + if (pEdit->fontModule) + { + PX_GeoDrawRect(&pEdit->EditSurface,x_draw_oft+1,y_draw_oft,x_draw_oft,y_draw_oft+pEdit->fontModule->max_Height-2,pEdit->TextColor); + } + else + { + PX_GeoDrawRect(&pEdit->EditSurface,x_draw_oft+1,y_draw_oft,x_draw_oft,y_draw_oft+__PX_FONT_HEIGHT-1,pEdit->TextColor); + } + + } + } + + + if (pEdit->fontModule) + { + px_dword code; + px_int width,height; + fsize=PX_FontModuleGetCharacterDesc(pEdit->fontModule,Text+cursor,&code,&width,&height); + if (!fsize) + { + break; + } + if (code=='\r') + { + //skip + }else if (code=='\n') + { + x=pEdit->HorizontalOffset; + y+=pEdit->fontModule->max_Height+pEdit->yFontSpacing; + } + else + { + PX_FontModuleDrawCharacter(&pEdit->EditSurface,pEdit->fontModule,x_draw_oft,y_draw_oft,code,pEdit->TextColor); + x+=width+pEdit->xFontSpacing; + } + + if (pEdit->AutoNewline) + { + if (x>objWidth-pEdit->AutoNewLineSpacing) + { + x=0; + y+=pEdit->fontModule->max_Height+pEdit->yFontSpacing; + } + } + + } + else + { + fsize=1; + + if (Text[cursor]=='\r') + { + //skip + }else if (Text[cursor]=='\n') + { + x=pEdit->HorizontalOffset; + y+=__PX_FONT_HEIGHT+pEdit->yFontSpacing; + } + else if(Text[cursor]) + { + if (pEdit->Password) + { + PX_FontDrawChar(&pEdit->EditSurface,x_draw_oft,y_draw_oft,'*',pEdit->TextColor); + x+=__PX_FONT_ASCSIZE; + } + else + { + PX_FontDrawChar(&pEdit->EditSurface,x_draw_oft,y_draw_oft,Text[cursor],pEdit->TextColor); + x+=__PX_FONT_ASCSIZE; + } + + } + else + { + break; + } + + if (pEdit->AutoNewline) + { + if (x>objWidth-pEdit->AutoNewLineSpacing) + { + x=pEdit->HorizontalOffset; + y+=__PX_FONT_HEIGHT+pEdit->yFontSpacing; + } + } + } + cursor+=fsize; + } + + PX_SurfaceRender(psurface,&pEdit->EditSurface,(px_int)objx,(px_int)objy,PX_ALIGN_LEFTTOP,PX_NULL); +} + +px_void PX_Object_EditFree( PX_Object *pObject ) +{ + PX_Object_Edit *pEdit=PX_Object_GetEdit(pObject); + if (pObject!=PX_NULL) + { + PX_StringFree(&pEdit->text); + PX_TextureFree(&pEdit->EditSurface); + } +} + +px_void PX_Object_EditAddString(PX_Object *pObject,px_char *Text) +{ + PX_Object_Edit *pEdit=PX_Object_GetEdit(pObject); + PX_Object_Event e; + if (pObject!=PX_NULL) + { + PX_Object_EditCheckCursor(pEdit); + while (*Text) + { + + if(*Text!=8) + { + if (!pEdit->multiLines&&Text[1]==0&&(*Text=='\n'||*Text=='\r')) + { + return; + } + + if (pEdit->Limit[0]) + { + px_bool bMatch=PX_FALSE; + const px_char *limitFilter=pEdit->Limit; + while (*limitFilter) + { + if (*limitFilter==*Text) + { + bMatch=PX_TRUE; + break; + } + limitFilter++; + } + if (!bMatch) + { + Text++; + continue; + } + } + + if (pEdit->max_length>0) + { + if (PX_StringLen(&pEdit->text)max_length) + { + px_char ch=*Text; + if (ch=='\r') + { + ch='\n'; + } + PX_StringInsertChar(&pEdit->text,pEdit->cursor_index,ch); + pEdit->cursor_index++; + } + } + else + { + px_char ch=*Text; + if (ch=='\r') + { + ch='\n'; + } + PX_StringInsertChar(&pEdit->text,pEdit->cursor_index,ch); + pEdit->cursor_index++; + } + + } + else + { + PX_Object_EditBackspace(pObject); + } + Text++; + } + } + PX_Object_EditUpdateCursorViewRegion(pObject); + e.Event=PX_OBJECT_EVENT_VALUECHANGED; + e.Param_ptr[0]=0; + PX_ObjectExecuteEvent(pObject,e); +} + +px_void PX_Object_EditBackspace(PX_Object *pObject) +{ + PX_Object_Event e; + PX_Object_Edit *pEdit=PX_Object_GetEdit(pObject); + + + if (pObject!=PX_NULL&&pEdit->onFocus) + { + px_char *pText; + pText=pEdit->text.buffer; + + if (!pEdit->fontModule) + { + if (pEdit->cursor_index) + { + PX_StringRemoveChar(&pEdit->text,pEdit->cursor_index-1); + pEdit->cursor_index--; + } + + return; + } + + switch(pEdit->fontModule->codePage) + { + case PX_FONTMODULE_CODEPAGE_GBK: + { + px_int idx=0; + px_int c=0; + while (PX_TRUE) + { + + if (idx==pEdit->cursor_index) + { + break; + } + + if (pText[idx]==0) + { + break; + } + + if (pText[idx]&0x80) + { + c=2; + idx+=2; + } + else + { + idx++; + c=1; + } + } + + while (c) + { + PX_StringRemoveChar(&pEdit->text,pEdit->cursor_index-1); + pEdit->cursor_index--; + c--; + } + + } + break; + case PX_FONTMODULE_CODEPAGE_UTF8: + { + px_int i; + for (i=0;i<6;i++) + { + if (pEdit->cursor_index==0) + { + break; + } + + if ((pText[pEdit->cursor_index-1]&0x80)==0x00) + { + PX_StringRemoveChar(&pEdit->text,pEdit->cursor_index-1); + pEdit->cursor_index--; + break; + } + + if ((pText[pEdit->cursor_index-1]&0xc0)==0x80) + { + PX_StringRemoveChar(&pEdit->text,pEdit->cursor_index-1); + pEdit->cursor_index--; + continue; + } + + if ((pText[pEdit->cursor_index-1]&0xc0)==0xc0) + { + PX_StringRemoveChar(&pEdit->text,pEdit->cursor_index-1); + pEdit->cursor_index--; + break; + } + + } + } + break; + case PX_FONTMODULE_CODEPAGE_UTF16: + { + //not support + } + break; + default: + { + //not support + } + break; + } + + e.Event=PX_OBJECT_EVENT_VALUECHANGED; + e.Param_ptr[0]=0; + PX_ObjectExecuteEvent(pObject,e); + } +} + +px_void PX_Object_EditAutoNewLine(PX_Object *pObject,px_bool b,px_int AutoNewLineSpacing) +{ + PX_Object_Edit *pEdit=PX_Object_GetEdit(pObject); + if (pObject!=PX_NULL) + { + pEdit->AutoNewline=b; + pEdit->AutoNewLineSpacing=AutoNewLineSpacing; + } +} + +px_void PX_Object_EditSetOffset(PX_Object *pObject,px_int TopOffset,px_int LeftOffset) +{ + PX_Object_Edit *pEdit=PX_Object_GetEdit(pObject); + if (pObject!=PX_NULL) + { + pEdit->VerticalOffset=TopOffset; + pEdit->HorizontalOffset=LeftOffset; + } +} + +px_void PX_Object_EditSetXYOffset(PX_Object* pObject, px_int XOffset, px_int YOffset) +{ + PX_Object_Edit* pEdit = PX_Object_GetEdit(pObject); + if (pObject != PX_NULL) + { + pEdit->XOffset = XOffset; + pEdit->YOffset = YOffset; + } +} diff --git a/lib/PainterEngine/kernel/PX_Object_Edit.h b/lib/PainterEngine/kernel/PX_Object_Edit.h new file mode 100644 index 0000000000000000000000000000000000000000..5d1bf39467e7f076cddedb1b97fb2617e3edb1ed --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_Edit.h @@ -0,0 +1,66 @@ +#ifndef PX_OBJECT_EDIT_H +#define PX_OBJECT_EDIT_H +#include "PX_Object.h" + +typedef enum +{ + PX_OBJECT_EDIT_STATE_ONCURSOR, + PX_OBJECT_EDIT_STATE_NORMAL, +}PX_OBJECT_EDIT_STATE; + +typedef enum +{ + PX_OBJECT_EDIT_STYLE_RECT, + PX_OBJECT_EDIT_STYLE_ROUNDRECT, +}PX_OBJECT_EDIT_STYLE; + +typedef struct +{ + px_string text; + px_bool onFocus; + px_bool Border; + px_color TextColor; + px_color BorderColor; + px_color CursorColor; + px_color BackgroundColor; + px_uint elapsed; + px_bool Password; + px_bool AutoNewline; + px_int AutoNewLineSpacing; + px_int XOffset,YOffset; + px_int VerticalOffset,HorizontalOffset; + px_int xFontSpacing,yFontSpacing; + px_int cursor_index; + px_int max_length; + px_bool multiLines; + px_surface EditSurface; + PX_FontModule *fontModule; + px_char Limit[128]; + PX_OBJECT_EDIT_STATE state; + PX_OBJECT_EDIT_STYLE style; +}PX_Object_Edit; + +PX_Object* PX_Object_EditCreate(px_memorypool *mp, PX_Object *Parent,px_int x,px_int y,px_int Width,px_int Height,PX_FontModule *fontModule ); +PX_Object_Edit * PX_Object_GetEdit( PX_Object *Object ); +px_char * PX_Object_EditGetText( PX_Object *pObject ); +px_void PX_Object_EditSetMaxTextLength(PX_Object *pObject,px_int max_length); +px_void PX_Object_EditSetText( PX_Object *pObject,const px_char *Text ); +px_void PX_Object_EditAppendText( PX_Object *pObject,const px_char *Text ); +px_void PX_Object_EditSetFocus( PX_Object *pObject,px_bool OnFocus); +px_void PX_Object_EditSetPasswordStyle( PX_Object *pObject,px_uchar Enabled ); +px_void PX_Object_EditSetBackgroundColor( PX_Object *pObject,px_color Color ); +px_void PX_Object_EditSetBorderColor( PX_Object *pObject,px_color Color ); +px_void PX_Object_EditSetCursorColor( PX_Object *pObject,px_color Color ); +px_void PX_Object_EditSetTextColor( PX_Object *pObject,px_color Color ); +px_void PX_Object_EditSetLimit(PX_Object *pObject,const px_char *Limit); +px_void PX_Object_EditSetStyle(PX_Object *pObject,PX_OBJECT_EDIT_STYLE style); +px_void PX_Object_EditSetBorder( PX_Object *pObj,px_bool Border ); +px_void PX_Object_EditRender(px_surface *psurface, PX_Object *pObject,px_uint elapsed); +px_void PX_Object_EditFree( PX_Object *pObject ); +px_void PX_Object_EditAddString(PX_Object *pObject,px_char *Text); +px_void PX_Object_EditBackspace(PX_Object *pObject); +px_void PX_Object_EditAutoNewLine(PX_Object *pObject,px_bool b,px_int AutoNewLineSpacing); +px_void PX_Object_EditSetOffset(PX_Object *pObject,px_int TopOffset,px_int LeftOffset); +px_void PX_Object_EditSetXYOffset(PX_Object* pObject, px_int XOffset, px_int YOffset); +#endif + diff --git a/lib/PainterEngine/kernel/PX_Object_Explorer.c b/lib/PainterEngine/kernel/PX_Object_Explorer.c new file mode 100644 index 0000000000000000000000000000000000000000..b37f2afc181c99fe02831953f23cd7b706283312 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_Explorer.c @@ -0,0 +1,681 @@ +#include "PX_Object_Explorer.h" +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// +//explorer + +PX_Object_Explorer * PX_Object_GetExplorer(PX_Object *Object) +{ + if(Object->Type==PX_OBJECT_TYPE_EXPLORER) + { + return (PX_Object_Explorer *)Object->pObject; + } + return PX_NULL; +} + +px_void PX_Object_ExplorerOnCursorMove(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + px_float x,y; + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_Object_Explorer *pExp=PX_Object_GetExplorer(pObject); + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + x=PX_Object_Event_GetCursorX(e); + y=PX_Object_Event_GetCursorY(e); + if (PX_isXYInRegion(x,y,objx,objy+PX_OBJECT_EXPOLRER_MENU_HEIGHT,objWidth-PX_OBJECT_EXPOLRER_SLIDERBAR_WIDTH,objHeight-PX_OBJECT_EXPOLRER_MENU_HEIGHT*2)) + { + //get cursor index + px_int i; + px_int ofty; + px_int index; + ofty=PX_Object_SliderBarGetValue(pExp->SliderBar); + index=(px_int)(y+ofty-objy-PX_OBJECT_EXPOLRER_MENU_HEIGHT)/PX_OBJECT_EXPOLRER_ITEM_HEIGHT; + //clear + for (i=0;iItemCount;i++) + { + pExp->Items[i].bcursor=PX_FALSE; + } + if (indexItemCount) + { + pExp->Items[index].bcursor=PX_TRUE; + } + + } +} + +px_void PX_Object_ExplorerOnButtonBack(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + px_char path[260]; + px_int index; + PX_Object_Explorer *pExp=PX_Object_GetExplorer((PX_Object *)ptr); + PX_strcpy(path,PX_Object_EditGetText(pExp->edit_Path),sizeof(path)); + index=PX_strlen(path); + while (index) + { + if (path[index]=='/'||path[index]=='\\') + { + break; + } + index--; + } + path[index]='\0'; + PX_Object_EditSetText(pExp->edit_Path,path); + PX_Object_ExplorerRefresh((PX_Object *)ptr); +} +px_void PX_Object_ExplorerOnButtonGo(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + PX_Object_ExplorerRefresh((PX_Object *)ptr); +} +px_void PX_Object_ExplorerOnButtonOk(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + PX_Object_Explorer *pExp=PX_Object_GetExplorer((PX_Object *)ptr); + PX_ObjectClearFocus((PX_Object *)ptr); + pExp->returnType=PX_OBJECT_EXPLORER_RETURN_CONFIRM; + PX_ObjectExecuteEvent((PX_Object *)ptr,e); + ((PX_Object *)ptr)->Visible=PX_FALSE; + +} +px_void PX_Object_ExplorerOnButtonCancel(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + PX_Object_Explorer *pExp=PX_Object_GetExplorer((PX_Object *)ptr); + PX_ObjectClearFocus((PX_Object *)ptr); + pExp->returnType=PX_OBJECT_EXPLORER_RETURN_CANCEL; + PX_ObjectExecuteEvent((PX_Object*)ptr, PX_OBJECT_BUILD_EVENT(PX_OBJECT_EVENT_CANCEL)); + ((PX_Object *)ptr)->Visible=PX_FALSE; +} + +px_void PX_Object_ExplorerOnCursorDown(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + px_float x,y; + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + PX_Object_Explorer *pExp=PX_Object_GetExplorer(pObject); + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + x=PX_Object_Event_GetCursorX(e); + y=PX_Object_Event_GetCursorY(e); + if (PX_isXYInRegion(x,y,objx,objy+PX_OBJECT_EXPOLRER_MENU_HEIGHT,objWidth-PX_OBJECT_EXPOLRER_SLIDERBAR_WIDTH,objHeight-PX_OBJECT_EXPOLRER_MENU_HEIGHT*2)) + { + px_int i=0,selectcount=0; + px_int ofty; + //get cursor index + + px_int index; + ofty=PX_Object_SliderBarGetValue(pExp->SliderBar); + index=(px_int)(y+ofty-objy-PX_OBJECT_EXPOLRER_MENU_HEIGHT)/PX_OBJECT_EXPOLRER_ITEM_HEIGHT; + if (indexItemCount) + { + if (pExp->Items[index].bselect&&pExp->Items[index].bFolder) + { + + //enter path + px_char *pEditPath=PX_Object_EditGetText(pExp->edit_Path); + if (pEditPath[PX_strlen(pEditPath)-1]!='/'&&pEditPath[PX_strlen(pEditPath)-1]!='\\'&&pEditPath[0]) + { + PX_Object_EditAppendText(pExp->edit_Path,"/"); + } + PX_Object_EditAppendText(pExp->edit_Path,pExp->Items[index].name); + + PX_Object_ExplorerRefresh(pObject); + } + else + { + if (!pExp->savemode&&pExp->MaxSelectedCount!=1) + { + for (i=0;iItemCount;i++) + { + if(pExp->Items[i].bselect) + { + selectcount++; + } + } + if (pExp->Items[index].bselect) + { + pExp->Items[index].bselect=PX_FALSE; + } + else + { + if (selectcountMaxSelectedCount) + { + pExp->Items[index].bselect=PX_TRUE; + } + } + + } + else + { + if (pExp->Items[index].bselect) + { + PX_ObjectClearFocus(pObject); + pExp->returnType=PX_OBJECT_EXPLORER_RETURN_CONFIRM; + PX_ObjectExecuteEvent(pObject,PX_OBJECT_BUILD_EVENT(PX_OBJECT_EVENT_EXECUTE)); + pObject->Visible=PX_FALSE; + } + else + { + if (pExp->savemode) + { + PX_Object_EditSetText(pExp->edit_FileName, ""); + } + for (i=0;iItemCount;i++) + { + if(pExp->Items[i].bselect) + { + pExp->Items[i].bselect=PX_FALSE; + } + } + pExp->Items[index].bselect=PX_TRUE; + if (pExp->savemode) + { + PX_Object_EditSetText(pExp->edit_FileName, pExp->Items[index].name); + } + } + + } + + } + + } + + if (PX_Object_ExplorerGetSelectedCount(pObject)==0) + { + pExp->btn_Ok->Visible=PX_FALSE; + } + else + { + pExp->btn_Ok->Visible=PX_TRUE; + } + } +} + +static px_void PX_Object_ExplorerOnCursorWheel(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + PX_Object_Explorer *pExp=PX_Object_GetExplorer(pObject); + px_float x=PX_Object_Event_GetCursorX(e); + px_float y=PX_Object_Event_GetCursorY(e); + px_float z=PX_Object_Event_GetCursorZ(e); + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + if (PX_isXYInRegion(x,y,objx,objy+PX_OBJECT_EXPOLRER_MENU_HEIGHT,objWidth-PX_OBJECT_EXPOLRER_SLIDERBAR_WIDTH,objHeight-PX_OBJECT_EXPOLRER_MENU_HEIGHT*2)) + { + if (z<0) + { + PX_Object_SliderBarSetValue(pExp->SliderBar,PX_Object_SliderBarGetValue(pExp->SliderBar)+PX_OBJECT_EXPOLRER_ITEM_HEIGHT/2); + } + else + { + PX_Object_SliderBarSetValue(pExp->SliderBar,PX_Object_SliderBarGetValue(pExp->SliderBar)-PX_OBJECT_EXPOLRER_ITEM_HEIGHT/2); + } + } + +} + +px_void PX_Object_ExplorerRender(px_surface *psurface, PX_Object *pObject,px_uint elapsed) +{ + PX_Object_Explorer *pExp=PX_Object_GetExplorer(pObject); + //background + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + px_int val,ofty; + + if (pObject->Width<256) + { + pObject->Width=256; + } + if (pObject->Height<128) + { + pObject->Height=128; + } + + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + val=PX_Object_SliderBarGetValue(pExp->SliderBar); + ofty=PX_Object_SliderBarGetValue(pExp->SliderBar); + + PX_GeoDrawRect(psurface,(px_int)objx,(px_int)objy,(px_int)(objx+objWidth),(px_int)(objy+objHeight),pExp->backgroundcolor); + + //button back + pExp->btn_Back->x=8; + pExp->btn_Back->y=8; + pExp->btn_Back->Width=PX_OBJECT_EXPOLRER_BUTTON_WIDTH; + pExp->btn_Back->Height=32; + PX_Object_PushButtonSetBackgroundColor(pExp->btn_Back,pExp->backgroundcolor); + PX_Object_PushButtonSetBorderColor(pExp->btn_Back,pExp->bordercolor); + PX_Object_PushButtonSetTextColor(pExp->btn_Back,pExp->fontcolor); + PX_Object_PushButtonSetCursorColor(pExp->btn_Back,pExp->cursorcolor); + PX_Object_PushButtonSetPushColor(pExp->btn_Back,pExp->pushcolor); + + pExp->edit_Path->x=PX_OBJECT_EXPOLRER_BUTTON_WIDTH+8+8; + pExp->edit_Path->Width=objWidth-PX_OBJECT_EXPOLRER_BUTTON_WIDTH-PX_OBJECT_EXPOLRER_BUTTON_WIDTH-8*4; + if (pExp->fontmodule) + { + pExp->edit_Path->Height=pExp->fontmodule->max_Height+6.0f; + } + else + { + pExp->edit_Path->Height=20; + } + pExp->edit_Path->y=24-pExp->edit_Path->Height/2; + PX_Object_EditSetBackgroundColor(pExp->edit_Path,pExp->backgroundcolor); + PX_Object_EditSetBorderColor(pExp->edit_Path,pExp->bordercolor); + PX_Object_EditSetTextColor(pExp->edit_Path,pExp->fontcolor); + PX_Object_EditSetCursorColor(pExp->edit_Path,pExp->fontcolor); + + pExp->btn_go->x=objWidth-8-PX_OBJECT_EXPOLRER_BUTTON_WIDTH; + pExp->btn_go->y=8; + pExp->btn_go->Width=PX_OBJECT_EXPOLRER_BUTTON_WIDTH; + pExp->btn_go->Height=32; + PX_Object_PushButtonSetBackgroundColor(pExp->btn_go,pExp->backgroundcolor); + PX_Object_PushButtonSetBorderColor(pExp->btn_go,pExp->bordercolor); + PX_Object_PushButtonSetTextColor(pExp->btn_go,pExp->fontcolor); + PX_Object_PushButtonSetCursorColor(pExp->btn_go,pExp->cursorcolor); + PX_Object_PushButtonSetPushColor(pExp->btn_go,pExp->pushcolor); + + + pExp->SliderBar->x=objx+objWidth-24; + pExp->SliderBar->Width=24; + pExp->SliderBar->y=PX_OBJECT_EXPOLRER_MENU_HEIGHT; + pExp->SliderBar->Height=objHeight-PX_OBJECT_EXPOLRER_MENU_HEIGHT-PX_OBJECT_EXPOLRER_MENU_HEIGHT; + PX_Object_SliderBarSetBackgroundColor(pExp->SliderBar,pExp->backgroundcolor); + PX_Object_SliderBarSetColor(pExp->SliderBar,pExp->bordercolor); + if (pExp->ItemCount*PX_OBJECT_EXPOLRER_ITEM_HEIGHT>objHeight-PX_OBJECT_EXPOLRER_MENU_HEIGHT-PX_OBJECT_EXPOLRER_MENU_HEIGHT) + { + pExp->SliderBar->Visible=PX_TRUE; + PX_Object_SliderBarSetRange(pExp->SliderBar,0,pExp->ItemCount*PX_OBJECT_EXPOLRER_ITEM_HEIGHT-((px_int)objHeight-PX_OBJECT_EXPOLRER_MENU_HEIGHT-PX_OBJECT_EXPOLRER_MENU_HEIGHT)); + PX_Object_SliderBarSetSliderButtonLength(pExp->SliderBar,(px_int)(pExp->SliderBar->Height*pExp->SliderBar->Height/pExp->ItemCount/PX_OBJECT_EXPOLRER_ITEM_HEIGHT)); + } + else + { + PX_Object_SliderBarSetRange(pExp->SliderBar,0,0); + pExp->SliderBar->Visible=PX_FALSE; + } + + + do + { + PX_SurfaceLimitInfo lmInfo; + px_int startIndex=ofty/PX_OBJECT_EXPOLRER_ITEM_HEIGHT; + px_int drawy=PX_OBJECT_EXPOLRER_MENU_HEIGHT-(ofty)%PX_OBJECT_EXPOLRER_ITEM_HEIGHT; + lmInfo=PX_SurfaceGetLimit(psurface); + PX_SurfaceSetLimit(psurface,(px_int)objx,(px_int)objy+PX_OBJECT_EXPOLRER_MENU_HEIGHT,(px_int)(objx+objWidth),(px_int)(objy+objHeight-PX_OBJECT_EXPOLRER_MENU_HEIGHT)); + while (startIndexItemCount&&drawyItems[startIndex]; + + if (pItem->bcursor) + { + PX_GeoDrawRect(psurface,(px_int)objx,(px_int)objy+drawy,(px_int)(objx+objWidth),(px_int)objy+drawy+PX_OBJECT_EXPOLRER_ITEM_HEIGHT-1,pExp->cursorcolor); + } + + if (pItem->bFolder) + { + PX_ShapeRender(psurface,&pExp->folder,(px_int)objx+16+3,(px_int)objy+drawy+PX_OBJECT_EXPOLRER_ITEM_HEIGHT/2,PX_ALIGN_CENTER,pExp->fontcolor); + } + else + { + PX_ShapeRender(psurface,&pExp->file,(px_int)objx+16+3,(px_int)objy+drawy+PX_OBJECT_EXPOLRER_ITEM_HEIGHT/2,PX_ALIGN_CENTER,pExp->fontcolor); + } + + PX_FontModuleDrawText(psurface,pExp->fontmodule,(px_int)objx+32+8,(px_int)objy+drawy+PX_OBJECT_EXPOLRER_ITEM_HEIGHT/2,PX_ALIGN_LEFTMID,pItem->name,pExp->fontcolor); + + if (pItem->bselect) + { + PX_GeoDrawSolidCircle(psurface,(px_int)(objx+objWidth)-24-16,(px_int)objy+drawy+PX_OBJECT_EXPOLRER_ITEM_HEIGHT/2,8,pExp->fontcolor); + } + + drawy+=PX_OBJECT_EXPOLRER_ITEM_HEIGHT; + startIndex++; + } + + PX_SurfaceSetLimitInfo(psurface,lmInfo); + + } while (0); + + + PX_GeoDrawLine(psurface,(px_int)objx,PX_OBJECT_EXPOLRER_MENU_HEIGHT,(px_int)(objx+objWidth),PX_OBJECT_EXPOLRER_MENU_HEIGHT,1,pExp->fontcolor); + PX_GeoDrawLine(psurface,(px_int)objx,(px_int)(objy+objHeight-PX_OBJECT_EXPOLRER_MENU_HEIGHT),(px_int)(objx+objWidth),(px_int)(objy+objHeight-PX_OBJECT_EXPOLRER_MENU_HEIGHT),1,pExp->fontcolor); + + pExp->btn_Ok->x=objWidth-8-PX_OBJECT_EXPOLRER_BUTTON_WIDTH-8-PX_OBJECT_EXPOLRER_BUTTON_WIDTH; + pExp->btn_Ok->y=objHeight-40; + pExp->btn_Ok->Width=PX_OBJECT_EXPOLRER_BUTTON_WIDTH; + pExp->btn_Ok->Height=32; + PX_Object_PushButtonSetBackgroundColor(pExp->btn_Ok,pExp->backgroundcolor); + PX_Object_PushButtonSetBorderColor(pExp->btn_Ok,pExp->bordercolor); + PX_Object_PushButtonSetTextColor(pExp->btn_Ok,pExp->fontcolor); + PX_Object_PushButtonSetCursorColor(pExp->btn_Ok,pExp->cursorcolor); + PX_Object_PushButtonSetPushColor(pExp->btn_Ok,pExp->pushcolor); + + pExp->btn_Cancel->x=objx+objWidth-8-PX_OBJECT_EXPOLRER_BUTTON_WIDTH; + pExp->btn_Cancel->y=objHeight-40; + pExp->btn_Cancel->Width=PX_OBJECT_EXPOLRER_BUTTON_WIDTH; + pExp->btn_Cancel->Height=32; + PX_Object_PushButtonSetBackgroundColor(pExp->btn_Cancel,pExp->backgroundcolor); + PX_Object_PushButtonSetBorderColor(pExp->btn_Cancel,pExp->bordercolor); + PX_Object_PushButtonSetTextColor(pExp->btn_Cancel,pExp->fontcolor); + PX_Object_PushButtonSetCursorColor(pExp->btn_Cancel,pExp->cursorcolor); + PX_Object_PushButtonSetPushColor(pExp->btn_Cancel,pExp->pushcolor); + + pExp->edit_FileName->x = 16; + pExp->edit_FileName->y = objHeight - 40; + pExp->edit_FileName->Width = 256; + pExp->edit_FileName->Height = 32; + if (pExp->MaxSelectedCount!=1||!pExp->savemode) + { + pExp->edit_FileName->Visible = PX_FALSE; + } + else + { + pExp->edit_FileName->Visible = PX_TRUE; + } + +} + +px_void PX_Object_ExplorerFree(PX_Object *pObject) +{ + PX_Object_Explorer *pExp=PX_Object_GetExplorer(pObject); + PX_ShapeFree(&pExp->file); + PX_ShapeFree(&pExp->folder); +} + + + +PX_Object * PX_Object_ExplorerCreate(px_memorypool *mp, PX_Object *Parent,px_int x,px_int y,px_int Width,px_int Height,PX_FontModule *fm, PX_ExplorerGetPathFolderCount _func_gpfdc, PX_ExplorerGetPathFileCount _func_gpfec, PX_ExplorerGetPathFolderName _func_gpfdn, PX_ExplorerGetPathFileName _func_gpfcn,const px_char path[]) +{ + PX_Object_Explorer explorer; + PX_Object *pObject; + px_byte PX_Object_Explorer_fileLogoData[] = { + 0x54,0x52,0x41,0x57,0x1a,0x0,0x0,0x0,0x20,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x28,0x0,0x0,0x0,0x67,0x0,0x0,0x0,0x74,0x0,0x0,0x0,0x74,0x0,0x0,0x0,0x74,0x0,0x0,0x0,0x74,0x0,0x0,0x0,0x74,0x0,0x0,0x0,0x74,0x0,0x0,0x0,0x74,0x0,0x0,0x0,0x74,0x0,0x0,0x0,0x74,0x0,0x0,0x0,0x74,0x0,0x0,0x0,0x74,0x0,0x0,0x0,0x74,0x0,0x0,0x0,0x75,0x0,0x0,0x0,0x55,0x0,0x0,0x0,0x5,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x38,0x0,0x0,0x0,0xd7,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xf5,0x0,0x0,0x0,0x75,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x9c,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xfe,0x0,0x0,0x0,0xf8,0x0,0x0,0x0,0xf8,0x0,0x0,0x0,0xf8,0x0,0x0,0x0,0xf8,0x0,0x0,0x0,0xf8,0x0,0x0,0x0,0xf8,0x0,0x0,0x0,0xf8,0x0,0x0,0x0,0xf8,0x0,0x0,0x0,0xf8,0x0,0x0,0x0,0xf8,0x0,0x0,0x0,0xfd,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xf6,0x0,0x0,0x0,0x75,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x8,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xde,0x0,0x0,0x0,0x54,0x0,0x0,0x0,0x44,0x0,0x0,0x0,0x45,0x0,0x0,0x0,0x45,0x0,0x0,0x0,0x45,0x0,0x0,0x0,0x45,0x0,0x0,0x0,0x45,0x0,0x0,0x0,0x45,0x0,0x0,0x0,0x44,0x0,0x0,0x0,0x4a,0x0,0x0,0x0,0xcb,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xf8,0x0,0x0,0x0,0xf7,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xf6,0x0,0x0,0x0,0x75,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xd1,0x0,0x0,0x0,0x11,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x3,0x0,0x0,0x0,0xb6,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xd8,0x0,0x0,0x0,0x6d,0x0,0x0,0x0,0xdf,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xf6,0x0,0x0,0x0,0x7c,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xd2,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x7,0x0,0x0,0x0,0xb7,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xd4,0x0,0x0,0x0,0x13,0x0,0x0,0x0,0x45,0x0,0x0,0x0,0xdf,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xf6,0x0,0x0,0x0,0x76,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xd2,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x7,0x0,0x0,0x0,0xb7,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xd4,0x0,0x0,0x0,0x16,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x46,0x0,0x0,0x0,0xdf,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xf6,0x0,0x0,0x0,0x76,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xd2,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x7,0x0,0x0,0x0,0xb7,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xd4,0x0,0x0,0x0,0x15,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x46,0x0,0x0,0x0,0xde,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xf6,0x0,0x0,0x0,0x6e,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xd2,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x5,0x0,0x0,0x0,0xb2,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xee,0x0,0x0,0x0,0xa2,0x0,0x0,0x0,0x98,0x0,0x0,0x0,0x99,0x0,0x0,0x0,0x98,0x0,0x0,0x0,0xd2,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xba,0x0,0x0,0x0,0x8,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xd2,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x7a,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xd2,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0x0,0x60,0x60,0x60,0xff,0x60,0x60,0x60,0xff,0x60,0x60,0x60,0xff,0x60,0x60,0x60,0xff,0x60,0x60,0x60,0xff,0x61,0x61,0x61,0xff,0x60,0x60,0x60,0xff,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0x95,0x0,0x0,0x0,0xe1,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xe9,0x0,0x0,0x0,0xe9,0x0,0x0,0x0,0xe9,0x0,0x0,0x0,0xeb,0x0,0x0,0x0,0xfb,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xd2,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x5,0x0,0x0,0x0,0x21,0x0,0x0,0x0,0x2b,0x0,0x0,0x0,0x2b,0x0,0x0,0x0,0x2b,0x0,0x0,0x0,0x2a,0x0,0x0,0x0,0x3c,0x0,0x0,0x0,0xd9,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xd2,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x12,0x0,0x0,0x0,0xd1,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xd2,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0xd2,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xd2,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0x0,0x61,0x61,0x61,0xff,0x60,0x60,0x60,0xff,0x60,0x60,0x60,0xff,0x60,0x60,0x60,0xff,0x60,0x60,0x60,0xff,0x61,0x61,0x61,0xff,0x60,0x60,0x60,0xff,0x60,0x60,0x60,0xff,0x60,0x60,0x60,0xff,0x60,0x60,0x60,0xff,0x60,0x60,0x60,0xff,0x61,0x61,0x61,0xff,0x60,0x60,0x60,0xff,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0xd2,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xd2,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0xd2,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xd2,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0xd2,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xd2,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0xd2,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xd2,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0x0,0x60,0x60,0x60,0xff,0x60,0x60,0x60,0xff,0x60,0x60,0x60,0xff,0x60,0x60,0x60,0xff,0x60,0x60,0x60,0xff,0x60,0x60,0x60,0xff,0x60,0x60,0x60,0xff,0x60,0x60,0x60,0xff,0x60,0x60,0x60,0xff,0x60,0x60,0x60,0xff,0x60,0x60,0x60,0xff,0x61,0x61,0x61,0xff,0x60,0x60,0x60,0xff,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0xd2,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xd2,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0xd2,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xd2,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0xd2,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xd2,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0xd2,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xd2,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0x0,0x60,0x60,0x60,0xff,0x61,0x61,0x61,0xff,0x61,0x61,0x61,0xff,0x60,0x60,0x60,0xff,0x60,0x60,0x60,0xff,0x60,0x60,0x60,0xff,0x60,0x60,0x60,0xff,0x61,0x61,0x61,0xff,0x60,0x60,0x60,0xff,0x60,0x60,0x60,0xff,0x60,0x60,0x60,0xff,0x60,0x60,0x60,0xff,0x60,0x60,0x60,0xff,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0xd2,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xd2,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0xd2,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xd2,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0xd2,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xd1,0x0,0x0,0x0,0x11,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x11,0x0,0x0,0x0,0xd1,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0x8,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xde,0x0,0x0,0x0,0x54,0x0,0x0,0x0,0x44,0x0,0x0,0x0,0x45,0x0,0x0,0x0,0x45,0x0,0x0,0x0,0x45,0x0,0x0,0x0,0x45,0x0,0x0,0x0,0x45,0x0,0x0,0x0,0x45,0x0,0x0,0x0,0x45,0x0,0x0,0x0,0x45,0x0,0x0,0x0,0x45,0x0,0x0,0x0,0x45,0x0,0x0,0x0,0x45,0x0,0x0,0x0,0x45,0x0,0x0,0x0,0x45,0x0,0x0,0x0,0x45,0x0,0x0,0x0,0x44,0x0,0x0,0x0,0x54,0x0,0x0,0x0,0xde,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0x8,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x9c,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xfe,0x0,0x0,0x0,0xf8,0x0,0x0,0x0,0xf8,0x0,0x0,0x0,0xf8,0x0,0x0,0x0,0xf8,0x0,0x0,0x0,0xf8,0x0,0x0,0x0,0xf8,0x0,0x0,0x0,0xf8,0x0,0x0,0x0,0xf8,0x0,0x0,0x0,0xf8,0x0,0x0,0x0,0xf8,0x0,0x0,0x0,0xf8,0x0,0x0,0x0,0xf8,0x0,0x0,0x0,0xf8,0x0,0x0,0x0,0xf8,0x0,0x0,0x0,0xf8,0x0,0x0,0x0,0xf8,0x0,0x0,0x0,0xf8,0x0,0x0,0x0,0xf8,0x0,0x0,0x0,0xfe,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0x9c,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x38,0x0,0x0,0x0,0xd7,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xd7,0x0,0x0,0x0,0x38,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x28,0x0,0x0,0x0,0x67,0x0,0x0,0x0,0x74,0x0,0x0,0x0,0x74,0x0,0x0,0x0,0x74,0x0,0x0,0x0,0x74,0x0,0x0,0x0,0x74,0x0,0x0,0x0,0x74,0x0,0x0,0x0,0x74,0x0,0x0,0x0,0x74,0x0,0x0,0x0,0x74,0x0,0x0,0x0,0x74,0x0,0x0,0x0,0x74,0x0,0x0,0x0,0x74,0x0,0x0,0x0,0x74,0x0,0x0,0x0,0x74,0x0,0x0,0x0,0x74,0x0,0x0,0x0,0x74,0x0,0x0,0x0,0x74,0x0,0x0,0x0,0x74,0x0,0x0,0x0,0x67,0x0,0x0,0x0,0x28,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0 + }; + + px_byte PX_Object_Explorer_folderLogoData[] = { + 0x54,0x52,0x41,0x57,0x27,0x0,0x0,0x0,0x20,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x32,0x0,0x0,0x0,0x7f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x81,0x0,0x0,0x0,0x42,0x0,0x0,0x0,0x3,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x56,0x0,0x0,0x0,0xde,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xed,0x0,0x0,0x0,0x91,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xf,0x0,0x0,0x0,0xc5,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0x92,0x0,0x0,0x0,0xc,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2b,0x0,0x0,0x0,0xe7,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xf6,0x0,0x0,0x0,0xb8,0x0,0x0,0x0,0xac,0x0,0x0,0x0,0xac,0x0,0x0,0x0,0xac,0x0,0x0,0x0,0xac,0x0,0x0,0x0,0xac,0x0,0x0,0x0,0xac,0x0,0x0,0x0,0xac,0x0,0x0,0x0,0xac,0x0,0x0,0x0,0xae,0x0,0x0,0x0,0xd4,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xfb,0x0,0x0,0x0,0x89,0x0,0x0,0x0,0x50,0x0,0x0,0x0,0x53,0x0,0x0,0x0,0x53,0x0,0x0,0x0,0x53,0x0,0x0,0x0,0x53,0x0,0x0,0x0,0x53,0x0,0x0,0x0,0x53,0x0,0x0,0x0,0x53,0x0,0x0,0x0,0x53,0x0,0x0,0x0,0x53,0x0,0x0,0x0,0x52,0x0,0x0,0x0,0x3e,0x0,0x0,0x0,0x11,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x34,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xe4,0x0,0x0,0x0,0x26,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x3,0x0,0x0,0x0,0x28,0x0,0x0,0x0,0xc8,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xfe,0x0,0x0,0x0,0xfb,0x0,0x0,0x0,0xfb,0x0,0x0,0x0,0xfb,0x0,0x0,0x0,0xfb,0x0,0x0,0x0,0xfb,0x0,0x0,0x0,0xfb,0x0,0x0,0x0,0xfb,0x0,0x0,0x0,0xfb,0x0,0x0,0x0,0xfb,0x0,0x0,0x0,0xfb,0x0,0x0,0x0,0xfb,0x0,0x0,0x0,0xf5,0x0,0x0,0x0,0xb0,0x0,0x0,0x0,0x19,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x34,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xe3,0x0,0x0,0x0,0x22,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x33,0x0,0x0,0x0,0xdb,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0x8e,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x34,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xe3,0x0,0x0,0x0,0x22,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x37,0x0,0x0,0x0,0xa4,0x0,0x0,0x0,0xd8,0x0,0x0,0x0,0xdc,0x0,0x0,0x0,0xdc,0x0,0x0,0x0,0xdc,0x0,0x0,0x0,0xdc,0x0,0x0,0x0,0xdc,0x0,0x0,0x0,0xdc,0x0,0x0,0x0,0xdc,0x0,0x0,0x0,0xdc,0x0,0x0,0x0,0xdc,0x0,0x0,0x0,0xdb,0x0,0x0,0x0,0xe8,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xd5,0x0,0x0,0x0,0x16,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x34,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xe3,0x0,0x0,0x0,0x22,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x5,0x0,0x0,0x0,0x17,0x0,0x0,0x0,0x19,0x0,0x0,0x0,0x19,0x0,0x0,0x0,0x19,0x0,0x0,0x0,0x19,0x0,0x0,0x0,0x19,0x0,0x0,0x0,0x19,0x0,0x0,0x0,0x19,0x0,0x0,0x0,0x19,0x0,0x0,0x0,0x19,0x0,0x0,0x0,0x15,0x0,0x0,0x0,0x66,0x0,0x0,0x0,0xfc,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xdc,0x0,0x0,0x0,0x18,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x34,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xe3,0x0,0x0,0x0,0x21,0x0,0x0,0x0,0x25,0x0,0x0,0x0,0x67,0x0,0x0,0x0,0x77,0x0,0x0,0x0,0x78,0x0,0x0,0x0,0x78,0x0,0x0,0x0,0x78,0x0,0x0,0x0,0x78,0x0,0x0,0x0,0x78,0x0,0x0,0x0,0x78,0x0,0x0,0x0,0x78,0x0,0x0,0x0,0x78,0x0,0x0,0x0,0x78,0x0,0x0,0x0,0x77,0x0,0x0,0x0,0x76,0x0,0x0,0x0,0x76,0x0,0x0,0x0,0x76,0x0,0x0,0x0,0x76,0x0,0x0,0x0,0x76,0x0,0x0,0x0,0x76,0x0,0x0,0x0,0x76,0x0,0x0,0x0,0x76,0x0,0x0,0x0,0x76,0x0,0x0,0x0,0x76,0x0,0x0,0x0,0x74,0x0,0x0,0x0,0xa4,0x0,0x0,0x0,0xfd,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xed,0x0,0x0,0x0,0x77,0x0,0x0,0x0,0x27,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x34,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xe1,0x0,0x0,0x0,0x48,0x0,0x0,0x0,0xc9,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xd3,0x0,0x0,0x0,0x47,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x34,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xe6,0x0,0x0,0x0,0xb1,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xbe,0x0,0x0,0x0,0xd,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x34,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xfa,0x0,0x0,0x0,0xf8,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xfe,0x0,0x0,0x0,0xd6,0x0,0x0,0x0,0xc1,0x0,0x0,0x0,0xc2,0x0,0x0,0x0,0xc2,0x0,0x0,0x0,0xc2,0x0,0x0,0x0,0xc2,0x0,0x0,0x0,0xc2,0x0,0x0,0x0,0xc2,0x0,0x0,0x0,0xc2,0x0,0x0,0x0,0xc2,0x0,0x0,0x0,0xc2,0x0,0x0,0x0,0xc2,0x0,0x0,0x0,0xc2,0x0,0x0,0x0,0xc2,0x0,0x0,0x0,0xc2,0x0,0x0,0x0,0xc2,0x0,0x0,0x0,0xc2,0x0,0x0,0x0,0xc2,0x0,0x0,0x0,0xc2,0x0,0x0,0x0,0xc2,0x0,0x0,0x0,0xc2,0x0,0x0,0x0,0xc2,0x0,0x0,0x0,0xc2,0x0,0x0,0x0,0xc2,0x0,0x0,0x0,0xc1,0x0,0x0,0x0,0xcd,0x0,0x0,0x0,0xfa,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xe4,0x0,0x0,0x0,0x27,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x34,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xf2,0x0,0x0,0x0,0x46,0x0,0x0,0x0,0x7,0x0,0x0,0x0,0xa,0x0,0x0,0x0,0xa,0x0,0x0,0x0,0xa,0x0,0x0,0x0,0xa,0x0,0x0,0x0,0xa,0x0,0x0,0x0,0xa,0x0,0x0,0x0,0xa,0x0,0x0,0x0,0xa,0x0,0x0,0x0,0xa,0x0,0x0,0x0,0xa,0x0,0x0,0x0,0xa,0x0,0x0,0x0,0xa,0x0,0x0,0x0,0xa,0x0,0x0,0x0,0xa,0x0,0x0,0x0,0xa,0x0,0x0,0x0,0xa,0x0,0x0,0x0,0xa,0x0,0x0,0x0,0xa,0x0,0x0,0x0,0xa,0x0,0x0,0x0,0xa,0x0,0x0,0x0,0xa,0x0,0x0,0x0,0xa,0x0,0x0,0x0,0x7,0x0,0x0,0x0,0x4d,0x0,0x0,0x0,0xf5,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xd9,0x0,0x0,0x0,0x1c,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x34,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xc7,0x0,0x0,0x0,0x13,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x87,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xb9,0x0,0x0,0x0,0x8,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x34,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0x9d,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x8,0x0,0x0,0x0,0xb8,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0x93,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x34,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0x75,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x19,0x0,0x0,0x0,0xd8,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0x6a,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x34,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xf9,0x0,0x0,0x0,0x4d,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x34,0x0,0x0,0x0,0xef,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xf2,0x0,0x0,0x0,0x41,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x34,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xe8,0x0,0x0,0x0,0x2c,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x58,0x0,0x0,0x0,0xfc,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xca,0x0,0x0,0x0,0x15,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x34,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xba,0x0,0x0,0x0,0xe,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x80,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0x9f,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x34,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0x83,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xd,0x0,0x0,0x0,0xb8,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0x77,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x34,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xfd,0x0,0x0,0x0,0x59,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2a,0x0,0x0,0x0,0xe7,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xfa,0x0,0x0,0x0,0x4f,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x34,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xf0,0x0,0x0,0x0,0x36,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x4c,0x0,0x0,0x0,0xf9,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0x2d,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x34,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xd9,0x0,0x0,0x0,0x1a,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x72,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xbe,0x0,0x0,0x0,0xf,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x34,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xbb,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x9a,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0x86,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x34,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0x8d,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0xc3,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xfd,0x0,0x0,0x0,0x5d,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x34,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xf6,0x0,0x0,0x0,0x4c,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x3e,0x0,0x0,0x0,0xef,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xf1,0x0,0x0,0x0,0x38,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2b,0x0,0x0,0x0,0xe7,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xf9,0x0,0x0,0x0,0xbb,0x0,0x0,0x0,0xab,0x0,0x0,0x0,0xac,0x0,0x0,0x0,0xac,0x0,0x0,0x0,0xac,0x0,0x0,0x0,0xac,0x0,0x0,0x0,0xac,0x0,0x0,0x0,0xac,0x0,0x0,0x0,0xac,0x0,0x0,0x0,0xac,0x0,0x0,0x0,0xac,0x0,0x0,0x0,0xac,0x0,0x0,0x0,0xac,0x0,0x0,0x0,0xac,0x0,0x0,0x0,0xac,0x0,0x0,0x0,0xac,0x0,0x0,0x0,0xac,0x0,0x0,0x0,0xac,0x0,0x0,0x0,0xac,0x0,0x0,0x0,0xac,0x0,0x0,0x0,0xac,0x0,0x0,0x0,0xac,0x0,0x0,0x0,0xac,0x0,0x0,0x0,0xac,0x0,0x0,0x0,0xab,0x0,0x0,0x0,0xc6,0x0,0x0,0x0,0xfe,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xdd,0x0,0x0,0x0,0x1d,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xf,0x0,0x0,0x0,0xc4,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xa3,0x0,0x0,0x0,0x7,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x55,0x0,0x0,0x0,0xde,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xcc,0x0,0x0,0x0,0x2d,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x32,0x0,0x0,0x0,0x7f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x75,0x0,0x0,0x0,0x23,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0 + }; + PX_memset(&explorer,0,sizeof(explorer)); + if (Width<256) + { + Width=256; + } + if (Height<128) + { + Height=128; + } + explorer.backgroundcolor=PX_OBJECT_UI_DEFAULT_BACKGROUNDCOLOR; + explorer.cursorcolor=PX_OBJECT_UI_DEFAULT_CURSORCOLOR; + explorer.fontcolor=PX_OBJECT_UI_DEFAULT_FONTCOLOR; + explorer.bordercolor=PX_OBJECT_UI_DEFAULT_BORDERCOLOR; + + explorer.func_getpathfilecount=_func_gpfec; + explorer.func_getpathfilename=_func_gpfcn; + explorer.func_getpathfoldercount=_func_gpfdc; + explorer.func_getpathfoldername=_func_gpfdn; + explorer.returnType=PX_OBJECT_EXPLORER_RETURN_CANCEL; + explorer.MaxSelectedCount=1; + explorer.fontmodule=fm; + + if(!PX_ShapeCreateFromMemory(mp,PX_Object_Explorer_fileLogoData,sizeof(PX_Object_Explorer_fileLogoData),&explorer.file))return PX_NULL; + if(!PX_ShapeCreateFromMemory(mp,PX_Object_Explorer_folderLogoData,sizeof(PX_Object_Explorer_folderLogoData),&explorer.folder))return PX_NULL; + + pObject=PX_ObjectCreateEx(mp,Parent,(px_float)x,(px_float)y,0,(px_float)Width,(px_float)Height,0,PX_OBJECT_TYPE_EXPLORER,PX_NULL,PX_Object_ExplorerRender,PX_Object_ExplorerFree,&explorer,sizeof(PX_Object_Explorer)); + + if (!pObject) + { + return PX_NULL; + } + + do + { + PX_Object_Explorer *pExp=PX_Object_GetExplorer(pObject); + pExp->btn_Back=PX_Object_PushButtonCreate(mp,pObject,0,0,1,1,"<-Back",pExp->fontmodule); + pExp->btn_go=PX_Object_PushButtonCreate(mp,pObject,0,0,1,1,"Go->",pExp->fontmodule); + pExp->btn_Ok=PX_Object_PushButtonCreate(mp,pObject,0,0,1,1,"Ok",pExp->fontmodule); + pExp->btn_Cancel=PX_Object_PushButtonCreate(mp,pObject,0,0,1,1,"Cancel",pExp->fontmodule); + pExp->edit_Path=PX_Object_EditCreate(mp,pObject,0,0,1,1,pExp->fontmodule); + pExp->edit_FileName = PX_Object_EditCreate(mp, pObject, 0, 0, 1, 1, pExp->fontmodule); + PX_Object_EditSetText(pExp->edit_Path,path); + pExp->SliderBar=PX_Object_SliderBarCreate(mp,pObject,0,0,24,24,PX_OBJECT_SLIDERBAR_TYPE_VERTICAL,PX_OBJECT_SLIDERBAR_STYLE_BOX); + pExp->btn_Ok->Visible=PX_FALSE; + PX_ObjectRegisterEvent(pExp->btn_Back,PX_OBJECT_EVENT_EXECUTE,PX_Object_ExplorerOnButtonBack,pObject); + PX_ObjectRegisterEvent(pExp->btn_go,PX_OBJECT_EVENT_EXECUTE,PX_Object_ExplorerOnButtonGo,pObject); + PX_ObjectRegisterEvent(pExp->btn_Ok,PX_OBJECT_EVENT_EXECUTE,PX_Object_ExplorerOnButtonOk,pObject); + PX_ObjectRegisterEvent(pExp->btn_Cancel,PX_OBJECT_EVENT_EXECUTE,PX_Object_ExplorerOnButtonCancel,pObject); + + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORMOVE,PX_Object_ExplorerOnCursorMove,pObject); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORDOWN,PX_Object_ExplorerOnCursorDown,pObject); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORWHEEL,PX_Object_ExplorerOnCursorWheel,pObject); + } while (0); + + PX_Object_ExplorerRefresh(pObject); + pObject->Visible=PX_FALSE; + pObject->OnLostFocusReleaseEvent=PX_TRUE; + return pObject; +} + +px_void PX_Object_ExplorerSetBorderColor(PX_Object *Object,px_color clr) +{ + PX_Object_Explorer *pExp=PX_Object_GetExplorer(Object); + if (pExp) + { + pExp->bordercolor=clr; + } +} + +px_void PX_Object_ExplorerSetPushColor(PX_Object *Object,px_color clr) +{ + PX_Object_Explorer *pExp=PX_Object_GetExplorer(Object); + if (pExp) + { + pExp->pushcolor=clr; + } +} + +px_void PX_Object_ExplorerSetCursorColor(PX_Object *Object,px_color clr) +{ + PX_Object_Explorer *pExp=PX_Object_GetExplorer(Object); + if (pExp) + { + pExp->cursorcolor=clr; + } +} + +px_void PX_Object_ExplorerSetTextColor(PX_Object *Object,px_color clr) +{ + PX_Object_Explorer *pExp=PX_Object_GetExplorer(Object); + if (pExp) + { + pExp->fontcolor=clr; + } +} + +px_void PX_Object_ExplorerRefresh(PX_Object *Object) +{ + PX_Object_Explorer *pExp=PX_Object_GetExplorer(Object); + px_char FileNames[PX_EXPLORER_MAX_ITEMS][260]; + + if (pExp) + { + px_int i; + px_int count; + px_char *path=PX_Object_EditGetText(pExp->edit_Path); + + if (!pExp->func_getpathfilecount||!pExp->func_getpathfilename||!pExp->func_getpathfoldercount||!pExp->func_getpathfoldername) + { + return; + } + + + pExp->ItemCount=0; + + //folder + count=pExp->func_getpathfoldercount(path,pExp->filter); + if (count>PX_EXPLORER_MAX_ITEMS) + { + count=PX_EXPLORER_MAX_ITEMS; + } + pExp->func_getpathfoldername(path,count,FileNames,pExp->filter); + for (i=0;iItems[i].bcursor=PX_FALSE; + pExp->Items[i].bFolder=PX_TRUE; + pExp->Items[i].bselect=PX_FALSE; + PX_strcpy(pExp->Items[i].name,FileNames[i],sizeof(pExp->Items[i].name)); + } + pExp->ItemCount+=count; + + count=pExp->func_getpathfilecount(path,pExp->filter); + if (count>PX_EXPLORER_MAX_ITEMS-pExp->ItemCount) + { + count=PX_EXPLORER_MAX_ITEMS-pExp->ItemCount; + } + pExp->func_getpathfilename(path,count,FileNames,pExp->filter); + for (i=0;iItems[pExp->ItemCount+i].bcursor=PX_FALSE; + pExp->Items[pExp->ItemCount+i].bFolder=PX_FALSE; + pExp->Items[pExp->ItemCount+i].bselect=PX_FALSE; + PX_strcpy(pExp->Items[pExp->ItemCount+i].name,FileNames[i],sizeof(pExp->Items[0].name)); + } + pExp->ItemCount+=count; + PX_Object_SliderBarSetValue(pExp->SliderBar,0); + + if (pExp->savemode) + { + PX_Object_EditSetText(pExp->edit_FileName, ""); + } + } +} +px_int PX_Object_ExplorerGetSelectedCount(PX_Object *Object) +{ + PX_Object_Explorer *pExp=PX_Object_GetExplorer(Object); + px_int selectCount=0; + px_int i; + for (i=0;iItemCount;i++) + { + if (pExp->Items[i].bselect) + { + selectCount++; + } + } + return selectCount; +} +px_void PX_Object_ExplorerGetPath(PX_Object *Object,px_char path[PX_EXPLORER_MAX_PATH_LEN],px_int index) +{ + PX_Object_Explorer *pExp=PX_Object_GetExplorer(Object); + px_int selectCount=0,selectIndex=0; + px_int i; + for (i=0;iItemCount;i++) + { + if (pExp->Items[i].bselect) + { + selectCount++; + } + } + if (pExp->savemode) + { + PX_strcpy(path, PX_Object_EditGetText(pExp->edit_Path), PX_EXPLORER_MAX_PATH_LEN); + if(path[0]) + PX_strcat(path, "/"); + PX_strcat(path, PX_Object_EditGetText(pExp->edit_FileName)); + } + else + { + if (index < selectCount) + { + for (i = 0; i < pExp->ItemCount; i++) + { + if (pExp->Items[i].bselect) + { + if (selectIndex == index) + { + PX_strcpy(path, PX_Object_EditGetText(pExp->edit_Path), PX_EXPLORER_MAX_PATH_LEN); + if (path[PX_strlen(path) - 1] != '/' && path[PX_strlen(path) - 1] != '\\' && path[0]) + { + PX_strcat(path, "/"); + } + PX_strcat(path, pExp->Items[i].name); + } + selectIndex++; + } + } + } + else + { + path[0] = '\0'; + } + } +} + +px_void PX_Object_ExplorerOpen(PX_Object *Object) +{ + if (Object->Type!=PX_OBJECT_TYPE_EXPLORER) + { + PX_ASSERT(); + return; + } + PX_ObjectSetFocus(Object); + PX_Object_ExplorerRefresh(Object); + Object->Visible=PX_TRUE; + PX_ObjectGetDesc(PX_Object_Explorer, Object)->savemode = PX_FALSE; +} + +px_void PX_Object_ExplorerSave(PX_Object* Object) +{ + if (Object->Type != PX_OBJECT_TYPE_EXPLORER) + { + PX_ASSERT(); + return; + } + PX_ObjectSetFocus(Object); + PX_Object_ExplorerRefresh(Object); + Object->Visible = PX_TRUE; + PX_ObjectGetDesc(PX_Object_Explorer, Object)->savemode = PX_TRUE; +} + +px_void PX_Object_ExplorerClose(PX_Object *Object) +{ + PX_ObjectClearFocus(Object); + Object->Visible=PX_FALSE; +} + +px_void PX_Object_ExplorerSetFilter(PX_Object *Object,const px_char *filter) +{ + PX_Object_Explorer *pExp=PX_Object_GetExplorer(Object); + if (pExp) + { + PX_memset(pExp->filter,0,sizeof(pExp->filter)); + PX_strcpy(pExp->filter,filter,sizeof(pExp->filter)); + } + +} +px_void PX_Object_ExplorerSetMaxSelectCount(PX_Object *Object,int selectCount) +{ + PX_Object_Explorer *pExp=PX_Object_GetExplorer(Object); + if (pExp) + { + pExp->MaxSelectedCount=selectCount; + } +} diff --git a/lib/PainterEngine/kernel/PX_Object_Explorer.h b/lib/PainterEngine/kernel/PX_Object_Explorer.h new file mode 100644 index 0000000000000000000000000000000000000000..3d5d7e6d69615de998e352aa325aa15feaf39706 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_Explorer.h @@ -0,0 +1,78 @@ +#ifndef PX_OBJECT_EXPLORER_H +#define PX_OBJECT_EXPLORER_H +#include "PX_Object.h" +#define PX_EXPLORER_MAX_PATH_LEN 260 +#define PX_EXPLORER_MAX_ITEMS 1024 +#define PX_OBJECT_EXPOLRER_MENU_HEIGHT 48 +#define PX_OBJECT_EXPOLRER_ITEM_HEIGHT 38 +#define PX_OBJECT_EXPOLRER_SLIDERBAR_WIDTH 24 +#define PX_OBJECT_EXPOLRER_BUTTON_WIDTH 64 +typedef px_int (*PX_ExplorerGetPathFolderCount)(const px_char *path,const char *filter); +typedef px_int (*PX_ExplorerGetPathFileCount)(const px_char *path,const char *filter); +typedef px_int (*PX_ExplorerGetPathFolderName)(const char path[],int count,char FileName[][260],const char *filter); +typedef px_int (*PX_ExplorerGetPathFileName)(const char path[],int count,char FileName[][260],const char *filter); + +typedef struct +{ + px_bool bFolder; + px_bool bcursor; + px_bool bselect; + px_char name[260]; +}PX_Object_Explorer_Item; + +typedef enum +{ + PX_OBJECT_EXPLORER_RETURN_CONFIRM, + PX_OBJECT_EXPLORER_RETURN_CANCEL, +}PX_OBJECT_EXPLORER_RETURN; + + +typedef struct +{ + PX_ExplorerGetPathFolderCount func_getpathfoldercount; + PX_ExplorerGetPathFileCount func_getpathfilecount; + PX_ExplorerGetPathFolderName func_getpathfoldername; + PX_ExplorerGetPathFileName func_getpathfilename; + px_bool savemode; + px_int ItemCount; + px_int MaxSelectedCount; + PX_FontModule *fontmodule; + PX_Object_Explorer_Item Items[PX_EXPLORER_MAX_ITEMS]; + + PX_Object *edit_Path; + PX_Object* edit_FileName; + PX_Object *btn_Back,*btn_go,*btn_Ok,*btn_Cancel; + PX_Object *SliderBar; + px_char filter[PX_EXPLORER_MAX_PATH_LEN]; + + px_shape file,folder; + + px_color backgroundcolor,cursorcolor,fontcolor,bordercolor,pushcolor; + + PX_OBJECT_EXPLORER_RETURN returnType; + +}PX_Object_Explorer; + +PX_Object_Explorer *PX_Object_GetExplorer(PX_Object *Object); +PX_Object * PX_Object_ExplorerCreate(px_memorypool *mp, PX_Object *Parent,px_int x,px_int y,px_int Width,px_int Height,PX_FontModule *fm, + PX_ExplorerGetPathFolderCount _func_gpfdc, + PX_ExplorerGetPathFileCount _func_gpfec, + PX_ExplorerGetPathFolderName _func_gpfdn, + PX_ExplorerGetPathFileName _func_gpfcn, + const px_char path[260] +); +px_void PX_Object_ExplorerSetBorderColor(PX_Object *Object,px_color clr); +px_void PX_Object_ExplorerSetPushColor(PX_Object *Object,px_color clr); +px_void PX_Object_ExplorerSetCursorColor(PX_Object *Object,px_color clr); +px_void PX_Object_ExplorerSetTextColor(PX_Object *Object,px_color clr); +px_void PX_Object_ExplorerRefresh(PX_Object *Object); +px_int PX_Object_ExplorerGetSelectedCount(PX_Object *Object); +px_void PX_Object_ExplorerGetPath(PX_Object *Object,px_char path[PX_EXPLORER_MAX_PATH_LEN],px_int index); +px_void PX_Object_ExplorerOpen(PX_Object *Object); +px_void PX_Object_ExplorerSave(PX_Object* Object); +px_void PX_Object_ExplorerClose(PX_Object *Object); +px_void PX_Object_ExplorerSetFilter(PX_Object *Object,const px_char *filter); +px_void PX_Object_ExplorerSetMaxSelectCount(PX_Object *Object,int selectCount); + + +#endif diff --git a/lib/PainterEngine/kernel/PX_Object_IPBox.c b/lib/PainterEngine/kernel/PX_Object_IPBox.c new file mode 100644 index 0000000000000000000000000000000000000000..84a6b3ab7ce4401aabe2c9361694a2306a4c2c2f --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_IPBox.c @@ -0,0 +1,79 @@ +#include "PX_Object_IPBox.h" + +PX_Object_IPBox* PX_Object_GetIPBox(PX_Object* pObject) +{ + if (pObject->Type==PX_OBJECT_TYPE_IPBOX) + { + return PX_ObjectGetDesc(PX_Object_IPBox, pObject); + } + return PX_NULL; +} + +px_void PX_Object_IPBoxOnConfirm(PX_Object* pObject, PX_Object_Event e, px_void* ptr) +{ + PX_Object_IPBox* pdesc = PX_ObjectGetDesc(PX_Object_IPBox, ((PX_Object*)ptr)); + if (!PX_IsValidIPAddress(PX_Object_VariousGetText(pdesc->various_ip))) + { + PX_Object_VariousSetTextColor(pdesc->various_ip, PX_COLOR_RED); + } + else + { + PX_ObjectExecuteEvent((PX_Object*)ptr, e); + PX_Object_IPBoxClose((PX_Object*)ptr); + } + +} + +px_void PX_Object_IPBoxOnCancel(PX_Object* pObject, PX_Object_Event e, px_void* ptr) +{ + PX_Object_IPBoxClose((PX_Object*)ptr); +} + +px_void PX_Object_IPBoxOnEditChanged(PX_Object* pObject, PX_Object_Event e, px_void* ptr) +{ + PX_Object_IPBox* pdesc = PX_ObjectGetDesc(PX_Object_IPBox,((PX_Object *)ptr)); + + PX_Object_VariousSetTextColor(pdesc->various_ip, PX_OBJECT_UI_DEFAULT_FONTCOLOR); +} + +PX_Object* PX_Object_IPBoxCreate(px_memorypool* mp, PX_Object* Parent, int x, int y, int width, int height, const px_char title[], PX_FontModule* fontmodule) +{ + PX_Object_IPBox desc, * pdesc; + PX_Object* pObject; + pObject = PX_ObjectCreateEx(mp, Parent, (px_float)x, (px_float)y, 0, (px_float)width, (px_float)height, 0, PX_OBJECT_TYPE_IPBOX, PX_NULL, PX_NULL, PX_NULL, &desc, sizeof(desc)); + pdesc = PX_ObjectGetDesc(PX_Object_IPBox, pObject); + pdesc->widget = PX_Object_WidgetCreate(mp, pObject, 0, 0, width, height, "", fontmodule); + PX_Object_WidgetShowHideCloseButton(pdesc->widget, PX_FALSE); + pdesc->various_ip = PX_Object_VariousCreate(mp, pdesc->widget , width / 2 - 128, height / 2 - 64, 256, 32, "IP:",PX_OBJECT_VARIOUS_TYPE_EDIT,fontmodule); + PX_Object_VariousSetEditStyle(pdesc->various_ip, PX_OBJECT_VARIOUS_EDIT_TYPE_STRING); + pdesc->various_port = PX_Object_VariousCreate(mp, pdesc->widget, width / 2 - 128, height / 2 - 24, 256, 32, "Port:", PX_OBJECT_VARIOUS_TYPE_EDIT, fontmodule); + PX_Object_VariousSetEditStyle(pdesc->various_port, PX_OBJECT_VARIOUS_EDIT_TYPE_INT); + pdesc->btn_ok = PX_Object_PushButtonCreate(mp, pdesc->widget, width - 256, height - 68, 96, 32, "OK", fontmodule); + pdesc->btn_close = PX_Object_PushButtonCreate(mp, pdesc->widget, width - 128, height - 68, 96, 32, "Cancel", fontmodule); + + PX_ObjectRegisterEvent(pdesc->btn_ok, PX_OBJECT_EVENT_EXECUTE, PX_Object_IPBoxOnConfirm, pObject); + PX_ObjectRegisterEvent(pdesc->btn_close, PX_OBJECT_EVENT_EXECUTE, PX_Object_IPBoxOnCancel, pObject); + PX_ObjectRegisterEvent(pdesc->various_ip, PX_OBJECT_EVENT_VALUECHANGED, PX_Object_IPBoxOnEditChanged, pObject); + + pdesc->widget->Visible = PX_TRUE; + pObject->Visible = PX_FALSE; + return pObject; +} + +px_void PX_Object_IPBoxShow(PX_Object* pObject) +{ + pObject->Visible = PX_TRUE; + PX_ObjectSetFocus(pObject); +} + +px_void PX_Object_IPBoxClose(PX_Object* pObject) +{ + pObject->Visible = PX_FALSE; + PX_ObjectClearFocus(pObject); +} + +px_void PX_Object_IPBoxHide(PX_Object* pObject) +{ + pObject->Visible = PX_FALSE; + PX_ObjectClearFocus(pObject); +} \ No newline at end of file diff --git a/lib/PainterEngine/kernel/PX_Object_IPBox.h b/lib/PainterEngine/kernel/PX_Object_IPBox.h new file mode 100644 index 0000000000000000000000000000000000000000..6e3e90a150e35e4d3718387b99e2979decf4507d --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_IPBox.h @@ -0,0 +1,20 @@ +#ifndef PX_OBJECT_IPBOX_H +#define PX_OBJECT_IPBOX_H +#include "PX_Object.h" + + +typedef struct +{ + PX_Object *widget; + PX_Object* various_ip; + PX_Object* various_port; + PX_Object *btn_close; + PX_Object *btn_ok; +}PX_Object_IPBox; + +PX_Object_IPBox* PX_Object_GetIPBox( PX_Object *Object ); +PX_Object * PX_Object_IPBoxCreate(px_memorypool *mp,PX_Object *Parent,int x,int y,int width,int height,const px_char title[],PX_FontModule *fontmodule); +px_void PX_Object_IPBoxShow(PX_Object *pObject); +px_void PX_Object_IPBoxClose(PX_Object* pObject); +#endif + diff --git a/lib/PainterEngine/kernel/PX_Object_Image.c b/lib/PainterEngine/kernel/PX_Object_Image.c new file mode 100644 index 0000000000000000000000000000000000000000..cba7ebd18d4e8f1f151c7f3a7f378b58b704df2d --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_Image.c @@ -0,0 +1,212 @@ +#include "PX_Object_Image.h" + +px_void PX_Object_ImageRender(px_surface *psurface, PX_Object *pObject,px_uint elapsed) +{ + PX_Object_Image *pImage=PX_Object_GetImage(pObject); + px_int x,y,w,h; + PX_SurfaceLimitInfo limitInfo; + px_float inheritX,inheritY; + if (!pImage->pTexture) + { + return; + } + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + x=(px_int)(pObject->x+inheritX); + y=(px_int)(pObject->y+inheritY); + w=(px_int)pObject->Width; + h=(px_int)pObject->Height; + + limitInfo=PX_SurfaceGetLimit(psurface); + PX_SurfaceSetLimit(psurface,x,y,x+w-1,y+h-1); + + switch(pImage->Align) + { + case PX_ALIGN_LEFTTOP: + { + if (pImage!=PX_NULL) + { + if(pImage->pmask) + PX_TextureRenderMask(psurface,pImage->pmask,pImage->pTexture,x,y,PX_ALIGN_LEFTTOP,PX_NULL); + else + PX_TextureRender(psurface,pImage->pTexture,x,y,PX_ALIGN_LEFTTOP,PX_NULL); + } + } + break; + case PX_ALIGN_LEFTMID: + { + if (pImage!=PX_NULL) + { + if(pImage->pmask) + PX_TextureRenderMask(psurface,pImage->pmask,pImage->pTexture,x,y+h/2,PX_ALIGN_LEFTMID,PX_NULL); + else + PX_TextureRender(psurface,pImage->pTexture,x,y+h/2,PX_ALIGN_LEFTMID,PX_NULL); + } + } + break; + case PX_ALIGN_LEFTBOTTOM: + { + if (pImage!=PX_NULL) + { + if(pImage->pmask) + PX_TextureRenderMask(psurface,pImage->pmask,pImage->pTexture,x,y+h,PX_ALIGN_LEFTBOTTOM,PX_NULL); + else + PX_TextureRender(psurface,pImage->pTexture,x,y+h,PX_ALIGN_LEFTBOTTOM,PX_NULL); + } + } + break; + case PX_ALIGN_MIDTOP: + { + if (pImage!=PX_NULL) + { + if(pImage->pmask) + PX_TextureRenderMask(psurface,pImage->pmask,pImage->pTexture,x+w/2,y,PX_ALIGN_MIDTOP,PX_NULL); + else + PX_TextureRender(psurface,pImage->pTexture,x+w/2,y,PX_ALIGN_MIDTOP,PX_NULL); + } + } + break; + case PX_ALIGN_CENTER: + { + if (pImage!=PX_NULL) + { + if(pImage->pmask) + PX_TextureRenderMask(psurface,pImage->pmask,pImage->pTexture,x+w/2,y+h/2,PX_ALIGN_CENTER,PX_NULL); + else + PX_TextureRender(psurface,pImage->pTexture,x+w/2,y+h/2,PX_ALIGN_CENTER,PX_NULL); + } + } + break; + case PX_ALIGN_MIDBOTTOM: + { + if (pImage!=PX_NULL) + { + if(pImage->pmask) + PX_TextureRenderMask(psurface,pImage->pmask,pImage->pTexture,x+w/2,y+h,PX_ALIGN_MIDBOTTOM,PX_NULL); + else + PX_TextureRender(psurface,pImage->pTexture,x+w/2,y+h,PX_ALIGN_MIDBOTTOM,PX_NULL); + } + } + break; + case PX_ALIGN_RIGHTTOP: + { + if (pImage!=PX_NULL) + { + if(pImage->pmask) + PX_TextureRenderMask(psurface,pImage->pmask,pImage->pTexture,x+w,y,PX_ALIGN_RIGHTTOP,PX_NULL); + else + PX_TextureRender(psurface,pImage->pTexture,x+w,y,PX_ALIGN_RIGHTTOP,PX_NULL); + } + } + break; + case PX_ALIGN_RIGHTMID: + { + if (pImage!=PX_NULL) + { + if(pImage->pmask) + PX_TextureRenderMask(psurface,pImage->pmask,pImage->pTexture,x+w,y+h/2,PX_ALIGN_RIGHTMID,PX_NULL); + else + PX_TextureRender(psurface,pImage->pTexture,x+w,y+h/2,PX_ALIGN_RIGHTMID,PX_NULL); + } + } + break; + case PX_ALIGN_RIGHTBOTTOM: + { + if (pImage!=PX_NULL) + { + if(pImage->pmask) + PX_TextureRenderMask(psurface,pImage->pmask,pImage->pTexture,x+w,y+h,PX_ALIGN_RIGHTBOTTOM,PX_NULL); + else + PX_TextureRender(psurface,pImage->pTexture,x+w,y+h,PX_ALIGN_RIGHTBOTTOM,PX_NULL); + } + } + break; + } + + PX_SurfaceSetLimitInfo(psurface,limitInfo); + +} + +px_void PX_Object_ImageFree( PX_Object *pBitmap ) +{ + +} + +PX_Object * PX_Object_ImageCreate(px_memorypool *mp,PX_Object *Parent,px_int x,px_int y,px_int width,px_int height,px_texture *ptex ) +{ + PX_Object *pObject; + PX_Object_Image *pImage=(PX_Object_Image *)MP_Malloc(mp,sizeof(PX_Object_Image)); + if (pImage==PX_NULL) + { + return PX_NULL; + } + pObject=PX_ObjectCreate(mp,Parent,(px_float)x,(px_float)y,0,(px_float)width,(px_float)height,0); + if (pObject==PX_NULL) + { + MP_Free(pObject->mp,pImage); + return PX_NULL; + } + + pObject->pObject=pImage; + pObject->Enabled=PX_TRUE; + pObject->Visible=PX_TRUE; + pObject->Type=PX_OBJECT_TYPE_IMAGE; + pObject->ReceiveEvents=PX_FALSE; + pObject->Func_ObjectFree=PX_Object_ImageFree; + pObject->Func_ObjectRender=PX_Object_ImageRender; + pImage->pTexture=ptex; + pImage->pmask=PX_NULL; + pImage->Align=PX_ALIGN_CENTER; + return pObject; +} + + +PX_Object_Image * PX_Object_GetImage( PX_Object *Object ) +{ + if(Object->Type==PX_OBJECT_TYPE_IMAGE) + return (PX_Object_Image *)Object->pObject; + else + return PX_NULL; +} + +px_void PX_Object_ImageSetAlign( PX_Object *pImage,PX_ALIGN Align) +{ + PX_Object_Image *Bitmap=PX_Object_GetImage(pImage); + if (Bitmap) + { + Bitmap->Align=Align; + } +} + + +px_void PX_Object_ImageSetMask(PX_Object *pObject,px_texture *pmask) +{ + PX_Object_Image *pImg=PX_Object_GetImage(pObject); + if (pImg) + { + pImg->pmask=pmask; + } +} + + +px_void PX_Object_ImageSetTexture(PX_Object *pObject,px_texture *pTex) +{ + PX_Object_Image *pImg=PX_Object_GetImage(pObject); + if (pImg) + { + pImg->pTexture=pTex; + } +} + + +px_void PX_Object_ImageFreeWithTexture(PX_Object *pBitmap) +{ + PX_Object_Image *pImage; + pImage=PX_Object_GetImage(pBitmap); + if (pImage) + { + PX_TextureFree(pImage->pTexture); + } +} + diff --git a/lib/PainterEngine/kernel/PX_Object_Image.h b/lib/PainterEngine/kernel/PX_Object_Image.h new file mode 100644 index 0000000000000000000000000000000000000000..06a4e4fe90b16669211ffe36dd27464cf2e436b5 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_Image.h @@ -0,0 +1,25 @@ +#ifndef PX_OBJECT_IMAGE_H +#define PX_OBJECT_IMAGE_H +#include "PX_Object.h" + + +typedef struct +{ + PX_ALIGN Align; + px_texture *pTexture; + px_texture *pmask; +}PX_Object_Image; + +PX_Object * PX_Object_ImageCreate(px_memorypool *mp,PX_Object *Parent,px_int x,px_int y,px_int width,px_int height,px_texture *ptex ); +PX_Object_Image *PX_Object_GetImage(PX_Object *Object); +px_void PX_Object_ImageSetAlign(PX_Object *pObject,PX_ALIGN Align); +px_void PX_Object_ImageSetMask(PX_Object *pObject,px_texture *pmask); +px_void PX_Object_ImageSetTexture(PX_Object *pObject,px_texture *pTex); +px_void PX_Object_ImageFreeWithTexture(PX_Object *pObject); + + + +#endif + + + diff --git a/lib/PainterEngine/kernel/PX_Object_Joystick.c b/lib/PainterEngine/kernel/PX_Object_Joystick.c new file mode 100644 index 0000000000000000000000000000000000000000..ab16639655671a38cc9eaf71c57459f6517b3f89 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_Joystick.c @@ -0,0 +1,184 @@ +#include "PX_Object_Joystick.h" + +PX_Object_Joystick* PX_Object_GetJoystick(PX_Object* pObject) { + if (pObject->Type != PX_OBJECT_TYPE_JOYSTICK) { + return PX_NULL; + } + return (PX_Object_Joystick*)pObject->pObject; +} + +px_double PX_Object_JoystickGetAngle(PX_Object* pObject) { + if (pObject->Type != PX_OBJECT_TYPE_JOYSTICK) { + return 0.0; + } + return ((PX_Object_Joystick*)(pObject->pObject))->Angle; +} + +px_double PX_Object_JoystickGetDistance(PX_Object* pObject) { + if (pObject->Type != PX_OBJECT_TYPE_JOYSTICK) { + return 0.0; + } + return ((PX_Object_Joystick*)(pObject->pObject))->Distance; +} + +px_point2D PX_Object_JoystickGetVector(PX_Object* pObject) { + px_point2D p; + if (pObject->Type != PX_OBJECT_TYPE_JOYSTICK) { + p.x = 0.0; + p.y = 0.0; + } else { + p.x = ((PX_Object_Joystick*)(pObject->pObject))->Distance * + (px_float)PX_cosd(((PX_Object_Joystick*)(pObject->pObject))->Angle); + p.y = ((PX_Object_Joystick*)(pObject->pObject))->Distance * + (px_float)PX_sind(((PX_Object_Joystick*)(pObject->pObject))->Angle); + } + return p; +} + +/////////////////////////////////////////////// + +px_void Func_JoystickRender(px_surface* pSurface, PX_Object* pObject, px_uint elapsed); +px_void Func_JoystickOnCursorDown(PX_Object* pObject, PX_Object_Event e, px_void* ptr); +px_void Func_JoystickOnCursorDrag(PX_Object* pObject, PX_Object_Event e, px_void* ptr); +px_void Func_JoystickOnCursorUp(PX_Object* pObject, PX_Object_Event e, px_void* ptr); + +PX_Object* PX_Object_JoystickCreate(px_memorypool* mp, PX_Object* Parent, + px_float x, px_float y, + px_float deferentR, px_float epicycleR, px_float senseR, + px_color deferentColor, px_color epicycleColoe) { + + px_float z = 0.0f; + PX_Object* pObject; + PX_Object_Joystick joystick; + + joystick.DeferentColor = deferentColor; + joystick.EpicycleColor = epicycleColoe; + joystick.Distance = 0.0; + joystick.Angle = 0.0; + joystick.DeferentRadius = deferentR; + joystick.EpicycleRadius = epicycleR; + joystick.SenseRadius = senseR; + + pObject = PX_ObjectCreateEx(mp, Parent, + x, y, z, + 0.0f, 0.0f, 0.0f, PX_OBJECT_TYPE_JOYSTICK, + PX_NULL, Func_JoystickRender, PX_NULL, &joystick, sizeof(PX_Object_Joystick)); + + if (pObject == PX_NULL) { + return PX_NULL; + } + + pObject->diameter = 2 * joystick.SenseRadius; + + PX_ObjectRegisterEvent(pObject, PX_OBJECT_EVENT_CURSORDOWN, Func_JoystickOnCursorDown, PX_NULL); + PX_ObjectRegisterEvent(pObject, PX_OBJECT_EVENT_CURSORDRAG, Func_JoystickOnCursorDrag, PX_NULL); + PX_ObjectRegisterEvent(pObject, PX_OBJECT_EVENT_CURSORUP, Func_JoystickOnCursorUp, PX_NULL); + + return pObject; +} + +px_void Func_JoystickRender(px_surface* pSurface, PX_Object* pObject, px_uint elapsed) { + PX_Object_Joystick* pJoystick = (PX_Object_Joystick*)pObject->pObject; + px_float objx, objy, objWidth, objHeight; + px_float inheritX, inheritY; + PX_ObjectGetInheritXY(pObject, &inheritX, &inheritY); + + objx = (pObject->x + inheritX); + objy = (pObject->y + inheritY); + objWidth = pObject->Width; + objHeight = pObject->Height; + + PX_GeoDrawSolidCircle( + pSurface, + (px_int)objx, + (px_int)objy, + (px_int)pJoystick->DeferentRadius, pJoystick->DeferentColor); + PX_GeoDrawSolidCircle( + pSurface, + (px_int)(objx + pJoystick->Distance * PX_cosd(pJoystick->Angle)), + (px_int)(objy + pJoystick->Distance * PX_sind(pJoystick->Angle)), + (px_int)(pJoystick->EpicycleRadius), pJoystick->EpicycleColor); +} + +px_void Func_JoystickOnCursorDown(PX_Object* pObject, PX_Object_Event e, px_void* ptr) { + PX_Object_Joystick* pJoystick = (PX_Object_Joystick*)pObject->pObject; + px_float objx, objy, objWidth, objHeight; + px_float inheritX, inheritY; + px_float x,y,r; + PX_ObjectGetInheritXY(pObject, &inheritX, &inheritY); + + objx = (pObject->x + inheritX); + objy = (pObject->y + inheritY); + objWidth = pObject->Width; + objHeight = pObject->Height; + x = PX_Object_Event_GetCursorX(e) - objx, + y = PX_Object_Event_GetCursorY(e) - objy, + r = PX_sqrt(x * x + y * y); + + if (pJoystick->IsAciton) { + return; + } + + if (r < pJoystick->SenseRadius) { + pJoystick->IsAciton = PX_TRUE; + pJoystick->Distance = r; + pJoystick->Angle = (px_float)PX_atan2(y, x); + } else { + pJoystick->Distance = 0.0f; + } +} + +px_void Func_JoystickOnCursorDrag(PX_Object* pObject, PX_Object_Event e, px_void* ptr) { + PX_Object_Joystick* pJoystick = (PX_Object_Joystick*)pObject->pObject; + px_float objx, objy, objWidth, objHeight; + px_float inheritX, inheritY; + px_float x,y,r; + PX_ObjectGetInheritXY(pObject, &inheritX, &inheritY); + + objx = (pObject->x + inheritX); + objy = (pObject->y + inheritY); + objWidth = pObject->Width; + objHeight = pObject->Height; + + x = PX_Object_Event_GetCursorX(e) - objx, + y = PX_Object_Event_GetCursorY(e) - objy, + r = PX_sqrt(x * x + y * y); + + if (!pJoystick->IsAciton) { + return; + } + + if (r <= pJoystick->DeferentRadius) { + pJoystick->Distance = r; + } else if (r <= pJoystick->SenseRadius) { + pJoystick->Distance = pJoystick->DeferentRadius; + } else { + pJoystick->Distance = 0.0f; + pJoystick->IsAciton = PX_FALSE; + return; + } + + pJoystick->Angle = (px_float)PX_atan2(y, x); +} + +px_void Func_JoystickOnCursorUp(PX_Object* pObject, PX_Object_Event e, px_void* ptr) { + PX_Object_Joystick* pJoystick = (PX_Object_Joystick*)pObject->pObject; + px_float objx, objy, objWidth, objHeight; + px_float inheritX, inheritY; + px_float x,y,r; + PX_ObjectGetInheritXY(pObject, &inheritX, &inheritY); + + objx = (pObject->x + inheritX); + objy = (pObject->y + inheritY); + objWidth = pObject->Width; + objHeight = pObject->Height; + + x = PX_Object_Event_GetCursorX(e) - objx, + y = PX_Object_Event_GetCursorY(e) - objy, + r = PX_sqrt(x * x + y * y); + + if (r <= pJoystick->SenseRadius) { + pJoystick->Distance = 0.0f; + pJoystick->IsAciton = PX_FALSE; + } +} \ No newline at end of file diff --git a/lib/PainterEngine/kernel/PX_Object_Joystick.h b/lib/PainterEngine/kernel/PX_Object_Joystick.h new file mode 100644 index 0000000000000000000000000000000000000000..74e97f764c81411d82dc06e24caff76d2eb1443e --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_Joystick.h @@ -0,0 +1,31 @@ +#ifndef PX_OBJECT_JOYSTICK_H +#define PX_OBJECT_JOYSTICK_H + +#include"PX_Object.h" + +typedef struct { + px_color DeferentColor; + px_color EpicycleColor; + px_float Distance; + px_float Angle; + px_float DeferentRadius; + px_float EpicycleRadius; + px_float SenseRadius; + px_bool IsAciton; +}PX_Object_Joystick; + +PX_Object* PX_Object_JoystickCreate(px_memorypool* mp, PX_Object* Parent, + px_float x, px_float y, + px_float deferentR, px_float epicycleR, px_float senseR, + px_color deferentColor, px_color epicycleColoe); + +PX_Object_Joystick* PX_Object_GetJoystick(PX_Object* pObject); + +px_double PX_Object_JoystickGetAngle(PX_Object* pObject); + +px_double PX_Object_JoystickGetDistance(PX_Object* pObject); + +px_point2D PX_Object_JoystickGetVector(PX_Object *pObject); + +#endif + diff --git a/lib/PainterEngine/kernel/PX_Object_Label.c b/lib/PainterEngine/kernel/PX_Object_Label.c new file mode 100644 index 0000000000000000000000000000000000000000..fd65e82d24afd0ef2784bb57d729e8b15703be54 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_Label.c @@ -0,0 +1,250 @@ +#include "PX_Object_Label.h" + +px_void PX_Object_LabelRender(px_surface *psurface, PX_Object *pObject,px_uint elapsed) +{ + px_int x,y,w,h; + px_float inheritX,inheritY; + PX_SurfaceLimitInfo limitInfo; + PX_Object_Label *pLabel=(PX_Object_Label *)pObject->pObject; + if (pLabel==PX_NULL) + { + return; + } + + if (!pObject->Visible) + { + return; + } + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + x=(px_int)(pObject->x+inheritX); + y=(px_int)(pObject->y+inheritY); + w=(px_int)pObject->Width; + h=(px_int)pObject->Height; + + PX_GeoDrawRect(psurface,x,y,x+w,y+h-1,pLabel->BackgroundColor); + if (pLabel->bBorder) + { + switch(pLabel->style) + { + case PX_OBJECT_LABEL_STYLE_ROUNDRECT: + PX_GeoDrawRoundRect(psurface,x,y,x+w,y+h-1,h/2-2.0f,1,pLabel->borderColor); + break; + default: + PX_GeoDrawBorder(psurface,x,y,x+w,y+h-1,1,pLabel->borderColor); + } + } + + limitInfo=PX_SurfaceGetLimit(psurface); + PX_SurfaceSetLimit(psurface,x,y,x+w-1,y+h-1); + + switch (pLabel->Align) + { + case PX_ALIGN_LEFTTOP: + PX_FontModuleDrawText(psurface,pLabel->fontModule,x,y,PX_ALIGN_LEFTTOP,pLabel->Text,pLabel->TextColor); + break; + case PX_ALIGN_LEFTMID: + PX_FontModuleDrawText(psurface,pLabel->fontModule,x,y+h/2,PX_ALIGN_LEFTMID,pLabel->Text,pLabel->TextColor); + break; + case PX_ALIGN_LEFTBOTTOM: + PX_FontModuleDrawText(psurface,pLabel->fontModule,x,y+h,PX_ALIGN_LEFTBOTTOM,pLabel->Text,pLabel->TextColor); + break; + case PX_ALIGN_MIDTOP: + PX_FontModuleDrawText(psurface,pLabel->fontModule,x+w/2,y,PX_ALIGN_MIDTOP,pLabel->Text,pLabel->TextColor); + break; + case PX_ALIGN_CENTER: + PX_FontModuleDrawText(psurface,pLabel->fontModule,x+w/2,y+h/2,PX_ALIGN_CENTER,pLabel->Text,pLabel->TextColor); + break; + case PX_ALIGN_MIDBOTTOM: + PX_FontModuleDrawText(psurface,pLabel->fontModule,x+w/2,y+h,PX_ALIGN_MIDBOTTOM,pLabel->Text,pLabel->TextColor); + break; + case PX_ALIGN_RIGHTTOP: + PX_FontModuleDrawText(psurface,pLabel->fontModule,x+w,y,PX_ALIGN_RIGHTTOP,pLabel->Text,pLabel->TextColor); + break; + case PX_ALIGN_RIGHTMID: + PX_FontModuleDrawText(psurface,pLabel->fontModule,x+w,y+h/2,PX_ALIGN_RIGHTMID,pLabel->Text,pLabel->TextColor); + break; + case PX_ALIGN_RIGHTBOTTOM: + PX_FontModuleDrawText(psurface,pLabel->fontModule,x+w,y+h,PX_ALIGN_RIGHTBOTTOM,pLabel->Text,pLabel->TextColor); + break; + } + PX_SurfaceSetLimitInfo(psurface,limitInfo); +} + +px_void PX_Object_LabelFree( PX_Object *pLabel ) +{ + PX_Object_Label *Label=PX_Object_GetLabel(pLabel); + if (pLabel!=PX_NULL) + { + MP_Free(pLabel->mp,Label->Text); + } +} + +PX_Object* PX_Object_LabelCreate(px_memorypool *mp,PX_Object *Parent,px_int x,px_int y,px_int Width,px_int Height,const px_char *Text,PX_FontModule *fm,px_color Color ) +{ + px_int TextLen; + PX_Object *pObject; + PX_Object_Label *pLable=(PX_Object_Label *)MP_Malloc(mp,sizeof(PX_Object_Label)); + if (pLable==PX_NULL) + { + return PX_NULL; + } + pObject=PX_ObjectCreate(mp,Parent,(px_float)x,(px_float)y,0,(px_float)Width,(px_float)Height,0); + + if (pObject==PX_NULL) + { + return PX_NULL; + } + + if (!pObject) + { + MP_Free(mp,pLable); + return PX_NULL; + } + pObject->pObject=pLable; + pObject->Type=PX_OBJECT_TYPE_LABEL; + pObject->ReceiveEvents=PX_FALSE; + pObject->Func_ObjectFree=PX_Object_LabelFree; + pObject->Func_ObjectRender=PX_Object_LabelRender; + + TextLen=PX_strlen(Text); + + pLable->Text=(px_char *)MP_Malloc(mp,TextLen+1); + if (pLable->Text==PX_NULL) + { + MP_Free(pObject->mp,pObject); + MP_Free(pObject->mp,pLable); + return PX_NULL; + } + + PX_strcpy(pLable->Text,Text,TextLen+1); + + pLable->TextColor=Color; + pLable->BackgroundColor=PX_COLOR(0,0,0,0); + pLable->Align=PX_ALIGN_LEFTMID; + pLable->bBorder=PX_FALSE; + pLable->borderColor=PX_COLOR(255,0,0,0); + pLable->fontModule=fm; + pLable->style=PX_OBJECT_LABEL_STYLE_RECT; + return pObject; +} + + +PX_Object_Label * PX_Object_GetLabel( PX_Object *Object ) +{ + if(Object->Type==PX_OBJECT_TYPE_LABEL) + return (PX_Object_Label *)Object->pObject; + else + return PX_NULL; +} + +px_char * PX_Object_LabelGetText( PX_Object *Label ) +{ + PX_Object_Label *pLabel=PX_Object_GetLabel(Label); + if (pLabel!=PX_NULL) + { + return pLabel->Text; + } + return PX_NULL; +} +px_void PX_Object_LabelSetText( PX_Object *pObject,const px_char *Text ) +{ + PX_Object_Label *pLabel; + px_int TextLen; + if (pObject==PX_NULL||Text==PX_NULL) + { + return; + } + if (pObject->Type!=PX_OBJECT_TYPE_LABEL) + { + PX_ASSERT(); + return; + } + + TextLen=PX_strlen(Text); + pLabel=(PX_Object_Label *)pObject->pObject; + if(TextLen>PX_strlen(pLabel->Text)) + { + MP_Free(pObject->mp,pLabel->Text); + pLabel->Text=(px_char *)MP_Malloc(pObject->mp,TextLen+1); + if (!pLabel->Text) + { + PX_ERROR("Text create out of memories"); + } + PX_strcpy(pLabel->Text,Text,TextLen+1); + } + else + { + PX_strcpy(pLabel->Text,Text,TextLen+1); + } +} + + +px_void PX_Object_LabelSetTextColor(PX_Object *pObject,px_color Color) +{ + PX_Object_Label * pLabel=PX_Object_GetLabel(pObject); + if (pLabel) + { + pLabel->TextColor=Color; + } +} + + +px_void PX_Object_LabelSetBackgroundColor( PX_Object *pObject,px_color Color ) +{ + PX_Object_Label * pLabel=PX_Object_GetLabel(pObject); + if (pLabel) + { + pLabel->BackgroundColor=Color; + } +} +px_void PX_Object_LabelSetAlign( PX_Object *pObject,PX_ALIGN Align ) +{ + PX_Object_Label * pLabel=PX_Object_GetLabel(pObject); + if (pLabel) + { + + pLabel->Align=Align; + } +} + + + +px_void PX_Object_LabelSetBorder(PX_Object *pObject,px_bool b) +{ + PX_Object_Label * pLabel=PX_Object_GetLabel(pObject); + if (pLabel) + { + pLabel->bBorder=b; + } +} + +px_void PX_Object_LabelSetBorderColor(PX_Object *pObject,px_color color) +{ + PX_Object_Label * pLabel=PX_Object_GetLabel(pObject); + if (pLabel) + { + pLabel->borderColor=color; + } +} + +px_void PX_Object_LabelSetStyle(PX_Object *pObject,PX_OBJECT_LABEL_STYLE style) +{ + PX_Object_Label * pLabel=PX_Object_GetLabel(pObject); + if (pLabel) + { + pLabel->style=style; + } +} + +px_int PX_Object_LabelGetTextRenderWidth(PX_Object* pObject) +{ + PX_Object_Label* pLabel = PX_Object_GetLabel(pObject); + if (pLabel) + { + px_int w, h; + PX_FontModuleTextGetRenderWidthHeight(pLabel->fontModule, pLabel->Text, &w, &h); + return w; + } + return 0; +} diff --git a/lib/PainterEngine/kernel/PX_Object_Label.h b/lib/PainterEngine/kernel/PX_Object_Label.h new file mode 100644 index 0000000000000000000000000000000000000000..5994b6b02a98f6643bc76417aedb4b93b22a2a05 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_Label.h @@ -0,0 +1,37 @@ +#ifndef PX_OBJECT_LABEL_H +#define PX_OBJECT_LABEL_H +#include "PX_Object.h" + +typedef enum +{ + PX_OBJECT_LABEL_STYLE_RECT, + PX_OBJECT_LABEL_STYLE_ROUNDRECT, +}PX_OBJECT_LABEL_STYLE; + +typedef struct +{ + PX_ALIGN Align; + px_color borderColor; + px_color TextColor; + px_color BackgroundColor; + px_bool bBorder; + PX_OBJECT_LABEL_STYLE style; + PX_FontModule *fontModule; + px_char *Text; +}PX_Object_Label; + +PX_Object * PX_Object_LabelCreate(px_memorypool *mp,PX_Object *Parent,px_int x,px_int y,px_int Width,px_int Height,const px_char *Text,PX_FontModule *fm,px_color Color); +PX_Object_Label * PX_Object_GetLabel(PX_Object *Object); +px_char * PX_Object_LabelGetText(PX_Object *Label); +px_void PX_Object_LabelSetText(PX_Object *pLabel,const px_char *Text); +px_void PX_Object_LabelSetTextColor(PX_Object *pLabel,px_color Color); +px_void PX_Object_LabelSetBackgroundColor(PX_Object *pLabel,px_color Color); +px_void PX_Object_LabelSetAlign(PX_Object *pLabel,PX_ALIGN Align); +px_void PX_Object_LabelSetBorder(PX_Object *pLabel,px_bool b); +px_void PX_Object_LabelSetBorderColor(PX_Object *pLabel,px_color color); +px_void PX_Object_LabelSetStyle(PX_Object *pLabel,PX_OBJECT_LABEL_STYLE style); +px_int PX_Object_LabelGetTextRenderWidth(PX_Object* pLabel); + + +#endif + diff --git a/lib/PainterEngine/kernel/PX_Object_List.c b/lib/PainterEngine/kernel/PX_Object_List.c new file mode 100644 index 0000000000000000000000000000000000000000..388679b41dfa6f39bf4872d7cc7695148a7990ba --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_List.c @@ -0,0 +1,557 @@ +#include "PX_Object_List.h" +PX_Object_List * PX_Object_GetList( PX_Object *Object ) +{ + if(Object->Type==PX_OBJECT_TYPE_LIST) + return (PX_Object_List *)Object->pObject; + else + return PX_NULL; +} + +PX_Object_ListItem * PX_Object_GetListItem( PX_Object *Object ) +{ + if(Object->Type==PX_OBJECT_TYPE_LISTITEM) + return (PX_Object_ListItem *)Object->pObject; + else + return PX_NULL; +} + +px_void PX_Object_ListOnCursorMove(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + + PX_Object_List *pList= PX_Object_GetList(pObject); + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + pList->currentCursorIndex=-1; + if (!PX_ObjectIsCursorInRegion(pObject,e)) + { + return; + } + + if (pList->pData.size*pList->ItemHeight>pObject->Height) + { + if (PX_Object_Event_GetCursorX(e)>objx+objWidth-32) + { + return; + } + } + + + pList->currentCursorIndex=(px_int)(PX_Object_Event_GetCursorY(e)+pList->offsety-objy)/pList->ItemHeight; + if(pList->currentCursorIndex<0||pList->currentCursorIndex>=pList->pData.size) + { + pList->currentCursorIndex=-1; + } + +} + +px_void PX_Object_ListOnCursorDown(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + PX_Object_List *pList= PX_Object_GetList(pObject); + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + px_int currentSelectedIndex; + PX_Object_Event ne; + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + if (!PX_ObjectIsCursorInRegion(pObject,e)) + { + return; + } + if (pList->pData.size*pList->ItemHeight>pObject->Height) + { + if (PX_Object_Event_GetCursorX(e)>objx+objWidth-32) + { + return; + } + } + + currentSelectedIndex=(px_int)(PX_Object_Event_GetCursorY(e)+pList->offsety-objy)/pList->ItemHeight; + if (pList->currentSelectedIndex!=currentSelectedIndex) + { + PX_memset(&ne,0,sizeof(ne)); + pList->currentSelectedIndex=currentSelectedIndex; + if(pList->currentSelectedIndex<0||pList->currentSelectedIndex>=pList->pData.size) + { + pList->currentSelectedIndex=-1; + } + ne.Event=PX_OBJECT_EVENT_VALUECHANGED; + PX_Object_Event_SetIndex(&ne,pList->currentSelectedIndex); + PX_ObjectExecuteEvent(pObject,ne); + } + else + { + if (pList->doubleCursorCancel&&pList->currentSelectedIndex!=-1) + { + PX_memset(&e,0,sizeof(ne)); + pList->currentSelectedIndex=-1; + ne.Event=PX_OBJECT_EVENT_VALUECHANGED; + PX_Object_Event_SetIndex(&ne,pList->currentSelectedIndex); + PX_ObjectExecuteEvent(pObject,ne); + } + } +} + +px_void PX_Object_ListOnCursorRDown(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + PX_Object_List *pList= PX_Object_GetList(pObject); + if (!PX_ObjectIsCursorInRegion(pObject,e)) + { + return; + } + + if (pList->currentSelectedIndex!=-1) + { + pList->currentSelectedIndex=-1; + e.Event=PX_OBJECT_EVENT_VALUECHANGED; + PX_Object_Event_SetIndex(&e,pList->currentSelectedIndex); + PX_ObjectExecuteEvent(pObject,e); + } + +} + +px_void PX_Object_ListOnWheel(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + PX_Object_List *pList= PX_Object_GetList(pObject); + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + if (!PX_ObjectIsCursorInRegion(pObject,e)) + { + return; + } + pList->offsety-=(px_int)PX_Object_Event_GetCursorZ(e)/5; + + + if (pList->offsety>(pList->ItemHeight)*pList->pData.size-objHeight) + { + pList->offsety=(pList->ItemHeight)*pList->pData.size-(px_int)objHeight; + } + + if (pList->offsety<0) + { + pList->offsety=0; + } + + PX_Object_SliderBarSetValue(pList->SliderBar,pList->offsety); +} + +px_void PX_Object_ListMoveToTop(PX_Object *pObject) +{ + PX_Object_List *pList= PX_Object_GetList(pObject); + pList->offsety=0; + PX_Object_SliderBarSetValue(pList->SliderBar,0); +} + +px_void PX_Object_ListRender(px_surface *psurface, PX_Object *pObject,px_uint elapsed) +{ + PX_Object *pItemObject; + px_int offsetX=0,drawXCenter=0; + px_int i; + px_int iy; + PX_Object_List *pList= PX_Object_GetList(pObject); + PX_Object_ListItem *pItem; + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + if (pList->Items.size!=(px_int)(objHeight/(pList->ItemHeight) + 2)) + { + PX_Object_ListItem Item; + for (i=0;iItems.size;i++) + { + PX_Object* pItemObject = *PX_VECTORAT(PX_Object*, &pList->Items, i); + PX_ObjectDelete(pItemObject); + } + + + PX_VectorClear(&pList->Items); + + for (i = 0; i < (px_int)(objHeight / pList->ItemHeight + 2); i++) + { + Item.pList = pObject; + Item.pdata = PX_NULL; + pItemObject = PX_ObjectCreateEx(pList->mp, PX_NULL, 0, 0, 0, (px_float)pObject->Width, (px_float)pList->ItemHeight, 0, PX_OBJECT_TYPE_LISTITEM, PX_NULL, PX_NULL, PX_NULL, &Item, sizeof(PX_Object_ListItem)); + if (!pList->CreateFunctions(pList->mp, pItemObject, pList->userptr)) return; + if (!PX_VectorPushback(&pList->Items, &pItemObject))return; + } + } + + + if (pList->ItemHeight*pList->pData.size>objHeight) + { + PX_Object_SliderBar *pSliderBar=PX_Object_GetSliderBar(pList->SliderBar); + pList->SliderBar->Visible=PX_TRUE; + pList->SliderBar->y=0; + pList->SliderBar->x=objx+objWidth-32; + pList->SliderBar->Height = objHeight; + pSliderBar->SliderButtonLength=(px_int)(pList->SliderBar->Height*objHeight/(pList->ItemHeight*pList->pData.size)); + if(pSliderBar->SliderButtonLength<32) pSliderBar->SliderButtonLength=32; + pSliderBar->Max=(pList->ItemHeight)*pList->pData.size-(px_int)objHeight; + PX_Object_SliderBarSetBackgroundColor(pList->SliderBar,pList->BackgroundColor); + PX_Object_SliderBarSetColor(pList->SliderBar,pList->BorderColor); + } + else + { + pList->SliderBar->Visible=PX_FALSE; + } + + + if (pList->offsety<0) + { + iy=-pList->offsety; + } + else + { + iy=-(pList->offsety%pList->ItemHeight); + } + + for (i=0;iItems.size;i++) + { + + pItemObject=*PX_VECTORAT(PX_Object *,&pList->Items,i); + pItemObject->x=0; + pItemObject->y=(px_float)iy; + pItemObject->Width = pObject->Width; + pItem=PX_Object_GetListItem(pItemObject); + if (pList->offsety<0) + { + if(ipData.size) + { + pItem->pdata=*PX_VECTORAT(px_void *,&pList->pData,i); + PX_ObjectUpdate(pItemObject,elapsed); + } + else + { + pItem->pdata=PX_NULL; + } + } + else + { + if(i+pList->offsety/pList->ItemHeightpData.size) + { + pItem->pdata=*PX_VECTORAT(px_void *,&pList->pData,i+pList->offsety/pList->ItemHeight); + PX_ObjectUpdate(pItemObject,elapsed); + } + else + { + pItem->pdata=PX_NULL; + } + } + iy+=(px_int)pItemObject->Height; + } + + if ((px_int)pList->renderSurface.width!=(px_int)pObject->Width|| (px_int)pList->renderSurface.height != (px_int)pObject->Height) + { + PX_SurfaceFree(&pList->renderSurface); + if (!PX_SurfaceCreate(pList->mp, (px_int)pObject->Width, (px_int)pObject->Height, &pList->renderSurface)) + { + PX_ASSERT(); + return; + } + } + + PX_SurfaceClear(&pList->renderSurface,0,0,pList->renderSurface.width-1,pList->renderSurface.height-1,pList->BackgroundColor); + for (i=0;iItems.size;i++) + { + px_int index=i+pList->offsety/pList->ItemHeight; + pItemObject=*PX_VECTORAT(PX_Object *,&pList->Items,i); + pItem=PX_Object_GetListItem(pItemObject); + if (pItemObject->y+pItemObject->Height>0&&pItemObject->yHeight&&pItem->pdata) + { + + if (pList->showCursor) + { + if (index==pList->currentCursorIndex&&index!=pList->currentSelectedIndex) + { + PX_GeoDrawRect(&pList->renderSurface,(px_int)pItemObject->x,(px_int)pItemObject->y,(px_int)(pItemObject->x+pItemObject->Width-1),(px_int)(pItemObject->y+pItemObject->Height-1),pList->CursorColor); + } + } + if (index==pList->currentSelectedIndex) + { + PX_GeoDrawRect(&pList->renderSurface,(px_int)pItemObject->x,(px_int)pItemObject->y,(px_int)(pItemObject->x+pItemObject->Width-1),(px_int)(pItemObject->y+pItemObject->Height-1),pList->SelectCursor); + } + PX_ObjectRender(&pList->renderSurface,pItemObject,elapsed); + } + } + PX_GeoDrawBorder(&pList->renderSurface,0,0,pList->renderSurface.width-1,pList->renderSurface.height-1,1,pList->BorderColor); + PX_SurfaceCover(psurface,&pList->renderSurface,(px_int)objx,(px_int)objy,PX_ALIGN_LEFTTOP); + +} + +px_void PX_Object_ListClear(PX_Object *pListObj) +{ + PX_Object_List *pList=PX_Object_GetList(pListObj); + if(pList) + PX_VectorClear(&pList->pData); +} + +px_void PX_Object_ListSetCurrentSelectIndex(PX_Object *pObject,px_int index) +{ + PX_Object_List *pList=PX_Object_GetList(pObject); + if(pList) + { + if (index>=0&&indexItems.size) + { + pList->currentSelectedIndex=index; + } + else + { + pList->currentSelectedIndex=-1; + } + } +} + +px_int PX_Object_ListGetCurrentSelectIndex(PX_Object *pObject) +{ + PX_Object_List *pList=PX_Object_GetList(pObject); + if(pList) + { + return pList->currentSelectedIndex; + } + return -1; +} + +px_int PX_Object_ListAdd(PX_Object *pListObj,px_void *ptr) +{ + PX_Object_List *pList=PX_Object_GetList(pListObj); + if(pList) + { + if(PX_VectorPushback(&pList->pData,&ptr)) + return pList->pData.size-1; + } + return -1; +} + +px_void PX_Object_ListFree(PX_Object *pListObj) +{ + PX_Object_List *pList=PX_Object_GetList(pListObj); + if (!pList) + { + PX_ASSERT(); + return; + } + PX_Object_ListClear(pListObj); + PX_SurfaceFree(&pList->renderSurface); + PX_VectorFree(&pList->Items); +} + +px_void PX_Object_ListOnSliderValueChanged(PX_Object *Object,PX_Object_Event e,px_void *ptr) +{ + px_int value=PX_Object_SliderBarGetValue(Object); + PX_Object_List *pList=PX_Object_GetList((PX_Object *)ptr); + pList->offsety=value; +} + +px_void PX_Object_ListOnEvent(PX_Object *Object,PX_Object_Event e,px_void *ptr) +{ + px_int i; + PX_Object_List *pList=PX_Object_GetList(Object); + + switch (e.Event) + { + case PX_OBJECT_EVENT_CURSORWHEEL: + if (!PX_ObjectIsPointInRegion(Object,PX_Object_Event_GetCursorX(e),PX_Object_Event_GetCursorY(e))) + { + return; + } + case PX_OBJECT_EVENT_CURSORDRAG: + case PX_OBJECT_EVENT_CURSORRDOWN: + case PX_OBJECT_EVENT_CURSORDOWN: + case PX_OBJECT_EVENT_CURSORUP: + case PX_OBJECT_EVENT_CURSORRUP: + case PX_OBJECT_EVENT_CURSORMOVE: + if (!PX_ObjectIsPointInRegion(Object,PX_Object_Event_GetCursorX(e),PX_Object_Event_GetCursorY(e))) + { + return; + } + PX_Object_Event_SetCursorX(&e,PX_Object_Event_GetCursorX(e)-Object->x); + PX_Object_Event_SetCursorY(&e,PX_Object_Event_GetCursorY(e)-Object->y); + break; + } + + for (i=0;iItems.size;i++) + { + PX_Object *pItem=*PX_VECTORAT(PX_Object *,&pList->Items,i); + PX_ObjectPostEvent(pItem,e); + } +} + +PX_Object * PX_Object_ListCreate(px_memorypool *mp, PX_Object *Parent,px_int x,px_int y,px_int Width,px_int Height,px_int ItemHeight,PX_Object_ListItemOnCreate _CreateFunc,px_void *userptr) +{ + PX_Object_List List,*pList; + + PX_Object *pListObject; + PX_memset(&List,0,sizeof(List)); + List.mp=mp; + List.ItemWidth=Width-32; + List.ItemHeight=ItemHeight; + List.CreateFunctions=_CreateFunc; + + List.BorderColor=PX_OBJECT_UI_DEFAULT_BORDERCOLOR; + List.BackgroundColor=PX_OBJECT_UI_DEFAULT_BACKGROUNDCOLOR; + List.CursorColor=PX_OBJECT_UI_DEFAULT_CURSORCOLOR; + List.SelectCursor=PX_OBJECT_UI_DEFAULT_PUSHCOLOR; + + List.offsetx=0; + List.currentSelectedIndex=-1; + List.currentCursorIndex=-1; + List.offsety=0; + List.showCursor=PX_TRUE; + List.userptr = userptr; + + PX_VectorInitialize(mp,&List.Items,sizeof(PX_Object *),64); + PX_VectorInitialize(mp,&List.pData,sizeof(px_void *),32); + if(!PX_SurfaceCreate(mp,Width,Height,&List.renderSurface)) return PX_NULL; + if(!(pListObject=PX_ObjectCreateEx(mp,Parent,(px_float)x,(px_float)y,0,(px_float)Width,(px_float)Height,0,PX_OBJECT_TYPE_LIST,PX_NULL,PX_Object_ListRender,PX_Object_ListFree,&List,sizeof(PX_Object_List)))) return PX_NULL; + + pList=PX_Object_GetList(pListObject); + pList->SliderBar=PX_Object_SliderBarCreate(mp,pListObject,(px_int)pListObject->Width-32,0,32,(px_int)pListObject->Height,PX_OBJECT_SLIDERBAR_TYPE_VERTICAL,PX_OBJECT_SLIDERBAR_STYLE_BOX); + + PX_ObjectRegisterEvent(pListObject,PX_OBJECT_EVENT_CURSORWHEEL,PX_Object_ListOnWheel,pListObject); + PX_ObjectRegisterEvent(pListObject,PX_OBJECT_EVENT_CURSORDOWN,PX_Object_ListOnCursorDown,pListObject); + PX_ObjectRegisterEvent(pListObject,PX_OBJECT_EVENT_CURSORRDOWN,PX_Object_ListOnCursorRDown,pListObject); + PX_ObjectRegisterEvent(pListObject,PX_OBJECT_EVENT_CURSORMOVE,PX_Object_ListOnCursorMove,pListObject); + PX_ObjectRegisterEvent(pList->SliderBar,PX_OBJECT_EVENT_VALUECHANGED,PX_Object_ListOnSliderValueChanged,pListObject); + PX_ObjectRegisterEvent(pListObject,PX_OBJECT_EVENT_ANY,PX_Object_ListOnEvent,pListObject); + return pListObject; +} + +static px_void PX_Object_ListContentItemOnRender(px_surface* psurface, PX_Object* pObject, px_dword elapsed) +{ + PX_Object_ListItem* pListItem; + px_float objx, objy, objWidth, objHeight; + px_float inheritX, inheritY; + pListItem = PX_Object_GetListItem(pObject); + + PX_ObjectGetInheritXY(pObject, &inheritX, &inheritY); + objx = (pObject->x + inheritX); + objy = (pObject->y + inheritY); + objWidth = pObject->Width; + objHeight = pObject->Height; + + PX_FontModuleDrawText(psurface, PX_Object_GetList(pListItem->pList)->fm, (px_int)objx + 3, (px_int)(objy + objHeight / 2), PX_ALIGN_LEFTMID, (const px_char*)pListItem->pdata, PX_OBJECT_UI_DEFAULT_FONTCOLOR); + +} + +px_bool PX_Designer_ListContentItemOnCreate(px_memorypool* mp, PX_Object* ItemObject, px_void* userptr) +{ + ItemObject->Func_ObjectRender = PX_Object_ListContentItemOnRender; + return PX_TRUE; +} + + +PX_Object* PX_Object_ListContentCreate(px_memorypool* mp, PX_Object* Parent, px_int x, px_int y, px_int Width, px_int Height, PX_FontModule* fm) +{ + PX_Object* pObject; + if (fm) + { + pObject=PX_Object_ListCreate(mp, Parent, x, y, Width, Height, fm->max_Height + 6, PX_Designer_ListContentItemOnCreate, PX_NULL); + if (pObject) + { + PX_Object_List* pList = PX_ObjectGetDesc(PX_Object_List,pObject); + pList->fm = fm; + } + } + else + { + pObject = PX_Object_ListCreate(mp, Parent, x, y, Width, Height, __PX_FONT_HEIGHT+6, PX_Designer_ListContentItemOnCreate,PX_NULL); + } + return pObject; + +} + +px_bool PX_Object_ListItemIsOnDisplayPresent(PX_Object* pObject, px_int index) +{ + if (pObject->Type==PX_OBJECT_TYPE_LIST) + { + PX_Object_List* pList = PX_ObjectGetDesc(PX_Object_List, pObject); + PX_Object* pItemObject = *PX_VECTORAT(PX_Object*, &pList->Items, index); + PX_Object_ListItem* pItem = PX_Object_GetListItem(pItemObject); + if (pItemObject->y + pItemObject->Height > 0 && pItemObject->y < pObject->Height && pItem->pdata) + { + return PX_TRUE; + } + } + PX_ASSERT(); + return PX_FALSE; +} + +px_void PX_Object_ListSetBackgroundColor(PX_Object *pListObject,px_color color) +{ + PX_Object_List *pList=PX_Object_GetList(pListObject); + if (pList) + { + pList->BackgroundColor=color; + } +} + +px_void PX_Object_ListSetBorderColor(PX_Object *pListObject,px_color color) +{ + PX_Object_List *pList=PX_Object_GetList(pListObject); + if (pList) + { + pList->BorderColor=color; + } +} + +px_void PX_Object_ListSetDoubleClickCancel(PX_Object *pListObject,px_bool b) +{ + PX_Object_List *pList=PX_Object_GetList(pListObject); + if (pList) + { + pList->doubleCursorCancel=b; + } +} + +px_void * PX_Object_ListGetItemData(PX_Object *pListObject,px_int index) +{ + PX_Object_List *pList=PX_Object_GetList(pListObject); + if (index>=0&&indexpData.size) + { + return *PX_VECTORAT(px_void *,&pList->pData,index); + } + return PX_NULL; +} + +px_void* PX_Object_ListItemGetData(PX_Object* pItemObject) +{ + PX_Object_ListItem* pItem=(PX_Object_ListItem *)pItemObject->pObject; + return pItem->pdata; +} + +px_void PX_Object_ListRemoveItem(PX_Object *pListObject,px_int index) +{ + PX_Object_List *pList=PX_Object_GetList(pListObject); + if (index>=0&&indexpData.size) + { + PX_VectorErase(&pList->pData,index); + } + return ; +} + diff --git a/lib/PainterEngine/kernel/PX_Object_List.h b/lib/PainterEngine/kernel/PX_Object_List.h new file mode 100644 index 0000000000000000000000000000000000000000..9b956a757a7eb25eb02d78817ae79a8f8ffa9a04 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_List.h @@ -0,0 +1,57 @@ +#ifndef PX_OBJECT_LIST_H +#define PX_OBJECT_LIST_H +#include "PX_Object.h" + + +typedef px_bool (*PX_Object_ListItemOnCreate)(px_memorypool *mp,PX_Object *ItemObject,px_void *userptr); + + +typedef struct +{ + PX_Object* pList; + px_void *pdata; +}PX_Object_ListItem; + +typedef struct +{ + px_memorypool *mp; + px_int ItemWidth; + px_int ItemHeight; + px_int offsetx; + px_int offsety; + px_int currentSelectedIndex,currentCursorIndex; + px_color BorderColor; + px_color BackgroundColor; + px_color CursorColor; + px_color SelectCursor; + px_surface renderSurface; + px_bool showCursor; + px_bool doubleCursorCancel; + px_vector Items; + px_vector pData; + PX_Object *SliderBar; + PX_FontModule* fm; + px_void* userptr; + PX_Object_ListItemOnCreate CreateFunctions; +}PX_Object_List; + +PX_Object_List * PX_Object_GetList( PX_Object *Object ); +PX_Object_ListItem * PX_Object_GetListItem( PX_Object *Object ); +PX_Object * PX_Object_ListCreate(px_memorypool *mp, PX_Object *Parent,px_int x,px_int y,px_int Width,px_int Height,px_int ItemHeight,PX_Object_ListItemOnCreate _CreateFunc,px_void *userptr); +PX_Object* PX_Object_ListContentCreate(px_memorypool* mp, PX_Object* Parent, px_int x, px_int y, px_int Width, px_int Height, PX_FontModule* fm); +px_bool PX_Object_ListItemIsOnDisplayPresent(PX_Object* pObject,px_int index); +px_void PX_Object_ListMoveToTop(PX_Object *pObject); +px_void PX_Object_ListClear(PX_Object *pListObj); +px_void PX_Object_ListSetCurrentSelectIndex(PX_Object *pObject,px_int index); +px_int PX_Object_ListGetCurrentSelectIndex(PX_Object *pObject); +px_int PX_Object_ListAdd(PX_Object *pListObj,px_void *ptr); +px_void *PX_Object_ListGetItemData(PX_Object *pListObject,px_int index); +px_void* PX_Object_ListItemGetData(PX_Object* pItemObject); +px_void PX_Object_ListRemoveItem(PX_Object *pListObject,px_int index); +px_void PX_Object_ListSetBackgroundColor(PX_Object *pListObject,px_color color); +px_void PX_Object_ListSetBorderColor(PX_Object *pListObject,px_color color); +px_void PX_Object_ListSetDoubleClickCancel(PX_Object *pListObject,px_bool b); + + +#endif + diff --git a/lib/PainterEngine/kernel/PX_Object_MemoryView.c b/lib/PainterEngine/kernel/PX_Object_MemoryView.c new file mode 100644 index 0000000000000000000000000000000000000000..2fc0f4f418daf7356f665868dd46e7dc94b4103b --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_MemoryView.c @@ -0,0 +1,410 @@ +#include "PX_Object_MemoryView.h" + +////////////////////////////////////////////////////////////////////////// +// 0x00000000 00 a -- +// 16+64 16 16+8+8+16 + +static px_int PX_Object_MemoryViewGetCursorMapIndex(PX_Object *pObject,px_float cx,px_float cy) +{ + PX_Object_MemoryView *pdesc; + px_int x,y,w,h; + px_float inheritX,inheritY; + px_int row,column; + px_int columnoffset; + px_int rel_address_offset; + px_int xIndex,yIndex,Index; + pdesc=PX_ObjectGetDesc(PX_Object_MemoryView,pObject); + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + x=(px_int)(pObject->x+inheritX); + y=(px_int)(pObject->y+inheritY); + w=(px_int)pObject->Width; + h=(px_int)pObject->Height; + + row=(w-(16+64+16+8+16))/32; + column=h/(15+3); + + cx-=x; + cy-=y; + + columnoffset=PX_Object_SliderBarGetValue(pdesc->scrollbar); + rel_address_offset=row*columnoffset; + + if (cx<96+row*24) + { + xIndex=(px_int)((cx-96)/8-(cx-96)/24); + if(xIndex<0)xIndex=0; + } + else if(cx=row*2) xIndex=row*2-2; + } + else + { + return -1; + } + + yIndex=(px_int)(cy/18); + + Index=yIndex*row*2+rel_address_offset*2+xIndex; + if (Index<0) + { + Index=0; + } + + if (Index>=pdesc->size*2) + { + Index=pdesc->size*2-1; + } + return Index; +} + + +px_void PX_Object_MemoryViewRender(px_surface *prendersurface,PX_Object *pObject,px_dword elapsed) +{ + px_int row,column,i,j; + px_int rel_address_offset; + px_int mst,med; + PX_Object_MemoryView *pdesc; + px_int x,y,w,h; + px_float inheritX,inheritY; + px_int columnoffset; + px_int drawx,drawy; + + pdesc=PX_ObjectGetDesc(PX_Object_MemoryView,pObject); + pdesc->cursor_elapsed+=elapsed; + columnoffset=PX_Object_SliderBarGetValue(pdesc->scrollbar); + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + x=(px_int)(pObject->x+inheritX); + y=(px_int)(pObject->y+inheritY); + w=(px_int)pObject->Width; + h=(px_int)pObject->Height; + + + pdesc->scrollbar->x=x+w-16.f; + pdesc->scrollbar->y=(px_float)y; + pdesc->scrollbar->Width=16.f; + pdesc->scrollbar->Height=(px_float)h; + + row=(w-(16+64+16+8+16))/32; + + if (row<1) + { + return; + } + + column=h/(15+3); + if (column<1) + { + return; + } + + mst=pdesc->mark_start_cursor; + med=pdesc->mark_end_cursor; + if (mst>med) + { + mst^=med; + med=mst^med; + mst^=med; + } + + + + + + ////////////////////////////////////////////////////////////////////////// + //render background + PX_GeoDrawRect(prendersurface,x,y,x+w,y+h,pdesc->backgroundcolor); + + ///////////////////////////////////////////////////////////////////////// + //render border + PX_GeoDrawBorder(prendersurface, x, y, x + w, y + h, 1,pdesc->bordercolor); + + rel_address_offset=row*columnoffset; + + drawy=y; + for (j=0;j=pdesc->size) + { + break; + } + addr=rel_address_offset+pdesc->address_offset; + + + drawx=0; + //0x + PX_FontDrawChar(prendersurface,drawx,drawy,'0',pdesc->fontcolor); + drawx+=8; + + PX_FontDrawChar(prendersurface,drawx,drawy,'x',pdesc->fontcolor); + drawx+=8; + + + PX_BufferToHexString((px_byte *)&addr,4,addrhex); + PX_FontDrawText(prendersurface,drawx,drawy,PX_ALIGN_LEFTTOP,addrhex,pdesc->fontcolor); + drawx+=8*8; + + drawx+=16; + + for (i=0;i=pdesc->size) + { + break; + } + b=((px_byte *)pdesc->pdata)[rel_address_offset]; + PX_BufferToHexString(&b,1,hex); + PX_strupr(hex); + + if (rel_address_offset*2>=mst&&rel_address_offset*2<=med) + { + PX_GeoDrawRect(prendersurface,drawx,drawy,drawx+7,drawy+15,pdesc->selectcolor); + } + + if ((rel_address_offset*2>=mst&&rel_address_offset*2<=med)||(rel_address_offset*2+1>=mst&&rel_address_offset*2+1<=med)) + { + PX_GeoDrawRect(prendersurface,96+row*24+8*i,drawy,96+row*24+8*i+7,drawy+15,pdesc->selectcolor); + } + + if (rel_address_offset*2==pdesc->cursor) + { + if ((pdesc->cursor_elapsed/200)&1) + { + PX_GeoDrawRect(prendersurface,drawx,drawy,drawx+7,drawy+15,pdesc->cursorcolor); + } + } + if (rel_address_offset*2==pdesc->cursor||rel_address_offset*2+1==pdesc->cursor) + { + PX_GeoDrawRect(prendersurface,96+row*24+8*i,drawy,96+row*24+8*i+7,drawy+15,pdesc->selectcolor); + } + + + PX_FontDrawChar(prendersurface,drawx,drawy,hex[0],pdesc->fontcolor); + if (b>=32&&b<=126) + { + PX_FontDrawChar(prendersurface,96+row*24+8*i,drawy,b,pdesc->fontcolor); + } + + drawx+=8; + if (rel_address_offset*2+1>=mst&&rel_address_offset*2+1<=med) + { + PX_GeoDrawRect(prendersurface,drawx,drawy,drawx+7,drawy+15,pdesc->selectcolor); + } + + if (rel_address_offset*2+1==pdesc->cursor) + { + if ((pdesc->cursor_elapsed/200)&1) + { + PX_GeoDrawRect(prendersurface,drawx,drawy,drawx+7,drawy+15,pdesc->cursorcolor); + } + } + PX_FontDrawChar(prendersurface,drawx,drawy,hex[1],pdesc->fontcolor); + drawx+=16; + rel_address_offset++; + } + + drawy+=16; + + } + + +} + +px_void PX_Object_MemoryViewOnCursorClick(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + px_float x,y; + PX_Object_MemoryView *pdesc; + + if (!PX_ObjectIsCursorInRegion(pObject,e)) + { + return; + } + + pdesc=PX_ObjectGetDesc(PX_Object_MemoryView,pObject); + + pdesc->mark_end_cursor=-1; + pdesc->mark_start_cursor=-1; + x=PX_Object_Event_GetCursorX(e); + y=PX_Object_Event_GetCursorY(e); + + pdesc->cursor=PX_Object_MemoryViewGetCursorMapIndex(pObject,x,y); +} + +px_void PX_Object_MemoryViewOnCursorDrag(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + px_float x,y; + PX_Object_MemoryView *pdesc; + + if (!PX_ObjectIsCursorInRegion(pObject,e)) + { + return; + } + + pdesc=PX_ObjectGetDesc(PX_Object_MemoryView,pObject); + x=PX_Object_Event_GetCursorX(e); + y=PX_Object_Event_GetCursorY(e); + + pdesc->mark_end_cursor=PX_Object_MemoryViewGetCursorMapIndex(pObject,x,y); + +} + +px_void PX_Object_MemoryViewOnCursorDown(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + px_float x,y; + PX_Object_MemoryView *pdesc; + + if (!PX_ObjectIsCursorInRegion(pObject,e)) + { + return; + } + + pdesc=PX_ObjectGetDesc(PX_Object_MemoryView,pObject); + pdesc->mark_end_cursor=-1; + pdesc->mark_start_cursor=-1; + pdesc->cursor=-1; + x=PX_Object_Event_GetCursorX(e); + y=PX_Object_Event_GetCursorY(e); + + pdesc->mark_start_cursor=pdesc->mark_end_cursor=PX_Object_MemoryViewGetCursorMapIndex(pObject,x,y); +} + +px_void PX_Object_MemoryViewOnKeyDown(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + PX_Object_MemoryView *pdesc=PX_ObjectGetDesc(PX_Object_MemoryView,pObject); + PX_Object_Event ne; + px_char key=PX_Object_Event_GetKeyDown(e); + + if ((key>='A'&&key<='F')||(key>='a'&&key<='f')||(key>='0'&&key<='9')) + { + if (pdesc->cursor>=0&&pdesc->cursorsize*2) + { + px_int index=pdesc->cursor/2; + px_uchar value=0; + if ((key>='A'&&key<='F')) + { + value=key-'A'+10; + } + else if ((key>='a'&&key<='f')) + { + value=key-'a'+10; + } + else if ((key>='0'&&key<='9')) + { + value=key-'0'; + } + + if (pdesc->cursor&1) + { + ((px_byte *)pdesc->pdata)[index]&=0xf0; + ((px_byte *)pdesc->pdata)[index]|=(value); + } + else + { + ((px_byte *)pdesc->pdata)[index]&=0x0f; + ((px_byte *)pdesc->pdata)[index]|=(value<<4); + } + + + ne.Event=PX_OBJECT_EVENT_VALUECHANGED; + ne.Param_uint[0]=index; + ne.Param_uint[1]=((px_byte *)pdesc->pdata)[index]; + PX_ObjectExecuteEvent(pObject,ne); + + if (pdesc->cursorsize*2-1) + { + pdesc->cursor++; + } + } + } + +} + + +PX_Object * PX_Object_MemoryViewCreate(px_memorypool *mp,PX_Object *pParent,px_int x,px_int y,px_int Width,px_int Height) +{ + PX_Object_MemoryView desc,*pdesc; + PX_Object *pObject; + PX_memset(&desc,0,sizeof(desc)); + desc.backgroundcolor=PX_OBJECT_UI_DEFAULT_BACKGROUNDCOLOR; + desc.cursor=-1; + desc.mark_end_cursor=-1; + desc.mark_start_cursor=-1; + desc.cursorcolor=PX_COLOR(64,255,255,255); + desc.fontcolor=PX_OBJECT_UI_DEFAULT_FONTCOLOR; + desc.selectcolor=PX_COLOR(64,255,255,255); + desc.bordercolor = PX_OBJECT_UI_DEFAULT_BORDERCOLOR; + pObject=PX_ObjectCreateEx(mp,pParent,(px_float)x,(px_float)y,0,(px_float)Width,(px_float)Height,0,PX_OBJECT_TYPE_MEMORYVIEW,PX_NULL,PX_Object_MemoryViewRender,PX_NULL,&desc,sizeof(desc)); + pdesc=PX_ObjectGetDesc(PX_Object_MemoryView,pObject); + pdesc->scrollbar=PX_Object_SliderBarCreate(mp,pObject,0,0,10,10,PX_OBJECT_SLIDERBAR_TYPE_VERTICAL,PX_OBJECT_SLIDERBAR_STYLE_BOX); + pdesc->scrollbar->Visible=PX_FALSE; + + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORCLICK,PX_Object_MemoryViewOnCursorClick,PX_NULL); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORDOWN,PX_Object_MemoryViewOnCursorDown,PX_NULL); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORDRAG,PX_Object_MemoryViewOnCursorDrag,PX_NULL); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_KEYDOWN,PX_Object_MemoryViewOnKeyDown,PX_NULL); + return pObject; +} + +PX_Object_MemoryView * PX_Object_GetMemoryView(PX_Object *pObject) +{ + if (pObject->Type!=PX_OBJECT_TYPE_MEMORYVIEW) + { + PX_ASSERT(); + return PX_NULL; + } + return (PX_Object_MemoryView * )pObject->pObject; +} + +px_void PX_Object_MemoryViewSetFontColor(PX_Object *pObject,px_color Color) +{ + PX_Object_MemoryView *pdesc=PX_Object_GetMemoryView(pObject); + if(pdesc) + pdesc->fontcolor=Color; +} + +px_void PX_Object_MemoryViewSetBackgroundColor(PX_Object *pObject,px_color Color) +{ + PX_Object_MemoryView *pdesc=PX_Object_GetMemoryView(pObject); + if(pdesc) + pdesc->backgroundcolor=Color; +} + +px_void PX_Object_MemoryViewSetData(PX_Object *pObject,px_void *pdata,px_dword size) +{ + PX_Object_MemoryView *pdesc=PX_Object_GetMemoryView(pObject); + if(pdesc) + { + px_int row,column,cc; + pdesc->pdata=pdata; + pdesc->size=size; + pdesc->cursor=-1; + pdesc->mark_start_cursor=-1; + pdesc->mark_end_cursor=-1; + + ////////////////////////////////////////////////////////////////////////// + //scrollbar + row=(px_int)(pObject->Width-(16+64+16+8+16))/32; + column=(px_int)pObject->Height/(15+3); + cc=(pdesc->size+row/2)/row; + if (cc>column) + { + PX_Object_SliderBarSetRange(pdesc->scrollbar,0,cc-column); + PX_Object_SliderBarSetValue(pdesc->scrollbar,0); + pdesc->scrollbar->Visible=PX_TRUE; + } + else + { + pdesc->scrollbar->Visible=PX_FALSE; + PX_Object_SliderBarSetValue(pdesc->scrollbar,0); + } + + } +} + diff --git a/lib/PainterEngine/kernel/PX_Object_MemoryView.h b/lib/PainterEngine/kernel/PX_Object_MemoryView.h new file mode 100644 index 0000000000000000000000000000000000000000..9a0558c54af534a6c622ce9f21b852e09c338bcb --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_MemoryView.h @@ -0,0 +1,31 @@ +#ifndef PX_OBJECT_MEMORYVIEW_H +#define PX_OBJECT_MEMORYVIEW_H +#include "PX_Object.h" + +typedef struct +{ + px_void *pdata; + px_int size; + px_int cursor; + PX_Object *scrollbar; + px_dword address_offset; + px_int mark_start_cursor; + px_int mark_end_cursor; + + px_dword cursor_elapsed; + + px_color bordercolor; + px_color backgroundcolor; + px_color fontcolor; + px_color cursorcolor; + px_color selectcolor; +}PX_Object_MemoryView; + +PX_Object * PX_Object_MemoryViewCreate(px_memorypool *mp,PX_Object *pParent,px_int x,px_int y,px_int Width,px_int Height); +PX_Object_MemoryView *PX_Object_GetMemoryView(PX_Object *pObject); +px_void PX_Object_MemoryViewSetFontColor(PX_Object *pObject,px_color Color); +px_void PX_Object_MemoryViewSetBackgroundColor(PX_Object *pObject,px_color Color); +px_void PX_Object_MemoryViewSetData(PX_Object *pObject,px_void *pdata,px_dword size); + +#endif + diff --git a/lib/PainterEngine/kernel/PX_Object_Menu.c b/lib/PainterEngine/kernel/PX_Object_Menu.c new file mode 100644 index 0000000000000000000000000000000000000000..fb6f1fd6cf1e96907b362ce3b30200241b1b4c4c --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_Menu.c @@ -0,0 +1,460 @@ +#include "PX_Object_Menu.h" +static PX_Object_Menu *PX_Object_GetMenu(PX_Object *pMenuObject) +{ + if (pMenuObject->Type==PX_OBJECT_TYPE_MENU) + { + return (PX_Object_Menu *)pMenuObject->pObject; + } + return PX_NULL; +} +static px_void PX_MenuSubMenuUpdateEx(PX_Object_Menu *pMenu,PX_Object_Menu_Item *pItem,px_int startX,px_int startY) +{ + px_int index=0; + px_int maxWidth=0,maxHeight=0; + px_list_node *pNode=PX_NULL; + + + for (pNode=PX_ListNodeAt(&pItem->Items,0);pNode;pNode=PX_ListNodeNext(pNode)) + { + px_int cWidth,cHeight; + PX_Object_Menu_Item *pSubItem=PX_LIST_NODETDATA(PX_Object_Menu_Item,pNode); + PX_FontModuleTextGetRenderWidthHeight(pMenu->fontmodule,pSubItem->Text,&cWidth,&cHeight); + if (cWidth>maxWidth) + { + maxWidth=cWidth; + } + if (cHeight>maxHeight) + { + maxHeight=cHeight; + } + } + + maxWidth+=PX_MENU_ITEM_SPACER_SIZE*2+18+16; + maxHeight+=PX_MENU_ITEM_SPACER_SIZE*2; + + + if (maxWidthminimumSize) + { + maxWidth=pMenu->minimumSize; + } + + for (pNode=PX_ListNodeAt(&pItem->Items,0);pNode;pNode=PX_ListNodeNext(pNode)) + { + PX_Object_Menu_Item *pSubItem=PX_LIST_NODETDATA(PX_Object_Menu_Item,pNode); + pSubItem->x=startX; + pSubItem->y=startY+index*maxHeight; + pSubItem->width=maxWidth; + pSubItem->height=maxHeight; + index++; + } + + + for (pNode=PX_ListNodeAt(&pItem->Items,0);pNode;pNode=PX_ListNodeNext(pNode)) + { + PX_Object_Menu_Item *pSubItem=PX_LIST_NODETDATA(PX_Object_Menu_Item,pNode); + PX_MenuSubMenuUpdateEx(pMenu,pSubItem,pSubItem->x+pSubItem->width,pSubItem->y); + } +} +static px_void PX_MenuSubMenuUpdate(px_int x,px_int y,PX_Object_Menu *pMenu) +{ + px_int index=0; + px_int maxWidth=0,maxHeight=0; + px_list_node *pNode=PX_NULL; + + + for (pNode=PX_ListNodeAt(&pMenu->root.Items,0);pNode;pNode=PX_ListNodeNext(pNode)) + { + px_int cWidth,cHeight; + PX_Object_Menu_Item *pSubItem=PX_LIST_NODETDATA(PX_Object_Menu_Item,pNode); + PX_FontModuleTextGetRenderWidthHeight(pMenu->fontmodule,pSubItem->Text,&cWidth,&cHeight); + if (cWidth>maxWidth) + { + maxWidth=cWidth; + } + if (cHeight>maxHeight) + { + maxHeight=cHeight; + } + } + + maxWidth+=PX_MENU_ITEM_SPACER_SIZE*2+18+16; + maxHeight+=PX_MENU_ITEM_SPACER_SIZE*2; + + + if (maxWidthminimumSize) + { + maxWidth=pMenu->minimumSize; + } + + for (pNode=PX_ListNodeAt(&pMenu->root.Items,0);pNode;pNode=PX_ListNodeNext(pNode)) + { + PX_Object_Menu_Item *pSubItem=PX_LIST_NODETDATA(PX_Object_Menu_Item,pNode); + pSubItem->x=x+index*maxWidth; + pSubItem->y=y; + pSubItem->width=maxWidth; + pSubItem->height=maxHeight; + index++; + } + + + for (pNode=PX_ListNodeAt(&pMenu->root.Items,0);pNode;pNode=PX_ListNodeNext(pNode)) + { + PX_Object_Menu_Item *pSubItem=PX_LIST_NODETDATA(PX_Object_Menu_Item,pNode); + PX_MenuSubMenuUpdateEx(pMenu,pSubItem,pSubItem->x,pSubItem->y+pSubItem->height); + } +} +static px_bool PX_Object_MenuInitialize(px_memorypool *mp,PX_Object_Menu *pMenu,px_int x,int y,px_int width,PX_FontModule *fontmodule) +{ + PX_memset(pMenu,0,sizeof(PX_Object_Menu)); + pMenu->fontmodule=fontmodule; + pMenu->minimumSize=width; + pMenu->mp=mp; + pMenu->activating=PX_FALSE; + pMenu->backgroundColor=PX_OBJECT_UI_DEFAULT_BACKGROUNDCOLOR; + pMenu->cursorColor=PX_OBJECT_UI_DEFAULT_CURSORCOLOR; + pMenu->fontColor=PX_OBJECT_UI_DEFAULT_FONTCOLOR; + pMenu->disableColor=PX_OBJECT_UI_DISABLE_FONTCOLOR; + PX_ListInitialize(mp,&pMenu->root.Items); + pMenu->root.Activated=PX_TRUE; + return PX_TRUE; +} +typedef enum +{ + PX_MENU_CURSORACTION_MOVE, + PX_MENU_CURSORACTION_DOWN, +}PX_MENU_CURSORACTION; +static px_void PX_MenuClearParent(PX_Object_Menu *pMenu,PX_Object_Menu_Item *pItem) +{ + px_list_node *pNode=PX_NULL; + + for (pNode=PX_ListNodeAt(&pItem->pParent->Items,0);pNode;pNode=PX_ListNodeNext(pNode)) + { + PX_Object_Menu_Item *pSubItem=PX_LIST_NODETDATA(PX_Object_Menu_Item,pNode); + pSubItem->onCursor=PX_FALSE; + pSubItem->Activated=PX_FALSE; + } +} +static px_void PX_MenuClearChild(PX_Object_Menu *pMenu,PX_Object_Menu_Item *pItem) +{ + px_list_node *pNode=PX_NULL; + + for (pNode=PX_ListNodeAt(&pItem->Items,0);pNode;pNode=PX_ListNodeNext(pNode)) + { + PX_Object_Menu_Item *pSubItem=PX_LIST_NODETDATA(PX_Object_Menu_Item,pNode); + pSubItem->onCursor=PX_FALSE; + pSubItem->Activated=PX_FALSE; + } +} +static px_void PX_MenuClearState(PX_Object *pMenuObject) +{ + PX_Object_Menu *pMenu=PX_Object_GetMenu(pMenuObject); + px_list_node *pNode=PX_NULL; + + for (pNode=PX_ListNodeAt(&pMenu->root.Items,0);pNode;pNode=PX_ListNodeNext(pNode)) + { + PX_Object_Menu_Item *pSubItem=PX_LIST_NODETDATA(PX_Object_Menu_Item,pNode); + pSubItem->onCursor=PX_FALSE; + pSubItem->Activated=PX_FALSE; + } + PX_ObjectClearFocus(pMenuObject); + pMenu->activating=PX_FALSE; +} +px_bool PX_Menu_CursorAction(PX_Object *pObject,PX_Object_Menu_Item *pItem,px_float x,px_float y,PX_MENU_CURSORACTION action) +{ + px_list_node *pNode=PX_NULL; + PX_Object_Menu *pMenu=PX_Object_GetMenu(pObject); + + if (PX_isXYInRegion(x,y,(px_float)pItem->x,(px_float)pItem->y,(px_float)pItem->width,(px_float)pItem->height)) + { + + PX_MenuClearParent(pMenu,pItem); + switch (action) + { + case PX_MENU_CURSORACTION_MOVE: + { + if (!pItem->enable) + { + return PX_TRUE; + } + pItem->onCursor=PX_TRUE; + if (pMenu->activating&&pItem->Items.size!=0) + { + pItem->Activated=PX_TRUE; + PX_MenuClearChild(pMenu,pItem); + } + } + break; + case PX_MENU_CURSORACTION_DOWN: + { + if (!pItem->enable) + { + return PX_TRUE; + } + pItem->onCursor=PX_TRUE; + pItem->Activated=PX_TRUE; + + if (pItem->Items.size==0) + { + PX_MenuClearState(pObject); + } + else + { + PX_MenuClearChild(pMenu,pItem); + } + + if (pItem->func_callback) + { + pItem->func_callback(pItem->user_ptr); + } + + return PX_TRUE; + } + break; + } + } + else + { + pItem->onCursor=PX_FALSE; + } + + if (!pItem->Activated) + { + return PX_FALSE; + } + + for (pNode=PX_ListNodeAt(&pItem->Items,0);pNode;pNode=PX_ListNodeNext(pNode)) + { + PX_Object_Menu_Item *pSubItem=PX_LIST_NODETDATA(PX_Object_Menu_Item,pNode); + if(PX_Menu_CursorAction(pObject,pSubItem,x,y,action)) + return PX_TRUE; + } + return PX_FALSE; +} +px_void PX_MenuPostEvent_OnCursorDown(PX_Object *pObject,PX_Object_Event e) +{ + px_list_node *pNode=PX_NULL; + px_float x=PX_Object_Event_GetCursorX(e); + px_float y=PX_Object_Event_GetCursorY(e); + PX_Object_Menu *pMenu=PX_Object_GetMenu(pObject); + + if (!pMenu->activating) + { + for (pNode=PX_ListNodeAt(&pMenu->root.Items,0);pNode;pNode=PX_ListNodeNext(pNode)) + { + PX_Object_Menu_Item *pSubItem=PX_LIST_NODETDATA(PX_Object_Menu_Item,pNode); + if (PX_isXYInRegion(x,y,(px_float)pSubItem->x,(px_float)pSubItem->y,(px_float)pSubItem->width,(px_float)pSubItem->height)&&pSubItem->enable) + { + pMenu->activating=PX_TRUE; + PX_ObjectSetFocus(pObject); + pSubItem->Activated=PX_TRUE; + PX_MenuClearChild(pMenu,pSubItem); + return; + } + } + PX_ObjectClearFocus(pObject); + pMenu->activating=PX_FALSE; + return; + } + else + { + if (!PX_Menu_CursorAction(pObject,&pMenu->root,x,y,PX_MENU_CURSORACTION_DOWN)) + { + PX_MenuClearState(pObject); + } + } +} +px_void PX_MenuPostEvent_OnCursorMove(PX_Object *pObject,PX_Object_Event e) +{ + PX_Object_Menu *pMenu=PX_Object_GetMenu(pObject); + px_float x=PX_Object_Event_GetCursorX(e); + px_float y=PX_Object_Event_GetCursorY(e); + PX_Menu_CursorAction(pObject,&pMenu->root,x,y,PX_MENU_CURSORACTION_MOVE); +} +px_void PX_Object_MenuOnCursorEventEx(PX_Object *pObject,PX_Object_Event e) +{ + + switch(e.Event) + { + case PX_OBJECT_EVENT_CURSORMOVE: + case PX_OBJECT_EVENT_CURSORDRAG: + { + PX_MenuPostEvent_OnCursorMove(pObject,e); + } + break; + case PX_OBJECT_EVENT_CURSORDOWN: + { + PX_MenuPostEvent_OnCursorDown(pObject,e); + } + break; + default: + break; + } + +} +static px_void PX_MenuRenderItem(px_surface *pSurface,PX_Object_Menu *pMenu,PX_Object_Menu_Item *pItem,px_bool broot,px_dword elapsed) +{ + if (pItem->width&&pItem->height) + { + if (pItem->onCursor||pItem->Activated) + { + PX_GeoDrawRect(pSurface,pItem->x,pItem->y,pItem->x+pItem->width-1,pItem->y+pItem->height-1,pMenu->cursorColor); + } + else + { + PX_GeoDrawRect(pSurface,pItem->x,pItem->y,pItem->x+pItem->width-1,pItem->y+pItem->height-1,pMenu->backgroundColor); + } + + if (broot) + PX_FontModuleDrawText(pSurface,pMenu->fontmodule,pItem->x+pItem->width/2,pItem->y+pItem->height/2,PX_ALIGN_CENTER,pItem->Text,pMenu->fontColor); + else + { + if (!pItem->enable) + { + PX_FontModuleDrawText(pSurface,pMenu->fontmodule,pItem->x+18,pItem->y+pItem->height/2,PX_ALIGN_LEFTMID,pItem->Text,pMenu->disableColor); + } + else + { + PX_FontModuleDrawText(pSurface,pMenu->fontmodule,pItem->x+18,pItem->y+pItem->height/2,PX_ALIGN_LEFTMID,pItem->Text,pMenu->fontColor); + } + + if (pItem->Items.size!=0) + { + PX_GeoDrawTriangle(pSurface, + PX_POINT2D((px_float)(pItem->x+pItem->width-6),(px_float)(pItem->y+pItem->height/2)), + PX_POINT2D((px_float)(pItem->x+pItem->width-12),(px_float)(pItem->y+pItem->height/2-4)), + PX_POINT2D((px_float)(pItem->x+pItem->width-12),(px_float)(pItem->y+pItem->height/2+4)), + pMenu->fontColor); + } + } + + } + + + if (pItem->Activated) + { + if(pItem->Items.size) + { + px_list_node *pNode=PX_NULL; + for (pNode=PX_ListNodeAt(&pItem->Items,0);pNode;pNode=PX_ListNodeNext(pNode)) + { + PX_Object_Menu_Item *pSubItem=PX_LIST_NODETDATA(PX_Object_Menu_Item,pNode); + PX_MenuRenderItem(pSurface,pMenu,pSubItem,PX_FALSE,elapsed); + } + } + } +} +px_void PX_Object_MenuRenderEx(px_surface *pSurface,PX_Object_Menu *pMenu,px_dword elapsed) +{ + px_list_node *pNode=PX_NULL; + + for (pNode=PX_ListNodeAt(&pMenu->root.Items,0);pNode;pNode=PX_ListNodeNext(pNode)) + { + PX_Object_Menu_Item *pSubItem=PX_LIST_NODETDATA(PX_Object_Menu_Item,pNode); + PX_MenuRenderItem(pSurface,pMenu,pSubItem,PX_TRUE,elapsed); + } + +} +static px_void PX_MenuItemFree(PX_Object_Menu_Item *pItem) +{ + px_list_node *pNode=PX_NULL; + + for (pNode=PX_ListNodeAt(&pItem->Items,0);pNode;pNode=PX_ListNodeNext(pNode)) + { + PX_Object_Menu_Item *pSubItem=PX_LIST_NODETDATA(PX_Object_Menu_Item,pNode); + PX_MenuItemFree(pSubItem); + } + PX_ListFree(&pItem->Items); +} +px_void PX_Object_MenuFreeEx(PX_Object_Menu *pMenu) +{ + PX_MenuItemFree(&pMenu->root); +} +PX_Object_Menu_Item * PX_Object_MenuAddItem(PX_Object *pObject,PX_Object_Menu_Item *parent,const px_char Text[],PX_MenuExecuteFunc _callback,px_void *ptr) +{ + PX_Object_Menu_Item item,*ret; + PX_Object_Menu *pMenu=PX_Object_GetMenu(pObject); + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + if (parent==PX_NULL) + { + parent = PX_Object_MenuGetRootItem(pObject); + } + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + PX_memset(&item,0,sizeof(PX_Object_Menu_Item)); + PX_strcpy(item.Text,Text,sizeof(item.Text)); + item.func_callback=_callback; + PX_ListInitialize(pMenu->mp,&item.Items); + item.pParent=parent; + item.user_ptr=ptr; + item.enable=PX_TRUE; + ret=(PX_Object_Menu_Item *)PX_ListPush(&parent->Items,&item,sizeof(item)); + if (ret!=PX_NULL) + { + PX_MenuSubMenuUpdate((px_int)objx,(px_int)objy,pMenu); + } + return ret; +} + +px_void PX_Object_MenuFree(PX_Object *Obj) +{ + PX_Object_MenuFreeEx(PX_Object_GetMenu(Obj)); +} + +px_void PX_Object_MenuRender(px_surface *psurface, PX_Object *Obj,px_uint elapsed) +{ + PX_Object_MenuRenderEx(psurface,PX_Object_GetMenu(Obj),elapsed); +} + +px_void PX_Object_MenuOnCursorEvent(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + PX_Object_MenuOnCursorEventEx(pObject,e); +} + +PX_Object * PX_Object_MenuCreate(px_memorypool *mp,PX_Object *Parent,px_int x,int y,px_int width,PX_FontModule *fontmodule) +{ + PX_Object *pObject; + PX_Object_Menu *pMenu=(PX_Object_Menu *)MP_Malloc(mp,sizeof(PX_Object_Menu)); + + if (pMenu==PX_NULL) + { + return PX_NULL; + } + + if (!PX_Object_MenuInitialize(mp,pMenu,x,y,width,fontmodule)) + { + return PX_NULL; + } + + + pObject=PX_ObjectCreate(mp,Parent,(px_float)x,(px_float)y,0,0,0,0); + if (pObject==PX_NULL) + { + MP_Free(pObject->mp,pMenu); + return PX_NULL; + } + + + pObject->pObject=pMenu; + pObject->Enabled=PX_TRUE; + pObject->Visible=PX_TRUE; + pObject->Type=PX_OBJECT_TYPE_MENU; + pObject->Func_ObjectFree=PX_Object_MenuFree; + pObject->Func_ObjectRender=PX_Object_MenuRender; + pObject->OnLostFocusReleaseEvent=PX_TRUE; + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORDOWN,PX_Object_MenuOnCursorEvent,PX_NULL); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORMOVE,PX_Object_MenuOnCursorEvent,PX_NULL); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORDRAG,PX_Object_MenuOnCursorEvent,PX_NULL); + return pObject; +} + +PX_Object_Menu_Item * PX_Object_MenuGetRootItem(PX_Object *pMenuObject) +{ + return &PX_Object_GetMenu(pMenuObject)->root; +} \ No newline at end of file diff --git a/lib/PainterEngine/kernel/PX_Object_Menu.h b/lib/PainterEngine/kernel/PX_Object_Menu.h new file mode 100644 index 0000000000000000000000000000000000000000..2293ae8141cac3efdcb218e7080396086e5435a0 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_Menu.h @@ -0,0 +1,44 @@ +#ifndef PX_OBJECT_MENU_H +#define PX_OBJECT_MENU_H +#include "PX_Object.h" + +#define PX_MENU_CONTENT_MAX_LEN 48 +#define PX_MENU_ITEM_SPACER_SIZE 2 +typedef px_void (*PX_MenuExecuteFunc)(px_void *userPtr); + + +struct _PX_Object_Menu_Item +{ + struct _PX_Object_Menu_Item *pParent; + px_int x,y,width,height; + px_bool enable; + px_char Text[PX_MENU_CONTENT_MAX_LEN]; + px_bool onCursor; + px_bool Activated; + px_list Items; + PX_MenuExecuteFunc func_callback; + px_void *user_ptr; +}; +typedef struct _PX_Object_Menu_Item PX_Object_Menu_Item; + +typedef struct +{ + px_memorypool *mp; + px_bool activating; + px_int minimumSize; + PX_Object_Menu_Item root; + PX_FontModule *fontmodule; + px_color backgroundColor; + px_color fontColor; + px_color disableColor; + px_color cursorColor; +}PX_Object_Menu; + + +PX_Object * PX_Object_MenuCreate(px_memorypool *mp,PX_Object *Parent,px_int x,int y,px_int width,PX_FontModule *fontmodule); +PX_Object_Menu_Item * PX_Object_MenuGetRootItem(PX_Object *pMenuObject); +PX_Object_Menu_Item * PX_Object_MenuAddItem(PX_Object *pMenuObject,PX_Object_Menu_Item *parent,const px_char Text[],PX_MenuExecuteFunc _callback,px_void *ptr); + + +#endif + diff --git a/lib/PainterEngine/kernel/PX_Object_MessageBox.c b/lib/PainterEngine/kernel/PX_Object_MessageBox.c new file mode 100644 index 0000000000000000000000000000000000000000..a4a3e7678b669871c4b7c334e3e93d34042f1b9b --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_MessageBox.c @@ -0,0 +1,291 @@ +#include "PX_Object_MessageBox.h" + +PX_Object_MessageBox *PX_Object_GetMessageBox(PX_Object *pObject) +{ + if (pObject->Type==PX_OBJECT_TYPE_MESSAGEBOX) + { + return (PX_Object_MessageBox *)pObject->pObject; + } + return PX_NULL; +} + +static px_void PX_Object_MessageBox_BtnYesClick(PX_Object *pObject,PX_Object_Event e,px_void *user) +{ + PX_Object_MessageBox *pm=PX_Object_GetMessageBox((PX_Object *)user); + PX_Object_MessageBoxClose((PX_Object *)user); + if (pm->function_yes) + { + pm->function_yes((PX_Object *)user,PX_OBJECT_BUILD_EVENT(PX_OBJECT_EVENT_EXECUTE),pm->function_yes_ptr); + } + +} + +static px_void PX_Object_MessageBox_BtnNoClick(PX_Object *pObject,PX_Object_Event e,px_void *user) +{ + PX_Object_MessageBox *pm=PX_Object_GetMessageBox((PX_Object *)user); + PX_Object_MessageBoxClose((PX_Object *)user); + if (pm->function_no) + { + pm->function_no((PX_Object *)user,PX_OBJECT_BUILD_EVENT(PX_OBJECT_EVENT_EXECUTE),pm->function_yes_ptr); + } +} + +static px_void PX_Object_MessageBox_EditOnEnter(PX_Object *pObject,PX_Object_Event e,px_void *user) +{ + if (e.Event==PX_OBJECT_EVENT_KEYDOWN) + { + if (PX_Object_Event_GetKeyDown(e)=='\r') + { + PX_Object_MessageBox *pm=PX_Object_GetMessageBox((PX_Object *)user); + PX_Object_MessageBoxClose((PX_Object *)user); + if (pm->function_yes) + { + pm->function_yes((PX_Object *)user,PX_OBJECT_BUILD_EVENT(PX_OBJECT_EVENT_EXECUTE),pm->function_yes_ptr); + } + return; + } + } +} + +px_void PX_Object_MessageBoxClose(PX_Object *pObject) +{ + PX_Object_MessageBox *pMessageBox=PX_Object_GetMessageBox(pObject); + if (pMessageBox) + { + PX_ObjectReleaseFocus(pObject); + pMessageBox->mode=PX_OBJECT_MESSAGEBOX_MODE_CLOSE; + pMessageBox->btn_Ok->Visible=PX_FALSE; + pMessageBox->btn_Cancel->Visible=PX_FALSE; + pMessageBox->edit_inputbox->Visible=PX_FALSE; + } + +} + +static px_void PX_Object_MessageBoxRender(px_surface *pSurface,PX_Object *pObject,px_dword elapsed) +{ + + px_color backGroundColor,frontColor; + PX_Object_MessageBox *pm=PX_Object_GetMessageBox(pObject); + if (elapsed>2000) + { + return; + } + + if (pm->fillbackgroundcolor._argb.a) + { + PX_SurfaceClear(pSurface,0,0,pSurface->width-1,pSurface->height-1,pm->fillbackgroundcolor); + } + + + pm->btn_Ok->x=pSurface->width/2+200.0f; + pm->btn_Ok->y=pSurface->height/2+150.0f; + + pm->btn_Cancel->x=pSurface->width/2+300.0f; + pm->btn_Cancel->y=pSurface->height/2+150.0f; + + pm->edit_inputbox->x=pSurface->width/2-100.0f; + pm->edit_inputbox->y=pSurface->height/2-12.0f; + + if (pm->edit_inputbox->Visible) + { + PX_Object_EditSetFocus(pm->edit_inputbox,PX_TRUE); + } + + switch(pm->mode) + { + case PX_OBJECT_MESSAGEBOX_MODE_EXPAND: + pm->schedule+=elapsed; + if (pm->schedule>PX_OBJECT_MESSAGEBOX_DEFAULT_STAGE_2_TIME) + { + pm->schedule=PX_OBJECT_MESSAGEBOX_DEFAULT_STAGE_2_TIME; + } + break; + case PX_OBJECT_MESSAGEBOX_MODE_CLOSE: + default: + { + pm->schedule-=elapsed; + if (pm->schedule<0) + { + pm->schedule=0; + pObject->Visible=PX_FALSE; + } + } + break; + + } + + switch(pm->colormod) + { + case PX_MESSAGEBOX_COLORMOD_LIGHT: + { + backGroundColor=PX_COLOR(255,0,0,0); + frontColor=PX_COLOR(255,255,255,255); + } + break; + case PX_MESSAGEBOX_COLORMOD_NIGHT: + default: + { + backGroundColor=PX_COLOR(255,255,255,255); + frontColor=PX_COLOR(255,0,0,0); + } + break; + } + + + + if (pm->schedulewidth*pm->schedule*pm->schedule/(PX_OBJECT_MESSAGEBOX_DEFAULT_STAGE_1_TIME*PX_OBJECT_MESSAGEBOX_DEFAULT_STAGE_1_TIME); + PX_GeoDrawRect(pSurface,(pSurface->width-width)/2,(pSurface->height-pm->PX_MESSAGEBOX_STAGE_1_HEIGHT)/2,(pSurface->width+width)/2,(pSurface->height+pm->PX_MESSAGEBOX_STAGE_1_HEIGHT)/2,backGroundColor); + } + else if(pm->scheduleschedule*pm->schedule/(PX_OBJECT_MESSAGEBOX_DEFAULT_STAGE_2_TIME*PX_OBJECT_MESSAGEBOX_DEFAULT_STAGE_2_TIME); + PX_GeoDrawRect(pSurface,0,(pSurface->height-height)/2,pSurface->width-1,(pSurface->height+height)/2,backGroundColor); + } + else + { + PX_GeoDrawRect(pSurface,0,(pSurface->height-pm->PX_MESSAGEBOX_STAGE_2_HEIGHT)/2,pSurface->width-1,(pSurface->height+pm->PX_MESSAGEBOX_STAGE_2_HEIGHT)/2,backGroundColor); + PX_GeoDrawRect(pSurface,0,(pSurface->height-pm->PX_MESSAGEBOX_STAGE_2_HEIGHT)/2-30,pSurface->width-1,(pSurface->height-pm->PX_MESSAGEBOX_STAGE_2_HEIGHT)/2-10,backGroundColor); + PX_GeoDrawRect(pSurface,0,(pSurface->height+pm->PX_MESSAGEBOX_STAGE_2_HEIGHT)/2+10,pSurface->width-1,(pSurface->height+pm->PX_MESSAGEBOX_STAGE_2_HEIGHT)/2+30,backGroundColor); + + if (pm->edit_inputbox->Visible) + { + //inputbox mode + PX_FontModuleDrawText(pSurface,pm->fontmodule,pSurface->width/2-108,pSurface->height/2,PX_ALIGN_RIGHTMID,pm->Message,frontColor); + } + else + { + PX_FontModuleDrawText(pSurface,pm->fontmodule,pSurface->width/2,pSurface->height/2,PX_ALIGN_CENTER,pm->Message,frontColor); + } + } + + +} + +px_void PX_Object_MessageBoxAlertOk(PX_Object *pObject,const px_char *message,PX_Object_MessageBoxCallBack func_callback,px_void *ptr) +{ + PX_Object_MessageBox *pm=PX_Object_GetMessageBox(pObject); + pm->function_yes=func_callback; + pm->function_yes_ptr=ptr; + + pm->schedule=0; + pObject->Visible=PX_TRUE; + PX_strcpy(pm->Message,message,sizeof(pm->Message)); + pm->mode=PX_OBJECT_MESSAGEBOX_MODE_EXPAND; + pm->btn_Cancel->Visible=PX_FALSE; + pm->btn_Ok->Visible=PX_TRUE; + + pm->edit_inputbox->Visible=PX_FALSE; + PX_ObjectSetFocus(pObject); +} + +px_void PX_Object_MessageBoxAlert(PX_Object *pObject,const px_char *message) +{ + PX_Object_MessageBox *pm=PX_Object_GetMessageBox(pObject); + if (!pObject->Visible) + { + pm->schedule=0; + pObject->Visible=PX_TRUE; + } + + PX_strcpy(pm->Message,message,sizeof(pm->Message)); + pm->mode=PX_OBJECT_MESSAGEBOX_MODE_EXPAND; + pm->btn_Cancel->Visible=PX_FALSE; + pm->btn_Ok->Visible=PX_FALSE; + + pm->function_yes=PX_NULL; + pm->function_no_ptr=PX_NULL; + + pm->edit_inputbox->Visible=PX_FALSE; + PX_ObjectSetFocus(pObject); +} + + + +px_void PX_Object_MessageBoxAlertYesNo(PX_Object *pObject,const char *Message,PX_Object_MessageBoxCallBack func_yescallback,px_void *yesptr,PX_Object_MessageBoxCallBack func_nocallback,px_void *noptr) +{ + PX_Object_MessageBox *pm=PX_Object_GetMessageBox(pObject); + pm->function_yes=func_yescallback; + pm->function_no=func_nocallback; + pm->function_yes_ptr=yesptr; + pm->function_no_ptr=noptr; + + pm->schedule=0; + pObject->Visible=PX_TRUE; + PX_strcpy(pm->Message,Message,sizeof(pm->Message)); + pm->mode=PX_OBJECT_MESSAGEBOX_MODE_EXPAND; + pm->btn_Cancel->Visible=PX_TRUE; + pm->btn_Ok->Visible=PX_TRUE; + pm->edit_inputbox->Visible=PX_FALSE; + PX_ObjectSetFocus(pObject); +} + +px_void PX_Object_MessageBoxInputBox(PX_Object *pObject,const char *Message,PX_Object_MessageBoxCallBack func_yescallback,px_void *yesptr,PX_Object_MessageBoxCallBack func_cancelcallback,px_void *cancelptr) +{ + PX_Object_MessageBox *pm=PX_Object_GetMessageBox(pObject); + pm->function_yes=func_yescallback; + pm->function_no=func_cancelcallback; + pm->function_yes_ptr=yesptr; + pm->function_no_ptr=cancelptr; + + pm->schedule=0; + pObject->Visible=PX_TRUE; + PX_strcpy(pm->Message,Message,sizeof(pm->Message)); + pm->mode=PX_OBJECT_MESSAGEBOX_MODE_EXPAND; + pm->btn_Cancel->Visible=PX_TRUE; + pm->btn_Ok->Visible=PX_TRUE; + pm->edit_inputbox->Visible=PX_TRUE; + + PX_Object_EditSetText(pm->edit_inputbox,""); + PX_ObjectSetFocus(pObject); +} + +px_char * PX_Object_MessageBoxGetInput(PX_Object *pObject) +{ + PX_Object_MessageBox *pm=PX_Object_GetMessageBox(pObject); + return PX_Object_EditGetText(pm->edit_inputbox); +} + +px_void PX_Object_MessageBoxFree(PX_Object *pObject) +{ + +} + +PX_Object * PX_Object_MessageBoxCreate(px_memorypool *mp,PX_Object *parent,PX_FontModule *fontmodule) +{ + PX_Object_MessageBox msgbox; + PX_Object_MessageBox *pm=&msgbox; + PX_Object *pObject; + PX_memset(pm,0,sizeof(PX_Object_MessageBox)); + + pObject=PX_ObjectCreateEx(mp,parent,0,0,0,0,0,0,PX_OBJECT_TYPE_MESSAGEBOX,PX_NULL,PX_Object_MessageBoxRender,PX_Object_MessageBoxFree,pm,sizeof(PX_Object_MessageBox)); + pObject->Visible=PX_FALSE; + pm=PX_Object_GetMessageBox(pObject); + + pm->schedule=0; + pm->function_no=PX_NULL; + pm->function_yes=PX_NULL; + + if(!(pm->btn_Ok=PX_Object_PushButtonCreate(mp,pObject,0,0,84,28,"OK",PX_NULL))) return PX_FALSE; + + if(!(pm->btn_Cancel=PX_Object_PushButtonCreate(mp,pObject,0,0,84,28,"Cancel",PX_NULL))) return PX_FALSE; + + + if(!(pm->edit_inputbox=PX_Object_EditCreate(mp,pObject,0,0,256,32,fontmodule))) return PX_FALSE; + + PX_ObjectSetVisible(pm->edit_inputbox,PX_FALSE); + + pm->fontmodule=fontmodule; + + pm->PX_MESSAGEBOX_STAGE_1_HEIGHT=PX_OBJECT_MESSAGEBOX_DEFAULT_STAGE_1_HEIGHT; + pm->PX_MESSAGEBOX_STAGE_2_HEIGHT=PX_OBJECT_MESSAGEBOX_DEFAULT_STAGE_2_HEIGHT; + pm->fillbackgroundcolor=PX_OBJECT_UI_DEFAULT_BACKGROUNDCOLOR; + PX_ObjectRegisterEvent(pm->edit_inputbox,PX_OBJECT_EVENT_KEYDOWN,PX_Object_MessageBox_EditOnEnter,pObject); + PX_ObjectRegisterEvent(pm->btn_Ok,PX_OBJECT_EVENT_EXECUTE,PX_Object_MessageBox_BtnYesClick,pObject); + PX_ObjectRegisterEvent(pm->btn_Cancel,PX_OBJECT_EVENT_EXECUTE,PX_Object_MessageBox_BtnNoClick,pObject); + + + return pObject; +} + diff --git a/lib/PainterEngine/kernel/PX_Object_MessageBox.h b/lib/PainterEngine/kernel/PX_Object_MessageBox.h new file mode 100644 index 0000000000000000000000000000000000000000..a8201930c36fa10153ab4f0124a9866fa8b849db --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_MessageBox.h @@ -0,0 +1,58 @@ +#ifndef PX_OBJECT_MESSAGEBOX_H +#define PX_OBJECT_MESSAGEBOX_H +#include "PX_Object.h" + + +#define PX_OBJECT_MESSAGEBOX_DEFAULT_STAGE_1_HEIGHT 10 +#define PX_OBJECT_MESSAGEBOX_DEFAULT_STAGE_1_TIME 60 +#define PX_OBJECT_MESSAGEBOX_DEFAULT_STAGE_2_HEIGHT 200 +#define PX_OBJECT_MESSAGEBOX_DEFAULT_STAGE_2_TIME 240 +#define PX_OBJECT_MESSAGEBOX_MAX_MESSAGESIZE 128 + +typedef enum +{ + PX_OBJECT_MESSAGEBOX_MODE_EXPAND, + PX_OBJECT_MESSAGEBOX_MODE_CLOSE +}PX_OBJECT_MESSAGEBOX_MODE; + + +typedef enum +{ + PX_MESSAGEBOX_COLORMOD_LIGHT, + PX_MESSAGEBOX_COLORMOD_NIGHT, +}PX_MESSAGEBOX_COLORMOD; + +struct _PX_Object_MessageBox; + +typedef px_void (*PX_Object_MessageBoxCallBack)(PX_Object *pmessagebox,PX_Object_Event e, px_void *ptr); + +typedef struct _PX_Object_MessageBox +{ + px_int schedule; + + PX_OBJECT_MESSAGEBOX_MODE mode; + PX_MESSAGEBOX_COLORMOD colormod; + + px_int PX_MESSAGEBOX_STAGE_1_HEIGHT; + px_int PX_MESSAGEBOX_STAGE_2_HEIGHT; + + PX_Object_MessageBoxCallBack function_yes,function_no; + px_void *function_yes_ptr,*function_no_ptr; + px_char Message[PX_OBJECT_MESSAGEBOX_MAX_MESSAGESIZE]; + PX_FontModule *fontmodule; + PX_Object *btn_Ok,*btn_Cancel,*edit_inputbox; + + px_color fillbackgroundcolor; +}PX_Object_MessageBox; + + +PX_Object_MessageBox *PX_Object_GetMessageBox(PX_Object *pObject); +px_void PX_Object_MessageBoxClose(PX_Object *pObject); +px_void PX_Object_MessageBoxAlertOk(PX_Object *pObject,const px_char *message,PX_Object_MessageBoxCallBack func_callback,px_void *ptr); +px_void PX_Object_MessageBoxAlert(PX_Object *pObject,const px_char *message); +px_void PX_Object_MessageBoxAlertYesNo(PX_Object *pObject,const char *Message,PX_Object_MessageBoxCallBack func_yescallback,px_void *yesptr,PX_Object_MessageBoxCallBack func_nocallback,px_void *noptr); +px_void PX_Object_MessageBoxInputBox(PX_Object *pObject,const char *Message,PX_Object_MessageBoxCallBack func_yescallback,px_void *yesptr,PX_Object_MessageBoxCallBack func_cancelcallback,px_void *cancelptr); +px_char * PX_Object_MessageBoxGetInput(PX_Object *pObject); +PX_Object * PX_Object_MessageBoxCreate(px_memorypool *mp,PX_Object *parent,PX_FontModule *fontmodule); +#endif + diff --git a/lib/PainterEngine/kernel/PX_Object_Panc.c b/lib/PainterEngine/kernel/PX_Object_Panc.c new file mode 100644 index 0000000000000000000000000000000000000000..e01936278d8facac1706e5576c1f07f2daf2d56f --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_Panc.c @@ -0,0 +1,428 @@ +#include "PX_Object_Panc.h" +#include "PX_Object_Panc.h" + +px_void PX_Object_PancRender(px_surface *pSurface,PX_Object *pObject,px_dword elapsed) +{ + PX_Object_Panc *pDesc=PX_ObjectGetDesc(PX_Object_Panc,pObject); + px_int i; + px_float step; + px_color renderColor; + + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + ////////////////////////////////////////////////////////////////////////// + //source + //x + + renderColor=pDesc->borderColor; + renderColor._argb.a/=6; + + step=pDesc->sourceX-objx; + step=step/4; + for (i=0;i<5;i++) + { + PX_GeoDrawLine(pSurface,(px_int)(objx+step*i), (px_int)objy,(px_int)(objx+step*i),(px_int)(objy+objHeight),1,renderColor); + } + + step=objx+objWidth-pDesc->sourceX; + step=step/4; + for (i=0;i<5;i++) + { + PX_GeoDrawLine(pSurface,(px_int)(pDesc->sourceX+step*i), (px_int)objy,(px_int)(pDesc->sourceX+step*i),(px_int)(objy+objHeight),1,renderColor); + } + + //y + step=pDesc->sourceY-objy; + step=step/4; + for (i=0;i<5;i++) + { + PX_GeoDrawLine(pSurface,(px_int)objx,(px_int)(objy+step*i),(px_int)(objx+objWidth),(px_int)(objy+step*i),1,renderColor); + } + + step=objy+objHeight-pDesc->sourceY; + step=step/4; + for (i=0;i<5;i++) + { + PX_GeoDrawLine(pSurface, (px_int)objx,(px_int)(pDesc->sourceY+step*i),(px_int)(objx+objWidth),(px_int)(pDesc->sourceY+step*i),1,renderColor); + } + + + ////////////////////////////////////////////////////////////////////////// + //current + //x + + renderColor=pDesc->borderColor; + + step=pDesc->currentX-objx; + step=step/4; + for (i=0;i<5;i++) + { + PX_GeoDrawLine(pSurface,(px_int)(objx+step*i), (px_int)objy,(px_int)(objx+step*i),(px_int)(objy+objHeight),1,renderColor); + } + + step=objx+objWidth-pDesc->currentX; + step=step/4; + for (i=0;i<5;i++) + { + PX_GeoDrawLine(pSurface,(px_int)(pDesc->currentX+step*i), (px_int)objy,(px_int)(pDesc->currentX+step*i),(px_int)(objy+objHeight),1,renderColor); + } + + //y + step=pDesc->currentY-objy; + step=step/4; + for (i=0;i<5;i++) + { + PX_GeoDrawLine(pSurface, (px_int)objx,(px_int)(objy+step*i),(px_int)(objx+objWidth),(px_int)(objy+step*i),1,renderColor); + } + + step=objy+objHeight-pDesc->currentY; + step=step/4; + for (i=0;i<5;i++) + { + PX_GeoDrawLine(pSurface, (px_int)objx,(px_int)(pDesc->currentY+step*i),(px_int)(objx+objWidth),(px_int)(pDesc->currentY+step*i),1,renderColor); + } + + ////////////////////////////////////////////////////////////////////////// + //controller point + renderColor=pDesc->borderColor; + renderColor._argb.a/=6; + PX_GeoDrawSolidCircle(pSurface,(px_int)pDesc->currentX,(px_int)pDesc->currentY,8,renderColor); + + PX_GeoDrawSolidCircle(pSurface,(px_int)(objx),(px_int)(objy),5,renderColor); + PX_GeoDrawSolidCircle(pSurface,(px_int)(objx+objWidth),(px_int)(objy),5,renderColor); + PX_GeoDrawSolidCircle(pSurface,(px_int)(objx),(px_int)(objy+objHeight),5,renderColor); + PX_GeoDrawSolidCircle(pSurface,(px_int)(objx+objWidth),(px_int)(objy+objHeight),5,renderColor); + + PX_GeoDrawBorder(pSurface,(px_int)objx,(px_int)objy,(px_int)(objx+objWidth),(px_int)(objy+objHeight),3,pDesc->borderColor); + +} + +px_void PX_Object_PancOnCursorDown(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + px_float x,y; + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + PX_Object_Panc *pDesc=PX_ObjectGetDesc(PX_Object_Panc,pObject); + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + x=PX_Object_Event_GetCursorX(e); + y=PX_Object_Event_GetCursorY(e); + + + pDesc->bselect=PX_Object_Panc_bselect_none; + if ((x-pDesc->currentX)*(x-pDesc->currentX)+(y-pDesc->currentY)*(y-pDesc->currentY)<64) + { + pDesc->bselect=PX_Object_Panc_bselect_center; + return; + } + + + if ((x-objx)*(x-objx)+(y-objy)*(y-objy)<25) + { + pDesc->bselect=PX_Object_Panc_bselect_lefttop; + return; + } + + if ((x-objx-objWidth)*(x-objx-objWidth)+(y-objy)*(y-objy)<25) + { + pDesc->bselect=PX_Object_Panc_bselect_righttop; + return; + } + + if ((x-objx)*(x-objx)+(y-objy-objHeight)*(y-objy-objHeight)<25) + { + pDesc->bselect=PX_Object_Panc_bselect_leftbottom; + return; + } + + if ((x-objx-objWidth)*(x-objx-objWidth)+(y-objy-objHeight)*(y-objy-objHeight)<25) + { + pDesc->bselect=PX_Object_Panc_bselect_rightbottom; + return; + } + +} + +px_void PX_Object_PancOnCursorRDown(PX_Object* pObject, PX_Object_Event e, px_void* ptr) +{ + px_float x, y; + PX_Object_Panc* pDesc = PX_ObjectGetDesc(PX_Object_Panc, pObject); + px_float objx, objy, objWidth, objHeight; + px_float inheritX, inheritY; + PX_ObjectGetInheritXY(pObject, &inheritX, &inheritY); + + objx = (pObject->x + inheritX); + objy = (pObject->y + inheritY); + objWidth = pObject->Width; + objHeight = pObject->Height; + + + x = PX_Object_Event_GetCursorX(e); + y = PX_Object_Event_GetCursorY(e); + + pDesc->sourceX = x; + pDesc->sourceY = y; + + if (pDesc->sourceX < objx) + { + pDesc->sourceX = objx; + } + + if (pDesc->sourceX > objx + objWidth) + { + pDesc->sourceX = objx + objWidth; + } + + if (pDesc->sourceY < objy) + { + pDesc->sourceY = objy; + } + + if (pDesc->sourceY > objy + objHeight) + { + pDesc->sourceY = objy + objHeight; + } + + pDesc->currentX = pDesc->sourceX; + pDesc->currentY = pDesc->sourceY; +} + +px_void PX_Object_PancOnCursorDrag(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + px_float x,y; + PX_Object_Panc *pDesc=PX_ObjectGetDesc(PX_Object_Panc,pObject); + px_float objx, objy, objWidth, objHeight; + px_float inheritX, inheritY; + PX_ObjectGetInheritXY(pObject, &inheritX, &inheritY); + + objx = (pObject->x + inheritX); + objy = (pObject->y + inheritY); + objWidth = pObject->Width; + objHeight = pObject->Height; + + + x=PX_Object_Event_GetCursorX(e); + y=PX_Object_Event_GetCursorY(e); + + switch (pDesc->bselect) + { + case PX_Object_Panc_bselect_center: + { + pDesc->currentX= x; + pDesc->currentY =y; + + if (pDesc->currentXcurrentX = objx; + } + + if (pDesc->currentX > objx+ objWidth) + { + pDesc->currentX = objx+ objWidth; + } + + if (pDesc->currentY < objy) + { + pDesc->currentY = objy; + } + + if (pDesc->currentY > objy + objHeight) + { + pDesc->currentY = objy + objHeight; + } + + PX_ObjectExecuteEvent(pObject, PX_OBJECT_BUILD_EVENT(PX_OBJECT_EVENT_VALUECHANGED)); + } + break; + case PX_Object_Panc_bselect_lefttop: + { + px_float widthinc,heightinc; + widthinc=objx-x; + heightinc=objy-y; + + if (objWidth+widthinc<=10) + { + return; + } + + if (objHeight+heightinc<=10) + { + return; + } + + pObject->x=x-inheritX; + pObject->y=y-inheritY; + pObject->Width+=widthinc; + pObject->Height+=heightinc; + + pDesc->sourceX=pObject->x+pObject->Width/2; + pDesc->sourceY=pObject->y+pObject->Height/2; + + pDesc->currentX=pDesc->sourceX; + pDesc->currentY=pDesc->sourceY; + PX_ObjectExecuteEvent(pObject, PX_OBJECT_BUILD_EVENT(PX_OBJECT_EVENT_VALUECHANGED)); + } + break; + case PX_Object_Panc_bselect_righttop: + { + px_float widthinc,heightinc; + widthinc=x-objx-objWidth; + heightinc=objy-y; + + if (objWidth+widthinc<=10) + { + return; + } + + if (objHeight+heightinc<=10) + { + return; + } + + pObject->y=y-inheritY; + + pObject->Width+=widthinc; + pObject->Height+=heightinc; + + pDesc->sourceX=pObject->x+pObject->Width/2; + pDesc->sourceY=pObject->y+pObject->Height/2; + + pDesc->currentX=pDesc->sourceX; + pDesc->currentY=pDesc->sourceY; + PX_ObjectExecuteEvent(pObject, PX_OBJECT_BUILD_EVENT(PX_OBJECT_EVENT_VALUECHANGED)); + } + break; + case PX_Object_Panc_bselect_leftbottom: + { + px_float widthinc,heightinc; + widthinc=objx-x; + heightinc=y-objy-objHeight; + + if (pObject->Width+widthinc<=10) + { + return; + } + + if (pObject->Height+heightinc<=10) + { + return; + } + + pObject->x=x-inheritX; + + pObject->Width+=widthinc; + pObject->Height+=heightinc; + + pDesc->sourceX=pObject->x+pObject->Width/2; + pDesc->sourceY=pObject->y+pObject->Height/2; + + pDesc->currentX=pDesc->sourceX; + pDesc->currentY=pDesc->sourceY; + PX_ObjectExecuteEvent(pObject, PX_OBJECT_BUILD_EVENT(PX_OBJECT_EVENT_VALUECHANGED)); + } + break; + + case PX_Object_Panc_bselect_rightbottom: + { + px_float widthinc,heightinc; + widthinc=x-objx-objWidth; + heightinc=y-objy-objHeight; + + if (pObject->Width+widthinc<=10) + { + return; + } + + if (pObject->Height+heightinc<=10) + { + return; + } + + pObject->Width+=widthinc; + pObject->Height+=heightinc; + + pDesc->sourceX=pObject->x+pObject->Width/2; + pDesc->sourceY=pObject->y+pObject->Height/2; + + pDesc->currentX=pDesc->sourceX; + pDesc->currentY=pDesc->sourceY; + PX_ObjectExecuteEvent(pObject, PX_OBJECT_BUILD_EVENT(PX_OBJECT_EVENT_VALUECHANGED)); + } + break; + default: + break; + } + + + +} + +PX_Object * PX_Object_PancCreate(px_memorypool *mp,PX_Object *Parent,px_float x,px_float y,px_float widht,px_float height) +{ + PX_Object_Panc panc; + PX_Object *pObject; + PX_memset(&panc, 0, sizeof(panc)); + panc.sourceX=x+widht/2; + panc.sourceY=y+height/2; + + panc.currentX=x+widht/2; + panc.currentY=y+height/2; + + panc.borderColor=PX_OBJECT_UI_DEFAULT_FONTCOLOR; + + pObject=PX_ObjectCreateEx(mp,Parent,x,y,0,widht,height,0,PX_OBJECT_TYPE_PANC,PX_NULL,PX_Object_PancRender,PX_NULL,&panc,sizeof(panc)); + PX_ObjectRegisterEvent(pObject, PX_OBJECT_EVENT_CURSORDOWN, PX_Object_PancOnCursorDown, PX_NULL); + PX_ObjectRegisterEvent(pObject, PX_OBJECT_EVENT_CURSORDRAG, PX_Object_PancOnCursorDrag, PX_NULL); + PX_ObjectRegisterEvent(pObject, PX_OBJECT_EVENT_CURSORRDOWN, PX_Object_PancOnCursorRDown, PX_NULL); + return pObject; + +} + +PX_Object_Panc * PX_Object_GetPanc(PX_Object *pObject) +{ + return PX_ObjectGetDesc(PX_Object_Panc, pObject); +} + +px_void PX_Object_PancReset(PX_Object* pObject, px_float x, px_float y, px_float width, px_float height) +{ + PX_Object_Panc* pDesc = PX_ObjectGetDesc(PX_Object_Panc, pObject); + pObject->x = x; + pObject->y = y; + pObject->Width = width; + pObject->Height = height; + + pDesc->sourceX = x + width / 2; + pDesc->sourceY = y + height / 2; + + pDesc->currentX = x + width / 2; + pDesc->currentY = y + height / 2; +} + +PX_PancMatrix PX_Object_PancGetMatrix(PX_Object* pObject) +{ + PX_Object_Panc* pDesc = PX_ObjectGetDesc(PX_Object_Panc, pObject); + PX_PancMatrix mat; + mat.x = pObject->x; + mat.y = pObject->y; + mat.width = pObject->Width; + mat.height = pObject->Height; + mat.currentX = pDesc->currentX; + mat.currentY = pDesc->currentY; + mat.sourceX = pDesc->sourceX; + mat.sourceY = pDesc->sourceY; + return mat; +} + diff --git a/lib/PainterEngine/kernel/PX_Object_Panc.h b/lib/PainterEngine/kernel/PX_Object_Panc.h new file mode 100644 index 0000000000000000000000000000000000000000..7f4597f7824bcbd219162b1ef1473135b21a9ca7 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_Panc.h @@ -0,0 +1,39 @@ +#ifndef PX_OBJECT_PANC_H +#define PX_OBJECT_PANC_H +#include "PX_Object.h" + +typedef struct +{ + px_float x,y; + px_float width; + px_float height; + px_float sourceX,sourceY; + px_float currentX, currentY; +}PX_PancMatrix; + +typedef enum +{ + PX_Object_Panc_bselect_none=0, + PX_Object_Panc_bselect_center, + PX_Object_Panc_bselect_lefttop, + PX_Object_Panc_bselect_righttop, + PX_Object_Panc_bselect_leftbottom, + PX_Object_Panc_bselect_rightbottom, +}PX_Object_Panc_bselect; + + +typedef struct +{ + px_float sourceX,sourceY; + px_float currentX,currentY; + px_color borderColor; + PX_Object_Panc_bselect bselect; +}PX_Object_Panc; + +PX_Object * PX_Object_PancCreate(px_memorypool *mp,PX_Object *Parent,px_float x,px_float y,px_float width,px_float height); +PX_Object_Panc * PX_Object_GetPanc(PX_Object *pObject ); +px_void PX_Object_PancReset(PX_Object* pObject, px_float x, px_float y, px_float widht, px_float height); +PX_PancMatrix PX_Object_PancGetMatrix(PX_Object* pObject); + +#endif + diff --git a/lib/PainterEngine/kernel/PX_Object_Processbar.c b/lib/PainterEngine/kernel/PX_Object_Processbar.c new file mode 100644 index 0000000000000000000000000000000000000000..7378040f5d60aaa0ef1a919ee5c4a8f20433da98 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_Processbar.c @@ -0,0 +1,162 @@ +#include "PX_Object_Processbar.h" + + +px_void PX_Object_ProcessBarRender(px_surface *psurface, PX_Object *pObject,px_uint elapsed) +{ + px_int px,py,pl;//Processing start X,Processing Start Y &Processing length + px_int x,y,w,h; + px_float inheritX,inheritY; + + PX_Object_ProcessBar *pProcessBar=(PX_Object_ProcessBar *)pObject->pObject; + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + x=(px_int)(pObject->x+inheritX); + y=(px_int)(pObject->y+inheritY); + w=(px_int)pObject->Width; + h=(px_int)pObject->Height; + + + + px=(px_int)x+2; //increase line width + py=(px_int)y+2; + + if (pProcessBar->Value<0) + { + pProcessBar->Value=0; + } + if (pProcessBar->Value>pProcessBar->MAX) + { + pProcessBar->Value=pProcessBar->MAX; + } + + if (w<=4) + { + return; + } + if(pProcessBar->ValueMAX) + pl=(px_int)((w-4)*((pProcessBar->Value*1.0)/pProcessBar->MAX)); + else + pl=(px_int)w-2; + //Draw BackGround + PX_SurfaceClear( + psurface, + (px_int)x, + (px_int)y, + (px_int)x+w-1, + (px_int)y+h-1, + pProcessBar->BackgroundColor + ); + //Draw border + PX_GeoDrawBorder( + psurface, + x, + y, + x+w-1, + y+h-1, + 1, + pProcessBar->Color + ); + + PX_GeoDrawRect(psurface,px,py,px+pl-2-1,py+(px_int)h-4-1,pProcessBar->Color); + +} + +PX_Object * PX_Object_ProcessBarCreate(px_memorypool *mp,PX_Object *Parent,px_int x,px_int y,px_int Width,px_int Height ) +{ + PX_Object *pObject; + PX_Object_ProcessBar *ProcessBar=(PX_Object_ProcessBar *)MP_Malloc(mp,sizeof(PX_Object_ProcessBar)); + if (ProcessBar==PX_NULL) + { + return PX_NULL; + } + pObject=PX_ObjectCreate(mp,Parent,(px_float)x,(px_float)y,0,(px_float)Width,(px_float)Height,0); + if (pObject==PX_NULL) + { + MP_Free(pObject->mp,ProcessBar); + return PX_NULL; + } + + pObject->pObject=ProcessBar; + pObject->Enabled=PX_TRUE; + pObject->Visible=PX_TRUE; + pObject->Type=PX_OBJECT_TYPE_PROCESSBAR; + pObject->ReceiveEvents=PX_FALSE; + pObject->Func_ObjectFree=PX_NULL; + pObject->Func_ObjectRender=PX_Object_ProcessBarRender; + + ProcessBar->MAX=100; + ProcessBar->Value=0; + ProcessBar->Color=PX_OBJECT_UI_DEFAULT_FONTCOLOR; + ProcessBar->BackgroundColor= PX_OBJECT_UI_DEFAULT_BACKGROUNDCOLOR; + return pObject; +} + +px_void PX_Object_ProcessBarSetColor( PX_Object *pProcessBar,px_color Color) +{ + PX_Object_ProcessBar *pProcess=PX_Object_GetProcessBar(pProcessBar); + if (pProcess!=PX_NULL) + { + + pProcess->Color=Color; + } +} + +px_void PX_Object_ProcessBarSetBackgroundColor(PX_Object *pProcessBar,px_color Color) +{ + PX_Object_ProcessBar *pProcess=PX_Object_GetProcessBar(pProcessBar); + if (pProcess!=PX_NULL) + { + pProcess->BackgroundColor=Color; + } +} + +px_void PX_Object_ProcessBarSetValue( PX_Object *pProcessBar,px_int Value ) +{ + PX_Object_ProcessBar *pProcess=PX_Object_GetProcessBar(pProcessBar); + if (pProcess!=PX_NULL) + { + pProcess->Value=Value; + } +} + + +px_void PX_Object_ProcessBarSetMax( PX_Object *pProcessBar,px_int Max ) +{ + PX_Object_ProcessBar *pProcess=PX_Object_GetProcessBar(pProcessBar); + if (pProcess!=PX_NULL) + { + + pProcess->MAX=Max; + } +} + +px_int PX_Object_ProcessBarGetMax(PX_Object* pProcessBar) +{ + PX_Object_ProcessBar* pProcess = PX_Object_GetProcessBar(pProcessBar); + if (pProcess != PX_NULL) + { + + return pProcess->MAX; + } + PX_ASSERT(); + return 0; +} + +PX_Object_ProcessBar * PX_Object_GetProcessBar( PX_Object *Object ) +{ + if(Object->Type==PX_OBJECT_TYPE_PROCESSBAR) + return (PX_Object_ProcessBar *)Object->pObject; + else + return PX_NULL; +} + +px_int PX_Object_ProcessBarGetValue( PX_Object *pProcessBar ) +{ + if (pProcessBar->Type!=PX_OBJECT_TYPE_PROCESSBAR) + { + PX_ASSERT(); + return 0; + } + return PX_Object_GetProcessBar(pProcessBar)->Value; +} + diff --git a/lib/PainterEngine/kernel/PX_Object_Processbar.h b/lib/PainterEngine/kernel/PX_Object_Processbar.h new file mode 100644 index 0000000000000000000000000000000000000000..d2c8bcd4ac74b448d308e052e1d9318850d60557 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_Processbar.h @@ -0,0 +1,23 @@ +#ifndef PX_OBJECT_PROCESSBAR_H +#define PX_OBJECT_PROCESSBAR_H +#include "PX_Object.h" + +typedef struct +{ + px_int Value; + px_int MAX; + px_color Color; + px_color BackgroundColor; +}PX_Object_ProcessBar; + +PX_Object * PX_Object_ProcessBarCreate(px_memorypool *mp,PX_Object *Parent,px_int x,px_int y,px_int Width,px_int Height); +PX_Object_ProcessBar *PX_Object_GetProcessBar(PX_Object *Object); +px_void PX_Object_ProcessBarSetColor(PX_Object *pProcessBar,px_color Color); +px_void PX_Object_ProcessBarSetBackgroundColor(PX_Object *pProcessBar,px_color Color); +px_void PX_Object_ProcessBarSetValue(PX_Object *pProcessBar,px_int Value); +px_void PX_Object_ProcessBarSetMax(PX_Object *pProcessBar,px_int Max); +px_int PX_Object_ProcessBarGetMax(PX_Object* pProcessBar); +px_int PX_Object_ProcessBarGetValue(PX_Object* pProcessBar); + +#endif + diff --git a/lib/PainterEngine/kernel/PX_Object_Protractor.c b/lib/PainterEngine/kernel/PX_Object_Protractor.c new file mode 100644 index 0000000000000000000000000000000000000000..16723fb2fc7dba96e4dc7925da2abd10f47bb2f4 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_Protractor.c @@ -0,0 +1,173 @@ +#include "PX_Object_Protractor.h" + +PX_Object_Protractor * PX_Object_GetProtractor(PX_Object *Object) +{ + if (Object->Type==PX_OBJECT_TYPE_PROTRACTOR) + { + return (PX_Object_Protractor *)Object->pObject; + } + return PX_NULL; +} + +px_void PX_Object_ProtractorRender(px_surface *rendersurface,PX_Object *pObject,px_dword elapsed) +{ + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + PX_Object_Protractor *pProtractor=PX_Object_GetProtractor(pObject); + px_color acolor; + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + PX_GeoDrawCircle(rendersurface,(px_int)objx,(px_int)objy,(px_int)pProtractor->radius,1,pProtractor->color); + PX_GeoDrawSolidCircle(rendersurface,(px_int)objx,(px_int)objy,3,pProtractor->color); + + switch (pProtractor->state) + { + case PX_OBJECT_PROTRACTOR_STATE_STANDBY: + { + PX_GeoDrawLine(rendersurface,(px_int)objx,(px_int)objy,(px_int)(objx+PX_cos_angle(pProtractor->startAngle)*pProtractor->radius), + (px_int)(objy+PX_sin_angle(pProtractor->startAngle)*pProtractor->radius),1,pProtractor->color); + + PX_GeoDrawSolidCircle(rendersurface,(px_int)(objx+PX_cos_angle(pProtractor->startAngle)*pProtractor->radius), + (px_int)(objy+PX_sin_angle(pProtractor->startAngle)*pProtractor->radius),3 + ,pProtractor->color); + } + break; + case PX_OBJECT_PROTRACTOR_STATE_ADJUST: + case PX_OBJECT_PROTRACTOR_STATE_DONE: + { + px_char degree[32]; + acolor=pProtractor->color; + acolor._argb.a/=4; + + PX_GeoDrawSector(rendersurface,(px_int)objx,(px_int)objy,(px_int)pProtractor->radius,1,acolor,(px_int)pProtractor->startAngle,(px_int)pProtractor->endAngle); + + PX_GeoDrawLine(rendersurface,(px_int)objx,(px_int)objy,(px_int)(objx+PX_cos_angle(pProtractor->startAngle)*pProtractor->radius), + (px_int)(objy+PX_sin_angle(pProtractor->startAngle)*pProtractor->radius),1,pProtractor->color); + + PX_GeoDrawLine(rendersurface,(px_int)objx,(px_int)objy,(px_int)(objx+PX_cos_angle(pProtractor->endAngle)*pProtractor->radius), + (px_int)(objy+PX_sin_angle(pProtractor->endAngle)*pProtractor->radius),1,pProtractor->color); + + PX_GeoDrawSolidCircle(rendersurface,(px_int)(objx+PX_cos_angle(pProtractor->endAngle)*pProtractor->radius), + (px_int)(objy+PX_sin_angle(pProtractor->endAngle)*pProtractor->radius),5,pProtractor->color); + + PX_itoa((px_int)PX_Object_ProtractorGetAngle(pObject),degree,sizeof(degree),10); + PX_FontModuleDrawText(rendersurface,PX_NULL,(px_int)objx,(px_int)objy-2,PX_ALIGN_MIDBOTTOM,degree,pProtractor->fontColor); + } + break; + } + + + +} + +px_void PX_Object_ProtractorOnCursorDown(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY,x,y; + PX_Object_Protractor *pProtractor=PX_Object_GetProtractor(pObject); + x=PX_Object_Event_GetCursorX(e); + y=PX_Object_Event_GetCursorY(e); + + if (pProtractor->state==PX_OBJECT_PROTRACTOR_STATE_STANDBY) + { + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + pProtractor->endAngle=pProtractor->startAngle; + pProtractor->state=PX_OBJECT_PROTRACTOR_STATE_ADJUST; + } + else if (pProtractor->state==PX_OBJECT_PROTRACTOR_STATE_ADJUST) + { + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + pProtractor->state=PX_OBJECT_PROTRACTOR_STATE_DONE; + } + +} + +px_void PX_Object_ProtractorOnCursorMove(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY,x,y; + PX_Object_Protractor *pProtractor=PX_Object_GetProtractor(pObject); + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + x=PX_Object_Event_GetCursorX(e); + y=PX_Object_Event_GetCursorY(e); + + switch (pProtractor->state) + { + case PX_OBJECT_PROTRACTOR_STATE_STANDBY: + { + pProtractor->startAngle=(px_float)PX_RadianToAngle(PX_atan2(y-objy*1.0,x-objx*1.0)); + } + break; + case PX_OBJECT_PROTRACTOR_STATE_ADJUST: + { + px_float angle=(px_float)PX_RadianToAngle(PX_atan2(y-objy*1.0,x-objx*1.0)); + px_float lastAngleMod=pProtractor->endAngle; + px_float inc; + px_int round=(px_int)(lastAngleMod/360); + lastAngleMod=lastAngleMod-round*360; + + inc=angle-lastAngleMod; + if (inc>180) + { + inc-=360; + } + if (inc<-180) + { + inc+=360; + } + pProtractor->endAngle+=inc; + + } + break; + default: + break; + } + +} + +px_void PX_Object_ProtractorOnCursorRDown(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + PX_Object_Protractor *pProtractor=PX_Object_GetProtractor(pObject); + pProtractor->state=PX_OBJECT_PROTRACTOR_STATE_STANDBY; +} + +PX_Object * PX_Object_ProtractorCreate(px_memorypool *mp, PX_Object *Parent,px_int x,px_int y,px_int radius) +{ + PX_Object *pObject; + PX_Object_Protractor protractor; + PX_memset(&protractor,0,sizeof(protractor)); + protractor.color=PX_OBJECT_UI_DEFAULT_BORDERCOLOR; + protractor.fontColor=PX_COLOR(255,255,0,0); + protractor.radius=radius; + + pObject=PX_ObjectCreateEx(mp,Parent,(px_float)x,(px_float)y,0,0,0,0,PX_OBJECT_TYPE_PROTRACTOR,0,PX_Object_ProtractorRender,0,&protractor,sizeof(protractor)); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORDOWN,PX_Object_ProtractorOnCursorDown,PX_NULL); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORMOVE,PX_Object_ProtractorOnCursorMove,PX_NULL); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORRDOWN,PX_Object_ProtractorOnCursorRDown,PX_NULL); + return pObject; +} + +px_float PX_Object_ProtractorGetAngle(PX_Object *Object) +{ + return PX_Object_GetProtractor(Object)->endAngle-PX_Object_GetProtractor(Object)->startAngle; +} + diff --git a/lib/PainterEngine/kernel/PX_Object_Protractor.h b/lib/PainterEngine/kernel/PX_Object_Protractor.h new file mode 100644 index 0000000000000000000000000000000000000000..c61f3861c37c0b3c5966b297cc4c19e515897924 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_Protractor.h @@ -0,0 +1,27 @@ +#ifndef PX_OBJECT_PROTRACTOR_H +#define PX_OBJECT_PROTRACTOR_H +#include "PX_Object.h" + +typedef enum +{ + PX_OBJECT_PROTRACTOR_STATE_STANDBY=0, + PX_OBJECT_PROTRACTOR_STATE_ADJUST, + PX_OBJECT_PROTRACTOR_STATE_DONE +}PX_OBJECT_PROTRACTOR_STATE; + + +typedef struct +{ + px_int radius; + px_float startAngle; + px_float endAngle; + px_bool bselect; + px_color color,fontColor; + PX_OBJECT_PROTRACTOR_STATE state; +}PX_Object_Protractor; + +PX_Object_Protractor *PX_Object_GetProtractor(PX_Object *Object); +PX_Object * PX_Object_ProtractorCreate(px_memorypool *mp, PX_Object *Parent,px_int x,px_int y,px_int radius); +px_float PX_Object_ProtractorGetAngle(PX_Object *Object); + +#endif diff --git a/lib/PainterEngine/kernel/PX_Object_PushButton.c b/lib/PainterEngine/kernel/PX_Object_PushButton.c new file mode 100644 index 0000000000000000000000000000000000000000..fcd258313a4fbd8fa6683f2aa75e3cc2ce413bd0 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_PushButton.c @@ -0,0 +1,392 @@ +#include "PX_Object_PushButton.h" +px_void PX_Object_PushButtonOnMouseMove(PX_Object *Object,PX_Object_Event e,px_void *user_ptr) +{ + PX_Object_PushButton *pPushButton=PX_Object_GetPushButton(Object); + px_float x,y; + + x=PX_Object_Event_GetCursorX(e); + y=PX_Object_Event_GetCursorY(e); + + if (pPushButton) + { + if(PX_ObjectIsPointInRegion(Object,(px_float)x,(px_float)y)) + { + if (pPushButton->state!=PX_OBJECT_BUTTON_STATE_ONPUSH) + { + if (pPushButton->state!=PX_OBJECT_BUTTON_STATE_ONCURSOR) + { + PX_Object_Event e; + e.Event=PX_OBJECT_EVENT_CURSOROVER; + e.Param_uint[0]=0; + e.Param_uint[1]=0; + e.Param_uint[2]=0; + e.Param_uint[3]=0; + e.Param_ptr[0]=PX_NULL; + PX_ObjectExecuteEvent(Object,e); + } + pPushButton->state=PX_OBJECT_BUTTON_STATE_ONCURSOR; + } + } + else + { + if (pPushButton->state!=PX_OBJECT_BUTTON_STATE_NORMAL) + { + PX_Object_Event e; + e.Event=PX_OBJECT_EVENT_CURSOROUT; + e.Param_uint[0]=0; + e.Param_uint[1]=0; + e.Param_uint[2]=0; + e.Param_uint[3]=0; + PX_ObjectExecuteEvent(Object,e); + } + pPushButton->state=PX_OBJECT_BUTTON_STATE_NORMAL; + } + } +} + +px_void PX_Object_PushButtonOnMouseLButtonDown(PX_Object *Object,PX_Object_Event e,px_void *user_ptr) +{ + PX_Object_PushButton *pPushButton=PX_Object_GetPushButton(Object); + px_float x,y; + + x=PX_Object_Event_GetCursorX(e); + y=PX_Object_Event_GetCursorY(e); + + if (pPushButton) + { + if(PX_ObjectIsPointInRegion(Object,(px_float)x,(px_float)y)) + pPushButton->state=PX_OBJECT_BUTTON_STATE_ONPUSH; + else + { + if (pPushButton->state!=PX_OBJECT_BUTTON_STATE_NORMAL) + { + PX_Object_Event e; + e.Event=PX_OBJECT_EVENT_CURSOROUT; + e.Param_uint[0]=0; + e.Param_uint[1]=0; + e.Param_uint[2]=0; + e.Param_uint[3]=0; + PX_ObjectExecuteEvent(Object,e); + } + pPushButton->state=PX_OBJECT_BUTTON_STATE_NORMAL; + } + } +} + +px_void PX_Object_PushButtonOnMouseLButtonUp(PX_Object *Object,PX_Object_Event e,px_void *user_ptr) +{ + PX_Object_PushButton *pPushButton=PX_Object_GetPushButton(Object); + px_float x,y; + + x=PX_Object_Event_GetCursorX(e); + y=PX_Object_Event_GetCursorY(e); + + if (pPushButton) + { + if(PX_ObjectIsPointInRegion(Object,(px_float)x,(px_float)y)) + if(pPushButton->state==PX_OBJECT_BUTTON_STATE_ONPUSH) + { + pPushButton->state=PX_OBJECT_BUTTON_STATE_ONCURSOR; + e.Event=PX_OBJECT_EVENT_EXECUTE; + PX_ObjectExecuteEvent(Object,e); + } + } +} + +PX_Object * PX_Object_PushButtonCreate(px_memorypool *mp,PX_Object *Parent,px_int x,px_int y,px_int Width,px_int Height,const px_char *Text,PX_FontModule *fontmodule) +{ + px_int TextLen; + PX_Object *pObject; + PX_Object_PushButton *pPushButton=(PX_Object_PushButton *)MP_Malloc(mp,sizeof(PX_Object_PushButton)); + if (pPushButton==PX_NULL) + { + return PX_NULL; + } + pObject=PX_ObjectCreate(mp,Parent,(px_float)x,(px_float)y,0,(px_float)Width,(px_float)Height,0); + if (!pObject) + { + MP_Free(mp,pPushButton); + return PX_NULL; + } + pObject->pObject=pPushButton; + pObject->Type=PX_OBJECT_TYPE_PUSHBUTTON; + pObject->ReceiveEvents=PX_TRUE; + pObject->Func_ObjectFree=PX_Object_PushButtonFree; + pObject->Func_ObjectRender=PX_Object_PushButtonRender; + + TextLen=PX_strlen(Text)+1; + + pPushButton->Text=(px_char *)MP_Malloc(mp,TextLen); + + if (pPushButton->Text==PX_NULL) + { + MP_Free(pObject->mp,pObject); + MP_Free(pObject->mp,pPushButton); + return PX_NULL; + } + + PX_strcpy(pPushButton->Text,Text,TextLen); + + pPushButton->TextColor=PX_OBJECT_UI_DEFAULT_FONTCOLOR; + pPushButton->CursorColor=PX_OBJECT_UI_DEFAULT_CURSORCOLOR; + pPushButton->PushColor=PX_OBJECT_UI_DEFAULT_PUSHCOLOR; + pPushButton->BackgroundColor=PX_OBJECT_UI_DEFAULT_BACKGROUNDCOLOR; + pPushButton->BorderColor=PX_OBJECT_UI_DEFAULT_BORDERCOLOR; + pPushButton->Border=PX_TRUE; + pPushButton->state=PX_OBJECT_BUTTON_STATE_NORMAL; + pPushButton->Border=PX_TRUE; + pPushButton->style=PX_OBJECT_PUSHBUTTON_STYLE_RECT; + pPushButton->roundradius=PX_OBJECT_PUSHBUTTON_ROUNDRADIUS; + pPushButton->shape=PX_NULL; + pPushButton->Texture=PX_NULL; + pPushButton->fontModule=fontmodule; + + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORMOVE,PX_Object_PushButtonOnMouseMove,PX_NULL); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORDRAG,PX_Object_PushButtonOnMouseMove,PX_NULL); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORDOWN,PX_Object_PushButtonOnMouseLButtonDown,PX_NULL); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORUP,PX_Object_PushButtonOnMouseLButtonUp,PX_NULL); + + return pObject; +} + +PX_Object_PushButton * PX_Object_GetPushButton( PX_Object *Object ) +{ + if(Object->Type==PX_OBJECT_TYPE_PUSHBUTTON) + return (PX_Object_PushButton *)Object->pObject; + else + return PX_NULL; +} + +px_char * PX_Object_PushButtonGetText( PX_Object *PushButton ) +{ + PX_Object_PushButton *pPushButton=PX_Object_GetPushButton(PushButton); + if (pPushButton!=PX_NULL) + { + return pPushButton->Text; + } + return PX_NULL; +} + +px_void PX_Object_PushButtonSetText( PX_Object *pObject,const px_char *Text ) +{ + PX_Object_PushButton *pPushButton; + px_int TextLen; + if (pObject==PX_NULL||Text==PX_NULL) + { + return; + } + if (pObject->Type!=PX_OBJECT_TYPE_PUSHBUTTON) + { + return; + } + + TextLen=PX_strlen(Text); + pPushButton=(PX_Object_PushButton *)pObject->pObject; + + if (TextLen>PX_strlen(pPushButton->Text)) + { + MP_Free(pObject->mp,pPushButton->Text); + + pPushButton->Text=(px_char *)MP_Malloc(pObject->mp,TextLen+1); + if (!pPushButton->Text) + { + return; + } + } + PX_strcpy(pPushButton->Text,Text,TextLen+1); + +} + + +px_void PX_Object_PushButtonSetBackgroundColor( PX_Object *pObject,px_color Color ) +{ + PX_Object_PushButton * pPushButton=PX_Object_GetPushButton(pObject); + if (pPushButton) + { + pPushButton->BackgroundColor=Color; + } +} + +px_void PX_Object_PushButtonSetTextColor( PX_Object *pObject,px_color Color ) +{ + PX_Object_PushButton * pPushButton=PX_Object_GetPushButton(pObject); + if (pPushButton) + { + + pPushButton->TextColor=Color; + } +} + +px_void PX_Object_PushButtonSetTexture(PX_Object *pObject,px_texture *texture) +{ + PX_Object_PushButton * pPushButton=PX_Object_GetPushButton(pObject); + if (pPushButton) + { + pPushButton->Texture=texture; + } +} + +px_void PX_Object_PushButtonSetShape(PX_Object *pObject,px_shape *pshape) +{ + PX_Object_PushButton * pPushButton=PX_Object_GetPushButton(pObject); + if (pPushButton) + { + pPushButton->shape=pshape; + } +} + +px_void PX_Object_PushButtonSetBorderColor( PX_Object *pObject,px_color Color ) +{ + PX_Object_PushButton * pPushButton=PX_Object_GetPushButton(pObject); + if (pPushButton) + { + + pPushButton->BorderColor=Color; + } +} + +px_void PX_Object_PushButtonSetCursorColor(PX_Object *pObject,px_color Color) +{ + PX_Object_PushButton * pPushButton=PX_Object_GetPushButton(pObject); + if (pPushButton) + { + + pPushButton->CursorColor=Color; + } +} + +px_void PX_Object_PushButtonSetStyle(PX_Object *pObject,PX_OBJECT_PUSHBUTTON_STYLE style) +{ + PX_Object_PushButton * pPushButton=PX_Object_GetPushButton(pObject); + if (pPushButton) + { + pPushButton->style=style; + } +} + +px_void PX_Object_PushButtonSetPushColor(PX_Object *pObject,px_color Color) +{ + PX_Object_PushButton * pPushButton=PX_Object_GetPushButton(pObject); + if (pPushButton) + { + + pPushButton->PushColor=Color; + } +} + +px_void PX_Object_PushButtonSetBorder( PX_Object *Object,px_bool Border ) +{ + PX_Object_PushButton *PushButton=PX_Object_GetPushButton(Object); + if (PushButton) + { + + PushButton->Border=Border; + } +} + +px_void PX_Object_PushButtonRender(px_surface *psurface, PX_Object *pObject,px_uint elapsed) +{ + px_int fx,fy; + PX_Object_PushButton *pPushButton=PX_Object_GetPushButton(pObject); + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + if (pPushButton==PX_NULL) + { + return; + } + + if (!pObject->Visible) + { + return; + } + + if (!pObject->Enabled) + { + pPushButton->state=PX_OBJECT_BUTTON_STATE_NORMAL; + } + + switch(pPushButton->style) + { + case PX_OBJECT_PUSHBUTTON_STYLE_RECT: + PX_GeoDrawRect(psurface,(px_int)objx,(px_int)objy,(px_int)objx+(px_int)objWidth-1,(px_int)objy+(px_int)objHeight-1,pPushButton->BackgroundColor); + switch (pPushButton->state) + { + case PX_OBJECT_BUTTON_STATE_NORMAL: + PX_GeoDrawRect(psurface,(px_int)objx,(px_int)objy,(px_int)objx+(px_int)objWidth-1,(px_int)objy+(px_int)objHeight-1,pPushButton->BackgroundColor); + break; + case PX_OBJECT_BUTTON_STATE_ONPUSH: + PX_GeoDrawRect(psurface,(px_int)objx,(px_int)objy,(px_int)objx+(px_int)objWidth-1,(px_int)objy+(px_int)objHeight-1,pPushButton->PushColor); + break; + case PX_OBJECT_BUTTON_STATE_ONCURSOR: + PX_GeoDrawRect(psurface,(px_int)objx,(px_int)objy,(px_int)objx+(px_int)objWidth-1,(px_int)objy+(px_int)objHeight-1,pPushButton->CursorColor); + break; + } + break; + case PX_OBJECT_PUSHBUTTON_STYLE_ROUNDRECT: + PX_GeoDrawSolidRoundRect(psurface,(px_int)objx,(px_int)objy,(px_int)objx+(px_int)objWidth-1,(px_int)objy+(px_int)objHeight-1,pPushButton->roundradius,pPushButton->BackgroundColor); + switch (pPushButton->state) + { + case PX_OBJECT_BUTTON_STATE_NORMAL: + PX_GeoDrawSolidRoundRect(psurface,(px_int)objx,(px_int)objy,(px_int)objx+(px_int)objWidth-1,(px_int)objy+(px_int)objHeight-1,pPushButton->roundradius,pPushButton->BackgroundColor); + break; + case PX_OBJECT_BUTTON_STATE_ONPUSH: + PX_GeoDrawSolidRoundRect(psurface,(px_int)objx,(px_int)objy,(px_int)objx+(px_int)objWidth-1,(px_int)objy+(px_int)objHeight-1,pPushButton->roundradius,pPushButton->PushColor); + break; + case PX_OBJECT_BUTTON_STATE_ONCURSOR: + PX_GeoDrawSolidRoundRect(psurface,(px_int)objx,(px_int)objy,(px_int)objx+(px_int)objWidth-1,(px_int)objy+(px_int)objHeight-1,pPushButton->roundradius,pPushButton->CursorColor); + break; + } + break; + } + + + + + if (pPushButton->Texture) + { + PX_TextureRender(psurface,pPushButton->Texture,(px_int)objx+(px_int)objWidth/2,(px_int)objy+(px_int)objHeight/2,PX_ALIGN_CENTER,PX_NULL); + } + else if (pPushButton->shape) + { + PX_ShapeRender(psurface,pPushButton->shape,(px_int)objx+(px_int)objWidth/2,(px_int)objy+(px_int)objHeight/2,PX_ALIGN_CENTER,pPushButton->TextColor); + } + + if (pPushButton->Border) + { + switch(pPushButton->style) + { + case PX_OBJECT_PUSHBUTTON_STYLE_RECT: + PX_GeoDrawBorder(psurface,(px_int)objx,(px_int)objy,(px_int)objx+(px_int)objWidth-1,(px_int)objy+(px_int)objHeight-1,1,pPushButton->BorderColor); + break; + case PX_OBJECT_PUSHBUTTON_STYLE_ROUNDRECT: + PX_GeoDrawRoundRect(psurface,(px_int)objx,(px_int)objy,(px_int)objx+(px_int)objWidth-1,(px_int)objy+(px_int)objHeight-1,pPushButton->roundradius,0.6f,pPushButton->BorderColor); + break; + } + } + + fx=(px_int)(objx+objWidth/2); + fy=(px_int)(objy+objHeight/2); + + PX_FontModuleDrawText(psurface,pPushButton->fontModule,fx,fy,PX_ALIGN_CENTER,pPushButton->Text,pPushButton->TextColor); + + + +} + +px_void PX_Object_PushButtonFree( PX_Object *Obj ) +{ + PX_Object_PushButton *PushButton=PX_Object_GetPushButton(Obj); + if (Obj!=PX_NULL) + { + MP_Free(Obj->mp,PushButton->Text); + } +} + diff --git a/lib/PainterEngine/kernel/PX_Object_PushButton.h b/lib/PainterEngine/kernel/PX_Object_PushButton.h new file mode 100644 index 0000000000000000000000000000000000000000..764b15be884f32d4739897690c6a9d95f21da6e6 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_PushButton.h @@ -0,0 +1,57 @@ +#ifndef PX_OBJECT_PUSHBUTTON_H +#define PX_OBJECT_PUSHBUTTON_H +#include "PX_Object.h" + + +#define PX_OBJECT_PUSHBUTTON_ROUNDRADIUS 8.0f +typedef enum +{ + PX_OBJECT_BUTTON_STATE_ONCURSOR, + PX_OBJECT_BUTTON_STATE_ONPUSH, + PX_OBJECT_BUTTON_STATE_NORMAL, +}PX_Object_PUSHBUTTON_STATE; + + +typedef enum +{ + PX_OBJECT_PUSHBUTTON_STYLE_RECT, + PX_OBJECT_PUSHBUTTON_STYLE_ROUNDRECT, +}PX_OBJECT_PUSHBUTTON_STYLE; + +typedef struct +{ + px_bool Border; + px_color TextColor; + px_color BorderColor; + px_color BackgroundColor; + px_color CursorColor; + px_color PushColor; + px_char *Text; + PX_FontModule *fontModule; + px_texture *Texture; + px_shape *shape; + px_float roundradius; + PX_OBJECT_PUSHBUTTON_STYLE style; + PX_Object_PUSHBUTTON_STATE state; +}PX_Object_PushButton; + +PX_Object *PX_Object_PushButtonCreate(px_memorypool *mp,PX_Object *Parent,px_int x,px_int y,px_int Width,px_int Height,const px_char *Text,PX_FontModule *fontmodule); +PX_Object_PushButton * PX_Object_GetPushButton( PX_Object *Object ); +px_char * PX_Object_PushButtonGetText( PX_Object *PushButton ); +px_void PX_Object_PushButtonSetText( PX_Object *pObject,const px_char *Text ); +px_void PX_Object_PushButtonSetBackgroundColor( PX_Object *pObject,px_color Color ); +px_void PX_Object_PushButtonSetCursorColor( PX_Object *pObject,px_color Color ); +px_void PX_Object_PushButtonSetStyle(PX_Object *pObject,PX_OBJECT_PUSHBUTTON_STYLE style); +px_void PX_Object_PushButtonSetPushColor( PX_Object *pObject,px_color Color ); +px_void PX_Object_PushButtonSetBorderColor( PX_Object *pObject,px_color Color ); +px_void PX_Object_PushButtonSetBorder( PX_Object *Object,px_bool Border ); +px_void PX_Object_PushButtonRender(px_surface *psurface, PX_Object *pObject,px_uint elapsed); +px_void PX_Object_PushButtonSetTextColor( PX_Object *pObject,px_color Color ); +px_void PX_Object_PushButtonSetTexture(PX_Object *pObject,px_texture *texture); +px_void PX_Object_PushButtonSetShape(PX_Object *pObject,px_shape *pshape); +px_void PX_Object_PushButtonFree( PX_Object *Obj ); + + + +#endif + diff --git a/lib/PainterEngine/kernel/PX_Object_RadioBox.c b/lib/PainterEngine/kernel/PX_Object_RadioBox.c new file mode 100644 index 0000000000000000000000000000000000000000..a4cce3a3940422c6318e2b4436ed2103b4ddac3b --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_RadioBox.c @@ -0,0 +1,274 @@ +#include "PX_Object_RadioBox.h" +////////////////////////////////////////////////////////////////////////// + +PX_Object_RadioBox * PX_Object_GetRadioBox(PX_Object *Object) +{ + PX_Object_RadioBox *pcb=(PX_Object_RadioBox *)Object->pObject; + if (Object->Type==PX_OBJECT_TYPE_RADIOBOX) + { + return pcb; + } + return PX_NULL; +} + + +px_void PX_Object_RadioBoxOnMouseMove(PX_Object *Object,PX_Object_Event e,px_void *user_ptr) +{ + PX_Object_RadioBox *pcb=PX_Object_GetRadioBox(Object); + + px_float x=(PX_Object_Event_GetCursorX(e)); + px_float y=(PX_Object_Event_GetCursorY(e)); + + if (pcb) + { + if(PX_ObjectIsPointInRegion(Object,(px_float)x,(px_float)y)) + { + if (pcb->state!=PX_OBJECT_BUTTON_STATE_ONPUSH) + { + if (pcb->state!=PX_OBJECT_BUTTON_STATE_ONCURSOR) + { + PX_Object_Event e; + e.Event=PX_OBJECT_EVENT_CURSOROVER; + e.Param_uint[0]=0; + e.Param_uint[1]=0; + e.Param_uint[2]=0; + e.Param_uint[3]=0; + e.Param_ptr[0]=PX_NULL; + PX_ObjectExecuteEvent(Object,e); + } + pcb->state=PX_OBJECT_RADIOBOX_STATE_ONCURSOR; + } + } + else + { + if (pcb->state!=PX_OBJECT_BUTTON_STATE_NORMAL) + { + PX_Object_Event e; + e.Event=PX_OBJECT_EVENT_CURSOROUT; + e.Param_uint[0]=0; + e.Param_uint[1]=0; + e.Param_uint[2]=0; + e.Param_uint[3]=0; + PX_ObjectExecuteEvent(Object,e); + } + pcb->state=PX_OBJECT_RADIOBOX_STATE_NORMAL; + } + } +} + +px_void PX_Object_RadioBoxClearOtherCheck(PX_Object *Object) +{ + PX_Object *pObject=Object->pPreBrother; + while (pObject) + { + if (PX_Object_GetRadioBox(pObject)) + { + PX_Object_GetRadioBox(pObject)->bCheck=PX_FALSE; + } + pObject=pObject->pPreBrother; + } + + pObject=Object->pNextBrother; + while (pObject) + { + if (PX_Object_GetRadioBox(pObject)) + { + PX_Object_GetRadioBox(pObject)->bCheck=PX_FALSE; + } + pObject=pObject->pNextBrother; + } +} +px_void PX_Object_RadioBoxOnMouseLButtonDown(PX_Object *Object,PX_Object_Event e,px_void *user_ptr) +{ + PX_Object_RadioBox *pcb=PX_Object_GetRadioBox(Object); + px_float x=(PX_Object_Event_GetCursorX(e)); + px_float y=(PX_Object_Event_GetCursorY(e)); + + if (pcb) + { + if(PX_ObjectIsPointInRegion(Object,(px_float)x,(px_float)y)) + { + pcb->state=PX_OBJECT_RADIOBOX_STATE_ONPUSH; + PX_Object_RadioBoxClearOtherCheck(Object); + pcb->bCheck=PX_TRUE; + e.Event=PX_OBJECT_EVENT_VALUECHANGED; + e.Param_uint[0]=0; + e.Param_uint[1]=0; + e.Param_uint[2]=0; + e.Param_uint[3]=0; + PX_ObjectExecuteEvent(Object,e); + } + else + { + if (pcb->state!=PX_OBJECT_BUTTON_STATE_NORMAL) + { + PX_Object_Event e; + e.Event=PX_OBJECT_EVENT_CURSOROUT; + e.Param_uint[0]=0; + e.Param_uint[1]=0; + e.Param_uint[2]=0; + e.Param_uint[3]=0; + PX_ObjectExecuteEvent(Object,e); + } + pcb->state=PX_OBJECT_RADIOBOX_STATE_NORMAL; + } + } +} + +px_void PX_Object_RadioBoxOnMouseLButtonUp(PX_Object *Object,PX_Object_Event e,px_void *user_ptr) +{ + PX_Object_RadioBox *pcb=PX_Object_GetRadioBox(Object); + + px_float x,y; + + x=PX_Object_Event_GetCursorX(e); + y=PX_Object_Event_GetCursorY(e); + + if (pcb) + { + if(PX_ObjectIsPointInRegion(Object,(px_float)x,(px_float)y)) + if(pcb->state==PX_OBJECT_RADIOBOX_STATE_ONPUSH) + { + pcb->state=PX_OBJECT_RADIOBOX_STATE_ONCURSOR; + } + } +} + +px_void PX_Object_RadioBoxRender(px_surface *psurface, PX_Object *pObject,px_uint elapsed) +{ + + PX_Object_RadioBox *pcb=PX_Object_GetRadioBox(pObject); + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + + if (pcb==PX_NULL) + { + return; + } + + if (!pObject->Visible) + { + return; + } + + PX_GeoDrawRect(psurface,(px_int)objx,(px_int)objy,(px_int)objx+(px_int)objWidth-1,(px_int)objy+(px_int)objHeight-1,pcb->BackgroundColor); + switch (pcb->state) + { + case PX_OBJECT_BUTTON_STATE_NORMAL: + PX_GeoDrawRect(psurface,(px_int)objx,(px_int)objy,(px_int)objx+(px_int)objWidth-1,(px_int)objy+(px_int)objHeight-1,pcb->BackgroundColor); + break; + case PX_OBJECT_BUTTON_STATE_ONPUSH: + PX_GeoDrawRect(psurface,(px_int)objx,(px_int)objy,(px_int)objx+(px_int)objWidth-1,(px_int)objy+(px_int)objHeight-1,pcb->PushColor); + break; + case PX_OBJECT_BUTTON_STATE_ONCURSOR: + PX_GeoDrawRect(psurface,(px_int)objx,(px_int)objy,(px_int)objx+(px_int)objWidth-1,(px_int)objy+(px_int)objHeight-1,pcb->CursorColor); + break; + } + + if (pcb->Border) + { + PX_GeoDrawBorder(psurface,(px_int)objx,(px_int)objy,(px_int)objx+(px_int)objWidth-1,(px_int)objy+(px_int)objHeight-1,1,pcb->BorderColor); + } + + PX_FontModuleDrawText(psurface,pcb->fm,(px_int)objx+20,(px_int)(objy+objHeight/2),PX_ALIGN_LEFTMID,pcb->Text,pcb->TextColor); + + //draw RadioState + PX_GeoDrawCircle(psurface,(px_int)objx+8,(px_int)(objy+objHeight/2),7,1,pcb->BorderColor); + + if (pcb->bCheck) + { + PX_GeoDrawSolidCircle(psurface,(px_int)objx+8,(px_int)(objy+objHeight/2),5,pcb->BorderColor); + } + +} + +PX_Object * PX_Object_RadioBoxCreate(px_memorypool *mp, PX_Object *Parent,px_int x,px_int y,px_int Width,px_int Height,const char text[],PX_FontModule *fm) +{ + PX_Object *pObject; + PX_Object_RadioBox cbx; + cbx.Align=PX_ALIGN_LEFTMID; + cbx.BackgroundColor=PX_COLOR(0,0,0,0); + cbx.bCheck=PX_FALSE; + cbx.Border=PX_FALSE; + cbx.BorderColor=PX_OBJECT_UI_DEFAULT_FONTCOLOR; + cbx.CursorColor=PX_COLOR(0,0,0,0); + cbx.PushColor=PX_COLOR(0,0,0,0); + cbx.fm=fm; + cbx.state=PX_OBJECT_RADIOBOX_STATE_NORMAL; + PX_strset(cbx.Text,text); + cbx.TextColor= PX_OBJECT_UI_DEFAULT_FONTCOLOR; + pObject=PX_ObjectCreateEx(mp,Parent,(px_float)x,(px_float)y,0,(px_float)Width,(px_float)Height,0,PX_OBJECT_TYPE_RADIOBOX,PX_NULL,PX_Object_RadioBoxRender,PX_NULL,&cbx,sizeof(cbx)); + if (!pObject) + { + return PX_NULL; + } + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORMOVE,PX_Object_RadioBoxOnMouseMove,PX_NULL); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORDOWN,PX_Object_RadioBoxOnMouseLButtonDown,PX_NULL); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORUP,PX_Object_RadioBoxOnMouseLButtonUp,PX_NULL); + return pObject; +} + +px_bool PX_Object_RadioBoxGetCheck(PX_Object *Object) +{ + return PX_Object_GetRadioBox(Object)->bCheck; +} + +px_void PX_Object_RadioBoxSetBackgroundColor(PX_Object *Object,px_color clr) +{ + PX_Object_GetRadioBox(Object)->BackgroundColor=clr; +} + +px_void PX_Object_RadioBoxSetBorderColor(PX_Object *Object,px_color clr) +{ + PX_Object_GetRadioBox(Object)->BorderColor=clr; +} + +px_void PX_Object_RadioBoxSetPushColor(PX_Object *Object,px_color clr) +{ + PX_Object_GetRadioBox(Object)->PushColor=clr; +} + +px_void PX_Object_RadioBoxSetCursorColor(PX_Object *Object,px_color clr) +{ + PX_Object_GetRadioBox(Object)->CursorColor=clr; +} + +px_void PX_Object_RadioBoxSetText(PX_Object *Object,const px_char text[]) +{ + PX_strset(PX_Object_GetRadioBox(Object)->Text,text); +} + +const px_char *PX_Object_RadioBoxGetText(PX_Object *Object) +{ + PX_Object_RadioBox *pDesc=PX_Object_GetRadioBox(Object); + if (pDesc) + { + return pDesc->Text; + } + PX_ASSERT(); + return PX_NULL; +} + +px_void PX_Object_RadioBoxSetTextColor(PX_Object *Object,px_color clr) +{ + PX_Object_RadioBox *pDesc=PX_Object_GetRadioBox(Object); + if (pDesc) + { + pDesc->TextColor=clr; + } + else + PX_ASSERT(); +} + +px_void PX_Object_RadioBoxSetCheck(PX_Object *Object,px_bool check) +{ + PX_Object_GetRadioBox(Object)->bCheck=check; +} \ No newline at end of file diff --git a/lib/PainterEngine/kernel/PX_Object_RadioBox.h b/lib/PainterEngine/kernel/PX_Object_RadioBox.h new file mode 100644 index 0000000000000000000000000000000000000000..97bb806fe1b275f96086b9ae5c9dabbb838767d5 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_RadioBox.h @@ -0,0 +1,41 @@ +#ifndef PX_OBJECT_RADIOBOX_H +#define PX_OBJECT_RADIOBOX_H +#include "PX_Object.h" +typedef enum +{ + PX_OBJECT_RADIOBOX_STATE_ONCURSOR, + PX_OBJECT_RADIOBOX_STATE_ONPUSH, + PX_OBJECT_RADIOBOX_STATE_NORMAL, +}PX_Object_RADIOBOX_STATE; +#define PX_OBJECT_RADIOBOX_MAX_CONTENT 64 +typedef struct +{ + PX_ALIGN Align; + px_bool Border; + px_color TextColor; + px_color BorderColor; + px_color BackgroundColor; + px_color CursorColor; + px_color PushColor; + px_char Text[PX_OBJECT_RADIOBOX_MAX_CONTENT]; + px_bool bCheck; + PX_FontModule *fm; + PX_Object_RADIOBOX_STATE state; +}PX_Object_RadioBox; + +PX_Object_RadioBox *PX_Object_GetRadioBox(PX_Object *Object); +PX_Object * PX_Object_RadioBoxCreate(px_memorypool *mp, PX_Object *Parent,px_int x,px_int y,px_int Width,px_int Height,const char text[],PX_FontModule *fm); +px_bool PX_Object_RadioBoxGetCheck(PX_Object *Object); +px_void PX_Object_RadioBoxSetBackgroundColor(PX_Object *Object,px_color clr); +px_void PX_Object_RadioBoxSetBorderColor(PX_Object *Object,px_color clr); +px_void PX_Object_RadioBoxSetPushColor(PX_Object *Object,px_color clr); +px_void PX_Object_RadioBoxSetCursorColor(PX_Object *Object,px_color clr); +px_void PX_Object_RadioBoxSetText(PX_Object *Object,const px_char text[]); +const px_char *PX_Object_RadioBoxGetText(PX_Object *Object); +px_void PX_Object_RadioBoxSetTextColor(PX_Object *Object,px_color clr); +px_void PX_Object_RadioBoxSetCheck(PX_Object *Object,px_bool check); + + + +#endif + diff --git a/lib/PainterEngine/kernel/PX_Object_RingProcessbar.c b/lib/PainterEngine/kernel/PX_Object_RingProcessbar.c new file mode 100644 index 0000000000000000000000000000000000000000..6eb2f8428418f9298878b5777467d48bc511baf2 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_RingProcessbar.c @@ -0,0 +1,119 @@ +#include "PX_Object_RingProcessbar.h" + + +px_void PX_Object_RingProcessBarRender(px_surface *psurface, PX_Object *pObject,px_uint elapsed) +{ + px_int x,y,r; + px_char content[8]={0}; + px_float process; + px_float inheritX,inheritY; + + PX_Object_RingProcessBar *pDesc=(PX_Object_RingProcessBar *)pObject->pObject; + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + x=(px_int)(pObject->x+inheritX); + y=(px_int)(pObject->y+inheritY); + r=(px_int)pObject->diameter/2; + + process=(pDesc->Value-pDesc->Min)*1.0f/(pDesc->Max-pDesc->Min); + + if (process<0) + { + process=0; + } + if (process>1) + { + process=1; + } + + PX_sprintf1(content,sizeof(content),"%1.2%",PX_STRINGFORMAT_FLOAT(process*100)); + PX_GeoDrawCircle(psurface,x,y,r,pDesc->linewidth+6,pDesc->BackgroundColor); + PX_GeoDrawRing(psurface,x,y,r,pDesc->linewidth,pDesc->Color,-90,-90+(px_int)(360*process)); + PX_FontModuleDrawText(psurface,pDesc->fm,x,y,PX_ALIGN_CENTER,content,pDesc->Color); + +} + +PX_Object * PX_Object_RingProcessBarCreate(px_memorypool *mp,PX_Object *Parent,px_int x,px_int y,px_int r,PX_FontModule *fm) +{ + PX_Object *pObject; + PX_Object_RingProcessBar Desc; + Desc.BackgroundColor=PX_OBJECT_UI_DEFAULT_PUSHCOLOR; + Desc.Color=PX_OBJECT_UI_DEFAULT_FONTCOLOR; + Desc.linewidth=12; + Desc.Max=100; + Desc.Min=0; + Desc.Value=32; + Desc.fm=fm; + pObject=PX_ObjectCreateEx(mp,Parent,(px_float)x,(px_float)y,0,(px_float)0,(px_float)0,0,PX_OBJECT_TYPE_RINGPROCESSBAR,PX_NULL,PX_Object_RingProcessBarRender,PX_NULL,&Desc,sizeof(PX_Object_RingProcessBar)); + pObject->diameter=r*2.0f; + return pObject; +} + +px_void PX_Object_RingProcessBarSetColor( PX_Object *pRingProcessBar,px_color Color) +{ + PX_Object_RingProcessBar *pProcess=PX_Object_GetRingProcessBar(pRingProcessBar); + if (pProcess!=PX_NULL) + { + + pProcess->Color=Color; + } +} + +px_void PX_Object_RingProcessBarSetBackgroundColor(PX_Object *pRingProcessBar,px_color Color) +{ + PX_Object_RingProcessBar *pProcess=PX_Object_GetRingProcessBar(pRingProcessBar); + if (pProcess!=PX_NULL) + { + pProcess->BackgroundColor=Color; + } +} + +px_void PX_Object_RingProcessBarSetValue( PX_Object *pRingProcessBar,px_int Value ) +{ + PX_Object_RingProcessBar *pProcess=PX_Object_GetRingProcessBar(pRingProcessBar); + if (pProcess!=PX_NULL) + { + pProcess->Value=Value; + } +} + + +px_void PX_Object_RingProcessBarSetMax( PX_Object *pRingProcessBar,px_int Max ) +{ + PX_Object_RingProcessBar *pProcess=PX_Object_GetRingProcessBar(pRingProcessBar); + if (pProcess!=PX_NULL) + { + pProcess->Max=Max; + } +} + +px_int PX_Object_RingProcessBarGetMax(PX_Object* pRingProcessBar) +{ + PX_Object_RingProcessBar* pProcess = PX_Object_GetRingProcessBar(pRingProcessBar); + if (pProcess != PX_NULL) + { + + return pProcess->Max; + } + PX_ASSERT(); + return 0; +} + +PX_Object_RingProcessBar * PX_Object_GetRingProcessBar( PX_Object *Object ) +{ + if(Object->Type==PX_OBJECT_TYPE_RINGPROCESSBAR) + return (PX_Object_RingProcessBar *)Object->pObject; + else + return PX_NULL; +} + +px_int PX_Object_RingProcessBarGetValue( PX_Object *pRingProcessBar ) +{ + if (pRingProcessBar->Type!=PX_OBJECT_TYPE_RINGPROCESSBAR) + { + PX_ASSERT(); + return 0; + } + return PX_Object_GetRingProcessBar(pRingProcessBar)->Value; +} + diff --git a/lib/PainterEngine/kernel/PX_Object_RingProcessbar.h b/lib/PainterEngine/kernel/PX_Object_RingProcessbar.h new file mode 100644 index 0000000000000000000000000000000000000000..8ceaae6413511d5762120e0669ae7994d853756b --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_RingProcessbar.h @@ -0,0 +1,27 @@ +#ifndef PX_OBJECT_RINGPROCESSBAR_H +#define PX_OBJECT_RINGPROCESSBAR_H +#include "PX_Object.h" + +typedef struct +{ + px_int Value; + px_int Min; + px_int Max; + px_int linewidth; + px_color Color; + px_color BackgroundColor; + PX_FontModule *fm; +}PX_Object_RingProcessBar; + +PX_Object * PX_Object_RingProcessBarCreate(px_memorypool *mp,PX_Object *Parent,px_int x,px_int y,px_int r,PX_FontModule *fm); +PX_Object_RingProcessBar *PX_Object_GetRingProcessBar(PX_Object *Object); +px_void PX_Object_RingProcessBarSetColor(PX_Object *pRingProcessBar,px_color Color); +px_void PX_Object_RingProcessBarSetBackgroundColor(PX_Object *pRingProcessBar,px_color Color); +px_void PX_Object_RingProcessBarSetValue(PX_Object *pRingProcessBar,px_int Value); +px_void PX_Object_RingProcessBarSetMax(PX_Object *pRingProcessBar,px_int Max); +px_int PX_Object_RingProcessBarGetMax(PX_Object* pRingProcessBar); +px_int PX_Object_RingProcessBarGetValue(PX_Object* pRingProcessBar); + + +#endif + diff --git a/lib/PainterEngine/kernel/PX_Object_ScaleBox.c b/lib/PainterEngine/kernel/PX_Object_ScaleBox.c new file mode 100644 index 0000000000000000000000000000000000000000..e75fa32151308ae10d9eb6c34f6c6bc30d97d7d9 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_ScaleBox.c @@ -0,0 +1,385 @@ +#include "PX_Object_ScaleBox.h" + + +px_void PX_Object_ScaleBoxRender(px_surface *psurface, PX_Object *pObject,px_uint elapsed) +{ + + PX_Object_ScaleBox * pScaleBox=PX_Object_GetScaleBox(pObject); + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + switch (pScaleBox->editpt_count) + { + case 0: + default: + return; + case 1: + PX_GeoDrawLine(psurface,(px_int)(objx+pScaleBox->edit_pt[0].x),(px_int)(objx+pScaleBox->edit_pt[0].y),\ + (px_int)(objx+pScaleBox->cursor_pt.x),(px_int)(objx+pScaleBox->cursor_pt.y), + 1, + (pScaleBox->linecolor) + ); + PX_GeoDrawSolidCircle(psurface,(px_int)(objx+pScaleBox->edit_pt[0].x),(px_int)(objx+pScaleBox->edit_pt[0].y),3,pScaleBox->linecolor); + PX_GeoDrawSolidCircle(psurface,(px_int)(objx+pScaleBox->cursor_pt.x),(px_int)(objx+pScaleBox->cursor_pt.y),3,pScaleBox->linecolor); + break; + case 2: + { + px_point2D pt[4]; + + PX_memcpy(pt,pScaleBox->edit_pt,2*sizeof(px_point2D)); + pt[2]=pScaleBox->cursor_pt; + pt[3]=PX_Point2DAdd(pt[0],PX_Point2DSub(pt[2],pt[1])); + + PX_GeoDrawTriangle(psurface,pt[0],pt[1],pt[2],pScaleBox->regioncolor); + PX_GeoDrawTriangle(psurface,pt[0],pt[2],pt[3],pScaleBox->regioncolor); + + PX_GeoDrawLine(psurface,(px_int)(objx+pt[0].x),(px_int)(objx+pt[0].y),\ + (px_int)(objx+pt[1].x),(px_int)(objx+pt[1].y), + 1, + (pScaleBox->linecolor) + ); + + PX_GeoDrawLine(psurface,(px_int)(objx+pt[1].x),(px_int)(objx+pt[1].y),\ + (px_int)(objx+pt[2].x),(px_int)(objx+pt[2].y), + 1, + (pScaleBox->linecolor) + ); + + PX_GeoDrawLine(psurface,(px_int)(objx+pt[2].x),(px_int)(objx+pt[2].y),\ + (px_int)(objx+pt[3].x),(px_int)(objx+pt[3].y), + 1, + (pScaleBox->linecolor) + ); + + PX_GeoDrawLine(psurface,(px_int)(objx+pt[0].x),(px_int)(objx+pt[0].y),\ + (px_int)(objx+pt[3].x),(px_int)(objx+pt[3].y), + 1, + (pScaleBox->linecolor) + ); + + PX_GeoDrawSolidCircle(psurface,(px_int)(objx+pt[0].x),(px_int)(objx+pt[0].y),3,pScaleBox->linecolor); + PX_GeoDrawSolidCircle(psurface,(px_int)(objx+pt[1].x),(px_int)(objx+pt[1].y),3,pScaleBox->linecolor); + PX_GeoDrawSolidCircle(psurface,(px_int)(objx+pt[2].x),(px_int)(objx+pt[2].y),3,pScaleBox->linecolor); + PX_GeoDrawSolidCircle(psurface,(px_int)(objx+pt[3].x),(px_int)(objx+pt[3].y),3,pScaleBox->linecolor); + } + break; + case 3: + { + px_point2D mpt; + + PX_GeoDrawTriangle(psurface,pScaleBox->edit_pt[0],pScaleBox->edit_pt[1],pScaleBox->edit_pt[2],pScaleBox->regioncolor); + PX_GeoDrawTriangle(psurface,pScaleBox->edit_pt[0],pScaleBox->edit_pt[2],pScaleBox->edit_pt[3],pScaleBox->regioncolor); + + PX_GeoDrawTriangle(psurface,pScaleBox->scale_pt[0],pScaleBox->scale_pt[1],pScaleBox->scale_pt[2],pScaleBox->regioncolor); + PX_GeoDrawTriangle(psurface,pScaleBox->scale_pt[0],pScaleBox->scale_pt[2],pScaleBox->scale_pt[3],pScaleBox->regioncolor); + + + PX_GeoDrawLine(psurface,(px_int)(objx+pScaleBox->edit_pt[0].x),(px_int)(objx+pScaleBox->edit_pt[0].y),\ + (px_int)(objx+pScaleBox->edit_pt[1].x),(px_int)(objx+pScaleBox->edit_pt[1].y), + 1, + (pScaleBox->linecolor) + ); + PX_GeoDrawLine(psurface,(px_int)(objx+pScaleBox->scale_pt[0].x),(px_int)(objx+pScaleBox->scale_pt[0].y),\ + (px_int)(objx+pScaleBox->scale_pt[1].x),(px_int)(objx+pScaleBox->scale_pt[1].y), + 1, + (pScaleBox->linecolor) + ); + + + PX_GeoDrawLine(psurface,(px_int)(objx+pScaleBox->edit_pt[1].x),(px_int)(objx+pScaleBox->edit_pt[1].y),\ + (px_int)(objx+pScaleBox->edit_pt[2].x),(px_int)(objx+pScaleBox->edit_pt[2].y), + 1, + (pScaleBox->linecolor) + ); + + PX_GeoDrawLine(psurface,(px_int)(objx+pScaleBox->scale_pt[1].x),(px_int)(objx+pScaleBox->scale_pt[1].y),\ + (px_int)(objx+pScaleBox->scale_pt[2].x),(px_int)(objx+pScaleBox->scale_pt[2].y), + 1, + (pScaleBox->linecolor) + ); + + PX_GeoDrawLine(psurface,(px_int)(objx+pScaleBox->edit_pt[2].x),(px_int)(objx+pScaleBox->edit_pt[2].y),\ + (px_int)(objx+pScaleBox->edit_pt[3].x),(px_int)(objx+pScaleBox->edit_pt[3].y), + 1, + (pScaleBox->linecolor) + ); + PX_GeoDrawLine(psurface,(px_int)(objx+pScaleBox->scale_pt[2].x),(px_int)(objx+pScaleBox->scale_pt[2].y),\ + (px_int)(objx+pScaleBox->scale_pt[3].x),(px_int)(objx+pScaleBox->scale_pt[3].y), + 1, + (pScaleBox->linecolor) + ); + + PX_GeoDrawLine(psurface,(px_int)(objx+pScaleBox->edit_pt[0].x),(px_int)(objx+pScaleBox->edit_pt[0].y),\ + (px_int)(objx+pScaleBox->edit_pt[3].x),(px_int)(objx+pScaleBox->edit_pt[3].y), + 1, + (pScaleBox->linecolor) + ); + PX_GeoDrawLine(psurface,(px_int)(objx+pScaleBox->scale_pt[0].x),(px_int)(objx+pScaleBox->scale_pt[0].y),\ + (px_int)(objx+pScaleBox->scale_pt[3].x),(px_int)(objx+pScaleBox->scale_pt[3].y), + 1, + (pScaleBox->linecolor) + ); + + mpt.x=(pScaleBox->scale_pt[0].x+pScaleBox->scale_pt[1].x)/2; + mpt.y=(pScaleBox->scale_pt[0].y+pScaleBox->scale_pt[1].y)/2; + PX_GeoDrawSolidCircle(psurface,(px_int)(objx+mpt.x),(px_int)(objx+mpt.y),3,pScaleBox->linecolor); + if (pScaleBox->current_cursorpt==0||pScaleBox->current_selectpt==0) + { + PX_GeoDrawCircle(psurface,(px_int)(objx+mpt.x),(px_int)(objx+mpt.y),5,1,pScaleBox->linecolor); + } + + mpt.x=(pScaleBox->scale_pt[2].x+pScaleBox->scale_pt[1].x)/2; + mpt.y=(pScaleBox->scale_pt[2].y+pScaleBox->scale_pt[1].y)/2; + PX_GeoDrawSolidCircle(psurface,(px_int)(objx+mpt.x),(px_int)(objx+mpt.y),3,pScaleBox->linecolor); + if (pScaleBox->current_cursorpt==1||pScaleBox->current_selectpt==1) + { + PX_GeoDrawCircle(psurface,(px_int)(objx+mpt.x),(px_int)(objx+mpt.y),5,1,pScaleBox->linecolor); + } + + mpt.x=(pScaleBox->scale_pt[2].x+pScaleBox->scale_pt[3].x)/2; + mpt.y=(pScaleBox->scale_pt[2].y+pScaleBox->scale_pt[3].y)/2; + PX_GeoDrawSolidCircle(psurface,(px_int)(objx+mpt.x),(px_int)(objx+mpt.y),3,pScaleBox->linecolor); + if (pScaleBox->current_cursorpt==2||pScaleBox->current_selectpt==2) + { + PX_GeoDrawCircle(psurface,(px_int)(objx+mpt.x),(px_int)(objx+mpt.y),5,1,pScaleBox->linecolor); + } + + mpt.x=(pScaleBox->scale_pt[0].x+pScaleBox->scale_pt[3].x)/2; + mpt.y=(pScaleBox->scale_pt[0].y+pScaleBox->scale_pt[3].y)/2; + PX_GeoDrawSolidCircle(psurface,(px_int)(objx+mpt.x),(px_int)(objx+mpt.y),3,pScaleBox->linecolor); + if (pScaleBox->current_cursorpt==3||pScaleBox->current_selectpt==3) + { + PX_GeoDrawCircle(psurface,(px_int)(objx+mpt.x),(px_int)(objx+mpt.y),5,1,pScaleBox->linecolor); + } + + } + break; + } +} + +px_void PX_Object_ScaleBoxOnCursorDown(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + PX_Object_ScaleBox *pscalebox=PX_Object_GetScaleBox(pObject); + px_float inheritX,inheritY; + px_float objx,objy,x,y; + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + x=PX_Object_Event_GetCursorX(e); + y=PX_Object_Event_GetCursorY(e); + if (pscalebox->editpt_count==3) + { + px_int i; + px_point2D select_pt[4];//01,12,23,30 + + select_pt[0].x=(pscalebox->scale_pt[0].x+pscalebox->scale_pt[1].x)/2; + select_pt[0].y=(pscalebox->scale_pt[0].y+pscalebox->scale_pt[1].y)/2; + + select_pt[1].x=(pscalebox->scale_pt[2].x+pscalebox->scale_pt[1].x)/2; + select_pt[1].y=(pscalebox->scale_pt[2].y+pscalebox->scale_pt[1].y)/2; + + select_pt[2].x=(pscalebox->scale_pt[2].x+pscalebox->scale_pt[3].x)/2; + select_pt[2].y=(pscalebox->scale_pt[2].y+pscalebox->scale_pt[3].y)/2; + + select_pt[3].x=(pscalebox->scale_pt[0].x+pscalebox->scale_pt[3].x)/2; + select_pt[3].y=(pscalebox->scale_pt[0].y+pscalebox->scale_pt[3].y)/2; + + pscalebox->current_selectpt=-1; + for (i=0;i<4;i++) + { + if (PX_isPoint2DInCircle(PX_POINT2D(x,y),select_pt[i],5)) + { + pscalebox->current_selectpt=i; + break; + } + } + } + else + { + pscalebox->edit_pt[pscalebox->editpt_count]=PX_POINT2D(PX_Object_Event_GetCursorX(e)-inheritX,PX_Object_Event_GetCursorY(e)-inheritY); + pscalebox->editpt_count++; + if (pscalebox->editpt_count==3) + { + PX_memcpy(pscalebox->scale_pt,pscalebox->edit_pt,3*sizeof(px_point2D)); + pscalebox->edit_pt[3]=PX_Point2DAdd(pscalebox->edit_pt[0],PX_Point2DSub(pscalebox->edit_pt[2],pscalebox->edit_pt[1])); + pscalebox->scale_pt[3]=pscalebox->edit_pt[3]; + } + + } +} +px_void PX_Object_ScaleBoxOnCursorDrag(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + PX_Object_ScaleBox *pscalebox=PX_Object_GetScaleBox(pObject); + px_float inheritX,inheritY; + px_float objx,objy,x,y,d; + px_point2D base; + + px_point2D p0,p1,p2,v0,v1,v2; + + if (pscalebox->current_selectpt==-1) + { + return; + } + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + x=PX_Object_Event_GetCursorX(e)-objx; + y=PX_Object_Event_GetCursorY(e)-objy; + + switch(pscalebox->current_cursorpt) + { + case 0: + { + p0=pscalebox->scale_pt[2]; + p1=pscalebox->scale_pt[1]; + p2=pscalebox->scale_pt[3]; + } + break; + case 1: + { + p0=pscalebox->scale_pt[0]; + p1=pscalebox->scale_pt[1]; + p2=pscalebox->scale_pt[3]; + } + break; + case 2: + { + p0=pscalebox->scale_pt[1]; + p1=pscalebox->scale_pt[2]; + p2=pscalebox->scale_pt[0]; + } + break; + case 3: + { + p0=pscalebox->scale_pt[1]; + p1=pscalebox->scale_pt[0]; + p2=pscalebox->scale_pt[2]; + } + break; + default: + return; + } + v0=PX_Point2DNormalization(PX_Point2DSub(p1,p0)) ; + v1=PX_Point2DNormalization(PX_Point2DSub(p2,p0)); + v2=(PX_Point2DSub(PX_POINT2D(x,y),p0)); + + base=PX_Point2DBase(v0,v1,v2); + d=base.x; + switch(pscalebox->current_cursorpt) + { + case 0: + { + pscalebox->scale_pt[1]=PX_Point2DAdd(p0,PX_Point2DMul((v0),d)); + pscalebox->scale_pt[0]=PX_Point2DAdd(p2,PX_Point2DMul((v0),d)); + } + break; + case 1: + { + pscalebox->scale_pt[1]=PX_Point2DAdd(p0,PX_Point2DMul((v0),d)); + pscalebox->scale_pt[2]=PX_Point2DAdd(p2,PX_Point2DMul((v0),d)); + } + break; + case 2: + { + pscalebox->scale_pt[2]=PX_Point2DAdd(p0,PX_Point2DMul((v0),d)); + pscalebox->scale_pt[3]=PX_Point2DAdd(p2,PX_Point2DMul((v0),d)); + } + break; + case 3: + { + pscalebox->scale_pt[0]=PX_Point2DAdd(p0,PX_Point2DMul((v0),d)); + pscalebox->scale_pt[3]=PX_Point2DAdd(p2,PX_Point2DMul((v0),d)); + } + break; + } +} + +px_void PX_Object_ScaleBoxOnCursorMove(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + PX_Object_ScaleBox *pscalebox=PX_Object_GetScaleBox(pObject); + px_float inheritX,inheritY; + px_float objx,objy,x,y; + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + x=PX_Object_Event_GetCursorX(e); + y=PX_Object_Event_GetCursorY(e); + if (pscalebox->editpt_count==3) + { + px_int i; + px_point2D select_pt[4];//01,12,23,30 + + select_pt[0].x=(pscalebox->scale_pt[0].x+pscalebox->scale_pt[1].x)/2; + select_pt[0].y=(pscalebox->scale_pt[0].y+pscalebox->scale_pt[1].y)/2; + + select_pt[1].x=(pscalebox->scale_pt[2].x+pscalebox->scale_pt[1].x)/2; + select_pt[1].y=(pscalebox->scale_pt[2].y+pscalebox->scale_pt[1].y)/2; + + select_pt[2].x=(pscalebox->scale_pt[2].x+pscalebox->scale_pt[3].x)/2; + select_pt[2].y=(pscalebox->scale_pt[2].y+pscalebox->scale_pt[3].y)/2; + + select_pt[3].x=(pscalebox->scale_pt[0].x+pscalebox->scale_pt[3].x)/2; + select_pt[3].y=(pscalebox->scale_pt[0].y+pscalebox->scale_pt[3].y)/2; + + pscalebox->current_cursorpt=-1; + for (i=0;i<4;i++) + { + if (PX_isPoint2DInCircle(PX_POINT2D(x,y),select_pt[i],5)) + { + pscalebox->current_cursorpt=i; + break; + } + } + + } + else + { + pscalebox->cursor_pt=PX_POINT2D(PX_Object_Event_GetCursorX(e)-inheritX,PX_Object_Event_GetCursorY(e)-inheritY); + } +} +PX_Object * PX_Object_ScaleBoxCreate(px_memorypool *mp,PX_Object *Parent) +{ + PX_Object_ScaleBox scaleBox; + PX_Object *pObject; + PX_memset(&scaleBox,0,sizeof(scaleBox)); + scaleBox.linecolor=PX_COLOR(204,0,0,255); + scaleBox.regioncolor=PX_COLOR(64,0,0,255); + scaleBox.current_cursorpt=-1; + scaleBox.current_selectpt=-1; + pObject=PX_ObjectCreateEx(mp,Parent,0,0,0,0,0,0,PX_OBJECT_TYPE_SCALEBOX,PX_NULL,PX_Object_ScaleBoxRender,PX_NULL,&scaleBox,sizeof(scaleBox)); + if (!pObject) + { + return pObject; + } + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORDOWN,PX_Object_ScaleBoxOnCursorDown,PX_NULL); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORMOVE,PX_Object_ScaleBoxOnCursorMove,PX_NULL); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORDRAG,PX_Object_ScaleBoxOnCursorDrag,PX_NULL); + return pObject; +} + +PX_Object_ScaleBox * PX_Object_GetScaleBox(PX_Object *Object) +{ + if (Object->Type==PX_OBJECT_TYPE_SCALEBOX) + { + return (PX_Object_ScaleBox *)Object->pObject; + } + return PX_NULL; +} + +px_point2D * PX_Object_ScaleBoxGetPoints(PX_Object *Object) +{ + PX_Object_ScaleBox *pscalebox=PX_Object_GetScaleBox(Object); + if (pscalebox) + { + return pscalebox->edit_pt; + } + return PX_NULL; +} + diff --git a/lib/PainterEngine/kernel/PX_Object_ScaleBox.h b/lib/PainterEngine/kernel/PX_Object_ScaleBox.h new file mode 100644 index 0000000000000000000000000000000000000000..f937154f4b0d0e601a634f86f91105d0e5d2fd10 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_ScaleBox.h @@ -0,0 +1,24 @@ +#ifndef PX_OBJECT_SCALEBOX_H +#define PX_OBJECT_SCALEBOX_H +#include "PX_Object.h" + + + +typedef struct +{ + px_int current_selectpt; + px_int current_cursorpt; + px_int editpt_count; + px_point2D cursor_pt; + px_point2D edit_pt[4]; + px_point2D scale_pt[4]; + px_color linecolor,regioncolor; +}PX_Object_ScaleBox; +PX_Object * PX_Object_ScaleBoxCreate(px_memorypool *mp,PX_Object *Parent); +PX_Object_ScaleBox * PX_Object_GetScaleBox( PX_Object *Object ); +px_point2D *PX_Object_ScaleBoxGetPoints(PX_Object *Object); + + + +#endif + diff --git a/lib/PainterEngine/kernel/PX_Object_ScrollArea.c b/lib/PainterEngine/kernel/PX_Object_ScrollArea.c new file mode 100644 index 0000000000000000000000000000000000000000..31c505e3158479bd356bc3e76723f0b6e2737519 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_ScrollArea.c @@ -0,0 +1,354 @@ +#include "PX_Object_ScrollArea.h" + +px_void PX_Object_ScrollArea_EventDispatcher(PX_Object *Object,PX_Object_Event e,px_void *user_ptr) +{ + PX_Object_ScrollArea *pSA=PX_Object_GetScrollArea(Object); + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(Object,&inheritX,&inheritY); + + objx=(Object->x+inheritX); + objy=(Object->y+inheritY); + objWidth=Object->Width; + objHeight=Object->Height; + + if (!pSA) + { + return; + } + + if (e.Event==PX_OBJECT_EVENT_EXECUTE||e.Event==PX_OBJECT_EVENT_CURSORDRAG||e.Event==PX_OBJECT_EVENT_CURSORDOWN||e.Event==PX_OBJECT_EVENT_CURSORUP||e.Event==PX_OBJECT_EVENT_CURSORMOVE) + { + + if (!PX_ObjectIsPointInRegion(Object,PX_Object_Event_GetCursorX(e),PX_Object_Event_GetCursorY(e))) + { + return; + } + PX_Object_Event_SetCursorX(&e,PX_Object_Event_GetCursorX(e)-objx); + PX_Object_Event_SetCursorY(&e,PX_Object_Event_GetCursorY(e)-objy); + } + PX_ObjectPostEvent(pSA->root,e); +} + +px_void PX_Object_ScrollAreaLinkChild(PX_Object *parent,PX_Object *child) +{ + PX_ObjectAddClild(PX_Object_ScrollAreaGetIncludedObjects(parent),child); + PX_Object_ScrollAreaUpdateRange(parent); +} + +px_void PX_Object_ScrollAreaHSliderChanged(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + px_int value=PX_Object_SliderBarGetValue(pObject); + PX_Object_ScrollArea *pSA=(PX_Object_ScrollArea *)ptr; + pSA->root->x=-(px_float)value; +} + +px_void PX_Object_ScrollAreaVSliderChanged(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + px_int value=PX_Object_SliderBarGetValue(pObject); + PX_Object_ScrollArea *pSA=(PX_Object_ScrollArea *)ptr; + pSA->root->y=-(px_float)value; +} + +PX_Object * PX_Object_ScrollAreaCreate(px_memorypool *mp,PX_Object *Parent,px_int x,px_int y,px_int Width,px_int Height) +{ + PX_Object *pObject; + PX_Object_ScrollArea *pSA=(PX_Object_ScrollArea *)MP_Malloc(mp,sizeof(PX_Object_ScrollArea)); + + if (pSA==PX_NULL) + { + return PX_NULL; + } + PX_memset(pSA,0,sizeof(PX_Object_ScrollArea)); + + if (Height<=24||Width<=24) + { + return PX_NULL; + } + + pObject=PX_ObjectCreate(mp,Parent,(px_float)x,(px_float)y,0,(px_float)Width,(px_float)Height,0); + + if (pObject==PX_NULL) + { + return PX_NULL; + } + + if (!pObject) + { + MP_Free(mp,pSA); + return PX_NULL; + } + + pObject->pObject=pSA; + pObject->Type=PX_OBJECT_TYPE_SCROLLAREA; + pObject->ReceiveEvents=PX_TRUE; + pObject->Func_ObjectFree=PX_Object_ScrollAreaFree; + pObject->Func_ObjectRender=PX_Object_ScrollAreaRender; + + pSA->BackgroundColor=PX_COLOR(0,0,0,0); + pSA->bBorder=PX_TRUE; + pSA->borderColor=PX_COLOR(255,0,0,0); + //root + pSA->root=PX_ObjectCreate(pObject->mp,0,0,0,0,0,0,0); + pSA->hscroll=PX_Object_SliderBarCreate(mp,pObject,0,0,16,16,PX_OBJECT_SLIDERBAR_TYPE_HORIZONTAL,PX_OBJECT_SLIDERBAR_STYLE_BOX); + pSA->vscroll=PX_Object_SliderBarCreate(mp,pObject,0,0,16,16,PX_OBJECT_SLIDERBAR_TYPE_VERTICAL,PX_OBJECT_SLIDERBAR_STYLE_BOX); + if(!PX_SurfaceCreate(mp,Width,Height,&pSA->surface)) + { + MP_Free(mp,pSA); + MP_Free(mp,pObject); + return PX_NULL; + } + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_ANY,PX_Object_ScrollArea_EventDispatcher,PX_NULL); + PX_ObjectRegisterEvent(pSA->hscroll,PX_OBJECT_EVENT_VALUECHANGED,PX_Object_ScrollAreaHSliderChanged,pSA); + PX_ObjectRegisterEvent(pSA->vscroll,PX_OBJECT_EVENT_VALUECHANGED,PX_Object_ScrollAreaVSliderChanged,pSA); + + pObject->Func_ObjectLinkChild=PX_Object_ScrollAreaLinkChild; + PX_Object_ScrollAreaUpdateRange(pObject); + return pObject; +} + +PX_Object * PX_Object_ScrollAreaGetIncludedObjects(PX_Object *pObj) +{ + PX_Object_ScrollArea *pSA; + pSA=PX_Object_GetScrollArea(pObj); + if (pSA) + { + return pSA->root; + } + return PX_NULL; +} + +px_void PX_Object_ScrollAreaMoveToBottom(PX_Object *pObject) +{ + px_float left=0,top=0,right=0,bottom=0; + PX_Object_ScrollArea *psa=PX_Object_GetScrollArea(pObject); + if(psa) + { + PX_Object_ScrollAreaGetRegion(psa->root,&left,&top,&right,&bottom); + if (bottom-top>=pObject->Height) + { + psa->root->y=-(bottom-top-pObject->Height); + } + else + { + psa->root->y=0; + } + } + +} + +px_void PX_Object_ScrollAreaMoveToTop(PX_Object *pObject) +{ + px_float left=0,top=0,right=0,bottom=0; + PX_Object_ScrollArea *psa=PX_Object_GetScrollArea(pObject); + PX_Object_ScrollAreaGetRegion(psa->root,&left,&top,&right,&bottom); + if(psa) + psa->root->y=top; +} + +px_void PX_Object_ScrollAreaGetRegion(PX_Object *pObject,px_float *left,px_float *top,px_float *right,px_float *bottom) +{ + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + if (pObject==PX_NULL||pObject->Visible==PX_FALSE) + { + return; + } + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + if (objx<*left) + { + *left=objx; + } + + + if (objx+objWidth-1>*right) + { + *right=objx+objWidth; + } + + if (objy<*top) + { + *top=objy; + } + + if (objy+objHeight-1>*bottom) + { + *bottom=objy+objHeight; + } + + PX_Object_ScrollAreaGetRegion(pObject->pNextBrother,left,top,right,bottom); + PX_Object_ScrollAreaGetRegion(pObject->pChilds,left,top,right,bottom); +} + +px_void PX_Object_ScrollAreaUpdateRange( PX_Object *pObject) +{ + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + px_float left=0,top=0,right=0,bottom=0; + PX_Object_ScrollArea *pSA; + + + pSA=PX_Object_GetScrollArea(pObject); + pSA->root->x = 0; + pSA->root->y = 0; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + PX_Object_ScrollAreaGetRegion(pSA->root,&left,&top,&right,&bottom); + + do + { + px_float rWidth=right-left; + pSA->hscroll->x=0; + pSA->hscroll->y=objHeight; + pSA->hscroll->Width=pObject->Width; + pSA->hscroll->Height=16; + if (rWidth>pObject->Width) + { + if (pObject->Width!=0) + { + px_float btnW=pObject->Width/rWidth*pObject->Width; + pSA->hscroll->Visible=PX_TRUE; + PX_Object_SliderBarSetSliderButtonLength(pSA->hscroll,(px_int)btnW); + } + PX_Object_SliderBarSetRange(pSA->hscroll,(px_int)left,(px_int)(right-objWidth)); + PX_Object_SliderBarSetValue(pSA->hscroll, (px_int)left); + } + else + { + pSA->hscroll->Visible=PX_FALSE; + PX_Object_SliderBarSetValue(pSA->hscroll, 0); + } + } while (0); + + do + { + px_float rHeight=bottom-top; + + pSA->vscroll->x=objWidth; + pSA->vscroll->y=0; + pSA->vscroll->Width=16; + pSA->vscroll->Height=objHeight; + if (rHeight>pObject->Height) + { + if (pObject->Height!=0) + { + px_float btnH=pObject->Height/rHeight*pObject->Height; + pSA->vscroll->Visible=PX_TRUE; + PX_Object_SliderBarSetSliderButtonLength(pSA->vscroll,(px_int)btnH); + } + PX_Object_SliderBarSetRange(pSA->vscroll, (px_int)top, (px_int)(bottom - objHeight)); + PX_Object_SliderBarSetValue(pSA->vscroll, (px_int)top); + } + else + { + pSA->vscroll->Visible=PX_FALSE; + PX_Object_SliderBarSetValue(pSA->vscroll, 0); + } + + } while (0); +} + +px_void PX_Object_ScrollAreaRender(px_surface *psurface, PX_Object *pObject,px_uint elapsed) +{ + PX_Object_ScrollArea *pSA; + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + pSA=PX_Object_GetScrollArea(pObject); + if (!pSA) + { + return; + } + + + if (pSA->surface.height!=(px_int)objHeight||pSA->surface.width!=(px_int)objWidth) + { + PX_SurfaceFree(&pSA->surface); + if(!PX_SurfaceCreate(pObject->mp,(px_int)objWidth,(px_int)objHeight,&pSA->surface)) + { + return; + } + } + + + PX_SurfaceClear(&pSA->surface,0,0,(px_int)objWidth-1,(px_int)objHeight-1,pSA->BackgroundColor); + + //draw + PX_ObjectRender(&pSA->surface,pSA->root,elapsed); + PX_SurfaceRender(psurface,&pSA->surface,(px_int)objx,(px_int)objy,PX_ALIGN_LEFTTOP,PX_NULL); + + //Draw Border + if(pSA->bBorder) + PX_GeoDrawBorder(&pSA->surface,0,0,(px_int)objWidth-1,(px_int)objHeight-1,1,pSA->borderColor); + PX_SurfaceRender(psurface,&pSA->surface,(px_int)objx,(px_int)objy,PX_ALIGN_LEFTTOP,PX_NULL); +} + +px_void PX_Object_ScrollAreaFree(PX_Object *pObj) +{ + PX_Object_ScrollArea *pSA; + pSA=PX_Object_GetScrollArea(pObj); + if (pSA) + { + PX_ObjectDelete(pSA->root); + PX_SurfaceFree(&pSA->surface); + } +} + +px_void PX_Object_ScrollAreaSetBkColor(PX_Object *pObj,px_color bkColor) +{ + PX_Object_ScrollArea *pSA; + pSA=PX_Object_GetScrollArea(pObj); + if (pSA) + { + pSA->BackgroundColor=bkColor; + } +} + +px_void PX_Object_ScrollAreaSetBorder(PX_Object *pObj,px_bool Border) +{ + PX_Object_ScrollArea *pSA; + pSA=PX_Object_GetScrollArea(pObj); + if (pSA) + { + pSA->bBorder=Border; + } +} + +px_void PX_Object_ScrollAreaSetBorderColor(PX_Object *pObj,px_color borderColor) +{ + PX_Object_ScrollArea *pSA; + pSA=PX_Object_GetScrollArea(pObj); + if (pSA) + { + pSA->borderColor=borderColor; + } +} + +PX_Object_ScrollArea * PX_Object_GetScrollArea(PX_Object *Object) +{ + if(Object->Type==PX_OBJECT_TYPE_SCROLLAREA) + return (PX_Object_ScrollArea *)Object->pObject; + else + return PX_NULL; +} diff --git a/lib/PainterEngine/kernel/PX_Object_ScrollArea.h b/lib/PainterEngine/kernel/PX_Object_ScrollArea.h new file mode 100644 index 0000000000000000000000000000000000000000..ce257d0e72142813e6314f258db3a907da1cba7b --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_ScrollArea.h @@ -0,0 +1,31 @@ +#ifndef PX_OBJECT_SCROLLAREA_H +#define PX_OBJECT_SCROLLAREA_H +#include "PX_Object.h" + + +typedef struct +{ + px_bool bBorder; + px_surface surface; + px_color BackgroundColor; + px_color borderColor; + PX_Object *root; + PX_Object *hscroll,*vscroll; +}PX_Object_ScrollArea; + + +PX_Object *PX_Object_ScrollAreaCreate(px_memorypool *mp,PX_Object *Parent,int x,int y,int width,int height); +PX_Object_ScrollArea * PX_Object_GetScrollArea( PX_Object *Object ); +PX_Object * PX_Object_ScrollAreaGetIncludedObjects(PX_Object *pObj); +px_void PX_Object_ScrollAreaMoveToBottom(PX_Object *pObject); +px_void PX_Object_ScrollAreaMoveToTop(PX_Object *pObject); +px_void PX_Object_ScrollAreaGetRegion(PX_Object *pObject,px_float *left,px_float *top,px_float *right,px_float *bottom); +px_void PX_Object_ScrollAreaUpdateRange( PX_Object *pObject); +px_void PX_Object_ScrollAreaRender(px_surface *psurface, PX_Object *pObject,px_uint elapsed); +px_void PX_Object_ScrollAreaSetBkColor(PX_Object *pObj,px_color bkColor); +px_void PX_Object_ScrollAreaSetBorder( PX_Object *pObj,px_bool Border ); +px_void PX_Object_ScrollAreaSetBorderColor(PX_Object *pObj,px_color borderColor); +px_void PX_Object_ScrollAreaFree(PX_Object *pObj); + +#endif + diff --git a/lib/PainterEngine/kernel/PX_Object_Selectbar.c b/lib/PainterEngine/kernel/PX_Object_Selectbar.c new file mode 100644 index 0000000000000000000000000000000000000000..1a6c57bc5dc09a78611c1bc5f913a9150bbd6f22 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_Selectbar.c @@ -0,0 +1,567 @@ +#include "PX_Object_Selectbar.h" + +////////////////////////////////////////////////////////////////////////// +// +px_void PX_Object_SelectBarSliderOnChanged(PX_Object* pObject, PX_Object_Event e, px_void* ptr) +{ + PX_Object_SelectBar* pSelectbar = (PX_Object_SelectBar*)ptr; + pSelectbar->currentDisplayOffsetIndex = PX_Object_SliderBarGetValue(pObject); +} + +PX_Object_SelectBar *PX_Object_GetSelectBar(PX_Object *pSelecrBar) +{ + if (pSelecrBar->Type==PX_OBJECT_TYPE_SELECTBAR) + { + return (PX_Object_SelectBar *)pSelecrBar->pObject; + } + return PX_NULL; +} +static px_void PX_SelecrbarClearCurrentCursor(PX_Object_SelectBar *pSelectbar) +{ + px_int i; + for (i=0;iItems.size;i++) + { + PX_VECTORAT(PX_Object_SelectBar_Item,&pSelectbar->Items,i)->onCursor=PX_FALSE; + } +} +static px_void PX_SelectbarOnCursorMove(PX_Object *pObject,px_float x,px_float y) +{ + PX_Object_SelectBar *pSelectbar=PX_Object_GetSelectBar(pObject); + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + + if(pSelectbar->activating) + { + px_int index; + if (pSelectbar->Items.size>pSelectbar->maxDisplayCount) + { + if (xobjx+objWidth-16) + { + return; + } + } + else + { + if (xobjx+objWidth) + { + return; + } + } + + index=(px_int)((y-objy-objHeight)/pSelectbar->ItemHeight); + PX_SelecrbarClearCurrentCursor(pSelectbar); + + if (y=pSelectbar->maxDisplayCount||index>=pSelectbar->Items.size) + { + return; + } + else + { + PX_VECTORAT(PX_Object_SelectBar_Item,&pSelectbar->Items,index+pSelectbar->currentDisplayOffsetIndex)->onCursor=PX_TRUE; + } + } + else + { + if(PX_isPointInRect(PX_POINT(x,y,0),PX_RECT(objx,objy,objWidth,objHeight))) + { + pSelectbar->onCursor=PX_TRUE; + } + else + { + pSelectbar->onCursor=PX_FALSE; + } + } +} +static px_void PX_SelectbarOnCursorDown(PX_Object *pObject,px_float x,px_float y) +{ + PX_Object_SelectBar *pSelectbar=PX_Object_GetSelectBar(pObject); + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + if(pSelectbar->activating) + { + px_int index; + if (pSelectbar->Items.size>pSelectbar->maxDisplayCount) + { + if (xobjx+objWidth) + { + PX_SelecrbarClearCurrentCursor(pSelectbar); + pSelectbar->onCursor=PX_FALSE; + pSelectbar->activating=PX_FALSE; + PX_ObjectClearFocus(pObject); + return; + } + if (x>=objx+objWidth-16&&x<=objx+objWidth) + { + return; + } + } + else + { + if (xobjx+objWidth) + { + PX_SelecrbarClearCurrentCursor(pSelectbar); + pSelectbar->activating=PX_FALSE; + PX_ObjectClearFocus(pObject); + pSelectbar->onCursor=PX_FALSE; + return; + } + } + + index=(px_int)((y-objy-objHeight)/pSelectbar->ItemHeight); + PX_SelecrbarClearCurrentCursor(pSelectbar); + if (y=pSelectbar->maxDisplayCount||index>=pSelectbar->Items.size) + { + pSelectbar->activating=PX_FALSE; + PX_ObjectClearFocus(pObject); + pSelectbar->onCursor=PX_FALSE; + return; + } + else + { + pSelectbar->activating=PX_FALSE; + PX_ObjectClearFocus(pObject); + pSelectbar->selectIndex=index+pSelectbar->currentDisplayOffsetIndex; + do + { + PX_Object_Event e; + e.Event=PX_OBJECT_EVENT_VALUECHANGED; + PX_Object_Event_SetIndex(&e,index); + PX_ObjectPostEvent(pObject,e); + } while (0); + } + pSelectbar->onCursor=PX_FALSE; + } + else + { + if (pSelectbar->Items.size==0) + { + return; + } + + if(PX_isPointInRect(PX_POINT(x,y,0),PX_RECT(objx,objy,objWidth,objHeight))) + { + pSelectbar->activating=PX_TRUE; + PX_ObjectSetFocus(pObject); + } + } + +} + +static px_void PX_SelectbarOnCursorWheel(PX_Object *pObject,px_float z) +{ + PX_Object_SelectBar *pSelectbar=PX_Object_GetSelectBar(pObject); + if (pSelectbar->activating) + { + if (pSelectbar->Items.size>pSelectbar->maxDisplayCount) + { + if (z<0) + { + PX_Object_SliderBarSetValue(pSelectbar->sliderBar,PX_Object_SliderBarGetValue(pSelectbar->sliderBar)+1); + } + else + { + PX_Object_SliderBarSetValue(pSelectbar->sliderBar,PX_Object_SliderBarGetValue(pSelectbar->sliderBar)-1); + } + } + } +} +static px_void PX_SelectbarOnCursorEvent(PX_Object *pSelectBarObject,PX_Object_Event e,px_void *ptr) +{ + switch(e.Event) + { + case PX_OBJECT_EVENT_CURSORMOVE: + case PX_OBJECT_EVENT_CURSORDRAG: + { + PX_SelectbarOnCursorMove(pSelectBarObject,PX_Object_Event_GetCursorX(e),PX_Object_Event_GetCursorY(e)); + } + break; + case PX_OBJECT_EVENT_CURSORDOWN: + { + PX_SelectbarOnCursorDown(pSelectBarObject,PX_Object_Event_GetCursorX(e),PX_Object_Event_GetCursorY(e)); + } + break; + case PX_OBJECT_EVENT_CURSORWHEEL: + { + PX_Object_SelectBar* pDesc = PX_ObjectGetDesc(PX_Object_SelectBar, pSelectBarObject); + PX_SelectbarOnCursorWheel(pSelectBarObject,PX_Object_Event_GetCursorZ(e)); + PX_Object_SelectBarSliderOnChanged(pDesc->sliderBar, PX_OBJECT_BUILD_EVENT(PX_OBJECT_EVENT_VALUECHANGED), pDesc); + } + break; + default: + break; + } +} +static px_void PX_SelectbarFree(PX_Object *pObject) +{ + PX_VectorFree(&PX_Object_GetSelectBar(pObject)->Items); +} +static px_void PX_SelectbarRender(px_surface *pRenderSurface,PX_Object *pObject,px_dword elpase) +{ + PX_Object_SelectBar *pSelectBar=PX_Object_GetSelectBar(pObject); + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + + + + //border + if (pSelectBar->style==PX_OBJECT_SELECTBAR_STYLE_RECT) + { + //background + if (pSelectBar->onCursor) + { + PX_GeoDrawRect(pRenderSurface,(px_int)objx,(px_int)objy,(px_int)(objx+objWidth-1),(px_int)(objy+objHeight-1),pSelectBar->cursorColor); + } + else + { + PX_GeoDrawRect(pRenderSurface,(px_int)objx,(px_int)objy,(px_int)(objx+objWidth-1),(px_int)(objy+objHeight-1),pSelectBar->backgroundColor); + } + + PX_GeoDrawBorder(pRenderSurface,(px_int)objx,(px_int)objy,(px_int)(objx+objWidth-1),(px_int)(objy+objHeight-1),1,pSelectBar->borderColor); + + } + else if (pSelectBar->style==PX_OBJECT_SELECTBAR_STYLE_ROUNDRECT) + { + if (pSelectBar->onCursor) + { + PX_GeoDrawSolidRoundRect(pRenderSurface,(px_int)objx,(px_int)objy,(px_int)(objx+objWidth-1),(px_int)(objy+objHeight-1),objHeight/2,pSelectBar->cursorColor); + } + else + { + PX_GeoDrawSolidRoundRect(pRenderSurface,(px_int)objx,(px_int)objy,(px_int)(objx+objWidth-1),(px_int)(objy+objHeight-1),objHeight/2,pSelectBar->backgroundColor); + } + + PX_GeoDrawRoundRect(pRenderSurface,(px_int)objx,(px_int)objy,(px_int)(objx+objWidth-1),(px_int)(objy+objHeight-1),objHeight/2,1,pSelectBar->borderColor); + } + + //font + do + { + if (pSelectBar->selectIndex>=0&&pSelectBar->selectIndexItems.size) + { + PX_Object_SelectBar_Item *pItem=PX_VECTORAT(PX_Object_SelectBar_Item,&pSelectBar->Items,pSelectBar->selectIndex); + PX_FontModuleDrawText(pRenderSurface,pSelectBar->fontmodule,(px_int)(objx+objHeight/2+1),(px_int)(objy+objHeight/2),PX_ALIGN_LEFTMID,pItem->Text,pSelectBar->fontColor); + } + } while (0); + + //triangle + PX_GeoDrawTriangle(pRenderSurface, + PX_POINT2D(objx+objWidth-16,objy+objHeight/2-3), + PX_POINT2D(objx+objWidth-4,objy+objHeight/2-3), + PX_POINT2D(objx+objWidth-10,objy+objHeight/2+3), + pSelectBar->borderColor + ); + + if (pSelectBar->activating) + { + px_int i; + px_int count=pSelectBar->maxDisplayCount>pSelectBar->Items.size?pSelectBar->Items.size:pSelectBar->maxDisplayCount; + + for (i=0;iItems,i+pSelectBar->currentDisplayOffsetIndex); + + if (pItem->onCursor) + { + PX_GeoDrawRect(pRenderSurface, + (px_int)(objx), + (px_int)(objy+objHeight+i*pSelectBar->ItemHeight), + (px_int)(objx+objWidth), + (px_int)(objy+objHeight+(i+1)*pSelectBar->ItemHeight), + pSelectBar->cursorColor + ); + } + else + { + PX_GeoDrawRect(pRenderSurface, + (px_int)(objx), + (px_int)(objy+objHeight+i*pSelectBar->ItemHeight), + (px_int)(objx+objWidth), + (px_int)(objy+objHeight+(i+1)*pSelectBar->ItemHeight), + pSelectBar->backgroundColor + ); + } + + PX_FontModuleDrawText(pRenderSurface,pSelectBar->fontmodule,(px_int)(objx+objHeight/2+1), + (px_int)(objy+objHeight+(i*pSelectBar->ItemHeight)+pSelectBar->ItemHeight/2), + PX_ALIGN_LEFTMID, + pItem->Text, + pSelectBar->fontColor + ); + } + PX_GeoDrawBorder(pRenderSurface, + (px_int)objx, + (px_int)(objy+objHeight), + (px_int)(objx+objWidth-1), + (px_int)(objy+objHeight+count*pSelectBar->ItemHeight), + 1, + pSelectBar->borderColor + ); + + if (pSelectBar->Items.size>pSelectBar->maxDisplayCount) + { + pSelectBar->sliderBar->Visible=PX_TRUE; + pSelectBar->sliderBar->x=objWidth-16; + pSelectBar->sliderBar->y=objHeight; + pSelectBar->sliderBar->Width=16; + pSelectBar->sliderBar->Height=count*pSelectBar->ItemHeight*1.0f; + PX_Object_SliderBarSetBackgroundColor(pSelectBar->sliderBar,pSelectBar->backgroundColor); + PX_Object_SliderBarSetColor(pSelectBar->sliderBar,pSelectBar->borderColor); + PX_Object_SliderBarSetRange(pSelectBar->sliderBar,0,pSelectBar->Items.size-pSelectBar->maxDisplayCount); + PX_Object_SliderBarSetSliderButtonLength(pSelectBar->sliderBar,(px_int)(pSelectBar->sliderBar->Height*pSelectBar->maxDisplayCount/pSelectBar->Items.size)); + } + else + { + pSelectBar->sliderBar->Visible=PX_FALSE; + } + } + else + { + pSelectBar->sliderBar->Visible=PX_FALSE; + } + +} + + + +PX_Object * PX_Object_SelectBarCreate(px_memorypool *mp,PX_Object *Parent,px_int x,int y,px_int width,px_int height,PX_FontModule *fontmodule) +{ + PX_Object *pObject; + PX_Object_SelectBar *pSelectbar=(PX_Object_SelectBar *)MP_Malloc(mp,sizeof(PX_Object_SelectBar)); + + if (pSelectbar==PX_NULL) + { + return PX_NULL; + } + + PX_memset(pSelectbar,0,sizeof(PX_Object_SelectBar)); + pSelectbar->fontmodule=fontmodule; + pSelectbar->mp=mp; + pSelectbar->activating=PX_FALSE; + pSelectbar->currentDisplayOffsetIndex=0; + if (fontmodule) + { + pSelectbar->ItemHeight=fontmodule->max_Height; + } + else + { + pSelectbar->ItemHeight=__PX_FONT_HEIGHT; + } + + pSelectbar->maxDisplayCount=16; + pSelectbar->backgroundColor= PX_OBJECT_UI_DEFAULT_BACKGROUNDCOLOR; + pSelectbar->cursorColor= PX_OBJECT_UI_DEFAULT_CURSORCOLOR; + pSelectbar->fontColor=PX_OBJECT_UI_DEFAULT_FONTCOLOR; + pSelectbar->borderColor= PX_OBJECT_UI_DEFAULT_BORDERCOLOR; + pSelectbar->activating=PX_FALSE; + pSelectbar->style=PX_OBJECT_SELECTBAR_STYLE_RECT; + PX_VectorInitialize(mp,&pSelectbar->Items,sizeof(PX_Object_SelectBar_Item),16); + + + pObject=PX_ObjectCreate(mp,Parent,(px_float)x,(px_float)y,0,(px_float)width,(px_float)height,0); + if (pObject==PX_NULL) + { + MP_Free(pObject->mp,pSelectbar); + return PX_NULL; + } + + + pObject->pObject=pSelectbar; + pObject->Enabled=PX_TRUE; + pObject->Visible=PX_TRUE; + pObject->Type=PX_OBJECT_TYPE_SELECTBAR; + pObject->Func_ObjectFree=PX_SelectbarFree; + pObject->Func_ObjectRender=PX_SelectbarRender; + pObject->OnLostFocusReleaseEvent=PX_TRUE; + + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORDOWN,PX_SelectbarOnCursorEvent,PX_NULL); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORMOVE,PX_SelectbarOnCursorEvent,PX_NULL); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORDRAG,PX_SelectbarOnCursorEvent,PX_NULL); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORWHEEL,PX_SelectbarOnCursorEvent,PX_NULL); + + pSelectbar->sliderBar=PX_Object_SliderBarCreate(mp,pObject,0,0,0,0,PX_OBJECT_SLIDERBAR_TYPE_VERTICAL,PX_OBJECT_SLIDERBAR_STYLE_BOX); + + if (!pSelectbar->sliderBar) + { + PX_ObjectDelete(pObject); + return PX_NULL; + } + PX_ObjectRegisterEvent(pSelectbar->sliderBar,PX_OBJECT_EVENT_VALUECHANGED,PX_Object_SelectBarSliderOnChanged,pSelectbar); + return pObject; +} + +px_int PX_Object_SelectBarAddItem(PX_Object *pSelectBarObject,const px_char Text[]) +{ + PX_Object_SelectBar *pSelectBar=PX_Object_GetSelectBar(pSelectBarObject); + PX_Object_SelectBar_Item item; + PX_strcpy(item.Text,Text,sizeof(item.Text)); + item.onCursor=PX_FALSE; + if(PX_VectorPushback(&pSelectBar->Items,&item)) + return pSelectBar->Items.size-1; + else + return -1; +} + +px_void PX_Object_SelectBarClear(PX_Object* pSelectBarObject) +{ + PX_Object_SelectBar* pSelectBar = PX_Object_GetSelectBar(pSelectBarObject); + PX_VectorClear(&pSelectBar->Items); +} + +px_void PX_Object_SelectBarRemoveItem(PX_Object *pObject,px_int index) +{ + PX_Object_SelectBar *pSelectBar=PX_Object_GetSelectBar(pObject); + if (index>=0&&indexItems.size) + { + PX_VectorErase(&pSelectBar->Items,index); + } +} + +px_int PX_Object_SelectBarGetItemIndexByText(PX_Object *pObject,const px_char Text[]) +{ + PX_Object_SelectBar *pSelectBar=PX_Object_GetSelectBar(pObject); + px_int i; + for (i=0;iItems.size;i++) + { + PX_Object_SelectBar_Item *pItem=PX_VECTORAT(PX_Object_SelectBar_Item,&pSelectBar->Items,i); + if (PX_strequ(Text,pItem->Text)) + { + return i; + } + } + return -1; +} + +const px_char * PX_Object_SelectBarGetCurrentText(PX_Object *pObject) +{ + PX_Object_SelectBar *pSelectBar=PX_Object_GetSelectBar(pObject); + if (pSelectBar) + { + return PX_VECTORAT(PX_Object_SelectBar_Item,&pSelectBar->Items,pSelectBar->selectIndex)->Text; + } + return ""; +} + + +const px_char* PX_Object_SelectBarGetItemText(PX_Object* pObject,px_int index) +{ + PX_Object_SelectBar* pSelectBar = PX_Object_GetSelectBar(pObject); + if (!PX_VectorCheckIndex(&pSelectBar->Items,index)) + { + return ""; + } + if (pSelectBar) + { + return PX_VECTORAT(PX_Object_SelectBar_Item, &pSelectBar->Items, index)->Text; + } + return ""; +} + +px_void PX_Object_SelectBarSetDisplayCount(PX_Object *pObject,px_int count) +{ + PX_Object_SelectBar *pSelectBar=PX_Object_GetSelectBar(pObject); + if (pSelectBar) + { + pSelectBar->maxDisplayCount=count; + } +} + +px_int PX_Object_SelectBarGetCurrentIndex(PX_Object *pObject) +{ + PX_Object_SelectBar *pSelectBar=PX_Object_GetSelectBar(pObject); + if (pSelectBar) + { + return pSelectBar->selectIndex; + } + return -1; +} + +px_void PX_Object_SelectBarSetCurrentIndex(PX_Object *pObject,px_int index) +{ + PX_Object_SelectBar *pSelectBar=PX_Object_GetSelectBar(pObject); + if (pSelectBar) + { + if (index>=0&&indexItems.size) + { + pSelectBar->selectIndex=index; + } + } +} + +px_void PX_Object_SelectBarSetStyle(PX_Object *pObject,PX_OBJECT_SELECTBAR_STYLE style) +{ + PX_Object_SelectBar *pSelectBar=PX_Object_GetSelectBar(pObject); + if (pSelectBar) + { + pSelectBar->style=style; + } +} + +px_void PX_Object_SelectBarSetFontColor(PX_Object *pObject,px_color color) +{ + PX_Object_SelectBar *pSelectBar=PX_Object_GetSelectBar(pObject); + if (pSelectBar) + { + pSelectBar->fontColor=color; + } +} + +px_void PX_Object_SelectBarSetCursorColor(PX_Object *pObject,px_color color) +{ + PX_Object_SelectBar *pSelectBar=PX_Object_GetSelectBar(pObject); + if (pSelectBar) + { + pSelectBar->cursorColor=color; + } +} + +px_void PX_Object_SelectBarSetBorderColor(PX_Object *pObject,px_color color) +{ + PX_Object_SelectBar *pSelectBar=PX_Object_GetSelectBar(pObject); + if (pSelectBar) + { + pSelectBar->borderColor=color; + } +} + +px_void PX_Object_SelectBarSetBackgroundColor(PX_Object *pObject,px_color color) +{ + PX_Object_SelectBar *pSelectBar=PX_Object_GetSelectBar(pObject); + if (pSelectBar) + { + pSelectBar->backgroundColor=color; + } +} + +px_void PX_Object_SelectBarSetMaxDisplayCount(PX_Object* pObject, px_int i) +{ + PX_Object_SelectBar* pSelectBar = PX_Object_GetSelectBar(pObject); + if (pSelectBar) + { + pSelectBar->maxDisplayCount = i; + } +} + diff --git a/lib/PainterEngine/kernel/PX_Object_Selectbar.h b/lib/PainterEngine/kernel/PX_Object_Selectbar.h new file mode 100644 index 0000000000000000000000000000000000000000..2d0fb54e725f5888f2f1abd8087cd61c6888cd12 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_Selectbar.h @@ -0,0 +1,56 @@ +#ifndef PX_OBJECT_SELECTBAR_H +#define PX_OBJECT_SELECTBAR_H +#include "PX_Object.h" +#define PX_SELECTBAR_CONTENT_MAX_LEN 48 + +typedef enum +{ + PX_OBJECT_SELECTBAR_STYLE_RECT, + PX_OBJECT_SELECTBAR_STYLE_ROUNDRECT, +}PX_OBJECT_SELECTBAR_STYLE; + + +typedef struct +{ + px_char Text[PX_SELECTBAR_CONTENT_MAX_LEN]; + px_bool onCursor; +}PX_Object_SelectBar_Item;; + +typedef struct +{ + px_memorypool *mp; + px_int maxDisplayCount; + px_int currentDisplayOffsetIndex; + px_int ItemHeight; + px_bool activating; + px_bool onCursor; + px_vector Items;//PX_Object_SelectBar_Item; + PX_FontModule *fontmodule; + px_color backgroundColor; + px_color fontColor; + px_color cursorColor; + px_color borderColor; + px_int selectIndex; + PX_Object *sliderBar; + PX_OBJECT_SELECTBAR_STYLE style; +}PX_Object_SelectBar; + +PX_Object_SelectBar *PX_Object_GetSelectBar(PX_Object *pSelecrBar); +PX_Object * PX_Object_SelectBarCreate(px_memorypool *mp,PX_Object *Parent,px_int x,int y,px_int width,px_int height,PX_FontModule *fontmodule); +px_int PX_Object_SelectBarAddItem(PX_Object *PX_Object_SelectBar,const px_char Text[]); +px_void PX_Object_SelectBarClear(PX_Object* pSelectBarObject); +px_void PX_Object_SelectBarRemoveItem(PX_Object* PX_Object_SelectBar, px_int index); +px_int PX_Object_SelectBarGetItemIndexByText(PX_Object *pObject,const px_char Text[]); +const px_char *PX_Object_SelectBarGetCurrentText(PX_Object *pObject); +const px_char* PX_Object_SelectBarGetItemText(PX_Object* pObject, px_int index); +px_void PX_Object_SelectBarSetDisplayCount(PX_Object* pObject, px_int count); +px_int PX_Object_SelectBarGetCurrentIndex(PX_Object *pObject); +px_void PX_Object_SelectBarSetCurrentIndex(PX_Object *pObject,px_int index); +px_void PX_Object_SelectBarSetStyle(PX_Object *pObject,PX_OBJECT_SELECTBAR_STYLE style); +px_void PX_Object_SelectBarSetFontColor(PX_Object *pObject,px_color color); +px_void PX_Object_SelectBarSetCursorColor(PX_Object *pObject,px_color color); +px_void PX_Object_SelectBarSetBorderColor(PX_Object *pObject,px_color color); +px_void PX_Object_SelectBarSetBackgroundColor(PX_Object *pObject,px_color color); +px_void PX_Object_SelectBarSetMaxDisplayCount(PX_Object* pObject, px_int color); +#endif + diff --git a/lib/PainterEngine/kernel/PX_Object_Sliderbar.c b/lib/PainterEngine/kernel/PX_Object_Sliderbar.c new file mode 100644 index 0000000000000000000000000000000000000000..b18886e2c8e62bbfa6ab05f85c6b33a63b8c13d3 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_Sliderbar.c @@ -0,0 +1,710 @@ +#include "PX_Object_Sliderbar.h" + +px_void PX_Object_SliderBarOnMouseLButtonDown(PX_Object *pObject,PX_Object_Event e,px_void *user_ptr) +{ + PX_Object_SliderBar *pSliderBar=PX_Object_GetSliderBar(pObject); + px_float x,y; + px_int SliderBtnLen,Sx,Sy; + px_rect rect; + px_int Range,relValue; + + px_int objx,objy,objw,objh; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(px_int)(pObject->x+inheritX); + objy=(px_int)(pObject->y+inheritY); + objw=(px_int)pObject->Width; + objh=(px_int)pObject->Height; + + x=PX_Object_Event_GetCursorX(e); + y=PX_Object_Event_GetCursorY(e); + + + if (pSliderBar) + { + Range=pSliderBar->Max-pSliderBar->Min; + relValue=pSliderBar->Value-pSliderBar->Min; + + if(PX_ObjectIsPointInRegion(pObject,(px_float)x,(px_float)y)) + { + if (pSliderBar==PX_NULL) + { + return; + } + + if (objw<=10) + { + return; + } + + if (objh<10) + { + return; + } + + SliderBtnLen=pSliderBar->SliderButtonLength; + + + if(pSliderBar->Type==PX_OBJECT_SLIDERBAR_TYPE_HORIZONTAL) + { + switch(pSliderBar->style) + { + case PX_OBJECT_SLIDERBAR_STYLE_LINER: + { + Sx=objx+(px_int)((objw-pSliderBar->SliderButtonLength)*(1.0f)*relValue/Range); + + + rect.x=(px_float)Sx; + rect.y=(px_float)objy; + rect.width=(px_float)pSliderBar->SliderButtonLength; + + rect.height=(px_float)objh; + + if (PX_isPointInRect(PX_POINT((px_float)x,(px_float)y,0),rect)) + { + pSliderBar->btnDownX=x; + pSliderBar->btnDownY=y; + pSliderBar->status=PX_OBJECT_SLIDERBAR_STATUS_ONDRAG; + } + } + break; + case PX_OBJECT_SLIDERBAR_STYLE_BOX: + { + Sx=(px_int)objx+(px_int)((objw-pSliderBar->SliderButtonLength)*(1.0f)*relValue/Range); + + rect.x=(px_float)Sx; + rect.y=(px_float)objy; + rect.width=(px_float)pSliderBar->SliderButtonLength; + rect.height=(px_float)objh; + + if (PX_isPointInRect(PX_POINT((px_float)x,(px_float)y,0),rect)) + { + pSliderBar->btnDownX=x; + pSliderBar->btnDownY=y; + pSliderBar->status=PX_OBJECT_SLIDERBAR_STATUS_ONDRAG; + } + else if(x>rect.x) + { + pSliderBar->Value+=Range*pSliderBar->SliderButtonLength/((px_int)objw); + if (pSliderBar->Value>pSliderBar->Max) + { + pSliderBar->Value=pSliderBar->Max; + } + } + else + { + pSliderBar->Value-=Range*pSliderBar->SliderButtonLength/((px_int)objw); + if (pSliderBar->Value<0) + { + pSliderBar->Value=0; + } + } + + } + break; + } + + + } + + if (pSliderBar->Type==PX_OBJECT_SLIDERBAR_TYPE_VERTICAL) + { + switch(pSliderBar->style) + { + case PX_OBJECT_SLIDERBAR_STYLE_LINER: + { + Sx=(px_int)objx; + Sy=(px_int)objy+((px_int)objh-pSliderBar->SliderButtonLength)*relValue/Range; + + rect.x=(px_float)Sx; + rect.y=(px_float)Sy; + rect.width=(px_float)objh; + rect.height=(px_float)pSliderBar->SliderButtonLength; + + if (PX_isPointInRect(PX_POINT((px_float)x,(px_float)y,0),rect)) + { + pSliderBar->btnDownX=x; + pSliderBar->btnDownY=y; + pSliderBar->status=PX_OBJECT_SLIDERBAR_STATUS_ONDRAG; + } + } + break; + case PX_OBJECT_SLIDERBAR_STYLE_BOX: + { + Sy=(px_int)objy+(px_int)((objh-pSliderBar->SliderButtonLength)*(1.0f)*relValue/Range); + + + rect.x=(px_float)objx+2; + rect.y=(px_float)Sy; + + rect.width=(px_float)objw; + rect.height=(px_float)pSliderBar->SliderButtonLength; + + if (PX_isPointInRect(PX_POINT((px_float)x,(px_float)y,0),rect)) + { + pSliderBar->btnDownX=x; + pSliderBar->btnDownY=y; + pSliderBar->status=PX_OBJECT_SLIDERBAR_STATUS_ONDRAG; + } + else if(y>rect.y) + { + pSliderBar->Value+=Range*pSliderBar->SliderButtonLength/((px_int)objh); + if (pSliderBar->Value>pSliderBar->Max) + { + pSliderBar->Value=pSliderBar->Max; + } + } + else + { + pSliderBar->Value-=Range*pSliderBar->SliderButtonLength/((px_int)objh); + if (pSliderBar->ValueMin) + { + pSliderBar->Value=pSliderBar->Min; + } + } + } + break; + } + + } + } + } +} + +px_void PX_Object_SliderBarOnCursorNormal(PX_Object *pObject,PX_Object_Event e,px_void *user_ptr) +{ + PX_Object_SliderBar *pSliderBar=PX_Object_GetSliderBar(pObject); + + if (pSliderBar) + { + pSliderBar->status=PX_OBJECT_SLIDERBAR_STATUS_NORMAL; + } +} + +px_void PX_Object_SliderBarOnCursorDrag(PX_Object *pObject,PX_Object_Event e,px_void *user_ptr) +{ + PX_Object_SliderBar *pSliderBar=PX_Object_GetSliderBar(pObject); + px_float x,y; + + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + + x=PX_Object_Event_GetCursorX(e); + y=PX_Object_Event_GetCursorY(e); + + if (pSliderBar) + { + if (pSliderBar->status!=PX_OBJECT_SLIDERBAR_STATUS_ONDRAG) + { + return; + } + + if(pSliderBar->Type==PX_OBJECT_SLIDERBAR_TYPE_HORIZONTAL) + { + if (xDargButtonX=0; + return; + } + if (x>objx+objWidth) + { + pSliderBar->DargButtonX=objWidth-pSliderBar->SliderButtonLength; + return; + } + + pSliderBar->DargButtonX+=(x-pSliderBar->btnDownX); + pSliderBar->btnDownX=x; + if (pSliderBar->DargButtonX<0) + { + pSliderBar->DargButtonX=0; + } + if (pSliderBar->DargButtonX>=objWidth-pSliderBar->SliderButtonLength) + { + pSliderBar->DargButtonX=objWidth-pSliderBar->SliderButtonLength; + } + + } + + if (pSliderBar->Type==PX_OBJECT_SLIDERBAR_TYPE_VERTICAL) + { + if (yDargButtonY=0; + return; + } + if (y>objy+objHeight) + { + pSliderBar->DargButtonY=objHeight-pSliderBar->SliderButtonLength; + return; + } + + pSliderBar->DargButtonY+=(y-pSliderBar->btnDownY); + pSliderBar->btnDownY=y; + + if (pSliderBar->DargButtonY<0) + { + pSliderBar->DargButtonY=0; + } + if (pSliderBar->DargButtonY>=objHeight-pSliderBar->SliderButtonLength) + { + pSliderBar->DargButtonY=objHeight-pSliderBar->SliderButtonLength; + } + } + + } +} + +PX_Object * PX_Object_SliderBarCreate(px_memorypool *mp,PX_Object *Parent,px_int x,px_int y,px_int Width,px_int Height,PX_OBJECT_SLIDERBAR_TYPE Type,PX_OBJECT_SLIDERBAR_STYLE style) +{ + PX_Object *pObject; + PX_Object_SliderBar *pSliderbar=(PX_Object_SliderBar *)MP_Malloc(mp,sizeof(PX_Object_SliderBar)); + if (pSliderbar==PX_NULL) + { + return PX_NULL; + } + pObject=PX_ObjectCreate(mp,Parent,(px_float)x,(px_float)y,0,(px_float)Width,(px_float)Height,0); + if (pObject==PX_NULL) + { + MP_Free(pObject->mp,pSliderbar); + return PX_NULL; + } + + pObject->pObject=pSliderbar; + pObject->Enabled=PX_TRUE; + pObject->Visible=PX_TRUE; + pObject->Type=PX_OBJECT_TYPE_SLIDERBAR; + pObject->ReceiveEvents=PX_TRUE; + pObject->Func_ObjectFree=PX_Object_SliderBarFree; + pObject->Func_ObjectRender=PX_Object_SliderBarRender; + pSliderbar->Max=100; + pSliderbar->Value=0; + pSliderbar->SliderButtonLength=16; + pSliderbar->style=style; + pSliderbar->status=PX_OBJECT_SLIDERBAR_STATUS_NORMAL; + pSliderbar->Type=Type; + pSliderbar->color=PX_OBJECT_UI_DEFAULT_FONTCOLOR; + pSliderbar->BackgroundColor=PX_OBJECT_UI_DEFAULT_BACKGROUNDCOLOR; + pSliderbar->btnDownX=0; + pSliderbar->btnDownY=0; + pSliderbar->DargButtonX=0; + pSliderbar->DargButtonY=0; + + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORDOWN,PX_Object_SliderBarOnMouseLButtonDown,PX_NULL); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORMOVE,PX_Object_SliderBarOnCursorNormal,PX_NULL); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORUP,PX_Object_SliderBarOnCursorNormal,PX_NULL); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORDRAG,PX_Object_SliderBarOnCursorDrag,PX_NULL); + return pObject; +} + +PX_Object_SliderBar * PX_Object_GetSliderBar( PX_Object *Object ) +{ + if(Object->Type==PX_OBJECT_TYPE_SLIDERBAR) + return (PX_Object_SliderBar *)Object->pObject; + else + return PX_NULL; +} + +px_void PX_Object_SliderBarSetValue( PX_Object *pSliderBar,px_int Value ) +{ + PX_Object_SliderBar *SliderBar=PX_Object_GetSliderBar(pSliderBar); + if (SliderBar!=PX_NULL) + { + if (Value>SliderBar->Max) + { + Value=SliderBar->Max; + } + if (ValueMin) + { + Value=SliderBar->Min; + } + SliderBar->Value=Value; + } +} + +px_void PX_Object_SliderBarSetRange( PX_Object *pSliderBar,px_int Min,px_int Max ) +{ + PX_Object_SliderBar *SliderBar=PX_Object_GetSliderBar(pSliderBar); + if (SliderBar!=PX_NULL) + { + SliderBar->Min=Min; + SliderBar->Max=Max; + } +} + +px_int PX_Object_SliderBarGetMax( PX_Object *pSliderBar ) +{ + PX_Object_SliderBar *SliderBar=PX_Object_GetSliderBar(pSliderBar); + if (SliderBar!=PX_NULL) + { + return SliderBar->Max; + } + return 0; +} + +px_int PX_Object_SliderBarGetValue( PX_Object *pSliderBar ) +{ + PX_Object_SliderBar *SliderBar=PX_Object_GetSliderBar(pSliderBar); + if (SliderBar!=PX_NULL) + { + if (SliderBar->Value>SliderBar->Max) + { + SliderBar->Value=SliderBar->Max; + } + if (SliderBar->ValueMin) + { + SliderBar->Value=SliderBar->Min; + } + return SliderBar->Value; + } + return 0; +} + +px_void PX_Object_SliderBarRender(px_surface *psurface, PX_Object *pObject,px_uint elapsed) +{ + PX_Object_SliderBar *pSliderBar=PX_Object_GetSliderBar(pObject); + PX_Object_Event e; + px_int SliderBtnLen; + px_float Sx,Sy; + px_int Range; + px_int relValue; + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + if (pSliderBar==PX_NULL) + { + return; + } + + if (objWidth<=10) + { + return; + } + + if (objHeight<10) + { + return; + } + + Range=pSliderBar->Max-pSliderBar->Min; + SliderBtnLen=pSliderBar->SliderButtonLength; + + if (pSliderBar->Value>=pSliderBar->Max) + { + pSliderBar->Value=pSliderBar->Max; + } + + if (pSliderBar->ValueMin) + { + pSliderBar->Value=pSliderBar->Min; + } + + if (pSliderBar->Value<0) + { + pSliderBar->Value=0; + } + + //Clear + PX_SurfaceClear( + psurface, + (px_int)objx, + (px_int)objy, + (px_int)objx+(px_int)objWidth-1, + (px_int)objy+(px_int)objHeight-1, + pSliderBar->BackgroundColor + ); + + switch(pSliderBar->status) + { + case PX_OBJECT_SLIDERBAR_STATUS_NORMAL: + { + if (pObject->OnFocus) + { + PX_ObjectClearFocus(pObject); + } + if (pSliderBar->Value>pSliderBar->Max) + { + pSliderBar->Value=pSliderBar->Max; + } + if (pSliderBar->ValueMin) + { + pSliderBar->Value=pSliderBar->Min; + } + relValue=pSliderBar->Value-pSliderBar->Min; + if(pSliderBar->Type==PX_OBJECT_SLIDERBAR_TYPE_HORIZONTAL) + { + switch(pSliderBar->style) + { + case PX_OBJECT_SLIDERBAR_STYLE_LINER: + { + Sx=(objWidth-pSliderBar->SliderButtonLength)*relValue/Range; + pSliderBar->DargButtonX=Sx; + Sx+=objx; + Sy=objy; + //Draw Line + PX_GeoDrawRect( + psurface, + (px_int)objx, + (px_int)objy+(px_int)objHeight/2, + (px_int)objx+(px_int)objWidth-1, + (px_int)objy+(px_int)objHeight/2, + pSliderBar->color + ); + //Draw Slider button + PX_GeoDrawRect(psurface,(px_int)Sx,(px_int)Sy,(px_int)(Sx+SliderBtnLen-1),(px_int)(Sy+objHeight-1),pSliderBar->color); + } + break; + case PX_OBJECT_SLIDERBAR_STYLE_BOX: + { + //draw border + PX_GeoDrawBorder(psurface,(px_int)objx,(px_int)objy,(px_int)objx+(px_int)objWidth-1,(px_int)objy+(px_int)objHeight-1,1,pSliderBar->color); + Sx=((objWidth-pSliderBar->SliderButtonLength)*(1.0f)*relValue/Range); + pSliderBar->DargButtonX=Sx; + Sx+=SliderBtnLen/2; + //draw slider bar + PX_GeoDrawRect(psurface,(px_int)(objx+Sx-SliderBtnLen/2+2),(px_int)(objy+2),(px_int)(objx+Sx-SliderBtnLen/2+SliderBtnLen-3),(px_int)(objy+objHeight-3),pSliderBar->color); + } + break; + } + + + } + + if (pSliderBar->Type==PX_OBJECT_SLIDERBAR_TYPE_VERTICAL) + { + switch(pSliderBar->style) + { + case PX_OBJECT_SLIDERBAR_STYLE_LINER: + { + Sx=objx; + Sy=(objHeight-pSliderBar->SliderButtonLength)*relValue/Range; + pSliderBar->DargButtonY=Sy; + Sy+=(px_int)objy; + //Draw Line + PX_GeoDrawRect( + psurface, + (px_int)objx+(px_int)objWidth/2, + (px_int)objy, + (px_int)objx+(px_int)objWidth/2, + (px_int)objy+(px_int)objHeight-1, + pSliderBar->color + ); + //Draw Slider button + PX_GeoDrawRect(psurface,(px_int)Sx,(px_int)Sy,(px_int)(Sx+objWidth-1),(px_int)(Sy+SliderBtnLen-1),pSliderBar->color); + } + break; + case PX_OBJECT_SLIDERBAR_STYLE_BOX: + { + //draw border + PX_GeoDrawBorder(psurface,(px_int)objx,(px_int)objy,(px_int)objx+(px_int)objWidth-1,(px_int)objy+(px_int)objHeight-1,1,pSliderBar->color); + Sy=((objHeight-pSliderBar->SliderButtonLength)*(1.0f)*relValue/Range); + pSliderBar->DargButtonY=Sy; + Sy+=SliderBtnLen/2; + //draw slider bar + PX_GeoDrawRect(psurface,(px_int)objx+2,(px_int)(objy+Sy-SliderBtnLen/2+2),(px_int)(objx+objWidth-1-2),(px_int)(objy+Sy+SliderBtnLen/2-3),pSliderBar->color); + } + break; + } + + } + } + break; + case PX_OBJECT_SLIDERBAR_STATUS_ONDRAG: + { + if (!pObject->OnFocus) + { + PX_ObjectSetFocus(pObject); + } + if(pSliderBar->Type==PX_OBJECT_SLIDERBAR_TYPE_HORIZONTAL) + { + switch(pSliderBar->style) + { + case PX_OBJECT_SLIDERBAR_STYLE_LINER: + { + Sx=pSliderBar->DargButtonX; + Sy=objy; + + pSliderBar->Value=(px_int)(pSliderBar->Min+Range*(Sx)/(objWidth-pSliderBar->SliderButtonLength)); + if (pSliderBar->Value>pSliderBar->Max) + { + pSliderBar->Value=pSliderBar->Max; + } + if (pSliderBar->ValueMin) + { + pSliderBar->Value=pSliderBar->Min; + } + //Draw Line + PX_GeoDrawRect( + psurface, + (px_int)objx, + (px_int)objy+(px_int)objHeight/2, + (px_int)objx+(px_int)objWidth-1, + (px_int)objy+(px_int)objHeight/2, + pSliderBar->color + ); + //Draw Slider button + PX_GeoDrawRect(psurface,(px_int)(objx+Sx),(px_int)Sy,(px_int)(objx+Sx+SliderBtnLen-1),(px_int)(Sy+objHeight-1),pSliderBar->color); + } + break; + case PX_OBJECT_SLIDERBAR_STYLE_BOX: + { + //draw border + PX_GeoDrawBorder(psurface,(px_int)objx,(px_int)objy,(px_int)objx+(px_int)objWidth-1,(px_int)objy+(px_int)objHeight-1,1,pSliderBar->color); + + Sx=pSliderBar->DargButtonX; + + pSliderBar->Value=(px_int)(pSliderBar->Min+Range*(Sx)/(objWidth-pSliderBar->SliderButtonLength)); + if (pSliderBar->Value>pSliderBar->Max) + { + pSliderBar->Value=pSliderBar->Max; + } + if (pSliderBar->ValueMin) + { + pSliderBar->Value=pSliderBar->Min; + } + Sx+=SliderBtnLen/2; + //draw slider bar + PX_GeoDrawRect(psurface,(px_int)(objx+Sx-SliderBtnLen/2+2),(px_int)objy+2,(px_int)(objx+Sx+SliderBtnLen/2-3),(px_int)(objy+objHeight-3),pSliderBar->color); + } + break; + } + + + } + + if (pSliderBar->Type==PX_OBJECT_SLIDERBAR_TYPE_VERTICAL) + { + switch(pSliderBar->style) + { + case PX_OBJECT_SLIDERBAR_STYLE_LINER: + { + pSliderBar->Value=(px_int)(pSliderBar->Min+Range*(pSliderBar->DargButtonY)/(objHeight-pSliderBar->SliderButtonLength)); + if (pSliderBar->Value>pSliderBar->Max) + { + pSliderBar->Value=pSliderBar->Max; + } + if (pSliderBar->ValueMin) + { + pSliderBar->Value=pSliderBar->Min; + } + + Sy=pSliderBar->DargButtonY+objy; + Sx=objx; + + + + //Draw Line + PX_GeoDrawRect( + psurface, + (px_int)objx+(px_int)objWidth/2, + (px_int)objy, + (px_int)objx+(px_int)objWidth/2, + (px_int)objy+(px_int)objHeight-1, + pSliderBar->color + ); + //Draw Slider button + PX_GeoDrawRect(psurface,(px_int)Sx,(px_int)(Sy),(px_int)(Sx+objWidth-1),(px_int)(Sy+SliderBtnLen-1),pSliderBar->color); + } + break; + case PX_OBJECT_SLIDERBAR_STYLE_BOX: + { + //draw border + PX_GeoDrawBorder(psurface,(px_int)objx,(px_int)objy,(px_int)objx+(px_int)objWidth-1,(px_int)objy+(px_int)objHeight-1,1,pSliderBar->color); + + pSliderBar->Value=(px_int)(pSliderBar->Min+Range*(pSliderBar->DargButtonY)/(objHeight-pSliderBar->SliderButtonLength)); + if (pSliderBar->Value>pSliderBar->Max) + { + pSliderBar->Value=pSliderBar->Max; + } + if (pSliderBar->ValueMin) + { + pSliderBar->Value=pSliderBar->Min; + } + + Sy=pSliderBar->DargButtonY; + Sx=objx; + Sy+=SliderBtnLen/2; + + + PX_GeoDrawRect(psurface,(px_int)objx+2,(px_int)(objy+Sy-SliderBtnLen/2+2),(px_int)(objx+objWidth-1-2),(px_int)(objy+Sy+SliderBtnLen/2-3),pSliderBar->color); + } + break; + } + + } + + if (pSliderBar->lastValue!=pSliderBar->Value) + { + e.Event=PX_OBJECT_EVENT_VALUECHANGED; + e.Param_uint[0]=0; + e.Param_uint[1]=0; + e.Param_uint[2]=0; + e.Param_uint[3]=0; + pSliderBar->lastValue=pSliderBar->Value; + PX_ObjectExecuteEvent(pObject,e); + } + + } + break; + } + + if (pSliderBar->Value>=pSliderBar->Max) + { + pSliderBar->Value=pSliderBar->Max; + } + + if (pSliderBar->Value<0) + { + pSliderBar->Value=0; + } + +} + +px_void PX_Object_SliderBarSetBackgroundColor(PX_Object *pSliderBar,px_color color) +{ + PX_Object_SliderBar *SliderBar=PX_Object_GetSliderBar(pSliderBar); + if (SliderBar!=PX_NULL) + { + SliderBar->BackgroundColor=color; + } +} + +px_void PX_Object_SliderBarFree( PX_Object *pSliderBar ) +{ + +} + +px_void PX_Object_SliderBarSetColor(PX_Object *pSliderBar,px_color color) +{ + PX_Object_SliderBar *SliderBar=PX_Object_GetSliderBar(pSliderBar); + if (SliderBar!=PX_NULL) + { + SliderBar->color=color; + } +} + +px_void PX_Object_SliderBarSetSliderButtonLength(PX_Object *pSliderBar,px_int length) +{ + PX_Object_SliderBar *SliderBar=PX_Object_GetSliderBar(pSliderBar); + if (SliderBar!=PX_NULL) + { + SliderBar->SliderButtonLength=length; + } +} + diff --git a/lib/PainterEngine/kernel/PX_Object_Sliderbar.h b/lib/PainterEngine/kernel/PX_Object_Sliderbar.h new file mode 100644 index 0000000000000000000000000000000000000000..a22798d8cd94a1bcb27e142d2c5aca4bbb912cf1 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_Sliderbar.h @@ -0,0 +1,56 @@ +#ifndef PX_OBJECT_SLIDERBAR_H +#define PX_OBJECT_SLIDERBAR_H +#include "PX_Object.h" + + +typedef enum +{ + PX_OBJECT_SLIDERBAR_TYPE_HORIZONTAL , + PX_OBJECT_SLIDERBAR_TYPE_VERTICAL , +}PX_OBJECT_SLIDERBAR_TYPE; + +typedef enum +{ + PX_OBJECT_SLIDERBAR_STYLE_BOX , + PX_OBJECT_SLIDERBAR_STYLE_LINER , +}PX_OBJECT_SLIDERBAR_STYLE; + +typedef enum +{ + PX_OBJECT_SLIDERBAR_STATUS_ONDRAG , + PX_OBJECT_SLIDERBAR_STATUS_NORMAL , +}PX_OBJECT_SLIDERBAR_STATUS; + + +typedef struct +{ + PX_OBJECT_SLIDERBAR_TYPE Type; + PX_OBJECT_SLIDERBAR_STYLE style; + PX_OBJECT_SLIDERBAR_STATUS status; + px_float btnDownX,btnDownY; + px_float DargButtonX,DargButtonY; + px_int Min; + px_int Max; + px_int lastValue; + px_int Value; + px_int SliderButtonLength; + px_color color; + px_color BackgroundColor; +}PX_Object_SliderBar; + +PX_Object *PX_Object_SliderBarCreate(px_memorypool *mp,PX_Object *Parent,px_int x,px_int y,px_int Width,px_int Height,PX_OBJECT_SLIDERBAR_TYPE Type,PX_OBJECT_SLIDERBAR_STYLE style); +PX_Object_SliderBar *PX_Object_GetSliderBar(PX_Object *Object); +px_void PX_Object_SliderBarSetValue(PX_Object *pSliderBar,px_int Value); +px_void PX_Object_SliderBarSetRange(PX_Object *pSliderBar,px_int Min,px_int Max); +px_int PX_Object_SliderBarGetMax( PX_Object *pSliderBar ); +px_int PX_Object_SliderBarGetValue(PX_Object *pSliderBar); +px_void PX_Object_SliderBarRender(px_surface *psurface,PX_Object *pSliderBar,px_uint elapsed); +px_void PX_Object_SliderBarSetBackgroundColor(PX_Object *pSliderBar,px_color color); +px_void PX_Object_SliderBarFree(PX_Object *pSliderBar); +px_void PX_Object_SliderBarSetColor(PX_Object *pSliderBar,px_color color); +px_void PX_Object_SliderBarSetSliderButtonLength(PX_Object *pSliderBar,px_int length); + + + +#endif + diff --git a/lib/PainterEngine/kernel/PX_Object_TransformAdapter.c b/lib/PainterEngine/kernel/PX_Object_TransformAdapter.c new file mode 100644 index 0000000000000000000000000000000000000000..04ea1ca242cd429e3b1edad245e6febf08addfaa --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_TransformAdapter.c @@ -0,0 +1,200 @@ +#include "PX_Object_TransformAdapter.h" + +PX_Object_TransformAdapter * PX_Object_GetTransformAdapter(PX_Object *Object) +{ + if (Object->Type==PX_OBJECT_TYPE_TRANSFORMADAPTER) + { + return (PX_Object_TransformAdapter *)Object->pObject; + } + return PX_NULL; +} + +px_void PX_Object_TransformAdapterRender(px_surface *rendersurface,PX_Object *pObject,px_dword elapsed) +{ + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + PX_Object_TransformAdapter *pTransformAdapter=PX_Object_GetTransformAdapter(pObject); + px_point2D vres,vnow; + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + ////////////////////////////////////////////////////////////////////////// + //update rotation & stretch + vres=PX_Point2DSub(pTransformAdapter->sourceAdaptPoint,PX_POINT2D(pObject->x,pObject->y)); + vnow=PX_Point2DRotate(vres,pTransformAdapter->endAngle-pTransformAdapter->startAngle); + + + + if (pTransformAdapter->mode==PX_OBJECT_TRANSFORMADAPTER_MODE_ANY||pTransformAdapter->mode==PX_OBJECT_TRANSFORMADAPTER_MODE_ROTATION) + { + //draw circle + px_color rendercolor=pTransformAdapter->color; + rendercolor._argb.a/=4; + PX_GeoDrawCircle(rendersurface,(px_int)pObject->x,(px_int)pObject->y,(px_int)PX_Point2DMod(vres),1,rendercolor); + } + + if (pTransformAdapter->mode==PX_OBJECT_TRANSFORMADAPTER_MODE_ANY||pTransformAdapter->mode==PX_OBJECT_TRANSFORMADAPTER_MODE_STRETCH) + { + //draw line + px_color rendercolor=pTransformAdapter->color; + rendercolor._argb.a/=4; + + PX_GeoDrawLine(rendersurface,(px_int)pObject->x,(px_int)pObject->y,(px_int)(vres.x+pObject->x),(px_int)(vres.y+pObject->y),1,rendercolor); + PX_GeoDrawLine(rendersurface,(px_int)pObject->x,(px_int)pObject->y,(px_int)(vnow.x+pObject->x),(px_int)(vnow.y+pObject->y),1,rendercolor); + } + + //draw point + vnow=PX_Point2DMul(vnow,pTransformAdapter->stretch); + PX_GeoDrawSector(rendersurface,(px_int)objx,(px_int)objy,(px_int)PX_Point2DMod(vnow),1,PX_COLOR(16,0,255,255),(px_int)pTransformAdapter->startAngle,(px_int)pTransformAdapter->endAngle); + + PX_GeoDrawSolidCircle(rendersurface,(px_int)(vnow.x+pObject->x),(px_int)(vnow.y+pObject->y),5,pTransformAdapter->color); + if (pTransformAdapter->bSelect) + { + PX_GeoDrawCircle(rendersurface,(px_int)(vnow.x+pObject->x),(px_int)(vnow.y+pObject->y),8,1,pTransformAdapter->color); + } + PX_GeoDrawCircle(rendersurface,(px_int)pObject->x,(px_int)pObject->y,(px_int)PX_Point2DMod(vnow),1,pTransformAdapter->color); + PX_GeoDrawLine(rendersurface,(px_int)pObject->x,(px_int)pObject->y,(px_int)(vnow.x+pObject->x),(px_int)(vnow.y+pObject->y),1,pTransformAdapter->color); + + do + { + px_char content[32]; + PX_sprintf2(content,sizeof(content),"rotation:%1.1 stretch:%2.2",PX_STRINGFORMAT_FLOAT(pTransformAdapter->endAngle-pTransformAdapter->startAngle),PX_STRINGFORMAT_FLOAT(pTransformAdapter->stretch)); + PX_FontDrawText(rendersurface,(px_int)(vnow.x+pObject->x),(px_int)(vnow.y+pObject->y-2),PX_ALIGN_MIDBOTTOM,content,pTransformAdapter->fontColor); + } while (0); + + +} + +px_void PX_Object_TransformAdapterOnCursorDown(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + px_float objx,objy,objWidth,objHeight; + + px_float inheritX,inheritY,x,y; + PX_Object_TransformAdapter *pTransformAdapter=PX_Object_GetTransformAdapter(pObject); + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + x=PX_Object_Event_GetCursorX(e); + y=PX_Object_Event_GetCursorY(e); + + do + { + px_point2D vres,vnow; + vres=PX_Point2DSub(pTransformAdapter->sourceAdaptPoint,PX_POINT2D(pObject->x,pObject->y)); + vnow=PX_Point2DRotate(vres,pTransformAdapter->endAngle-pTransformAdapter->startAngle); + vnow=PX_Point2DMul(vnow,pTransformAdapter->stretch); + vnow.x+=pObject->x; + vnow.y+=pObject->y; + if (PX_isPoint2DInCircle(PX_POINT2D(x,y),vnow,5)) + { + pTransformAdapter->bSelect=PX_TRUE; + } + else + { + pTransformAdapter->bSelect=PX_FALSE; + } + } while (0); +} + + +px_void PX_Object_TransformAdapterOnCursorDrag(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + px_float objx,objy,objWidth,objHeight; + px_point2D vres; + px_float inheritX,inheritY,x,y; + PX_Object_TransformAdapter *pTransformAdapter=PX_Object_GetTransformAdapter(pObject); + + if(pTransformAdapter->bSelect) + { + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + x=PX_Object_Event_GetCursorX(e); + y=PX_Object_Event_GetCursorY(e); + + if (pTransformAdapter->mode==PX_OBJECT_TRANSFORMADAPTER_MODE_ANY||pTransformAdapter->mode==PX_OBJECT_TRANSFORMADAPTER_MODE_ROTATION) + { + px_float angle=(px_float)PX_RadianToAngle(PX_atan2(y-objy*1.0,x-objx*1.0)); + px_float lastAngleMod=pTransformAdapter->endAngle; + px_float inc; + px_int round=(px_int)(lastAngleMod/360); + lastAngleMod=lastAngleMod-round*360; + + inc=angle-lastAngleMod; + if (inc>180) + { + inc-=360; + } + if (inc<-180) + { + inc+=360; + } + pTransformAdapter->endAngle+=inc; + } + if (pTransformAdapter->mode==PX_OBJECT_TRANSFORMADAPTER_MODE_ANY||pTransformAdapter->mode==PX_OBJECT_TRANSFORMADAPTER_MODE_STRETCH) + { + vres=PX_POINT2D(pObject->x-x,pObject->y-y); + pTransformAdapter->stretch=PX_Point2DMod(vres)/PX_Point2DMod(PX_Point2DSub(pTransformAdapter->sourceAdaptPoint,PX_POINT2D(pObject->x,pObject->y))); + } + + PX_ObjectExecuteEvent(pObject,PX_OBJECT_BUILD_EVENT(PX_OBJECT_EVENT_VALUECHANGED)); + } +} + + +PX_Object * PX_Object_TransformAdapterCreate(px_memorypool *mp, PX_Object *Parent,px_int x,px_int y,px_point2D sourceAdaptPoint) +{ + PX_Object *pObject; + PX_Object_TransformAdapter TransformAdapter; + PX_memset(&TransformAdapter,0,sizeof(TransformAdapter)); + TransformAdapter.color=PX_COLOR(255,255,64,64); + TransformAdapter.fontColor=PX_COLOR(255,255,0,0); + TransformAdapter.stretch=1; + TransformAdapter.currentAdaptPoint=sourceAdaptPoint; + TransformAdapter.sourceAdaptPoint=sourceAdaptPoint; + TransformAdapter.startAngle=(px_float)PX_RadianToAngle(PX_atan2(sourceAdaptPoint.y-y*1.0,sourceAdaptPoint.x-x*1.0)); + TransformAdapter.endAngle=TransformAdapter.startAngle; + pObject=PX_ObjectCreateEx(mp,Parent,(px_float)x,(px_float)y,0,0,0,0,PX_OBJECT_TYPE_TRANSFORMADAPTER,0,PX_Object_TransformAdapterRender,0,&TransformAdapter,sizeof(TransformAdapter)); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORDOWN,PX_Object_TransformAdapterOnCursorDown,PX_NULL); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_CURSORDRAG,PX_Object_TransformAdapterOnCursorDrag,PX_NULL); + return pObject; +} + +px_void PX_Object_TransformAdapterSetMode(PX_Object *Object,PX_OBJECT_TRANSFORMADAPTER_MODE mode) +{ + PX_Object_GetTransformAdapter(Object)->mode=mode; +} + +px_float PX_Object_TransformAdapterGetRotation(PX_Object *Object) +{ + return PX_Object_GetTransformAdapter(Object)->endAngle-PX_Object_GetTransformAdapter(Object)->startAngle; +} + +px_float PX_Object_TransformAdapterGetStretch(PX_Object *Object) +{ + return PX_Object_GetTransformAdapter(Object)->stretch; +} + +px_void PX_Object_TransformAdapterResetState(PX_Object *pObject,px_float x,px_float y,px_point2D sourceAdaptPoint,px_float rotation,px_float stretch) +{ + PX_Object_TransformAdapter *pTransformAdapter=PX_Object_GetTransformAdapter(pObject); + pObject->x=x; + pObject->y=y; + pTransformAdapter->startAngle=(px_float)PX_RadianToAngle(PX_atan2(sourceAdaptPoint.y-y*1.0,sourceAdaptPoint.x-x*1.0)); + pTransformAdapter->endAngle=pTransformAdapter->startAngle+rotation; + pTransformAdapter->sourceAdaptPoint=sourceAdaptPoint; + pTransformAdapter->stretch=stretch; +} + diff --git a/lib/PainterEngine/kernel/PX_Object_TransformAdapter.h b/lib/PainterEngine/kernel/PX_Object_TransformAdapter.h new file mode 100644 index 0000000000000000000000000000000000000000..429180a0159dd5e1b386eb90b7f44d6385b44796 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_TransformAdapter.h @@ -0,0 +1,30 @@ +#ifndef PX_OBJECT_TRANSFORMADAPTER_H +#define PX_OBJECT_TRANSFORMADAPTER_H +#include "PX_Object.h" + +typedef enum +{ + PX_OBJECT_TRANSFORMADAPTER_MODE_ANY, + PX_OBJECT_TRANSFORMADAPTER_MODE_ROTATION, + PX_OBJECT_TRANSFORMADAPTER_MODE_STRETCH +}PX_OBJECT_TRANSFORMADAPTER_MODE; + + +typedef struct +{ + px_point2D sourceAdaptPoint,currentAdaptPoint,cursor; + px_float startAngle; + px_float endAngle; + px_float stretch; + px_bool bSelect; + px_color color,fontColor; + PX_OBJECT_TRANSFORMADAPTER_MODE mode; +}PX_Object_TransformAdapter; + +PX_Object_TransformAdapter *PX_Object_GetTransformAdapter(PX_Object *Object); +PX_Object * PX_Object_TransformAdapterCreate(px_memorypool *mp, PX_Object *Parent,px_int x,px_int y,px_point2D sourceAdaptPoint); +px_void PX_Object_TransformAdapterSetMode(PX_Object *Object,PX_OBJECT_TRANSFORMADAPTER_MODE mode); +px_float PX_Object_TransformAdapterGetRotation(PX_Object *Object); +px_float PX_Object_TransformAdapterGetStretch(PX_Object *Object); +px_void PX_Object_TransformAdapterResetState(PX_Object *pObject,px_float x,px_float y,px_point2D sourceAdaptPoint,px_float rotation,px_float stretch); +#endif diff --git a/lib/PainterEngine/kernel/PX_Object_VarBox.c b/lib/PainterEngine/kernel/PX_Object_VarBox.c new file mode 100644 index 0000000000000000000000000000000000000000..40e1281327b1a1c0f3af2d99755313cd489b8089 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_VarBox.c @@ -0,0 +1,164 @@ +#include "PX_Object_VarBox.h" + + +PX_Object_VarBox* PX_Object_GetVarBox(PX_Object* pObject) +{ + if (pObject->Type==PX_OBJECT_TYPE_IPBOX) + { + return PX_ObjectGetDesc(PX_Object_VarBox, pObject); + } + return PX_NULL; +} + +px_void PX_Object_VarBoxOnConfirm(PX_Object* pObject, PX_Object_Event e, px_void* ptr) +{ + PX_Object_VarBox* pdesc = PX_ObjectGetDesc(PX_Object_VarBox, ((PX_Object*)ptr)); + if (!*PX_Object_VariousGetText(pdesc->various_name)) + { + return; + } + if (!*PX_Object_VariousGetText(pdesc->various_address)) + { + return; + } + if (PX_strlen(PX_Object_VariousGetText(pdesc->various_address))>16) + { + return; + } + if (!*PX_Object_VariousGetText(pdesc->various_size)) + { + return; + } + if (PX_atoi(PX_Object_VariousGetText(pdesc->various_size))==0) + { + return; + } + + PX_ObjectExecuteEvent(((PX_Object*)ptr), PX_OBJECT_BUILD_EVENT(PX_OBJECT_EVENT_EXECUTE)); + PX_Object_VarBoxClose((PX_Object*)ptr); +} + +px_void PX_Object_VarBoxOnKeyDown(PX_Object* pObject, PX_Object_Event e, px_void* ptr) +{ + if (e.Event == PX_OBJECT_EVENT_KEYDOWN && PX_Object_Event_GetKeyDown(e) == '\r') + { + PX_Object_VarBoxOnConfirm(pObject, PX_OBJECT_BUILD_EVENT(PX_OBJECT_EVENT_EXECUTE), ptr); + } +} + + +px_void PX_Object_VarBoxOnCancel(PX_Object* pObject, PX_Object_Event e, px_void* ptr) +{ + PX_Object_VarBoxClose((PX_Object*)ptr); +} + +px_void PX_Object_VarBoxOnTypeChanged(PX_Object* pObject, PX_Object_Event e, px_void* ptr) +{ + PX_Object_VarBox* pDesc = (PX_Object_VarBox*)ptr; + switch (PX_Object_SelectBarGetCurrentIndex(pObject)) + { + case 0: + case 4: + PX_Object_VariousSetInt(pDesc->various_size, 1); + pDesc->various_size->Enabled = PX_FALSE; + pDesc->various_size->Visible = PX_TRUE; + break; + case 1: + case 5: + PX_Object_VariousSetInt(pDesc->various_size, 2); + pDesc->various_size->Enabled = PX_FALSE; + pDesc->various_size->Visible = PX_TRUE; + break; + case 2: + case 6: + case 8: + PX_Object_VariousSetInt(pDesc->various_size, 4); + pDesc->various_size->Enabled = PX_FALSE; + pDesc->various_size->Visible = PX_TRUE; + break; + case 3: + case 7: + case 9: + PX_Object_VariousSetInt(pDesc->various_size, 8); + pDesc->various_size->Enabled = PX_FALSE; + pDesc->various_size->Visible = PX_TRUE; + break; + case 10: + case 11: + PX_Object_VariousSetInt(pDesc->various_size, 32); + pDesc->various_size->Enabled = PX_TRUE; + pDesc->various_size->Visible = PX_TRUE; + break; + case 12: + PX_Object_VariousSetInt(pDesc->various_size, 1); + pDesc->various_size->Enabled = PX_FALSE; + pDesc->various_size->Visible = PX_FALSE; + break; + default: + break; + } +} + +PX_Object* PX_Object_VarBoxCreate(px_memorypool* mp, PX_Object* Parent, int x, int y, int width, int height, const px_char title[], PX_FontModule* fontmodule) +{ + PX_Object_VarBox desc, * pdesc; + PX_Object* pObject; + pObject = PX_ObjectCreateEx(mp, Parent, (px_float)x, (px_float)y, 0, (px_float)width, (px_float)height, 0, PX_OBJECT_TYPE_IPBOX, PX_NULL, PX_NULL, PX_NULL, &desc, sizeof(desc)); + pdesc = PX_ObjectGetDesc(PX_Object_VarBox, pObject); + pdesc->widget = PX_Object_WidgetCreate(mp, pObject, 0, 0, width, height, "", fontmodule); + PX_Object_WidgetShowHideCloseButton(pdesc->widget, PX_FALSE); + pdesc->various_name = PX_Object_VariousCreate(mp, pdesc->widget, width / 2 - 128, 32, 256, 32, "Name:",PX_OBJECT_VARIOUS_TYPE_EDIT, fontmodule); + PX_Object_VariousSetEditStyle(pdesc->various_name, PX_OBJECT_VARIOUS_EDIT_TYPE_STRING); + pdesc->various_address = PX_Object_VariousCreate(mp, pdesc->widget, width / 2 - 128, 72, 256, 32, "Address:", PX_OBJECT_VARIOUS_TYPE_EDIT, fontmodule); + PX_Object_VariousSetEditStyle(pdesc->various_address, PX_OBJECT_VARIOUS_EDIT_TYPE_HEX); + pdesc->various_size = PX_Object_VariousCreate(mp, pdesc->widget, width / 2 - 128, 112, 256, 32, "Size:", PX_OBJECT_VARIOUS_TYPE_EDIT, fontmodule); + PX_Object_VariousSetEditStyle(pdesc->various_size, PX_OBJECT_VARIOUS_EDIT_TYPE_INT); + PX_Object_VariousSetInt(pdesc->various_size, 1); + pdesc->various_size->Enabled = PX_FALSE; + pdesc->selectbar_type = PX_Object_SelectBarCreate(mp, pdesc->widget, width / 2 - 128, 152, 256, 32, fontmodule); + PX_Object_SelectBarSetMaxDisplayCount(pdesc->selectbar_type, 5); + + PX_Object_SelectBarAddItem(pdesc->selectbar_type, "Type: int8(LE)"); //0 + PX_Object_SelectBarAddItem(pdesc->selectbar_type, "Type: int16(LE)"); //1 + PX_Object_SelectBarAddItem(pdesc->selectbar_type, "Type: int32(LE)"); //2 + PX_Object_SelectBarAddItem(pdesc->selectbar_type, "Type: int64(LE)"); //3 + PX_Object_SelectBarAddItem(pdesc->selectbar_type, "Type: uint8(LE)"); //4 + PX_Object_SelectBarAddItem(pdesc->selectbar_type, "Type: uint16(LE)"); //5 + PX_Object_SelectBarAddItem(pdesc->selectbar_type, "Type: uint32(LE)"); //6 + PX_Object_SelectBarAddItem(pdesc->selectbar_type, "Type: uint64(LE)"); //7 + PX_Object_SelectBarAddItem(pdesc->selectbar_type, "Type: float32(LE IEEE754)"); //8 + PX_Object_SelectBarAddItem(pdesc->selectbar_type, "Type: double64(LE IEEE754)"); //9 + PX_Object_SelectBarAddItem(pdesc->selectbar_type, "Type: string"); //10 + PX_Object_SelectBarAddItem(pdesc->selectbar_type, "Type: hexadecimal"); //11 + PX_Object_SelectBarAddItem(pdesc->selectbar_type, "Type: boolean"); //12 + PX_ObjectRegisterEvent(pdesc->selectbar_type, PX_OBJECT_EVENT_VALUECHANGED, PX_Object_VarBoxOnTypeChanged, pdesc); + + pdesc->checkbox_readonly = PX_Object_CheckBoxCreate(mp, pdesc->widget, width / 2 - 128, 192, 256, 32, "Read Only", fontmodule); + pdesc->btn_ok = PX_Object_PushButtonCreate(mp, pdesc->widget, width - 256, height - 68, 96, 32, "OK", fontmodule); + pdesc->btn_close = PX_Object_PushButtonCreate(mp, pdesc->widget, width - 128, height - 68, 96, 32, "Cancel", fontmodule); + + PX_ObjectRegisterEvent(pdesc->btn_ok, PX_OBJECT_EVENT_EXECUTE, PX_Object_VarBoxOnConfirm, pObject); + PX_ObjectRegisterEvent(pdesc->btn_close, PX_OBJECT_EVENT_EXECUTE, PX_Object_VarBoxOnCancel, pObject); + PX_ObjectRegisterEvent(pdesc->widget, PX_OBJECT_EVENT_KEYDOWN, PX_Object_VarBoxOnKeyDown, pObject); + pdesc->widget->Visible = PX_TRUE; + pObject->Visible = PX_FALSE; + return pObject; +} + +px_void PX_Object_VarBoxShow(PX_Object* pObject) +{ + pObject->Visible = PX_TRUE; + PX_ObjectSetFocus(pObject); +} + +px_void PX_Object_VarBoxClose(PX_Object* pObject) +{ + pObject->Visible = PX_FALSE; + PX_ObjectClearFocus(pObject); +} + +px_void PX_Object_VarBoxHide(PX_Object* pObject) +{ + pObject->Visible = PX_FALSE; + PX_ObjectClearFocus(pObject); +} \ No newline at end of file diff --git a/lib/PainterEngine/kernel/PX_Object_VarBox.h b/lib/PainterEngine/kernel/PX_Object_VarBox.h new file mode 100644 index 0000000000000000000000000000000000000000..394cdf26ca0ae2cc1e39c64d2eccb5d594664ad6 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_VarBox.h @@ -0,0 +1,23 @@ +#ifndef PX_OBJECT_VARBOX_H +#define PX_OBJECT_VARBOX_H +#include "PX_Object.h" + + +typedef struct +{ + PX_Object *widget; + PX_Object* various_name; + PX_Object* various_address; + PX_Object* various_size; + PX_Object* selectbar_type; + PX_Object* checkbox_readonly; + PX_Object *btn_close; + PX_Object *btn_ok; +}PX_Object_VarBox; + +PX_Object_VarBox* PX_Object_GetVarBox( PX_Object *Object ); +PX_Object * PX_Object_VarBoxCreate(px_memorypool *mp,PX_Object *Parent,int x,int y,int width,int height,const px_char title[],PX_FontModule *fontmodule); +px_void PX_Object_VarBoxShow(PX_Object *pObject); +px_void PX_Object_VarBoxClose(PX_Object* pObject); +#endif + diff --git a/lib/PainterEngine/kernel/PX_Object_Various.c b/lib/PainterEngine/kernel/PX_Object_Various.c new file mode 100644 index 0000000000000000000000000000000000000000..ce4f3cf73786f323c162f66967c33b19a962a183 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_Various.c @@ -0,0 +1,363 @@ +#include "PX_Object_Various.h" + +px_void PX_Object_VariousOnEditChange(PX_Object* pEObject, PX_Object_Event e, px_void* ptr) +{ + PX_Object* pObject = (PX_Object*)ptr; + PX_ObjectExecuteEvent(pObject, PX_OBJECT_BUILD_EVENT(PX_OBJECT_EVENT_VALUECHANGED)); +} + + +px_void PX_Object_VariousRender(px_surface *psurface,PX_Object* pObject,px_dword elapsed) +{ + PX_Object_Various* pDesc = PX_ObjectGetDesc(PX_Object_Various, pObject); + + pDesc->label->Width = pObject->Width * 0.25f; + if (pDesc->label->Widthlabel)+16) + { + pDesc->label->Width = PX_Object_LabelGetTextRenderWidth(pDesc->label) +16.f; + } + pDesc->label->Height = pObject->Height; + + + + + pDesc->various->Width = pObject->Width -pDesc->label->Width; + pDesc->various->Height = pObject->Height; + pDesc->various->x = pDesc->label->Width; + + PX_ObjectSetEnabled(pDesc->various, pDesc->editable); + +} + +px_void PX_Object_VariousEditSetMaxLength(PX_Object* pObject, px_int len) +{ + PX_Object_Various* pDesc = PX_ObjectGetDesc(PX_Object_Various, pObject); + if (pDesc->type==PX_OBJECT_VARIOUS_TYPE_EDIT) + { + PX_Object_EditSetMaxTextLength(pDesc->various, len); + } + +} + +PX_Object* PX_Object_VariousCreate(px_memorypool* mp, PX_Object* Parent, px_int x, px_int y, px_int Width, px_int Height, const px_char* Text, PX_OBJECT_VARIOUS_TYPE type, PX_FontModule* fm) +{ + PX_Object_Various var,*pdesc; + PX_Object* pObject; + PX_zeromemory(&var,sizeof(var)); + pObject=PX_ObjectCreateEx(mp, Parent, (px_float)x, (px_float)y, 0, (px_float)Width, (px_float)Height, 0,PX_OBJECT_TYPE_VARIOUS,PX_NULL, PX_Object_VariousRender,PX_NULL,&var,sizeof(var)); + pdesc = PX_ObjectGetDesc(PX_Object_Various, pObject); + pdesc->label = PX_Object_LabelCreate(mp, pObject, 0, 0, 1, 1, Text, fm, PX_OBJECT_UI_DEFAULT_FONTCOLOR); + pdesc->editable = PX_TRUE; + pdesc->type = type; + switch (type) + { + case PX_OBJECT_VARIOUS_TYPE_EDIT: + { + pdesc->various = PX_Object_EditCreate(mp, pObject, 0, 0, 1, 1, fm); + PX_ObjectRegisterEvent(pdesc->various, PX_OBJECT_EVENT_VALUECHANGED, PX_Object_VariousOnEditChange, pObject); + } + break; + case PX_OBJECT_VARIOUS_TYPE_LABEL: + { + pdesc->various = PX_Object_LabelCreate(mp, pObject, 0, 0, 1, 1,"",fm, PX_OBJECT_UI_DEFAULT_FONTCOLOR); + } + break; + case PX_OBJECT_VARIOUS_TYPE_SELECTBAR: + { + pdesc->various = PX_Object_SelectBarCreate(mp, pObject, 0, 0, 1, 1,fm); + PX_ObjectRegisterEvent(pdesc->various, PX_OBJECT_EVENT_VALUECHANGED, PX_Object_VariousOnEditChange, pObject); + } + break; + default: + break; + } + + return pObject; +} + +PX_Object_Various* PX_Object_GetVarious(PX_Object* pObject) +{ + if (pObject->Type== PX_OBJECT_TYPE_VARIOUS) + { + return PX_ObjectGetDesc(PX_Object_Various, pObject); + } + return PX_NULL; +} + +px_void PX_Object_VariousSetEditStyle(PX_Object* pObject,PX_OBJECT_VARIOUS_EIDT_TYPE type) +{ + if (pObject->Type != PX_OBJECT_TYPE_VARIOUS) + { + PX_ASSERT(); + return; + } + else + { + PX_Object_Various* pDesc = PX_ObjectGetDesc(PX_Object_Various, pObject); + if (pDesc->type==PX_OBJECT_VARIOUS_TYPE_EDIT) + { + switch (type) + { + case PX_OBJECT_VARIOUS_EDIT_TYPE_INT: + { + PX_Object_EditSetLimit(pDesc->various, "-01234567890"); + } + break; + case PX_OBJECT_VARIOUS_EDIT_TYPE_FLOAT: + { + PX_Object_EditSetLimit(pDesc->various, "-01234567890."); + } + break; + case PX_OBJECT_VARIOUS_EDIT_TYPE_HEX: + { + PX_Object_EditSetLimit(pDesc->various, "-01234567890ABCDEFabcdef"); + } + break; + default: + break; + } + } + } +} + +const px_char* PX_Object_VariousGetText(PX_Object* pObject) +{ + if (pObject->Type!= PX_OBJECT_TYPE_VARIOUS) + { + PX_ASSERT(); + return PX_NULL; + } + else + { + PX_Object_Various* pDesc = PX_ObjectGetDesc(PX_Object_Various, pObject); + switch (pDesc->type) + { + case PX_OBJECT_VARIOUS_TYPE_EDIT: + { + return PX_Object_EditGetText(PX_Object_GetVarious(pObject)->various); + } + case PX_OBJECT_VARIOUS_TYPE_LABEL: + { + return PX_Object_LabelGetText(PX_Object_GetVarious(pObject)->various); + } + case PX_OBJECT_VARIOUS_TYPE_SELECTBAR: + { + return PX_Object_SelectBarGetCurrentText(PX_Object_GetVarious(pObject)->various); + } + default: + break; + } + } + + PX_ASSERT(); + return PX_NULL; + +} + +px_void PX_Object_VariousSetText(PX_Object* pObject, const px_char* Text) +{ + if (pObject->Type != PX_OBJECT_TYPE_VARIOUS) + { + PX_ASSERT(); + return; + } + else + { + PX_Object_Various* pDesc = PX_ObjectGetDesc(PX_Object_Various, pObject); + switch (pDesc->type) + { + case PX_OBJECT_VARIOUS_TYPE_EDIT: + { + PX_Object_EditSetXYOffset(PX_Object_GetVarious(pObject)->various, 0, 0); + PX_Object_EditSetText(PX_Object_GetVarious(pObject)->various,Text); + } + break; + case PX_OBJECT_VARIOUS_TYPE_LABEL: + { + PX_Object_LabelSetText(PX_Object_GetVarious(pObject)->various, Text); + } + break; + case PX_OBJECT_VARIOUS_TYPE_SELECTBAR: + { + PX_ASSERT(); + return; + } + default: + break; + } + } + +} + +px_void PX_Object_VariousAddItem(PX_Object* pObject, const px_char* ItemText) +{ + if (pObject->Type != PX_OBJECT_TYPE_VARIOUS) + { + PX_ASSERT(); + return; + } + else + { + PX_Object_Various* pDesc = PX_ObjectGetDesc(PX_Object_Various, pObject); + switch (pDesc->type) + { + case PX_OBJECT_VARIOUS_TYPE_SELECTBAR: + { + PX_Object_SelectBarAddItem(pDesc->various, ItemText); + return; + } + default: + break; + } + } + PX_ASSERT(); + return; +} + +const px_char* PX_Object_VariousGetLabelText(PX_Object* pObject) +{ + if (pObject->Type != PX_OBJECT_TYPE_VARIOUS) + { + PX_ASSERT(); + return PX_NULL; + } + return PX_Object_LabelGetText(PX_Object_GetVarious(pObject)->label); +} + +px_int PX_Object_VariousSelectBarGetCurrentIndex(PX_Object* pObject) +{ + if (pObject->Type != PX_OBJECT_TYPE_VARIOUS) + { + PX_ASSERT(); + return PX_NULL; + } + else + { + PX_Object_Various* pDesc = PX_ObjectGetDesc(PX_Object_Various, pObject); + if (pDesc->type==PX_OBJECT_VARIOUS_TYPE_SELECTBAR) + { + return PX_Object_SelectBarGetCurrentIndex(pDesc->various); + } + } + return 0; +} + +px_void PX_Object_VariousSetLabelText(PX_Object* pObject, const px_char* Text) +{ + if (pObject->Type != PX_OBJECT_TYPE_VARIOUS) + { + PX_ASSERT(); + return; + } + PX_Object_LabelSetText(PX_Object_GetVarious(pObject)->label, Text); +} + +px_void PX_Object_VariousSetTextColor(PX_Object* pObject, px_color Color) +{ + if (pObject->Type != PX_OBJECT_TYPE_VARIOUS) + { + PX_ASSERT(); + return; + } + PX_Object_EditSetTextColor(PX_Object_GetVarious(pObject)->various, Color); + PX_Object_LabelSetTextColor(PX_Object_GetVarious(pObject)->label, Color); +} + +px_void PX_Object_VariousSetBackgroundColor(PX_Object* pObject, px_color Color) +{ + if (pObject->Type != PX_OBJECT_TYPE_VARIOUS) + { + PX_ASSERT(); + return; + } + else + { + PX_Object_Various* pDesc = PX_ObjectGetDesc(PX_Object_Various, pObject); + switch (pDesc->type) + { + case PX_OBJECT_VARIOUS_TYPE_EDIT: + { + PX_Object_LabelSetBackgroundColor(PX_Object_GetVarious(pObject)->label, Color); + PX_Object_EditSetBackgroundColor(PX_Object_GetVarious(pObject)->various, Color); + } + break; + case PX_OBJECT_VARIOUS_TYPE_LABEL: + { + PX_Object_LabelSetBackgroundColor(PX_Object_GetVarious(pObject)->label, Color); + PX_Object_LabelSetBackgroundColor(PX_Object_GetVarious(pObject)->various, Color); + } + break; + case PX_OBJECT_VARIOUS_TYPE_SELECTBAR: + { + PX_Object_LabelSetBackgroundColor(PX_Object_GetVarious(pObject)->label, Color); + PX_Object_SelectBarSetBackgroundColor(PX_Object_GetVarious(pObject)->various, Color); + } + break; + default: + break; + } + } +} + +px_void PX_Object_VariousSetAlign(PX_Object* pObject, PX_ALIGN Align) +{ + if (pObject->Type != PX_OBJECT_TYPE_VARIOUS) + { + PX_ASSERT(); + return; + } + PX_Object_LabelSetAlign(PX_Object_GetVarious(pObject)->label, Align); +} + +px_void PX_Object_VariousSetString(PX_Object* pObject, const px_char* Text) +{ + if (pObject->Type != PX_OBJECT_TYPE_VARIOUS) + { + PX_ASSERT(); + return; + } + PX_Object_VariousSetText(pObject, Text); +} + +px_void PX_Object_VariousSetFloat(PX_Object* pObject, float f) +{ + px_char content[32]; + if (pObject->Type != PX_OBJECT_TYPE_VARIOUS) + { + PX_ASSERT(); + return; + } + PX_ftoa(f, content, sizeof(content), 6); + PX_Object_VariousSetText(pObject, content); +} + +px_void PX_Object_VariousSetInt(PX_Object* pObject, int i) +{ + px_char content[32]; + if (pObject->Type != PX_OBJECT_TYPE_VARIOUS) + { + PX_ASSERT(); + return; + } + PX_itoa(i, content, sizeof(content),10); + + PX_Object_VariousSetText(pObject, content); +} + +px_void PX_Object_VariousSetBool(PX_Object* pObject, px_bool b) +{ + if (pObject->Type != PX_OBJECT_TYPE_VARIOUS) + { + PX_ASSERT(); + return; + } + if (b) + { + PX_Object_VariousSetText(pObject, "true"); + } + else + { + PX_Object_VariousSetText(pObject, "false"); + } +} + diff --git a/lib/PainterEngine/kernel/PX_Object_Various.h b/lib/PainterEngine/kernel/PX_Object_Various.h new file mode 100644 index 0000000000000000000000000000000000000000..ceb9293a753f1d5373a3ae212d87dd567beb7c7b --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_Various.h @@ -0,0 +1,49 @@ +#ifndef PX_OBJECT_LABELCONTENT_H +#define PX_OBJECT_LABELCONTENT_H +#include "PX_Object.h" + +typedef enum +{ + PX_OBJECT_VARIOUS_EDIT_TYPE_INT, + PX_OBJECT_VARIOUS_EDIT_TYPE_FLOAT, + PX_OBJECT_VARIOUS_EDIT_TYPE_STRING, + PX_OBJECT_VARIOUS_EDIT_TYPE_HEX, +}PX_OBJECT_VARIOUS_EIDT_TYPE; + + +typedef enum +{ + PX_OBJECT_VARIOUS_TYPE_LABEL, + PX_OBJECT_VARIOUS_TYPE_EDIT, + PX_OBJECT_VARIOUS_TYPE_SELECTBAR, +}PX_OBJECT_VARIOUS_TYPE; + +typedef struct +{ + PX_Object* label; + PX_Object* various; + px_bool editable; + PX_OBJECT_VARIOUS_TYPE type; +}PX_Object_Various; + +px_void PX_Object_VariousEditSetMaxLength(PX_Object* pObject, px_int len); +PX_Object* PX_Object_VariousCreate(px_memorypool* mp, PX_Object* Parent, px_int x, px_int y, px_int Width, px_int Height, const px_char* Text, PX_OBJECT_VARIOUS_TYPE type, PX_FontModule* fm); +PX_Object_Various* PX_Object_GetVarious(PX_Object* pObject); +px_void PX_Object_VariousSetEditStyle(PX_Object* pObject, PX_OBJECT_VARIOUS_EIDT_TYPE type); + + +const px_char* PX_Object_VariousGetText(PX_Object* pObject); +const px_char* PX_Object_VariousGetLabelText(PX_Object* pObject); +px_void PX_Object_VariousSetText(PX_Object* pObject, const px_char* Text); +px_void PX_Object_VariousAddItem(PX_Object* pObject, const px_char* ItemText); + +px_void PX_Object_VariousSetLabelText(PX_Object* pObject, const px_char* Text); +px_void PX_Object_VariousSetTextColor(PX_Object* pObject, px_color Color); +px_void PX_Object_VariousSetBackgroundColor(PX_Object* pObject, px_color Color); +px_void PX_Object_VariousSetAlign(PX_Object* pObject, PX_ALIGN Align); + +px_void PX_Object_VariousSetString(PX_Object* pObject, const px_char* Text); +px_void PX_Object_VariousSetFloat(PX_Object* pObject, px_float f); +px_void PX_Object_VariousSetInt(PX_Object* pObject, px_int i); +px_void PX_Object_VariousSetBool(PX_Object* pObject, px_bool b); +#endif \ No newline at end of file diff --git a/lib/PainterEngine/kernel/PX_Object_VirtualKeyboard.c b/lib/PainterEngine/kernel/PX_Object_VirtualKeyboard.c new file mode 100644 index 0000000000000000000000000000000000000000..2fe040cff7866aecde2d356ee8f6fa31aca3b6e2 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_VirtualKeyboard.c @@ -0,0 +1,1122 @@ +#include "PX_Object_VirtualKeyboard.h" +PX_Object_VirtualKeyBoard *PX_Object_GetVirtualKeyBoard(PX_Object *pObject) +{ + if (!pObject) + { + return PX_NULL; + } + if (pObject->Type==PX_OBJECT_TYPE_VKEYBOARD) + { + return (PX_Object_VirtualKeyBoard *)pObject->pObject; + } + return PX_NULL; +} + +px_void PX_Object_VirtualKeyBoardRender(px_surface *psurface, PX_Object *pObject,px_uint elapsed) +{ + px_int i; + px_int oftx; + px_int ofty; + PX_Object_VirtualKeyBoard *keyBoard=(PX_Object_VirtualKeyBoard *)pObject->pObject; + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + oftx=(px_int)objx; + ofty=(px_int)objy; + + //clear background + PX_SurfaceClear(psurface,(px_int)objx,(px_int)objy,(px_int)(objx+objWidth),(px_int)(objy+objHeight),keyBoard->backgroundColor); + + for (i=0;iKeys);i++) + { + //draw rect + + if (keyBoard->Keys[i].bDown||keyBoard->Keys[i].bhold) + { + PX_GeoDrawRect(psurface,oftx+keyBoard->Keys[i].x,ofty+keyBoard->Keys[i].y,oftx+keyBoard->Keys[i].x+keyBoard->Keys[i].width,ofty+keyBoard->Keys[i].y+keyBoard->Keys[i].height,keyBoard->pushColor); + } + else if (keyBoard->Keys[i].bCursor) + { + PX_GeoDrawRect(psurface,oftx+keyBoard->Keys[i].x,ofty+keyBoard->Keys[i].y,oftx+keyBoard->Keys[i].x+keyBoard->Keys[i].width,ofty+keyBoard->Keys[i].y+keyBoard->Keys[i].height,keyBoard->cursorColor); + } + + PX_GeoDrawBorder(psurface,oftx+keyBoard->Keys[i].x,ofty+keyBoard->Keys[i].y,oftx+keyBoard->Keys[i].x+keyBoard->Keys[i].width,ofty+keyBoard->Keys[i].y+keyBoard->Keys[i].height,1,keyBoard->borderColor); + + if (keyBoard->bShift||keyBoard->bUpper) + { + PX_FontModuleDrawText(psurface,PX_NULL,oftx+keyBoard->Keys[i].x+2,ofty+keyBoard->Keys[i].y+2,PX_ALIGN_LEFTTOP,keyBoard->Keys[i].u_key,keyBoard->borderColor); + } + else + { + PX_FontModuleDrawText(psurface,PX_NULL,oftx+keyBoard->Keys[i].x+2,ofty+keyBoard->Keys[i].y+2,PX_ALIGN_LEFTTOP,keyBoard->Keys[i].d_key,keyBoard->borderColor); + } + } + +} + +px_void PX_Object_VirtualKeyBoardOnCursorUp(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + px_float x=PX_Object_Event_GetCursorX(e); + px_float y=PX_Object_Event_GetCursorY(e); + px_int i; + PX_Object_VirtualKeyBoard *pkb=(PX_Object_VirtualKeyBoard *)pObject->pObject; + if (!PX_ObjectIsPointInRegion(pObject,(px_float)x,(px_float)y)) + { + return; + } + + for (i=0;iKeys);i++) + { + + pkb->Keys[i].bDown=PX_FALSE; + } +} + +px_void PX_Object_VirtualKeyBoardOnCursorMove(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + px_float x=PX_Object_Event_GetCursorX(e); + px_float y=PX_Object_Event_GetCursorY(e); + px_int i; + px_int kh=(px_int)(pObject->Height/5); + PX_Object_VirtualKeyBoard *pkb=(PX_Object_VirtualKeyBoard *)pObject->pObject; + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + + x=(PX_Object_Event_GetCursorX(e)-objx); + y=(PX_Object_Event_GetCursorY(e)-objy); + + + for (i=0;iKeys);i++) + { + if(!pkb->Keys[i].bDown) + { + pkb->Keys[i].bCursor=PX_FALSE; + } + else + { + if (!PX_isPointInRect(PX_POINT((px_float)x,(px_float)y,0),PX_RECT((px_float)pkb->Keys[i].x,(px_float)pkb->Keys[i].y,(px_float)pkb->Keys[i].width,(px_float)pkb->Keys[i].height))) + pkb->Keys[i].bDown=PX_FALSE; + } + } + + if (yKeys[i].x,(px_float)pkb->Keys[i].y,(px_float)pkb->Keys[i].width,(px_float)pkb->Keys[i].height))) + { + pkb->Keys[i].bCursor=PX_TRUE; + break; + } + } + } + else if (y<2*kh) + { + for (i=14;i<=27;i++) + { + if (PX_isPointInRect(PX_POINT((px_float)x,(px_float)y,0),PX_RECT((px_float)pkb->Keys[i].x,(px_float)pkb->Keys[i].y,(px_float)pkb->Keys[i].width,(px_float)pkb->Keys[i].height))) + { + pkb->Keys[i].bCursor=PX_TRUE; + break; + } + } + } + else if (y<3*kh) + { + for (i=28;i<=40;i++) + { + if (PX_isPointInRect(PX_POINT((px_float)x,(px_float)y,0),PX_RECT((px_float)pkb->Keys[i].x,(px_float)pkb->Keys[i].y,(px_float)pkb->Keys[i].width,(px_float)pkb->Keys[i].height))) + { + pkb->Keys[i].bCursor=PX_TRUE; + break; + } + } + } + else if (y<4*kh) + { + for (i=41;i<=52;i++) + { + if (PX_isPointInRect(PX_POINT((px_float)x,(px_float)y,0),PX_RECT((px_float)pkb->Keys[i].x,(px_float)pkb->Keys[i].y,(px_float)pkb->Keys[i].width,(px_float)pkb->Keys[i].height))) + { + pkb->Keys[i].bCursor=PX_TRUE; + break; + } + } + } + else + { + for (i=53;i<=55;i++) + { + if (PX_isPointInRect(PX_POINT((px_float)x,(px_float)y,0),PX_RECT((px_float)pkb->Keys[i].x,(px_float)pkb->Keys[i].y,(px_float)pkb->Keys[i].width,(px_float)pkb->Keys[i].height))) + { + pkb->Keys[i].bCursor=PX_TRUE; + break; + } + } + } + + + +} + +px_void PX_Object_VirtualKeyBoardOnCursorDown(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + px_float x=PX_Object_Event_GetCursorX(e); + px_float y=PX_Object_Event_GetCursorY(e); + px_int i; + px_int kh=(px_int)(pObject->Height/5); + PX_Object_VirtualKeyBoard *pkb=(PX_Object_VirtualKeyBoard *)pObject->pObject; + + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_Object_Event stringEvent; + + px_char strEve[2]={0}; + + stringEvent.Event=PX_OBJECT_EVENT_STRING; + PX_Object_Event_SetStringPtr(&stringEvent,strEve); + + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + if (!PX_ObjectIsPointInRegion(pObject,(px_float)x,(px_float)y)) + { + PX_ObjectClearFocus(pObject); + return; + } + + PX_ObjectSetFocus(pObject); + + x=(PX_Object_Event_GetCursorX(e)-objx); + y=(PX_Object_Event_GetCursorY(e)-objy); + + + if (yKeys[i].x,(px_float)pkb->Keys[i].y,(px_float)pkb->Keys[i].width,(px_float)pkb->Keys[i].height))) + { + pkb->Keys[i].bDown=PX_TRUE; + break; + } + } + } + else if (y<2*kh) + { + for (i=14;i<=27;i++) + { + if (PX_isPointInRect(PX_POINT((px_float)x,(px_float)y,0),PX_RECT((px_float)pkb->Keys[i].x,(px_float)pkb->Keys[i].y,(px_float)pkb->Keys[i].width,(px_float)pkb->Keys[i].height))) + { + pkb->Keys[i].bDown=PX_TRUE; + break; + } + } + } + else if (y<3*kh) + { + for (i=28;i<=40;i++) + { + if (PX_isPointInRect(PX_POINT((px_float)x,(px_float)y,0),PX_RECT((px_float)pkb->Keys[i].x,(px_float)pkb->Keys[i].y,(px_float)pkb->Keys[i].width,(px_float)pkb->Keys[i].height))) + { + pkb->Keys[i].bDown=PX_TRUE; + break; + } + } + } + else if (y<4*kh) + { + for (i=41;i<=52;i++) + { + if (PX_isPointInRect(PX_POINT((px_float)x,(px_float)y,0),PX_RECT((px_float)pkb->Keys[i].x,(px_float)pkb->Keys[i].y,(px_float)pkb->Keys[i].width,(px_float)pkb->Keys[i].height))) + { + pkb->Keys[i].bDown=PX_TRUE; + break; + } + } + } + else + { + for (i=53;i<=55;i++) + { + if (PX_isPointInRect(PX_POINT((px_float)x,(px_float)y,0),PX_RECT((px_float)pkb->Keys[i].x,(px_float)pkb->Keys[i].y,(px_float)pkb->Keys[i].width,(px_float)pkb->Keys[i].height))) + { + pkb->Keys[i].bDown=PX_TRUE; + break; + } + } + } + + if (i==13) + { + pkb->functionCode=8; + if (pkb->LinkerObject) + { + strEve[0]=pkb->functionCode; + PX_ObjectPostEvent(pkb->LinkerObject,stringEvent); + } + } + else if(i==14) + { + pkb->functionCode='\t'; + if (pkb->LinkerObject) + { + strEve[0]=pkb->functionCode; + PX_ObjectPostEvent(pkb->LinkerObject,stringEvent); + } + } + else if(i==28) + { + pkb->bUpper=!pkb->bUpper; + if (pkb->bUpper) + { + pkb->Keys[28].bhold=PX_TRUE; + } + else + { + pkb->Keys[28].bhold=PX_FALSE; + } + pkb->functionCode=0; + } + else if(i==40) + { + pkb->functionCode='\r'; + if (pkb->LinkerObject) + { + strEve[0]=pkb->functionCode; + PX_ObjectPostEvent(pkb->LinkerObject,stringEvent); + } + } + else if(i==41) + { + pkb->bShift=!pkb->bShift; + if (pkb->bShift) + { + pkb->Keys[41].bhold=PX_TRUE; + } + else + { + pkb->Keys[41].bhold=PX_FALSE; + } + pkb->functionCode=0; + } + else if(i==52) + { + pkb->bShift=!pkb->bShift; + if (pkb->bShift) + { + pkb->Keys[52].bhold=PX_TRUE; + } + else + { + pkb->Keys[52].bhold=PX_FALSE; + } + pkb->functionCode=0; + } + else if(i==53) + { + pkb->bCtrl=!pkb->bCtrl; + if (pkb->bCtrl) + { + pkb->Keys[53].bhold=PX_TRUE; + } + else + { + pkb->Keys[53].bhold=PX_FALSE; + } + pkb->functionCode=0; + } + else if(i==54) + { + pkb->bAlt=!pkb->bAlt; + if (pkb->bAlt) + { + pkb->Keys[54].bhold=PX_TRUE; + } + else + { + pkb->Keys[54].bhold=PX_FALSE; + } + pkb->functionCode=0; + } + else if(i==55) + { + pkb->functionCode=' '; + if (pkb->LinkerObject) + { + strEve[0]=pkb->functionCode; + PX_ObjectPostEvent(pkb->LinkerObject,stringEvent); + } + } + else + { + if (pkb->bUpper||pkb->bShift) + { + pkb->functionCode=pkb->Keys[i].u_key[0]; + } + else + { + pkb->functionCode=pkb->Keys[i].d_key[0]; + } + + pkb->bShift=PX_FALSE; + pkb->Keys[52].bhold=PX_FALSE; + pkb->Keys[41].bhold=PX_FALSE; + if (pkb->LinkerObject) + { + strEve[0]=pkb->functionCode; + PX_ObjectPostEvent(pkb->LinkerObject,stringEvent); + } + } + + +} + +PX_Object* PX_Object_VirtualKeyBoardCreate(px_memorypool *mp, PX_Object *Parent,px_int x,px_int y,px_int width,px_int height) +{ + px_int i; + px_int kw,kh; + px_int xoffset,yoffset; + PX_Object_VirtualKeyBoard keyboard; + px_char line1_upper[]="~!@#$%^&*()_+"; + px_char line1_lower[]="`1234567890-="; + px_char line2_upper[]="QWERTYUIOP{}|"; + px_char line2_lower[]="qwertyuiop[]\\"; + px_char line3_upper[]="ASDFGHJKL:\""; + px_char line3_lower[]="asdfghjkl;'"; + px_char line4_upper[]="ZXCVBNM<>?"; + px_char line4_lower[]="zxcvbnm,./"; + + + PX_Object *keyboardObject; + + if (width<24*15||height<16*5) + { + return PX_NULL; + } + PX_memset(&keyboard,0,sizeof(PX_Object_VirtualKeyBoard)); + + kw=width/15; + kh=height/5; + + xoffset=0; + yoffset=0; + for (i=0;i<=12;i++) + { + keyboard.Keys[i].d_key[0]=line1_lower[i]; + keyboard.Keys[i].u_key[0]=line1_upper[i]; + keyboard.Keys[i].x=xoffset; + keyboard.Keys[i].y=yoffset; + keyboard.Keys[i].width=kw; + keyboard.Keys[i].height=kh; + xoffset+=kw; + } + + PX_strset(keyboard.Keys[13].d_key,"Back"); + PX_strset(keyboard.Keys[13].u_key,"Back"); + keyboard.Keys[13].x=xoffset; + keyboard.Keys[13].y=0; + keyboard.Keys[13].width=kw*2; + keyboard.Keys[13].height=kh; + + + xoffset=0; + yoffset=kh; + + PX_strset(keyboard.Keys[14].d_key,"Tab"); + PX_strset(keyboard.Keys[14].u_key,"Tab"); + + keyboard.Keys[14].x=xoffset; + keyboard.Keys[14].y=kh; + keyboard.Keys[14].width=(px_int)(kw*1.5); + keyboard.Keys[14].height=kh; + + xoffset+=keyboard.Keys[14].width; + + for (i=15;i<=26;i++) + { + keyboard.Keys[i].d_key[0]=line2_lower[i-15]; + keyboard.Keys[i].u_key[0]=line2_upper[i-15]; + keyboard.Keys[i].x=xoffset; + keyboard.Keys[i].y=yoffset; + keyboard.Keys[i].width=kw; + keyboard.Keys[i].height=kh; + xoffset+=keyboard.Keys[i].width; + } + PX_strset(keyboard.Keys[27].d_key,"\\"); + PX_strset(keyboard.Keys[27].u_key,"|"); + keyboard.Keys[27].x=xoffset; + keyboard.Keys[27].y=yoffset; + keyboard.Keys[27].width=(px_int)(kw*1.5);; + keyboard.Keys[27].height=kh; + + xoffset=0; + yoffset=2*kh; + + PX_strset(keyboard.Keys[28].d_key,"Upper"); + PX_strset(keyboard.Keys[28].u_key,"Upper"); + keyboard.Keys[28].x=xoffset; + keyboard.Keys[28].y=yoffset; + keyboard.Keys[28].width=(px_int)(kw*2); + keyboard.Keys[28].height=kh; + xoffset+=keyboard.Keys[28].width; + + for (i=29;i<=39;i++) + { + keyboard.Keys[i].d_key[0]=line3_lower[i-29]; + keyboard.Keys[i].u_key[0]=line3_upper[i-29]; + keyboard.Keys[i].x=xoffset; + keyboard.Keys[i].y=yoffset; + keyboard.Keys[i].width=kw; + keyboard.Keys[i].height=kh; + xoffset+=keyboard.Keys[i].width; + } + + PX_strset(keyboard.Keys[40].d_key,"Enter"); + PX_strset(keyboard.Keys[40].u_key,"Enter"); + keyboard.Keys[40].x=xoffset; + keyboard.Keys[40].y=yoffset; + keyboard.Keys[40].width=(px_int)(kw*2);; + keyboard.Keys[40].height=kh; + xoffset+=keyboard.Keys[40].width; + + xoffset=0; + yoffset=3*kh; + + PX_strset(keyboard.Keys[41].d_key,"Shift"); + PX_strset(keyboard.Keys[41].u_key,"Shift"); + keyboard.Keys[41].x=xoffset; + keyboard.Keys[41].y=yoffset; + keyboard.Keys[41].width=(px_int)(kw*2.5);; + keyboard.Keys[41].height=kh; + xoffset+=keyboard.Keys[41].width; + + for (i=42;i<=51;i++) + { + keyboard.Keys[i].d_key[0]=line4_lower[i-42]; + keyboard.Keys[i].u_key[0]=line4_upper[i-42]; + keyboard.Keys[i].x=xoffset; + keyboard.Keys[i].y=yoffset; + keyboard.Keys[i].width=kw; + keyboard.Keys[i].height=kh; + xoffset+=keyboard.Keys[i].width; + } + + PX_strset(keyboard.Keys[52].d_key,"Shift"); + PX_strset(keyboard.Keys[52].u_key,"Shift"); + keyboard.Keys[52].x=xoffset; + keyboard.Keys[52].y=yoffset; + keyboard.Keys[52].width=(px_int)(kw*2.5);; + keyboard.Keys[52].height=kh; + xoffset+=keyboard.Keys[52].width; + + xoffset=0; + yoffset=4*kh; + PX_strset(keyboard.Keys[53].d_key,"Ctrl"); + PX_strset(keyboard.Keys[53].u_key,"Ctrl"); + keyboard.Keys[53].x=xoffset; + keyboard.Keys[53].y=yoffset; + keyboard.Keys[53].width=(px_int)(kw*1.5);; + keyboard.Keys[53].height=kh; + xoffset+=keyboard.Keys[53].width; + + PX_strset(keyboard.Keys[54].d_key,"Alt"); + PX_strset(keyboard.Keys[54].u_key,"Alt"); + keyboard.Keys[54].x=xoffset; + keyboard.Keys[54].y=yoffset; + keyboard.Keys[54].width=(px_int)(kw*1.5);; + keyboard.Keys[54].height=kh; + xoffset+=keyboard.Keys[54].width; + + PX_strset(keyboard.Keys[55].d_key,""); + PX_strset(keyboard.Keys[55].u_key,""); + keyboard.Keys[55].x=xoffset; + keyboard.Keys[55].y=yoffset; + keyboard.Keys[55].width=(px_int)(kw*12);; + keyboard.Keys[55].height=kh; + xoffset+=keyboard.Keys[55].width; + + keyboard.cursorColor=PX_COLOR(255,192,192,192); + keyboard.pushColor=PX_COLOR(255,128,128,128); + keyboard.backgroundColor=PX_COLOR(255,255,255,255); + keyboard.borderColor=PX_COLOR(255,0,0,0); + + keyboard.LinkerObject=PX_NULL; + + keyboardObject=PX_ObjectCreateEx(mp,Parent,(px_float)x,(px_float)y,0,(px_float)width,(px_float)height,0,PX_OBJECT_TYPE_VKEYBOARD,PX_NULL,PX_Object_VirtualKeyBoardRender,PX_NULL,&keyboard,sizeof(PX_Object_VirtualKeyBoard)); + + PX_ObjectRegisterEvent(keyboardObject,PX_OBJECT_EVENT_CURSORMOVE,PX_Object_VirtualKeyBoardOnCursorMove,PX_NULL); + PX_ObjectRegisterEvent(keyboardObject,PX_OBJECT_EVENT_CURSORDRAG,PX_Object_VirtualKeyBoardOnCursorMove,PX_NULL); + PX_ObjectRegisterEvent(keyboardObject,PX_OBJECT_EVENT_CURSORDOWN,PX_Object_VirtualKeyBoardOnCursorDown,PX_NULL); + PX_ObjectRegisterEvent(keyboardObject,PX_OBJECT_EVENT_CURSORUP,PX_Object_VirtualKeyBoardOnCursorUp,PX_NULL); + + keyboardObject->OnLostFocusReleaseEvent=PX_FALSE; + + return keyboardObject; +} + +px_void PX_Object_VirtualKeyBoardSetBackgroundColor(PX_Object *pObject,px_color Color) +{ + PX_Object_VirtualKeyBoard *pkb=PX_Object_GetVirtualKeyBoard(pObject); + if (pkb) + { + pkb->backgroundColor=Color; + } +} + +px_void PX_Object_VirtualKeyBoardSetBorderColor(PX_Object *pObject,px_color Color) +{ + PX_Object_VirtualKeyBoard *pkb=PX_Object_GetVirtualKeyBoard(pObject); + if (pkb) + { + pkb->borderColor=Color; + } +} + +px_void PX_Object_VirtualKeyBoardSetCursorColor(PX_Object *pObject,px_color Color) +{ + PX_Object_VirtualKeyBoard *pkb=PX_Object_GetVirtualKeyBoard(pObject); + if (pkb) + { + pkb->cursorColor=Color; + } +} + +px_void PX_Object_VirtualKeyBoardSetPushColor(PX_Object *pObject,px_color Color) +{ + PX_Object_VirtualKeyBoard *pkb=PX_Object_GetVirtualKeyBoard(pObject); + if (pkb) + { + pkb->pushColor=Color; + } +} + +px_char PX_Object_VirtualKeyBoardGetCode(PX_Object *pObject) +{ + PX_Object_VirtualKeyBoard *pkb=PX_Object_GetVirtualKeyBoard(pObject); + if (pkb) + { + px_char ch= pkb->functionCode; + pkb->functionCode=0; + return ch; + } + return 0; +} + +px_void PX_Object_VirtualKeyBoardSetLinkerObject(PX_Object *pObject,PX_Object *linker) +{ + PX_Object_VirtualKeyBoard *pkb=PX_Object_GetVirtualKeyBoard(pObject); + if (pkb) + { + pkb->LinkerObject=linker; + } +} + +////////////////////////////////////////////////////////////////////////// +//NumberKey +PX_Object_VirtualNumberKeyBoard *PX_Object_GetVirtualNumberKeyBoard(PX_Object *pObject) +{ + if (!pObject) + { + return PX_NULL; + } + if (pObject->Type==PX_OBJECT_TYPE_VNKEYBOARD) + { + return (PX_Object_VirtualNumberKeyBoard *)pObject->pObject; + } + return PX_NULL; +} + +px_void PX_Object_VirtualNumberKeyBoardRender(px_surface *psurface, PX_Object *pObject,px_uint elapsed) +{ + px_int i; + px_int oftx; + px_int ofty; + PX_Object_VirtualNumberKeyBoard *keyBoard=(PX_Object_VirtualNumberKeyBoard *)pObject->pObject; + + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + oftx=(px_int)objx; + ofty=(px_int)objy; + //clear background + PX_SurfaceClear(psurface,(px_int)objx,(px_int)objy,(px_int)(objx+objWidth-1),(px_int)(objy+objHeight-1),keyBoard->backgroundColor); + + for (i=0;iKeys);i++) + { + //draw rect + + if (keyBoard->Keys[i].bDown||keyBoard->Keys[i].bhold) + { + PX_GeoDrawRect(psurface,oftx+keyBoard->Keys[i].x,ofty+keyBoard->Keys[i].y,oftx+keyBoard->Keys[i].x+keyBoard->Keys[i].width,ofty+keyBoard->Keys[i].y+keyBoard->Keys[i].height,keyBoard->pushColor); + } + else if (keyBoard->Keys[i].bCursor) + { + PX_GeoDrawRect(psurface,oftx+keyBoard->Keys[i].x,ofty+keyBoard->Keys[i].y,oftx+keyBoard->Keys[i].x+keyBoard->Keys[i].width,ofty+keyBoard->Keys[i].y+keyBoard->Keys[i].height,keyBoard->cursorColor); + } + + PX_GeoDrawBorder(psurface,oftx+keyBoard->Keys[i].x,ofty+keyBoard->Keys[i].y,oftx+keyBoard->Keys[i].x+keyBoard->Keys[i].width,ofty+keyBoard->Keys[i].y+keyBoard->Keys[i].height,1,keyBoard->borderColor); + + PX_FontModuleDrawText(psurface,PX_NULL,oftx+keyBoard->Keys[i].x+2,ofty+keyBoard->Keys[i].y+2,PX_ALIGN_LEFTTOP,keyBoard->Keys[i].d_key,keyBoard->borderColor); + } + +} + +px_void PX_Object_VirtualNumberKeyBoardOnCursorUp(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + px_float x=PX_Object_Event_GetCursorX(e); + px_float y=PX_Object_Event_GetCursorY(e); + px_int i; + PX_Object_VirtualNumberKeyBoard *pkb=(PX_Object_VirtualNumberKeyBoard *)pObject->pObject; + if (!PX_ObjectIsPointInRegion(pObject,(px_float)x,(px_float)y)) + { + return; + } + + for (i=0;iKeys);i++) + { + pkb->Keys[i].bDown=PX_FALSE; + } +} + +px_void PX_Object_VirtualNumberKeyBoardOnCursorMove(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + px_float x=PX_Object_Event_GetCursorX(e); + px_float y=PX_Object_Event_GetCursorY(e); + px_int i; + px_int kh=(px_int)(pObject->Height/5); + PX_Object_VirtualNumberKeyBoard *pkb=(PX_Object_VirtualNumberKeyBoard *)pObject->pObject; + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + + + x=(PX_Object_Event_GetCursorX(e)-objx); + y=(PX_Object_Event_GetCursorY(e)-objy); + + + for (i=0;iKeys);i++) + { + if(!pkb->Keys[i].bDown) + { + pkb->Keys[i].bCursor=PX_FALSE; + } + else + { + if (!PX_isPointInRect(PX_POINT((px_float)x,(px_float)y,0),PX_RECT((px_float)pkb->Keys[i].x,(px_float)pkb->Keys[i].y,(px_float)pkb->Keys[i].width,(px_float)pkb->Keys[i].height))) + pkb->Keys[i].bDown=PX_FALSE; + } + } + + if (yKeys[i].x,(px_float)pkb->Keys[i].y,(px_float)pkb->Keys[i].width,(px_float)pkb->Keys[i].height))) + { + pkb->Keys[i].bCursor=PX_TRUE; + break; + } + } + } + else if (y<2*kh) + { + for (i=4;i<=7;i++) + { + if (PX_isPointInRect(PX_POINT((px_float)x,(px_float)y,0),PX_RECT((px_float)pkb->Keys[i].x,(px_float)pkb->Keys[i].y,(px_float)pkb->Keys[i].width,(px_float)pkb->Keys[i].height))) + { + pkb->Keys[i].bCursor=PX_TRUE; + break; + } + } + } + else if (y<3*kh) + { + for (i=7;i<=10;i++) + { + if (PX_isPointInRect(PX_POINT((px_float)x,(px_float)y,0),PX_RECT((px_float)pkb->Keys[i].x,(px_float)pkb->Keys[i].y,(px_float)pkb->Keys[i].width,(px_float)pkb->Keys[i].height))) + { + pkb->Keys[i].bCursor=PX_TRUE; + break; + } + } + } + else if (y<4*kh) + { + for (i=11;i<=14;i++) + { + if (PX_isPointInRect(PX_POINT((px_float)x,(px_float)y,0),PX_RECT((px_float)pkb->Keys[i].x,(px_float)pkb->Keys[i].y,(px_float)pkb->Keys[i].width,(px_float)pkb->Keys[i].height))) + { + pkb->Keys[i].bCursor=PX_TRUE; + break; + } + } + } + else + { + for (i=14;i<=16;i++) + { + if (PX_isPointInRect(PX_POINT((px_float)x,(px_float)y,0),PX_RECT((px_float)pkb->Keys[i].x,(px_float)pkb->Keys[i].y,(px_float)pkb->Keys[i].width,(px_float)pkb->Keys[i].height))) + { + pkb->Keys[i].bCursor=PX_TRUE; + break; + } + } + } + + + +} + +px_void PX_Object_VirtualNumberKeyBoardOnCursorDown(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + px_float x=PX_Object_Event_GetCursorX(e); + px_float y=PX_Object_Event_GetCursorY(e); + px_int i; + px_int kh=(px_int)(pObject->Height/5); + PX_Object_Event stringEvent; + PX_Object_VirtualKeyBoard *pkb=(PX_Object_VirtualKeyBoard *)pObject->pObject; + PX_Object_Event ke; + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + px_char strEve[2]={0}; + + stringEvent.Event=PX_OBJECT_EVENT_STRING; + PX_Object_Event_SetStringPtr(&stringEvent,strEve); + + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + if (!PX_ObjectIsPointInRegion(pObject,(px_float)x,(px_float)y)) + { + return; + } + + x=(PX_Object_Event_GetCursorX(e)-objx); + y=(PX_Object_Event_GetCursorY(e)-objy); + ke.Event=PX_OBJECT_EVENT_KEYDOWN; + + if (yKeys[i].x,(px_float)pkb->Keys[i].y,(px_float)pkb->Keys[i].width,(px_float)pkb->Keys[i].height))) + { + pkb->Keys[i].bDown=PX_TRUE; + if (i!=0) + { + + PX_Object_Event_SetKeyDown(&ke,pkb->Keys[i].u_key[0]); + PX_ObjectExecuteEvent(pObject,ke); + strEve[0]=pkb->Keys[i].u_key[0]; + PX_ObjectPostEvent(pkb->LinkerObject,stringEvent); + } + else + { + PX_Object_Event_SetKeyDown(&ke,8); + PX_ObjectExecuteEvent(pObject,ke); + strEve[0]=8; + PX_ObjectPostEvent(pkb->LinkerObject,stringEvent); + } + + break; + } + } + } + else if (y<2*kh) + { + for (i=4;i<=7;i++) + { + if (PX_isPointInRect(PX_POINT((px_float)x,(px_float)y,0),PX_RECT((px_float)pkb->Keys[i].x,(px_float)pkb->Keys[i].y,(px_float)pkb->Keys[i].width,(px_float)pkb->Keys[i].height))) + { + PX_Object_Event_SetKeyDown(&ke,pkb->Keys[i].u_key[0]); + PX_ObjectExecuteEvent(pObject,ke); + strEve[0]=pkb->Keys[i].u_key[0]; + PX_ObjectPostEvent(pkb->LinkerObject,stringEvent); + pkb->Keys[i].bDown=PX_TRUE; + + break; + } + } + } + else if (y<3*kh) + { + for (i=7;i<=10;i++) + { + if (PX_isPointInRect(PX_POINT((px_float)x,(px_float)y,0),PX_RECT((px_float)pkb->Keys[i].x,(px_float)pkb->Keys[i].y,(px_float)pkb->Keys[i].width,(px_float)pkb->Keys[i].height))) + { + PX_Object_Event_SetKeyDown(&ke,pkb->Keys[i].u_key[0]); + PX_ObjectExecuteEvent(pObject,ke); + strEve[0]=pkb->Keys[i].u_key[0]; + PX_ObjectPostEvent(pkb->LinkerObject,stringEvent); + pkb->Keys[i].bDown=PX_TRUE; + break; + } + } + } + else if (y<4*kh) + { + for (i=11;i<=14;i++) + { + if (PX_isPointInRect(PX_POINT((px_float)x,(px_float)y,0),PX_RECT((px_float)pkb->Keys[i].x,(px_float)pkb->Keys[i].y,(px_float)pkb->Keys[i].width,(px_float)pkb->Keys[i].height))) + { + if (i!=14) + { + PX_Object_Event_SetKeyDown(&ke,pkb->Keys[i].u_key[0]); + PX_ObjectExecuteEvent(pObject,ke); + strEve[0]=pkb->Keys[i].u_key[0]; + PX_ObjectPostEvent(pkb->LinkerObject,stringEvent); + } + else + { + PX_Object_Event_SetKeyDown(&ke,'\r'); + PX_ObjectExecuteEvent(pObject,ke); + strEve[0]='\r'; + PX_ObjectPostEvent(pkb->LinkerObject,stringEvent); + } + pkb->Keys[i].bDown=PX_TRUE; + break; + } + } + } + else + { + for (i=14;i<=16;i++) + { + if (PX_isPointInRect(PX_POINT((px_float)x,(px_float)y,0),PX_RECT((px_float)pkb->Keys[i].x,(px_float)pkb->Keys[i].y,(px_float)pkb->Keys[i].width,(px_float)pkb->Keys[i].height))) + { + if (i!=14) + { + PX_Object_Event_SetKeyDown(&ke,pkb->Keys[i].u_key[0]); + PX_ObjectExecuteEvent(pObject,ke); + strEve[0]=pkb->Keys[i].u_key[0]; + PX_ObjectPostEvent(pkb->LinkerObject,stringEvent); + } + else + { + PX_Object_Event_SetKeyDown(&ke,'\r'); + PX_ObjectExecuteEvent(pObject,ke); + strEve[0]='\r'; + PX_ObjectPostEvent(pkb->LinkerObject,stringEvent); + } + pkb->Keys[i].bDown=PX_TRUE; + break; + } + } + } +} +PX_Object* PX_Object_VirtualNumberKeyBoardCreate(px_memorypool *mp, PX_Object *Parent,px_int x,px_int y,px_int width,px_int height) +{ + px_int i; + px_int kw,kh; + px_int xoffset,yoffset; + PX_Object_VirtualNumberKeyBoard keyboard; + px_char line1_lower[]=" /*-"; + px_char line2_lower[]="789+"; + px_char line3_lower[]="456"; + px_char line4_lower[]="123 "; + px_char line5_lower[]="0."; + + PX_Object *keyboardObject; + + if (width<16*4||height<16*5) + { + return PX_NULL; + } + PX_memset(&keyboard,0,sizeof(PX_Object_VirtualNumberKeyBoard)); + + kw=width/4; + kh=height/5; + + xoffset=0; + yoffset=0; + + for (i=0;i<=3;i++) + { + keyboard.Keys[i].d_key[0]=line1_lower[i]; + keyboard.Keys[i].u_key[0]=line1_lower[i]; + keyboard.Keys[i].x=xoffset; + keyboard.Keys[i].y=yoffset; + keyboard.Keys[i].width=kw; + keyboard.Keys[i].height=kh; + xoffset+=kw; + } + PX_strset(keyboard.Keys[0].d_key,"<--"); + PX_strset(keyboard.Keys[0].u_key,"<--"); + xoffset=0; + yoffset=1*kh; + + for (i=4;i<=7;i++) + { + keyboard.Keys[i].d_key[0]=line2_lower[i-4]; + keyboard.Keys[i].u_key[0]=line2_lower[i-4]; + keyboard.Keys[i].x=xoffset; + keyboard.Keys[i].y=yoffset; + keyboard.Keys[i].width=kw; + keyboard.Keys[i].height=kh; + xoffset+=keyboard.Keys[i].width; + } + keyboard.Keys[7].height*=2; + + xoffset=0; + yoffset=2*kh; + for (i=8;i<=10;i++) + { + keyboard.Keys[i].d_key[0]=line3_lower[i-8]; + keyboard.Keys[i].u_key[0]=line3_lower[i-8]; + keyboard.Keys[i].x=xoffset; + keyboard.Keys[i].y=yoffset; + keyboard.Keys[i].width=kw; + keyboard.Keys[i].height=kh; + xoffset+=keyboard.Keys[i].width; + } + + xoffset=0; + yoffset=3*kh; + for (i=11;i<=14;i++) + { + keyboard.Keys[i].d_key[0]=line4_lower[i-11]; + keyboard.Keys[i].u_key[0]=line4_lower[i-11]; + keyboard.Keys[i].x=xoffset; + keyboard.Keys[i].y=yoffset; + keyboard.Keys[i].width=kw; + keyboard.Keys[i].height=kh; + xoffset+=keyboard.Keys[i].width; + } + + + PX_strset(keyboard.Keys[14].d_key,"Enter"); + PX_strset(keyboard.Keys[14].u_key,"Enter"); + keyboard.Keys[14].height*=2; + + xoffset=0; + yoffset=4*kh; + + keyboard.Keys[15].d_key[0]='0'; + keyboard.Keys[15].u_key[0]='0'; + keyboard.Keys[15].x=xoffset; + keyboard.Keys[15].y=yoffset; + keyboard.Keys[15].width=kw*2; + keyboard.Keys[15].height=kh; + xoffset+=keyboard.Keys[15].width; + + + keyboard.Keys[16].d_key[0]='.'; + keyboard.Keys[16].u_key[0]='.'; + keyboard.Keys[16].x=xoffset; + keyboard.Keys[16].y=yoffset; + keyboard.Keys[16].width=kw; + keyboard.Keys[16].height=kh; + xoffset+=keyboard.Keys[16].width; + + keyboard.cursorColor=PX_COLOR(255,192,192,192); + keyboard.pushColor=PX_COLOR(255,128,128,128); + keyboard.backgroundColor=PX_COLOR(255,255,255,255); + keyboard.borderColor=PX_COLOR(255,0,0,0); + keyboard.LinkerObject=PX_NULL; + keyboardObject=PX_ObjectCreateEx(mp,Parent,(px_float)x,(px_float)y,0,(px_float)width,(px_float)height,0,PX_OBJECT_TYPE_VNKEYBOARD,PX_NULL,PX_Object_VirtualNumberKeyBoardRender,PX_NULL,&keyboard,sizeof(PX_Object_VirtualNumberKeyBoard)); + + PX_ObjectRegisterEvent(keyboardObject,PX_OBJECT_EVENT_CURSORMOVE,PX_Object_VirtualNumberKeyBoardOnCursorMove,PX_NULL); + PX_ObjectRegisterEvent(keyboardObject,PX_OBJECT_EVENT_CURSORDRAG,PX_Object_VirtualNumberKeyBoardOnCursorMove,PX_NULL); + PX_ObjectRegisterEvent(keyboardObject,PX_OBJECT_EVENT_CURSORDOWN,PX_Object_VirtualNumberKeyBoardOnCursorDown,PX_NULL); + PX_ObjectRegisterEvent(keyboardObject,PX_OBJECT_EVENT_CURSORUP,PX_Object_VirtualNumberKeyBoardOnCursorUp,PX_NULL); + return keyboardObject; +} + +px_void PX_Object_VirtualNumberKeyBoardSetBackgroundColor(PX_Object *pObject,px_color Color) +{ + PX_Object_VirtualNumberKeyBoard *pkb=PX_Object_GetVirtualNumberKeyBoard(pObject); + if (pkb) + { + pkb->backgroundColor=Color; + } +} + +px_void PX_Object_VirtualNumberKeyBoardSetBorderColor(PX_Object *pObject,px_color Color) +{ + PX_Object_VirtualNumberKeyBoard *pkb=PX_Object_GetVirtualNumberKeyBoard(pObject); + if (pkb) + { + pkb->borderColor=Color; + } +} + +px_void PX_Object_VirtualNumberKeyBoardSetCursorColor(PX_Object *pObject,px_color Color) +{ + PX_Object_VirtualNumberKeyBoard *pkb=PX_Object_GetVirtualNumberKeyBoard(pObject); + if (pkb) + { + pkb->cursorColor=Color; + } +} + +px_void PX_Object_VirtualNumberKeyBoardSetPushColor(PX_Object *pObject,px_color Color) +{ + PX_Object_VirtualNumberKeyBoard *pkb=PX_Object_GetVirtualNumberKeyBoard(pObject); + if (pkb) + { + pkb->pushColor=Color; + } +} + +px_char PX_Object_VirtualNumberKeyBoardGetCode(PX_Object *pObject) +{ + PX_Object_VirtualNumberKeyBoard *pkb=PX_Object_GetVirtualNumberKeyBoard(pObject); + if (pkb) + { + px_char ch= pkb->functionCode; + pkb->functionCode=0; + return ch; + } + return 0; +} + +px_void PX_Object_VirtualNumberKeyBoardSetLinkerObject(PX_Object *pObject,PX_Object *linker) +{ + PX_Object_VirtualNumberKeyBoard *pkb=PX_Object_GetVirtualNumberKeyBoard(pObject); + if (pkb) + { + pkb->LinkerObject=linker; + } +} diff --git a/lib/PainterEngine/kernel/PX_Object_VirtualKeyboard.h b/lib/PainterEngine/kernel/PX_Object_VirtualKeyboard.h new file mode 100644 index 0000000000000000000000000000000000000000..2a803866218555cb991c36b662641729cfb89023 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_VirtualKeyboard.h @@ -0,0 +1,56 @@ +#ifndef PX_OBJECT_VKBOARD_H +#define PX_OBJECT_VKBOARD_H +#include "PX_Object.h" +typedef struct +{ + px_int x,y,width,height; + px_char u_key[8]; + px_char d_key[8]; + px_bool bCursor; + px_bool bDown; + px_bool bhold; + +}PX_Object_VirtualKey; + +typedef struct +{ + PX_Object_VirtualKey Keys[14+14+13+12+3]; + px_color backgroundColor; + px_color borderColor; + px_color cursorColor; + px_color pushColor; + px_char functionCode; + PX_Object *LinkerObject; + px_bool bTab,bUpper,bShift,bCtrl,bAlt; +}PX_Object_VirtualKeyBoard; + +PX_Object* PX_Object_VirtualKeyBoardCreate(px_memorypool *mp, PX_Object *Parent,px_int x,px_int y,px_int width,px_int height); +px_void PX_Object_VirtualKeyBoardSetBackgroundColor( PX_Object *pObject,px_color Color ); +px_void PX_Object_VirtualKeyBoardSetBorderColor( PX_Object *pObject,px_color Color ); +px_void PX_Object_VirtualKeyBoardSetCursorColor( PX_Object *pObject,px_color Color ); +px_void PX_Object_VirtualKeyBoardSetPushColor( PX_Object *pObject,px_color Color ); +px_char PX_Object_VirtualKeyBoardGetCode(PX_Object *pObject); +px_void PX_Object_VirtualKeyBoardSetLinkerObject(PX_Object *pObject,PX_Object *linker); + +typedef struct +{ + PX_Object_VirtualKey Keys[17]; + px_color backgroundColor; + px_color borderColor; + px_color cursorColor; + px_color pushColor; + px_char functionCode; + PX_Object *LinkerObject; +}PX_Object_VirtualNumberKeyBoard; + +PX_Object* PX_Object_VirtualNumberKeyBoardCreate(px_memorypool *mp, PX_Object *Parent,px_int x,px_int y,px_int width,px_int height); +px_void PX_Object_VirtualNumberKeyBoardSetBackgroundColor( PX_Object *pObject,px_color Color ); +px_void PX_Object_VirtualNumberKeyBoardSetBorderColor( PX_Object *pObject,px_color Color ); +px_void PX_Object_VirtualNumberKeyBoardSetCursorColor( PX_Object *pObject,px_color Color ); +px_void PX_Object_VirtualNumberKeyBoardSetPushColor( PX_Object *pObject,px_color Color ); +px_char PX_Object_VirtualNumberKeyBoardGetCode(PX_Object *pObject); +px_void PX_Object_VirtualNumberKeyBoardSetLinkerObject(PX_Object *pObject,PX_Object *linker); + + +#endif + diff --git a/lib/PainterEngine/kernel/PX_Object_Widget.c b/lib/PainterEngine/kernel/PX_Object_Widget.c new file mode 100644 index 0000000000000000000000000000000000000000..9466ac83cce2b55c20a3248ca17fd6e093f3d30a --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_Widget.c @@ -0,0 +1,356 @@ +#include "PX_Object_Widget.h" + + +px_void PX_Object_WidgetFree(PX_Object *pObject) +{ + PX_Object_Widget *pWidget=PX_Object_GetWidget(pObject); + if (pWidget) + { + PX_ObjectDelete(pWidget->root); + PX_TextureFree(&pWidget->renderTarget); + } +} + +px_void PX_Object_WidgetLinkChild(PX_Object *parent,PX_Object *child) +{ + PX_ObjectAddClild(PX_Object_WidgetGetRoot(parent),child); +} + +px_void PX_Object_WidgetShow(PX_Object *pObject) +{ + PX_Object_Widget *pWidget=PX_Object_GetWidget(pObject); + if (pWidget) + { + pObject->Visible=PX_TRUE; + PX_ObjectSetFocus(pObject); + } +} + +px_void PX_Object_WidgetHide(PX_Object *pObject) +{ + PX_Object_Widget *pWidget=PX_Object_GetWidget(pObject); + if (pWidget) + { + pObject->Visible=PX_FALSE; + PX_ObjectReleaseFocus(pObject); + } +} + +px_void PX_Object_WidgetShowHideCloseButton(PX_Object *pObject,px_bool show) +{ + PX_Object_Widget *pWidget=PX_Object_GetWidget(pObject); + if (pWidget) + { + pWidget->btn_close->Visible=show; + } +} + +static px_void PX_Object_WidgetOnButtonClose(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + PX_Object *pWidgetObject=(PX_Object *)ptr; + PX_ObjectExecuteEvent(pWidgetObject, PX_OBJECT_BUILD_EVENT(PX_OBJECT_EVENT_CLOSE)); + PX_Object_WidgetHide(pWidgetObject); + +} + +px_void PX_Object_Widget_EventDispatcher(PX_Object *pObject,PX_Object_Event e,px_void *ptr) +{ + PX_Object_Event oe; + PX_Object_Widget *pwidget=PX_Object_GetWidget(pObject); + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + + switch(e.Event) + { + case PX_OBJECT_EVENT_CURSORDOWN: + { + px_float x,y; + + if (PX_ObjectIsCursorInRegion(pObject,e)) + { + PX_ObjectSetFocus(pObject); + x=PX_Object_Event_GetCursorX(e); + y=PX_Object_Event_GetCursorY(e); + if (!pwidget->bDraging) + { + if (x>objx&&xWidth&&y>objy&&y<=objy+PX_OBJECT_WIDGET_BAR_SIZE) + { + if (pwidget->bmoveable) + { + pwidget->bDraging=PX_TRUE; + pwidget->lastDragPosition.x=x; + pwidget->lastDragPosition.y=y; + pwidget->lastDragPosition.z=0; + } + + } + } + pwidget->bevent_update=PX_TRUE; + } + else + { + if (!pwidget->bmodel) + { + PX_ObjectClearFocus(pObject); + } + + } + } + break; + case PX_OBJECT_EVENT_CURSORMOVE: + case PX_OBJECT_EVENT_CURSORUP: + { + pwidget->bDraging=PX_FALSE; + } + break; + case PX_OBJECT_EVENT_CURSORDRAG: + { + if (pwidget->bDraging) + { + px_float x,y; + x=PX_Object_Event_GetCursorX(e); + y=PX_Object_Event_GetCursorY(e); + + pObject->x+=x-pwidget->lastDragPosition.x; + pObject->y+=y-pwidget->lastDragPosition.y; + pwidget->lastDragPosition.x=x; + pwidget->lastDragPosition.y=y; + } + } + break; + default: + { + + } + break; + } + + oe=PX_Object_Event_CursorOffset(e,PX_POINT(-objx,-objy-PX_OBJECT_WIDGET_BAR_SIZE,0)); + PX_ObjectPostEvent(pwidget->root,oe); +} + +px_void PX_Object_WidgetRender(px_surface *psurface, PX_Object *pObject,px_uint elapsed) +{ + PX_Object_Widget *pwidget=PX_Object_GetWidget(pObject); + px_float objx,objy,objWidth,objHeight; + px_float inheritX,inheritY; + + PX_ObjectGetInheritXY(pObject,&inheritX,&inheritY); + + objx=(pObject->x+inheritX); + objy=(pObject->y+inheritY); + objWidth=pObject->Width; + objHeight=pObject->Height; + + if (!pObject->Visible) + { + return; + } + + if (pObject->Width!=(px_int)(pwidget->renderTarget.width)||pObject->Height!=(px_int)(pwidget->renderTarget.height+PX_OBJECT_WIDGET_BAR_SIZE)) + { + px_texture *old=&pwidget->renderTarget; + if(!PX_TextureCreate(pObject->mp,&pwidget->renderTarget,(px_int)pObject->Width,(px_int)pObject->Height+PX_OBJECT_WIDGET_BAR_SIZE))return; + PX_TextureFree(old); + } + + do + { + if (pwidget->event_optimization) + { + if (!pwidget->bevent_update) + { + break; + } + } + + pwidget->bevent_update=PX_FALSE; + PX_SurfaceClear(&pwidget->renderTarget,0,0,pwidget->renderTarget.width-1,pwidget->renderTarget.height-1,pwidget->backgroundcolor); + PX_ObjectRender(&pwidget->renderTarget,pwidget->root,elapsed); + PX_SurfaceRender(psurface,&pwidget->renderTarget,(px_int)objx,(px_int)objy+PX_OBJECT_WIDGET_BAR_SIZE,PX_ALIGN_LEFTTOP,PX_NULL); + } while (0); + + + PX_GeoDrawRect(psurface,(px_int)objx,(px_int)objy,(px_int)(objx+pObject->Width-1),(px_int)objy+PX_OBJECT_WIDGET_BAR_SIZE-1,pwidget->barColor); + + if (pObject->OnFocus) + PX_GeoDrawBorder(psurface,(px_int)objx,(px_int)objy,(px_int)(objx+pObject->Width-1),(px_int)(objy+pObject->Height-1),1,pwidget->focusColor); + else + PX_GeoDrawBorder(psurface,(px_int)objx,(px_int)objy,(px_int)(objx+pObject->Width-1),(px_int)(objy+pObject->Height-1),1,pwidget->borderColor); + + PX_FontModuleDrawText(psurface,pwidget->fontmodule,(px_int)objx+3,(px_int)objy+3,PX_ALIGN_LEFTTOP,pwidget->title,pwidget->fontcolor); + +} + + +PX_Object * PX_Object_WidgetCreate(px_memorypool *mp,PX_Object *Parent,int x,int y,int width,int height,const px_char title[],PX_FontModule *fontmodule) +{ + PX_Object *pObject; + PX_Object_Widget *pWidget=(PX_Object_Widget *)MP_Malloc(mp,sizeof(PX_Object_Widget)); + + if(width<=0) width=1; + if(height<=PX_OBJECT_WIDGET_BAR_SIZE)height=PX_OBJECT_WIDGET_BAR_SIZE+1; + + if (pWidget==PX_NULL) + { + return PX_NULL; + } + PX_memset(pWidget,0,sizeof(PX_Object_Widget)); + + pObject=PX_ObjectCreate(mp,Parent,(px_float)x,(px_float)y,0,(px_float)width,(px_float)height,0); + + if (pObject==PX_NULL) + { + + return PX_NULL; + } + + pObject->pObject=pWidget; + pObject->Type=PX_OBJECT_TYPE_WIDGET; + pObject->ReceiveEvents=PX_TRUE; + pObject->Func_ObjectFree=PX_Object_WidgetFree; + pObject->Func_ObjectRender=PX_Object_WidgetRender; + pObject->OnLostFocusReleaseEvent=PX_FALSE; + + if (PX_strlen(title)title)-1) + { + PX_strcpy(pWidget->title,title,sizeof(pWidget->title)); + } + + if(!PX_TextureCreate(mp,&pWidget->renderTarget,width,height-PX_OBJECT_WIDGET_BAR_SIZE))return PX_FALSE; + + pWidget->root=PX_ObjectCreate(mp,PX_NULL,0,0,0,0,0,0); + pWidget->btn_close=PX_Object_PushButtonCreate(mp,pObject,width-PX_OBJECT_WIDGET_BAR_SIZE,3,PX_OBJECT_WIDGET_BAR_SIZE-6,PX_OBJECT_WIDGET_BAR_SIZE-6,"-",PX_NULL); + + if(!pWidget->btn_close) goto _ERROR; + pWidget->fontmodule=fontmodule; + + pWidget->backgroundcolor=PX_OBJECT_UI_DEFAULT_BACKGROUNDCOLOR; + pWidget->barColor=PX_COLOR(255,48,48,48); + pWidget->borderColor=PX_OBJECT_UI_DEFAULT_BORDERCOLOR; + pWidget->focusColor=PX_COLOR_WHITE; + pWidget->bevent_update=PX_TRUE; + pWidget->bmoveable=PX_TRUE; + pWidget->fontcolor=PX_OBJECT_UI_DEFAULT_FONTCOLOR; + + PX_ObjectRegisterEvent(pWidget->btn_close,PX_OBJECT_EVENT_EXECUTE,PX_Object_WidgetOnButtonClose,pObject); + PX_ObjectRegisterEvent(pObject,PX_OBJECT_EVENT_ANY,PX_Object_Widget_EventDispatcher,PX_NULL); + + pObject->Func_ObjectLinkChild=PX_Object_WidgetLinkChild; + return pObject; +_ERROR: + if(pWidget) + MP_Free(mp,pWidget); + if(pObject) + PX_ObjectDelete(pObject); + return PX_FALSE; +} + +PX_Object_Widget * PX_Object_GetWidget(PX_Object *Object) +{ + if (Object->Type==PX_OBJECT_TYPE_WIDGET) + { + return (PX_Object_Widget *)Object->pObject; + } + return PX_NULL; +} + +px_void PX_Object_WidgetSetModel(PX_Object *pObject,px_bool model) +{ + PX_Object_Widget *pWidget=PX_Object_GetWidget(pObject); + if (pWidget) + { + pWidget->bmodel=model; + } +} + +PX_Object * PX_Object_WidgetGetRoot(PX_Object *pObject) +{ + PX_Object_Widget *pWidget=PX_Object_GetWidget(pObject); + if (pWidget) + { + return pWidget->root; + } + return PX_NULL; +} + +px_int PX_Object_WidgetGetRenderTargetHeight(PX_Object *pObject) +{ + PX_Object_Widget *pWidget=PX_Object_GetWidget(pObject); + if (pWidget) + { + return pWidget->renderTarget.height; + } + return 0; +} + +px_int PX_Object_WidgetGetRenderTargetWidth(PX_Object *pObject) +{ + PX_Object_Widget *pWidget=PX_Object_GetWidget(pObject); + if (pWidget) + { + return pWidget->renderTarget.width; + } + return 0; +} + +px_void PX_Object_WidgetSetBorderColor(PX_Object *pObject,px_color clr) +{ + PX_Object_Widget *pWidget=PX_Object_GetWidget(pObject); + if (pWidget) + { + pWidget->borderColor=clr; + } +} + +px_void PX_Object_WidgetSetBarColor(PX_Object *pObject,px_color clr) +{ + PX_Object_Widget *pWidget=PX_Object_GetWidget(pObject); + if (pWidget) + { + pWidget->barColor=clr; + } +} + +px_void PX_Object_WidgetSetBackgroundColor(PX_Object *pObject,px_color clr) +{ + PX_Object_Widget *pWidget=PX_Object_GetWidget(pObject); + if (pWidget) + { + pWidget->backgroundcolor=clr; + } +} + +px_void PX_Object_WidgetSetFocusColor(PX_Object *pObject,px_color clr) +{ + PX_Object_Widget *pWidget=PX_Object_GetWidget(pObject); + if (pWidget) + { + pWidget->focusColor=clr; + } +} + +px_void PX_Object_WidgetSetFontColor(PX_Object *pObject,px_color clr) +{ + PX_Object_Widget *pWidget=PX_Object_GetWidget(pObject); + if (pWidget) + { + pWidget->fontcolor=clr; + } +} + +px_void PX_Object_WidgetSetTitle(PX_Object *pObject,const px_char title[]) +{ + PX_Object_Widget *pWidget=PX_Object_GetWidget(pObject); + if (pWidget) + { + PX_strcpy(pWidget->title,title,sizeof(pWidget->title)); + } +} diff --git a/lib/PainterEngine/kernel/PX_Object_Widget.h b/lib/PainterEngine/kernel/PX_Object_Widget.h new file mode 100644 index 0000000000000000000000000000000000000000..6f6cc4c302af4c8806802761549c3f0ded64b4e8 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Object_Widget.h @@ -0,0 +1,40 @@ +#ifndef PX_OBJECT_WIDGET_H +#define PX_OBJECT_WIDGET_H +#include "PX_Object.h" + +#define PX_OBJECT_WIDGET_TITLE_LEN 64 +#define PX_OBJECT_WIDGET_BAR_SIZE 28 +typedef struct +{ + PX_Object *root; + PX_Object *btn_close; + px_color borderColor,barColor,backgroundcolor,focusColor,fontcolor; + px_char title[PX_OBJECT_WIDGET_TITLE_LEN]; + PX_FontModule *fontmodule; + px_texture renderTarget;//optimization for render + px_point lastDragPosition; + px_bool bDraging; + px_bool bmoveable; + px_bool bmodel; + px_bool event_optimization; + px_bool bevent_update; +}PX_Object_Widget; + +PX_Object_Widget * PX_Object_GetWidget( PX_Object *Object ); +PX_Object * PX_Object_WidgetCreate(px_memorypool *mp,PX_Object *Parent,int x,int y,int width,int height,const px_char title[],PX_FontModule *fontmodule); +px_void PX_Object_WidgetShow(PX_Object *pObject); +px_void PX_Object_WidgetHide(PX_Object *pObject); +px_void PX_Object_WidgetShowHideCloseButton(PX_Object *pObject,px_bool show); +px_void PX_Object_WidgetSetModel(PX_Object *Object,px_bool model); +PX_Object * PX_Object_WidgetGetRoot(PX_Object *pObject); +px_int PX_Object_WidgetGetRenderTargetHeight(PX_Object *pObject); +px_int PX_Object_WidgetGetRenderTargetWidth(PX_Object *pObject); + +px_void PX_Object_WidgetSetBorderColor(PX_Object *pObject,px_color clr); +px_void PX_Object_WidgetSetBarColor(PX_Object *pObject,px_color clr); +px_void PX_Object_WidgetSetBackgroundColor(PX_Object *pObject,px_color clr); +px_void PX_Object_WidgetSetFocusColor(PX_Object *pObject,px_color clr); +px_void PX_Object_WidgetSetFontColor(PX_Object *pObject,px_color clr); +px_void PX_Object_WidgetSetTitle(PX_Object *pObject,const px_char title[]); +#endif + diff --git a/lib/PainterEngine/kernel/PX_Partical.c b/lib/PainterEngine/kernel/PX_Partical.c new file mode 100644 index 0000000000000000000000000000000000000000..ba75a117fdcfe25f0e7b4fac00aa2815db0cb862 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Partical.c @@ -0,0 +1,392 @@ +#include "PX_Partical.h" + + + +px_void PX_ParticalLauncherInitializeDefault(PX_ParticalLauncher_InitializeInfo* info) +{ + PX_memset(info, 0, sizeof(PX_ParticalLauncher_InitializeInfo)); + info->ak = 1; + info->alive = -1; + info->alpha = 1; + info->atomsize = 1; + info->hdrB = 1; + info->hdrG = 1; + info->hdrR = 1; + info->launchCount = -1; + info->maxCount = 100; +} + +px_bool PX_ParticalLauncherCreate(PX_Partical_Launcher *launcher,px_memorypool *mp,PX_ParticalLauncher_InitializeInfo Info) +{ + PX_memset(launcher,0,sizeof(PX_Partical_Launcher)); + launcher->LauncherInfo=Info; + launcher->mp=mp; + + launcher->ParticalPool=(PX_Partical_Atom *)MP_Malloc(mp,sizeof(PX_Partical_Atom)*launcher->LauncherInfo.maxCount); + PX_memset(launcher->ParticalPool,0,sizeof(PX_Partical_Atom)*launcher->LauncherInfo.maxCount); + return PX_TRUE; +} + + +px_void PX_ParticalLauncherSetPosition(PX_Partical_Launcher *launcher,px_float x,px_float y,px_float z) +{ + launcher->LauncherInfo.position=PX_POINT(x,y,z); +} + +px_void PX_ParticalAtomUpdate(PX_Partical_Launcher *env,PX_Partical_Atom *pAtom,px_dword elapsed) +{ + px_int updateTime; + px_int atomTime; + px_point ak; + + if (elapsed==0) + { + return; + } + if (pAtom->reg_alive) + { + if (pAtom->reg_alivereg_alive=0; + return; + } + else + { + pAtom->reg_alive-=elapsed; + pAtom->elapsedTime+=elapsed; + } + + updateTime=elapsed; + + while (updateTime) + { + if (updateTime>PX_PARTICAL_ATOM_TIME) + { + atomTime=PX_PARTICAL_ATOM_TIME; + updateTime-=PX_PARTICAL_ATOM_TIME; + } + else + { + atomTime=updateTime; + updateTime=0; + } + + pAtom->reg_size+=pAtom->reg_sizeinc*atomTime/1000.f; + pAtom->reg_alpha+=pAtom->reg_alphainc*atomTime/1000.f; + pAtom->reg_currentrotation+=pAtom->reg_rotation*atomTime/1000.f; + + pAtom->velocity.x+=pAtom->reg_a.x*atomTime/1000.f; + pAtom->velocity.y+=pAtom->reg_a.y*atomTime/1000.f; + pAtom->velocity.z+=pAtom->reg_a.z*atomTime/1000.f; + + ak=PX_PointMul(pAtom->velocity,1.0f-pAtom->reg_ak); + PX_PointMul(ak,atomTime/1000.f); + pAtom->velocity.x-=ak.x; + pAtom->velocity.y-=ak.y; + pAtom->velocity.z-=ak.z; + + pAtom->position.x += pAtom->velocity.x * atomTime / 1000.f; + pAtom->position.y += pAtom->velocity.y * atomTime / 1000.f; + pAtom->position.z += pAtom->velocity.z * atomTime / 1000.f; + } + + + if (env->LauncherInfo.Update_func) + { + env->LauncherInfo.Update_func(env,pAtom); + } + + + if (pAtom->reg_size<0) + { + pAtom->reg_size=0; + } + + if (pAtom->hdrR<0) + { + pAtom->hdrR=0; + } + + if (pAtom->hdrG<0) + { + pAtom->hdrG=0; + } + + if (pAtom->hdrB<0) + { + pAtom->hdrB=0; + } + + if (pAtom->reg_alpha<0) + { + pAtom->reg_alpha=0; + } + } + + +} + +px_void PX_ParticalLauncherUpdate(PX_Partical_Launcher *launcher,px_dword elapsed) +{ + px_int i,j; + px_int redTime=0; + px_int gencount=0; + PX_Partical_Atom *pAtom; + + launcher->lefttopX=0; + launcher->leftTopY=0; + launcher->rightBottomX=0; + launcher->rightBottomY=0; + + for (i=0;i<(px_int)launcher->LauncherInfo.maxCount;i++) + { + pAtom=&launcher->ParticalPool[i]; + PX_ParticalAtomUpdate(launcher,pAtom,elapsed); + if (pAtom->reg_alive!=0) + { + if (launcher->ParticalPool[i].position.xlefttopX) + { + launcher->lefttopX=launcher->ParticalPool[i].position.x; + } + if (launcher->ParticalPool[i].position.x>launcher->rightBottomX) + { + launcher->rightBottomX=launcher->ParticalPool[i].position.x; + } + if (launcher->ParticalPool[i].position.yleftTopY) + { + launcher->leftTopY=launcher->ParticalPool[i].position.y; + } + if (launcher->ParticalPool[i].position.y>launcher->rightBottomY) + { + launcher->rightBottomY=launcher->ParticalPool[i].position.y; + } + } + } + if(launcher->LauncherInfo.launchCount!=0) + { + if (launcher->LauncherInfo.generateDuration!=0) + { + if (launcher->elapsed/launcher->LauncherInfo.generateDuration<((launcher->elapsed+elapsed)/launcher->LauncherInfo.generateDuration)) + { + gencount=(launcher->elapsed+elapsed)/launcher->LauncherInfo.generateDuration-launcher->elapsed/launcher->LauncherInfo.generateDuration; + redTime=launcher->elapsed+elapsed-(launcher->elapsed+launcher->LauncherInfo.generateDuration)/launcher->LauncherInfo.generateDuration*launcher->LauncherInfo.generateDuration; + } + else + gencount=0; + } + else + { + gencount=launcher->LauncherInfo.maxCount; + redTime=elapsed; + } + + + for (i=0;iLauncherInfo.launchCount!=0) + { + for (j=0;j<(px_int)launcher->LauncherInfo.maxCount;j++) + { + if (launcher->ParticalPool[j].reg_alive==0) + { + px_float dirAngle; + px_float var; + PX_memset(&launcher->ParticalPool[j],0,sizeof(launcher->ParticalPool[j])); + launcher->lastgenIndex = j; + //position + launcher->ParticalPool[j].position = launcher->LauncherInfo.position; + //velocity + dirAngle = (px_float)PX_RadianToAngle(PX_atan2(launcher->LauncherInfo.direction.y, launcher->LauncherInfo.direction.x)); + dirAngle += (px_float)PX_randRange(-launcher->LauncherInfo.deviation_rangAngle, launcher->LauncherInfo.deviation_rangAngle); + var = launcher->LauncherInfo.velocity; + var += (px_float)PX_randRange(-launcher->LauncherInfo.deviation_velocity, launcher->LauncherInfo.deviation_velocity); + launcher->ParticalPool[j].velocity = PX_POINT(PX_cos_angle(dirAngle), PX_sin_angle(dirAngle), 0); + launcher->ParticalPool[j].velocity = PX_PointMul(launcher->ParticalPool[j].velocity, var); + //size + var = launcher->LauncherInfo.atomsize; + var += (px_float)PX_randRange(-launcher->LauncherInfo.deviation_atomsize, launcher->LauncherInfo.deviation_atomsize); + if (var < 0)var = 0; + launcher->ParticalPool[j].reg_size = var; + //rotation + var = launcher->LauncherInfo.rotation; + var += (px_float)PX_randRange(-launcher->LauncherInfo.deviation_rotation, launcher->LauncherInfo.deviation_rotation); + launcher->ParticalPool[j].reg_rotation = var; + //alpha + var = launcher->LauncherInfo.alpha; + var += (px_float)PX_randRange(-launcher->LauncherInfo.deviation_alpha, launcher->LauncherInfo.deviation_alpha); + if (var < 0)var = 0; + launcher->ParticalPool[j].reg_alpha = var; + + //hdrR + var = launcher->LauncherInfo.hdrR; + var += (px_float)PX_randRange(-launcher->LauncherInfo.deviation_hdrR, launcher->LauncherInfo.deviation_hdrR); + if (var < 0)var = 0; + launcher->ParticalPool[j].hdrR = var; + + //hdrG + var = launcher->LauncherInfo.hdrG; + var += (px_float)PX_randRange(-launcher->LauncherInfo.deviation_hdrG, launcher->LauncherInfo.deviation_hdrG); + if (var < 0)var = 0; + launcher->ParticalPool[j].hdrG = var; + + //hdrB + var = launcher->LauncherInfo.hdrB; + var += (px_float)PX_randRange(-launcher->LauncherInfo.deviation_hdrB, launcher->LauncherInfo.deviation_hdrB); + if (var < 0)var = 0; + launcher->ParticalPool[j].hdrB = var; + + //size inc + launcher->ParticalPool[j].reg_sizeinc = launcher->LauncherInfo.sizeincrease; + //alpha inc + launcher->ParticalPool[j].reg_alphainc = launcher->LauncherInfo.alphaincrease; + //a + launcher->ParticalPool[j].reg_a = launcher->LauncherInfo.a; + //ak + launcher->ParticalPool[j].reg_ak = launcher->LauncherInfo.ak; + //alive + launcher->ParticalPool[j].reg_alive = launcher->LauncherInfo.alive; + //texture + launcher->ParticalPool[j].ptexture = launcher->LauncherInfo.tex; + + if (launcher->LauncherInfo.Create_func) + { + launcher->ParticalPool[j]=launcher->LauncherInfo.Create_func(launcher,launcher->genIndex); + } + + PX_ParticalAtomUpdate(launcher,&launcher->ParticalPool[j],redTime); + + if (launcher->ParticalPool[j].position.xlefttopX) + { + launcher->lefttopX=launcher->ParticalPool[j].position.x; + } + if (launcher->ParticalPool[j].position.x>launcher->rightBottomX) + { + launcher->rightBottomX=launcher->ParticalPool[j].position.x; + } + if (launcher->ParticalPool[j].position.yleftTopY) + { + launcher->leftTopY=launcher->ParticalPool[j].position.y; + } + if (launcher->ParticalPool[j].position.y>launcher->rightBottomY) + { + launcher->rightBottomY=launcher->ParticalPool[j].position.y; + } + if(redTime>launcher->LauncherInfo.generateDuration) + { + redTime-=launcher->LauncherInfo.generateDuration; + } + else + { + redTime=0; + } + + launcher->genIndex++; + if (launcher->LauncherInfo.launchCount>0) + { + launcher->LauncherInfo.launchCount--; + } + break; + } + } + } + + } + } + launcher->elapsed+=elapsed; +} + +px_bool PX_ParticalIsInSurfaceRegion(px_point atomPoint,px_int atomWidth,px_int atomHeight,px_float scale,px_int surfaceWidth,px_int surfaceHeight) +{ + px_rect atomRect; + px_rect surfaceRect; + atomRect.x=atomPoint.x; + atomRect.y=atomPoint.y; + atomRect.width=atomWidth*scale; + atomRect.height=atomHeight*scale; + + surfaceRect.x=0; + surfaceRect.y=0; + surfaceRect.height=(px_float)surfaceHeight; + surfaceRect.width=(px_float)surfaceWidth; + + return PX_isRectCrossRect(atomRect,surfaceRect); +} + +px_void PX_ParticalLauncherRender(px_surface *surface,PX_Partical_Launcher *launcher, px_dword elapsed) +{ + px_int m,i; + PX_TEXTURERENDER_BLEND blend; + PX_ParticalLauncherUpdate(launcher, elapsed); + + if (!PX_isRectCrossRect(PX_RECT(0,0,(px_float)surface->width,(px_float)surface->height),\ + PX_RECT(launcher->lefttopX+ launcher->LauncherInfo.position.x,launcher->leftTopY+ launcher->LauncherInfo.position.y,launcher->rightBottomX-launcher->lefttopX+1,launcher->rightBottomY-launcher->leftTopY+1))) + { + return; + } + + i = launcher->lastgenIndex + 1; + + for (m =0; m LauncherInfo.maxCount;m++,i++) + { + px_point pos; + if (i>= launcher->LauncherInfo.maxCount) + { + i = 0; + } + + pos=launcher->ParticalPool[i].position; + + if (!launcher->ParticalPool[i].ptexture) + { + continue; + } + + if (launcher->ParticalPool[i].reg_alive!=0&&launcher->ParticalPool[i].reg_size!=0) + { + if (launcher->ParticalPool[i].reg_size!=1.0||launcher->ParticalPool[i].reg_currentrotation!=0) + { + if (launcher->ParticalPool[i].reg_size<0) + { + launcher->ParticalPool[i].reg_size=0; + continue; + } + if(launcher->ParticalPool[i].reg_alpha==1.0&&launcher->ParticalPool[i].hdrR==1.0f&&launcher->ParticalPool[i].hdrG==1.0f&&launcher->ParticalPool[i].hdrB==1.0f) + PX_TextureRenderEx(surface,launcher->ParticalPool[i].ptexture,(px_int)(pos.x),(px_int)(pos.y),PX_ALIGN_CENTER,PX_NULL,launcher->ParticalPool[i].reg_size,launcher->ParticalPool[i].reg_currentrotation); + else + { + blend.alpha = launcher->ParticalPool[i].reg_alpha; + blend.hdr_R=launcher->ParticalPool[i].hdrR; + blend.hdr_G=launcher->ParticalPool[i].hdrG; + blend.hdr_B=launcher->ParticalPool[i].hdrB; + PX_TextureRenderEx(surface,launcher->ParticalPool[i].ptexture,(px_int)(pos.x),(px_int)(pos.y),PX_ALIGN_CENTER,&blend,launcher->ParticalPool[i].reg_size,launcher->ParticalPool[i].reg_currentrotation); + } + } + else + { + if(launcher->ParticalPool[i].reg_alpha==1.0&&launcher->ParticalPool[i].hdrR==1.0f&&launcher->ParticalPool[i].hdrG==1.0f&&launcher->ParticalPool[i].hdrB==1.0f) + PX_TextureRender(surface,launcher->ParticalPool[i].ptexture,(px_int)(pos.x),(px_int)(pos.y),PX_ALIGN_CENTER,PX_NULL); + else + { + blend.alpha=launcher->ParticalPool[i].reg_alpha; + blend.hdr_R=launcher->ParticalPool[i].hdrR; + blend.hdr_G=launcher->ParticalPool[i].hdrG; + blend.hdr_B=launcher->ParticalPool[i].hdrB; + PX_TextureRender(surface,launcher->ParticalPool[i].ptexture,(px_int)(pos.x),(px_int)(pos.y),PX_ALIGN_CENTER,&blend); + } + } + } + } + +} + +px_void PX_ParticalLauncherFree(PX_Partical_Launcher *env) +{ + MP_Free(env->mp,env->ParticalPool); +} + + +px_void PX_ParticalLauncherSetDirection(PX_Partical_Launcher *launcher,px_point direction) +{ + launcher->LauncherInfo.direction=PX_PointNormalization(direction); +} + diff --git a/lib/PainterEngine/kernel/PX_Partical.h b/lib/PainterEngine/kernel/PX_Partical.h new file mode 100644 index 0000000000000000000000000000000000000000..da7b328dc2380b3d42a4c53e87f658533f6223d3 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Partical.h @@ -0,0 +1,101 @@ +#ifndef PX_PARTICAL_H +#define PX_PARTICAL_H +#include "../core/PX_Core.h" + +#define PX_PARTICAL_ATOM_TIME 16 + +typedef struct +{ + px_texture *ptexture; + // + px_point position; + px_point velocity; + px_dword elapsedTime; + + // + px_dword reg_alive; + px_float reg_size; + px_float reg_currentrotation; + px_float reg_alpha; + + px_float hdrR, hdrG, hdrB; + // + px_float reg_rotation; + px_float reg_sizeinc; + px_float reg_alphainc; + px_point reg_a; + px_float reg_ak; +}PX_Partical_Atom; + +struct _PX_Partical_Launcher; + +typedef PX_Partical_Atom (* PX_ParticalLauncher_CreateAtom)(struct _PX_Partical_Launcher *launcher,px_int index); +typedef px_void (* PX_ParticalLauncher_UpdateAtom)(struct _PX_Partical_Launcher *launcher,PX_Partical_Atom *pAtom); + + +typedef struct +{ + px_void *userptr; + px_texture *tex; + px_point position; + + px_point direction; + px_float deviation_rangAngle; + + px_float velocity; + px_float deviation_velocity; + + px_float atomsize; + px_float deviation_atomsize; + + px_float rotation; + px_float deviation_rotation; + + px_float alpha; + px_float deviation_alpha; + + px_float hdrR; + px_float deviation_hdrR; + + px_float hdrG; + px_float deviation_hdrG; + + px_float hdrB; + px_float deviation_hdrB; + + px_float sizeincrease; + px_float alphaincrease; + + px_point a; + px_float ak; + + px_int alive; + px_int generateDuration; + px_int maxCount; + px_int launchCount; + + PX_ParticalLauncher_CreateAtom Create_func; + PX_ParticalLauncher_UpdateAtom Update_func; +}PX_ParticalLauncher_InitializeInfo; + +typedef struct _PX_Partical_Launcher +{ + px_memorypool *mp; + PX_ParticalLauncher_InitializeInfo LauncherInfo; + + px_dword elapsed; + px_int genIndex; + px_int lastgenIndex; + PX_Partical_Atom *ParticalPool; + px_float lefttopX,leftTopY,rightBottomX,rightBottomY; +}PX_Partical_Launcher; + + +px_void PX_ParticalLauncherInitializeDefault(PX_ParticalLauncher_InitializeInfo* info); +px_bool PX_ParticalLauncherCreate(PX_Partical_Launcher *launcher,px_memorypool *mp,PX_ParticalLauncher_InitializeInfo Info); +px_void PX_ParticalLauncherSetPosition(PX_Partical_Launcher *launcher,px_float x,px_float y,px_float z); +px_void PX_ParticalLauncherSetDirection(PX_Partical_Launcher *launcher,px_point direction); +px_void PX_ParticalLauncherUpdate(PX_Partical_Launcher *launcher,px_dword elapsed); +px_void PX_ParticalLauncherRender(px_surface *surface,PX_Partical_Launcher *launcher,px_dword elapsed); +px_void PX_ParticalLauncherFree(PX_Partical_Launcher *launcher); +#endif diff --git a/lib/PainterEngine/kernel/PX_Resource.c b/lib/PainterEngine/kernel/PX_Resource.c new file mode 100644 index 0000000000000000000000000000000000000000..c93b40d2266bd1e13213e8943ed6af0a60efd2a1 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Resource.c @@ -0,0 +1,318 @@ +#include "PX_Resource.h" + +px_bool PX_ResourceLibraryInitialize(px_memorypool *mp,PX_ResourceLibrary *lib) +{ + lib->mp=mp; + PX_MapInitialize(mp,&lib->map); + PX_ListInitialize(mp,&lib->resources); + return PX_TRUE; +} + +px_bool PX_ResourceLibraryLoad(PX_ResourceLibrary *lib,PX_RESOURCE_TYPE type,px_byte *data,px_uint datasize,const px_char key[]) +{ + PX_Resource res; + res.Type=type; + + if (PX_ResourceLibraryGet(lib,key)) + { + PX_ResourceLibraryDelete(lib,key); + } + + switch (type) + { + case PX_RESOURCE_TYPE_NULL: + break; + case PX_RESOURCE_TYPE_TEXTURE: + if(!PX_TextureCreateFromMemory(lib->mp,data,datasize,&res.texture)) + return PX_FALSE; + break; + case PX_RESOURCE_TYPE_SHAPE: + if(!PX_ShapeCreateFromMemory(lib->mp,data,datasize,&res.shape)) + return PX_FALSE; + break; + case PX_RESOURCE_TYPE_SCRIPT: + /* + if (data[0]!='P'||data[1]!='A'||data[2]!='S'||data[3]!='M') + { + PX_SCRIPT_LIBRARY compilelib; + px_string asmcodeString; + px_memory bin; + MP_Reset(mptemp); + if(!PX_ScriptCompilerInit(&compilelib,mptemp)) + { + return PX_FALSE; + } + + if(!PX_ScriptCompilerLoad(&compilelib,(px_char *)data)) + { + PX_ScriptCompilerFree(&compilelib); + return PX_FALSE; + } + + PX_VectorInitialize(mptemp,&asmcodeString); + + + if(PX_ScriptCompilerCompile(&compilelib,"main",&asmcodeString,256)) + { + PX_ScriptCompilerFree(&compilelib); + + PX_ScriptAsmOptimization(&asmcodeString); + PX_MemoryInit(mptemp,&bin); + + if(!PX_ScriptAsmCompile(mptemp,asmcodeString.buffer,&bin)) + { + PX_MemoryFree(&bin); + PX_StringFree(&asmcodeString); + PX_ScriptCompilerFree(&compilelib); + return PX_FALSE; + } + + if(!PX_ScriptVM_InstanceInit(&res.Script,lib->mp,bin.buffer,bin.usedsize)) + { + PX_MemoryFree(&bin); + PX_StringFree(&asmcodeString); + PX_ScriptCompilerFree(&compilelib); + return PX_FALSE; + } + + PX_MemoryFree(&bin); + } + else + { + PX_StringFree(&asmcodeString); + PX_ScriptCompilerFree(&compilelib); + MP_Reset(mptemp); + return PX_FALSE; + } + + PX_StringFree(&asmcodeString); + + MP_Reset(mptemp); + } + else + */ + if(!PX_ScriptVM_InstanceInitialize(&res.Script,lib->mp,data,datasize)) + return PX_FALSE; + break; + case PX_RESOURCE_TYPE_ANIMATIONLIBRARY: + if(!PX_AnimationLibraryCreateFromMemory(lib->mp,&res.animationlibrary,data,datasize)) + return PX_FALSE; + break; + case PX_RESOURCE_TYPE_SOUND: + if (PX_WaveVerify(data,datasize)) + { + px_uint offset=0,pcmSize,woffset; + pcmSize=PX_WaveGetPCMSize(data,datasize); + + if (pcmSize!=0) + { + PX_WAVE_DATA_BLOCK *pBlock; + PX_WAVE_RIFF_HEADER *pHeader=(PX_WAVE_RIFF_HEADER *)data; + PX_WAVE_FMT_BLOCK *pfmt_block; + res.sound.mp=lib->mp; + res.sound.buffer=(px_byte *)MP_Malloc(lib->mp,pcmSize); + res.sound.size=pcmSize; + res.sound.channel=PX_WaveGetChannel(data,pcmSize)==1?PX_SOUND_CHANNEL_ONE:PX_SOUND_CHANNEL_DOUBLE; + if (!res.sound.buffer) + { + return PX_FALSE; + } + pfmt_block=(PX_WAVE_FMT_BLOCK *)(data+sizeof(PX_WAVE_RIFF_HEADER)); + offset+=sizeof(PX_WAVE_RIFF_HEADER); + offset+=8; + offset+=pfmt_block->dwFmtSize; + + pcmSize=0; + woffset=0; + while (offsetszDataID,"data",4)) + { + offset+=pBlock->dwDataSize+sizeof(PX_WAVE_DATA_BLOCK); + continue; + } + offset+=sizeof(PX_WAVE_DATA_BLOCK); + PX_memcpy(res.sound.buffer+woffset,data+offset,pBlock->dwDataSize); + offset+=pBlock->dwDataSize; + woffset+=pBlock->dwDataSize; + } + } + else + return PX_FALSE; + } + else + { + return PX_FALSE; + } + break; + case PX_RESOURCE_TYPE_DATA: + PX_MemoryInitialize(lib->mp,&res.data); + if (!PX_MemoryCat(&res.data,data,datasize)) + { + PX_MemoryFree(&res.data); + return PX_FALSE; + } + break; + } + + PX_MapPut(&lib->map,key,PX_ListPush(&lib->resources,&res,sizeof(res))); + return PX_TRUE; +} + +px_void PX_ResourceLibraryFree(PX_ResourceLibrary *lib) +{ + PX_Resource *pres; + px_list_node *pNode=lib->resources.head; + while (pNode) + { + pres=(PX_Resource *)pNode->pdata; + switch(pres->Type) + { + case PX_RESOURCE_TYPE_NULL: + break; + case PX_RESOURCE_TYPE_TEXTURE: + PX_TextureFree(&pres->texture); + break; + case PX_RESOURCE_TYPE_SCRIPT: + PX_ScriptVM_InstanceFree(&pres->Script); + break; + case PX_RESOURCE_TYPE_ANIMATIONLIBRARY: + PX_AnimationLibraryFree(&pres->animationlibrary); + break; + case PX_RESOURCE_TYPE_DATA: + PX_MemoryFree(&pres->data); + break; + case PX_RESOURCE_TYPE_SOUND: + PX_SoundStaticDataFree(&pres->sound); + break; + case PX_RESOURCE_TYPE_SHAPE: + PX_ShapeFree(&pres->shape); + break; + } + pNode=pNode->pnext; + } + PX_ListFree(&lib->resources); + PX_MapFree(&lib->map); + +} + +PX_Resource * PX_ResourceLibraryGet(PX_ResourceLibrary *lib,const px_char key[]) +{ + return (PX_Resource *)PX_MapGet(&lib->map,key); +} + +px_bool PX_ResourceLibraryAddTexture(PX_ResourceLibrary *lib,const px_char key[],px_texture *pTexture) +{ + PX_Resource res; + res.Type=PX_RESOURCE_TYPE_TEXTURE; + if(!PX_TextureCopy(lib->mp,pTexture,&res.texture))return PX_FALSE; + PX_MapPut(&lib->map,key,PX_ListPush(&lib->resources,&res,sizeof(res))); + return PX_TRUE; +} + +px_void PX_ResourceLibraryDelete(PX_ResourceLibrary *lib,const px_char key[]) +{ + PX_Resource * pres,*pnodeRes; + + pres=(PX_Resource *)PX_MapGet(&lib->map,key); + if (pres) + { + px_list_node *pNode=lib->resources.head; + while (pNode) + { + pnodeRes=(PX_Resource *)pNode->pdata; + if (pnodeRes==pres) + { + switch(pres->Type) + { + case PX_RESOURCE_TYPE_NULL: + break; + case PX_RESOURCE_TYPE_TEXTURE: + PX_TextureFree(&pres->texture); + break; + case PX_RESOURCE_TYPE_SCRIPT: + PX_ScriptVM_InstanceFree(&pres->Script); + break; + case PX_RESOURCE_TYPE_ANIMATIONLIBRARY: + PX_AnimationLibraryFree(&pres->animationlibrary); + break; + case PX_RESOURCE_TYPE_DATA: + PX_MemoryFree(&pres->data); + break; + case PX_RESOURCE_TYPE_SOUND: + PX_SoundStaticDataFree(&pres->sound); + break; + case PX_RESOURCE_TYPE_SHAPE: + PX_ShapeFree(&pres->shape); + break; + } + PX_ListPop(&lib->resources,pNode); + PX_MapErase(&lib->map,key); + return; + } + pNode=pNode->pnext; + } + } +} + +px_texture * PX_ResourceLibraryGetTexture(PX_ResourceLibrary *lib,const px_char key[]) +{ + PX_Resource *pres=PX_ResourceLibraryGet(lib,key); + if (pres&&pres->Type==PX_RESOURCE_TYPE_TEXTURE) + { + return &pres->texture; + } + return PX_NULL; +} + +px_shape * PX_ResourceLibraryGetShape(PX_ResourceLibrary *lib,const px_char key[]) +{ + PX_Resource *pres=PX_ResourceLibraryGet(lib,key); + if (pres&&pres->Type==PX_RESOURCE_TYPE_SHAPE) + { + return &pres->shape; + } + return PX_NULL; +} + +PX_AnimationLibrary * PX_ResourceLibraryGetAnimationLibrary(PX_ResourceLibrary *lib,const px_char key[]) +{ + PX_Resource *pres=PX_ResourceLibraryGet(lib,key); + if (pres&&pres->Type==PX_RESOURCE_TYPE_ANIMATIONLIBRARY) + { + return &pres->animationlibrary; + } + return PX_NULL; +} + +PX_ScriptVM_Instance * PX_ResourceLibraryGetScript(PX_ResourceLibrary *lib,const px_char key[]) +{ + PX_Resource *pres=PX_ResourceLibraryGet(lib,key); + if (pres&&pres->Type==PX_RESOURCE_TYPE_SCRIPT) + { + return &pres->Script; + } + return PX_NULL; +} + +px_memory * PX_ResourceLibraryGetData(PX_ResourceLibrary *lib,const px_char key[]) +{ + PX_Resource *pres=PX_ResourceLibraryGet(lib,key); + if (pres&&pres->Type==PX_RESOURCE_TYPE_DATA) + { + return &pres->data; + } + return PX_NULL; +} + +PX_SoundData * PX_ResourceLibraryGetSound(PX_ResourceLibrary *lib,const px_char key[]) +{ + PX_Resource *pres=PX_ResourceLibraryGet(lib,key); + if (pres&&pres->Type==PX_RESOURCE_TYPE_SOUND) + { + return &pres->sound; + } + return PX_NULL; +} + diff --git a/lib/PainterEngine/kernel/PX_Resource.h b/lib/PainterEngine/kernel/PX_Resource.h new file mode 100644 index 0000000000000000000000000000000000000000..b2c0b8e0b09608696f2e6be23b584e6c2d080f47 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Resource.h @@ -0,0 +1,63 @@ +#ifndef PX_RESOURCE_H +#define PX_RESOURCE_H + +#include "../core/PX_Core.h" +#include "PX_Script_VM.h" +#include "PX_Animation.h" +#include "PX_Partical.h" +#include "PX_Script_Interpreter.h" +#include "PX_Script_ASMCompiler.h" + +typedef enum +{ + PX_RESOURCE_TYPE_NULL, + PX_RESOURCE_TYPE_ANIMATIONLIBRARY, + PX_RESOURCE_TYPE_SCRIPT, + PX_RESOURCE_TYPE_TEXTURE, + PX_RESOURCE_TYPE_SHAPE, + PX_RESOURCE_TYPE_SOUND, + PX_RESOURCE_TYPE_DATA, +}PX_RESOURCE_TYPE; + + +typedef struct +{ + PX_RESOURCE_TYPE Type; + union + { + px_texture texture; + px_shape shape; + PX_AnimationLibrary animationlibrary; + PX_ScriptVM_Instance Script; + PX_SoundData sound; + px_memory data; + }; +}PX_Resource; + +typedef struct +{ + px_memorypool *mp; + px_list resources; + px_map map; +}PX_ResourceLibrary; + + + +px_bool PX_ResourceLibraryInitialize(px_memorypool *mp,PX_ResourceLibrary *lib); +px_bool PX_ResourceLibraryLoad(PX_ResourceLibrary *lib,PX_RESOURCE_TYPE type,px_byte *data,px_uint datasize,const px_char key[]); +px_bool PX_ResourceLibraryAddTexture(PX_ResourceLibrary *lib,const px_char key[],px_texture *pTexture); +PX_Resource * PX_ResourceLibraryGet(PX_ResourceLibrary *lib,const px_char key[]); +px_texture *PX_ResourceLibraryGetTexture(PX_ResourceLibrary *lib,const px_char key[]); +px_shape *PX_ResourceLibraryGetShape(PX_ResourceLibrary *lib,const px_char key[]); +PX_AnimationLibrary *PX_ResourceLibraryGetAnimationLibrary(PX_ResourceLibrary *lib,const px_char key[]); +PX_ScriptVM_Instance *PX_ResourceLibraryGetScript(PX_ResourceLibrary *lib,const px_char key[]); +PX_SoundData *PX_ResourceLibraryGetSound(PX_ResourceLibrary *lib,const px_char key[]); +px_memory *PX_ResourceLibraryGetData(PX_ResourceLibrary *lib,const px_char key[]); + +px_void PX_ResourceLibraryDelete(PX_ResourceLibrary *lib,const px_char key[]); +px_void PX_ResourceLibraryFree(PX_ResourceLibrary *lib); + + +#endif + + diff --git a/lib/PainterEngine/kernel/PX_ScriptCore.h b/lib/PainterEngine/kernel/PX_ScriptCore.h new file mode 100644 index 0000000000000000000000000000000000000000..6f552ad690acf003711f4d65784d981612fadabf --- /dev/null +++ b/lib/PainterEngine/kernel/PX_ScriptCore.h @@ -0,0 +1,343 @@ +#ifndef __PX_SCRIPT_H +#define __PX_SCRIPT_H +#include "../core/PX_Core.h" +#include "PX_Lexer.h" + +//special register IP,SP,BP,rRET + +//register r0~r15 + + + +//Pretreatment +//#include [name] + +//special +//ASSUME [name] [name] +//.GLOBAL [int] +//.STACK [int] +//.THREAD [int] + +//instructions + + +//mov [reg,local,global],[num,string,reg,local,global] + +//add [reg,local,global],[num,reg,local,global] +//sub [reg,local,global],[num,reg,local,global] +//div [reg,local,global],[num,reg,local,global] +//mul [reg,local,global],[num,reg,local,global] +//mod [reg,local,global],[int,reg,local,global] +//shl [reg,local,global],[int,reg,local,global] +//shr [reg,local,global],[int,reg,local,global] +//or [reg,local,global],[num,reg,local,global] +//xor [reg,local,global],[num,reg,local,global] +//pow [reg,local,global],[num,reg,local,global] +//sin [reg,local,global],[num,reg,local,global] +//cos [reg,local,global],[num,reg,local,global] +//int [reg,local,global] +//flt [reg,local,global] + +//strlen [reg,local,global],[reg,local,global,string] +//strcat [reg,local,global],[reg,local,global,string] +//strrep [reg,local,global],[reg,local,global,string],[reg,local,global,string] +//strchr [reg,local,global],[reg,local,global,string],[reg,local,global,int] +//strtoi [reg,local,global],[reg,local,global,string] +//strtof [reg,local,global],[reg,local,global,string] +//strfri [reg,local,global],[reg,local,global,int] +//strfrf [reg,local,global],[reg,local,global,float] +//strset [reg,local,global],[reg,local,global,int],[reg,local,global,string,int] +//strtmem [reg,local,global] +//asc [reg,local,global],[reg,local,global,string] + + +//membyte [reg,local,global],[reg,local,global,int],[reg,local,global,memory] +//memset [reg,local,global],[reg,local,global,int],[reg,local,global,memory] +//memcpy [reg,local,global],[reg,local,global,int],[reg,local,global,memory] +//memfind [reg,local,global],[reg,local,global,memory],[reg,local,global,memory] +//memlen [reg,local,global],[reg,local,global,memory] +//memcat [reg,local,global],[reg,local,global,memory] +//memtstr [reg,local,global] + +//not [reg,local,global] +//inv [reg,local,global] + +//jmp [reg,num,local,global,label] +//je [num,string,reg,local,global],[num,string,reg,local,global],[reg,int,local,global,label] +//jne [num,string,reg,local,global],[num,string,reg,local,global],[reg,int,local,global,label] +//jl [num,string,reg,local,global],[num,string,reg,local,global],[reg,int,local,global,label] +//jle [num,string,reg,local,global],[num,string,reg,local,global],[reg,int,local,global,label] +//jg [num,string,reg,local,global],[num,string,reg,local,global],[reg,int,local,global,label] +//jge [num,string,reg,local,global],[num,string,reg,local,global],[reg,int,local,global,label] + +//call [reg,int,local,global,label,host] + +//push [num,reg,local,global] +//pop [reg,local,global] + +//ret + +//binary format +//opcode 1 byte +//optype 3 byte +//operand [0,3] byte + +#define PX_SCRIPT_MAX_FUNC_NAME_SIZE 32 + +enum PX_SCRIPT_ASM_INSTR_OPCODE +{ + PX_SCRIPT_ASM_INSTR_OPCODE_MOV=1, + PX_SCRIPT_ASM_INSTR_OPCODE_ADD, + PX_SCRIPT_ASM_INSTR_OPCODE_SUB, + PX_SCRIPT_ASM_INSTR_OPCODE_DIV, + PX_SCRIPT_ASM_INSTR_OPCODE_MUL, + PX_SCRIPT_ASM_INSTR_OPCODE_MOD, + PX_SCRIPT_ASM_INSTR_OPCODE_SHL, + PX_SCRIPT_ASM_INSTR_OPCODE_SHR, + PX_SCRIPT_ASM_INSTR_OPCODE_AND, + PX_SCRIPT_ASM_INSTR_OPCODE_OR, + PX_SCRIPT_ASM_INSTR_OPCODE_XOR, + PX_SCRIPT_ASM_INSTR_OPCODE_ANDL, + PX_SCRIPT_ASM_INSTR_OPCODE_ORL, + PX_SCRIPT_ASM_INSTR_OPCODE_POW, + PX_SCRIPT_ASM_INSTR_OPCODE_SIN, + PX_SCRIPT_ASM_INSTR_OPCODE_COS, + PX_SCRIPT_ASM_INSTR_OPCODE_INT, + PX_SCRIPT_ASM_INSTR_OPCODE_FLT, + PX_SCRIPT_ASM_INSTR_OPCODE_STRLEN, + PX_SCRIPT_ASM_INSTR_OPCODE_STRCAT, + PX_SCRIPT_ASM_INSTR_OPCODE_STRREP, + PX_SCRIPT_ASM_INSTR_OPCODE_STRCHR, + PX_SCRIPT_ASM_INSTR_OPCODE_STRTOI, + PX_SCRIPT_ASM_INSTR_OPCODE_STRTOF, + PX_SCRIPT_ASM_INSTR_OPCODE_STRFRI, + PX_SCRIPT_ASM_INSTR_OPCODE_STRFRF, + PX_SCRIPT_ASM_INSTR_OPCODE_STRSET, + PX_SCRIPT_ASM_INSTR_OPCODE_STRFIND, + PX_SCRIPT_ASM_INSTR_OPCODE_STRTMEM, + PX_SCRIPT_ASM_INSTR_OPCODE_ASC, + PX_SCRIPT_ASM_INSTR_OPCODE_MEMBYTE, + PX_SCRIPT_ASM_INSTR_OPCODE_MEMSET, + PX_SCRIPT_ASM_INSTR_OPCODE_MEMFIND, + PX_SCRIPT_ASM_INSTR_OPCODE_MEMLEN, + PX_SCRIPT_ASM_INSTR_OPCODE_MEMTRM, + PX_SCRIPT_ASM_INSTR_OPCODE_MEMCAT, + PX_SCRIPT_ASM_INSTR_OPCODE_MEMTSTR, + PX_SCRIPT_ASM_INSTR_OPCODE_DATACPY, + PX_SCRIPT_ASM_INSTR_OPCODE_INV, + PX_SCRIPT_ASM_INSTR_OPCODE_NOT, + PX_SCRIPT_ASM_INSTR_OPCODE_NEG, + PX_SCRIPT_ASM_INSTR_OPCODE_JMP, + PX_SCRIPT_ASM_INSTR_OPCODE_JE, + PX_SCRIPT_ASM_INSTR_OPCODE_JNE, + PX_SCRIPT_ASM_INSTR_OPCODE_JGE, + PX_SCRIPT_ASM_INSTR_OPCODE_JLE, + PX_SCRIPT_ASM_INSTR_OPCODE_JG, + PX_SCRIPT_ASM_INSTR_OPCODE_JL, + + PX_SCRIPT_ASM_INSTR_OPCODE_LGE, + PX_SCRIPT_ASM_INSTR_OPCODE_LGNE, + PX_SCRIPT_ASM_INSTR_OPCODE_LGZ, + PX_SCRIPT_ASM_INSTR_OPCODE_LGGZ, + PX_SCRIPT_ASM_INSTR_OPCODE_LGGEZ, + PX_SCRIPT_ASM_INSTR_OPCODE_LGLZ, + PX_SCRIPT_ASM_INSTR_OPCODE_LGLEZ, + + PX_SCRIPT_ASM_INSTR_OPCODE_CALL, + PX_SCRIPT_ASM_INSTR_OPCODE_PUSH, + PX_SCRIPT_ASM_INSTR_OPCODE_POP, + PX_SCRIPT_ASM_INSTR_OPCODE_POPN, + PX_SCRIPT_ASM_INSTR_OPCODE_ADR, + PX_SCRIPT_ASM_INSTR_OPCODE_RET, + + PX_SCRIPT_ASM_INSTR_OPCODE_NOP, + PX_SCRIPT_ASM_INSTR_OPCODE_BPX, + PX_SCRIPT_ASM_INSTR_OPCODE_WAIT, + PX_SCRIPT_ASM_INSTR_OPCODE_SIGNAL, +}; + +enum PX_SCRIPT_ASM_OPTYPE +{ + PX_SCRIPT_ASM_OPTYPE_INT, + PX_SCRIPT_ASM_OPTYPE_FLOAT, + PX_SCRIPT_ASM_OPTYPE_REG, + PX_SCRIPT_ASM_OPTYPE_LOCAL,//mnemonic + PX_SCRIPT_ASM_OPTYPE_LOCAL_CONST, + PX_SCRIPT_ASM_OPTYPE_LOCAL_REGREF, + PX_SCRIPT_ASM_OPTYPE_LOCAL_GLOBALREF, + PX_SCRIPT_ASM_OPTYPE_LOCAL_LOCALREF, + PX_SCRIPT_ASM_OPTYPE_GLOBAL,//mnemonic + PX_SCRIPT_ASM_OPTYPE_GLOBAL_CONST, + PX_SCRIPT_ASM_OPTYPE_GLOBAL_REGREF, + PX_SCRIPT_ASM_OPTYPE_GLOBAL_GLOBALREF, + PX_SCRIPT_ASM_OPTYPE_GLOBAL_LOCALREF, + PX_SCRIPT_ASM_OPTYPE_GLOBAL_SPREF, + PX_SCRIPT_ASM_OPTYPE_STRING, + PX_SCRIPT_ASM_OPTYPE_LABEL,//mnemonic + PX_SCRIPT_ASM_OPTYPE_HOST,//mnemonic + PX_SCRIPT_ASM_OPTYPE_MEMORY, + PX_SCRIPT_ASM_OPTYPE_BP, + PX_SCRIPT_ASM_OPTYPE_SP, + PX_SCRIPT_ASM_OPTYPE_IP, +}; +#define PX_SCRIPT_ASM_OPERAND_ACC_TYPE_UNKNOW 0 +#define PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT 1 +#define PX_SCRIPT_ASM_OPERAND_ACC_TYPE_FLOAT 2 +#define PX_SCRIPT_ASM_OPERAND_ACC_TYPE_NUM 3 +#define PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG 4 +#define PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL 8 +#define PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL 16 +#define PX_SCRIPT_ASM_OPERAND_ACC_TYPE_STRING 32 +#define PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LABEL 64 +#define PX_SCRIPT_ASM_OPERAND_ACC_TYPE_HOST 128 +#define PX_SCRIPT_ASM_OPERAND_ACC_TYPE_MEMORY 256 +#define PX_SCRIPT_ASM_OPERAND_ACC_TYPE_IP 512 +#define PX_SCRIPT_ASM_OPERAND_ACC_TYPE_SP 1024 +#define PX_SCRIPT_ASM_OPERAND_ACC_TYPE_BP 2048 + +#define PX_SCRIPT_ASM_OPERAND_ACC_TYPE_TOKEN 0xffffffff + + +#define __PX_SCRIPT_ASM_MNEMONIC_NAME_LEN 48 +#define __PX_SCRIPT_ASM_INSTR_MNEMONIC_NAME_LEN 16 + +typedef struct __PX_SCRIPT_EXPORT_FUNCTION +{ + px_char name[__PX_SCRIPT_ASM_MNEMONIC_NAME_LEN]; + px_int Addr; +}PX_SCRIPT_EXPORT_FUNCTION; + +typedef struct __PX_SCRIPT_ASM_LABEL_NODE +{ + px_char mnemonic[__PX_SCRIPT_ASM_MNEMONIC_NAME_LEN]; + px_bool bfunction; + px_int binaddr; +}PX_SCRIPT_ASM_LABEL_NODE; + + +typedef struct __PX_SCRIPT_ASM_ASSUME_NODE +{ + px_string name; + px_string assume; + +}PX_SCRIPT_ASM_ASSUME_NODE; + + +typedef struct __PX_SCRIPT_ASM_STRING_NODE +{ + px_string str; + px_int addr; +}PX_SCRIPT_ASM_STRING_NODE; + +typedef struct __PX_SCRIPT_ASM_MEMORY_NODE +{ + px_memory mem; + px_int addr; +}PX_SCRIPT_ASM_MEMORY_NODE; + +typedef struct __PX_SCRIPT_ASM_HOST_NODE +{ + px_char name[__PX_SCRIPT_ASM_MNEMONIC_NAME_LEN]; + const px_void *map; + px_void *userptr; +}PX_SCRIPT_ASM_HOST_NODE; + +typedef struct __PX_SCRIPT_ASM_GRAMMAR_INSTR +{ + px_char mnemonic[__PX_SCRIPT_ASM_INSTR_MNEMONIC_NAME_LEN]; + px_char opcode; + px_char paramCount; + px_int operandAccTypes[3]; +}PX_SCRIPT_ASM_GRAMMAR_INSTR; + +typedef struct __PX_SCRIPT_ASM_INSTR_BIN +{ + px_char opCode; + px_char optype[3]; + px_dword param[3]; + px_dword addr; + px_int opcount; +}PX_SCRIPT_ASM_INSTR_BIN; + + +typedef struct __PX_SCRIPT_ASM_COMPILER +{ + px_lexer lexer; + px_vector StreamTable; + px_list LabelTable; + px_list assumeTable; + px_list StringTable; + px_list memoriesTable; + px_list HostTable; + px_list GrammarInstrTable; + px_int globalsize; + px_int stacksize; + px_int threadcount; + px_memorypool *mp; + +}PX_SCRIPT_ASM_COMPILER; + + +typedef struct __PX_SCRIPT_ASM_HEADER +{ + ////////////////////////////////////////////////////////////////////////// + //8 bytes check + px_dword magic; + px_dword CRC; + ////////////////////////////////////////////////////////////////////////// + px_dword stacksize; + px_dword globalsize; + px_dword threadcount; + px_dword oftbin; + px_dword oftfunc; + px_dword funcCount; + px_dword ofthost; + px_dword oftmem; + px_dword memsize; + px_dword hostCount; + px_dword oftString; + px_dword stringSize; + px_dword binsize; + px_dword reserved[6]; +}PX_SCRIPT_ASM_HEADER; + +typedef enum __PX_SCRIPT_VM_VARIABLE_TYPE +{ + PX_SCRIPTVM_VARIABLE_TYPE_INT, + PX_SCRIPTVM_VARIABLE_TYPE_FLOAT, + PX_SCRIPTVM_VARIABLE_TYPE_STRING, + PX_SCRIPTVM_VARIABLE_TYPE_MEMORY, +}PX_SCRIPTVM_VARIABLE_TYPE; + +#define PX_SCRIPTVM_VARIABLE_TYPE_PTR PX_SCRIPTVM_VARIABLE_TYPE_INT + +typedef struct __PX_SCRIPT_VM_VARIABLE +{ + px_int type; + union + { + px_char _byte; + px_char _char; + px_word _word; + px_dword _dword; + px_short _short; + px_int _int; + px_uint _uint; + px_float _float; + px_string _string; + px_memory _memory; + }; +}PX_SCRIPTVM_VARIABLE; + +typedef struct __PX_ASM_GRAMMAR +{ + px_lexer *lexer; + px_memorypool *mp; + px_bool bSkipSpacer; + px_bool bSkipNewline; + px_bool bLowercase; + px_vector V_SentenceMatcher; +}PX_ASM_Grammar; + +#endif + diff --git a/lib/PainterEngine/kernel/PX_Script_ASMCompiler.c b/lib/PainterEngine/kernel/PX_Script_ASMCompiler.c new file mode 100644 index 0000000000000000000000000000000000000000..7d346cda90ab5ae2c2667f386cdcb4c3a669867e --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Script_ASMCompiler.c @@ -0,0 +1,2004 @@ +#include "PX_Script_ASMCompiler.h" + +static px_char PX_Script_ASMError[128]; + +static px_void PX_ScriptAsmError(px_lexer *lexer,px_char *err) +{ + lexer->Sources[lexer->SourceOffset]='\0'; + + PX_Script_ASMError[0]='\0'; + if (lexer->SourceOffset>96) + { + PX_strcpy(PX_Script_ASMError,lexer->Sources+lexer->SourceOffset-96,96); + } + else + { + PX_strcpy(PX_Script_ASMError,lexer->Sources,96); + } + + PX_LOG(err); +} + +px_int PX_ScriptAsm_atoi(px_char *str) +{ + if (str[0]=='0'&&str[1]=='X') + { + return PX_htoi(str); + } + return PX_atoi(str); +} + +px_bool PX_ScriptAsm_isInt(px_char token[]) +{ + px_int i; + if (token[0]=='0'&&(token[1]=='X')) + { + i=2; + while (token[i]) + { + if ((token[i]>='0'&&token[i]<='9')||(token[i]>='A'&&token[i]<='F')) + { + i++; + continue; + } + else + { + return PX_FALSE; + } + + if (i>10) + { + return PX_FALSE; + } + } + return PX_TRUE; + } + return PX_strIsInt(token); +} + +static px_void PX_ScriptAsmRegistInstr(PX_SCRIPT_ASM_COMPILER *compiler,px_char mnemonic[__PX_SCRIPT_ASM_INSTR_MNEMONIC_NAME_LEN],px_char opcode,px_int accType[],px_char paramcout) +{ + px_int i=0; + PX_SCRIPT_ASM_GRAMMAR_INSTR instr; + + PX_strcpy(instr.mnemonic,mnemonic,sizeof(instr.mnemonic)); + instr.opcode=opcode; + instr.paramCount=paramcout; + + for (i=0;iGrammarInstrTable,&instr,sizeof(instr)); +} +static px_void PX_ScriptAsmStringConvert(px_string *str) +{ + px_int i,j; + for (i=0;ibuffer);i++) + { + if (str->buffer[i]=='\\') + { + switch (str->buffer[i+1]) + { + case '\\': + for(j=i+1;str->buffer[j];j++) + str->buffer[j]=str->buffer[j+1]; + str->buffer[j-1]=0; + break; + case 'r': + case 'R': + str->buffer[i]='\r'; + for(j=i+1;str->buffer[j];j++) + str->buffer[j]=str->buffer[j+1]; + str->buffer[j-1]=0; + break; + case 'n': + case 'N': + str->buffer[i]='\n'; + for(j=i+1;str->buffer[j];j++) + str->buffer[j]=str->buffer[j+1]; + str->buffer[j-1]=0; + break; + case 't': + case 'T': + str->buffer[i]='\t'; + for(j=i+1;str->buffer[j];j++) + str->buffer[j]=str->buffer[j+1]; + str->buffer[j-1]=0; + break; + case '"': + str->buffer[i]='"'; + for(j=i+1;str->buffer[j];j++) + str->buffer[j]=str->buffer[j+1]; + str->buffer[j-1]=0; + break; + default: + break; + } + } + } +} + + +PX_LEXER_LEXEME_TYPE PX_ScriptAsmNexLexeme(px_lexer *lexer) +{ + PX_LEXER_LEXEME_TYPE type; + while (PX_LEXER_LEXEME_TYPE_SPACER==(type=PX_LexerGetNextLexeme(lexer))); + if (PX_strlen(lexer->CurLexeme.buffer)>__PX_SCRIPT_ASM_MNEMONIC_NAME_LEN-1) + { + if(type!=PX_LEXER_LEXEME_TYPE_CONATINER) + { + PX_ScriptAsmError(lexer,"Script ASM Compiler:Token too long error"); + return PX_LEXER_LEXEME_TYPE_ERR; + } + } + return type; + +} + +px_bool PX_ScriptAsmIsValidToken(px_char *token) +{ + if (token[0]=='\0'||PX_charIsNumeric(token[0])) + { + return PX_FALSE; + } + while (*token) + { + if ((*token>='A'&&*token<='Z')||*token=='_'||PX_charIsNumeric(*token)) + { + token++; + continue; + } + return PX_FALSE; + } + return PX_TRUE; +} + +px_int PX_ScriptAsmGetGlobalIndex(px_char * mne) +{ + px_char data[__PX_SCRIPT_ASM_MNEMONIC_NAME_LEN]; + PX_strcpy(data,mne,sizeof(data)); + data[PX_strlen(data)-1]='\0'; + return PX_ScriptAsm_atoi(data+sizeof("GLOBAL[")); +} + +px_int PX_ScriptAsmGetStackIndex(px_char * mne) +{ + px_char data[__PX_SCRIPT_ASM_MNEMONIC_NAME_LEN]; + PX_strcpy(data,mne,sizeof(data)); + data[PX_strlen(data)-1]='\0'; + return PX_ScriptAsm_atoi(data+sizeof("STACK[")); +} + +px_int PX_ScriptAsmTokenType(PX_SCRIPT_ASM_COMPILER *compiler,px_char *token) +{ + px_bool bfound; + px_int matchIteration=256,i; + while (--matchIteration) + { + bfound=PX_FALSE; + for (i=0;iassumeTable.size;i++) + { + if (PX_strequ(((PX_SCRIPT_ASM_ASSUME_NODE *)(PX_ListNodeAt(&compiler->assumeTable,i)->pdata))->name.buffer,token)) + { + token=((PX_SCRIPT_ASM_ASSUME_NODE *)(PX_ListNodeAt(&compiler->assumeTable,i)->pdata))->assume.buffer; + bfound=PX_TRUE; + break; + } + } + if (bfound==PX_FALSE) + { + break; + } + } + if (matchIteration==0) + { + PX_ScriptAsmError(&compiler->lexer,"ASSUME too much iteration"); + return PX_SCRIPT_ASM_OPERAND_ACC_TYPE_UNKNOW; + } + if (PX_strequ(token,"SP")) + { + return PX_SCRIPT_ASM_OPERAND_ACC_TYPE_SP; + } + + if (PX_strequ(token,"IP")) + { + return PX_SCRIPT_ASM_OPERAND_ACC_TYPE_IP; + } + + if (PX_strequ(token,"BP")) + { + return PX_SCRIPT_ASM_OPERAND_ACC_TYPE_BP; + } + + if (PX_memequ(token,"GLOBAL[",sizeof("GLOBAL[")-1)&&token[PX_strlen(token)-1]==']') + { + return PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL; + } + + if (PX_memequ(token,"LOCAL[",sizeof("LOCAL[")-1)&&token[PX_strlen(token)-1]==']') + { + return PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL; + } + + if (token[0]=='R'&&PX_strIsInt(token+1)) + { + return PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG; + } + + if (token[0]=='$'&&PX_ScriptAsmIsValidToken(token+1)) + { + return PX_SCRIPT_ASM_OPERAND_ACC_TYPE_HOST; + } + + if (token[0]=='\"'&&token[PX_strlen(token)-1]=='\"') + { + return PX_SCRIPT_ASM_OPERAND_ACC_TYPE_STRING; + } + + if (token[0]=='\''&&token[PX_strlen(token)-1]=='\'') + { + return PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT; + } + + if (token[0]=='@'&&token[PX_strlen(token)-1]=='@') + { + return PX_SCRIPT_ASM_OPERAND_ACC_TYPE_MEMORY; + } + + + + if (PX_ScriptAsm_isInt(token)) + { + return PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT; + } + + if (PX_strIsFloat(token)) + { + return PX_SCRIPT_ASM_OPERAND_ACC_TYPE_FLOAT; + } + + for (i=0;iLabelTable.size;i++) + { + if (PX_strequ(((PX_SCRIPT_ASM_LABEL_NODE *)(PX_ListNodeAt(&compiler->LabelTable,i)->pdata))->mnemonic,token)) + { + return PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LABEL; + } + } + + return PX_SCRIPT_ASM_OPERAND_ACC_TYPE_UNKNOW; +} + + +px_char PX_ScriptAsmTokenTypeToOpType(px_int TokenType) +{ + switch(TokenType) + { + case PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT: + return PX_SCRIPT_ASM_OPTYPE_INT; + case PX_SCRIPT_ASM_OPERAND_ACC_TYPE_FLOAT: + return PX_SCRIPT_ASM_OPTYPE_FLOAT; + case PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG: + return PX_SCRIPT_ASM_OPTYPE_REG; + case PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL: + { + return PX_SCRIPT_ASM_OPTYPE_LOCAL; + } + break; + case PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL: + { + return PX_SCRIPT_ASM_OPTYPE_GLOBAL; + } + break; + case PX_SCRIPT_ASM_OPERAND_ACC_TYPE_STRING: + return PX_SCRIPT_ASM_OPTYPE_STRING; + case PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LABEL: + return PX_SCRIPT_ASM_OPTYPE_LABEL; + case PX_SCRIPT_ASM_OPERAND_ACC_TYPE_HOST: + return PX_SCRIPT_ASM_OPTYPE_HOST; + case PX_SCRIPT_ASM_OPERAND_ACC_TYPE_MEMORY: + return PX_SCRIPT_ASM_OPTYPE_MEMORY; + case PX_SCRIPT_ASM_OPERAND_ACC_TYPE_BP: + return PX_SCRIPT_ASM_OPTYPE_BP; + case PX_SCRIPT_ASM_OPERAND_ACC_TYPE_SP: + return PX_SCRIPT_ASM_OPTYPE_SP; + case PX_SCRIPT_ASM_OPERAND_ACC_TYPE_IP: + return PX_SCRIPT_ASM_OPTYPE_IP; + default: + return 0; + } +} + +static px_bool PX_ScriptASMMapAssume(PX_SCRIPT_ASM_COMPILER *compiler,px_string *mnenonic) +{ + px_bool bfound; + px_int matchIteration=256,i; + + while (--matchIteration) + { + bfound=PX_FALSE; + for (i=0;iassumeTable.size;i++) + { + if (PX_strequ(((PX_SCRIPT_ASM_ASSUME_NODE *)(PX_ListNodeAt(&compiler->assumeTable,i)->pdata))->name.buffer,mnenonic->buffer)) + { + + PX_StringCopy(mnenonic,&(((PX_SCRIPT_ASM_ASSUME_NODE *)PX_ListNodeAt(&compiler->assumeTable,i)->pdata)->assume)); + + bfound=PX_TRUE; + break; + } + } + if (bfound==PX_FALSE) + { + break; + } + } + if (matchIteration==0) + { + PX_ScriptAsmError(&compiler->lexer,"ASSUME too much iteration"); + return PX_FALSE; + } + return PX_TRUE; +} + +static px_bool PX_ScriptAsmLocalType(PX_SCRIPT_ASM_COMPILER *compiler,px_char *Token,px_char *type,px_dword *index) +{ + px_string TempTokenString; + PX_StringInitialize(compiler->mp,&TempTokenString); + PX_StringCat(&TempTokenString,Token); + + PX_StringTrimLeft(&TempTokenString,PX_strlen("LOCAL[")); + PX_StringTrimRight(&TempTokenString,1); + + PX_ScriptASMMapAssume(compiler,&TempTokenString); + + if (PX_memequ(TempTokenString.buffer,"GLOBAL[",sizeof("GLOBAL[")-1)&&TempTokenString.buffer[PX_strlen(TempTokenString.buffer)-1]==']') + { + PX_StringTrimLeft(&TempTokenString,PX_strlen("GLOBAL[")); + PX_StringTrimRight(&TempTokenString,1); + PX_ScriptASMMapAssume(compiler,&TempTokenString); + if (!PX_ScriptAsm_isInt(TempTokenString.buffer)) + { + PX_StringFree(&TempTokenString); + return PX_FALSE; + } + *type=PX_SCRIPT_ASM_OPTYPE_LOCAL_GLOBALREF; + *index=PX_ScriptAsm_atoi(TempTokenString.buffer); + PX_StringFree(&TempTokenString); + return PX_TRUE; + } + + if (PX_memequ(TempTokenString.buffer,"LOCAL[",sizeof("LOCAL[")-1)&&TempTokenString.buffer[PX_strlen(TempTokenString.buffer)-1]==']') + { + PX_StringTrimLeft(&TempTokenString,PX_strlen("LOCAL[")); + PX_StringTrimRight(&TempTokenString,1); + PX_ScriptASMMapAssume(compiler,&TempTokenString); + + if (!PX_ScriptAsm_isInt(TempTokenString.buffer)) + { + PX_StringFree(&TempTokenString); + return PX_FALSE; + } + *type=PX_SCRIPT_ASM_OPTYPE_LOCAL_LOCALREF; + *index=PX_ScriptAsm_atoi(TempTokenString.buffer); + PX_StringFree(&TempTokenString); + return PX_TRUE; + } + + if (TempTokenString.buffer[0]=='R'&&PX_strIsInt(TempTokenString.buffer+1)) + { + *type=PX_SCRIPT_ASM_OPTYPE_LOCAL_REGREF; + *index=PX_ScriptAsm_atoi(TempTokenString.buffer+1); + PX_StringFree(&TempTokenString); + return PX_TRUE; + } + + if (PX_ScriptAsm_isInt(TempTokenString.buffer)) + { + *type=PX_SCRIPT_ASM_OPTYPE_LOCAL_CONST; + *index=PX_ScriptAsm_atoi(TempTokenString.buffer); + PX_StringFree(&TempTokenString); + return PX_TRUE; + } + PX_StringFree(&TempTokenString); + return PX_FALSE; +} + +static px_bool PX_ScriptAsmGlobalType(PX_SCRIPT_ASM_COMPILER *compiler,px_char *Token,px_char *type,px_dword *index) +{ + px_string TempTokenString; + PX_StringInitialize(compiler->mp,&TempTokenString); + + PX_StringCat(&TempTokenString,Token); + + PX_StringTrimLeft(&TempTokenString,PX_strlen("GLOBAL[")); + PX_StringTrimRight(&TempTokenString,1); + + PX_ScriptASMMapAssume(compiler,&TempTokenString); + + if (PX_memequ(TempTokenString.buffer,"GLOBAL[",sizeof("GLOBAL[")-1)&&TempTokenString.buffer[PX_strlen(TempTokenString.buffer)-1]==']') + { + PX_StringTrimLeft(&TempTokenString,PX_strlen("GLOBAL[")); + PX_StringTrimRight(&TempTokenString,1); + PX_ScriptASMMapAssume(compiler,&TempTokenString); + if (!PX_ScriptAsm_isInt(TempTokenString.buffer)) + { + PX_StringFree(&TempTokenString); + return PX_FALSE; + } + + *type=PX_SCRIPT_ASM_OPTYPE_GLOBAL_GLOBALREF; + *index=PX_ScriptAsm_atoi(TempTokenString.buffer); + PX_StringFree(&TempTokenString); + return PX_TRUE; + } + + if (PX_memequ(TempTokenString.buffer,"LOCAL[",sizeof("LOCAL[")-1)&&TempTokenString.buffer[PX_strlen(TempTokenString.buffer)-1]==']') + { + PX_StringTrimLeft(&TempTokenString,PX_strlen("LOCAL[")); + PX_StringTrimRight(&TempTokenString,1); + PX_ScriptASMMapAssume(compiler,&TempTokenString); + if (!PX_ScriptAsm_isInt(TempTokenString.buffer)) + { + PX_StringFree(&TempTokenString); + return PX_FALSE; + } + *type=PX_SCRIPT_ASM_OPTYPE_GLOBAL_LOCALREF; + *index=PX_ScriptAsm_atoi(TempTokenString.buffer); + PX_StringFree(&TempTokenString); + return PX_TRUE; + } + + if (PX_memequ(TempTokenString.buffer,"BP+",sizeof("BP+")-1)&&PX_ScriptAsm_isInt(TempTokenString.buffer+sizeof("BP+")-1)) + { + PX_StringTrimLeft(&TempTokenString,PX_strlen("BP+")); + + PX_ScriptASMMapAssume(compiler,&TempTokenString); + if (!PX_ScriptAsm_isInt(TempTokenString.buffer)) + { + PX_StringFree(&TempTokenString); + return PX_FALSE; + } + *type=PX_SCRIPT_ASM_OPTYPE_GLOBAL_LOCALREF; + *index=PX_ScriptAsm_atoi(TempTokenString.buffer); + PX_StringFree(&TempTokenString); + return PX_TRUE; + } + else if (PX_strequ(TempTokenString.buffer,"BP")) + { + *type=PX_SCRIPT_ASM_OPTYPE_GLOBAL_LOCALREF; + *index=0; + PX_StringFree(&TempTokenString); + return PX_TRUE; + } + + + if (PX_memequ(TempTokenString.buffer,"SP+",sizeof("SP+")-1)&&PX_ScriptAsm_isInt(TempTokenString.buffer+sizeof("SP+")-1)) + { + PX_StringTrimLeft(&TempTokenString,PX_strlen("SP+")); + PX_ScriptASMMapAssume(compiler,&TempTokenString); + if (!PX_ScriptAsm_isInt(TempTokenString.buffer)) + { + PX_StringFree(&TempTokenString); + return PX_FALSE; + } + *type=PX_SCRIPT_ASM_OPTYPE_GLOBAL_SPREF; + *index=PX_ScriptAsm_atoi(TempTokenString.buffer); + PX_StringFree(&TempTokenString); + return PX_TRUE; + } + else if (PX_strequ(TempTokenString.buffer,"SP")) + { + *type=PX_SCRIPT_ASM_OPTYPE_GLOBAL_SPREF; + *index=0; + PX_StringFree(&TempTokenString); + return PX_TRUE; + } + + + if (TempTokenString.buffer[0]=='R'&&PX_strIsInt(TempTokenString.buffer+1)) + { + *type=PX_SCRIPT_ASM_OPTYPE_GLOBAL_REGREF; + *index=PX_ScriptAsm_atoi(TempTokenString.buffer+1); + PX_StringFree(&TempTokenString); + return PX_TRUE; + } + + + if (PX_ScriptAsm_isInt(TempTokenString.buffer)) + { + *type=PX_SCRIPT_ASM_OPTYPE_GLOBAL_CONST; + *index=PX_ScriptAsm_atoi(TempTokenString.buffer); + PX_StringFree(&TempTokenString); + return PX_TRUE; + } + PX_StringFree(&TempTokenString); + return PX_FALSE; +} + + +px_void PX_ScriptAsmUpdateAssumeTable(PX_SCRIPT_ASM_COMPILER *compiler,px_char *name,px_char *assume) +{ + px_int i; + PX_SCRIPT_ASM_ASSUME_NODE newNode; + for (i=0;iassumeTable.size;i++) + { + if (PX_strequ(((PX_SCRIPT_ASM_ASSUME_NODE *)(PX_ListNodeAt(&compiler->assumeTable,i)->pdata))->name.buffer,name)) + { + PX_StringClear(&PX_LISTAT(PX_SCRIPT_ASM_ASSUME_NODE,&compiler->assumeTable,i)->assume); + PX_StringCat(&PX_LISTAT(PX_SCRIPT_ASM_ASSUME_NODE,&compiler->assumeTable,i)->assume,assume); + return; + } + } + PX_StringInitialize(compiler->mp,&newNode.assume); + PX_StringInitialize(compiler->mp,&newNode.name); + PX_StringCat(&newNode.assume,assume); + PX_StringCat(&newNode.name,name); + + PX_ListPush(&compiler->assumeTable,&newNode,sizeof(PX_SCRIPT_ASM_ASSUME_NODE)); +} + +px_bool PX_ScriptAsmAddSourceLabel(PX_SCRIPT_ASM_COMPILER *compiler,px_char *Name,px_bool bFunction) +{ + px_int i; + PX_SCRIPT_ASM_LABEL_NODE label; + for (i=0;iLabelTable.size;i++) + { + if (PX_strequ(PX_LISTAT(PX_SCRIPT_ASM_LABEL_NODE,&compiler->LabelTable,i)->mnemonic,Name)) + { + PX_ScriptAsmError(&compiler->lexer,"Label name redefined."); + return PX_FALSE; + } + } + PX_strcpy(label.mnemonic,Name,sizeof(label.mnemonic)); + label.bfunction=bFunction; + PX_ListPush(&compiler->LabelTable,&label,sizeof(label)); + return PX_TRUE; +} + +px_bool PX_ScriptAsmUpdateLabelAddr(PX_SCRIPT_ASM_COMPILER *compiler,px_char *Name,px_int addr) +{ + px_int i; + for (i=0;iLabelTable.size;i++) + { + if (PX_strequ(((PX_SCRIPT_ASM_LABEL_NODE *)(PX_ListNodeAt(&compiler->LabelTable,i)->pdata))->mnemonic,Name)) + { + ((PX_SCRIPT_ASM_LABEL_NODE *)(PX_ListNodeAt(&compiler->LabelTable,i)->pdata))->binaddr=addr; + return PX_TRUE; + } + } + return PX_FALSE; +} + +px_int PX_ScriptAsmGetLabelIndex(PX_SCRIPT_ASM_COMPILER *compiler,px_char *Name) +{ + px_int i; + for (i=0;iLabelTable.size;i++) + { + if (PX_strequ(PX_LISTAT(PX_SCRIPT_ASM_LABEL_NODE,&compiler->LabelTable,i)->mnemonic,Name)) + { + return i; + } + } + return -1; +} + +px_int PX_ScriptAsmGetFuncCount(PX_SCRIPT_ASM_COMPILER *compiler) +{ + px_int i; + px_int count=0; + for (i=0;iLabelTable.size;i++) + { + if (PX_LISTAT(PX_SCRIPT_ASM_LABEL_NODE,&compiler->LabelTable,i)->bfunction) + { + count++; + } + } + return count; +} + +px_int PX_ScriptAsmStringSize(PX_SCRIPT_ASM_COMPILER *compiler) +{ + px_int i; + px_int size=0; + for (i=0;iStringTable.size;i++) + { + size+= (PX_strlen(((PX_SCRIPT_ASM_STRING_NODE *)(PX_ListNodeAt(&compiler->StringTable,i)->pdata))->str.buffer))+1; + } + return size; +} + +px_int PX_ScriptAsmMemorySize(PX_SCRIPT_ASM_COMPILER *compiler) +{ + px_int i; + px_int size=0; + for (i=0;imemoriesTable.size;i++) + { + size+=PX_LISTAT(PX_SCRIPT_ASM_MEMORY_NODE,&compiler->memoriesTable,i)->mem.usedsize+4; + } + return size; +} + +px_void PX_ScriptAsmAddStringConst(PX_SCRIPT_ASM_COMPILER *compiler,px_char *Str) +{ + px_int i; + PX_SCRIPT_ASM_STRING_NODE stringNode,*pLastNode; + for (i=0;iStringTable.size;i++) + { + if (PX_strequ(((PX_SCRIPT_ASM_STRING_NODE *)(PX_ListNodeAt(&compiler->StringTable,i)->pdata))->str.buffer,Str)) + { + return; + } + } + PX_StringInitialize(compiler->mp,&stringNode.str); + if(compiler->StringTable.size!=0) + { + pLastNode=(PX_SCRIPT_ASM_STRING_NODE *)(PX_ListNodeAt(&compiler->StringTable,compiler->StringTable.size-1)->pdata); + stringNode.addr=pLastNode->addr+PX_strlen(pLastNode->str.buffer)+1; + } + else + stringNode.addr=0; + PX_StringCat(&stringNode.str,Str); + PX_ListPush(&compiler->StringTable,&stringNode,sizeof(stringNode)); +} + +px_bool PX_ScriptAsmAddMemoryConst(PX_SCRIPT_ASM_COMPILER *compiler,px_char *StringMap) +{ + px_char hex[3]; + px_char _byte; + PX_SCRIPT_ASM_MEMORY_NODE memoryNode,*pLastNode; + + if (PX_strlen(StringMap)&1) + { + PX_ScriptAsmError(&compiler->lexer,"Invalid binary stream map"); + return PX_FALSE; + } + + PX_MemoryInitialize(compiler->mp,&memoryNode.mem); + + if(!PX_MemoryAlloc(&memoryNode.mem,PX_strlen(StringMap)>>1)) + return PX_FALSE; + + while (*StringMap) + { + hex[0]=*StringMap; + hex[1]=*(StringMap+1); + hex[2]=0; + + _byte=(px_char)PX_htoi(hex); + PX_MemoryCat(&memoryNode.mem,&_byte,1); + StringMap+=2; + } + + if(compiler->memoriesTable.size!=0) + { + pLastNode=PX_LISTAT(PX_SCRIPT_ASM_MEMORY_NODE,&compiler->memoriesTable,compiler->memoriesTable.size-1); + memoryNode.addr=pLastNode->addr+pLastNode->mem.usedsize+sizeof(px_dword); + } + else + memoryNode.addr=0; + + PX_ListPush(&compiler->memoriesTable,&memoryNode,sizeof(memoryNode)); + return PX_TRUE; +} + +px_dword PX_ScriptAsmGetStringAddr(PX_SCRIPT_ASM_COMPILER *compiler,px_char *Str) +{ + px_int i; + for (i=0;iStringTable.size;i++) + { + if (PX_strequ(((PX_SCRIPT_ASM_STRING_NODE *)(PX_ListNodeAt(&compiler->StringTable,i)->pdata))->str.buffer,Str)) + { + return ((PX_SCRIPT_ASM_STRING_NODE *)(PX_ListNodeAt(&compiler->StringTable,i)->pdata))->addr; + } + } + return 0; +} + +px_dword PX_ScriptAsmGetMemoryAddr(PX_SCRIPT_ASM_COMPILER *compiler,px_char *StringMap) +{ + px_int i; + px_char hex[3]; + px_char _byte; + PX_SCRIPT_ASM_MEMORY_NODE memoryNode; + + if (PX_strlen(StringMap)&1) + { + PX_ScriptAsmError(&compiler->lexer,"Invalid binary stream map"); + return PX_FALSE; + } + + PX_MemoryInitialize(compiler->mp,&memoryNode.mem); + PX_MemoryAlloc(&memoryNode.mem,PX_strlen(StringMap)>>1); + while (*StringMap) + { + hex[0]=*StringMap; + hex[1]=*(StringMap+1); + hex[2]=0; + + _byte=(px_char)PX_htoi(hex); + PX_MemoryCat(&memoryNode.mem,&_byte,1); + StringMap+=2; + } + + + for (i=0;imemoriesTable.size;i++) + { + if (PX_LISTAT(PX_SCRIPT_ASM_MEMORY_NODE,&compiler->memoriesTable,i)->mem.buffer==PX_NULL) + { + continue; + } + + if (PX_memequ(PX_LISTAT(PX_SCRIPT_ASM_MEMORY_NODE,&compiler->memoriesTable,i)->mem.buffer,memoryNode.mem.buffer,memoryNode.mem.usedsize)) + { + PX_MemoryFree(&memoryNode.mem); + return PX_LISTAT(PX_SCRIPT_ASM_MEMORY_NODE,&compiler->memoriesTable,i)->addr; + } + } + PX_MemoryFree(&memoryNode.mem); + return 0; +} + +px_void PX_ScriptAsmAddHost(PX_SCRIPT_ASM_COMPILER *compiler,px_char *Str) +{ + px_int i; + PX_SCRIPT_ASM_HOST_NODE Host; + for (i=0;iHostTable.size;i++) + { + if (PX_strequ(((PX_SCRIPT_ASM_HOST_NODE *)(PX_ListNodeAt(&compiler->HostTable,i)->pdata))->name,Str)) + { + return; + } + } + PX_strcpy(Host.name,Str,sizeof(Host.name)); + Host.map=PX_NULL; + Host.userptr=PX_NULL; + PX_ListPush(&compiler->HostTable,&Host,sizeof(Host)); +} + +px_int PX_ScriptAsmGetHostIndex(PX_SCRIPT_ASM_COMPILER *compiler,px_char *Str) +{ + px_int i; + for (i=0;iHostTable.size;i++) + { + if (PX_strequ(((PX_SCRIPT_ASM_HOST_NODE *)(PX_ListNodeAt(&compiler->HostTable,i)->pdata))->name,Str)) + { + return i; + } + } + return -1; +} +px_bool PX_ScriptAsmScan(PX_SCRIPT_ASM_COMPILER *compiler) +{ + PX_LEXER_STATE state=PX_LexerGetState(&compiler->lexer); + PX_LEXER_LEXEME_TYPE type; + PX_SCRIPT_ASM_GRAMMAR_INSTR *pinstr; + px_string assumeString,assumeName; + px_string includeStr; + px_int i,j; + px_bool hasMatched; + px_char *pLexeme; + + PX_StringInitialize(compiler->mp,&assumeName); + PX_StringInitialize(compiler->mp,&assumeString); + + while ((type=PX_ScriptAsmNexLexeme (&compiler->lexer))!=PX_LEXER_LEXEME_TYPE_END) + { + pLexeme=compiler->lexer.CurLexeme.buffer; + switch(type) + { + case PX_LEXER_LEXEME_TYPE_CONATINER: + case PX_LEXER_LEXEME_TYPE_DELIMITER: + case PX_LEXER_LEXEME_TYPE_ERR: + case PX_LEXER_LEXEME_TYPE_END: + goto _ERROR; + break; + case PX_LEXER_LEXEME_TYPE_SPACER: + case PX_LEXER_LEXEME_TYPE_NEWLINE: + continue; + break; + case PX_LEXER_LEXEME_TYPE_TOKEN: + { + //special + + //ASSUME + pLexeme=compiler->lexer.CurLexeme.buffer; + if (PX_strequ("ASSUME",pLexeme)) + { + if ((type=PX_ScriptAsmNexLexeme (&compiler->lexer))!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + PX_ScriptAsmError(&compiler->lexer,"ASSUME first token should be token!"); + goto _ERROR; + } + pLexeme=compiler->lexer.CurLexeme.buffer; + if (PX_strIsNumeric(pLexeme)) + { + PX_ScriptAsmError(&compiler->lexer,"ASSUME first token should not be numeric!"); + goto _ERROR; + } + + PX_StringClear(&assumeName); + PX_StringCat(&assumeName,pLexeme); + + if ((type=PX_ScriptAsmNexLexeme (&compiler->lexer))!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + PX_ScriptAsmError(&compiler->lexer,"ASSUME second token should be token!"); + goto _ERROR; + } + pLexeme=compiler->lexer.CurLexeme.buffer; + PX_StringClear(&assumeString); + PX_StringCat(&assumeString,pLexeme); + + if (PX_strequ(assumeString.buffer,assumeName.buffer)) + { + PX_ScriptAsmError(&compiler->lexer,"ASSUME token should not equal."); + goto _ERROR; + } + + if ((type=PX_ScriptAsmNexLexeme (&compiler->lexer))!=PX_LEXER_LEXEME_TYPE_NEWLINE&&type!=PX_LEXER_LEXEME_TYPE_END) + { + PX_ScriptAsmError(&compiler->lexer,"New line is expected but not found."); + goto _ERROR; + } + pLexeme=compiler->lexer.CurLexeme.buffer; + PX_ScriptAsmUpdateAssumeTable(compiler,assumeName.buffer,assumeString.buffer); + continue; + } + + //Function or Lable + if (pLexeme[PX_strlen(pLexeme)-1]==':') + { + pLexeme[PX_strlen(pLexeme)-1]='\0'; + if (PX_ScriptAsmIsValidToken(pLexeme)) + { + if (!PX_ScriptAsmAddSourceLabel(compiler,pLexeme,PX_FALSE)) + { + PX_ScriptAsmError(&compiler->lexer,"Add label error."); + goto _ERROR; + } + } + continue; + } + + + if (PX_strequ("EXPORT",pLexeme)) + { + if ((type=PX_ScriptAsmNexLexeme (&compiler->lexer))!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + PX_ScriptAsmError(&compiler->lexer,"Mnemonic \"Function\" not found!"); + goto _ERROR; + } + pLexeme=compiler->lexer.CurLexeme.buffer; + + if (!PX_strequ(pLexeme,"FUNCTION")) + { + PX_ScriptAsmError(&compiler->lexer,"Mnemonic \"Function\" not found!"); + goto _ERROR; + } + + if ((type=PX_ScriptAsmNexLexeme (&compiler->lexer))!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + PX_ScriptAsmError(&compiler->lexer,"Function name expected but not found!"); + goto _ERROR; + } + + pLexeme=compiler->lexer.CurLexeme.buffer; + + if (pLexeme[PX_strlen(pLexeme)-1]!=':') + { + PX_ScriptAsmError(&compiler->lexer,"Function name colon expected but not found!"); + goto _ERROR; + } + pLexeme[PX_strlen(pLexeme)-1]='\0'; + if (PX_ScriptAsmIsValidToken(pLexeme)) + { + if (!PX_ScriptAsmAddSourceLabel(compiler,pLexeme,PX_TRUE)) + { + PX_ScriptAsmError(&compiler->lexer,"Add label error."); + goto _ERROR; + } + } + + continue; + } + + if (PX_strequ("FUNCTION",pLexeme)) + { + if ((type=PX_ScriptAsmNexLexeme (&compiler->lexer))!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + PX_ScriptAsmError(&compiler->lexer,"Function name expected but not found!"); + goto _ERROR; + } + pLexeme=compiler->lexer.CurLexeme.buffer; + + if (pLexeme[PX_strlen(pLexeme)-1]!=':') + { + PX_ScriptAsmError(&compiler->lexer,"Function name colon expected but not found!"); + goto _ERROR; + } + pLexeme[PX_strlen(pLexeme)-1]='\0'; + if (PX_ScriptAsmIsValidToken(pLexeme)) + { + if (!PX_ScriptAsmAddSourceLabel(compiler,pLexeme,PX_FALSE)) + { + PX_ScriptAsmError(&compiler->lexer,"Add label error."); + goto _ERROR; + } + } + + continue; + } + + //.Global + if (PX_strequ(".GLOBAL",pLexeme)) + { + if ((type=PX_ScriptAsmNexLexeme (&compiler->lexer))!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + PX_ScriptAsmError(&compiler->lexer,"Global size should be integer(const)!"); + goto _ERROR; + } + + pLexeme=compiler->lexer.CurLexeme.buffer; + if(!PX_ScriptAsm_isInt(pLexeme)) + { + PX_ScriptAsmError(&compiler->lexer,"Global size should be integer(const)!"); + goto _ERROR; + } + compiler->globalsize=PX_ScriptAsm_atoi(pLexeme); + if ((type=PX_ScriptAsmNexLexeme (&compiler->lexer))!=PX_LEXER_LEXEME_TYPE_NEWLINE&&type!=PX_LEXER_LEXEME_TYPE_END) + { + PX_ScriptAsmError(&compiler->lexer,"New line is expected but not found."); + goto _ERROR; + } + continue; + } + + //.STACK + if (PX_strequ(".STACK",pLexeme)) + { + if ((type=PX_ScriptAsmNexLexeme (&compiler->lexer))!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + PX_ScriptAsmError(&compiler->lexer,"Stack size should be integer(const)!"); + goto _ERROR; + } + + pLexeme=compiler->lexer.CurLexeme.buffer; + + if(!PX_ScriptAsm_isInt(pLexeme)) + { + PX_ScriptAsmError(&compiler->lexer,"Stack size should be integer(const)!"); + goto _ERROR; + } + compiler->stacksize=PX_ScriptAsm_atoi(pLexeme); + if ((type=PX_ScriptAsmNexLexeme (&compiler->lexer))!=PX_LEXER_LEXEME_TYPE_NEWLINE&&type!=PX_LEXER_LEXEME_TYPE_END) + { + PX_ScriptAsmError(&compiler->lexer,"New line is expected but not found."); + goto _ERROR; + } + continue; + } + + //.THREAD + if (PX_strequ(".THREAD",pLexeme)) + { + if ((type=PX_ScriptAsmNexLexeme (&compiler->lexer))!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + PX_ScriptAsmError(&compiler->lexer,"thread count should be integer(const)!"); + goto _ERROR; + } + + pLexeme=compiler->lexer.CurLexeme.buffer; + + if(!PX_ScriptAsm_isInt(pLexeme)) + { + PX_ScriptAsmError(&compiler->lexer,"thread count should be integer(const)!"); + goto _ERROR; + } + compiler->threadcount=PX_ScriptAsm_atoi(pLexeme); + + if(compiler->threadcount<=0) + { + PX_ScriptAsmError(&compiler->lexer,"thread count should not less than 1!"); + goto _ERROR; + } + + if ((type=PX_ScriptAsmNexLexeme (&compiler->lexer))!=PX_LEXER_LEXEME_TYPE_NEWLINE&&type!=PX_LEXER_LEXEME_TYPE_END) + { + PX_ScriptAsmError(&compiler->lexer,"New line is expected but not found."); + goto _ERROR; + } + continue; + } + + //normal + hasMatched=PX_FALSE; + state=PX_LexerGetState(&compiler->lexer); + for (i=0;iGrammarInstrTable.size;i++) + { + pinstr=PX_LISTAT(PX_SCRIPT_ASM_GRAMMAR_INSTR,&compiler->GrammarInstrTable,i); + if (PX_strequ(pinstr->mnemonic,pLexeme)) + { + if (pinstr->paramCount==0) + { + if ((type=PX_ScriptAsmNexLexeme (&compiler->lexer))!=PX_LEXER_LEXEME_TYPE_NEWLINE&&type!=PX_LEXER_LEXEME_TYPE_END) + { + PX_LexerSetState(state); + continue; + } + hasMatched=PX_TRUE; + break; + } + + for (j=0;jparamCount;j++) + { + type=PX_ScriptAsmNexLexeme (&compiler->lexer); + pLexeme=compiler->lexer.CurLexeme.buffer; + if (type!=PX_LEXER_LEXEME_TYPE_TOKEN&&type!=PX_LEXER_LEXEME_TYPE_CONATINER) + { + PX_LexerSetState(state); + continue; + } + else + { + + if (PX_ScriptAsmTokenType(compiler,compiler->lexer.CurLexeme.buffer)==PX_SCRIPT_ASM_OPERAND_ACC_TYPE_UNKNOW) + { + if (!PX_ScriptAsmIsValidToken(compiler->lexer.CurLexeme.buffer)) + { + PX_ScriptAsmError(&compiler->lexer,"Unknow token type"); + goto _ERROR; + } + } + + if (PX_ScriptAsmTokenType(compiler,compiler->lexer.CurLexeme.buffer)==PX_SCRIPT_ASM_OPERAND_ACC_TYPE_STRING) + { + PX_StringInitialize(compiler->mp,&includeStr); + PX_LexerGetIncludedString(&compiler->lexer,&includeStr); + PX_ScriptAsmStringConvert(&includeStr); + PX_ScriptAsmAddStringConst(compiler,includeStr.buffer); + PX_StringFree(&includeStr); + } + + if (PX_ScriptAsmTokenType(compiler,compiler->lexer.CurLexeme.buffer)==PX_SCRIPT_ASM_OPERAND_ACC_TYPE_MEMORY) + { + PX_StringInitialize(compiler->mp,&includeStr); + PX_LexerGetIncludedString(&compiler->lexer,&includeStr); + if(!PX_ScriptAsmAddMemoryConst(compiler,includeStr.buffer)) + { + PX_ScriptAsmError(&compiler->lexer,"Invalid memories const!"); + goto _ERROR; + } + PX_StringFree(&includeStr); + } + + if (PX_ScriptAsmTokenType(compiler,compiler->lexer.CurLexeme.buffer)==PX_SCRIPT_ASM_OPERAND_ACC_TYPE_HOST) + { + PX_ScriptAsmAddHost(compiler,compiler->lexer.CurLexeme.buffer); + } + + if(jparamCount-1) + { + type=PX_ScriptAsmNexLexeme (&compiler->lexer); + pLexeme=compiler->lexer.CurLexeme.buffer; + if (type!=PX_LEXER_LEXEME_TYPE_DELIMITER) + { + PX_ScriptAsmError(&compiler->lexer,"Parameters error."); + goto _ERROR; + } + } + } + } + + if ((type=PX_ScriptAsmNexLexeme (&compiler->lexer))!=PX_LEXER_LEXEME_TYPE_NEWLINE&&type!=PX_LEXER_LEXEME_TYPE_END) + { + PX_LexerSetState(state); + continue; + } + hasMatched=PX_TRUE; + break; + } + } + if (!hasMatched) + { + PX_ScriptAsmError(&compiler->lexer,"Instr not match."); + PX_LexerSetState(state); + goto _ERROR; + } + + } + break; + } + } + PX_StringFree(&assumeName); + PX_StringFree(&assumeString); + return PX_TRUE; +_ERROR: + PX_StringFree(&assumeName); + PX_StringFree(&assumeString); + return PX_FALSE; + +} + + + + +px_bool PX_ScriptAsmCc(PX_SCRIPT_ASM_COMPILER *compiler) +{ + px_string ParamMne; + PX_LEXER_STATE state=PX_LexerGetState(&compiler->lexer); + PX_LEXER_LEXEME_TYPE type; + PX_SCRIPT_ASM_GRAMMAR_INSTR *pinstr; + PX_SCRIPT_ASM_INSTR_BIN instrbin; + px_string assumeString,assumeName; + px_int i,j,TokenType,InstrBinOffset=0; + px_float itf; + px_bool hasMatched; + px_char *pLexeme; + px_string strInc; + + PX_StringInitialize(compiler->mp,&ParamMne); + PX_StringInitialize(compiler->mp,&assumeName); + PX_StringInitialize(compiler->mp,&assumeString); + + + while ((type=PX_ScriptAsmNexLexeme (&compiler->lexer))!=PX_LEXER_LEXEME_TYPE_END) + { + pLexeme=compiler->lexer.CurLexeme.buffer; + switch(type) + { + case PX_LEXER_LEXEME_TYPE_CONATINER: + case PX_LEXER_LEXEME_TYPE_DELIMITER: + case PX_LEXER_LEXEME_TYPE_ERR: + case PX_LEXER_LEXEME_TYPE_END: + goto _ERROR; + break; + case PX_LEXER_LEXEME_TYPE_SPACER: + case PX_LEXER_LEXEME_TYPE_NEWLINE: + continue; + break; + case PX_LEXER_LEXEME_TYPE_TOKEN: + { + //special + + //ASSUME + pLexeme=compiler->lexer.CurLexeme.buffer; + if (PX_strequ("ASSUME",pLexeme)) + { + if ((type=PX_ScriptAsmNexLexeme (&compiler->lexer))!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + PX_ScriptAsmError(&compiler->lexer,"ASSUME first token should be token!"); + goto _ERROR; + } + + if (PX_strIsNumeric(pLexeme)) + { + PX_ScriptAsmError(&compiler->lexer,"ASSUME first token should not be numeric!"); + goto _ERROR; + } + + PX_StringSet(&assumeName,pLexeme); + + if ((type=PX_ScriptAsmNexLexeme (&compiler->lexer))!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + PX_ScriptAsmError(&compiler->lexer,"ASSUME second token should be token!"); + goto _ERROR; + } + pLexeme=compiler->lexer.CurLexeme.buffer; + PX_StringSet(&assumeString,pLexeme); + + if (PX_strequ(assumeString.buffer,assumeName.buffer)) + { + PX_ScriptAsmError(&compiler->lexer,"ASSUME token should not equal."); + goto _ERROR; + } + + if ((type=PX_ScriptAsmNexLexeme (&compiler->lexer))!=PX_LEXER_LEXEME_TYPE_NEWLINE&&type!=PX_LEXER_LEXEME_TYPE_END) + { + PX_ScriptAsmError(&compiler->lexer,"New line is expected but not found."); + goto _ERROR; + } + pLexeme=compiler->lexer.CurLexeme.buffer; + PX_ScriptAsmUpdateAssumeTable(compiler,assumeName.buffer,assumeString.buffer); + continue; + } + + //Function or Lable + if (pLexeme[PX_strlen(pLexeme)-1]==':') + { + pLexeme[PX_strlen(pLexeme)-1]='\0'; + if (PX_ScriptAsmIsValidToken(pLexeme)) + { + if (!PX_ScriptAsmUpdateLabelAddr(compiler,pLexeme,InstrBinOffset)) + { + goto _ERROR; + } + } + continue; + } + + if (PX_strequ("EXPORT",pLexeme)) + { + PX_ScriptAsmNexLexeme (&compiler->lexer); + PX_ScriptAsmNexLexeme (&compiler->lexer); + pLexeme=compiler->lexer.CurLexeme.buffer; + pLexeme[PX_strlen(pLexeme)-1]='\0'; + if (PX_ScriptAsmIsValidToken(pLexeme)) + { + if (!PX_ScriptAsmUpdateLabelAddr(compiler,pLexeme,InstrBinOffset)) + { + goto _ERROR; + } + } + continue; + } + + if (PX_strequ("FUNCTION",pLexeme)) + { + PX_ScriptAsmNexLexeme (&compiler->lexer); + pLexeme=compiler->lexer.CurLexeme.buffer; + pLexeme[PX_strlen(pLexeme)-1]='\0'; + if (PX_ScriptAsmIsValidToken(pLexeme)) + { + if (!PX_ScriptAsmUpdateLabelAddr(compiler,pLexeme,InstrBinOffset)) + { + goto _ERROR; + } + } + continue; + } + + //.Global + if (PX_strequ(".GLOBAL",pLexeme)) + { + PX_ScriptAsmNexLexeme (&compiler->lexer); + PX_ScriptAsmNexLexeme (&compiler->lexer); + continue; + } + + //.Stack + if (PX_strequ(".STACK",pLexeme)) + { + PX_ScriptAsmNexLexeme (&compiler->lexer); + PX_ScriptAsmNexLexeme (&compiler->lexer); + continue; + } + + //.Thread + if (PX_strequ(".THREAD",pLexeme)) + { + PX_ScriptAsmNexLexeme (&compiler->lexer); + PX_ScriptAsmNexLexeme (&compiler->lexer); + continue; + } + + //normal + hasMatched=PX_FALSE; + state=PX_LexerGetState(&compiler->lexer); + for (i=0;iGrammarInstrTable.size;i++) + { + PX_memset(&instrbin,0,sizeof(instrbin)); + pinstr=(PX_SCRIPT_ASM_GRAMMAR_INSTR *)PX_ListNodeAt(&compiler->GrammarInstrTable,i)->pdata; + if (PX_strequ(pinstr->mnemonic,pLexeme)) + { + instrbin.opCode=pinstr->opcode; + + for (j=0;jparamCount;j++) + { + type=PX_ScriptAsmNexLexeme (&compiler->lexer); + pLexeme=compiler->lexer.CurLexeme.buffer; + PX_StringClear(&ParamMne); + PX_StringCat(&ParamMne,pLexeme); + + PX_ScriptASMMapAssume(compiler,&ParamMne); + + if (type!=PX_LEXER_LEXEME_TYPE_TOKEN&&type!=PX_LEXER_LEXEME_TYPE_CONATINER) + { + PX_LexerSetState(state); + continue; + } + else + { + if (((TokenType=PX_ScriptAsmTokenType(compiler,ParamMne.buffer))&pinstr->operandAccTypes[j])==0) + { + PX_LexerSetState(state); + continue; + } + if (TokenType==PX_SCRIPT_ASM_OPERAND_ACC_TYPE_UNKNOW) + { + PX_ScriptAsmError(&compiler->lexer,"illegal Token Type"); + return PX_FALSE; + } + instrbin.optype[j]=PX_ScriptAsmTokenTypeToOpType(TokenType); + switch(instrbin.optype[j]) + { + case PX_SCRIPT_ASM_OPTYPE_BP: + case PX_SCRIPT_ASM_OPTYPE_SP: + case PX_SCRIPT_ASM_OPTYPE_IP: + instrbin.param[j]=0; + break; + + case PX_SCRIPT_ASM_OPTYPE_MEMORY: + PX_StringInitialize(compiler->mp,&strInc); + PX_StringCat(&strInc,ParamMne.buffer); + PX_LexerGetIncludedString(&compiler->lexer,&strInc); + instrbin.param[j]=PX_ScriptAsmGetMemoryAddr(compiler,strInc.buffer); + PX_StringFree(&strInc); + break; + case PX_SCRIPT_ASM_OPTYPE_STRING: + PX_StringInitialize(compiler->mp,&strInc); + PX_StringCat(&strInc,ParamMne.buffer); + PX_LexerGetIncludedString(&compiler->lexer,&strInc); + PX_ScriptAsmStringConvert(&strInc); + instrbin.param[j]=PX_ScriptAsmGetStringAddr(compiler,strInc.buffer); + PX_StringFree(&strInc); + break; + case PX_SCRIPT_ASM_OPTYPE_LABEL: + instrbin.param[j]=PX_ScriptAsmGetLabelIndex(compiler,ParamMne.buffer); + break; + case PX_SCRIPT_ASM_OPTYPE_FLOAT: + itf=PX_atof(ParamMne.buffer); + instrbin.param[j]=*((int *)&itf); + break; + case PX_SCRIPT_ASM_OPTYPE_INT: + if(ParamMne.buffer[0]!='\'') + instrbin.param[j]=PX_ScriptAsm_atoi(ParamMne.buffer); + else + instrbin.param[j]=ParamMne.buffer[1]; + break; + case PX_SCRIPT_ASM_OPTYPE_REG: + instrbin.param[j]=PX_ScriptAsm_atoi(ParamMne.buffer+1); + break; + case PX_SCRIPT_ASM_OPTYPE_LOCAL: + if (!PX_ScriptAsmLocalType(compiler,ParamMne.buffer,&instrbin.optype[j],&instrbin.param[j])) + { + PX_ScriptAsmError(&compiler->lexer,"illegal local referenced"); + return PX_FALSE; + } + + break; + case PX_SCRIPT_ASM_OPTYPE_GLOBAL: + if (!PX_ScriptAsmGlobalType(compiler,ParamMne.buffer,&instrbin.optype[j],&instrbin.param[j])) + { + PX_ScriptAsmError(&compiler->lexer,"illegal local referenced"); + return PX_FALSE; + } + break; + case PX_SCRIPT_ASM_OPTYPE_HOST: + instrbin.param[j]=PX_ScriptAsmGetHostIndex(compiler,ParamMne.buffer); + break; + default: + { + PX_ScriptAsmError(&compiler->lexer,"Instrutment not match."); + PX_LexerSetState(state); + return PX_FALSE; + } + } + + } + if (j!=pinstr->paramCount-1) + { + PX_ScriptAsmNexLexeme (&compiler->lexer); + } + } + + if ((type=PX_ScriptAsmNexLexeme (&compiler->lexer))!=PX_LEXER_LEXEME_TYPE_NEWLINE&&type!=PX_LEXER_LEXEME_TYPE_END) + { + PX_LexerSetState(state); + continue; + } + hasMatched=PX_TRUE; + instrbin.addr=InstrBinOffset; + instrbin.opcount=pinstr->paramCount; + PX_VectorPushback(&compiler->StreamTable,&instrbin); + InstrBinOffset+=(4+sizeof(px_dword)*pinstr->paramCount); + break; + } + } + if (!hasMatched) + { + PX_ScriptAsmError(&compiler->lexer,"Instr not match."); + PX_LexerSetState(state); + return PX_FALSE; + } + + } + break; + } + } + PX_StringFree(&ParamMne); + PX_StringFree(&assumeName); + PX_StringFree(&assumeString); + return PX_TRUE; +_ERROR: + PX_StringFree(&ParamMne); + PX_StringFree(&assumeName); + PX_StringFree(&assumeString); + return PX_FALSE; +} + +px_void PX_ScriptAsmLink(PX_SCRIPT_ASM_COMPILER *compiler) +{ + px_int i,j; + PX_SCRIPT_ASM_INSTR_BIN *pbin=(PX_SCRIPT_ASM_INSTR_BIN *)compiler->StreamTable.data; + for (i=0;iStreamTable.size;i++) + { + for (j=0;j<3;j++) + { + if (pbin[i].optype[j]==PX_SCRIPT_ASM_OPTYPE_LABEL) + { + pbin[i].param[j]=PX_LISTAT(PX_SCRIPT_ASM_LABEL_NODE,&compiler->LabelTable,pbin[i].param[j])->binaddr; + pbin[i].optype[j]=PX_SCRIPT_ASM_OPTYPE_INT; + } + } + } +} + +static px_void PX_ScriptAsmRegistInstr_0(PX_SCRIPT_ASM_COMPILER *compiler,px_char mnemonic[__PX_SCRIPT_ASM_INSTR_MNEMONIC_NAME_LEN],px_char opcode) +{ + PX_ScriptAsmRegistInstr(compiler,mnemonic,opcode,PX_NULL,0); +} + +static px_void PX_ScriptAsmRegistInstr_1(PX_SCRIPT_ASM_COMPILER *compiler,px_char mnemonic[__PX_SCRIPT_ASM_INSTR_MNEMONIC_NAME_LEN],px_char opcode,px_int accType1) +{ + PX_ScriptAsmRegistInstr(compiler,mnemonic,opcode,&accType1,1); +} + +static px_void PX_ScriptAsmRegistInstr_2(PX_SCRIPT_ASM_COMPILER *compiler,px_char mnemonic[__PX_SCRIPT_ASM_INSTR_MNEMONIC_NAME_LEN],px_char opcode,px_int accType1,px_int accType2) +{ + px_int accType[2]; + accType[0]=accType1; + accType[1]=accType2; + PX_ScriptAsmRegistInstr(compiler,mnemonic,opcode,accType,2); +} + +static px_void PX_ScriptAsmRegistInstr_3(PX_SCRIPT_ASM_COMPILER *compiler,px_char mnemonic[__PX_SCRIPT_ASM_INSTR_MNEMONIC_NAME_LEN],px_char opcode,px_int accType1,px_int accType2,px_int accType3) +{ + px_int accType[3]; + accType[0]=accType1; + accType[1]=accType2; + accType[2]=accType3; + PX_ScriptAsmRegistInstr(compiler,mnemonic,opcode,accType,3); +} + + +px_bool PX_ScriptAsmCompile(px_memorypool *mp,px_char *asmcode,px_memory *binmemory) +{ + + PX_SCRIPT_ASM_COMPILER compiler; + PX_SCRIPT_ASM_HEADER header,*pheader; + PX_SCRIPT_EXPORT_FUNCTION expFunc; + PX_SCRIPT_ASM_HOST_NODE host; + PX_SCRIPT_ASM_INSTR_BIN *pinstrs; + PX_LEXER_STATE lexerstate; + px_uint quotes; + px_int i; + px_char *pbuf; + px_dword woffset; + px_dword binsize,bufsize; + + + ////////////////////////////////////////////////////////////////////////// + //test + + compiler.mp=mp; + + PX_LexerInit(&compiler.lexer,mp); + PX_LexerRegisterComment(&compiler.lexer,";","\n"); + PX_LexerRegisterComment(&compiler.lexer,";","\r"); + PX_LexerRegisterDelimiter(&compiler.lexer,','); + PX_LexerRegisterSpacer(&compiler.lexer,' '); + PX_LexerRegisterSpacer(&compiler.lexer,'\t'); + quotes=PX_LexerRegisterContainer(&compiler.lexer,"\"","\""); + PX_LexerRegisterContainerTransfer(&compiler.lexer,quotes,'\\'); + PX_LexerRegisterContainer(&compiler.lexer,"\'","\'"); + PX_LexerRegisterContainer(&compiler.lexer,"@","@"); + + PX_VectorInitialize(mp,&compiler.StreamTable,sizeof(PX_SCRIPT_ASM_INSTR_BIN),256); + PX_ListInitialize(mp,&compiler.assumeTable); + PX_ListInitialize(mp,&compiler.GrammarInstrTable); + PX_ListInitialize(mp,&compiler.HostTable); + PX_ListInitialize(mp,&compiler.LabelTable); + PX_ListInitialize(mp,&compiler.StringTable); + PX_ListInitialize(mp,&compiler.memoriesTable); + + compiler.threadcount=1; + + //binary format + //opcode 1 byte + //optype 3 byte + //operand [0,3]4 byte + + PX_ScriptAsmRegistInstr_2(&compiler,"MOV",PX_SCRIPT_ASM_INSTR_OPCODE_MOV, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_BP|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_SP|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_IP, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_NUM|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_BP|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_SP|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_IP|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_MEMORY|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_STRING + ); + + + PX_ScriptAsmRegistInstr_2(&compiler,"ADD",PX_SCRIPT_ASM_INSTR_OPCODE_ADD, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_BP|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_SP|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_IP, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_NUM|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_BP|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_SP|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_IP + ); + + PX_ScriptAsmRegistInstr_2(&compiler,"SUB",PX_SCRIPT_ASM_INSTR_OPCODE_SUB, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_BP|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_SP|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_IP, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_NUM|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL + ); + + PX_ScriptAsmRegistInstr_2(&compiler,"DIV",PX_SCRIPT_ASM_INSTR_OPCODE_DIV, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_NUM|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL + ); + + PX_ScriptAsmRegistInstr_2(&compiler,"MUL",PX_SCRIPT_ASM_INSTR_OPCODE_MUL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_NUM|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL + ); + + PX_ScriptAsmRegistInstr_2(&compiler,"MOD",PX_SCRIPT_ASM_INSTR_OPCODE_MOD, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL + ); + + PX_ScriptAsmRegistInstr_2(&compiler,"SHL",PX_SCRIPT_ASM_INSTR_OPCODE_SHL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL + ); + + PX_ScriptAsmRegistInstr_2(&compiler,"SHR",PX_SCRIPT_ASM_INSTR_OPCODE_SHR, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL + ); + + PX_ScriptAsmRegistInstr_2(&compiler,"AND",PX_SCRIPT_ASM_INSTR_OPCODE_AND, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_NUM|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL + ); + + PX_ScriptAsmRegistInstr_2(&compiler,"ANDL",PX_SCRIPT_ASM_INSTR_OPCODE_ANDL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_NUM|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL + ); + + PX_ScriptAsmRegistInstr_2(&compiler,"ORL",PX_SCRIPT_ASM_INSTR_OPCODE_ORL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_NUM|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL + ); + + PX_ScriptAsmRegistInstr_2(&compiler,"OR",PX_SCRIPT_ASM_INSTR_OPCODE_OR, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_NUM|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL + ); + + PX_ScriptAsmRegistInstr_2(&compiler,"XOR",PX_SCRIPT_ASM_INSTR_OPCODE_XOR, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_NUM|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL + ); + + PX_ScriptAsmRegistInstr_2(&compiler,"POW",PX_SCRIPT_ASM_INSTR_OPCODE_POW, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_NUM|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL + ); + PX_ScriptAsmRegistInstr_2(&compiler,"SIN",PX_SCRIPT_ASM_INSTR_OPCODE_SIN, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_NUM|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL + ); + + PX_ScriptAsmRegistInstr_2(&compiler,"COS",PX_SCRIPT_ASM_INSTR_OPCODE_COS, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_NUM|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL + ); + + PX_ScriptAsmRegistInstr_1(&compiler,"INT",PX_SCRIPT_ASM_INSTR_OPCODE_INT, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL + ); + + PX_ScriptAsmRegistInstr_1(&compiler,"FLT",PX_SCRIPT_ASM_INSTR_OPCODE_FLT, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL + ); + + + PX_ScriptAsmRegistInstr_2(&compiler,"STRLEN",PX_SCRIPT_ASM_INSTR_OPCODE_STRLEN, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_STRING + ); + + PX_ScriptAsmRegistInstr_2(&compiler,"STRCAT",PX_SCRIPT_ASM_INSTR_OPCODE_STRCAT, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_STRING + ); + + PX_ScriptAsmRegistInstr_3(&compiler,"STRREP",PX_SCRIPT_ASM_INSTR_OPCODE_STRREP, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_STRING, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_STRING + ); + + PX_ScriptAsmRegistInstr_3(&compiler,"STRCHR",PX_SCRIPT_ASM_INSTR_OPCODE_STRCHR, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_STRING, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT + ); + + PX_ScriptAsmRegistInstr_2(&compiler,"STRTOI",PX_SCRIPT_ASM_INSTR_OPCODE_STRTOI, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_STRING + ); + + PX_ScriptAsmRegistInstr_2(&compiler,"STRTOF",PX_SCRIPT_ASM_INSTR_OPCODE_STRTOF, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_STRING + ); + + PX_ScriptAsmRegistInstr_2(&compiler,"STRFRI",PX_SCRIPT_ASM_INSTR_OPCODE_STRFRI, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT + ); + + PX_ScriptAsmRegistInstr_2(&compiler,"STRFRF",PX_SCRIPT_ASM_INSTR_OPCODE_STRFRF, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_FLOAT + ); + + PX_ScriptAsmRegistInstr_1(&compiler,"STRTMEM",PX_SCRIPT_ASM_INSTR_OPCODE_STRTMEM, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL + ); + + PX_ScriptAsmRegistInstr_3(&compiler,"STRSET",PX_SCRIPT_ASM_INSTR_OPCODE_STRSET, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_STRING + ); + + PX_ScriptAsmRegistInstr_3(&compiler,"STRFIND",PX_SCRIPT_ASM_INSTR_OPCODE_STRFIND, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_STRING, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_STRING + ); + + PX_ScriptAsmRegistInstr_2(&compiler,"ASC",PX_SCRIPT_ASM_INSTR_OPCODE_ASC, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_STRING + ); + + PX_ScriptAsmRegistInstr_3(&compiler,"MEMBYTE",PX_SCRIPT_ASM_INSTR_OPCODE_MEMBYTE, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_MEMORY + ); + + PX_ScriptAsmRegistInstr_3(&compiler,"MEMSET",PX_SCRIPT_ASM_INSTR_OPCODE_MEMSET, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_NUM|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL + ); + PX_ScriptAsmRegistInstr_3(&compiler,"MEMTRM",PX_SCRIPT_ASM_INSTR_OPCODE_MEMTRM, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT + ); + + PX_ScriptAsmRegistInstr_3(&compiler,"MEMFIND",PX_SCRIPT_ASM_INSTR_OPCODE_MEMFIND, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_MEMORY, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_MEMORY + ); + + PX_ScriptAsmRegistInstr_2(&compiler,"MEMLEN",PX_SCRIPT_ASM_INSTR_OPCODE_MEMLEN, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_MEMORY + ); + + PX_ScriptAsmRegistInstr_2(&compiler,"MEMCAT",PX_SCRIPT_ASM_INSTR_OPCODE_MEMCAT, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_MEMORY + ); + + PX_ScriptAsmRegistInstr_1(&compiler,"MEMTSTR",PX_SCRIPT_ASM_INSTR_OPCODE_MEMTSTR, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL + ); + + PX_ScriptAsmRegistInstr_3(&compiler,"MEMTRM",PX_SCRIPT_ASM_INSTR_OPCODE_MEMTRM, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT + ); + + PX_ScriptAsmRegistInstr_3(&compiler,"DATACPY",PX_SCRIPT_ASM_INSTR_OPCODE_DATACPY, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT + ); + + PX_ScriptAsmRegistInstr_1(&compiler,"NEG",PX_SCRIPT_ASM_INSTR_OPCODE_NEG, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL + ); + + PX_ScriptAsmRegistInstr_1(&compiler,"INV",PX_SCRIPT_ASM_INSTR_OPCODE_INV, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL + ); + + PX_ScriptAsmRegistInstr_1(&compiler,"NOT",PX_SCRIPT_ASM_INSTR_OPCODE_NOT, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL + ); + + PX_ScriptAsmRegistInstr_1(&compiler,"JMP",PX_SCRIPT_ASM_INSTR_OPCODE_JMP, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LABEL + ); + + PX_ScriptAsmRegistInstr_3(&compiler,"JE",PX_SCRIPT_ASM_INSTR_OPCODE_JE, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_NUM|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_STRING, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_NUM|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_STRING, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LABEL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT + ); + + PX_ScriptAsmRegistInstr_3(&compiler,"JNE",PX_SCRIPT_ASM_INSTR_OPCODE_JNE, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_NUM|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_STRING, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_NUM|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_STRING, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LABEL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT + ); + + PX_ScriptAsmRegistInstr_3(&compiler,"JLE",PX_SCRIPT_ASM_INSTR_OPCODE_JLE, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_NUM|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_STRING, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_NUM|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_STRING, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LABEL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT + ); + + PX_ScriptAsmRegistInstr_3(&compiler,"JGE",PX_SCRIPT_ASM_INSTR_OPCODE_JGE, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_NUM|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_STRING, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_NUM|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_STRING, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LABEL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT + ); + + PX_ScriptAsmRegistInstr_3(&compiler,"JL",PX_SCRIPT_ASM_INSTR_OPCODE_JL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_NUM|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_STRING, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_NUM|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_STRING, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LABEL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT + ); + + PX_ScriptAsmRegistInstr_3(&compiler,"JG",PX_SCRIPT_ASM_INSTR_OPCODE_JG, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_NUM|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_STRING, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_NUM|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_STRING, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LABEL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT + ); + + PX_ScriptAsmRegistInstr_3(&compiler,"LGE",PX_SCRIPT_ASM_INSTR_OPCODE_LGE, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LABEL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_NUM|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_STRING, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_NUM|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_STRING + ); + + PX_ScriptAsmRegistInstr_3(&compiler,"LGNE",PX_SCRIPT_ASM_INSTR_OPCODE_LGNE, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LABEL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_NUM|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_STRING, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_NUM|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_STRING + ); + + + PX_ScriptAsmRegistInstr_1(&compiler,"LGZ",PX_SCRIPT_ASM_INSTR_OPCODE_LGZ, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL + ); + + PX_ScriptAsmRegistInstr_1(&compiler,"LGGZ",PX_SCRIPT_ASM_INSTR_OPCODE_LGGZ, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL + ); + + PX_ScriptAsmRegistInstr_1(&compiler,"LGGEZ",PX_SCRIPT_ASM_INSTR_OPCODE_LGGEZ, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL + ); + + PX_ScriptAsmRegistInstr_1(&compiler,"LGLZ",PX_SCRIPT_ASM_INSTR_OPCODE_LGLZ, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL + ); + + PX_ScriptAsmRegistInstr_1(&compiler,"LGLEZ",PX_SCRIPT_ASM_INSTR_OPCODE_LGLEZ, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL + ); + + PX_ScriptAsmRegistInstr_1(&compiler,"CALL",PX_SCRIPT_ASM_INSTR_OPCODE_CALL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LABEL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_HOST + ); + + PX_ScriptAsmRegistInstr_1(&compiler,"PUSH",PX_SCRIPT_ASM_INSTR_OPCODE_PUSH, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_NUM|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LABEL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_STRING|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_BP|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_SP + ); + + PX_ScriptAsmRegistInstr_1(&compiler,"POP",PX_SCRIPT_ASM_INSTR_OPCODE_POP, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_BP|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_SP + ); + + PX_ScriptAsmRegistInstr_1(&compiler,"POPN",PX_SCRIPT_ASM_INSTR_OPCODE_POPN, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT + ); + + PX_ScriptAsmRegistInstr_2(&compiler,"ADR",PX_SCRIPT_ASM_INSTR_OPCODE_ADR, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL + ); + + PX_ScriptAsmRegistInstr_0(&compiler,"RET",PX_SCRIPT_ASM_INSTR_OPCODE_RET); + PX_ScriptAsmRegistInstr_0(&compiler,"NOP",PX_SCRIPT_ASM_INSTR_OPCODE_NOP); + PX_ScriptAsmRegistInstr_0(&compiler,"BPX",PX_SCRIPT_ASM_INSTR_OPCODE_BPX); + + PX_ScriptAsmRegistInstr_1(&compiler,"WAIT",PX_SCRIPT_ASM_INSTR_OPCODE_WAIT, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT + ); + + PX_ScriptAsmRegistInstr_2(&compiler,"SIGNAL",PX_SCRIPT_ASM_INSTR_OPCODE_SIGNAL, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT, + PX_SCRIPT_ASM_OPERAND_ACC_TYPE_REG|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_LOCAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_GLOBAL|PX_SCRIPT_ASM_OPERAND_ACC_TYPE_INT + ); + + if(!PX_LexerLoadSourceFromMemory(&compiler.lexer,asmcode)) + { + goto __ERROR; + } + + PX_LexerSetTokenCase(&compiler.lexer,PX_LEXER_LEXEME_CASE_UPPER); + + lexerstate=PX_LexerGetState(&compiler.lexer); + if(!PX_ScriptAsmScan(&compiler)) + goto __ERROR; + PX_LexerSetState(lexerstate); + if(!PX_ScriptAsmCc(&compiler)) + goto __ERROR; + + PX_ScriptAsmLink(&compiler); + + //Header + woffset=sizeof(PX_SCRIPT_ASM_HEADER); + PX_memset(&header,0,sizeof(header)); + header.magic=*((px_dword *)"PASM"); + header.stacksize=compiler.stacksize; + header.globalsize=compiler.globalsize; + header.threadcount=compiler.threadcount; + header.oftfunc=woffset; + header.funcCount=PX_ScriptAsmGetFuncCount(&compiler); + woffset+=header.funcCount*sizeof(PX_SCRIPT_EXPORT_FUNCTION); + header.ofthost=woffset; + header.hostCount=compiler.HostTable.size; + woffset+=header.hostCount*sizeof(PX_SCRIPT_ASM_HOST_NODE); + header.oftString=woffset; + header.stringSize=PX_ScriptAsmStringSize(&compiler); + woffset+=header.stringSize; + header.oftmem=woffset; + header.memsize=PX_ScriptAsmMemorySize(&compiler); + woffset+=header.memsize; + header.oftbin=woffset; + + PX_MemoryCat(binmemory,&header,sizeof(header)); + for (i=0;ibfunction) + { + PX_memset(expFunc.name,0,sizeof(expFunc.name)); + PX_strcpy(expFunc.name,PX_LISTAT(PX_SCRIPT_ASM_LABEL_NODE,&compiler.LabelTable,i)->mnemonic,sizeof(expFunc.name)); + expFunc.Addr=PX_LISTAT(PX_SCRIPT_ASM_LABEL_NODE,&compiler.LabelTable,i)->binaddr; + PX_MemoryCat(binmemory,&expFunc,sizeof(expFunc)); + } + } + + for (i=0;iname,sizeof(host.name)); + host.map=PX_NULL; + host.userptr=PX_NULL; + expFunc.Addr=0; + PX_MemoryCat(binmemory,&host,sizeof(host)); + } + + for (i=0;istr.buffer; + PX_MemoryCat(binmemory,pbuf,PX_strlen(pbuf)+1); + } + + for (i=0;imem.usedsize; + pbuf=(px_char *)PX_LISTAT(PX_SCRIPT_ASM_MEMORY_NODE,&compiler.memoriesTable,i)->mem.buffer; + PX_MemoryCat(binmemory,&bufsize,sizeof(px_dword)); + PX_MemoryCat(binmemory,pbuf,bufsize); + } + + + binsize=0; + for (i=0;iopCode,1); + PX_MemoryCat(binmemory,pinstrs->optype,3); + PX_MemoryCat(binmemory,pinstrs->param,pinstrs->opcount*sizeof(px_dword)); + binsize+=pinstrs->opcount*sizeof(px_dword)+4; + } + pheader=(PX_SCRIPT_ASM_HEADER *)binmemory->buffer; + pheader->binsize=binsize; + + pheader->CRC=PX_crc32(binmemory->buffer+8,binmemory->usedsize-8); + + //pTexpfunc=(PX_SCRIPT_EXPORT_FUNCTION *)(binmemory->buffer+header.oftfunc); + + PX_LexerFree(&compiler.lexer); + //link + PX_ListFree(&compiler.LabelTable); + PX_ListFree(&compiler.HostTable); + for (i=0;iname); + PX_StringFree(&PX_LISTAT(PX_SCRIPT_ASM_ASSUME_NODE,&compiler.assumeTable,i)->assume); + } + PX_ListFree(&compiler.assumeTable); + for (i=0;istr); + } + PX_ListFree(&compiler.StringTable); + for (i=0;imem); + } + PX_ListFree(&compiler.memoriesTable); + + PX_ListFree(&compiler.GrammarInstrTable); + PX_VectorFree(&compiler.StreamTable); + + return PX_TRUE; + + __ERROR: + //free compiler + //lexer + PX_LexerFree(&compiler.lexer); + //link + PX_ListFree(&compiler.LabelTable); + PX_ListFree(&compiler.HostTable); + for (i=0;iname); + PX_StringFree(&PX_LISTAT(PX_SCRIPT_ASM_ASSUME_NODE,&compiler.assumeTable,i)->assume); + } + PX_ListFree(&compiler.assumeTable); + for (i=0;istr); + } + PX_ListFree(&compiler.StringTable); + for (i=0;imem); + } + PX_ListFree(&compiler.memoriesTable); + + PX_ListFree(&compiler.GrammarInstrTable); + PX_VectorFree(&compiler.StreamTable); + return PX_FALSE; + +} + +px_bool PX_ScriptAsmOptimization(px_string *asmcode) +{ + px_bool opt=PX_FALSE; + + + do{ + opt=PX_FALSE; + opt=opt|PX_StringTrimer_Solve(asmcode,"SUB SP,0\n",""); + opt=opt|PX_StringTrimer_Solve(asmcode,"SUB %1,0\n",""); + opt=opt|PX_StringTrimer_Solve(asmcode,"ADD %1,0\n",""); + opt=opt|PX_StringTrimer_Solve(asmcode,"MUL %1,1\n",""); + opt=opt|PX_StringTrimer_Solve(asmcode,"PUSH %1\nPOP %1\n",""); + opt=opt|PX_StringTrimer_Solve(asmcode,"RET\nRET\n","RET\n"); + opt=opt|PX_StringTrimer_Solve(asmcode,"PUSH %1\nPOP %2\n","MOV %2,%1\n"); + opt=opt|PX_StringTrimer_Solve(asmcode,"MOV R%1,%2\nMOV %3,R%1\n","MOV %3,%2\n"); + opt=opt|PX_StringTrimer_Solve(asmcode,"MOV R2,0\nFLT R2\n","MOV R2,0.0\n"); + opt=opt|PX_StringTrimer_Solve(asmcode,"PUSH R1\nMOV R2,%1\nPOP R1\n","MOV R2,%1\n"); + }while(opt); + + return PX_TRUE; +} + +px_char * PX_ScriptASMCompilerError() +{ + return PX_Script_ASMError; +} diff --git a/lib/PainterEngine/kernel/PX_Script_ASMCompiler.h b/lib/PainterEngine/kernel/PX_Script_ASMCompiler.h new file mode 100644 index 0000000000000000000000000000000000000000..ecfd9652db3b462048981bfe54f737d006c928c8 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Script_ASMCompiler.h @@ -0,0 +1,7 @@ +#ifndef PX_SCRIPT_ASM_COMPILER_H +#define PX_SCRIPT_ASM_COMPILER_H +#include "PX_ScriptCore.h" +px_bool PX_ScriptAsmCompile(px_memorypool *mp,px_char *asmcode,px_memory *binmemory); +px_bool PX_ScriptAsmOptimization(px_string *asmcode); +px_char * PX_ScriptASMCompilerError(void); +#endif diff --git a/lib/PainterEngine/kernel/PX_Script_Interpreter.c b/lib/PainterEngine/kernel/PX_Script_Interpreter.c new file mode 100644 index 0000000000000000000000000000000000000000..d6a1d1364466094d9b588d00862e6e7e14b75b60 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Script_Interpreter.c @@ -0,0 +1,10755 @@ +#include "PX_Script_Interpreter.h" + +static px_char *PX_Script_Keywords[]={"IF","ELSE","SWITCH","CASE","WHILE","FOR","BREAK","RETURN","STRUCT","FUNCTION","EXPORT","HOST","INT","FLOAT","STRING","MEMORY","_BOOT","RETURN","_ASM"}; +static px_char PX_Script_InterpreterError[256]; + +px_void PX_ScriptTranslatorError(px_lexer *lexer,px_char *info) +{ + if (lexer) + { + lexer->Sources[lexer->SourceOffset]='\0'; + PX_Script_InterpreterError[0]='\0'; + if (lexer->SourceOffset>200) + { + PX_strcpy(PX_Script_InterpreterError,lexer->Sources+lexer->SourceOffset-200,200); + } + else + { + PX_strcpy(PX_Script_InterpreterError,lexer->Sources,200); + } + } + PX_LOG(info); +} + +px_void PX_ScriptParserClearStack(PX_SCRIPT_Analysis *analysis) +{ + int i; + PX_SCRIPT_VARIABLES *pvar; + for (i=0;iv_variablesStackTable.size;i++) + { + pvar=PX_VECTORAT(PX_SCRIPT_VARIABLES,&analysis->v_variablesStackTable,i); + if(pvar->bInitialized) + PX_StringFree(&pvar->GlobalInitializeValue); + + PX_StringFree(&pvar->Mnemonic); + } + PX_VectorClear(&analysis->v_variablesStackTable); + analysis->currentAllocStackSize=0; +} + +PX_LEXER_LEXEME_TYPE PX_ScriptTranslatorNextToken(px_lexer *lexer) +{ + PX_LEXER_LEXEME_TYPE type; + while ((type= PX_LexerGetNextLexeme(lexer))==PX_LEXER_LEXEME_TYPE_SPACER); + return type; +} +PX_LEXER_LEXEME_TYPE PX_ScriptTranslatorNextTokenSN(px_lexer *lexer) +{ + PX_LEXER_LEXEME_TYPE type; + while ((type= PX_LexerGetNextLexeme(lexer))==PX_LEXER_LEXEME_TYPE_SPACER||type==PX_LEXER_LEXEME_TYPE_NEWLINE); + + return type; +} +px_bool PX_ScriptCompilerInitialize(PX_SCRIPT_LIBRARY *lib,px_memorypool *mp) +{ + lib->mp=mp; + PX_VectorInitialize(mp,&lib->codeLibraries,sizeof(PX_SCRIPT_CODE),1); + return PX_TRUE; +} +px_void PX_ScriptCompilerFree(PX_SCRIPT_LIBRARY *lib) +{ + int i; + for (i=0;icodeLibraries.size;i++) + { + PX_StringFree(&PX_VECTORAT(PX_SCRIPT_CODE,&lib->codeLibraries,i)->name); + PX_StringFree(&PX_VECTORAT(PX_SCRIPT_CODE,&lib->codeLibraries,i)->code); + } + PX_VectorFree(&lib->codeLibraries); +} +px_bool PX_ScriptCompilerLoad(PX_SCRIPT_LIBRARY *lib,const px_char *code) +{ + px_lexer lexer; + PX_SCRIPT_CODE scode; + int i; + scode.bInclude=PX_FALSE; + + + PX_LexerInit(&lexer,lib->mp); + PX_LexerRegisterComment(&lexer,"//","\n"); + PX_LexerRegisterComment(&lexer,"/*","*/"); + PX_LexerRegisterDelimiter(&lexer,','); + PX_LexerRegisterSpacer(&lexer,' '); + PX_LexerRegisterSpacer(&lexer,'\t'); + PX_LexerRegisterContainer(&lexer,"\"","\""); + PX_LexerSetTokenCase(&lexer,PX_LEXER_LEXEME_CASE_UPPER); + + if(!PX_LexerLoadSourceFromMemory(&lexer,code)) + { + PX_LexerFree(&lexer); + return PX_FALSE; + } + if(PX_LexerGetNextLexeme(&lexer)!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + PX_LexerFree(&lexer); + return PX_FALSE; + } + if (!PX_strequ(lexer.CurLexeme.buffer,"#NAME")) + { + PX_LexerFree(&lexer); + return PX_FALSE; + } + + if(PX_LexerGetNextLexeme(&lexer)!=PX_LEXER_LEXEME_TYPE_SPACER) + { + PX_LexerFree(&lexer); + return PX_FALSE; + } + if(PX_LexerGetNextLexeme(&lexer)!=PX_LEXER_LEXEME_TYPE_CONATINER) + { + PX_LexerFree(&lexer); + return PX_FALSE; + } + PX_StringInitialize(lib->mp,&scode.code); + PX_StringInitialize(lib->mp,&scode.name); + + + PX_StringCat(&scode.name,lexer.CurLexeme.buffer); + PX_LexerGetIncludedString(&lexer,&scode.name); + + if(PX_LexerGetNextLexeme(&lexer)!=PX_LEXER_LEXEME_TYPE_NEWLINE) + { + PX_StringFree(&scode.name); + PX_StringFree(&scode.code); + PX_LexerFree(&lexer); + return PX_FALSE; + } + + PX_StringCat(&scode.code,lexer.Sources+lexer.SourceOffset); + PX_LexerFree(&lexer); + + + for (i=0;icodeLibraries.size;i++) + { + if (PX_strequ(scode.name.buffer,PX_VECTORAT(PX_SCRIPT_CODE,&lib->codeLibraries,i)->name.buffer)) + { + PX_StringFree(&scode.name); + PX_StringFree(&scode.code); + return PX_FALSE; + } + } + + PX_VectorPushback(&lib->codeLibraries,&scode); + + return PX_TRUE; +} +static px_bool PX_ScriptParseInclude(px_string *codes,PX_SCRIPT_LIBRARY *lib,const px_char *name) +{ + px_lexer lexer; + PX_LEXER_STATE lexerState; + px_int allocsize; + px_int quotes,singleQuotes,i; + px_bool bfound; + px_char *exchangeBuffer; + PX_LEXER_LEXEME_TYPE type; + + PX_LexerInit(&lexer,lib->mp); + PX_LexerRegisterDelimiter(&lexer,','); + PX_LexerRegisterDelimiter(&lexer,';'); + PX_LexerRegisterDelimiter(&lexer,'+'); + PX_LexerRegisterDelimiter(&lexer,'-'); + PX_LexerRegisterDelimiter(&lexer,'*'); + PX_LexerRegisterDelimiter(&lexer,'/'); + PX_LexerRegisterDelimiter(&lexer,'%'); + PX_LexerRegisterDelimiter(&lexer,'&'); + PX_LexerRegisterDelimiter(&lexer,'^'); + PX_LexerRegisterDelimiter(&lexer,'~'); + PX_LexerRegisterDelimiter(&lexer,'('); + PX_LexerRegisterDelimiter(&lexer,')'); + PX_LexerRegisterDelimiter(&lexer,'!'); + PX_LexerRegisterDelimiter(&lexer,'='); + PX_LexerRegisterDelimiter(&lexer,'>'); + PX_LexerRegisterDelimiter(&lexer,'<'); + PX_LexerRegisterDelimiter(&lexer,'{'); + PX_LexerRegisterDelimiter(&lexer,'}'); + PX_LexerRegisterDelimiter(&lexer,'['); + PX_LexerRegisterDelimiter(&lexer,']'); + PX_LexerRegisterSpacer(&lexer,' '); + PX_LexerRegisterSpacer(&lexer,'\t'); + quotes=PX_LexerRegisterContainer(&lexer,"\"","\""); + PX_LexerRegisterContainerTransfer(&lexer,quotes,'\\'); + singleQuotes=PX_LexerRegisterContainer(&lexer,"\'","\'"); + PX_LexerSetTokenCase(&lexer,PX_LEXER_LEXEME_CASE_UPPER); + + + if(!PX_LexerSetSourcePointer(&lexer,codes->buffer)) + goto _ERROR; + + while (PX_TRUE) + { + + lexerState=PX_LexerGetState(&lexer); + type=PX_ScriptTranslatorNextToken(&lexer); + if (type==PX_LEXER_LEXEME_TYPE_ERR) + { + PX_ScriptTranslatorError(&lexer,"lexer error."); + goto _ERROR; + } + if (type==PX_LEXER_LEXEME_TYPE_END) + { + break; + } + if (type==PX_LEXER_LEXEME_TYPE_TOKEN) + { + if (PX_strequ(lexer.CurLexeme.buffer,"#INCLUDE")) + { + if (PX_ScriptTranslatorNextToken(&lexer)==PX_LEXER_LEXEME_TYPE_CONATINER) + { + if (PX_LexerGetCurrentContainerType(&lexer)!=quotes) + { + PX_ScriptTranslatorError(&lexer,"syntactic error: include \"name\" expected but not found."); + goto _ERROR; + } + PX_LexerGetIncludedString(&lexer,&lexer.CurLexeme); + bfound=PX_FALSE; + for (i=0;icodeLibraries.size;i++) + { + if (PX_strequ(lexer.CurLexeme.buffer,PX_VECTORAT(PX_SCRIPT_CODE,&lib->codeLibraries,i)->name.buffer)) + { + if (PX_VECTORAT(PX_SCRIPT_CODE,&lib->codeLibraries,i)->bInclude!=PX_FALSE) + { + PX_ScriptTranslatorError(&lexer,"syntactic error: reduplicate included-name."); + goto _ERROR; + } + PX_VECTORAT(PX_SCRIPT_CODE,&lib->codeLibraries,i)->bInclude=PX_TRUE; + bfound=PX_TRUE; + + + if ((type=PX_ScriptTranslatorNextToken(&lexer))!=PX_LEXER_LEXEME_TYPE_NEWLINE) + { + if (type==PX_LEXER_LEXEME_TYPE_END) + { + PX_ScriptTranslatorError(&lexer,"syntactic error:include on last line without newline"); + goto _ERROR; + } + else + { + PX_ScriptTranslatorError(&lexer,"syntactic error:new line expected but not found."); + goto _ERROR; + } + + } + allocsize=lexerState.offset+PX_strlen(PX_VECTORAT(PX_SCRIPT_CODE,&lib->codeLibraries,i)->code.buffer)+PX_strlen(lexer.Sources+PX_LexerGetState(&lexer).offset-1)+1; + exchangeBuffer=(px_char *)MP_Malloc(lib->mp,allocsize); + + if (exchangeBuffer==PX_NULL) + { + PX_ScriptTranslatorError(&lexer,"memory error."); + goto _ERROR; + } + + PX_memcpy(exchangeBuffer,codes->buffer,lexerState.offset); + exchangeBuffer[lexerState.offset]=0; + PX_strcat(exchangeBuffer,PX_VECTORAT(PX_SCRIPT_CODE,&lib->codeLibraries,i)->code.buffer); + PX_strcat(exchangeBuffer,lexer.Sources+PX_LexerGetState(&lexer).offset-1); + + PX_StringClear(codes); + PX_StringCat(codes,exchangeBuffer); + + PX_LexerSetSourcePointer(&lexer,codes->buffer); + PX_LexerSetState(lexerState); + + MP_Free(lib->mp,exchangeBuffer); + + break; + + } + } + if (!bfound) + { + PX_ScriptTranslatorError(&lexer,"include error: source not found."); + goto _ERROR; + } + } + else + { + PX_ScriptTranslatorError(&lexer,"syntactic error:include-name expected but not found."); + goto _ERROR; + } + } + } + } + PX_LexerSetSourcePointer(&lexer,PX_NULL); + PX_LexerFree(&lexer); + return PX_TRUE; +_ERROR: + PX_LexerFree(&lexer); + PX_LexerSetSourcePointer(&lexer,PX_NULL); + return PX_FALSE; + +} +typedef struct +{ + px_string name; + px_string token; +}PX_SCRIPT_TRANSLATOR_DEFINE_ST; +static px_bool PX_ScriptParseDefine(px_string *codes,PX_SCRIPT_LIBRARY *lib,const px_char *name) +{ + px_lexer lexer; + px_int startIndex; + px_int quotes,singleQuotes,i; + PX_LEXER_LEXEME_TYPE type; + px_vector defines; + PX_SCRIPT_TRANSLATOR_DEFINE_ST defst; + + PX_VectorInitialize(lib->mp,&defines,sizeof(PX_SCRIPT_TRANSLATOR_DEFINE_ST),32); + + PX_LexerInit(&lexer,lib->mp); + PX_LexerRegisterDelimiter(&lexer,','); + PX_LexerRegisterDelimiter(&lexer,';'); + PX_LexerRegisterDelimiter(&lexer,'+'); + PX_LexerRegisterDelimiter(&lexer,'-'); + PX_LexerRegisterDelimiter(&lexer,'*'); + PX_LexerRegisterDelimiter(&lexer,'/'); + PX_LexerRegisterDelimiter(&lexer,'%'); + PX_LexerRegisterDelimiter(&lexer,'&'); + PX_LexerRegisterDelimiter(&lexer,'^'); + PX_LexerRegisterDelimiter(&lexer,'~'); + PX_LexerRegisterDelimiter(&lexer,'('); + PX_LexerRegisterDelimiter(&lexer,')'); + PX_LexerRegisterDelimiter(&lexer,'!'); + PX_LexerRegisterDelimiter(&lexer,'='); + PX_LexerRegisterDelimiter(&lexer,'>'); + PX_LexerRegisterDelimiter(&lexer,'<'); + PX_LexerRegisterDelimiter(&lexer,'{'); + PX_LexerRegisterDelimiter(&lexer,'}'); + PX_LexerRegisterDelimiter(&lexer,'['); + PX_LexerRegisterDelimiter(&lexer,']'); + PX_LexerRegisterSpacer(&lexer,' '); + PX_LexerRegisterSpacer(&lexer,'\t'); + quotes=PX_LexerRegisterContainer(&lexer,"\"","\""); + PX_LexerRegisterContainerTransfer(&lexer,quotes,'\\'); + singleQuotes=PX_LexerRegisterContainer(&lexer,"\'","\'"); + PX_LexerSetTokenCase(&lexer,PX_LEXER_LEXEME_CASE_UPPER); + + + if(!PX_LexerSetSourcePointer(&lexer,codes->buffer)) + goto _ERROR; + + while (PX_TRUE) + { + type=PX_ScriptTranslatorNextToken(&lexer); + if (type==PX_LEXER_LEXEME_TYPE_ERR) + { + PX_ScriptTranslatorError(&lexer,"lexer error."); + goto _ERROR; + } + if (type==PX_LEXER_LEXEME_TYPE_END) + { + break; + } + if (type==PX_LEXER_LEXEME_TYPE_TOKEN) + { + if (PX_strequ(lexer.CurLexeme.buffer,"#DEFINE")) + { + startIndex=lexer.SourceOffset-7; + if (PX_ScriptTranslatorNextToken(&lexer)!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + PX_ScriptTranslatorError(&lexer,"syntactic error:include-name expected but not found."); + goto _ERROR; + } + + + + PX_StringInitialize(lib->mp,&defst.name); + PX_StringCat(&defst.name,lexer.CurLexeme.buffer); + + if (PX_LexerGetNextLexeme(&lexer)!=PX_LEXER_LEXEME_TYPE_SPACER) + { + PX_ScriptTranslatorError(&lexer,"syntactic error:spacer expected but not found."); + goto _ERROR; + } + + PX_StringInitialize(lib->mp,&defst.token); + + if (lexer.Sources[lexer.SourceOffset]==' ') + { + lexer.SourceOffset++; + } + + while (PX_TRUE) + { + if (lexer.Sources[lexer.SourceOffset]!='\n'&&lexer.Sources[lexer.SourceOffset]!='\0'&&lexer.Sources[lexer.SourceOffset]!='\r') + { + PX_StringCatChar(&defst.token,lexer.Sources[lexer.SourceOffset]); + lexer.SourceOffset++; + } + else + break; + } + PX_VectorPushback(&defines,&defst); + + PX_StringReplaceRange(codes,startIndex,lexer.SourceOffset,""); + PX_LexerSetSourcePointer(&lexer,codes->buffer); + lexer.SourceOffset=startIndex; + } + } + } + + lexer.SourceOffset=0; + + while (PX_TRUE) + { + type=PX_ScriptTranslatorNextToken(&lexer); + if (type==PX_LEXER_LEXEME_TYPE_ERR) + { + PX_ScriptTranslatorError(&lexer,"lexer error."); + goto _ERROR; + } + if (type==PX_LEXER_LEXEME_TYPE_END) + { + break; + } + if (type==PX_LEXER_LEXEME_TYPE_TOKEN) + { + for (i=0;iname.buffer)) + { + startIndex=lexer.SourceOffset-PX_strlen(lexer.CurLexeme.buffer); + PX_StringReplaceRange(codes,startIndex,lexer.SourceOffset-1,PX_VECTORAT(PX_SCRIPT_TRANSLATOR_DEFINE_ST,&defines,i)->token.buffer); + PX_LexerSetSourcePointer(&lexer,codes->buffer); + lexer.SourceOffset=startIndex+PX_strlen(PX_VECTORAT(PX_SCRIPT_TRANSLATOR_DEFINE_ST,&defines,i)->token.buffer); + break; + } + } + } + } + PX_LexerSetSourcePointer(&lexer,PX_NULL); + PX_LexerFree(&lexer); + for (i=0;iname); + PX_StringFree(&PX_VECTORAT(PX_SCRIPT_TRANSLATOR_DEFINE_ST,&defines,i)->token); + } + PX_VectorFree(&defines); + return PX_TRUE; +_ERROR: + PX_LexerFree(&lexer); + for (i=0;iname); + PX_StringFree(&PX_VECTORAT(PX_SCRIPT_TRANSLATOR_DEFINE_ST,&defines,i)->token); + } + PX_LexerSetSourcePointer(&lexer,PX_NULL); + PX_VectorFree(&defines); + return PX_FALSE; +} +static px_bool PX_ScriptParsePretreatment(px_string *codes,PX_SCRIPT_LIBRARY *lib,const px_char *name) +{ + + if(!PX_ScriptParseInclude(codes,lib,name)) + goto _ERROR; + + if(!PX_ScriptParseDefine(codes,lib,name)) + goto _ERROR; + + return PX_TRUE; +_ERROR: + return PX_FALSE; +} +static px_bool PX_ScriptParseIsValidToken(px_char *token) +{ + px_int i; + if (token[0]=='\0'||PX_charIsNumeric(token[0])) + { + return PX_FALSE; + } + + for(i=0;i='A'&&*token<='Z')||(*token>='a'&&*token<='z')||*token=='_'||*token==':'||PX_charIsNumeric(*token)) + { + token++; + continue; + } + return PX_FALSE; + } + return PX_TRUE; +} +static px_bool PX_ScriptParseCheckBrackets(px_char *pstr) +{ + px_int big=0,mid=0,lit=0; + while (*pstr) + { + if (*pstr=='{') + { + big++; + } + + if (*pstr=='}') + { + big--; + } + + if (*pstr=='[') + { + mid++; + } + + if (*pstr==']') + { + mid--; + } + + if (*pstr=='(') + { + lit++; + } + + if (*pstr==')') + { + lit--; + } + if (big<0||lit<0) + { + return PX_FALSE; + } + pstr++; + } + if (big||mid||lit) + { + return PX_FALSE; + } + return PX_TRUE; +} +static PX_SCRIPT_STRUCT *PX_ScriptParseGetStructByIndex(PX_SCRIPT_Analysis *analysis,px_int index) +{ + if (index>=analysis->v_struct.size||index<0) + { + return PX_NULL; + } + + return PX_VECTORAT(PX_SCRIPT_STRUCT,&analysis->v_struct,index); +} +static px_char PX_ScriptParseGetOpLevel(px_char *op,px_bool binary) +{ + if (PX_strlen(op)==1) + { + switch(*op) + { + case '(': + case ')': + case '[': + case ']': + case '.': + return 1; + case '!': + case '~': + return 2; + case '+': + case '-': + { + if (binary) + return 4; + else + return 2; + } + break; + case '>': + return 6; + case '<': + return 6; + case '*': + if(!binary) return 2; + case '/': + case '%': + return 3; + case '&': + if(!binary) return 2; + return 8; + case '^': + return 9; + case '|': + return 10; + + case '=': + return 14; + case ',': + return 15; + + } + } + else + { + if (PX_strequ(op,">=")) + { + return 6; + } + if (PX_strequ(op,"<=")) + { + return 6; + } + if (PX_strequ(op,"<<")) + { + return 5; + } + if (PX_strequ(op,">>")) + { + return 5; + } + if (PX_strequ(op,"&&")) + { + return 11; + } + if (PX_strequ(op,"||")) + { + return 12; + } + if (PX_strequ(op,"==")) + { + return 7; + } + if (PX_strequ(op,"!=")) + { + return 7; + } + if (PX_strequ(op,"++")) + { + return 2; + } + if (PX_strequ(op,"--")) + { + return 2; + } + } + return -1; +} +static px_bool PX_ScriptParse_AST_PushToken(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,PX_SCRIPT_EXPR_STREAM atom,PX_SCRIPT_STRUCT *_inset,PX_SCRIPT_STRUCT **_outset) +{ + px_int i; + PX_SCRIPT_VARIABLES *pvar; + PX_SCRIPT_AST_OPERAND operand; + PX_SCRIPT_SETMEMBER *psetmem; + + //Struct offset + if (_inset!=PX_NULL) + { + for (i=0;i<_inset->members.size;i++) + { + psetmem=PX_VECTORAT(PX_SCRIPT_SETMEMBER,&_inset->members,i); + if (PX_strequ(psetmem->defvar.Mnemonic.buffer,atom.code.buffer)) + { + *_outset=PX_NULL; + switch(psetmem->defvar.type) + { + case PX_SCRIPT_PARSER_VAR_TYPE_INT: + { + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT; + operand._oft=psetmem->offset; + operand.pSet=PX_NULL; + PX_VectorPushback(tk,&operand); + return PX_TRUE; + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_FLOAT: + { + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT; + operand._oft=psetmem->offset; + operand.pSet=PX_NULL; + PX_VectorPushback(tk,&operand); + return PX_TRUE; + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_STRING: + { + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_STRING; + operand._oft=psetmem->offset; + operand.pSet=PX_NULL; + PX_VectorPushback(tk,&operand); + return PX_TRUE; + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_MEMORY: + { + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY; + operand._oft=psetmem->offset; + operand.pSet=PX_NULL; + PX_VectorPushback(tk,&operand); + return PX_TRUE; + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_STRUCT: + { + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_STRUCT; + operand._oft=psetmem->offset; + operand.pSet=PX_ScriptParseGetStructByIndex(analysis,psetmem->defvar.setIndex); + *_outset=operand.pSet; + PX_VectorPushback(tk,&operand); + return PX_TRUE; + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_INT_ARRAY: + { + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR_CONST; + operand._oft=psetmem->offset; + operand.pSet=PX_NULL; + PX_VectorPushback(tk,&operand); + return PX_TRUE; + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_FLOAT_ARRAY: + { + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR_CONST; + operand._oft=psetmem->offset; + operand.pSet=PX_NULL; + PX_VectorPushback(tk,&operand); + return PX_TRUE; + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_STRING_ARRAY: + { + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR_CONST; + operand._oft=psetmem->offset; + operand.pSet=PX_NULL; + PX_VectorPushback(tk,&operand); + return PX_TRUE; + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_MEMORY_ARRAY: + { + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR_CONST; + operand._oft=psetmem->offset; + operand.pSet=PX_NULL; + PX_VectorPushback(tk,&operand); + return PX_TRUE; + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_SET_ARRAY: + { + + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_SET_PTR_CONST; + operand._oft=psetmem->offset; + operand.pSet=PX_ScriptParseGetStructByIndex(analysis,psetmem->defvar.setIndex); + *_outset=operand.pSet; + PX_VectorPushback(tk,&operand); + return PX_TRUE; + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_INT_PTR: + { + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR; + operand._oft=psetmem->offset; + operand.pSet=PX_NULL; + PX_VectorPushback(tk,&operand); + return PX_TRUE; + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_FLOAT_PTR: + { + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR; + operand._oft=psetmem->offset; + operand.pSet=PX_NULL; + PX_VectorPushback(tk,&operand); + return PX_TRUE; + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_STRING_PTR: + { + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR; + operand._oft=psetmem->offset; + operand.pSet=PX_NULL; + PX_VectorPushback(tk,&operand); + return PX_TRUE; + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_MEMORY_PTR: + { + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR; + operand._oft=psetmem->offset; + operand.pSet=PX_NULL; + PX_VectorPushback(tk,&operand); + return PX_TRUE; + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_STRUCT_PTR: + { + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR; + operand._oft=psetmem->offset; + operand.pSet=PX_ScriptParseGetStructByIndex(analysis,psetmem->defvar.setIndex); + *_outset=operand.pSet; + PX_VectorPushback(tk,&operand); + return PX_TRUE; + } + break; + default: + break; + } + + } + } + return PX_FALSE; + } + + + + if (atom.opclass==PX_SCRIPT_TRANSLATOR_OP_CLASS_VAR) + { + + for (i=0;iv_variablesStackTable.size;i++) + { + pvar=PX_VECTORAT(PX_SCRIPT_VARIABLES,&analysis->v_variablesStackTable,i); + if (PX_strequ(pvar->Mnemonic.buffer,atom.code.buffer)) + { + operand.region=PX_SCRIPT_VARIABLE_REGION_LOCAL; + goto _CONTINUE; + } + } + + for (i=0;iv_variablesGlobalTable.size;i++) + { + pvar=PX_VECTORAT(PX_SCRIPT_VARIABLES,&analysis->v_variablesGlobalTable,i); + if (PX_strequ(pvar->Mnemonic.buffer,atom.code.buffer)) + { + operand.region=PX_SCRIPT_VARIABLE_REGION_GLOBAL; + goto _CONTINUE; + } + } + return PX_FALSE; + + _CONTINUE: + switch (pvar->type) + { + case PX_SCRIPT_PARSER_VAR_TYPE_INT: + { + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT; + operand._oft=pvar->BeginIndex; + operand.pSet=PX_NULL; + PX_VectorPushback(tk,&operand); + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_FLOAT: + { + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT; + operand._oft=pvar->BeginIndex; + operand.pSet=PX_NULL; + PX_VectorPushback(tk,&operand); + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_STRING: + { + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_STRING; + operand._oft=pvar->BeginIndex; + operand.pSet=PX_NULL; + PX_VectorPushback(tk,&operand); + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_MEMORY: + { + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY; + operand._oft=pvar->BeginIndex; + operand.pSet=PX_NULL; + PX_VectorPushback(tk,&operand); + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_STRUCT: + { + *_outset=PX_ScriptParseGetStructByIndex(analysis,pvar->setIndex); + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_STRUCT; + operand._oft=pvar->BeginIndex; + operand.pSet=PX_ScriptParseGetStructByIndex(analysis,pvar->setIndex); + PX_VectorPushback(tk,&operand); + } + break; + + case PX_SCRIPT_PARSER_VAR_TYPE_INT_ARRAY: + { + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR_CONST; + operand._oft=pvar->BeginIndex; + operand.pSet=PX_NULL; + PX_VectorPushback(tk,&operand); + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_FLOAT_ARRAY: + { + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR_CONST; + operand._oft=pvar->BeginIndex; + operand.pSet=PX_NULL; + PX_VectorPushback(tk,&operand); + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_STRING_ARRAY: + { + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR_CONST; + operand._oft=pvar->BeginIndex; + operand.pSet=PX_NULL; + PX_VectorPushback(tk,&operand); + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_MEMORY_ARRAY: + { + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR_CONST; + operand._oft=pvar->BeginIndex; + operand.pSet=PX_NULL; + PX_VectorPushback(tk,&operand); + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_SET_ARRAY: + { + *_outset=PX_ScriptParseGetStructByIndex(analysis,pvar->setIndex); + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_SET_PTR_CONST; + operand._oft=pvar->BeginIndex; + operand.pSet=PX_ScriptParseGetStructByIndex(analysis,pvar->setIndex); + PX_VectorPushback(tk,&operand); + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_INT_PTR: + { + *_outset=PX_NULL; + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR; + operand._oft=pvar->BeginIndex; + operand.pSet=PX_NULL; + PX_VectorPushback(tk,&operand); + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_FLOAT_PTR: + { + *_outset=PX_NULL; + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR; + operand._oft=pvar->BeginIndex; + operand.pSet=PX_NULL; + PX_VectorPushback(tk,&operand); + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_STRING_PTR: + { + *_outset=PX_NULL; + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR; + operand._oft=pvar->BeginIndex; + operand.pSet=PX_NULL; + PX_VectorPushback(tk,&operand); + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_MEMORY_PTR: + { + *_outset=PX_NULL; + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR; + operand._oft=pvar->BeginIndex; + operand.pSet=PX_NULL; + PX_VectorPushback(tk,&operand); + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_STRUCT_PTR: + { + *_outset=PX_ScriptParseGetStructByIndex(analysis,pvar->setIndex); + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_STRUCT_PTR; + operand._oft=pvar->BeginIndex; + operand.pSet=PX_ScriptParseGetStructByIndex(analysis,pvar->setIndex); + PX_VectorPushback(tk,&operand); + } + break; + default: + return PX_FALSE; + } + + return PX_TRUE; + } + else if(atom.opclass==PX_SCRIPT_TRANSLATOR_OP_CLASS_CONST) + { + //Hexadecimal + if (atom.code.buffer[0]=='0'&&atom.code.buffer[1]=='X') + { + operand.region=PX_SCRIPT_VARIABLE_REGION_GLOBAL; + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + operand._int=PX_htoi(atom.code.buffer+2); + PX_VectorPushback(tk,&operand); + return PX_TRUE; + } + else + { + if (!PX_strIsNumeric(atom.code.buffer)) + { + return PX_FALSE; + } + operand.region=PX_SCRIPT_VARIABLE_REGION_GLOBAL; + if (PX_strIsFloat(atom.code.buffer)) + { + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST; + operand._float=PX_atof(atom.code.buffer); + PX_VectorPushback(tk,&operand); + return PX_TRUE; + } + else + { + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + operand._int=PX_atoi(atom.code.buffer); + PX_VectorPushback(tk,&operand); + return PX_TRUE; + } + } + + } + else if(atom.opclass==PX_SCRIPT_TRANSLATOR_OP_CLASS_CONTAINER) + { + operand.region=PX_SCRIPT_VARIABLE_REGION_GLOBAL; + if(atom.code.buffer[0]=='"') + { + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_STRING_CONST; + operand._contaniner=atom.code.buffer; + } + else if(atom.code.buffer[0]=='\'') + { + if (atom.code.buffer[2]!='\'') + { + return PX_FALSE; + } + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + operand._int=atom.code.buffer[1]; + } + else + { + operand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_CONST; + operand._contaniner=atom.code.buffer; + } + PX_VectorPushback(tk,&operand); + return PX_TRUE; + } + else + { + return PX_FALSE; + } +} +static px_bool PX_ScriptParseAST_PushOpcode(PX_SCRIPT_Analysis *analysis,px_vector *op,PX_SCRIPT_EXPR_STREAM atom) +{ + PX_SCRIPT_AST_OPCODE opc; + switch(atom.type) + { + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_ADD: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_ADD; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_INC: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_INC; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_POSITIVE: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_POSITIVE; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_SUB: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_SUB; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_DEC: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_DEC; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_NEGATIVE: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_NEGATIVE; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_MUL: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_MUL; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_DIV: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_DIV; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_AND: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_AND; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_OR: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_OR; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_NOT: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_NOT; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_XOR: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_XOR; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_INV: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_INV; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_MOD: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_MOD; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_SHL: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_SHL; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_SHR: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_SHR; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_DOT: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_DOT; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_COMMA: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_COMMA; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_MBRACKETBEGIN: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_IDX; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LBRACKETBEGIN: + return PX_TRUE; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LARGE: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_LARGE; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LARGEEUQ: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_LARGEEQU; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LESS: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_LESS; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LESSEQU: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_LESSEQU; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_UNEQU: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_UNEQU; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_EQU: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_EQU; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LGEQU: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_LGEQU; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LAND: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_LAND; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LOR: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_LOR; + break; + + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_PTR: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_PTR; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_ADR: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_ADR; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_OFT: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_OFT; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_INT: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_INT; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_FLOAT: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_FLOAT; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_STRING: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_STRING; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_MEMORY: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_MEMORY; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_STRLEN: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_STRLEN; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_MEMLEN: + opc.operandType=PX_SCRIPT_AST_OPCODE_TYPE_MEMLEN; + break; + default: + return PX_FALSE; + } + opc.level=atom.oplevel; + PX_VectorPushback(op,&opc); + return PX_TRUE; +} +static px_bool PX_ScriptParseIsOperandNumericType(PX_SCRIPT_AST_OPERAND ope) +{ + if (ope.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT||ope.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST) + { + return PX_TRUE; + } + if (ope.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT||ope.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST) + { + return PX_TRUE; + } + if (ope.operandType==PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX||ope.operandType==PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX) + { + return PX_TRUE; + } + return PX_FALSE; +} +static PX_SCRIPT_STRUCT *PX_ScriptParseGetStructInfo(PX_SCRIPT_Analysis *analysis,px_char *name) +{ + px_int i; + PX_SCRIPT_STRUCT *pset; + for (i=0;iv_struct.size;i++) + { + pset=PX_VECTORAT(PX_SCRIPT_STRUCT,&analysis->v_struct,i); + if (PX_strequ(name,pset->Name.buffer)) + { + return pset; + } + } + return PX_NULL; +} +static px_int PX_ScriptParseGetSetIndex(PX_SCRIPT_Analysis *analysis,px_char *name) +{ + px_int i; + PX_SCRIPT_STRUCT *pset; + for (i=0;iv_struct.size;i++) + { + pset=PX_VECTORAT(PX_SCRIPT_STRUCT,&analysis->v_struct,i); + if (PX_strequ(name,pset->Name.buffer)) + { + return i; + } + } + return -1; +} +static px_bool PX_ScriptParseIsCompareAbleOperand(PX_SCRIPT_AST_OPERAND operand1,PX_SCRIPT_AST_OPERAND operand2) +{ + if (!PX_ScriptParseIsOperandNumericType(operand1)||!PX_ScriptParseIsOperandNumericType(operand2)) + { + switch(operand1.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY: + { + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_CONST: + return PX_TRUE; + break; + default: + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING: + { + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_STRING: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_CONST: + return PX_TRUE; + break; + default: + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPERAND_TYPE_STRUCT: + return PX_FALSE; + default: + if (operand1.operandType!=operand2.operandType) + { + return PX_FALSE; + } + } + } + return PX_TRUE; +} +static px_bool PX_ScriptParseAST_MapTokenToR2(PX_SCRIPT_Analysis *analysis,PX_SCRIPT_AST_OPERAND operand,px_string *out) +{ + px_string fmrString; + + switch(operand.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_VOID: + PX_StringCat(out,"MOV R2,0\n"); + break; + ////////////////////////////////////////////////////////////////////////// + //R2 + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING: //string var + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY://memory var + case PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR: //int var[x] + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR://float var[x] + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR://string var[x] + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR://memory var[x] + case PX_SCRIPT_AST_OPERAND_TYPE_STRUCT_PTR://struct xx var[x] + { + PX_StringInitialize(analysis->mp,&fmrString); + + if(operand.region==PX_SCRIPT_VARIABLE_REGION_LOCAL) + { + PX_StringFormat1(&fmrString,"MOV R2,LOCAL[%1]\n",PX_STRINGFORMAT_INT(operand._oft)); + PX_StringCat(out,fmrString.buffer); + } + else if(operand.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + PX_StringFormat1(&fmrString,"MOV R2,GLOBAL[%1]\n",PX_STRINGFORMAT_INT(operand._oft)); + PX_StringCat(out,fmrString.buffer); + } + else if(operand.region==PX_SCRIPT_VARIABLE_REGION_POP) + { + PX_StringSet(&fmrString,"POP R2\n"); + PX_StringCat(out,fmrString.buffer); + PX_StringSet(&fmrString,"MOV R2,GLOBAL[R2]\n"); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFree(&fmrString); + return PX_FALSE; + } + + PX_StringFree(&fmrString); + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_STRUCT: + { + PX_StringInitialize(analysis->mp,&fmrString); + + if(operand.region==PX_SCRIPT_VARIABLE_REGION_LOCAL) + { + PX_StringFormat1(&fmrString,"MOV R2,BP\nSUB R2,%1\n",PX_STRINGFORMAT_INT(operand._oft)); + PX_StringCat(out,fmrString.buffer); + } + else if(operand.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + PX_StringFormat1(&fmrString,"MOV R2,%1\n",PX_STRINGFORMAT_INT(operand._oft)); + PX_StringCat(out,fmrString.buffer); + } + else if(operand.region==PX_SCRIPT_VARIABLE_REGION_POP) + { + PX_StringSet(&fmrString,"POP R2\n"); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFree(&fmrString); + return PX_FALSE; + } + + PX_StringFree(&fmrString); + return PX_TRUE; + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_SET_PTR_CONST: + { + PX_StringInitialize(analysis->mp,&fmrString); + + if(operand.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + PX_StringFormat1(&fmrString,"MOV R2,%1\n",PX_STRINGFORMAT_INT(operand._oft)); + PX_StringCat(out,fmrString.buffer); + } + else if(operand.region==PX_SCRIPT_VARIABLE_REGION_LOCAL) + { + PX_StringFormat1(&fmrString,"MOV R2,BP\nSUB R2,%1\n",PX_STRINGFORMAT_INT(operand._oft));// + PX_StringCat(out,fmrString.buffer); + } + else if(operand.region==PX_SCRIPT_VARIABLE_REGION_POP) + { + PX_StringSet(&fmrString,"POP R2\n"); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFree(&fmrString); + return PX_FALSE; + } + PX_StringFree(&fmrString); + + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + { + PX_StringInitialize(analysis->mp,&fmrString); + + if(operand.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + PX_StringFormat1(&fmrString,"MOV R2,%1\n",PX_STRINGFORMAT_INT(operand._int)); + PX_StringCat(out,fmrString.buffer); + } + else if(operand.region==PX_SCRIPT_VARIABLE_REGION_POP) + { + PX_StringSet(&fmrString,"POP R2\n"); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFree(&fmrString); + return PX_FALSE; + } + + PX_StringFree(&fmrString); + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST: + { + PX_StringInitialize(analysis->mp,&fmrString); + + if(operand.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + PX_StringFormat1(&fmrString,"MOV R2,%1.7\n",PX_STRINGFORMAT_FLOAT(operand._float)); + PX_StringCat(out,fmrString.buffer); + } + else if(operand.region==PX_SCRIPT_VARIABLE_REGION_POP) + { + PX_StringSet(&fmrString,"POP R2\n"); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFree(&fmrString); + return PX_FALSE; + } + PX_StringFree(&fmrString); + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_CONST: + { + ////////////////////////////////////////////////////////////////////////// + + PX_StringInitialize(analysis->mp,&fmrString); + + if(operand.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + PX_StringFormat1(&fmrString,"MOV R2,%1\n",PX_STRINGFORMAT_STRING(operand._contaniner)); + PX_StringCat(out,fmrString.buffer); + } + else if(operand.region==PX_SCRIPT_VARIABLE_REGION_POP) + { + PX_StringSet(&fmrString,"POP R2\n"); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFree(&fmrString); + return PX_FALSE; + } + PX_StringFree(&fmrString); + + //Check operand + ////////////////////////////////////////////////////////////////////////// + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + { + switch(operand.region) + { + case PX_SCRIPT_VARIABLE_REGION_LOCAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + if(operand.bAtomPopIndex) + { + PX_StringCat(out,"POP R3\n"); + PX_StringFormat1(&fmrString,"STRCHR R2,LOCAL[%1],R3\n",PX_STRINGFORMAT_INT(operand._oft)); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFormat2(&fmrString,"STRCHR R2,LOCAL[%1],%2\n",PX_STRINGFORMAT_INT(operand._oft),PX_STRINGFORMAT_INT(operand.bAtomPopIndex)); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_GLOBAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + if(operand.bAtomPopIndex) + { + PX_StringCat(out,"POP R3\n"); + PX_StringFormat1(&fmrString,"STRCHR R2,GLOBAL[%1],R3\n",PX_STRINGFORMAT_INT(operand._oft)); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFormat2(&fmrString,"STRCHR R2,GLOBAL[%1],%2\n",PX_STRINGFORMAT_INT(operand._oft),PX_STRINGFORMAT_INT(operand.bAtomPopIndex)); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_POP: + { + PX_StringInitialize(analysis->mp,&fmrString); + + if(operand.bAtomPopIndex) + { + PX_StringCat(out,"POP R1\n"); + PX_StringCat(out,"POP R3\n"); + PX_StringSet(&fmrString,"STRCHR R2,GLOBAL[R1],R3\n"); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringCat(out,"POP R1\n"); + PX_StringFormat1(&fmrString,"STRCHR R2,STRSET GLOBAL[R1],%1\n",PX_STRINGFORMAT_INT(operand._oft)); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + default: + return PX_FALSE; + } + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + { + + switch(operand.region) + { + case PX_SCRIPT_VARIABLE_REGION_LOCAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + if(operand.bAtomPopIndex) + { + PX_StringCat(out,"POP R3\n"); + PX_StringFormat1(&fmrString,"MEMBYTE R2,LOCAL[%1],R3\n",PX_STRINGFORMAT_INT(operand._oft)); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFormat2(&fmrString,"MEMBYTE R2,LOCAL[%1],%2\n",PX_STRINGFORMAT_INT(operand._oft),PX_STRINGFORMAT_INT(operand.bAtomPopIndex)); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_GLOBAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + if(operand.bAtomPopIndex) + { + PX_StringCat(out,"POP R3\n"); + PX_StringFormat1(&fmrString,"MEMBYTE R2,GLOBAL[%1],R3\n",PX_STRINGFORMAT_INT(operand._oft)); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFormat2(&fmrString,"MEMBYTE R2,GLOBAL[%1],%2\n",PX_STRINGFORMAT_INT(operand._oft),PX_STRINGFORMAT_INT(operand.bAtomPopIndex)); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_POP: + { + PX_StringInitialize(analysis->mp,&fmrString); + + if(operand.bAtomPopIndex) + { + PX_StringCat(out,"POP R1\n"); + PX_StringCat(out,"POP R3\n"); + PX_StringSet(&fmrString,"MEMBYTE R2,GLOBAL[R1],R3\n"); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringCat(out,"POP R1\n"); + PX_StringFormat1(&fmrString,"MEMBYTE R2,STRSET GLOBAL[R1],%1\n",PX_STRINGFORMAT_INT(operand._oft)); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + default: + return PX_FALSE; + } + + } + break; + + default: + return PX_FALSE; + } + return PX_TRUE; +} +static px_bool PX_ScriptParseAST_MapTokenToR1(PX_SCRIPT_Analysis *analysis,PX_SCRIPT_AST_OPERAND operand,px_string *out) +{ + px_string fmrString; + + switch(operand.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_VOID: + PX_StringCat(out,"MOV R1,0\n"); + break; + ////////////////////////////////////////////////////////////////////////// + //R2 + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING: //string var + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY://memory var + case PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR: //int var[x] + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR://float var[x] + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR://string var[x] + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR://memory var[x] + case PX_SCRIPT_AST_OPERAND_TYPE_STRUCT_PTR://struct xx var[x] + { + PX_StringInitialize(analysis->mp,&fmrString); + + if(operand.region==PX_SCRIPT_VARIABLE_REGION_LOCAL) + { + PX_StringFormat1(&fmrString,"MOV R1,LOCAL[%1]\n",PX_STRINGFORMAT_INT(operand._oft)); + PX_StringCat(out,fmrString.buffer); + } + else if(operand.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + PX_StringFormat1(&fmrString,"MOV R1,GLOBAL[%1]\n",PX_STRINGFORMAT_INT(operand._oft)); + PX_StringCat(out,fmrString.buffer); + } + else if(operand.region==PX_SCRIPT_VARIABLE_REGION_POP) + { + PX_StringSet(&fmrString,"POP R1\n"); + PX_StringCat(out,fmrString.buffer); + PX_StringSet(&fmrString,"MOV R1,GLOBAL[R1]\n"); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFree(&fmrString); + return PX_FALSE; + } + + PX_StringFree(&fmrString); + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_STRUCT: + { + PX_StringInitialize(analysis->mp,&fmrString); + + if(operand.region==PX_SCRIPT_VARIABLE_REGION_LOCAL) + { + PX_StringFormat1(&fmrString,"MOV R1,BP\nSUB R1,%1\n",PX_STRINGFORMAT_INT(operand._oft)); + PX_StringCat(out,fmrString.buffer); + } + else if(operand.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + PX_StringFormat1(&fmrString,"MOV R1,%1\n",PX_STRINGFORMAT_INT(operand._oft)); + PX_StringCat(out,fmrString.buffer); + } + else if(operand.region==PX_SCRIPT_VARIABLE_REGION_POP) + { + PX_StringSet(&fmrString,"POP R1\n"); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFree(&fmrString); + return PX_FALSE; + } + + PX_StringFree(&fmrString); + return PX_TRUE; + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_SET_PTR_CONST: + { + PX_StringInitialize(analysis->mp,&fmrString); + + if(operand.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + PX_StringFormat1(&fmrString,"MOV R1,%1\n",PX_STRINGFORMAT_INT(operand._oft)); + PX_StringCat(out,fmrString.buffer); + } + else if(operand.region==PX_SCRIPT_VARIABLE_REGION_LOCAL) + { + PX_StringFormat1(&fmrString,"MOV R1,BP\nSUB R1,%1\n",PX_STRINGFORMAT_INT(operand._oft));// + PX_StringCat(out,fmrString.buffer); + } + else if(operand.region==PX_SCRIPT_VARIABLE_REGION_POP) + { + PX_StringSet(&fmrString,"POP R1\n"); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFree(&fmrString); + return PX_FALSE; + } + PX_StringFree(&fmrString); + + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + { + PX_StringInitialize(analysis->mp,&fmrString); + + if(operand.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + PX_StringFormat1(&fmrString,"MOV R1,%1\n",PX_STRINGFORMAT_INT(operand._int)); + PX_StringCat(out,fmrString.buffer); + } + else if(operand.region==PX_SCRIPT_VARIABLE_REGION_POP) + { + PX_StringSet(&fmrString,"POP R1\n"); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFree(&fmrString); + return PX_FALSE; + } + + PX_StringFree(&fmrString); + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST: + { + PX_StringInitialize(analysis->mp,&fmrString); + + if(operand.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + PX_StringFormat1(&fmrString,"MOV R1,%1.7\n",PX_STRINGFORMAT_FLOAT(operand._float)); + PX_StringCat(out,fmrString.buffer); + } + else if(operand.region==PX_SCRIPT_VARIABLE_REGION_POP) + { + PX_StringSet(&fmrString,"POP R1\n"); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFree(&fmrString); + return PX_FALSE; + } + PX_StringFree(&fmrString); + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_CONST: + { + ////////////////////////////////////////////////////////////////////////// + + PX_StringInitialize(analysis->mp,&fmrString); + + if(operand.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + PX_StringFormat1(&fmrString,"MOV R1,%1\n",PX_STRINGFORMAT_STRING(operand._contaniner)); + PX_StringCat(out,fmrString.buffer); + } + else if(operand.region==PX_SCRIPT_VARIABLE_REGION_POP) + { + PX_StringSet(&fmrString,"POP R1\n"); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFree(&fmrString); + return PX_FALSE; + } + PX_StringFree(&fmrString); + + //Check operand + ////////////////////////////////////////////////////////////////////////// + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + { + switch(operand.region) + { + case PX_SCRIPT_VARIABLE_REGION_LOCAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + if(operand.bAtomPopIndex) + { + PX_StringCat(out,"POP R3\n"); + PX_StringFormat1(&fmrString,"STRCHR R1,LOCAL[%1],R3\n",PX_STRINGFORMAT_INT(operand._oft)); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFormat2(&fmrString,"STRCHR R1,LOCAL[%1],%2\n",PX_STRINGFORMAT_INT(operand._oft),PX_STRINGFORMAT_INT(operand.bAtomPopIndex)); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_GLOBAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + if(operand.bAtomPopIndex) + { + PX_StringCat(out,"POP R3\n"); + PX_StringFormat1(&fmrString,"STRCHR R1,GLOBAL[%1],R3\n",PX_STRINGFORMAT_INT(operand._oft)); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFormat2(&fmrString,"STRCHR R1,GLOBAL[%1],%2\n",PX_STRINGFORMAT_INT(operand._oft),PX_STRINGFORMAT_INT(operand.bAtomPopIndex)); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_POP: + { + PX_StringInitialize(analysis->mp,&fmrString); + + if(operand.bAtomPopIndex) + { + PX_StringCat(out,"POP R1\n"); + PX_StringCat(out,"POP R3\n"); + PX_StringSet(&fmrString,"STRCHR R1,GLOBAL[R1],R3\n"); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringCat(out,"POP R1\n"); + PX_StringFormat1(&fmrString,"STRCHR R1,STRSET GLOBAL[R1],%1\n",PX_STRINGFORMAT_INT(operand._oft)); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + default: + return PX_FALSE; + } + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + { + + switch(operand.region) + { + case PX_SCRIPT_VARIABLE_REGION_LOCAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + if(operand.bAtomPopIndex) + { + PX_StringCat(out,"POP R3\n"); + PX_StringFormat1(&fmrString,"MEMBYTE R1,LOCAL[%1],R3\n",PX_STRINGFORMAT_INT(operand._oft)); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFormat2(&fmrString,"MEMBYTE R1,LOCAL[%1],%2\n",PX_STRINGFORMAT_INT(operand._oft),PX_STRINGFORMAT_INT(operand.bAtomPopIndex)); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_GLOBAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + if(operand.bAtomPopIndex) + { + PX_StringCat(out,"POP R3\n"); + PX_StringFormat1(&fmrString,"MEMBYTE R1,GLOBAL[%1],R3\n",PX_STRINGFORMAT_INT(operand._oft)); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFormat2(&fmrString,"MEMBYTE R1,GLOBAL[%1],%2\n",PX_STRINGFORMAT_INT(operand._oft),PX_STRINGFORMAT_INT(operand.bAtomPopIndex)); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_POP: + { + PX_StringInitialize(analysis->mp,&fmrString); + + if(operand.bAtomPopIndex) + { + PX_StringCat(out,"POP R1\n"); + PX_StringCat(out,"POP R3\n"); + PX_StringSet(&fmrString,"MEMBYTE R1,GLOBAL[R1],R3\n"); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringCat(out,"POP R1\n"); + PX_StringFormat1(&fmrString,"MEMBYTE R1,STRSET GLOBAL[R1],%1\n",PX_STRINGFORMAT_INT(operand._oft)); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + default: + return PX_FALSE; + } + + } + break; + + default: + return PX_FALSE; + } + + return PX_TRUE; +} +static px_bool PX_ScriptParseLastInstr_DOT(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1,operand2,*pTop; + px_string fmrString; + if (tk->size<2) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-2)); + operand2=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + + PX_VectorPop(op); + + if (operand1.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_STRUCT) + { + return PX_FALSE; + } + + if (operand1.region==PX_SCRIPT_VARIABLE_REGION_POP) + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringFormat1(&fmrString,"POP R1\nADD R1,%1\nPUSH R1\n",PX_STRINGFORMAT_INT(operand2._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFree(&fmrString); + operand2._oft=0; + operand2.region=operand1.region; + } + else if (operand1.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + operand2._oft+=operand1._oft; + operand2.region=operand1.region; + } + else if (operand1.region==PX_SCRIPT_VARIABLE_REGION_LOCAL) + { + operand2._oft=operand1._oft-operand2._oft; + operand2.region=operand1.region; + } + else + { + return PX_FALSE; + } + + + PX_VectorPop(tk); + + pTop=(PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1); + *pTop=operand2; + return PX_TRUE; + +} +static px_bool PX_ScriptParseLastInstr_EQUAL(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operandLeft,operandRight,*pTop; + px_string fmrString; + if (tk->size<2) + { + return PX_FALSE; + } + operandLeft=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-2)); + operandRight=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + + PX_VectorPop(op); + PX_VectorPop(tk); + + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + + + switch(operandRight.operandType) + { + ////////////////////////////////////////////////////////////////////////// + //R2 + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + { + if (!PX_ScriptParseAST_MapTokenToR2(analysis,operandRight,out)) + { + return PX_FALSE; + } + + //Check operand1 + switch (operandLeft.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + { + if (operandLeft.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT) + { + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + else + { + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + PX_StringCat(out,"FLT R2\n"); + + } + switch(operandLeft.region) + { + case PX_SCRIPT_VARIABLE_REGION_LOCAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringFormat1(&fmrString,"MOV LOCAL[%1],R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH LOCAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_GLOBAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringFormat1(&fmrString,"MOV GLOBAL[%1],R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH GLOBAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_POP: + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringCat(out,"POP R1\n"); + PX_StringSet(&fmrString,"MOV GLOBAL[R1],R2\n"); + PX_StringCat(out,fmrString.buffer); + PX_StringSet(&fmrString,"PUSH GLOBAL[R1]\n"); + PX_StringCat(out,fmrString.buffer); + PX_StringFree(&fmrString); + } + break; + default: + return PX_FALSE; + } + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + { + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + switch(operandLeft.region) + { + case PX_SCRIPT_VARIABLE_REGION_LOCAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + if(operandLeft.bAtomPopIndex) + { + PX_StringCat(out,"POP R3\n"); + PX_StringFormat1(&fmrString,"STRSET LOCAL[%1],R3,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH LOCAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFormat2(&fmrString,"STRSET LOCAL[%1],%2,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft),PX_STRINGFORMAT_INT(operandLeft.AtomIndex)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH LOCAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_GLOBAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + if(operandLeft.bAtomPopIndex) + { + PX_StringCat(out,"POP R3\n"); + PX_StringFormat1(&fmrString,"STRSET GLOBAL[%1],R3,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH GLOBAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFormat2(&fmrString,"STRSET GLOBAL[%1],%2,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft),PX_STRINGFORMAT_INT(operandLeft.AtomIndex)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH GLOBAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_POP: + { + PX_StringInitialize(analysis->mp,&fmrString); + + if(operandLeft.bAtomPopIndex) + { + PX_StringCat(out,"POP R1\n"); + PX_StringCat(out,"POP R3\n"); + PX_StringSet(&fmrString,"STRSET GLOBAL[R1],R3,R2\n"); + PX_StringCat(out,fmrString.buffer); + PX_StringSet(&fmrString,"PUSH GLOBAL[R1]\n"); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringCat(out,"POP R1\n"); + PX_StringFormat1(&fmrString,"STRSET GLOBAL[R1],%1,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringSet(&fmrString,"PUSH GLOBAL[R1]\n"); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + default: + return PX_FALSE; + } + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + { + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + switch(operandLeft.region) + { + case PX_SCRIPT_VARIABLE_REGION_LOCAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + if(operandLeft.bAtomPopIndex) + { + PX_StringCat(out,"POP R3\n"); + PX_StringFormat1(&fmrString,"MEMSET LOCAL[%1],R3,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH LOCAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFormat2(&fmrString,"MEMSET LOCAL[%1],%2,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft),PX_STRINGFORMAT_INT(operandLeft.AtomIndex)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH LOCAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_GLOBAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + if(operandLeft.bAtomPopIndex) + { + PX_StringCat(out,"POP R3\n"); + PX_StringFormat1(&fmrString,"MEMSET GLOBAL[%1],R3,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH GLOBAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFormat2(&fmrString,"MEMSET GLOBAL[%1],%2,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft),PX_STRINGFORMAT_INT(operandLeft.AtomIndex)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH GLOBAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_POP: + { + PX_StringInitialize(analysis->mp,&fmrString); + + if(operandLeft.bAtomPopIndex) + { + PX_StringCat(out,"POP R1\n"); + PX_StringCat(out,"POP R3\n"); + PX_StringSet(&fmrString,"MEMSET GLOBAL[R1],R3,R2\n"); + PX_StringCat(out,fmrString.buffer); + PX_StringSet(&fmrString,"PUSH GLOBAL[R1]\n"); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringCat(out,"POP R1\n"); + PX_StringFormat1(&fmrString,"MEMSET GLOBAL[R1],%1,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringSet(&fmrString,"PUSH GLOBAL[R1]\n"); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + default: + return PX_FALSE; + } + } + break; + default: + return PX_FALSE; + + } + + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT: + { + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operandRight,out)) return PX_FALSE; + + //Check operand1 + switch (operandLeft.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + { + if (operandLeft.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT) + { + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + else + { + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + + if(operandLeft.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT) + PX_StringCat(out,"INT R2\n"); + + switch(operandLeft.region) + { + case PX_SCRIPT_VARIABLE_REGION_LOCAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringFormat1(&fmrString,"MOV LOCAL[%1],R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH LOCAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_GLOBAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringFormat1(&fmrString,"MOV GLOBAL[%1],R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH GLOBAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_POP: + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringCat(out,"POP R1\n"); + PX_StringSet(&fmrString,"MOV GLOBAL[R1],R2\n"); + PX_StringCat(out,fmrString.buffer); + PX_StringSet(&fmrString,"PUSH GLOBAL[R1]\n"); + PX_StringCat(out,fmrString.buffer); + PX_StringFree(&fmrString); + } + break; + default: + return PX_FALSE; + } + } + break; + default: + return PX_FALSE; + } + + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_STRING: //string var + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY://memory var + case PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR: //int var[x] + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR://float var[x] + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR://string var[x] + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR://memory var[x] + case PX_SCRIPT_AST_OPERAND_TYPE_STRUCT_PTR://struct xx var[x] + { + if (operandLeft.operandType==PX_SCRIPT_AST_OPERAND_TYPE_STRING) + { + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_STRING_CONST; + } + else if (operandLeft.operandType==PX_SCRIPT_AST_OPERAND_TYPE_MEMORY) + { + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_CONST; + } + else if (operandLeft.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR) + { + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR_CONST; + } + else if (operandLeft.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR) + { + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR_CONST; + } + else if (operandLeft.operandType==PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR) + { + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR_CONST; + } + else if (operandLeft.operandType==PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR) + { + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR_CONST; + } + else + { + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_SET_PTR_CONST; + } + + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + pTop->pSet=operandLeft.pSet; + + if (operandLeft.operandType!=operandRight.operandType) + { + return PX_FALSE; + } + + PX_StringInitialize(analysis->mp,&fmrString); + + if(operandRight.region==PX_SCRIPT_VARIABLE_REGION_LOCAL) + { + PX_StringFormat1(&fmrString,"MOV R2,LOCAL[%1]\n",PX_STRINGFORMAT_INT(operandRight._oft)); + PX_StringCat(out,fmrString.buffer); + } + else if(operandRight.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + PX_StringFormat1(&fmrString,"MOV R2,GLOBAL[%1]\n",PX_STRINGFORMAT_INT(operandRight._oft)); + PX_StringCat(out,fmrString.buffer); + } + else if(operandRight.region==PX_SCRIPT_VARIABLE_REGION_POP) + { + PX_StringSet(&fmrString,"POP R2\n"); + PX_StringCat(out,fmrString.buffer); + PX_StringSet(&fmrString,"MOV R2,GLOBAL[R2]\n"); + PX_StringCat(out,fmrString.buffer); + } + else + { + return PX_FALSE; + } + + PX_StringFree(&fmrString); + + switch(operandLeft.region) + { + case PX_SCRIPT_VARIABLE_REGION_LOCAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringFormat1(&fmrString,"MOV LOCAL[%1],R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH LOCAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_GLOBAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringFormat1(&fmrString,"MOV GLOBAL[%1],R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH GLOBAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_POP: + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringCat(out,"POP R1\n"); + PX_StringSet(&fmrString,"MOV GLOBAL[R1],R2\n"); + PX_StringCat(out,fmrString.buffer); + PX_StringSet(&fmrString,"PUSH GLOBAL[R1]\n"); + PX_StringCat(out,fmrString.buffer); + PX_StringFree(&fmrString); + } + break; + default: + PX_ScriptTranslatorError(&analysis->lexer,"Invalid left-value."); + return PX_FALSE; + } + + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_STRUCT: + { + if (operandLeft.operandType!=operandRight.operandType) + { + return PX_FALSE; + } + if (operandLeft.pSet!=operandRight.pSet) + { + return PX_FALSE; + } + PX_StringInitialize(analysis->mp,&fmrString); + + if (!PX_ScriptParseAST_MapTokenToR2(analysis,operandRight,out)) + { + return PX_FALSE; + } + if (!PX_ScriptParseAST_MapTokenToR1(analysis,operandLeft,out)) + { + return PX_FALSE; + } + + + PX_StringFormat1(&fmrString,"DATACPY R1,R2,%1\n",PX_STRINGFORMAT_INT(operandLeft.pSet->size)); + PX_StringCat(out,fmrString.buffer); + PX_StringSet(&fmrString,"PUSH R1\n"); + PX_StringCat(out,fmrString.buffer); + PX_StringFree(&fmrString); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_STRUCT; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + pTop->pSet=operandLeft.pSet; + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_SET_PTR_CONST: + { + if (operandRight.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR_CONST&&operandLeft.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR) + { + return PX_FALSE; + } + if (operandRight.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR_CONST&&operandLeft.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR) + { + return PX_FALSE; + } + if (operandRight.operandType==PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR_CONST&&operandLeft.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR) + { + return PX_FALSE; + } + if (operandRight.operandType==PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR_CONST&&operandLeft.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR) + { + return PX_FALSE; + } + if (operandRight.operandType==PX_SCRIPT_AST_OPERAND_TYPE_SET_PTR_CONST&&operandLeft.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_STRUCT_PTR) + { + return PX_FALSE; + } + + + PX_StringInitialize(analysis->mp,&fmrString); + + if(operandRight.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + PX_StringFormat1(&fmrString,"MOV R2,%1\n",PX_STRINGFORMAT_INT(operandRight._oft)); + PX_StringCat(out,fmrString.buffer); + } + else if(operandRight.region==PX_SCRIPT_VARIABLE_REGION_LOCAL) + { + PX_StringFormat1(&fmrString,"MOV R2,BP\nSUB R2,%1\n",PX_STRINGFORMAT_INT(operandRight._oft));// + PX_StringCat(out,fmrString.buffer); + } + else if(operandRight.region==PX_SCRIPT_VARIABLE_REGION_POP) + { + PX_StringSet(&fmrString,"POP R2\n"); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFree(&fmrString); + return PX_FALSE; + } + + switch(operandLeft.region) + { + case PX_SCRIPT_VARIABLE_REGION_LOCAL: + { + PX_StringFormat1(&fmrString,"MOV LOCAL[%1],R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH LOCAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + break; + case PX_SCRIPT_VARIABLE_REGION_GLOBAL: + { + PX_StringFormat1(&fmrString,"MOV GLOBAL[%1],R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH GLOBAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + break; + case PX_SCRIPT_VARIABLE_REGION_POP: + { + PX_StringCat(out,"POP R1\n"); + PX_StringSet(&fmrString,"MOV GLOBAL[R1],R2\n"); + PX_StringCat(out,fmrString.buffer); + PX_StringSet(&fmrString,"PUSH GLOBAL[R1]\n"); + PX_StringCat(out,fmrString.buffer); + } + break; + default: + { + PX_ScriptTranslatorError(&analysis->lexer,"Invalid left-value."); + PX_StringFree(&fmrString); + return PX_FALSE; + } + } + PX_StringFree(&fmrString); + pTop->operandType=operandRight.operandType; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + pTop->pSet=operandLeft.pSet; + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + { + if (!PX_ScriptParseAST_MapTokenToR2(analysis,operandRight,out)) + { + return PX_FALSE; + } + + //Check operand1 + switch (operandLeft.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + { + if (operandLeft.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT) + { + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + PX_StringCat(out,"FLT R2\n"); + } + else + { + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + + switch(operandLeft.region) + { + case PX_SCRIPT_VARIABLE_REGION_LOCAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringFormat1(&fmrString,"MOV LOCAL[%1],R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH LOCAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_GLOBAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringFormat1(&fmrString,"MOV GLOBAL[%1],R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH GLOBAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_POP: + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringCat(out,"POP R1\n"); + PX_StringSet(&fmrString,"MOV GLOBAL[R1],R2\n"); + PX_StringCat(out,fmrString.buffer); + PX_StringSet(&fmrString,"PUSH GLOBAL[R1]\n"); + PX_StringCat(out,fmrString.buffer); + PX_StringFree(&fmrString); + } + break; + default: + return PX_FALSE; + } + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + { + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + switch(operandLeft.region) + { + case PX_SCRIPT_VARIABLE_REGION_LOCAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + if(operandLeft.bAtomPopIndex) + { + PX_StringCat(out,"POP R3\n"); + PX_StringFormat1(&fmrString,"STRSET LOCAL[%1],R3,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH LOCAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFormat2(&fmrString,"STRSET LOCAL[%1],%2,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft),PX_STRINGFORMAT_INT(operandLeft.AtomIndex)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH LOCAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_GLOBAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + if(operandLeft.bAtomPopIndex) + { + PX_StringCat(out,"POP R3\n"); + PX_StringFormat1(&fmrString,"STRSET GLOBAL[%1],R3,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH GLOBAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFormat2(&fmrString,"STRSET GLOBAL[%1],%2,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft),PX_STRINGFORMAT_INT(operandLeft.AtomIndex)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH GLOBAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_POP: + { + PX_StringInitialize(analysis->mp,&fmrString); + + if(operandLeft.bAtomPopIndex) + { + PX_StringCat(out,"POP R1\n"); + PX_StringCat(out,"POP R3\n"); + PX_StringSet(&fmrString,"STRSET GLOBAL[R1],R3,R2\n"); + PX_StringCat(out,fmrString.buffer); + PX_StringSet(&fmrString,"PUSH GLOBAL[R1]\n"); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringCat(out,"POP R1\n"); + PX_StringFormat1(&fmrString,"STRSET GLOBAL[R1],%1,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringSet(&fmrString,"PUSH GLOBAL[R1]\n"); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + default: + return PX_FALSE; + } + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + { + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + switch(operandLeft.region) + { + case PX_SCRIPT_VARIABLE_REGION_LOCAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + if(operandLeft.bAtomPopIndex) + { + PX_StringCat(out,"POP R3\n"); + PX_StringFormat1(&fmrString,"MEMSET LOCAL[%1],R3,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH LOCAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFormat2(&fmrString,"MEMSET LOCAL[%1],%2,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft),PX_STRINGFORMAT_INT(operandLeft.AtomIndex)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH LOCAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_GLOBAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + if(operandLeft.bAtomPopIndex) + { + PX_StringCat(out,"POP R3\n"); + PX_StringFormat1(&fmrString,"MEMSET GLOBAL[%1],R3,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH GLOBAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFormat2(&fmrString,"MEMSET GLOBAL[%1],%2,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft),PX_STRINGFORMAT_INT(operandLeft.AtomIndex)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH GLOBAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_POP: + { + PX_StringInitialize(analysis->mp,&fmrString); + + if(operandLeft.bAtomPopIndex) + { + PX_StringCat(out,"POP R1\n"); + PX_StringCat(out,"POP R3\n"); + PX_StringSet(&fmrString,"MEMSET GLOBAL[R1],R3,R2\n"); + PX_StringCat(out,fmrString.buffer); + PX_StringSet(&fmrString,"PUSH GLOBAL[R1]\n"); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringCat(out,"POP R1\n"); + PX_StringFormat1(&fmrString,"MEMSET GLOBAL[R1],%1,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringSet(&fmrString,"PUSH GLOBAL[R1]\n"); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + default: + return PX_FALSE; + } + } + break; + default: + return PX_FALSE; + + } + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST: + { + if (!PX_ScriptParseAST_MapTokenToR2(analysis,operandRight,out)) + { + return PX_FALSE; + } + + //Check operand1 + switch (operandLeft.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + { + if (operandLeft.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT) + { + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + else + { + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + + if(operandLeft.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT) + PX_StringCat(out,"INT R2\n"); + + switch(operandLeft.region) + { + case PX_SCRIPT_VARIABLE_REGION_LOCAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringFormat1(&fmrString,"MOV LOCAL[%1],R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH LOCAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_GLOBAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringFormat1(&fmrString,"MOV GLOBAL[%1],R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH GLOBAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_POP: + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringCat(out,"POP R1\n"); + PX_StringSet(&fmrString,"MOV GLOBAL[R1],R2\n"); + PX_StringCat(out,fmrString.buffer); + PX_StringSet(&fmrString,"PUSH GLOBAL[R1]\n"); + PX_StringCat(out,fmrString.buffer); + PX_StringFree(&fmrString); + } + break; + default: + return PX_FALSE; + } + } + break; + default: + return PX_FALSE; + } + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_CONST: + { + pTop->operandType=operandRight.operandType; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + ////////////////////////////////////////////////////////////////////////// + if (operandRight.operandType==PX_SCRIPT_AST_OPERAND_TYPE_STRING_CONST&&operandLeft.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_STRING) + { + return PX_FALSE; + } + + if (operandRight.operandType==PX_SCRIPT_AST_OPERAND_TYPE_MEMORY&&operandLeft.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY) + { + return PX_FALSE; + } + + PX_StringInitialize(analysis->mp,&fmrString); + + if(operandRight.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + PX_StringFormat1(&fmrString,"MOV R2,%1\n",PX_STRINGFORMAT_STRING(operandRight._contaniner)); + PX_StringCat(out,fmrString.buffer); + } + else if(operandRight.region==PX_SCRIPT_VARIABLE_REGION_POP) + { + PX_StringSet(&fmrString,"POP R2\n"); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFree(&fmrString); + return PX_FALSE; + } + PX_StringFree(&fmrString); + + //Check operand1 + + switch(operandLeft.region) + { + case PX_SCRIPT_VARIABLE_REGION_LOCAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringFormat1(&fmrString,"MOV LOCAL[%1],R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH LOCAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_GLOBAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringFormat1(&fmrString,"MOV GLOBAL[%1],R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH GLOBAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_POP: + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringCat(out,"POP R1\n"); + PX_StringSet(&fmrString,"MOV GLOBAL[R1],R2\n"); + PX_StringCat(out,fmrString.buffer); + PX_StringSet(&fmrString,"PUSH GLOBAL[R1]\n"); + PX_StringCat(out,fmrString.buffer); + PX_StringFree(&fmrString); + } + break; + default: + return PX_FALSE; + } + ////////////////////////////////////////////////////////////////////////// + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + { + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + if (operandLeft.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_INT&&operandLeft.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX&&operandLeft.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX) + { + return PX_FALSE; + } + + if (!PX_ScriptParseAST_MapTokenToR2(analysis,operandRight,out)) + { + return PX_FALSE; + } + + if (operandLeft.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT) + { + ////////////////////////////////////////////////////////////////////////// + switch(operandLeft.region) + { + case PX_SCRIPT_VARIABLE_REGION_LOCAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringFormat1(&fmrString,"MOV LOCAL[%1],R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH LOCAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_GLOBAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringFormat1(&fmrString,"MOV GLOBAL[%1],R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH GLOBAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_POP: + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringCat(out,"POP R1\n"); + PX_StringSet(&fmrString,"MOV GLOBAL[R1],R2\n"); + PX_StringCat(out,fmrString.buffer); + PX_StringSet(&fmrString,"PUSH GLOBAL[R1]\n"); + PX_StringCat(out,fmrString.buffer); + PX_StringFree(&fmrString); + } + break; + default: + return PX_FALSE; + } + ////////////////////////////////////////////////////////////////////////// + } + else if(operandLeft.operandType==PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX) + { + switch(operandLeft.region) + { + case PX_SCRIPT_VARIABLE_REGION_LOCAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + if(operandLeft.bAtomPopIndex) + { + PX_StringCat(out,"POP R3\n"); + PX_StringFormat1(&fmrString,"STRSET LOCAL[%1],R3,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH LOCAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFormat2(&fmrString,"STRSET LOCAL[%1],%2,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft),PX_STRINGFORMAT_INT(operandLeft.bAtomPopIndex)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH LOCAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_GLOBAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + if(operandLeft.bAtomPopIndex) + { + PX_StringCat(out,"POP R3\n"); + PX_StringFormat1(&fmrString,"STRSET GLOBAL[%1],R3,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH GLOBAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFormat2(&fmrString,"STRSET GLOBAL[%1],%2,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft),PX_STRINGFORMAT_INT(operandLeft.bAtomPopIndex)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH GLOBAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_POP: + { + PX_StringInitialize(analysis->mp,&fmrString); + + if(operandLeft.bAtomPopIndex) + { + PX_StringCat(out,"POP R1\n"); + PX_StringCat(out,"POP R3\n"); + PX_StringSet(&fmrString,"STRSET GLOBAL[R1],R3,R2\n"); + PX_StringCat(out,fmrString.buffer); + PX_StringSet(&fmrString,"PUSH GLOBAL[R1]\n"); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringCat(out,"POP R1\n"); + PX_StringFormat1(&fmrString,"STRSET GLOBAL[R1],%1,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringSet(&fmrString,"PUSH GLOBAL[R1]\n"); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + default: + return PX_FALSE; + } + } + else + { + switch(operandLeft.region) + { + case PX_SCRIPT_VARIABLE_REGION_LOCAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + if(operandLeft.bAtomPopIndex) + { + PX_StringCat(out,"POP R3\n"); + PX_StringFormat1(&fmrString,"MEMSET LOCAL[%1],R3,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH LOCAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFormat2(&fmrString,"MEMSET LOCAL[%1],%2,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft),PX_STRINGFORMAT_INT(operandLeft.bAtomPopIndex)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH LOCAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_GLOBAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + if(operandLeft.bAtomPopIndex) + { + PX_StringCat(out,"POP R3\n"); + PX_StringFormat1(&fmrString,"MEMSET GLOBAL[%1],R3,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH GLOBAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFormat2(&fmrString,"MEMSET GLOBAL[%1],%2,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft),PX_STRINGFORMAT_INT(operandLeft.bAtomPopIndex)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH GLOBAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_POP: + { + PX_StringInitialize(analysis->mp,&fmrString); + + if(operandLeft.bAtomPopIndex) + { + PX_StringCat(out,"POP R1\n"); + PX_StringCat(out,"POP R3\n"); + PX_StringSet(&fmrString,"MEMSET GLOBAL[R1],R3,R2\n"); + PX_StringCat(out,fmrString.buffer); + PX_StringSet(&fmrString,"PUSH GLOBAL[R1]\n"); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringCat(out,"POP R1\n"); + PX_StringFormat1(&fmrString,"MEMSET GLOBAL[R1],%1,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringSet(&fmrString,"PUSH GLOBAL[R1]\n"); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + default: + return PX_FALSE; + } + } + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + { + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + if (operandLeft.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_INT&&operandLeft.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX&&operandLeft.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX) + { + return PX_FALSE; + } + + if (!PX_ScriptParseAST_MapTokenToR2(analysis,operandRight,out)) + { + return PX_FALSE; + } + + if (operandLeft.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT) + { + ////////////////////////////////////////////////////////////////////////// + switch(operandLeft.region) + { + case PX_SCRIPT_VARIABLE_REGION_LOCAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringFormat1(&fmrString,"MOV LOCAL[%1],R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH LOCAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_GLOBAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringFormat1(&fmrString,"MOV GLOBAL[%1],R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH GLOBAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_POP: + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringCat(out,"POP R1\n"); + PX_StringSet(&fmrString,"MOV GLOBAL[R1],R2\n"); + PX_StringCat(out,fmrString.buffer); + PX_StringSet(&fmrString,"PUSH GLOBAL[R1]\n"); + PX_StringCat(out,fmrString.buffer); + PX_StringFree(&fmrString); + } + break; + default: + return PX_FALSE; + } + ////////////////////////////////////////////////////////////////////////// + } + else if(operandLeft.operandType==PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX) + { + switch(operandLeft.region) + { + case PX_SCRIPT_VARIABLE_REGION_LOCAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + if(operandLeft.bAtomPopIndex) + { + PX_StringCat(out,"POP R3\n"); + PX_StringFormat1(&fmrString,"MEMSET LOCAL[%1],R3,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH LOCAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFormat2(&fmrString,"MEMSET LOCAL[%1],%2,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft),PX_STRINGFORMAT_INT(operandLeft.bAtomPopIndex)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH LOCAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_GLOBAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + if(operandLeft.bAtomPopIndex) + { + PX_StringCat(out,"POP R3\n"); + PX_StringFormat1(&fmrString,"MEMSET GLOBAL[%1],R3,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH GLOBAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFormat2(&fmrString,"MEMSET GLOBAL[%1],%2,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft),PX_STRINGFORMAT_INT(operandLeft.bAtomPopIndex)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH GLOBAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_POP: + { + PX_StringInitialize(analysis->mp,&fmrString); + + if(operandLeft.bAtomPopIndex) + { + PX_StringCat(out,"POP R1\n"); + PX_StringCat(out,"POP R3\n"); + PX_StringSet(&fmrString,"MEMSET GLOBAL[R1],R3,R2\n"); + PX_StringCat(out,fmrString.buffer); + PX_StringSet(&fmrString,"PUSH GLOBAL[R1]\n"); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringCat(out,"POP R1\n"); + PX_StringFormat1(&fmrString,"MEMSET GLOBAL[R1],%1,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringSet(&fmrString,"PUSH GLOBAL[R1]\n"); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + default: + return PX_FALSE; + } + } + else + { + switch(operandLeft.region) + { + case PX_SCRIPT_VARIABLE_REGION_LOCAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + if(operandLeft.bAtomPopIndex) + { + PX_StringCat(out,"POP R3\n"); + PX_StringFormat1(&fmrString,"STRSET LOCAL[%1],R3,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH LOCAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFormat2(&fmrString,"STRSET LOCAL[%1],%2,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft),PX_STRINGFORMAT_INT(operandLeft.bAtomPopIndex)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH LOCAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_GLOBAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + if(operandLeft.bAtomPopIndex) + { + PX_StringCat(out,"POP R3\n"); + PX_StringFormat1(&fmrString,"STRSET GLOBAL[%1],R3,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH GLOBAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFormat2(&fmrString,"STRSET GLOBAL[%1],%2,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft),PX_STRINGFORMAT_INT(operandLeft.bAtomPopIndex)); + PX_StringCat(out,fmrString.buffer); + PX_StringFormat1(&fmrString,"PUSH GLOBAL[%1]\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_POP: + { + PX_StringInitialize(analysis->mp,&fmrString); + + if(operandLeft.bAtomPopIndex) + { + PX_StringCat(out,"POP R1\n"); + PX_StringCat(out,"POP R3\n"); + PX_StringSet(&fmrString,"STRSET GLOBAL[R1],R3,R2\n"); + PX_StringCat(out,fmrString.buffer); + PX_StringSet(&fmrString,"PUSH GLOBAL[R1]\n"); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringCat(out,"POP R1\n"); + PX_StringFormat1(&fmrString,"MEMSET GLOBAL[R1],%1,R2\n",PX_STRINGFORMAT_INT(operandLeft._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringSet(&fmrString,"PUSH GLOBAL[R1]\n"); + PX_StringCat(out,fmrString.buffer); + } + PX_StringFree(&fmrString); + } + break; + default: + return PX_FALSE; + } + } + + } + break; + + default: + return PX_FALSE; + } + + return PX_TRUE; +} +static px_bool PX_ScriptParseLastInstr_IDX(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1,operand2,resOperand; + px_string fmrString; + if (tk->size<2) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-2)); + operand2=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + + PX_VectorPop(op); + PX_VectorPop(tk); + PX_VectorPop(tk); + + PX_StringInitialize(analysis->mp,&fmrString); + + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + { + if (!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) + { + return PX_FALSE; + } + } + break; + default: + { + PX_StringFree(&fmrString); + return PX_FALSE; + } + } + + switch (operand1.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR: + case PX_SCRIPT_AST_OPERAND_TYPE_STRUCT_PTR: + { + if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR) + { + resOperand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT; + resOperand.pSet=PX_NULL; + } + if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR) + { + resOperand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT; + resOperand.pSet=PX_NULL; + } + if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR) + { + resOperand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_STRING; + resOperand.pSet=PX_NULL; + } + if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR) + { + resOperand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY; + resOperand.pSet=PX_NULL; + } + if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_STRUCT_PTR) + { + resOperand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_STRUCT; + resOperand.pSet=operand1.pSet; + PX_StringFormat1(&fmrString,"MUL R2,%1\n",PX_STRINGFORMAT_INT(operand1.pSet->size)); + PX_StringCat(out,fmrString.buffer); + } + + if (operand1.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + PX_StringFormat1(&fmrString,"ADD R2,GLOBAL[%1]\n",PX_STRINGFORMAT_INT(operand1._oft)); + PX_StringCat(out,fmrString.buffer); + } + else if(operand1.region==PX_SCRIPT_VARIABLE_REGION_LOCAL) + { + PX_StringFormat1(&fmrString,"ADD R2,LOCAL[%1]\n",PX_STRINGFORMAT_INT(operand1._oft)); + PX_StringCat(out,fmrString.buffer); + } + else if(operand1.region==PX_SCRIPT_VARIABLE_REGION_POP) + { + PX_StringCat(out,"POP R3\n"); + PX_StringSet(&fmrString,"ADD R2,GLOBAL[R3]\n"); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFree(&fmrString); + return PX_FALSE; + } + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_SET_PTR_CONST: + { + if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR_CONST) + { + resOperand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT; + resOperand.pSet=PX_NULL; + } + if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR_CONST) + { + resOperand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT; + resOperand.pSet=PX_NULL; + } + if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR_CONST) + { + resOperand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_STRING; + resOperand.pSet=PX_NULL; + } + if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR_CONST) + { + resOperand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY; + resOperand.pSet=PX_NULL; + } + if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_SET_PTR_CONST) + { + resOperand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_STRUCT; + resOperand.pSet=operand1.pSet; + PX_StringFormat1(&fmrString,"MUL R2,%1\n",PX_STRINGFORMAT_INT(operand1.pSet->size)); + PX_StringCat(out,fmrString.buffer); + + } + + if (operand1.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + PX_StringFormat1(&fmrString,"ADD R2,%1\n",PX_STRINGFORMAT_INT(operand1._oft)); + PX_StringCat(out,fmrString.buffer); + } + else if(operand1.region==PX_SCRIPT_VARIABLE_REGION_LOCAL) + { + PX_StringFormat1(&fmrString,"SUB R2,%1\nADD R2,BP\n",PX_STRINGFORMAT_INT(operand1._oft));// + PX_StringCat(out,fmrString.buffer); + } + else if(operand1.region==PX_SCRIPT_VARIABLE_REGION_POP) + { + PX_StringCat(out,"POP R3\n"); + PX_StringSet(&fmrString,"ADD R2,GLOBAL[R3]\n"); + PX_StringCat(out,fmrString.buffer); + } + else + { + PX_StringFree(&fmrString); + return PX_FALSE; + } + + } + break; + case PX_SCRIPT_AST_OPERAND_TYPE_STRING: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY: + { + resOperand.bAtomPopIndex=PX_TRUE; + + if(operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_MEMORY) + resOperand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX; + else + resOperand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX; + + if (operand1.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + PX_StringCat(out,"PUSH R2\n"); + PX_StringFormat1(&fmrString,"MOV R2,%1\n",PX_STRINGFORMAT_INT(operand1._oft)); + PX_StringCat(out,fmrString.buffer); + } + else if(operand1.region==PX_SCRIPT_VARIABLE_REGION_LOCAL) + { + PX_StringCat(out,"PUSH R2\n"); + PX_StringFormat1(&fmrString,"MOV R2,BP\nSUB R2,%1\n",PX_STRINGFORMAT_INT(operand1._oft));// + PX_StringCat(out,fmrString.buffer); + } + else if(operand1.region==PX_SCRIPT_VARIABLE_REGION_POP) + { + PX_StringCat(out,"MOV R1,R2\n"); + PX_StringCat(out,"POP R2\n"); + PX_StringCat(out,"PUSH R1\n"); + } + else + { + PX_StringFree(&fmrString); + return PX_FALSE; + } + } + break; + default: + { + PX_StringFree(&fmrString); + return PX_FALSE; + } + } + PX_StringCat(out,"PUSH R2\n"); + + resOperand.region=PX_SCRIPT_VARIABLE_REGION_POP; + resOperand._int=0; + resOperand._oft=0; + PX_VectorPushback(tk,&resOperand); + + PX_StringFree(&fmrString); + return PX_TRUE; +} +static px_bool PX_ScriptParseLastInstr_OFT(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1,operand2,*pTop; + px_string fmrString; + if (tk->size<2) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-2)); + operand2=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + + PX_VectorPop(op); + PX_VectorPop(tk); + + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringFormat1(&fmrString,"ADD R1,%1\nPUSH R1\n",PX_STRINGFORMAT_INT(operand2._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFree(&fmrString); + + pTop=(PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1); + *pTop=operand2; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + return PX_TRUE; +} +static px_bool PX_ScriptParseLastInstr_PTR(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1,resOperand; + px_string fmrString; + if (tk->size<1) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + + PX_VectorPop(op); + PX_VectorPop(tk); + + PX_StringInitialize(analysis->mp,&fmrString); + + if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR) + { + resOperand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT; + resOperand.pSet=PX_NULL; + } + else if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR) + { + resOperand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT; + resOperand.pSet=PX_NULL; + } + else if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR) + { + resOperand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_STRING; + resOperand.pSet=PX_NULL; + } + else if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR) + { + resOperand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY; + resOperand.pSet=PX_NULL; + } + else if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_STRUCT_PTR) + { + resOperand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_STRUCT; + resOperand.pSet=operand1.pSet; + } + + else if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR_CONST) + { + resOperand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT; + resOperand.pSet=PX_NULL; + } + else if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR_CONST) + { + resOperand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT; + resOperand.pSet=PX_NULL; + } + else if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR_CONST) + { + resOperand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_STRING; + resOperand.pSet=PX_NULL; + } + else if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR_CONST) + { + resOperand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY; + resOperand.pSet=PX_NULL; + } + else if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_SET_PTR_CONST) + { + resOperand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_STRUCT; + resOperand.pSet=operand1.pSet; + + } + else + { + return PX_FALSE; + } + + if (!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) + { + return PX_FALSE; + } + + PX_StringCat(out,"PUSH R1\n"); + resOperand.region=PX_SCRIPT_VARIABLE_REGION_POP; + resOperand._oft=0; + resOperand._int=0; + PX_VectorPushback(tk,&resOperand); + + PX_StringFree(&fmrString); + return PX_TRUE; +} +static px_bool PX_ScriptParseLastInstr_ADR(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1,*pTop; + px_string fmrString; + if (tk->size<1) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + + PX_VectorPop(op); + + pTop=((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + + switch(operand1.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR_CONST; + break; + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT: + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR_CONST; + break; + case PX_SCRIPT_AST_OPERAND_TYPE_STRING: + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR_CONST; + break; + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY: + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR_CONST; + break; + case PX_SCRIPT_AST_OPERAND_TYPE_STRUCT: + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_SET_PTR_CONST; + break; + default: + return PX_FALSE; + } + + if(operand1.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + pTop->_int=operand1._int; + pTop->region=PX_SCRIPT_VARIABLE_REGION_GLOBAL; + return PX_TRUE; + } + else if(operand1.region==PX_SCRIPT_VARIABLE_REGION_LOCAL) + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringFormat1(&fmrString,"MOV R1,BP\nSUB R1,%1\n",PX_STRINGFORMAT_INT(operand1._oft));// + PX_StringCat(out,fmrString.buffer); + PX_StringSet(&fmrString,"PUSH R1\n"); + PX_StringCat(out,fmrString.buffer); + PX_StringFree(&fmrString); + + pTop->_int=operand1._int; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + else if (operand1.region==PX_SCRIPT_VARIABLE_REGION_POP) + { + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + else + { + return PX_FALSE; + } + + return PX_TRUE; +} +static px_bool PX_ScriptParseLastInstr_ADD(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1,operand2,*pTop; + px_string fmrString; + + if (tk->size<2) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-2)); + operand2=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + + PX_VectorPop(op); + PX_VectorPop(tk); + if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST&&operand1.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + if (operand2.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST&&operand2.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->_int=operand1._int+operand2._int; + return PX_TRUE; + } + + if (operand2.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST&&operand2.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST; + pTop->_float=operand1._int+operand2._float; + return PX_TRUE; + } + } + + if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST&&operand1.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + if (operand2.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST&&operand2.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST; + pTop->_float=operand1._float+operand2._int; + return PX_TRUE; + } + + if (operand2.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST&&operand2.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->_float=operand1._float+operand2._float; + return PX_TRUE; + } + } + + switch(operand1.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + { + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + { + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + PX_StringCat(out,"ADD R1,R2\nPUSH R1\n"); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + if(operand2.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT||operand2.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST) + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST; + else + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + break; + default: + return PX_FALSE; + } + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT: + { + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST: + { + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + PX_StringCat(out,"ADD R1,R2\nPUSH R1\n"); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + break; + default: + return PX_FALSE; + } + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_STRING: + { + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING: + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + { + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + PX_StringCat(out,"STRCAT R1,R2\nPUSH R1\n"); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_STRING_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + break; + default: + return PX_FALSE; + } + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY: + { + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY: + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + { + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + PX_StringCat(out,"MEMCAT R1,R2\nPUSH R1\n"); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + break; + default: + return PX_FALSE; + } + } + break; + + + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_CONST: + { + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_STRING: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + { + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + PX_StringCat(out,"STRCAT R1,R2\nPUSH R1\n"); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=operand1.operandType; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + break; + default: + return PX_FALSE; + } + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_CONST: + { + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + { + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + PX_StringCat(out,"MEMCAT R1,R2\nPUSH R1\n"); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=operand1.operandType; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + break; + default: + return PX_FALSE; + } + } + break; + + + case PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR_CONST: + { + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + { + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringFormat1(&fmrString,"MUL R2,%1\n",PX_STRINGFORMAT_INT(operand1.pSet->size)); + PX_StringCat(out,fmrString.buffer); + PX_StringFree(&fmrString); + PX_StringCat(out,"ADD R1,R2\nPUSH R1\n"); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + break; + default: + return PX_FALSE; + } + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR_CONST: + { + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + { + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + PX_StringCat(out,"ADD R1,R2\nPUSH R1\n"); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + break; + default: + return PX_FALSE; + } + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR_CONST: + { + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + { + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + PX_StringCat(out,"ADD R1,R2\nPUSH R1\n"); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + break; + default: + return PX_FALSE; + } + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR_CONST: + { + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + { + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + PX_StringCat(out,"ADD R1,R2\nPUSH R1\n"); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + break; + default: + return PX_FALSE; + } + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_STRUCT_PTR: + case PX_SCRIPT_AST_OPERAND_TYPE_SET_PTR_CONST: + { + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + { + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + + PX_StringCat(out,"ADD R1,R2\nPUSH R1\n"); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_SET_PTR_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + break; + default: + return PX_FALSE; + } + } + break; + + default: + return PX_FALSE; + } + + return PX_TRUE; + +} +static px_bool PX_ScriptParseLastInstr_INC(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1; + px_string fmrString; + + if (tk->size<1) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + + PX_VectorPop(op); + if (operand1.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_INT&&operand1.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR&&operand1.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR&&operand1.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR&&operand1.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR&&operand1.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_STRUCT_PTR) + { + return PX_FALSE; + } + switch(operand1.region) + { + case PX_SCRIPT_VARIABLE_REGION_GLOBAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringFormat1(&fmrString,"ADD GLOBAL[%1],1\n",PX_STRINGFORMAT_INT(operand1._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_LOCAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringFormat1(&fmrString,"ADD LOCAL[%1],1\n",PX_STRINGFORMAT_INT(operand1._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_POP: + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringCat(out,"POP R1\n"); + PX_StringSet(&fmrString,"ADD GLOBAL[R1],1\n"); + PX_StringCat(out,fmrString.buffer); + PX_StringCat(out,"PUSH R1\n"); + PX_StringFree(&fmrString); + } + break; + default: + return PX_FALSE; + } + return PX_TRUE; +} +static px_bool PX_ScriptParseLastInstr_POSITIVE(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1; + + if (tk->size<1) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + + switch(operand1.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + break; + default: + return PX_FALSE; + } + PX_VectorPop(op); + return PX_TRUE; +} +static px_bool PX_ScriptParseLastInstr_SUB(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1,operand2,*pTop; + + if (tk->size<2) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-2)); + operand2=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + + PX_VectorPop(op); + PX_VectorPop(tk); + if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST&&operand1.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + if (operand2.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST&&operand2.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->_int=operand1._int-operand2._int; + return PX_TRUE; + } + + if (operand2.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST&&operand2.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST; + pTop->_float=operand1._int-operand2._float; + return PX_TRUE; + } + } + + if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST&&operand1.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + if (operand2.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST&&operand2.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST; + pTop->_float=operand1._float-operand2._int; + return PX_TRUE; + } + + if (operand2.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST&&operand2.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->_float=operand1._float-operand2._float; + return PX_TRUE; + } + } + + switch(operand1.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + { + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + { + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + PX_StringCat(out,"SUB R1,R2\nPUSH R1\n"); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + if(operand2.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT||operand2.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST) + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST; + else + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + break; + default: + return PX_FALSE; + } + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT: + { + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST: + { + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + PX_StringCat(out,"SUB R1,R2\nPUSH R1\n"); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + break; + default: + return PX_FALSE; + } + } + break; + + + + case PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR_CONST: + { + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + { + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + PX_StringCat(out,"SUB R1,R2\nPUSH R1\n"); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + break; + default: + return PX_FALSE; + } + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR_CONST: + { + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + { + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + PX_StringCat(out,"SUB R1,R2\nPUSH R1\n"); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + break; + default: + return PX_FALSE; + } + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR_CONST: + { + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + { + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + PX_StringCat(out,"SUB R1,R2\nPUSH R1\n"); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + break; + default: + return PX_FALSE; + } + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR_CONST: + { + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + { + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + PX_StringCat(out,"SUB R1,R2\nPUSH R1\n"); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + break; + default: + return PX_FALSE; + } + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_STRUCT_PTR: + case PX_SCRIPT_AST_OPERAND_TYPE_SET_PTR_CONST: + { + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + { + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + PX_StringCat(out,"SUB R1,R2\nPUSH R1\n"); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_SET_PTR_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + break; + default: + return PX_FALSE; + } + } + break; + + default: + return PX_FALSE; + } + + return PX_TRUE; + +} +static px_bool PX_ScriptParseLastInstr_DEC(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1; + px_string fmrString; + + if (tk->size<1) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + + PX_VectorPop(op); + + if (operand1.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_INT&&operand1.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR&&operand1.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR&&operand1.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR&&operand1.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR&&operand1.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_STRUCT_PTR) + { + return PX_FALSE; + } + switch(operand1.region) + { + case PX_SCRIPT_VARIABLE_REGION_GLOBAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringFormat1(&fmrString,"SUB GLOBAL[%1],1\n",PX_STRINGFORMAT_INT(operand1._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_LOCAL: + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringFormat1(&fmrString,"SUB LOCAL[%1],1\n",PX_STRINGFORMAT_INT(operand1._oft)); + PX_StringCat(out,fmrString.buffer); + PX_StringFree(&fmrString); + } + break; + case PX_SCRIPT_VARIABLE_REGION_POP: + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringCat(out,"POP R1\n"); + PX_StringSet(&fmrString,"SUB GLOBAL[R1],1\n"); + PX_StringCat(out,fmrString.buffer); + PX_StringCat(out,"PUSH R1\n"); + PX_StringFree(&fmrString); + } + break; + default: + return PX_FALSE; + } + return PX_TRUE; +} +static px_bool PX_ScriptParseLastInstr_NEGATIVE(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1,*pTop; + + if (tk->size<1) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + PX_VectorPop(op); + if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST&&operand1.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->_int=-operand1._int; + return PX_TRUE; + } + + if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST&&operand1.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->_float=-operand1._float; + return PX_TRUE; + } + + + switch(operand1.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + break; + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST: + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST; + break; + default: + return PX_FALSE; + } + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + pTop->pSet=PX_NULL; + pTop->_int=0; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + PX_StringCat(out,"NEG R1\n"); + PX_StringCat(out,"PUSH R1\n"); + return PX_TRUE; +} +static px_bool PX_ScriptParseLastInstr_MUL(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1,operand2,*pTop; + + if (tk->size<2) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-2)); + operand2=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + + PX_VectorPop(op); + PX_VectorPop(tk); + if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST&&operand1.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + if (operand2.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST&&operand2.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->region=PX_SCRIPT_VARIABLE_REGION_GLOBAL; + pTop->_int=operand1._int*operand2._int; + return PX_TRUE; + } + + if (operand2.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST&&operand2.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST; + pTop->_float=operand1._int*operand2._float; + return PX_TRUE; + } + } + + if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST&&operand1.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + if (operand2.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST&&operand2.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST; + pTop->_float=operand1._float*operand2._int; + return PX_TRUE; + } + + if (operand2.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST&&operand2.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->_float=operand1._float*operand2._float; + return PX_TRUE; + } + } + + switch(operand1.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + { + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + { + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + PX_StringCat(out,"MUL R1,R2\nPUSH R1\n"); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + if(operand2.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT||operand2.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST) + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST; + else + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + break; + default: + return PX_FALSE; + } + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT: + { + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + { + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + PX_StringCat(out,"MUL R1,R2\nPUSH R1\n"); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + break; + default: + return PX_FALSE; + } + } + break; + + default: + return PX_FALSE; + } + + return PX_TRUE; + +} +static px_bool PX_ScriptParseLastInstr_DIV(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1,operand2,*pTop; + + if (tk->size<2) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-2)); + operand2=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + + PX_VectorPop(op); + PX_VectorPop(tk); + if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST&&operand1.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + if (operand2._int==0) + { + PX_ScriptTranslatorError(&analysis->lexer,"Divide by zero error."); + return PX_FALSE; + } + + if (operand2.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST&&operand2.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->_int=operand1._int/operand2._int; + return PX_TRUE; + } + + if (operand2.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST&&operand2.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST; + pTop->_float=operand1._int/operand2._float; + return PX_TRUE; + } + } + + if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST&&operand1.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + if (operand2._int==0) + { + PX_ScriptTranslatorError(&analysis->lexer,"Divide by zero error."); + return PX_FALSE; + } + if (operand2.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST&&operand2.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST; + pTop->_float=operand1._float/operand2._int; + return PX_TRUE; + } + + if (operand2.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST&&operand2.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->_float=operand1._float/operand2._float; + return PX_TRUE; + } + } + + switch(operand1.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + { + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + { + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + PX_StringCat(out,"DIV R1,R2\nPUSH R1\n"); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + if(operand2.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT||operand2.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST) + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST; + else + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + break; + default: + return PX_FALSE; + } + } + break; + + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT: + { + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + { + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + PX_StringCat(out,"DIV R1,R2\nPUSH R1\n"); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + break; + default: + return PX_FALSE; + } + } + break; + + default: + return PX_FALSE; + } + + return PX_TRUE; + +} +static px_bool PX_ScriptParseLastInstr_AND(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1,operand2,*pTop; + + if (tk->size<2) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-2)); + operand2=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + + PX_VectorPop(op); + PX_VectorPop(tk); + if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST&&operand1.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + if (operand2.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST&&operand2.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->_int=operand1._int&operand2._int; + return PX_TRUE; + } + } + + + switch(operand1.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + { + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + { + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + PX_StringCat(out,"AND R1,R2\nPUSH R1\n"); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + break; + default: + return PX_FALSE; + } + } + break; + + default: + return PX_FALSE; + } + + return PX_TRUE; + +} +static px_bool PX_ScriptParseLastInstr_OR(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1,operand2,*pTop; + + if (tk->size<2) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-2)); + operand2=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + + PX_VectorPop(op); + PX_VectorPop(tk); + if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST&&operand1.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + if (operand2.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST&&operand2.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->_int=operand1._int|operand2._int; + return PX_TRUE; + } + } + + + switch(operand1.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + { + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + { + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + PX_StringCat(out,"OR R1,R2\nPUSH R1\n"); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + break; + default: + return PX_FALSE; + } + } + break; + + default: + return PX_FALSE; + } + + return PX_TRUE; + +} +static px_bool PX_ScriptParseLastInstr_NOT(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1,*pTop; + + if (tk->size<1) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + PX_VectorPop(op); + if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST&&operand1.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->_int=(operand1._int==0); + return PX_TRUE; + } + + switch(operand1.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + break; + default: + return PX_FALSE; + } + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + pTop->pSet=PX_NULL; + pTop->_int=0; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + PX_StringCat(out,"NOT R1\n"); + PX_StringCat(out,"PUSH R1\n"); + return PX_TRUE; +} +static px_bool PX_ScriptParseLastInstr_XOR(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1,operand2,*pTop; + + if (tk->size<2) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-2)); + operand2=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + + PX_VectorPop(op); + PX_VectorPop(tk); + if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST&&operand1.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + if (operand2.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST&&operand2.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->_int=operand1._int^operand2._int; + return PX_TRUE; + } + } + + + switch(operand1.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + { + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + { + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + PX_StringCat(out,"XOR R1,R2\nPUSH R1\n"); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + break; + default: + return PX_FALSE; + } + } + break; + + default: + return PX_FALSE; + } + + return PX_TRUE; + +} +static px_bool PX_ScriptParseLastInstr_INV(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1,*pTop; + + if (tk->size<1) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + PX_VectorPop(op); + if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST&&operand1.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->_int=(~operand1._int); + return PX_TRUE; + } + + switch(operand1.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + break; + default: + return PX_FALSE; + } + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + pTop->pSet=PX_NULL; + pTop->_int=0; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + PX_StringCat(out,"INV R1\n"); + PX_StringCat(out,"PUSH R1\n"); + return PX_TRUE; +} +static px_bool PX_ScriptParseLastInstr_MOD(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1,operand2,*pTop; + + if (tk->size<2) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-2)); + operand2=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + + PX_VectorPop(op); + PX_VectorPop(tk); + if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST&&operand1.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + if (operand2._int==0) + { + PX_ScriptTranslatorError(&analysis->lexer,"mod by zero error."); + return PX_FALSE; + } + + if (operand2.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST&&operand2.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->_int=operand1._int%operand2._int; + return PX_TRUE; + } + } + + switch(operand1.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + { + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + { + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + PX_StringCat(out,"MOD R1,R2\nPUSH R1\n"); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + break; + default: + return PX_FALSE; + } + } + break; + + default: + return PX_FALSE; + } + + return PX_TRUE; + +} +static px_bool PX_ScriptParseLastInstr_SHL(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1,operand2,*pTop; + + if (tk->size<2) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-2)); + operand2=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + + PX_VectorPop(op); + PX_VectorPop(tk); + if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST&&operand1.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + if (operand2.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST&&operand2.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->_int=operand1._int<operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + break; + default: + return PX_FALSE; + } + } + break; + + default: + return PX_FALSE; + } + + return PX_TRUE; + +} +static px_bool PX_ScriptParseLastInstr_SHR(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1,operand2,*pTop; + + if (tk->size<2) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-2)); + operand2=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + + PX_VectorPop(op); + PX_VectorPop(tk); + if (operand1.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST&&operand1.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + if (operand2.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST&&operand2.region==PX_SCRIPT_VARIABLE_REGION_GLOBAL) + { + + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->_int=operand1._int>>operand2._int; + return PX_TRUE; + } + } + + + switch(operand1.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + { + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + { + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + PX_StringCat(out,"SHR R1,R2\nPUSH R1\n"); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + } + break; + default: + return PX_FALSE; + } + } + break; + + default: + return PX_FALSE; + } + + return PX_TRUE; + +} +static px_bool PX_ScriptParseLastInstr_INT(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1,*pTop; + + if (tk->size<1) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + PX_VectorPop(op); + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + pTop->pSet=PX_NULL; + pTop->_int=0; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + + switch(operand1.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST: + PX_StringCat(out,"INT R1\n"); + break; + case PX_SCRIPT_AST_OPERAND_TYPE_STRING: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_CONST: + PX_StringCat(out,"STRTOI R1,R1\n"); + break; + default: + return PX_FALSE; + } + PX_StringCat(out,"PUSH R1\n"); + return PX_TRUE; +} +static px_bool PX_ScriptParseLastInstr_FLOAT(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1,*pTop; + + if (tk->size<1) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + PX_VectorPop(op); + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + pTop->pSet=PX_NULL; + pTop->_int=0; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST; + + switch(operand1.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST: + PX_StringCat(out,"FLT R1\n"); + break; + case PX_SCRIPT_AST_OPERAND_TYPE_STRING: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_CONST: + PX_StringCat(out,"STRTOF R1,R1\n"); + break; + default: + return PX_FALSE; + } + PX_StringCat(out,"PUSH R1\n"); + return PX_TRUE; +} +static px_bool PX_ScriptParseLastInstr_STRING(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1,*pTop; + + if (tk->size<1) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + PX_VectorPop(op); + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + pTop->pSet=PX_NULL; + pTop->_int=0; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_STRING_CONST; + + switch(operand1.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: + PX_StringCat(out,"STRFRI R1,R1\n"); + break; + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST: + PX_StringCat(out,"STRFRF R1,R1\n"); + break; + case PX_SCRIPT_AST_OPERAND_TYPE_STRING: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_CONST: + break; + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_CONST: + PX_StringCat(out,"MEMTSTR R1\n"); + break; + default: + return PX_FALSE; + } + PX_StringCat(out,"PUSH R1\n"); + return PX_TRUE; +} +static px_bool PX_ScriptParseLastInstr_MEMORY(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1,*pTop; + + if (tk->size<1) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + PX_VectorPop(op); + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + pTop->pSet=PX_NULL; + pTop->_int=0; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_CONST; + + switch(operand1.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_STRING: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_CONST: + PX_StringCat(out,"STRTMEM R1\n"); + break; + default: + return PX_FALSE; + } + PX_StringCat(out,"PUSH R1\n"); + return PX_TRUE; +} +static px_bool PX_ScriptParseLastInstr_STRLEN(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1,*pTop; + + if (tk->size<1) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + PX_VectorPop(op); + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + pTop->pSet=PX_NULL; + pTop->_int=0; + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand1,out)) return PX_FALSE; + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + + switch(operand1.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_STRING: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_CONST: + PX_StringCat(out,"STRLEN R1,R2\n"); + break; + default: + return PX_FALSE; + } + PX_StringCat(out,"PUSH R1\n"); + return PX_TRUE; +} +static px_bool PX_ScriptParseLastInstr_MEMLEN(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1,*pTop; + + if (tk->size<1) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + PX_VectorPop(op); + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + pTop->pSet=PX_NULL; + pTop->_int=0; + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand1,out)) return PX_FALSE; + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + + switch(operand1.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_CONST: + PX_StringCat(out,"MEMLEN R1,R2\n"); + break; + default: + return PX_FALSE; + } + PX_StringCat(out,"PUSH R1\n"); + return PX_TRUE; +} + +static px_bool PX_ScriptParseLastInstr_LARGE(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1,operand2,*pTop; + + if (tk->size<2) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-2)); + operand2=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + + PX_VectorPop(op); + PX_VectorPop(tk); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + if (!PX_ScriptParseIsOperandNumericType(operand1)||!PX_ScriptParseIsOperandNumericType(operand2)) + { + return PX_FALSE; + } + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + + PX_StringCat(out,"SUB R1,R2\n"); + PX_StringCat(out,"LGGZ R1\n"); + PX_StringCat(out,"PUSH R1\n"); + return PX_TRUE; +} +static px_bool PX_ScriptParseLastInstr_LARGEEQU(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1,operand2,*pTop; + + if (tk->size<2) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-2)); + operand2=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + + PX_VectorPop(op); + PX_VectorPop(tk); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + if (!PX_ScriptParseIsOperandNumericType(operand1)||!PX_ScriptParseIsOperandNumericType(operand2)) + { + return PX_FALSE; + } + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + + PX_StringCat(out,"SUB R1,R2\n"); + PX_StringCat(out,"LGGEZ R1\n"); + PX_StringCat(out,"PUSH R1\n"); + return PX_TRUE; +} +static px_bool PX_ScriptParseLastInstr_LESS(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1,operand2,*pTop; + + if (tk->size<2) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-2)); + operand2=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + + PX_VectorPop(op); + PX_VectorPop(tk); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + if (!PX_ScriptParseIsOperandNumericType(operand1)||!PX_ScriptParseIsOperandNumericType(operand2)) + { + return PX_FALSE; + } + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + + PX_StringCat(out,"SUB R1,R2\n"); + PX_StringCat(out,"LGLZ R1\n"); + PX_StringCat(out,"PUSH R1\n"); + return PX_TRUE; +} +static px_bool PX_ScriptParseLastInstr_LAND(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1,operand2,*pTop; + + if (tk->size<2) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-2)); + operand2=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + + PX_VectorPop(op); + PX_VectorPop(tk); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + if (!PX_ScriptParseIsOperandNumericType(operand1)||!PX_ScriptParseIsOperandNumericType(operand2)) + { + return PX_FALSE; + } + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + + PX_StringCat(out,"ANDL R1,R2\n"); + PX_StringCat(out,"PUSH R1\n"); + return PX_TRUE; +} +static px_bool PX_ScriptParseLastInstr_LOR(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1,operand2,*pTop; + + if (tk->size<2) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-2)); + operand2=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + + PX_VectorPop(op); + PX_VectorPop(tk); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + if (!PX_ScriptParseIsOperandNumericType(operand1)||!PX_ScriptParseIsOperandNumericType(operand2)) + { + return PX_FALSE; + } + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + + PX_StringCat(out,"ORL R1,R2\n"); + PX_StringCat(out,"PUSH R1\n"); + return PX_TRUE; +} +static px_bool PX_ScriptParseLastInstr_LESSEQU(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1,operand2,*pTop; + + if (tk->size<2) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-2)); + operand2=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + + PX_VectorPop(op); + PX_VectorPop(tk); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + if (!PX_ScriptParseIsOperandNumericType(operand1)||!PX_ScriptParseIsOperandNumericType(operand2)) + { + return PX_FALSE; + } + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + + PX_StringCat(out,"SUB R1,R2\n"); + PX_StringCat(out,"LGLEZ R1\n"); + PX_StringCat(out,"PUSH R1\n"); + return PX_TRUE; +} +static px_bool PX_ScriptParseLastInstr_LGEQU(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1,operand2,*pTop; + + if (tk->size<2) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-2)); + operand2=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + + PX_VectorPop(op); + PX_VectorPop(tk); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + if (!PX_ScriptParseIsOperandNumericType(operand1)||!PX_ScriptParseIsOperandNumericType(operand2)) + { + switch(operand1.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY: + { + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_CONST: + break; + default: + PX_ScriptTranslatorError(&analysis->lexer,"Matched-type difference."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING: + { + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_STRING: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_CONST: + break; + default: + PX_ScriptTranslatorError(&analysis->lexer,"Matched-type difference."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPERAND_TYPE_STRUCT: + PX_ScriptTranslatorError(&analysis->lexer,"Struct-type could not be compared."); + return PX_FALSE; + default: + if (operand1.operandType!=operand2.operandType) + { + PX_ScriptTranslatorError(&analysis->lexer,"Matched-type difference."); + return PX_FALSE; + } + } + } + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + PX_StringCat(out,"LGE R1,R1,R2\n"); + PX_StringCat(out,"PUSH R1\n"); + return PX_TRUE; +} +static px_bool PX_ScriptParseLastInstr_UNEQU(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + PX_SCRIPT_AST_OPERAND operand1,operand2,*pTop; + + if (tk->size<2) + { + return PX_FALSE; + } + operand1=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-2)); + operand2=*((PX_SCRIPT_AST_OPERAND *)PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,tk->size-1)); + + PX_VectorPop(op); + PX_VectorPop(tk); + pTop=PX_VECTORLAST(PX_SCRIPT_AST_OPERAND,tk); + pTop->operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + pTop->region=PX_SCRIPT_VARIABLE_REGION_POP; + pTop->_oft=0; + if (!PX_ScriptParseIsOperandNumericType(operand1)||!PX_ScriptParseIsOperandNumericType(operand2)) + { + switch(operand1.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY: + { + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_CONST: + break; + default: + PX_ScriptTranslatorError(&analysis->lexer,"Matched-type difference."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING: + { + switch(operand2.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_STRING: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_CONST: + break; + default: + PX_ScriptTranslatorError(&analysis->lexer,"Matched-type difference."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPERAND_TYPE_STRUCT: + PX_ScriptTranslatorError(&analysis->lexer,"Struct-type could not be compared."); + return PX_FALSE; + default: + if (operand1.operandType!=operand2.operandType) + { + PX_ScriptTranslatorError(&analysis->lexer,"Matched-type difference."); + return PX_FALSE; + } + } + } + if(!PX_ScriptParseAST_MapTokenToR2(analysis,operand2,out)) return PX_FALSE; + if(!PX_ScriptParseAST_MapTokenToR1(analysis,operand1,out)) return PX_FALSE; + PX_StringCat(out,"LGNE R1,R1,R2\n"); + PX_StringCat(out,"PUSH R1\n"); + return PX_TRUE; +} +static px_bool PX_ScriptParseLastInstr(PX_SCRIPT_Analysis *analysis,px_vector *op,px_vector *tk,px_string *out) +{ + + PX_SCRIPT_AST_OPCODE opcode; + opcode=*((PX_SCRIPT_AST_OPCODE *)PX_VECTORAT(PX_SCRIPT_AST_OPCODE,op,op->size-1)); + + if (tk->size==1&&op->size==0)//(const) + { + return PX_TRUE; + } + + switch(opcode.operandType) + { + case PX_SCRIPT_AST_OPCODE_TYPE_EQU: + { + if(!PX_ScriptParseLastInstr_EQUAL(analysis,op,tk,out)) + { + PX_ScriptTranslatorError(&analysis->lexer,"'=' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_DOT: + { + if(!PX_ScriptParseLastInstr_DOT(analysis,op,tk,out)){ + PX_ScriptTranslatorError(&analysis->lexer,"'.' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_IDX: + { + if(!PX_ScriptParseLastInstr_IDX(analysis,op,tk,out)){ + PX_ScriptTranslatorError(&analysis->lexer,"'.' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_OFT: + { + if(!PX_ScriptParseLastInstr_OFT(analysis,op,tk,out)) { + PX_ScriptTranslatorError(&analysis->lexer,"'[]' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_PTR: + { + if(!PX_ScriptParseLastInstr_PTR(analysis,op,tk,out)) { + PX_ScriptTranslatorError(&analysis->lexer,"'->' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_ADR: + { + if(!PX_ScriptParseLastInstr_ADR(analysis,op,tk,out)) { + PX_ScriptTranslatorError(&analysis->lexer,"'&' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_ADD: + { + if(!PX_ScriptParseLastInstr_ADD(analysis,op,tk,out)) { + PX_ScriptTranslatorError(&analysis->lexer,"'+' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_INC: + { + if(!PX_ScriptParseLastInstr_INC(analysis,op,tk,out)) { + PX_ScriptTranslatorError(&analysis->lexer,"'++' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_POSITIVE: + { + if(!PX_ScriptParseLastInstr_POSITIVE(analysis,op,tk,out)) { + PX_ScriptTranslatorError(&analysis->lexer,"'+' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_SUB: + { + if(!PX_ScriptParseLastInstr_SUB(analysis,op,tk,out)) { + PX_ScriptTranslatorError(&analysis->lexer,"'-' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_DEC: + { + if(!PX_ScriptParseLastInstr_DEC(analysis,op,tk,out)) { + PX_ScriptTranslatorError(&analysis->lexer,"'--' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_NEGATIVE: + { + if(!PX_ScriptParseLastInstr_NEGATIVE(analysis,op,tk,out)) { + PX_ScriptTranslatorError(&analysis->lexer,"'-' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_MUL: + { + if(!PX_ScriptParseLastInstr_MUL(analysis,op,tk,out)) { + PX_ScriptTranslatorError(&analysis->lexer,"'*' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_DIV: + { + if(!PX_ScriptParseLastInstr_DIV(analysis,op,tk,out)) { + PX_ScriptTranslatorError(&analysis->lexer,"'/' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_AND: + { + if(!PX_ScriptParseLastInstr_AND(analysis,op,tk,out)) { + PX_ScriptTranslatorError(&analysis->lexer,"'&' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_OR: + { + if(!PX_ScriptParseLastInstr_OR(analysis,op,tk,out)) { + PX_ScriptTranslatorError(&analysis->lexer,"'|' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_NOT: + { + if(!PX_ScriptParseLastInstr_NOT(analysis,op,tk,out)) { + PX_ScriptTranslatorError(&analysis->lexer,"'!' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_XOR: + { + if(!PX_ScriptParseLastInstr_XOR(analysis,op,tk,out)) { + PX_ScriptTranslatorError(&analysis->lexer,"'^' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_INV: + { + if(!PX_ScriptParseLastInstr_INV(analysis,op,tk,out)) { + PX_ScriptTranslatorError(&analysis->lexer,"'~' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_MOD: + { + if(!PX_ScriptParseLastInstr_MOD(analysis,op,tk,out)) { + PX_ScriptTranslatorError(&analysis->lexer,"'%' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_SHL: + { + if(!PX_ScriptParseLastInstr_SHL(analysis,op,tk,out)) { + PX_ScriptTranslatorError(&analysis->lexer,"'<<' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_SHR: + { + if(!PX_ScriptParseLastInstr_SHR(analysis,op,tk,out)) { + PX_ScriptTranslatorError(&analysis->lexer,"'>>' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_LARGE: + { + if(!PX_ScriptParseLastInstr_LARGE(analysis,op,tk,out)) { + PX_ScriptTranslatorError(&analysis->lexer,"'>' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_LARGEEQU: + { + if(!PX_ScriptParseLastInstr_LARGEEQU(analysis,op,tk,out)) { + PX_ScriptTranslatorError(&analysis->lexer,"'>=' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_LESS: + { + if(!PX_ScriptParseLastInstr_LESS(analysis,op,tk,out)) { + PX_ScriptTranslatorError(&analysis->lexer,"'<' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_LESSEQU: + { + if(!PX_ScriptParseLastInstr_LESSEQU(analysis,op,tk,out)) { + PX_ScriptTranslatorError(&analysis->lexer,"'<=' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_LGEQU: + { + if(!PX_ScriptParseLastInstr_LGEQU(analysis,op,tk,out)) { + PX_ScriptTranslatorError(&analysis->lexer,"'>=' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_UNEQU: + { + if(!PX_ScriptParseLastInstr_UNEQU(analysis,op,tk,out)) { + PX_ScriptTranslatorError(&analysis->lexer,"'!=' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_LAND: + { + if(!PX_ScriptParseLastInstr_LAND(analysis,op,tk,out)) { + PX_ScriptTranslatorError(&analysis->lexer,"'&&' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_LOR: + { + if(!PX_ScriptParseLastInstr_LOR(analysis,op,tk,out)) { + PX_ScriptTranslatorError(&analysis->lexer,"'||' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_INT: + { + if(!PX_ScriptParseLastInstr_INT(analysis,op,tk,out)) { + PX_ScriptTranslatorError(&analysis->lexer,"'int' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_FLOAT: + { + if(!PX_ScriptParseLastInstr_FLOAT(analysis,op,tk,out)) { + PX_ScriptTranslatorError(&analysis->lexer,"'float' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_STRING: + { + if(!PX_ScriptParseLastInstr_STRING(analysis,op,tk,out)) { + PX_ScriptTranslatorError(&analysis->lexer,"'string' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_MEMORY: + { + if(!PX_ScriptParseLastInstr_MEMORY(analysis,op,tk,out)) { + PX_ScriptTranslatorError(&analysis->lexer,"'memory' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_STRLEN: + { + if(!PX_ScriptParseLastInstr_STRLEN(analysis,op,tk,out)) { + PX_ScriptTranslatorError(&analysis->lexer,"'strlen' not match error."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_OPCODE_TYPE_MEMLEN: + { + if(!PX_ScriptParseLastInstr_MEMLEN(analysis,op,tk,out)) { + PX_ScriptTranslatorError(&analysis->lexer,"'memlen' not match error."); + return PX_FALSE; + } + } + break; + default: + return PX_FALSE; + } + return PX_TRUE; +} +static px_bool PX_ScriptParseExpressionStream(PX_SCRIPT_Analysis *analysis,px_vector *stream,px_int *offset,PX_SCRIPT_AST_OPERAND *pretOperand,PX_SCRIPT_TRANSLATOR_EXPRESSION_TYPE expectedEndl,px_string *out) +{ + px_vector vOp; + px_vector vTk; + px_vector *op=&vOp; + px_vector *tk=&vTk; + PX_SCRIPT_AST_OPERAND retOperand; + PX_SCRIPT_AST_OPCODE *plastop=PX_NULL; + PX_SCRIPT_STRUCT *pcurrentSet=PX_NULL; + px_int level=PX_SCRIPT_OPCODE_LEVEL_BOTTOM; + PX_SCRIPT_EXPR_STREAM *pVec=(PX_SCRIPT_EXPR_STREAM *)(stream->data); + PX_SCRIPT_FUNCTION *pfunc=PX_NULL; + px_int i,LBracketBalance,MBracketBalance,paramBeginIndex[16],paramcount=0; + px_string fmrString; + PX_VectorInitialize(analysis->mp,op,sizeof(PX_SCRIPT_AST_OPCODE),16); + PX_VectorInitialize(analysis->mp,tk,sizeof(PX_SCRIPT_AST_OPERAND),16); + + + + while(*offsetsize) + { + if (pVec[*offset].type==expectedEndl) + { + while(op->size) + { + if(!PX_ScriptParseLastInstr(analysis,op,tk,out)) + { + goto _ERROR; + } + } + *pretOperand=*(PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,0)); + + break; + } + switch(pVec[*offset].type) + { + case PX_SCRIPT_TRANSLATOR_EXPRESSION_TOKEN: + { + if(!PX_ScriptParse_AST_PushToken(analysis,op,tk,pVec[*offset],pcurrentSet,&pcurrentSet)) + { + PX_ScriptTranslatorError(&analysis->lexer,"Function error."); + goto _ERROR; + } + } + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_FUNCTION: + { + //call func + for (i=0;iv_functions.size;i++) + { + pfunc=PX_VECTORAT(PX_SCRIPT_FUNCTION,&analysis->v_functions,i); + if (PX_strequ(pfunc->name,pVec[*offset].code.buffer)) + { + break; + } + } + if (i==analysis->v_functions.size) + { + PX_ScriptTranslatorError(&analysis->lexer,"Function name undefined."); + goto _ERROR; + } + + //( + (*offset)++; + if (pVec[*offset].type!=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LBRACKETBEGIN) + { + PX_ScriptTranslatorError(&analysis->lexer,"'(' expected but not found."); + goto _ERROR; + } + (*offset)++; + LBracketBalance=1; + paramcount=0; + paramBeginIndex[paramcount]=*offset; + + if(pVec[*offset].type==PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LBRACKETEND) + { + paramBeginIndex[paramcount]++; + } + else + while (PX_TRUE) + { + if (!LBracketBalance&&pVec[*offset].type==PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LBRACKETEND) + { + break; + } + MBracketBalance=0; + while (PX_TRUE) + { + if (*offset==stream->size) + { + PX_ScriptTranslatorError(&analysis->lexer,"Function parse error."); + goto _ERROR; + } + switch(pVec[*offset].type) + { + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LBRACKETBEGIN: + LBracketBalance++; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LBRACKETEND: + LBracketBalance--; + if (LBracketBalance==0) + { + goto _EXPR_OUT; + } + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_MBRACKETBEGIN: + MBracketBalance++; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_MBRACKETEND: + MBracketBalance--; + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_COMMA: + if (LBracketBalance==1&&MBracketBalance==0) + { + goto _EXPR_OUT; + } + break; + default: + break; + } + (*offset)++; + } +_EXPR_OUT: + if (pVec[*offset].type==PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LBRACKETEND) + { + (*offset)++; + paramcount++; + paramBeginIndex[paramcount]=*offset; + break; + } + else + { + (*offset)++; + paramcount++; + paramBeginIndex[paramcount]=*offset; + } + + } + if (paramcount!=pfunc->parametersCount) + { + PX_ScriptTranslatorError(&analysis->lexer,"Function parameter-count error."); + goto _ERROR; + } + + + for (i=paramcount-1;i>=0;i--) + //for (i=0;ilexer,"Function left-bracket-end missing."); + goto _ERROR; + } + } + else + { + if (!PX_ScriptParseExpressionStream(analysis,stream,¶mBeginIndex[i],&retOperand,PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_COMMA,out)) + { + PX_ScriptTranslatorError(&analysis->lexer,"Function comma missing."); + goto _ERROR; + } + } + + if (retOperand.operandType==PX_SCRIPT_AST_OPERAND_TYPE_STRUCT||retOperand.operandType==PX_SCRIPT_AST_OPERAND_TYPE_STRUCT_PTR||retOperand.operandType==PX_SCRIPT_AST_OPERAND_TYPE_SET_PTR_CONST) + { + pcurrentSet=retOperand.pSet; + } + + switch (retOperand.operandType) + { + case PX_SCRIPT_AST_OPERAND_TYPE_INT: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX: +// if (pfunc->parameters[i].type!=PX_SCRIPT_PARSER_VAR_TYPE_INT) +// { +// PX_ScriptTranslatorError(&analysis->lexer,"Parameter not matched."); +// goto _ERROR; +// } +// break; + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST: + if (pfunc->parameters[i].type!=PX_SCRIPT_PARSER_VAR_TYPE_FLOAT&&pfunc->parameters[i].type!=PX_SCRIPT_PARSER_VAR_TYPE_INT) + { + PX_ScriptTranslatorError(&analysis->lexer,"Parameter not matched."); + goto _ERROR; + } + break; + case PX_SCRIPT_AST_OPERAND_TYPE_STRING: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_CONST: + if (pfunc->parameters[i].type!=PX_SCRIPT_PARSER_VAR_TYPE_STRING) + { + PX_ScriptTranslatorError(&analysis->lexer,"Parameter not matched."); + goto _ERROR; + } + break; + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_CONST: + if (pfunc->parameters[i].type!=PX_SCRIPT_PARSER_VAR_TYPE_MEMORY) + { + PX_ScriptTranslatorError(&analysis->lexer,"Parameter not matched."); + goto _ERROR; + } + break; + case PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR: + case PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR_CONST: + if (pfunc->parameters[i].type!=PX_SCRIPT_PARSER_VAR_TYPE_INT_ARRAY&&pfunc->parameters[i].type!=PX_SCRIPT_PARSER_VAR_TYPE_INT_PTR) + { + PX_ScriptTranslatorError(&analysis->lexer,"Parameter not matched."); + goto _ERROR; + } + break; + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR: + case PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR_CONST: + if (pfunc->parameters[i].type!=PX_SCRIPT_PARSER_VAR_TYPE_FLOAT_ARRAY&&pfunc->parameters[i].type!=PX_SCRIPT_PARSER_VAR_TYPE_FLOAT_PTR) + { + PX_ScriptTranslatorError(&analysis->lexer,"Parameter not matched."); + goto _ERROR; + } + break; + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR: + case PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR_CONST: + if (pfunc->parameters[i].type!=PX_SCRIPT_PARSER_VAR_TYPE_STRING_ARRAY&&pfunc->parameters[i].type!=PX_SCRIPT_PARSER_VAR_TYPE_STRING_PTR) + { + PX_ScriptTranslatorError(&analysis->lexer,"Parameter not matched."); + goto _ERROR; + } + break; + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR: + case PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR_CONST: + if (pfunc->parameters[i].type!=PX_SCRIPT_PARSER_VAR_TYPE_MEMORY_ARRAY&&pfunc->parameters[i].type!=PX_SCRIPT_PARSER_VAR_TYPE_MEMORY_PTR) + { + PX_ScriptTranslatorError(&analysis->lexer,"Parameter not matched."); + goto _ERROR; + } + break; + case PX_SCRIPT_AST_OPERAND_TYPE_STRUCT_PTR: + case PX_SCRIPT_AST_OPERAND_TYPE_SET_PTR_CONST: + if (pfunc->parameters[i].type!=PX_SCRIPT_PARSER_VAR_TYPE_STRUCT_PTR||PX_ScriptParseGetStructByIndex(analysis,pfunc->parameters[i].setIndex)!=retOperand.pSet) + { + PX_ScriptTranslatorError(&analysis->lexer,"Parameter not matched."); + goto _ERROR; + } + break; + default: + PX_ScriptTranslatorError(&analysis->lexer,"unexpected error."); + goto _ERROR; + } + if (!PX_ScriptParseAST_MapTokenToR1(analysis,retOperand,out)) + { + goto _ERROR; + } + + if (retOperand.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT||retOperand.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST) + { + if (pfunc->parameters[i].type==PX_SCRIPT_PARSER_VAR_TYPE_INT) + { + PX_StringCat(out,"INT R1\n"); + } + } + + if (retOperand.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT||retOperand.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST\ + ||retOperand.operandType==PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX||retOperand.operandType==PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX) + { + if (pfunc->parameters[i].type==PX_SCRIPT_PARSER_VAR_TYPE_FLOAT) + { + PX_StringCat(out,"FLT R1\n"); + } + } + + PX_StringCat(out,"PUSH R1\n"); + + } + + //call + switch(pfunc->type) + { + case PX_SCRIPT_TRANSLATOR_FUNCTION_TYPE_EXPORT: + case PX_SCRIPT_TRANSLATOR_FUNCTION_TYPE_CUSTOM: + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringFormat1(&fmrString,"CALL %1\n",PX_STRINGFORMAT_STRING(pfunc->name)); + PX_StringCat(out,fmrString.buffer); + + if(pfunc->parametersCount) + { + PX_StringFormat1(&fmrString,"POPN %1\n",PX_STRINGFORMAT_INT(pfunc->parametersSize)); + PX_StringCat(out,fmrString.buffer); + } + + + PX_StringFree(&fmrString); + break; + case PX_SCRIPT_TRANSLATOR_FUNCTION_TYPE_HOST: + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringFormat1(&fmrString,"CALL $%1\n",PX_STRINGFORMAT_STRING(pfunc->name)); + PX_StringCat(out,fmrString.buffer); + if(pfunc->parametersCount) + { + PX_StringFormat1(&fmrString,"POPN %1\n",PX_STRINGFORMAT_INT(pfunc->parametersSize)); + PX_StringCat(out,fmrString.buffer); + } + + PX_StringFree(&fmrString); + break; + } + + retOperand.region=PX_SCRIPT_VARIABLE_REGION_POP; + retOperand._oft=0; + + switch (pfunc->retType) + { + case PX_SCRIPT_PARSER_VAR_TYPE_INT: + retOperand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + break; + case PX_SCRIPT_PARSER_VAR_TYPE_FLOAT: + retOperand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST; + break; + case PX_SCRIPT_PARSER_VAR_TYPE_STRING: + retOperand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_STRING_CONST; + break; + case PX_SCRIPT_PARSER_VAR_TYPE_MEMORY: + retOperand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_CONST; + break; + case PX_SCRIPT_PARSER_VAR_TYPE_INT_PTR: + retOperand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR_CONST; + break; + case PX_SCRIPT_PARSER_VAR_TYPE_FLOAT_PTR: + retOperand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR_CONST; + break; + case PX_SCRIPT_PARSER_VAR_TYPE_STRING_PTR: + retOperand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR_CONST; + break; + case PX_SCRIPT_PARSER_VAR_TYPE_MEMORY_PTR: + retOperand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR_CONST; + break; + case PX_SCRIPT_PARSER_VAR_TYPE_STRUCT_PTR: + retOperand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_SET_PTR_CONST; + retOperand.pSet=PX_ScriptParseGetStructByIndex(analysis,pfunc->retSetIndex); + break; + case PX_SCRIPT_PARSER_VAR_TYPE_VOID: + retOperand.operandType=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST; + retOperand._int=0; + break; + default: + goto _ERROR; + } + + + + PX_StringCat(out,"PUSH R1\n"); + PX_VectorPushback(tk,&retOperand); + + + + (*offset)=paramBeginIndex[paramcount]-1; + + + } + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LBRACKETBEGIN: + { + (*offset)++; + + if(!PX_ScriptParseExpressionStream(analysis,stream,offset,&retOperand,PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LBRACKETEND,out)) + goto _ERROR; + + PX_VectorPushback(tk,&retOperand); + if (retOperand.operandType==PX_SCRIPT_AST_OPERAND_TYPE_STRUCT||retOperand.operandType==PX_SCRIPT_AST_OPERAND_TYPE_STRUCT_PTR||retOperand.operandType==PX_SCRIPT_AST_OPERAND_TYPE_SET_PTR_CONST) + { + pcurrentSet=retOperand.pSet; + } + } + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_MBRACKETBEGIN: + { + + if (level>pVec[*offset].oplevel) + { + level=pVec[*offset].oplevel; + if(!PX_ScriptParseAST_PushOpcode(analysis,op,pVec[*offset])) goto _ERROR; + } + else + { + level=pVec[*offset].oplevel; + do{ + if(op->size>0) + { + if(!PX_ScriptParseLastInstr(analysis,op,tk,out)) goto _ERROR; + if(op->size) + plastop=PX_VECTORAT(PX_SCRIPT_AST_OPCODE,op,op->size-1); + } + else + break; + }while(op->size&&plastop->level<=level); + if(!PX_ScriptParseAST_PushOpcode(analysis,op,pVec[*offset])) goto _ERROR; + } + + (*offset)++; + if(!PX_ScriptParseExpressionStream(analysis,stream,offset,&retOperand,PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_MBRACKETEND,out)) + goto _ERROR; + + PX_VectorPushback(tk,&retOperand); + + if (retOperand.operandType==PX_SCRIPT_AST_OPERAND_TYPE_STRUCT||retOperand.operandType==PX_SCRIPT_AST_OPERAND_TYPE_STRUCT_PTR||retOperand.operandType==PX_SCRIPT_AST_OPERAND_TYPE_SET_PTR_CONST) + { + pcurrentSet=retOperand.pSet; + } + } + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_COMMA: + { + while(op->size) + { + if(!PX_ScriptParseLastInstr(analysis,op,tk,out)) + goto _ERROR; + } + *pretOperand=*(PX_VECTORAT(PX_SCRIPT_AST_OPERAND,tk,0)); + if(!PX_ScriptParseAST_MapTokenToR1(analysis,*pretOperand,out)) goto _ERROR; + + if (tk->size!=1) + { + goto _ERROR; + } + + level=PX_SCRIPT_OPCODE_LEVEL_BOTTOM; + PX_VectorPop(tk); + break; + } + break; + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_ADD: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_INC: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_POSITIVE: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_SUB: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_DEC: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_NEGATIVE: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_MUL: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_DIV: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_AND: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_OR: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_NOT: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_XOR: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_INV: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_MOD: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_SHL: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_SHR: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_DOT: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LARGE: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LARGEEUQ: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LESS: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LESSEQU: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_UNEQU: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_EQU: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LGEQU: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LAND: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LOR: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_ADR: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_OFT: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_PTR: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_INT: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_FLOAT: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_STRING: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_MEMORY: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_MEMLEN: + case PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_STRLEN: + { + if (pVec[*offset].type==PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_DOT||pVec[*offset].type==PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_OFT) + { + if (pcurrentSet==PX_NULL) + { + goto _ERROR; + } + } + else + { + pcurrentSet=PX_NULL; + } + if (level>pVec[*offset].oplevel) + { + level=pVec[*offset].oplevel; + if(!PX_ScriptParseAST_PushOpcode(analysis,op,pVec[*offset])) goto _ERROR;; + } + else + { + level=pVec[*offset].oplevel; + do{ + if(op->size>0) + { + if(!PX_ScriptParseLastInstr(analysis,op,tk,out)) goto _ERROR;; + if(op->size) + plastop=PX_VECTORAT(PX_SCRIPT_AST_OPCODE,op,op->size-1); + } + else + break; + }while(op->size&&plastop->level<=level); + if(!PX_ScriptParseAST_PushOpcode(analysis,op,pVec[*offset])) goto _ERROR;; + } + } + break; + default: + { + goto _ERROR; + } + } + (*offset)++; + } + + PX_VectorFree(op); + PX_VectorFree(tk); + return PX_TRUE; +_ERROR: + PX_VectorFree(op); + PX_VectorFree(tk); + return PX_FALSE; +} +#define PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE 1 +#define PX_SCRIPT_EXPRESSION_ACCEPT_BINARY 2 +#define PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN 4 +#define PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START 8 +#define PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_END 16 +#define PX_SCRIPT_EXPRESSION_ACCEPT_MBRACKET_START 32 +#define PX_SCRIPT_EXPRESSION_ACCEPT_MBRACKET_END 16 +#define PX_SCRIPT_EXPRESSION_ACCEPT_BRACKET_START (PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START|PX_SCRIPT_EXPRESSION_ACCEPT_MBRACKET_START) +#define PX_SCRIPT_EXPRESSION_ACCEPT_BRACKET_END (PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_END|PX_SCRIPT_EXPRESSION_ACCEPT_MBRACKET_END) +static px_bool PX_ScriptParseExpression(PX_SCRIPT_Analysis *analysis,px_char *expr,px_string *out,PX_SCRIPT_AST_OPERAND *retOperand) +{ + px_int i; + px_uint quotes; + px_vector stream,opStack,tkStack; + px_lexer lexer; + PX_LEXER_STATE state; + PX_LEXER_LEXEME_TYPE type; + px_int streamOft=1; + px_int accept_type; + PX_SCRIPT_AST_OPERAND operand; + + px_bool ret=PX_TRUE; + + PX_SCRIPT_EXPR_STREAM Op; + + if (PX_strlen(expr)==0) + { + retOperand->operandType=PX_SCRIPT_AST_OPERAND_TYPE_VOID; + retOperand->region=PX_SCRIPT_VARIABLE_REGION_GLOBAL; + return PX_TRUE; + } + + PX_StringClear(out); + + + PX_LexerInit(&lexer,analysis->mp); + PX_LexerRegisterDelimiter(&lexer,','); + PX_LexerRegisterDelimiter(&lexer,';'); + PX_LexerRegisterDelimiter(&lexer,'+'); + PX_LexerRegisterDelimiter(&lexer,'-'); + PX_LexerRegisterDelimiter(&lexer,'*'); + PX_LexerRegisterDelimiter(&lexer,'/'); + PX_LexerRegisterDelimiter(&lexer,'%'); + PX_LexerRegisterDelimiter(&lexer,'&'); + PX_LexerRegisterDelimiter(&lexer,'|'); + PX_LexerRegisterDelimiter(&lexer,'^'); + PX_LexerRegisterDelimiter(&lexer,'~'); + PX_LexerRegisterDelimiter(&lexer,'('); + PX_LexerRegisterDelimiter(&lexer,')'); + PX_LexerRegisterDelimiter(&lexer,'!'); + PX_LexerRegisterDelimiter(&lexer,'='); + PX_LexerRegisterDelimiter(&lexer,'>'); + PX_LexerRegisterDelimiter(&lexer,'<'); + PX_LexerRegisterDelimiter(&lexer,'{'); + PX_LexerRegisterDelimiter(&lexer,'}'); + PX_LexerRegisterDelimiter(&lexer,'['); + PX_LexerRegisterDelimiter(&lexer,']'); + PX_LexerRegisterDelimiter(&lexer,'.'); + PX_LexerRegisterSpacer(&lexer,' '); + PX_LexerRegisterSpacer(&lexer,'\t'); + quotes=PX_LexerRegisterContainer(&lexer,"\"","\""); + PX_LexerRegisterContainerTransfer(&lexer,quotes,'\\'); + PX_LexerRegisterContainer(&lexer,"\'","\'"); + PX_LexerRegisterContainer(&lexer,"@","@"); + PX_LexerSetTokenCase(&lexer,PX_LEXER_LEXEME_CASE_UPPER); + + PX_LexerSetNumericMatch(&lexer,PX_TRUE); + + + if(!PX_LexerLoadSourceFromMemory(&lexer,expr)) + return PX_FALSE; + + PX_VectorInitialize(analysis->mp,&stream,sizeof(PX_SCRIPT_EXPR_STREAM),32); + PX_VectorInitialize(analysis->mp,&opStack,sizeof(PX_SCRIPT_AST_OPCODE),32); + PX_VectorInitialize(analysis->mp,&tkStack,sizeof(PX_SCRIPT_AST_OPERAND),32); + + // + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE|PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN|PX_SCRIPT_EXPRESSION_ACCEPT_BRACKET_START; + + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LBRACKETBEGIN; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_CONTAINER; + Op.oplevel=0; + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,lexer.CurLexeme.buffer); + PX_VectorPushback(&stream,&Op); + + while (PX_TRUE) + { + type=PX_ScriptTranslatorNextToken(&lexer); + if (type==PX_LEXER_LEXEME_TYPE_END) + { + break; + } + + if (type==PX_LEXER_LEXEME_TYPE_TOKEN) + { + ////////////////////////////////////////////////////////////////////////// + //key word + if (PX_strequ(lexer.CurLexeme.buffer,"STRLEN")) + { + if ((accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE)==0) + { + ret=PX_FALSE; + goto _CLEAR; + } + else + { + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START; + } + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_STRLEN; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_SINGLE; + Op.oplevel=1; + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,lexer.CurLexeme.buffer); + PX_VectorPushback(&stream,&Op); + } + else if (PX_strequ(lexer.CurLexeme.buffer,"MEMLEN")) + { + if ((accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE)==0) + { + ret=PX_FALSE; + goto _CLEAR; + } + else + { + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START; + } + + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_MEMLEN; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_SINGLE; + Op.oplevel=1; + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,lexer.CurLexeme.buffer); + PX_VectorPushback(&stream,&Op); + } + else if (PX_strequ(lexer.CurLexeme.buffer,"INT")) + { + if ((accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE)==0) + { + ret=PX_FALSE; + goto _CLEAR; + } + else + { + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START; + } + + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_INT; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_SINGLE; + Op.oplevel=1; + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,lexer.CurLexeme.buffer); + PX_VectorPushback(&stream,&Op); + } + else if (PX_strequ(lexer.CurLexeme.buffer,"FLOAT")) + { + if ((accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE)==0) + { + ret=PX_FALSE; + goto _CLEAR; + } + else + { + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START; + } + + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_FLOAT; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_SINGLE; + Op.oplevel=1; + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,lexer.CurLexeme.buffer); + PX_VectorPushback(&stream,&Op); + } + else if (PX_strequ(lexer.CurLexeme.buffer,"STRING")) + { + if ((accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE)==0) + { + ret=PX_FALSE; + goto _CLEAR; + } + else + { + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START; + } + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_STRING; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_SINGLE; + Op.oplevel=1; + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,lexer.CurLexeme.buffer); + PX_VectorPushback(&stream,&Op); + } + else if (PX_strequ(lexer.CurLexeme.buffer,"MEMORY")) + { + if ((accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE)==0) + { + ret=PX_FALSE; + goto _CLEAR; + } + else + { + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START; + } + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_MEMORY; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_SINGLE; + Op.oplevel=1; + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,lexer.CurLexeme.buffer); + PX_VectorPushback(&stream,&Op); + } + else if (PX_ScriptParseIsValidToken(lexer.CurLexeme.buffer)) + { + if ((accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN)==0) + { + ret=PX_FALSE; + goto _CLEAR; + } + + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,lexer.CurLexeme.buffer); + + state=PX_LexerGetState(&lexer); + type=PX_ScriptTranslatorNextToken(&lexer); + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER&&lexer.Symbol=='(') + { + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_FUNCTION; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_FUNC; + Op.oplevel=0; + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START; + } + else + { + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_TOKEN; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_VAR; + Op.oplevel=0; + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_BINARY|PX_SCRIPT_EXPRESSION_ACCEPT_MBRACKET_START|PX_SCRIPT_EXPRESSION_ACCEPT_BRACKET_END; + } + PX_VectorPushback(&stream,&Op); + + PX_LexerSetState(state); + + } + else if(PX_strIsNumeric(lexer.CurLexeme.buffer)) + { + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_BINARY|PX_SCRIPT_EXPRESSION_ACCEPT_BRACKET_END; + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_TOKEN; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_CONST; + Op.oplevel=0; + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,lexer.CurLexeme.buffer); + PX_VectorPushback(&stream,&Op); + } + else if(lexer.CurLexeme.buffer[0]=='0'&&lexer.CurLexeme.buffer[1]=='X') + { + for (i=2;lexer.CurLexeme.buffer[i];i++) + { + if (lexer.CurLexeme.buffer[i]>='0'&&lexer.CurLexeme.buffer[i]<='F') + { + continue; + } + else + { + ret=PX_FALSE; + PX_ScriptTranslatorError(&analysis->lexer,"Illegal hexadecimal."); + goto _CLEAR; + } + } + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_BINARY|PX_SCRIPT_EXPRESSION_ACCEPT_BRACKET_END; + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_TOKEN; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_CONST; + Op.oplevel=0; + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,lexer.CurLexeme.buffer); + PX_VectorPushback(&stream,&Op); + } + else + { + ret=PX_FALSE; + PX_ScriptTranslatorError(&analysis->lexer,"Unexpected opcode."); + goto _CLEAR; + } + } + else if (type==PX_LEXER_LEXEME_TYPE_CONATINER) + { + if (lexer.CurrentContainerType==quotes) + { + PX_StringReplace(&lexer.CurLexeme,"\n","\\n"); + PX_StringReplace(&lexer.CurLexeme,"\r","\\r"); + } + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_TOKEN; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_CONTAINER; + Op.oplevel=0; + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,lexer.CurLexeme.buffer); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_BINARY|PX_SCRIPT_EXPRESSION_ACCEPT_BRACKET_END; + } + else if (type==PX_LEXER_LEXEME_TYPE_DELIMITER) + { + switch(lexer.Symbol) + { + case '+': + { + if ((accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_BINARY)==0&&(accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE)==0) + { + ret=PX_FALSE; + goto _CLEAR; + } + state=PX_LexerGetState(&lexer); + + if(PX_LexerGetNextLexeme(&lexer)==PX_LEXER_LEXEME_TYPE_DELIMITER&&lexer.Symbol=='+') + { + if (accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_BINARY) + { + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_INC; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_SINGLE; + Op.oplevel=PX_ScriptParseGetOpLevel("++",PX_FALSE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,"++"); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_BINARY|PX_SCRIPT_EXPRESSION_ACCEPT_BRACKET_END; + } + else + { + ret=PX_FALSE; + goto _CLEAR; + } + } + else + { + PX_LexerSetState(state); + + if (accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_BINARY) + { + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_ADD; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_BINARY; + Op.oplevel=PX_ScriptParseGetOpLevel("+",PX_TRUE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,"+"); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN|PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START|PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE; + } + else + { + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_POSITIVE; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_SINGLE; + Op.oplevel=PX_ScriptParseGetOpLevel("+",PX_FALSE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,"+"); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN|PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START; + } + } + + + } + break; + + case '-': + { + if ((accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_BINARY)==0&&(accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE)==0) + { + ret=PX_FALSE; + goto _CLEAR; + } + + state=PX_LexerGetState(&lexer); + type=PX_LexerGetNextLexeme(&lexer); + if(type==PX_LEXER_LEXEME_TYPE_DELIMITER&&lexer.Symbol=='>') + { + if (accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_BINARY) + { + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_OFT; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_BINARY; + Op.oplevel=PX_ScriptParseGetOpLevel("->",PX_TRUE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,"->"); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN; + } + else + { + ret=PX_FALSE; + goto _CLEAR; + } + } + else if(type==PX_LEXER_LEXEME_TYPE_DELIMITER&&lexer.Symbol=='-') + { + if (accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_BINARY) + { + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_DEC; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_SINGLE; + Op.oplevel=PX_ScriptParseGetOpLevel("--",PX_FALSE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,"--"); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_BINARY|PX_SCRIPT_EXPRESSION_ACCEPT_BRACKET_END; + } + else + { + ret=PX_FALSE; + goto _CLEAR; + } + } + else + { + PX_LexerSetState(state); + if (accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_BINARY) + { + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_SUB; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_BINARY; + Op.oplevel=PX_ScriptParseGetOpLevel("-",PX_TRUE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,"-"); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN|PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START|PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE; + } + else + { + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_NEGATIVE; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_SINGLE; + Op.oplevel=PX_ScriptParseGetOpLevel("-",PX_FALSE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,"-"); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN|PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START; + } + } + + } + break; + + case '*': + { + if ((accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_BINARY)==0&&(accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE)==0) + { + ret=PX_FALSE; + goto _CLEAR; + } + + if (accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_BINARY) + { + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_MUL; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_BINARY; + Op.oplevel=PX_ScriptParseGetOpLevel("*",PX_TRUE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,"*"); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN|PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START|PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE; + } + else + { + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_PTR; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_SINGLE; + Op.oplevel=PX_ScriptParseGetOpLevel("*",PX_FALSE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,"*"); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN|PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START; + } + + } + break; + + case '/': + { + + if ((accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_BINARY)==0) + { + ret=PX_FALSE; + PX_ScriptTranslatorError(&analysis->lexer,"Unexpected opcode."); + goto _CLEAR; + } + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_DIV; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_BINARY; + Op.oplevel=PX_ScriptParseGetOpLevel("/",PX_TRUE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,"/"); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN|PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START|PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE; + } + break; + + case '[': + { + if ((accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_MBRACKET_START)==0) + { + ret=PX_FALSE; + PX_ScriptTranslatorError(&analysis->lexer,"Unexpected opcode."); + goto _CLEAR; + } + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_MBRACKETBEGIN; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_CONTAINER; + Op.oplevel=PX_ScriptParseGetOpLevel("[",PX_FALSE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,"["); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN|PX_SCRIPT_EXPRESSION_ACCEPT_BRACKET_START|PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE; + } + break; + + case ']': + { + if ((accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_MBRACKET_END)==0) + { + ret=PX_FALSE; + PX_ScriptTranslatorError(&analysis->lexer,"Unexpected opcode."); + goto _CLEAR; + } + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_MBRACKETEND; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_CONTAINER; + Op.oplevel=PX_ScriptParseGetOpLevel("]",PX_FALSE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,"]"); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_BINARY|PX_SCRIPT_EXPRESSION_ACCEPT_BRACKET_END; + } + break; + + case '(': + { + if ((accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START)==0) + { + ret=PX_FALSE; + PX_ScriptTranslatorError(&analysis->lexer,"Unexpected opcode."); + goto _CLEAR; + } + + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LBRACKETBEGIN; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_CONTAINER; + Op.oplevel=PX_ScriptParseGetOpLevel("(",PX_FALSE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,"("); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN|PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START|PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_END|PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE; + } + break; + + case ')': + { + if ((accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_END)==0) + { + ret=PX_FALSE; + PX_ScriptTranslatorError(&analysis->lexer,"Unexpected opcode."); + goto _CLEAR; + } + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LBRACKETEND; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_CONTAINER; + Op.oplevel=PX_ScriptParseGetOpLevel(")",PX_FALSE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,")"); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_BINARY|PX_SCRIPT_EXPRESSION_ACCEPT_BRACKET_END|PX_SCRIPT_EXPRESSION_ACCEPT_MBRACKET_START; + } + break; + + case '.': + { + if ((accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_BINARY)==0) + { + ret=PX_FALSE; + PX_ScriptTranslatorError(&analysis->lexer,"Unexpected opcode."); + goto _CLEAR; + } + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_DOT; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_SINGLE; + Op.oplevel=PX_ScriptParseGetOpLevel(lexer.CurLexeme.buffer,PX_FALSE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,"."); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN; + } + break; + + case '!': + { + state=PX_LexerGetState(&lexer); + type=PX_LexerGetNextLexeme(&lexer); + if(type!=PX_LEXER_LEXEME_TYPE_DELIMITER) + { + PX_LexerSetState(state); + + if ((accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE)==0) + { + ret=PX_FALSE; + PX_ScriptTranslatorError(&analysis->lexer,"Unexpected opcode."); + goto _CLEAR; + } + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_NOT; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_SINGLE; + Op.oplevel=PX_ScriptParseGetOpLevel("!",PX_FALSE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,"!"); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START|PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN; + } + else if (lexer.Symbol=='=') + { + if ((accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_BINARY)==0) + { + ret=PX_FALSE; + PX_ScriptTranslatorError(&analysis->lexer,"Unexpected opcode."); + goto _CLEAR; + } + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_UNEQU; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_BINARY; + Op.oplevel=PX_ScriptParseGetOpLevel("!=",PX_TRUE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,"!="); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START|PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN|PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE; + } + else if (lexer.Symbol=='(') + { + PX_LexerSetState(state); + + if ((accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE)==0) + { + ret=PX_FALSE; + PX_ScriptTranslatorError(&analysis->lexer,"Unexpected opcode."); + goto _CLEAR; + } + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_NOT; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_SINGLE; + Op.oplevel=PX_ScriptParseGetOpLevel("!",PX_FALSE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,"!"); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START|PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN; + } + else + { + ret=PX_FALSE; + PX_ScriptTranslatorError(&analysis->lexer,"Unexpected opcode."); + goto _CLEAR; + } + + } + break; + + case '~': + { + if ((accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE)==0) + { + ret=PX_FALSE; + PX_ScriptTranslatorError(&analysis->lexer,"Unexpected opcode."); + goto _CLEAR; + } + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_INV; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_SINGLE; + Op.oplevel=PX_ScriptParseGetOpLevel("~",PX_FALSE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,"~"); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START|PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN; + } + break; + + case '^': + { + if ((accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_BINARY)==0) + { + ret=PX_FALSE; + PX_ScriptTranslatorError(&analysis->lexer,"Unexpected opcode."); + goto _CLEAR; + } + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_XOR; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_BINARY; + Op.oplevel=PX_ScriptParseGetOpLevel("^",PX_TRUE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,"^"); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START|PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN|PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE; + } + break; + + case '%': + { + if ((accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_BINARY)==0) + { + ret=PX_FALSE; + PX_ScriptTranslatorError(&analysis->lexer,"Unexpected opcode."); + goto _CLEAR; + } + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_MOD; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_SINGLE; + Op.oplevel=PX_ScriptParseGetOpLevel(lexer.CurLexeme.buffer,PX_TRUE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,"%"); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START|PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN|PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE; + } + break; + + + case '<': + { + if ((accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_BINARY)==0) + { + ret=PX_FALSE; + PX_ScriptTranslatorError(&analysis->lexer,"Unexpected opcode."); + goto _CLEAR; + } + + state=PX_LexerGetState(&lexer); + + if(PX_LexerGetNextLexeme(&lexer)!=PX_LEXER_LEXEME_TYPE_DELIMITER) + { + PX_LexerSetState(state); + + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LESS; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_BINARY; + Op.oplevel=PX_ScriptParseGetOpLevel("<",PX_TRUE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,"<"); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START|PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN|PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE; + } + else if (lexer.Symbol=='<') + { + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_SHL; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_BINARY; + Op.oplevel=PX_ScriptParseGetOpLevel("<<",PX_TRUE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,"<<"); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START|PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN|PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE; + } + else if (lexer.Symbol=='=') + { + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LESSEQU; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_BINARY; + Op.oplevel=PX_ScriptParseGetOpLevel("<=",PX_TRUE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,"<="); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START|PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN|PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE; + } + else + { + ret=PX_FALSE; + PX_ScriptTranslatorError(&analysis->lexer,"Unexpected opcode."); + goto _CLEAR; + } + + } + break; + + case '>': + { + if ((accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_BINARY)==0) + { + ret=PX_FALSE; + PX_ScriptTranslatorError(&analysis->lexer,"Unexpected opcode."); + goto _CLEAR; + } + + state=PX_LexerGetState(&lexer); + + if(PX_LexerGetNextLexeme(&lexer)!=PX_LEXER_LEXEME_TYPE_DELIMITER) + { + PX_LexerSetState(state); + + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LARGE; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_BINARY; + Op.oplevel=PX_ScriptParseGetOpLevel(">",PX_TRUE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,">"); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START|PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN|PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE; + } + else if (lexer.Symbol=='>') + { + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_SHR; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_BINARY; + Op.oplevel=PX_ScriptParseGetOpLevel(">>",PX_TRUE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,">>"); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START|PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN|PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE; + } + else if (lexer.Symbol=='=') + { + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LARGEEUQ; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_BINARY; + Op.oplevel=PX_ScriptParseGetOpLevel(">=",PX_TRUE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,">="); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START|PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN|PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE; + } + else + { + ret=PX_FALSE; + PX_ScriptTranslatorError(&analysis->lexer,"Unexpected opcode."); + goto _CLEAR; + } + + } + break; + + case '=': + { + if ((accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_BINARY)==0) + { + ret=PX_FALSE; + PX_ScriptTranslatorError(&analysis->lexer,"Unexpected opcode."); + goto _CLEAR; + } + + state=PX_LexerGetState(&lexer); + + if(PX_LexerGetNextLexeme(&lexer)==PX_LEXER_LEXEME_TYPE_DELIMITER&&lexer.Symbol=='=') + { + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LGEQU; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_BINARY; + Op.oplevel=PX_ScriptParseGetOpLevel("==",PX_TRUE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,"=="); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START|PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN|PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE; + } + else + { + PX_LexerSetState(state); + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_EQU; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_BINARY; + Op.oplevel=PX_ScriptParseGetOpLevel("=",PX_TRUE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,"="); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START|PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN|PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE; + continue; + } + } + break; + + + case '&': + { + if ((accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_BINARY)==0&&(accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE)==0) + { + ret=PX_FALSE; + goto _CLEAR; + } + + if (accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_BINARY) + { + state=PX_LexerGetState(&lexer); + + if(PX_LexerGetNextLexeme(&lexer)!=PX_LEXER_LEXEME_TYPE_DELIMITER) + { + if ((accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_BINARY)==0) + { + ret=PX_FALSE; + goto _CLEAR; + } + + PX_LexerSetState(state); + + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_AND; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_BINARY; + Op.oplevel=PX_ScriptParseGetOpLevel("&",PX_TRUE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,"&"); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START|PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN|PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE; + } + else if (lexer.Symbol=='&') + { + if ((accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_BINARY)==0) + { + ret=PX_FALSE; + goto _CLEAR; + } + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LAND; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_BINARY; + Op.oplevel=PX_ScriptParseGetOpLevel("&&",PX_TRUE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,"&&"); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START|PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN|PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE; + } + else if (lexer.Symbol=='(') + { + if ((accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_BINARY)==0) + { + ret=PX_FALSE; + goto _CLEAR; + } + + PX_LexerSetState(state); + + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_AND; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_BINARY; + Op.oplevel=PX_ScriptParseGetOpLevel("&",PX_TRUE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,"&"); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START|PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN|PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE; + } + else + { + ret=PX_FALSE; + PX_ScriptTranslatorError(&analysis->lexer,"Unexpected opcode."); + goto _CLEAR; + } + } + else + { + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_ADR; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_SINGLE; + Op.oplevel=PX_ScriptParseGetOpLevel("&",PX_FALSE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,"&"); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN; + } + + + } + break; + + case '|': + { + if ((accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_BINARY)==0) + { + ret=PX_FALSE; + PX_ScriptTranslatorError(&analysis->lexer,"Unexpected opcode."); + goto _CLEAR; + } + + state=PX_LexerGetState(&lexer); + + if(PX_LexerGetNextLexeme(&lexer)!=PX_LEXER_LEXEME_TYPE_DELIMITER) + { + PX_LexerSetState(state); + + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_OR; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_BINARY; + Op.oplevel=PX_ScriptParseGetOpLevel("|",PX_TRUE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,"|"); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START|PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN|PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE; + } + else if (lexer.Symbol=='|') + { + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LAND; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_BINARY; + Op.oplevel=PX_ScriptParseGetOpLevel("||",PX_TRUE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,"||"); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START|PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN|PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE; + } + else if (lexer.Symbol=='(') + { + PX_LexerSetState(state); + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_OR; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_BINARY; + Op.oplevel=PX_ScriptParseGetOpLevel("|",PX_TRUE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,"|"); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START|PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN|PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE; + } + else + { + ret=PX_FALSE; + PX_ScriptTranslatorError(&analysis->lexer,"Unexpected opcode."); + goto _CLEAR; + } + + } + break; + + case ',': + { + if ((accept_type&PX_SCRIPT_EXPRESSION_ACCEPT_BINARY)==0) + { + ret=PX_FALSE; + PX_ScriptTranslatorError(&analysis->lexer,"Unexpected opcode."); + goto _CLEAR; + } + + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_COMMA; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_BINARY; + Op.oplevel=PX_ScriptParseGetOpLevel(",",PX_TRUE); + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,","); + PX_VectorPushback(&stream,&Op); + accept_type=PX_SCRIPT_EXPRESSION_ACCEPT_LBRACKET_START|PX_SCRIPT_EXPRESSION_ACCEPT_TOKEN|PX_SCRIPT_EXPRESSION_ACCEPT_SINGLE; + } + break; + } + } + } + + Op.type=PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LBRACKETEND; + Op.opclass=PX_SCRIPT_TRANSLATOR_OP_CLASS_CONTAINER; + Op.oplevel=0; + PX_StringInitialize(analysis->mp,&Op.code); + PX_StringCat(&Op.code,lexer.CurLexeme.buffer); + PX_VectorPushback(&stream,&Op); + PX_StringCat(out,";--------"); + + for(i=0;icode); + } + PX_VectorFree(&stream); + + for (i=0;icode); + } + PX_VectorFree(&opStack); + + for (i=0;ilexer); + if (type!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + return PX_FALSE; + } + + if (PX_strequ(analysis->lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_INT)) + { + resType=PX_SCRIPT_PARSER_VAR_TYPE_INT; + } + else if (PX_strequ(analysis->lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_FLOAT)) + { + resType=PX_SCRIPT_PARSER_VAR_TYPE_FLOAT; + } + else if (PX_strequ(analysis->lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_STRING)) + { + resType=PX_SCRIPT_PARSER_VAR_TYPE_STRING; + } + else if (PX_strequ(analysis->lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_MEMORY)) + { + resType=PX_SCRIPT_PARSER_VAR_TYPE_MEMORY; + } + else + { + goto _ERROR; + } + + while(PX_TRUE) + { + PX_memset(&variable,0,sizeof(variable)); + variable.bParam=PX_FALSE; + variable.bInitialized=PX_FALSE; + variable.BeginIndex=-1; + variable.size=-1; + variable.type=resType; + variable.layer=analysis->v_astStructure.size; + + type=PX_ScriptTranslatorNextToken(&analysis->lexer); + + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER&&analysis->lexer.Symbol=='*') + { + switch(variable.type) + { + case PX_SCRIPT_PARSER_VAR_TYPE_INT: + { + variable.type=PX_SCRIPT_PARSER_VAR_TYPE_INT_PTR; + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_FLOAT: + { + variable.type=PX_SCRIPT_PARSER_VAR_TYPE_FLOAT_PTR; + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_STRING: + { + variable.type=PX_SCRIPT_PARSER_VAR_TYPE_STRING_PTR; + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_MEMORY: + { + variable.type=PX_SCRIPT_PARSER_VAR_TYPE_MEMORY_PTR; + } + break; + default: + goto _ERROR; + } + + type=PX_ScriptTranslatorNextToken(&analysis->lexer); + } + + if (type!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + return PX_FALSE; + } + + if (!PX_ScriptParseIsValidToken(analysis->lexer.CurLexeme.buffer)) + { + PX_ScriptTranslatorError(&analysis->lexer,"Invalid var token"); + goto _ERROR; + } + + PX_StringInitialize(analysis->mp,&variable.Mnemonic); + PX_StringCat(&variable.Mnemonic,analysis->lexer.CurLexeme.buffer); + + type=PX_ScriptTranslatorNextToken(&analysis->lexer); + + if (type!=PX_LEXER_LEXEME_TYPE_DELIMITER) + { + PX_ScriptTranslatorError(&analysis->lexer,"Invalid var token"); + PX_StringFree(&variable.Mnemonic); + goto _ERROR; + } + + + if (analysis->lexer.Symbol=='[') + { + + switch(variable.type) + { + case PX_SCRIPT_PARSER_VAR_TYPE_INT: + { + variable.type=PX_SCRIPT_PARSER_VAR_TYPE_INT_ARRAY; + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_FLOAT: + { + variable.type=PX_SCRIPT_PARSER_VAR_TYPE_FLOAT_ARRAY; + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_STRING: + { + variable.type=PX_SCRIPT_PARSER_VAR_TYPE_STRING_ARRAY; + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_MEMORY: + { + variable.type=PX_SCRIPT_PARSER_VAR_TYPE_MEMORY_ARRAY; + } + break; + + default: + goto _ERROR; + } + + if(PX_ScriptTranslatorNextToken(&analysis->lexer)!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + PX_ScriptTranslatorError(&analysis->lexer,"Invalid var token"); + PX_StringFree(&variable.Mnemonic); + goto _ERROR; + } + + if(!PX_strIsNumeric(analysis->lexer.CurLexeme.buffer)) + { + PX_ScriptTranslatorError(&analysis->lexer,"Invalid var token"); + } + + variable.size=PX_atoi(analysis->lexer.CurLexeme.buffer); + + if (variable.size==0) + { + PX_ScriptTranslatorError(&analysis->lexer,"Invalid array"); + PX_StringFree(&variable.Mnemonic); + goto _ERROR; + } + + type=PX_ScriptTranslatorNextToken(&analysis->lexer); + + if (type!=PX_LEXER_LEXEME_TYPE_DELIMITER||analysis->lexer.Symbol!=']') + { + PX_ScriptTranslatorError(&analysis->lexer,"Invalid var token"); + PX_StringFree(&variable.Mnemonic); + goto _ERROR; + } + + type=PX_ScriptTranslatorNextToken(&analysis->lexer); + } + else if(analysis->lexer.Symbol=='=') + { + variable.size=1; + variable.bInitialized=PX_TRUE; + PX_StringInitialize(analysis->mp,&variable.GlobalInitializeValue); + while(PX_TRUE) + { + type=PX_ScriptTranslatorNextToken(&analysis->lexer); + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER&&analysis->lexer.Symbol==';') + { + break; + } + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER&&analysis->lexer.Symbol==',') + { + break; + } + if (type==PX_LEXER_LEXEME_TYPE_END) + { + PX_ScriptTranslatorError(&analysis->lexer,"Error Expression."); + PX_StringFree(&variable.Mnemonic); + PX_StringFree(&variable.GlobalInitializeValue); + goto _ERROR; + } + PX_StringCat(&variable.GlobalInitializeValue,analysis->lexer.CurLexeme.buffer); + } + + if (PX_strlen(variable.GlobalInitializeValue.buffer)==0) + { + PX_ScriptTranslatorError(&analysis->lexer,"Error Expression."); + PX_StringFree(&variable.Mnemonic); + PX_StringFree(&variable.GlobalInitializeValue); + goto _ERROR; + } + + } + else + { + variable.size=1; + } + + + if (analysis->functionInside) + { + + for (i=0;iv_variablesStackTable.size;i++) + { + if (PX_strequ(variable.Mnemonic.buffer,PX_VECTORAT(PX_SCRIPT_VARIABLES,&analysis->v_variablesStackTable,i)->Mnemonic.buffer)) + { + PX_ScriptTranslatorError(&analysis->lexer,"variable redefined."); + PX_StringFree(&variable.Mnemonic); + if(variable.bInitialized) + PX_StringFree(&variable.GlobalInitializeValue); + goto _ERROR; + } + } + + pvar=PX_VECTORAT(PX_SCRIPT_VARIABLES,&analysis->v_variablesStackTable,analysis->v_variablesStackTable.size-1); + variable.BeginIndex=pvar->BeginIndex+variable.size; + + if (variable.BeginIndex+variable.size-1>analysis->currentAllocStackSize) + { + analysis->currentAllocStackSize=variable.BeginIndex+variable.size-1; + } + + PX_VectorPushback(&analysis->v_variablesStackTable,&variable); + + ////////////////////////////////////////////////////////////////////////// + if(variable.bInitialized) + { + px_string code; + px_string exprgen; + PX_SCRIPT_AST_OPERAND retOperand; + PX_StringInitialize(analysis->mp,&code); + PX_StringInitialize(analysis->mp,&exprgen); + PX_StringFormat2(&code,"%1=%2",PX_STRINGFORMAT_STRING(variable.Mnemonic.buffer),PX_STRINGFORMAT_STRING(variable.GlobalInitializeValue.buffer)); + if (!PX_ScriptParseExpression(analysis,code.buffer,&exprgen,&retOperand)) + { + PX_StringFree(&code); + PX_StringFree(&exprgen); + return PX_FALSE; + } + PX_StringCat(&analysis->code,exprgen.buffer); + PX_StringFree(&exprgen); + PX_StringFree(&code); + + } + else + { + if (variable.type==PX_SCRIPT_PARSER_VAR_TYPE_STRING) + { + px_string code; + px_string exprgen; + PX_SCRIPT_AST_OPERAND retOperand; + PX_StringInitialize(analysis->mp,&code); + PX_StringInitialize(analysis->mp,&exprgen); + PX_StringFormat1(&code,"%1=\"\"",PX_STRINGFORMAT_STRING(variable.Mnemonic.buffer)); + if (!PX_ScriptParseExpression(analysis,code.buffer,&exprgen,&retOperand)) + { + PX_StringFree(&code); + PX_StringFree(&exprgen); + return PX_FALSE; + } + PX_StringCat(&analysis->code,exprgen.buffer); + PX_StringFree(&exprgen); + PX_StringFree(&code); + } + + if (variable.type==PX_SCRIPT_PARSER_VAR_TYPE_MEMORY) + { + px_string code; + px_string exprgen; + PX_SCRIPT_AST_OPERAND retOperand; + PX_StringInitialize(analysis->mp,&code); + PX_StringInitialize(analysis->mp,&exprgen); + PX_StringFormat1(&code,"%1=@@",PX_STRINGFORMAT_STRING(variable.Mnemonic.buffer)); + if (!PX_ScriptParseExpression(analysis,code.buffer,&exprgen,&retOperand)) + { + PX_StringFree(&code); + PX_StringFree(&exprgen); + return PX_FALSE; + } + PX_StringCat(&analysis->code,exprgen.buffer); + PX_StringFree(&exprgen); + PX_StringFree(&code); + } + + if (variable.type==PX_SCRIPT_PARSER_VAR_TYPE_STRUCT) + { + px_string code; + PX_SCRIPT_STRUCT *pset=PX_ScriptParseGetStructByIndex(analysis,variable.setIndex); + PX_StringInitialize(analysis->mp,&code); + if (pset) + { + px_int j; + for (j=0;jmembers.size;j++) + { + pvar=PX_VECTORAT(PX_SCRIPT_VARIABLES,&pset->members,j); + + if (!pvar->bParam&&pvar->type==PX_SCRIPT_PARSER_VAR_TYPE_STRING) + { + PX_StringFormat1(&code,"MOV LOCAL[%1],\"\"\n",PX_STRINGFORMAT_INT(pvar->BeginIndex)); + PX_StringCat(&analysis->code,code.buffer); + } + if (!pvar->bParam&&pvar->type==PX_SCRIPT_PARSER_VAR_TYPE_MEMORY) + { + PX_StringFormat1(&code,"MOV LOCAL[%1],@@\n",PX_STRINGFORMAT_INT(pvar->BeginIndex)); + PX_StringCat(&analysis->code,code.buffer); + } + } + } + PX_StringFree(&code); + } + }; + ////////////////////////////////////////////////////////////////////////// + } + else + { + for (i=0;iv_variablesGlobalTable.size;i++) + { + if (PX_strequ(variable.Mnemonic.buffer,PX_VECTORAT(PX_SCRIPT_VARIABLES,&analysis->v_variablesGlobalTable,i)->Mnemonic.buffer)) + { + PX_ScriptTranslatorError(&analysis->lexer,"variable redefined."); + PX_StringFree(&variable.Mnemonic); + if(variable.bInitialized) + PX_StringFree(&variable.GlobalInitializeValue); + goto _ERROR; + } + } + + if (analysis->v_variablesGlobalTable.size==0) + { + variable.BeginIndex=0; + } + else + { + pvar=PX_VECTORAT(PX_SCRIPT_VARIABLES,&analysis->v_variablesGlobalTable,analysis->v_variablesGlobalTable.size-1); + variable.BeginIndex=pvar->BeginIndex+pvar->size; + } + + + PX_VectorPushback(&analysis->v_variablesGlobalTable,&variable); + } + + if(analysis->lexer.Symbol==',') + { + continue; + } + else if(analysis->lexer.Symbol==';') + { + break; + } + else + { + PX_ScriptTranslatorError(&analysis->lexer,"Invalid var token"); + PX_StringFree(&variable.Mnemonic); + goto _ERROR; + } + } + + return PX_TRUE; +_ERROR: + return PX_FALSE; +} +static px_bool PX_ScriptParseStruct(PX_SCRIPT_Analysis *analysis) +{ + PX_LEXER_LEXEME_TYPE type; + PX_SCRIPT_VARIABLES variable,*pvar; + PX_SCRIPT_STRUCT *pset; + PX_LEXER_STATE state; + px_int i; + variable.bParam=PX_FALSE; + variable.bInitialized=PX_FALSE; + variable.BeginIndex=-1; + variable.size=-1; + variable.type=PX_SCRIPT_PARSER_VAR_TYPE_STRUCT; + + + type=PX_ScriptTranslatorNextToken(&analysis->lexer); + + if (type!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + return PX_FALSE; + } + + if (!PX_ScriptParseIsValidToken(analysis->lexer.CurLexeme.buffer)) + { + PX_ScriptTranslatorError(&analysis->lexer,"Invalid struct name"); + goto _ERROR; + } + + if (!(pset=PX_ScriptParseGetStructInfo(analysis,analysis->lexer.CurLexeme.buffer))) + { + PX_ScriptTranslatorError(&analysis->lexer,"Invalid struct type"); + goto _ERROR; + } + + variable.setIndex=PX_ScriptParseGetSetIndex(analysis,analysis->lexer.CurLexeme.buffer); + variable.layer=analysis->v_astStructure.size; + + while(PX_TRUE) + { + type=PX_ScriptTranslatorNextToken(&analysis->lexer); + + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER&&analysis->lexer.Symbol=='*') + { + variable.size=1; + variable.type=PX_SCRIPT_PARSER_VAR_TYPE_STRUCT_PTR; + type=PX_ScriptTranslatorNextToken(&analysis->lexer); + } + + if (type!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + return PX_FALSE; + } + + if (!PX_ScriptParseIsValidToken(analysis->lexer.CurLexeme.buffer)) + { + PX_ScriptTranslatorError(&analysis->lexer,"Invalid struct name"); + goto _ERROR; + } + + PX_StringInitialize(analysis->mp,&variable.Mnemonic); + PX_StringCat(&variable.Mnemonic,analysis->lexer.CurLexeme.buffer); + + + state=PX_LexerGetState(&analysis->lexer); + + type=PX_ScriptTranslatorNextToken(&analysis->lexer); + + if (type!=PX_LEXER_LEXEME_TYPE_DELIMITER) + { + PX_ScriptTranslatorError(&analysis->lexer,"Invalid var token"); + PX_StringFree(&variable.Mnemonic); + goto _ERROR; + } + + + if (analysis->lexer.Symbol=='[') + { + if (variable.type==PX_SCRIPT_PARSER_VAR_TYPE_STRUCT_PTR) + { + PX_ScriptTranslatorError(&analysis->lexer,"Array of struct pointers is not support."); + PX_StringFree(&variable.Mnemonic); + goto _ERROR; + } + + variable.type=PX_SCRIPT_PARSER_VAR_TYPE_SET_ARRAY; + + if(PX_ScriptTranslatorNextToken(&analysis->lexer)!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + PX_ScriptTranslatorError(&analysis->lexer,"Invalid var token"); + PX_StringFree(&variable.Mnemonic); + goto _ERROR; + } + + if(!PX_strIsNumeric(analysis->lexer.CurLexeme.buffer)) + { + PX_ScriptTranslatorError(&analysis->lexer,"Invalid var token"); + } + + + if(variable.type==PX_SCRIPT_PARSER_VAR_TYPE_STRUCT_PTR) + variable.size=PX_atoi(analysis->lexer.CurLexeme.buffer); + else + variable.size=PX_atoi(analysis->lexer.CurLexeme.buffer)*pset->size; + + if (variable.size==0) + { + PX_ScriptTranslatorError(&analysis->lexer,"Invalid array"); + PX_StringFree(&variable.Mnemonic); + goto _ERROR; + } + type=PX_ScriptTranslatorNextToken(&analysis->lexer); + + if (type!=PX_LEXER_LEXEME_TYPE_DELIMITER||analysis->lexer.Symbol!=']') + { + PX_ScriptTranslatorError(&analysis->lexer,"Invalid var token"); + PX_StringFree(&variable.Mnemonic); + goto _ERROR; + } + + type=PX_ScriptTranslatorNextToken(&analysis->lexer); + + } + else + { + if(variable.type==PX_SCRIPT_PARSER_VAR_TYPE_STRUCT_PTR) + variable.size=1; + else + variable.size=pset->size; + } + + + if (analysis->functionInside) + { + PX_SCRIPT_VARIABLES *pvar; + for (i=0;iv_variablesStackTable.size;i++) + { + if (PX_strequ(variable.Mnemonic.buffer,PX_VECTORAT(PX_SCRIPT_VARIABLES,&analysis->v_variablesStackTable,i)->Mnemonic.buffer)) + { + PX_ScriptTranslatorError(&analysis->lexer,"variable redefined."); + PX_StringFree(&variable.Mnemonic); + if(variable.bInitialized) + PX_StringFree(&variable.GlobalInitializeValue); + goto _ERROR; + } + } + + pvar=PX_VECTORLAST(PX_SCRIPT_VARIABLES,&analysis->v_variablesStackTable); + variable.BeginIndex=pvar->BeginIndex+variable.size; + + if (variable.BeginIndex+variable.size-1>analysis->currentAllocStackSize) + { + analysis->currentAllocStackSize=variable.BeginIndex+variable.size-1; + } + + PX_VectorPushback(&analysis->v_variablesStackTable,&variable); + } + else + { + for (i=0;iv_variablesGlobalTable.size;i++) + { + if (PX_strequ(variable.Mnemonic.buffer,PX_VECTORAT(PX_SCRIPT_VARIABLES,&analysis->v_variablesGlobalTable,i)->Mnemonic.buffer)) + { + PX_ScriptTranslatorError(&analysis->lexer,"variable redefined."); + PX_StringFree(&variable.Mnemonic); + if(variable.bInitialized) + PX_StringFree(&variable.GlobalInitializeValue); + goto _ERROR; + } + } + + if (analysis->v_variablesGlobalTable.size==0) + { + variable.BeginIndex=0; + } + else + { + pvar=PX_VECTORAT(PX_SCRIPT_VARIABLES,&analysis->v_variablesGlobalTable,analysis->v_variablesGlobalTable.size-1); + variable.BeginIndex=pvar->BeginIndex+pvar->size; + } + + + PX_VectorPushback(&analysis->v_variablesGlobalTable,&variable); + } + + + if (type!=PX_LEXER_LEXEME_TYPE_DELIMITER) + { + PX_ScriptTranslatorError(&analysis->lexer,"\";\" is expected but not found."); + PX_StringFree(&variable.Mnemonic); + goto _ERROR; + } + + if(analysis->lexer.Symbol==',') + { + continue; + } + else if(analysis->lexer.Symbol==';') + { + break; + } + else + { + PX_ScriptTranslatorError(&analysis->lexer,"\";\" is expected but not found."); + PX_StringFree(&variable.Mnemonic); + goto _ERROR; + } + } + + return PX_TRUE; +_ERROR: + return PX_FALSE; +} +px_bool PX_ScriptParseStructDefine(PX_SCRIPT_Analysis *analysis) +{ + PX_SCRIPT_SETMEMBER member,*pmember; + PX_SCRIPT_STRUCT vSet,*pSet; + PX_LEXER_LEXEME_TYPE type; + px_int i; + + member.defvar.BeginIndex=-1; + + vSet.size=0; + + if ((PX_ScriptTranslatorNextToken(&analysis->lexer))!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + return PX_FALSE; + } + + if (!PX_ScriptParseIsValidToken(analysis->lexer.CurLexeme.buffer)) + { + return PX_FALSE; + } + + PX_StringInitialize(analysis->mp,&vSet.Name); + PX_StringCat(&vSet.Name,analysis->lexer.CurLexeme.buffer); + PX_VectorInitialize(analysis->mp,&vSet.members,sizeof(PX_SCRIPT_SETMEMBER),1); + + if ((PX_ScriptTranslatorNextTokenSN(&analysis->lexer))!=PX_LEXER_LEXEME_TYPE_DELIMITER) + { + goto _ERROR; + } + if (analysis->lexer.Symbol!='{') + { + goto _ERROR; + } + + while(PX_TRUE) + { + type=PX_ScriptTranslatorNextToken(&analysis->lexer); + + if (type==PX_LEXER_LEXEME_TYPE_NEWLINE) + { + continue; + } + + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER&&analysis->lexer.Symbol=='}') + { + break; + } + + if (type!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + goto _ERROR; + } + + if((pSet=PX_ScriptParseGetStructInfo(analysis,analysis->lexer.CurLexeme.buffer))!=PX_NULL) + { + member.defvar.setIndex=PX_ScriptParseGetSetIndex(analysis,analysis->lexer.CurLexeme.buffer); + + ////////////////////////////////////////////////////////////////////////// + while (PX_TRUE) + { + type=PX_ScriptTranslatorNextToken(&analysis->lexer); + + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER&&analysis->lexer.Symbol=='*') + { + member.defvar.type=PX_SCRIPT_PARSER_VAR_TYPE_STRUCT_PTR; + type=PX_ScriptTranslatorNextToken(&analysis->lexer); + } + + + if (type!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + goto _ERROR; + } + + if (!PX_ScriptParseIsValidToken(analysis->lexer.CurLexeme.buffer)) + { + PX_ScriptTranslatorError(&analysis->lexer,"Invalid var token"); + goto _ERROR; + } + + PX_StringInitialize(analysis->mp,&member.defvar.Mnemonic); + PX_StringCat(&member.defvar.Mnemonic,analysis->lexer.CurLexeme.buffer); + + type=PX_ScriptTranslatorNextToken(&analysis->lexer); + + if (type!=PX_LEXER_LEXEME_TYPE_DELIMITER) + { + PX_ScriptTranslatorError(&analysis->lexer,"Invalid var token"); + PX_StringFree(&member.defvar.Mnemonic); + goto _ERROR; + } + + + if (analysis->lexer.Symbol=='[') + { + if (member.defvar.type==PX_SCRIPT_PARSER_VAR_TYPE_STRUCT_PTR) + { + PX_ScriptTranslatorError(&analysis->lexer,"Array of struct is not support."); + PX_StringFree(&member.defvar.Mnemonic); + goto _ERROR; + } + + member.defvar.type=PX_SCRIPT_PARSER_VAR_TYPE_SET_ARRAY; + + if(PX_ScriptTranslatorNextToken(&analysis->lexer)!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + PX_ScriptTranslatorError(&analysis->lexer,"Invalid var token"); + PX_StringFree(&member.defvar.Mnemonic); + goto _ERROR; + } + + if(!PX_strIsNumeric(analysis->lexer.CurLexeme.buffer)) + { + PX_ScriptTranslatorError(&analysis->lexer,"Invalid var token"); + PX_StringFree(&member.defvar.Mnemonic); + goto _ERROR; + } + + member.offset=vSet.size; + vSet.size+=PX_atoi(analysis->lexer.CurLexeme.buffer)*pSet->size; + + if (vSet.size==0) + { + PX_ScriptTranslatorError(&analysis->lexer,"Invalid array"); + PX_StringFree(&member.defvar.Mnemonic); + goto _ERROR; + } + type=PX_ScriptTranslatorNextToken(&analysis->lexer); + + if (type!=PX_LEXER_LEXEME_TYPE_DELIMITER||analysis->lexer.Symbol!=']') + { + PX_ScriptTranslatorError(&analysis->lexer,"Invalid var token"); + PX_StringFree(&member.defvar.Mnemonic); + goto _ERROR; + } + + + type=PX_ScriptTranslatorNextToken(&analysis->lexer); + + + if (type!=PX_LEXER_LEXEME_TYPE_DELIMITER) + { + PX_ScriptTranslatorError(&analysis->lexer,"\";\" is expected but not found."); + PX_StringFree(&member.defvar.Mnemonic); + goto _ERROR; + } + + if(analysis->lexer.Symbol==',') + { + PX_VectorPushback(&vSet.members,&member); + continue; + } + else if(analysis->lexer.Symbol==';') + { + PX_VectorPushback(&vSet.members,&member); + break; + } + else + { + PX_ScriptTranslatorError(&analysis->lexer,"\";\" is expected but not found."); + PX_StringFree(&member.defvar.Mnemonic); + goto _ERROR; + } + break; + } + else if(analysis->lexer.Symbol==';') + { + member.offset=vSet.size; + member.defvar.type=PX_SCRIPT_PARSER_VAR_TYPE_STRUCT; + vSet.size+=pSet->size; + PX_VectorPushback(&vSet.members,&member); + break; + } + else if(analysis->lexer.Symbol==',') + { + member.offset=vSet.size; + member.defvar.type=PX_SCRIPT_PARSER_VAR_TYPE_STRUCT; + vSet.size+=pSet->size; + PX_VectorPushback(&vSet.members,&member); + continue; + } + else + { + PX_ScriptTranslatorError(&analysis->lexer,"Invalid var token"); + PX_StringFree(&member.defvar.Mnemonic); + goto _ERROR; + } + } + ////////////////////////////////////////////////////////////////////////// + + } + else + { + if (type!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + return PX_FALSE; + } + + if (PX_strequ(analysis->lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_INT)) + { + member.defvar.type=PX_SCRIPT_PARSER_VAR_TYPE_INT; + } + else if (PX_strequ(analysis->lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_FLOAT)) + { + member.defvar.type=PX_SCRIPT_PARSER_VAR_TYPE_FLOAT; + } + else if (PX_strequ(analysis->lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_STRING)) + { + member.defvar.type=PX_SCRIPT_PARSER_VAR_TYPE_STRING; + } + else if (PX_strequ(analysis->lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_MEMORY)) + { + member.defvar.type=PX_SCRIPT_PARSER_VAR_TYPE_MEMORY; + } + else + { + goto _ERROR; + } + + ////////////////////////////////////////////////////////////////////////// + while (PX_TRUE) + { + type=PX_ScriptTranslatorNextToken(&analysis->lexer); + + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER&&analysis->lexer.Symbol=='*') + { + switch(member.defvar.type) + { + case PX_SCRIPT_PARSER_VAR_TYPE_INT: + { + member.defvar.type=PX_SCRIPT_PARSER_VAR_TYPE_INT_PTR; + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_FLOAT: + { + member.defvar.type=PX_SCRIPT_PARSER_VAR_TYPE_FLOAT_PTR; + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_STRING: + { + member.defvar.type=PX_SCRIPT_PARSER_VAR_TYPE_STRING_PTR; + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_MEMORY: + { + member.defvar.type=PX_SCRIPT_PARSER_VAR_TYPE_MEMORY_PTR; + } + break; + default: + goto _ERROR; + } + + type=PX_ScriptTranslatorNextToken(&analysis->lexer); + } + + if (type!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + goto _ERROR; + } + + if (!PX_ScriptParseIsValidToken(analysis->lexer.CurLexeme.buffer)) + { + PX_ScriptTranslatorError(&analysis->lexer,"Invalid var token"); + goto _ERROR; + } + + PX_StringInitialize(analysis->mp,&member.defvar.Mnemonic); + PX_StringCat(&member.defvar.Mnemonic,analysis->lexer.CurLexeme.buffer); + member.defvar.bInitialized=PX_FALSE; + + type=PX_ScriptTranslatorNextToken(&analysis->lexer); + + if (type!=PX_LEXER_LEXEME_TYPE_DELIMITER) + { + PX_ScriptTranslatorError(&analysis->lexer,"Invalid var token"); + PX_StringFree(&member.defvar.Mnemonic); + goto _ERROR; + } + + + if (analysis->lexer.Symbol=='[') + { + switch(member.defvar.type) + { + case PX_SCRIPT_PARSER_VAR_TYPE_INT: + { + member.defvar.type=PX_SCRIPT_PARSER_VAR_TYPE_INT_ARRAY; + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_FLOAT: + { + member.defvar.type=PX_SCRIPT_PARSER_VAR_TYPE_FLOAT_ARRAY; + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_STRING: + { + member.defvar.type=PX_SCRIPT_PARSER_VAR_TYPE_STRING_ARRAY; + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_MEMORY: + { + member.defvar.type=PX_SCRIPT_PARSER_VAR_TYPE_MEMORY_ARRAY; + } + break; + + default: + goto _ERROR; + } + + if(PX_ScriptTranslatorNextToken(&analysis->lexer)!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + PX_ScriptTranslatorError(&analysis->lexer,"Invalid var token"); + PX_StringFree(&member.defvar.Mnemonic); + goto _ERROR; + } + + if(!PX_strIsNumeric(analysis->lexer.CurLexeme.buffer)) + { + PX_ScriptTranslatorError(&analysis->lexer,"Invalid var token"); + PX_StringFree(&member.defvar.Mnemonic); + goto _ERROR; + } + + member.offset=vSet.size; + member.defvar.size=PX_atoi(analysis->lexer.CurLexeme.buffer); + vSet.size+=PX_atoi(analysis->lexer.CurLexeme.buffer); + + if (member.defvar.size==0) + { + PX_ScriptTranslatorError(&analysis->lexer,"Invalid array"); + PX_StringFree(&member.defvar.Mnemonic); + goto _ERROR; + } + type=PX_ScriptTranslatorNextToken(&analysis->lexer); + + if (type!=PX_LEXER_LEXEME_TYPE_DELIMITER||analysis->lexer.Symbol!=']') + { + PX_ScriptTranslatorError(&analysis->lexer,"Invalid var token"); + PX_StringFree(&member.defvar.Mnemonic); + goto _ERROR; + } + + + type=PX_ScriptTranslatorNextToken(&analysis->lexer); + + if(analysis->lexer.Symbol=='=') + { + PX_ScriptTranslatorError(&analysis->lexer,"Initialize of array is not support."); + PX_StringFree(&member.defvar.Mnemonic); + goto _ERROR; + } + + if (type!=PX_LEXER_LEXEME_TYPE_DELIMITER) + { + PX_ScriptTranslatorError(&analysis->lexer,"\";\" is expected but not found."); + PX_StringFree(&member.defvar.Mnemonic); + goto _ERROR; + } + + if(analysis->lexer.Symbol==',') + { + PX_VectorPushback(&vSet.members,&member); + continue; + } + else if(analysis->lexer.Symbol==';') + { + PX_VectorPushback(&vSet.members,&member); + break; + } + else + { + PX_ScriptTranslatorError(&analysis->lexer,"\";\" is expected but not found."); + PX_StringFree(&member.defvar.Mnemonic); + PX_VectorPushback(&vSet.members,&member); + goto _ERROR; + } + break; + } + else if(analysis->lexer.Symbol==';') + { + member.offset=vSet.size; + member.defvar.size=1; + member.defvar.setIndex=-1; + vSet.size+=1; + + PX_VectorPushback(&vSet.members,&member); + break; + } + else if(analysis->lexer.Symbol==',') + { + member.offset=vSet.size; + member.defvar.size=1; + member.defvar.setIndex=-1; + vSet.size+=1; + PX_VectorPushback(&vSet.members,&member); + continue; + } + else + { + PX_ScriptTranslatorError(&analysis->lexer,"Invalid var token"); + PX_StringFree(&member.defvar.Mnemonic); + goto _ERROR; + } + } + ////////////////////////////////////////////////////////////////////////// + } + + } + if (vSet.size==0) + { + PX_ScriptTranslatorError(&analysis->lexer,"Zero size of struct"); + goto _ERROR; + } + PX_VectorPushback(&analysis->v_struct,&vSet); + return PX_TRUE; +_ERROR: + PX_StringFree(&vSet.Name); + PX_VectorFree(&vSet.members); + for (i=0;idefvar.Mnemonic); + if (pmember->defvar.bInitialized) + { + PX_StringFree(&pmember->defvar.GlobalInitializeValue); + } + } + PX_VectorFree(&vSet.members); + return PX_FALSE; +} +px_bool PX_ScriptParseFunctionDefined(PX_SCRIPT_Analysis *analysis,PX_SCRIPT_TRANSLATOR_FUNCTION_TYPE functype) +{ + PX_SCRIPT_FUNCTION func,*pfunc=PX_NULL; + PX_SCRIPT_VARIABLES fvar; + px_int count=0,i=0,j=0; + PX_LEXER_LEXEME_TYPE type; + fvar.bParam=PX_TRUE; + func.retSetIndex=-1; + type=PX_ScriptTranslatorNextToken(&analysis->lexer); + if (type!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + return PX_FALSE; + } + + if (PX_strequ(analysis->lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_INT)) + { + func.retType=PX_SCRIPT_PARSER_VAR_TYPE_INT; + } + else if (PX_strequ(analysis->lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_FLOAT)) + { + func.retType=PX_SCRIPT_PARSER_VAR_TYPE_FLOAT; + } + else if (PX_strequ(analysis->lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_STRING)) + { + func.retType=PX_SCRIPT_PARSER_VAR_TYPE_STRING; + } + else if (PX_strequ(analysis->lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_MEMORY)) + { + func.retType=PX_SCRIPT_PARSER_VAR_TYPE_MEMORY; + } + else if (PX_strequ(analysis->lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_VOID)) + { + func.retType=PX_SCRIPT_PARSER_VAR_TYPE_VOID; + } + else if ((func.retSetIndex=PX_ScriptParseGetSetIndex(analysis,analysis->lexer.CurLexeme.buffer))!=-1) + { + func.retType=PX_SCRIPT_PARSER_VAR_TYPE_STRUCT; + } + else + { + goto _ERROR; + } + + //function Name + PX_ScriptParserClearStack(analysis); + func.parametersSize=0; + + type=PX_ScriptTranslatorNextToken(&analysis->lexer); + + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER&&analysis->lexer.Symbol=='*') + { + switch(func.retType) + { + case PX_SCRIPT_PARSER_VAR_TYPE_INT: + func.retType=PX_SCRIPT_PARSER_VAR_TYPE_INT_PTR; + break; + case PX_SCRIPT_PARSER_VAR_TYPE_FLOAT: + func.retType=PX_SCRIPT_PARSER_VAR_TYPE_FLOAT_PTR; + break; + case PX_SCRIPT_PARSER_VAR_TYPE_STRING: + func.retType=PX_SCRIPT_PARSER_VAR_TYPE_STRING_PTR; + break; + case PX_SCRIPT_PARSER_VAR_TYPE_MEMORY: + func.retType=PX_SCRIPT_PARSER_VAR_TYPE_MEMORY_PTR; + break; + case PX_SCRIPT_PARSER_VAR_TYPE_STRUCT: + func.retType=PX_SCRIPT_PARSER_VAR_TYPE_STRUCT_PTR; + break; + default: + goto _ERROR; + } + type=PX_ScriptTranslatorNextToken(&analysis->lexer); + } + if (func.retType==PX_SCRIPT_PARSER_VAR_TYPE_STRUCT) + { + PX_ScriptTranslatorError(&analysis->lexer,"Could not return a struct-type"); + goto _ERROR; + } + if (type!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + return PX_FALSE; + } + if (!PX_ScriptParseIsValidToken(analysis->lexer.CurLexeme.buffer)) + { + return PX_FALSE; + } + + if (PX_StringLen(&analysis->lexer.CurLexeme)>PX_SCRIPT_FUNCTION_NAME_MAX_LEN) + { + return PX_FALSE; + } + PX_strcpy(func.name,analysis->lexer.CurLexeme.buffer,PX_SCRIPT_FUNCTION_NAME_MAX_LEN); + if ((PX_ScriptTranslatorNextToken(&analysis->lexer))!=PX_LEXER_LEXEME_TYPE_DELIMITER||analysis->lexer.Symbol!='(') + { + goto _ERROR; + } + + while (PX_TRUE) + { + + type=PX_ScriptTranslatorNextToken(&analysis->lexer); + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER&&analysis->lexer.Symbol==')') + { + break; + } + if (type!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + goto _ERROR; + } + fvar.layer=analysis->v_astStructure.size; + fvar.size=1; + ////////////////////////////////////////////////////////////////////////// + if (PX_strequ(analysis->lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_INT)) + { + fvar.type=PX_SCRIPT_PARSER_VAR_TYPE_INT; + } + else if (PX_strequ(analysis->lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_FLOAT)) + { + fvar.type=PX_SCRIPT_PARSER_VAR_TYPE_FLOAT; + } + else if (PX_strequ(analysis->lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_STRING)) + { + fvar.type=PX_SCRIPT_PARSER_VAR_TYPE_STRING; + } + else if (PX_strequ(analysis->lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_MEMORY)) + { + fvar.type=PX_SCRIPT_PARSER_VAR_TYPE_MEMORY; + } + else if (PX_ScriptParseGetStructInfo(analysis,analysis->lexer.CurLexeme.buffer)) + { + fvar.type=PX_SCRIPT_PARSER_VAR_TYPE_STRUCT; + + if ((fvar.setIndex=PX_ScriptParseGetSetIndex(analysis,analysis->lexer.CurLexeme.buffer))==-1) + { + goto _ERROR; + } + } + else + { + goto _ERROR; + } + + ////////////////////////////////////////////////////////////////////////// + + type=PX_ScriptTranslatorNextToken(&analysis->lexer); + + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER&&analysis->lexer.Symbol=='*') + { + switch(fvar.type) + { + case PX_SCRIPT_PARSER_VAR_TYPE_INT: + fvar.type=PX_SCRIPT_PARSER_VAR_TYPE_INT_PTR; + break; + case PX_SCRIPT_PARSER_VAR_TYPE_FLOAT: + fvar.type=PX_SCRIPT_PARSER_VAR_TYPE_FLOAT_PTR; + break; + case PX_SCRIPT_PARSER_VAR_TYPE_STRING: + fvar.type=PX_SCRIPT_PARSER_VAR_TYPE_STRING_PTR; + break; + case PX_SCRIPT_PARSER_VAR_TYPE_MEMORY: + fvar.type=PX_SCRIPT_PARSER_VAR_TYPE_MEMORY_PTR; + break; + case PX_SCRIPT_PARSER_VAR_TYPE_STRUCT: + fvar.type=PX_SCRIPT_PARSER_VAR_TYPE_STRUCT_PTR; + break; + default: + goto _ERROR; + } + type=PX_ScriptTranslatorNextToken(&analysis->lexer); + } + + if (fvar.type==PX_SCRIPT_PARSER_VAR_TYPE_STRUCT) + { + PX_ScriptTranslatorError(&analysis->lexer,"Could not use a struct for parameter.consider use a struct pointer."); + goto _ERROR; + } + + if (type!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + goto _ERROR; + } + if (!PX_ScriptParseIsValidToken(analysis->lexer.CurLexeme.buffer)) + { + goto _ERROR; + } + + fvar.bInitialized=PX_FALSE; + if (analysis->v_variablesStackTable.size==0) + { + fvar.BeginIndex=-2; + } + else + { + PX_SCRIPT_VARIABLES *plastvar=PX_VECTORLAST(PX_SCRIPT_VARIABLES,&analysis->v_variablesStackTable); + fvar.BeginIndex=plastvar->BeginIndex-plastvar->size; + } + + + PX_StringInitialize(analysis->mp,&fvar.Mnemonic); + PX_StringCat(&fvar.Mnemonic,analysis->lexer.CurLexeme.buffer); + + + if (count>=PX_SCRIPT_FUNCTION_MAX_PARAM) + { + goto _ERROR; + } + + func.parameters[count]=fvar; + PX_VectorPushback(&analysis->v_variablesStackTable,&fvar); + count++; + + if ((PX_ScriptTranslatorNextToken(&analysis->lexer))!=PX_LEXER_LEXEME_TYPE_DELIMITER||analysis->lexer.Symbol!=',') + { + if (analysis->lexer.Symbol==')') + { + break; + } + goto _ERROR; + } + } + + do + { + PX_SCRIPT_VARIABLES _ret_bp; + PX_memset(&_ret_bp,0,sizeof(_ret_bp)); + _ret_bp.BeginIndex=0; + _ret_bp.bInitialized=PX_FALSE; + _ret_bp.bParam=PX_TRUE; + PX_StringInitialize(analysis->mp,&_ret_bp.Mnemonic); + _ret_bp.size=2; + _ret_bp.type=PX_SCRIPT_PARSER_VAR_TYPE_INT_ARRAY; + PX_VectorPushback(&analysis->v_variablesStackTable,&_ret_bp); + } while (0); + + + func.parametersCount=count; + func.type=functype; + + for (i=0;iv_functions.size;i++) + { + pfunc=PX_VECTORAT(PX_SCRIPT_FUNCTION,&analysis->v_functions,i); + if (PX_strequ(pfunc->name,func.name)) + { + if (pfunc->parametersCount!=func.parametersCount) + { + PX_ScriptTranslatorError(&analysis->lexer,"Function redefined error."); + goto _ERROR; + } + for (j=0;jparameters[j].type) + { + PX_ScriptTranslatorError(&analysis->lexer,"Function parameters are not compatible"); + goto _ERROR; + } + } + analysis->currentFunc=*pfunc; + return PX_TRUE; + } + } + for (i=0;icurrentFunc=func; + PX_VectorPushback(&analysis->v_functions,&func); + return PX_TRUE; +_ERROR: + return PX_FALSE; +} +px_bool PX_ScriptParseFunctionGuiderCode(PX_SCRIPT_Analysis *analysis) +{ + int stacksize; + px_string code; + + px_string guiderCode; + + if(!PX_StringInitialize(analysis->mp,&guiderCode))return PX_FALSE; + + stacksize=analysis->currentAllocStackSize; + + if (analysis->currentFunc.type==PX_SCRIPT_TRANSLATOR_FUNCTION_TYPE_EXPORT) + { + PX_StringCat(&guiderCode,"EXPORT "); + } + + PX_StringCat(&guiderCode,"FUNCTION "); + PX_StringCat(&guiderCode,analysis->currentFunc.name); + PX_StringCat(&guiderCode,":\n"); + + //generate codes + PX_StringInitialize(analysis->mp,&code); + + PX_StringCat(&guiderCode,"PUSH BP\nMOV BP,SP\n"); + + if(stacksize!=0) + { + PX_StringFormat1(&code,"SUB SP,%1\n",PX_STRINGFORMAT_INT(stacksize)); + PX_StringCat(&guiderCode,code.buffer); + } + + PX_StringFree(&code); + + + if (analysis->functionguider!=-1) + { + if(!PX_StringInsert(&analysis->code,analysis->functionguider,guiderCode.buffer))return PX_FALSE; + } + else + { + PX_ASSERT(); + PX_StringFree(&guiderCode); + return PX_FALSE; + } + + analysis->functionguider=-1; + PX_StringFree(&guiderCode); + return PX_TRUE; +} +px_bool PX_ScriptParseBootCode(PX_SCRIPT_Analysis *analysis) +{ + px_int i; + PX_SCRIPT_VARIABLES *pvar; + px_string code; + px_string exprgen; + PX_SCRIPT_AST_OPERAND retOperand; + for (i=0;iv_variablesGlobalTable.size;i++) + { + pvar=PX_VECTORAT(PX_SCRIPT_VARIABLES,&analysis->v_variablesGlobalTable,i); + if(pvar->bInitialized) + { + PX_StringInitialize(analysis->mp,&code); + PX_StringInitialize(analysis->mp,&exprgen); + PX_StringFormat2(&code,"%1=%2\n",PX_STRINGFORMAT_STRING(pvar->Mnemonic.buffer),PX_STRINGFORMAT_STRING(pvar->GlobalInitializeValue.buffer)); + if (!PX_ScriptParseExpression(analysis,code.buffer,&exprgen,&retOperand)) + { + PX_StringFree(&code); + PX_StringFree(&exprgen); + return PX_FALSE; + } + PX_StringCat(&analysis->bootCode,exprgen.buffer); + PX_StringFree(&exprgen); + PX_StringFree(&code); + } + } + return PX_TRUE; +} +px_bool PX_ScriptParseFunctionReturn(PX_SCRIPT_Analysis *analysis) +{ + px_string code; + int stacksize=0; + PX_StringInitialize(analysis->mp,&code); + + stacksize=analysis->currentAllocStackSize; + + PX_StringCat(&analysis->code,"_"); + PX_StringCat(&analysis->code,analysis->currentFunc.name); + PX_StringCat(&analysis->code,"_RET:\n"); + + if(stacksize!=0) + { + PX_StringFormat1(&code,"POPN %1\n",PX_STRINGFORMAT_INT(stacksize)); + PX_StringCat(&analysis->code,code.buffer); + } + PX_StringCat(&analysis->code,"POP BP\nRET\n"); + PX_StringFree(&code); + return PX_TRUE; +} +px_bool PX_ScriptParsePopAstStructure(PX_SCRIPT_Analysis *analysis) +{ + PX_SCRIPT_AST_STRUCTURE *plast; + if (analysis->v_astStructure.size==0) + { + return PX_FALSE; + } + plast=PX_VECTORLAST(PX_SCRIPT_AST_STRUCTURE,&analysis->v_astStructure); + PX_VectorPop(&analysis->v_astStructure); + return PX_TRUE; +} +px_bool PX_ScriptParseLastCodeblockEnd(PX_SCRIPT_Analysis *analysis); + +px_bool PX_ScriptParseLastBlockEnd(PX_SCRIPT_Analysis *analysis) +{ + PX_SCRIPT_AST_STRUCTURE astStruct; + + astStruct=*PX_VECTORLAST(PX_SCRIPT_AST_STRUCTURE,&analysis->v_astStructure); + switch(astStruct.type) + { + case PX_SCRIPT_AST_STRUCTURE_TYPE_IF: + { + if (astStruct._if.oneline_expr) + { + return PX_ScriptParseLastCodeblockEnd(analysis); + } + } + break; + case PX_SCRIPT_AST_STRUCTURE_TYPE_ELSE: + { + if (astStruct._else.oneline_expr) + { + return PX_ScriptParseLastCodeblockEnd(analysis); + } + } + break; + case PX_SCRIPT_AST_STRUCTURE_TYPE_FOR: + { + if (astStruct._for.oneline_expr) + { + return PX_ScriptParseLastCodeblockEnd(analysis); + } + } + break; + case PX_SCRIPT_AST_STRUCTURE_TYPE_WHILE: + { + if (astStruct._while.oneline_expr) + { + return PX_ScriptParseLastCodeblockEnd(analysis); + } + } + break; + case PX_SCRIPT_AST_STRUCTURE_TYPE_SWITCH: + { + if (astStruct._compare.oneline_expr) + { + return PX_ScriptParseLastCodeblockEnd(analysis); + } + } + break; + case PX_SCRIPT_AST_STRUCTURE_TYPE_CASE: + { + if (astStruct._with.oneline_expr) + { + return PX_ScriptParseLastCodeblockEnd(analysis); + } + } + break; + case PX_SCRIPT_AST_STRUCTURE_TYPE_FUNCTION: + break; + default: + return PX_FALSE; + } + return PX_TRUE; +} +px_bool PX_ScriptParseLastCodeblockEnd(PX_SCRIPT_Analysis *analysis) +{ + PX_LEXER_STATE state; + PX_LEXER_LEXEME_TYPE type; + PX_SCRIPT_AST_STRUCTURE buildastStruct; + PX_SCRIPT_AST_STRUCTURE astStruct; + px_string fmrString; + px_int layer=analysis->v_astStructure.size; + + if (analysis->v_astStructure.size==0) + { + return PX_FALSE; + } + + astStruct=*PX_VECTORLAST(PX_SCRIPT_AST_STRUCTURE,&analysis->v_astStructure); + + if(!PX_ScriptParsePopAstStructure(analysis))return PX_FALSE; + + switch(astStruct.type) + { + case PX_SCRIPT_AST_STRUCTURE_TYPE_FUNCTION: + { + ////////////////////////////////////////////////////////////////////////// + //Function Guider + ////////////////////////////////////////////////////////////////////////// + if(!PX_ScriptParseFunctionGuiderCode(analysis)) return PX_FALSE; + + + ////////////////////////////////////////////////////////////////////////// + //Function Clear + if(!PX_ScriptParseFunctionReturn(analysis)) return PX_FALSE; + + analysis->functionInside=PX_FALSE; + } + break; + case PX_SCRIPT_AST_STRUCTURE_TYPE_IF: + { + // + //if() + //{ + //}<---here + + //else + state=PX_LexerGetState(&analysis->lexer); + type=PX_ScriptTranslatorNextTokenSN(&analysis->lexer); + if (type==PX_LEXER_LEXEME_TYPE_TOKEN&&PX_strequ(analysis->lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_ELSE)) + { + //generate code + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringFormat1(&fmrString,"JMP _ELSE_%1\n",PX_STRINGFORMAT_INT(astStruct._if.elseflag)); + PX_StringCat(&analysis->code,fmrString.buffer); + PX_StringFree(&fmrString); + + buildastStruct.type=PX_SCRIPT_AST_STRUCTURE_TYPE_ELSE; + buildastStruct._else.elseflag=astStruct._if.elseflag; + + state=PX_LexerGetState(&analysis->lexer); + type=PX_ScriptTranslatorNextTokenSN(&analysis->lexer); + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER&&analysis->lexer.Symbol=='{') + { + buildastStruct._else.oneline_expr=PX_FALSE; + } + else + { + PX_LexerSetState(state); + buildastStruct._else.oneline_expr=PX_TRUE; + } + PX_VectorPushback(&analysis->v_astStructure,&buildastStruct); + + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringFormat1(&fmrString,"_IF_%1:\n",PX_STRINGFORMAT_INT(astStruct._if.ifflag)); + PX_StringCat(&analysis->code,fmrString.buffer); + PX_StringFree(&fmrString); + } + else + { + PX_LexerSetState(state); + + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringFormat1(&fmrString,"_IF_%1:\n",PX_STRINGFORMAT_INT(astStruct._if.ifflag)); + PX_StringCat(&analysis->code,fmrString.buffer); + PX_StringFree(&fmrString); + + if (!PX_ScriptParseLastBlockEnd(analysis)) + { + return PX_FALSE; + } + + } + + } + break; + case PX_SCRIPT_AST_STRUCTURE_TYPE_ELSE: + { + // + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringFormat1(&fmrString,"_ELSE_%1:\n",PX_STRINGFORMAT_INT(astStruct._else.elseflag)); + PX_StringCat(&analysis->code,fmrString.buffer); + PX_StringFree(&fmrString); + + if (!PX_ScriptParseLastBlockEnd(analysis)) + { + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_STRUCTURE_TYPE_WHILE: + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringFormat1(&fmrString,"JMP _WHILE_%1\n",PX_STRINGFORMAT_INT(astStruct._while.loopflag)); + PX_StringCat(&analysis->code,fmrString.buffer); + PX_StringFormat1(&fmrString,"_WHILE_%1:\n",PX_STRINGFORMAT_INT(astStruct._while.endflag)); + PX_StringCat(&analysis->code,fmrString.buffer); + PX_StringFree(&fmrString); + + if (!PX_ScriptParseLastBlockEnd(analysis)) + { + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_STRUCTURE_TYPE_FOR: + { + PX_StringInitialize(analysis->mp,&fmrString); + PX_StringFormat1(&fmrString,"JMP _FOR_%1\n",PX_STRINGFORMAT_INT(astStruct._for.additionFlag)); + PX_StringCat(&analysis->code,fmrString.buffer); + //endflag + PX_StringFormat1(&fmrString,"_FOR_%1:\n",PX_STRINGFORMAT_INT(astStruct._for.endFlag)); + PX_StringCat(&analysis->code,fmrString.buffer); + PX_StringFree(&fmrString); + + if (!PX_ScriptParseLastBlockEnd(analysis)) + { + return PX_FALSE; + } + } + break; + + case PX_SCRIPT_AST_STRUCTURE_TYPE_SWITCH: + { + PX_StringInitialize(analysis->mp,&fmrString); + //endflag + PX_StringFormat1(&fmrString,"_COMPARE_%1:\n",PX_STRINGFORMAT_INT(astStruct._compare.endFlag)); + PX_StringCat(&analysis->code,fmrString.buffer); + //pop + PX_StringSet(&fmrString,"POP R1\n"); + PX_StringCat(&analysis->code,fmrString.buffer); + + PX_StringFree(&fmrString); + + if (!PX_ScriptParseLastBlockEnd(analysis)) + { + return PX_FALSE; + } + } + break; + + case PX_SCRIPT_AST_STRUCTURE_TYPE_CASE: + { + PX_StringInitialize(analysis->mp,&fmrString); + //endflag + PX_StringFormat1(&fmrString,"_WITH_%1:\n",PX_STRINGFORMAT_INT(astStruct._compare.endFlag)); + PX_StringCat(&analysis->code,fmrString.buffer); + + PX_StringFree(&fmrString); + + if (!PX_ScriptParseLastBlockEnd(analysis)) + { + return PX_FALSE; + } + } + break; + default: + PX_ERROR("Assert Error:FSM Error"); + } + + //clear stack + while (analysis->v_variablesStackTable.size) + { + PX_SCRIPT_VARIABLES *pvar=PX_VECTORLAST(PX_SCRIPT_VARIABLES,&analysis->v_variablesStackTable); + if (pvar->layer>=layer) + { + if(pvar->bInitialized) + PX_StringFree(&pvar->GlobalInitializeValue); + + PX_StringFree(&pvar->Mnemonic); + + PX_VectorPop(&analysis->v_variablesStackTable); + } + else + { + break; + } + } + + + return PX_TRUE; +} +px_bool PX_ScriptParseIfLastAST(PX_SCRIPT_Analysis *analysis) +{ + PX_SCRIPT_AST_STRUCTURE astStruct; + + + if(analysis->v_astStructure.size) + { + astStruct=*PX_VECTORLAST(PX_SCRIPT_AST_STRUCTURE,&analysis->v_astStructure); + switch(astStruct.type) + { + case PX_SCRIPT_AST_STRUCTURE_TYPE_IF: + { + if (astStruct._if.oneline_expr) + { + return PX_ScriptParseLastCodeblockEnd(analysis); + } + } + break; + case PX_SCRIPT_AST_STRUCTURE_TYPE_ELSE: + { + if (astStruct._else.oneline_expr) + { + return PX_ScriptParseLastCodeblockEnd(analysis); + } + } + break; + case PX_SCRIPT_AST_STRUCTURE_TYPE_WHILE: + { + if (astStruct._while.oneline_expr) + { + return PX_ScriptParseLastCodeblockEnd(analysis); + } + } + break; + case PX_SCRIPT_AST_STRUCTURE_TYPE_FOR: + { + if (astStruct._for.oneline_expr) + { + return PX_ScriptParseLastCodeblockEnd(analysis); + } + } + break; + case PX_SCRIPT_AST_STRUCTURE_TYPE_SWITCH: + { + if (astStruct._compare.oneline_expr) + { + PX_ScriptTranslatorError(&analysis->lexer,"expression in useless compared."); + return PX_FALSE; + } + } + break; + case PX_SCRIPT_AST_STRUCTURE_TYPE_CASE: + { + if (astStruct._with.oneline_expr) + { + return PX_ScriptParseLastCodeblockEnd(analysis); + } + } + break; + default: + break; + } + } + else + return PX_FALSE; + + return PX_TRUE; +} +px_bool PX_ScriptParseGetExpression(PX_SCRIPT_Analysis *analysis,px_string *expr,px_char end) +{ + int mBracket=0,lBracket=0; + PX_LEXER_LEXEME_TYPE type; + + PX_StringClear(expr); + + while (PX_TRUE) + { + type=PX_ScriptTranslatorNextToken(&analysis->lexer); + + if (type==PX_LEXER_LEXEME_TYPE_NEWLINE) + { + continue; + } + if (type==PX_LEXER_LEXEME_TYPE_END) + { + return PX_FALSE; + } + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER&&analysis->lexer.Symbol==end&&!mBracket&&!lBracket) + { + break; + } + + if (analysis->lexer.Symbol=='(') + { + lBracket++; + } + if (analysis->lexer.Symbol==')') + { + lBracket--; + if(lBracket<0) + return PX_FALSE; + } + if (analysis->lexer.Symbol=='[') + { + mBracket++; + } + if (analysis->lexer.Symbol==']') + { + mBracket--; + if(mBracket<0) + return PX_FALSE; + } + + if (type==PX_LEXER_LEXEME_TYPE_SPACER) + { + continue; + } + + PX_StringCat(expr,analysis->lexer.CurLexeme.buffer); + } + return PX_TRUE; +} +px_bool PX_ScriptCompilerCompile(PX_SCRIPT_LIBRARY *lib,const px_char *name,px_string *ASM,px_int LocalStackSize) +{ + PX_SCRIPT_SETMEMBER *psetmem; + PX_SCRIPT_STRUCT *pset; + px_string codes; + PX_LEXER_STATE state; + px_int i,j,globalSize; + px_uint quotes; + PX_LEXER_LEXEME_TYPE type; + PX_SCRIPT_Analysis analysis; + PX_SCRIPT_AST_STRUCTURE buildAstStruct; + PX_SCRIPT_AST_STRUCTURE astStruct; + px_string expression,fmrString,condCodes; + px_string expCode; + px_bool hasLastReturn=PX_FALSE; + PX_SCRIPT_AST_OPERAND retOperand; + int mBracket=0,lBracket=0; + PX_SCRIPT_VARIABLES *pvar; + px_int thread=1; + px_bool caseEnd; + ////////////////////////////////////////////////////////////////////////// + + ////////////////////////////////////////////////////////////////////////// + PX_memset(&astStruct, 0, sizeof(&astStruct)); + PX_StringInitialize(lib->mp,&codes); + + for (i=0;icodeLibraries.size;i++) + { + if (PX_strequ(name,PX_VECTORAT(PX_SCRIPT_CODE,&lib->codeLibraries,i)->name.buffer)) + { + PX_VECTORAT(PX_SCRIPT_CODE,&lib->codeLibraries,i)->bInclude=PX_TRUE; + PX_StringCopy(&codes,&PX_VECTORAT(PX_SCRIPT_CODE,&lib->codeLibraries,i)->code); + break; + } + } + + if (i==lib->codeLibraries.size) + { + PX_ScriptTranslatorError(PX_NULL,"Code of name was not existed"); + return PX_FALSE; + } + + if(!PX_ScriptParsePretreatment(&codes,lib,name)) + return PX_FALSE; + + PX_memset(&analysis,0,sizeof(analysis)); + + analysis.functionInside=PX_FALSE; + analysis.functionReturn=PX_FALSE; + analysis._jFlag=0; + + PX_LexerInit(&analysis.lexer,lib->mp); + PX_LexerRegisterDelimiter(&analysis.lexer,','); + PX_LexerRegisterDelimiter(&analysis.lexer,';'); + PX_LexerRegisterDelimiter(&analysis.lexer,'+'); + PX_LexerRegisterDelimiter(&analysis.lexer,'-'); + PX_LexerRegisterDelimiter(&analysis.lexer,'*'); + PX_LexerRegisterDelimiter(&analysis.lexer,'/'); + PX_LexerRegisterDelimiter(&analysis.lexer,'%'); + PX_LexerRegisterDelimiter(&analysis.lexer,'&'); + PX_LexerRegisterDelimiter(&analysis.lexer,'^'); + PX_LexerRegisterDelimiter(&analysis.lexer,'~'); + PX_LexerRegisterDelimiter(&analysis.lexer,'('); + PX_LexerRegisterDelimiter(&analysis.lexer,')'); + PX_LexerRegisterDelimiter(&analysis.lexer,'!'); + PX_LexerRegisterDelimiter(&analysis.lexer,'='); + PX_LexerRegisterDelimiter(&analysis.lexer,'>'); + PX_LexerRegisterDelimiter(&analysis.lexer,'<'); + PX_LexerRegisterDelimiter(&analysis.lexer,'{'); + PX_LexerRegisterDelimiter(&analysis.lexer,'}'); + PX_LexerRegisterDelimiter(&analysis.lexer,'['); + PX_LexerRegisterDelimiter(&analysis.lexer,']'); + PX_LexerRegisterSpacer(&analysis.lexer,' '); + PX_LexerRegisterSpacer(&analysis.lexer,'\t'); + quotes=PX_LexerRegisterContainer(&analysis.lexer,"\"","\""); + PX_LexerRegisterContainerTransfer(&analysis.lexer,quotes,'\\'); + PX_LexerRegisterContainer(&analysis.lexer,"\'","\'"); + PX_LexerRegisterContainer(&analysis.lexer,"@","@"); + PX_LexerSetTokenCase(&analysis.lexer,PX_LEXER_LEXEME_CASE_UPPER); + + + PX_LexerLoadSourceFromMemory(&analysis.lexer,codes.buffer); + PX_StringFree(&codes); + + PX_VectorInitialize(lib->mp,&analysis.v_variablesGlobalTable,sizeof(PX_SCRIPT_VARIABLES),1); + PX_VectorInitialize(lib->mp,&analysis.v_variablesStackTable,sizeof(PX_SCRIPT_VARIABLES),1); + PX_VectorInitialize(lib->mp,&analysis.v_struct,sizeof(PX_SCRIPT_STRUCT),1); + PX_VectorInitialize(lib->mp,&analysis.v_functions,sizeof(PX_SCRIPT_FUNCTION),1); + PX_VectorInitialize(lib->mp,&analysis.v_astStructure,sizeof(PX_SCRIPT_AST_STRUCTURE),1); + + analysis.mp=lib->mp; + PX_StringInitialize(analysis.mp,&analysis.bootCode); + PX_StringInitialize(analysis.mp,&analysis.code); + + + ////////////////////////////////////////////////////////////////////////// + //Handle codes to stream + + + while (PX_TRUE) + { + state=PX_LexerGetState(&analysis.lexer); + if ((type=PX_ScriptTranslatorNextToken(&analysis.lexer))==PX_LEXER_LEXEME_TYPE_ERR) + { + goto _ERROR; + } + if (type==PX_LEXER_LEXEME_TYPE_END) + { + break; + } + + if (type==PX_LEXER_LEXEME_TYPE_NEWLINE) + { + continue; + } + ////////////////////////////////////////////////////////////////////////// + ///Runtime + ////////////////////////////////////////////////////////////////////////// + if (PX_strequ(analysis.lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_RUNTIME)) + { + type=PX_ScriptTranslatorNextToken(&analysis.lexer); + if (type!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + goto _ERROR; + } + if (PX_strequ(analysis.lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_STACK)) + { + type=PX_ScriptTranslatorNextToken(&analysis.lexer); + if (type!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + goto _ERROR; + } + if (!PX_strIsInt(analysis.lexer.CurLexeme.buffer)) + { + goto _ERROR; + } + LocalStackSize=PX_atoi(analysis.lexer.CurLexeme.buffer); + type=PX_ScriptTranslatorNextToken(&analysis.lexer); + if (type!=PX_LEXER_LEXEME_TYPE_NEWLINE) + { + goto _ERROR; + } + } + if (PX_strequ(analysis.lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_THREAD)) + { + type=PX_ScriptTranslatorNextToken(&analysis.lexer); + if (type!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + goto _ERROR; + } + if (!PX_strIsInt(analysis.lexer.CurLexeme.buffer)) + { + goto _ERROR; + } + thread=PX_atoi(analysis.lexer.CurLexeme.buffer); + type=PX_ScriptTranslatorNextToken(&analysis.lexer); + if (type!=PX_LEXER_LEXEME_TYPE_NEWLINE) + { + goto _ERROR; + } + } + + continue; + } + + ////////////////////////////////////////////////////////////////////////// + ///VAR + ////////////////////////////////////////////////////////////////////////// + if ((pset=PX_ScriptParseGetStructInfo(&analysis,analysis.lexer.CurLexeme.buffer))!=PX_NULL||\ + PX_strequ(analysis.lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_INT)||\ + PX_strequ(analysis.lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_FLOAT)||\ + PX_strequ(analysis.lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_STRING)||\ + PX_strequ(analysis.lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_VOID)||\ + PX_strequ(analysis.lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_MEMORY) + ) + { + + type=PX_ScriptTranslatorNextToken(&analysis.lexer); + + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER&&analysis.lexer.Symbol=='*') + { + type=PX_ScriptTranslatorNextToken(&analysis.lexer); + } + + if (type!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + goto _ERROR; + } + if (!PX_ScriptParseIsValidToken(analysis.lexer.CurLexeme.buffer)) + { + goto _ERROR; + } + type=PX_ScriptTranslatorNextToken(&analysis.lexer); + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER&&analysis.lexer.Symbol=='(') + { + //custom function + PX_LexerSetState(state); + ////////////////////////////////////////////////////////////////////////// + if (analysis.functionInside) + { + goto _ERROR; + } + + if(!PX_ScriptParseFunctionDefined(&analysis,PX_SCRIPT_TRANSLATOR_FUNCTION_TYPE_CUSTOM)) + goto _ERROR; + + type=PX_ScriptTranslatorNextTokenSN(&analysis.lexer); + + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER&&analysis.lexer.Symbol=='{') + { + analysis.functionInside=PX_TRUE; + buildAstStruct.type=PX_SCRIPT_AST_STRUCTURE_TYPE_FUNCTION; + PX_strcpy(buildAstStruct._func.name,analysis.currentFunc.name,sizeof(analysis.currentFunc.name)); + PX_VectorPushback(&analysis.v_astStructure,&buildAstStruct); + analysis.functionguider=PX_StringLen(&analysis.code); + continue; + } + else if (analysis.lexer.Symbol==';') + { + continue; + } + else + { + goto _ERROR; + } + ////////////////////////////////////////////////////////////////////////// + } + else + { + + if (pset) + { + ////////////////////////////////////////////////////////////////////////// + //STRUCT VARIALBE + ////////////////////////////////////////////////////////////////////////// + //if (isBeginExpression) + //{ + // goto _ERROR; + //} + + PX_LexerSetState(state); + if(!PX_ScriptParseStruct(&analysis)) goto _ERROR; + } + else + { + //var + PX_LexerSetState(state); +// +// if (isBeginExpression) +// { +// PX_ScriptTranslatorError(&analysis.lexer,"Define variable before expression"); +// goto _ERROR; +// } + if(!PX_ScriptParseVar(&analysis)) goto _ERROR; + } + continue; + } + + } + ////////////////////////////////////////////////////////////////////////// + + + ////////////////////////////////////////////////////////////////////////// + ///STRUCT DEFINE + ////////////////////////////////////////////////////////////////////////// + if (PX_strequ(analysis.lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_STRUCT)) + { + if (analysis.functionInside) + { + goto _ERROR; + } + + state=PX_LexerGetState(&analysis.lexer); + if (PX_ScriptTranslatorNextToken(&analysis.lexer)!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + goto _ERROR; + } + + if ((type=PX_ScriptTranslatorNextTokenSN(&analysis.lexer))==PX_LEXER_LEXEME_TYPE_DELIMITER&&analysis.lexer.Symbol=='{') + { + PX_LexerSetState(state); + {if(!PX_ScriptParseStructDefine(&analysis)) goto _ERROR;} + } + else + { + goto _ERROR; + } + continue; + } + ////////////////////////////////////////////////////////////////////////// + + + ////////////////////////////////////////////////////////////////////////// + // Host function define + if (PX_strequ(analysis.lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_HOST)) + { + if (analysis.functionInside) + { + goto _ERROR; + } + state=PX_LexerGetState(&analysis.lexer); + if ((type=PX_ScriptTranslatorNextToken(&analysis.lexer))!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + goto _ERROR; + } + if (PX_strequ(analysis.lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_INT)||\ + PX_strequ(analysis.lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_FLOAT)||\ + PX_strequ(analysis.lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_STRING)||\ + PX_strequ(analysis.lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_MEMORY)||\ + PX_strequ(analysis.lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_VOID)||\ + PX_ScriptParseGetStructInfo(&analysis,analysis.lexer.CurLexeme.buffer)!=PX_NULL + ) + { + PX_LexerSetState(state); + if(!PX_ScriptParseFunctionDefined(&analysis,PX_SCRIPT_TRANSLATOR_FUNCTION_TYPE_HOST)) + goto _ERROR; + } + else + { + goto _ERROR; + } + + type=PX_ScriptTranslatorNextTokenSN(&analysis.lexer); + + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER&&analysis.lexer.Symbol=='{') + { + PX_ScriptTranslatorError(&analysis.lexer,"Could not implement host function."); + goto _ERROR; + } + else if (analysis.lexer.Symbol==';') + { + continue; + } + else + { + goto _ERROR; + } + + } + ////////////////////////////////////////////////////////////////////////// + + ////////////////////////////////////////////////////////////////////////// + // Export function define + if (PX_strequ(analysis.lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_EXPORT)) + { + state=PX_LexerGetState(&analysis.lexer); + + if (analysis.functionInside) + { + goto _ERROR; + } + if ((type=PX_ScriptTranslatorNextToken(&analysis.lexer))!=PX_LEXER_LEXEME_TYPE_TOKEN) + { + goto _ERROR; + } + + if (PX_strequ(analysis.lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_INT)||\ + PX_strequ(analysis.lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_FLOAT)||\ + PX_strequ(analysis.lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_STRING)||\ + PX_strequ(analysis.lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_MEMORY)||\ + PX_strequ(analysis.lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_VOID)||\ + PX_ScriptParseGetStructInfo(&analysis,analysis.lexer.CurLexeme.buffer)!=PX_NULL + ) + { + PX_LexerSetState(state); + if(!PX_ScriptParseFunctionDefined(&analysis,PX_SCRIPT_TRANSLATOR_FUNCTION_TYPE_EXPORT)) + goto _ERROR; + } + else + { + goto _ERROR; + } + + type=PX_ScriptTranslatorNextTokenSN(&analysis.lexer); + + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER&&analysis.lexer.Symbol=='{') + { + analysis.functionInside=PX_TRUE; + buildAstStruct.type=PX_SCRIPT_AST_STRUCTURE_TYPE_FUNCTION; + PX_strcpy(buildAstStruct._func.name,analysis.currentFunc.name,sizeof(analysis.currentFunc.name)); + PX_VectorPushback(&analysis.v_astStructure,&buildAstStruct); + analysis.functionguider=PX_StringLen(&analysis.code); + continue; + } + else if (analysis.lexer.Symbol==';') + { + continue; + } + else + { + goto _ERROR; + } + } + ////////////////////////////////////////////////////////////////////////// + + + + ////////////////////////////////////////////////////////////////////////// + //IF + ////////////////////////////////////////////////////////////////////////// + if (PX_strequ(analysis.lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_IF)) + { + if (!analysis.functionInside) + { + goto _ERROR; + } + type=PX_ScriptTranslatorNextTokenSN(&analysis.lexer); + + if (type!=PX_LEXER_LEXEME_TYPE_DELIMITER||analysis.lexer.Symbol!='(') + { + goto _ERROR; + } + + //condition expression + PX_StringInitialize(analysis.mp,&expression); + PX_StringInitialize(analysis.mp,&expCode); + + if(!PX_ScriptParseGetExpression(&analysis,&expression,')')) + { + PX_StringFree(&expression); + PX_StringFree(&expCode); + goto _ERROR; + } + PX_StringCat(&analysis.code,";--------IF (CONDITION) \n"); + if(!PX_ScriptParseExpression(&analysis,expression.buffer,&expCode,&retOperand)) + { + PX_StringFree(&expression); + PX_StringFree(&expCode); + goto _ERROR; + } + PX_StringCat(&analysis.code,expCode.buffer); + PX_StringFree(&expression); + PX_StringFree(&expCode); + ////////////////////////////////////////////////////////////////////////// + + if (!PX_ScriptParseIsOperandNumericType(retOperand)) + { + goto _ERROR; + } + + + buildAstStruct.type=PX_SCRIPT_AST_STRUCTURE_TYPE_IF; + buildAstStruct._if.ifflag=analysis._jFlag++; + buildAstStruct._if.elseflag=analysis._jFlag++; + + state=PX_LexerGetState(&analysis.lexer); + type=PX_ScriptTranslatorNextTokenSN(&analysis.lexer); + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER&&analysis.lexer.Symbol=='{') + { + buildAstStruct._if.oneline_expr=PX_FALSE; + } + else + { + PX_LexerSetState(state); + buildAstStruct._if.oneline_expr=PX_TRUE; + } + PX_VectorPushback(&analysis.v_astStructure,&buildAstStruct); + + PX_StringInitialize(analysis.mp,&expression); + PX_StringFormat1(&expression,"JE R1,0,_IF_%1\n",PX_STRINGFORMAT_INT(buildAstStruct._if.ifflag)); + PX_StringCat(&analysis.code,expression.buffer); + PX_StringFree(&expression); + continue; + } + + ////////////////////////////////////////////////////////////////////////// + //WHILE + ////////////////////////////////////////////////////////////////////////// + + if (PX_strequ(analysis.lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_WHILE)) + { + if (!analysis.functionInside) + { + goto _ERROR; + } + type=PX_ScriptTranslatorNextTokenSN(&analysis.lexer); + + if (type!=PX_LEXER_LEXEME_TYPE_DELIMITER||analysis.lexer.Symbol!='(') + { + goto _ERROR; + } + + //condition expression + PX_StringInitialize(analysis.mp,&expression); + PX_StringInitialize(analysis.mp,&expCode); + + if(!PX_ScriptParseGetExpression(&analysis,&expression,')')) + { + PX_StringFree(&expression); + PX_StringFree(&expCode); + goto _ERROR; + } + PX_StringCat(&analysis.code,";--------WHILE (CONDITION) \n"); + buildAstStruct.type=PX_SCRIPT_AST_STRUCTURE_TYPE_WHILE; + buildAstStruct._while.loopflag=analysis._jFlag++; + buildAstStruct._while.endflag=analysis._jFlag++; + + PX_StringInitialize(analysis.mp,&fmrString); + PX_StringFormat1(&fmrString,"_WHILE_%1:\n",PX_STRINGFORMAT_INT(buildAstStruct._while.loopflag)); + PX_StringCat(&analysis.code,fmrString.buffer); + PX_StringFree(&fmrString); + + if(!PX_ScriptParseExpression(&analysis,expression.buffer,&expCode,&retOperand)) + { + PX_StringFree(&expression); + PX_StringFree(&expCode); + goto _ERROR; + } + PX_StringCat(&analysis.code,expCode.buffer); + PX_StringFree(&expression); + PX_StringFree(&expCode); + ////////////////////////////////////////////////////////////////////////// + + if (!PX_ScriptParseIsOperandNumericType(retOperand)) + { + goto _ERROR; + } + + + + + state=PX_LexerGetState(&analysis.lexer); + type=PX_ScriptTranslatorNextTokenSN(&analysis.lexer); + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER&&analysis.lexer.Symbol=='{') + { + buildAstStruct._while.oneline_expr=PX_FALSE; + } + else + { + PX_LexerSetState(state); + buildAstStruct._while.oneline_expr=PX_TRUE; + } + PX_VectorPushback(&analysis.v_astStructure,&buildAstStruct); + + PX_StringInitialize(analysis.mp,&expression); + PX_StringFormat1(&expression,"JE R1,0,_WHILE_%1\n",PX_STRINGFORMAT_INT(buildAstStruct._while.endflag)); + PX_StringCat(&analysis.code,expression.buffer); + PX_StringFree(&expression); + continue; + } + ////////////////////////////////////////////////////////////////////////// + //_ASM + ////////////////////////////////////////////////////////////////////////// + + if (PX_strequ(analysis.lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_ASM)) + { + if (!analysis.functionInside) + { + goto _ERROR; + } + + type=PX_ScriptTranslatorNextTokenSN(&analysis.lexer); + if (type!=PX_LEXER_LEXEME_TYPE_DELIMITER||analysis.lexer.Symbol!='{') + { + goto _ERROR; + } + + PX_StringInitialize(analysis.mp,&codes); + PX_StringInitialize(analysis.mp,&fmrString); + while (PX_TRUE) + { + type=PX_LexerGetNextLexeme(&analysis.lexer); + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER&&analysis.lexer.Symbol=='}') + { + PX_StringCat(&codes,"\n"); + break; + } + + for (i=0;itype==PX_SCRIPT_PARSER_VAR_TYPE_INT||pvar->type==PX_SCRIPT_PARSER_VAR_TYPE_FLOAT||pvar->type==PX_SCRIPT_PARSER_VAR_TYPE_STRING||pvar->type==PX_SCRIPT_PARSER_VAR_TYPE_MEMORY) + if (PX_strequ(pvar->Mnemonic.buffer,analysis.lexer.CurLexeme.buffer)) + { + PX_StringFormat1(&fmrString,"LOCAL[%1]",PX_STRINGFORMAT_INT(pvar->BeginIndex)); + PX_StringCat(&codes,fmrString.buffer); + goto _CONTINUE; + } + } + + for (i=0;itype==PX_SCRIPT_PARSER_VAR_TYPE_INT||pvar->type==PX_SCRIPT_PARSER_VAR_TYPE_FLOAT||pvar->type==PX_SCRIPT_PARSER_VAR_TYPE_STRING||pvar->type==PX_SCRIPT_PARSER_VAR_TYPE_MEMORY) + if (PX_strequ(pvar->Mnemonic.buffer,analysis.lexer.CurLexeme.buffer)) + { + PX_StringFormat1(&fmrString,"GLOBAL[%1]",PX_STRINGFORMAT_INT(pvar->BeginIndex)); + PX_StringCat(&codes,fmrString.buffer); + goto _CONTINUE; + } + } + + PX_StringCat(&codes,analysis.lexer.CurLexeme.buffer); +_CONTINUE: + PX_StringClear(&fmrString); + } + PX_StringCat(&analysis.code,codes.buffer); + PX_StringFree(&codes); + PX_StringFree(&fmrString); + continue; + } + + + ////////////////////////////////////////////////////////////////////////// + //FOR + ////////////////////////////////////////////////////////////////////////// + + if (PX_strequ(analysis.lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_FOR)) + { + if (!analysis.functionInside) + { + goto _ERROR; + } + type=PX_ScriptTranslatorNextTokenSN(&analysis.lexer); + + if (type!=PX_LEXER_LEXEME_TYPE_DELIMITER||analysis.lexer.Symbol!='(') + { + goto _ERROR; + } + + buildAstStruct.type=PX_SCRIPT_AST_STRUCTURE_TYPE_FOR; + buildAstStruct._for.additionFlag=analysis._jFlag++; + buildAstStruct._for.conditionFlag=analysis._jFlag++; + buildAstStruct._for.endFlag=analysis._jFlag++; + + //condition expression + PX_StringCat(&analysis.code,";--------FOR (INIT;CONDITION;ADDITION) \n"); + + PX_StringInitialize(analysis.mp,&expression); + PX_StringInitialize(analysis.mp,&expCode); + PX_StringInitialize(analysis.mp,&fmrString); + PX_StringInitialize(analysis.mp,&condCodes); + //INIT code + if(!PX_ScriptParseGetExpression(&analysis,&expression,';')) + { + PX_StringFree(&expression); + PX_StringFree(&expCode); + PX_StringFree(&fmrString); + PX_StringFree(&condCodes); + goto _ERROR; + } + + if(!PX_ScriptParseExpression(&analysis,expression.buffer,&expCode,&retOperand)) + { + PX_StringFree(&expression); + PX_StringFree(&expCode); + PX_StringFree(&fmrString); + PX_StringFree(&condCodes); + goto _ERROR; + } + PX_StringCat(&analysis.code,expCode.buffer); + + //Jump to condition + + PX_StringFormat1(&fmrString,"JMP _FOR_%1\n",PX_STRINGFORMAT_INT(buildAstStruct._for.conditionFlag)); + PX_StringCat(&analysis.code,fmrString.buffer); + + + //Condition + if(!PX_ScriptParseGetExpression(&analysis,&expression,';')) + { + PX_StringFree(&expression); + PX_StringFree(&expCode); + PX_StringFree(&fmrString); + PX_StringFree(&condCodes); + goto _ERROR; + } + + if(!PX_ScriptParseExpression(&analysis,expression.buffer,&expCode,&retOperand)) + { + PX_StringFree(&expression); + PX_StringFree(&expCode); + PX_StringFree(&fmrString); + PX_StringFree(&condCodes); + goto _ERROR; + } + PX_StringCat(&condCodes,expCode.buffer); + + + //Addition + //Addition flag + PX_StringFormat1(&fmrString,"_FOR_%1:\n",PX_STRINGFORMAT_INT(buildAstStruct._for.additionFlag)); + PX_StringCat(&analysis.code,fmrString.buffer); + + if(!PX_ScriptParseGetExpression(&analysis,&expression,')')) + { + PX_StringFree(&expression); + PX_StringFree(&expCode); + PX_StringFree(&fmrString); + PX_StringFree(&condCodes); + goto _ERROR; + } + + if(!PX_ScriptParseExpression(&analysis,expression.buffer,&expCode,&retOperand)) + { + PX_StringFree(&expression); + PX_StringFree(&expCode); + PX_StringFree(&fmrString); + PX_StringFree(&condCodes); + goto _ERROR; + } + PX_StringCat(&analysis.code,expCode.buffer); + + //condition + //condition flag + PX_StringFormat1(&fmrString,"_FOR_%1:\n",PX_STRINGFORMAT_INT(buildAstStruct._for.conditionFlag)); + PX_StringCat(&analysis.code,fmrString.buffer); + PX_StringCat(&analysis.code,condCodes.buffer); + + //jump to end + PX_StringFormat1(&fmrString,"JE R1,0,_FOR_%1\n",PX_STRINGFORMAT_INT(buildAstStruct._for.endFlag)); + PX_StringCat(&analysis.code,fmrString.buffer); + + PX_StringFree(&expression); + PX_StringFree(&expCode); + PX_StringFree(&fmrString); + PX_StringFree(&condCodes); + + + ////////////////////////////////////////////////////////////////////////// + + if (!PX_ScriptParseIsOperandNumericType(retOperand)) + { + goto _ERROR; + } + + + state=PX_LexerGetState(&analysis.lexer); + type=PX_ScriptTranslatorNextTokenSN(&analysis.lexer); + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER&&analysis.lexer.Symbol=='{') + { + buildAstStruct._for.oneline_expr=PX_FALSE; + } + else + { + PX_LexerSetState(state); + buildAstStruct._for.oneline_expr=PX_TRUE; + } + PX_VectorPushback(&analysis.v_astStructure,&buildAstStruct); + continue; + } + + + ////////////////////////////////////////////////////////////////////////// + //SWITCH + ////////////////////////////////////////////////////////////////////////// + if (PX_strequ(analysis.lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_SWITCH)) + { + if (!analysis.functionInside) + { + goto _ERROR; + } + + buildAstStruct.type=PX_SCRIPT_AST_STRUCTURE_TYPE_SWITCH; + buildAstStruct._compare.endFlag=analysis._jFlag++; + + type=PX_ScriptTranslatorNextTokenSN(&analysis.lexer); + + if (type!=PX_LEXER_LEXEME_TYPE_DELIMITER||analysis.lexer.Symbol!='(') + { + goto _ERROR; + } + + PX_StringCat(&analysis.code,";--------SWITCH (ORIGINAL) \n"); + + //condition expression + PX_StringInitialize(analysis.mp,&expression); + PX_StringInitialize(analysis.mp,&expCode); + + if(!PX_ScriptParseGetExpression(&analysis,&expression,')')) + { + PX_StringFree(&expression); + PX_StringFree(&expCode); + goto _ERROR; + } + + if(!PX_ScriptParseExpression(&analysis,expression.buffer,&expCode,&retOperand)) + { + PX_StringFree(&expression); + PX_StringFree(&expCode); + goto _ERROR; + } + + buildAstStruct._compare.OriginOperand=retOperand; + + PX_StringCat(&analysis.code,expCode.buffer); + PX_StringCat(&analysis.code,"PUSH R1\n"); + PX_StringFree(&expression); + PX_StringFree(&expCode); + ////////////////////////////////////////////////////////////////////////// + + state=PX_LexerGetState(&analysis.lexer); + type=PX_ScriptTranslatorNextTokenSN(&analysis.lexer); + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER&&analysis.lexer.Symbol=='{') + { + buildAstStruct._compare.oneline_expr=PX_FALSE; + } + else + { + PX_LexerSetState(state); + buildAstStruct._compare.oneline_expr=PX_TRUE; + } + + PX_VectorPushback(&analysis.v_astStructure,&buildAstStruct); + continue; + } + + + + ////////////////////////////////////////////////////////////////////////// + //CASE + ////////////////////////////////////////////////////////////////////////// + if (PX_strequ(analysis.lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_CASE)) + { + if (!analysis.functionInside) + { + goto _ERROR; + } + caseEnd=PX_FALSE; + for (i=analysis.v_astStructure.size-1;i>=0;i--) + { + astStruct=*PX_VECTORAT(PX_SCRIPT_AST_STRUCTURE,&analysis.v_astStructure,i); + if (astStruct.type==PX_SCRIPT_AST_STRUCTURE_TYPE_SWITCH) + { + break; + } + } + if (i<=0) //0 is function AST structure + { + goto _ERROR; + } + + + type=PX_ScriptTranslatorNextTokenSN(&analysis.lexer); + + if (type!=PX_LEXER_LEXEME_TYPE_DELIMITER||analysis.lexer.Symbol!='(') + { + goto _ERROR; + } + + buildAstStruct.type=PX_SCRIPT_AST_STRUCTURE_TYPE_CASE; + buildAstStruct._with.endFlag=analysis._jFlag++; + + PX_StringCat(&analysis.code,";--------WITH (CONDITION) \n"); + + //condition expression + PX_StringInitialize(analysis.mp,&expression); + PX_StringInitialize(analysis.mp,&expCode); + + PX_StringCat(&analysis.code,"MOV R3,0\n"); + PX_StringCat(&analysis.code,"MOV R2,GLOBAL[SP]\n"); + + while(PX_TRUE) + { + +// if(!PX_ScriptParseGetExpression(&analysis,&expression,';')) +// { +// PX_StringFree(&expression); +// PX_StringFree(&expCode); +// goto _ERROR; +// } + ////////////////////////////////////////////////////////////////////////// + PX_StringClear(&expression); + mBracket=0,lBracket=0; + + while (PX_TRUE) + { + type=PX_ScriptTranslatorNextToken(&analysis.lexer); + + if (type==PX_LEXER_LEXEME_TYPE_NEWLINE) + { + PX_StringFree(&expression); + PX_StringFree(&expCode); + goto _ERROR; + } + if (type==PX_LEXER_LEXEME_TYPE_END) + { + PX_StringFree(&expression); + PX_StringFree(&expCode); + goto _ERROR; + } + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER&&analysis.lexer.Symbol==';'&&!mBracket&&!lBracket) + { + break; + } + + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER&&analysis.lexer.Symbol==')'&&!mBracket&&!lBracket) + { + caseEnd=PX_TRUE; + break; + } + + if (analysis.lexer.Symbol=='(') + { + lBracket++; + } + if (analysis.lexer.Symbol==')') + { + lBracket--; + if(lBracket<0) + return PX_FALSE; + } + if (analysis.lexer.Symbol=='[') + { + mBracket++; + } + if (analysis.lexer.Symbol==']') + { + mBracket--; + if(mBracket<0) + return PX_FALSE; + } + + if (type==PX_LEXER_LEXEME_TYPE_SPACER) + { + continue; + } + + PX_StringCat(&expression,analysis.lexer.CurLexeme.buffer); + } + ////////////////////////////////////////////////////////////////////////// + + if(!PX_ScriptParseExpression(&analysis,expression.buffer,&expCode,&retOperand)) + { + PX_StringFree(&expression); + PX_StringFree(&expCode); + goto _ERROR; + } + + if (!PX_ScriptParseIsCompareAbleOperand(retOperand,astStruct._compare.OriginOperand)) + { + PX_StringFree(&expression); + PX_StringFree(&expCode); + PX_ScriptTranslatorError(&analysis.lexer,"Invalid operand-type."); + goto _ERROR; + } + + PX_StringCat(&analysis.code,expCode.buffer); + PX_StringCat(&analysis.code,"LGE R1,R1,R2\n"); + PX_StringCat(&analysis.code,"OR R3,R1\n"); + state=PX_LexerGetState(&analysis.lexer); + + if (caseEnd) + { + break; + } + + } + PX_StringFormat1(&expCode,"JE R3,0,_WITH_%1\n",PX_STRINGFORMAT_INT(buildAstStruct._with.endFlag)); + PX_StringCat(&analysis.code,expCode.buffer); + + PX_StringFree(&expression); + PX_StringFree(&expCode); + + ////////////////////////////////////////////////////////////////////////// + + + state=PX_LexerGetState(&analysis.lexer); + type=PX_ScriptTranslatorNextTokenSN(&analysis.lexer); + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER&&analysis.lexer.Symbol=='{') + { + buildAstStruct._with.oneline_expr=PX_FALSE; + } + else + { + PX_LexerSetState(state); + buildAstStruct._with.oneline_expr=PX_TRUE; + } + + PX_VectorPushback(&analysis.v_astStructure,&buildAstStruct); + continue; + } + /////////////////////////////////////////////////////////////////////////// + //break + ////////////////////////////////////////////////////////////////////////// + + if (PX_strequ(analysis.lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_BREAK)) + { + type=PX_ScriptTranslatorNextToken(&analysis.lexer); + + if (type!=PX_LEXER_LEXEME_TYPE_DELIMITER||analysis.lexer.Symbol!=';') + { + goto _ERROR; + } + for (i=analysis.v_astStructure.size-1;i>=0;i--) + { + astStruct=*PX_VECTORAT(PX_SCRIPT_AST_STRUCTURE,&analysis.v_astStructure,i); + switch(astStruct.type) + { + case PX_SCRIPT_AST_STRUCTURE_TYPE_WHILE: + { + PX_StringInitialize(analysis.mp,&fmrString); + PX_StringFormat1(&fmrString,"JMP _WHILE_%1\n",PX_STRINGFORMAT_INT(astStruct._while.endflag)); + PX_StringCat(&analysis.code,fmrString.buffer); + PX_StringFree(&fmrString); + goto _BREAKOUT; + } + break; + case PX_SCRIPT_AST_STRUCTURE_TYPE_FOR: + { + PX_StringInitialize(analysis.mp,&fmrString); + PX_StringFormat1(&fmrString,"JMP _FOR_%1\n",PX_STRINGFORMAT_INT(astStruct._for.endFlag)); + PX_StringCat(&analysis.code,fmrString.buffer); + PX_StringFree(&fmrString); + goto _BREAKOUT; + } + break; + case PX_SCRIPT_AST_STRUCTURE_TYPE_SWITCH: + { + PX_StringInitialize(analysis.mp,&fmrString); + PX_StringFormat1(&fmrString,"JMP _COMPARE_%1\n",PX_STRINGFORMAT_INT(astStruct._compare.endFlag)); + PX_StringCat(&analysis.code,fmrString.buffer); + PX_StringFree(&fmrString); + goto _BREAKOUT; + } + break; + default: + continue; + } + } + _BREAKOUT: + if (i<0) + { + PX_ScriptTranslatorError(&analysis.lexer,"Could not matched break to block."); + goto _ERROR; + } + if(!PX_ScriptParseIfLastAST(&analysis)) goto _ERROR; + continue; + } + + + /////////////////////////////////////////////////////////////////////////// + //continue + ////////////////////////////////////////////////////////////////////////// + + if (PX_strequ(analysis.lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_CONTINUE)) + { + type=PX_ScriptTranslatorNextToken(&analysis.lexer); + + if (type!=PX_LEXER_LEXEME_TYPE_DELIMITER||analysis.lexer.Symbol!=';') + { + goto _ERROR; + } + for (i=analysis.v_astStructure.size-1;i>=0;i--) + { + astStruct=*PX_VECTORAT(PX_SCRIPT_AST_STRUCTURE,&analysis.v_astStructure,i); + switch(astStruct.type) + { + case PX_SCRIPT_AST_STRUCTURE_TYPE_WHILE: + { + PX_StringInitialize(analysis.mp,&fmrString); + PX_StringFormat1(&fmrString,"JMP _WHILE_%1\n",PX_STRINGFORMAT_INT(astStruct._while.loopflag)); + PX_StringCat(&analysis.code,fmrString.buffer); + PX_StringFree(&fmrString); + goto _CONTINUEOUT; + } + break; + case PX_SCRIPT_AST_STRUCTURE_TYPE_FOR: + { + PX_StringInitialize(analysis.mp,&fmrString); + PX_StringFormat1(&fmrString,"JMP _FOR_%1\n",PX_STRINGFORMAT_INT(astStruct._for.additionFlag)); + PX_StringCat(&analysis.code,fmrString.buffer); + PX_StringFree(&fmrString); + goto _CONTINUEOUT; + } + break; + default: + continue; + } + } +_CONTINUEOUT: + if (i<0) + { + PX_ScriptTranslatorError(&analysis.lexer,"Could not matched break to block."); + goto _ERROR; + } + if(!PX_ScriptParseIfLastAST(&analysis)) goto _ERROR; + continue; + } + + /////////////////////////////////////////////////////////////////////////// + //Return + ////////////////////////////////////////////////////////////////////////// + if (PX_strequ(analysis.lexer.CurLexeme.buffer,PX_SCRIPT_TRANSLATOR_KEYWORD_RETURN)) + { + if (!analysis.functionInside) + { + goto _ERROR; + } + //custom expression + PX_StringInitialize(analysis.mp,&expression); + PX_StringInitialize(analysis.mp,&expCode); + + if(!PX_ScriptParseGetExpression(&analysis,&expression,';')) + { + PX_StringFree(&expression); + PX_StringFree(&expCode); + goto _ERROR; + } + PX_StringCat(&analysis.code,";RETURN (EXPRESSION)\n"); + if(!PX_ScriptParseExpression(&analysis,expression.buffer,&expCode,&retOperand)) + { + PX_StringFree(&expression); + PX_StringFree(&expCode); + goto _ERROR; + } + + + PX_StringCat(&analysis.code,expCode.buffer); + PX_StringFree(&expression); + PX_StringFree(&expCode); + + switch (analysis.currentFunc.retType) + { + case PX_SCRIPT_PARSER_VAR_TYPE_VOID: + if (retOperand.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_VOID) + { + PX_ScriptTranslatorError(&analysis.lexer,"Return-type not matched."); + goto _ERROR; + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_INT: + if (retOperand.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_INT&&retOperand.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST&&\ + retOperand.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT&&retOperand.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST&&\ + retOperand.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX&&retOperand.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX) + { + PX_ScriptTranslatorError(&analysis.lexer,"Return-type not matched."); + goto _ERROR; + } + if (retOperand.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT||retOperand.operandType==PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST) + { + PX_StringCat(&analysis.code,"INT R1\n"); + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_FLOAT: + if (retOperand.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_INT&&retOperand.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST&&\ + retOperand.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT&&retOperand.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST&&\ + retOperand.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX&&retOperand.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX) + { + PX_ScriptTranslatorError(&analysis.lexer,"Return-type not matched."); + goto _ERROR; + } + if (retOperand.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT||retOperand.operandType==PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST) + { + PX_StringCat(&analysis.code,"FLT R1\n"); + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_STRING: + if (retOperand.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_STRING&&retOperand.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_STRING_CONST) + { + PX_ScriptTranslatorError(&analysis.lexer,"Return-type not matched."); + goto _ERROR; + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_MEMORY: + if (retOperand.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY&&retOperand.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_CONST) + { + PX_ScriptTranslatorError(&analysis.lexer,"Return-type not matched."); + goto _ERROR; + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_INT_PTR: + if (retOperand.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR&&retOperand.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR_CONST) + { + PX_ScriptTranslatorError(&analysis.lexer,"Return-type not matched."); + goto _ERROR; + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_FLOAT_PTR: + if (retOperand.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR&&retOperand.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR_CONST) + { + PX_ScriptTranslatorError(&analysis.lexer,"Return-type not matched."); + goto _ERROR; + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_STRING_PTR: + if (retOperand.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR&&retOperand.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR_CONST) + { + PX_ScriptTranslatorError(&analysis.lexer,"Return-type not matched."); + goto _ERROR; + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_MEMORY_PTR: + if (retOperand.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR&&retOperand.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR_CONST) + { + PX_ScriptTranslatorError(&analysis.lexer,"Return-type not matched."); + goto _ERROR; + } + break; + case PX_SCRIPT_PARSER_VAR_TYPE_STRUCT_PTR: + if (retOperand.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_STRUCT_PTR&&retOperand.operandType!=PX_SCRIPT_AST_OPERAND_TYPE_SET_PTR_CONST) + { + PX_ScriptTranslatorError(&analysis.lexer,"Return-type not matched."); + goto _ERROR; + } + if (retOperand.pSet!=PX_ScriptParseGetStructByIndex(&analysis,analysis.currentFunc.retSetIndex)) + { + PX_ScriptTranslatorError(&analysis.lexer,"Return-type not matched."); + goto _ERROR; + } + break; + default: + goto _ERROR; + } + + PX_StringInitialize(analysis.mp,&fmrString); + PX_StringFormat1(&fmrString,"JMP _%1_RET\n",PX_STRINGFORMAT_STRING(analysis.currentFunc.name)); + PX_StringCat(&analysis.code,fmrString.buffer); + PX_StringFree(&fmrString); + + + if(!PX_ScriptParseIfLastAST(&analysis)) goto _ERROR; + continue; + } + + + //Expression parse + + if(analysis.functionInside) + { + + if (type==PX_LEXER_LEXEME_TYPE_DELIMITER&&analysis.lexer.Symbol=='}') + { + if(!PX_ScriptParseLastCodeblockEnd(&analysis)) goto _ERROR; + } + else + { + //custom expression + PX_LexerSetState(state); + + PX_StringInitialize(analysis.mp,&expression); + PX_StringInitialize(analysis.mp,&expCode); + + if(!PX_ScriptParseGetExpression(&analysis,&expression,';')) + { + PX_StringFree(&expression); + PX_StringFree(&expCode); + goto _ERROR; + } + + if(!PX_ScriptParseExpression(&analysis,expression.buffer,&expCode,&retOperand)) + { + PX_StringFree(&expression); + PX_StringFree(&expCode); + goto _ERROR; + } + + PX_StringCat(&analysis.code,expCode.buffer); + + PX_StringFree(&expression); + PX_StringFree(&expCode); + + if(!PX_ScriptParseIfLastAST(&analysis)) goto _ERROR; + } + continue; + } + ////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////// + // + + PX_ScriptTranslatorError(&analysis.lexer,"Invalid expression."); + goto _ERROR; + + } + ////////////////////////////////////////////////////////////////////////// + //Output + if (!PX_ScriptParseBootCode(&analysis)) + { + goto _ERROR; + } + //.Global .Local + globalSize=0; + for (i=0;isize; + } + + PX_StringInitialize(analysis.mp,&fmrString); + PX_StringFormat3(&fmrString,".GLOBAL %1\n.STACK %2\n.THREAD %3\n",PX_STRINGFORMAT_INT(globalSize),PX_STRINGFORMAT_INT(LocalStackSize),PX_STRINGFORMAT_INT(thread)); + PX_StringCat(ASM,fmrString.buffer); + PX_StringFree(&fmrString); + + PX_StringCat(ASM,"EXPORT FUNCTION _BOOT:\n"); + + PX_StringInitialize(analysis.mp,&fmrString); + for (i=0;ibParam&&pvar->type==PX_SCRIPT_PARSER_VAR_TYPE_STRING) + { + PX_StringFormat1(&fmrString,"MOV GLOBAL[%1],\"\"\n",PX_STRINGFORMAT_INT(pvar->BeginIndex)); + PX_StringCat(ASM,fmrString.buffer); + } + if (!pvar->bParam&&pvar->type==PX_SCRIPT_PARSER_VAR_TYPE_MEMORY) + { + PX_StringFormat1(&fmrString,"MOV GLOBAL[%1],@@\n",PX_STRINGFORMAT_INT(pvar->BeginIndex)); + PX_StringCat(ASM,fmrString.buffer); + } + } + PX_StringFree(&fmrString); + + PX_StringCat(ASM,analysis.bootCode.buffer); + PX_StringCat(ASM,"RET\n"); + + PX_StringCat(ASM,analysis.code.buffer); + + if (analysis.v_astStructure.size) + { + while(analysis.v_astStructure.size) + { + PX_ScriptParsePopAstStructure(&analysis); + } + goto _ERROR; + } + + for (i=0;iMnemonic); + if (PX_VECTORAT(PX_SCRIPT_VARIABLES,&analysis.v_variablesGlobalTable,i)->bInitialized) + { + PX_StringFree(&PX_VECTORAT(PX_SCRIPT_VARIABLES,&analysis.v_variablesGlobalTable,i)->GlobalInitializeValue); + } + } + + for (i=0;iMnemonic); + if (pvar->bInitialized) + { + PX_StringFree(&pvar->GlobalInitializeValue); + } + } + + //struct + for (i=0;imembers.size;j++) + { + psetmem=PX_VECTORAT(PX_SCRIPT_SETMEMBER,&pset->members,j); + PX_StringFree(&psetmem->defvar.Mnemonic); + if (psetmem->defvar.bInitialized) + { + PX_StringFree(&psetmem->defvar.GlobalInitializeValue); + } + } + PX_StringFree(&pset->Name); + PX_VectorFree(&pset->members); + } + + //ast structure + + + PX_VectorFree(&analysis.v_astStructure); + PX_VectorFree(&analysis.v_variablesGlobalTable); + PX_VectorFree(&analysis.v_variablesStackTable); + PX_VectorFree(&analysis.v_struct); + PX_VectorFree(&analysis.v_functions); + + PX_StringFree(&analysis.bootCode); + PX_StringFree(&analysis.code); + PX_LexerFree(&analysis.lexer); + return PX_TRUE; +_ERROR: + PX_ScriptTranslatorError(&analysis.lexer,"ERROR:Compile terminated."); + + if (analysis.v_astStructure.size) + { + while(analysis.v_astStructure.size) + { + PX_ScriptParsePopAstStructure(&analysis); + } + goto _ERROR; + } + + for (i=0;iMnemonic); + if (PX_VECTORAT(PX_SCRIPT_VARIABLES,&analysis.v_variablesGlobalTable,i)->bInitialized) + { + PX_StringFree(&PX_VECTORAT(PX_SCRIPT_VARIABLES,&analysis.v_variablesGlobalTable,i)->GlobalInitializeValue); + } + } + + for (i=0;iMnemonic); + if (PX_VECTORAT(PX_SCRIPT_VARIABLES,&analysis.v_variablesStackTable,i)->bInitialized) + { + PX_StringFree(&PX_VECTORAT(PX_SCRIPT_VARIABLES,&analysis.v_variablesStackTable,i)->GlobalInitializeValue); + } + } + + //struct + for (i=0;imembers.size;j++) + { + psetmem=PX_VECTORAT(PX_SCRIPT_SETMEMBER,&pset->members,j); + PX_StringFree(&psetmem->defvar.Mnemonic); + if (psetmem->defvar.bInitialized) + { + PX_StringFree(&psetmem->defvar.GlobalInitializeValue); + } + } + PX_StringFree(&pset->Name); + PX_VectorFree(&pset->members); + } + + //ast structure + + + PX_VectorFree(&analysis.v_astStructure); + PX_VectorFree(&analysis.v_variablesGlobalTable); + PX_VectorFree(&analysis.v_variablesStackTable); + PX_VectorFree(&analysis.v_struct); + PX_VectorFree(&analysis.v_functions); + + PX_StringFree(&analysis.bootCode); + PX_StringFree(&analysis.code); + PX_LexerFree(&analysis.lexer); + + + return PX_FALSE; +} + +px_char * PX_ScriptCompilerError(void) +{ + return PX_Script_InterpreterError; +} + +px_bool PX_ScriptInterpreterExpression(PX_SCRIPT_Analysis *analysis,px_char *expr,px_string *out,PX_SCRIPT_AST_OPERAND *retOperand) +{ + return PX_ScriptParseExpression(analysis,expr,out,retOperand); +} + + + diff --git a/lib/PainterEngine/kernel/PX_Script_Interpreter.h b/lib/PainterEngine/kernel/PX_Script_Interpreter.h new file mode 100644 index 0000000000000000000000000000000000000000..0fecdc89dcef4ce7cd10ca6df80652ce5c6d509e --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Script_Interpreter.h @@ -0,0 +1,429 @@ +////////////////////////////////////////////////////////////////////////// +//Painter Engine Interpreter +//code by DBinary, matrixcascade@gmail.com +//QQ:477608346,tel-18959060883 +//include script compiler & parser & AST + +#ifndef _PX_SCRIPT_TRANSLATOR_H +#define _PX_SCRIPT_TRANSLATOR_H +#include "PX_ScriptCore.h" + +#define PX_SCRIPT_TRANSLATOR_FLOAT_PRECISION 6 +#define PX_SCRIPT_OPCODE_LEVEL_BOTTOM 255 +#define PX_SCRIPT_FUNCTION_MAX_PARAM 16 +#define PX_SCRIPT_FUNCTION_NAME_MAX_LEN 48 + + + +typedef enum +{ + PX_SCRIPT_PARSER_VAR_TYPE_INT, + PX_SCRIPT_PARSER_VAR_TYPE_STRING, + PX_SCRIPT_PARSER_VAR_TYPE_FLOAT, + PX_SCRIPT_PARSER_VAR_TYPE_MEMORY, + PX_SCRIPT_PARSER_VAR_TYPE_VOID, + PX_SCRIPT_PARSER_VAR_TYPE_STRUCT, + + PX_SCRIPT_PARSER_VAR_TYPE_INT_ARRAY, + PX_SCRIPT_PARSER_VAR_TYPE_STRING_ARRAY, + PX_SCRIPT_PARSER_VAR_TYPE_FLOAT_ARRAY, + PX_SCRIPT_PARSER_VAR_TYPE_MEMORY_ARRAY, + PX_SCRIPT_PARSER_VAR_TYPE_SET_ARRAY, + + PX_SCRIPT_PARSER_VAR_TYPE_INT_PTR, + PX_SCRIPT_PARSER_VAR_TYPE_STRING_PTR, + PX_SCRIPT_PARSER_VAR_TYPE_FLOAT_PTR, + PX_SCRIPT_PARSER_VAR_TYPE_MEMORY_PTR, + PX_SCRIPT_PARSER_VAR_TYPE_STRUCT_PTR, + +}PX_SCRIPT_PARSER_VAR_TYPE; + +typedef enum +{ + //// + PX_SCRIPT_TRANSLATOR_EXPRESSION_TOKEN, + //// + + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_FUNCTION, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_ADD, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_INC, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_POSITIVE, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_SUB, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_DEC, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_NEGATIVE, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_MUL, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_DIV, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_AND, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_OR, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_NOT, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_XOR, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_INV, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_MOD, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_SHL, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_SHR, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_DOT, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_COMMA, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LBRACKETBEGIN, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LBRACKETEND, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_MBRACKETBEGIN, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_MBRACKETEND, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LARGE, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LARGEEUQ, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LESS, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LESSEQU, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_UNEQU, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_EQU, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LGEQU, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LAND, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_LOR, + //pointer + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_PTR, //* + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_ADR, //& + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_OFT, //-> + + //transfer + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_INT, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_FLOAT, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_STRING, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_MEMORY, + + //key word + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_STRLEN, + PX_SCRIPT_TRANSLATOR_EXPRESSION_OP_MEMLEN, +}PX_SCRIPT_TRANSLATOR_EXPRESSION_TYPE; + +typedef enum +{ + PX_SCRIPT_AST_OPCODE_TYPE_ADD, + PX_SCRIPT_AST_OPCODE_TYPE_INC, + PX_SCRIPT_AST_OPCODE_TYPE_POSITIVE, + PX_SCRIPT_AST_OPCODE_TYPE_SUB, + PX_SCRIPT_AST_OPCODE_TYPE_DEC, + PX_SCRIPT_AST_OPCODE_TYPE_NEGATIVE, + PX_SCRIPT_AST_OPCODE_TYPE_MUL, + PX_SCRIPT_AST_OPCODE_TYPE_DIV, + PX_SCRIPT_AST_OPCODE_TYPE_AND, + PX_SCRIPT_AST_OPCODE_TYPE_OR, + PX_SCRIPT_AST_OPCODE_TYPE_NOT, + PX_SCRIPT_AST_OPCODE_TYPE_XOR, + PX_SCRIPT_AST_OPCODE_TYPE_INV, + PX_SCRIPT_AST_OPCODE_TYPE_MOD, + PX_SCRIPT_AST_OPCODE_TYPE_SHL, + PX_SCRIPT_AST_OPCODE_TYPE_SHR, + + PX_SCRIPT_AST_OPCODE_TYPE_COMMA, + PX_SCRIPT_AST_OPCODE_TYPE_LARGE, + PX_SCRIPT_AST_OPCODE_TYPE_LARGEEQU, + PX_SCRIPT_AST_OPCODE_TYPE_LESS, + PX_SCRIPT_AST_OPCODE_TYPE_LESSEQU, + PX_SCRIPT_AST_OPCODE_TYPE_UNEQU, + PX_SCRIPT_AST_OPCODE_TYPE_EQU, + PX_SCRIPT_AST_OPCODE_TYPE_LGEQU, + PX_SCRIPT_AST_OPCODE_TYPE_LAND, + PX_SCRIPT_AST_OPCODE_TYPE_LOR, + //pointer + PX_SCRIPT_AST_OPCODE_TYPE_PTR, //* + PX_SCRIPT_AST_OPCODE_TYPE_ADR, //& + PX_SCRIPT_AST_OPCODE_TYPE_DOT, //. + PX_SCRIPT_AST_OPCODE_TYPE_IDX, //[] + PX_SCRIPT_AST_OPCODE_TYPE_OFT, //-> + //transfer + PX_SCRIPT_AST_OPCODE_TYPE_INT, + PX_SCRIPT_AST_OPCODE_TYPE_STRING, + PX_SCRIPT_AST_OPCODE_TYPE_FLOAT, + PX_SCRIPT_AST_OPCODE_TYPE_MEMORY, + PX_SCRIPT_AST_OPCODE_TYPE_STRLEN, + PX_SCRIPT_AST_OPCODE_TYPE_MEMLEN, + PX_SCRIPT_AST_OPCODE_TYPE_SIN, + PX_SCRIPT_AST_OPCODE_TYPE_COS, +}PX_SCRIPT_AST_OPCODE_TYPE; + +typedef enum +{ + PX_SCRIPT_AST_OPERAND_TYPE_VOID, + + PX_SCRIPT_AST_OPERAND_TYPE_INT, //int var //region G/L/ + PX_SCRIPT_AST_OPERAND_TYPE_FLOAT, //float var + PX_SCRIPT_AST_OPERAND_TYPE_STRING, //string var + PX_SCRIPT_AST_OPERAND_TYPE_MEMORY,//memory var + PX_SCRIPT_AST_OPERAND_TYPE_STRUCT, //set xx var + + PX_SCRIPT_AST_OPERAND_TYPE_INT_CONST,//int const + PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_CONST,//float const + PX_SCRIPT_AST_OPERAND_TYPE_STRING_CONST,//string const + PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_CONST,//memory const + + PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR, //int var[x] + PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR,//float var[x] + PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR,//string var[x] + PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR,//memory var[x] + PX_SCRIPT_AST_OPERAND_TYPE_STRUCT_PTR,//set xx var[x] + + PX_SCRIPT_AST_OPERAND_TYPE_INT_PTR_CONST, //int var[] + PX_SCRIPT_AST_OPERAND_TYPE_FLOAT_PTR_CONST,//float var[] + PX_SCRIPT_AST_OPERAND_TYPE_STRING_PTR_CONST,//string var[] + PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_PTR_CONST,//memory var[] + PX_SCRIPT_AST_OPERAND_TYPE_SET_PTR_CONST,//set xx var[] + + PX_SCRIPT_AST_OPERAND_TYPE_STRING_IDX, + PX_SCRIPT_AST_OPERAND_TYPE_MEMORY_IDX, +}PX_SCRIPT_AST_OPERAND_TYPE; + +typedef enum +{ + PX_SCRIPT_TRANSLATOR_OP_CLASS_SINGLE, + PX_SCRIPT_TRANSLATOR_OP_CLASS_BINARY, + PX_SCRIPT_TRANSLATOR_OP_CLASS_CONTAINER, + PX_SCRIPT_TRANSLATOR_OP_CLASS_CONST, + PX_SCRIPT_TRANSLATOR_OP_CLASS_VAR, + PX_SCRIPT_TRANSLATOR_OP_CLASS_FUNC, + PX_SCRIPT_TRANSLATOR_OP_CLASS_UNDEFINED, +}PX_SCRIPT_TRANSLATOR_OP_CLASS; + + +typedef enum +{ + PX_SCRIPT_TRANSLATOR_FUNCTION_TYPE_HOST, + PX_SCRIPT_TRANSLATOR_FUNCTION_TYPE_EXPORT, + PX_SCRIPT_TRANSLATOR_FUNCTION_TYPE_CUSTOM, +}PX_SCRIPT_TRANSLATOR_FUNCTION_TYPE; + +typedef enum +{ + PX_SCRIPT_VARIABLE_REGION_LOCAL, + PX_SCRIPT_VARIABLE_REGION_GLOBAL, + PX_SCRIPT_VARIABLE_REGION_POP, +}PX_SCRIPT_VARIABLE_REGION; + +#define PX_SCRIPT_TRANSLATOR_KEYWORD_RUNTIME "#RUNTIME" +#define PX_SCRIPT_TRANSLATOR_KEYWORD_STACK "STACK" +#define PX_SCRIPT_TRANSLATOR_KEYWORD_THREAD "THREAD" + +#define PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_INT "INT" +#define PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_STRING "STRING" +#define PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_MEMORY "MEMORY" +#define PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_FLOAT "FLOAT" +#define PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_VOID "VOID" +#define PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_STRUCT "STRUCT" +#define PX_SCRIPT_TRANSLATOR_KEYWORD_RETURN "RETURN" +#define PX_SCRIPT_TRANSLATOR_KEYWORD_VAR_SIZEOF "SIZEOF" + +#define PX_SCRIPT_TRANSLATOR_KEYWORD_IF "IF" +#define PX_SCRIPT_TRANSLATOR_KEYWORD_ELSE "ELSE" + +#define PX_SCRIPT_TRANSLATOR_KEYWORD_WHILE "WHILE" +#define PX_SCRIPT_TRANSLATOR_KEYWORD_FOR "FOR" + +#define PX_SCRIPT_TRANSLATOR_KEYWORD_ASM "_ASM" + +#define PX_SCRIPT_TRANSLATOR_KEYWORD_BREAK "BREAK" +#define PX_SCRIPT_TRANSLATOR_KEYWORD_CONTINUE "CONTINUE" + +#define PX_SCRIPT_TRANSLATOR_KEYWORD_SWITCH "SWITCH" +#define PX_SCRIPT_TRANSLATOR_KEYWORD_CASE "CASE" + +#define PX_SCRIPT_TRANSLATOR_KEYWORD_HOST "HOST" +#define PX_SCRIPT_TRANSLATOR_KEYWORD_FUNCTION "FUNCTION" +#define PX_SCRIPT_TRANSLATOR_KEYWORD_EXPORT "EXPORT" + + + +typedef struct +{ + px_string name; + px_string code; + px_bool bInclude; +}PX_SCRIPT_CODE; + +typedef struct +{ + px_string Name; + px_vector members; + px_int size; +}PX_SCRIPT_STRUCT; + +typedef struct +{ + px_string Mnemonic; + PX_SCRIPT_PARSER_VAR_TYPE type; + px_int layer; + px_int setIndex; + px_int BeginIndex; + px_int size; + px_bool bParam; + px_bool bInitialized; + px_string GlobalInitializeValue; +}PX_SCRIPT_VARIABLES; + +typedef struct +{ + px_int offset; + PX_SCRIPT_VARIABLES defvar; +}PX_SCRIPT_SETMEMBER; + +typedef struct +{ + px_memorypool *mp; + px_vector codeLibraries;//PX_SCRIPT_CODE vector +}PX_SCRIPT_LIBRARY; + + +typedef struct +{ + PX_SCRIPT_AST_OPCODE_TYPE operandType; + px_int level; +}PX_SCRIPT_AST_OPCODE; + +typedef struct +{ + PX_SCRIPT_AST_OPERAND_TYPE operandType; + PX_SCRIPT_VARIABLE_REGION region; + PX_SCRIPT_STRUCT *pSet; + union + { + px_int _oft; + px_int _int; + px_float _float; + px_char *_contaniner; + }; + px_bool bAtomPopIndex; + px_int AtomIndex; +}PX_SCRIPT_AST_OPERAND; + + + + +typedef struct +{ + PX_SCRIPT_TRANSLATOR_EXPRESSION_TYPE type; + PX_SCRIPT_TRANSLATOR_OP_CLASS opclass; + px_int oplevel; + px_string code; + +}PX_SCRIPT_EXPR_STREAM; + + +typedef struct +{ + PX_SCRIPT_TRANSLATOR_FUNCTION_TYPE type; + px_char name[48]; + PX_SCRIPT_VARIABLES parameters[PX_SCRIPT_FUNCTION_MAX_PARAM]; + px_int parametersCount; + px_int parametersSize; + + PX_SCRIPT_PARSER_VAR_TYPE retType; + px_int retSetIndex; +}PX_SCRIPT_FUNCTION; + + + +typedef struct +{ + px_char name[48]; +}PX_SCRIPT_AST_STRUCTURE_FUNCTION; + +typedef struct +{ + px_int ifflag; + px_int elseflag; + px_bool oneline_expr; +}PX_SCRIPT_AST_STRUCTURE_IF; + +typedef struct +{ + px_int elseflag; + px_bool oneline_expr; +}PX_SCRIPT_AST_STRUCTURE_ELSE; + +typedef struct +{ + px_int loopflag; + + px_int endflag; + px_bool oneline_expr; +}PX_SCRIPT_AST_STRUCTURE_WHILE; + +typedef struct +{ + px_int additionFlag; + px_int conditionFlag; + px_int endFlag; + px_bool oneline_expr; +}PX_SCRIPT_AST_STRUCTURE_FOR; + +typedef struct +{ + px_int endFlag; + px_bool oneline_expr; + PX_SCRIPT_AST_OPERAND OriginOperand; +}PX_SCRIPT_AST_STRUCTURE_COMPARE; + +typedef struct +{ + px_int endFlag; + px_bool oneline_expr; +}PX_SCRIPT_AST_STRUCTURE_WITH; + + +typedef enum +{ + PX_SCRIPT_AST_STRUCTURE_TYPE_FUNCTION, + PX_SCRIPT_AST_STRUCTURE_TYPE_IF, + PX_SCRIPT_AST_STRUCTURE_TYPE_ELSE, + PX_SCRIPT_AST_STRUCTURE_TYPE_WHILE, + PX_SCRIPT_AST_STRUCTURE_TYPE_FOR, + PX_SCRIPT_AST_STRUCTURE_TYPE_SWITCH, + PX_SCRIPT_AST_STRUCTURE_TYPE_CASE +}PX_SCRIPT_AST_STRUCTURE_TYPE; + +typedef struct +{ + PX_SCRIPT_AST_STRUCTURE_TYPE type; + union + { + PX_SCRIPT_AST_STRUCTURE_FUNCTION _func; + PX_SCRIPT_AST_STRUCTURE_IF _if; + PX_SCRIPT_AST_STRUCTURE_ELSE _else; + PX_SCRIPT_AST_STRUCTURE_WHILE _while; + PX_SCRIPT_AST_STRUCTURE_FOR _for; + PX_SCRIPT_AST_STRUCTURE_COMPARE _compare; + PX_SCRIPT_AST_STRUCTURE_WITH _with; + }; +}PX_SCRIPT_AST_STRUCTURE; + +typedef enum +{ + PX_SCRIPT_AST_SET_TREE_NODE_TYPE_STRUCT, + PX_SCRIPT_AST_SET_TREE_NODE_TYPE_MEMBER, +}PX_SCRIPT_AST_SET_TREE_NODE_TYPE; + + + + +typedef struct +{ + px_memorypool *mp; + px_string bootCode; + px_string code; + px_lexer lexer; + px_bool functionInside; + px_bool functionReturn; + px_int functionlable; + px_int functionguider; + PX_SCRIPT_FUNCTION currentFunc; + px_vector v_struct; + px_vector v_functions; + px_vector v_variablesGlobalTable; + px_vector v_variablesStackTable; + px_int currentAllocStackSize; + px_vector v_astStructure; + px_int _jFlag; +}PX_SCRIPT_Analysis; + +px_bool PX_ScriptCompilerInitialize(PX_SCRIPT_LIBRARY *lib,px_memorypool *mp); +px_bool PX_ScriptCompilerLoad(PX_SCRIPT_LIBRARY *lib,const px_char *code); +px_bool PX_ScriptCompilerCompile(PX_SCRIPT_LIBRARY *lib,const px_char *name,px_string *ASM,px_int StackSize); +px_void PX_ScriptCompilerFree(PX_SCRIPT_LIBRARY *lib); +px_char *PX_ScriptCompilerError(void); +px_bool PX_ScriptInterpreterExpression(PX_SCRIPT_Analysis *analysis,px_char *expr,px_string *out,PX_SCRIPT_AST_OPERAND *retOperand); +#endif diff --git a/lib/PainterEngine/kernel/PX_Script_VM.c b/lib/PainterEngine/kernel/PX_Script_VM.c new file mode 100644 index 0000000000000000000000000000000000000000..ea9d2e172f0b320515eea21f33002ff5cf15139d --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Script_VM.c @@ -0,0 +1,4758 @@ +#include "PX_Script_VM.h" + + +static px_void PX_ScriptVM_Error(PX_ScriptVM_Instance *Ins,px_char *log) +{ + PX_ERROR(log); +} + +static px_void PX_ScriptVM_LOG(px_char *log) +{ + PX_LOG(log); +} +#ifdef PX_DEBUG_MODE +#include "stdio.h" +#define PX_SCRIPT_VM_LOG printf +#else +#define PX_SCRIPT_VM_LOG +#endif + +static PX_ScriptVM_DebuggerPrint g_scriptVM_printFunc=PX_NULL; +static PX_ScriptVM_DebuggerCommand g_scriptVM_cmdFunc=PX_NULL; + +px_bool PX_ScriptVM_InstanceInitialize(PX_ScriptVM_Instance *Ins,px_memorypool *mp,px_byte *code,px_int size) +{ + PX_SCRIPT_ASM_HEADER *header; + PX_SCRIPT_EXPORT_FUNCTION *pfunc; + PX_SCRIPT_ASM_HOST_NODE *phost; + px_int i,j; + if (sizeuser_ptr=PX_NULL; + Ins->mp=mp; + header=(PX_SCRIPT_ASM_HEADER *)code; + Ins->debug=PX_FALSE; + Ins->VM_Globalsize=header->globalsize; + Ins->VM_Stacksize=header->stacksize; + Ins->VM_memsize=header->globalsize+header->stacksize*header->threadcount; + Ins->maxThreadCount=header->threadcount; + Ins->T=0; + + if (header->threadcount<1) + { + return PX_FALSE; + } + + if (!PX_memequ(header,"PASM",4)) + { + return PX_FALSE; + } + + if (PX_crc32(code+8,size-8)!=header->CRC) + { + return PX_FALSE; + } + + + if ((Ins->_mem=(PX_SCRIPTVM_VARIABLE *)MP_Malloc(mp,sizeof(PX_SCRIPTVM_VARIABLE)*Ins->VM_memsize))==PX_NULL) + { + return PX_FALSE; + } + + + if ((Ins->pThread=(PX_ScriptVM_InstanceThread *)MP_Malloc(mp,sizeof(PX_ScriptVM_InstanceThread)*Ins->maxThreadCount))==PX_NULL) + { + return PX_FALSE; + } + + for (i=0;imaxThreadCount;i++) + { + PX_memset(Ins->pThread,0,sizeof(PX_ScriptVM_InstanceThread)*Ins->maxThreadCount); + Ins->pThread[i].Activated=PX_FALSE; + Ins->pThread[i].suspend=PX_FALSE; + for (j=0;jpThread[i].R[j],0,sizeof(PX_SCRIPTVM_VARIABLE)); + Ins->pThread[i].R[j].type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + } + } + + for (i=0;iVM_memsize;i++) + { + PX_memset(&Ins->_mem[i],0,sizeof(PX_SCRIPTVM_VARIABLE)); + Ins->_mem[i].type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + } + + + Ins->funcCount=header->funcCount; + Ins->hostCount=header->hostCount; + Ins->_func=PX_NULL; + Ins->_host=PX_NULL; + PX_memset(Ins->signal,0,sizeof(Ins->signal)); + + if (Ins->funcCount!=0) + { + if ((Ins->_func=(PX_SCRIPT_EXPORT_FUNCTION *)MP_Malloc(mp,sizeof(PX_SCRIPT_EXPORT_FUNCTION)*Ins->funcCount))==PX_NULL) + { + return PX_FALSE; + } + //read export functions + pfunc=(PX_SCRIPT_EXPORT_FUNCTION *)(code+header->oftfunc); + for (i=0;ifuncCount;i++) + { + PX_memcpy(&Ins->_func[i],&pfunc[i],sizeof(PX_SCRIPT_EXPORT_FUNCTION)); + } + } + + if(Ins->hostCount!=0) + { + if ((Ins->_host=(PX_SCRIPT_ASM_HOST_NODE *)MP_Malloc(mp,sizeof(PX_SCRIPT_ASM_HOST_NODE)*Ins->hostCount))==PX_NULL) + { + return PX_FALSE; + } + PX_memset(Ins->_host,0,sizeof(PX_SCRIPT_ASM_HOST_NODE)*Ins->hostCount); + phost=(PX_SCRIPT_ASM_HOST_NODE *)(code+header->ofthost); + for (i=0;ihostCount;i++) + { + PX_memcpy(&Ins->_host[i],&phost[i],sizeof(PX_SCRIPT_ASM_HOST_NODE)); + Ins->_host[i].map=PX_NULL; + } + } + + + Ins->stringsize=header->stringSize; + Ins->memorysize=header->memsize; + Ins->binsize=header->binsize; + Ins->Suspend=PX_FALSE; + + + + Ins->_string=(px_char *)MP_Malloc(mp,header->stringSize); + PX_memcpy(Ins->_string,code+header->oftString,header->stringSize); + + Ins->_memory=(px_byte *)MP_Malloc(mp,header->memsize); + PX_memcpy(Ins->_memory,code+header->oftmem,header->memsize); + + Ins->_bin=(px_byte *)MP_Malloc(mp,header->binsize); + PX_memcpy(Ins->_bin,code+header->oftbin,header->binsize); + + + + return PX_TRUE; +} + +PX_SCRIPTVM_VARIABLE PX_SCRIPTVM_VaribaleCopy(PX_ScriptVM_Instance *Ins,PX_SCRIPTVM_VARIABLE var,px_bool *bOutOfMemory) +{ + PX_SCRIPTVM_VARIABLE cpyVar; + cpyVar=var; + *bOutOfMemory=PX_FALSE; + + if (var.type==PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + if(!PX_StringInitialize(Ins->mp,&cpyVar._string)) + { + cpyVar.type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + *bOutOfMemory=PX_TRUE; + } + else + { + if(!PX_StringCopy(&cpyVar._string,&var._string)) + { + cpyVar.type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + *bOutOfMemory=PX_TRUE; + } + } + } + else if (var.type==PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + { + PX_MemoryInitialize(Ins->mp,&cpyVar._memory); + if(!PX_MemoryCat(&cpyVar._memory,var._memory.buffer,var._memory.usedsize)) + { + cpyVar.type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + *bOutOfMemory=PX_TRUE; + } + } + return cpyVar; +} + +static px_void PX_SCRIPTVM_VaribaleFree(PX_ScriptVM_Instance *Ins,PX_SCRIPTVM_VARIABLE *var) +{ + if (var->type==PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + { + PX_MemoryFree(&var->_memory); + } + else if (var->type==PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_StringFree(&var->_string); + } + var->type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + var->_int=0; +} + + +static PX_SCRIPTVM_VARIABLE PX_SCRIPT_VM_GetParamConst(PX_ScriptVM_Instance *Ins,px_char optype,px_int param,px_bool *bOutofMemory) +{ + PX_SCRIPTVM_VARIABLE rVar,ret; + PX_ScriptVM_InstanceThread *pT=&Ins->pThread[Ins->T]; + *bOutofMemory=PX_FALSE; + ret.type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + ret._int=0; + switch (optype) + { + case PX_SCRIPT_ASM_OPTYPE_IP: + { + ret.type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + ret._int=pT->IP; + return ret; + } + break; + + case PX_SCRIPT_ASM_OPTYPE_SP: + { + ret.type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + ret._int=pT->SP; + return ret; + } + break; + + case PX_SCRIPT_ASM_OPTYPE_BP: + { + ret.type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + ret._int=pT->BP; + return ret; + } + break; + case PX_SCRIPT_ASM_OPTYPE_HOST: + case PX_SCRIPT_ASM_OPTYPE_INT: + { + ret.type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + ret._int=param; + return ret; + } + break; + case PX_SCRIPT_ASM_OPTYPE_FLOAT: + { + //Must be IEEE 754 format + ret.type=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT; + ret._int=param; + return ret; + } + break; + case PX_SCRIPT_ASM_OPTYPE_STRING: + { + ret.type=PX_SCRIPTVM_VARIABLE_TYPE_STRING; + ret._string.buffer=Ins->_string+param; + ret._string.bufferlen=0; + ret._string.mp=PX_NULL; + return ret; + } + break; + + case PX_SCRIPT_ASM_OPTYPE_MEMORY: + { + ret.type=PX_SCRIPTVM_VARIABLE_TYPE_MEMORY; + ret._memory.buffer=Ins->_memory+param+4; + ret._memory.allocsize=0; + ret._memory.usedsize=*(px_int *)(Ins->_memory+param); + ret._memory.mp=PX_NULL; + return ret; + } + break; + + case PX_SCRIPT_ASM_OPTYPE_REG: + { + if (paramR[param],bOutofMemory); + } + else + { + PX_ScriptVM_Error(Ins,"Variable parameter error."); + } + } + break; + case PX_SCRIPT_ASM_OPTYPE_LOCAL_CONST: + { + if(pT->BP-param>0&&pT->BP-paramVM_memsize) + return PX_SCRIPTVM_VaribaleCopy(Ins,Ins->_mem[pT->BP-param],bOutofMemory); + else + goto _ERROR; + } + break; + case PX_SCRIPT_ASM_OPTYPE_LOCAL_REGREF: + { + if (paramR[param]; + if (rVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + if (pT->BP-rVar._int>0&&pT->BP-rVar._intVM_memsize) + { + return PX_SCRIPTVM_VaribaleCopy(Ins,Ins->_mem[rVar._int-pT->BP],bOutofMemory); + } + else + { + goto _ERROR; + } + } + else + { + goto _ERROR; + } + } + else + { + goto _ERROR; + } + + } + break; + case PX_SCRIPT_ASM_OPTYPE_LOCAL_GLOBALREF: + { + if (paramVM_memsize) + { + rVar=Ins->_mem[param]; + if (rVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + if (pT->BP-rVar._int>0&&pT->BP-rVar._intVM_memsize) + { + return PX_SCRIPTVM_VaribaleCopy(Ins,Ins->_mem[pT->BP-rVar._int],bOutofMemory); + } + else + { + goto _ERROR; + } + } + else + { + goto _ERROR; + } + } + else + { + goto _ERROR; + } + } + break; + case PX_SCRIPT_ASM_OPTYPE_LOCAL_LOCALREF: + { + if (pT->BP-param>0&&pT->BP-paramVM_memsize) + { + rVar=Ins->_mem[pT->BP-param]; + if (rVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + if (pT->BP-rVar._int>0&&pT->BP-rVar._intVM_memsize) + { + return PX_SCRIPTVM_VaribaleCopy(Ins,Ins->_mem[pT->BP-rVar._int],bOutofMemory); + } + else + { + goto _ERROR; + } + } + else + { + goto _ERROR; + } + } + else + { + goto _ERROR; + } + } + break; + case PX_SCRIPT_ASM_OPTYPE_GLOBAL_CONST: + { + if(paramVM_memsize) + return PX_SCRIPTVM_VaribaleCopy(Ins,Ins->_mem[param],bOutofMemory); + else + goto _ERROR; + } + break; + case PX_SCRIPT_ASM_OPTYPE_GLOBAL_SPREF: + { + if(pT->SP+paramVM_memsize) + return PX_SCRIPTVM_VaribaleCopy(Ins,Ins->_mem[pT->SP+param],bOutofMemory); + else + goto _ERROR; + } + break; + case PX_SCRIPT_ASM_OPTYPE_GLOBAL_REGREF: + { + if (paramR[param]; + if (rVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + if (rVar._intVM_memsize) + { + return PX_SCRIPTVM_VaribaleCopy(Ins,Ins->_mem[rVar._int],bOutofMemory); + } + else + { + goto _ERROR; + } + } + else + { + goto _ERROR; + } + } + else + { + goto _ERROR; + } + } + break; + case PX_SCRIPT_ASM_OPTYPE_GLOBAL_GLOBALREF: + { + if (paramVM_memsize) + { + rVar=Ins->_mem[param]; + if (rVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + if (rVar._intVM_memsize) + { + return PX_SCRIPTVM_VaribaleCopy(Ins,Ins->_mem[rVar._int],bOutofMemory); + } + else + { + goto _ERROR; + } + } + else + { + goto _ERROR; + } + } + else + { + goto _ERROR; + } + } + break; + case PX_SCRIPT_ASM_OPTYPE_GLOBAL_LOCALREF: + { + if (pT->BP-param>0&&pT->BP-paramVM_memsize) + { + rVar=Ins->_mem[pT->BP-param]; + if (rVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + if (rVar._intVM_memsize) + { + return PX_SCRIPTVM_VaribaleCopy(Ins,Ins->_mem[rVar._int],bOutofMemory); + } + else + { + goto _ERROR; + } + } + else + { + goto _ERROR; + } + } + else + { + goto _ERROR; + } + } + break; + + + default: + { + goto _ERROR; + } + } +_ERROR: + PX_ScriptVM_Error(Ins,"Virtual Machine Runtime error"); + return ret; + +} +static PX_SCRIPTVM_VARIABLE * PX_SCRIPT_VM_GetVariablePointer(PX_ScriptVM_Instance *Ins,px_char optype,px_int param) +{ + PX_SCRIPTVM_VARIABLE rVar; + PX_ScriptVM_InstanceThread *pT=&Ins->pThread[Ins->T]; + switch (optype) + { + case PX_SCRIPT_ASM_OPTYPE_REG: + { + if (paramR[param]; + } + else + { + PX_ScriptVM_Error(Ins,"Variable parameter error."); + } + } + break; + case PX_SCRIPT_ASM_OPTYPE_LOCAL_CONST: + { + if(pT->BP-param>0&&pT->BP-paramVM_memsize) + return &Ins->_mem[pT->BP-param]; + else + goto _ERROR; + } + break; + case PX_SCRIPT_ASM_OPTYPE_LOCAL_REGREF: + { + if (paramR[param]; + if (rVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + if (pT->BP-rVar._int>0&&pT->BP-rVar._intVM_memsize) + { + return &Ins->_mem[pT->BP-rVar._int]; + } + else + { + goto _ERROR; + } + } + else + { + goto _ERROR; + } + } + else + { + goto _ERROR; + } + + } + break; + case PX_SCRIPT_ASM_OPTYPE_LOCAL_GLOBALREF: + { + if (paramVM_memsize) + { + rVar=Ins->_mem[param]; + if (rVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + if (pT->BP-rVar._int>0&&pT->BP-rVar._intVM_memsize) + { + return &Ins->_mem[pT->BP-rVar._int]; + } + else + { + goto _ERROR; + } + } + else + { + goto _ERROR; + } + } + else + { + goto _ERROR; + } + } + break; + case PX_SCRIPT_ASM_OPTYPE_LOCAL_LOCALREF: + { + if (pT->BP-param>0&&pT->BP-paramVM_memsize) + { + rVar=Ins->_mem[pT->BP-param]; + if (rVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + if (pT->BP-rVar._int>0&&pT->BP-rVar._intVM_memsize) + { + return &Ins->_mem[pT->BP-rVar._int]; + } + else + { + goto _ERROR; + } + } + else + { + goto _ERROR; + } + } + else + { + goto _ERROR; + } + } + break; + case PX_SCRIPT_ASM_OPTYPE_GLOBAL_CONST: + { + if(paramVM_memsize) + return &Ins->_mem[param]; + else + goto _ERROR; + } + break; + + case PX_SCRIPT_ASM_OPTYPE_GLOBAL_SPREF: + { + if(pT->SP+paramVM_memsize) + return &Ins->_mem[pT->SP+param]; + else + goto _ERROR; + } + break; + + case PX_SCRIPT_ASM_OPTYPE_GLOBAL_REGREF: + { + if (paramR[param]; + if (rVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + if (rVar._intVM_memsize) + { + return &Ins->_mem[rVar._int]; + } + else + { + goto _ERROR; + } + } + else + { + goto _ERROR; + } + } + else + { + goto _ERROR; + } + } + break; + case PX_SCRIPT_ASM_OPTYPE_GLOBAL_GLOBALREF: + { + if (paramVM_memsize) + { + rVar=Ins->_mem[param]; + if (rVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + if (rVar._intVM_memsize) + { + return &Ins->_mem[rVar._int]; + } + else + { + goto _ERROR; + } + } + else + { + goto _ERROR; + } + } + else + { + goto _ERROR; + } + } + break; + case PX_SCRIPT_ASM_OPTYPE_GLOBAL_LOCALREF: + { + if (pT->BP-param>0&&pT->BP-paramVM_memsize) + { + rVar=Ins->_mem[pT->BP-param]; + if (rVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + if (rVar._intVM_memsize) + { + return &Ins->_mem[rVar._int]; + } + else + { + goto _ERROR; + } + } + else + { + goto _ERROR; + } + } + else + { + goto _ERROR; + } + } + break; + + default: + { + goto _ERROR; + } + } + return PX_NULL; +_ERROR: + PX_ScriptVM_Error(Ins,"Variable parameter error."); + return PX_NULL; + +} + +#define PX_SCRIPT_VM_PARAM(i) (*(((px_int32 *)(Ins->_bin+pT->IP+4))+i)) +#define PX_SCRIPT_VM_IP_PARAM(i) (*(((px_int32 *)(Ins->_bin+IP+4))+i)) + +px_void PX_ScriptVM_DebuggerInterrupt(PX_ScriptVM_Instance *Ins); +px_bool PX_ScriptVM_DebuggerCurrentInstruction(PX_ScriptVM_Instance *Ins,px_int IP); + +PX_SCRIPTVM_RUNRETURN PX_ScriptVM_InstanceRunThread(PX_ScriptVM_Instance *Ins,px_int tick) +{ + px_char opCode,opType[3],numOut[32],lastchar,*pchar; + px_float p1=0,p2=0; + PX_SCRIPTVM_VARIABLE *pVar,cVar,sVar,tVar; + px_string newString; + px_byte *newBuffer; + px_bool bOutofMemory; + int i,j; + PX_ScriptVM_InstanceThread *pT=&Ins->pThread[Ins->T]; + + while(PX_TRUE) + { + if(Ins->debug) + { + PX_ScriptVM_DebuggerInterrupt(Ins); + } + + if (!pT->Activated) + { + return PX_SCRIPTVM_RUNRETURN_END; + } + + if (Ins->Suspend||pT->suspend) + { + return PX_SCRIPTVM_RUNRETURN_SUSPEND; + } + + + pVar=PX_NULL; + cVar.type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + sVar.type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + tVar.type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + cVar._int=-1; + sVar._int=-1; + tVar._int=-1; + + + if(tick==0) + { + PX_SCRIPTVM_VaribaleFree(Ins,&cVar); + PX_SCRIPTVM_VaribaleFree(Ins,&sVar); + PX_SCRIPTVM_VaribaleFree(Ins,&tVar); + return PX_SCRIPTVM_RUNRETURN_TIMEOUT; + } + + if(tick>0) + { + tick--; + } + + + if (pT->IP>Ins->binsize||pT->IP<0) + { + PX_ScriptVM_Error(Ins,"IP point to invalid address"); + goto _ERROR; + } + + if (pT->SP>Ins->VM_memsize||pT->SP<0) + { + PX_ScriptVM_Error(Ins,"SP point to invalid address"); + goto _ERROR; + } + + opCode=*(Ins->_bin+pT->IP); + opType[0]=*(Ins->_bin+pT->IP+1); + opType[1]=*(Ins->_bin+pT->IP+2); + opType[2]=*(Ins->_bin+pT->IP+3); + + if (opCode!=PX_SCRIPT_ASM_INSTR_OPCODE_MOV&&opCode!=PX_SCRIPT_ASM_INSTR_OPCODE_ADD&&opCode!=PX_SCRIPT_ASM_INSTR_OPCODE_SUB&&opCode!=PX_SCRIPT_ASM_INSTR_OPCODE_PUSH&&opCode!=PX_SCRIPT_ASM_INSTR_OPCODE_POP) + { + if (opType[0]==PX_SCRIPT_ASM_OPTYPE_IP||opType[0]==PX_SCRIPT_ASM_OPTYPE_SP||opType[0]==PX_SCRIPT_ASM_OPTYPE_BP) + { + goto _ERROR; + } + } + switch(opCode) + { + case PX_SCRIPT_ASM_INSTR_OPCODE_MOV: + { + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) + { + PX_ScriptVM_Error(Ins,"MOV out of memory."); + goto _ERROR; + } + if (opType[0]==PX_SCRIPT_ASM_OPTYPE_IP) + { + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"MOV IP is not a integer."); + goto _ERROR; + } + pT->IP=cVar._int; + break; + } + + if (opType[0]==PX_SCRIPT_ASM_OPTYPE_SP) + { + + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"MOV SP is not a integer."); + goto _ERROR; + } + pT->SP=cVar._int; + pT->IP+=(4+2*4); + break; + } + + if (opType[0]==PX_SCRIPT_ASM_OPTYPE_BP) + { + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"MOV BP is not a integer."); + goto _ERROR; + } + pT->BP=cVar._int; + pT->IP+=(4+2*4); + break; + } + + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + + PX_SCRIPTVM_VaribaleFree(Ins,pVar); + + if (cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + if(!PX_StringInitialize(Ins->mp,&pVar->_string)) + { + PX_ScriptVM_Error(Ins,"MOV crash."); + goto _ERROR; + } + if(!PX_StringCat(&pVar->_string,cVar._string.buffer)) + { + PX_ScriptVM_Error(Ins,"MOV crash."); + goto _ERROR; + } + pVar->type=cVar.type; + } + else if (cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + { + PX_MemoryInitialize(Ins->mp,&pVar->_memory); + if(!PX_MemoryAlloc(&pVar->_memory,cVar._memory.usedsize)) + { + PX_ScriptVM_Error(Ins,"MOV crash."); + goto _ERROR; + } + if(!PX_MemoryCat(&pVar->_memory,cVar._memory.buffer,cVar._memory.usedsize)) + { + PX_ScriptVM_Error(Ins,"MOV crash."); + goto _ERROR; + } + pVar->type=cVar.type; + } + else + { + *pVar=cVar; + } + + pT->IP+=(4+2*4); + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_ADD: + { + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) + { + PX_ScriptVM_Error(Ins,"Add crash."); + goto _ERROR; + } + if (opType[0]==PX_SCRIPT_ASM_OPTYPE_IP) + { + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"ADD IP is not a integer."); + goto _ERROR; + } + pT->IP+=cVar._int; + break; + } + + if (opType[0]==PX_SCRIPT_ASM_OPTYPE_SP) + { + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"ADD SP is not a integer."); + goto _ERROR; + } + pT->SP+=cVar._int; + pT->IP+=(4+2*4); + break; + } + + if (opType[0]==PX_SCRIPT_ASM_OPTYPE_BP) + { + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"ADD BP is not a integer."); + goto _ERROR; + } + pT->BP+=cVar._int; + pT->IP+=(4+2*4); + break; + } + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + + if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_INT&&cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + pVar->_int+=cVar._int; + pT->IP+=(4+2*4); + break; + } + if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_INT&&cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + pVar->_float=pVar->_int+cVar._float; + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT; + pT->IP+=(4+2*4); + break; + } + if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_FLOAT&&cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + pVar->_float=pVar->_float+cVar._float; + pT->IP+=(4+2*4); + break; + } + if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_FLOAT&&cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + pVar->_float=pVar->_float+cVar._int; + pT->IP+=(4+2*4); + break; + } + PX_ScriptVM_Error(Ins,"ADD Invalid instr"); + goto _ERROR; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_SUB: + { + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) + { + PX_ScriptVM_Error(Ins,"SUB out of memory."); + goto _ERROR; + } + if (opType[0]==PX_SCRIPT_ASM_OPTYPE_IP) + { + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"SUB IP is not a integer."); + goto _ERROR; + } + pT->IP-=cVar._int; + break; + } + + if (opType[0]==PX_SCRIPT_ASM_OPTYPE_SP) + { + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"SUB SP is not a integer."); + goto _ERROR; + } + pT->SP-=cVar._int; + if (pT->SP<0) + { + PX_ScriptVM_Error(Ins,"SUB SP<0."); + goto _ERROR; + } + pT->IP+=(4+2*4); + break; + } + + if (opType[0]==PX_SCRIPT_ASM_OPTYPE_BP) + { + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"SUB BP is not a integer."); + goto _ERROR; + } + pT->BP-=cVar._int; + pT->IP+=(4+2*4); + break; + } + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + if (pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_INT&&pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + PX_ScriptVM_Error(Ins,"SUB parameters error."); + goto _ERROR; + } + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT&&cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + PX_ScriptVM_Error(Ins,"SUB parameters error."); + goto _ERROR; + } + if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_INT&&cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + pVar->_int-=cVar._int; + } + else if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_INT&&cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + pVar->_float=pVar->_int-cVar._float; + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT; + } + else if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_FLOAT&&cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + pVar->_float=pVar->_float-cVar._float; + } + else if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_FLOAT&&cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + pVar->_float=pVar->_float-cVar._int; + } + pT->IP+=(4+2*4); + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_DIV: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + if (cVar._int==0) + { + PX_ScriptVM_Error(Ins,"Divide by zero error"); + goto _ERROR; + } + if (pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_INT&&pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + PX_ScriptVM_Error(Ins,"DIV parameters error."); + goto _ERROR; + } + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT&&cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + PX_ScriptVM_Error(Ins,"DIV parameters error."); + goto _ERROR; + } + if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_INT&&cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + pVar->_int/=cVar._int; + } + else if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_INT&&cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + pVar->_float=pVar->_int/cVar._float; + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT; + } + else if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_FLOAT&&cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + pVar->_float=pVar->_float/cVar._float; + } + else if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_FLOAT&&cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + pVar->_float=pVar->_float/cVar._int; + } + pT->IP+=(4+2*4); + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_MUL: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + if (pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_INT&&pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + PX_ScriptVM_Error(Ins,"MUL parameters error."); + goto _ERROR; + } + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT&&cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + PX_ScriptVM_Error(Ins,"MUL parameters error."); + goto _ERROR; + } + if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_INT&&cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + pVar->_int*=cVar._int; + } + else if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_INT&&cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + pVar->_float=pVar->_int*cVar._float; + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT; + } + else if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_FLOAT&&cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + pVar->_float=pVar->_float*cVar._float; + } + else if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_FLOAT&&cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + pVar->_float=pVar->_float*cVar._int; + } + pT->IP+=(4+2*4); + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_MOD: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + if (pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_INT&&cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"MOD parameters error."); + goto _ERROR; + } + pVar->_int%=cVar._int; + pT->IP+=(4+2*4); + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_SHL: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + if (pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_INT&&cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"SHL parameters error."); + goto _ERROR; + } + pVar->_int<<=cVar._int; + pT->IP+=(4+2*4); + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_SHR: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + if (pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_INT&&cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"SHR parameters error."); + goto _ERROR; + } + pVar->_int>>=cVar._int; + pT->IP+=(4+2*4); + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_AND: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + if (pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_INT&&cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"AND parameters error."); + goto _ERROR; + } + pVar->_int&=cVar._int; + pT->IP+=(4+2*4); + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_ANDL: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + if (pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_INT&&pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + PX_ScriptVM_Error(Ins,"ANDL parameters error."); + goto _ERROR; + } + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT&&cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + PX_ScriptVM_Error(Ins,"ANDL parameters error."); + goto _ERROR; + } + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + pVar->_int=(pVar->_int&&cVar._int); + pT->IP+=(4+2*4); + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_ORL: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + if (pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_INT&&pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + PX_ScriptVM_Error(Ins,"ORL parameters error."); + goto _ERROR; + } + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT&&cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + PX_ScriptVM_Error(Ins,"ORL parameters error."); + goto _ERROR; + } + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + pVar->_int=(pVar->_int||cVar._int); + pT->IP+=(4+2*4); + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_OR: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + if (pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_INT&&pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + PX_ScriptVM_Error(Ins,"OR parameters error."); + goto _ERROR; + } + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT&&cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + PX_ScriptVM_Error(Ins,"OR parameters error."); + goto _ERROR; + } + pVar->_int|=cVar._int; + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + pT->IP+=(4+2*4); + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_XOR: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + if (pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_INT&&pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + PX_ScriptVM_Error(Ins,"XOR parameters error."); + goto _ERROR; + } + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT&&cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + PX_ScriptVM_Error(Ins,"XOR parameters error."); + goto _ERROR; + } + pVar->_int^=cVar._int; + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + pT->IP+=(4+2*4); + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_POW: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + if (pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_INT&&pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + PX_ScriptVM_Error(Ins,"POW parameters error."); + goto _ERROR; + } + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT&&cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + PX_ScriptVM_Error(Ins,"POW parameters error."); + goto _ERROR; + } + + if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_INT&&cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + pVar->_int=PX_pow_ii(pVar->_int,cVar._int); + } + else if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_INT&&cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + pVar->_float=(px_float)PX_pow_dd(pVar->_int,cVar._float); + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT; + } + else if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_FLOAT&&cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + pVar->_float=(px_float)PX_pow_dd(pVar->_float,cVar._float); + } + else if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_FLOAT&&cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + pVar->_float=(px_float)PX_pow_dd(pVar->_float,cVar._int); + } + pT->IP+=(4+2*4); + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_SIN: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT&&cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + goto _ERROR; + } + + if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_StringFree(&pVar->_string); + } + + if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + { + PX_MemoryFree(&pVar->_memory); + } + + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT; + if (cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + pVar->_float=PX_sin_angle(cVar._float); + } + if (cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + pVar->_float=PX_sin_angle((px_float)cVar._int); + } + pT->IP+=(4+2*4); + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_COS: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT&&cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + goto _ERROR; + } + + if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_StringFree(&pVar->_string); + } + + if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + { + PX_MemoryFree(&pVar->_memory); + } + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT; + if (cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + pVar->_float=PX_cos_angle(cVar._float); + } + if (cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + pVar->_float=PX_cos_angle((px_float)cVar._int); + } + pT->IP+=(4+2*4); + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_INT: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + if (pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT&&pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"INT transform error."); + goto _ERROR; + } + + if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + pVar->_int=(px_int)(pVar->_float); + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + } + + pT->IP+=(4+1*4); + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_FLT: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + if (pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT&&pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"FLT transform error."); + goto _ERROR; + } + + if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + pVar->_float=(px_float)(pVar->_int); + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT; + } + + pT->IP+=(4+1*4); + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_STRLEN: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_ScriptVM_Error(Ins,"strlen parameters error."); + goto _ERROR; + } + PX_SCRIPTVM_VaribaleFree(Ins,pVar); + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + pVar->_int=PX_strlen(cVar._string.buffer); + pT->IP+=(4+2*4); + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_STRCAT: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + if (pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_ScriptVM_Error(Ins,"strcat parameters error."); + goto _ERROR; + } + if (cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + if(!PX_StringCat(&pVar->_string,cVar._string.buffer)) goto _ERROR; + } + else if (cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + if(!PX_StringCatChar(&pVar->_string,(px_char)cVar._int)) goto _ERROR; + } + else + { + goto _ERROR; + } + pT->IP+=(4+2*4); + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_STRREP: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + sVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[2],PX_SCRIPT_VM_PARAM(2),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + if (pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_ScriptVM_Error(Ins,"strrep parameters error."); + goto _ERROR; + } + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_ScriptVM_Error(Ins,"strrep parameters error."); + goto _ERROR; + } + if (sVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_ScriptVM_Error(Ins,"strrep parameters error."); + goto _ERROR; + } + PX_StringReplace(&pVar->_string,cVar._string.buffer,sVar._string.buffer); + pT->IP+=(4+3*4); + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_STRCHR: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + sVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[2],PX_SCRIPT_VM_PARAM(2),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + PX_SCRIPTVM_VaribaleFree(Ins,pVar); + + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_ScriptVM_Error(Ins,"strchr parameters error."); + goto _ERROR; + } + if (sVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"strchr parameters error."); + goto _ERROR; + } + + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + + if(sVar._int_int=(px_uchar)cVar._string.buffer[sVar._int]; + pT->IP+=(4+3*4); + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_STRTOI: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + PX_SCRIPTVM_VaribaleFree(Ins,pVar); + + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_ScriptVM_Error(Ins,"strtoi parameters error."); + goto _ERROR; + } + + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + pVar->_int=PX_atoi(cVar._string.buffer); + pT->IP+=(4+2*4); + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_STRTOF: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + PX_SCRIPTVM_VaribaleFree(Ins,pVar); + + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_ScriptVM_Error(Ins,"strtof parameters error."); + goto _ERROR; + } + + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT; + pVar->_int=(px_int)PX_atof(cVar._string.buffer); + pT->IP+=(4+2*4); + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_STRFRI: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + PX_SCRIPTVM_VaribaleFree(Ins,pVar); + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT&&cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + PX_ScriptVM_Error(Ins,"strfri parameters error."); + goto _ERROR; + } + + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_STRING; + PX_StringInitialize(Ins->mp,&pVar->_string); + if(cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + PX_itoa(cVar._int,numOut,sizeof(numOut),10); + else + PX_itoa((px_int)cVar._float,numOut,sizeof(numOut),10); + + if(!PX_StringCat(&pVar->_string,numOut)) goto _ERROR; + pT->IP+=(4+2*4); + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_STRFRF: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + PX_SCRIPTVM_VaribaleFree(Ins,pVar); + + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT&&cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + PX_ScriptVM_Error(Ins,"strfrf parameters error."); + goto _ERROR; + } + + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_STRING; + PX_StringInitialize(Ins->mp,&pVar->_string); + numOut[0]=0; + if(cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + PX_ftoa((px_float)cVar._int,numOut,sizeof(numOut),PX_SCRIPTVM_DEFALUT_FLOAT_PRECCISION); + else + PX_ftoa(cVar._float,numOut,sizeof(numOut),PX_SCRIPTVM_DEFALUT_FLOAT_PRECCISION); + + PX_StringCat(&pVar->_string,numOut); + pT->IP+=(4+2*4); + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_STRTMEM: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_MemoryInitialize(Ins->mp,&cVar._memory); + if(!PX_MemoryCat(&cVar._memory,pVar->_string.buffer,pVar->_string.bufferlen)) goto _ERROR; + PX_StringFree(&pVar->_string); + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_MEMORY; + pVar->_memory=cVar._memory; + } + else + { + PX_ScriptVM_Error(Ins,"strtmem parameters error."); + goto _ERROR; + } + pT->IP+=(4+1*4); + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_STRSET: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + sVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + tVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[2],PX_SCRIPT_VM_PARAM(2),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + if (pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + if(pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"strset parameters error."); + goto _ERROR; + } + else + { + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_STRING; + PX_StringInitialize(Ins->mp,&pVar->_string); + } + } + + + if (sVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT||(tVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT)) + { + goto _ERROR; + } + + if (sVar._int>=pVar->_string.bufferlen-1) + { + i=8; + while(imp,&newString,i); + PX_memset(newString.buffer,0,i); + PX_strcat(newString.buffer,pVar->_string.buffer); + PX_StringFree(&pVar->_string); + pVar->_string=newString; + } + + if(tVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + pVar->_string.buffer[sVar._int]=(px_char)tVar._int; + else + goto _ERROR; + + pT->IP+=(4+3*4); + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_STRFIND: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + sVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + tVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[2],PX_SCRIPT_VM_PARAM(2),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + PX_SCRIPTVM_VaribaleFree(Ins,pVar); + if (sVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_STRING||tVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_ScriptVM_Error(Ins,"strfind parameters error."); + goto _ERROR; + } + pVar->_int=-1; + pchar=PX_strstr(sVar._string.buffer,tVar._string.buffer); + if (pchar) + { + pVar->_int=(px_uint)(pchar-sVar._string.buffer); + } + pT->IP+=(4+3*4); + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_ASC: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + PX_SCRIPTVM_VaribaleFree(Ins,pVar); + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_ScriptVM_Error(Ins,"asc parameters error."); + goto _ERROR; + } + + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + pVar->_int=cVar._string.buffer[0]; + pT->IP+=(4+2*4); + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_MEMBYTE: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + sVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + tVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[2],PX_SCRIPT_VM_PARAM(2),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + PX_SCRIPTVM_VaribaleFree(Ins,pVar); + + if (sVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_MEMORY||tVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"membyte parameters error."); + goto _ERROR; + } + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + if (tVar._int_int=sVar._memory.buffer[tVar._int]; + } + else + { + pVar->_int=0; + } + + + pT->IP+=(4+3*4); + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_MEMSET: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + sVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + tVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[2],PX_SCRIPT_VM_PARAM(2),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + + if (pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + { + if(pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"memset parameters error."); + goto _ERROR; + } + else + { + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_MEMORY; + PX_MemoryInitialize(Ins->mp,&pVar->_memory); + } + } + + + if (sVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT||tVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + goto _ERROR; + } + + if (sVar._int>=pVar->_memory.allocsize) + { + i=1; + while(i<=sVar._int) + i<<=1; + newBuffer=(px_byte *)MP_Malloc(Ins->mp,i); + PX_memcpy(newBuffer,pVar->_memory.buffer,pVar->_memory.usedsize); + if (pVar->_memory.buffer) + { + MP_Free(Ins->mp,pVar->_memory.buffer); + } + pVar->_memory.buffer=newBuffer; + pVar->_memory.allocsize=i; + } + + pVar->_memory.buffer[sVar._int]=tVar._char; + if(sVar._int>pVar->_memory.usedsize-1) + pVar->_memory.usedsize=sVar._int+1; + + pT->IP+=(4+3*4); + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_MEMTRM: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + sVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + tVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[2],PX_SCRIPT_VM_PARAM(2),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + + if (pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + { + PX_ScriptVM_Error(Ins,"memtrm parameters error."); + goto _ERROR; + } + + + if (sVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT||tVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"memtrm parameters error."); + goto _ERROR; + } + + if (sVar._int+tVar._int>pVar->_memory.usedsize) + { + PX_ScriptVM_Error(Ins,"memtrm out of range."); + goto _ERROR; + } + j=0; + for (i=sVar._int;i_memory.buffer[j]=pVar->_memory.buffer[i]; + j++; + } + pVar->_memory.usedsize=tVar._int; + + pT->IP+=(4+3*4); + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_MEMFIND: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + sVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + tVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[2],PX_SCRIPT_VM_PARAM(2),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + PX_SCRIPTVM_VaribaleFree(Ins,pVar); + if (sVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_MEMORY||tVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + { + PX_ScriptVM_Error(Ins,"memfind parameters error."); + goto _ERROR; + } + pVar->_int=-1; + for(i=0;i_int=i; + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + break; + } + } + pT->IP+=(4+3*4); + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_MEMLEN: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + sVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + PX_SCRIPTVM_VaribaleFree(Ins,pVar); + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + pVar->_int=sVar._memory.usedsize; + + pT->IP+=(4+2*4); + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_MEMCAT: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + sVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + if (pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_MEMORY||sVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + { + if (pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_MEMORY||sVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"memcat crash."); + goto _ERROR; + } + else + { + if(!PX_MemoryCat(&pVar->_memory,&sVar._int,1)) goto _ERROR; + pT->IP+=(4+2*4); + } + } + else + { + if(!PX_MemoryCat(&pVar->_memory,sVar._memory.buffer,sVar._memory.usedsize)) goto _ERROR; + pT->IP+=(4+2*4); + } + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_MEMTSTR: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + { + if (pVar->_memory.usedsize==0) + { + PX_StringInitialize(Ins->mp,&cVar._string); + PX_MemoryFree(&pVar->_memory); + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_STRING; + pVar->_string=cVar._string; + } + else + { + lastchar=pVar->_memory.buffer[pVar->_memory.usedsize-1]; + + pVar->_memory.buffer[pVar->_memory.usedsize-1]=0; + + PX_StringInitialize(Ins->mp,&cVar._string); + + if(!PX_StringCat(&cVar._string,(px_char *)pVar->_memory.buffer)) { + PX_ScriptVM_Error(Ins,"memstr crash."); + goto _ERROR; + } + if(PX_strlen((px_char *)pVar->_memory.buffer)==pVar->_memory.usedsize-1) + PX_StringCatChar(&cVar._string,lastchar); + + PX_MemoryFree(&pVar->_memory); + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_STRING; + pVar->_string=cVar._string; + } + + } + else + { + goto _ERROR; + } + pT->IP+=(4+1*4); + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_DATACPY: + { + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[0],PX_SCRIPT_VM_PARAM(0),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + sVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + tVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[2],PX_SCRIPT_VM_PARAM(2),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT||sVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT||tVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"datacpy parameters error"); + goto _ERROR; + } + if (cVar._int+tVar._int>Ins->VM_memsize||cVar._int<0||sVar._int+tVar._int>Ins->VM_memsize||sVar._int<0) + { + PX_ScriptVM_Error(Ins,"Out of memory access"); + goto _ERROR; + } + PX_memcpy(&Ins->_mem[cVar._int],&Ins->_mem[sVar._int],sizeof(PX_SCRIPTVM_VARIABLE)*tVar._int); + + pT->IP+=(4+3*4); + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_NEG: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + + if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + pVar->_int=-pVar->_int; + } + else if(pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + pVar->_float=-pVar->_float; + } + else + { + PX_ScriptVM_Error(Ins,"neg parameters error"); + goto _ERROR; + } + + pT->IP+=(4+1*4); + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_INV: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + + if (pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"inv parameters error"); + goto _ERROR; + } + + pVar->_int=~pVar->_int; + + pT->IP+=(4+1*4); + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_NOT: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + + if (pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"not parameters error"); + goto _ERROR; + } + + pVar->_int=!pVar->_int; + + pT->IP+=(4+1*4); + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_JMP: + { + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[0],PX_SCRIPT_VM_PARAM(0),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"JMP parameters error"); + goto _ERROR; + } + + if (cVar._int<0||cVar._int>Ins->binsize) + { + PX_ScriptVM_Error(Ins,"JMP jump to invalid address"); + goto _ERROR; + } + + pT->IP=cVar._int; + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_JE: + { + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[0],PX_SCRIPT_VM_PARAM(0),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + sVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + tVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[2],PX_SCRIPT_VM_PARAM(2),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + + if (tVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + goto _ERROR; + } + + if (cVar.type==sVar.type) + { + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_STRING&&cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + { + if (cVar._int==sVar._int) + { + if (tVar._int<0||tVar._int>Ins->binsize) + { + PX_ScriptVM_Error(Ins,"JE jump to invalid address"); + goto _ERROR; + } + pT->IP=tVar._int; + break; + } + } + else + { + if(cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_STRING) + if (PX_strequ(cVar._string.buffer,sVar._string.buffer)) + { + if (tVar._int<0||tVar._int>Ins->binsize) + { + PX_ScriptVM_Error(Ins,"JE jump to invalid address"); + goto _ERROR; + } + pT->IP=tVar._int; + break; + } + + if(cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + if (PX_memequ(cVar._memory.buffer,sVar._memory.buffer,cVar._memory.usedsize)) + { + if (tVar._int<0||tVar._int>Ins->binsize) + { + PX_ScriptVM_Error(Ins,"JE jump to invalid address"); + goto _ERROR; + } + pT->IP=tVar._int; + break; + } + } + } + pT->IP+=(4+3*4); + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_JNE: + { + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[0],PX_SCRIPT_VM_PARAM(0),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + sVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + tVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[2],PX_SCRIPT_VM_PARAM(2),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + if (tVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + goto _ERROR; + } + + if (cVar.type==sVar.type) + { + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_STRING&&cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + { + if (cVar._int!=sVar._int) + { + if (tVar._int<0||tVar._int>Ins->binsize) + { + PX_ScriptVM_Error(Ins,"JNE jump to invalid address"); + goto _ERROR; + } + pT->IP=tVar._int; + break; + } + } + else + { + if(cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_STRING) + if (!PX_strequ(cVar._string.buffer,sVar._string.buffer)) + { + if (tVar._int<0||tVar._int>Ins->binsize) + { + PX_ScriptVM_Error(Ins,"JNE jump to invalid address"); + goto _ERROR; + } + pT->IP=tVar._int; + break; + } + + if(cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + if (!PX_memequ(cVar._memory.buffer,sVar._memory.buffer,cVar._memory.usedsize)) + { + if (tVar._int<0||tVar._int>Ins->binsize) + { + PX_ScriptVM_Error(Ins,"JNE jump to invalid address"); + goto _ERROR; + } + pT->IP=tVar._int; + break; + } + } + } + pT->IP+=(4+3*4); + + + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_JL: + { + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[0],PX_SCRIPT_VM_PARAM(0),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + sVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + tVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[2],PX_SCRIPT_VM_PARAM(2),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + + if (tVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"JL parameters error"); + goto _ERROR; + } + if (cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_STRING||sVar.type==PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_ScriptVM_Error(Ins,"JL parameters error"); + goto _ERROR; + } + if (cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_MEMORY||sVar.type==PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + { + PX_ScriptVM_Error(Ins,"JL parameters error"); + goto _ERROR; + } + if (cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + p1=(px_float)cVar._int; + } + if (cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + p1=cVar._float; + } + if (sVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + p2=(px_float)sVar._int; + } + if (sVar.type==PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + p2=sVar._float; + } + + if (p1Ins->binsize) + { + PX_ScriptVM_Error(Ins,"JL jump to invalid address"); + goto _ERROR; + } + pT->IP=tVar._int; + } + else + { + pT->IP+=(4+3*4); + } + + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_JLE: + { + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[0],PX_SCRIPT_VM_PARAM(0),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + sVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + tVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[2],PX_SCRIPT_VM_PARAM(2),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + + if (tVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"JLE parameters error"); + goto _ERROR; + } + if (cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_STRING||sVar.type==PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_ScriptVM_Error(Ins,"JLE parameters error"); + goto _ERROR; + } + if (cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_MEMORY||sVar.type==PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + { + PX_ScriptVM_Error(Ins,"JLE parameters error"); + goto _ERROR; + } + if (cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + p1=(px_float)cVar._int; + } + if (cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + p1=cVar._float; + } + if (sVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + p2=(px_float)sVar._int; + } + if (sVar.type==PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + p2=sVar._float; + } + + if (p1<=p2) + { + if (tVar._int<0||tVar._int>Ins->binsize) + { + PX_ScriptVM_Error(Ins,"JLE jump to invalid address"); + goto _ERROR; + } + pT->IP=tVar._int; + } + else + { + pT->IP+=(4+3*4); + } + + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_JG: + { + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[0],PX_SCRIPT_VM_PARAM(0),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + sVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + tVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[2],PX_SCRIPT_VM_PARAM(2),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + + if (tVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"JG parameters error"); + goto _ERROR; + } + if (cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_STRING||sVar.type==PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_ScriptVM_Error(Ins,"JG parameters error"); + goto _ERROR; + } + if (cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_MEMORY||sVar.type==PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + { + PX_ScriptVM_Error(Ins,"JG parameters error"); + goto _ERROR; + } + if (cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + p1=(px_float)cVar._int; + } + if (cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + p1=cVar._float; + } + if (sVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + p2=(px_float)sVar._int; + } + if (sVar.type==PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + p2=sVar._float; + } + + if (p1>p2) + { + if (tVar._int<0||tVar._int>Ins->binsize) + { + PX_ScriptVM_Error(Ins,"JG jump to invalid address"); + goto _ERROR; + } + pT->IP=tVar._int; + } + else + { + pT->IP+=(4+3*4); + } + + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_JGE: + { + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[0],PX_SCRIPT_VM_PARAM(0),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + sVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + tVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[2],PX_SCRIPT_VM_PARAM(2),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + + if (tVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"JGE parameters error"); + goto _ERROR; + } + if (cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_STRING||sVar.type==PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_ScriptVM_Error(Ins,"JGE parameters error"); + goto _ERROR; + } + if (cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_MEMORY||sVar.type==PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + { + PX_ScriptVM_Error(Ins,"JGE parameters error"); + goto _ERROR; + } + if (cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + p1=(px_float)cVar._int; + } + if (cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + p1=cVar._float; + } + if (sVar.type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + p2=(px_float)sVar._int; + } + if (sVar.type==PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + p2=sVar._float; + } + + if (p1>=p2) + { + if (tVar._int<0||tVar._int>Ins->binsize) + { + PX_ScriptVM_Error(Ins,"JGE jump to invalid address"); + goto _ERROR; + } + pT->IP=tVar._int; + } + else + { + pT->IP+=(4+3*4); + } + + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_LGE: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + sVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + tVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[2],PX_SCRIPT_VM_PARAM(2),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + PX_SCRIPTVM_VaribaleFree(Ins,pVar); + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + pVar->_int=0; + + if (sVar.type==tVar.type) + { + if (sVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_STRING&&sVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + { + if (sVar._int==tVar._int) + { + pVar->_int=1; + pT->IP+=(4+3*4); + break; + } + } + else + { + if(sVar.type==PX_SCRIPTVM_VARIABLE_TYPE_STRING) + if (PX_strequ(sVar._string.buffer,tVar._string.buffer)) + { + pVar->_int=1; + pT->IP+=(4+3*4); + break; + } + + + if(sVar.type==PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + if ((sVar._memory.usedsize==tVar._memory.usedsize)&&PX_memequ(sVar._memory.buffer,tVar._memory.buffer,sVar._memory.usedsize)) + { + pVar->_int=1; + pT->IP+=(4+3*4); + break; + } + } + } + pT->IP+=(4+3*4); + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_LGNE: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + sVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + tVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[2],PX_SCRIPT_VM_PARAM(2),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + PX_SCRIPTVM_VaribaleFree(Ins,pVar); + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + pVar->_int=1; + + if (sVar.type==tVar.type) + { + if (sVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_STRING&&sVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + { + if (sVar._int==tVar._int) + { + pVar->_int=0; + pT->IP+=(4+3*4); + break; + } + } + else + { + if(sVar.type==PX_SCRIPTVM_VARIABLE_TYPE_STRING) + if (PX_strequ(sVar._string.buffer,tVar._string.buffer)) + { + pVar->_int=0; + pT->IP+=(4+3*4); + break; + } + + + if(cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + if ((sVar._memory.usedsize==tVar._memory.usedsize)&&PX_memequ(sVar._memory.buffer,tVar._memory.buffer,sVar._memory.usedsize)) + { + pVar->_int=0; + pT->IP+=(4+3*4); + break; + } + } + } + pT->IP+=(4+3*4); + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_LGZ: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + + if (pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_INT&&pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + PX_ScriptVM_Error(Ins,"LGZ parameters error"); + goto _ERROR; + } + + if (pVar->_int==0) + { + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + pVar->_int=1; + } + else + { + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + pVar->_int=0; + } + pT->IP+=(4+1*4); + + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_LGGZ: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + + if (pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_INT&&pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + PX_ScriptVM_Error(Ins,"LGGZ parameters error"); + goto _ERROR; + } + + if (pVar->_int>0) + { + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + pVar->_int=1; + } + else + { + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + pVar->_int=0; + } + pT->IP+=(4+1*4); + + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_LGGEZ: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + + if (pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_INT&&pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + PX_ScriptVM_Error(Ins,"LGGEZ parameters error"); + goto _ERROR; + } + + if (pVar->_int>=0) + { + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + pVar->_int=1; + } + else + { + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + pVar->_int=0; + } + pT->IP+=(4+1*4); + + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_LGLZ: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + + if (pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_INT&&pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + PX_ScriptVM_Error(Ins,"LGLZ parameters error"); + goto _ERROR; + } + + if (pVar->_int<0) + { + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + pVar->_int=1; + } + else + { + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + pVar->_int=0; + } + pT->IP+=(4+1*4); + + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_LGLEZ: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + + if (pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_INT&&pVar->type!=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT) + { + PX_ScriptVM_Error(Ins,"LGLEZ parameters error"); + goto _ERROR; + } + + if (pVar->_int<=0) + { + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + pVar->_int=1; + } + else + { + pVar->type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + pVar->_int=0; + } + pT->IP+=(4+1*4); + + } + break; + + + case PX_SCRIPT_ASM_INSTR_OPCODE_CALL: + { + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[0],PX_SCRIPT_VM_PARAM(0),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"CALL parameters error"); + goto _ERROR; + } + + if (opType[0]==PX_SCRIPT_ASM_OPTYPE_HOST) + { + if (Ins->_host[cVar._int].map!=PX_NULL) + { + if (!((PX_ScriptVM_Function_Modules)(Ins->_host[cVar._int].map))(Ins,Ins->_host[cVar._int].userptr)) + { + PX_ScriptVM_Error(Ins,"CALL function crash"); + goto _ERROR;//runtime error + } + } + else + { + PX_ScriptVM_Error(Ins,"CALL host call not found"); + goto _ERROR;//runtime error + } + pT->IP+=8; + } + else + { + //push IP+8 + if (pT->SP>0) + { + pT->SP-=1; + } + else + { + PX_ScriptVM_Error(Ins,"CALL error"); + goto _ERROR; + } + + + pVar=&Ins->_mem[pT->SP]; + if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_StringFree(&pVar->_string); + } + + if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + { + PX_MemoryFree(&pVar->_memory); + } + + Ins->_mem[pT->SP].type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + Ins->_mem[pT->SP]._int=pT->IP+8; + pT->IP=cVar._int; + } + + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_PUSH: + { + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[0],PX_SCRIPT_VM_PARAM(0),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + if(pT->SP>0) + pT->SP-=1; + else + { + PX_ScriptVM_Error(Ins,"push error"); + goto _ERROR; + } + pVar=&Ins->_mem[pT->SP]; + + if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_StringFree(&pVar->_string); + } + + if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + { + PX_MemoryFree(&pVar->_memory); + } + + if (cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + if(!PX_StringInitialize(Ins->mp,&pVar->_string)) goto _ERROR; + if(!PX_StringCat(&pVar->_string,cVar._string.buffer)) goto _ERROR; + pVar->type=cVar.type; + } + else if (cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + { + PX_MemoryInitialize(Ins->mp,&pVar->_memory); + if(!PX_MemoryAlloc(&pVar->_memory,cVar._memory.usedsize)) goto _ERROR; + if(!PX_MemoryCat(&pVar->_memory,cVar._memory.buffer,cVar._memory.usedsize)) goto _ERROR; + pVar->type=cVar.type; + } + else + { + *pVar=cVar; + } + + pT->IP+=8; + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_POP: + { + if (opType[0]==PX_SCRIPT_ASM_OPTYPE_IP) + { + if(Ins->_mem[pT->SP].type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + pT->IP=Ins->_mem[pT->SP]._int; + pT->SP+=1; + } + else + { + PX_ScriptVM_Error(Ins,"POP error"); + goto _ERROR; + } + } + else if (opType[0]==PX_SCRIPT_ASM_OPTYPE_SP) + { + PX_ScriptVM_Error(Ins,"POP error"); + goto _ERROR; + } + else if (opType[0]==PX_SCRIPT_ASM_OPTYPE_BP) + { + if(Ins->_mem[pT->SP].type==PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + pT->BP=Ins->_mem[pT->SP]._int; + pT->SP+=1; + pT->IP+=8; + } + else + { + PX_ScriptVM_Error(Ins,"POP error"); + goto _ERROR; + } + } + else + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + + if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_StringFree(&pVar->_string); + } + + if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + { + PX_MemoryFree(&pVar->_memory); + } + *pVar=Ins->_mem[pT->SP]; + + Ins->_mem[pT->SP].type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + Ins->_mem[pT->SP]._int=0; + + pT->SP+=1; + pT->IP+=8; + } + + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_POPN: + { + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[0],PX_SCRIPT_VM_PARAM(0),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"POPN error"); + goto _ERROR; + } + for (i=0;i_mem[pT->SP+i]; + + if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_StringFree(&pVar->_string); + } + + if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + { + PX_MemoryFree(&pVar->_memory); + } + + Ins->_mem[pT->SP+i].type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + Ins->_mem[pT->SP+i]._int=0; + } + pT->SP+=cVar._int; + pT->IP+=8; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_ADR: + { + pVar=PX_SCRIPT_VM_GetVariablePointer(Ins,opType[0],PX_SCRIPT_VM_PARAM(0)); + PX_SCRIPTVM_VaribaleFree(Ins,pVar); + switch(opType[1]) + { + case PX_SCRIPT_ASM_OPTYPE_GLOBAL: + pVar->_int=PX_SCRIPT_VM_PARAM(1); + break; + case PX_SCRIPT_ASM_OPTYPE_LOCAL: + pVar->_int=pT->BP-PX_SCRIPT_VM_PARAM(1); + break; + case PX_SCRIPT_ASM_OPTYPE_GLOBAL_REGREF: + if (pT->R[PX_SCRIPT_VM_PARAM(1)].type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"ADR error"); + goto _ERROR; + } + pVar->_int=pT->R[PX_SCRIPT_VM_PARAM(1)]._int; + break; + case PX_SCRIPT_ASM_OPTYPE_GLOBAL_GLOBALREF: + if (Ins->_mem[PX_SCRIPT_VM_PARAM(1)].type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"ADR error"); + goto _ERROR; + } + pVar->_int=Ins->_mem[PX_SCRIPT_VM_PARAM(1)]._int; + break; + case PX_SCRIPT_ASM_OPTYPE_GLOBAL_LOCALREF: + if (Ins->_mem[pT->BP-PX_SCRIPT_VM_PARAM(1)].type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"ADR error"); + goto _ERROR; + } + pVar->_int=Ins->_mem[pT->BP-PX_SCRIPT_VM_PARAM(1)]._int; + break; + case PX_SCRIPT_ASM_OPTYPE_LOCAL_REGREF: + if (Ins->_mem[PX_SCRIPT_VM_PARAM(1)].type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"ADR error"); + goto _ERROR; + } + pVar->_int=pT->BP-pT->R[PX_SCRIPT_VM_PARAM(1)]._int; + break; + case PX_SCRIPT_ASM_OPTYPE_LOCAL_GLOBALREF: + if (Ins->_mem[PX_SCRIPT_VM_PARAM(1)].type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"ADR error"); + goto _ERROR; + } + pVar->_int=pT->BP-Ins->_mem[PX_SCRIPT_VM_PARAM(1)]._int; + break; + case PX_SCRIPT_ASM_OPTYPE_LOCAL_LOCALREF: + if (Ins->_mem[pT->BP-PX_SCRIPT_VM_PARAM(1)].type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"ADR error"); + goto _ERROR; + } + pVar->_int=pT->BP-Ins->_mem[pT->BP-PX_SCRIPT_VM_PARAM(1)]._int; + break; + + } + pT->IP+=8; + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_RET: + { + if (pT->SP>=Ins->VM_memsize) + { + PX_SCRIPTVM_VaribaleFree(Ins,&cVar); + PX_SCRIPTVM_VaribaleFree(Ins,&sVar); + PX_SCRIPTVM_VaribaleFree(Ins,&tVar); + + PX_ScriptVM_ThreadStop(Ins,Ins->T); + return PX_SCRIPTVM_RUNRETURN_END; + } + else + { + cVar=Ins->_mem[pT->SP]; + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"RET error"); + goto _ERROR; + } + pT->SP+=1; + if (pT->SP>=Ins->VM_memsize||cVar._int==-1) + { + PX_SCRIPTVM_VaribaleFree(Ins,&cVar); + PX_SCRIPTVM_VaribaleFree(Ins,&sVar); + PX_SCRIPTVM_VaribaleFree(Ins,&tVar); + + PX_ScriptVM_ThreadStop(Ins,Ins->T); + return PX_SCRIPTVM_RUNRETURN_END; + } + else + { + pT->IP=cVar._int; + } + } + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_NOP: + { + pT->IP+=4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_BPX: + { + if (Ins->debug) + { + g_scriptVM_printFunc("Story Script Debugger Interrupt.\n"); + PX_ScriptVM_DebuggerInterrupt(Ins); + + } + pT->IP+=4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_WAIT: + { + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[0],PX_SCRIPT_VM_PARAM(0),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ScriptVM_Error(Ins,"WAIT index error"); + goto _ERROR; + } + if (Ins->signal[cVar._int]) + { + PX_SCRIPTVM_VaribaleFree(Ins,&cVar); + PX_SCRIPTVM_VaribaleFree(Ins,&sVar); + PX_SCRIPTVM_VaribaleFree(Ins,&tVar); + return PX_SCRIPTVM_RUNRETURN_WAIT; + } + else + { + pT->IP+=8; + if (tick==0) + { + tick=1; + } + } + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_SIGNAL: + { + cVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[0],PX_SCRIPT_VM_PARAM(0),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + sVar=PX_SCRIPT_VM_GetParamConst(Ins,opType[1],PX_SCRIPT_VM_PARAM(1),&bOutofMemory); + if(bOutofMemory) goto _ERROR; + if (cVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT||sVar.type!=PX_SCRIPTVM_VARIABLE_TYPE_INT) + { + PX_ERROR("SIGNAL ERROR"); + goto _ERROR; + } + Ins->signal[cVar._int]=sVar._int; + pT->IP+=4+4*2; + } + break; + default: + PX_ScriptVM_Error(Ins,"INVALID INSTR"); + goto _ERROR; + } + + PX_SCRIPTVM_VaribaleFree(Ins,&cVar); + PX_SCRIPTVM_VaribaleFree(Ins,&sVar); + PX_SCRIPTVM_VaribaleFree(Ins,&tVar); + + if (pT->IP==-1) + { + break; + } + } + return PX_SCRIPTVM_RUNRETURN_END; +_ERROR: + + PX_SCRIPTVM_VaribaleFree(Ins,&cVar); + PX_SCRIPTVM_VaribaleFree(Ins,&sVar); + PX_SCRIPTVM_VaribaleFree(Ins,&tVar); + + PX_ScriptVM_Error(Ins,"Virtual Machine runtime error"); + return PX_SCRIPTVM_RUNRETURN_ERROR; +} + +px_bool PX_ScriptVM_InstanceRunFunction(PX_ScriptVM_Instance *Ins,px_int threadID,const px_char *functionName,PX_SCRIPTVM_VARIABLE args[],px_int paramcount) +{ + int i,j,ip=-1; + px_char uprname[__PX_SCRIPT_ASM_MNEMONIC_NAME_LEN]; + px_int old_T; + if (paramcount>16||threadID>=Ins->maxThreadCount) + { + return PX_FALSE; + } + + if (PX_strlen(functionName)>=__PX_SCRIPT_ASM_MNEMONIC_NAME_LEN) + { + return PX_FALSE; + } + + for (i=0;ifuncCount;i++) + { + PX_strcpy(uprname,functionName,sizeof(uprname)); + PX_strupr(uprname); + if(PX_strequ(Ins->_func[i].name,uprname)) + { + ip=Ins->_func[i].Addr; + break; + } + } + + if (i==Ins->funcCount) + { + return PX_FALSE; + } + + if (Ins->pThread[threadID].Activated==PX_FALSE) + { + Ins->pThread[threadID].suspend=PX_FALSE; + Ins->pThread[threadID].Activated=PX_TRUE; + Ins->pThread[threadID].SP=Ins->VM_memsize-Ins->VM_Stacksize*threadID; + Ins->pThread[threadID].BP=Ins->pThread[threadID].SP; + Ins->pThread[threadID].IP=ip; + for(j=0;jpThread[threadID].R)/sizeof(Ins->pThread[threadID].R[0]);j++) + { + PX_SCRIPTVM_VaribaleFree(Ins,&Ins->pThread[threadID].R[j]); + } + } + else + { + return PX_FALSE; + } + + old_T=Ins->T; + if(!PX_ScriptVM_InstanceThreadSwitch(Ins,threadID)) + { + return PX_FALSE; + } + + for (i=paramcount-1;i>=0;i--) + { + PX_ScriptVM_PUSH(Ins,args[i]); + } + + PX_ScriptVM_PUSH(Ins,PX_ScriptVM_Variable_int(-1)); + + PX_ScriptVM_InstanceRunThread(Ins,-1); + + Ins->T=old_T; + return PX_TRUE; +} + +px_bool PX_ScriptVM_InstanceRunFunctionIndex(PX_ScriptVM_Instance *Ins,px_int threadID,px_int funcIndex,PX_SCRIPTVM_VARIABLE args[],px_int paramcount) +{ + int i,j,ip; + px_int old_T; + if (paramcount>16||threadID>=Ins->maxThreadCount) + { + return PX_FALSE; + } + + ip=Ins->_func[funcIndex].Addr; + + if (Ins->pThread[threadID].Activated==PX_FALSE) + { + Ins->pThread[threadID].suspend=PX_FALSE; + Ins->pThread[threadID].Activated=PX_TRUE; + Ins->pThread[threadID].SP=Ins->VM_memsize-Ins->VM_Stacksize*threadID; + Ins->pThread[threadID].BP=Ins->pThread[threadID].SP; + Ins->pThread[threadID].IP=ip; + for(j=0;jpThread[threadID].R)/sizeof(Ins->pThread[threadID].R[0]);j++) + { + PX_SCRIPTVM_VaribaleFree(Ins,&Ins->pThread[threadID].R[j]); + } + } + else + { + return PX_FALSE; + } + + old_T=Ins->T; + if(!PX_ScriptVM_InstanceThreadSwitch(Ins,threadID)) + { + return PX_FALSE; + } + + for (i=paramcount-1;i>=0;i--) + { + PX_ScriptVM_PUSH(Ins,args[i]); + } + + PX_ScriptVM_PUSH(Ins,PX_ScriptVM_Variable_int(-1)); + + PX_ScriptVM_InstanceRunThread(Ins,-1); + Ins->T=old_T; + return PX_TRUE; +} + + +px_bool PX_ScriptVM_InstanceBeginThreadFunction(PX_ScriptVM_Instance *Ins,px_int threadID,const px_char *func,PX_SCRIPTVM_VARIABLE args[],px_int paramcount) +{ + int i,j,ip=-1; + px_int old_T; + px_char uprname[__PX_SCRIPT_ASM_MNEMONIC_NAME_LEN]; + + if (paramcount>16||threadID>=Ins->maxThreadCount||threadID<0) + { + return PX_FALSE; + } + + + for (i=0;ifuncCount;i++) + { + PX_strcpy(uprname,func,sizeof(uprname)); + PX_strupr(uprname); + if(PX_strequ(Ins->_func[i].name,uprname)) + { + ip=Ins->_func[i].Addr; + break; + } + } + + if (i==Ins->funcCount) + { + return PX_FALSE; + } + + if (Ins->pThread[threadID].Activated==PX_FALSE) + { + Ins->pThread[threadID].suspend=PX_FALSE; + Ins->pThread[threadID].Activated=PX_TRUE; + Ins->pThread[threadID].SP=Ins->VM_memsize-Ins->VM_Stacksize*threadID; + Ins->pThread[threadID].BP=Ins->pThread[threadID].SP; + Ins->pThread[threadID].IP=ip; + for(j=0;jpThread[threadID].R)/sizeof(Ins->pThread[threadID].R[0]);j++) + { + PX_SCRIPTVM_VaribaleFree(Ins,&Ins->pThread[threadID].R[j]); + } + } + else + { + return PX_FALSE; + } + + old_T=Ins->T; + if(!PX_ScriptVM_InstanceThreadSwitch(Ins,threadID)) + { + return PX_FALSE; + } + + for (i=paramcount-1;i>=0;i--) + { + PX_ScriptVM_PUSH(Ins,args[i]); + } + + PX_ScriptVM_PUSH(Ins,PX_ScriptVM_Variable_int(-1)); + + if(!PX_ScriptVM_InstanceThreadSwitch(Ins,old_T)) + { + return PX_FALSE; + } + return PX_TRUE; +} + +px_bool PX_ScriptVM_InstanceBeginThreadFunctionIndex(PX_ScriptVM_Instance *Ins,px_int threadID,px_int funcIndex,PX_SCRIPTVM_VARIABLE args[],px_int paramcount) +{ + int i,j,ip; + px_int old_T; + if (paramcount>16||threadID>=Ins->maxThreadCount) + { + return PX_FALSE; + } + + ip=Ins->_func[funcIndex].Addr; + + if (Ins->pThread[threadID].Activated==PX_FALSE) + { + Ins->pThread[threadID].suspend=PX_FALSE; + Ins->pThread[threadID].Activated=PX_TRUE; + Ins->pThread[threadID].SP=Ins->VM_memsize-Ins->VM_Stacksize*threadID; + Ins->pThread[threadID].BP=Ins->pThread[threadID].SP; + Ins->pThread[threadID].IP=ip; + for(j=0;jpThread[threadID].R[j]); + } + } + else + { + return PX_FALSE; + } + + old_T=Ins->T; + if(!PX_ScriptVM_InstanceThreadSwitch(Ins,threadID)) + { + return PX_FALSE; + } + + + for (i=paramcount-1;i>=0;i--) + { + PX_ScriptVM_PUSH(Ins,args[i]); + } + + + PX_ScriptVM_PUSH(Ins,PX_ScriptVM_Variable_int(-1)); + + if(!PX_ScriptVM_InstanceThreadSwitch(Ins,old_T)) + { + return PX_FALSE; + } + return PX_TRUE; +} + + +px_int PX_ScriptVM_InstanceGetFreeThreadId(PX_ScriptVM_Instance *Ins) +{ + px_int i; + for (i=0;imaxThreadCount;i++) + { + if (!Ins->pThread[i].Activated) + { + return i; + } + } + return -1; +} + +px_bool PX_ScriptVM_InstanceFree(PX_ScriptVM_Instance *Ins) +{ + px_int i,j; + for (i=0;iVM_memsize;i++) + { + if (Ins->_mem[i].type==PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_StringFree(&Ins->_mem[i]._string); + } + if (Ins->_mem[i].type==PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + { + PX_MemoryFree(&Ins->_mem[i]._memory); + } + } + + + if (Ins->pThread) + { + //Free Thread + for (i=0;imaxThreadCount;i++) + { + for (j=0;jpThread[i].R[j].type==PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_StringFree(&Ins->pThread[i].R[j]._string); + } + if (Ins->pThread[i].R[j].type==PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + { + PX_MemoryFree(&Ins->pThread[i].R[j]._memory); + } + } + } + MP_Free(Ins->mp,Ins->pThread); + } + + + if(Ins->_mem) + MP_Free(Ins->mp,Ins->_mem); + + if(Ins->_func) + MP_Free(Ins->mp,Ins->_func); + + if(Ins->_host) + MP_Free(Ins->mp,Ins->_host); + + if(Ins->_string) + MP_Free(Ins->mp,Ins->_string); + + if(Ins->_bin) + MP_Free(Ins->mp,Ins->_bin); + + if(Ins->_memory) + MP_Free(Ins->mp,Ins->_memory); + + return PX_TRUE; +} + +px_bool PX_ScriptVM_RegistryHostFunction(PX_ScriptVM_Instance *Ins,const px_char *name,PX_ScriptVM_Function_Modules funcModules,px_void *userptr) +{ + px_int i; + px_char uprname[__PX_SCRIPT_ASM_MNEMONIC_NAME_LEN]; + PX_strset(uprname,name); + PX_strupr(uprname); + for (i=0;ihostCount;i++) + { + if (PX_strequ(uprname,Ins->_host[i].name+1)) + { + Ins->_host[i].map=(px_void *)funcModules; + Ins->_host[i].userptr=userptr; + return PX_TRUE; + } + } + return PX_FALSE; +} + +px_void PX_ScriptVM_RET(PX_ScriptVM_Instance *Ins,PX_SCRIPTVM_VARIABLE cVar) +{ + PX_SCRIPTVM_VARIABLE *pVar; + pVar=&Ins->pThread[Ins->T].R[1]; + + PX_SCRIPTVM_VaribaleFree(Ins,pVar); + + if (cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_StringInitialize(Ins->mp,&pVar->_string); + PX_StringCat(&pVar->_string,cVar._string.buffer); + pVar->type=cVar.type; + } + else if (cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + { + PX_MemoryInitialize(Ins->mp,&pVar->_memory); + PX_MemoryAlloc(&pVar->_memory,cVar._memory.usedsize); + PX_MemoryCat(&pVar->_memory,cVar._memory.buffer,cVar._memory.usedsize); + pVar->type=cVar.type; + } + else + { + *pVar=cVar; + } +} + +px_void PX_ScriptVM_PUSH(PX_ScriptVM_Instance *Ins,PX_SCRIPTVM_VARIABLE cVar) +{ + PX_SCRIPTVM_VARIABLE *pVar; + PX_ScriptVM_InstanceThread *pT=&Ins->pThread[Ins->T]; + if (pT->SP>0) + { + pT->SP-=1; + } + else + return; + + pVar=&Ins->_mem[pT->SP]; + + if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_StringFree(&pVar->_string); + } + + if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + { + PX_MemoryFree(&pVar->_memory); + } + + + if (cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_StringInitialize(Ins->mp,&pVar->_string); + PX_StringCat(&pVar->_string,cVar._string.buffer); + pVar->type=cVar.type; + } + else if (cVar.type==PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + { + PX_MemoryInitialize(Ins->mp,&pVar->_memory); + PX_MemoryAlloc(&pVar->_memory,cVar._memory.usedsize); + PX_MemoryCat(&pVar->_memory,cVar._memory.buffer,cVar._memory.usedsize); + pVar->type=cVar.type; + } + else + { + *pVar=cVar; + } + +} + +px_void PX_ScriptVM_POPN(PX_ScriptVM_Instance *Ins,px_int T,px_int n) +{ + PX_SCRIPTVM_VARIABLE *pVar; + px_int i; + PX_ScriptVM_InstanceThread *pT=&Ins->pThread[T]; + + for (i=0;i_mem[pT->SP+i]; + + if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_StringFree(&pVar->_string); + } + + if (pVar->type==PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + { + PX_MemoryFree(&pVar->_memory); + } + + Ins->_mem[pT->SP+i].type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + Ins->_mem[pT->SP+i]._int=0; + } + pT->SP+=n; + if (pT->SP>Ins->VM_memsize) + { + PX_ScriptVM_Error(Ins,"host call Stack overflow!"); + } +} + +PX_SCRIPTVM_VARIABLE PX_ScriptVM_Variable_int(px_int _int) +{ + PX_SCRIPTVM_VARIABLE var; + var.type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + var._int=_int; + return var; +} + +PX_SCRIPTVM_VARIABLE PX_ScriptVM_Variable_float(px_float _float) +{ + PX_SCRIPTVM_VARIABLE var; + var.type=PX_SCRIPTVM_VARIABLE_TYPE_FLOAT; + var._float=_float; + return var; +} + +PX_SCRIPTVM_VARIABLE PX_ScriptVM_Variable_string(px_string _string) +{ + PX_SCRIPTVM_VARIABLE var; + var.type=PX_SCRIPTVM_VARIABLE_TYPE_STRING; + var._string=_string; + return var; +} + +PX_SCRIPTVM_VARIABLE PX_ScriptVM_Variable_memory(px_byte *buffer,px_int _size) +{ + PX_SCRIPTVM_VARIABLE var; + var.type=PX_SCRIPTVM_VARIABLE_TYPE_MEMORY; + var._memory.allocsize=0; + var._memory.buffer=buffer; + var._memory.usedsize=_size; + return var; +} + +PX_SCRIPTVM_VARIABLE PX_ScriptVM_Variable_const_string(px_char *buffer) +{ + PX_SCRIPTVM_VARIABLE var; + var.type=PX_SCRIPTVM_VARIABLE_TYPE_STRING; + var._string.buffer=buffer; + var._string.bufferlen=0; + var._string.mp=PX_NULL; + return var; +} + +PX_SCRIPTVM_VARIABLE PX_ScriptVM_Variable_const_memory(px_byte *buffer,px_int _size) +{ + PX_SCRIPTVM_VARIABLE var; + var.type=PX_SCRIPTVM_VARIABLE_TYPE_MEMORY; + var._memory.allocsize=0; + var._memory.buffer=buffer; + var._memory.usedsize=_size; + return var; +} + + +px_bool PX_ScriptVM_DebuggerEnable(PX_ScriptVM_Instance *Ins,PX_ScriptVM_DebuggerPrint _printFunc,PX_ScriptVM_DebuggerCommand _cmdFunc) +{ + if (g_scriptVM_printFunc&&_printFunc!=g_scriptVM_printFunc) + { + return PX_FALSE; + } + if (g_scriptVM_cmdFunc&&_cmdFunc!=g_scriptVM_cmdFunc) + { + return PX_FALSE; + } + g_scriptVM_cmdFunc=_cmdFunc; + g_scriptVM_printFunc=_printFunc; + Ins->bp_IP=-1; + Ins->bp_next=PX_TRUE; + Ins->debug=PX_TRUE; + + g_scriptVM_printFunc("Story Script debugger enabled.\n"); + return PX_TRUE; +} + + +px_int PX_ScriptVM_GetFunctionIndex(PX_ScriptVM_Instance *Ins,px_char *func) +{ + int i; + px_char cmpName[sizeof(Ins->_func[0].name)]; + if (func==PX_NULL) + { + return -1; + } + if (PX_strlen(func)>=sizeof(cmpName)) + { + return -1; + } + PX_strcpy(cmpName,func,sizeof(cmpName)); + PX_strupr(cmpName); + + for (i=0;ifuncCount;i++) + { + if(PX_strequ(Ins->_func[i].name,cmpName)) + { + return i; + } + } + + return -1; +} + +px_bool PX_ScriptVM_LocalAlloc(PX_ScriptVM_Instance *Ins,int size,PX_SCRIPTVM_MEMORY_PTR *mem_ptr) +{ + px_int i; + PX_ScriptVM_InstanceThread *pT=&Ins->pThread[Ins->T]; + + if (size>pT->SP-Ins->VM_Globalsize) + { + return PX_FALSE; + } + pT->SP-=size; + for (i=pT->SP;iSP+size;i++) + { + if (Ins->_mem[i].type==PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + { + PX_MemoryFree(&Ins->_mem[i]._memory); + } + if (Ins->_mem[i].type==PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_StringFree(&Ins->_mem[i]._string); + } + Ins->_mem[i].type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + } + mem_ptr->ptr= pT->SP; + mem_ptr->size=size; + return PX_TRUE; +} + +px_bool PX_ScriptVM_LocalFree(PX_ScriptVM_Instance *Ins,PX_SCRIPTVM_MEMORY_PTR *mem_ptr) +{ + px_int i; + PX_ScriptVM_InstanceThread *pT=&Ins->pThread[Ins->T]; + + if (pT->SP!=mem_ptr->ptr) + { + return PX_FALSE; + } + for (i=pT->SP;iSP+mem_ptr->size;i++) + { + if (Ins->_mem[i].type==PX_SCRIPTVM_VARIABLE_TYPE_MEMORY) + { + PX_MemoryFree(&Ins->_mem[i]._memory); + } + if (Ins->_mem[i].type==PX_SCRIPTVM_VARIABLE_TYPE_STRING) + { + PX_StringFree(&Ins->_mem[i]._string); + } + Ins->_mem[i].type=PX_SCRIPTVM_VARIABLE_TYPE_INT; + } + pT->SP+=mem_ptr->size; + return PX_TRUE; +} + +static px_void PX_ScriptVM_DebuggerGetParamName(PX_ScriptVM_Instance *Ins,px_char optype,px_int param) +{ + px_int i; + PX_ScriptVM_InstanceThread *pT=&Ins->pThread[Ins->T]; + + switch (optype) + { + case PX_SCRIPT_ASM_OPTYPE_IP: + { + g_scriptVM_printFunc("IP"); + } + break; + + case PX_SCRIPT_ASM_OPTYPE_SP: + { + g_scriptVM_printFunc("SP"); + } + break; + + case PX_SCRIPT_ASM_OPTYPE_BP: + { + g_scriptVM_printFunc("BP"); + } + break; + case PX_SCRIPT_ASM_OPTYPE_HOST: + case PX_SCRIPT_ASM_OPTYPE_INT: + { + g_scriptVM_printFunc("%d",param); + } + break; + case PX_SCRIPT_ASM_OPTYPE_FLOAT: + { + //Must be IEEE 754 format + g_scriptVM_printFunc("%f",param); + } + break; + case PX_SCRIPT_ASM_OPTYPE_STRING: + { + g_scriptVM_printFunc("%d",Ins->_string+param); + } + break; + + case PX_SCRIPT_ASM_OPTYPE_MEMORY: + { + g_scriptVM_printFunc("@"); + for (i=0;i<*(px_int *)(Ins->_memory+param);i++) + { + g_scriptVM_printFunc("%x",*(Ins->_memory+param+4+i)); + } + g_scriptVM_printFunc("@"); + } + break; + + case PX_SCRIPT_ASM_OPTYPE_REG: + { + g_scriptVM_printFunc("R%d",param); + } + break; + case PX_SCRIPT_ASM_OPTYPE_LOCAL_CONST: + { + g_scriptVM_printFunc("LOCAL[%d]",param); + } + break; + case PX_SCRIPT_ASM_OPTYPE_LOCAL_REGREF: + { + g_scriptVM_printFunc("LOCAL[R%d]",param); + } + break; + case PX_SCRIPT_ASM_OPTYPE_LOCAL_GLOBALREF: + { + g_scriptVM_printFunc("GLOBAL[LOCAL[%d]]",param); + } + break; + case PX_SCRIPT_ASM_OPTYPE_LOCAL_LOCALREF: + { + g_scriptVM_printFunc("LOCAL[LOCAL[%d]]",param); + } + break; + case PX_SCRIPT_ASM_OPTYPE_GLOBAL_CONST: + { + g_scriptVM_printFunc("GLOBAL[%d]",param); + } + break; + case PX_SCRIPT_ASM_OPTYPE_GLOBAL_SPREF: + { + g_scriptVM_printFunc("GLOBAL[%d]",pT->SP+param); + } + break; + case PX_SCRIPT_ASM_OPTYPE_GLOBAL_REGREF: + { + g_scriptVM_printFunc("GLOBAL[R%d]",param); + } + break; + case PX_SCRIPT_ASM_OPTYPE_GLOBAL_GLOBALREF: + { + g_scriptVM_printFunc("GLOBAL[GLOBAL[%d]]",param); + } + break; + case PX_SCRIPT_ASM_OPTYPE_GLOBAL_LOCALREF: + { + g_scriptVM_printFunc("GLOBAL[LOCAL[%d]]",param); + } + break; + + default: + { + PX_ScriptVM_Error(Ins,"Unknow parameter"); + } + } +} + +px_void PX_ScriptVM_DebuggerDisplayBinary(PX_ScriptVM_Instance *Ins,px_int IP,px_int size) +{ + px_int i; + px_byte *buffer=(Ins->_bin+IP); + for (i=0;i=Ins->binsize) + { + return 0; + } + opCode=*(Ins->_bin+IP); + opType[0]=*(Ins->_bin+IP+1); + opType[1]=*(Ins->_bin+IP+2); + opType[2]=*(Ins->_bin+IP+3); + + + switch(opCode) + { + case PX_SCRIPT_ASM_INSTR_OPCODE_MOV: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+2*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("MOV "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + return 4+2*4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_ADD: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+2*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("ADD "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + return 4+2*4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_SUB: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+2*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("SUB "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + return 4+2*4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_DIV: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+2*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("DIV "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + return 4+2*4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_MUL: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+2*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("MUL "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + return 4+2*4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_MOD: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+2*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("MOD "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + return 4+2*4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_SHL: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+2*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("SHL "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + return 4+2*4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_SHR: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+2*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("SHR "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + return 4+2*4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_AND: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+2*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("AND "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + return 4+2*4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_ANDL: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+2*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("ANDL "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + return 4+2*4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_ORL: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+2*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("ORL "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + return 4+2*4; + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_OR: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+2*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("OR "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + return 4+2*4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_XOR: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+2*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("XOR "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + return 4+2*4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_POW: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+2*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("POW "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + return 4+2*4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_SIN: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+2*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("SIN "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + return 4+2*4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_COS: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+2*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("COS "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + return 4+2*4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_INT: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+2*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("INT "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + return 4+1*4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_FLT: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+1*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("FLT "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + return 4+1*4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_STRLEN: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+2*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("STRLEN "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + return 4+2*4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_STRCAT: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+2*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("STRCAT "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + return 4+2*4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_STRREP: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+3*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("STRREP "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[2],PX_SCRIPT_VM_IP_PARAM(2)); + return 4+3*4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_STRCHR: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+3*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("STRCHR "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[2],PX_SCRIPT_VM_IP_PARAM(2)); + return 4+3*4; + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_STRTOI: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+2*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("STRTOI "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + return 4+2*4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_STRTOF: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+2*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("STRTOF "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + return 4+2*4; + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_STRFRI: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+2*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("STRFRI "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + return 4+2*4; + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_STRFRF: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+2*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("STRFRF "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + return 4+2*4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_STRTMEM: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+1*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("STRMEM "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + return 4+1*4; + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_STRSET: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+2*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("STRSET "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + return 4+2*4; + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_STRFIND: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+2*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("STRFIND "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[2],PX_SCRIPT_VM_IP_PARAM(2)); + return 4+3*4; + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_ASC: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+2*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("ASC "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + return 4+2*4; + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_MEMBYTE: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+3*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("MEMBYTE "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[2],PX_SCRIPT_VM_IP_PARAM(2)); + return 4+2*4; + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_MEMSET: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+3*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("MEMSET "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[2],PX_SCRIPT_VM_IP_PARAM(2)); + return 4+3*4; + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_MEMTRM: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+3*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("MEMCPY "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[2],PX_SCRIPT_VM_IP_PARAM(2)); + return 4+3*4; + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_MEMFIND: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+3*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("MEMFIND "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[2],PX_SCRIPT_VM_IP_PARAM(2)); + return 4+3*4; + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_MEMLEN: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+2*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("MEMLEN "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + return 4+2*4; + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_MEMCAT: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+2*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("MEMCAT "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + return 4+2*4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_MEMTSTR: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+1*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("MEMSTR "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + return 4+1*4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_DATACPY: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+3*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("DATACPY "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[2],PX_SCRIPT_VM_IP_PARAM(2)); + return 4+3*4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_NEG: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+1*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("NEG "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + return 4+1*4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_INV: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+1*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("INV "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + return 4+1*4; + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_NOT: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+1*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("NOT "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + return 4+1*4; + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_JMP: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+1*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("JMP "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + return 4+1*4; + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_JE: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+3*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("JE "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[2],PX_SCRIPT_VM_IP_PARAM(2)); + return 4+3*4; + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_JNE: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+3*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("JNE "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[2],PX_SCRIPT_VM_IP_PARAM(2)); + return 4+3*4; + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_JL: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+3*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("JL "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[2],PX_SCRIPT_VM_IP_PARAM(2)); + return 4+3*4; + + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_JLE: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+3*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("JLE "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[2],PX_SCRIPT_VM_IP_PARAM(2)); + return 4+3*4; + + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_JG: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+3*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("JG "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[2],PX_SCRIPT_VM_IP_PARAM(2)); + return 4+3*4; + + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_JGE: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+3*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("JGE "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[2],PX_SCRIPT_VM_IP_PARAM(2)); + return 4+3*4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_LGE: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+3*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("LGE "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[2],PX_SCRIPT_VM_IP_PARAM(2)); + return 4+3*4; + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_LGNE: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+3*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("LGNE "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[2],PX_SCRIPT_VM_IP_PARAM(2)); + return 4+3*4; + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_LGZ: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+1*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("LGZ "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + return 4+1*4; + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_LGGZ: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+1*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("LGGZ "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + return 4+1*4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_LGGEZ: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+1*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("LGGEZ "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + return 4+1*4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_LGLZ: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+1*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("LGLZ "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + return 4+1*4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_LGLEZ: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+1*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("LGLZE "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + return 4+1*4; + } + break; + + + case PX_SCRIPT_ASM_INSTR_OPCODE_CALL: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+1*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("CALL "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + return 4+1*4; + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_PUSH: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+1*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("PUSH "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + return 4+1*4; + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_POP: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+1*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("POP "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + return 4+1*4; + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_POPN: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+1*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("POPN "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + return 4+1*4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_ADR: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+1*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("ADR "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + return 4+1*4; + } + break; + + case PX_SCRIPT_ASM_INSTR_OPCODE_RET: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("RET"); + return 4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_NOP: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("NOP"); + return 4; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_BPX: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("BPX"); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + return 8; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_WAIT: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("WAIT"); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + return 8; + } + break; + case PX_SCRIPT_ASM_INSTR_OPCODE_SIGNAL: + { + PX_ScriptVM_DebuggerDisplayBinary(Ins,IP,4+2*4); + g_scriptVM_printFunc(" "); + g_scriptVM_printFunc("SIGNAL "); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[0],PX_SCRIPT_VM_IP_PARAM(0)); + g_scriptVM_printFunc(","); + PX_ScriptVM_DebuggerGetParamName(Ins,opType[1],PX_SCRIPT_VM_IP_PARAM(1)); + return 4+2*4; + } + break; + default: + PX_ScriptVM_Error(Ins,"unknow instruction"); + } + + PX_ScriptVM_Error(Ins,"unknow instruction"); + return 0; +} +px_void PX_ScriptVM_DebuggerDisplayVariable(PX_ScriptVM_Instance *Ins,px_int index) +{ + PX_SCRIPTVM_VARIABLE var; + if (index>=Ins->VM_memsize) + { + g_scriptVM_printFunc("Variable illegal.\n"); + return; + } + var=Ins->_mem[index]; + + switch(var.type) + { + case PX_SCRIPTVM_VARIABLE_TYPE_INT: + g_scriptVM_printFunc("memptr %d [INT] %d\n",index,var._int); + break; + case PX_SCRIPTVM_VARIABLE_TYPE_FLOAT: + g_scriptVM_printFunc("memptr %d [FLOAT] %f\n",index,var._float); + break; + case PX_SCRIPTVM_VARIABLE_TYPE_MEMORY: + g_scriptVM_printFunc("memptr %d [MEMORY]\n",index); + break; + case PX_SCRIPTVM_VARIABLE_TYPE_STRING: + g_scriptVM_printFunc("memptr %d [STRING] %s\n",index,var._string.buffer); + break; + } +} + +px_void PX_ScriptVM_DebuggerDisplayReg(PX_ScriptVM_Instance *Ins,px_int index) +{ + PX_SCRIPTVM_VARIABLE var; + if (index>=PX_SCRIPTVM_REG_COUNT) + { + g_scriptVM_printFunc("Register illegal.\n"); + return; + } + var=Ins->pThread[Ins->T].R[index]; + + switch(var.type) + { + case PX_SCRIPTVM_VARIABLE_TYPE_INT: + g_scriptVM_printFunc("Thread %d R%d [INT] %d\n",Ins->T,index,var._int); + break; + case PX_SCRIPTVM_VARIABLE_TYPE_FLOAT: + g_scriptVM_printFunc("Thread %d R%d [FLOAT] %f\n",Ins->T,index,var._float); + break; + case PX_SCRIPTVM_VARIABLE_TYPE_MEMORY: + g_scriptVM_printFunc("Thread %d R%d [MEMORY]\n",Ins->T,index); + break; + case PX_SCRIPTVM_VARIABLE_TYPE_STRING: + g_scriptVM_printFunc("Thread %d R%d [STRING] %s\n",Ins->T,index,var._string.buffer); + break; + } +} + +static px_bool PX_ScriptVM_DebuggerSolveCmd(PX_ScriptVM_Instance *Ins,px_char *cmd) +{ + + PX_LEXER_LEXEME_TYPE type; + px_lexer lexer; + px_int u,i,oft,instrLen; + px_bool bContinue=PX_FALSE; + + PX_LexerInit(&lexer,Ins->mp); + PX_LexerRegisterSpacer(&lexer,' '); + PX_LexerRegisterSpacer(&lexer,'\t'); + + PX_LexerLoadSourceFromMemory(&lexer,cmd); + + /////////////////////////////////////////////////////////////////////////// + // + //b break Point + //n next instruction + //r run + //u disassembly + //global global[] + //local local[] + + while (PX_TRUE) + { + type=PX_LexerGetNextLexeme(&lexer); + if (type==PX_LEXER_LEXEME_TYPE_END) + { + break; + } + if (PX_strequ(lexer.CurLexeme.buffer,"B")) + { + type=PX_LexerGetNextLexeme(&lexer); + if (type!=PX_LEXER_LEXEME_TYPE_SPACER) + { + break; + } + type=PX_LexerGetNextLexeme(&lexer); + if(PX_strIsInt(lexer.CurLexeme.buffer)) + Ins->bp_IP=PX_atoi(lexer.CurLexeme.buffer); + else + break; + + type=PX_LexerGetNextLexeme(&lexer); + if (type!=PX_LEXER_LEXEME_TYPE_END) + { + Ins->bp_IP=-1; + break; + } + } + else if(PX_strequ(lexer.CurLexeme.buffer,"N")) + { + type=PX_LexerGetNextLexeme(&lexer); + if (type!=PX_LEXER_LEXEME_TYPE_END) + { + break; + } + Ins->bp_next=PX_TRUE; + bContinue=PX_TRUE; + } + else if(PX_strequ(lexer.CurLexeme.buffer,"C")) + { + type=PX_LexerGetNextLexeme(&lexer); + if (type!=PX_LEXER_LEXEME_TYPE_END) + { + break; + } + Ins->bp_next=PX_FALSE; + bContinue=PX_TRUE; + } + else if(PX_strequ(lexer.CurLexeme.buffer,"U")) + { + type=PX_LexerGetNextLexeme(&lexer); + if (type!=PX_LEXER_LEXEME_TYPE_SPACER) + { + break; + } + + type=PX_LexerGetNextLexeme(&lexer); + if(PX_strIsInt(lexer.CurLexeme.buffer)) + u=PX_atoi(lexer.CurLexeme.buffer); + else + break; + + type=PX_LexerGetNextLexeme(&lexer); + if (type!=PX_LEXER_LEXEME_TYPE_END) + { + break; + } + + oft=0; + for (i=0;ipThread[Ins->T].IP+oft); + oft+=instrLen; + if(instrLen) + g_scriptVM_printFunc("\n"); + } + break; + } + else if(PX_strequ(lexer.CurLexeme.buffer,"R")) + { + type=PX_LexerGetNextLexeme(&lexer); + if (type!=PX_LEXER_LEXEME_TYPE_SPACER) + { + break; + } + + type=PX_LexerGetNextLexeme(&lexer); + if(PX_strIsInt(lexer.CurLexeme.buffer)) + u=PX_atoi(lexer.CurLexeme.buffer); + else + break; + + type=PX_LexerGetNextLexeme(&lexer); + if (type!=PX_LEXER_LEXEME_TYPE_END) + { + break; + } + + PX_ScriptVM_DebuggerDisplayReg(Ins,u); + + break; + } + else if(PX_strequ(lexer.CurLexeme.buffer,"G")) + { + type=PX_LexerGetNextLexeme(&lexer); + if (type!=PX_LEXER_LEXEME_TYPE_SPACER) + { + break; + } + + type=PX_LexerGetNextLexeme(&lexer); + if(PX_strIsInt(lexer.CurLexeme.buffer)) + u=PX_atoi(lexer.CurLexeme.buffer); + else + break; + + type=PX_LexerGetNextLexeme(&lexer); + if (type!=PX_LEXER_LEXEME_TYPE_END) + { + break; + } + + PX_ScriptVM_DebuggerDisplayVariable(Ins,u); + + break; + } + else if(PX_strequ(lexer.CurLexeme.buffer,"L")) + { + type=PX_LexerGetNextLexeme(&lexer); + if (type!=PX_LEXER_LEXEME_TYPE_SPACER) + { + break; + } + + type=PX_LexerGetNextLexeme(&lexer); + if(PX_strIsInt(lexer.CurLexeme.buffer)) + u=PX_atoi(lexer.CurLexeme.buffer); + else + break; + + PX_ScriptVM_DebuggerDisplayVariable(Ins,Ins->pThread[Ins->T].BP-u); + + + type=PX_LexerGetNextLexeme(&lexer); + if (type!=PX_LEXER_LEXEME_TYPE_END) + { + break; + } + break; + } + else if(PX_strequ(lexer.CurLexeme.buffer,"D")) + { + g_scriptVM_printFunc("IP:%d SP:%d BP:%d\n",Ins->pThread[Ins->T].IP,Ins->pThread[Ins->T].SP,Ins->pThread[Ins->T].BP); + } + + } + + PX_LexerFree(&lexer); + + return bContinue; +} +px_void PX_ScriptVM_DebuggerInterrupt(PX_ScriptVM_Instance *Ins) +{ + + px_char cmd[PX_SCRIPTVM_DEBUGGER_CMD_LEN]; + PX_ScriptVM_InstanceThread *pT=&Ins->pThread[Ins->T]; + + px_byte *pInstrs=Ins->_bin+pT->IP; + + if (!Ins->debug) + { + return; + } + if ((Ins->bp_IP==pT->IP)||Ins->bp_next) + { + if(Ins->bp_next) + Ins->bp_IP=PX_FALSE; + } + else + { + return; + } + PX_ScriptVM_DebuggerCurrentInstruction(Ins,pT->IP); + g_scriptVM_printFunc("\n"); + do + { + g_scriptVM_cmdFunc(cmd,PX_SCRIPTVM_DEBUGGER_CMD_LEN); + PX_strupr(cmd); + } while (!PX_ScriptVM_DebuggerSolveCmd(Ins,cmd)); + + + +} + +px_bool PX_ScriptVM_InstanceThreadSwitch(PX_ScriptVM_Instance *Ins,px_int T) +{ + if (TmaxThreadCount&&Ins->pThread[T].Activated) + { + Ins->T=T; + return PX_TRUE; + } + return PX_FALSE; +} + +px_void PX_ScriptVM_ThreadStop(PX_ScriptVM_Instance *Ins,px_int ThreadId) +{ + px_int popn; + if (ThreadIdmaxThreadCount) + { + if (Ins->pThread[ThreadId].Activated) + { + popn=Ins->VM_memsize-Ins->VM_Stacksize*ThreadId-Ins->pThread[ThreadId].SP; + PX_ScriptVM_POPN(Ins,ThreadId,popn); + Ins->pThread[ThreadId].Activated=PX_FALSE; + } + } +} + + +px_void PX_ScriptVM_ThreadClear(PX_ScriptVM_Instance *Ins,px_int ThreadId) +{ + px_int i,popn; + if (ThreadIdmaxThreadCount) + { + //clear stack + popn=Ins->VM_memsize-Ins->VM_Stacksize*ThreadId-Ins->pThread[ThreadId].SP; + PX_ScriptVM_POPN(Ins,ThreadId,popn); + //Clear registers + for (i=0;ipThread[ThreadId].R[i]); + } + Ins->pThread[ThreadId].Activated=PX_FALSE; + } +} + +px_void PX_ScriptVM_ThreadSuspend(PX_ScriptVM_Instance *Ins,px_int ThreadId) +{ + if (ThreadIdmaxThreadCount) + { + if (Ins->pThread[ThreadId].Activated) + { + Ins->pThread[ThreadId].suspend=PX_TRUE; + } + } +} + +px_void PX_ScriptVM_ThreadResume(PX_ScriptVM_Instance *Ins,px_int ThreadId) +{ + if (ThreadIdmaxThreadCount) + { + if (Ins->pThread[ThreadId].Activated) + { + Ins->pThread[ThreadId].suspend=PX_FALSE; + } + } +} + + + +px_void PX_ScriptVM_InstanceRun(PX_ScriptVM_Instance *Ins,px_int tick) +{ + px_int i,activating=0; + for (i=0;imaxThreadCount;i++) + { + if (Ins->pThread[i].Activated) + { + activating++; + } + } + if (!activating) + { + return; + } + + if (tickmaxThreadCount;i++) + if (Ins->pThread[i].Activated) + { + PX_ScriptVM_InstanceThreadSwitch(Ins,i); + PX_ScriptVM_InstanceRunThread(Ins,PX_SCRIPTVM_ATOM_INSTRUCTMENTS); + tick-=PX_SCRIPTVM_ATOM_INSTRUCTMENTS; + if (tick<=0) + { + return; + } + } + } + +} + + + + + + diff --git a/lib/PainterEngine/kernel/PX_Script_VM.h b/lib/PainterEngine/kernel/PX_Script_VM.h new file mode 100644 index 0000000000000000000000000000000000000000..932380ed56daa1e353904a130e903e453c5be87b --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Script_VM.h @@ -0,0 +1,123 @@ +#ifndef __PX_SCRIPT_VM_H +#define __PX_SCRIPT_VM_H +#include "PX_ScriptCore.h" +#define PX_SCRIPTVM_DEFALUT_FLOAT_PRECCISION 6 +#define PX_SCRIPTVM_REG_COUNT 8 +#define PX_SCRIPTVM_SIGNAL_COUNT 16 +#define PX_SCRIPTVM_DEBUGGER_CMD_LEN 128 +#define PX_SCRIPTVM_ATOM_INSTRUCTMENTS 64 +#define PX_SCRIPTVM_TICK_INFINITE (-1) +typedef struct +{ + px_bool Activated; + px_bool suspend; + px_uint sleep; + px_int IP,SP,BP; + PX_SCRIPTVM_VARIABLE R[PX_SCRIPTVM_REG_COUNT]; +}PX_ScriptVM_InstanceThread; + +typedef struct +{ + px_int VM_Globalsize; + px_int VM_Stacksize; + px_int VM_memsize; + + px_int stringsize; + px_int memorysize; + px_int binsize; + px_int funcCount; + px_int hostCount; + px_int maxThreadCount; + + px_bool signal[PX_SCRIPTVM_SIGNAL_COUNT]; + px_bool Suspend; + + px_int T; + + px_byte * _bin; + px_byte *_memory; + px_char *_string; + px_memorypool *mp; + + union + { + px_void *user_ptr; + px_int user_int; + px_float user_float; + }; + + + PX_SCRIPT_EXPORT_FUNCTION *_func; + PX_SCRIPT_ASM_HOST_NODE *_host; + PX_SCRIPTVM_VARIABLE *_mem; + PX_ScriptVM_InstanceThread *pThread; + + px_bool debug; + px_bool bp_next; + px_int bp_IP; + +}PX_ScriptVM_Instance; + +typedef struct +{ + px_int ptr; + px_int size; +}PX_SCRIPTVM_MEMORY_PTR; + +typedef enum +{ + PX_SCRIPTVM_RUNRETURN_ERROR =0, + PX_SCRIPTVM_RUNRETURN_TIMEOUT, + PX_SCRIPTVM_RUNRETURN_END, + PX_SCRIPTVM_RUNRETURN_SUSPEND, + PX_SCRIPTVM_RUNRETURN_WAIT, +}PX_SCRIPTVM_RUNRETURN; + +typedef px_bool (*PX_ScriptVM_Function_Modules)(PX_ScriptVM_Instance *Ins,px_void *userptr); + +px_int PX_ScriptVM_GetFunctionIndex(PX_ScriptVM_Instance *Ins,px_char *func); + +px_bool PX_ScriptVM_InstanceThreadSwitch(PX_ScriptVM_Instance *Ins,px_int T); +px_bool PX_ScriptVM_InstanceRunFunction(PX_ScriptVM_Instance *Ins,px_int threadID,const px_char *functionName,PX_SCRIPTVM_VARIABLE args[],px_int paramcount); +px_bool PX_ScriptVM_InstanceRunFunctionIndex(PX_ScriptVM_Instance *Ins,px_int threadID,px_int funcIndex,PX_SCRIPTVM_VARIABLE args[],px_int paramcount); +px_bool PX_ScriptVM_InstanceBeginThreadFunction(PX_ScriptVM_Instance *Ins,px_int threadID,const px_char *functionName,PX_SCRIPTVM_VARIABLE args[],px_int paramcount); +px_bool PX_ScriptVM_InstanceBeginThreadFunctionIndex(PX_ScriptVM_Instance *Ins,px_int threadID,px_int funcIndex,PX_SCRIPTVM_VARIABLE args[],px_int paramcount); +px_int PX_ScriptVM_InstanceGetFreeThreadId(PX_ScriptVM_Instance *Ins); +PX_SCRIPTVM_RUNRETURN PX_ScriptVM_InstanceRunThread(PX_ScriptVM_Instance *Ins,px_int tick); +px_void PX_ScriptVM_InstanceRun(PX_ScriptVM_Instance *Ins,px_int tick); +px_void PX_ScriptVM_ThreadStop(PX_ScriptVM_Instance *Ins,px_int ThreadId); +px_void PX_ScriptVM_ThreadClear(PX_ScriptVM_Instance *Ins,px_int ThreadId); +px_void PX_ScriptVM_ThreadSuspend(PX_ScriptVM_Instance *Ins,px_int ThreadId); +px_void PX_ScriptVM_ThreadResume(PX_ScriptVM_Instance *Ins,px_int ThreadId); + + +px_bool PX_ScriptVM_InstanceInitialize(PX_ScriptVM_Instance *Ins,px_memorypool *mp,px_byte *code,px_int size); +px_bool PX_ScriptVM_LocalAlloc(PX_ScriptVM_Instance *Ins,int size,PX_SCRIPTVM_MEMORY_PTR *mem_ptr); +px_bool PX_ScriptVM_LocalFree(PX_ScriptVM_Instance *Ins,PX_SCRIPTVM_MEMORY_PTR *mem_ptr); +px_bool PX_ScriptVM_RegistryHostFunction(PX_ScriptVM_Instance *Ins,const px_char *name,PX_ScriptVM_Function_Modules funcModules,px_void *userptr); +px_bool PX_ScriptVM_InstanceFree(PX_ScriptVM_Instance *Ins); + +#define PX_ScriptVM_STACK(Ins,i) ((Ins)->_mem[(Ins)->pThread[(Ins)->T].SP+i]) +#define PX_ScriptVM_HOSTPARAM(Ins,i) PX_ScriptVM_STACK(Ins,i) +#define PX_ScriptVM_LOCALPARAM(Ins,i) ((Ins)->_mem[(Ins)->pThread[(Ins)->T].BP-i]) +#define PX_ScriptVM_GLOBAL(Ins,i) ((Ins)->_mem[i]) +#define PX_ScriptVM_RETURN_POINTER(Ins,oft) ((Ins)->_mem[((Ins)->pThread[(Ins)->T].R[1])._int+(oft)]) +#define PX_ScriptVM_REG_RETURN(Ins) ((Ins)->pThread[(Ins)->T].R[1]) + +px_void PX_ScriptVM_POPN(PX_ScriptVM_Instance *Ins,px_int n,px_int Threadid); +px_void PX_ScriptVM_RET(PX_ScriptVM_Instance *Ins,PX_SCRIPTVM_VARIABLE ret); +px_void PX_ScriptVM_PUSH(PX_ScriptVM_Instance *Ins,PX_SCRIPTVM_VARIABLE val); +PX_SCRIPTVM_VARIABLE PX_ScriptVM_Variable_int(px_int _int); +PX_SCRIPTVM_VARIABLE PX_ScriptVM_Variable_float(px_float _float); +PX_SCRIPTVM_VARIABLE PX_ScriptVM_Variable_string(px_string _ref_string); +PX_SCRIPTVM_VARIABLE PX_ScriptVM_Variable_memory(px_byte *buffer,px_int _size); +PX_SCRIPTVM_VARIABLE PX_ScriptVM_Variable_const_string(px_char *buffer); +PX_SCRIPTVM_VARIABLE PX_ScriptVM_Variable_const_memory(px_byte *buffer,px_int _size); +PX_SCRIPTVM_VARIABLE PX_SCRIPTVM_VaribaleCopy(PX_ScriptVM_Instance *Ins,PX_SCRIPTVM_VARIABLE var,px_bool *bOutofMemory); +typedef px_int (* PX_ScriptVM_DebuggerPrint)(px_char fmr[],...); +typedef px_int (* PX_ScriptVM_DebuggerCommand)(px_char cmd[],px_int size); + +px_int PX_ScriptVM_DebuggerEnable(PX_ScriptVM_Instance *Ins,PX_ScriptVM_DebuggerPrint _printFunc,PX_ScriptVM_DebuggerCommand _cmdFunc); + + +#endif diff --git a/lib/PainterEngine/kernel/PX_Sync.c b/lib/PainterEngine/kernel/PX_Sync.c new file mode 100644 index 0000000000000000000000000000000000000000..1778e302165fff871b20a26fd694eed953e6c555 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Sync.c @@ -0,0 +1,1179 @@ +#include "PX_Sync.h" + +#ifdef PX_DEBUG_MODE +#include "stdio.h" +#define PX_SYNC_LOG printf +#else +#define PX_SYNC_LOG +#endif + +typedef struct +{ + px_dword param[4]; +}PX_Sync_IO_Info; + +px_bool PX_SyncFrameServerInit(PX_SyncFrame_Server *sync,px_memorypool *mp,px_dword updateDuration,PX_Linker *linker) +{ + sync->mp=mp; + sync->linker=linker; + sync->time=0; + sync->updateDuration=updateDuration; + sync->status=PX_SYNC_SERVER_STATUS_END; + sync->instr_once_maxsize=PX_SYNC_DEFAULT_INSTR_ONCE_MAX_SIZE; + sync->unique=0; + sync->version=0; + PX_VectorInitialize(mp,&sync->clients,sizeof(PX_SyncFrame_Server_Clients),32); + PX_VectorInitialize(mp,&sync->stampsIndexTable,sizeof(PX_SyncFrame_InstrStream_StampIndex),PX_SYNC_INSTRS_SIZE); + PX_MemoryInitialize(mp,&sync->stampsInstrStream); + return PX_MemoryResize(&sync->stampsInstrStream,PX_SYNC_INSTRS_BYTES_SIZE); +} + +px_void PX_SyncFrameServerSetVersion(PX_SyncFrame_Server *sync,px_dword version) +{ + sync->version=version; +} + +static px_bool PX_SyncFrameServer_Write(PX_SyncFrame_Server *sync_server,PX_SyncFrame_Server_Clients *pClient,px_void *data,px_uint size) +{ + PX_Sync_IO_Packet *packet=(PX_Sync_IO_Packet *)data; + packet->verify_id=pClient->client_id; + return PX_LinkerWrite(sync_server->linker,data,size)!=0; +} +static px_bool PX_SyncFrameServer_Read(PX_SyncFrame_Server *server,PX_SyncFrame_Server_Clients **ppclient) +{ + PX_SyncFrame_Server_Clients *pClient=PX_NULL; + PX_Sync_IO_Packet *packet=PX_NULL; + +__RE_RECV: + + while ((server->recv_cache_size=PX_LinkerRead(server->linker,server->recv_cache_buffer,sizeof(server->recv_cache_buffer)))!=0) + { + int i; + packet=(PX_Sync_IO_Packet *)(server->recv_cache_buffer); + for (i=0;iclients.size;i++) + { + pClient=PX_VECTORAT(PX_SyncFrame_Server_Clients,&server->clients,i); + if (pClient->server_id==packet->verify_id) + { + if(packet->unique==0) + { + *ppclient=pClient; + return PX_TRUE; + } + else + { + px_int j; + for (j=0;junique==pClient->acceptuniqueQueue[j]) + { + goto __RE_RECV; + } + } + if (pClient->uniqueQueuewIndex>=PX_SYNC_UNIQUE_ARRAY_SIZE) + { + pClient->uniqueQueuewIndex=0; + } + pClient->acceptuniqueQueue[pClient->uniqueQueuewIndex]=packet->unique; + pClient->uniqueQueuewIndex++; + *ppclient=pClient; + return PX_TRUE; + } + + } + } + + } + return PX_FALSE; +} + +static px_void PX_SyncFrameServerHandle_StatusConnect(PX_SyncFrame_Server *sync_server,px_dword elapsed) +{ + PX_SyncFrame_Server_Clients *pClient=PX_NULL; + PX_Sync_IO_Packet *recv_packet,*send_packet; + px_int i; + + while (PX_SyncFrameServer_Read(sync_server,&pClient)) + { + recv_packet=(PX_Sync_IO_Packet *)(sync_server->recv_cache_buffer); + + if (recv_packet->type==PX_SYNC_IO_TYPE_CONNECT) + { + if (recv_packet->param1==sync_server->version) + { + if(pClient->status==PX_SYNC_SERVERCLIENT_STATUS_CONNECT) + { + pClient->status=PX_SYNC_SERVERCLIENT_STATUS_PROCESSING; + pClient->timeIndexOffset=0; + pClient->timeStreamOffset=0; + pClient->sendDurationTick=PX_SYNC_SERVER_SEND_DURATION; + } + } + + send_packet=(PX_Sync_IO_Packet *)(sync_server->send_cache_buffer); + send_packet->verify_id=0; + send_packet->type=PX_SYNC_IO_TYPE_CONNECTACK; + send_packet->unique=0; + send_packet->param1=pClient->c_id; + send_packet->param2=0; + PX_SyncFrameServer_Write(sync_server,pClient,send_packet,sizeof(PX_Sync_IO_Packet)); + + for(i=0;iclients.size;i++) + { + pClient=PX_VECTORAT(PX_SyncFrame_Server_Clients,&sync_server->clients,i); + if (pClient->status!=PX_SYNC_SERVERCLIENT_STATUS_PROCESSING) + { + break; + } + } + + if (i>=sync_server->clients.size) + { + sync_server->status=PX_SYNC_SERVER_STATUS_PROCESSING; + return; + } + } + else if(recv_packet->type==PX_SYNC_IO_TYPE_QUERYSTATE) + { + px_int count=0; + for(i=0;iclients.size;i++) + { + PX_SyncFrame_Server_Clients *pEnumClient=PX_VECTORAT(PX_SyncFrame_Server_Clients,&sync_server->clients,i); + if (pEnumClient->status==PX_SYNC_SERVERCLIENT_STATUS_PROCESSING) + { + count++; + } + } + + send_packet=(PX_Sync_IO_Packet *)(sync_server->send_cache_buffer); + send_packet->verify_id=0; + send_packet->type=PX_SYNC_IO_TYPE_QUERYSTATEACK; + send_packet->unique=0; + send_packet->param1=count; + send_packet->param2=sync_server->clients.size; + PX_SyncFrameServer_Write(sync_server,pClient,send_packet,sizeof(PX_Sync_IO_Packet)); + } + } +} + + +static px_void PX_SyncFrameServerHandle_StatusProcess(PX_SyncFrame_Server *sync_server,px_dword updateelapsed) +{ + px_int i,datasize=0,dataoffset; + PX_SyncFrame_Server_Clients *pClient=PX_NULL; + PX_Sync_IO_Packet *send_packet,*recv_packet; + px_dword elapsed; + sync_server->time+=updateelapsed; + + for (i=0;iclients.size;i++) + { + pClient=PX_VECTORAT(PX_SyncFrame_Server_Clients,&sync_server->clients,i); + pClient->lastInstrelapsed+=updateelapsed; + } + + do + { + if (updateelapsed>=PX_SYNC_SERVER_SEND_DURATION) + { + elapsed=PX_SYNC_SERVER_SEND_DURATION; + updateelapsed-=elapsed; + } + else + { + elapsed=updateelapsed; + updateelapsed=0; + } + + + //nop timestamp + if ((sync_server->time+elapsed)/sync_server->updateDuration>=(px_dword)sync_server->stampsIndexTable.size) + { + PX_SyncFrame_InstrStream_StampIndex newStamp; + newStamp.oft=sync_server->stampsInstrStream.usedsize; + newStamp.size=0; + //PX_SYNC_LOG("Time thunk %d sum32 %d\n",sync_server->stampsIndexTable.size,PX_SyncFrameServerSum32(sync_server)); + + PX_VectorPushback(&sync_server->stampsIndexTable,&newStamp); + for (i=0;iclients.size;i++) + { + pClient=PX_VECTORAT(PX_SyncFrame_Server_Clients,&sync_server->clients,i); + pClient->onceRecvSize=0; + } + } + + while (PX_SyncFrameServer_Read(sync_server,&pClient)) + { + recv_packet=(PX_Sync_IO_Packet *)(sync_server->recv_cache_buffer); + pClient->lastInstrelapsed=0; + + switch (recv_packet->type) + { + case PX_SYNC_IO_TYPE_CONNECT: + { + if (recv_packet->param1==sync_server->version) + { + send_packet=(PX_Sync_IO_Packet *)(sync_server->send_cache_buffer); + send_packet->verify_id=0; + send_packet->type=PX_SYNC_IO_TYPE_CONNECTACK; + send_packet->unique=0; + send_packet->param1=pClient->c_id;; + send_packet->param2=0; + PX_SyncFrameServer_Write(sync_server,pClient,send_packet,sizeof(PX_Sync_IO_Packet)); + } + } + break; + case PX_SYNC_IO_TYPE_QUERYSTATE: + { + send_packet=(PX_Sync_IO_Packet *)(sync_server->send_cache_buffer); + send_packet->verify_id=0; + send_packet->type=PX_SYNC_IO_TYPE_QUERYSTATEACK; + send_packet->unique=0; + send_packet->param1=sync_server->clients.size; + send_packet->param2=sync_server->clients.size; + PX_SyncFrameServer_Write(sync_server,pClient,send_packet,sizeof(PX_Sync_IO_Packet)); + } + break; + case PX_SYNC_IO_TYPE_REQUEST: + { + pClient->timeIndexOffset=recv_packet->param1; + pClient->timeStreamOffset=recv_packet->param2; + pClient->sendTimes=0; + pClient->sendDurationTick=PX_SYNC_SERVER_SEND_DURATION; + } + break; + case PX_SYNC_IO_TYPE_OPCODE: + { + px_int max_size=0; + PX_SyncFrame_InstrStream_StampIndex *plastStamp=PX_VECTORLAST(PX_SyncFrame_InstrStream_StampIndex,&sync_server->stampsIndexTable); + + //check size + if (sync_server->recv_cache_size<(px_int)((PX_STRUCT_OFFSET(PX_Sync_IO_Packet,data)+sizeof(px_dword)*2))) + { + break; + } + + //check size + if (pClient->onceRecvSize+sync_server->recv_cache_size>sync_server->instr_once_maxsize) + { + break; + } + pClient->onceRecvSize+=sync_server->recv_cache_size; + datasize=sync_server->recv_cache_size-(px_int)PX_STRUCT_OFFSET(PX_Sync_IO_Packet,data); + + PX_MemoryCat(&sync_server->stampsInstrStream,&pClient->c_id,sizeof(pClient->c_id));//id + PX_MemoryCat(&sync_server->stampsInstrStream,&datasize,sizeof(px_dword));//size + PX_MemoryCat(&sync_server->stampsInstrStream,&recv_packet->data,datasize); + + plastStamp->size+=sizeof(pClient->c_id)+sizeof(px_dword)+datasize; + + } + break; + } + } + + //send instrument + + if(sync_server->stampsIndexTable.size) + { + for (i=0;iclients.size;i++) + { + pClient=PX_VECTORAT(PX_SyncFrame_Server_Clients,&sync_server->clients,i); + + if (((px_int)pClient->timeIndexOffset>=sync_server->stampsIndexTable.size)&&((px_int)pClient->timeStreamOffset>=sync_server->stampsInstrStream.usedsize)) + { + continue; + } + + if (pClient->sendDurationTick>=PX_SYNC_SERVER_SEND_DURATION) + { + pClient->sendDurationTick=0; + + if (pClient->sendTimes<=0) + { + px_uint reserve_size; + px_dword stream_size=0,indexTableSize=0; + px_dword wstream_size=0,windexTableSize=0; + + + send_packet=(PX_Sync_IO_Packet *)(pClient->send_cache_instr_buffer); + PX_memset(pClient->send_cache_instr_buffer,0,sizeof(pClient->send_cache_instr_buffer)); + + + send_packet->type=PX_SYNC_IO_TYPE_OPCODE; + send_packet->verify_id=0; + + reserve_size=sizeof(pClient->send_cache_instr_buffer)- (px_int)PX_STRUCT_OFFSET(PX_Sync_IO_Packet,data); + + wstream_size=sync_server->stampsInstrStream.usedsize-pClient->timeStreamOffset; + + if (wstream_size>reserve_size-sizeof(pClient->timeStreamOffset)-sizeof(wstream_size))//<--- start offset dword and size dword + { + wstream_size=reserve_size-sizeof(pClient->timeStreamOffset)-sizeof(wstream_size); + } + + datasize=0; + dataoffset=0; + + //stream start-offset 4bytes + PX_memcpy(pClient->send_cache_instr_buffer+(sizeof(sync_server->recv_cache_buffer)-reserve_size),&pClient->timeStreamOffset,sizeof(pClient->timeStreamOffset)); + reserve_size-=sizeof(pClient->timeStreamOffset); + //stream size 4bytes + PX_memcpy(pClient->send_cache_instr_buffer+(sizeof(sync_server->recv_cache_buffer)-reserve_size),&wstream_size,sizeof(wstream_size)); + reserve_size-=sizeof(wstream_size); + + //Instr stream + if (wstream_size>reserve_size){wstream_size=reserve_size;} + PX_memcpy(pClient->send_cache_instr_buffer+(sizeof(sync_server->recv_cache_buffer)-reserve_size),sync_server->stampsInstrStream.buffer+pClient->timeStreamOffset,wstream_size); + datasize+=wstream_size; + reserve_size-=wstream_size; + + + if (reserve_size>=sizeof(PX_SyncFrame_InstrStream_StampIndex)+sizeof(px_dword)*2) + { + if (sync_server->stampsIndexTable.size-pClient->timeIndexOffset>1) //last stamp is not ready + { + windexTableSize=(sync_server->stampsIndexTable.size-pClient->timeIndexOffset-1); + + if (windexTableSize>(reserve_size-sizeof(px_dword)*2)/sizeof(PX_SyncFrame_InstrStream_StampIndex)) + { + windexTableSize=(reserve_size-sizeof(px_dword)*2)/sizeof(PX_SyncFrame_InstrStream_StampIndex); + } + if (windexTableSize) + { + //Index start-offset + PX_memcpy(pClient->send_cache_instr_buffer+(sizeof(sync_server->recv_cache_buffer)-reserve_size),&pClient->timeIndexOffset,sizeof(pClient->timeIndexOffset)); + reserve_size-=sizeof(pClient->timeIndexOffset); + //Index Size + PX_memcpy(pClient->send_cache_instr_buffer+(sizeof(sync_server->recv_cache_buffer)-reserve_size),&windexTableSize,sizeof(windexTableSize)); + reserve_size-=sizeof(windexTableSize); + //data + PX_memcpy(pClient->send_cache_instr_buffer+(sizeof(sync_server->recv_cache_buffer)-reserve_size),(px_byte *)sync_server->stampsIndexTable.data+pClient->timeIndexOffset*sizeof(PX_SyncFrame_InstrStream_StampIndex),windexTableSize*sizeof(PX_SyncFrame_InstrStream_StampIndex)); + reserve_size-=(windexTableSize*sizeof(PX_SyncFrame_InstrStream_StampIndex)); + datasize+=(windexTableSize*sizeof(PX_SyncFrame_InstrStream_StampIndex)); + } + } + } + + + pClient->timeStreamOffset+=wstream_size; + pClient->timeIndexOffset+=windexTableSize; + pClient->send_cache_instr_size=sizeof(sync_server->recv_cache_buffer)-reserve_size; + //send cache + + if(datasize) + { + //alloc unique + send_packet->unique=(++sync_server->unique); + if (send_packet->unique==0) + { + send_packet->unique=1; + } + // PX_SYNC_LOG("id %d Update ms %d\n",pClient->c_id,sync_server->time-pClient->lastsendtime); + pClient->lastsendtime=sync_server->time; + PX_SyncFrameServer_Write(sync_server,pClient,pClient->send_cache_instr_buffer,pClient->send_cache_instr_size); + ////////////////////////////////////////////////////////////////////////// + pClient->sendTimes=PX_SYNC_SERVER_SEND_TIMES; + ////////////////////////////////////////////////////////////////////////// + } + else + { + pClient->send_cache_instr_size=0; + pClient->sendTimes=0; + } + + } + else + { + pClient->sendTimes--; + send_packet=(PX_Sync_IO_Packet *)(pClient->send_cache_instr_buffer); + if (pClient->send_cache_instr_size) + { + PX_SyncFrameServer_Write(sync_server,pClient,pClient->send_cache_instr_buffer,pClient->send_cache_instr_size); + } + } + } + else + { + pClient->sendDurationTick+=elapsed; + } + + } + } + + }while (updateelapsed); +} +px_void PX_SyncFrameServerUpdate(PX_SyncFrame_Server *sync_server,px_dword elapsed) +{ + switch(sync_server->status) + { + case PX_SYNC_SERVER_STATUS_CONNECT: + { + PX_SyncFrameServerHandle_StatusConnect(sync_server,elapsed); + } + break; + case PX_SYNC_SERVER_STATUS_PROCESSING: + { + PX_SyncFrameServerHandle_StatusProcess(sync_server,elapsed); + } + break; + case PX_SYNC_SERVER_STATUS_END: + break; + default: + break; + + } +} +px_bool PX_SyncFrameServerAddClient(PX_SyncFrame_Server *sync,px_dword server_verify_id,px_dword client_id,px_dword c_id) +{ + PX_SyncFrame_Server_Clients client; + px_int i; + client.timeIndexOffset=0; + client.timeStreamOffset=0; + client.sendDurationTick=PX_SYNC_SERVER_SEND_DURATION; + client.status=PX_SYNC_SERVERCLIENT_STATUS_CONNECT; + for(i=0;iclients,&client); +} + + +px_void PX_SyncFrameServerSetInstrOnceMaxSize(PX_SyncFrame_Server *sync,px_int maxsize) +{ + sync->instr_once_maxsize=maxsize; +} + +px_bool PX_SyncFrameClientInit(PX_SyncFrame_Client *client,px_memorypool *mp,px_dword updateDuration,px_dword server_verify_id,px_dword client_id,PX_Linker *linker) +{ + px_int i; + + client->mp=mp; + client->linker=linker; + client->server_verify_id=server_verify_id; + client->client_id=client_id; + client->updateDuration=updateDuration; + client->time=0; + client->unique=0; + client->delayms=0; + client->c_id=0; + client->connectCount=0; + client->connectSumCount=0; + client->version=0; + + for(i=0;iacceptuniqueQueue[i]=0; + client->uniqueQueuewIndex=0; + client->status=PX_SYNC_CLIENT_STATUS_CONNECTING; + client->send_cache_Instr_size=0; + client->send_repeat_times=0; + PX_VectorInitialize(mp,&client->stampsIndexTable,sizeof(PX_SyncFrame_InstrStream_StampIndex),PX_SYNC_INSTRS_SIZE); + PX_MemoryInitialize(mp,&client->Input_InstrStream); + PX_MemoryInitialize(mp,&client->stampsInstrStream); + return PX_MemoryResize(&client->stampsInstrStream,2*PX_SYNC_INSTRS_SIZE); + +} +static px_bool PX_SyncFrameClient_Read(PX_SyncFrame_Client *client) +{ + px_bool repeat; + + while ((client->recv_cache_buffer_size=PX_LinkerRead(client->linker,client->recv_cache_buffer,sizeof(client->recv_cache_buffer)))!=0) + { + PX_Sync_IO_Packet *packet=(PX_Sync_IO_Packet *)(client->recv_cache_buffer); + if (packet->verify_id!=client->client_id) + { + return PX_FALSE; + } + + if(packet->unique==0) + { + return PX_TRUE; + } + else + { + px_int j; + repeat=PX_FALSE; + for (j=0;junique==client->acceptuniqueQueue[j]) + { + repeat=PX_TRUE; + break; + } + } + if (repeat) + { + continue; + } + if (client->uniqueQueuewIndex>=PX_SYNC_UNIQUE_ARRAY_SIZE) + { + client->uniqueQueuewIndex=0; + } + client->acceptuniqueQueue[client->uniqueQueuewIndex]=packet->unique; + client->uniqueQueuewIndex++; + return PX_TRUE; + } + + } + return PX_FALSE; +} +static px_bool PX_SyncFrameClient_Write(PX_SyncFrame_Client *client,px_void *data,px_uint size) +{ + PX_Sync_IO_Packet *packet=(PX_Sync_IO_Packet *)(data); + if (!data) + { + return PX_FALSE; + } + packet->verify_id=client->server_verify_id; + + return PX_LinkerWrite(client->linker,data,size)!=0; +} + +static px_void PX_SyncFrame_ClientHandle_StatusConneting(PX_SyncFrame_Client *client,px_dword elapsed) +{ + //read + PX_Sync_IO_Packet *packet; + + while (PX_SyncFrameClient_Read(client)) + { + PX_Sync_IO_Packet *packet=(PX_Sync_IO_Packet *)(client->recv_cache_buffer); + if (packet->type==PX_SYNC_IO_TYPE_CONNECTACK) + { + client->status=PX_SYNC_CLIENT_STATUS_WAITING; + client->c_id=packet->param1; + while (PX_SyncFrameClient_Read(client));//clear buffer + return; + } + } + + if (elapsed) + { + packet=(PX_Sync_IO_Packet *)(client->send_cache_buffer); + packet->verify_id=0; + packet->type=PX_SYNC_IO_TYPE_CONNECT; + packet->unique=0; + packet->param1=client->version; + packet->param2=0; + PX_SyncFrameClient_Write(client,packet,sizeof(PX_Sync_IO_Packet)); + } + +} + +static px_void PX_SyncFrame_ClientHandle_StatusWaiting(PX_SyncFrame_Client *client,px_dword elapsed) +{ + //read + PX_Sync_IO_Packet *packet; + + while (PX_SyncFrameClient_Read(client)) + { + PX_Sync_IO_Packet *packet=(PX_Sync_IO_Packet *)(client->recv_cache_buffer); + if (packet->type==PX_SYNC_IO_TYPE_QUERYSTATEACK) + { + client->connectCount=packet->param1; + client->connectSumCount=packet->param2; + while (PX_SyncFrameClient_Read(client));//clear buffer + if (client->connectCount>=client->connectSumCount) + { + client->status=PX_SYNC_CLIENT_STATUS_PROCESSING; + } + return; + } + } + + if (elapsed) + { + packet=(PX_Sync_IO_Packet *)(client->send_cache_buffer); + packet->verify_id=0; + packet->type=PX_SYNC_IO_TYPE_QUERYSTATE; + packet->unique=0; + packet->param1=0; + packet->param2=0; + PX_SyncFrameClient_Write(client,packet,sizeof(PX_Sync_IO_Packet)); + } + +} + +static px_void PX_SyncFrame_ClientHandle_Request(PX_SyncFrame_Client *client) +{ + PX_Sync_IO_Packet *packet; + + packet=(PX_Sync_IO_Packet *)(client->send_cache_buffer); + + packet->unique=0; + packet->type=PX_SYNC_IO_TYPE_REQUEST; + packet->verify_id=0; + packet->param1=client->stampsIndexTable.size; + packet->param2=client->stampsInstrStream.usedsize; + + PX_SyncFrameClient_Write(client,packet,sizeof(PX_Sync_IO_Packet)); + +} + +static px_void PX_SyncFrame_ClientHandle_StatusProcessing(PX_SyncFrame_Client *client,px_dword elapsed) +{ + PX_Sync_IO_Packet *recv_packet,*send_packet; + px_int i; + client->time+=elapsed; + //write + //update send cache + if (client->send_repeat_times==0) + { + //read instr to send_repeat_times + + if (client->Input_InstrStream.usedsize) + { + px_int sendsize=0; + + send_packet=(PX_Sync_IO_Packet *)(client->send_cache_Instr_buffer); + send_packet->type=PX_SYNC_IO_TYPE_OPCODE; + send_packet->verify_id=0; + if (client->unique==0) + { + client->unique=1; + } + send_packet->unique=(client->unique++); + + sendsize+=sizeof(recv_packet->type)+sizeof(recv_packet->verify_id); + + if((px_uint)client->Input_InstrStream.usedsizesend_cache_Instr_buffer)- (px_int)PX_STRUCT_OFFSET(PX_Sync_IO_Packet,data)) + { + client->send_cache_Instr_size=client->Input_InstrStream.usedsize+ (px_int)PX_STRUCT_OFFSET(PX_Sync_IO_Packet,data); + PX_memcpy(send_packet->data,client->Input_InstrStream.buffer,client->Input_InstrStream.usedsize); + } + else + { + PX_MemoryClear(&client->Input_InstrStream); + client->send_cache_Instr_size=0; + } + PX_MemoryClear(&client->Input_InstrStream); + + client->send_repeat_times=PX_SYNC_CLIENT_SEND_TIMES-1; + + + PX_SyncFrameClient_Write(client,client->send_cache_Instr_buffer,client->send_cache_Instr_size); + } + } + else + { + + if (client->sendDurationTick+elapsed>=PX_SYNC_CLIENT_SEND_DURATION) + { + client->sendDurationTick=0; + client->send_repeat_times--; + if(client->send_cache_Instr_size) + { + PX_SyncFrameClient_Write(client,client->send_cache_Instr_buffer,client->send_cache_Instr_size); + } + } + else + { + client->sendDurationTick+=elapsed; + } + } + + + + + + //recv + while (PX_SyncFrameClient_Read(client)) + { + recv_packet=(PX_Sync_IO_Packet *)(client->recv_cache_buffer); + + if (recv_packet->type==PX_SYNC_IO_TYPE_OPCODE) + { + px_int streamStart,streamSize,stampStartIndex,stampSize,reserve_size; + px_byte *streamdata; + PX_SyncFrame_InstrStream_StampIndex *pStamps; + streamStart=*(px_dword *)recv_packet->data; + streamSize=*(px_dword *)(recv_packet->data+sizeof(px_dword)); + streamdata=recv_packet->data+sizeof(px_dword)*2; + if (streamStart>client->stampsInstrStream.usedsize) + { + PX_SyncFrame_ClientHandle_Request(client); + return; + } + + if (streamStartstampsInstrStream.usedsize) + { + continue; + } + + + if (streamSize) + { + PX_MemoryCat(&client->stampsInstrStream,streamdata,streamSize); + } + reserve_size=client->recv_cache_buffer_size-streamSize-sizeof(px_dword)*2- (px_int)PX_STRUCT_OFFSET(PX_Sync_IO_Packet,data); + if (reserve_size>=sizeof(PX_SyncFrame_InstrStream_StampIndex)+sizeof(px_dword)*2) + { + stampStartIndex=*(px_dword *)(recv_packet->data+sizeof(px_dword)*2+streamSize); + stampSize=*(px_dword *)(recv_packet->data+sizeof(px_dword)*2+streamSize+sizeof(px_dword)); + pStamps=(PX_SyncFrame_InstrStream_StampIndex *)(recv_packet->data+sizeof(px_dword)*2+streamSize+sizeof(px_dword)*2); + } + else + { + continue; + } + + if (stampStartIndex>client->stampsIndexTable.size) + { + PX_SyncFrame_ClientHandle_Request(client); + return; + } + + if (stampStartIndexstampsIndexTable.size) + { + continue; + } + + + for(i=0;istampsIndexTable,&pStamps[i]); + } + //PX_SYNC_LOG("Sync %d delay %d ms sum32:%d\n",client->stampsIndexTable.size,client->time-client->delayms,PX_SyncFrameClientSum32(client)); + client->delayms=client->time; + } + } + + + +} +px_void PX_SyncFrameClientUpdate(PX_SyncFrame_Client *client,px_dword elapsed) +{ + switch (client->status) + { + case PX_SYNC_CLIENT_STATUS_CONNECTING: + { + PX_SyncFrame_ClientHandle_StatusConneting(client,elapsed); + } + break; + case PX_SYNC_CLIENT_STATUS_WAITING: + { + PX_SyncFrame_ClientHandle_StatusWaiting(client,elapsed); + } + break; + case PX_SYNC_CLIENT_STATUS_PROCESSING: + { + PX_SyncFrame_ClientHandle_StatusProcessing(client,elapsed); + } + break; + case PX_SYNC_CLIENT_STATUS_END: + break; + } +} + + +px_int PX_SyncFrameClientGetReadyFrameCount(PX_SyncFrame_Client *sync) +{ + return sync->stampsIndexTable.size; +} + +px_void PX_SyncFrameClientAddInstr(PX_SyncFrame_Client *client,px_void *instr,px_int size) +{ + if (client->status==PX_SYNC_CLIENT_STATUS_PROCESSING) + { + PX_MemoryCat(&client->Input_InstrStream,instr,size); + } + +} + + +px_void PX_SyncFrameClientSetVersion(PX_SyncFrame_Client *sync,px_dword version) +{ + sync->version=version; +} + +px_void PX_SyncFrameServerStop(PX_SyncFrame_Server *sync) +{ + sync->status=PX_SYNC_SERVER_STATUS_END; +} +px_void PX_SyncFrameServerRun(PX_SyncFrame_Server *sync) +{ + sync->status=PX_SYNC_SERVER_STATUS_CONNECT; +} +px_void PX_SyncFrameServerFree(PX_SyncFrame_Server *sync) +{ + PX_VectorFree(&sync->clients); + PX_VectorFree(&sync->stampsIndexTable); + PX_MemoryFree(&sync->stampsInstrStream); +} + +px_int PX_SyncFrameServerGetReadyFrameCount(PX_SyncFrame_Server *sync) +{ + return sync->stampsIndexTable.size-1; +} + +px_void PX_SyncFrameClientFree(PX_SyncFrame_Client *sync) +{ + PX_VectorFree(&sync->stampsIndexTable); + PX_MemoryFree(&sync->stampsInstrStream); + PX_MemoryFree(&sync->Input_InstrStream); +} + + + + +px_uint32 PX_SyncFrameServerSum32(PX_SyncFrame_Server *sync) +{ + px_uint32 sum=0; + sum+=PX_sum32(sync->stampsIndexTable.data,sync->stampsIndexTable.nodesize*sync->stampsIndexTable.size); + sum+=PX_sum32(sync->stampsInstrStream.buffer,sync->stampsInstrStream.usedsize); + return sum; +} + +px_uint32 PX_SyncFrameClientSum32(PX_SyncFrame_Client *sync) +{ + px_uint32 sum=0; + sum+=PX_sum32(sync->stampsIndexTable.data,sync->stampsIndexTable.nodesize*sync->stampsIndexTable.size); + sum+=PX_sum32(sync->stampsInstrStream.buffer,sync->stampsInstrStream.usedsize); + return sum; +} + + + +////////////////////////////////////////////////////////////////////////// +//SyncData + +static px_int PX_SyncDataCalculateBlockCount(px_int size) +{ + return size%PX_SYNCDATA_BLOCK_SIZE?size/PX_SYNCDATA_BLOCK_SIZE+1:size/PX_SYNCDATA_BLOCK_SIZE; +} + +px_bool PX_SyncDataServerInit(PX_SyncData_Server *syncdata_server,px_memorypool *mp,px_dword serverID,PX_Linker *linker) +{ + PX_memset(syncdata_server,0,sizeof(PX_SyncData_Server)); + syncdata_server->serverID=serverID; + syncdata_server->linker=linker; + if(!PX_VectorInitialize(mp,&syncdata_server->clients,sizeof(PX_SyncData_Server_Client),16)) return PX_FALSE; + return PX_TRUE; +} + + + +px_bool PX_SyncDataServerSetSyncData(PX_SyncData_Server *s,px_void *data,px_dword size) +{ + s->data=(px_byte *)data; + s->size=size; + + return PX_TRUE; +} + +px_bool PX_SyncDataServer_ReadBlock(PX_SyncData_Server *s,px_byte *data,px_int bufferSize,px_int *readsize) +{ + + if ((*readsize=PX_LinkerRead(s->linker,data,bufferSize))!=0) + { + if (*readsize>bufferSize) + { + return PX_FALSE; + } + + return PX_TRUE; + } + return PX_FALSE; +} + +px_bool PX_SyncDataServer_WriteBlock(PX_SyncData_Server *s,px_byte *data,px_int bufferSize) +{ + if (bufferSize>PX_SYNCDATA_DATAGRAM_MAX_SIZE) + { + return PX_FALSE; + } + + if (PX_LinkerWrite(s->linker,data,bufferSize)) + { + return PX_TRUE; + } + return PX_FALSE; +} + + + +px_bool PX_SyncDataServerUpdate(PX_SyncData_Server *s,px_int elapsed) +{ + px_int readSize,i; + PX_SyncData_Server_Client *pClient=PX_NULL; + PX_SyncData_Datagram R_datagram; + + + while (PX_SyncDataServer_ReadBlock(s,(px_byte *)&R_datagram,sizeof(R_datagram),&readSize)) + { + if (R_datagram.header.serverID==s->serverID) + { + if (R_datagram.header.opcode==PX_SYNCDATA_OPCODE_QUERY) + { + if ((px_int)R_datagram.request.blockIndex>=s->clients.size) + { + continue; + } + //searching data + for (i=0;iclients.size;i++) + { + pClient=PX_VECTORAT(PX_SyncData_Server_Client,&s->clients,i); + if (pClient->clientID==R_datagram.query.clientID) + { + PX_SyncData_QueryAck queryAck; + queryAck.opcode=PX_SYNCDATA_OPCODE_QUERYACK; + queryAck.serverID=s->serverID; + queryAck.reserved=0; + queryAck.size=s->size; + PX_SyncDataServer_WriteBlock(s,(px_byte *)&queryAck,sizeof(queryAck)); + break; + } + } + } + + if (R_datagram.header.opcode==PX_SYNCDATA_OPCODE_REQUEST) + { + for (i=0;iclients.size;i++) + { + int j=0; + pClient=PX_VECTORAT(PX_SyncData_Server_Client,&s->clients,i); + + if ((px_int)R_datagram.request.blockIndexsize)) + { + pClient->status=PX_SYNCDATA_CLIENT_STATUS_SYNCHRONIZING; + pClient->ProcessIndex=R_datagram.request.blockIndex; + } + else + { + pClient->status=PX_SYNCDATA_CLIENT_STATUS_SYNCHRONIZED; + pClient->ProcessIndex=R_datagram.request.blockIndex; + } + + } + } + + } + } + + for (i=0;iclients.size;i++) + { + pClient=PX_VECTORAT(PX_SyncData_Server_Client,&s->clients,i); + if (pClient->status!=PX_SYNCDATA_CLIENT_STATUS_SYNCHRONIZING) + { + continue; + } + if (pClient->ProcessIndexsize)) + { + if(pClient->send_elapsed>=PX_SYNCDATA_SENDING_DURATION) + { + px_int size; + PX_SyncData_RequestAck QuestAck; + pClient->send_elapsed=0; + QuestAck.blockIndex=pClient->ProcessIndex; + QuestAck.opcode=PX_SYNCDATA_OPCODE_REQUESTACK; + QuestAck.reserved=0; + QuestAck.serverID=s->serverID; + size=s->size-pClient->ProcessIndex*PX_SYNCDATA_BLOCK_SIZE; + size=(size>PX_SYNCDATA_BLOCK_SIZE?PX_SYNCDATA_BLOCK_SIZE:size); + PX_memcpy(QuestAck.data,s->data+pClient->ProcessIndex*PX_SYNCDATA_BLOCK_SIZE,size); + PX_SyncDataServer_WriteBlock(s,(px_byte *)&QuestAck,sizeof(QuestAck)); + pClient->ProcessIndex++; + } + else + { + pClient->send_elapsed+=elapsed; + } + } + } + return PX_TRUE; +} + +px_bool PX_SyncDataServerAddClient(PX_SyncData_Server *syncdata_server,px_dword clientID) +{ + PX_SyncData_Server_Client newClient; + PX_memset(&newClient,0,sizeof(newClient)); + newClient.ProcessIndex=0; + newClient.send_elapsed=0; + newClient.status=PX_SYNCDATA_CLIENT_STATUS_QUERY; + newClient.clientID=clientID; + return PX_VectorPushback(&syncdata_server->clients,&newClient); +} + +px_void PX_SyncDataServerFree(PX_SyncData_Server *syncdata_server) +{ + PX_VectorFree(&syncdata_server->clients); +} + +px_bool PX_SyncDataClientInit(PX_SyncData_Client *syncdata_client,px_memorypool *mp,px_dword serverID,px_dword clientID,PX_Linker *linker) +{ + PX_memset(syncdata_client,0,sizeof(PX_SyncData_Client)); + syncdata_client->clientID=clientID; + syncdata_client->mp=mp; + syncdata_client->linker=linker; + syncdata_client->serverID=serverID; + syncdata_client->status=PX_SYNCDATA_CLIENT_STATUS_QUERY; + return PX_TRUE; +} + + + +px_bool PX_SyncDataClientIsCompleted(PX_SyncData_Client *syncdata_client) +{ + return (syncdata_client->status==PX_SYNC_SERVERCLIENT_STATUS_END); +} + +px_bool PX_SyncDataClient_ReadBlock(PX_SyncData_Client *s,px_byte *data,px_int bufferSize,px_int *readsize) +{ + + if ((*readsize=PX_LinkerRead(s->linker,data,bufferSize))!=0) + { + return PX_TRUE; + } + return PX_FALSE; +} + +px_bool PX_SyncDataClient_WriteBlock(PX_SyncData_Client *s,px_byte *data,px_int bufferSize) +{ + if (bufferSize>PX_SYNCDATA_DATAGRAM_MAX_SIZE) + { + return PX_FALSE; + } + + if (PX_LinkerWrite(s->linker,data,bufferSize)) + { + return PX_TRUE; + } + return PX_FALSE; +} + +px_bool PX_SyncDataClientResetData(PX_SyncData_Client *syncdata_client,px_uint size) +{ + if (syncdata_client->data) + { + MP_Free(syncdata_client->mp,syncdata_client->data); + } + syncdata_client->data=(px_byte *)MP_Malloc(syncdata_client->mp,size); + syncdata_client->datasize=size; + syncdata_client->blockCount=PX_SyncDataCalculateBlockCount(size); + syncdata_client->acceptBlock=0; + + return syncdata_client->data!=PX_NULL; +} + +px_bool PX_SyncDataClientUpdate(PX_SyncData_Client *syncdata_client,px_int elapsed) +{ + px_int readSize; + PX_SyncData_Datagram R_datagram; + + syncdata_client->last_recv_elapsed+=elapsed; + + switch (syncdata_client->status) + { + case PX_SYNCDATA_CLIENT_STATUS_QUERY: + { + if (syncdata_client->query_elapsed>PX_SYNCDATA_QUERY_DURATION) + { + PX_SyncData_Query query; + syncdata_client->query_elapsed=0; + query.opcode=PX_SYNCDATA_OPCODE_QUERY; + query.reserved=0; + query.serverID=syncdata_client->serverID; + query.clientID=syncdata_client->clientID; + PX_SyncDataClient_WriteBlock(syncdata_client,(px_byte *)&query,sizeof(query)); + } + else + { + syncdata_client->query_elapsed+=elapsed; + } + + if (PX_SyncDataClient_ReadBlock(syncdata_client,(px_byte *)&R_datagram,sizeof(R_datagram),&readSize)) + { + if (R_datagram.header.serverID==syncdata_client->serverID) + { + if (R_datagram.header.opcode==PX_SYNCDATA_OPCODE_QUERYACK) + { + syncdata_client->last_recv_elapsed=0; + if (!PX_SyncDataClientResetData(syncdata_client,R_datagram.queryack.size)) + { + return PX_FALSE; + } + syncdata_client->status=PX_SYNCDATA_CLIENT_STATUS_SYNCHRONIZING; + } + } + + } + } + break; + case PX_SYNCDATA_CLIENT_STATUS_SYNCHRONIZING: + { + syncdata_client->last_recv_elapsed+=elapsed; + + if (PX_SyncDataClient_ReadBlock(syncdata_client,(px_byte *)&R_datagram,sizeof(R_datagram),&readSize)) + { + if (R_datagram.requestAck.serverID==syncdata_client->serverID&&R_datagram.header.opcode==PX_SYNCDATA_OPCODE_REQUESTACK) + { + px_int size; + px_int index=R_datagram.requestAck.blockIndex; + if (index==syncdata_client->acceptBlock) + { + syncdata_client->last_recv_elapsed=0; + syncdata_client->query_elapsed=0; + size=syncdata_client->datasize-index*PX_SYNCDATA_BLOCK_SIZE; + size=(size>PX_SYNCDATA_BLOCK_SIZE?PX_SYNCDATA_BLOCK_SIZE:size); + PX_memcpy(syncdata_client->data+index*PX_SYNCDATA_BLOCK_SIZE,R_datagram.requestAck.data,size); + syncdata_client->acceptBlock++; + } + else + { + syncdata_client->query_elapsed=PX_SYNCDATA_REQUEST_DURATION; + } + + } + } + + if (syncdata_client->acceptBlockblockCount) + { + if (syncdata_client->query_elapsed>=PX_SYNCDATA_REQUEST_DURATION) + { + px_int o=0; + PX_SyncData_Request request; + syncdata_client->query_elapsed=0; + request.blockIndex=syncdata_client->acceptBlock; + request.serverID=syncdata_client->serverID; + request.opcode=PX_SYNCDATA_OPCODE_REQUEST; + request.reserved=0; + PX_SyncDataClient_WriteBlock(syncdata_client,(px_byte *)&request,sizeof(request)); + } + else + { + syncdata_client->query_elapsed+=elapsed; + } + } + else + { + syncdata_client->status=PX_SYNCDATA_CLIENT_STATUS_SYNCHRONIZED; + + } + } + break; + case PX_SYNCDATA_CLIENT_STATUS_SYNCHRONIZED: + break; + case PX_SYNCDATA_STATUS_ERROR: + break; + } + return PX_TRUE; +} + +px_void PX_SyncDataClientFree(PX_SyncData_Client *syncdata_client) +{ + if (syncdata_client->data) + { + MP_Free(syncdata_client->mp,syncdata_client->data); + syncdata_client->data=PX_NULL; + } +} + + + + diff --git a/lib/PainterEngine/kernel/PX_Sync.h b/lib/PainterEngine/kernel/PX_Sync.h new file mode 100644 index 0000000000000000000000000000000000000000..b04701873275df7b560af6188954d6643c5a120f --- /dev/null +++ b/lib/PainterEngine/kernel/PX_Sync.h @@ -0,0 +1,313 @@ +#ifndef PX_SYNC_H +#define PX_SYNC_H + +#include "../core/PX_Core.h" + + +#define PX_SYNC_SERVER_ID 0 +#define PX_SYNC_SERVER_SEND_DURATION 3 +#define PX_SYNC_SERVER_SEND_TIMES 3 + +#define PX_SYNC_CLIENT_SEND_TIMES 3 +#define PX_SYNC_DEFAULT_INSTR_ONCE_MAX_SIZE 256 +#define PX_SYNC_UNIQUE_ARRAY_SIZE 64 +#define PX_SYNC_CACHESIZE 1420 +#define PX_SYNC_INSTRS_SIZE 128*1024 +#define PX_SYNC_INSTRS_BYTES_SIZE 1024*1024 +#define PX_SYNC_CLIENT_SEND_DURATION 3 + +typedef enum +{ + PX_SYNC_IO_TYPE_CONNECT, + PX_SYNC_IO_TYPE_CONNECTACK, + PX_SYNC_IO_TYPE_QUERYSTATE, + PX_SYNC_IO_TYPE_QUERYSTATEACK, + PX_SYNC_IO_TYPE_REQUEST, + PX_SYNC_IO_TYPE_OPCODE, +}PX_SYNC_IO_TYPE; + +typedef enum +{ + PX_SYNC_SERVER_STATUS_CONNECT, + PX_SYNC_SERVER_STATUS_PROCESSING, + PX_SYNC_SERVER_STATUS_END, +}PX_SYNC_SERVER_STATUS; + +typedef enum +{ + PX_SYNC_SERVERCLIENT_STATUS_CONNECT, + PX_SYNC_SERVERCLIENT_STATUS_PROCESSING, + PX_SYNC_SERVERCLIENT_STATUS_END, +}PX_SYNC_SERVERCLIENT_STATUS; + +typedef enum +{ + PX_SYNC_CLIENT_STATUS_CONNECTING, + PX_SYNC_CLIENT_STATUS_WAITING, + PX_SYNC_CLIENT_STATUS_PROCESSING, + PX_SYNC_CLIENT_STATUS_END, +}PX_SYNC_CLIENT_STATUS; + + +struct _PX_SyncFrame_Server; +struct _PX_SyncFrame_Client; + + +typedef struct +{ + px_dword c_id; + px_dword size; + px_byte data[1]; +}PX_SyncFrame_InstrStream_Stamp; + + +typedef struct +{ + px_dword oft; + px_dword size; +}PX_SyncFrame_InstrStream_StampIndex; + +typedef struct +{ + px_dword client_id; + px_dword server_id; + px_dword c_id; + px_dword timeIndexOffset; + px_dword timeStreamOffset; + px_dword uniqueQueuewIndex; + px_dword acceptuniqueQueue[PX_SYNC_UNIQUE_ARRAY_SIZE]; + px_dword unique; + px_dword sendDurationTick; + px_dword sendTimes; + px_dword onceRecvSize; + px_dword lastsendtime; + px_dword lastInstrelapsed; + PX_SYNC_SERVERCLIENT_STATUS status; + px_int send_cache_instr_size; + px_byte send_cache_instr_buffer[PX_SYNC_CACHESIZE]; +}PX_SyncFrame_Server_Clients; + + +typedef struct +{ + px_dword verify_id; + px_dword type; + px_dword unique; + union + { + struct + { + px_dword param1; + px_dword param2; + }; + px_byte data[1]; + }; +}PX_Sync_IO_Packet; + + +typedef struct _PX_SyncFrame_Server +{ + px_memorypool *mp; + px_dword time; + px_dword updateDuration; + px_dword unique; + px_dword version; + px_memory stampsInstrStream; + px_vector stampsIndexTable;//PX_Sync_Server_StampIndex * + px_vector clients;//PX_Sync_Server_Clients * + PX_SYNC_SERVER_STATUS status; + PX_Linker *linker; + px_int recv_cache_size; + px_uint instr_once_maxsize; + px_byte recv_cache_buffer[PX_SYNC_CACHESIZE]; + px_byte send_cache_buffer[PX_SYNC_CACHESIZE]; +}PX_SyncFrame_Server; + + + + +typedef struct _PX_SyncFrame_Client +{ + px_memorypool *mp; + px_dword c_id; + px_dword client_id; + px_dword server_verify_id; + px_int connectCount; + px_int connectSumCount; + px_dword version; + px_dword time; + px_dword delayms; + px_dword sendDurationTick; + px_dword updateDuration; + px_dword uniqueQueuewIndex; + px_dword acceptuniqueQueue[PX_SYNC_UNIQUE_ARRAY_SIZE]; + px_dword unique; + px_memory stampsInstrStream;//instrments + px_vector stampsIndexTable;//PX_Sync_Server_StampIndex * + px_memory Input_InstrStream; + PX_Linker *linker; + PX_SYNC_CLIENT_STATUS status; + px_int send_repeat_times; + px_byte send_cache_buffer[PX_SYNC_CACHESIZE]; + px_int recv_cache_buffer_size; + px_byte recv_cache_buffer[PX_SYNC_CACHESIZE]; + px_int send_cache_Instr_size; + px_byte send_cache_Instr_buffer[PX_SYNC_CACHESIZE]; +}PX_SyncFrame_Client; + + + + +px_bool PX_SyncFrameServerInit(PX_SyncFrame_Server *sync,px_memorypool *mp,px_dword updateDuration,PX_Linker *linker); +px_void PX_SyncFrameServerSetVersion(PX_SyncFrame_Server *sync,px_dword version); +px_bool PX_SyncFrameServerAddClient(PX_SyncFrame_Server *sync,px_dword server_verify_id,px_dword client_id,px_dword c_id); +px_void PX_SyncFrameServerSetInstrOnceMaxSize(PX_SyncFrame_Server *sync,px_int maxsize); +px_void PX_SyncFrameServerRun(PX_SyncFrame_Server *sync); +px_void PX_SyncFrameServerStop(PX_SyncFrame_Server *sync); +px_void PX_SyncFrameServerUpdate(PX_SyncFrame_Server *sync,px_dword elapsed); +px_void PX_SyncFrameServerFree(PX_SyncFrame_Server *sync); +px_int PX_SyncFrameServerGetReadyFrameCount(PX_SyncFrame_Server *sync); +px_uint32 PX_SyncFrameServerSum32(PX_SyncFrame_Server *sync); + + +px_bool PX_SyncFrameClientInit(PX_SyncFrame_Client *client,px_memorypool *mp,px_dword updateDuration,px_dword server_verify_id,px_dword client_id,PX_Linker *linker); +px_void PX_SyncFrameClientAddInstr(PX_SyncFrame_Client *client,px_void *instr,px_int size); +px_void PX_SyncFrameClientSetVersion(PX_SyncFrame_Client *sync,px_dword version); +px_void PX_SyncFrameClientUpdate(PX_SyncFrame_Client *sync,px_dword elapsed); +px_int PX_SyncFrameClientGetReadyFrameCount(PX_SyncFrame_Client *sync); +px_void PX_SyncFrameClientFree(PX_SyncFrame_Client *sync); +px_uint32 PX_SyncFrameClientSum32(PX_SyncFrame_Client *sync); + + +#define PX_SYNCDATA_DATAGRAM_MAX_SIZE 1460 +#define PX_SYNCDATA_BLOCK_SIZE 1408 +#define PX_SYNCDATA_SENDING_DURATION 20 +#define PX_SYNCDATA_QUERY_DURATION 500 +#define PX_SYNCDATA_REQUEST_DURATION 100 + +struct _PX_SyncData_Server; +struct _PX_SyncData_Client; + + +typedef struct +{ + px_int blockIndex; +}PX_SyncDataBlock; + +typedef enum +{ + PX_SYNCDATA_CLIENT_STATUS_QUERY, + PX_SYNCDATA_CLIENT_STATUS_SYNCHRONIZING, + PX_SYNCDATA_CLIENT_STATUS_SYNCHRONIZED, + PX_SYNCDATA_STATUS_ERROR, +}PX_SYNCDATA_STATUS; + +typedef px_bool (*PX_SyncData_Encode)(px_byte *data,px_int size); +typedef px_bool (*PX_SyncData_Decode)(px_byte *data,px_int size); + +typedef struct _PX_SyncData_Server_Client +{ + px_dword clientID; + PX_SYNCDATA_STATUS status; + px_int ProcessIndex; + px_dword send_elapsed; +}PX_SyncData_Server_Client; + +typedef struct _PX_SyncData_Server +{ + PX_Linker *linker; + px_dword serverID; + px_byte *data; + px_dword size; + + px_void *user; + px_vector clients;// vector for PX_SyncData_Server_Client +}PX_SyncData_Server; + +typedef struct _PX_SyncData_Client +{ + PX_Linker *linker; + + px_memorypool *mp; + px_dword clientID,serverID; + + px_byte *data; + px_dword datasize; + + px_int blockCount; + px_int acceptBlock; + + px_void *user; + + PX_SYNCDATA_STATUS status; + + px_dword query_elapsed; + px_dword last_recv_elapsed; +}PX_SyncData_Client; + +#define PX_SYNCDATA_OPCODE_QUERY 0x680 +#define PX_SYNCDATA_OPCODE_QUERYACK 0x6802 +#define PX_SYNCDATA_OPCODE_REQUEST 0x6803 +#define PX_SYNCDATA_OPCODE_REQUESTACK 0x6804 + + +typedef struct +{ + px_dword opcode; + px_dword serverID; +}PX_SyncData_DatagramHeader; + +typedef struct +{ + px_dword opcode; + px_dword serverID; + px_dword clientID; + px_dword reserved; +}PX_SyncData_Query; + +typedef struct +{ + px_dword opcode; + px_dword serverID; + px_dword size; + px_dword reserved; +}PX_SyncData_QueryAck; + +typedef struct +{ + px_dword opcode; + px_dword serverID; + px_dword reserved; + px_dword blockIndex; +}PX_SyncData_Request; + +typedef struct +{ + px_dword opcode; + px_dword serverID; + px_dword reserved; + px_dword blockIndex; + px_byte data[PX_SYNCDATA_BLOCK_SIZE]; +}PX_SyncData_RequestAck; + +typedef union +{ + PX_SyncData_DatagramHeader header; + PX_SyncData_Query query; + PX_SyncData_QueryAck queryack; + PX_SyncData_Request request; + PX_SyncData_RequestAck requestAck; +}PX_SyncData_Datagram; + +px_bool PX_SyncDataServerInit(PX_SyncData_Server *syncdata_server,px_memorypool *mp,px_dword serverID,PX_Linker *linker); +px_bool PX_SyncDataServerAddClient(PX_SyncData_Server *syncdata_server,px_dword clientID); +px_bool PX_SyncDataServerSetSyncData(PX_SyncData_Server *s,px_void *data,px_dword size); +px_bool PX_SyncDataServerUpdate(PX_SyncData_Server *syncdata_server,px_int elapsed); +px_void PX_SyncDataServerFree(PX_SyncData_Server *syncdata_server); + + +px_bool PX_SyncDataClientInit(PX_SyncData_Client *syncdata_client,px_memorypool *mp,px_dword serverID,px_dword clientID,PX_Linker *linker); +px_bool PX_SyncDataClientIsCompleted(PX_SyncData_Client *syncdata_client); +px_bool PX_SyncDataClientUpdate(PX_SyncData_Client *syncdata_client,px_int elapsed); +px_void PX_SyncDataClientFree(PX_SyncData_Client *syncdata_client); +#endif diff --git a/lib/PainterEngine/kernel/PX_UI.c b/lib/PainterEngine/kernel/PX_UI.c new file mode 100644 index 0000000000000000000000000000000000000000..c944f55fb0ec26368f2fed563f9d897d1c650d50 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_UI.c @@ -0,0 +1,1049 @@ +#include "PX_UI.h" + +typedef enum +{ + PX_UI_HALIGN_LEFT, + PX_UI_HALIGN_MID, + PX_UI_HALIGN_RIGHT, +}PX_UI_HALIGN; + +typedef enum +{ + PX_UI_VALIGN_TOP, + PX_UI_VALIGN_MID, + PX_UI_VALIGN_BOTTOM, +}PX_UI_VALIGN; + +typedef struct +{ + px_char id[32]; + px_float x,y,z,height,width,length; + PX_UI_HALIGN halign; + PX_UI_VALIGN valign; +}PX_UiBaseInfo; + +PX_UiBaseInfo PX_UIGetBaseInfo(PX_Json_Value *json_value,px_int width,px_int height) +{ + PX_UiBaseInfo baseInfo; + PX_Json_Value *pSubValue=PX_NULL; + PX_memset(&baseInfo,0,sizeof(PX_UiBaseInfo)); + pSubValue=PX_JsonGetObjectValue(json_value,"x"); + if (pSubValue&&pSubValue->type==PX_JSON_VALUE_TYPE_NUMBER) + { + baseInfo.x=(px_float)pSubValue->_number; + } + pSubValue=PX_JsonGetObjectValue(json_value,"y"); + if (pSubValue&&pSubValue->type==PX_JSON_VALUE_TYPE_NUMBER) + { + baseInfo.y=(px_float)pSubValue->_number; + } + pSubValue=PX_JsonGetObjectValue(json_value,"z"); + if (pSubValue&&pSubValue->type==PX_JSON_VALUE_TYPE_NUMBER) + { + baseInfo.z=(px_float)pSubValue->_number; + } + pSubValue=PX_JsonGetObjectValue(json_value,"width"); + if (pSubValue&&pSubValue->type==PX_JSON_VALUE_TYPE_NUMBER) + { + baseInfo.width=(px_float)pSubValue->_number; + } + pSubValue=PX_JsonGetObjectValue(json_value,"height"); + if (pSubValue&&pSubValue->type==PX_JSON_VALUE_TYPE_NUMBER) + { + baseInfo.height=(px_float)pSubValue->_number; + } + pSubValue=PX_JsonGetObjectValue(json_value,"length"); + if (pSubValue&&pSubValue->type==PX_JSON_VALUE_TYPE_NUMBER) + { + baseInfo.length=(px_float)pSubValue->_number; + } + pSubValue=PX_JsonGetObjectValue(json_value,"id"); + if (pSubValue&&pSubValue->type==PX_JSON_VALUE_TYPE_STRING) + { + PX_strcpy(baseInfo.id,pSubValue->_string.buffer,sizeof(baseInfo.id)); + } + pSubValue=PX_JsonGetObjectValue(json_value,"halign"); + if (pSubValue&&pSubValue->type==PX_JSON_VALUE_TYPE_STRING) + { + if(PX_strequ(pSubValue->_string.buffer,"left")) + { + // + } + if(PX_strequ(pSubValue->_string.buffer,"mid")) + { + baseInfo.x+=width/2; + } + if(PX_strequ(pSubValue->_string.buffer,"right")) + { + baseInfo.x+=width; + } + } + + pSubValue=PX_JsonGetObjectValue(json_value,"valign"); + if (pSubValue&&pSubValue->type==PX_JSON_VALUE_TYPE_STRING) + { + if(PX_strequ(pSubValue->_string.buffer,"top")) + { + // + } + if(PX_strequ(pSubValue->_string.buffer,"mid")) + { + baseInfo.y+=height/2; + } + if(PX_strequ(pSubValue->_string.buffer,"bottom")) + { + baseInfo.y+=height; + } + } + + return baseInfo; +} + +px_bool PX_UI_GetColor(PX_Json_Value *json_value,const px_char name[],px_color *color) +{ + PX_Json_Value *pSubValue=PX_NULL; + pSubValue=PX_JsonGetObjectValue(json_value,name); + if (pSubValue) + { + if (pSubValue->type==PX_JSON_VALUE_TYPE_ARRAY) + { + PX_Json_Value *parrayValue; + parrayValue=PX_JsonGetArrayValue(pSubValue,0); + if (parrayValue&&parrayValue->type==PX_JSON_VALUE_TYPE_NUMBER) + { + color->_argb.a=(px_byte)parrayValue->_number; + } + parrayValue=PX_JsonGetArrayValue(pSubValue,1); + if (parrayValue&&parrayValue->type==PX_JSON_VALUE_TYPE_NUMBER) + { + color->_argb.r=(px_byte)parrayValue->_number; + } + parrayValue=PX_JsonGetArrayValue(pSubValue,2); + if (parrayValue&&parrayValue->type==PX_JSON_VALUE_TYPE_NUMBER) + { + color->_argb.g=(px_byte)parrayValue->_number; + } + parrayValue=PX_JsonGetArrayValue(pSubValue,3); + if (parrayValue&&parrayValue->type==PX_JSON_VALUE_TYPE_NUMBER) + { + color->_argb.b=(px_byte)parrayValue->_number; + } + return PX_TRUE; + } + } + return PX_FALSE; +} +px_bool PX_UI_GetBool(PX_Json_Value *json_value,const px_char name[],px_bool *b) +{ + PX_Json_Value *pSubValue=PX_NULL; + pSubValue=PX_JsonGetObjectValue(json_value,name); + if (pSubValue) + { + if (pSubValue->type==PX_JSON_VALUE_TYPE_BOOLEAN) + { + *b=pSubValue->_boolean; + return PX_TRUE; + } + } + return PX_FALSE; +} +px_bool PX_UI_GetNumber(PX_Json_Value *json_value,const px_char name[],px_double *number) +{ + PX_Json_Value *pSubValue=PX_NULL; + pSubValue=PX_JsonGetObjectValue(json_value,name); + if (pSubValue) + { + if (pSubValue->type==PX_JSON_VALUE_TYPE_NUMBER) + { + *number=pSubValue->_number; + return PX_TRUE; + } + } + return PX_FALSE; +} +px_bool PX_UI_GetString(PX_Json_Value *json_value,const px_char name[],px_char str[],px_int size) +{ + PX_Json_Value *pSubValue=PX_NULL; + pSubValue=PX_JsonGetObjectValue(json_value,name); + if (pSubValue) + { + if (pSubValue->type==PX_JSON_VALUE_TYPE_STRING) + { + PX_strcpy(str,pSubValue->_string.buffer,size); + return PX_TRUE; + } + } + return PX_FALSE; +} + +PX_Object * PX_UI_CreateNode(PX_UI *ui,PX_Object *parent,PX_Json_Value *json_value,px_int width,px_int height) +{ + return PX_ObjectCreate(ui->ui_mp,parent,0,0,0,0,0,0); +} + +PX_Object * PX_UI_CreateLabel(PX_UI *ui,PX_Object *parent,PX_Json_Value *json_value,px_int width,px_int height) +{ + PX_Object *pObject; + PX_UiBaseInfo baseInfo; + const px_char *text=""; + px_char style[8]; + px_bool border; + PX_Json_Value *pSubValue=PX_NULL; + px_color fontColor,backgroundColor,Color; + pSubValue=PX_JsonGetObjectValue(json_value,"text"); + if (pSubValue&&pSubValue->type==PX_JSON_VALUE_TYPE_STRING) + { + text=pSubValue->_string.buffer; + } + + baseInfo=PX_UIGetBaseInfo(json_value,width,height); + fontColor=PX_COLOR(255,0,0,0); + backgroundColor=PX_COLOR(0,0,0,0); + + PX_UI_GetColor(json_value,"fontcolor",&fontColor); + PX_UI_GetColor(json_value,"backgroundcolor",&backgroundColor); + pObject=PX_Object_LabelCreate(ui->ui_mp,parent,(px_int)baseInfo.x,(px_int)baseInfo.y,(px_int)baseInfo.width,(px_int)baseInfo.height,text,ui->fontmodule,fontColor); + PX_Object_LabelSetBackgroundColor(pObject,backgroundColor); + + if (PX_UI_GetColor(json_value,"bordercolor",&Color)) + { + PX_Object_LabelSetBorderColor(pObject,Color); + } + + if (PX_UI_GetString(json_value,"style",style,sizeof(style))) + { + if (PX_strequ(style,"round")) + { + PX_Object_LabelSetStyle(pObject,PX_OBJECT_LABEL_STYLE_ROUNDRECT); + } + } + + if (PX_UI_GetBool(json_value,"border",&border)) + { + PX_Object_LabelSetBorder(pObject,border); + } + + pSubValue=PX_JsonGetObjectValue(json_value,"align"); + if (pSubValue&&pSubValue->type==PX_JSON_VALUE_TYPE_STRING) + { + if (PX_strequ(pSubValue->_string.buffer,"lefttop")) + { + PX_Object_LabelSetAlign(pObject,PX_ALIGN_LEFTTOP); + } + else if (PX_strequ(pSubValue->_string.buffer,"leftmid")) + { + PX_Object_LabelSetAlign(pObject,PX_ALIGN_LEFTMID); + } + else if (PX_strequ(pSubValue->_string.buffer,"leftbottom")) + { + PX_Object_LabelSetAlign(pObject,PX_ALIGN_LEFTBOTTOM); + } + else if (PX_strequ(pSubValue->_string.buffer,"midtop")) + { + PX_Object_LabelSetAlign(pObject,PX_ALIGN_MIDTOP); + } + else if (PX_strequ(pSubValue->_string.buffer,"center")) + { + PX_Object_LabelSetAlign(pObject,PX_ALIGN_CENTER); + } + else if (PX_strequ(pSubValue->_string.buffer,"midbottom")) + { + PX_Object_LabelSetAlign(pObject,PX_ALIGN_MIDBOTTOM); + } + else if (PX_strequ(pSubValue->_string.buffer,"righttop")) + { + PX_Object_LabelSetAlign(pObject,PX_ALIGN_RIGHTTOP); + } + else if (PX_strequ(pSubValue->_string.buffer,"rightmid")) + { + PX_Object_LabelSetAlign(pObject,PX_ALIGN_RIGHTMID); + } + else if (PX_strequ(pSubValue->_string.buffer,"rightbottom")) + { + PX_Object_LabelSetAlign(pObject,PX_ALIGN_RIGHTBOTTOM); + } + } + + return pObject; +} +PX_Object * PX_UI_CreateProcessbar(PX_UI *ui,PX_Object *parent,PX_Json_Value *json_value,px_int width,px_int height) +{ + PX_Object *pObject; + PX_UiBaseInfo baseInfo; + px_int max=100; + PX_Json_Value *pSubValue=PX_NULL; + px_color Color,backgroundColor; + + baseInfo=PX_UIGetBaseInfo(json_value,width,height); + Color=PX_COLOR(255,0,0,0); + backgroundColor=PX_COLOR(0,0,0,0); + + pObject=PX_Object_ProcessBarCreate(ui->ui_mp,parent,(px_int)baseInfo.x,(px_int)baseInfo.y,(px_int)baseInfo.width,(px_int)baseInfo.height); + + pSubValue=PX_JsonGetObjectValue(json_value,"max"); + + if (pSubValue&&pSubValue->type==PX_JSON_VALUE_TYPE_NUMBER) + { + max=(px_int)pSubValue->_number; + PX_Object_ProcessBarSetMax(pObject,max); + } + + if(PX_UI_GetColor(json_value,"bordercolor",&Color)) + { + PX_Object_ProcessBarSetColor(pObject,Color); + } + + if(PX_UI_GetColor(json_value,"backgroundcolor",&backgroundColor)) + { + PX_Object_ProcessBarSetBackgroundColor(pObject,backgroundColor); + } + + + return pObject; +} +PX_Object * PX_UI_CreateImage(PX_UI *ui,PX_Object *parent,PX_Json_Value *json_value,px_int width,px_int height) +{ + PX_Object *pObject; + PX_UiBaseInfo baseInfo; + px_int max=100; + PX_Json_Value *pSubValue=PX_NULL; + + baseInfo=PX_UIGetBaseInfo(json_value,width,height); + + pObject=PX_Object_ImageCreate(ui->ui_mp,parent,(px_int)baseInfo.x,(px_int)baseInfo.y,(px_int)baseInfo.width,(px_int)baseInfo.height,PX_NULL); + + return pObject; +} +PX_Object * PX_UI_CreateSliderbar(PX_UI *ui,PX_Object *parent,PX_Json_Value *json_value,px_int width,px_int height) +{ + PX_Object *pObject; + PX_UiBaseInfo baseInfo; + px_int max=100; + px_int min=0; + PX_Json_Value *pSubValue=PX_NULL; + px_color Color,backgroundColor; + PX_OBJECT_SLIDERBAR_TYPE type=PX_OBJECT_SLIDERBAR_TYPE_HORIZONTAL; + PX_OBJECT_SLIDERBAR_STYLE style=PX_OBJECT_SLIDERBAR_STYLE_BOX; + + baseInfo=PX_UIGetBaseInfo(json_value,width,height); + + pSubValue=PX_JsonGetObjectValue(json_value,"max"); + if (pSubValue&&pSubValue->type==PX_JSON_VALUE_TYPE_NUMBER) + { + max=(px_int)pSubValue->_number; + } + + pSubValue=PX_JsonGetObjectValue(json_value,"min"); + if (pSubValue&&pSubValue->type==PX_JSON_VALUE_TYPE_NUMBER) + { + min=(px_int)pSubValue->_number; + } + + pSubValue=PX_JsonGetObjectValue(json_value,"type"); + if (pSubValue&&pSubValue->type==PX_JSON_VALUE_TYPE_STRING&&PX_strequ(pSubValue->_string.buffer,"vertical")) + { + type=PX_OBJECT_SLIDERBAR_TYPE_VERTICAL; + } + + pSubValue=PX_JsonGetObjectValue(json_value,"style"); + if (pSubValue&&pSubValue->type==PX_JSON_VALUE_TYPE_STRING&&PX_strequ(pSubValue->_string.buffer,"liner")) + { + style=PX_OBJECT_SLIDERBAR_STYLE_LINER; + } + + pObject=PX_Object_SliderBarCreate(ui->ui_mp,parent,(px_int)baseInfo.x,(px_int)baseInfo.y,(px_int)baseInfo.width,(px_int)baseInfo.height,type,style); + if (pObject) + { + PX_Object_SliderBarSetRange(pObject,min,max); + + if(PX_UI_GetColor(json_value,"color",&Color)) + { + PX_Object_SliderBarSetColor(pObject,Color); + } + + if(PX_UI_GetColor(json_value,"backgroundcolor",&backgroundColor)) + { + PX_Object_SliderBarSetBackgroundColor(pObject,backgroundColor); + } + + pSubValue=PX_JsonGetObjectValue(json_value,"buttonlength"); + if (pSubValue&&pSubValue->type==PX_JSON_VALUE_TYPE_NUMBER) + { + PX_Object_SliderBarSetSliderButtonLength(pObject,(px_int)pSubValue->_number); + } + } + + return pObject; +} +PX_Object * PX_UI_CreateButton(PX_UI *ui,PX_Object *parent,PX_Json_Value *json_value,px_int width,px_int height) +{ + PX_Object *pObject; + PX_UiBaseInfo baseInfo; + const px_char *text=""; + px_char style[32]; + px_bool border; + PX_Json_Value *pSubValue=PX_NULL; + px_color fontColor,Color; + pSubValue=PX_JsonGetObjectValue(json_value,"text"); + if (pSubValue&&pSubValue->type==PX_JSON_VALUE_TYPE_STRING) + { + text=pSubValue->_string.buffer; + } + + baseInfo=PX_UIGetBaseInfo(json_value,width,height); + fontColor=PX_OBJECT_UI_DEFAULT_FONTCOLOR; + + PX_UI_GetColor(json_value,"fontcolor",&fontColor); + + pObject=PX_Object_PushButtonCreate(ui->ui_mp,parent,(px_int)baseInfo.x,(px_int)baseInfo.y,(px_int)baseInfo.width,(px_int)baseInfo.height,text,ui->fontmodule); + + if (PX_UI_GetColor(json_value,"backgroundcolor",&Color)) + { + PX_Object_PushButtonSetBackgroundColor(pObject,Color); + } + + if (PX_UI_GetColor(json_value,"cursorcolor",&Color)) + { + PX_Object_PushButtonSetCursorColor(pObject,Color); + } + + if (PX_UI_GetColor(json_value,"pushcolor",&Color)) + { + PX_Object_PushButtonSetPushColor(pObject,Color); + } + + if (PX_UI_GetColor(json_value,"bordercolor",&Color)) + { + PX_Object_PushButtonSetBorderColor(pObject,Color); + } + + if (PX_UI_GetString(json_value,"style",style,sizeof(style))) + { + if (PX_strequ(style,"round")) + { + PX_Object_PushButtonSetStyle(pObject,PX_OBJECT_PUSHBUTTON_STYLE_ROUNDRECT); + } + } + + if (PX_UI_GetBool(json_value,"border",&border)) + { + PX_Object_PushButtonSetBorder(pObject,border); + } + return pObject; +} +PX_Object * PX_UI_CreateEdit(PX_UI *ui,PX_Object *parent,PX_Json_Value *json_value,px_int width,px_int height) +{ + PX_Object *pObject; + PX_UiBaseInfo baseInfo; + const px_char *text=""; + px_bool b; + PX_Json_Value *pSubValue=PX_NULL; + px_color Color; + px_char style[8]; + px_char str[128]; + px_double number; + + baseInfo=PX_UIGetBaseInfo(json_value,width,height); + + pObject=PX_Object_EditCreate(ui->ui_mp,parent,(px_int)baseInfo.x,(px_int)baseInfo.y,(px_int)baseInfo.width,(px_int)baseInfo.height,ui->fontmodule); + + if (PX_UI_GetColor(json_value,"fontcolor",&Color)) + { + PX_Object_EditSetTextColor(pObject,Color); + } + + if (PX_UI_GetColor(json_value,"backgroundcolor",&Color)) + { + PX_Object_EditSetBackgroundColor(pObject,Color); + } + + if (PX_UI_GetColor(json_value,"cursorcolor",&Color)) + { + PX_Object_EditSetCursorColor(pObject,Color); + } + + if (PX_UI_GetColor(json_value,"bordercolor",&Color)) + { + PX_Object_EditSetBorderColor(pObject,Color); + } + + if (PX_UI_GetBool(json_value,"border",&b)) + { + PX_Object_EditSetBorder(pObject,b); + } + + if (PX_UI_GetBool(json_value,"passwordstyle",&b)) + { + PX_Object_EditSetPasswordStyle(pObject,b); + } + + if (PX_UI_GetBool(json_value,"autonewline",&b)) + { + PX_Object_EditAutoNewLine(pObject,b,16); + } + + if (PX_UI_GetString(json_value,"limit",str,sizeof(str))) + { + PX_Object_EditSetLimit(pObject,str); + } + + if (PX_UI_GetNumber(json_value,"maxlength",&number)) + { + PX_Object_EditSetMaxTextLength(pObject,(px_int)number); + } + + if (PX_UI_GetString(json_value,"text",str,sizeof(str))) + { + PX_Object_EditSetText(pObject,str); + } + + if (PX_UI_GetString(json_value,"style",style,sizeof(style))) + { + if (PX_strequ(style,"round")) + { + PX_Object_EditSetStyle(pObject,PX_OBJECT_EDIT_STYLE_ROUNDRECT); + } + } + + return pObject; +} +PX_Object * PX_UI_CreateScrollArea(PX_UI *ui,PX_Object *parent,PX_Json_Value *json_value,px_int width,px_int height) +{ + PX_Object *pObject; + PX_UiBaseInfo baseInfo; + px_bool b; + px_color Color; + + + baseInfo=PX_UIGetBaseInfo(json_value,width,height); + + pObject=PX_Object_ScrollAreaCreate(ui->ui_mp,parent,(px_int)baseInfo.x,(px_int)baseInfo.y,(px_int)baseInfo.width,(px_int)baseInfo.height); + + if (PX_UI_GetColor(json_value,"bordercolor",&Color)) + { + PX_Object_EditSetBorderColor(pObject,Color); + } + + if (PX_UI_GetBool(json_value,"border",&b)) + { + PX_Object_EditSetBorder(pObject,b); + } + return pObject; +} +PX_Object * PX_UI_CreateAutoText(PX_UI *ui,PX_Object *parent,PX_Json_Value *json_value,px_int width,px_int height) +{ + PX_Object *pObject; + PX_UiBaseInfo baseInfo; + const px_char *text=""; + PX_Json_Value *pSubValue=PX_NULL; + px_color Color; + + baseInfo=PX_UIGetBaseInfo(json_value,width,height); + + pObject=PX_Object_AutoTextCreate(ui->ui_mp,parent,(px_int)baseInfo.x,(px_int)baseInfo.y,(px_int)baseInfo.width,ui->fontmodule); + + pSubValue=PX_JsonGetObjectValue(json_value,"text"); + if (pSubValue&&pSubValue->type==PX_JSON_VALUE_TYPE_STRING) + { + text=pSubValue->_string.buffer; + PX_Object_AutoTextSetText(pObject,text); + } + + if (PX_UI_GetColor(json_value,"fontcolor",&Color)) + { + PX_Object_AutoTextSetTextColor(pObject,Color); + } + + return pObject; +} +PX_Object * PX_UI_CreateCursorButton(PX_UI *ui,PX_Object *parent,PX_Json_Value *json_value,px_int width,px_int height) +{ + PX_Object *pObject; + PX_UiBaseInfo baseInfo; + const px_char *text=""; + px_char style[32]; + px_bool border; + PX_Json_Value *pSubValue=PX_NULL; + px_color fontColor,Color; + pSubValue=PX_JsonGetObjectValue(json_value,"text"); + if (pSubValue&&pSubValue->type==PX_JSON_VALUE_TYPE_STRING) + { + text=pSubValue->_string.buffer; + } + + baseInfo=PX_UIGetBaseInfo(json_value,width,height); + fontColor=PX_COLOR(255,0,0,0); + + PX_UI_GetColor(json_value,"fontcolor",&fontColor); + + pObject=PX_Object_CursorButtonCreate(ui->ui_mp,parent,(px_int)baseInfo.x,(px_int)baseInfo.y,(px_int)baseInfo.width,(px_int)baseInfo.height,text,ui->fontmodule,fontColor); + + if (PX_UI_GetColor(json_value,"backgroundcolor",&Color)) + { + PX_Object_PushButtonSetBackgroundColor(PX_Object_GetCursorButton(pObject)->pushbutton,Color); + } + + if (PX_UI_GetColor(json_value,"cursorcolor",&Color)) + { + PX_Object_PushButtonSetCursorColor(PX_Object_GetCursorButton(pObject)->pushbutton,Color); + } + + if (PX_UI_GetColor(json_value,"pushcolor",&Color)) + { + PX_Object_PushButtonSetPushColor(PX_Object_GetCursorButton(pObject)->pushbutton,Color); + } + + if (PX_UI_GetColor(json_value,"bordercolor",&Color)) + { + PX_Object_PushButtonSetBorderColor(PX_Object_GetCursorButton(pObject)->pushbutton,Color); + } + + if (PX_UI_GetString(json_value,"style",style,sizeof(style))) + { + if (PX_strequ(style,"round")) + { + PX_Object_PushButtonSetStyle(PX_Object_GetCursorButton(pObject)->pushbutton,PX_OBJECT_PUSHBUTTON_STYLE_ROUNDRECT); + } + } + + if (PX_UI_GetBool(json_value,"border",&border)) + { + PX_Object_PushButtonSetBorder(PX_Object_GetCursorButton(pObject)->pushbutton,border); + } + return pObject; +} +PX_Object * PX_UI_CreateVirtualKeyboard(PX_UI *ui,PX_Object *parent,PX_Json_Value *json_value,px_int width,px_int height) +{ + PX_Object *pObject; + PX_UiBaseInfo baseInfo; + PX_Json_Value *pSubValue=PX_NULL; + px_color Color; + + baseInfo=PX_UIGetBaseInfo(json_value,width,height); + + pObject=PX_Object_VirtualKeyBoardCreate(ui->ui_mp,parent,(px_int)baseInfo.x,(px_int)baseInfo.y,(px_int)baseInfo.width,(px_int)baseInfo.height); + + if (PX_UI_GetColor(json_value,"backgroundcolor",&Color)) + { + PX_Object_VirtualKeyBoardSetBackgroundColor(pObject,Color); + } + + if (PX_UI_GetColor(json_value,"cursorcolor",&Color)) + { + PX_Object_VirtualKeyBoardSetCursorColor(pObject,Color); + } + + if (PX_UI_GetColor(json_value,"pushcolor",&Color)) + { + PX_Object_VirtualKeyBoardSetPushColor(pObject,Color); + } + + if (PX_UI_GetColor(json_value,"bordercolor",&Color)) + { + PX_Object_VirtualKeyBoardSetBorderColor(pObject,Color); + } + + return pObject; +} +PX_Object * PX_UI_CreateVirtualNumberKeyboard(PX_UI *ui,PX_Object *parent,PX_Json_Value *json_value,px_int width,px_int height) +{ + PX_Object *pObject; + PX_UiBaseInfo baseInfo; + PX_Json_Value *pSubValue=PX_NULL; + px_color Color; + + baseInfo=PX_UIGetBaseInfo(json_value,width,height); + + pObject=PX_Object_VirtualNumberKeyBoardCreate(ui->ui_mp,parent,(px_int)baseInfo.x,(px_int)baseInfo.y,(px_int)baseInfo.width,(px_int)baseInfo.height); + + if (PX_UI_GetColor(json_value,"backgroundcolor",&Color)) + { + PX_Object_VirtualNumberKeyBoardSetBackgroundColor(pObject,Color); + } + + if (PX_UI_GetColor(json_value,"cursorcolor",&Color)) + { + PX_Object_VirtualNumberKeyBoardSetCursorColor(pObject,Color); + } + + if (PX_UI_GetColor(json_value,"pushcolor",&Color)) + { + PX_Object_VirtualNumberKeyBoardSetPushColor(pObject,Color); + } + + if (PX_UI_GetColor(json_value,"bordercolor",&Color)) + { + PX_Object_VirtualNumberKeyBoardSetBorderColor(pObject,Color); + } + + return pObject; +} +PX_Object * PX_UI_CreateCheckBox(PX_UI *ui,PX_Object *parent,PX_Json_Value *json_value,px_int width,px_int height) +{ + PX_Object *pObject; + PX_UiBaseInfo baseInfo; + const px_char *text=""; + PX_Json_Value *pSubValue=PX_NULL; + px_color Color; + pSubValue=PX_JsonGetObjectValue(json_value,"text"); + if (pSubValue&&pSubValue->type==PX_JSON_VALUE_TYPE_STRING) + { + text=pSubValue->_string.buffer; + } + + baseInfo=PX_UIGetBaseInfo(json_value,width,height); + + pObject=PX_Object_CheckBoxCreate(ui->ui_mp,parent,(px_int)baseInfo.x,(px_int)baseInfo.y,(px_int)baseInfo.width,(px_int)baseInfo.height,text,ui->fontmodule); + + if (PX_UI_GetColor(json_value,"fontcolor",&Color)) + { + PX_Object_CheckBoxSetTextColor(pObject,Color); + } + + if (PX_UI_GetColor(json_value,"backgroundcolor",&Color)) + { + PX_Object_CheckBoxSetBackgroundColor(pObject,Color); + } + + if (PX_UI_GetColor(json_value,"cursorcolor",&Color)) + { + PX_Object_CheckBoxSetCursorColor(pObject,Color); + } + + if (PX_UI_GetColor(json_value,"pushcolor",&Color)) + { + PX_Object_CheckBoxSetPushColor(pObject,Color); + } + + if (PX_UI_GetColor(json_value,"bordercolor",&Color)) + { + PX_Object_CheckBoxSetBorderColor(pObject,Color); + } + + return pObject; +} + +px_bool PX_UI_IsValidUIObject(PX_UI *ui,PX_Json_Value *json_value) +{ + if (json_value->type==PX_JSON_VALUE_TYPE_OBJECT) + { + if (json_value->name.buffer&&json_value->name.buffer[0]) + { + px_int i; + for (i=0;iinfos.size;i++) + { + PX_UI_ControllerInfo *pInfo=PX_VECTORAT(PX_UI_ControllerInfo,&ui->infos,i); + if (PX_strequ(pInfo->Type,json_value->name.buffer)) + { + return PX_TRUE; + } + } + } + } + return PX_FALSE; +} + +PX_Object * PX_UI_CreateRadioBox(PX_UI *ui,PX_Object *parent,PX_Json_Value *json_value,px_int width,px_int height) +{ + PX_Object *pObject; + PX_UiBaseInfo baseInfo; + const px_char *text=""; + PX_Json_Value *pSubValue=PX_NULL; + px_color Color; + px_bool bselect; + pSubValue=PX_JsonGetObjectValue(json_value,"text"); + if (pSubValue&&pSubValue->type==PX_JSON_VALUE_TYPE_STRING) + { + text=pSubValue->_string.buffer; + } + + baseInfo=PX_UIGetBaseInfo(json_value,width,height); + + pObject=PX_Object_RadioBoxCreate(ui->ui_mp,parent,(px_int)baseInfo.x,(px_int)baseInfo.y,(px_int)baseInfo.width,(px_int)baseInfo.height,text,ui->fontmodule); + + if (PX_UI_GetColor(json_value,"fontcolor",&Color)) + { + PX_Object_RadioBoxSetTextColor(pObject,Color); + } + + if (PX_UI_GetColor(json_value,"backgroundcolor",&Color)) + { + PX_Object_RadioBoxSetBackgroundColor(pObject,Color); + } + + if (PX_UI_GetColor(json_value,"cursorcolor",&Color)) + { + PX_Object_RadioBoxSetCursorColor(pObject,Color); + } + + if (PX_UI_GetColor(json_value,"pushcolor",&Color)) + { + PX_Object_RadioBoxSetPushColor(pObject,Color); + } + + if (PX_UI_GetColor(json_value,"bordercolor",&Color)) + { + PX_Object_RadioBoxSetBorderColor(pObject,Color); + } + + if (PX_UI_GetBool(json_value,"select",&bselect)) + { + PX_Object_RadioBoxSetCheck(pObject,bselect); + } + + if (PX_UI_GetBool(json_value,"check",&bselect)) + { + PX_Object_RadioBoxSetCheck(pObject,bselect); + } + + return pObject; +} +PX_Object * PX_UI_CreateSelectBar(PX_UI *ui,PX_Object *parent,PX_Json_Value *json_value,px_int width,px_int height) +{ + PX_Object *pObject; + PX_UiBaseInfo baseInfo; + PX_Json_Value *pSubValue=PX_NULL; + px_color Color; + px_char style[8]; + px_double number; + + baseInfo=PX_UIGetBaseInfo(json_value,width,height); + + pObject=PX_Object_SelectBarCreate(ui->ui_mp,parent,(px_int)baseInfo.x,(px_int)baseInfo.y,(px_int)baseInfo.width,(px_int)baseInfo.height,ui->fontmodule); + + if (PX_UI_GetColor(json_value,"fontcolor",&Color)) + { + PX_Object_SelectBarSetFontColor(pObject,Color); + } + + if (PX_UI_GetColor(json_value,"backgroundcolor",&Color)) + { + PX_Object_SelectBarSetBackgroundColor(pObject,Color); + } + + if (PX_UI_GetColor(json_value,"cursorcolor",&Color)) + { + PX_Object_SelectBarSetCursorColor(pObject,Color); + } + + if (PX_UI_GetColor(json_value,"bordercolor",&Color)) + { + PX_Object_SelectBarSetBorderColor(pObject,Color); + } + + if (PX_UI_GetString(json_value,"style",style,sizeof(style))) + { + if (PX_strequ(style,"round")) + { + PX_Object_SelectBarSetStyle(pObject,PX_OBJECT_SELECTBAR_STYLE_ROUNDRECT); + } + } + + if (PX_UI_GetNumber(json_value,"displaycount",&number)) + { + if (number<1) + { + number=1; + } + PX_Object_SelectBarSetDisplayCount(pObject,(px_int)number); + } + + + pSubValue=PX_JsonGetObjectValue(json_value,"items"); + if (pSubValue&&pSubValue->type==PX_JSON_VALUE_TYPE_ARRAY) + { + px_int i; + PX_Json_Value *pArrayValue; + for (i=0;i_array.size;i++) + { + pArrayValue=PX_JsonGetArrayValue(pSubValue,i); + if (pArrayValue&&pArrayValue->type==PX_JSON_VALUE_TYPE_STRING) + { + PX_Object_SelectBarAddItem(pObject,pArrayValue->_string.buffer); + } + } + } + + if (PX_UI_GetNumber(json_value,"currentindex",&number)) + { + PX_Object_SelectBarSetCurrentIndex(pObject,(px_int)number); + } + + return pObject; +} + +px_bool PX_UIInitialize(px_memorypool *mp,px_memorypool *ui_mp,PX_UI *ui,PX_FontModule *fontmodule) +{ + PX_memset(ui,0,sizeof(PX_UI)); + ui->mp=mp; + ui->ui_mp=ui_mp; + ui->fontmodule=fontmodule; + if(!PX_VectorInitialize(mp,&ui->infos,sizeof(PX_UI_ControllerInfo),32)) return PX_FALSE; + if(!PX_MapInitialize(mp,&ui->ObjectMap)) + { + PX_VectorFree(&ui->infos); + return PX_FALSE; + } + if(!PX_UIAddControllerInfo(ui,"node",PX_UI_CreateNode)) goto _ERROR; + if(!PX_UIAddControllerInfo(ui,"label",PX_UI_CreateLabel)) goto _ERROR; + if(!PX_UIAddControllerInfo(ui,"processbar",PX_UI_CreateProcessbar)) goto _ERROR; + if(!PX_UIAddControllerInfo(ui,"image",PX_UI_CreateImage)) goto _ERROR; + if(!PX_UIAddControllerInfo(ui,"sliderbar",PX_UI_CreateSliderbar)) goto _ERROR; + if(!PX_UIAddControllerInfo(ui,"pushbutton",PX_UI_CreateButton)) goto _ERROR; + if(!PX_UIAddControllerInfo(ui,"edit",PX_UI_CreateEdit)) goto _ERROR; + if(!PX_UIAddControllerInfo(ui,"scrollarea",PX_UI_CreateScrollArea)) goto _ERROR; + if(!PX_UIAddControllerInfo(ui,"text",PX_UI_CreateAutoText)) goto _ERROR; + if(!PX_UIAddControllerInfo(ui,"cursorbutton",PX_UI_CreateCursorButton)) goto _ERROR; + if(!PX_UIAddControllerInfo(ui,"virtualkeyboard",PX_UI_CreateVirtualKeyboard)) goto _ERROR; + if(!PX_UIAddControllerInfo(ui,"virtualnumberkeyboard",PX_UI_CreateVirtualNumberKeyboard)) goto _ERROR; + if(!PX_UIAddControllerInfo(ui,"checkbox",PX_UI_CreateCheckBox)) goto _ERROR; + if(!PX_UIAddControllerInfo(ui,"radiobox",PX_UI_CreateRadioBox)) goto _ERROR; + if(!PX_UIAddControllerInfo(ui,"selectbar",PX_UI_CreateSelectBar)) goto _ERROR; + return PX_TRUE; +_ERROR: + + return PX_FALSE; +} + +px_bool PX_UIAddControllerInfo(PX_UI *ui,const px_char controllertype[],PX_UI_ControllerCreate _func) +{ + PX_UI_ControllerInfo info; + PX_strcpy(info.Type,controllertype,sizeof(info.Type)); + info.create_func=_func; + return PX_VectorPushback(&ui->infos,&info); +} + +PX_Object * PX_UICreate(PX_UI *ui,PX_Object *parent,PX_Json_Value *json_value,px_int width,px_int height) +{ + //key properties + //type default root + //x,y default 0,0 + PX_Object *pNewObject=PX_NULL; + PX_Json_Value *pSubValue=PX_NULL; + + if (json_value->type!=PX_JSON_VALUE_TYPE_OBJECT) + { + return PX_NULL; + } + + if (json_value->name.buffer&&json_value->name.buffer[0]) + { + px_int i; + for (i=0;iinfos.size;i++) + { + PX_UI_ControllerInfo *pInfo=PX_VECTORAT(PX_UI_ControllerInfo,&ui->infos,i); + if (PX_strequ(pInfo->Type,json_value->name.buffer)) + { + if (pInfo->create_func) + { + pNewObject=pInfo->create_func(ui,parent,json_value,width,height); + if (!pNewObject) + { + goto _ERROR; + } + break; + } + else + { + goto _ERROR; + } + } + } + + } + else + { + //root object + PX_UiBaseInfo baseInfo; + baseInfo=PX_UIGetBaseInfo(json_value,width,height); + + pNewObject=PX_ObjectCreate(ui->ui_mp,parent,baseInfo.x,baseInfo.y,baseInfo.z,baseInfo.width,baseInfo.height,baseInfo.length); + if (!pNewObject) + { + goto _ERROR; + } + } + + pSubValue=PX_JsonGetObjectValue(json_value,"id"); + if (pSubValue&&pSubValue->type==PX_JSON_VALUE_TYPE_STRING&&pSubValue->_string.buffer[0]) + { + if(PX_MapGet(&ui->ObjectMap,pSubValue->_string.buffer)) + { + //"Repeat controller" + PX_ASSERT(); + goto _ERROR; + } + if(PX_MapPut(&ui->ObjectMap,pSubValue->_string.buffer,pNewObject)!=PX_HASHMAP_RETURN_OK) + goto _ERROR; + } + + if (pNewObject) + { + px_list_node *pNode=PX_ListNodeAt(&json_value->_object.values,0); + while (pNode) + { + PX_Json_Value *pvalue=PX_LIST_NODETDATA(PX_Json_Value,pNode); + if (PX_UI_IsValidUIObject(ui,pvalue)) + { + if(!PX_UICreate(ui,pNewObject,pvalue,width,height)) + { + goto _ERROR; + } + } + pNode=pNode->pnext; + } + } + + return pNewObject; +_ERROR: + if (pNewObject) + { + PX_ObjectDelete(pNewObject); + } + return PX_NULL; + +} + +px_void PX_UIUpdateObjectsPostions(PX_UI *ui,PX_Object *pObject,PX_Json_Value *json_value,px_int width,px_int height) +{ + PX_UiBaseInfo baseInfo; + PX_Json_Value *pSubValue=PX_NULL; + PX_Object *pChildObject; + px_int i; + px_int index=0; + + baseInfo=PX_UIGetBaseInfo(json_value,width,height); + pObject->x=baseInfo.x; + pObject->y=baseInfo.y; + pObject->Height=baseInfo.height; + pObject->Width=baseInfo.width; + if (json_value->type==PX_JSON_VALUE_TYPE_OBJECT) + { + for (i=0;i_object.values.size;i++) + { + pSubValue=PX_JsonGetObjectValueByIndex(json_value,i); + if (PX_UI_IsValidUIObject(ui,pSubValue)) + { + pChildObject=PX_ObjectGetChild(pObject,index); + if (pChildObject) + { + PX_UIUpdateObjectsPostions(ui,pChildObject,pSubValue,width,height); + } + index++; + } + + } + } +} + +PX_Object * PX_UIGetObjectByID(PX_UI *ui,const px_char id[]) +{ + return (PX_Object *)PX_MapGet(&ui->ObjectMap,id); +} + +px_void PX_UIFree(PX_UI *ui) +{ + PX_VectorFree(&ui->infos); + PX_MapFree(&ui->ObjectMap); +} + diff --git a/lib/PainterEngine/kernel/PX_UI.h b/lib/PainterEngine/kernel/PX_UI.h new file mode 100644 index 0000000000000000000000000000000000000000..904669461db84d45835baa81beb10b10bd5f078d --- /dev/null +++ b/lib/PainterEngine/kernel/PX_UI.h @@ -0,0 +1,31 @@ +#ifndef PX_UI_H +#define PX_UI_H + +#include "PX_Json.h" +#include "PX_Object.h" + +typedef struct +{ + px_memorypool *mp,*ui_mp; + px_map ObjectMap; + px_vector infos; + PX_FontModule *fontmodule; +}PX_UI; + + +typedef PX_Object * (*PX_UI_ControllerCreate)(PX_UI *ui,PX_Object *parent,PX_Json_Value *value,px_int width,px_int height); + +typedef struct +{ + px_char Type[32]; + PX_UI_ControllerCreate create_func; +}PX_UI_ControllerInfo; + +px_bool PX_UIInitialize(px_memorypool *mp,px_memorypool *ui_mp,PX_UI *ui,PX_FontModule *fontmodule); +px_bool PX_UIAddControllerInfo(PX_UI *ui,const px_char controllertype[],PX_UI_ControllerCreate _func); +PX_Object * PX_UICreate(PX_UI *ui,PX_Object *parent,PX_Json_Value *json_value,px_int width,px_int height); +px_void PX_UIUpdateObjectsPostions(PX_UI *ui,PX_Object *update,PX_Json_Value *json_value,px_int width,px_int height); +PX_Object *PX_UIGetObjectByID(PX_UI *ui,const px_char id[]); +px_void PX_UIFree(PX_UI *ui); + +#endif \ No newline at end of file diff --git a/lib/PainterEngine/kernel/PX_World.c b/lib/PainterEngine/kernel/PX_World.c new file mode 100644 index 0000000000000000000000000000000000000000..11be16612c80d2d2675de3ebf8e7ce1204037850 --- /dev/null +++ b/lib/PainterEngine/kernel/PX_World.c @@ -0,0 +1,588 @@ +#include "PX_World.h" + + +px_bool PX_WorldInitialize(px_memorypool *mp,PX_World *World,px_int world_width,px_int world_height,px_int surface_width,px_int surface_height,px_dword calcSize) +{ + px_void *ptr; + PX_memset(World, 0, sizeof(PX_World)); + if(!PX_VectorInitialize(mp,&World->pObjects,sizeof(PX_WorldObject),256)) return PX_FALSE; + if(!PX_VectorInitialize(mp,&World->pNewObjects,sizeof(PX_Object *),128)) return PX_FALSE; + World->mp=mp; + World->world_height=world_height; + World->world_width=world_width; + World->surface_height=surface_height; + World->surface_width=surface_width; + World->auxiliaryline=PX_TRUE; + World->auxiliaryline_color=PX_COLOR(64,255,192,255); + World->camera_offset=PX_POINT(0,0,0); + World->aliveCount=0; + World->offsetx=0; + World->offsety=0; + PX_WorldSetAuxiliaryXYSpacer(World,32,32); + ptr=MP_Malloc(World->mp,calcSize); + if (!ptr) + { + return PX_FALSE; + } + World->mp_WorldCalc=MP_Create(ptr,calcSize); + PX_memset(World->Impact_Test_array,0,sizeof(World->Impact_Test_array)); + return PX_TRUE; +} + +px_void PX_WorldSetAuxiliaryXYSpacer(PX_World *pw,px_int x,px_int y) +{ + pw->auxiliaryXSpacer=x; + pw->auxiliaryYSpacer=y; +} + +px_void PX_WorldEnableAuxiliaryLine(PX_World *pw,px_bool bline) +{ + pw->auxiliaryline=bline; +} + + +px_int PX_WorldGetCount(PX_World *World) +{ + return World->pObjects.size; +} + +px_int PX_WorldAddObjectEx(PX_World *World,PX_Object *pObject) +{ + PX_WorldObject *pwo,wo; + int i; + wo.pObject=pObject; + wo.DeleteMark=PX_FALSE; + + for (i=0;ipObjects.size;i++) + { + pwo=PX_VECTORAT(PX_WorldObject,&World->pObjects,i); + if (!pwo->pObject) + { + *pwo=wo; + World->aliveCount++; + return i; + } + } + if (PX_VectorPushback(&World->pObjects,&wo)) + { + World->aliveCount++; + return World->pObjects.size-1; + } + return -1; +} + +px_void PX_WorldRemoveObjectEx(PX_World *world,px_int i_index) +{ + PX_WorldObject *pwo=PX_VECTORAT(PX_WorldObject,&world->pObjects,i_index); + if (pwo->pObject) + { + pwo->DeleteMark=PX_FALSE; + world->aliveCount--; + PX_ObjectDelete(pwo->pObject); + pwo->pObject=PX_NULL; + } +} + +static px_void PX_WorldUpdateNewObjectList(PX_World* pworld) +{ + px_int k = 0,i,j; + for (i = 0; i < pworld->pNewObjects.size; i++) + { + PX_WorldObject* pwo, wo; + + wo.pObject = *PX_VECTORAT(PX_Object*, &pworld->pNewObjects, i); + wo.DeleteMark = PX_FALSE; + + for (j = k; j < pworld->pObjects.size; j++) + { + pwo = PX_VECTORAT(PX_WorldObject, &pworld->pObjects, j); + if (!pwo->pObject) + { + wo.pObject->world_index = j; + *pwo = wo; + pworld->aliveCount++; + k = j + 1; + goto NEW_OBJECT_CONTINUE; + } + } + + if (PX_VectorPushback(&pworld->pObjects, &wo)) + { + pworld->aliveCount++; + wo.pObject->world_index = pworld->pObjects.size - 1; + k = wo.pObject->world_index + 1; + } + NEW_OBJECT_CONTINUE: + continue; + } + PX_VectorClear(&pworld->pNewObjects); +} + +px_void PX_WorldUpdate( PX_World *pworld,px_uint elapsed ) +{ + px_int updateCount; + px_int i,b,j; + px_float w_left=0,w_top=0,w_right=0,w_height=0; + PX_Object_Event e; + PX_WorldObject *pwo; + + px_int impact_count[sizeof(pwo->pObject->impact_object_type)*8]={0}; + px_memorypool *calcmp=&pworld->mp_WorldCalc; + + if (pworld==PX_NULL) + { + return; + } + + MP_Reset(calcmp); + + //Add NewObjects + PX_WorldUpdateNewObjectList(pworld); + + //Object Counts + updateCount=pworld->pObjects.size; + + ////////////////////////////////////////////////////////////////////////// + //impact test + ////////////////////////////////////////////////////////////////////////// + for (i=0;ipObjects,i); + if (!pwo->pObject) + { + continue; + } + if (pwo->pObject->impact_object_type) + { + j=0; + while(!(pwo->pObject->impact_object_type &(1<pObject->impact_object_type)*8;i++) + { + if (impact_count[i]) + { + PX_QuadtreeCreate(calcmp,&pworld->Impact_Test_array[i],0,0,(px_float)pworld->world_width,(px_float)pworld->world_height,impact_count[i],2); + } + else + { + PX_QuadtreeCreate(calcmp,&pworld->Impact_Test_array[i],0,0,(px_float)pworld->world_width,(px_float)pworld->world_height,impact_count[i],0); + } + } + + for (i=0;ipObjects,i); + if (!pwo->pObject) + { + continue; + } + if (pwo->pObject->impact_object_type) + { + for (b=0;bpObject->impact_object_type)*8;b++) + { + if ((pwo->pObject->impact_object_type &(1<pObject->diameter) + { + PX_QuadtreeAddNode(&pworld->Impact_Test_array[b],(px_float)pwo->pObject->x,(px_float)pwo->pObject->y,(px_float)pwo->pObject->diameter,(px_float)pwo->pObject->diameter,userData); + } + else + { + PX_QuadtreeAddNode(&pworld->Impact_Test_array[b],(px_float)pwo->pObject->x,(px_float)pwo->pObject->y,(px_float)pwo->pObject->Width,(px_float)pwo->pObject->Height,userData); + } + + } + } + } + } + + for (i=0;ipObjects,i); + if (!pwo->pObject) + { + continue; + } + + if (pwo->pObject->impact_target_type) + { + for (b=0;bpObject->impact_target_type)*8;b++) + { + if ((pwo->pObject->impact_target_type &(1<Impact_Test_array[b]); + if (pwo->pObject->diameter) + { + PX_QuadtreeTestNode(&pworld->Impact_Test_array[b],(px_float)pwo->pObject->x,(px_float)pwo->pObject->y,(px_float)pwo->pObject->diameter,(px_float)pwo->pObject->diameter,userData); + } + else + { + PX_QuadtreeTestNode(&pworld->Impact_Test_array[b],(px_float)pwo->pObject->x,(px_float)pwo->pObject->y,(px_float)pwo->pObject->Width,(px_float)pwo->pObject->Height,userData); + } + + for (im_i=0;im_iImpact_Test_array[b].Impacts.size;im_i++) + { + PX_Quadtree_UserData *puData=PX_VECTORAT(PX_Quadtree_UserData,&pworld->Impact_Test_array[b].Impacts,im_i); + PX_Object *pObj1=pwo->pObject; + PX_WorldObject *pimpactWo=(PX_WorldObject *)puData->ptr; + PX_Object *pObj2=((PX_WorldObject *)(puData->ptr))->pObject; + + if (pObj1->diameter&&pObj2->diameter) + { + if(!PX_isCircleCrossCircle(PX_POINT(pObj1->x,pObj1->y,0),pObj1->diameter/2,PX_POINT(pObj2->x,pObj2->y,0),pObj2->diameter/2)) + continue; + } + else if (pObj1->diameter==0&&pObj2->diameter) + { + if (!PX_isRectCrossCircle(PX_RECT(pObj1->x-pObj1->Width/2,pObj1->y-pObj1->Height/2,pObj1->Width,pObj1->Height),PX_POINT(pObj2->x,pObj2->y,0),pObj2->diameter/2)) + { + continue; + } + } + else if (pObj1->diameter&&pObj2->diameter==0) + { + if (!PX_isRectCrossCircle(PX_RECT(pObj2->x-pObj2->Width/2,pObj2->y-pObj2->Height/2,pObj2->Width,pObj2->Height),PX_POINT(pObj1->x,pObj1->y,0),pObj1->diameter/2)) + { + continue; + } + } + if (pimpactWo->DeleteMark!=PX_TRUE) + { + e.Event=PX_OBJECT_EVENT_IMPACT; + e.Param_ptr[0]=pObj2; + PX_ObjectPostEvent(pObj1,e); + } + } + + } + } + } + } + + ////////////////////////////////////////////////////////////////////////// + //Update Objects + + + for (i=0;ipObjects,i); + if (!pwo->pObject) + { + continue; + } + PX_ObjectUpdate(pwo->pObject,elapsed); + } + + ////////////////////////////////////////////////////////////////////////// + //delete death objects + for (i=0;ipObjects,i); + if (pwo->pObject&&pwo->DeleteMark) + { + PX_WorldRemoveObjectEx(pworld,i); + } + } + +} + +px_void PX_WorldUpdateOffset(PX_World *pw) +{ + px_int surface_width,surface_height; + px_int LeftTopX,LeftTopY; + + surface_width=pw->surface_width; + surface_height=pw->surface_height; + LeftTopX=(px_int)(pw->camera_offset.x-surface_width/2),LeftTopY=(px_int)(pw->camera_offset.y-surface_height/2); + + if (LeftTopX+surface_width>pw->world_width) + { + LeftTopX=pw->world_width-surface_width; + } + + if (LeftTopY+surface_height>pw->world_height) + { + LeftTopY=pw->world_height-surface_height; + } + + if (LeftTopX<0) + { + LeftTopX=0; + } + if (LeftTopY<0) + { + LeftTopY=0; + } + + pw->offsetx=(px_float)LeftTopX; + pw->offsety=(px_float)LeftTopY; +} + +static px_void PX_WorldClildRender(PX_World *pworld,px_surface *pSurface, PX_Object *Object,px_uint elapsed,px_float oftX,px_float oftY) +{ + if (Object==PX_NULL) + { + return; + } + if (Object->Visible==PX_FALSE) + { + return; + } + if (Object->Func_ObjectRender!=0) + { + px_float x=Object->x; + px_float y=Object->y; + Object->x-=oftX; + Object->y-=oftY; + Object->Func_ObjectRender(pSurface,Object,elapsed); + + if (pworld->showImpactRegion) + { + if (Object->diameter) + { + PX_GeoDrawSolidCircle(pSurface, (px_int)Object->x, (px_int)Object->y, (px_int)Object->diameter / 2, PX_COLOR(32, 255, 0, 0)); + } + else + { + PX_GeoDrawRect(pSurface, (px_int)(Object->x- Object->Width/2), (px_int)(Object->y- Object->Height/2), (px_int)(Object->x + Object->Width/2), (px_int)(Object->y + Object->Height/2), PX_COLOR(32, 255, 0, 0)); + } + } + + + Object->x=x; + Object->y=y; + } + if (Object->pNextBrother!=PX_NULL) + { + PX_WorldClildRender(pworld,pSurface,Object->pNextBrother,elapsed,oftX,oftY); + } + if (Object->pChilds!=PX_NULL) + { + PX_WorldClildRender(pworld,pSurface,Object->pNextBrother,elapsed,oftX,oftY); + } +} + + + +px_void PX_WorldRender(px_surface *psurface,PX_World *pw,px_uint elapsed) +{ + px_int i,j; + px_int surface_width,surface_height; + PX_QuickSortAtom *ArrayIndex; + px_memorypool *calcmp; + px_int sx,sy; + PX_WorldObject *pwo; + + if (pw==PX_NULL) + { + return; + } + + calcmp=&pw->mp_WorldCalc; + MP_Reset(calcmp); + + + PX_WorldUpdateOffset(pw); + + surface_width=pw->surface_width; + surface_height=pw->surface_height; + + + if (pw->auxiliaryline) + { + for (sy=pw->auxiliaryYSpacer-((px_int)pw->offsety%pw->auxiliaryYSpacer);syauxiliaryYSpacer) + { + PX_GeoDrawLine(psurface,0,sy,surface_width-1,sy,1,pw->auxiliaryline_color); + } + + for (sx=pw->auxiliaryXSpacer-((px_int)pw->offsetx%pw->auxiliaryXSpacer);sxauxiliaryXSpacer) + { + PX_GeoDrawLine(psurface,sx,0,sx,surface_height-1,1,pw->auxiliaryline_color); + } + + } + + ArrayIndex=(PX_QuickSortAtom *)MP_Malloc(calcmp,pw->aliveCount*sizeof(PX_QuickSortAtom)); + j=0; + + for (i=0;ipObjects.size;i++) + { + pwo=PX_VECTORAT(PX_WorldObject,&pw->pObjects,i); + if (!pwo->pObject) + { + continue; + } + ArrayIndex[j].weight=pwo->pObject->z; + ArrayIndex[j].pData=pwo->pObject; + j++; + } + + PX_Quicksort_MaxToMin(ArrayIndex,0,pw->aliveCount-1); + + + + for (i=0;ialiveCount;i++) + { + PX_WorldClildRender(pw,psurface,(PX_Object *)ArrayIndex[i].pData,elapsed,pw->offsetx,pw->offsety); + } + MP_Reset(calcmp); +} + +px_void PX_WorldSetImpact(PX_Object *pObj,px_dword type,px_dword Intersect) +{ + pObj->impact_object_type=type; + pObj->impact_target_type=Intersect; +} + + + +px_bool PX_WorldAddObject(PX_World *World,PX_Object *pObject) +{ + return PX_VectorPushback(&World->pNewObjects,&pObject); +} + + + + +px_void PX_WorldSetAuxiliaryLineColor(PX_World *pw,px_color color) +{ + pw->auxiliaryline_color=color; +} + + + +px_point PX_WolrdObjectXYtoScreenXY(PX_World *pw,px_float x,px_float y) +{ + return PX_POINT(x-pw->offsetx,y-pw->offsety,0); +} + +px_void PX_WorldPostEvent(PX_World* pw, PX_Object_Event e) +{ + PX_WorldObject* pwo; + int i; + for (i = 0; i < pw->pObjects.size; i++) + { + pwo = PX_VECTORAT(PX_WorldObject, &pw->pObjects, i); + if (pwo->pObject) + { + PX_ObjectPostEvent(pwo->pObject, e); + } + } +} + +px_void PX_WorldFree(PX_World *pw) +{ + PX_WorldObject *pwo; + int i; + for (i=0;ipObjects.size;i++) + { + pwo=PX_VECTORAT(PX_WorldObject,&pw->pObjects,i); + if (pwo->pObject) + { + PX_ObjectDelete(pwo->pObject); + } + } + PX_VectorFree(&pw->pObjects); + PX_VectorFree(&pw->pNewObjects); + + MP_Free(pw->mp,pw->mp_WorldCalc.StartAddr); + +} + +px_void PX_WorldSetCamera(PX_World *World,px_point camera_center_point) +{ + World->camera_offset=camera_center_point; + PX_WorldUpdateOffset(World); +} + +px_void PX_WorldRemoveObject(PX_World *world,PX_Object *pObject) +{ + PX_WorldObject *pwo; + if (pObject->world_index!=-1&&pObject->world_indexpObjects.size) + { + pwo=PX_VECTORAT(PX_WorldObject,&world->pObjects,pObject->world_index); + if (pwo->pObject==pObject) + { + pwo->DeleteMark=PX_TRUE; + + return; + } + } +} + +px_void PX_WorldRemoveObjectByIndex(PX_World *world,px_int i_index) +{ + PX_WorldObject *pwo=PX_VECTORAT(PX_WorldObject,&world->pObjects,i_index); + +#ifdef PX_DEBUG_MODE + if (i_index>world->pObjects.size) + { + PX_ASSERT(); + } +#endif + + if (pwo->pObject) + { + pwo->DeleteMark=PX_TRUE; + } +} + +_LIMIT px_int PX_WorldSearchRegion(PX_World *world,px_float x,px_float y,px_float raduis,PX_Object *Object[],px_int MaxSearchCount,px_dword impact_test_type) +{ + px_int b; + px_int m=0; + for (b=0;bImpact_Test_array[b]); + PX_QuadtreeTestNode(&world->Impact_Test_array[b],x,y,raduis*2,raduis*2,userData); + + for (im_i=0;im_iImpact_Test_array[b].Impacts.size;im_i++) + { + PX_Quadtree_UserData *puData=PX_VECTORAT(PX_Quadtree_UserData,&world->Impact_Test_array[b].Impacts,im_i); + PX_WorldObject *pimpactWo=(PX_WorldObject *)puData->ptr; + PX_Object *pObj2=((PX_WorldObject *)(puData->ptr))->pObject; + + if (pObj2->diameter) + { + if(!PX_isCircleCrossCircle(PX_POINT(x,y,0),raduis,PX_POINT(pObj2->x,pObj2->y,0),pObj2->diameter/2)) + continue; + } + else + { + if (!PX_isRectCrossCircle(PX_RECT(pObj2->x-pObj2->Width/2,pObj2->y-pObj2->Height/2,pObj2->Width,pObj2->Height),PX_POINT(x,y,0),raduis)) + { + continue; + } + } + + if (pimpactWo->DeleteMark!=PX_TRUE) + { + if (m +#include +#pragma comment (lib,"dsound.lib") + +extern "C" +{ + #include "../../core/PX_Sound.h" + int PX_AudioInitialize(PX_SoundPlay *soundPlay); + int PX_AudioInitializeEx(); + void PX_AudioSetVolume( unsigned int Vol ); + void PX_AudioPlay( unsigned long Vol ); + int PX_AudioGetStandbyBufferSize(); + int PX_AudioWriteBuffer(void *pBuffer,size_t Size ); + BOOL PX_AudioCaptureOpen(GUID dev_id,int channel); + void PX_AudioCaptureClose(); + DWORD PX_AudioCaptureReadEx(void *pBuffer,px_int buffersize,px_int align); + DWORD PX_AudioCaptureRead(void *buffer,px_int buffersize); + LPDIRECTSOUNDBUFFER PX_AudioGetDirectSoundBuffer(); +}; + +#define DSOUND_BUFFER_SIZE (1764*16) + +static LPDIRECTSOUNDBUFFER DSound_lpdbsBuffer; +static DSBUFFERDESC DSound_dsbd; +static LPDIRECTSOUND DSound_lpds; +static WAVEFORMATEX DSound_waveformat; +static PX_SoundPlay *DSound_soundplay; +static px_byte DSound_data[DSOUND_BUFFER_SIZE]; +volatile static DWORD DSound_wPosition=0; + + + +DWORD _stdcall DEMO_DSoundProc(LPVOID p) +{ + px_dword wsize=0; + + while (!DSound_soundplay) + { + Sleep(10); + } + + while(1) + { + wsize=PX_AudioGetStandbyBufferSize(); + + if (PX_SoundPlayGetDataCount(DSound_soundplay)) + { + + if (wsize>DSOUND_BUFFER_SIZE) + { + wsize=DSOUND_BUFFER_SIZE; + } + PX_SoundPlayRead(DSound_soundplay,DSound_data,wsize); + PX_AudioWriteBuffer(DSound_data,wsize); + } + else + { + memset(DSound_data,0,DSOUND_BUFFER_SIZE); + PX_AudioWriteBuffer(DSound_data,wsize); + } + Sleep(10); + } +} + +extern HWND Win_Hwnd; +int PX_AudioInitialize(PX_SoundPlay *soundPlay) +{ + DSound_soundplay=soundPlay; + return 1; +} +int PX_AudioInitializeEx() +{ + VOID* pDSLockedBuffer =NULL; + DWORD dwDSLockedBufferSize =0; + HANDLE hThread; + DWORD threadId; + HWND hwnd=Win_Hwnd; + BOOL startThread=PX_TRUE; + /*Sound Play*/ + if (!DSound_soundplay) + { + return 1; + } + + //DSound created + if(DSound_lpds==NULL) + { + if(DirectSoundCreate(NULL,&DSound_lpds,NULL) == DS_OK) + { + if(DSound_lpds ->SetCooperativeLevel(hwnd,DSSCL_NORMAL)!=DS_OK) + { + return FALSE; + } + } + } + + + /////////////////////////////////////////////////////////////////////////// + //Create Sound buffer + + + DSound_waveformat.wFormatTag = WAVE_FORMAT_PCM; + DSound_waveformat.nSamplesPerSec = 44100;//44100; + DSound_waveformat.wBitsPerSample = 16;// + DSound_waveformat.nChannels = 2;// + DSound_waveformat.nBlockAlign = (DSound_waveformat.wBitsPerSample >> 3) * DSound_waveformat.nChannels;; + DSound_waveformat.nAvgBytesPerSec = DSound_waveformat.nBlockAlign * DSound_waveformat.nSamplesPerSec; + DSound_waveformat.cbSize = 0; + + memset(&DSound_dsbd,0,sizeof(DSBUFFERDESC)); + DSound_dsbd.dwSize = sizeof(DSBUFFERDESC); + DSound_dsbd.dwFlags=DSBCAPS_GLOBALFOCUS | DSBCAPS_CTRLPOSITIONNOTIFY |DSBCAPS_GETCURRENTPOSITION2|DSBCAPS_CTRLVOLUME ; + DSound_dsbd.dwBufferBytes =DSOUND_BUFFER_SIZE; + DSound_dsbd.lpwfxFormat =&DSound_waveformat; + DSound_dsbd.dwReserved=0; + + + HRESULT hr; + if(FAILED(hr=DSound_lpds ->CreateSoundBuffer(&DSound_dsbd,&DSound_lpdbsBuffer,NULL))) + { + return FALSE; + } + + PX_AudioSetVolume(0); + + if(DSound_lpdbsBuffer ->Lock(0,DSOUND_BUFFER_SIZE,&pDSLockedBuffer,&dwDSLockedBufferSize,NULL,NULL,0)) + return FALSE; + + memset(pDSLockedBuffer,0,dwDSLockedBufferSize); + + DSound_lpdbsBuffer->Unlock(pDSLockedBuffer,dwDSLockedBufferSize,NULL,0); + DSound_lpdbsBuffer->Play(0,0,DSBPLAY_LOOPING); + + if(startThread) + hThread = CreateThread(NULL, 0, DEMO_DSoundProc, 0, 0, &threadId); + + return TRUE; +} + +LPDIRECTSOUNDBUFFER PX_AudioGetDirectSoundBuffer() +{ + return DSound_lpdbsBuffer; +} + + + +void PX_AudioSetVolume( unsigned int Vol ) +{ + DSound_lpdbsBuffer->SetVolume(Vol); +} + +void PX_AudioPlay( unsigned long Vol ) +{ + DSound_lpdbsBuffer->Play(0,0,DSBPLAY_LOOPING); +} + + +int PX_AudioGetStandbyBufferSize() +{ + DWORD PlayCursor,__w; + + if (FAILED(DSound_lpdbsBuffer->GetCurrentPosition(&PlayCursor,&__w))) + { + return 0; + } + + if (DSound_wPosition>PlayCursor) + { + return DSOUND_BUFFER_SIZE-(DSound_wPosition-PlayCursor); + } + else + { + return PlayCursor-DSound_wPosition; + } +} + +int PX_AudioWriteBuffer(void *pBuffer,size_t Size ) +{ + DWORD wbuf1_size,wbuf2_size; + VOID* pDSLockedBuffer =NULL; + DWORD dwDSLockedBufferSize =0; + + if (Size>DSOUND_BUFFER_SIZE) + { + PX_ASSERT(); + } + + wbuf1_size=DSOUND_BUFFER_SIZE-DSound_wPosition; + if (wbuf1_size>Size) + { + wbuf1_size= (DWORD)Size; + } + + Size-=wbuf1_size; + + if(DSound_lpdbsBuffer ->Lock(DSound_wPosition,wbuf1_size,&pDSLockedBuffer,&dwDSLockedBufferSize,NULL,NULL,0L)) + return FALSE; + + memcpy(pDSLockedBuffer,pBuffer,dwDSLockedBufferSize); + + DSound_lpdbsBuffer->Unlock(pDSLockedBuffer,dwDSLockedBufferSize,NULL,0); + + DSound_wPosition+=wbuf1_size; + + if (DSound_wPosition>=DSOUND_BUFFER_SIZE) + { + DSound_wPosition=0; + } + + if (Size) + { + pBuffer=((char *)pBuffer+wbuf1_size); + + wbuf2_size=(DWORD)Size; + + if(DSound_lpdbsBuffer ->Lock(0,wbuf2_size,&pDSLockedBuffer,&dwDSLockedBufferSize,NULL,NULL,0L)) + return FALSE; + + memcpy(pDSLockedBuffer,pBuffer,dwDSLockedBufferSize); + + DSound_lpdbsBuffer->Unlock(pDSLockedBuffer,dwDSLockedBufferSize,NULL,0); + + DSound_wPosition+=wbuf2_size; + } + + + return (DWORD)Size; +} + +#define DSOUNDCAPTURE_CHANNEL 1 +#define DSOUNDCAPTURE_SAMPLERATE 44100 +#define DSOUNDCAPTURE_BITS 16 +#define DSOUNDCAPTURE_BUFFER_SIZE (DSOUNDCAPTURE_SAMPLERATE*DSOUNDCAPTURE_CHANNEL*DSOUNDCAPTURE_BITS/8*2) //2 second cache buffer + +static LPDIRECTSOUNDCAPTURE8 DSoundCapture_pCapDev ; //capture device ptr +static LPDIRECTSOUNDCAPTUREBUFFER DSoundCapture_pCapBuf=PX_NULL ; //capture loop buffer ptr +static GUID DSoundCapture_guidCapDevId ; //capture device id +static WAVEFORMATEX DSoundCapture_wfxInput; //input wave format description struct +volatile static DWORD DSoundCapture_RPosition; + +BOOL PX_AudioCaptureOpen(GUID dev_id,int channel) +{ + HRESULT hr ; + + DSoundCapture_guidCapDevId = dev_id ; + + if (DSoundCapture_pCapBuf||DSoundCapture_pCapDev) + { + PX_AudioCaptureClose(); + } + + + // Create IDirectSoundCapture using the preferred capture device + hr = DirectSoundCaptureCreate(&DSoundCapture_guidCapDevId, &DSoundCapture_pCapDev, NULL ) ; + // init wave format + + if (FAILED(hr)) return PX_FALSE; + + // get the default capture wave formate + ZeroMemory(&DSoundCapture_wfxInput, sizeof(WAVEFORMATEX)) ; + DSoundCapture_wfxInput.wFormatTag = WAVE_FORMAT_PCM; + // 8KHz, 16 bits PCM, Mono + DSoundCapture_wfxInput.nSamplesPerSec = 44100 ; + DSoundCapture_wfxInput.wBitsPerSample = 16 ; + DSoundCapture_wfxInput.nChannels = channel ; + DSoundCapture_wfxInput.nBlockAlign = DSoundCapture_wfxInput.nChannels * ( DSoundCapture_wfxInput.wBitsPerSample / 8 ) ; + DSoundCapture_wfxInput.nAvgBytesPerSec = DSoundCapture_wfxInput.nBlockAlign * DSoundCapture_wfxInput.nSamplesPerSec; + + //Create CaptureBuffer + DSCBUFFERDESC dscbd; + + // Create the capture buffer + ZeroMemory( &dscbd, sizeof(dscbd) ); + dscbd.dwSize = sizeof(dscbd); + dscbd.dwBufferBytes = DSOUNDCAPTURE_BUFFER_SIZE; + dscbd.lpwfxFormat = &DSoundCapture_wfxInput ; // Set the format during creatation + + + + if( FAILED( hr = DSoundCapture_pCapDev->CreateCaptureBuffer( &dscbd, &DSoundCapture_pCapBuf, NULL ) ) ) + return PX_FALSE ; + + DSoundCapture_RPosition=0; + + DSoundCapture_pCapBuf->Start(DSCBSTART_LOOPING); + + return PX_TRUE; + +} + +#include "stdio.h" +DWORD PX_AudioCaptureReadEx(void *pBuffer,px_int buffersize,px_int align) +{ + DWORD rbuf1_size,rbuf2_size,Size=0; + VOID* pDSLockedBuffer =NULL; + DWORD dwDSLockedBufferSize =0; + + DWORD RecorderCursor,__r; + DWORD ReadySize; + + if (FAILED(DSoundCapture_pCapBuf->GetCurrentPosition(&RecorderCursor,&__r))) + { + return 0; + } + + if (DSoundCapture_RPosition>RecorderCursor) + { + ReadySize= DSOUNDCAPTURE_BUFFER_SIZE-(DSoundCapture_RPosition-RecorderCursor); + } + else + { + ReadySize= RecorderCursor-DSoundCapture_RPosition; + } + + if ((DWORD)buffersizeReadySize) + { + rbuf1_size=ReadySize; + } + + ReadySize-=rbuf1_size; + + if(DSoundCapture_pCapBuf ->Lock(DSoundCapture_RPosition,rbuf1_size,&pDSLockedBuffer,&dwDSLockedBufferSize,NULL,NULL,0L)) + return FALSE; + + memcpy(pBuffer,pDSLockedBuffer,dwDSLockedBufferSize); + Size+=dwDSLockedBufferSize; + DSoundCapture_pCapBuf->Unlock(pDSLockedBuffer,dwDSLockedBufferSize,NULL,0); + + DSoundCapture_RPosition+=rbuf1_size; + + if (DSoundCapture_RPosition>=DSOUNDCAPTURE_BUFFER_SIZE) + { + DSoundCapture_RPosition=0; + } + + if (ReadySize) + { + pBuffer=((char *)pBuffer+rbuf1_size); + + rbuf2_size=ReadySize; + + if(DSoundCapture_pCapBuf ->Lock(0,rbuf2_size,&pDSLockedBuffer,&dwDSLockedBufferSize,NULL,NULL,0L)) + return FALSE; + + memcpy(pBuffer,pDSLockedBuffer,dwDSLockedBufferSize); + + Size+=dwDSLockedBufferSize; + DSoundCapture_pCapBuf->Unlock(pDSLockedBuffer,dwDSLockedBufferSize,NULL,0); + + DSoundCapture_RPosition+=rbuf2_size; + } + return Size; +} + + + +DWORD PX_AudioCaptureRead(void *pBuffer,px_int buffersize) +{ + return PX_AudioCaptureReadEx(pBuffer,buffersize,1); +} + +void PX_AudioCaptureClose() +{ + if (DSoundCapture_pCapBuf) + { + DSoundCapture_pCapBuf->Stop(); + DSoundCapture_pCapBuf->Release(); + DSoundCapture_pCapBuf=PX_NULL; + } + if (DSoundCapture_pCapDev) + { + DSoundCapture_pCapDev->Release(); + DSoundCapture_pCapDev=PX_NULL; + } + + + DSoundCapture_RPosition=0; +} diff --git a/lib/PainterEngine/platform/windows/px_display.cpp b/lib/PainterEngine/platform/windows/px_display.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cb4c8bf405aabdb520138355f768179a6b18a43d --- /dev/null +++ b/lib/PainterEngine/platform/windows/px_display.cpp @@ -0,0 +1,691 @@ +#include +#include +#include +#pragma comment(lib,"d2d1.lib") + +typedef struct +{ + UINT uMsg; + LPARAM lparam; + WPARAM wparam; +}WM_MESSAGE; + +extern "C" BOOL PX_CreateWindow( int windowWidth,int windowHeight, int surfaceWidth,int surfaceHeight,const char *name); +extern "C" BOOL PX_WindowResize(int surfaceWidth,int surfaceHeight,int windowWidth,int windowHeight); + +extern "C" int PX_GetScreenHeight(); +extern "C" int PX_GetScreenWidth(); +extern "C" int PX_SetWindowResizeable(); + +extern "C" HWND PX_GetWindowHwnd(); +extern "C" VOID PX_SystemReadDeviceState(); +extern "C" BOOL PX_SystemLoop(); +extern "C" BOOL PX_SystemRender(void *raw,int width,int height); +extern "C" BOOL PX_SystemisAvtivated(); +extern "C" BOOL PX_KeyboardDown(unsigned char X ); +extern "C" char *PX_KeyboardString(); +extern "C" char *PX_DragfileString(); +extern "C" BOOL PX_MouseLButtonDown(); +extern "C" BOOL PX_MouseRButtonDown(); +extern "C" BOOL PX_MouseMButtonDown(); +extern "C" POINT PX_MousePosition(); +extern "C" BOOL PX_KeyDown(unsigned char key); +extern "C" BOOL PX_MouseWheel(int *x,int *y,int *delta); +extern "C" BOOL PX_GetWinMessage(WM_MESSAGE *Msg); +extern "C" char *PX_OpenFileDialog(const char Filter[]); +extern "C" char *PX_MultFileDialog(const char Filter[]); +extern "C" char *PX_SaveFileDialog(const char Filter[],const char ext[]); +extern "C" double PX_GetWindowScale(); +#define WIN_MAX_INPUT_STRING_LEN 64 +#define WIN_MAX_INPUT_SPECKEY_LEN 0xff + + +#define WIN_KEYDOWN_BACKSPACE 1 +#define WIN_KEYDOWN_RETURN 2 +#define WIN_KEYDOWN_LEFT 3 +#define WIN_KEYDOWN_RIGHT 4 +#define WIN_KEYDOWN_UP 5 +#define WIN_KEYDOWN_DOWN 6 + + +#define WIN_MESSAGESTACK_SIZE 32 + +HWND Win_Hwnd; +int Win_Height; +int Win_Width; +double Win_Scale; +int Surface_Height; +int Surface_Width; +BOOL Win_Activated; +WM_MESSAGE Win_messageStack[WIN_MESSAGESTACK_SIZE]={0}; +unsigned char DInput_KeyBoardState[256]; +char DInput_AccepyFile[MAX_PATH]={0}; +POINT DInput_MousePosition; +POINT DInput_MouseWheelPosition; +POINT DInput_MouseWheelDelta; + + +unsigned int D2D_ColorConversion; +ID2D1Bitmap *D2D_pSurface; +ID2D1Factory* D2D_pDirect2dFactory; +ID2D1HwndRenderTarget *D2D_pRenderTarget; + + + + + +static WNDCLASSEXA Win_Wcx; + +///////////////////////////////////////////////////// +LRESULT CALLBACK AppWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); +///////////////////////////////////////////////////// + + +void DInput_Update() +{ + POINT point; + GetCursorPos(&point); + ScreenToClient(Win_Hwnd,&point); + DInput_MousePosition=point; +} + +BOOL PX_D3DReset(HWND hWnd,int Width,int Height,BOOL bfullScreen) +{ + return TRUE; +} + +int PX_GetScreenHeight() +{ + return GetSystemMetrics(SM_CYSCREEN); +} + +int PX_GetScreenWidth() +{ + return GetSystemMetrics(SM_CXSCREEN); +} + +BOOL PX_WindowResize(int surfaceWidth,int surfaceHeight,int windowWidth,int windowHeight) +{ + HRESULT hr; + D2D1_SIZE_U size; + RECT rc; + + Win_Width=windowWidth; + Win_Height=windowHeight; + + GetClientRect(Win_Hwnd, &rc); + + size.width=rc.right - rc.left; + size.height=rc.bottom - rc.top; + + hr=D2D_pRenderTarget->Resize(size); + + if (FAILED(hr)) + { + return FALSE; + } + + size = D2D1::SizeU( + surfaceWidth, + surfaceHeight + ); + + Surface_Height=surfaceHeight; + Surface_Width=surfaceWidth; + + if(D2D_pSurface) + D2D_pSurface->Release(); + + D2D1_BITMAP_PROPERTIES bitmapformat; + bitmapformat.dpiX=0; + bitmapformat.dpiY=0; + bitmapformat.pixelFormat=D2D1::PixelFormat(DXGI_FORMAT_R8G8B8A8_UNORM,D2D1_ALPHA_MODE_IGNORE); + hr=D2D_pRenderTarget->CreateBitmap(size,bitmapformat,&D2D_pSurface); + D2D_ColorConversion=0; + + if (FAILED(hr)) + { + + D2D1_BITMAP_PROPERTIES bitmapformat; + bitmapformat.dpiX=0; + bitmapformat.dpiY=0; + bitmapformat.pixelFormat=D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM,D2D1_ALPHA_MODE_IGNORE); + + hr=D2D_pRenderTarget->CreateBitmap(size,bitmapformat,&D2D_pSurface); + D2D_ColorConversion=1; + if(FAILED(hr)) + return FALSE; + } + + return TRUE; + +} +BOOL PX_CreateWindow( int surfaceWidth,int surfaceHeight,int windowWidth,int windowHeight,const char *name) +{ + HRESULT hr; + D2D1_SIZE_U size; + RECT rc; + + if (Win_Wcx.cbSize==0) + { + //////////////////////////////////////////////////////////////////////////// + // Initialize Window class struct + /////////////////////////////////////////////////////////////////////////// + Win_Wcx.cbSize = sizeof(WNDCLASSEX); + Win_Wcx.style = CS_CLASSDC; + Win_Wcx.lpfnWndProc = AppWindowProc; + Win_Wcx.cbClsExtra = 0; + Win_Wcx.cbWndExtra = 0; + Win_Wcx.hInstance = GetModuleHandle(NULL); + Win_Wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION); + Win_Wcx.hCursor = LoadCursor(NULL, IDC_ARROW); + Win_Wcx.hbrBackground = (HBRUSH)(COLOR_WINDOW); + Win_Wcx.lpszMenuName = NULL; + Win_Wcx.lpszClassName = "WindowCls"; + Win_Wcx.hIconSm = LoadIcon(NULL, IDI_APPLICATION); + + + /////////////////////////////////////////////////////////////////////////// + //Class Register + /////////////////////////////////////////////////////////////////////////// + if(!RegisterClassExA(&Win_Wcx)) + return FALSE; + } + + + Win_Width=windowWidth; + Win_Height=windowHeight; + + //////////////////////////////////////////////////////////////////////////// + //Create window + //////////////////////////////////////////////////////////////////////////// +#ifdef _UNICODE + do + { + WCHAR wname[128]={0}; + MultiByteToWideChar(CP_ACP, 0,name, (int)strlen(name), wname,128); + Win_Hwnd = CreateWindowA("WindowCls", (LPCSTR)wname, + WS_OVERLAPPED|WS_SYSMENU|WS_MAXIMIZEBOX|WS_SIZEBOX, + CW_USEDEFAULT, CW_USEDEFAULT, + Win_Width, Win_Height, + NULL, NULL, GetModuleHandle(NULL), NULL); + } while (0); +#else + Win_Hwnd = CreateWindowA("WindowCls", name, + WS_OVERLAPPED|WS_SYSMENU|WS_MAXIMIZEBOX|WS_SIZEBOX, + CW_USEDEFAULT, CW_USEDEFAULT, + Win_Width, Win_Height, + NULL, NULL, GetModuleHandle(NULL), NULL); +#endif + + + + if(!Win_Hwnd) + { + MessageBoxA(0,"create window failed","error",MB_OK); + return FALSE; + } + + + //////////////////////////////////////////////////////////////////////////// + //Show window + //////////////////////////////////////////////////////////////////////////// + ShowWindow(Win_Hwnd, SW_SHOWNORMAL); + UpdateWindow(Win_Hwnd); + //CoInitialize(NULL); + DragAcceptFiles(Win_Hwnd,TRUE); + ////////////////////////////////////////////////////////////////////////// + // + + if((Win_Hwnd) == NULL) + return FALSE; + + hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED,&D2D_pDirect2dFactory); + if (FAILED(hr)) + { + MessageBoxA(0,"could not create d2d factory","error",MB_OK); + return FALSE; + } + + GetClientRect(Win_Hwnd, &rc); + SetWindowPos(Win_Hwnd,0,0,0,windowWidth+windowWidth-(rc.right - rc.left),windowHeight+windowHeight-(rc.bottom - rc.top),SWP_NOMOVE); + GetClientRect(Win_Hwnd, &rc); + + + size.width=rc.right - rc.left; + size.height=rc.bottom - rc.top; + + hr=D2D_pDirect2dFactory->CreateHwndRenderTarget( + D2D1::RenderTargetProperties(D2D1_RENDER_TARGET_TYPE_DEFAULT, D2D1::PixelFormat(), 96.0F, 96.0F, D2D1_RENDER_TARGET_USAGE_NONE, D2D1_FEATURE_LEVEL_DEFAULT), + D2D1::HwndRenderTargetProperties(Win_Hwnd, size), + &D2D_pRenderTarget + ); + + if (FAILED(hr)) + { + MessageBoxA(0,"could not create d2d render target","error",MB_OK); + return FALSE; + } + + + size = D2D1::SizeU( + surfaceWidth, + surfaceHeight + ); + Surface_Height=surfaceHeight; + Surface_Width=surfaceWidth; + + + + D2D1_BITMAP_PROPERTIES bitmapformat; + bitmapformat.dpiX=0; + bitmapformat.dpiY=0; + bitmapformat.pixelFormat=D2D1::PixelFormat(DXGI_FORMAT_R8G8B8A8_UNORM,D2D1_ALPHA_MODE_IGNORE); + hr=D2D_pRenderTarget->CreateBitmap(size,bitmapformat,&D2D_pSurface); + D2D_ColorConversion=0; + + if (FAILED(hr)) + { + + D2D1_BITMAP_PROPERTIES bitmapformat; + bitmapformat.dpiX=0; + bitmapformat.dpiY=0; + bitmapformat.pixelFormat=D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM,D2D1_ALPHA_MODE_IGNORE); + + hr=D2D_pRenderTarget->CreateBitmap(size,bitmapformat,&D2D_pSurface); + D2D_ColorConversion=1; + if(FAILED(hr)) + return FALSE; + } + + + if (FAILED(hr)) + { + MessageBoxA(0,"could not create d2d bitmap","error",MB_OK); + return FALSE; + } + + PX_GetWindowScale(); + return TRUE; +} +///////////////////////////////////////////////////////////// +char Win_Str[WIN_MAX_INPUT_STRING_LEN]={0}; +char Win_SpecKey[WIN_MAX_INPUT_SPECKEY_LEN]={0}; +int Win_CurrentIndex=0; +#include "stdio.h" +LRESULT CALLBACK AppWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + +// if(uMsg==0x246) +// printf("%x\n",uMsg); + WM_MESSAGE message; + int i; + + switch(uMsg) + { + case WM_MOUSEMOVE: + case WM_MBUTTONDOWN: + case WM_MBUTTONUP: + case WM_LBUTTONDOWN: + case WM_LBUTTONUP: + case WM_RBUTTONDOWN: + case WM_RBUTTONUP: + break; + case WM_KILLFOCUS: + { + Win_Activated=FALSE; + } + break; + case WM_SETFOCUS: + { + Win_Activated=TRUE; + } + break; + case WM_KEYDOWN: + { + Win_SpecKey[wParam]=1; + } + break; + case WM_MOUSEWHEEL: + { + DInput_MouseWheelPosition.x=GET_X_LPARAM(lParam); + DInput_MouseWheelPosition.y=GET_Y_LPARAM(lParam); + DInput_MouseWheelDelta.x=0; + DInput_MouseWheelDelta.y=GET_WHEEL_DELTA_WPARAM(wParam); + } + break; + case WM_CHAR: + { + if(Win_CurrentIndex=32||wParam==8) + { + Win_Str[Win_CurrentIndex++]=(char)wParam; + Win_Str[Win_CurrentIndex]='\0'; + } + } + } + break; + case WM_DROPFILES: + { + HDROP hdrop = (HDROP)wParam; + DragQueryFileA(hdrop, 0, DInput_AccepyFile, MAX_PATH); + DragFinish(hdrop); + } + break; + case WM_CLOSE: + { + PostQuitMessage(0); + exit(0); + } + break; + case WM_DESTROY: + { + PostQuitMessage(0); + return 0; + } + break; + case WM_SIZE: + { + + } + break; + default: return DefWindowProc(hWnd,uMsg,wParam,lParam); + } + + message.uMsg=uMsg; + message.wparam=wParam; + message.lparam=lParam; + for (i=0;iBeginDraw(); + D2D_pRenderTarget->Clear(); + if (D2D_ColorConversion) + { + int i; + DWORD *pData=(DWORD *)raw; + for (i=0;i>16)&0x000000FF)+((pData[i]<<16)&0x00FF0000); + } + } + D2D_pSurface->CopyFromMemory(&size,raw,width*sizeof(DWORD)); + D2D_pRenderTarget->DrawBitmap(D2D_pSurface,screenSize); + D2D_pRenderTarget->EndDraw(); + + return TRUE; +} + +BOOL PX_SystemisAvtivated() +{ + return Win_Activated; +} + +BOOL PX_KeyboardDown(unsigned char X) +{ + return (DInput_KeyBoardState[X]&0x80?TRUE:FALSE); +} + +BOOL PX_MouseLButtonDown() +{ + return GetAsyncKeyState(VK_LBUTTON) & 0xFF00; +} + +BOOL PX_MouseRButtonDown() +{ + return GetAsyncKeyState(VK_RBUTTON) & 0xFF00; +} + +BOOL PX_MouseMButtonDown() +{ + return GetAsyncKeyState(VK_MBUTTON) & 0xFF00; +} + +POINT PX_MousePosition() +{ + return DInput_MousePosition; +} + +char * PX_KeyboardString() +{ + if(Win_CurrentIndex!=0) + { + Win_CurrentIndex=0; + return Win_Str; + } + else + { + return 0; + } +} + +VOID PX_SystemReadDeviceState() +{ + DInput_Update(); +} + +char * PX_DragfileString() +{ + return DInput_AccepyFile; +} + +HWND PX_GetWindowHwnd() +{ + return Win_Hwnd; +} + +BOOL PX_KeyDown(unsigned char key) +{ + if (Win_SpecKey[key]) + { + Win_SpecKey[key]=0; + return TRUE; + } + return FALSE; +} + +BOOL PX_MouseWheel(int *x,int *y,int *delta) +{ + if (DInput_MouseWheelDelta.y!=0) + { + *x=DInput_MouseWheelPosition.x; + *y=DInput_MouseWheelPosition.y; + *delta=DInput_MouseWheelDelta.y; + DInput_MouseWheelDelta.y=0; + return TRUE; + } + return FALSE; +} + +BOOL PX_GetWinMessage(WM_MESSAGE *Msg) +{ + int i; + for (i=0;i=0) + { + if (szFile[oft]=='\\'||szFile[oft]=='/') + { + szFile[oft]=0; + break; + } + oft--; + } + } + return szFile; + } + return NULL; +} + +char *PX_SaveFileDialog(const char Filter[],const char ext[]) +{ + OPENFILENAMEA ofn; + static char szFile[MAX_PATH]; + ZeroMemory(&ofn,sizeof(ofn)); + ofn.lStructSize = sizeof(ofn); + ofn.lpstrFile = szFile; + ofn.lpstrFile[0] = TEXT('\0'); + ofn.nMaxFile = sizeof(szFile); + ofn.lpstrFilter = Filter;//TEXT("MirrorÎļþ(.mirror)\0*.mirror"); + ofn.nFilterIndex = 1; + ofn.lpstrFileTitle = NULL; + ofn.nMaxFileTitle = 0; + ofn.lpstrInitialDir = NULL; + ofn.hwndOwner = Win_Hwnd; + ofn.Flags = OFN_EXPLORER |OFN_PATHMUSTEXIST |OFN_NOCHANGEDIR; + + if (GetSaveFileNameA(&ofn)) + { + if (ext) + { + char uprFile[MAX_PATH]={0}; + char uprExt[MAX_PATH]={0}; + strcpy_s(uprExt,ext); + _strupr_s(uprExt,MAX_PATH); + strcpy_s(uprFile,szFile); + _strupr_s(uprFile,MAX_PATH); + if (!strstr(uprFile,uprExt)) + { + strcat_s(szFile,sizeof(szFile),ext); + } + } + return szFile; + } + return NULL; +} + + + + +int PX_SetWindowResizeable() +{ + return SetWindowLong(Win_Hwnd,GWL_STYLE,WS_OVERLAPPED|WS_SYSMENU); +} + +double PX_GetWindowScale() +{ + + HWND hWnd = GetDesktopWindow(); + HMONITOR hMonitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST); + + + MONITORINFOEX miex; + miex.cbSize = sizeof(miex); + GetMonitorInfo(hMonitor, &miex); + int cxLogical = (miex.rcMonitor.right - miex.rcMonitor.left); + int cyLogical = (miex.rcMonitor.bottom - miex.rcMonitor.top); + + + DEVMODE dm; + dm.dmSize = sizeof(dm); + dm.dmDriverExtra = 0; + EnumDisplaySettings(miex.szDevice, ENUM_CURRENT_SETTINGS, &dm); + int cxPhysical = dm.dmPelsWidth; + int cyPhysical = dm.dmPelsHeight; + + + double horzScale = ((double)cxPhysical / (double)cxLogical); + double vertScale = ((double)cyPhysical / (double)cyLogical); + + Win_Scale=horzScale; + return horzScale; +} diff --git a/lib/PainterEngine/platform/windows/px_display.h b/lib/PainterEngine/platform/windows/px_display.h new file mode 100644 index 0000000000000000000000000000000000000000..02a13571c5238158ae1a3156af19f883ab926ed8 --- /dev/null +++ b/lib/PainterEngine/platform/windows/px_display.h @@ -0,0 +1,46 @@ +#ifndef PX_PLATFORM_WINDOWS +#define PX_PLATFORM_WINDOWS + +#include +#include "stdio.h" +#include "time.h" +#pragma comment(lib,"User32.lib") +#pragma comment(lib,"Shell32.lib") +#pragma comment(lib,"Ole32.lib") +#pragma comment(lib,"winmm.lib" ) + + +typedef struct +{ + UINT uMsg; + LPARAM lparam; + WPARAM wparam; +}WM_MESSAGE; + +extern BOOL PX_CreateWindow( int surfaceWidth,int surfaceHeight,int windowWidth,int windowHeight, const char *name); +extern BOOL PX_WindowResize(int surfaceWidth,int surfaceHeight,int windowWidth,int windowHeight); +extern int PX_GetScreenHeight(); +extern int PX_GetScreenWidth(); +extern int PX_SetWindowResizeable(); + +extern HWND PX_GetWindowHwnd(); +extern VOID PX_SystemReadDeviceState(); +extern BOOL PX_SystemLoop(); +extern BOOL PX_SystemRender(void *raw,int width,int height); +extern BOOL PX_SystemisAvtivated(); +extern BOOL PX_KeyboardDown(unsigned char X ); +extern char *PX_KeyboardString(); +extern char *PX_DragfileString(); +extern BOOL PX_MouseLButtonDown(); +extern BOOL PX_MouseRButtonDown(); +extern BOOL PX_MouseMButtonDown(); +extern POINT PX_MousePosition(); +extern BOOL PX_KeyDown(unsigned char key); +extern BOOL PX_MouseWheel(int *x,int *y,int *delta); +extern BOOL PX_GetWinMessage(WM_MESSAGE *Msg); +extern double PX_GetWindowScale(); + +extern char *PX_OpenFileDialog(const char Filter[]); +extern char *PX_MultFileDialog(const char Filter[]); +extern char *PX_SaveFileDialog(const char Filter[],const char ext[]); +#endif \ No newline at end of file diff --git a/lib/PainterEngine/platform/windows/px_file.c b/lib/PainterEngine/platform/windows/px_file.c new file mode 100644 index 0000000000000000000000000000000000000000..63b42ba2bc7c37bb2f6edcf3c8ba6ca2ff1c1842 --- /dev/null +++ b/lib/PainterEngine/platform/windows/px_file.c @@ -0,0 +1,351 @@ + +#include "../modules/px_file.h" +#include "stdio.h" +#include "stdlib.h" +#include "string.h" +#include "windows.h" + +int PX_SaveDataToFile(void *buffer,int size,const char path[]) +{ + char _path[MAX_PATH]; + FILE *pf; + if (path[0]=='\\'||path[0]=='/') + { + strcpy_s(_path,sizeof(_path),path+1); + } + else + { + strcpy_s(_path,sizeof(_path),path); + } + fopen_s(&pf,_path,"wb"); + if (pf) + { + fwrite(buffer,1,size,pf); + fclose(pf); + return 1; + } + return 0; +} + + + +PX_IO_Data PX_LoadFileToIOData(const char path[]) +{ + PX_IO_Data io; + int fileoft=0; + FILE *pf; + int filesize; + char _path[MAX_PATH]; + if (path[0]=='\\'||path[0]=='/') + { + strcpy_s(_path,sizeof(_path),path+1); + } + else + { + strcpy_s(_path,sizeof(_path),path); + } + + fopen_s(&pf,_path,"rb"); + if (!pf) + { + goto _ERROR; + } + + fseek(pf,0,SEEK_END); + filesize=ftell(pf); + fseek(pf,0,SEEK_SET); + + io.buffer=(unsigned char *)malloc(filesize+1); + if (!io.buffer) + { + goto _ERROR; + } + + while (!feof(pf)) + { + fileoft+=(int)fread(io.buffer+fileoft,1,1024,pf); + } + fclose(pf); + + io.buffer[filesize]='\0'; + io.size=filesize; + return io; +_ERROR: + io.buffer=0; + io.size=0; + return io; +} + +void PX_FreeIOData(PX_IO_Data *io) +{ + if (io->size&&io->buffer) + { + free(io->buffer); + io->size=0; + io->buffer=0; + } +} + +int PX_FileExist(const char path[]) +{ + char _path[MAX_PATH]; + FILE *pf; + if (path[0]=='\\'||path[0]=='/') + { + strcpy_s(_path,sizeof(_path),path+1); + } + else + { + strcpy_s(_path,sizeof(_path),path); + } + + fopen_s(&pf,_path,"rb");; + if (pf) + { + fclose(pf); + return 1; + } + return 0; +} + + + + +int PX_FileGetDirectoryFileCount(const char path[],PX_FILEENUM_TYPE type,const char *filter) +{ + HANDLE hFind; + int count=0; + WIN32_FIND_DATAA FindFileData; + char _findpath[MAX_PATH]; + + if (path[0]==0||(path[0]=='\\'&&path[1]=='\0')||(path[0]=='/'&&path[1]=='\0')) + { + if (type==PX_FILEENUM_TYPE_FILE) + { + return 0; + } + if (type==PX_FILEENUM_TYPE_FOLDER) + { + char drivers[128]; + int index=0; + if(GetLogicalDriveStringsA(128,drivers)) + { + while (drivers[index]) + { + count++; + index+= (int)(strlen(drivers))+1; + } + } + return count; + } + } + if (path[0]=='\\'||path[0]=='/') + { + strcpy_s(_findpath,sizeof(_findpath),path+1); + } + else + { + strcpy_s(_findpath,sizeof(_findpath),path); + } + + if (_findpath[strlen(path)-1]!='/'&&_findpath[strlen(path)-1]!='\\') + { + strcat_s(_findpath,sizeof(_findpath),"/"); + } + strcat_s(_findpath,sizeof(_findpath),"*.*"); + + hFind = FindFirstFileA(_findpath,&FindFileData); + if (hFind==INVALID_HANDLE_VALUE) + { + return 0; + } + do + { + switch (type) + { + case PX_FILEENUM_TYPE_ANY: + { + if (filter[0]&&FindFileData.dwFileAttributes !=FILE_ATTRIBUTE_DIRECTORY) + { + const char *pFilter=filter; + while (pFilter[0]) + { + if (strstr(FindFileData.cFileName,pFilter)) + { + count++; + break; + } + pFilter+=strlen(pFilter)+1; + } + + } else + { + count++; + } + } + break; + case PX_FILEENUM_TYPE_DEVICE: + case PX_FILEENUM_TYPE_FILE: + { + if (FindFileData.dwFileAttributes !=FILE_ATTRIBUTE_DIRECTORY) + { + if (filter[0]) + { + const char *pFilter=filter; + while (pFilter[0]) + { + if (strstr(FindFileData.cFileName,pFilter)) + { + count++; + break; + } + pFilter+=strlen(pFilter)+1; + + } + } else + { + count++; + } + } + } + break; + case PX_FILEENUM_TYPE_FOLDER: + { + if (FindFileData.dwFileAttributes ==FILE_ATTRIBUTE_DIRECTORY) + { + count++; + } + } + break; + default: + break; + } + } while (FindNextFileA(hFind,&FindFileData)); + FindClose(hFind); + return count; +} + +int PX_FileGetDirectoryFileName(const char path[],int count,char FileName[][260],PX_FILEENUM_TYPE type,const char *filter) +{ + HANDLE hFind; + int index=0; + WIN32_FIND_DATAA FindFileData; + static char _findpath[MAX_PATH]; + + if (path[0]==0||(path[0]=='\\'&&path[1]=='\0')||(path[0]=='/'&&path[1]=='\0')) + { + int dcount=0; + if (type==PX_FILEENUM_TYPE_FILE) + { + return 0; + } + if (type==PX_FILEENUM_TYPE_FOLDER) + { + char drivers[128]; + int index=0; + if(GetLogicalDriveStringsA(128,drivers)) + { + while (drivers[index]) + { + strcpy_s(FileName[dcount],260,drivers+index); + dcount++; + index+=(int)(strlen(drivers)+1); + } + } + return dcount; + } + } + + if (path[0]=='\\'||path[0]=='/') + { + strcpy_s(_findpath,sizeof(_findpath),path+1); + } + else + { + strcpy_s(_findpath,sizeof(_findpath),path); + } + + if (_findpath[strlen(path)-1]!='/'&&_findpath[strlen(path)-1]!='\\') + { + strcat_s(_findpath,sizeof(_findpath),"/"); + } + strcat_s(_findpath,sizeof(_findpath),"*.*"); + + hFind = FindFirstFileA(_findpath,&FindFileData); + if (hFind==INVALID_HANDLE_VALUE) + { + return 0; + } + do + { + if (index>=count) + { + break; + } + + switch (type) + { + case PX_FILEENUM_TYPE_ANY: + { + if (filter[0]&&FindFileData.dwFileAttributes !=FILE_ATTRIBUTE_DIRECTORY) + { + const char *pFilter=filter; + while (pFilter[0]) + { + if (strstr(FindFileData.cFileName,pFilter)) + { + strcpy_s(FileName[index],260,FindFileData.cFileName); + index++; + break; + } + pFilter+=strlen(pFilter)+1; + } + } else + { + strcpy_s(FileName[index],260,FindFileData.cFileName); + index++; + } + } + break; + case PX_FILEENUM_TYPE_DEVICE: + case PX_FILEENUM_TYPE_FILE: + { + if (FindFileData.dwFileAttributes !=FILE_ATTRIBUTE_DIRECTORY) + { + if (filter[0]) + { + const char *pFilter=filter; + while (pFilter[0]) + { + if (strstr(FindFileData.cFileName,pFilter)) + { + strcpy_s(FileName[index],260,FindFileData.cFileName); + index++; + break; + } + pFilter+=strlen(pFilter)+1; + } + } else + { + strcpy_s(FileName[index],260,FindFileData.cFileName); + index++; + } + } + } + break; + case PX_FILEENUM_TYPE_FOLDER: + { + if (FindFileData.dwFileAttributes ==FILE_ATTRIBUTE_DIRECTORY) + { + strcpy_s(FileName[index],260,FindFileData.cFileName); + index++; + } + } + break; + default: + break; + } + } while (FindNextFileA(hFind,&FindFileData)); + FindClose(hFind); + return index; +} \ No newline at end of file diff --git a/lib/PainterEngine/platform/windows/px_main.c b/lib/PainterEngine/platform/windows/px_main.c new file mode 100644 index 0000000000000000000000000000000000000000..0d185c8d35a8249962a0a5e751a08f8d1db7be07 --- /dev/null +++ b/lib/PainterEngine/platform/windows/px_main.c @@ -0,0 +1,323 @@ + +//Platform supports +#include "PainterEngine_Application.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#include "px_display.h" + +#ifdef __cplusplus +} +#endif + +//mouse informations +POINT main_zoomPoint; +px_int main_ZoomRegion; + +volatile px_bool main_exit=0; +////////////////////////////////////////////////////////////////////////// +DWORD WINAPI DEMO_RenderThreadFunc(LPVOID p) +{ + DWORD time,elapsed; + PX_Object_Event e; + WM_MESSAGE msg; + static POINT LastDownPoint; + px_float cursorx=-1,cursory=-1,cursorz=-1; + px_float cursorx_scale,cursory_scale; + + LastDownPoint.x=-1; + LastDownPoint.y=-1; + + /* px_char *keyBoardString;*/ + ////////////////////////////////////////////////////////////////////////// + //CreateWindow + + time=timeGetTime(); + + while(1) + { + + PX_SystemReadDeviceState(); + + elapsed=timeGetTime()-time; + time=timeGetTime(); + + cursorx_scale=App.runtime.surface_width*1.0f/App.runtime.window_width; + cursory_scale=App.runtime.surface_height*1.0f/App.runtime.window_height; + + while (PX_GetWinMessage(&msg)) + { + px_char text[2]={0}; + e.Event=PX_OBJECT_EVENT_ANY; + switch(msg.uMsg) + { + case WM_SIZE: + { + px_float width=(px_float)((msg.lparam)&0xffff); + px_float height=(px_float)((msg.lparam>>16)&0xffff); + e.Event=PX_OBJECT_EVENT_WINDOWRESIZE; + PX_Object_Event_SetWidth(&e,width); + PX_Object_Event_SetHeight(&e,height); + + if (width!=0&&height!=0) + { + PX_ApplicationPostEvent(&App,e); + PX_WindowResize(App.runtime.surface_width,App.runtime.surface_height,(px_int)width, (px_int)height); + } + else + { + + } + + continue; + + } + break; + case WM_MOUSEMOVE: + { + if (msg.wparam&MK_LBUTTON) + { + e.Event=PX_OBJECT_EVENT_CURSORDRAG; + } + else + { + e.Event=PX_OBJECT_EVENT_CURSORMOVE; + } + + cursorx=(px_float)((msg.lparam)&0xffff); + cursory=(px_float)((msg.lparam>>16)&0xffff); + + PX_Object_Event_SetCursorX(&e,cursorx*cursorx_scale); + PX_Object_Event_SetCursorY(&e,cursory*cursory_scale); + } + break; + case WM_LBUTTONDOWN: + { + e.Event=PX_OBJECT_EVENT_CURSORDOWN; + cursorx=(px_float)((msg.lparam)&0xffff); + cursory=(px_float)((msg.lparam>>16)&0xffff); + PX_Object_Event_SetCursorX(&e,cursorx*cursorx_scale); + PX_Object_Event_SetCursorY(&e,cursory*cursory_scale); + + LastDownPoint.x=((msg.lparam)&0xffff); + LastDownPoint.y=((msg.lparam>>16)&0xffff); + } + break; + case WM_LBUTTONUP: + { + if (((msg.lparam)&0xffff)==LastDownPoint.x&&((msg.lparam>>16)&0xffff)==LastDownPoint.y) + { + e.Event=PX_OBJECT_EVENT_CURSORCLICK; + cursorx=(px_float)((msg.lparam)&0xffff); + cursory=(px_float)((msg.lparam>>16)&0xffff); + PX_Object_Event_SetCursorX(&e,cursorx*cursorx_scale); + PX_Object_Event_SetCursorY(&e,cursory*cursory_scale); + + LastDownPoint.x=-1; + LastDownPoint.y=-1; + PX_ApplicationPostEvent(&App,e); + } + e.Event=PX_OBJECT_EVENT_CURSORUP; + + cursorx=(px_float)((msg.lparam)&0xffff); + cursory=(px_float)((msg.lparam>>16)&0xffff); + PX_Object_Event_SetCursorX(&e,cursorx*cursorx_scale); + PX_Object_Event_SetCursorY(&e,cursory*cursory_scale); + } + break; + case WM_RBUTTONDOWN: + { + e.Event=PX_OBJECT_EVENT_CURSORRDOWN; + cursorx=(px_float)((msg.lparam)&0xffff); + cursory=(px_float)((msg.lparam>>16)&0xffff); + PX_Object_Event_SetCursorX(&e,cursorx*cursorx_scale); + PX_Object_Event_SetCursorY(&e,cursory*cursory_scale); + } + break; + case WM_RBUTTONUP: + { + e.Event=PX_OBJECT_EVENT_CURSORRUP; + cursorx=(px_float)((msg.lparam)&0xffff); + cursory=(px_float)((msg.lparam>>16)&0xffff); + PX_Object_Event_SetCursorX(&e,cursorx*cursorx_scale); + PX_Object_Event_SetCursorY(&e,cursory*cursory_scale); + } + break; + case WM_MBUTTONDOWN: + { + e.Event = PX_OBJECT_EVENT_CURSORMDOWN; + cursorx = (px_float)((msg.lparam) & 0xffff); + cursory = (px_float)((msg.lparam >> 16) & 0xffff); + PX_Object_Event_SetCursorX(&e, cursorx * cursorx_scale); + PX_Object_Event_SetCursorY(&e, cursory * cursory_scale); + } + break; + case WM_MBUTTONUP: + { + e.Event = PX_OBJECT_EVENT_CURSORMUP; + cursorx = (px_float)((msg.lparam) & 0xffff); + cursory = (px_float)((msg.lparam >> 16) & 0xffff); + PX_Object_Event_SetCursorX(&e, cursorx * cursorx_scale); + PX_Object_Event_SetCursorY(&e, cursory * cursory_scale); + } + break; + + case WM_KEYDOWN: + { + e.Event=PX_OBJECT_EVENT_KEYDOWN; + PX_Object_Event_SetKeyDown(&e,(px_uint)msg.wparam); + } + break; + case WM_MOUSEWHEEL: + { + RECT rect,crect; + GetClientRect(PX_GetWindowHwnd(),&crect); + GetWindowRect(PX_GetWindowHwnd(),&rect); + e.Event=PX_OBJECT_EVENT_CURSORWHEEL; + cursorx=(px_float)((msg.lparam)&0xffff)-rect.left; + cursory=(px_float)((msg.lparam>>16)&0xffff)-rect.top-((rect.bottom-rect.top)-crect.bottom)+2; + cursorz=(px_float)((px_short)((msg.wparam>>16)&0xffff)); + PX_Object_Event_SetCursorX(&e,cursorx*cursorx_scale); + PX_Object_Event_SetCursorY(&e,cursory*cursory_scale); + PX_Object_Event_SetCursorZ(&e,cursorz); + + } + break; + case WM_CHAR: + { + text[0]=(px_char)msg.wparam; + e.Event=PX_OBJECT_EVENT_STRING; + PX_Object_Event_SetStringPtr(&e,text); + } + break; + /* + case WM_GESTURE: + { + GESTUREINFO gi; + BOOL bHandled; + BOOL bResult; + ZeroMemory(&gi, sizeof(GESTUREINFO)); + + gi.cbSize = sizeof(GESTUREINFO); + + bResult = GetGestureInfo((HGESTUREINFO)msg.lparam, &gi); + bHandled = FALSE; + + if (bResult){ + // now interpret the gesture + switch (gi.dwID){ + case GID_ZOOM: + // Code for zooming goes here + + if (25>(main_zoomPoint.x-gi.ptsLocation.x)*(main_zoomPoint.x-gi.ptsLocation.x)+(main_zoomPoint.y-gi.ptsLocation.y)*(main_zoomPoint.y-gi.ptsLocation.y)) + { + e.Event=PX_OBJECT_EVENT_SCALE; + PX_Object_Event_SetScaleCursorX(&e,(px_float)gi.ptsLocation.x); + PX_Object_Event_SetScaleCursorY(&e,(px_float)gi.ptsLocation.y); + PX_Object_Event_SetScaleCursorZ(&e,(px_float)(gi.ullArguments-main_ZoomRegion)); + } + + main_zoomPoint.x=gi.ptsLocation.x; + main_zoomPoint.y=gi.ptsLocation.y; + main_ZoomRegion=(px_int)gi.ullArguments; + + bHandled = TRUE; + break; + case GID_PAN: + // Code for panning goes here + bHandled = TRUE; + break; + case GID_ROTATE: + // Code for rotation goes here + bHandled = TRUE; + break; + case GID_TWOFINGERTAP: + // Code for two-finger tap goes here + bHandled = TRUE; + break; + case GID_PRESSANDTAP: + // Code for roll over goes here + bHandled = TRUE; + break; + default: + // A gesture was not recognized + break; + } + CloseGestureInfoHandle((HGESTUREINFO)msg.lparam); + }else{ + DWORD dwErr = GetLastError(); + if (dwErr > 0){ + //MessageBoxW(hWnd, L"Error!", L"Could not retrieve a GESTUREINFO structure.", MB_OK); + } + } + } + break; + */ + default: + continue; + } + + if(e.Event!=PX_OBJECT_EVENT_ANY) + { + PX_ApplicationPostEvent(&App,e); + } + + } + PX_ApplicationUpdate(&App,elapsed); + PX_ApplicationRender(&App,elapsed); + PX_SystemRender(App.runtime.RenderSurface.surfaceBuffer,App.runtime.surface_width,App.runtime.surface_height); + Sleep(0); + } + return 0; +} + +void setCurrentDirectory() +{ + px_char szExeFilePathFileName[MAX_PATH]; + px_char path[MAX_PATH]; + GetModuleFileNameA(NULL, szExeFilePathFileName, MAX_PATH); + PX_FileGetPath(szExeFilePathFileName,path,sizeof(path)); + if (path[PX_strlen(path)-1]==':') + { + PX_strcat(path,"\\"); + } + + SetCurrentDirectoryA(path); +} + +#ifdef _DEBUG + int main() +#else + int WINAPI WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in LPSTR lpCmdLine, __in int nShowCmd ) +#endif +{ + HANDLE hThread; + DWORD threadId; + + setCurrentDirectory(); + PX_srand(time(NULL)); + if(!PX_ApplicationInitialize(&App,PX_GetScreenWidth(),PX_GetScreenHeight()))return 0; + if(!PX_CreateWindow(App.runtime.surface_width,App.runtime.surface_height,App.runtime.window_width,App.runtime.window_height,PX_APPLICATION_NAME)) + { + return 0; + } + +#ifdef PX_AUDIO_H + do + { + extern int PX_AudioInitializeEx(); + if(!PX_AudioInitializeEx())return 0; + } while (0); +#endif + ////////////////////////////////////////////////////////////////////////// + //CreateThread + + hThread = CreateThread(NULL, 0, DEMO_RenderThreadFunc, 0, 0, &threadId); + + while(PX_SystemLoop()&&!main_exit){}; + + return 0; +} + diff --git a/lib/PainterEngine/platform/windows/px_serialport.c b/lib/PainterEngine/platform/windows/px_serialport.c new file mode 100644 index 0000000000000000000000000000000000000000..e2c9d96430b15e3809a4182338ba2bb949e0af93 --- /dev/null +++ b/lib/PainterEngine/platform/windows/px_serialport.c @@ -0,0 +1,273 @@ + +#include "../modules/px_serialPort.h" +#include "windows.h" +const char* PX_SerialPortEnumComName(int index) +{ + static char szPortName[25]; + HKEY hKey; + CHAR Name[25]; + LONG Status; + DWORD dwIndex = 0; + DWORD dwName; + DWORD dwSizeofPortName; + DWORD Type; + + //RegDisableReflectionKey(HKEY_LOCAL_MACHINE); + LPCSTR data_Set="HARDWARE\\DEVICEMAP\\SERIALCOMM\\"; + long ret0 = (RegOpenKeyExA(HKEY_LOCAL_MACHINE, data_Set, 0, KEY_READ, &hKey)); + if(ret0 != ERROR_SUCCESS) + { + return 0; + } + + do + { + dwName = sizeof(Name); + dwSizeofPortName = sizeof(szPortName); + + Status = RegEnumValueA(hKey, dwIndex, Name, &dwName, NULL, &Type, + (LPBYTE)szPortName, &dwSizeofPortName); + + if((Status == ERROR_SUCCESS)||(Status == ERROR_MORE_DATA)) + { + if (dwIndex==index) + { + return szPortName; + } + } + dwIndex++; + } while((Status == ERROR_SUCCESS)||(Status == ERROR_MORE_DATA)); + RegCloseKey(hKey); + return NULL; +} + +const BOOL PX_SerialPortInitialize(PX_SerialPort *com,const char *name,unsigned int baudRate,unsigned int DataBits,char ParityType,unsigned int stopBit) +{ + COMMTIMEOUTS CommTimeouts; + DCB dcb; + + if (strlen(name)>4&&strlen(name)<6) + { + char comName[16]="\\\\.\\"; + strcat_s(comName,16,name); + com->Handle=(long long)CreateFileA(comName, + GENERIC_READ | GENERIC_WRITE, + 0, /** Share mode,No share if zero */ + NULL, /** */ + OPEN_EXISTING, /** This device should be existing */ + 0, + 0); + } + else + { + com->Handle=(long long)CreateFileA(name, + GENERIC_READ | GENERIC_WRITE, + 0, /** Share mode,No share if zero */ + NULL, /** */ + OPEN_EXISTING, /** This device should be existing */ + 0, + 0); + } + + + if (com->Handle==-1) + { + goto _ERROR; + } + + + CommTimeouts.ReadIntervalTimeout = 0; + CommTimeouts.ReadTotalTimeoutMultiplier = 0; + CommTimeouts.ReadTotalTimeoutConstant = 0; + CommTimeouts.WriteTotalTimeoutMultiplier = 0; + CommTimeouts.WriteTotalTimeoutConstant = 0; + + if(!SetCommTimeouts((HANDLE)com->Handle, &CommTimeouts)) + { + goto _ERROR; + } + + if(!GetCommState((HANDLE)com->Handle, &dcb)) + { + goto _ERROR; + } + + //Setup BCD + dcb.DCBlength = sizeof(DCB); + dcb.ByteSize=DataBits; + dcb.BaudRate=baudRate; + dcb.StopBits=stopBit-1; + switch (ParityType) + { + default: + case 'N': + case 'n': + dcb.Parity=NOPARITY ; + break; + case 'O': + case 'o': + dcb.Parity=ODDPARITY; + break; + case 'E': + case 'e': + dcb.Parity=EVENPARITY; + break; + case 'M': + case 'm': + dcb.Parity=MARKPARITY; + break; + } + + dcb.fRtsControl = RTS_CONTROL_ENABLE; + + com->BaudRate=baudRate; + com->DataBits=DataBits; + com->ParityType=ParityType; + com->StopBit=stopBit; + + + if(!SetCommState((HANDLE)com->Handle, &dcb)) + { + goto _ERROR; + } + + return 1; +_ERROR: + CloseHandle((HANDLE)com->Handle); + return 0; +} + +const int PX_SerialPortReset(PX_SerialPort *com,unsigned int baudRate,unsigned int DataBits,char ParityType,unsigned int stopBit) +{ + DCB dcb; + + if(!GetCommState((HANDLE)com->Handle, &dcb)) + { + goto _ERROR; + } + + dcb.ByteSize=DataBits; + dcb.BaudRate=baudRate; + dcb.StopBits=stopBit-1; + switch (ParityType) + { + default: + case 'N': + case 'n': + dcb.Parity=NOPARITY ; + break; + case 'O': + case 'o': + dcb.Parity=ODDPARITY; + break; + case 'E': + case 'e': + dcb.Parity=EVENPARITY; + break; + case 'M': + case 'm': + dcb.Parity=MARKPARITY; + break; + } + dcb.fRtsControl = RTS_CONTROL_ENABLE; + + com->BaudRate=baudRate; + com->DataBits=DataBits; + com->ParityType=ParityType; + com->StopBit=stopBit; + + if(!SetCommState((HANDLE)com->Handle, &dcb)) + { + goto _ERROR; + } + + return 1; +_ERROR: + CloseHandle((HANDLE)com->Handle); + return 0; +} + + + +size_t PX_SerialPortGetBufferBytes(PX_SerialPort *com) +{ + DWORD dwError = 0; + COMSTAT comstat; + UINT BytesInQue = 0; + + memset(&comstat, 0, sizeof(COMSTAT)); + + + if ( ClearCommError((HANDLE)com->Handle, &dwError, &comstat) ) + { + BytesInQue = comstat.cbInQue; + } + + return BytesInQue; +} + +const int PX_SerialPortWrite(PX_SerialPort *com,void *data,int size) +{ + DWORD WriteSize=0; + + if (com->Handle==-1) + { + return 0; + } + + + if (!WriteFile((HANDLE)com->Handle, data, size, &WriteSize, NULL)) + { + DWORD dwError = GetLastError(); + PurgeComm((HANDLE)com->Handle, PURGE_RXCLEAR | PURGE_RXABORT); + return WriteSize; + } + return WriteSize; +} + +const int PX_SerialPortRead(PX_SerialPort *com,void *data,int size) +{ + int Offset; + int QueSize; + DWORD rSize; + + if(com->Handle!=-1) + { + int BytesInQue = (int)PX_SerialPortGetBufferBytes(com); + + /*if Buffer is empty,sleep 10ms*/ + if ( BytesInQue == 0 ) + { + return 0; + } + + Offset=0; + QueSize=BytesInQue; + + if (QueSize>size) + { + QueSize=size; + BytesInQue=QueSize; + } + + while(QueSize>0) + { + ReadFile((HANDLE)com->Handle,(char *)data+Offset,QueSize,&rSize,NULL); + Offset+=rSize; + QueSize-=rSize; + } + return Offset; + } + return 0; +} + +void PX_SerialPortClose(PX_SerialPort *com) +{ + if (com->Handle!=0&&com->Handle!=-1) + { + CloseHandle((HANDLE)com->Handle); + com->Handle=0; + } + +} + diff --git a/lib/PainterEngine/platform/windows/px_tcp.c b/lib/PainterEngine/platform/windows/px_tcp.c new file mode 100644 index 0000000000000000000000000000000000000000..b8780e8b396bc3c5fb10dc4e7d294aa631cf1c18 --- /dev/null +++ b/lib/PainterEngine/platform/windows/px_tcp.c @@ -0,0 +1,216 @@ + +#include "../modules/px_tcp.h" + +#pragma comment(lib,"ws2_32.lib") // Platform of MSVC +#pragma comment( lib,"winmm.lib" ) + +#include //header +#include +#include +#include "stdio.h" + + +int PX_TCPInitialize(PX_TCP *tcp,PX_TCP_IP_TYPE type) +{ + WORD wVersionRequested; + WSADATA wsaData; + int err; + int nZero=0; + int nRecvBuf=1024*1024*2; + int nSendBuf=1024*1024*2; + int optval=TRUE; + + tcp->type=type; + + wVersionRequested = MAKEWORD( 1, 1 ); + err = WSAStartup( wVersionRequested, &wsaData ); + if ( err != 0 ) { + + return 0; + } + + if ( LOBYTE( wsaData.wVersion ) != 1 || + HIBYTE( wsaData.wVersion ) != 1 ) { + WSACleanup(); + return 0; + } + //Initialize socket + + if ((tcp->socket=(unsigned int)socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==INVALID_SOCKET) + { + return 0; + } + + setsockopt(tcp->socket,SOL_SOCKET,SO_RCVBUF,(const char*)&nRecvBuf,sizeof(int)); + setsockopt(tcp->socket,SOL_SOCKET,SO_SNDBUF,(const char*)&nSendBuf,sizeof(int)); + + return 1; +} + +int PX_TCPConnect(PX_TCP *tcp,PX_TCP_ADDR addr) +{ + SOCKADDR_IN to; + int ret; + to.sin_family=AF_INET; + to.sin_addr.s_addr=addr.ipv4; + to.sin_port=(addr.port); + + ret=connect(tcp->socket,(LPSOCKADDR)&to,sizeof(to)); + if (ret==0) + { + tcp->connectAddr=addr; + return 1; + } + return 0; +} + +int PX_TCPSend(PX_TCP *tcp,void *buffer,int size) +{ + char *sendBuffer=(char *)buffer; + int length; + switch(tcp->type) + { + case PX_TCP_IP_TYPE_IPV4: + { + do + { + if ((length=send(tcp->socket,(const char *)sendBuffer,size,0))==SOCKET_ERROR) + { + int error=WSAGetLastError(); + return 0; + } + sendBuffer+=length; + size-=length; + }while(size>0); + return 1; + } + break; + case PX_TCP_IP_TYPE_IPV6: + { + return 0; + } + break; + } + return 0; +} + +int PX_TCPReceived(PX_TCP *tcp,void *buffer,int buffersize,int timeout) +{ + size_t ReturnSize; + int ret =setsockopt(tcp->socket,SOL_SOCKET,SO_RCVTIMEO,(const char *)&timeout,sizeof(timeout)); + + if(ret!=0) + { + return 0; + } + + switch (tcp->type) + { + case PX_TCP_IP_TYPE_IPV4: + { + int SockAddrSize=sizeof(SOCKADDR); + if((ReturnSize=recv(tcp->socket,(char *)buffer,buffersize,0))!=SOCKET_ERROR) + { + return (int)ReturnSize; + } + else + { + int error=WSAGetLastError(); + return 0; + } + } + break; + case PX_TCP_IP_TYPE_IPV6: + { + return 0; + } + break; + } + return 0; +} + +int PX_TCPAccept(PX_TCP *tcp,unsigned int *socket,PX_TCP_ADDR *fromAddr) +{ + DWORD lasterror; + SOCKADDR_IN sockaddr_in; + int len=sizeof(SOCKADDR); + *socket=(unsigned int)accept((SOCKET)(tcp->socket),(LPSOCKADDR)&sockaddr_in,&len); + lasterror=WSAGetLastError(); + return *socket!=INVALID_SOCKET; +} + + +int PX_TCPIsConnecting(PX_TCP *tcp) +{ + char b; + int err,ret; + int timeout=1; + setsockopt(tcp->socket,SOL_SOCKET,SO_RCVTIMEO,(const char *)&timeout,sizeof(timeout)); + ret=recv(tcp->socket,&b,1,MSG_PEEK); + if ((err=WSAGetLastError())==10060) + { + return 1; + } + return ret>0; +} + +int PX_TCPKeepConnect(PX_TCP *tcp) +{ + if (!PX_TCPIsConnecting(tcp)) + { + return PX_TCPConnect(tcp,tcp->connectAddr); + } + return 1; +} + +int PX_TCPRecvCacheSize(PX_TCP *tcp) +{ + unsigned long bytesToRecv; + if (ioctlsocket(tcp->socket, FIONREAD, &bytesToRecv) == 0) + { + return bytesToRecv; + } + return 0; +} + +int PX_TCPReConnect(PX_TCP *tcp) +{ + return PX_TCPConnect(tcp,tcp->connectAddr); +} + +void PX_TCPFree(PX_TCP *tcp) +{ + closesocket(tcp->socket); +} + + +int PX_TCPListen(PX_TCP *tcp,unsigned short listen_Port) +{ + SOCKADDR_IN sockaddr_in; + memset(&sockaddr_in,0,sizeof(SOCKADDR_IN)); + sockaddr_in.sin_family=AF_INET; + sockaddr_in.sin_addr.s_addr=INADDR_ANY; + sockaddr_in.sin_port=(listen_Port); + + if (bind(tcp->socket,(LPSOCKADDR)&sockaddr_in,sizeof(sockaddr_in))!=0) + { + closesocket(tcp->socket); + return 0; + } + + if (listen(tcp->socket,5)!=0) + { + closesocket(tcp->socket); + return 0; + } + return 1; +} + +PX_TCP_ADDR PX_TCP_ADDR_IPV4(unsigned int ipv4,unsigned short port) +{ + PX_TCP_ADDR addr; + addr.ipv4=ipv4; + addr.port=port; + return addr; +} + diff --git a/lib/PainterEngine/platform/windows/px_thread.c b/lib/PainterEngine/platform/windows/px_thread.c new file mode 100644 index 0000000000000000000000000000000000000000..1d46bffbe50d3e5600709a4f15a8e1068c8c2be2 --- /dev/null +++ b/lib/PainterEngine/platform/windows/px_thread.c @@ -0,0 +1,23 @@ +#include "../modules/px_thread.h" +#include "windows.h" + +DWORD WINAPI PX_ThreadRun(void *ptr) +{ + px_thread *pthread=(px_thread *)ptr; + pthread->isRun=1; + pthread->pfunc(pthread->userptr); + pthread->isRun=0; + return 0; +} + + +int PX_ThreadCreate(px_thread *pthread,func_thread func,void *ptr) +{ + pthread->pfunc=func; + pthread->userptr=ptr; + pthread->isRun=0; + if(CreateThread(NULL,0,PX_ThreadRun,pthread,0,&pthread->handle_ulong)!=INVALID_HANDLE_VALUE) + return 1; + else + return 0; +} diff --git a/lib/PainterEngine/platform/windows/px_time.c b/lib/PainterEngine/platform/windows/px_time.c new file mode 100644 index 0000000000000000000000000000000000000000..b5ca457bebff4543b94b6576fb645fb7c45c4bee --- /dev/null +++ b/lib/PainterEngine/platform/windows/px_time.c @@ -0,0 +1,76 @@ +#include "../modules/px_time.h" +#include "time.h" +#include "windows.h" +#pragma comment (lib,"winmm.lib") + + +int PX_TimeGetYear() +{ + + time_t timep; + struct tm p; + time (&timep); + gmtime_s(&p,&timep); + + return 1900+p.tm_year; +} + +int PX_TimeGetMouth() +{ + time_t timep; + struct tm p; + time(&timep); + gmtime_s(&p, &timep); + + return p.tm_mon; +} + +int PX_TimeGetDay() +{ + time_t timep; + struct tm p; + time(&timep); + gmtime_s(&p, &timep); + + return p.tm_mday; +} + +int PX_TimeGetHour() +{ + time_t timep; + struct tm p; + time(&timep); + gmtime_s(&p, &timep); + + return p.tm_hour; +} + +int PX_TimeGetMinute() +{ + time_t timep; + struct tm p; + time(&timep); + gmtime_s(&p, &timep); + + return p.tm_min; +} + +int PX_TimeGetSecond() +{ + time_t timep; + struct tm p; + time(&timep); + gmtime_s(&p, &timep); + + return p.tm_sec; +} + +unsigned int PX_TimeGetTime() +{ + return timeGetTime(); +} + +void PX_Sleep(unsigned int ms) +{ + Sleep(ms); +} \ No newline at end of file diff --git a/lib/PainterEngine/platform/windows/px_udp.c b/lib/PainterEngine/platform/windows/px_udp.c new file mode 100644 index 0000000000000000000000000000000000000000..d95796cb3dda6c06d8d700f46970ffb9bff307e2 --- /dev/null +++ b/lib/PainterEngine/platform/windows/px_udp.c @@ -0,0 +1,178 @@ + +#include "../modules/px_udp.h" + +#pragma comment(lib,"ws2_32.lib") // Platform of MSVC +#pragma comment( lib,"winmm.lib" ) + +#include //header +#include +#include +#include "stdio.h" + +int PX_UDPInitialize(PX_UDP *udp,PX_UDP_IP_TYPE type) +{ + WORD wVersionRequested; + WSADATA wsaData; + int err; + int nZero=0; + int nRecvBuf=1024*1024; + int nSendBuf=1024*1024; + int optval=TRUE; + int imode=1,rev; + udp->type=type; + + wVersionRequested = MAKEWORD( 1, 1 ); + err = WSAStartup( wVersionRequested, &wsaData ); + if ( err != 0 ) { + + return 0; + } + + if ( LOBYTE( wsaData.wVersion ) != 1 || + HIBYTE( wsaData.wVersion ) != 1 ) { + WSACleanup(); + return 0; + } + //Initialize socket + + + if ((udp->socket=(unsigned int)socket(AF_INET,SOCK_DGRAM,0))==INVALID_SOCKET) + { + return 0; + } + + rev=ioctlsocket(udp->socket,FIONBIO,(u_long *)&imode); + + + setsockopt(udp->socket,SOL_SOCKET,SO_RCVBUF,(const char*)&nRecvBuf,sizeof(int)); + + setsockopt(udp->socket,SOL_SOCKET,SO_SNDBUF,(const char*)&nSendBuf,sizeof(int)); + + if(rev == SOCKET_ERROR) + { + printf("ioctlsocket failed!"); + closesocket(udp->socket); + WSACleanup(); + return 0; + } + + if (setsockopt(udp->socket,SOL_SOCKET,SO_BROADCAST,(char *)&optval,sizeof(int))==SOCKET_ERROR) + { + closesocket(udp->socket); + return 0; + } + return 1; +} + +int PX_UDPSend(PX_UDP *udp,PX_UDP_ADDR addr,void *buffer,int size) +{ + + int length; + switch(udp->type) + { + case PX_UDP_IP_TYPE_IPV4: + { + SOCKADDR_IN to; + to.sin_family=AF_INET; + to.sin_addr.s_addr=addr.ipv4; + to.sin_port=(addr.port); + while(size>0) + { + if ((length=sendto(udp->socket,(const char *)buffer,size,0,(LPSOCKADDR)&to,sizeof(SOCKADDR)))==SOCKET_ERROR) + { + return FALSE; + } + size-=length; + } + return TRUE; + } + break; + case PX_UDP_IP_TYPE_IPV6: + { +// sockaddr_in6 to; +// to.sin6_family=AF_INET6; +// to.sin6_port=htons(addr.port); +// px_memcpy(to.sin6_addr,addr.ipv6,sizeof(addr.ipv6)); +// while(size>0) +// { +// if ((length=sendto(udp->socket,(const char *)buffer,size,0,(LPSOCKADDR)&to,sizeof(sockaddr_in6)))==SOCKET_ERROR) +// { +// return FALSE; +// } +// size-=length; +// } +// return TRUE; + } + break; + } + return 0; +} + +int PX_UDPReceived(PX_UDP *udp,PX_UDP_ADDR *from_addr,void *buffer,int buffersize,int *readsize) +{ + size_t ReturnSize; + switch (udp->type) + { + case PX_UDP_IP_TYPE_IPV4: + { + SOCKADDR_IN in; + int SockAddrSize=sizeof(SOCKADDR); + if((ReturnSize=recvfrom(udp->socket,(char *)buffer,buffersize,0,(LPSOCKADDR)&in,&SockAddrSize))!=SOCKET_ERROR) + { + from_addr->ipv4=in.sin_addr.s_addr; + from_addr->port=in.sin_port; + *readsize=(int)ReturnSize; + return 1; + } + else + return 0; + } + break; + case PX_UDP_IP_TYPE_IPV6: + { +// sockaddr_in6 in; +// int SockAddrSize=sizeof(SOCKADDR); +// if((ReturnSize=recvfrom(udp->socket,(char *)buffer,buffersize,0,(LPSOCKADDR)&in,&SockAddrSize))!=SOCKET_ERROR) +// { +// px_memcpy(from_addr->ipv6,in.sin6_addr,sizeof(from_addr->ipv6)); +// from_addr->port=in.sin_port; +// *readsize=ReturnSize; +// return 1; +// } +// else +// return 0; + } + break; + } + return 0; +} + +void PX_UDPFree(PX_UDP *udp) +{ + closesocket(udp->socket); +} + + +int PX_UDPListen(PX_UDP *udp,unsigned short listen_Port) +{ + SOCKADDR_IN sockaddr_in; + sockaddr_in.sin_family=AF_INET; + sockaddr_in.sin_addr.s_addr=INADDR_ANY; + sockaddr_in.sin_port=(listen_Port); + + if (bind(udp->socket,(LPSOCKADDR)&sockaddr_in,sizeof(sockaddr_in))==SOCKET_ERROR) + { + closesocket(udp->socket); + return 0; + } + return 1; +} + +PX_UDP_ADDR PX_UDP_ADDR_IPV4(unsigned int ipv4,unsigned short port) +{ + PX_UDP_ADDR addr; + addr.ipv4=ipv4; + addr.port=port; + return addr; +} + diff --git a/lib/PainterEngine/supports/documents/PainterEngine API Manual.docx b/lib/PainterEngine/supports/documents/PainterEngine API Manual.docx new file mode 100644 index 0000000000000000000000000000000000000000..0543660b2b2c3d6149b77b3ce5bd6ed36fe2a6f4 Binary files /dev/null and b/lib/PainterEngine/supports/documents/PainterEngine API Manual.docx differ diff --git a/lib/PainterEngine/supports/logo/PainterEngineLogo.png b/lib/PainterEngine/supports/logo/PainterEngineLogo.png new file mode 100644 index 0000000000000000000000000000000000000000..a808ad824c89ca572c41421ad0f55d44a6d27eaa Binary files /dev/null and b/lib/PainterEngine/supports/logo/PainterEngineLogo.png differ diff --git a/lib/PainterEngine/supports/logo/logo_web.png b/lib/PainterEngine/supports/logo/logo_web.png new file mode 100644 index 0000000000000000000000000000000000000000..057246dd66d6505cf69bd2eee4745c7886952c3d Binary files /dev/null and b/lib/PainterEngine/supports/logo/logo_web.png differ diff --git a/lib/PainterEngine/supports/old/Platform_Windows_D2D.cbak b/lib/PainterEngine/supports/old/Platform_Windows_D2D.cbak new file mode 100644 index 0000000000000000000000000000000000000000..d43a638240afbf0bed84ebad3fe37693ae6273ae --- /dev/null +++ b/lib/PainterEngine/supports/old/Platform_Windows_D2D.cbak @@ -0,0 +1,540 @@ +#include +#include +#pragma comment(lib, "d2d1.lib") + +typedef struct +{ + UINT uMsg; + LPARAM lparam; + WPARAM wparam; +} WM_MESSAGE; + +BOOL PX_CreateWindow(int Width, int Height, const char *name, BOOL bfullScreen); +HWND PX_GetWindowHwnd(void); +VOID PX_SystemReadDeviceState(void); +BOOL PX_SystemLoop(void); +BOOL PX_SystemRender(void *raw, int width, int height); +BOOL PX_SystemIsActivated(void); +BOOL PX_KeyboardDown(unsigned char X); +char *PX_KeyboardString(void); +char *PX_DragfileString(void); +BOOL PX_MouseLButtonDown(void); +BOOL PX_MouseRButtonDown(void); +BOOL PX_MouseMButtonDown(void); +POINT PX_MousePosition(void); +BOOL PX_KeyDown(unsigned char key); +BOOL PX_MouseWheel(int *x, int *y, int *delta); +BOOL PX_GetWinMessage(WM_MESSAGE *Msg); +char *PX_OpenFileDialog(const char Filter[]); +char *PX_SaveFileDialog(const char Filter[], const char ext[]); +char *PX_MultFileDialog(const char Filter[]); +char *PX_GetFileName(const char filePath[]); + + +#define WIN_MAX_INPUT_STRING_LEN 64 +#define WIN_MAX_INPUT_SPECKEY_LEN 0xff + +#define WIN_KEYDOWN_BACKSPACE 1 +#define WIN_KEYDOWN_RETURN 2 +#define WIN_KEYDOWN_LEFT 3 +#define WIN_KEYDOWN_RIGHT 4 +#define WIN_KEYDOWN_UP 5 +#define WIN_KEYDOWN_DOWN 6 + +#define WIN_MESSAGESTACK_SIZE 32 + +HWND Win_Hwnd; +int Win_Height; +int Win_Width; +BOOL Win_bFullScreen; +BOOL Win_Activated; +WM_MESSAGE Win_messageStack[WIN_MESSAGESTACK_SIZE] = {0}; +unsigned char DInput_KeyBoardState[256]; +char DInput_AcceptFile[MAX_PATH] = {0}; +POINT DInput_MousePosition; +POINT DInput_MouseWheelPosition; +POINT DInput_MouseWheelDelta; + +ID2D1Bitmap *D2D_pSurface; +ID2D1Factory *D2D_pDirect2dFactory; +ID2D1HwndRenderTarget *D2D_pRenderTarget; + +static WNDCLASSEXA Win_Wcx; + +///////////////////////////////////////////////////// +LRESULT CALLBACK AppWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); +///////////////////////////////////////////////////// + +void DInput_Update() +{ + POINT point; + GetCursorPos(&point); + ScreenToClient(Win_Hwnd, &point); + DInput_MousePosition = point; +} + +BOOL PX_D3DReset(HWND hWnd, int Width, int Height, BOOL bfullScreen) +{ + return TRUE; +} + +BOOL PX_CreateWindow(int Width, int Height, const char *name, BOOL bfullScreen) +{ + HRESULT hr; + HINSTANCE hInstance; + D2D1_SIZE_U size; + D2D1_RENDER_TARGET_PROPERTIES render_target_properties; + D2D1_HWND_RENDER_TARGET_PROPERTIES hwnd_render_target_properties; + D2D1_BITMAP_PROPERTIES bitmapformat; + RECT rc; + + int nScreenWidth, nScreenHeight; + nScreenWidth = GetSystemMetrics(SM_CXSCREEN); + nScreenHeight = GetSystemMetrics(SM_CYSCREEN); + + hInstance = GetModuleHandleA(NULL); + + if (Win_Wcx.cbSize == 0) + { + //////////////////////////////////////////////////////////////////////////// + // Initialize Window class struct + /////////////////////////////////////////////////////////////////////////// + Win_Wcx.cbSize = sizeof(WNDCLASSEX); + Win_Wcx.style = CS_CLASSDC; + Win_Wcx.lpfnWndProc = AppWindowProc; + Win_Wcx.cbClsExtra = 0; + Win_Wcx.cbWndExtra = 0; + Win_Wcx.hInstance = hInstance; + Win_Wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION); + Win_Wcx.hCursor = LoadCursor(NULL, IDC_ARROW); + Win_Wcx.hbrBackground = (HBRUSH)(COLOR_WINDOW); + Win_Wcx.lpszMenuName = NULL; + Win_Wcx.lpszClassName = "WindowCls"; + Win_Wcx.hIconSm = LoadIcon(NULL, IDI_APPLICATION); + + /////////////////////////////////////////////////////////////////////////// + // Class Register + /////////////////////////////////////////////////////////////////////////// + if (!RegisterClassExA(&Win_Wcx)) + return FALSE; + } + + + Win_Width = Width; + Win_Height = Height; + Win_bFullScreen = bfullScreen; + + //////////////////////////////////////////////////////////////////////////// + // Create window + //////////////////////////////////////////////////////////////////////////// + Win_Hwnd = CreateWindowA("WindowCls", name, + WS_OVERLAPPED | WS_SYSMENU, + CW_USEDEFAULT, CW_USEDEFAULT, + Width, Height, + NULL, NULL, hInstance, NULL); + + if (Win_Hwnd == NULL) + return FALSE; + + //////////////////////////////////////////////////////////////////////////// + // Show window + //////////////////////////////////////////////////////////////////////////// + ShowWindow(Win_Hwnd, SW_SHOWNORMAL); + UpdateWindow(Win_Hwnd); + //CoInitialize(NULL); + DragAcceptFiles(Win_Hwnd, TRUE); + //////////////////////////////////////////////////////////////////////////// + + if (Win_Hwnd == NULL) + return FALSE; + + hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &IID_ID2D1Factory, NULL, (void **)&D2D_pDirect2dFactory); + if (FAILED(hr)) + { + return FALSE; + } + + GetClientRect(Win_Hwnd, &rc); + SetWindowPos(Win_Hwnd, 0, 0, 0, Width + Width - (rc.right - rc.left), Height + Height - (rc.bottom - rc.top), SWP_NOMOVE); + GetClientRect(Win_Hwnd, &rc); + + size.width=rc.right - rc.left; + size.height=rc.bottom - rc.top; + + render_target_properties.type = D2D1_RENDER_TARGET_TYPE_DEFAULT; + render_target_properties.pixelFormat.format = DXGI_FORMAT_UNKNOWN; + render_target_properties.pixelFormat.alphaMode = D2D1_ALPHA_MODE_UNKNOWN; + render_target_properties.dpiX = 0.0f; + render_target_properties.dpiY = 0.0f; + render_target_properties.usage = D2D1_RENDER_TARGET_USAGE_NONE; + render_target_properties.minLevel = D2D1_FEATURE_LEVEL_DEFAULT; + + hwnd_render_target_properties.hwnd = Win_Hwnd; + hwnd_render_target_properties.pixelSize = size; + hwnd_render_target_properties.presentOptions = D2D1_PRESENT_OPTIONS_NONE; + + hr = ID2D1Factory_CreateHwndRenderTarget(D2D_pDirect2dFactory, + &render_target_properties, + &hwnd_render_target_properties, + &D2D_pRenderTarget + ); + + if (FAILED(hr)) + { + return FALSE; + } + + + bitmapformat.dpiX = 0; + bitmapformat.dpiY = 0; + bitmapformat.pixelFormat.format = DXGI_FORMAT_R8G8B8A8_UNORM; + bitmapformat.pixelFormat.alphaMode = D2D1_ALPHA_MODE_IGNORE; + + size.width = Width; + size.height = Height; + hr = ID2D1HwndRenderTarget_CreateBitmap(D2D_pRenderTarget, size, NULL, 0, &bitmapformat, &D2D_pSurface); + + if (FAILED(hr)) + { + return FALSE; + } + + return TRUE; +} +///////////////////////////////////////////////////////////// +char Win_Str[WIN_MAX_INPUT_STRING_LEN] = {0}; +char Win_SpecKey[WIN_MAX_INPUT_SPECKEY_LEN] = {0}; +int Win_CurrentIndex = 0; +// #include +LRESULT CALLBACK AppWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + +// if (uMsg == 0x246) +// printf("%x\n",uMsg); + WM_MESSAGE message; + int i; + + switch (uMsg) + { + case WM_MOUSEMOVE: + case WM_LBUTTONDOWN: + case WM_LBUTTONUP: + case WM_RBUTTONDOWN: + case WM_RBUTTONUP: + break; + case WM_KILLFOCUS: + { + Win_Activated = FALSE; + break; + } + case WM_SETFOCUS: + { + Win_Activated = TRUE; + break; + } + case WM_KEYDOWN: + { + Win_SpecKey[wParam] = 1; + break; + } + case WM_MOUSEWHEEL: + { + DInput_MouseWheelPosition.x = GET_X_LPARAM(lParam); + DInput_MouseWheelPosition.y = GET_Y_LPARAM(lParam); + DInput_MouseWheelDelta.x = 0; + DInput_MouseWheelDelta.y = GET_WHEEL_DELTA_WPARAM(wParam); + break; + } + case WM_CHAR: + { + if (Win_CurrentIndex < WIN_MAX_INPUT_STRING_LEN - 1) + { + if (wParam >= 32 || wParam == 8) + { + Win_Str[Win_CurrentIndex++] = (char)wParam; + Win_Str[Win_CurrentIndex] = '\0'; + } + } + break; + } + case WM_DROPFILES: + { + HDROP hdrop = (HDROP)wParam; + DragQueryFileA(hdrop, 0, DInput_AcceptFile, MAX_PATH); + DragFinish(hdrop); + break; + } + case WM_CLOSE: + { + PostQuitMessage(0); + exit(0); + } + case WM_DESTROY: + { + PostQuitMessage(0); + return 0; + } + default: + return DefWindowProcA(hWnd, uMsg, wParam, lParam); + } + + message.uMsg = uMsg; + message.wparam = wParam; + message.lparam = lParam; + for (i = 0; i < WIN_MESSAGESTACK_SIZE; i++) + { + if (Win_messageStack[i].uMsg == 0) + { + Win_messageStack[i] = message; + break; + } + } + + return TRUE; +} + +BOOL PX_SystemLoop(void) +{ + MSG Msg; + ZeroMemory(&Msg, sizeof(MSG)); + + if (PeekMessageA(&Msg, NULL, 0, 0, PM_REMOVE)) + { + TranslateMessage(&Msg); + DispatchMessageA(&Msg); + } + else + { + Sleep(10); + } + return TRUE; +} + + +BOOL PX_SystemRender(void *raw, int width, int height) +{ + D2D1_RECT_U size; + size.left = 0; + size.right = width; + size.top = 0; + size.bottom = height; + + ID2D1HwndRenderTarget_BeginDraw(D2D_pRenderTarget); + ID2D1HwndRenderTarget_Clear(D2D_pRenderTarget, NULL); + ID2D1Bitmap_CopyFromMemory(D2D_pSurface, &size, raw, width * sizeof(DWORD)); + ID2D1HwndRenderTarget_DrawBitmap(D2D_pRenderTarget, D2D_pSurface, NULL, 1.0f, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, NULL); + ID2D1HwndRenderTarget_EndDraw(D2D_pRenderTarget, NULL, NULL); + + return TRUE; +} + +BOOL PX_SystemIsActivated(void) +{ + return Win_Activated; +} + +BOOL PX_KeyboardDown(unsigned char X) +{ + return (DInput_KeyBoardState[X] & 0x80) != 0; +} + +BOOL PX_MouseLButtonDown(void) +{ + return GetAsyncKeyState(VK_LBUTTON) & 0xFF00; +} + +BOOL PX_MouseRButtonDown(void) +{ + return GetAsyncKeyState(VK_RBUTTON) & 0xFF00; +} + +BOOL PX_MouseMButtonDown(void) +{ + return GetAsyncKeyState(VK_MBUTTON) & 0xFF00; +} + +POINT PX_MousePosition(void) +{ + return DInput_MousePosition; +} + +char *PX_KeyboardString(void) +{ + if (Win_CurrentIndex != 0) + { + Win_CurrentIndex = 0; + return Win_Str; + } + else + { + return 0; + } +} + +VOID PX_SystemReadDeviceState(void) +{ + DInput_Update(); +} + +char *PX_DragfileString(void) +{ + return DInput_AcceptFile; +} + +HWND PX_GetWindowHwnd(void) +{ + return Win_Hwnd; +} + +BOOL PX_KeyDown(unsigned char key) +{ + if (Win_SpecKey[key]) + { + Win_SpecKey[key] = 0; + return TRUE; + } + return FALSE; +} + +BOOL PX_MouseWheel(int *x, int *y, int *delta) +{ + if (DInput_MouseWheelDelta.y != 0) + { + *x = DInput_MouseWheelPosition.x; + *y = DInput_MouseWheelPosition.y; + *delta = DInput_MouseWheelDelta.y; + DInput_MouseWheelDelta.y = 0; + return TRUE; + } + return FALSE; +} + +BOOL PX_GetWinMessage(WM_MESSAGE *Msg) +{ + int i; + for (i = 0; i < WIN_MESSAGESTACK_SIZE; i++) + { + if (Win_messageStack[i].uMsg != 0) + { + *Msg = Win_messageStack[i]; + ZeroMemory(&Win_messageStack[i], sizeof(WM_MESSAGE)); + return TRUE; + } + } + return FALSE; +} + + +char *PX_OpenFileDialog(const char Filter[]) +{ + OPENFILENAMEA ofn; + static char szFile[MAX_PATH]; + ZeroMemory(&ofn, sizeof(ofn)); + ofn.lStructSize = sizeof(ofn); + ofn.lpstrFile = szFile; + ofn.lpstrFile[0] = '\0'; + ofn.nMaxFile = sizeof(szFile); + ofn.lpstrFilter = Filter;//TEXT("Mirrorļ(.mirror)\0*.mirror"); + ofn.nFilterIndex = 1; + ofn.lpstrFileTitle = NULL; + ofn.nMaxFileTitle = 0; + ofn.lpstrInitialDir = NULL; + ofn.hwndOwner = Win_Hwnd; + ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST; + + if (GetSaveFileNameA(&ofn)) + { + return szFile; + } + return NULL; +} + +char *PX_MultFileDialog(const char Filter[]) +{ + OPENFILENAMEA ofn; + static char szFile[MAX_PATH * 64]; + ZeroMemory(&ofn, sizeof(ofn)); + ofn.lStructSize = sizeof(ofn); + ofn.lpstrFile = szFile; + ofn.lpstrFile[0] = '\0'; + ofn.nMaxFile = sizeof(szFile); + ofn.lpstrFilter = Filter;//TEXT("Mirrorļ(.mirror)\0*.mirror"); + ofn.nFilterIndex = 1; + ofn.lpstrFileTitle = NULL; + ofn.nMaxFileTitle = 0; + ofn.lpstrInitialDir = NULL; + ofn.hwndOwner = Win_Hwnd; + ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_ALLOWMULTISELECT; + + if (GetOpenFileNameA(&ofn)) + { + if (szFile[strlen(szFile) + 1] == '\0') + { + INT_PTR oft = strlen(szFile) - 1; + while (oft >= 0) + { + if (szFile[oft] == '\\' || szFile[oft] == '/') + { + szFile[oft] = 0; + break; + } + oft--; + } + } + return szFile; + } + return NULL; +} + +char *PX_SaveFileDialog(const char Filter[], const char ext[]) +{ + OPENFILENAMEA ofn; + static char szFile[MAX_PATH]; + ZeroMemory(&ofn, sizeof(ofn)); + ofn.lStructSize = sizeof(ofn); + ofn.lpstrFile = szFile; + ofn.lpstrFile[0] = '\0'; + ofn.nMaxFile = sizeof(szFile); + ofn.lpstrFilter = Filter;//TEXT("Mirrorļ(.mirror)\0*.mirror"); + ofn.nFilterIndex = 1; + ofn.lpstrFileTitle = NULL; + ofn.nMaxFileTitle = 0; + ofn.lpstrInitialDir = NULL; + ofn.hwndOwner = Win_Hwnd; + ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST; + + if (GetSaveFileNameA(&ofn)) + { + if (ext != NULL) + { + char uprFile[MAX_PATH] = { 0 }; + char uprExt[MAX_PATH] = { 0 }; + strcpy_s(uprExt, MAX_PATH, ext); + _strupr_s(uprExt, MAX_PATH); + strcpy_s(uprFile, MAX_PATH, szFile); + _strupr_s(uprFile, MAX_PATH); + if (strstr(uprFile, uprExt) == NULL) + { + strcat_s(szFile, MAX_PATH, ext); + } + } + return szFile; + } + return NULL; +} + + +char *PX_GetFileName(const char filePath[]) +{ + INT_PTR offset = strlen(filePath) - 1; + while (offset != 0) + { + if (filePath[offset] == '/' || filePath[offset] == '\\') + { + offset++; + break; + } + offset--; + } + return (char *)filePath + offset; +} diff --git a/lib/PainterEngine/supports/old/Platform_Windows_D2D.hcbak b/lib/PainterEngine/supports/old/Platform_Windows_D2D.hcbak new file mode 100644 index 0000000000000000000000000000000000000000..5f1f378d9ec9550ba303b1584a61ac26b2db48b3 --- /dev/null +++ b/lib/PainterEngine/supports/old/Platform_Windows_D2D.hcbak @@ -0,0 +1,182 @@ +#ifndef PLATFORM_WINDOWS +#define PLATFORM_WINDOWS + +#include +#pragma comment(lib, "User32.lib") +#pragma comment(lib, "Shell32.lib") +#pragma comment(lib, "Ole32.lib") +#pragma comment(lib, "winmm.lib") + +#define PX_DIK_ESCAPE 0x01 +#define PX_DIK_1 0x02 +#define PX_DIK_2 0x03 +#define PX_DIK_3 0x04 +#define PX_DIK_4 0x05 +#define PX_DIK_5 0x06 +#define PX_DIK_6 0x07 +#define PX_DIK_7 0x08 +#define PX_DIK_8 0x09 +#define PX_DIK_9 0x0A +#define PX_DIK_0 0x0B +#define PX_DIK_MINUS 0x0C /* - on main keyboard */ +#define PX_DIK_EQUALS 0x0D +#define PX_DIK_BACK 0x0E /* backspace */ +#define PX_DIK_TAB 0x0F +#define PX_DIK_Q 0x10 +#define PX_DIK_W 0x11 +#define PX_DIK_E 0x12 +#define PX_DIK_R 0x13 +#define PX_DIK_T 0x14 +#define PX_DIK_Y 0x15 +#define PX_DIK_U 0x16 +#define PX_DIK_I 0x17 +#define PX_DIK_O 0x18 +#define PX_DIK_P 0x19 +#define PX_DIK_LBRACKET 0x1A +#define PX_DIK_RBRACKET 0x1B +#define PX_DIK_RETURN 0x1C /* Enter on main keyboard */ +#define PX_DIK_LCONTROL 0x1D +#define PX_DIK_A 0x1E +#define PX_DIK_S 0x1F +#define PX_DIK_D 0x20 +#define PX_DIK_F 0x21 +#define PX_DIK_G 0x22 +#define PX_DIK_H 0x23 +#define PX_DIK_J 0x24 +#define PX_DIK_K 0x25 +#define PX_DIK_L 0x26 +#define PX_DIK_SEMICOLON 0x27 +#define PX_DIK_APOSTROPHE 0x28 +#define PX_DIK_GRAVE 0x29 /* accent grave */ +#define PX_DIK_LSHIFT 0x2A +#define PX_DIK_BACKSLASH 0x2B +#define PX_DIK_Z 0x2C +#define PX_DIK_X 0x2D +#define PX_DIK_C 0x2E +#define PX_DIK_V 0x2F +#define PX_DIK_B 0x30 +#define PX_DIK_N 0x31 +#define PX_DIK_M 0x32 +#define PX_DIK_COMMA 0x33 +#define PX_DIK_PERIOD 0x34 /* . on main keyboard */ +#define PX_DIK_SLASH 0x35 /* / on main keyboard */ +#define PX_DIK_RSHIFT 0x36 +#define PX_DIK_MULTIPLY 0x37 /* * on numeric keypad */ +#define PX_DIK_LMENU 0x38 /* left Alt */ +#define PX_DIK_SPACE 0x39 +#define PX_DIK_CAPITAL 0x3A +#define PX_DIK_F1 0x3B +#define PX_DIK_F2 0x3C +#define PX_DIK_F3 0x3D +#define PX_DIK_F4 0x3E +#define PX_DIK_F5 0x3F +#define PX_DIK_F6 0x40 +#define PX_DIK_F7 0x41 +#define PX_DIK_F8 0x42 +#define PX_DIK_F9 0x43 +#define PX_DIK_F10 0x44 +#define PX_DIK_NUMLOCK 0x45 +#define PX_DIK_SCROLL 0x46 /* Scroll Lock */ +#define PX_DIK_NUMPAD7 0x47 +#define PX_DIK_NUMPAD8 0x48 +#define PX_DIK_NUMPAD9 0x49 +#define PX_DIK_SUBTRACT 0x4A /* - on numeric keypad */ +#define PX_DIK_NUMPAD4 0x4B +#define PX_DIK_NUMPAD5 0x4C +#define PX_DIK_NUMPAD6 0x4D +#define PX_DIK_ADD 0x4E /* + on numeric keypad */ +#define PX_DIK_NUMPAD1 0x4F +#define PX_DIK_NUMPAD2 0x50 +#define PX_DIK_NUMPAD3 0x51 +#define PX_DIK_NUMPAD0 0x52 +#define PX_DIK_DECIMAL 0x53 /* . on numeric keypad */ +#define PX_DIK_OEM_102 0x56 /* <> or \| on RT 102-key keyboard (Non-U.S.) */ +#define PX_DIK_F11 0x57 +#define PX_DIK_F12 0x58 +#define PX_DIK_F13 0x64 /* (NEC PC98) */ +#define PX_DIK_F14 0x65 /* (NEC PC98) */ +#define PX_DIK_F15 0x66 /* (NEC PC98) */ +#define PX_DIK_KANA 0x70 /* (Japanese keyboard) */ +#define PX_DIK_ABNT_C1 0x73 /* /? on Brazilian keyboard */ +#define PX_DIK_CONVERT 0x79 /* (Japanese keyboard) */ +#define PX_DIK_NOCONVERT 0x7B /* (Japanese keyboard) */ +#define PX_DIK_YEN 0x7D /* (Japanese keyboard) */ +#define PX_DIK_ABNT_C2 0x7E /* Numpad . on Brazilian keyboard */ +#define PX_DIK_NUMPADEQUALS 0x8D /* = on numeric keypad (NEC PC98) */ +#define PX_DIK_PREVTRACK 0x90 /* Previous Track (PX_DIK_CIRCUMFLEX on Japanese keyboard) */ +#define PX_DIK_AT 0x91 /* (NEC PC98) */ +#define PX_DIK_COLON 0x92 /* (NEC PC98) */ +#define PX_DIK_UNDERLINE 0x93 /* (NEC PC98) */ +#define PX_DIK_KANJI 0x94 /* (Japanese keyboard) */ +#define PX_DIK_STOP 0x95 /* (NEC PC98) */ +#define PX_DIK_AX 0x96 /* (Japan AX) */ +#define PX_DIK_UNLABELED 0x97 /* (J3100) */ +#define PX_DIK_NEXTTRACK 0x99 /* Next Track */ +#define PX_DIK_NUMPADENTER 0x9C /* Enter on numeric keypad */ +#define PX_DIK_RCONTROL 0x9D +#define PX_DIK_MUTE 0xA0 /* Mute */ +#define PX_DIK_CALCULATOR 0xA1 /* Calculator */ +#define PX_DIK_PLAYPAUSE 0xA2 /* Play / Pause */ +#define PX_DIK_MEDIASTOP 0xA4 /* Media Stop */ +#define PX_DIK_VOLUMEDOWN 0xAE /* Volume - */ +#define PX_DIK_VOLUMEUP 0xB0 /* Volume + */ +#define PX_DIK_WEBHOME 0xB2 /* Web home */ +#define PX_DIK_NUMPADCOMMA 0xB3 /* , on numeric keypad (NEC PC98) */ +#define PX_DIK_DIVIDE 0xB5 /* / on numeric keypad */ +#define PX_DIK_SYSRQ 0xB7 +#define PX_DIK_RMENU 0xB8 /* right Alt */ +#define PX_DIK_PAUSE 0xC5 /* Pause */ +#define PX_DIK_HOME 0xC7 /* Home on arrow keypad */ +#define PX_DIK_UP 0xC8 /* UpArrow on arrow keypad */ +#define PX_DIK_PRIOR 0xC9 /* PgUp on arrow keypad */ +#define PX_DIK_LEFT 0xCB /* LeftArrow on arrow keypad */ +#define PX_DIK_RIGHT 0xCD /* RightArrow on arrow keypad */ +#define PX_DIK_END 0xCF /* End on arrow keypad */ +#define PX_DIK_DOWN 0xD0 /* DownArrow on arrow keypad */ +#define PX_DIK_NEXT 0xD1 /* PgDn on arrow keypad */ +#define PX_DIK_INSERT 0xD2 /* Insert on arrow keypad */ +#define PX_DIK_DELETE 0xD3 /* Delete on arrow keypad */ +#define PX_DIK_LWIN 0xDB /* Left Windows key */ +#define PX_DIK_RWIN 0xDC /* Right Windows key */ +#define PX_DIK_APPS 0xDD /* AppMenu key */ +#define PX_DIK_POWER 0xDE /* System Power */ +#define PX_DIK_SLEEP 0xDF /* System Sleep */ +#define PX_DIK_WAKE 0xE3 /* System Wake */ +#define PX_DIK_WEBSEARCH 0xE5 /* Web Search */ +#define PX_DIK_WEBFAVORITES 0xE6 /* Web Favorites */ +#define PX_DIK_WEBREFRESH 0xE7 /* Web Refresh */ +#define PX_DIK_WEBSTOP 0xE8 /* Web Stop */ +#define PX_DIK_WEBFORWARD 0xE9 /* Web Forward */ +#define PX_DIK_WEBBACK 0xEA /* Web Back */ +#define PX_DIK_MYCOMPUTER 0xEB /* My Computer */ +#define PX_DIK_MAIL 0xEC /* Mail */ +#define PX_DIK_MEDIASELECT 0xED /* Media Select */ + +typedef struct +{ + UINT uMsg; + LPARAM lparam; + WPARAM wparam; +} WM_MESSAGE; + +BOOL PX_CreateWindow(int Width, int Height, const char *name, BOOL bfullScreen); +HWND PX_GetWindowHwnd(void); +VOID PX_SystemReadDeviceState(void); +BOOL PX_SystemLoop(void); +BOOL PX_SystemRender(void *raw, int width, int height); +BOOL PX_SystemIsActivated(void); +BOOL PX_KeyboardDown(unsigned char X); +char *PX_KeyboardString(void); +char *PX_DragfileString(void); +BOOL PX_MouseLButtonDown(void); +BOOL PX_MouseRButtonDown(void); +BOOL PX_MouseMButtonDown(void); +POINT PX_MousePosition(void); +BOOL PX_KeyDown(unsigned char key); +BOOL PX_MouseWheel(int *x, int *y, int *delta); +BOOL PX_GetWinMessage(WM_MESSAGE *Msg); +char *PX_OpenFileDialog(const char Filter[]); +char *PX_MultFileDialog(const char Filter[]); +char *PX_GetFileName(const char filePath[]); +char *PX_SaveFileDialog(const char Filter[], const char ext[]); +#endif diff --git a/lib/PainterEngine/supports/old/Platform_Windows_D3D.cpp b/lib/PainterEngine/supports/old/Platform_Windows_D3D.cpp new file mode 100644 index 0000000000000000000000000000000000000000..34e9462547ee381ba3e54789c73cb55d9d127077 --- /dev/null +++ b/lib/PainterEngine/supports/old/Platform_Windows_D3D.cpp @@ -0,0 +1,835 @@ + +#include "Platform_Windows_D3D.h" + + +#define WIN_MAX_INPUT_STRING_LEN 64 +#define WIN_MAX_INPUT_SPECKEY_LEN 0xff + + +#define WIN_KEYDOWN_BACKSPACE 1 +#define WIN_KEYDOWN_RETURN 2 +#define WIN_KEYDOWN_LEFT 3 +#define WIN_KEYDOWN_RIGHT 4 +#define WIN_KEYDOWN_UP 5 +#define WIN_KEYDOWN_DOWN 6 + +typedef enum +{ + DINPUT_IO_DEVICE_TYPE_KEYBOARD , + DINPUT_IO_DEVICE_TYPE_MOUSE , + DINPUT_IO_DEVICE_TYPE_JOY , +}DINPUT_IO_DEVICE_TYPE; + + +typedef struct +{ + IDirectInputDevice8 *pDIDevice; + GUID guid; +}DINPUT_INPUT_DEVICE; + +HWND Win_Hwnd; +int Win_Height; +int Win_Width; +BOOL Win_bFullScreen; +BOOL Win_Activated; +IDirect3D9 *DirectX_pDirect3D9; +IDirect3DDevice9 *DirectX_pD3DDevice; +ID3DXSprite *DirectX_pD3DSprite; +D3DPRESENT_PARAMETERS DirectX_d3dpp; +D3DDISPLAYMODE DirectX_DisplayMode; +unsigned int DirectX_Width; +unsigned int DirectX_Height; +char DirectX_BPP; +BOOL DirectX_HAREWARE; +BOOL DirectX_FullScreen; +IDirect3DTexture9 *DirectX_RenderTexture; + +IDirectInput8 *DInput_pDirectInput; +unsigned char DInput_KeyBoardState[256]; +char DInput_AccepyFile[MAX_PATH]={0}; +DIMOUSESTATE DInput_MouseState; +DIJOYSTATE DInput_JoyState; +POINT DInput_MousePosition; +int DInput_JoyDeviceIndex=0,DInput_KeyboardDeviceIndex=0,DInput_MouseDeviceIndex=0; +DINPUT_INPUT_DEVICE DInput_JoyDevice[8],DInput_KeyboardDevice[8],DInput_MouseDevice[8]; + + +static WNDCLASSEX Win_Wcx; + +///////////////////////////////////////////////////// +LRESULT CALLBACK AppWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); +///////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////// +// Get BPP(Color bit) from D3DFORMAT /// +/////////////////////////////////////////////////////////////////// +//************************************ +// Method: GetFormatBPP +// FullName: GetFormatBPP +// Access: public +// Returns: CHAR +// Qualifier: +// Parameter: D3DFORMAT Format +//************************************ +static int GetFormatBPP( D3DFORMAT Format ) +{ + switch(Format) { + + case D3DFMT_A8R8G8B8: + case D3DFMT_X8R8G8B8: + return 32; + break; + + + case D3DFMT_R8G8B8: + return 24; + break; + + + case D3DFMT_R5G6B5: + case D3DFMT_X1R5G5B5: + case D3DFMT_A1R5G5B5: + case D3DFMT_A4R4G4B4: + return 16; + break; + + + case D3DFMT_A8P8: + case D3DFMT_P8: + return 8; + break; + + default: + return 0; + } +} + + +static BOOL CheckFormat( D3DFORMAT Format, BOOL Windowed, BOOL HAL ) +{ + + if(FAILED(IDirect3D9_CheckDeviceType(DirectX_pDirect3D9,D3DADAPTER_DEFAULT, + (HAL == TRUE) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF, + Format, Format, Windowed))) + return FALSE; + + return TRUE; +} + +BOOL DINPUT_CreateDevice(HWND hWnd,REFGUID guid,LPDIRECTINPUTDEVICE8 *ppInputDevice,DINPUT_IO_DEVICE_TYPE nType) +{ + DIPROPRANGE dipr; + + if(FAILED(IDirectInput8_CreateDevice(DInput_pDirectInput,guid,ppInputDevice,NULL))) + { + return FALSE; + } + + switch(nType) + { + case DINPUT_IO_DEVICE_TYPE_KEYBOARD: + if(FAILED(IDirectInputDevice8_SetDataFormat((*ppInputDevice),&c_dfDIKeyboard))) + { + IDirectInputDevice8_Release((*ppInputDevice)); + (*ppInputDevice)=NULL; + return FALSE; + } + break; + case DINPUT_IO_DEVICE_TYPE_MOUSE: + if(FAILED(IDirectInputDevice8_SetDataFormat((*ppInputDevice),&c_dfDIMouse))) + { + IDirectInputDevice8_Release((*ppInputDevice)); + (*ppInputDevice)=NULL; + return FALSE; + } + break; + case DINPUT_IO_DEVICE_TYPE_JOY: + if(FAILED(IDirectInputDevice8_SetDataFormat((*ppInputDevice),&c_dfDIJoystick))) + { + IDirectInputDevice8_Release((*ppInputDevice)); + (*ppInputDevice)=NULL; + return FALSE; + } + break; + default: + return FALSE; + } + + if(FAILED(IDirectInputDevice8_SetCooperativeLevel((*ppInputDevice),hWnd,DISCL_BACKGROUND|DISCL_NONEXCLUSIVE))) + { + IDirectInputDevice8_Release((*ppInputDevice)); + (*ppInputDevice)=NULL; + return FALSE; + } + + if (nType==DINPUT_IO_DEVICE_TYPE_JOY) + { + ZeroMemory(&dipr,sizeof DIPROPRANGE); + dipr.diph.dwSize=sizeof(dipr); + dipr.diph.dwHeaderSize=sizeof (dipr); + dipr.diph.dwObj=DIJOFS_X; + dipr.diph.dwHow=DIPH_BYOFFSET; + + dipr.lMin=-1024; + dipr.lMax=1024; + + if (FAILED(IDirectInputDevice8_SetProperty((*ppInputDevice),DIPROP_RANGE,&dipr.diph))) + { + IDirectInputDevice8_Release((*ppInputDevice)); + (*ppInputDevice)=NULL; + return FALSE; + } + } + if (FAILED(IDirectInputDevice8_Acquire((*ppInputDevice)))) + { + IDirectInputDevice8_Release((*ppInputDevice)); + (*ppInputDevice)=NULL; + return FALSE; + } + + return TRUE; +} + +BOOL CALLBACK DInput_RecvJoyDevice(LPCDIDEVICEINSTANCE pDevicsInst,LPVOID pvRef) +{ + if(DInput_JoyDeviceIndex>=8) + { + return TRUE; + } + + DInput_JoyDevice[DInput_JoyDeviceIndex].guid=pDevicsInst->guidInstance; + if(DINPUT_CreateDevice(Win_Hwnd,DInput_JoyDevice[DInput_JoyDeviceIndex].guid,&DInput_JoyDevice[DInput_JoyDeviceIndex].pDIDevice,DINPUT_IO_DEVICE_TYPE_JOY)) + { + DInput_JoyDeviceIndex++; + } + + return DIENUM_CONTINUE; +} + +BOOL CALLBACK DInput_RecvMouseDevice(LPCDIDEVICEINSTANCE pDevicsInst,LPVOID pvRef) +{ + if(DInput_MouseDeviceIndex>=8) + { + return TRUE; + } + + DInput_MouseDevice[DInput_MouseDeviceIndex].guid=pDevicsInst->guidInstance; + if(DINPUT_CreateDevice(Win_Hwnd,DInput_MouseDevice[DInput_MouseDeviceIndex].guid,&DInput_MouseDevice[DInput_MouseDeviceIndex].pDIDevice,DINPUT_IO_DEVICE_TYPE_MOUSE)) + { + DInput_MouseDeviceIndex++; + } + + return DIENUM_CONTINUE; +} + +BOOL CALLBACK DInput_RecvKeyboardDevice(LPCDIDEVICEINSTANCE pDevicsInst,LPVOID pvRef) +{ + if(DInput_KeyboardDeviceIndex>=8) + { + return TRUE; + } + + DInput_KeyboardDevice[DInput_KeyboardDeviceIndex].guid=pDevicsInst->guidInstance; + if(DINPUT_CreateDevice(Win_Hwnd,DInput_KeyboardDevice[DInput_KeyboardDeviceIndex].guid,&DInput_KeyboardDevice[DInput_KeyboardDeviceIndex].pDIDevice,DINPUT_IO_DEVICE_TYPE_KEYBOARD)) + { + DInput_KeyboardDeviceIndex++; + } + + return DIENUM_CONTINUE; +} + +BOOL DInput_ReadDevice(IDirectInputDevice8 *pDevice,void *DataBuffer,long BufferSize) +{ + HRESULT hr; + if (pDevice==NULL) + { + return FALSE; + } + while(TRUE) + { + IDirectInputDevice8_Poll(pDevice); + + if (SUCCEEDED(hr=IDirectInputDevice8_GetDeviceState(pDevice,BufferSize,(LPVOID)DataBuffer))) + { + break; + } + + if (hr!=DIERR_INPUTLOST&&hr!=DIERR_NOTACQUIRED) + { + return FALSE; + } + + if (FAILED(IDirectInputDevice8_Acquire(pDevice))) + { + return FALSE; + } + } + + return TRUE; +} + +void DInput_UpdateDevice() +{ + DInput_JoyDeviceIndex=0,DInput_KeyboardDeviceIndex=0,DInput_MouseDeviceIndex=0; + IDirectInput8_EnumDevices(DInput_pDirectInput,DI8DEVTYPE_JOYSTICK,DInput_RecvJoyDevice,NULL,DIEDFL_ATTACHEDONLY); + IDirectInput8_EnumDevices(DInput_pDirectInput,DI8DEVTYPE_MOUSE,DInput_RecvMouseDevice,NULL,DIEDFL_ATTACHEDONLY); + IDirectInput8_EnumDevices(DInput_pDirectInput,DI8DEVTYPE_KEYBOARD,DInput_RecvKeyboardDevice,NULL,DIEDFL_ATTACHEDONLY); +} + + +void DInput_Update() +{ + BOOL KeyBoardReaded=FALSE; + BOOL MouseReaded=FALSE; + BOOL JoyReaded=FALSE; + int i; + POINT point; + + for(i=0;i=32||wParam==8) + { + Win_Str[Win_CurrentIndex++]=(char)wParam; + Win_Str[Win_CurrentIndex]='\0'; + } + } + return 0; + } + break; + case WM_DROPFILES: + { + HDROP hdrop = (HDROP)wParam; + DragQueryFile(hdrop, 0, DInput_AccepyFile, MAX_PATH); + DragFinish(hdrop); + } + break; + case WM_CLOSE: + { + PostQuitMessage(0); + exit(0); + } + break; + case WM_DESTROY: + { + PostQuitMessage(0); + return 0; + } + break; + + default: return DefWindowProc(hWnd,uMsg,wParam,lParam); + } + return TRUE; +} + +BOOL PX_SystemLoop() +{ + MSG Msg; + ZeroMemory(&Msg, sizeof(MSG)); + + if(PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)) + { + TranslateMessage(&Msg); + DispatchMessage(&Msg); + } + else + { + Sleep(10); + } + return TRUE; +} + +// Reset device +HRESULT ResetDevice(D3DPRESENT_PARAMETERS d3dpp) +{ + // Check device state + HRESULT hr =IDirect3DDevice9_TestCooperativeLevel(DirectX_pD3DDevice); + + // Device can be reset now + if (SUCCEEDED(hr) || hr == D3DERR_DEVICENOTRESET) + { + // Reset device + IDirect3DDevice9_Reset(DirectX_pD3DDevice,&d3dpp) ; + + if (!PX_D3DReset(Win_Hwnd,Win_Width,Win_Height,Win_bFullScreen)) + { + return FALSE; + } + } + // Device is still in lost state, wait + else if (hr == D3DERR_DEVICELOST) + { + Sleep(10) ; + } + + return hr ; +} + +BOOL PX_SystemRender(void *raw,int witdh,int height) +{ + D3DLOCKED_RECT lrect; + HRESULT hr; + RECT Rect; + unsigned char *pBits; + + + hr=IDirect3DTexture9_LockRect(DirectX_RenderTexture,0, &lrect, NULL, 0); + if (FAILED(hr)) + { + return FALSE; + } + pBits=(unsigned char *)lrect.pBits; + + memcpy(pBits,raw,witdh*height*sizeof(DWORD)); + + IDirect3DTexture9_UnlockRect(DirectX_RenderTexture,0); + + + if(FAILED(IDirect3DDevice9_Clear(DirectX_pD3DDevice,0, NULL, D3DCLEAR_TARGET, D3DXCOLOR(1,0,0,1), 1.0, 0))) + return FALSE; + + hr=DirectX_pD3DDevice->BeginScene(); + if (FAILED(hr)) + { + return FALSE; + } + + hr=DirectX_pD3DSprite->Begin(D3DXSPRITE_ALPHABLEND); + if (FAILED(hr)) + { + return FALSE; + } + Rect.left=0; + Rect.top =0; + Rect.right =DirectX_Width; + Rect.bottom =DirectX_Height; + + + if(FAILED(DirectX_pD3DSprite->Draw(DirectX_RenderTexture,&Rect,NULL,&D3DXVECTOR3(0,0,0),D3DXCOLOR(1,1,1,1)))) + { + return FALSE; + } + + DirectX_pD3DSprite->End(); + DirectX_pD3DDevice->EndScene(); + if(FAILED(DirectX_pD3DDevice->Present(0,0,0,0))) + ResetDevice(DirectX_d3dpp); + + return TRUE; +} + +BOOL PX_SystemisAvtivated() +{ + return Win_Activated; +} + +BOOL PX_KeyboardDown(unsigned char X) +{ + return (DInput_KeyBoardState[X]&0x80?TRUE:FALSE); +} + +BOOL PX_MouseLButtonDown() +{ + return DInput_MouseState.rgbButtons[0]&0x80; +} + +BOOL PX_MouseRButtonDown() +{ + return DInput_MouseState.rgbButtons[1]&0x80; +} + +BOOL PX_MouseMButtonDown() +{ + return DInput_MouseState.rgbButtons[2]&0x80; +} + +POINT PX_MousePosition() +{ + return DInput_MousePosition; +} + +char * PX_KeyboardString() +{ + if(Win_CurrentIndex!=0) + { + Win_CurrentIndex=0; + return Win_Str; + } + else + { + return 0; + } +} + +VOID PX_SystemReadDeviceState() +{ + DInput_Update(); +} + +char * PX_DragfileString() +{ + return DInput_AccepyFile; +} + +HWND PX_GetWindowHwnd() +{ + return Win_Hwnd; +} + +BOOL PX_KeyDown(char key) +{ + if (Win_SpecKey[key]) + { + Win_SpecKey[key]=0; + return TRUE; + } + return FALSE; +} \ No newline at end of file diff --git a/lib/PainterEngine/supports/old/Platform_Windows_D3D.h b/lib/PainterEngine/supports/old/Platform_Windows_D3D.h new file mode 100644 index 0000000000000000000000000000000000000000..91eb816deaa6c3acaba30387c480da1298b11a7d --- /dev/null +++ b/lib/PainterEngine/supports/old/Platform_Windows_D3D.h @@ -0,0 +1,181 @@ +#ifndef PLATFORM_WINDOWS +#define PLATFORM_WINDOWS + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#pragma comment(lib,"d3dx9.lib") +#pragma comment(lib,"d3d9.lib") +#pragma comment(lib,"WINMM.LIB") +#pragma comment(lib,"DXGUID.LIB") +#pragma comment(lib,"dsound.lib") +#pragma comment(lib,"dinput8.lib") + +#define PX_DIK_ESCAPE 0x01 +#define PX_DIK_1 0x02 +#define PX_DIK_2 0x03 +#define PX_DIK_3 0x04 +#define PX_DIK_4 0x05 +#define PX_DIK_5 0x06 +#define PX_DIK_6 0x07 +#define PX_DIK_7 0x08 +#define PX_DIK_8 0x09 +#define PX_DIK_9 0x0A +#define PX_DIK_0 0x0B +#define PX_DIK_MINUS 0x0C /* - on main keyboard */ +#define PX_DIK_EQUALS 0x0D +#define PX_DIK_BACK 0x0E /* backspace */ +#define PX_DIK_TAB 0x0F +#define PX_DIK_Q 0x10 +#define PX_DIK_W 0x11 +#define PX_DIK_E 0x12 +#define PX_DIK_R 0x13 +#define PX_DIK_T 0x14 +#define PX_DIK_Y 0x15 +#define PX_DIK_U 0x16 +#define PX_DIK_I 0x17 +#define PX_DIK_O 0x18 +#define PX_DIK_P 0x19 +#define PX_DIK_LBRACKET 0x1A +#define PX_DIK_RBRACKET 0x1B +#define PX_DIK_RETURN 0x1C /* Enter on main keyboard */ +#define PX_DIK_LCONTROL 0x1D +#define PX_DIK_A 0x1E +#define PX_DIK_S 0x1F +#define PX_DIK_D 0x20 +#define PX_DIK_F 0x21 +#define PX_DIK_G 0x22 +#define PX_DIK_H 0x23 +#define PX_DIK_J 0x24 +#define PX_DIK_K 0x25 +#define PX_DIK_L 0x26 +#define PX_DIK_SEMICOLON 0x27 +#define PX_DIK_APOSTROPHE 0x28 +#define PX_DIK_GRAVE 0x29 /* accent grave */ +#define PX_DIK_LSHIFT 0x2A +#define PX_DIK_BACKSLASH 0x2B +#define PX_DIK_Z 0x2C +#define PX_DIK_X 0x2D +#define PX_DIK_C 0x2E +#define PX_DIK_V 0x2F +#define PX_DIK_B 0x30 +#define PX_DIK_N 0x31 +#define PX_DIK_M 0x32 +#define PX_DIK_COMMA 0x33 +#define PX_DIK_PERIOD 0x34 /* . on main keyboard */ +#define PX_DIK_SLASH 0x35 /* / on main keyboard */ +#define PX_DIK_RSHIFT 0x36 +#define PX_DIK_MULTIPLY 0x37 /* * on numeric keypad */ +#define PX_DIK_LMENU 0x38 /* left Alt */ +#define PX_DIK_SPACE 0x39 +#define PX_DIK_CAPITAL 0x3A +#define PX_DIK_F1 0x3B +#define PX_DIK_F2 0x3C +#define PX_DIK_F3 0x3D +#define PX_DIK_F4 0x3E +#define PX_DIK_F5 0x3F +#define PX_DIK_F6 0x40 +#define PX_DIK_F7 0x41 +#define PX_DIK_F8 0x42 +#define PX_DIK_F9 0x43 +#define PX_DIK_F10 0x44 +#define PX_DIK_NUMLOCK 0x45 +#define PX_DIK_SCROLL 0x46 /* Scroll Lock */ +#define PX_DIK_NUMPAD7 0x47 +#define PX_DIK_NUMPAD8 0x48 +#define PX_DIK_NUMPAD9 0x49 +#define PX_DIK_SUBTRACT 0x4A /* - on numeric keypad */ +#define PX_DIK_NUMPAD4 0x4B +#define PX_DIK_NUMPAD5 0x4C +#define PX_DIK_NUMPAD6 0x4D +#define PX_DIK_ADD 0x4E /* + on numeric keypad */ +#define PX_DIK_NUMPAD1 0x4F +#define PX_DIK_NUMPAD2 0x50 +#define PX_DIK_NUMPAD3 0x51 +#define PX_DIK_NUMPAD0 0x52 +#define PX_DIK_DECIMAL 0x53 /* . on numeric keypad */ +#define PX_DIK_OEM_102 0x56 /* <> or \| on RT 102-key keyboard (Non-U.S.) */ +#define PX_DIK_F11 0x57 +#define PX_DIK_F12 0x58 +#define PX_DIK_F13 0x64 /* (NEC PC98) */ +#define PX_DIK_F14 0x65 /* (NEC PC98) */ +#define PX_DIK_F15 0x66 /* (NEC PC98) */ +#define PX_DIK_KANA 0x70 /* (Japanese keyboard) */ +#define PX_DIK_ABNT_C1 0x73 /* /? on Brazilian keyboard */ +#define PX_DIK_CONVERT 0x79 /* (Japanese keyboard) */ +#define PX_DIK_NOCONVERT 0x7B /* (Japanese keyboard) */ +#define PX_DIK_YEN 0x7D /* (Japanese keyboard) */ +#define PX_DIK_ABNT_C2 0x7E /* Numpad . on Brazilian keyboard */ +#define PX_DIK_NUMPADEQUALS 0x8D /* = on numeric keypad (NEC PC98) */ +#define PX_DIK_PREVTRACK 0x90 /* Previous Track (PX_DIK_CIRCUMFLEX on Japanese keyboard) */ +#define PX_DIK_AT 0x91 /* (NEC PC98) */ +#define PX_DIK_COLON 0x92 /* (NEC PC98) */ +#define PX_DIK_UNDERLINE 0x93 /* (NEC PC98) */ +#define PX_DIK_KANJI 0x94 /* (Japanese keyboard) */ +#define PX_DIK_STOP 0x95 /* (NEC PC98) */ +#define PX_DIK_AX 0x96 /* (Japan AX) */ +#define PX_DIK_UNLABELED 0x97 /* (J3100) */ +#define PX_DIK_NEXTTRACK 0x99 /* Next Track */ +#define PX_DIK_NUMPADENTER 0x9C /* Enter on numeric keypad */ +#define PX_DIK_RCONTROL 0x9D +#define PX_DIK_MUTE 0xA0 /* Mute */ +#define PX_DIK_CALCULATOR 0xA1 /* Calculator */ +#define PX_DIK_PLAYPAUSE 0xA2 /* Play / Pause */ +#define PX_DIK_MEDIASTOP 0xA4 /* Media Stop */ +#define PX_DIK_VOLUMEDOWN 0xAE /* Volume - */ +#define PX_DIK_VOLUMEUP 0xB0 /* Volume + */ +#define PX_DIK_WEBHOME 0xB2 /* Web home */ +#define PX_DIK_NUMPADCOMMA 0xB3 /* , on numeric keypad (NEC PC98) */ +#define PX_DIK_DIVIDE 0xB5 /* / on numeric keypad */ +#define PX_DIK_SYSRQ 0xB7 +#define PX_DIK_RMENU 0xB8 /* right Alt */ +#define PX_DIK_PAUSE 0xC5 /* Pause */ +#define PX_DIK_HOME 0xC7 /* Home on arrow keypad */ +#define PX_DIK_UP 0xC8 /* UpArrow on arrow keypad */ +#define PX_DIK_PRIOR 0xC9 /* PgUp on arrow keypad */ +#define PX_DIK_LEFT 0xCB /* LeftArrow on arrow keypad */ +#define PX_DIK_RIGHT 0xCD /* RightArrow on arrow keypad */ +#define PX_DIK_END 0xCF /* End on arrow keypad */ +#define PX_DIK_DOWN 0xD0 /* DownArrow on arrow keypad */ +#define PX_DIK_NEXT 0xD1 /* PgDn on arrow keypad */ +#define PX_DIK_INSERT 0xD2 /* Insert on arrow keypad */ +#define PX_DIK_DELETE 0xD3 /* Delete on arrow keypad */ +#define PX_DIK_LWIN 0xDB /* Left Windows key */ +#define PX_DIK_RWIN 0xDC /* Right Windows key */ +#define PX_DIK_APPS 0xDD /* AppMenu key */ +#define PX_DIK_POWER 0xDE /* System Power */ +#define PX_DIK_SLEEP 0xDF /* System Sleep */ +#define PX_DIK_WAKE 0xE3 /* System Wake */ +#define PX_DIK_WEBSEARCH 0xE5 /* Web Search */ +#define PX_DIK_WEBFAVORITES 0xE6 /* Web Favorites */ +#define PX_DIK_WEBREFRESH 0xE7 /* Web Refresh */ +#define PX_DIK_WEBSTOP 0xE8 /* Web Stop */ +#define PX_DIK_WEBFORWARD 0xE9 /* Web Forward */ +#define PX_DIK_WEBBACK 0xEA /* Web Back */ +#define PX_DIK_MYCOMPUTER 0xEB /* My Computer */ +#define PX_DIK_MAIL 0xEC /* Mail */ +#define PX_DIK_MEDIASELECT 0xED /* Media Select */ + +BOOL PX_CreateWindow( int Width,int Height,char *name,BOOL bfullScreen); +HWND PX_GetWindowHwnd(); +VOID PX_SystemReadDeviceState(); +BOOL PX_SystemLoop(); +BOOL PX_SystemRender(void *raw,int width,int hight); +BOOL PX_SystemisAvtivated(); +BOOL PX_KeyboardDown(unsigned char X ); +char *PX_KeyboardString(); +char *PX_DragfileString(); +BOOL PX_MouseLButtonDown(); +BOOL PX_MouseRButtonDown(); +BOOL PX_MouseMButtonDown(); +POINT PX_MousePosition(); +BOOL PX_KeyDown(char key); +#endif diff --git a/lib/PainterEngine/supports/old/Platform_Windows_WaveOut.c b/lib/PainterEngine/supports/old/Platform_Windows_WaveOut.c new file mode 100644 index 0000000000000000000000000000000000000000..986970a0d2a6343adece1f5eaee83f5330cb0a66 --- /dev/null +++ b/lib/PainterEngine/supports/old/Platform_Windows_WaveOut.c @@ -0,0 +1,89 @@ +#include +#include "../../core/PX_Sound.h" + + +static HWAVEOUT main_hWaveOut; +static HANDLE main_waveEvent; +static PX_SoundPlay *main_soundplay=NULL; + +#define MAIN_WAVEBUFFER_BLOCK_LEN 1764 +#define MAIN_WAVEBUFFER_BLOCK_COUNT 8 + +static unsigned char main_wavebuffer[MAIN_WAVEBUFFER_BLOCK_LEN*MAIN_WAVEBUFFER_BLOCK_COUNT]={0}; + +DWORD _stdcall DEMO_waveOutProc(LPVOID p) +{ + WAVEHDR waveheader; + px_int QueueSize=0; + px_int wIndex=0; + + while (!main_soundplay) + { + Sleep(10); + } + + while(1) + { + if (!PX_SoundPlayGetDataCount(main_soundplay)) + { + QueueSize=0; + } + while (QueueSize=MAIN_WAVEBUFFER_BLOCK_COUNT) + { + wIndex=0; + } + } + + WaitForSingleObject(main_waveEvent,INFINITE); + ResetEvent(main_waveEvent); + if(QueueSize>0) + QueueSize--; + } +} + + +BOOL PX_AudioInitialize(HWND hwnd,PX_SoundPlay *soundPlay) +{ + WAVEFORMATEX waveformat; + HANDLE hThread; + DWORD threadId; + + waveformat.wFormatTag = WAVE_FORMAT_PCM; + waveformat.nSamplesPerSec = 44100;//44100; + waveformat.wBitsPerSample = 16;// + waveformat.nChannels = 2;// + waveformat.nBlockAlign = (waveformat.wBitsPerSample >> 3) * waveformat.nChannels;; + waveformat.nAvgBytesPerSec = waveformat.nBlockAlign * waveformat.nSamplesPerSec; + waveformat.cbSize = 0; + + main_waveEvent= CreateEvent(NULL,FALSE,FALSE,"PCM_DONE"); + + if(FAILED(waveOutOpen(&main_hWaveOut,WAVE_MAPPER,&waveformat,(DWORD_PTR)main_waveEvent,(DWORD_PTR)NULL,CALLBACK_EVENT))) + return FALSE; + + hThread = CreateThread(NULL, 0, DEMO_waveOutProc, 0, 0, &threadId); + + main_soundplay=soundPlay; + return TRUE; +} + + +void PX_AudioSetVolume(DWORD volume) +{ + waveOutSetVolume(main_hWaveOut,volume); +} diff --git a/makefile b/makefile new file mode 100644 index 0000000000000000000000000000000000000000..c9bfb3d2c69f22f251b4d70b3be32dce05fb5a17 --- /dev/null +++ b/makefile @@ -0,0 +1,62 @@ +#mingw32-64 makefile +##################################################### +target := MineSweeper.exe +project_path := src +painterengine_path := lib\PainterEngine +##################################################### + +project_build := $(wildcard $(project_path)/*.c) +project_build_o := $(patsubst %.c,%.o,$(project_build)) + +painterengine_build_core := $(wildcard $(painterengine_path)/core/*.c) +painterengine_build_painterengine_o := $(patsubst %.c,%.o,$(painterengine_build_core)) + +painterengine_build_kernel := $(wildcard $(painterengine_path)/kernel/*.c) +painterengine_build_painterengine_o += $(patsubst %.c,%.o,$(painterengine_build_kernel)) + +painterengine_build_architecture := $(wildcard $(painterengine_path)/architecture/*.c) +painterengine_build_painterengine_o += $(patsubst %.c,%.o,$(painterengine_build_architecture)) + +painterengine_build_platform := $(wildcard $(painterengine_path)/platform/windows/*.c) +painterengine_build_painterengine_o += $(patsubst %.c,%.o,$(painterengine_build_platform)) + +painterengine_build_platform := $(wildcard $(painterengine_path)/platform/windows/*.cpp) +painterengine_build_painterengine_o += $(patsubst %.cpp,%.o,$(painterengine_build_platform)) + + +all:$(project_build_o) $(painterengine_build_painterengine_o) + gcc $(project_build_o) $(painterengine_build_painterengine_o) \ + -o $(project_path)\..\$(target) \ + -I "$(painterengine_path)" \ + -I "$(project_path)" \ + -I "$(painterengine_path)\platform\windows" \ + -L. -lwinmm -ld2d1 -lws2_32 -ldsound -lcomdlg32 -std=c99 + mingw32-make clean + + + +$(project_path)/%.o:$(project_path)/%.c + gcc -c $^ -o $@ -I "$(painterengine_path)" -I "$(painterengine_path)/platform/windows" -std=c99 + +$(painterengine_path)/architecture/%.o:$(painterengine_path)/architecture/%.c + gcc -c $^ -o $@ -I "$(painterengine_path)" -std=c99 + +$(painterengine_path)/kernel/%.o:$(painterengine_path)/kernel/%.c + gcc -c $^ -o $@ -std=c99 + +$(painterengine_path)/core/%.o:$(painterengine_path)/core/%.c + gcc -c $^ -o $@ -std=c99 + +$(painterengine_path)/platform/windows/%.o:$(painterengine_path)/platform/windows/%.c + gcc -c $^ -o $@ -I "$(project_path)" -I "$(painterengine_path)" -I "$(painterengine_path)/platform/windows" -std=c99 + + +.PHONY:clean +clean: +# -del /s "$(painterengine_path)\core\*.o" +# -del /s "$(painterengine_path)\kernel\*.o" +# -del /s "$(painterengine_path)\architecture\*.o" +# -del /s "$(painterengine_path)\platform\windows\*.o" + -del /s "$(project_path)\*.o" + + \ No newline at end of file diff --git a/pullTest/pull b/pullTest/pull deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/src/PainterEngine_Application.c b/src/PainterEngine_Application.c new file mode 100644 index 0000000000000000000000000000000000000000..65150718759ea18c9e9f06218bbf45111f0c37f9 --- /dev/null +++ b/src/PainterEngine_Application.c @@ -0,0 +1,520 @@ +#include "PainterEngine_Application.h" +#include +#include +#include +#include +#include"../include/map.h" +#include"../include/mine_map.h" +#include"../include/opt.h" + + + +PX_Application App; + + + + +PX_Object* root = PX_NULL;//定义根类型 (px必须) +PX_Object* cellbutton[10][10];//定义了十个小格子的按钮 + +PX_Object* beginbutton;//开始的按钮(在welcome里面 +PX_Object* rankingbutton;//排行榜按钮(在welcome里面 +PX_Object* menubutton;//首页的菜单栏 + +PX_Object* easymode; +PX_Object* midmode; +PX_Object* hardmode; + +PX_Object* title;//标题的图片框(在welcome里面 +px_texture titlepicture;//标题的图片(在welcome里面 +PX_Object* potatoboom;//标题的图片框(在welcome里面 +px_texture potatoboompicture;//标题的图片(在welcome里面 +PX_Object* towelcomebutton;//开始的按钮(在welcome里面 + +PX_Object* firstprize;//第一的图片框(在rank里面 +px_texture firstprizepicture;//第一的图片(in rank +PX_Object* secondprize;//第一的图片框(在rank里面 +px_texture secondprizepicture;//第一的图片(in rank +PX_Object* thirdprize;//第一的图片框(在rank里面 +px_texture thirdprizepicture;//第一的图片(in rank +PX_Object* ranktitle;//第一的图片框(在rank里面 +px_texture ranktitlepicture;//第一的图片(in rank + +px_shape flag;//旗帜的图片(in game +px_shape mine; + +opt_t cell[100][100]; +map* Map=NULL; +int mode=3; + +///函数声明 +void WELCOME(); +void RANK(); +void Gameinit(); + +void Gamenow(); +void Lclickcell(PX_Object* pObject, PX_Object_Event e, px_void* ptr); +void Rclickcell(PX_Object* pObject, PX_Object_Event e, px_void* ptr); +void Mclickcell(PX_Object* pObject, PX_Object_Event e, px_void* ptr); + + + + +///////////////////////////////////////////////////////////// +//辅助函数(不看 +/* +px_float PX_Object_Event_GetCursorX(PX_Object_Event e); +px_float PX_Object_Event_GetCursorY(PX_Object_Event e); + +px_void(*ProcessFunc)(PX_Object*, PX_Object_Event e, px_void* ptr);//点击左/右键时运行下方函数 + +*/ +///////////////////////////////////////////////////// + + + +//游戏正在进行的组件 + + + + + + + + + + + + + + + + + + + +void Gameinit() +{ + ///变换界面就删除原页面的object!(由Painterengine provide)/// +//删除之前的按钮(如果有 + if (root){ + PX_ObjectDelete(root); + } + //重新创建根对象 + root = PX_ObjectCreate(&App.runtime.mp_ui, PX_NULL, 0, 0, 0, 0, 0, 0); + ///变换界面就删除原页面的object!(由Painterengine provide)/// +//初始化map + Map = CreateMap(mode); + //生成cellbutton + printf("debug"); + for (int i = 1; i <= Map->mx; i++) + { + for (int j = 1; j <= Map->my; j++) + { + cell[j][i].y = i; + cell[j][i].x = j;//j行i列 x行y + cellbutton[j][i] = PX_Object_PushButtonCreate(&App.runtime.mp_ui, root, i * 51-51, j * 51-51, 47, 47, " ", PX_NULL); + PX_ObjectRegisterEvent(cellbutton[j][i], PX_OBJECT_EVENT_EXECUTE, Lclickcell, &cell[j][i]); + PX_ObjectRegisterEvent(cellbutton[j][i], PX_OBJECT_EVENT_CURSORRDOWN, Rclickcell, &cell[j][i]); + PX_ObjectRegisterEvent(cellbutton[j][i], PX_OBJECT_EVENT_CURSORMDOWN, Mclickcell, &cell[j][i]); + //生成结束cellbutton + } + }printf("debug"); +} + + + + + + + + +void Gamenow() +{ + printf("debug"); + + if (root) + { + PX_ObjectDelete(root); + } + //重新创建根对象 + + root = PX_ObjectCreate(&App.runtime.mp_ui, PX_NULL, 0, 0, 0, 0, 0, 0); + + + ///变换界面就删除原页面的object!(由Painterengine provide)/// + //printf("debug"); + for (int i = 1; i <= Map->mx; i++) + { + for (int j = 1; j <= Map->my; j++) + { + cell[j][i].y = i; + cell[j][i].x = j;//j行i列 x行y列 + + if (Map->stage[j][i] == MARKED) { + + cellbutton[j][i] = PX_Object_PushButtonCreate(&App.runtime.mp_ui, root, i * 51-51, j * 51-51, 47, 47, "?", PX_NULL); + PX_ObjectRegisterEvent(cellbutton[j][i], PX_OBJECT_EVENT_EXECUTE, Lclickcell, &cell[j][i]); + PX_ObjectRegisterEvent(cellbutton[j][i], PX_OBJECT_EVENT_CURSORRDOWN, Rclickcell, &cell[j][i]); + PX_ObjectRegisterEvent(cellbutton[j][i], PX_OBJECT_EVENT_CURSORMDOWN, Mclickcell, &cell[j][i]); + } + if (Map->stage[j][i] == FLAGED) + { + cellbutton[j][i] = PX_Object_PushButtonCreate(&App.runtime.mp_ui, root, i * 51-51, j * 51-51, 47, 47, " ", PX_NULL); + PX_ObjectRegisterEvent(cellbutton[j][i], PX_OBJECT_EVENT_EXECUTE, Lclickcell, &cell[j][i]); + PX_ObjectRegisterEvent(cellbutton[j][i], PX_OBJECT_EVENT_CURSORRDOWN, Rclickcell, &cell[j][i]); + PX_ObjectRegisterEvent(cellbutton[j][i], PX_OBJECT_EVENT_CURSORMDOWN, Mclickcell, &cell[j][i]); + PX_Object_PushButtonSetShape(cellbutton[j][i], &flag); + } + if (Map->stage[j][i] == UNCOVERED) + { + //printf("uncover%d %d\n", j, i); + cellbutton[j][i] = PX_Object_PushButtonCreate(&App.runtime.mp_ui, root, i * 51-51, j * 51-51, 47, 47, " ", PX_NULL); + PX_ObjectRegisterEvent(cellbutton[j][i], PX_OBJECT_EVENT_EXECUTE, Lclickcell, &cell[j][i]); + PX_ObjectRegisterEvent(cellbutton[j][i], PX_OBJECT_EVENT_CURSORRDOWN, Rclickcell, &cell[j][i]); + PX_ObjectRegisterEvent(cellbutton[j][i], PX_OBJECT_EVENT_CURSORMDOWN, Mclickcell, &cell[j][i]); + + } + if (Map->stage[j][i] == COVERED) + { + //printf("cover%d %d\n", j, i); + cellbutton[j][i] = PX_Object_PushButtonCreate(&App.runtime.mp_ui, root, i * 51-51, j * 51-51, 47, 47, " ", PX_NULL); + PX_ObjectRegisterEvent(cellbutton[j][i], PX_OBJECT_EVENT_EXECUTE, Lclickcell, &cell[j][i]); + PX_ObjectRegisterEvent(cellbutton[j][i], PX_OBJECT_EVENT_CURSORRDOWN, Rclickcell, &cell[j][i]); + PX_ObjectRegisterEvent(cellbutton[j][i], PX_OBJECT_EVENT_CURSORMDOWN, Mclickcell, &cell[j][i]); + if (opt_count(Map, j, i) == 0) { + PX_Object_PushButtonSetBorderColor(cellbutton[j][i], PX_COLOR(32, 255, 255, 255));;//标记为黑色按钮 + + } + else { + int count = opt_count(Map, j, i); + char text[2]; + sprintf(text, "%d", count); + if(count) PX_Object_PushButtonSetText(cellbutton[j][i], text); + } + + } + } + } + return; + +} + +////////////////////////////////////////////////////////////////////////////////// +void Gamewin() { + printf("you win"); +} + +void Gamefail() { + printf("debug2"); + for (int i = 1; i < Map->mx; i++) + { + for (int j = 1; j < Map->my; j++) { + if (Map->mineMap[j][i] == 1) { + PX_Object_PushButtonSetText(cellbutton[j][i], " "); + PX_Object_PushButtonSetShape(cellbutton[j][i], &mine); + PX_Object_PushButtonSetTextColor(cellbutton[j][i], PX_COLOR(255, 255, 0, 0)); + } + PX_ObjectSetEnabled(cellbutton[j][i], PX_FALSE);//使得所有按钮无效,无法继续点击! + } + } + + + printf("you lose"); +} + + + + + +////////////////////////////////////////////////////////////////////////////////// + +void Lclickcell(PX_Object* pObject, PX_Object_Event e, px_void* ptr){ + if (PX_ObjectIsCursorInRegion(pObject, e)) + { + + opt_t* pcell = (opt_t*)ptr; + + int temp; + temp= fnOptLeftClick(pcell->x, pcell->y, Map); + + if (Map->mineMap[pcell->x][pcell->y] == 1) + { + Gamefail(); + }//是雷就失败 + else if (opt_is_scuess(*Map)) { + Gamewin(); + } + else + { + + Gamenow(); + } + + } +} + +void Rclickcell(PX_Object* pObject, PX_Object_Event e, px_void* ptr) +{ + if (PX_ObjectIsCursorInRegion(pObject, e)) + { + + opt_t* pcell = (opt_t*)ptr; + int temp; + temp = fnOptRightClick(pcell->x, pcell->y, Map); + if(opt_is_scuess(*Map)) + { + Gamewin(); + } + else { + Gamenow(); + + } + + } + +} + + +void Mclickcell(PX_Object* pObject, PX_Object_Event e, px_void* ptr) +{ + if (PX_ObjectIsCursorInRegion(pObject, e)) + { + opt_t* pcell = (opt_t*)ptr; + int temp; + temp = fnOptMidClick(pcell->x, pcell->y, Map); + + + Gamenow(); + + } +} +///////////////////////////////////////////////////////////////////////// +void ceasy(PX_Object* pObject, PX_Object_Event e, px_void* ptr) +{ + if (PX_ObjectIsCursorInRegion(pObject, e)) + { + mode = 1; + Gameinit(); + + } + +} + +void cmid(PX_Object* pObject, PX_Object_Event e, px_void* ptr) +{ + if (PX_ObjectIsCursorInRegion(pObject, e)) + { + + Gameinit(); + + } + +} + +void chard(PX_Object* pObject, PX_Object_Event e, px_void* ptr) +{ + + mode = 1; + Gameinit(); + + + +} +void modechoose() { + ///变换界面就删除原页面的object!(由Painterengine provide)/// +//删除之前的按钮(如果有 + if (root) + { + PX_ObjectDelete(root); + } + //重新创建根对象 + root = PX_ObjectCreate(&App.runtime.mp_ui, PX_NULL, 0, 0, 0, 0, 0, 0); + ///变换界面就删除原页面的object!(由Painterengine provide)/// + + + easymode = PX_Object_PushButtonCreate(&App.runtime.mp_ui, root, 218, 200, 228, 64, "easy", PX_NULL); + PX_ObjectRegisterEvent(easymode, PX_OBJECT_EVENT_EXECUTE, ceasy, &easymode); + + midmode = PX_Object_PushButtonCreate(&App.runtime.mp_ui, root, 318, 300, 228, 64, "middle", PX_NULL); + PX_ObjectRegisterEvent(midmode, PX_OBJECT_EVENT_EXECUTE, cmid, &midmode); + + hardmode = PX_Object_PushButtonCreate(&App.runtime.mp_ui, root, 418, 400, 228, 64, "hard", PX_NULL); + PX_ObjectRegisterEvent(hardmode, PX_OBJECT_EVENT_EXECUTE, chard, &hardmode); +} + + + +//////////////////////----------------------------------rank 组件 +void towelcomeclick(PX_Object* pObject, PX_Object_Event e, px_void* ptr) +{ + WELCOME(); +} + + + +void RANK() +{ + ///变换界面就删除原页面的object!(由Painterengine provide)/// +//删除之前的按钮(如果有 + if (root) + { + PX_ObjectDelete(root); + } + //重新创建根对象 + root = PX_ObjectCreate(&App.runtime.mp_ui, PX_NULL, 0, 0, 0, 0, 0, 0); + ///变换界面就删除原页面的object!(由Painterengine provide)/// + + + towelcomebutton = PX_Object_PushButtonCreate(&App.runtime.mp_ui, root, 318, 400, 228, 64, "Return", PX_NULL); + PX_ObjectRegisterEvent(towelcomebutton, PX_OBJECT_EVENT_EXECUTE, towelcomeclick, &towelcomebutton); + + + //第一二三名排版 + firstprize = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 90, 90, 75, 75, &firstprizepicture); + PX_ObjectRegisterEvent(firstprize, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL); + secondprize = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 90, 190, 75, 75, &secondprizepicture); + PX_ObjectRegisterEvent(secondprize, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL); + thirdprize = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 90, 290, 75, 75, &thirdprizepicture); + PX_ObjectRegisterEvent(thirdprize, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL); + ranktitle = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 330, 20, 210, 75, &ranktitlepicture); + PX_ObjectRegisterEvent(ranktitle, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL); + +} +//////////////////////----------------------------------rank 组件 + + + + + + + + +//////////////////////----------------------------------welcome 组件 + + + + +px_void beginclick(PX_Object* pObject, PX_Object_Event e, px_void* ptr)//开始按钮的跳转 +{ + modechoose(); + + + printf("NOW begin!\n"); +} + +px_void rankingclick(PX_Object* pObject, PX_Object_Event e, px_void* ptr)//排名按钮的跳转 +{ + RANK(); + printf("Is ranking\t"); +} + + +void WELCOME()//初始化函数 +{ + ///变换界面就删除原页面的object!(由Painterengine provide)/// + //删除之前的按钮(如果有 + if (root) + { + PX_ObjectDelete(root); + } + //重新创建根对象 + root = PX_ObjectCreate(&App.runtime.mp_ui, PX_NULL, 0, 0, 0, 0, 0, 0); + ///变换界面就删除原页面的object!/// + + + + //初始化两个按钮 + beginbutton = PX_Object_PushButtonCreate(&App.runtime.mp_ui, root, 145, 400, 228, 64, "begin now", PX_NULL); + PX_ObjectRegisterEvent(beginbutton, PX_OBJECT_EVENT_EXECUTE, beginclick, &beginbutton); + + + rankingbutton = PX_Object_PushButtonCreate(&App.runtime.mp_ui, root, 490, 400, 228, 64, "RANK", PX_NULL); + PX_ObjectRegisterEvent(rankingbutton, PX_OBJECT_EVENT_EXECUTE, rankingclick, &rankingbutton); + + + //初始化界面的汉字 + + //PX_FontModuleDrawText(&App.runtime.RenderSurface, PX_NULL, 395, 200, PX_ALIGN_MIDTOP, "TEXT", PX_COLOR(250, 0, 0, 0)); + //展示静态文本框 + //title=PX_Object_LabelCreate(&App.runtime.mp_ui, root, 395, 175, 256, 64, "Minesweeper", PX_NULL, PX_COLOR(255 ,106, 106, 0)); + //PX_ObjectRegisterEvent(title, PX_OBJECT_EVENT_ANY,PX_NULL, PX_NULL); + + title = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 40, -225, 800,800, &titlepicture ); + PX_ObjectRegisterEvent(title, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL); + potatoboom = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 2, 415, 110, 105, &potatoboompicture); + PX_ObjectRegisterEvent(potatoboom, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL); + + + //这是MENU + PX_Object_Menu_Item* pItem; + menubutton=PX_Object_MenuCreate(&App.runtime.mp_ui, root,10,10,100,PX_NULL); + + pItem = PX_Object_MenuAddItem(menubutton,PX_Object_MenuGetRootItem(menubutton),"【Menu",PX_NULL,PX_NULL); + PX_Object_MenuAddItem(menubutton,pItem, "【Color", PX_NULL, PX_NULL); + + // ↑可以用一个回调函数!!!!!!必须先创建一个px_void callback(px_void* userptr)函数,【函数名可以任意取】在函数里写东西 + + +} + +/// ///////////////////////////////////////-----------------------welcome组件 + + + + + + +px_bool PX_ApplicationInitialize(PX_Application* pApp, px_int screen_width, px_int screen_height)//初始化函数(px内部) +{ + PX_ApplicationInitializeDefault(&pApp->runtime, screen_width, screen_height); + //PX_LoadShapeFromFile(&pApp->runtime.mp_resources, &titlepicture, "titlepicture.traw");//加载图片!! + //PX_LoadShapeFromFile(&pApp->runtime.mp_resources, &shape_mine, "mine.traw");//加载图片!! + //PX_LoadShapeFromFile(&pApp->runtime.mp_resources, &shape_mine, "mine.traw");//加载图片!! + + + //以下为欢迎页图片 + + PX_LoadTextureFromFile(&pApp->runtime.mp_resources, &titlepicture, "assets\\titlepicture2.traw");//加载图片!! + PX_LoadTextureFromFile(&pApp->runtime.mp_resources, &potatoboompicture, "assets\\potatoboom.traw"); +//注意文件地址!放在project里面,为何不能用相对地址??? ↑ +//以下为排行版页图片 + PX_LoadTextureFromFile(&pApp->runtime.mp_resources, &firstprizepicture, "assets\\firstprize.traw");//加载图片!! + PX_LoadTextureFromFile(&pApp->runtime.mp_resources, &secondprizepicture, "assets\\secondprize.traw"); + PX_LoadTextureFromFile(&pApp->runtime.mp_resources, &thirdprizepicture, "assets\\thirdprize.traw"); + PX_LoadTextureFromFile(&pApp->runtime.mp_resources, &ranktitlepicture, "assets\\ranktitlepicture.traw"); + + + + + + PX_LoadShapeFromFile(&pApp->runtime.mp_resources, &flag, "assets\\flagpicture.traw"); + PX_LoadShapeFromFile(&pApp->runtime.mp_resources, &mine, "assets\\minepicture.traw"); + + + WELCOME();//直接前往welcome函数 + + return PX_TRUE; +} + +px_void PX_ApplicationUpdate(PX_Application* pApp, px_dword elpased) +{ + +} + +px_void PX_ApplicationRender(PX_Application* pApp, px_dword elpased) +{ + px_surface* pRenderSurface = &pApp->runtime.RenderSurface; + PX_RuntimeRenderClear(&pApp->runtime, PX_OBJECT_UI_DEFAULT_BACKGROUNDCOLOR); + PX_ObjectRender(pRenderSurface, root, elpased); + + + +} + +px_void PX_ApplicationPostEvent(PX_Application* pApp, PX_Object_Event e) +{ + PX_ApplicationEventDefault(&pApp->runtime, e); + PX_ObjectPostEvent(root, e); + +} diff --git a/src/PainterEngine_Application.h b/src/PainterEngine_Application.h new file mode 100644 index 0000000000000000000000000000000000000000..60aa9ce1ec6b93e13f03863098cb253a68060405 --- /dev/null +++ b/src/PainterEngine_Application.h @@ -0,0 +1,24 @@ +#ifndef PAINTERENGINE_APPLICATION_H +#define PAINTERENGINE_APPLICATION_H + +#ifdef __cplusplus +extern "C"{ +#endif + +#include "PainterEngine_Startup.h" +#ifdef __cplusplus +} +#endif +typedef struct +{ + PX_Runtime runtime; +}PX_Application; + +extern PX_Application App; + +px_bool PX_ApplicationInitialize(PX_Application *App,px_int screen_Width,px_int screen_Height); +px_void PX_ApplicationUpdate(PX_Application *App,px_dword elapsed); +px_void PX_ApplicationRender(PX_Application *App,px_dword elapsed); +px_void PX_ApplicationPostEvent(PX_Application *App,PX_Object_Event e); + +#endif diff --git a/src/PainterEngine_Startup.c b/src/PainterEngine_Startup.c new file mode 100644 index 0000000000000000000000000000000000000000..fcb28f0791057bb736e436aed9aec3a0f4e1ab26 --- /dev/null +++ b/src/PainterEngine_Startup.c @@ -0,0 +1,295 @@ +#include "PainterEngine_Startup.h" + + +////////////////////////////////////////////////////////////////////////// +//Functions +static px_byte PX_ApplicationRuntime[PX_APPLICATION_MEMORYPOOL_UI_SIZE+PX_APPLICATION_MEMORYPOOL_RESOURCES_SIZE+PX_APPLICATION_MEMORYPOOL_GAME_SIZE+PX_APPLICATION_MEMORYPOOL_SPACE_SIZE]; +px_bool PX_ApplicationInitializeDefault(PX_Runtime *runtime, px_int screen_width, px_int screen_height) +{ + + + px_int surface_width=0,surface_height=0; + px_int window_width=0,window_height=0; + px_double wdh; + wdh=screen_width*1.0/screen_height; + surface_height=(px_int)(PX_sqrtd(PX_APPLICATION_SURFACE_SIZE*PX_APPLICATION_SURFACE_SIZE/wdh)); + surface_width=(px_int)(surface_height*wdh); + + + window_width=screen_width/2; + window_height=screen_height/2; + + + if(!PX_RuntimeInitialize(runtime,surface_width,surface_height,window_width,window_height,PX_ApplicationRuntime,sizeof(PX_ApplicationRuntime),PX_APPLICATION_MEMORYPOOL_UI_SIZE,PX_APPLICATION_MEMORYPOOL_RESOURCES_SIZE,PX_APPLICATION_MEMORYPOOL_GAME_SIZE)) + //if (!PX_RuntimeInitialize(runtime, 240, 240, 2240,2240 , PX_ApplicationRuntime, sizeof(PX_ApplicationRuntime), PX_APPLICATION_MEMORYPOOL_UI_SIZE, PX_APPLICATION_MEMORYPOOL_RESOURCES_SIZE, PX_APPLICATION_MEMORYPOOL_GAME_SIZE)) + return PX_FALSE; + return PX_TRUE; +} +px_void PX_ApplicationEventDefault(PX_Runtime *runtime,PX_Object_Event e) +{ + if (e.Event==PX_OBJECT_EVENT_WINDOWRESIZE) + { + px_int surface_width=0,surface_height=0; + px_double wdh; + + wdh=PX_Object_Event_GetWidth(e)*1.0/PX_Object_Event_GetHeight(e); + surface_height=(px_int)(PX_sqrtd(PX_APPLICATION_SURFACE_SIZE*PX_APPLICATION_SURFACE_SIZE/wdh)); + surface_width=(px_int)(surface_height*wdh); + + PX_RuntimeResize(runtime,surface_width,surface_height,(px_int)PX_Object_Event_GetWidth(e),(px_int)PX_Object_Event_GetHeight(e)); + return; + } +} + +#ifdef PAINTERENGIN_FILE_SUPPORT + +px_bool PX_LoadTextureFromFile(px_memorypool *mp,px_texture *tex,const px_char path[]) +{ + PX_IO_Data io; + + io=PX_LoadFileToIOData(path); + if (!io.size) + { + return PX_FALSE; + } + if (PX_TextureCreateFromMemory(mp,io.buffer,io.size,tex)) + { + PX_FreeIOData(&io); + return PX_TRUE; + } + PX_FreeIOData(&io); + return PX_FALSE; +} + +px_bool PX_LoadShapeFromFile(px_memorypool *mp,px_shape *shape,const px_char path[]) +{ + PX_IO_Data io=PX_LoadFileToIOData(path); + if (!io.size) + { + return PX_FALSE; + } + if (PX_ShapeCreateFromMemory(mp,io.buffer,io.size,shape)) + { + PX_FreeIOData(&io); + return PX_TRUE; + } + PX_FreeIOData(&io); + return PX_FALSE; + +} + + +px_bool PX_LoadSoundFromFile(px_memorypool *mp,PX_SoundData *sounddata,const px_char path[]) +{ + PX_IO_Data io=PX_LoadFileToIOData(path); + if (!io.size) + { + return PX_FALSE; + } + if (PX_WaveVerify(io.buffer,io.size)) + { + px_uint offset=0,pcmSize,woffset; + pcmSize=PX_WaveGetPCMSize(io.buffer,io.size); + + if (pcmSize!=0) + { + PX_WAVE_DATA_BLOCK *pBlock; + PX_WAVE_RIFF_HEADER *pHeader=(PX_WAVE_RIFF_HEADER *)io.buffer; + PX_WAVE_FMT_BLOCK *pfmt_block; + sounddata->mp=mp; + sounddata->buffer=(px_byte *)MP_Malloc(mp,pcmSize); + sounddata->size=pcmSize; + sounddata->channel=PX_WaveGetChannel(io.buffer,pcmSize)==1?PX_SOUND_CHANNEL_ONE:PX_SOUND_CHANNEL_DOUBLE; + if (!sounddata->buffer) + { + return PX_FALSE; + } + pfmt_block=(PX_WAVE_FMT_BLOCK *)(io.buffer+sizeof(PX_WAVE_RIFF_HEADER)); + offset+=sizeof(PX_WAVE_RIFF_HEADER); + offset+=8; + offset+=pfmt_block->dwFmtSize; + + pcmSize=0; + woffset=0; + while (offsetszDataID,"data",4)) + { + offset+=pBlock->dwDataSize+sizeof(PX_WAVE_DATA_BLOCK); + continue; + } + offset+=sizeof(PX_WAVE_DATA_BLOCK); + PX_memcpy(sounddata->buffer+woffset,io.buffer+offset,pBlock->dwDataSize); + offset+=pBlock->dwDataSize; + woffset+=pBlock->dwDataSize; + } + } + else + { + PX_FreeIOData(&io); + return PX_FALSE; + } + } + else + { + PX_FreeIOData(&io); + return PX_FALSE; + } + PX_FreeIOData(&io); + return PX_TRUE; +} + + +px_bool PX_LoadAnimationLibraryFromFile(px_memorypool *mp,PX_AnimationLibrary *lib,const px_char path[]) +{ + PX_IO_Data io; + io=PX_LoadFileToIOData(path); + if (!io.size) + { + return PX_FALSE; + } + if (PX_AnimationLibraryCreateFromMemory(mp,lib,io.buffer,io.size)) + { + PX_FreeIOData(&io); + return PX_TRUE; + } + PX_FreeIOData(&io); + return PX_FALSE; + +} + +px_bool PX_LoadScriptFromFile(px_memory *code,const px_char path[]) +{ + PX_IO_Data io=PX_LoadFileToIOData(path); + if (!io.size) + { + return PX_FALSE; + } + if(!PX_MemoryCopy(code,io.buffer,0,io.size)) + goto _ERROR; + + PX_FreeIOData(&io); + return PX_TRUE; +_ERROR: + PX_FreeIOData(&io); + return PX_FALSE; + +} + + +px_bool PX_LoadScriptInstanceFromFile(px_memorypool *mp,PX_ScriptVM_Instance *ins,const px_char path[]) +{ + PX_IO_Data io=PX_LoadFileToIOData(path); + if (!io.size) + { + return PX_FALSE; + } + if(!PX_ScriptVM_InstanceInitialize(ins,mp,io.buffer,io.size)) + goto _ERROR; + + PX_FreeIOData(&io); + return PX_TRUE; +_ERROR: + PX_FreeIOData(&io); + return PX_FALSE; +} + +px_bool PX_LoadTextureToResource(PX_ResourceLibrary *ResourceLibrary,const px_char Path[],const px_char key[]) +{ + PX_IO_Data io; + io=PX_LoadFileToIOData(Path); + if (!io.size)goto _ERROR; + if(!PX_ResourceLibraryLoad(ResourceLibrary,PX_RESOURCE_TYPE_TEXTURE,io.buffer,io.size,key)) goto _ERROR; + PX_FreeIOData(&io); + return PX_TRUE; +_ERROR: + PX_FreeIOData(&io); + return PX_FALSE; +} + +px_bool PX_LoadShapeToResource(PX_ResourceLibrary *ResourceLibrary,const px_char Path[],const px_char key[]) +{ + PX_IO_Data io; + io=PX_LoadFileToIOData(Path); + if (!io.size)goto _ERROR; + if(!PX_ResourceLibraryLoad(ResourceLibrary,PX_RESOURCE_TYPE_SHAPE,io.buffer,io.size,key)) goto _ERROR; + PX_FreeIOData(&io); + return PX_TRUE; +_ERROR: + PX_FreeIOData(&io); + return PX_FALSE; +} + +px_bool PX_LoadAnimationToResource(PX_ResourceLibrary *ResourceLibrary,const px_char Path[],const px_char key[]) +{ + PX_IO_Data io; + io=PX_LoadFileToIOData(Path); + if (!io.size)goto _ERROR; + if(!PX_ResourceLibraryLoad(ResourceLibrary,PX_RESOURCE_TYPE_ANIMATIONLIBRARY,io.buffer,io.size,key)) goto _ERROR; + PX_FreeIOData(&io); + return PX_TRUE; +_ERROR: + PX_FreeIOData(&io); + return PX_FALSE; +} + +px_bool PX_LoadScriptToResource(PX_ResourceLibrary *ResourceLibrary,const px_char Path[],const px_char key[]) +{ + PX_IO_Data io; + io=PX_LoadFileToIOData(Path); + if (!io.size)goto _ERROR; + if(!PX_ResourceLibraryLoad(ResourceLibrary,PX_RESOURCE_TYPE_SCRIPT,io.buffer,io.size,key)) goto _ERROR; + PX_FreeIOData(&io); + return PX_TRUE; +_ERROR: + PX_FreeIOData(&io); + return PX_FALSE; +} + + +px_bool PX_LoadSoundToResource(PX_ResourceLibrary *ResourceLibrary,const px_char Path[],const px_char key[]) +{ + PX_IO_Data io; + io=PX_LoadFileToIOData(Path); + if (!io.size)goto _ERROR; + if(!PX_ResourceLibraryLoad(ResourceLibrary,PX_RESOURCE_TYPE_SOUND,io.buffer,io.size,key)) goto _ERROR; + PX_FreeIOData(&io); + return PX_TRUE; +_ERROR: + PX_FreeIOData(&io); + return PX_FALSE; +} + +px_bool PX_LoadFontModuleFromFile(PX_FontModule *fm,const px_char Path[]) +{ + PX_IO_Data io; + io=PX_LoadFileToIOData(Path); + if (!io.size)goto _ERROR; + if(!PX_FontModuleLoad(fm,io.buffer,io.size)) goto _ERROR; + PX_FreeIOData(&io); + return PX_TRUE; +_ERROR: + PX_FreeIOData(&io); + return PX_FALSE; +} + +px_bool PX_LoadJsonFromFile(PX_Json *json,const px_char *path) +{ + PX_IO_Data io=PX_LoadFileToIOData((px_char *)path); + if (!io.size) + { + return PX_FALSE; + } + + if(!PX_JsonParse(json,(px_char *)io.buffer))goto _ERROR; + + + PX_FreeIOData(&io); + return PX_TRUE; +_ERROR: + PX_FreeIOData(&io); + return PX_FALSE; +} + +#endif \ No newline at end of file diff --git a/src/PainterEngine_Startup.h b/src/PainterEngine_Startup.h new file mode 100644 index 0000000000000000000000000000000000000000..d2019f64d7b4c911ad61a8ca57464cc35852e2b3 --- /dev/null +++ b/src/PainterEngine_Startup.h @@ -0,0 +1,39 @@ +#ifndef PAINTERENGINE_STARTUP_H +#define PAINTERENGINE_STARTUP_H + +////////////////////////////////////////////////////////////////////////// +//Configures +#include "platform/modules/px_file.h" + +#define PX_APPLICATION_NAME "PainterEngine" +#define PX_APPLICATION_SURFACE_SIZE 680 + +#define PX_APPLICATION_MEMORYPOOL_UI_SIZE 1024*1024*16 +#define PX_APPLICATION_MEMORYPOOL_RESOURCES_SIZE 1024*1024*96 +#define PX_APPLICATION_MEMORYPOOL_GAME_SIZE 1024*1024*8 +#define PX_APPLICATION_MEMORYPOOL_SPACE_SIZE 1024*1024*8 +////////////////////////////////////////////////////////////////////////// + +#include "architecture/PainterEngine_Runtime.h" +px_bool PX_ApplicationInitializeDefault(PX_Runtime *runtime, px_int screen_width, px_int screen_height); +px_void PX_ApplicationEventDefault(PX_Runtime *runtime,PX_Object_Event e); + +#ifdef PAINTERENGINE_FILE_H +px_bool PX_LoadTextureFromFile(px_memorypool *mp,px_texture *tex,const px_char path[]); +px_bool PX_LoadShapeFromFile(px_memorypool *mp,px_shape *shape,const px_char path[]); +px_bool PX_LoadSoundFromFile(px_memorypool *mp,PX_SoundData *sounddata,const px_char path[]); +px_bool PX_LoadAnimationLibraryFromFile(px_memorypool *mp,PX_AnimationLibrary *lib,const px_char path[]); +px_bool PX_LoadScriptFromFile(px_memory *code,const px_char path[]); +px_bool PX_LoadScriptInstanceFromFile(px_memorypool *mp,PX_ScriptVM_Instance *ins,const px_char path[]); + +px_bool PX_LoadTextureToResource(PX_ResourceLibrary *presourcelib,const px_char Path[],const px_char key[]); +px_bool PX_LoadShapeToResource(PX_ResourceLibrary *presourcelib,const px_char Path[],const px_char key[]); +px_bool PX_LoadAnimationToResource(PX_ResourceLibrary *presourcelib,const px_char Path[],const px_char key[]); +px_bool PX_LoadScriptToResource(PX_ResourceLibrary *presourcelib,const px_char Path[],const px_char key[]); +px_bool PX_LoadSoundToResource(PX_ResourceLibrary *presourcelib,const px_char Path[],const px_char key[]); +px_bool PX_LoadFontModuleFromFile(PX_FontModule *fm,const px_char Path[]); +px_bool PX_LoadJsonFromFile(PX_Json *json,const px_char *path); +#endif + + +#endif diff --git a/src/map.c b/src/map.c new file mode 100644 index 0000000000000000000000000000000000000000..c2ca6a91f8a58f154f22b01af482d7704e68c497 --- /dev/null +++ b/src/map.c @@ -0,0 +1,73 @@ +#include +#include +#include +#include +#include "../include/map.h" +#include "../include/mine_map.h" + +map *CreateMap(int mode) +{ + map *Map = malloc(sizeof(map)); + if (Map == NULL) + return NULL; + switch (mode) + { + case MODE_EASY: + Map->mx = MX_EASY; + Map->my = MY_EASY; + Map->cnt = NUM_EASY; + break; + case MODE_MID: + Map->mx = MX_MID; + Map->my = MY_MID; + Map->cnt = NUM_MID; + break; + case MODE_HARD: + Map->mx = MX_HARD; + Map->my = MY_HARD; + Map->cnt = NUM_HARD; + break; + default: + break; + } + Map -> generated = false; + return Map; +} + +void Setmine(map *Map, int posx, int posy, unsigned int seed) +{ + + for (int i = 0; i <= Map->mx; i++) + { + for (int j = 0; j <= Map->my; j++) + { + Map->autobook[i][j] = 0; + Map->mineMap[i][j] = 0; + Map->stage[i][j] = 0; + } + } + int cnt = 0; + srand(seed); + while (cnt < Map->cnt) + { + int x, y; + x = (rand() % (Map->mx)) + 1; + y = (rand() % (Map->my)) + 1; + if(abs(posx - x) <= 1 && abs(posy - y) <= 1) continue; + if (Map->mineMap[x][y] == 0) + { + Map->mineMap[x][y] = 1; + cnt++; + } + } + Map -> generated = true; +#ifdef DEBUG + puts("\nMap INFO:"); + printf("Seed: %u\n", seed); + for (int i = 1; i <= Map->mx; i++) + { + for (int j = 1; j <= Map->my; j++) putchar(Map -> mineMap[i][j] + '0'); + putchar('\n'); + } +#endif +} diff --git a/src/opt.c b/src/opt.c new file mode 100644 index 0000000000000000000000000000000000000000..6b45af95a91bf5b726e6c6bbb6c4fa26534737c1 --- /dev/null +++ b/src/opt.c @@ -0,0 +1,231 @@ +#include "../include/mine_map.h" +#include "../include/opt.h" +#include "../include/map.h" +#include +#include + +int opt(map *m, opt_t opt) +{ + /** + * @brief 操作类型 + * + */ + int optMode; + /** + * @brief 操作坐标 + * + */ + int optX, optY; + optX = opt.x; + optY = opt.y; + optMode = opt.mode; + if (optX < 1 || optX > m->mx || optY < 1 || optY > m->my) + return UNALLOWED; + switch (optMode) + { + case OPT_LEFT_CLICK: + return fnOptLeftClick(optX, optY, m); + break; + case OPT_MID_CLICK: + return fnOptMidClick(optX, optY, m); + break; + case OPT_RIGTH_CLICK: + return fnOptRightClick(optX, optY, m); + break; + case OPT_TOTAL_CLICK: + return fnTotalFlag(m); + break; + default: + return UNALLOWED; + break; + } +} + +int opt_count(map *map, int x, int y) +{ + int cnt = 0; + for (int i = x - 1; i <= x + 1; i++) + { + for (int j = y - 1; j <= y + 1; j++) + { + if (i < 1 || j < 1 || i > map->mx || j > map->my) + continue; + if (i == x && j == y) + continue; + if (map->mineMap[i][j] == 1) + cnt++; + } + } + return cnt; +} + +int opt_flag_count(map *map, int x, int y) +{ + int cnt = 0; + for (int i = x - 1; i <= x + 1; i++) + { + for (int j = y - 1; j <= y + 1; j++) + { + if (i < 1 || j < 1 || i > map->mx || j > map->my) + continue; + if (i == x && j == y) + continue; + if (map->stage[i][j] == FLAGED) + cnt++; + } + } + return cnt; +} + +int fnOptLeftClick(int x, int y, map *m) +{ + if(!m -> generated) Setmine(m, x, y, (unsigned int)time(NULL)); + /** + * @brief 地图当前状态 + * + */ + int map_stage; + + map_stage = m->stage[x][y]; + /** + * @brief 判断当前格子是否是雷 + * + */ + bool map_mine; + map_mine = (m->mineMap[x][y] == 1) ? true : false; + /** + * @brief 左键实现 + * 如果当前格子被标记或者已经打开 + * 返回UNALLOWED + */ + if (map_stage == FLAGED || map_stage == COVERED || map_stage == MARKED) + return UNALLOWED; + + if (map_mine == true) + { + m->stage[x][y] = COVERED; + return BOOM; + } + + m->stage[x][y] = COVERED; + if (opt_count(m, x, y) == 0) + fnOptAuto(x, y, m); + return ALLOWED; +} + +int fnOptRightClick(int x, int y, map *m) +{ + + /** + * @brief 地图当前状态 + * + */ + int map_stage; + + map_stage = m->stage[x][y]; + switch (map_stage) + { + case COVERED: + return UNALLOWED; + break; + case UNCOVERED: + m->stage[x][y] = FLAGED; + break; + case FLAGED: + m->stage[x][y] = MARKED; + break; + case MARKED: + m->stage[x][y] = UNCOVERED; + break; + default: + return ALLOWED; + break; + } +} + +int fnOptMidClick(int x, int y, map *m) +{ + /** + * @brief 地图当前状态 + * + */ + int map_stage; + map_stage = m->stage[x][y]; + if (map_stage != COVERED) + return UNALLOWED; + if (opt_count(m, x, y) != opt_flag_count(m, x, y)) + return UNALLOWED; + fnOptAuto(x, y, m); + return ALLOWED; +} + +void fnOptAuto(int x, int y, map *m) +{ + if (m->autobook[x][y] == 1) + return; + m->autobook[x][y] = 1; + for (int i = -1; i <= 1; i++) + { + for (int j = -1; j <= 1; j++) + { + int fx = x + i, fy = y + j; + if (i == 0 && j == 0) + continue; + if (fx < 1 || fx > m->mx || fy < 1 || fy > m->my) + continue; + if (m->stage[fx][fy] == UNCOVERED) + { + m->stage[fx][fy] = COVERED; + if (opt_count(m, fx, fy) == 0) + fnOptAuto(fx, fy, m); + } + } + } + return; +} + +bool opt_is_scuess(map m) +{ + /** + * @brief 扫雷成功条件 + * 打开所有不是雷的格子 + * + */ + int coverCnt = 0; + for (int i = 1; i <= m.mx; i++) + { + for (int j = 1; j <= m.my; j++) + { + if (m.stage[i][j] == COVERED) + coverCnt++; + } + } + if (coverCnt == (m.mx * m.my - m.cnt)) + return true; + else + return false; +} + +int fnTotalFlag(map *m) +{ + int flagCnt = 0; + for (int i = 1; i <= m->mx; i++) + for (int j = 1; j <= m->my; j++) + if (m->stage[i][j] == FLAGED) + flagCnt++; + if (flagCnt != m->cnt) + return UNALLOWED; + + for (int i = 1; i <= m->mx; i++) + { + for (int j = 1; j <= m->my; j++) + { + if (m->stage[i][j] != UNCOVERED) + continue; + m->stage[i][j] = COVERED; + if (m->mineMap[i][j] == 1) + return BOOM; + } + } + return ALLOWED; +} \ No newline at end of file diff --git a/test.txt b/test.txt deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000