├── .gitignore ├── CMakeLists.txt ├── LICENSE.txt ├── README.md ├── Sources ├── wxWidgetsAppSupport │ ├── WXAS_ContextFactory.cpp │ ├── WXAS_ContextFactory.hpp │ ├── WXAS_ControlUtilities.cpp │ ├── WXAS_ControlUtilities.hpp │ ├── WXAS_NodeEditorControl.cpp │ ├── WXAS_NodeEditorControl.hpp │ ├── WXAS_ParameterDialog.cpp │ ├── WXAS_ParameterDialog.hpp │ ├── WXAS_wxDrawingContext.cpp │ └── WXAS_wxDrawingContext.hpp └── wxWidgetsTestApp │ ├── DrawingControl.cpp │ ├── DrawingControl.hpp │ ├── ResultImage.cpp │ ├── ResultImage.hpp │ ├── TestAppNodes.cpp │ ├── TestAppNodes.hpp │ ├── TestAppValues.cpp │ ├── TestAppValues.hpp │ └── main.cpp ├── appveyor.yml └── installdepswin.py /.gitignore: -------------------------------------------------------------------------------- 1 | Build/* 2 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.6) 2 | 3 | set (VSE_VERSION_1 0) 4 | set (VSE_VERSION_2 0) 5 | set (VSE_VERSION_3 2) 6 | set (VSE_APP_NAME VisualScriptEngineWxWidgets) 7 | 8 | function (SetCompilerOptions module) 9 | target_compile_options (${module} PUBLIC "$<$:-DDEBUG>") 10 | if (MSVC) 11 | target_compile_options (${module} PUBLIC /W4 /WX) 12 | else () 13 | target_compile_options (${module} PUBLIC -std=c++11 -Wall -Wextra -Werror) 14 | endif () 15 | endfunction () 16 | 17 | set_property (GLOBAL PROPERTY USE_FOLDERS ON) 18 | 19 | set (CMAKE_SUPPRESS_REGENERATION 1) 20 | set (CMAKE_CONFIGURATION_TYPES Debug;Release) 21 | set (CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/DevKit CACHE PATH "Install prefix.") 22 | set (CMAKE_DEBUG_POSTFIX "Debug") 23 | set (VSE_DEVKIT_DIR $ENV{VSE_DEVKIT_DIR} CACHE PATH "VisualScriptEngine binary directory.") 24 | set (WXWIDGETS_DIR $ENV{WXWIDGETS_DIR} CACHE PATH "wxWidgets binary directory.") 25 | set (VSE_LIB_POSTFIX "$<$:Debug>") 26 | 27 | add_definitions (-DUNICODE -D_UNICODE) 28 | link_directories (${VSE_DEVKIT_DIR}/lib) 29 | 30 | project (VisualScriptEngineWxWidgets) 31 | 32 | enable_testing () 33 | 34 | if (MSVC AND NOT ${WXWIDGETS_DIR} STREQUAL "") 35 | set (WXWIDGETS_LIBS_DIR) 36 | set (WXWIDGETS_PLATFORM_INCLUDE_DIR) 37 | if (MSVC) 38 | set (WXWIDGETS_LIBS_DIR ${WXWIDGETS_DIR}/lib/vc_x64_lib) 39 | set (WXWIDGETS_PLATFORM_INCLUDE_DIR ${WXWIDGETS_DIR}/include/msvc) 40 | endif () 41 | link_directories (${WXWIDGETS_LIBS_DIR}) 42 | 43 | # wxWidgetsAppSupport 44 | 45 | set (wxWidgetsAppSupportSourcesFolder Sources/wxWidgetsAppSupport) 46 | file (GLOB wxWidgetsAppSupportHeaderFiles ${wxWidgetsAppSupportSourcesFolder}/*.hpp) 47 | file (GLOB wxWidgetsAppSupportSourceFiles ${wxWidgetsAppSupportSourcesFolder}/*.cpp) 48 | set ( 49 | wxWidgetsAppSupportFiles 50 | ${wxWidgetsAppSupportHeaderFiles} 51 | ${wxWidgetsAppSupportSourceFiles} 52 | ) 53 | source_group ("Sources" FILES ${wxWidgetsAppSupportFiles}) 54 | add_library (wxWidgetsAppSupport STATIC ${wxWidgetsAppSupportFiles}) 55 | target_include_directories ( 56 | wxWidgetsAppSupport PUBLIC 57 | ${VSE_DEVKIT_DIR}/include 58 | ${WXWIDGETS_DIR}/include 59 | ${WXWIDGETS_PLATFORM_INCLUDE_DIR} 60 | ) 61 | target_link_libraries (wxWidgetsAppSupport 62 | ${VSE_DEVKIT_DIR}/lib/NodeEngine${VSE_LIB_POSTFIX}.lib 63 | ${VSE_DEVKIT_DIR}/lib/NodeUIEngine${VSE_LIB_POSTFIX}.lib 64 | ${VSE_DEVKIT_DIR}/lib/BuiltInNodes${VSE_LIB_POSTFIX}.lib 65 | ) 66 | target_compile_definitions (wxWidgetsAppSupport PUBLIC _CRT_SECURE_NO_WARNINGS) 67 | SetCompilerOptions (wxWidgetsAppSupport) 68 | install (TARGETS wxWidgetsAppSupport DESTINATION lib) 69 | install (FILES ${wxWidgetsAppSupportHeaderFiles} DESTINATION include) 70 | install (FILES ${wxWidgetsAppSupportSourceFiles} DESTINATION source) 71 | 72 | # wxWidgetsTestApp 73 | 74 | set (wxWidgetsTestAppSourcesFolder Sources/wxWidgetsTestApp) 75 | file (GLOB wxWidgetsTestAppHeaderFiles ${wxWidgetsTestAppSourcesFolder}/*.hpp) 76 | file (GLOB wxWidgetsTestAppSourceFiles ${wxWidgetsTestAppSourcesFolder}/*.cpp) 77 | set ( 78 | wxWidgetsTestAppFiles 79 | ${wxWidgetsTestAppHeaderFiles} 80 | ${wxWidgetsTestAppSourceFiles} 81 | ) 82 | source_group ("Sources" FILES ${wxWidgetsTestAppFiles}) 83 | add_executable (wxWidgetsTestApp WIN32 ${wxWidgetsTestAppFiles}) 84 | target_include_directories ( 85 | wxWidgetsTestApp PUBLIC 86 | ${NodeEngineSourcesFolder} 87 | ${NodeUIEngineSourcesFolder} 88 | ${BuiltInNodesSourcesFolder} 89 | ${TestFrameworkSourcesFolder} 90 | ${wxWidgetsAppSupportSourcesFolder} 91 | ${VSE_DEVKIT_DIR}/include 92 | ${WXWIDGETS_DIR}/include 93 | ${WXWIDGETS_PLATFORM_INCLUDE_DIR} 94 | ) 95 | target_link_libraries (wxWidgetsTestApp 96 | ${VSE_DEVKIT_DIR}/lib/NodeEngine${VSE_LIB_POSTFIX}.lib 97 | ${VSE_DEVKIT_DIR}/lib/NodeUIEngine${VSE_LIB_POSTFIX}.lib 98 | ${VSE_DEVKIT_DIR}/lib/BuiltInNodes${VSE_LIB_POSTFIX}.lib 99 | wxWidgetsAppSupport 100 | ) 101 | target_compile_definitions (wxWidgetsTestApp PUBLIC _CRT_SECURE_NO_WARNINGS) 102 | SetCompilerOptions (wxWidgetsTestApp) 103 | 104 | endif () 105 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VisualScriptEngineWxWidgets 2 | 3 | [![Build Status](https://ci.appveyor.com/api/projects/status/0yniyf4ojyl1omy2?svg=true)](https://ci.appveyor.com/project/kovacsv/visualscriptenginewxwidgets) 4 | 5 | VisualScriptEngineWxWidgets is a utility module for [VisualScriptEngine](https://github.com/kovacsv/VisualScriptEngine) which provides helper classes for embedding the engine in a wxWidgets application. 6 | 7 | # Build 8 | 9 | You can build with Visual Studio by following these steps. 10 | * Build [wxWidgets](https://www.wxwidgets.org): 11 | * [Download and install wxWidgets v3.1.2 from here](https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.2/wxMSW-3.1.2-Setup.exe). 12 | * Open the solution from `build\msw\wx_vc15.sln` from the wxWidgets installation folder. 13 | * Build with Debug/x64 and Release/x64 configuration. 14 | * Build [VisualScriptEngine](https://github.com/kovacsv/VisualScriptEngine): 15 | * [Download the latest version of VisualScriptEngine from here](https://github.com/kovacsv/VisualScriptEngine/archive/master.zip). 16 | * Generate the project with cmake, and build it with Debug/x64 and Release/x64 configuration. 17 | * Build the `INSTALL` project for both configurations. 18 | * Build VisualScriptEngineWxWidgets: 19 | * Set the following environment variables: 20 | * `WXWIDGETS_DIR`: the wxWidgets installation directory (by default C:\wxWidgets-3.1.2) 21 | * `VSE_DEVKIT_DIR`: the VisualScriptEngine development kit directory (the DevKit folder next to the generated solution) 22 | * Generate the project with cmake and build it. 23 | -------------------------------------------------------------------------------- /Sources/wxWidgetsAppSupport/WXAS_ContextFactory.cpp: -------------------------------------------------------------------------------- 1 | #include "WXAS_ContextFactory.hpp" 2 | #include "WXAS_wxDrawingContext.hpp" 3 | 4 | #define USE_WX_CONTEXT 5 | 6 | namespace WXAS 7 | { 8 | 9 | void* GetNativeHandle (wxPanel* panel) 10 | { 11 | return panel; 12 | } 13 | 14 | std::unique_ptr CreateNativeDrawingContext () 15 | { 16 | return std::unique_ptr (new wxDrawingContext ()); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Sources/wxWidgetsAppSupport/WXAS_ContextFactory.hpp: -------------------------------------------------------------------------------- 1 | #ifndef WXAS_CONTEXTFACTORY_HPP 2 | #define WXAS_CONTEXTFACTORY_HPP 3 | 4 | #include "NUIE_DrawingContext.hpp" 5 | 6 | #include 7 | #include 8 | 9 | namespace WXAS 10 | { 11 | 12 | void* GetNativeHandle (wxPanel* panel); 13 | std::unique_ptr CreateNativeDrawingContext (); 14 | 15 | } 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /Sources/wxWidgetsAppSupport/WXAS_ControlUtilities.cpp: -------------------------------------------------------------------------------- 1 | #include "WXAS_ControlUtilities.hpp" 2 | 3 | namespace WXAS 4 | { 5 | 6 | MouseCaptureHandler::MouseCaptureHandler (wxPanel* panel) : 7 | panel (panel), 8 | counter (0) 9 | { 10 | 11 | } 12 | 13 | void MouseCaptureHandler::OnMouseDown () 14 | { 15 | if (counter == 0) { 16 | panel->CaptureMouse (); 17 | } 18 | counter++; 19 | } 20 | 21 | void MouseCaptureHandler::OnMouseUp () 22 | { 23 | counter--; 24 | if (counter == 0) { 25 | panel->ReleaseMouse (); 26 | } 27 | if (counter < 0) { 28 | counter = 0; 29 | } 30 | } 31 | 32 | void MouseCaptureHandler::OnCaptureLost () 33 | { 34 | counter--; 35 | } 36 | 37 | BusyCursorGuard::BusyCursorGuard () 38 | { 39 | wxBeginBusyCursor (); 40 | } 41 | 42 | BusyCursorGuard::~BusyCursorGuard () 43 | { 44 | wxEndBusyCursor (); 45 | } 46 | 47 | NUIE::ModifierKeys GetModiferKeysFromEvent (wxKeyboardState& evt) 48 | { 49 | NUIE::ModifierKeys keys; 50 | if (evt.ControlDown ()) { 51 | keys.Insert (NUIE::ModifierKeyCode::Command); 52 | } 53 | if (evt.ShiftDown ()) { 54 | keys.Insert (NUIE::ModifierKeyCode::Shift); 55 | } 56 | return keys; 57 | } 58 | 59 | NUIE::CommandCode GetCommandFromEvent (wxKeyEvent& evt) 60 | { 61 | wxChar unicodeKey = evt.GetUnicodeKey (); 62 | if (unicodeKey <= WXK_ESCAPE || unicodeKey == WXK_SPACE || unicodeKey == WXK_DELETE || unicodeKey >= WXK_START) { 63 | int key = evt.GetKeyCode (); 64 | switch (key) { 65 | case WXK_ESCAPE: 66 | return NUIE::CommandCode::Escape; 67 | case WXK_DELETE: 68 | case WXK_BACK: 69 | return NUIE::CommandCode::Delete; 70 | } 71 | } 72 | 73 | NUIE::ModifierKeys modifierKeys = GetModiferKeysFromEvent (evt); 74 | bool isControlPressed = modifierKeys.Contains (NUIE::ModifierKeyCode::Command); 75 | bool isShiftPressed = modifierKeys.Contains (NUIE::ModifierKeyCode::Shift); 76 | if (isControlPressed) { 77 | switch (unicodeKey) { 78 | case L'A': 79 | return NUIE::CommandCode::SelectAll; 80 | case L'C': 81 | return NUIE::CommandCode::Copy; 82 | case L'G': 83 | if (isShiftPressed) { 84 | return NUIE::CommandCode::Ungroup; 85 | } else { 86 | return NUIE::CommandCode::Group; 87 | } 88 | case L'V': 89 | return NUIE::CommandCode::Paste; 90 | case L'Z': 91 | if (isShiftPressed) { 92 | return NUIE::CommandCode::Redo; 93 | } else { 94 | return NUIE::CommandCode::Undo; 95 | } 96 | } 97 | } 98 | 99 | return NUIE::CommandCode::Undefined; 100 | } 101 | 102 | void SetTextControlValidator (wxTextCtrl* textCtrl, const std::wstring& validChars) 103 | { 104 | wxTextValidator validator (wxFILTER_INCLUDE_CHAR_LIST); 105 | wxArrayString includeList; 106 | 107 | for (const wchar_t& character : validChars) { 108 | includeList.Add (character); 109 | } 110 | 111 | validator.SetIncludes (includeList); 112 | textCtrl->SetValidator (validator); 113 | } 114 | 115 | NUIE::MenuCommandPtr SelectCommandFromContextMenu (wxPanel* panel, const NUIE::Point& position, const NUIE::MenuCommandStructure& commands) 116 | { 117 | if (commands.IsEmpty ()) { 118 | return nullptr; 119 | } 120 | 121 | wxMenu popupMenu; 122 | wxMenu* currentMenu = &popupMenu; 123 | 124 | size_t currentCommandId = 1000; 125 | std::unordered_map commandTable; 126 | std::function addCommand = [&] (const NUIE::MenuCommandPtr& command) { 127 | if (command->HasChildCommands ()) { 128 | wxMenu* oldMenu = currentMenu; 129 | currentMenu = new wxMenu (); 130 | oldMenu->AppendSubMenu (currentMenu, command->GetName ()); 131 | command->EnumerateChildCommands (addCommand); 132 | currentMenu = oldMenu; 133 | } else { 134 | wxMenuItem* currentMenuItem = currentMenu->AppendCheckItem (currentCommandId, command->GetName ()); 135 | currentMenuItem->Check (command->IsChecked ()); 136 | commandTable.insert ({ currentCommandId, command }); 137 | currentCommandId += 1; 138 | } 139 | }; 140 | commands.EnumerateCommands (addCommand); 141 | 142 | wxPoint mousePos ((int) position.GetX (), (int) position.GetY ()); 143 | int selectedItem = panel->GetPopupMenuSelectionFromUser (popupMenu, mousePos); 144 | if (selectedItem == wxID_NONE) { 145 | return nullptr; 146 | } 147 | 148 | return commandTable[selectedItem]; 149 | } 150 | 151 | } 152 | -------------------------------------------------------------------------------- /Sources/wxWidgetsAppSupport/WXAS_ControlUtilities.hpp: -------------------------------------------------------------------------------- 1 | #ifndef WXAS_CONTROLUTILITIES_HPP 2 | #define WXAS_CONTROLUTILITIES_HPP 3 | 4 | #include "NUIE_NodeEditor.hpp" 5 | #include "NUIE_MenuCommands.hpp" 6 | #include 7 | 8 | namespace WXAS 9 | { 10 | 11 | // On double click event the mouse down and up events are not in pair 12 | class MouseCaptureHandler 13 | { 14 | public: 15 | MouseCaptureHandler (wxPanel* panel); 16 | 17 | void OnMouseDown (); 18 | void OnMouseUp (); 19 | void OnCaptureLost (); 20 | 21 | private: 22 | wxPanel* panel; 23 | int counter; 24 | }; 25 | 26 | class BusyCursorGuard 27 | { 28 | public: 29 | BusyCursorGuard (); 30 | ~BusyCursorGuard (); 31 | }; 32 | 33 | NUIE::ModifierKeys GetModiferKeysFromEvent (wxKeyboardState& evt); 34 | NUIE::CommandCode GetCommandFromEvent (wxKeyEvent& evt); 35 | 36 | void SetTextControlValidator (wxTextCtrl* textCtrl, const std::wstring& validChars); 37 | NUIE::MenuCommandPtr SelectCommandFromContextMenu (wxPanel* panel, const NUIE::Point& position, const NUIE::MenuCommandStructure& commands); 38 | 39 | } 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /Sources/wxWidgetsAppSupport/WXAS_NodeEditorControl.cpp: -------------------------------------------------------------------------------- 1 | #include "WXAS_NodeEditorControl.hpp" 2 | #include "WXAS_ContextFactory.hpp" 3 | #include "WXAS_ParameterDialog.hpp" 4 | 5 | #include 6 | 7 | namespace WXAS 8 | { 9 | 10 | NodeEditorEventHandler::NodeEditorEventHandler (NodeEditorControl* control) : 11 | control (control) 12 | { 13 | 14 | } 15 | 16 | NodeEditorEventHandler::~NodeEditorEventHandler () 17 | { 18 | 19 | } 20 | 21 | NUIE::MenuCommandPtr NodeEditorEventHandler::OnContextMenu (NUIE::EventHandler::ContextMenuType, const NUIE::Point& position, const NUIE::MenuCommandStructure& commands) 22 | { 23 | return SelectCommandFromContextMenu (control, position, commands); 24 | } 25 | 26 | bool NodeEditorEventHandler::OnParameterSettings (NUIE::EventHandler::ParameterSettingsType, NUIE::ParameterInterfacePtr paramInterface) 27 | { 28 | ParameterDialog paramDialog (control, paramInterface); 29 | if (paramDialog.ShowModal () == wxID_OK) { 30 | return true; 31 | } 32 | return false; 33 | } 34 | 35 | void NodeEditorEventHandler::OnDoubleClick (const NUIE::Point&, NUIE::MouseButton) 36 | { 37 | 38 | } 39 | 40 | NodeEditorUIEnvironment::NodeEditorUIEnvironment ( NodeEditorControl* nodeEditorControl, 41 | NE::StringConverterPtr& stringConverter, 42 | NUIE::SkinParamsPtr& skinParams, 43 | NUIE::EventHandlerPtr& eventHandler, 44 | NE::EvaluationEnv& evaluationEnv) : 45 | nodeEditorControl (nodeEditorControl), 46 | evaluationEnv (evaluationEnv), 47 | stringConverter (stringConverter), 48 | skinParams (skinParams), 49 | eventHandler (eventHandler), 50 | clipboardHandler (new NUIE::MemoryClipboardHandler ()), 51 | drawingContext (CreateNativeDrawingContext ()) 52 | { 53 | drawingContext->Init (GetNativeHandle (nodeEditorControl)); 54 | } 55 | 56 | NodeEditorUIEnvironment::~NodeEditorUIEnvironment () 57 | { 58 | 59 | } 60 | 61 | void NodeEditorUIEnvironment::OnPaint (wxPanel*, wxPaintEvent&) 62 | { 63 | drawingContext->BlitToWindow (GetNativeHandle (nodeEditorControl)); 64 | } 65 | 66 | void NodeEditorUIEnvironment::OnResize (int width, int height) 67 | { 68 | drawingContext->Resize (width, height); 69 | } 70 | 71 | const NE::StringConverter& NodeEditorUIEnvironment::GetStringConverter () 72 | { 73 | return *stringConverter; 74 | } 75 | 76 | const NUIE::SkinParams& NodeEditorUIEnvironment::GetSkinParams () 77 | { 78 | return *skinParams; 79 | } 80 | 81 | NUIE::DrawingContext& NodeEditorUIEnvironment::GetDrawingContext () 82 | { 83 | return *drawingContext; 84 | } 85 | 86 | double NodeEditorUIEnvironment::GetWindowScale () 87 | { 88 | return 1.0; 89 | } 90 | 91 | NE::EvaluationEnv& NodeEditorUIEnvironment::GetEvaluationEnv () 92 | { 93 | return evaluationEnv; 94 | } 95 | 96 | void NodeEditorUIEnvironment::OnEvaluationBegin () 97 | { 98 | wxBeginBusyCursor (); 99 | } 100 | 101 | void NodeEditorUIEnvironment::OnEvaluationEnd () 102 | { 103 | wxEndBusyCursor (); 104 | } 105 | 106 | void NodeEditorUIEnvironment::OnValuesRecalculated () 107 | { 108 | 109 | } 110 | 111 | void NodeEditorUIEnvironment::OnRedrawRequested () 112 | { 113 | nodeEditorControl->Refresh (false); 114 | } 115 | 116 | NUIE::EventHandler& NodeEditorUIEnvironment::GetEventHandler () 117 | { 118 | return *eventHandler; 119 | } 120 | 121 | NUIE::ClipboardHandler& NodeEditorUIEnvironment::GetClipboardHandler () 122 | { 123 | return *clipboardHandler; 124 | } 125 | 126 | void NodeEditorUIEnvironment::OnSelectionChanged (const NUIE::Selection&) 127 | { 128 | 129 | } 130 | 131 | void NodeEditorUIEnvironment::OnUndoStateChanged (const NUIE::UndoState&) 132 | { 133 | 134 | } 135 | 136 | void NodeEditorUIEnvironment::OnClipboardStateChanged (const NUIE::ClipboardState&) 137 | { 138 | 139 | } 140 | 141 | void NodeEditorUIEnvironment::OnIncompatibleVersionPasted (const NUIE::Version&) 142 | { 143 | 144 | } 145 | 146 | NodeEditorControl::NodeEditorControl (wxWindow *parent) : 147 | wxPanel (parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS), 148 | captureHandler (this) 149 | { 150 | 151 | } 152 | 153 | NodeEditorControl::~NodeEditorControl () 154 | { 155 | 156 | } 157 | 158 | void NodeEditorControl::Init (std::shared_ptr& editorUIEnvironment) 159 | { 160 | uiEnvironment = editorUIEnvironment; 161 | nodeEditor = std::shared_ptr (new NUIE::NodeEditor (*uiEnvironment)); 162 | OnInit (); 163 | } 164 | 165 | void NodeEditorControl::OnInit () 166 | { 167 | 168 | } 169 | 170 | void NodeEditorControl::OnPaint (wxPaintEvent& evt) 171 | { 172 | nodeEditor->Draw (); 173 | uiEnvironment->OnPaint (this, evt); 174 | } 175 | 176 | void NodeEditorControl::OnResize (wxSizeEvent& evt) 177 | { 178 | SetFocus (); 179 | wxSize size = evt.GetSize (); 180 | nodeEditor->OnResize (size.GetWidth (), size.GetHeight ()); 181 | } 182 | 183 | void NodeEditorControl::OnMouseCaptureLost (wxMouseCaptureLostEvent&) 184 | { 185 | captureHandler.OnCaptureLost (); 186 | } 187 | 188 | void NodeEditorControl::OnLeftButtonDown (wxMouseEvent& evt) 189 | { 190 | captureHandler.OnMouseDown (); 191 | nodeEditor->OnMouseDown (GetModiferKeysFromEvent (evt), NUIE::MouseButton::Left, evt.GetX (), evt.GetY ()); 192 | } 193 | 194 | void NodeEditorControl::OnLeftButtonUp (wxMouseEvent& evt) 195 | { 196 | nodeEditor->OnMouseUp (GetModiferKeysFromEvent (evt), NUIE::MouseButton::Left, evt.GetX (), evt.GetY ()); 197 | captureHandler.OnMouseUp (); 198 | } 199 | 200 | void NodeEditorControl::OnLeftButtonDoubleClick (wxMouseEvent& evt) 201 | { 202 | nodeEditor->OnMouseDoubleClick (GetModiferKeysFromEvent (evt), NUIE::MouseButton::Left, evt.GetX (), evt.GetY ()); 203 | } 204 | 205 | void NodeEditorControl::OnRightButtonDown (wxMouseEvent& evt) 206 | { 207 | captureHandler.OnMouseDown (); 208 | nodeEditor->OnMouseDown (GetModiferKeysFromEvent (evt), NUIE::MouseButton::Right, evt.GetX (), evt.GetY ()); 209 | } 210 | 211 | void NodeEditorControl::OnRightButtonUp (wxMouseEvent& evt) 212 | { 213 | nodeEditor->OnMouseUp (GetModiferKeysFromEvent (evt), NUIE::MouseButton::Right, evt.GetX (), evt.GetY ()); 214 | captureHandler.OnMouseUp (); 215 | } 216 | 217 | void NodeEditorControl::OnRightButtonDoubleClick (wxMouseEvent& evt) 218 | { 219 | nodeEditor->OnMouseDoubleClick (GetModiferKeysFromEvent (evt), NUIE::MouseButton::Right, evt.GetX (), evt.GetY ()); 220 | } 221 | 222 | void NodeEditorControl::OnMiddleButtonDown (wxMouseEvent& evt) 223 | { 224 | captureHandler.OnMouseDown (); 225 | nodeEditor->OnMouseDown (GetModiferKeysFromEvent (evt), NUIE::MouseButton::Middle, evt.GetX (), evt.GetY ()); 226 | } 227 | 228 | void NodeEditorControl::OnMiddleButtonUp (wxMouseEvent& evt) 229 | { 230 | nodeEditor->OnMouseUp (GetModiferKeysFromEvent (evt), NUIE::MouseButton::Middle, evt.GetX (), evt.GetY ()); 231 | captureHandler.OnMouseUp (); 232 | } 233 | 234 | void NodeEditorControl::OnMiddleButtonDoubleClick (wxMouseEvent& evt) 235 | { 236 | nodeEditor->OnMouseDoubleClick (GetModiferKeysFromEvent (evt), NUIE::MouseButton::Middle, evt.GetX (), evt.GetY ()); 237 | } 238 | 239 | void NodeEditorControl::OnMouseMove (wxMouseEvent& evt) 240 | { 241 | SetFocus (); 242 | nodeEditor->OnMouseMove (GetModiferKeysFromEvent (evt), evt.GetX (), evt.GetY ()); 243 | } 244 | 245 | void NodeEditorControl::OnMouseWheel (wxMouseEvent& evt) 246 | { 247 | NUIE::MouseWheelRotation rotation = evt.GetWheelRotation () > 0 ? NUIE::MouseWheelRotation::Forward : NUIE::MouseWheelRotation::Backward; 248 | nodeEditor->OnMouseWheel (GetModiferKeysFromEvent (evt), rotation, evt.GetX (), evt.GetY ()); 249 | } 250 | 251 | void NodeEditorControl::OnKeyDown (wxKeyEvent& evt) 252 | { 253 | NUIE::CommandCode commandCode = GetCommandFromEvent (evt); 254 | if (commandCode == NUIE::CommandCode::Undefined) { 255 | return; 256 | } 257 | nodeEditor->ExecuteCommand (commandCode); 258 | } 259 | 260 | NodeEditorControl::UpdateMode NodeEditorControl::GetUpdateMode () const 261 | { 262 | if (nodeEditor->GetUpdateMode () == NUIE::NodeEditor::UpdateMode::Automatic) { 263 | return UpdateMode::Automatic; 264 | } else if (nodeEditor->GetUpdateMode () == NUIE::NodeEditor::UpdateMode::Manual) { 265 | return UpdateMode::Manual; 266 | } else { 267 | DBGBREAK (); 268 | return UpdateMode::Automatic; 269 | } 270 | } 271 | 272 | void NodeEditorControl::SetUpdateMode (UpdateMode mode) const 273 | { 274 | if (mode == UpdateMode::Automatic) { 275 | nodeEditor->SetUpdateMode (NUIE::NodeEditor::UpdateMode::Automatic); 276 | } else if (mode == UpdateMode::Manual) { 277 | nodeEditor->SetUpdateMode (NUIE::NodeEditor::UpdateMode::Manual); 278 | } else { 279 | DBGBREAK (); 280 | } 281 | } 282 | 283 | void NodeEditorControl::ManualUpdate () 284 | { 285 | nodeEditor->ManualUpdate (); 286 | } 287 | 288 | void NodeEditorControl::AddNode (const NUIE::UINodePtr& uiNode) 289 | { 290 | nodeEditor->AddNode (uiNode); 291 | } 292 | 293 | NUIE::Point NodeEditorControl::ViewToModel (const NUIE::Point& viewPoint) const 294 | { 295 | return nodeEditor->ViewToModel (viewPoint); 296 | } 297 | 298 | void NodeEditorControl::AlignToWindow () 299 | { 300 | nodeEditor->AlignToWindow (); 301 | } 302 | 303 | void NodeEditorControl::FitToWindow () 304 | { 305 | nodeEditor->FitToWindow (); 306 | } 307 | 308 | void NodeEditorControl::New () 309 | { 310 | nodeEditor->New (); 311 | } 312 | 313 | bool NodeEditorControl::Open (const std::wstring& fileName) 314 | { 315 | return nodeEditor->Open (fileName); 316 | } 317 | 318 | bool NodeEditorControl::Open (NE::InputStream& inputStream) 319 | { 320 | return nodeEditor->Open (inputStream); 321 | } 322 | 323 | bool NodeEditorControl::Save (const std::wstring& fileName) 324 | { 325 | return nodeEditor->Save (fileName); 326 | } 327 | 328 | bool NodeEditorControl::Save (NE::OutputStream& outputStream) const 329 | { 330 | return nodeEditor->Save (outputStream); 331 | } 332 | 333 | bool NodeEditorControl::NeedToSave () const 334 | { 335 | return nodeEditor->NeedToSave (); 336 | } 337 | 338 | void NodeEditorControl::Undo () 339 | { 340 | nodeEditor->Undo (); 341 | } 342 | 343 | void NodeEditorControl::Redo () 344 | { 345 | nodeEditor->Redo (); 346 | } 347 | 348 | BEGIN_EVENT_TABLE(NodeEditorControl, wxPanel) 349 | 350 | EVT_PAINT (NodeEditorControl::OnPaint) 351 | EVT_SIZE (NodeEditorControl::OnResize) 352 | EVT_MOUSE_CAPTURE_LOST (NodeEditorControl::OnMouseCaptureLost) 353 | 354 | EVT_LEFT_DOWN (NodeEditorControl::OnLeftButtonDown) 355 | EVT_LEFT_UP (NodeEditorControl::OnLeftButtonUp) 356 | EVT_LEFT_DCLICK (NodeEditorControl::OnLeftButtonDoubleClick) 357 | 358 | EVT_RIGHT_DOWN (NodeEditorControl::OnRightButtonDown) 359 | EVT_RIGHT_UP (NodeEditorControl::OnRightButtonUp) 360 | EVT_RIGHT_DCLICK (NodeEditorControl::OnRightButtonDoubleClick) 361 | 362 | EVT_MIDDLE_DOWN (NodeEditorControl::OnMiddleButtonDown) 363 | EVT_MIDDLE_UP (NodeEditorControl::OnMiddleButtonUp) 364 | EVT_MIDDLE_DCLICK (NodeEditorControl::OnMiddleButtonDoubleClick) 365 | 366 | EVT_MOUSEWHEEL (NodeEditorControl::OnMouseWheel) 367 | EVT_MOTION (NodeEditorControl::OnMouseMove) 368 | EVT_KEY_DOWN (NodeEditorControl::OnKeyDown) 369 | 370 | END_EVENT_TABLE () 371 | 372 | } 373 | -------------------------------------------------------------------------------- /Sources/wxWidgetsAppSupport/WXAS_NodeEditorControl.hpp: -------------------------------------------------------------------------------- 1 | #ifndef WXAS_NODEEDITORCONTROL_HPP 2 | #define WXAS_NODEEDITORCONTROL_HPP 3 | 4 | #include "NUIE_NodeEditor.hpp" 5 | #include "WXAS_ControlUtilities.hpp" 6 | 7 | #include 8 | #include 9 | 10 | namespace WXAS 11 | { 12 | 13 | class NodeEditorControl; 14 | 15 | class NodeEditorEventHandler : public NUIE::EventHandler 16 | { 17 | public: 18 | NodeEditorEventHandler (NodeEditorControl* control); 19 | virtual ~NodeEditorEventHandler (); 20 | 21 | virtual NUIE::MenuCommandPtr OnContextMenu (NUIE::EventHandler::ContextMenuType type, const NUIE::Point& position, const NUIE::MenuCommandStructure& commands) override; 22 | virtual bool OnParameterSettings (NUIE::EventHandler::ParameterSettingsType type, NUIE::ParameterInterfacePtr paramInterface); 23 | virtual void OnDoubleClick (const NUIE::Point& position, NUIE::MouseButton mouseButton) override; 24 | 25 | protected: 26 | NodeEditorControl* control; 27 | }; 28 | 29 | class NodeEditorUIEnvironment : public NUIE::NodeUIEnvironment 30 | { 31 | public: 32 | NodeEditorUIEnvironment ( NodeEditorControl* nodeEditorControl, 33 | NE::StringConverterPtr& stringConverter, 34 | NUIE::SkinParamsPtr& skinParams, 35 | NUIE::EventHandlerPtr& eventHandler, 36 | NE::EvaluationEnv& evaluationEnv); 37 | virtual ~NodeEditorUIEnvironment (); 38 | 39 | void OnPaint (wxPanel* panel, wxPaintEvent& evt); 40 | void OnResize (int width, int height); 41 | 42 | virtual const NE::StringConverter& GetStringConverter () override; 43 | virtual const NUIE::SkinParams& GetSkinParams () override; 44 | virtual NUIE::DrawingContext& GetDrawingContext () override; 45 | virtual double GetWindowScale () override; 46 | virtual NE::EvaluationEnv& GetEvaluationEnv () override; 47 | virtual void OnEvaluationBegin () override; 48 | virtual void OnEvaluationEnd () override; 49 | virtual void OnValuesRecalculated () override; 50 | virtual void OnRedrawRequested () override; 51 | virtual NUIE::EventHandler& GetEventHandler () override; 52 | virtual NUIE::ClipboardHandler& GetClipboardHandler () override; 53 | virtual void OnSelectionChanged (const NUIE::Selection& selection) override; 54 | virtual void OnUndoStateChanged (const NUIE::UndoState& undoState) override; 55 | virtual void OnClipboardStateChanged (const NUIE::ClipboardState& clipboardState) override; 56 | virtual void OnIncompatibleVersionPasted (const NUIE::Version& version) override; 57 | 58 | private: 59 | NodeEditorControl* nodeEditorControl; 60 | NE::EvaluationEnv& evaluationEnv; 61 | 62 | NE::StringConverterPtr stringConverter; 63 | NUIE::SkinParamsPtr skinParams; 64 | NUIE::EventHandlerPtr eventHandler; 65 | NUIE::ClipboardHandlerPtr clipboardHandler; 66 | std::shared_ptr drawingContext; 67 | }; 68 | 69 | class NodeEditorControl : public wxPanel 70 | { 71 | public: 72 | enum class UpdateMode 73 | { 74 | Automatic, 75 | Manual 76 | }; 77 | 78 | NodeEditorControl (wxWindow *parent); 79 | virtual ~NodeEditorControl (); 80 | 81 | void Init (std::shared_ptr& editorUIEnvironment); 82 | virtual void OnInit (); 83 | 84 | void OnPaint (wxPaintEvent& evt); 85 | void OnResize (wxSizeEvent& evt); 86 | void OnMouseCaptureLost (wxMouseCaptureLostEvent& evt); 87 | 88 | void OnLeftButtonDown (wxMouseEvent& evt); 89 | void OnLeftButtonUp (wxMouseEvent& evt); 90 | void OnLeftButtonDoubleClick (wxMouseEvent& evt); 91 | 92 | void OnRightButtonDown (wxMouseEvent& evt); 93 | void OnRightButtonUp (wxMouseEvent& evt); 94 | void OnRightButtonDoubleClick (wxMouseEvent& evt); 95 | 96 | void OnMiddleButtonDown (wxMouseEvent& evt); 97 | void OnMiddleButtonUp (wxMouseEvent& evt); 98 | void OnMiddleButtonDoubleClick (wxMouseEvent& evt); 99 | 100 | void OnMouseMove (wxMouseEvent& evt); 101 | void OnMouseWheel (wxMouseEvent& evt); 102 | 103 | void OnKeyDown (wxKeyEvent& evt); 104 | 105 | UpdateMode GetUpdateMode () const; 106 | void SetUpdateMode (UpdateMode mode) const; 107 | void ManualUpdate (); 108 | 109 | void AddNode (const NUIE::UINodePtr& uiNode); 110 | NUIE::Point ViewToModel (const NUIE::Point& viewPoint) const; 111 | void AlignToWindow (); 112 | void FitToWindow (); 113 | 114 | void New (); 115 | bool Open (const std::wstring& fileName); 116 | bool Open (NE::InputStream& inputStream); 117 | bool Save (const std::wstring& fileName); 118 | bool Save (NE::OutputStream& outputStream) const; 119 | bool NeedToSave () const; 120 | void Undo (); 121 | void Redo (); 122 | 123 | protected: 124 | MouseCaptureHandler captureHandler; 125 | std::shared_ptr uiEnvironment; 126 | std::shared_ptr nodeEditor; 127 | 128 | DECLARE_EVENT_TABLE () 129 | }; 130 | 131 | } 132 | 133 | #endif 134 | -------------------------------------------------------------------------------- /Sources/wxWidgetsAppSupport/WXAS_ParameterDialog.cpp: -------------------------------------------------------------------------------- 1 | #include "WXAS_ParameterDialog.hpp" 2 | #include "WXAS_ControlUtilities.hpp" 3 | #include "NUIE_NodeParameters.hpp" 4 | #include "NE_SingleValues.hpp" 5 | #include "NE_Localization.hpp" 6 | #include "NE_Debug.hpp" 7 | 8 | namespace WXAS 9 | { 10 | 11 | static const wxWindowID FirstControlId = 10000; 12 | 13 | static wxWindowID ParamIdToControlId (size_t paramId) 14 | { 15 | return FirstControlId + (wxWindowID) paramId; 16 | } 17 | 18 | static size_t ControlIdToParamId (wxWindowID controlId) 19 | { 20 | return (size_t) controlId - FirstControlId; 21 | } 22 | 23 | ParameterDialog::ParameterDialog (wxWindow* parent, NUIE::ParameterInterfacePtr& paramInterface) : 24 | wxDialog (parent, wxID_ANY, NE::LocalizeString (L"Set Parameters"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE), 25 | paramInterface (paramInterface), 26 | gridSizer (new wxGridSizer (2, 5, 5)), 27 | boxSizer (new wxBoxSizer (wxVERTICAL)), 28 | okButton (new wxButton (this, wxID_OK, NE::LocalizeString (L"OK"))) 29 | { 30 | gridSizer->SetRows (paramInterface->GetParameterCount ()); 31 | for (size_t paramIndex = 0; paramIndex < paramInterface->GetParameterCount (); ++paramIndex) { 32 | NUIE::ParameterType type = paramInterface->GetParameterType (paramIndex); 33 | NE::ValueConstPtr value = paramInterface->GetParameterValue (paramIndex); 34 | 35 | int controlId = ParamIdToControlId (paramIndex); 36 | wxControl* control = nullptr; 37 | if (type == NUIE::ParameterType::Boolean) { 38 | if (DBGVERIFY (NE::Value::IsType (value))) { 39 | wxChoice* choiceControl = new wxChoice (this, controlId); 40 | choiceControl->Append (wxString (NE::LocalizeString (L"true"))); 41 | choiceControl->Append (wxString (NE::LocalizeString (L"false"))); 42 | choiceControl->Select (NE::BooleanValue::Get (value) ? 0 : 1); 43 | control = choiceControl; 44 | } 45 | } else if (type == NUIE::ParameterType::Integer) { 46 | if (DBGVERIFY (NE::Value::IsType (value))) { 47 | wxTextCtrl* textControl = new wxTextCtrl (this, controlId, NUIE::ParameterValueToString (value, type)); 48 | SetTextControlValidator (textControl, L"0123456789-"); 49 | control = textControl; 50 | } 51 | } else if (type == NUIE::ParameterType::Float) { 52 | if (DBGVERIFY (NE::Value::IsType (value))) { 53 | wxTextCtrl* textControl = new wxTextCtrl (this, controlId, NUIE::ParameterValueToString (value, type)); 54 | SetTextControlValidator (textControl, L"0123456789.-"); 55 | control = textControl; 56 | } 57 | } else if (type == NUIE::ParameterType::Double) { 58 | if (DBGVERIFY (NE::Value::IsType (value))) { 59 | wxTextCtrl* textControl = new wxTextCtrl (this, controlId, NUIE::ParameterValueToString (value, type)); 60 | SetTextControlValidator (textControl, L"0123456789.-"); 61 | control = textControl; 62 | } 63 | } else if (type == NUIE::ParameterType::String) { 64 | if (DBGVERIFY (NE::Value::IsType (value))) { 65 | wxTextCtrl* textControl = new wxTextCtrl (this, controlId, NUIE::ParameterValueToString (value, type)); 66 | control = textControl; 67 | } 68 | } else if (type == NUIE::ParameterType::Enumeration) { 69 | if (DBGVERIFY (NE::Value::IsType (value))) { 70 | wxChoice* choiceControl = new wxChoice (this, controlId); 71 | std::vector choices = paramInterface->GetParameterValueChoices (paramIndex); 72 | for (const std::wstring& choice : choices) { 73 | choiceControl->Append (wxString (choice)); 74 | } 75 | choiceControl->Select (NE::IntValue::Get (value)); 76 | control = choiceControl; 77 | } 78 | } 79 | 80 | if (DBGERROR (control == nullptr)) { 81 | continue; 82 | } 83 | 84 | wxStaticText* paramNameText = new wxStaticText (this, wxID_ANY, paramInterface->GetParameterName (paramIndex)); 85 | gridSizer->Add (paramNameText, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL); 86 | 87 | gridSizer->Add (control, 1, wxEXPAND); 88 | paramUIDataList.push_back (ParamUIData (control)); 89 | } 90 | 91 | boxSizer->Add (gridSizer, 1, wxEXPAND | wxALL, 5); 92 | boxSizer->Add (okButton, 0, wxEXPAND | wxALL, 5); 93 | 94 | SetSizerAndFit (boxSizer); 95 | CenterOnParent (); 96 | SetEscapeId (wxID_CANCEL); 97 | } 98 | 99 | void ParameterDialog::OnButtonClick (wxCommandEvent& evt) 100 | { 101 | if (evt.GetId () == wxID_OK) { 102 | bool isAllParameterValid = true; 103 | for (size_t i = 0; i < paramInterface->GetParameterCount (); ++i) { 104 | ParamUIData& uiData = paramUIDataList[i]; 105 | if (!uiData.isChanged) { 106 | continue; 107 | } 108 | 109 | NUIE::ParameterType type = paramInterface->GetParameterType (i); 110 | NE::ValuePtr value = uiData.GetValue (type); 111 | if (DBGERROR (value == nullptr)) { 112 | isAllParameterValid = false; 113 | continue; 114 | } 115 | 116 | if (!paramInterface->IsValidParameterValue (i, value)) { 117 | NE::ValueConstPtr oldValue = paramInterface->GetParameterValue (i); 118 | std::wstring oldValueString = NUIE::ParameterValueToString (oldValue, type); 119 | uiData.SetStringValue (oldValueString); 120 | uiData.isChanged = false; 121 | isAllParameterValid = false; 122 | } 123 | } 124 | 125 | if (!isAllParameterValid) { 126 | return; 127 | } 128 | 129 | for (size_t i = 0; i < paramInterface->GetParameterCount (); ++i) { 130 | const ParamUIData& uiData = paramUIDataList[i]; 131 | if (!uiData.isChanged) { 132 | continue; 133 | } 134 | 135 | NUIE::ParameterType type = paramInterface->GetParameterType (i); 136 | NE::ValuePtr value = uiData.GetValue (type); 137 | if (DBGERROR (value == nullptr)) { 138 | continue; 139 | } 140 | 141 | paramInterface->SetParameterValue (i, value); 142 | } 143 | 144 | if (isAllParameterValid) { 145 | EndModal (wxID_OK); 146 | } 147 | } 148 | } 149 | 150 | void ParameterDialog::OnTextChanged (wxCommandEvent& evt) 151 | { 152 | int paramIndex = ControlIdToParamId (evt.GetId ()); 153 | paramUIDataList[paramIndex].isChanged = true; 154 | } 155 | 156 | void ParameterDialog::OnChoiceChanged (wxCommandEvent& evt) 157 | { 158 | int paramIndex = ControlIdToParamId (evt.GetId ()); 159 | paramUIDataList[paramIndex].isChanged = true; 160 | } 161 | 162 | void ParameterDialog::OnKeyDown (wxKeyEvent& evt) 163 | { 164 | if (evt.GetKeyCode () == WXK_ESCAPE) { 165 | EndModal (wxID_CANCEL); 166 | } 167 | evt.Skip (); 168 | } 169 | 170 | ParameterDialog::ParamUIData::ParamUIData (wxControl* control) : 171 | control (control), 172 | isChanged (false) 173 | { 174 | 175 | } 176 | 177 | std::wstring ParameterDialog::ParamUIData::GetStringValue () const 178 | { 179 | if (dynamic_cast (control) != nullptr) { 180 | return dynamic_cast (control)->GetValue ().ToStdWstring (); 181 | } else { 182 | DBGBREAK (); 183 | return std::wstring (); 184 | } 185 | } 186 | 187 | int ParameterDialog::ParamUIData::GetChoiceValue () const 188 | { 189 | if (dynamic_cast (control) != nullptr) { 190 | return dynamic_cast (control)->GetSelection (); 191 | } else { 192 | DBGBREAK (); 193 | return -1; 194 | } 195 | } 196 | 197 | void ParameterDialog::ParamUIData::SetStringValue (const std::wstring& value) 198 | { 199 | if (dynamic_cast (control) != nullptr) { 200 | dynamic_cast (control)->SetValue (value); 201 | } else { 202 | DBGBREAK (); 203 | } 204 | } 205 | 206 | NE::ValuePtr ParameterDialog::ParamUIData::GetValue (NUIE::ParameterType type) const 207 | { 208 | NE::ValuePtr value = nullptr; 209 | if (type == NUIE::ParameterType::Boolean) { 210 | int choiceValue = GetChoiceValue (); 211 | value = NE::ValuePtr (new NE::BooleanValue (choiceValue == 0 ? true : false)); 212 | } else if (type == NUIE::ParameterType::Integer || type == NUIE::ParameterType::Float || type == NUIE::ParameterType::Double || type == NUIE::ParameterType::String) { 213 | value = NUIE::StringToParameterValue (GetStringValue (), type); 214 | } else if (type == NUIE::ParameterType::Enumeration) { 215 | value = NE::ValuePtr (new NE::IntValue (GetChoiceValue ())); 216 | } 217 | return value; 218 | } 219 | 220 | BEGIN_EVENT_TABLE (ParameterDialog, wxDialog) 221 | EVT_BUTTON (wxID_ANY, ParameterDialog::OnButtonClick) 222 | EVT_TEXT (wxID_ANY, ParameterDialog::OnTextChanged) 223 | EVT_CHOICE (wxID_ANY, ParameterDialog::OnChoiceChanged) 224 | EVT_CHAR_HOOK (ParameterDialog::OnKeyDown) 225 | END_EVENT_TABLE () 226 | 227 | } 228 | -------------------------------------------------------------------------------- /Sources/wxWidgetsAppSupport/WXAS_ParameterDialog.hpp: -------------------------------------------------------------------------------- 1 | #ifndef WXAS_PARAMETERDIALOG_HPP 2 | #define WXAS_PARAMETERDIALOG_HPP 3 | 4 | #include "NUIE_ParameterInterface.hpp" 5 | 6 | #include 7 | #include 8 | 9 | namespace WXAS 10 | { 11 | 12 | class ParameterDialog : public wxDialog 13 | { 14 | public: 15 | ParameterDialog (wxWindow* parent, NUIE::ParameterInterfacePtr& paramInterface); 16 | 17 | void OnButtonClick (wxCommandEvent& evt); 18 | void OnTextChanged (wxCommandEvent& evt); 19 | void OnChoiceChanged (wxCommandEvent& evt); 20 | void OnKeyDown (wxKeyEvent& evt); 21 | 22 | private: 23 | struct ParamUIData 24 | { 25 | ParamUIData (wxControl* control); 26 | 27 | std::wstring GetStringValue () const; 28 | int GetChoiceValue () const; 29 | void SetStringValue (const std::wstring& value); 30 | NE::ValuePtr GetValue (NUIE::ParameterType type) const; 31 | 32 | wxControl* control; 33 | bool isChanged; 34 | }; 35 | 36 | NUIE::ParameterInterfacePtr paramInterface; 37 | std::vector paramUIDataList; 38 | 39 | wxGridSizer* gridSizer; 40 | wxBoxSizer* boxSizer; 41 | wxButton* okButton; 42 | 43 | DECLARE_EVENT_TABLE (); 44 | }; 45 | 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Sources/wxWidgetsAppSupport/WXAS_wxDrawingContext.cpp: -------------------------------------------------------------------------------- 1 | #include "WXAS_wxDrawingContext.hpp" 2 | #include "NE_Debug.hpp" 3 | 4 | #include 5 | 6 | namespace WXAS 7 | { 8 | 9 | wxDrawingContext::wxDrawingContext () : 10 | NUIE::NativeDrawingContext (), 11 | width (0), 12 | height (0), 13 | memoryBitmap (new wxBitmap (wxSize (1, 1))), 14 | memoryDC (new wxMemoryDC ()) 15 | { 16 | memoryDC->SelectObject (*memoryBitmap); 17 | graphicsContext = wxGraphicsContext::Create (*memoryDC); 18 | } 19 | 20 | wxDrawingContext::~wxDrawingContext () 21 | { 22 | delete memoryBitmap; 23 | delete memoryDC; 24 | delete graphicsContext; 25 | } 26 | 27 | void wxDrawingContext::DrawToDC (wxDC* targetDC) 28 | { 29 | targetDC->Blit (0, 0, width, height, memoryDC, 0, 0); 30 | } 31 | 32 | void wxDrawingContext::Init (void*) 33 | { 34 | 35 | } 36 | 37 | void wxDrawingContext::BlitToWindow (void* nativeHandle) 38 | { 39 | wxPanel* panel = (wxPanel*) nativeHandle; 40 | wxPaintDC dc (panel); 41 | BlitToContext (&dc); 42 | } 43 | 44 | void wxDrawingContext::BlitToContext (void* nativeContext) 45 | { 46 | wxPaintDC* dc = (wxPaintDC*) nativeContext; 47 | dc->Blit (0, 0, width, height, memoryDC, 0, 0); 48 | } 49 | 50 | void wxDrawingContext::Resize (int newWidth, int newHeight) 51 | { 52 | width = newWidth; 53 | height = newHeight; 54 | 55 | delete memoryBitmap; 56 | delete memoryDC; 57 | delete graphicsContext; 58 | 59 | memoryBitmap = new wxBitmap (newWidth, newHeight); 60 | memoryDC = new wxMemoryDC (); 61 | memoryDC->SelectObject (*memoryBitmap); 62 | graphicsContext = wxGraphicsContext::Create (*memoryDC); 63 | } 64 | 65 | int wxDrawingContext::GetWidth () const 66 | { 67 | return width; 68 | } 69 | 70 | int wxDrawingContext::GetHeight () const 71 | { 72 | return height; 73 | } 74 | 75 | void wxDrawingContext::BeginDraw () 76 | { 77 | 78 | } 79 | 80 | void wxDrawingContext::EndDraw () 81 | { 82 | 83 | } 84 | 85 | bool wxDrawingContext::NeedToDraw (ItemPreviewMode) 86 | { 87 | return true; 88 | } 89 | 90 | void wxDrawingContext::DrawLine (const NUIE::Point& beg, const NUIE::Point& end, const NUIE::Pen& pen) 91 | { 92 | graphicsContext->SetBrush (*wxTRANSPARENT_BRUSH); 93 | graphicsContext->SetPen (GetPen (pen)); 94 | std::vector lines; 95 | lines.push_back (wxPoint2DDouble (beg.GetX (), beg.GetY ())); 96 | lines.push_back (wxPoint2DDouble (end.GetX (), end.GetY ())); 97 | graphicsContext->DrawLines (lines.size (), lines.data ()); 98 | } 99 | 100 | void wxDrawingContext::DrawBezier (const NUIE::Point& p1, const NUIE::Point& p2, const NUIE::Point& p3, const NUIE::Point& p4, const NUIE::Pen& pen) 101 | { 102 | graphicsContext->SetBrush (*wxTRANSPARENT_BRUSH); 103 | graphicsContext->SetPen (GetPen (pen)); 104 | wxGraphicsPath path = graphicsContext->CreatePath (); 105 | wxPoint wxp1 = GetPoint (p1); 106 | wxPoint wxp2 = GetPoint (p2); 107 | wxPoint wxp3 = GetPoint (p3); 108 | wxPoint wxp4 = GetPoint (p4); 109 | path.MoveToPoint (wxp1); 110 | path.AddCurveToPoint (wxp2.x, wxp2.y, wxp3.x, wxp3.y, wxp4.x, wxp4.y); 111 | graphicsContext->DrawPath (path); 112 | } 113 | 114 | void wxDrawingContext::DrawRect (const NUIE::Rect& rect, const NUIE::Pen& pen) 115 | { 116 | graphicsContext->SetBrush (*wxTRANSPARENT_BRUSH); 117 | graphicsContext->SetPen (GetPen (pen)); 118 | wxRect theRect = GetRect (rect); 119 | graphicsContext->DrawRectangle (theRect.GetX (), theRect.GetY (), theRect.GetWidth (), theRect.GetHeight ()); 120 | } 121 | 122 | void wxDrawingContext::FillRect (const NUIE::Rect& rect, const NUIE::Color& color) 123 | { 124 | graphicsContext->SetBrush (wxBrush (GetColor (color))); 125 | graphicsContext->SetPen (*wxTRANSPARENT_PEN); 126 | wxRect theRect = GetRect (rect); 127 | graphicsContext->DrawRectangle (theRect.GetX (), theRect.GetY (), theRect.GetWidth (), theRect.GetHeight ()); 128 | } 129 | 130 | void wxDrawingContext::DrawEllipse (const NUIE::Rect& rect, const NUIE::Pen& pen) 131 | { 132 | graphicsContext->SetBrush (*wxTRANSPARENT_BRUSH); 133 | graphicsContext->SetPen (GetPen (pen)); 134 | wxRect theRect = GetRect (rect); 135 | graphicsContext->DrawEllipse (theRect.GetX (), theRect.GetY (), theRect.GetWidth (), theRect.GetHeight ()); 136 | } 137 | 138 | void wxDrawingContext::FillEllipse (const NUIE::Rect& rect, const NUIE::Color& color) 139 | { 140 | graphicsContext->SetBrush (wxBrush (GetColor (color))); 141 | graphicsContext->SetPen (*wxTRANSPARENT_PEN); 142 | wxRect theRect = GetRect (rect); 143 | graphicsContext->DrawEllipse (theRect.GetX (), theRect.GetY (), theRect.GetWidth (), theRect.GetHeight ()); 144 | } 145 | 146 | void wxDrawingContext::DrawFormattedText (const NUIE::Rect& rect, const NUIE::Font& font, const std::wstring& text, NUIE::HorizontalAnchor hAnchor, NUIE::VerticalAnchor vAnchor, const NUIE::Color& textColor) 147 | { 148 | memoryDC->SetTextForeground (GetColor (textColor)); 149 | memoryDC->SetFont (GetFont (font)); 150 | 151 | int alignment = 0; 152 | 153 | switch (hAnchor) { 154 | case NUIE::HorizontalAnchor::Left: 155 | alignment |= wxALIGN_LEFT; 156 | break; 157 | case NUIE::HorizontalAnchor::Center: 158 | alignment |= wxALIGN_CENTER_HORIZONTAL; 159 | break; 160 | case NUIE::HorizontalAnchor::Right: 161 | alignment |= wxALIGN_RIGHT; 162 | break; 163 | } 164 | 165 | switch (vAnchor) { 166 | case NUIE::VerticalAnchor::Top: 167 | alignment |= wxALIGN_TOP; 168 | break; 169 | case NUIE::VerticalAnchor::Center: 170 | alignment |= wxALIGN_CENTER_VERTICAL; 171 | break; 172 | case NUIE::VerticalAnchor::Bottom: 173 | alignment |= wxALIGN_BOTTOM; 174 | break; 175 | } 176 | 177 | memoryDC->DrawLabel (text, GetRect (rect), alignment); 178 | } 179 | 180 | NUIE::Size wxDrawingContext::MeasureText (const NUIE::Font& font, const std::wstring& text) 181 | { 182 | memoryDC->SetFont (GetFont (font)); 183 | wxSize size = memoryDC->GetTextExtent (text); 184 | return NUIE::Size (size.x, size.y); 185 | } 186 | 187 | bool wxDrawingContext::CanDrawIcon () 188 | { 189 | return false; 190 | } 191 | 192 | void wxDrawingContext::DrawIcon (const NUIE::Rect&, const NUIE::IconId&) 193 | { 194 | DBGBREAK (); 195 | } 196 | 197 | wxPoint wxDrawingContext::GetPoint (const NUIE::Point& point) 198 | { 199 | return wxPoint ((int) std::floor (point.GetX ()) - 1, (int) std::floor (point.GetY ()) - 1); 200 | } 201 | 202 | wxRect wxDrawingContext::GetRect (const NUIE::Rect& rect) 203 | { 204 | NUIE::IntRect intRect (rect); 205 | return wxRect (intRect.GetLeft (), intRect.GetTop (), intRect.GetWidth (), intRect.GetHeight ()); 206 | } 207 | 208 | wxColour wxDrawingContext::GetColor (const NUIE::Color& color) 209 | { 210 | return wxColour (color.GetR (), color.GetG (), color.GetB ()); 211 | } 212 | 213 | wxPen wxDrawingContext::GetPen (const NUIE::Pen& pen) 214 | { 215 | int thickness = (int) pen.GetThickness (); 216 | return wxPen (GetColor (pen.GetColor ()), thickness); 217 | } 218 | 219 | wxFont wxDrawingContext::GetFont (const NUIE::Font& font) 220 | { 221 | int fontSize = (int) font.GetSize (); 222 | if (fontSize == wxDEFAULT) { 223 | // TODO: wxFont handles font size 70 as the default, so changes it back to default font size 224 | fontSize += 1; 225 | } 226 | return wxFont (fontSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL); 227 | } 228 | 229 | } 230 | -------------------------------------------------------------------------------- /Sources/wxWidgetsAppSupport/WXAS_wxDrawingContext.hpp: -------------------------------------------------------------------------------- 1 | #ifndef WXAS_WXDRAWINGCONTEXT_HPP 2 | #define WXAS_WXDRAWINGCONTEXT_HPP 3 | 4 | #include "NUIE_DrawingContext.hpp" 5 | 6 | #include 7 | #include 8 | 9 | namespace WXAS 10 | { 11 | 12 | class wxDrawingContext : public NUIE::NativeDrawingContext 13 | { 14 | public: 15 | wxDrawingContext (); 16 | wxDrawingContext (const wxDrawingContext& rhs) = delete; 17 | virtual ~wxDrawingContext (); 18 | 19 | void DrawToDC (wxDC* target); 20 | 21 | virtual void Init (void* nativeHandle) override; 22 | virtual void BlitToWindow (void* nativeHandle) override; 23 | virtual void BlitToContext (void* nativeContext) override; 24 | 25 | virtual void Resize (int newWidth, int newHeight) override; 26 | 27 | virtual int GetWidth () const override; 28 | virtual int GetHeight () const override; 29 | 30 | virtual void BeginDraw () override; 31 | virtual void EndDraw () override; 32 | 33 | virtual bool NeedToDraw (ItemPreviewMode mode) override; 34 | 35 | virtual void DrawLine (const NUIE::Point& beg, const NUIE::Point& end, const NUIE::Pen& pen) override; 36 | virtual void DrawBezier (const NUIE::Point& p1, const NUIE::Point& p2, const NUIE::Point& p3, const NUIE::Point& p4, const NUIE::Pen& pen) override; 37 | 38 | virtual void DrawRect (const NUIE::Rect& rect, const NUIE::Pen& pen) override; 39 | virtual void FillRect (const NUIE::Rect& rect, const NUIE::Color& color) override; 40 | 41 | virtual void DrawEllipse (const NUIE::Rect& rect, const NUIE::Pen& pen) override; 42 | virtual void FillEllipse (const NUIE::Rect& rect, const NUIE::Color& color) override; 43 | 44 | virtual void DrawFormattedText (const NUIE::Rect& rect, const NUIE::Font& font, const std::wstring& text, NUIE::HorizontalAnchor hAnchor, NUIE::VerticalAnchor vAnchor, const NUIE::Color& textColor) override; 45 | virtual NUIE::Size MeasureText (const NUIE::Font& font, const std::wstring& text) override; 46 | 47 | virtual bool CanDrawIcon () override; 48 | virtual void DrawIcon (const NUIE::Rect& rect, const NUIE::IconId& iconId) override; 49 | 50 | private: 51 | wxPoint GetPoint (const NUIE::Point& point); 52 | wxRect GetRect (const NUIE::Rect& rect); 53 | wxColour GetColor (const NUIE::Color& color); 54 | wxPen GetPen (const NUIE::Pen& pen); 55 | wxFont GetFont (const NUIE::Font& font); 56 | 57 | int width; 58 | int height; 59 | wxBitmap* memoryBitmap; 60 | wxMemoryDC* memoryDC; 61 | wxGraphicsContext* graphicsContext; 62 | }; 63 | 64 | } 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /Sources/wxWidgetsTestApp/DrawingControl.cpp: -------------------------------------------------------------------------------- 1 | #include "DrawingControl.hpp" 2 | #include "NUIE_ContextDecorators.hpp" 3 | #include "WXAS_wxDrawingContext.hpp" 4 | 5 | DrawingControl::DrawingControl (wxWindow *parent, const std::shared_ptr& resultImage) : 6 | wxPanel (parent, wxID_ANY, wxDefaultPosition, wxDefaultSize), 7 | captureHandler (this), 8 | resultImage (resultImage), 9 | drawingContext (new WXAS::wxDrawingContext ()), 10 | viewBox (NUIE::Point (0.0, 0.0), 1.0), 11 | lastMousePos (nullptr) 12 | { 13 | drawingContext->Init (this); 14 | } 15 | 16 | void DrawingControl::OnPaint (wxPaintEvent&) 17 | { 18 | drawingContext->FillRect (NUIE::Rect (-10, -10, drawingContext->GetWidth () + 20, drawingContext->GetHeight () + 20), NUIE::Color (255, 255, 255)); 19 | NUIE::ViewBoxContextDecorator viewBoxDecorator (*drawingContext, viewBox); 20 | resultImage->Draw (viewBoxDecorator); 21 | resultImage->Validate (); 22 | drawingContext->BlitToWindow (this); 23 | } 24 | 25 | void DrawingControl::OnMouseCaptureLost (wxMouseCaptureLostEvent&) 26 | { 27 | captureHandler.OnCaptureLost (); 28 | } 29 | 30 | void DrawingControl::OnResize (wxSizeEvent& evt) 31 | { 32 | wxSize size = evt.GetSize (); 33 | drawingContext->Resize (size.GetWidth (), size.GetHeight ()); 34 | } 35 | 36 | void DrawingControl::OnRightButtonDown (wxMouseEvent& evt) 37 | { 38 | captureHandler.OnMouseDown (); 39 | lastMousePos.reset (new NUIE::Point (evt.GetX (), evt.GetY ())); 40 | } 41 | 42 | void DrawingControl::OnRightButtonUp (wxMouseEvent&) 43 | { 44 | captureHandler.OnMouseUp (); 45 | lastMousePos.reset (nullptr); 46 | } 47 | 48 | void DrawingControl::OnMouseMove (wxMouseEvent& evt) 49 | { 50 | if (lastMousePos != nullptr) { 51 | NUIE::Point diff = NUIE::Point (evt.GetX (), evt.GetY ()) - *lastMousePos; 52 | viewBox.SetOffset (viewBox.GetOffset () + diff); 53 | lastMousePos->Set (evt.GetX (), evt.GetY ()); 54 | RedrawImage (); 55 | } 56 | } 57 | 58 | void DrawingControl::OnMouseWheel (wxMouseEvent& evt) 59 | { 60 | double scaleRatio = (evt.GetWheelRotation () > 0 ? 1.1 : 0.9); 61 | viewBox.SetScale (viewBox.GetScale () * scaleRatio, NUIE::Point (evt.GetX (), evt.GetY ())); 62 | RedrawImage (); 63 | } 64 | 65 | void DrawingControl::ClearImage () 66 | { 67 | resultImage->Clear (); 68 | RedrawImage (); 69 | } 70 | 71 | void DrawingControl::RedrawImage () 72 | { 73 | Refresh (false); 74 | } 75 | 76 | BEGIN_EVENT_TABLE(DrawingControl, wxPanel) 77 | EVT_PAINT (DrawingControl::OnPaint) 78 | EVT_SIZE (DrawingControl::OnResize) 79 | EVT_MOUSE_CAPTURE_LOST (DrawingControl::OnMouseCaptureLost) 80 | EVT_RIGHT_DOWN (DrawingControl::OnRightButtonDown) 81 | EVT_RIGHT_UP (DrawingControl::OnRightButtonUp) 82 | EVT_MOUSEWHEEL (DrawingControl::OnMouseWheel) 83 | EVT_MOTION (DrawingControl::OnMouseMove) 84 | END_EVENT_TABLE () 85 | -------------------------------------------------------------------------------- /Sources/wxWidgetsTestApp/DrawingControl.hpp: -------------------------------------------------------------------------------- 1 | #ifndef DRAWINGCONTROL_HPP 2 | #define DRAWINGCONTROL_HPP 3 | 4 | #include "NUIE_DrawingContext.hpp" 5 | #include "NUIE_ViewBox.hpp" 6 | #include "WXAS_ControlUtilities.hpp" 7 | #include "ResultImage.hpp" 8 | 9 | #include 10 | #include 11 | 12 | class DrawingControl : public wxPanel 13 | { 14 | public: 15 | DrawingControl (wxWindow *parent, const std::shared_ptr& resultImage); 16 | 17 | void OnPaint (wxPaintEvent& evt); 18 | void OnResize (wxSizeEvent& evt); 19 | void OnMouseCaptureLost (wxMouseCaptureLostEvent& evt); 20 | 21 | void OnRightButtonDown (wxMouseEvent& evt); 22 | void OnRightButtonUp (wxMouseEvent& evt); 23 | void OnMouseMove (wxMouseEvent& evt); 24 | void OnMouseWheel (wxMouseEvent& evt); 25 | 26 | void ClearImage (); 27 | void RedrawImage (); 28 | 29 | private: 30 | WXAS::MouseCaptureHandler captureHandler; 31 | std::shared_ptr resultImage; 32 | 33 | std::shared_ptr drawingContext; 34 | NUIE::ViewBox viewBox; 35 | std::unique_ptr lastMousePos; 36 | 37 | DECLARE_EVENT_TABLE () 38 | }; 39 | 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /Sources/wxWidgetsTestApp/ResultImage.cpp: -------------------------------------------------------------------------------- 1 | #include "ResultImage.hpp" 2 | 3 | ResultImage::ResultImage () : 4 | modified (false) 5 | { 6 | 7 | } 8 | 9 | ResultImage::~ResultImage () 10 | { 11 | 12 | } 13 | 14 | bool ResultImage::IsModified () const 15 | { 16 | return modified; 17 | } 18 | 19 | void ResultImage::Draw (NUIE::DrawingContext& context) const 20 | { 21 | drawingImage.Draw (context); 22 | } 23 | 24 | void ResultImage::AddItem (const NUIE::DrawingItemConstPtr& item) 25 | { 26 | drawingImage.AddItem (item); 27 | Invalidate (); 28 | } 29 | 30 | void ResultImage::RemoveItem (const NUIE::DrawingItemConstPtr& item) 31 | { 32 | drawingImage.RemoveItem (item); 33 | Invalidate (); 34 | } 35 | 36 | void ResultImage::Invalidate () 37 | { 38 | modified = true; 39 | } 40 | 41 | void ResultImage::Validate () 42 | { 43 | modified = false; 44 | } 45 | 46 | void ResultImage::Clear () 47 | { 48 | drawingImage.Clear (); 49 | Invalidate (); 50 | } 51 | 52 | ResultImageEvaluationData::ResultImageEvaluationData (const std::shared_ptr& resultImage) : 53 | resultImage (resultImage) 54 | { 55 | 56 | } 57 | 58 | ResultImageEvaluationData::~ResultImageEvaluationData () 59 | { 60 | 61 | } 62 | 63 | std::shared_ptr& ResultImageEvaluationData::GetResultImage () 64 | { 65 | return resultImage; 66 | } 67 | 68 | void ResultImageEvaluationData::AddItem (const NUIE::DrawingItemConstPtr& item) 69 | { 70 | resultImage->AddItem (item); 71 | } 72 | 73 | void ResultImageEvaluationData::RemoveItem (const NUIE::DrawingItemConstPtr& item) 74 | { 75 | resultImage->RemoveItem (item); 76 | } 77 | -------------------------------------------------------------------------------- /Sources/wxWidgetsTestApp/ResultImage.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RESULTIMAGE_HPP 2 | #define RESULTIMAGE_HPP 3 | 4 | #include "NE_EvaluationEnv.hpp" 5 | #include "NUIE_DrawingImage.hpp" 6 | 7 | class ResultImage 8 | { 9 | public: 10 | ResultImage (); 11 | virtual ~ResultImage (); 12 | 13 | bool IsModified () const; 14 | void Draw (NUIE::DrawingContext& context) const; 15 | 16 | void AddItem (const NUIE::DrawingItemConstPtr& item); 17 | void RemoveItem (const NUIE::DrawingItemConstPtr& item); 18 | void Invalidate (); 19 | void Validate (); 20 | void Clear (); 21 | 22 | private: 23 | NUIE::DrawingImage drawingImage; 24 | bool modified; 25 | }; 26 | 27 | class ResultImageEvaluationData : public NE::EvaluationData 28 | { 29 | public: 30 | ResultImageEvaluationData (const std::shared_ptr& resultImage); 31 | virtual ~ResultImageEvaluationData (); 32 | 33 | std::shared_ptr& GetResultImage (); 34 | void AddItem (const NUIE::DrawingItemConstPtr& item); 35 | void RemoveItem (const NUIE::DrawingItemConstPtr& item); 36 | 37 | private: 38 | std::shared_ptr resultImage; 39 | }; 40 | 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /Sources/wxWidgetsTestApp/TestAppNodes.cpp: -------------------------------------------------------------------------------- 1 | #include "TestAppNodes.hpp" 2 | #include "NE_ValueCombination.hpp" 3 | #include "NUIE_NodeParameters.hpp" 4 | #include "NUIE_NodeCommonParameters.hpp" 5 | #include "TestAppValues.hpp" 6 | #include "ResultImage.hpp" 7 | 8 | SERIALIZATION_INFO (DrawableNode, 1); 9 | DYNAMIC_SERIALIZATION_INFO (ColorNode, 1, "{CBB0BCBD-488B-4A35-A796-9A7FED2E9420}"); 10 | DYNAMIC_SERIALIZATION_INFO (PointNode, 1, "{E19AC155-90A7-43EA-9406-8E0876BAE05F}"); 11 | DYNAMIC_SERIALIZATION_INFO (LineNode, 1, "{3EEBD3D1-7D67-4513-9F29-60E2D7B5DE2B}"); 12 | DYNAMIC_SERIALIZATION_INFO (CircleNode, 1, "{651FEFFD-4F77-4E31-8765-CAF542491261}"); 13 | DYNAMIC_SERIALIZATION_INFO (OffsetNode, 1, "{76B41F97-8819-4F7E-8377-BD0FC0491C1A}"); 14 | 15 | ColorNode::ColorNode () : 16 | ColorNode (NE::LocString (), NUIE::Point ()) 17 | { 18 | 19 | } 20 | 21 | ColorNode::ColorNode (const NE::LocString& name, const NUIE::Point& position) : 22 | BI::BasicUINode (name, position) 23 | { 24 | 25 | } 26 | 27 | void ColorNode::Initialize () 28 | { 29 | RegisterUIInputSlot (NUIE::UIInputSlotPtr (new NUIE::UIInputSlot (NE::SlotId ("r"), NE::LocString (L"Red"), NE::ValuePtr (new NE::IntValue (0)), NE::OutputSlotConnectionMode::Single))); 30 | RegisterUIInputSlot (NUIE::UIInputSlotPtr (new NUIE::UIInputSlot (NE::SlotId ("g"), NE::LocString (L"Green"), NE::ValuePtr (new NE::IntValue (0)), NE::OutputSlotConnectionMode::Single))); 31 | RegisterUIInputSlot (NUIE::UIInputSlotPtr (new NUIE::UIInputSlot (NE::SlotId ("b"), NE::LocString (L"Blue"), NE::ValuePtr (new NE::IntValue (0)), NE::OutputSlotConnectionMode::Single))); 32 | RegisterUIOutputSlot (NUIE::UIOutputSlotPtr (new NUIE::UIOutputSlot (NE::SlotId ("color"), NE::LocString (L"Color")))); 33 | RegisterFeature (BI::NodeFeaturePtr (new BI::ValueCombinationFeature (NE::ValueCombinationMode::Longest))); 34 | } 35 | 36 | NE::ValueConstPtr ColorNode::Calculate (NE::EvaluationEnv& env) const 37 | { 38 | NE::ValueConstPtr r = EvaluateInputSlot (NE::SlotId ("r"), env); 39 | NE::ValueConstPtr g = EvaluateInputSlot (NE::SlotId ("g"), env); 40 | NE::ValueConstPtr b = EvaluateInputSlot (NE::SlotId ("b"), env); 41 | if (!NE::IsComplexType (r) || !NE::IsComplexType (g) || !NE::IsComplexType (b)) { 42 | return nullptr; 43 | } 44 | 45 | NE::ListValuePtr result (new NE::ListValue ()); 46 | BI::ValueCombinationFeature::CombineValues (this, { r, g, b }, [&] (const NE::ValueCombination& combination) { 47 | unsigned char rColor = (unsigned char) NE::NumberValue::ToInteger (combination.GetValue (0)); 48 | unsigned char gColor = (unsigned char) NE::NumberValue::ToInteger (combination.GetValue (1)); 49 | unsigned char bColor = (unsigned char) NE::NumberValue::ToInteger (combination.GetValue (2)); 50 | result->Push (NE::ValuePtr (new ColorValue (Color (rColor, gColor, bColor)))); 51 | return true; 52 | }); 53 | 54 | return result; 55 | } 56 | 57 | void ColorNode::RegisterParameters (NUIE::NodeParameterList& parameterList) const 58 | { 59 | class RedParameter : public NUIE::SlotDefaultValueNodeParameter 60 | { 61 | public: 62 | RedParameter () : 63 | SlotDefaultValueNodeParameter (NE::SlotId ("r"), NE::LocString (L"Red"), NUIE::ParameterType::Integer) 64 | { 65 | 66 | } 67 | 68 | virtual bool IsValidValue (const NUIE::UINodeConstPtr&, const std::shared_ptr& value) const override 69 | { 70 | return value->GetValue () >= 0 && value->GetValue () <= 255; 71 | } 72 | }; 73 | 74 | class GreenParameter : public NUIE::SlotDefaultValueNodeParameter 75 | { 76 | public: 77 | GreenParameter () : 78 | SlotDefaultValueNodeParameter (NE::SlotId ("g"), NE::LocString (L"Green"), NUIE::ParameterType::Integer) 79 | { 80 | 81 | } 82 | 83 | virtual bool IsValidValue (const NUIE::UINodeConstPtr&, const std::shared_ptr& value) const override 84 | { 85 | return value->GetValue () >= 0 && value->GetValue () <= 255; 86 | } 87 | }; 88 | 89 | class BlueParameter : public NUIE::SlotDefaultValueNodeParameter 90 | { 91 | public: 92 | BlueParameter () : 93 | SlotDefaultValueNodeParameter (NE::SlotId ("b"), NE::LocString (L"Blue"), NUIE::ParameterType::Integer) 94 | { 95 | 96 | } 97 | 98 | virtual bool IsValidValue (const NUIE::UINodeConstPtr&, const std::shared_ptr& value) const override 99 | { 100 | return value->GetValue () >= 0 && value->GetValue () <= 255; 101 | } 102 | }; 103 | 104 | BI::BasicUINode::RegisterParameters (parameterList); 105 | parameterList.AddParameter (NUIE::NodeParameterPtr (new RedParameter ())); 106 | parameterList.AddParameter (NUIE::NodeParameterPtr (new GreenParameter ())); 107 | parameterList.AddParameter (NUIE::NodeParameterPtr (new BlueParameter ())); 108 | } 109 | 110 | NE::Stream::Status ColorNode::Read (NE::InputStream& inputStream) 111 | { 112 | NE::ObjectHeader header (inputStream); 113 | BI::BasicUINode::Read (inputStream); 114 | return inputStream.GetStatus (); 115 | } 116 | 117 | NE::Stream::Status ColorNode::Write (NE::OutputStream& outputStream) const 118 | { 119 | NE::ObjectHeader header (outputStream, serializationInfo); 120 | BI::BasicUINode::Write (outputStream); 121 | return outputStream.GetStatus (); 122 | } 123 | 124 | DrawableNode::DrawableNode () : 125 | DrawableNode (NE::LocString (), NUIE::Point ()) 126 | { 127 | 128 | } 129 | 130 | DrawableNode::DrawableNode (const NE::LocString& name, const NUIE::Point& position) : 131 | BI::BasicUINode (name, position) 132 | { 133 | 134 | } 135 | 136 | void DrawableNode::Initialize () 137 | { 138 | RegisterFeature (BI::NodeFeaturePtr (new BI::EnableDisableFeature (BI::EnableDisableFeature::State::Enabled, BI::EnableDisableFeature::Mode::DoNotInvalidate))); 139 | RegisterFeature (BI::NodeFeaturePtr (new BI::ValueCombinationFeature (NE::ValueCombinationMode::Longest))); 140 | } 141 | 142 | void DrawableNode::RegisterParameters (NUIE::NodeParameterList& parameterList) const 143 | { 144 | BI::BasicUINode::RegisterParameters (parameterList); 145 | } 146 | 147 | void DrawableNode::ProcessCalculatedValue (const NE::ValueConstPtr& value, NE::EvaluationEnv& env) const 148 | { 149 | std::shared_ptr enableDisable = GetEnableDisableFeature (this); 150 | if (enableDisable->GetState () == BI::EnableDisableFeature::State::Enabled) { 151 | OnCalculated (value, env); 152 | } 153 | } 154 | 155 | void DrawableNode::OnCalculated (const NE::ValueConstPtr&, NE::EvaluationEnv& env) const 156 | { 157 | RemoveItem (env); 158 | AddItem (env); 159 | } 160 | 161 | void DrawableNode::OnEnabled (NE::EvaluationEnv& env) const 162 | { 163 | RemoveItem (env); 164 | AddItem (env); 165 | } 166 | 167 | void DrawableNode::OnDisabled (NE::EvaluationEnv& env) const 168 | { 169 | RemoveItem (env); 170 | } 171 | 172 | void DrawableNode::OnFeatureChange (const BI::FeatureId& featureId, NE::EvaluationEnv& env) const 173 | { 174 | if (featureId == BI::EnableDisableFeatureId) { 175 | std::shared_ptr enableDisable = GetEnableDisableFeature (this); 176 | if (enableDisable->GetState () == BI::EnableDisableFeature::State::Enabled) { 177 | OnEnabled (env); 178 | } else { 179 | OnDisabled (env); 180 | } 181 | } 182 | } 183 | 184 | void DrawableNode::OnDelete (NE::EvaluationEnv& env) const 185 | { 186 | RemoveItem (env); 187 | } 188 | 189 | NUIE::DrawingItemConstPtr DrawableNode::CreateDrawingItem (const NE::ValueConstPtr& value) const 190 | { 191 | if (!NE::Value::IsType (value)) { 192 | return nullptr; 193 | } 194 | std::shared_ptr result (new NUIE::MultiDrawingItem ()); 195 | NE::Value::Cast (value)->Enumerate ([&] (const NE::ValueConstPtr& innerValue) { 196 | const DrawableValue* drawableValue = NE::Value::Cast (innerValue.get ()); 197 | if (DBGVERIFY (drawableValue != nullptr)) { 198 | result->AddItem (drawableValue->CreateDrawingItem ()); 199 | } 200 | return true; 201 | }); 202 | return result; 203 | } 204 | 205 | void DrawableNode::AddItem (NE::EvaluationEnv& env) const 206 | { 207 | if (DBGERROR (!env.IsDataType ())) { 208 | return; 209 | } 210 | NE::ValueConstPtr value = GetCalculatedValue (); 211 | drawingItem = CreateDrawingItem (value); 212 | if (drawingItem != nullptr) { 213 | std::shared_ptr evalData = env.GetData (); 214 | evalData->AddItem (drawingItem); 215 | } 216 | } 217 | 218 | void DrawableNode::RemoveItem (NE::EvaluationEnv& env) const 219 | { 220 | if (DBGERROR (!env.IsDataType ())) { 221 | return; 222 | } 223 | if (drawingItem != nullptr) { 224 | std::shared_ptr evalData = env.GetData (); 225 | evalData->RemoveItem (drawingItem); 226 | drawingItem = nullptr; 227 | } 228 | } 229 | 230 | NE::Stream::Status DrawableNode::Read (NE::InputStream& inputStream) 231 | { 232 | NE::ObjectHeader header (inputStream); 233 | BI::BasicUINode::Read (inputStream); 234 | return inputStream.GetStatus (); 235 | } 236 | 237 | NE::Stream::Status DrawableNode::Write (NE::OutputStream& outputStream) const 238 | { 239 | NE::ObjectHeader header (outputStream, serializationInfo); 240 | BI::BasicUINode::Write (outputStream); 241 | return outputStream.GetStatus (); 242 | } 243 | 244 | void DrawableNode::DrawInplace (NUIE::NodeUIDrawingEnvironment& env) const 245 | { 246 | std::shared_ptr enableDisable = GetEnableDisableFeature (this); 247 | enableDisable->DrawInplace (env, [&] (NUIE::NodeUIDrawingEnvironment& newEnv) { 248 | BI::BasicUINode::DrawInplace (newEnv); 249 | }); 250 | } 251 | 252 | PointNode::PointNode () : 253 | PointNode (NE::LocString (), NUIE::Point ()) 254 | { 255 | 256 | } 257 | 258 | PointNode::PointNode (const NE::LocString& name, const NUIE::Point& position) : 259 | DrawableNode (name, position) 260 | { 261 | 262 | } 263 | 264 | void PointNode::Initialize () 265 | { 266 | DrawableNode::Initialize (); 267 | RegisterUIInputSlot (NUIE::UIInputSlotPtr (new NUIE::UIInputSlot (NE::SlotId ("x"), NE::LocString (L"X"), NE::ValuePtr (new NE::DoubleValue (0.0)), NE::OutputSlotConnectionMode::Single))); 268 | RegisterUIInputSlot (NUIE::UIInputSlotPtr (new NUIE::UIInputSlot (NE::SlotId ("y"), NE::LocString (L"Y"), NE::ValuePtr (new NE::DoubleValue (0.0)), NE::OutputSlotConnectionMode::Single))); 269 | RegisterUIOutputSlot (NUIE::UIOutputSlotPtr (new NUIE::UIOutputSlot (NE::SlotId ("point"), NE::LocString (L"Point")))); 270 | } 271 | 272 | NE::ValueConstPtr PointNode::Calculate (NE::EvaluationEnv& env) const 273 | { 274 | NE::ValueConstPtr x = EvaluateInputSlot (NE::SlotId ("x"), env); 275 | NE::ValueConstPtr y = EvaluateInputSlot (NE::SlotId ("y"), env); 276 | if (!NE::IsComplexType (x) || !NE::IsComplexType (y)) { 277 | return nullptr; 278 | } 279 | 280 | NE::ListValuePtr result (new NE::ListValue ()); 281 | BI::ValueCombinationFeature::CombineValues (this, {x, y}, [&] (const NE::ValueCombination& combination) { 282 | result->Push (NE::ValuePtr (new PointValue ( 283 | Point ( 284 | NE::NumberValue::ToDouble (combination.GetValue (0)), 285 | NE::NumberValue::ToDouble (combination.GetValue (1)) 286 | ) 287 | ))); 288 | return true; 289 | }); 290 | 291 | return result; 292 | } 293 | 294 | void PointNode::RegisterParameters (NUIE::NodeParameterList& parameterList) const 295 | { 296 | DrawableNode::RegisterParameters (parameterList); 297 | NUIE::RegisterSlotDefaultValueNodeParameter (parameterList, NE::SlotId ("x"), NE::LocString (L"Position X"), NUIE::ParameterType::Double); 298 | NUIE::RegisterSlotDefaultValueNodeParameter (parameterList, NE::SlotId ("y"), NE::LocString (L"Position Y"), NUIE::ParameterType::Double); 299 | } 300 | 301 | NE::Stream::Status PointNode::Read (NE::InputStream& inputStream) 302 | { 303 | NE::ObjectHeader header (inputStream); 304 | DrawableNode::Read (inputStream); 305 | return inputStream.GetStatus (); 306 | } 307 | 308 | NE::Stream::Status PointNode::Write (NE::OutputStream& outputStream) const 309 | { 310 | NE::ObjectHeader header (outputStream, serializationInfo); 311 | DrawableNode::Write (outputStream); 312 | return outputStream.GetStatus (); 313 | } 314 | 315 | LineNode::LineNode () : 316 | LineNode (NE::LocString (), NUIE::Point ()) 317 | { 318 | 319 | } 320 | 321 | LineNode::LineNode (const NE::LocString& name, const NUIE::Point& position) : 322 | DrawableNode (name, position) 323 | { 324 | 325 | } 326 | 327 | void LineNode::Initialize () 328 | { 329 | DrawableNode::Initialize (); 330 | RegisterUIInputSlot (NUIE::UIInputSlotPtr (new NUIE::UIInputSlot (NE::SlotId ("beg"), NE::LocString (L"Beg"), nullptr, NE::OutputSlotConnectionMode::Single))); 331 | RegisterUIInputSlot (NUIE::UIInputSlotPtr (new NUIE::UIInputSlot (NE::SlotId ("end"), NE::LocString (L"End"), nullptr, NE::OutputSlotConnectionMode::Single))); 332 | RegisterUIInputSlot (NUIE::UIInputSlotPtr (new NUIE::UIInputSlot (NE::SlotId ("color"), NE::LocString (L"Color"), NE::ValuePtr (new ColorValue (Color (0, 0, 0))), NE::OutputSlotConnectionMode::Single))); 333 | RegisterUIOutputSlot (NUIE::UIOutputSlotPtr (new NUIE::UIOutputSlot (NE::SlotId ("line"), NE::LocString (L"Line")))); 334 | } 335 | 336 | NE::ValueConstPtr LineNode::Calculate (NE::EvaluationEnv& env) const 337 | { 338 | NE::ValueConstPtr beg = EvaluateInputSlot (NE::SlotId ("beg"), env); 339 | NE::ValueConstPtr end = EvaluateInputSlot (NE::SlotId ("end"), env); 340 | NE::ValueConstPtr color = EvaluateInputSlot (NE::SlotId ("color"), env); 341 | if (!NE::IsComplexType (beg) || !NE::IsComplexType (end) || !NE::IsComplexType (color)) { 342 | return nullptr; 343 | } 344 | 345 | NE::ListValuePtr result (new NE::ListValue ()); 346 | BI::ValueCombinationFeature::CombineValues (this, {beg, end, color}, [&] (const NE::ValueCombination& combination) { 347 | result->Push (NE::ValuePtr (new LineValue ( 348 | Line ( 349 | PointValue::Get (combination.GetValue (0)), 350 | PointValue::Get (combination.GetValue (1)), 351 | ColorValue::Get (combination.GetValue (2)) 352 | ) 353 | ))); 354 | return true; 355 | }); 356 | 357 | return result; 358 | } 359 | 360 | NE::Stream::Status LineNode::Read (NE::InputStream& inputStream) 361 | { 362 | NE::ObjectHeader header (inputStream); 363 | DrawableNode::Read (inputStream); 364 | return inputStream.GetStatus (); 365 | } 366 | 367 | NE::Stream::Status LineNode::Write (NE::OutputStream& outputStream) const 368 | { 369 | NE::ObjectHeader header (outputStream, serializationInfo); 370 | DrawableNode::Write (outputStream); 371 | return outputStream.GetStatus (); 372 | } 373 | 374 | CircleNode::CircleNode () : 375 | CircleNode (NE::LocString (), NUIE::Point ()) 376 | { 377 | 378 | } 379 | 380 | CircleNode::CircleNode (const NE::LocString& name, const NUIE::Point& position) : 381 | DrawableNode (name, position) 382 | { 383 | 384 | } 385 | 386 | void CircleNode::Initialize () 387 | { 388 | DrawableNode::Initialize (); 389 | RegisterUIInputSlot (NUIE::UIInputSlotPtr (new NUIE::UIInputSlot (NE::SlotId ("center"), NE::LocString (L"Center"), nullptr, NE::OutputSlotConnectionMode::Single))); 390 | RegisterUIInputSlot (NUIE::UIInputSlotPtr (new NUIE::UIInputSlot (NE::SlotId ("radius"), NE::LocString (L"Radius"), NE::ValuePtr (new NE::DoubleValue (10.0)), NE::OutputSlotConnectionMode::Single))); 391 | RegisterUIInputSlot (NUIE::UIInputSlotPtr (new NUIE::UIInputSlot (NE::SlotId ("color"), NE::LocString (L"Color"), NE::ValuePtr (new ColorValue (Color (0, 0, 0))), NE::OutputSlotConnectionMode::Single))); 392 | RegisterUIOutputSlot (NUIE::UIOutputSlotPtr (new NUIE::UIOutputSlot (NE::SlotId ("circle"), NE::LocString (L"Circle")))); 393 | } 394 | 395 | NE::ValueConstPtr CircleNode::Calculate (NE::EvaluationEnv& env) const 396 | { 397 | NE::ValueConstPtr beg = EvaluateInputSlot (NE::SlotId ("center"), env); 398 | NE::ValueConstPtr end = EvaluateInputSlot (NE::SlotId ("radius"), env); 399 | NE::ValueConstPtr color = EvaluateInputSlot (NE::SlotId ("color"), env); 400 | if (!NE::IsComplexType (beg) || !NE::IsComplexType (end) || !NE::IsComplexType (color)) { 401 | return nullptr; 402 | } 403 | 404 | NE::ListValuePtr result (new NE::ListValue ()); 405 | BI::ValueCombinationFeature::CombineValues (this, {beg, end, color}, [&] (const NE::ValueCombination& combination) { 406 | result->Push (NE::ValuePtr (new CircleValue ( 407 | Circle ( 408 | PointValue::Get (combination.GetValue (0)), 409 | NE::NumberValue::ToDouble (combination.GetValue (1)), 410 | ColorValue::Get (combination.GetValue (2)) 411 | ) 412 | ))); 413 | return true; 414 | }); 415 | 416 | return result; 417 | } 418 | 419 | void CircleNode::RegisterParameters (NUIE::NodeParameterList& parameterList) const 420 | { 421 | class RadiusParameter : public NUIE::SlotDefaultValueNodeParameter 422 | { 423 | public: 424 | RadiusParameter () : 425 | SlotDefaultValueNodeParameter (NE::SlotId ("radius"), NE::LocString (L"Radius"), NUIE::ParameterType::Double) 426 | { 427 | 428 | } 429 | 430 | virtual bool IsValidValue (const NUIE::UINodeConstPtr&, const std::shared_ptr& value) const override 431 | { 432 | return value->GetValue () >= 0.0; 433 | } 434 | }; 435 | 436 | DrawableNode::RegisterParameters (parameterList); 437 | parameterList.AddParameter (NUIE::NodeParameterPtr (new RadiusParameter ())); 438 | } 439 | 440 | NE::Stream::Status CircleNode::Read (NE::InputStream& inputStream) 441 | { 442 | NE::ObjectHeader header (inputStream); 443 | DrawableNode::Read (inputStream); 444 | return inputStream.GetStatus (); 445 | } 446 | 447 | NE::Stream::Status CircleNode::Write (NE::OutputStream& outputStream) const 448 | { 449 | NE::ObjectHeader header (outputStream, serializationInfo); 450 | DrawableNode::Write (outputStream); 451 | return outputStream.GetStatus (); 452 | } 453 | 454 | OffsetNode::OffsetNode () : 455 | OffsetNode (NE::LocString (), NUIE::Point ()) 456 | { 457 | 458 | } 459 | 460 | OffsetNode::OffsetNode (const NE::LocString& name, const NUIE::Point& position) : 461 | DrawableNode (name, position) 462 | { 463 | 464 | } 465 | 466 | void OffsetNode::Initialize () 467 | { 468 | DrawableNode::Initialize (); 469 | RegisterUIInputSlot (NUIE::UIInputSlotPtr (new NUIE::UIInputSlot (NE::SlotId ("geometry"), NE::LocString (L"Geometry"), nullptr, NE::OutputSlotConnectionMode::Single))); 470 | RegisterUIInputSlot (NUIE::UIInputSlotPtr (new NUIE::UIInputSlot (NE::SlotId ("x"), NE::LocString (L"X"), NE::ValuePtr (new NE::DoubleValue (0.0)), NE::OutputSlotConnectionMode::Single))); 471 | RegisterUIInputSlot (NUIE::UIInputSlotPtr (new NUIE::UIInputSlot (NE::SlotId ("y"), NE::LocString (L"Y"), NE::ValuePtr (new NE::DoubleValue (0.0)), NE::OutputSlotConnectionMode::Single))); 472 | RegisterUIOutputSlot (NUIE::UIOutputSlotPtr (new NUIE::UIOutputSlot (NE::SlotId ("geometry"), NE::LocString (L"Geometry")))); 473 | } 474 | 475 | NE::ValueConstPtr OffsetNode::Calculate (NE::EvaluationEnv& env) const 476 | { 477 | NE::ValueConstPtr geometry = EvaluateInputSlot (NE::SlotId ("geometry"), env); 478 | NE::ValueConstPtr x = EvaluateInputSlot (NE::SlotId ("x"), env); 479 | NE::ValueConstPtr y = EvaluateInputSlot (NE::SlotId ("y"), env); 480 | if (!NE::IsComplexType (geometry) || !NE::IsComplexType (x) || !NE::IsComplexType (y)) { 481 | return nullptr; 482 | } 483 | 484 | NE::ListValuePtr result (new NE::ListValue ()); 485 | BI::ValueCombinationFeature::CombineValues (this, { geometry, x, y }, [&] (const NE::ValueCombination& combination) { 486 | const GeometricValue* geomValue = NE::Value::Cast (combination.GetValue (0).get ()); 487 | Transformation transformation = Transformation::Translation ( 488 | NE::NumberValue::ToDouble (combination.GetValue (1)), 489 | NE::NumberValue::ToDouble (combination.GetValue (2)) 490 | ); 491 | if (DBGVERIFY (geomValue != nullptr)) { 492 | result->Push (geomValue->Transform (transformation)); 493 | } 494 | return true; 495 | }); 496 | 497 | return result; 498 | } 499 | 500 | void OffsetNode::RegisterParameters (NUIE::NodeParameterList& parameterList) const 501 | { 502 | BI::BasicUINode::RegisterParameters (parameterList); 503 | NUIE::RegisterSlotDefaultValueNodeParameter (parameterList, NE::SlotId ("x"), NE::LocString (L"X"), NUIE::ParameterType::Double); 504 | NUIE::RegisterSlotDefaultValueNodeParameter (parameterList, NE::SlotId ("y"), NE::LocString (L"Y"), NUIE::ParameterType::Double); 505 | } 506 | 507 | NE::Stream::Status OffsetNode::Read (NE::InputStream& inputStream) 508 | { 509 | NE::ObjectHeader header (inputStream); 510 | BI::BasicUINode::Read (inputStream); 511 | return inputStream.GetStatus (); 512 | } 513 | 514 | NE::Stream::Status OffsetNode::Write (NE::OutputStream& outputStream) const 515 | { 516 | NE::ObjectHeader header (outputStream, serializationInfo); 517 | BI::BasicUINode::Write (outputStream); 518 | return outputStream.GetStatus (); 519 | } 520 | -------------------------------------------------------------------------------- /Sources/wxWidgetsTestApp/TestAppNodes.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TESTAPPNODES_HPP 2 | #define TESTAPPNODES_HPP 3 | 4 | #include "NE_SingleValues.hpp" 5 | #include "NUIE_NodeUIManager.hpp" 6 | #include "NUIE_NodeMenuCommands.hpp" 7 | #include "BI_BasicUINode.hpp" 8 | #include "BI_BuiltInFeatures.hpp" 9 | 10 | class ColorNode : public BI::BasicUINode 11 | { 12 | DYNAMIC_SERIALIZABLE (ColorNode); 13 | 14 | public: 15 | ColorNode (); 16 | ColorNode (const NE::LocString& name, const NUIE::Point& position); 17 | 18 | virtual void Initialize () override; 19 | virtual NE::ValueConstPtr Calculate (NE::EvaluationEnv& env) const override; 20 | virtual void RegisterParameters (NUIE::NodeParameterList& parameterList) const; 21 | 22 | virtual NE::Stream::Status Read (NE::InputStream& inputStream) override; 23 | virtual NE::Stream::Status Write (NE::OutputStream& outputStream) const override; 24 | }; 25 | 26 | class DrawableNode : public BI::BasicUINode 27 | { 28 | SERIALIZABLE; 29 | 30 | public: 31 | DrawableNode (); 32 | DrawableNode (const NE::LocString& name, const NUIE::Point& position); 33 | 34 | virtual void Initialize () override; 35 | virtual void RegisterParameters (NUIE::NodeParameterList& parameterList) const override; 36 | virtual void ProcessCalculatedValue (const NE::ValueConstPtr& value, NE::EvaluationEnv& env) const override; 37 | virtual void OnFeatureChange (const BI::FeatureId& featureId, NE::EvaluationEnv& env) const override; 38 | virtual void OnDelete (NE::EvaluationEnv& env) const override; 39 | 40 | void OnCalculated (const NE::ValueConstPtr& value, NE::EvaluationEnv& env) const; 41 | void OnEnabled (NE::EvaluationEnv& env) const; 42 | void OnDisabled (NE::EvaluationEnv& env) const; 43 | 44 | virtual NE::Stream::Status Read (NE::InputStream& inputStream) override; 45 | virtual NE::Stream::Status Write (NE::OutputStream& outputStream) const override; 46 | 47 | private: 48 | virtual void DrawInplace (NUIE::NodeUIDrawingEnvironment& env) const override; 49 | NUIE::DrawingItemConstPtr CreateDrawingItem (const NE::ValueConstPtr& value) const; 50 | void AddItem (NE::EvaluationEnv& env) const; 51 | void RemoveItem (NE::EvaluationEnv& env) const; 52 | 53 | mutable NUIE::DrawingItemConstPtr drawingItem; 54 | }; 55 | 56 | class PointNode : public DrawableNode 57 | { 58 | DYNAMIC_SERIALIZABLE (PointNode); 59 | 60 | public: 61 | PointNode (); 62 | PointNode (const NE::LocString& name, const NUIE::Point& position); 63 | 64 | virtual void Initialize () override; 65 | virtual NE::ValueConstPtr Calculate (NE::EvaluationEnv& env) const override; 66 | virtual void RegisterParameters (NUIE::NodeParameterList& parameterList) const; 67 | 68 | virtual NE::Stream::Status Read (NE::InputStream& inputStream) override; 69 | virtual NE::Stream::Status Write (NE::OutputStream& outputStream) const override; 70 | }; 71 | 72 | class LineNode : public DrawableNode 73 | { 74 | DYNAMIC_SERIALIZABLE (LineNode); 75 | 76 | public: 77 | LineNode (); 78 | LineNode (const NE::LocString& name, const NUIE::Point& position); 79 | 80 | virtual void Initialize () override; 81 | virtual NE::ValueConstPtr Calculate (NE::EvaluationEnv& env) const override; 82 | 83 | virtual NE::Stream::Status Read (NE::InputStream& inputStream) override; 84 | virtual NE::Stream::Status Write (NE::OutputStream& outputStream) const override; 85 | }; 86 | 87 | class CircleNode : public DrawableNode 88 | { 89 | DYNAMIC_SERIALIZABLE (CircleNode); 90 | 91 | public: 92 | CircleNode (); 93 | CircleNode (const NE::LocString& name, const NUIE::Point& position); 94 | 95 | virtual void Initialize () override; 96 | virtual NE::ValueConstPtr Calculate (NE::EvaluationEnv& env) const override; 97 | virtual void RegisterParameters (NUIE::NodeParameterList& parameterList) const; 98 | 99 | virtual NE::Stream::Status Read (NE::InputStream& inputStream) override; 100 | virtual NE::Stream::Status Write (NE::OutputStream& outputStream) const override; 101 | }; 102 | 103 | class OffsetNode : public DrawableNode 104 | { 105 | DYNAMIC_SERIALIZABLE (OffsetNode); 106 | 107 | public: 108 | OffsetNode (); 109 | OffsetNode (const NE::LocString& name, const NUIE::Point& position); 110 | 111 | virtual void Initialize () override; 112 | virtual NE::ValueConstPtr Calculate (NE::EvaluationEnv& env) const override; 113 | virtual void RegisterParameters (NUIE::NodeParameterList& parameterList) const; 114 | 115 | virtual NE::Stream::Status Read (NE::InputStream& inputStream) override; 116 | virtual NE::Stream::Status Write (NE::OutputStream& outputStream) const override; 117 | }; 118 | 119 | #endif 120 | -------------------------------------------------------------------------------- /Sources/wxWidgetsTestApp/TestAppValues.cpp: -------------------------------------------------------------------------------- 1 | #include "TestAppValues.hpp" 2 | #include "ResultImage.hpp" 3 | #include "NE_StringConverter.hpp" 4 | #include "NE_ValueCombination.hpp" 5 | #include "NUIE_NodeParameters.hpp" 6 | #include "NUIE_NodeCommonParameters.hpp" 7 | 8 | NE::DynamicSerializationInfo ColorValue::serializationInfo (NE::ObjectId ("{E6D2DBDC-6311-4BA5-9B1A-A0FFF8CA2444}"), NE::ObjectVersion (1), ColorValue::CreateSerializableInstance); 9 | NE::DynamicSerializationInfo PointValue::serializationInfo (NE::ObjectId ("{2C242A9E-1054-4E16-82C1-759C006097C9}"), NE::ObjectVersion (1), PointValue::CreateSerializableInstance); 10 | NE::DynamicSerializationInfo LineValue::serializationInfo (NE::ObjectId ("{2C860493-09EE-4EA2-8BC4-7FD8DE97BBC8}"), NE::ObjectVersion (1), LineValue::CreateSerializableInstance); 11 | NE::DynamicSerializationInfo CircleValue::serializationInfo (NE::ObjectId ("{88E71F51-D47D-4DE5-9182-D608E7E71741}"), NE::ObjectVersion (1), CircleValue::CreateSerializableInstance); 12 | 13 | Color::Color () : 14 | Color (0, 0, 0) 15 | { 16 | 17 | } 18 | 19 | Color::Color (unsigned char r, unsigned char g, unsigned char b) : 20 | r (r), 21 | g (g), 22 | b (b) 23 | { 24 | 25 | } 26 | 27 | std::wstring Color::ToString (const NE::StringConverter& stringConverter) const 28 | { 29 | std::wstring result = L""; 30 | result += L"Color ("; 31 | result += stringConverter.IntegerToString (r); 32 | result += L", "; 33 | result += stringConverter.IntegerToString (g); 34 | result += L", "; 35 | result += stringConverter.IntegerToString (b); 36 | result += L")"; 37 | return result; 38 | } 39 | 40 | NE::Stream::Status Color::Read (NE::InputStream& inputStream) 41 | { 42 | inputStream.Read (r); 43 | inputStream.Read (g); 44 | inputStream.Read (b); 45 | return inputStream.GetStatus (); 46 | } 47 | 48 | NE::Stream::Status Color::Write (NE::OutputStream& outputStream) const 49 | { 50 | outputStream.Write (r); 51 | outputStream.Write (g); 52 | outputStream.Write (b); 53 | return outputStream.GetStatus (); 54 | } 55 | 56 | Transformation::Transformation () : 57 | matrix { 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 } 58 | { 59 | 60 | } 61 | 62 | Transformation::Transformation (double m11, double m12, double m13, double m21, double m22, double m23, double m31, double m32, double m33) : 63 | matrix { m11, m12, m13, m21, m22, m23, m31, m32, m33 } 64 | { 65 | 66 | } 67 | 68 | Transformation::~Transformation () 69 | { 70 | 71 | } 72 | 73 | Transformation Transformation::Translation (double x, double y) 74 | { 75 | return Transformation ( 76 | 1.0, 0.0, x, 77 | 0.0, 1.0, y, 78 | 0.0, 0.0, 1.0 79 | ); 80 | } 81 | 82 | std::wstring Transformation::ToString (const NE::StringConverter& stringConverter) const 83 | { 84 | std::wstring result = L""; 85 | result += L"Matrix ("; 86 | for (int i = 0; i < 9; i++) { 87 | result += stringConverter.NumberToString (matrix[i], NE::StringConverter::Measure::Number); 88 | if (i < 9 - 1) { 89 | result += L", "; 90 | } 91 | } 92 | result += L")"; 93 | return result; 94 | } 95 | 96 | NE::Stream::Status Transformation::Read (NE::InputStream& inputStream) 97 | { 98 | for (int i = 0; i < 9; i++) { 99 | inputStream.Read (matrix[i]); 100 | } 101 | return inputStream.GetStatus (); 102 | } 103 | 104 | NE::Stream::Status Transformation::Write (NE::OutputStream& outputStream) const 105 | { 106 | for (int i = 0; i < 9; i++) { 107 | outputStream.Write (matrix[i]); 108 | } 109 | return outputStream.GetStatus (); 110 | } 111 | 112 | void Transformation::Apply (double& x, double& y) const 113 | { 114 | double oX = x; 115 | double oY = y; 116 | x = oX * matrix[0] + oY * matrix[1] + 1.0 * matrix[2]; 117 | y = oX * matrix[3] + oY * matrix[4] + 1.0 * matrix[5]; 118 | } 119 | 120 | Point::Point () : 121 | Point (0.0, 0.0) 122 | { 123 | 124 | } 125 | 126 | Point::Point (double x, double y) : 127 | x (x), 128 | y (y) 129 | { 130 | 131 | } 132 | 133 | std::wstring Point::ToString (const NE::StringConverter& stringConverter) const 134 | { 135 | std::wstring result = L""; 136 | result += L"Point ("; 137 | result += stringConverter.NumberToString (x, NE::StringConverter::Measure::Number); 138 | result += L", "; 139 | result += stringConverter.NumberToString (y, NE::StringConverter::Measure::Number); 140 | result += L")"; 141 | return result; 142 | } 143 | 144 | NE::Stream::Status Point::Read (NE::InputStream& inputStream) 145 | { 146 | inputStream.Read (x); 147 | inputStream.Read (y); 148 | return inputStream.GetStatus (); 149 | } 150 | 151 | NE::Stream::Status Point::Write (NE::OutputStream& outputStream) const 152 | { 153 | outputStream.Write (x); 154 | outputStream.Write (y); 155 | return outputStream.GetStatus (); 156 | } 157 | 158 | Point Point::Transform (const Transformation& transformation) const 159 | { 160 | Point result (x, y); 161 | transformation.Apply (result.x, result.y); 162 | return result; 163 | } 164 | 165 | Line::Line () : 166 | Line (Point (), Point (), Color ()) 167 | { 168 | 169 | } 170 | 171 | Line::Line (const Point& beg, const Point& end, const Color& color) : 172 | beg (beg), 173 | end (end), 174 | color (color) 175 | { 176 | 177 | } 178 | 179 | std::wstring Line::ToString (const NE::StringConverter& stringConverter) const 180 | { 181 | std::wstring result = L""; 182 | result += L"Line ("; 183 | result += beg.ToString (stringConverter); 184 | result += L" - "; 185 | result += end.ToString (stringConverter); 186 | result += L")"; 187 | return result; 188 | } 189 | 190 | NE::Stream::Status Line::Read (NE::InputStream& inputStream) 191 | { 192 | beg.Read (inputStream); 193 | end.Read (inputStream); 194 | color.Read (inputStream); 195 | return inputStream.GetStatus (); 196 | } 197 | 198 | NE::Stream::Status Line::Write (NE::OutputStream& outputStream) const 199 | { 200 | beg.Write (outputStream); 201 | end.Write (outputStream); 202 | color.Write (outputStream); 203 | return outputStream.GetStatus (); 204 | } 205 | 206 | Line Line::Transform (const Transformation& transformation) const 207 | { 208 | return Line (beg.Transform (transformation), end.Transform (transformation), color); 209 | } 210 | 211 | Circle::Circle () : 212 | Circle (Point (), 0, Color ()) 213 | { 214 | 215 | } 216 | 217 | Circle::Circle (const Point& center, double radius, const Color& color) : 218 | center (center), 219 | radius (radius), 220 | color (color) 221 | { 222 | 223 | } 224 | 225 | std::wstring Circle::ToString (const NE::StringConverter& stringConverter) const 226 | { 227 | std::wstring result = L""; 228 | result += L"Circle ("; 229 | result += center.ToString (stringConverter); 230 | result += L", "; 231 | result += stringConverter.NumberToString (radius, NE::StringConverter::Measure::Number); 232 | result += L")"; 233 | return result; 234 | } 235 | 236 | NE::Stream::Status Circle::Read (NE::InputStream& inputStream) 237 | { 238 | center.Read (inputStream); 239 | inputStream.Read (radius); 240 | color.Read (inputStream); 241 | return inputStream.GetStatus (); 242 | } 243 | 244 | NE::Stream::Status Circle::Write (NE::OutputStream& outputStream) const 245 | { 246 | center.Write (outputStream); 247 | outputStream.Write (radius); 248 | color.Write (outputStream); 249 | return outputStream.GetStatus (); 250 | } 251 | 252 | Circle Circle::Transform (const Transformation& transformation) const 253 | { 254 | return Circle (center.Transform (transformation), radius, color); 255 | } 256 | 257 | ColorValue::ColorValue () : 258 | ColorValue (Color ()) 259 | { 260 | 261 | } 262 | 263 | ColorValue::ColorValue (const Color& val) : 264 | NE::GenericValue (val) 265 | { 266 | 267 | } 268 | 269 | NE::ValuePtr ColorValue::Clone () const 270 | { 271 | return NE::ValuePtr (new ColorValue (val)); 272 | } 273 | 274 | std::wstring ColorValue::ToString (const NE::StringConverter& stringConverter) const 275 | { 276 | return val.ToString (stringConverter); 277 | } 278 | 279 | NE::Stream::Status ColorValue::Read (NE::InputStream& inputStream) 280 | { 281 | NE::ObjectHeader header (inputStream); 282 | val.Read (inputStream); 283 | return inputStream.GetStatus (); 284 | } 285 | 286 | NE::Stream::Status ColorValue::Write (NE::OutputStream& outputStream) const 287 | { 288 | NE::ObjectHeader header (outputStream, serializationInfo); 289 | val.Write (outputStream); 290 | return outputStream.GetStatus (); 291 | } 292 | 293 | GeometricValue::GeometricValue () 294 | { 295 | 296 | } 297 | 298 | GeometricValue::~GeometricValue () 299 | { 300 | 301 | } 302 | 303 | DrawableValue::DrawableValue () 304 | { 305 | 306 | } 307 | 308 | DrawableValue::~DrawableValue () 309 | { 310 | 311 | } 312 | 313 | PointValue::PointValue () : 314 | PointValue (Point ()) 315 | { 316 | 317 | } 318 | 319 | PointValue::PointValue (const Point& val) : 320 | NE::GenericValue (val) 321 | { 322 | 323 | } 324 | 325 | NE::ValuePtr PointValue::Clone () const 326 | { 327 | return NE::ValuePtr (new PointValue (val)); 328 | } 329 | 330 | std::wstring PointValue::ToString (const NE::StringConverter& stringConverter) const 331 | { 332 | return val.ToString (stringConverter); 333 | } 334 | 335 | NE::Stream::Status PointValue::Read (NE::InputStream& inputStream) 336 | { 337 | NE::ObjectHeader header (inputStream); 338 | NE::GenericValue::Read (inputStream); 339 | val.Read (inputStream); 340 | return inputStream.GetStatus (); 341 | } 342 | 343 | NE::Stream::Status PointValue::Write (NE::OutputStream& outputStream) const 344 | { 345 | NE::ObjectHeader header (outputStream, serializationInfo); 346 | NE::GenericValue::Write (outputStream); 347 | val.Write (outputStream); 348 | return outputStream.GetStatus (); 349 | } 350 | 351 | NE::ValuePtr PointValue::Transform (const Transformation& transformation) const 352 | { 353 | return NE::ValuePtr (new PointValue (val.Transform (transformation))); 354 | } 355 | 356 | NUIE::DrawingItemConstPtr PointValue::CreateDrawingItem () const 357 | { 358 | std::shared_ptr result (new NUIE::MultiDrawingItem ()); 359 | static const int pointSize = 10; 360 | NUIE::Rect pointRect (val.x - pointSize / 2, val.y - pointSize / 2, pointSize, pointSize); 361 | NUIE::Pen pointPen (NUIE::Color (80, 80, 80), 1.0); 362 | result->AddItem (NUIE::DrawingItemConstPtr (new NUIE::DrawingLine (pointRect.GetTopLeft (), pointRect.GetBottomRight (), pointPen))); 363 | result->AddItem (NUIE::DrawingItemConstPtr (new NUIE::DrawingLine (pointRect.GetBottomLeft (), pointRect.GetTopRight (), pointPen))); 364 | return result; 365 | } 366 | 367 | LineValue::LineValue () : 368 | LineValue (Line ()) 369 | { 370 | 371 | } 372 | 373 | LineValue::LineValue (const Line& val) : 374 | NE::GenericValue (val) 375 | { 376 | 377 | } 378 | 379 | NE::ValuePtr LineValue::Clone () const 380 | { 381 | return NE::ValuePtr (new LineValue (val)); 382 | } 383 | 384 | std::wstring LineValue::ToString (const NE::StringConverter& stringConverter) const 385 | { 386 | return val.ToString (stringConverter); 387 | } 388 | 389 | NE::Stream::Status LineValue::Read (NE::InputStream& inputStream) 390 | { 391 | NE::ObjectHeader header (inputStream); 392 | NE::GenericValue::Read (inputStream); 393 | val.Read (inputStream); 394 | return inputStream.GetStatus (); 395 | } 396 | 397 | NE::Stream::Status LineValue::Write (NE::OutputStream& outputStream) const 398 | { 399 | NE::ObjectHeader header (outputStream, serializationInfo); 400 | NE::GenericValue::Write (outputStream); 401 | val.Write (outputStream); 402 | return outputStream.GetStatus (); 403 | } 404 | 405 | NE::ValuePtr LineValue::Transform (const Transformation& transformation) const 406 | { 407 | return NE::ValuePtr (new LineValue (val.Transform (transformation))); 408 | } 409 | 410 | NUIE::DrawingItemConstPtr LineValue::CreateDrawingItem () const 411 | { 412 | return NUIE::DrawingItemConstPtr ( 413 | new NUIE::DrawingLine ( 414 | NUIE::Point (val.beg.x, val.beg.y), 415 | NUIE::Point (val.end.x, val.end.y), 416 | NUIE::Pen (NUIE::Color (val.color.r, val.color.g, val.color.b), 1.0) 417 | ) 418 | ); 419 | } 420 | 421 | CircleValue::CircleValue () : 422 | CircleValue (Circle ()) 423 | { 424 | 425 | } 426 | 427 | CircleValue::CircleValue (const Circle& val) : 428 | NE::GenericValue (val) 429 | { 430 | 431 | } 432 | 433 | NE::ValuePtr CircleValue::Clone () const 434 | { 435 | return NE::ValuePtr (new CircleValue (val)); 436 | } 437 | 438 | std::wstring CircleValue::ToString (const NE::StringConverter& stringConverter) const 439 | { 440 | return val.ToString (stringConverter); 441 | } 442 | 443 | NE::Stream::Status CircleValue::Read (NE::InputStream& inputStream) 444 | { 445 | NE::ObjectHeader header (inputStream); 446 | NE::GenericValue::Read (inputStream); 447 | val.Read (inputStream); 448 | return inputStream.GetStatus (); 449 | } 450 | 451 | NE::Stream::Status CircleValue::Write (NE::OutputStream& outputStream) const 452 | { 453 | NE::ObjectHeader header (outputStream, serializationInfo); 454 | NE::GenericValue::Write (outputStream); 455 | val.Write (outputStream); 456 | return outputStream.GetStatus (); 457 | } 458 | 459 | NE::ValuePtr CircleValue::Transform (const Transformation& transformation) const 460 | { 461 | return NE::ValuePtr (new CircleValue (val.Transform (transformation))); 462 | } 463 | 464 | NUIE::DrawingItemConstPtr CircleValue::CreateDrawingItem () const 465 | { 466 | NUIE::Rect rect = NUIE::Rect::FromCenterAndSize (NUIE::Point (val.center.x, val.center.y), NUIE::Size (val.radius * 2.0, val.radius * 2.0)); 467 | return NUIE::DrawingItemConstPtr (new NUIE::DrawingEllipse (rect, NUIE::Pen (NUIE::Color (val.color.r, val.color.g, val.color.b), 1.0))); 468 | } 469 | -------------------------------------------------------------------------------- /Sources/wxWidgetsTestApp/TestAppValues.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TESTAPPVALUES_HPP 2 | #define TESTAPPVALUES_HPP 3 | 4 | #include "NE_SingleValues.hpp" 5 | #include "NUIE_Geometry.hpp" 6 | #include "NUIE_Drawing.hpp" 7 | #include "NUIE_DrawingImage.hpp" 8 | 9 | class Color 10 | { 11 | public: 12 | Color (); 13 | Color (unsigned char r, unsigned char g, unsigned char b); 14 | 15 | std::wstring ToString (const NE::StringConverter& stringConverter) const; 16 | NE::Stream::Status Read (NE::InputStream& inputStream); 17 | NE::Stream::Status Write (NE::OutputStream& outputStream) const; 18 | 19 | unsigned char r; 20 | unsigned char g; 21 | unsigned char b; 22 | }; 23 | 24 | class Transformation 25 | { 26 | public: 27 | Transformation (); 28 | Transformation (double m11, double m12, double m13, double m21, double m22, double m23, double m31, double m32, double m33); 29 | ~Transformation (); 30 | 31 | std::wstring ToString (const NE::StringConverter& stringConverter) const; 32 | NE::Stream::Status Read (NE::InputStream& inputStream); 33 | NE::Stream::Status Write (NE::OutputStream& outputStream) const; 34 | 35 | void Apply (double& x, double& y) const; 36 | 37 | static Transformation Translation (double x, double y); 38 | 39 | private: 40 | double matrix[9]; 41 | }; 42 | 43 | class Point 44 | { 45 | public: 46 | Point (); 47 | Point (double x, double y); 48 | 49 | std::wstring ToString (const NE::StringConverter& stringConverter) const; 50 | NE::Stream::Status Read (NE::InputStream& inputStream); 51 | NE::Stream::Status Write (NE::OutputStream& outputStream) const; 52 | 53 | Point Transform (const Transformation& transformation) const; 54 | 55 | double x; 56 | double y; 57 | }; 58 | 59 | class Line 60 | { 61 | public: 62 | Line (); 63 | Line (const Point& beg, const Point& end, const Color& color); 64 | 65 | std::wstring ToString (const NE::StringConverter& stringConverter) const; 66 | NE::Stream::Status Read (NE::InputStream& inputStream); 67 | NE::Stream::Status Write (NE::OutputStream& outputStream) const; 68 | 69 | Line Transform (const Transformation& transformation) const; 70 | 71 | Point beg; 72 | Point end; 73 | Color color; 74 | }; 75 | 76 | class Circle 77 | { 78 | public: 79 | Circle (); 80 | Circle (const Point& center, double radius, const Color& color); 81 | 82 | std::wstring ToString (const NE::StringConverter& stringConverter) const; 83 | NE::Stream::Status Read (NE::InputStream& inputStream); 84 | NE::Stream::Status Write (NE::OutputStream& outputStream) const; 85 | 86 | Circle Transform (const Transformation& transformation) const; 87 | 88 | Point center; 89 | double radius; 90 | Color color; 91 | }; 92 | 93 | class ColorValue : public NE::GenericValue 94 | { 95 | DYNAMIC_SERIALIZABLE (ColorValue); 96 | 97 | public: 98 | ColorValue (); 99 | ColorValue (const Color& val); 100 | 101 | virtual NE::ValuePtr Clone () const override; 102 | virtual std::wstring ToString (const NE::StringConverter& stringConverter) const override; 103 | 104 | virtual NE::Stream::Status Read (NE::InputStream& inputStream) override; 105 | virtual NE::Stream::Status Write (NE::OutputStream& outputStream) const override; 106 | }; 107 | 108 | class GeometricValue 109 | { 110 | public: 111 | GeometricValue (); 112 | virtual ~GeometricValue (); 113 | 114 | virtual NE::ValuePtr Transform (const Transformation& transformation) const = 0; 115 | }; 116 | 117 | class DrawableValue 118 | { 119 | public: 120 | DrawableValue (); 121 | virtual ~DrawableValue (); 122 | 123 | virtual NUIE::DrawingItemConstPtr CreateDrawingItem () const = 0; 124 | }; 125 | 126 | class PointValue : public NE::GenericValue, 127 | public GeometricValue, 128 | public DrawableValue 129 | { 130 | DYNAMIC_SERIALIZABLE (PointValue); 131 | 132 | public: 133 | PointValue (); 134 | PointValue (const Point& val); 135 | 136 | virtual NE::ValuePtr Clone () const override; 137 | virtual std::wstring ToString (const NE::StringConverter& stringConverter) const override; 138 | virtual NE::Stream::Status Read (NE::InputStream& inputStream) override; 139 | virtual NE::Stream::Status Write (NE::OutputStream& outputStream) const override; 140 | 141 | virtual NE::ValuePtr Transform (const Transformation& transformation) const override; 142 | virtual NUIE::DrawingItemConstPtr CreateDrawingItem () const override; 143 | }; 144 | 145 | class LineValue : public NE::GenericValue, 146 | public GeometricValue, 147 | public DrawableValue 148 | { 149 | DYNAMIC_SERIALIZABLE (LineValue); 150 | 151 | public: 152 | LineValue (); 153 | LineValue (const Line& val); 154 | 155 | virtual NE::ValuePtr Clone () const override; 156 | virtual std::wstring ToString (const NE::StringConverter& stringConverter) const override; 157 | virtual NE::Stream::Status Read (NE::InputStream& inputStream) override; 158 | virtual NE::Stream::Status Write (NE::OutputStream& outputStream) const override; 159 | 160 | virtual NE::ValuePtr Transform (const Transformation& transformation) const override; 161 | virtual NUIE::DrawingItemConstPtr CreateDrawingItem () const override; 162 | }; 163 | 164 | class CircleValue : public NE::GenericValue, 165 | public GeometricValue, 166 | public DrawableValue 167 | { 168 | DYNAMIC_SERIALIZABLE (CircleValue); 169 | 170 | public: 171 | CircleValue (); 172 | CircleValue (const Circle& val); 173 | 174 | virtual NE::ValuePtr Clone () const override; 175 | virtual std::wstring ToString (const NE::StringConverter& stringConverter) const override; 176 | virtual NE::Stream::Status Read (NE::InputStream& inputStream) override; 177 | virtual NE::Stream::Status Write (NE::OutputStream& outputStream) const override; 178 | 179 | virtual NE::ValuePtr Transform (const Transformation& transformation) const override; 180 | virtual NUIE::DrawingItemConstPtr CreateDrawingItem () const override; 181 | }; 182 | 183 | #endif 184 | -------------------------------------------------------------------------------- /Sources/wxWidgetsTestApp/main.cpp: -------------------------------------------------------------------------------- 1 | #include "DrawingControl.hpp" 2 | #include "NE_SingleValues.hpp" 3 | #include "NE_Debug.hpp" 4 | #include "BI_BuiltInNodes.hpp" 5 | #include "WXAS_ParameterDialog.hpp" 6 | #include "WXAS_NodeEditorControl.hpp" 7 | 8 | #include "TestAppNodes.hpp" 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | class ApplicationState 17 | { 18 | public: 19 | ApplicationState () : 20 | currentFileName () 21 | { 22 | 23 | } 24 | 25 | void ClearCurrentFileName () 26 | { 27 | currentFileName.clear (); 28 | } 29 | 30 | void SetCurrentFileName (const std::wstring& newCurrentFileName) 31 | { 32 | currentFileName = newCurrentFileName; 33 | } 34 | 35 | bool HasCurrentFileName () const 36 | { 37 | return !currentFileName.empty (); 38 | } 39 | 40 | const std::wstring& GetCurrentFileName () const 41 | { 42 | return currentFileName; 43 | } 44 | 45 | private: 46 | std::wstring currentFileName; 47 | }; 48 | 49 | class MyCreateNodeCommand : public NUIE::SingleMenuCommand 50 | { 51 | public: 52 | enum class NodeType 53 | { 54 | Boolean, 55 | Integer, 56 | Number, 57 | IntegerIncrement, 58 | NumberIncrement, 59 | NumberDistribution, 60 | ListBuilder, 61 | Addition, 62 | Subtraction, 63 | Multiplication, 64 | Division, 65 | Color, 66 | Point, 67 | Line, 68 | Circle, 69 | Offset, 70 | Viewer 71 | }; 72 | 73 | MyCreateNodeCommand (WXAS::NodeEditorControl* nodeEditorControl, NodeType nodeType, const NE::LocString& name, const NUIE::Point& position) : 74 | NUIE::SingleMenuCommand (name, false), 75 | nodeEditorControl (nodeEditorControl), 76 | nodeType (nodeType), 77 | position (position) 78 | { 79 | 80 | } 81 | 82 | virtual bool WillModify () const override 83 | { 84 | return true; 85 | } 86 | 87 | virtual void DoModification () override 88 | { 89 | nodeEditorControl->AddNode (CreateNode (nodeEditorControl->ViewToModel (position))); 90 | } 91 | 92 | NUIE::UINodePtr CreateNode (const NUIE::Point& modelPosition) 93 | { 94 | switch (nodeType) { 95 | case NodeType::Boolean: 96 | return NUIE::UINodePtr (new BI::BooleanNode (NE::LocString (L"Boolean"), modelPosition, true)); 97 | case NodeType::Integer: 98 | return NUIE::UINodePtr (new BI::IntegerUpDownNode (NE::LocString (L"Integer"), modelPosition, 0, 5)); 99 | case NodeType::Number: 100 | return NUIE::UINodePtr (new BI::DoubleUpDownNode (NE::LocString (L"Number"), modelPosition, 0.0, 5.0)); 101 | case NodeType::IntegerIncrement: 102 | return NUIE::UINodePtr (new BI::IntegerIncrementedNode (NE::LocString (L"Integer Increment"), modelPosition)); 103 | case NodeType::NumberIncrement: 104 | return NUIE::UINodePtr (new BI::DoubleIncrementedNode (NE::LocString (L"Number Increment"), modelPosition)); 105 | case NodeType::NumberDistribution: 106 | return NUIE::UINodePtr (new BI::DoubleDistributedNode (NE::LocString (L"Number Distribution"), modelPosition)); 107 | case NodeType::ListBuilder: 108 | return NUIE::UINodePtr (new BI::ListBuilderNode (NE::LocString (L"List Builder"), modelPosition)); 109 | case NodeType::Addition: 110 | return NUIE::UINodePtr (new BI::AdditionNode (NE::LocString (L"Addition"), modelPosition)); 111 | case NodeType::Subtraction: 112 | return NUIE::UINodePtr (new BI::SubtractionNode (NE::LocString (L"Subtraction"), modelPosition)); 113 | case NodeType::Multiplication: 114 | return NUIE::UINodePtr (new BI::MultiplicationNode (NE::LocString (L"Multiplication"), modelPosition)); 115 | case NodeType::Division: 116 | return NUIE::UINodePtr (new BI::DivisionNode (NE::LocString (L"Division"), modelPosition)); 117 | case NodeType::Color: 118 | return NUIE::UINodePtr (new ColorNode (NE::LocString (L"Color"), modelPosition)); 119 | case NodeType::Point: 120 | return NUIE::UINodePtr (new PointNode (NE::LocString (L"Point"), modelPosition)); 121 | case NodeType::Line: 122 | return NUIE::UINodePtr (new LineNode (NE::LocString (L"Line"), modelPosition)); 123 | case NodeType::Circle: 124 | return NUIE::UINodePtr (new CircleNode (NE::LocString (L"Circle"), modelPosition)); 125 | case NodeType::Offset: 126 | return NUIE::UINodePtr (new OffsetNode (NE::LocString (L"Offset"), modelPosition)); 127 | case NodeType::Viewer: 128 | return NUIE::UINodePtr (new BI::MultiLineViewerNode (NE::LocString (L"Viewer"), modelPosition, 5)); 129 | } 130 | return nullptr; 131 | } 132 | 133 | private: 134 | WXAS::NodeEditorControl* nodeEditorControl; 135 | NodeType nodeType; 136 | NUIE::Point position; 137 | }; 138 | 139 | class MyNodeEditorEventHandler : public WXAS::NodeEditorEventHandler 140 | { 141 | public: 142 | MyNodeEditorEventHandler (WXAS::NodeEditorControl* control) : 143 | WXAS::NodeEditorEventHandler (control) 144 | { 145 | 146 | } 147 | 148 | virtual NUIE::MenuCommandPtr OnContextMenu (NUIE::EventHandler::ContextMenuType type, const NUIE::Point& position, const NUIE::MenuCommandStructure& commands) override 149 | { 150 | if (type == NUIE::EventHandler::ContextMenuType::EmptyArea) { 151 | NUIE::MenuCommandStructure actualCommands = commands; 152 | NUIE::MultiMenuCommandPtr createCommandGroup (new NUIE::MultiMenuCommand (NE::LocString (L"Add Node"))); 153 | 154 | NUIE::MultiMenuCommandPtr inputCommandGroup (new NUIE::MultiMenuCommand (NE::LocString (L"Input Nodes"))); 155 | inputCommandGroup->AddChildCommand (NUIE::MenuCommandPtr (new MyCreateNodeCommand (control, MyCreateNodeCommand::NodeType::Boolean, NE::LocString (L"Boolean"), position))); 156 | inputCommandGroup->AddChildCommand (NUIE::MenuCommandPtr (new MyCreateNodeCommand (control, MyCreateNodeCommand::NodeType::Integer, NE::LocString (L"Integer"), position))); 157 | inputCommandGroup->AddChildCommand (NUIE::MenuCommandPtr (new MyCreateNodeCommand (control, MyCreateNodeCommand::NodeType::Number, NE::LocString (L"Number"), position))); 158 | inputCommandGroup->AddChildCommand (NUIE::MenuCommandPtr (new MyCreateNodeCommand (control, MyCreateNodeCommand::NodeType::IntegerIncrement, NE::LocString (L"Integer Increment"), position))); 159 | inputCommandGroup->AddChildCommand (NUIE::MenuCommandPtr (new MyCreateNodeCommand (control, MyCreateNodeCommand::NodeType::NumberIncrement, NE::LocString (L"Number Increment"), position))); 160 | inputCommandGroup->AddChildCommand (NUIE::MenuCommandPtr (new MyCreateNodeCommand (control, MyCreateNodeCommand::NodeType::NumberDistribution, NE::LocString (L"Number Distribution"), position))); 161 | inputCommandGroup->AddChildCommand (NUIE::MenuCommandPtr (new MyCreateNodeCommand (control, MyCreateNodeCommand::NodeType::ListBuilder, NE::LocString (L"List Builder"), position))); 162 | createCommandGroup->AddChildCommand (inputCommandGroup); 163 | 164 | NUIE::MultiMenuCommandPtr arithmeticCommandGroup (new NUIE::MultiMenuCommand (NE::LocString (L"Arithmetic Nodes"))); 165 | arithmeticCommandGroup->AddChildCommand (NUIE::MenuCommandPtr (new MyCreateNodeCommand (control, MyCreateNodeCommand::NodeType::Addition, NE::LocString (L"Addition"), position))); 166 | arithmeticCommandGroup->AddChildCommand (NUIE::MenuCommandPtr (new MyCreateNodeCommand (control, MyCreateNodeCommand::NodeType::Subtraction, NE::LocString (L"Subtraction"), position))); 167 | arithmeticCommandGroup->AddChildCommand (NUIE::MenuCommandPtr (new MyCreateNodeCommand (control, MyCreateNodeCommand::NodeType::Multiplication, NE::LocString (L"Multiplication"), position))); 168 | arithmeticCommandGroup->AddChildCommand (NUIE::MenuCommandPtr (new MyCreateNodeCommand (control, MyCreateNodeCommand::NodeType::Division, NE::LocString (L"Division"), position))); 169 | createCommandGroup->AddChildCommand (arithmeticCommandGroup); 170 | 171 | NUIE::MultiMenuCommandPtr drawingCommandGroup (new NUIE::MultiMenuCommand (NE::LocString (L"Drawing Nodes"))); 172 | drawingCommandGroup->AddChildCommand (NUIE::MenuCommandPtr (new MyCreateNodeCommand (control, MyCreateNodeCommand::NodeType::Color, NE::LocString (L"Color"), position))); 173 | drawingCommandGroup->AddChildCommand (NUIE::MenuCommandPtr (new MyCreateNodeCommand (control, MyCreateNodeCommand::NodeType::Point, NE::LocString (L"Point"), position))); 174 | drawingCommandGroup->AddChildCommand (NUIE::MenuCommandPtr (new MyCreateNodeCommand (control, MyCreateNodeCommand::NodeType::Line, NE::LocString (L"Line"), position))); 175 | drawingCommandGroup->AddChildCommand (NUIE::MenuCommandPtr (new MyCreateNodeCommand (control, MyCreateNodeCommand::NodeType::Circle, NE::LocString (L"Circle"), position))); 176 | createCommandGroup->AddChildCommand (drawingCommandGroup); 177 | 178 | NUIE::MultiMenuCommandPtr transformationCommandGroup (new NUIE::MultiMenuCommand (NE::LocString (L"Transformation Nodes"))); 179 | transformationCommandGroup->AddChildCommand (NUIE::MenuCommandPtr (new MyCreateNodeCommand (control, MyCreateNodeCommand::NodeType::Offset, NE::LocString (L"Offset"), position))); 180 | createCommandGroup->AddChildCommand (transformationCommandGroup); 181 | 182 | NUIE::MultiMenuCommandPtr otherCommandGroup (new NUIE::MultiMenuCommand (NE::LocString (L"Other Nodes"))); 183 | otherCommandGroup->AddChildCommand (NUIE::MenuCommandPtr (new MyCreateNodeCommand (control, MyCreateNodeCommand::NodeType::Viewer, NE::LocString (L"Viewer"), position))); 184 | createCommandGroup->AddChildCommand (otherCommandGroup); 185 | 186 | actualCommands.AddCommand (createCommandGroup); 187 | return WXAS::SelectCommandFromContextMenu (control, position, actualCommands); 188 | } else { 189 | return WXAS::SelectCommandFromContextMenu (control, position, commands); 190 | } 191 | } 192 | }; 193 | 194 | class MyNodeEditorUIEnvironment : public WXAS::NodeEditorUIEnvironment 195 | { 196 | public: 197 | MyNodeEditorUIEnvironment ( WXAS::NodeEditorControl* nodeEditorControl, 198 | DrawingControl* drawingControl, 199 | NE::StringConverterPtr& stringConverter, 200 | NUIE::SkinParamsPtr& skinParams, 201 | NUIE::EventHandlerPtr& eventHandler, 202 | NE::EvaluationEnv& evaluationEnv) : 203 | WXAS::NodeEditorUIEnvironment (nodeEditorControl, stringConverter, skinParams, eventHandler, evaluationEnv), 204 | drawingControl (drawingControl) 205 | { 206 | } 207 | 208 | virtual void OnValuesRecalculated () override 209 | { 210 | drawingControl->RedrawImage (); 211 | } 212 | 213 | private: 214 | DrawingControl* drawingControl; 215 | }; 216 | 217 | class MyNodeEditorControl : public WXAS::NodeEditorControl 218 | { 219 | public: 220 | MyNodeEditorControl (wxWindow *parent) : 221 | WXAS::NodeEditorControl (parent) 222 | { 223 | 224 | } 225 | 226 | virtual void OnInit () override 227 | { 228 | static const bool isStressTest = false; 229 | if (isStressTest) { 230 | static int count = 10; 231 | for (int i = 0; i < count; i++) { 232 | for (int j = 0; j < count; j++) { 233 | nodeEditor->AddNode (NUIE::UINodePtr (new BI::DoubleIncrementedNode (NE::LocString (L"Range"), NUIE::Point (i * 150, j * 150)))); 234 | } 235 | } 236 | nodeEditor->Update (); 237 | } else { 238 | NUIE::UINodePtr startInputNode (new BI::DoubleUpDownNode (NE::LocString (L"Number"), NUIE::Point (70, 70), 20, 5)); 239 | NUIE::UINodePtr stepInputNode (new BI::DoubleUpDownNode (NE::LocString (L"Number"), NUIE::Point (70, 180), 20, 5)); 240 | NUIE::UINodePtr intRangeNodeX (new BI::DoubleIncrementedNode (NE::LocString (L"Increment"), NUIE::Point (220, 100))); 241 | NUIE::UINodePtr inputNodeY (new BI::DoubleUpDownNode (NE::LocString (L"Number"), NUIE::Point (220, 220), 20, 5)); 242 | std::shared_ptr pointNode (new PointNode (NE::LocString (L"Point"), NUIE::Point (400, 150))); 243 | NUIE::UINodePtr viewerNode (new BI::MultiLineViewerNode (NE::LocString (L"Viewer"), NUIE::Point (600, 150), 5)); 244 | 245 | nodeEditor->AddNode (startInputNode); 246 | nodeEditor->AddNode (stepInputNode); 247 | nodeEditor->AddNode (intRangeNodeX); 248 | nodeEditor->AddNode (inputNodeY); 249 | nodeEditor->AddNode (pointNode); 250 | nodeEditor->AddNode (viewerNode); 251 | 252 | nodeEditor->ConnectOutputSlotToInputSlot (startInputNode->GetUIOutputSlot (NE::SlotId ("out")), intRangeNodeX->GetUIInputSlot (NE::SlotId ("start"))); 253 | nodeEditor->ConnectOutputSlotToInputSlot (stepInputNode->GetUIOutputSlot (NE::SlotId ("out")), intRangeNodeX->GetUIInputSlot (NE::SlotId ("step"))); 254 | nodeEditor->ConnectOutputSlotToInputSlot (intRangeNodeX->GetUIOutputSlot (NE::SlotId ("out")), pointNode->GetUIInputSlot (NE::SlotId ("x"))); 255 | nodeEditor->ConnectOutputSlotToInputSlot (inputNodeY->GetUIOutputSlot (NE::SlotId ("out")), pointNode->GetUIInputSlot (NE::SlotId ("y"))); 256 | nodeEditor->ConnectOutputSlotToInputSlot (pointNode->GetUIOutputSlot (NE::SlotId ("point")), viewerNode->GetUIInputSlot (NE::SlotId ("in"))); 257 | nodeEditor->Update (); 258 | } 259 | } 260 | }; 261 | 262 | class MenuBar : public wxMenuBar 263 | { 264 | public: 265 | enum CommandId 266 | { 267 | File_New = 1, 268 | File_Open = 2, 269 | File_Save = 3, 270 | File_SaveAs = 4, 271 | File_Exit = 5, 272 | Edit_Undo = 6, 273 | Edit_Redo = 7, 274 | Mode_Automatic = 8, 275 | Mode_Manual = 9, 276 | Mode_Update = 10, 277 | View_AlignToWindow = 11, 278 | View_FitToWindow = 12 279 | }; 280 | 281 | MenuBar () : 282 | wxMenuBar () 283 | { 284 | wxMenu* fileMenu = new wxMenu (); 285 | fileMenu->Append (CommandId::File_New, "New"); 286 | fileMenu->Append (CommandId::File_Open, "Open..."); 287 | fileMenu->Append (CommandId::File_Save, "Save..."); 288 | fileMenu->Append (CommandId::File_SaveAs, "Save As..."); 289 | fileMenu->AppendSeparator (); 290 | fileMenu->Append (CommandId::File_Exit, L"Exit"); 291 | Append (fileMenu, L"&File"); 292 | 293 | wxMenu* editMenu = new wxMenu (); 294 | editMenu->Append (CommandId::Edit_Undo, "Undo"); 295 | editMenu->Append (CommandId::Edit_Redo, "Redo"); 296 | Append (editMenu, L"&Edit"); 297 | 298 | wxMenu* modeMenu = new wxMenu (); 299 | modeMenu->AppendRadioItem (CommandId::Mode_Automatic, "Automatic"); 300 | modeMenu->AppendRadioItem (CommandId::Mode_Manual, "Manual"); 301 | modeMenu->AppendSeparator (); 302 | modeMenu->Append (CommandId::Mode_Update, L"Update"); 303 | Append (modeMenu, L"&Mode"); 304 | 305 | wxMenu* viewMenu = new wxMenu (); 306 | viewMenu->Append (CommandId::View_AlignToWindow, "Align To Window"); 307 | viewMenu->Append (CommandId::View_FitToWindow, "Fit To Window"); 308 | Append (viewMenu, L"&View"); 309 | } 310 | 311 | void UpdateStatus (WXAS::NodeEditorControl::UpdateMode updateMode) 312 | { 313 | if (updateMode == WXAS::NodeEditorControl::UpdateMode::Automatic) { 314 | FindItem (CommandId::Mode_Automatic)->Check (); 315 | } else if (updateMode == WXAS::NodeEditorControl::UpdateMode::Manual) { 316 | FindItem (CommandId::Mode_Manual)->Check (); 317 | } else { 318 | DBGBREAK (); 319 | } 320 | } 321 | }; 322 | 323 | static const NUIE::BasicSkinParams& GetAppSkinParams () 324 | { 325 | static const NUIE::BasicSkinParams skinParams ( 326 | /*backgroundColor*/ NUIE::Color (255, 255, 255), 327 | /*connectionLinePen*/ NUIE::Pen (NUIE::Color (38, 50, 56), 1.0), 328 | /*connectionMarker */ NUIE::SkinParams::ConnectionMarker::Circle, 329 | /*connectionMarkerSize*/ NUIE::Size (8.0, 8.0), 330 | /*nodePadding*/ 5.0, 331 | /*nodeBorderPen*/ NUIE::Pen (NUIE::Color (38, 50, 56), 1.0), 332 | /*nodeHeaderTextFont*/ NUIE::Font (L"Arial", 12.0), 333 | /*nodeHeaderTextColor*/ NUIE::Color (250, 250, 250), 334 | /*nodeHeaderErrorTextColor*/ NUIE::Color (250, 250, 250), 335 | /*nodeHeaderBackgroundColor*/ NUIE::Color (41, 127, 255), 336 | /*nodeHeaderErrorBackgroundColor*/ NUIE::Color (199, 80, 80), 337 | /*nodeContentTextFont*/ NUIE::Font (L"Arial", 10.0), 338 | /*nodeContentTextColor*/ NUIE::Color (0, 0, 0), 339 | /*nodeContentBackgroundColor*/ NUIE::Color (236, 236, 236), 340 | /*slotTextColor*/ NUIE::Color (0, 0, 0), 341 | /*slotTextBackgroundColor*/ NUIE::Color (246, 246, 246), 342 | /*slotMarker*/ NUIE::SkinParams::SlotMarker::Circle, 343 | /*hiddenSlotMarker*/ NUIE::SkinParams::HiddenSlotMarker::Arrow, 344 | /*slotMarkerSize*/ NUIE::Size (8.0, 8.0), 345 | /*selectionBlendColor*/ NUIE::BlendColor (NUIE::Color (41, 127, 255), 0.25), 346 | /*disabledBlendColor*/ NUIE::BlendColor (NUIE::Color (0, 138, 184), 0.2), 347 | /*selectionRectPen*/ NUIE::Pen (NUIE::Color (41, 127, 255), 1.0), 348 | /*nodeSelectionRectPen*/ NUIE::Pen (NUIE::Color (41, 127, 255), 3.0), 349 | /*buttonBorderPen*/ NUIE::Pen (NUIE::Color (146, 152, 155), 1.0), 350 | /*buttonBackgroundColor*/ NUIE::Color (217, 217, 217), 351 | /*textPanelTextColor*/ NUIE::Color (0, 0, 0), 352 | /*textPanelBackgroundColor*/ NUIE::Color (236, 236, 236), 353 | /*groupNameFont*/ NUIE::Font (L"Arial", 12.0), 354 | /*groupNameColor*/ NUIE::Color (0, 0, 0), 355 | /*groupBackgroundColors*/ NUIE::NamedColorSet ({ 356 | { NE::LocalizeString (L"Blue"), NUIE::Color (160, 200, 240) }, 357 | { NE::LocalizeString (L"Green"), NUIE::Color (160, 239, 160) }, 358 | { NE::LocalizeString (L"Red"), NUIE::Color (239, 189, 160) } 359 | }), 360 | /*groupPadding*/ 12.0 361 | ); 362 | return skinParams; 363 | } 364 | 365 | class MainFrame : public wxFrame 366 | { 367 | public: 368 | MainFrame (const std::shared_ptr& resultImage, NE::EvaluationEnv& evaluationEnv) : 369 | wxFrame (NULL, wxID_ANY, L"Node Engine Test App", wxDefaultPosition, wxSize (1000, 600)), 370 | menuBar (new MenuBar ()), 371 | mainWindow (new wxSplitterWindow (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_THIN_SASH | wxSP_LIVE_UPDATE)), 372 | drawingControl (new DrawingControl (mainWindow, resultImage)), 373 | nodeEditorControl (new MyNodeEditorControl (mainWindow)), 374 | applicationState () 375 | { 376 | NE::StringConverterPtr stringConverter (new NE::BasicStringConverter (NE::GetDefaultStringSettings ())); 377 | NUIE::SkinParamsPtr skinParams (new NUIE::BasicSkinParams (GetAppSkinParams ())); 378 | NUIE::EventHandlerPtr eventHandler (new MyNodeEditorEventHandler (nodeEditorControl)); 379 | std::shared_ptr uiEnvironment = std::shared_ptr ( 380 | new MyNodeEditorUIEnvironment ( 381 | nodeEditorControl, 382 | drawingControl, 383 | stringConverter, 384 | skinParams, 385 | eventHandler, 386 | evaluationEnv 387 | ) 388 | ); 389 | 390 | nodeEditorControl->Init (uiEnvironment); 391 | 392 | SetMenuBar (menuBar); 393 | UpdateMenuBar (); 394 | 395 | CreateStatusBar (); 396 | UpdateStatusBar (); 397 | 398 | mainWindow->SetSashGravity (0.5); 399 | mainWindow->SetMinimumPaneSize (20); 400 | mainWindow->SplitVertically (nodeEditorControl, drawingControl, 700); 401 | } 402 | 403 | ~MainFrame () 404 | { 405 | 406 | } 407 | 408 | void OnCommand (wxCommandEvent& evt) 409 | { 410 | MenuBar::CommandId commandId = (MenuBar::CommandId) evt.GetId (); 411 | switch (commandId) { 412 | case MenuBar::CommandId::File_New: 413 | { 414 | Reset (); 415 | } 416 | break; 417 | case MenuBar::CommandId::File_Open: 418 | { 419 | wxFileDialog fileDialog (this, L"Open", L"", L"", L"Node Engine Files (*.ne)|*.ne", wxFD_OPEN | wxFD_FILE_MUST_EXIST); 420 | if (fileDialog.ShowModal () == wxID_OK) { 421 | drawingControl->ClearImage (); 422 | std::wstring fileName = fileDialog.GetPath ().ToStdWstring (); 423 | if (nodeEditorControl->Open (fileName)) { 424 | applicationState.SetCurrentFileName (fileName); 425 | } else { 426 | Reset (); 427 | } 428 | } 429 | } 430 | break; 431 | case MenuBar::CommandId::File_Save: 432 | { 433 | wxFileDialog fileDialog (this, L"Save", L"", L"", L"Node Engine Files (*.ne)|*.ne", wxFD_SAVE); 434 | if (applicationState.HasCurrentFileName ()) { 435 | nodeEditorControl->Save (applicationState.GetCurrentFileName ()); 436 | } else if (fileDialog.ShowModal () == wxID_OK) { 437 | std::wstring fileName = fileDialog.GetPath ().ToStdWstring (); 438 | nodeEditorControl->Save (fileName); 439 | applicationState.SetCurrentFileName (fileName); 440 | } 441 | } 442 | break; 443 | case MenuBar::CommandId::File_SaveAs: 444 | { 445 | wxFileDialog fileDialog (this, L"Save As", L"", L"", L"Node Engine Files (*.ne)|*.ne", wxFD_SAVE); 446 | if (fileDialog.ShowModal () == wxID_OK) { 447 | std::wstring fileName = fileDialog.GetPath ().ToStdWstring (); 448 | nodeEditorControl->Save (fileName); 449 | applicationState.SetCurrentFileName (fileName); 450 | } 451 | } 452 | break; 453 | case MenuBar::CommandId::File_Exit: 454 | { 455 | Close (true); 456 | } 457 | break; 458 | case MenuBar::CommandId::Edit_Undo: 459 | { 460 | nodeEditorControl->Undo (); 461 | } 462 | break; 463 | case MenuBar::CommandId::Edit_Redo: 464 | { 465 | nodeEditorControl->Redo (); 466 | } 467 | break; 468 | case MenuBar::CommandId::Mode_Automatic: 469 | { 470 | nodeEditorControl->SetUpdateMode (WXAS::NodeEditorControl::UpdateMode::Automatic); 471 | } 472 | break; 473 | case MenuBar::CommandId::Mode_Manual: 474 | { 475 | nodeEditorControl->SetUpdateMode (WXAS::NodeEditorControl::UpdateMode::Manual); 476 | } 477 | break; 478 | case MenuBar::CommandId::Mode_Update: 479 | { 480 | nodeEditorControl->ManualUpdate (); 481 | } 482 | break; 483 | case MenuBar::CommandId::View_AlignToWindow: 484 | { 485 | nodeEditorControl->AlignToWindow (); 486 | } 487 | break; 488 | case MenuBar::CommandId::View_FitToWindow: 489 | { 490 | nodeEditorControl->FitToWindow (); 491 | } 492 | break; 493 | } 494 | UpdateMenuBar (); 495 | UpdateStatusBar (); 496 | } 497 | 498 | private: 499 | void UpdateMenuBar () 500 | { 501 | menuBar->UpdateStatus (nodeEditorControl->GetUpdateMode ()); 502 | } 503 | 504 | void UpdateStatusBar () 505 | { 506 | std::wstring currentFileText = L"No File"; 507 | if (applicationState.HasCurrentFileName ()) { 508 | currentFileText = applicationState.GetCurrentFileName (); 509 | } 510 | SetStatusText (currentFileText); 511 | } 512 | 513 | void Reset () 514 | { 515 | nodeEditorControl->New (); 516 | drawingControl->ClearImage (); 517 | applicationState.ClearCurrentFileName (); 518 | } 519 | 520 | MenuBar* menuBar; 521 | wxSplitterWindow* mainWindow; 522 | DrawingControl* drawingControl; 523 | WXAS::NodeEditorControl* nodeEditorControl; 524 | ApplicationState applicationState; 525 | 526 | DECLARE_EVENT_TABLE () 527 | }; 528 | 529 | BEGIN_EVENT_TABLE (MainFrame, wxFrame) 530 | EVT_MENU (wxID_ANY, MainFrame::OnCommand) 531 | END_EVENT_TABLE () 532 | 533 | class NodeEngineTestApplication : public wxApp 534 | { 535 | public: 536 | NodeEngineTestApplication () : 537 | resultImage (new ResultImage ()), 538 | evaluationData (new ResultImageEvaluationData (resultImage)), 539 | evaluationEnv (evaluationData), 540 | mainFrame (nullptr) 541 | { 542 | 543 | } 544 | 545 | virtual bool OnInit () 546 | { 547 | mainFrame = new MainFrame (resultImage, evaluationEnv); 548 | mainFrame->Show (true); 549 | SetTopWindow (mainFrame); 550 | return true; 551 | } 552 | 553 | private: 554 | std::shared_ptr resultImage; 555 | std::shared_ptr evaluationData; 556 | NE::EvaluationEnv evaluationEnv; 557 | 558 | MainFrame* mainFrame; 559 | }; 560 | 561 | IMPLEMENT_APP (NodeEngineTestApplication) 562 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: "{build}" 2 | 3 | clone_folder: c:\projects\VisualScriptEngineWxWidgets 4 | 5 | environment: 6 | PYTHON: "C:\\Python38-x64" 7 | 8 | image: 9 | - Visual Studio 2017 10 | 11 | cache: 12 | - C:\Dependencies\wxWidgets-3.1.2\include -> appveyor.yml 13 | - C:\Dependencies\wxWidgets-3.1.2\lib\vc_x64_lib -> appveyor.yml 14 | 15 | configuration: 16 | - Debug 17 | - Release 18 | 19 | platform: 20 | - x64 21 | 22 | init: 23 | - set PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH% 24 | - python -V 25 | 26 | before_build: 27 | - set VSE_DEVKIT_DIR=C:\Dependencies\VisualScriptEngine-master\Build\DevKit 28 | - set WXWIDGETS_DIR=C:\Dependencies\wxWidgets-3.1.2 29 | - python installdepswin.py C:\Dependencies msbuild %configuration% 30 | - mkdir Build 31 | - cd Build 32 | - cmake -G "Visual Studio 15 2017 Win64" .. 33 | 34 | build: 35 | project: c:\projects\VisualScriptEngineWxWidgets\Build\VisualScriptEngineWxWidgets.sln 36 | verbosity: minimal 37 | -------------------------------------------------------------------------------- /installdepswin.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import re 4 | import urllib.request 5 | import subprocess 6 | 7 | def DownloadFile (url, path): 8 | print ('Downloading ' + url) 9 | urllib.request.urlretrieve (url, path) 10 | 11 | def UnzipFile (zipFile, targetFolder): 12 | print ('Unzipping ' + zipFile) 13 | subprocess.call (['7z', 'x', zipFile, '-o' + targetFolder]) 14 | 15 | def CmakeProject (projectPath, buildFolderName): 16 | print ('CmakeProject ' + projectPath) 17 | buildFolder = os.path.join (projectPath, buildFolderName) 18 | os.makedirs (buildFolder) 19 | prevWorkDir = os.getcwd () 20 | os.chdir (buildFolder) 21 | subprocess.call (['cmake', '..', '-G', 'Visual Studio 15 2017 Win64']) 22 | os.chdir (prevWorkDir) 23 | 24 | def BuildSolution (msBuildPath, solutionPath, configuration): 25 | print ('Building ' + solutionPath) 26 | subprocess.call ([msBuildPath, solutionPath, '/property:Configuration=' + configuration, '/property:Platform=x64']) 27 | 28 | def InstallwxWidgets (targetFolder, msBuildPath, msBuildConfiguration): 29 | wxWidgetsName = 'wxWidgets-3.1.2' 30 | wxWidgetsZipUrl = 'https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.2/wxWidgets-3.1.2.7z' 31 | wxWidgetsZipPath = os.path.join (targetFolder, wxWidgetsName + '.7z') 32 | wxWidgetsFolderPath = os.path.join (targetFolder, wxWidgetsName) 33 | wxWidgetsIncludeFolderPath = os.path.join (wxWidgetsFolderPath, 'include') 34 | wxWidgetsLibFolderPath = os.path.join (wxWidgetsFolderPath, 'lib', 'vc_x64_lib') 35 | if not os.path.exists (wxWidgetsFolderPath): 36 | DownloadFile (wxWidgetsZipUrl, wxWidgetsZipPath) 37 | UnzipFile (wxWidgetsZipPath, wxWidgetsFolderPath) 38 | solutionPath = os.path.join (wxWidgetsFolderPath, 'build', 'msw', 'wx_vc15.sln') 39 | BuildSolution (msBuildPath, solutionPath, msBuildConfiguration) 40 | 41 | def InstallVisualScriptEngine (targetFolder, msBuildPath, msBuildConfiguration): 42 | vseName = 'VisualScriptEngine-master' 43 | vseZipUrl = 'https://github.com/kovacsv/VisualScriptEngine/archive/master.zip' 44 | vseZipPath = os.path.join (targetFolder, vseName + '.zip') 45 | vseFolderPath = os.path.join (targetFolder, vseName) 46 | if not os.path.exists (vseFolderPath): 47 | DownloadFile (vseZipUrl, vseZipPath) 48 | UnzipFile (vseZipPath, targetFolder) 49 | CmakeProject (vseFolderPath, 'Build') 50 | solutionPath = os.path.join (vseFolderPath, 'Build', 'VisualScriptEngine.sln') 51 | installProjectPath = os.path.join (vseFolderPath, 'Build', 'INSTALL.vcxproj') 52 | BuildSolution (msBuildPath, solutionPath, msBuildConfiguration) 53 | BuildSolution (msBuildPath, installProjectPath, msBuildConfiguration) 54 | 55 | def Main (argv): 56 | if len (argv) != 4: 57 | print ('usage: installdepswin.py ') 58 | return 1 59 | 60 | currentDir = os.path.dirname (os.path.abspath (__file__)) 61 | os.chdir (currentDir) 62 | 63 | targetFolder = sys.argv[1] 64 | msBuildPath = sys.argv[2] # "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe" 65 | msBuildConfiguration = sys.argv[3] 66 | 67 | if not os.path.exists (targetFolder): 68 | os.makedirs (targetFolder) 69 | 70 | InstallwxWidgets (targetFolder, msBuildPath, msBuildConfiguration) 71 | InstallVisualScriptEngine (targetFolder, msBuildPath, msBuildConfiguration) 72 | return 0 73 | 74 | sys.exit (Main (sys.argv)) 75 | --------------------------------------------------------------------------------